libegg r841 - in trunk: . libegg/toolpalette
- From: hasselmm svn gnome org
- To: svn-commits-list gnome org
- Subject: libegg r841 - in trunk: . libegg/toolpalette
- Date: Mon, 14 Jan 2008 08:40:51 +0000 (GMT)
Author: hasselmm
Date: Mon Jan 14 08:40:51 2008
New Revision: 841
URL: http://svn.gnome.org/viewvc/libegg?rev=841&view=rev
Log:
Support filtering of EggEnumAction entries.
* libegg/toolpalette/eggenumaction.c,
libegg/toolpalette/eggenumaction.h: Add egg_enum_action_set_filter.
* libegg/toolpalette/testtoolpalette.c: Filter GTK_ICON_SIZE_INVALID.
Modified:
trunk/ChangeLog
trunk/libegg/toolpalette/eggenumaction.c
trunk/libegg/toolpalette/eggenumaction.h
trunk/libegg/toolpalette/testtoolpalette.c
Modified: trunk/libegg/toolpalette/eggenumaction.c
==============================================================================
--- trunk/libegg/toolpalette/eggenumaction.c (original)
+++ trunk/libegg/toolpalette/eggenumaction.c Mon Jan 14 08:40:51 2008
@@ -36,6 +36,10 @@
GEnumClass *enum_class;
GSList *bindings;
GtkListStore *model;
+
+ EggEnumActionFilterFunc filter_func;
+ GDestroyNotify filter_destroy;
+ gpointer filter_data;
};
static GQuark egg_enum_action_child_quark;
@@ -131,6 +135,15 @@
action->priv->bindings->data);
}
+ if (action->priv->filter_destroy)
+ {
+ action->priv->filter_destroy (action->priv->filter_data);
+ action->priv->filter_destroy = NULL;
+ }
+
+ action->priv->filter_func = NULL;
+ action->priv->filter_data = NULL;
+
G_OBJECT_CLASS (egg_enum_action_parent_class)->dispose (object);
}
@@ -145,15 +158,20 @@
GtkTreeIter iter;
guint i;
- action->priv->model = gtk_list_store_new (2, G_TYPE_STRING, action->priv->enum_type);
+ action->priv->model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
for (i = 0; i < action->priv->enum_class->n_values; ++i)
{
- GEnumValue *v = &action->priv->enum_class->values[i];
+ GEnumValue *enum_value = &action->priv->enum_class->values[i];
+
+ if (action->priv->filter_func &&
+ !action->priv->filter_func (enum_value, action->priv->filter_data))
+ continue;
gtk_list_store_append (action->priv->model, &iter);
- gtk_list_store_set (action->priv->model, &iter,
- 0, v->value_nick, 1, v->value, -1);
+ gtk_list_store_set (action->priv->model, &iter,
+ 0, enum_value->value_nick,
+ 1, enum_value, -1);
}
}
@@ -167,7 +185,8 @@
GParamSpec *property)
{
GtkTreeModel *model = egg_enum_action_get_model (action);
- gint object_value, model_value;
+ GEnumValue *enum_value;
+ gint current_value;
if (!gtk_tree_model_get_iter_first (model, iter))
return FALSE;
@@ -175,13 +194,13 @@
if (!G_IS_OBJECT (object) || !G_IS_PARAM_SPEC_ENUM (property))
return TRUE;
- g_object_get (object, property->name, &object_value, NULL);
+ g_object_get (object, property->name, ¤t_value, NULL);
do
{
- gtk_tree_model_get (model, iter, 1, &model_value, -1);
+ gtk_tree_model_get (model, iter, 1, &enum_value, -1);
- if (model_value == object_value)
+ if (enum_value->value == current_value)
return TRUE;
}
while (gtk_tree_model_iter_next (model, iter));
@@ -227,15 +246,15 @@
gpointer data)
{
EggEnumAction *action = EGG_ENUM_ACTION (data);
+ GEnumValue *enum_value;
GtkTreeModel *model;
GtkTreeIter iter;
- gint value;
if (gtk_combo_box_get_active_iter (combo, &iter))
{
model = egg_enum_action_get_model (action);
- gtk_tree_model_get (model, &iter, 1, &value, -1);
- egg_enum_action_set_value (action, value);
+ gtk_tree_model_get (model, &iter, 1, &enum_value, -1);
+ egg_enum_action_set_value (action, enum_value->value);
}
}
@@ -327,17 +346,19 @@
egg_enum_action_menu_item_toggled (GtkCheckMenuItem *item,
gpointer data)
{
- gpointer value = g_object_get_qdata (G_OBJECT (item), egg_enum_action_value_quark);
- egg_enum_action_set_value (EGG_ENUM_ACTION (data), GPOINTER_TO_INT (value));
+ GEnumValue *enum_value;
+
+ enum_value = g_object_get_qdata (G_OBJECT (item), egg_enum_action_value_quark);
+ egg_enum_action_set_value (EGG_ENUM_ACTION (data), enum_value->value);
}
static GtkWidget*
egg_enum_action_create_menu_item (GtkAction *action)
{
GtkTreeModel *model = egg_enum_action_get_model (EGG_ENUM_ACTION (action));
+ GEnumValue *enum_value;
GtkTreeIter iter;
gchar *label;
- gint value;
GtkWidget *item;
GtkWidget *menu = gtk_menu_new ();
@@ -346,7 +367,7 @@
if (gtk_tree_model_get_iter_first (model, &iter))
do
{
- gtk_tree_model_get (model, &iter, 0, &label, 1, &value, -1);
+ gtk_tree_model_get (model, &iter, 0, &label, 1, &enum_value, -1);
item = gtk_radio_menu_item_new_with_label (group, label);
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
@@ -354,7 +375,7 @@
g_object_set_qdata (G_OBJECT (item),
egg_enum_action_value_quark,
- GINT_TO_POINTER (value));
+ enum_value);
g_signal_connect (item, "toggled",
G_CALLBACK (egg_enum_action_menu_item_toggled),
@@ -489,3 +510,18 @@
egg_enum_action_notify (object, property, action);
}
+void
+egg_enum_action_set_filter (EggEnumAction *action,
+ EggEnumActionFilterFunc filter,
+ gpointer user_data,
+ GDestroyNotify destroy_data)
+{
+ g_return_if_fail (EGG_IS_ENUM_ACTION (action));
+
+ if (action->priv->filter_destroy)
+ action->priv->filter_destroy (action->priv->filter_data);
+
+ action->priv->filter_func = filter;
+ action->priv->filter_data = user_data;
+ action->priv->filter_destroy = destroy_data;
+}
Modified: trunk/libegg/toolpalette/eggenumaction.h
==============================================================================
--- trunk/libegg/toolpalette/eggenumaction.h (original)
+++ trunk/libegg/toolpalette/eggenumaction.h Mon Jan 14 08:40:51 2008
@@ -37,6 +37,9 @@
typedef struct _EggEnumActionClass EggEnumActionClass;
typedef struct _EggEnumActionPrivate EggEnumActionPrivate;
+typedef gboolean (*EggEnumActionFilterFunc) (GEnumValue *enum_value,
+ gpointer user_data);
+
struct _EggEnumAction
{
GtkAction parent_instance;
@@ -48,14 +51,20 @@
GtkActionClass parent_class;
};
-GType egg_enum_action_get_type (void) G_GNUC_CONST;
-GtkAction* egg_enum_action_new (const gchar *name,
- const gchar *label,
- const gchar *tooltip,
- GType enum_type);
-void egg_enum_action_bind (EggEnumAction *action,
- GObject *object,
- const gchar *property_name);
+GType egg_enum_action_get_type (void) G_GNUC_CONST;
+GtkAction* egg_enum_action_new (const gchar *name,
+ const gchar *label,
+ const gchar *tooltip,
+ GType enum_type);
+
+void egg_enum_action_bind (EggEnumAction *action,
+ GObject *object,
+ const gchar *property_name);
+
+void egg_enum_action_set_filter (EggEnumAction *action,
+ EggEnumActionFilterFunc filter,
+ gpointer user_data,
+ GDestroyNotify destroy_data);
G_END_DECLS
Modified: trunk/libegg/toolpalette/testtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/testtoolpalette.c (original)
+++ trunk/libegg/toolpalette/testtoolpalette.c Mon Jan 14 08:40:51 2008
@@ -110,6 +110,13 @@
}
}
+static gboolean
+drop_invalid_icon_size (GEnumValue *enum_value,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ return (enum_value->value != GTK_ICON_SIZE_INVALID);
+}
+
static GtkWidget*
create_ui (void)
{
@@ -185,6 +192,7 @@
gtk_action_group_add_actions (group, actions, G_N_ELEMENTS (actions), window);
action = egg_enum_action_new ("ViewIconSize", _("Icon Size"), NULL, GTK_TYPE_ICON_SIZE);
+ egg_enum_action_set_filter (EGG_ENUM_ACTION (action), drop_invalid_icon_size, NULL, NULL);
egg_enum_action_bind (EGG_ENUM_ACTION (action), G_OBJECT (palette), "icon-size");
gtk_action_group_add_action (group, action);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]