GwySensitivityGroup — Control widget sensitivity by flags
GwySensitivityGroup * | gwy_sensitivity_group_new () |
void | gwy_sensitivity_group_add_widget () |
void | gwy_sensitivity_group_set_state () |
guint | gwy_sensitivity_group_get_state () |
void | gwy_sensitivity_group_release_widget () |
guint | gwy_sensitivity_group_get_widget_mask () |
void | gwy_sensitivity_group_set_widget_mask () |
gboolean | gwy_sensitivity_group_contains_widget () |
struct | GwySensitivityGroup |
struct | GwySensitivityGroupClass |
GObject ╰── GwySensitivityGroup
#include <libgwydgets/gwydgets.h>
GwySensitivityGroup is a tool to manage sensitivity of sets of related widgets based on fulfilment of some conditions.
A new sensitivity group is created with gwy_sensitivity_group_new()
.
Widgets are then added to it with gwy_sensitivity_group_add_widget()
, each
with some set of flags it reacts to. When state of the sensitivity group
is then changed with gwy_sensitivity_group_set_state()
, widgets whose flags
are set are made sensitive, others insensitive (see
gwy_sensitivity_group_set_state()
description for details).
The interpretation of the flags is completely up to GwySensitivityGroup user, but they generally represent availability of some resource or possibility of some action.
In the following example we have two conditions, SENS_IMAGE
and
SENS_GRAPH
, representing availability of image data and graph data:
1 2 3 4 5 |
enum { SENS_IMAGE = 1 << 0, SENS_GRAPH = 1 << 1, SENS_MASK = 0x03 }; |
We create buttons for three actions, one operates on image data, another on graph data, and the last on both:
1 2 3 4 5 6 7 8 |
sensgroup = gwy_sensitivity_group_new(); button = gtk_button_new_with_label("Filter Data"); gwy_sensitivity_group_add_widget(sensgroup, button, SENS_IMAGE); button = gtk_button_new_with_label("Fit Graph"); gwy_sensitivity_group_add_widget(sensgroup, button, SENS_GRAPH); button = gtk_button_new_with_label("Add Profile"); gwy_sensitivity_group_add_widget(sensgroup, button, SENS_IMAGE | SENS_GRAPH); g_object_unref(sensgroup); |
When graph data becomes available, we simply call
1 |
gwy_sensitivity_group_set_state(sensgroup, SENS_GRAPH, SENS_GRAPH); |
and when image data becomes unavailable
1 |
gwy_sensitivity_group_set_state(sensgroup, SENS_IMAGE, 0); |
and the button sensitivities will be adjusted to match the situation.
GwySensitivityGroup *
gwy_sensitivity_group_new (void
);
Creates a new flag-based widget sensitivity group.
The newly created sensitivity group. It starts with zero state.
void gwy_sensitivity_group_add_widget (GwySensitivityGroup *sensgroup
,GtkWidget *widget
,guint mask
);
Adds a widget to flag sensitivity group.
Widget sensitivity should not be set manually after the addition as the result is likely to be a fight over sensitivity setting.
The added widget takes a reference on sensgroup
. So the group is not
destroyed when they are any widgets in, generally, you can release your
initial reference after adding widgets to the group.
sensgroup |
A widget flag sensitivity group. |
|
widget |
Widget to add to |
|
mask |
Which flags the widget is sensitive to. See
|
void gwy_sensitivity_group_set_state (GwySensitivityGroup *sensgroup
,guint affected_mask
,guint state
);
Sets the state of a widget flag sensitivity group.
Widget sensitivity states are then updated accordingly.
More precisely, widget will be made sensitive when all bits in its mask
are
set in current sensgroup
state, insensitive otherwise. This means when
mask
is zero, widget will be always sensitive.
sensgroup |
A widget flag sensitivity group. |
|
affected_mask |
Which bits in |
|
state |
The new state of |
guint
gwy_sensitivity_group_get_state (GwySensitivityGroup *sensgroup
);
Gets the current state of a widget flag sensitivity group.
sensgroup |
A widget flag sensitivity group. |
The current state as set with gwy_sensitivity_group_set_state()
.
void gwy_sensitivity_group_release_widget (GwySensitivityGroup *sensgroup
,GtkWidget *widget
);
Removes a widget from flag sensitivity group.
sensgroup |
A widget flag sensitivity group. |
|
widget |
Widget to remove from |
guint gwy_sensitivity_group_get_widget_mask (GwySensitivityGroup *sensgroup
,GtkWidget *widget
);
Gets sensitivity flags of a widget in a flag sensitivity group.
sensgroup |
A widget flag sensitivity group. |
|
widget |
Widget to get flags of. |
The mask as passed to gwy_sensitivity_group_add_widget()
or gwy_sensitivity_group_set_widget_mask()
.
void gwy_sensitivity_group_set_widget_mask (GwySensitivityGroup *sensgroup
,GtkWidget *widget
,guint mask
);
Sets the flag mask of a widget in a flag sensitivity group.
sensgroup |
A widget flag sensitivity group. |
|
widget |
Widget to set flags of. |
|
mask |
Which flags the widget is sensitive to. See
|
gboolean gwy_sensitivity_group_contains_widget (GwySensitivityGroup *sensgroup
,GtkWidget *widget
);
Checks whether a widget belongs to a sensitivity group.
sensgroup |
A widget flag sensitivity group. |
|
widget |
Widget to test for membership. |
TRUE
if widget
is in sensgroup
, FALSE
otherwise.
Since: 2.34
struct GwySensitivityGroup;
struct GwySensitivityGroupClass { GObjectClass parent_class; void (*reserved1)(void); void (*reserved2)(void); void (*reserved3)(void); };