diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-12-30 20:19:58 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-12-30 20:19:58 +0900 |
commit | bc939d5ff620e650ad4ff19b7b8387b44478d36e (patch) | |
tree | 23812a0e3385f86d208277e676e209ed280a4b01 /plugins/gtk+ | |
parent | 7608035b9a6b312b6f7de084427ac9ddea18f09e (diff) | |
download | glade-bc939d5ff620e650ad4ff19b7b8387b44478d36e.tar.gz |
* ALL SOURCE FILES: Removed 8-space indentation, reformatted all code with:
indent \
--braces-after-if-line \
--case-brace-indentation0 \
--case-indentation2 \
--braces-after-struct-decl-line \
--line-length80 --no-tabs \
--dont-line-up-parentheses \
--continuation-indentation4 \
--continue-at-parentheses \
--honour-newlines --tab-size8 --indent-level2 -nbbo
Diffstat (limited to 'plugins/gtk+')
36 files changed, 17425 insertions, 16987 deletions
diff --git a/plugins/gtk+/glade-accels.c b/plugins/gtk+/glade-accels.c index 3b529628..bd32252a 100644 --- a/plugins/gtk+/glade-accels.c +++ b/plugins/gtk+/glade-accels.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom * @@ -32,81 +31,81 @@ #define GLADE_RESPONSE_CLEAR 42 GList * -glade_accel_list_copy (GList *accels) +glade_accel_list_copy (GList * accels) { - GList *ret = NULL, *list; - GladeAccelInfo *info, *dup_info; + GList *ret = NULL, *list; + GladeAccelInfo *info, *dup_info; - for (list = accels; list; list = list->next) - { - info = list->data; + for (list = accels; list; list = list->next) + { + info = list->data; - dup_info = g_new0 (GladeAccelInfo, 1); - dup_info->signal = g_strdup (info->signal); - dup_info->key = info->key; - dup_info->modifiers = info->modifiers; + dup_info = g_new0 (GladeAccelInfo, 1); + dup_info->signal = g_strdup (info->signal); + dup_info->key = info->key; + dup_info->modifiers = info->modifiers; - ret = g_list_prepend (ret, dup_info); - } + ret = g_list_prepend (ret, dup_info); + } - return g_list_reverse (ret); + return g_list_reverse (ret); } void -glade_accel_list_free (GList *accels) +glade_accel_list_free (GList * accels) { - GList *list; - GladeAccelInfo *info; + GList *list; + GladeAccelInfo *info; - for (list = accels; list; list = list->next) - { - info = list->data; + for (list = accels; list; list = list->next) + { + info = list->data; - g_free (info->signal); - g_free (info); - } - g_list_free (accels); + g_free (info->signal); + g_free (info); + } + g_list_free (accels); } GType glade_accel_glist_get_type (void) { - static GType type_id = 0; - - if (!type_id) - type_id = g_boxed_type_register_static - ("GladeAccelGList", - (GBoxedCopyFunc) glade_accel_list_copy, - (GBoxedFreeFunc) glade_accel_list_free); - return type_id; + static GType type_id = 0; + + if (!type_id) + type_id = g_boxed_type_register_static + ("GladeAccelGList", + (GBoxedCopyFunc) glade_accel_list_copy, + (GBoxedFreeFunc) glade_accel_list_free); + return type_id; } /* This is not used to save in the glade file... and its a one-way conversion. * its only usefull to show the values in the UI. */ gchar * -glade_accels_make_string (GList *accels) +glade_accels_make_string (GList * accels) { - GladeAccelInfo *info; - GString *string; - GList *list; - gchar *accel_text; + GladeAccelInfo *info; + GString *string; + GList *list; + gchar *accel_text; - string = g_string_new (""); + string = g_string_new (""); - for (list = accels; list; list = list->next) - { - info = list->data; + for (list = accels; list; list = list->next) + { + info = list->data; - accel_text = gtk_accelerator_name (info->key, info->modifiers); - g_string_append (string, accel_text); - g_free (accel_text); + accel_text = gtk_accelerator_name (info->key, info->modifiers); + g_string_append (string, accel_text); + g_free (accel_text); - if (list->next) - g_string_append (string, ", "); - } + if (list->next) + g_string_append (string, ", "); + } - return g_string_free (string, FALSE); + return g_string_free (string, FALSE); } @@ -114,31 +113,34 @@ glade_accels_make_string (GList *accels) * GladeEditorProperty stuff here **************************************************************/ -enum { - ACCEL_COLUMN_SIGNAL = 0, - ACCEL_COLUMN_REAL_SIGNAL, - ACCEL_COLUMN_TEXT, - ACCEL_COLUMN_WEIGHT, - ACCEL_COLUMN_STYLE, - ACCEL_COLUMN_FOREGROUND, - ACCEL_COLUMN_VISIBLE, - ACCEL_COLUMN_KEY_ENTERED, - ACCEL_COLUMN_KEYCODE, - ACCEL_COLUMN_MODIFIERS, - ACCEL_NUM_COLUMNS +enum +{ + ACCEL_COLUMN_SIGNAL = 0, + ACCEL_COLUMN_REAL_SIGNAL, + ACCEL_COLUMN_TEXT, + ACCEL_COLUMN_WEIGHT, + ACCEL_COLUMN_STYLE, + ACCEL_COLUMN_FOREGROUND, + ACCEL_COLUMN_VISIBLE, + ACCEL_COLUMN_KEY_ENTERED, + ACCEL_COLUMN_KEYCODE, + ACCEL_COLUMN_MODIFIERS, + ACCEL_NUM_COLUMNS }; -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *entry; - GList *parent_iters; - GtkTreeModel *model; +typedef struct +{ + GladeEditorProperty parent_instance; + + GtkWidget *entry; + GList *parent_iters; + GtkTreeModel *model; } GladeEPropAccel; -typedef struct { - GtkTreeIter *iter; - gchar *name; /* <-- dont free */ +typedef struct +{ + GtkTreeIter *iter; + gchar *name; /* <-- dont free */ } GladeEpropIterTab; GLADE_MAKE_EPROP (GladeEPropAccel, glade_eprop_accel) @@ -147,703 +149,716 @@ GLADE_MAKE_EPROP (GladeEPropAccel, glade_eprop_accel) #define GLADE_IS_EPROP_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ACCEL)) #define GLADE_IS_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ACCEL)) #define GLADE_EPROP_ACCEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ACCEL, GladeEPropAccelClass)) - -static void -glade_eprop_accel_finalize (GObject *object) + static void glade_eprop_accel_finalize (GObject * object) { - /* Chain up */ - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); + /* Chain up */ + GObjectClass *parent_class = + g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -glade_eprop_accel_load (GladeEditorProperty *eprop, - GladeProperty *property) +glade_eprop_accel_load (GladeEditorProperty * eprop, GladeProperty * property) { - GladeEditorPropertyClass *parent_class = - g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - gchar *accels; - - /* Chain up first */ - parent_class->load (eprop, property); - - if (property == NULL) return; - - if ((accels = - glade_accels_make_string (g_value_get_boxed (property->value))) != NULL) - { - gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), accels); - g_free (accels); - } - else - gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), ""); + GladeEditorPropertyClass *parent_class = + g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); + GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); + gchar *accels; + + /* Chain up first */ + parent_class->load (eprop, property); + + if (property == NULL) + return; + + if ((accels = + glade_accels_make_string (g_value_get_boxed (property->value))) != NULL) + { + gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), accels); + g_free (accels); + } + else + gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), ""); } static gint -eprop_find_iter (GladeEpropIterTab *iter_tab, - gchar *name) +eprop_find_iter (GladeEpropIterTab * iter_tab, gchar * name) { - return strcmp (iter_tab->name, name); + return strcmp (iter_tab->name, name); } static void -iter_tab_free (GladeEpropIterTab *iter_tab) +iter_tab_free (GladeEpropIterTab * iter_tab) { - gtk_tree_iter_free (iter_tab->iter); - g_free (iter_tab); + gtk_tree_iter_free (iter_tab->iter); + g_free (iter_tab); } static void -glade_eprop_accel_populate_view (GladeEditorProperty *eprop, - GtkTreeView *view) +glade_eprop_accel_populate_view (GladeEditorProperty * eprop, + GtkTreeView * view) { - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GladeSignalClass *sclass; - GladeWidgetAdaptor *adaptor = glade_widget_adaptor_from_pclass (eprop->klass); - GtkTreeStore *model = (GtkTreeStore *)gtk_tree_view_get_model (view); - GtkTreeIter iter; - GladeEpropIterTab *parent_tab; - GladeAccelInfo *info; - GList *list, *l, *found, *accelerators; - gchar *name, *accel_text; - - accelerators = g_value_get_boxed (eprop->property->value); - - /* First make parent iters... - */ - for (list = adaptor->signals; list; list = list->next) - { - sclass = list->data; - - /* Special case for GtkAction accelerators */ - if (adaptor->type == GTK_TYPE_ACTION || - g_type_is_a (adaptor->type, GTK_TYPE_ACTION)) - { - if (g_strcmp0 (sclass->type, "GtkAction") != 0 || - g_strcmp0 (sclass->name, "activate") != 0) - continue; - } - /* Only action signals have accelerators. */ - else if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0) - continue; - - if (g_list_find_custom (eprop_accel->parent_iters, - sclass->type, - (GCompareFunc)eprop_find_iter) == NULL) - { - gtk_tree_store_append (model, &iter, NULL); - gtk_tree_store_set (model, &iter, - ACCEL_COLUMN_SIGNAL, sclass->type, - ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_BOLD, - ACCEL_COLUMN_VISIBLE, FALSE, - -1); - - parent_tab = g_new0 (GladeEpropIterTab, 1); - parent_tab->name = sclass->type; - parent_tab->iter = gtk_tree_iter_copy (&iter); - - eprop_accel->parent_iters = - g_list_prepend (eprop_accel->parent_iters, - parent_tab); - } - } - - /* Now we populate... - */ - for (list = adaptor->signals; list; list = list->next) - { - sclass = list->data; - - /* Special case for GtkAction accelerators */ - if (adaptor->type == GTK_TYPE_ACTION || - g_type_is_a (adaptor->type, GTK_TYPE_ACTION)) - { - if (g_strcmp0 (sclass->type, "GtkAction") != 0 || - g_strcmp0 (sclass->name, "activate") != 0) - continue; - } - /* Only action signals have accelerators. */ - else if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0) - continue; - - if ((found = g_list_find_custom (eprop_accel->parent_iters, - sclass->type, - (GCompareFunc)eprop_find_iter)) != NULL) - { - parent_tab = found->data; - name = g_strdup_printf (" %s", sclass->name); - - /* Populate from accelerator list - */ - for (l = accelerators; l; l = l->next) - { - info = l->data; - - if (strcmp (info->signal, sclass->name)) - continue; - - accel_text = gtk_accelerator_name (info->key, info->modifiers); - - gtk_tree_store_append (model, &iter, parent_tab->iter); - gtk_tree_store_set - (model, &iter, - ACCEL_COLUMN_SIGNAL, name, - ACCEL_COLUMN_REAL_SIGNAL, sclass->name, - ACCEL_COLUMN_TEXT, accel_text, - ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, - ACCEL_COLUMN_STYLE, PANGO_STYLE_NORMAL, - ACCEL_COLUMN_FOREGROUND, "Black", - ACCEL_COLUMN_VISIBLE, TRUE, - ACCEL_COLUMN_KEYCODE, info->key, - ACCEL_COLUMN_MODIFIERS, info->modifiers, - ACCEL_COLUMN_KEY_ENTERED, TRUE, - -1); - - g_free (accel_text); - } - - /* Special case for GtkAction accelerators */ - if ((adaptor->type == GTK_TYPE_ACTION || - g_type_is_a (adaptor->type, GTK_TYPE_ACTION)) && - g_list_length (accelerators) > 0) - continue; - - /* Append a new empty slot at the end */ - gtk_tree_store_append (model, &iter, parent_tab->iter); - gtk_tree_store_set - (model, &iter, - ACCEL_COLUMN_SIGNAL, name, - ACCEL_COLUMN_REAL_SIGNAL, sclass->name, - ACCEL_COLUMN_TEXT, _("<choose a key>"), - ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, - ACCEL_COLUMN_STYLE, PANGO_STYLE_ITALIC, - ACCEL_COLUMN_FOREGROUND, "Grey", - ACCEL_COLUMN_VISIBLE, TRUE, - ACCEL_COLUMN_KEYCODE, 0, - ACCEL_COLUMN_MODIFIERS, 0, - ACCEL_COLUMN_KEY_ENTERED, FALSE, - -1); - - g_free (name); - } - } + GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); + GladeSignalClass *sclass; + GladeWidgetAdaptor *adaptor = glade_widget_adaptor_from_pclass (eprop->klass); + GtkTreeStore *model = (GtkTreeStore *) gtk_tree_view_get_model (view); + GtkTreeIter iter; + GladeEpropIterTab *parent_tab; + GladeAccelInfo *info; + GList *list, *l, *found, *accelerators; + gchar *name, *accel_text; + + accelerators = g_value_get_boxed (eprop->property->value); + + /* First make parent iters... + */ + for (list = adaptor->signals; list; list = list->next) + { + sclass = list->data; + + /* Special case for GtkAction accelerators */ + if (adaptor->type == GTK_TYPE_ACTION || + g_type_is_a (adaptor->type, GTK_TYPE_ACTION)) + { + if (g_strcmp0 (sclass->type, "GtkAction") != 0 || + g_strcmp0 (sclass->name, "activate") != 0) + continue; + } + /* Only action signals have accelerators. */ + else if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0) + continue; + + if (g_list_find_custom (eprop_accel->parent_iters, + sclass->type, + (GCompareFunc) eprop_find_iter) == NULL) + { + gtk_tree_store_append (model, &iter, NULL); + gtk_tree_store_set (model, &iter, + ACCEL_COLUMN_SIGNAL, sclass->type, + ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_BOLD, + ACCEL_COLUMN_VISIBLE, FALSE, -1); + + parent_tab = g_new0 (GladeEpropIterTab, 1); + parent_tab->name = sclass->type; + parent_tab->iter = gtk_tree_iter_copy (&iter); + + eprop_accel->parent_iters = + g_list_prepend (eprop_accel->parent_iters, parent_tab); + } + } + + /* Now we populate... + */ + for (list = adaptor->signals; list; list = list->next) + { + sclass = list->data; + + /* Special case for GtkAction accelerators */ + if (adaptor->type == GTK_TYPE_ACTION || + g_type_is_a (adaptor->type, GTK_TYPE_ACTION)) + { + if (g_strcmp0 (sclass->type, "GtkAction") != 0 || + g_strcmp0 (sclass->name, "activate") != 0) + continue; + } + /* Only action signals have accelerators. */ + else if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0) + continue; + + if ((found = g_list_find_custom (eprop_accel->parent_iters, + sclass->type, + (GCompareFunc) eprop_find_iter)) != NULL) + { + parent_tab = found->data; + name = g_strdup_printf (" %s", sclass->name); + + /* Populate from accelerator list + */ + for (l = accelerators; l; l = l->next) + { + info = l->data; + + if (strcmp (info->signal, sclass->name)) + continue; + + accel_text = gtk_accelerator_name (info->key, info->modifiers); + + gtk_tree_store_append (model, &iter, parent_tab->iter); + gtk_tree_store_set + (model, &iter, + ACCEL_COLUMN_SIGNAL, name, + ACCEL_COLUMN_REAL_SIGNAL, sclass->name, + ACCEL_COLUMN_TEXT, accel_text, + ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, + ACCEL_COLUMN_STYLE, PANGO_STYLE_NORMAL, + ACCEL_COLUMN_FOREGROUND, "Black", + ACCEL_COLUMN_VISIBLE, TRUE, + ACCEL_COLUMN_KEYCODE, info->key, + ACCEL_COLUMN_MODIFIERS, info->modifiers, + ACCEL_COLUMN_KEY_ENTERED, TRUE, -1); + + g_free (accel_text); + } + + /* Special case for GtkAction accelerators */ + if ((adaptor->type == GTK_TYPE_ACTION || + g_type_is_a (adaptor->type, GTK_TYPE_ACTION)) && + g_list_length (accelerators) > 0) + continue; + + /* Append a new empty slot at the end */ + gtk_tree_store_append (model, &iter, parent_tab->iter); + gtk_tree_store_set + (model, &iter, + ACCEL_COLUMN_SIGNAL, name, + ACCEL_COLUMN_REAL_SIGNAL, sclass->name, + ACCEL_COLUMN_TEXT, _("<choose a key>"), + ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, + ACCEL_COLUMN_STYLE, PANGO_STYLE_ITALIC, + ACCEL_COLUMN_FOREGROUND, "Grey", + ACCEL_COLUMN_VISIBLE, TRUE, + ACCEL_COLUMN_KEYCODE, 0, + ACCEL_COLUMN_MODIFIERS, 0, ACCEL_COLUMN_KEY_ENTERED, FALSE, -1); + + g_free (name); + } + } } void -accel_edited (GtkCellRendererAccel *accel, - gchar *path_string, - guint accel_key, - GdkModifierType accel_mods, - guint hardware_keycode, - GladeEPropAccel *eprop_accel) +accel_edited (GtkCellRendererAccel * accel, + gchar * path_string, + guint accel_key, + GdkModifierType accel_mods, + guint hardware_keycode, GladeEPropAccel * eprop_accel) { - gboolean key_was_set; - GtkTreeIter iter, parent_iter, new_iter; - gchar *accel_text; - GladeWidgetAdaptor *adaptor = - glade_widget_adaptor_from_pclass (GLADE_EDITOR_PROPERTY (eprop_accel)->klass); - gboolean is_action; - - if (!gtk_tree_model_get_iter_from_string (eprop_accel->model, - &iter, path_string)) - return; - - is_action = (adaptor->type == GTK_TYPE_ACTION || - g_type_is_a (adaptor->type, GTK_TYPE_ACTION)); - - gtk_tree_model_get (eprop_accel->model, &iter, - ACCEL_COLUMN_KEY_ENTERED, &key_was_set, - -1); - - accel_text = gtk_accelerator_name (accel_key, accel_mods); - - gtk_tree_store_set - (GTK_TREE_STORE (eprop_accel->model), &iter, - ACCEL_COLUMN_KEY_ENTERED, TRUE, - ACCEL_COLUMN_STYLE, PANGO_STYLE_NORMAL, - ACCEL_COLUMN_FOREGROUND, "Black", - ACCEL_COLUMN_TEXT, accel_text, - ACCEL_COLUMN_KEYCODE, accel_key, - ACCEL_COLUMN_MODIFIERS, accel_mods, - -1); - - g_free (accel_text); - - /* Append a new one if needed - */ - if (is_action == FALSE && key_was_set == FALSE && - gtk_tree_model_iter_parent (eprop_accel->model, - &parent_iter, &iter)) - { - gchar *signal, *real_signal; - - gtk_tree_model_get (eprop_accel->model, &iter, - ACCEL_COLUMN_SIGNAL, &signal, - ACCEL_COLUMN_REAL_SIGNAL, &real_signal, - -1); - - /* Append a new empty slot at the end */ - gtk_tree_store_insert_after (GTK_TREE_STORE (eprop_accel->model), - &new_iter, &parent_iter, &iter); - gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &new_iter, - ACCEL_COLUMN_SIGNAL, signal, - ACCEL_COLUMN_REAL_SIGNAL, real_signal, - ACCEL_COLUMN_TEXT, _("<choose a key>"), - ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, - ACCEL_COLUMN_STYLE, PANGO_STYLE_ITALIC, - ACCEL_COLUMN_FOREGROUND, "Grey", - ACCEL_COLUMN_VISIBLE, TRUE, - ACCEL_COLUMN_KEYCODE, 0, - ACCEL_COLUMN_MODIFIERS, 0, - ACCEL_COLUMN_KEY_ENTERED, FALSE, - -1); - g_free (signal); - g_free (real_signal); - } + gboolean key_was_set; + GtkTreeIter iter, parent_iter, new_iter; + gchar *accel_text; + GladeWidgetAdaptor *adaptor = + glade_widget_adaptor_from_pclass (GLADE_EDITOR_PROPERTY (eprop_accel)-> + klass); + gboolean is_action; + + if (!gtk_tree_model_get_iter_from_string (eprop_accel->model, + &iter, path_string)) + return; + + is_action = (adaptor->type == GTK_TYPE_ACTION || + g_type_is_a (adaptor->type, GTK_TYPE_ACTION)); + + gtk_tree_model_get (eprop_accel->model, &iter, + ACCEL_COLUMN_KEY_ENTERED, &key_was_set, -1); + + accel_text = gtk_accelerator_name (accel_key, accel_mods); + + gtk_tree_store_set + (GTK_TREE_STORE (eprop_accel->model), &iter, + ACCEL_COLUMN_KEY_ENTERED, TRUE, + ACCEL_COLUMN_STYLE, PANGO_STYLE_NORMAL, + ACCEL_COLUMN_FOREGROUND, "Black", + ACCEL_COLUMN_TEXT, accel_text, + ACCEL_COLUMN_KEYCODE, accel_key, ACCEL_COLUMN_MODIFIERS, accel_mods, -1); + + g_free (accel_text); + + /* Append a new one if needed + */ + if (is_action == FALSE && key_was_set == FALSE && + gtk_tree_model_iter_parent (eprop_accel->model, &parent_iter, &iter)) + { + gchar *signal, *real_signal; + + gtk_tree_model_get (eprop_accel->model, &iter, + ACCEL_COLUMN_SIGNAL, &signal, + ACCEL_COLUMN_REAL_SIGNAL, &real_signal, -1); + + /* Append a new empty slot at the end */ + gtk_tree_store_insert_after (GTK_TREE_STORE (eprop_accel->model), + &new_iter, &parent_iter, &iter); + gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &new_iter, + ACCEL_COLUMN_SIGNAL, signal, + ACCEL_COLUMN_REAL_SIGNAL, real_signal, + ACCEL_COLUMN_TEXT, _("<choose a key>"), + ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL, + ACCEL_COLUMN_STYLE, PANGO_STYLE_ITALIC, + ACCEL_COLUMN_FOREGROUND, "Grey", + ACCEL_COLUMN_VISIBLE, TRUE, + ACCEL_COLUMN_KEYCODE, 0, + ACCEL_COLUMN_MODIFIERS, 0, + ACCEL_COLUMN_KEY_ENTERED, FALSE, -1); + g_free (signal); + g_free (real_signal); + } } void -accel_cleared (GtkCellRendererAccel *accel, - gchar *path_string, - GladeEPropAccel *eprop_accel) +accel_cleared (GtkCellRendererAccel * accel, + gchar * path_string, GladeEPropAccel * eprop_accel) { - GtkTreeIter iter; + GtkTreeIter iter; + + if (!gtk_tree_model_get_iter_from_string (eprop_accel->model, + &iter, path_string)) + return; - if (!gtk_tree_model_get_iter_from_string (eprop_accel->model, - &iter, path_string)) - return; - - gtk_tree_store_remove (GTK_TREE_STORE (eprop_accel->model), &iter); + gtk_tree_store_remove (GTK_TREE_STORE (eprop_accel->model), &iter); } static GtkWidget * -glade_eprop_accel_view (GladeEditorProperty *eprop) +glade_eprop_accel_view (GladeEditorProperty * eprop) { - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GtkWidget *view_widget; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - eprop_accel->model = (GtkTreeModel *)gtk_tree_store_new - (ACCEL_NUM_COLUMNS, - G_TYPE_STRING, /* The GSignal name formatted for display */ - G_TYPE_STRING, /* The GSignal name */ - G_TYPE_STRING, /* The text to show in the accelerator cell */ - G_TYPE_INT, /* PangoWeight attribute for bold headers */ - G_TYPE_INT, /* PangoStyle attribute for italic grey unset items */ - G_TYPE_STRING, /* Foreground colour for italic grey unset items */ - G_TYPE_BOOLEAN, /* Visible attribute to hide items for header entries */ - G_TYPE_BOOLEAN, /* Whether the key has been entered for this row */ - G_TYPE_UINT, /* Hardware keycode */ - G_TYPE_INT); /* GdkModifierType */ - - view_widget = gtk_tree_view_new_with_model (eprop_accel->model); - gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view_widget), FALSE); - gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view_widget), FALSE); - - /********************* signal name column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "editable", FALSE, NULL); - - column = gtk_tree_view_column_new_with_attributes - (_("Signal"), renderer, - "text", ACCEL_COLUMN_SIGNAL, - "weight", ACCEL_COLUMN_WEIGHT, - NULL); - - - gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - /********************* accel editor column *********************/ - renderer = gtk_cell_renderer_accel_new (); - g_object_set (G_OBJECT (renderer), - "editable", TRUE, - NULL); - - g_signal_connect (renderer, "accel-edited", - G_CALLBACK (accel_edited), eprop); - g_signal_connect (renderer, "accel-cleared", - G_CALLBACK (accel_cleared), eprop); - - column = gtk_tree_view_column_new_with_attributes - (_("Accelerator Key"), renderer, - "text", ACCEL_COLUMN_TEXT, - "foreground", ACCEL_COLUMN_FOREGROUND, - "style", ACCEL_COLUMN_STYLE, - "visible", ACCEL_COLUMN_VISIBLE, - NULL); - - gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - return view_widget; + GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); + GtkWidget *view_widget; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + eprop_accel->model = (GtkTreeModel *) gtk_tree_store_new (ACCEL_NUM_COLUMNS, G_TYPE_STRING, /* The GSignal name formatted for display */ + G_TYPE_STRING, /* The GSignal name */ + G_TYPE_STRING, /* The text to show in the accelerator cell */ + G_TYPE_INT, /* PangoWeight attribute for bold headers */ + G_TYPE_INT, /* PangoStyle attribute for italic grey unset items */ + G_TYPE_STRING, /* Foreground colour for italic grey unset items */ + G_TYPE_BOOLEAN, /* Visible attribute to hide items for header entries */ + G_TYPE_BOOLEAN, /* Whether the key has been entered for this row */ + G_TYPE_UINT, /* Hardware keycode */ + G_TYPE_INT); /* GdkModifierType */ + + view_widget = gtk_tree_view_new_with_model (eprop_accel->model); + gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view_widget), FALSE); + gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view_widget), FALSE); + + /********************* signal name column *********************/ + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); + + column = gtk_tree_view_column_new_with_attributes + (_("Signal"), renderer, + "text", ACCEL_COLUMN_SIGNAL, "weight", ACCEL_COLUMN_WEIGHT, NULL); + + + gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); + + /********************* accel editor column *********************/ + renderer = gtk_cell_renderer_accel_new (); + g_object_set (G_OBJECT (renderer), "editable", TRUE, NULL); + + g_signal_connect (renderer, "accel-edited", G_CALLBACK (accel_edited), eprop); + g_signal_connect (renderer, "accel-cleared", + G_CALLBACK (accel_cleared), eprop); + + column = gtk_tree_view_column_new_with_attributes + (_("Accelerator Key"), renderer, + "text", ACCEL_COLUMN_TEXT, + "foreground", ACCEL_COLUMN_FOREGROUND, + "style", ACCEL_COLUMN_STYLE, "visible", ACCEL_COLUMN_VISIBLE, NULL); + + gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); + + return view_widget; } static gboolean -glade_eprop_accel_accum_accelerators (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - GList **ret) +glade_eprop_accel_accum_accelerators (GtkTreeModel * model, + GtkTreePath * path, + GtkTreeIter * iter, GList ** ret) { - GladeAccelInfo *info; - gchar *signal; - GdkModifierType accel_mods; - guint accel_key; - gboolean entered = FALSE; - - gtk_tree_model_get (model, iter, ACCEL_COLUMN_KEY_ENTERED, &entered, -1); - if (!entered) return FALSE; - - gtk_tree_model_get (model, iter, - ACCEL_COLUMN_REAL_SIGNAL, &signal, - ACCEL_COLUMN_KEYCODE, &accel_key, - ACCEL_COLUMN_MODIFIERS, &accel_mods, - -1); - - info = g_new0 (GladeAccelInfo, 1); - info->signal = signal; - info->key = accel_key; - info->modifiers = accel_mods; - - *ret = g_list_prepend (*ret, info); - - return FALSE; + GladeAccelInfo *info; + gchar *signal; + GdkModifierType accel_mods; + guint accel_key; + gboolean entered = FALSE; + + gtk_tree_model_get (model, iter, ACCEL_COLUMN_KEY_ENTERED, &entered, -1); + if (!entered) + return FALSE; + + gtk_tree_model_get (model, iter, + ACCEL_COLUMN_REAL_SIGNAL, &signal, + ACCEL_COLUMN_KEYCODE, &accel_key, + ACCEL_COLUMN_MODIFIERS, &accel_mods, -1); + + info = g_new0 (GladeAccelInfo, 1); + info->signal = signal; + info->key = accel_key; + info->modifiers = accel_mods; + + *ret = g_list_prepend (*ret, info); + + return FALSE; } static void -glade_eprop_accel_show_dialog (GtkWidget *dialog_button, - GladeEditorProperty *eprop) +glade_eprop_accel_show_dialog (GtkWidget * dialog_button, + GladeEditorProperty * eprop) { - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GtkWidget *dialog, *parent, *vbox, *sw, *tree_view; - GladeProject *project; - GValue value = { 0, }; - GList *accelerators = NULL; - gint res; - - project = glade_widget_get_project (eprop->property->widget); - parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop)); - - dialog = gtk_dialog_new_with_buttons (_("Choose accelerator keys..."), - GTK_WINDOW (parent), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - - gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - vbox, TRUE, TRUE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 200); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - tree_view = glade_eprop_accel_view (eprop); - glade_eprop_accel_populate_view (eprop, GTK_TREE_VIEW (tree_view)); - - gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); - - gtk_widget_show (tree_view); - gtk_container_add (GTK_CONTAINER (sw), tree_view); - - /* Run the dialog */ - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) - { - gtk_tree_model_foreach - (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)), - (GtkTreeModelForeachFunc) - glade_eprop_accel_accum_accelerators, &accelerators); - - g_value_init (&value, GLADE_TYPE_ACCEL_GLIST); - g_value_take_boxed (&value, accelerators); - - glade_editor_property_commit (eprop, &value); - g_value_unset (&value); - } - else if (res == GLADE_RESPONSE_CLEAR) - { - g_value_init (&value, GLADE_TYPE_ACCEL_GLIST); - g_value_set_boxed (&value, NULL); - - glade_editor_property_commit (eprop, &value); - - g_value_unset (&value); - } - - /* Clean up ... - */ - gtk_widget_destroy (dialog); - - g_object_unref (G_OBJECT (eprop_accel->model)); - eprop_accel->model = NULL; - - if (eprop_accel->parent_iters) - { - g_list_foreach (eprop_accel->parent_iters, (GFunc)iter_tab_free, NULL); - g_list_free (eprop_accel->parent_iters); - eprop_accel->parent_iters = NULL; - } + GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); + GtkWidget *dialog, *parent, *vbox, *sw, *tree_view; + GladeProject *project; + GValue value = { 0, }; + GList *accelerators = NULL; + gint res; + + project = glade_widget_get_project (eprop->property->widget); + parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop)); + + dialog = gtk_dialog_new_with_buttons (_("Choose accelerator keys..."), + GTK_WINDOW (parent), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + + vbox = gtk_vbox_new (FALSE, 6); + gtk_widget_show (vbox); + + gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); + + gtk_box_pack_start (GTK_BOX + (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox, + TRUE, TRUE, 0); + + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (sw); + gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); + gtk_widget_set_size_request (sw, 400, 200); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); + + tree_view = glade_eprop_accel_view (eprop); + glade_eprop_accel_populate_view (eprop, GTK_TREE_VIEW (tree_view)); + + gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); + + gtk_widget_show (tree_view); + gtk_container_add (GTK_CONTAINER (sw), tree_view); + + /* Run the dialog */ + res = gtk_dialog_run (GTK_DIALOG (dialog)); + if (res == GTK_RESPONSE_OK) + { + gtk_tree_model_foreach + (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)), + (GtkTreeModelForeachFunc) + glade_eprop_accel_accum_accelerators, &accelerators); + + g_value_init (&value, GLADE_TYPE_ACCEL_GLIST); + g_value_take_boxed (&value, accelerators); + + glade_editor_property_commit (eprop, &value); + g_value_unset (&value); + } + else if (res == GLADE_RESPONSE_CLEAR) + { + g_value_init (&value, GLADE_TYPE_ACCEL_GLIST); + g_value_set_boxed (&value, NULL); + + glade_editor_property_commit (eprop, &value); + + g_value_unset (&value); + } + + /* Clean up ... + */ + gtk_widget_destroy (dialog); + + g_object_unref (G_OBJECT (eprop_accel->model)); + eprop_accel->model = NULL; + + if (eprop_accel->parent_iters) + { + g_list_foreach (eprop_accel->parent_iters, (GFunc) iter_tab_free, NULL); + g_list_free (eprop_accel->parent_iters); + eprop_accel->parent_iters = NULL; + } } static GtkWidget * -glade_eprop_accel_create_input (GladeEditorProperty *eprop) +glade_eprop_accel_create_input (GladeEditorProperty * eprop) { - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GtkWidget *hbox; - GtkWidget *button; + GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); + GtkWidget *hbox; + GtkWidget *button; - hbox = gtk_hbox_new (FALSE, 0); - eprop_accel->entry = gtk_entry_new (); - gtk_editable_set_editable (GTK_EDITABLE (eprop_accel->entry), FALSE); - gtk_widget_show (eprop_accel->entry); - gtk_box_pack_start (GTK_BOX (hbox), eprop_accel->entry, TRUE, TRUE, 0); + hbox = gtk_hbox_new (FALSE, 0); + eprop_accel->entry = gtk_entry_new (); + gtk_editable_set_editable (GTK_EDITABLE (eprop_accel->entry), FALSE); + gtk_widget_show (eprop_accel->entry); + gtk_box_pack_start (GTK_BOX (hbox), eprop_accel->entry, TRUE, TRUE, 0); - button = gtk_button_new_with_label ("..."); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_label ("..."); + gtk_widget_show (button); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_accel_show_dialog), - eprop); + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (glade_eprop_accel_show_dialog), eprop); - return hbox; + return hbox; } static GdkModifierType -glade_gtk_parse_modifiers (const gchar *string) +glade_gtk_parse_modifiers (const gchar * string) { - const gchar *pos = string; - GdkModifierType modifiers = 0; - - while (pos && pos[0]) - { - if (!strncmp(pos, "GDK_", 4)) { - pos += 4; - if (!strncmp(pos, "SHIFT_MASK", 10)) { - modifiers |= GDK_SHIFT_MASK; - pos += 10; - } else if (!strncmp(pos, "LOCK_MASK", 9)) { - modifiers |= GDK_LOCK_MASK; - pos += 9; - } else if (!strncmp(pos, "CONTROL_MASK", 12)) { - modifiers |= GDK_CONTROL_MASK; - pos += 12; - } else if (!strncmp(pos, "MOD", 3) && - !strncmp(pos+4, "_MASK", 5)) { - switch (pos[3]) { - case '1': - modifiers |= GDK_MOD1_MASK; break; - case '2': - modifiers |= GDK_MOD2_MASK; break; - case '3': - modifiers |= GDK_MOD3_MASK; break; - case '4': - modifiers |= GDK_MOD4_MASK; break; - case '5': - modifiers |= GDK_MOD5_MASK; break; - } - pos += 9; - } else if (!strncmp(pos, "BUTTON", 6) && - !strncmp(pos+7, "_MASK", 5)) { - switch (pos[6]) { - case '1': - modifiers |= GDK_BUTTON1_MASK; break; - case '2': - modifiers |= GDK_BUTTON2_MASK; break; - case '3': - modifiers |= GDK_BUTTON3_MASK; break; - case '4': - modifiers |= GDK_BUTTON4_MASK; break; - case '5': - modifiers |= GDK_BUTTON5_MASK; break; - } - pos += 12; - } else if (!strncmp(pos, "RELEASE_MASK", 12)) { - modifiers |= GDK_RELEASE_MASK; - pos += 12; - } else - pos++; - } else - pos++; - } - return modifiers; + const gchar *pos = string; + GdkModifierType modifiers = 0; + + while (pos && pos[0]) + { + if (!strncmp (pos, "GDK_", 4)) + { + pos += 4; + if (!strncmp (pos, "SHIFT_MASK", 10)) + { + modifiers |= GDK_SHIFT_MASK; + pos += 10; + } + else if (!strncmp (pos, "LOCK_MASK", 9)) + { + modifiers |= GDK_LOCK_MASK; + pos += 9; + } + else if (!strncmp (pos, "CONTROL_MASK", 12)) + { + modifiers |= GDK_CONTROL_MASK; + pos += 12; + } + else if (!strncmp (pos, "MOD", 3) && !strncmp (pos + 4, "_MASK", 5)) + { + switch (pos[3]) + { + case '1': + modifiers |= GDK_MOD1_MASK; + break; + case '2': + modifiers |= GDK_MOD2_MASK; + break; + case '3': + modifiers |= GDK_MOD3_MASK; + break; + case '4': + modifiers |= GDK_MOD4_MASK; + break; + case '5': + modifiers |= GDK_MOD5_MASK; + break; + } + pos += 9; + } + else if (!strncmp (pos, "BUTTON", 6) && + !strncmp (pos + 7, "_MASK", 5)) + { + switch (pos[6]) + { + case '1': + modifiers |= GDK_BUTTON1_MASK; + break; + case '2': + modifiers |= GDK_BUTTON2_MASK; + break; + case '3': + modifiers |= GDK_BUTTON3_MASK; + break; + case '4': + modifiers |= GDK_BUTTON4_MASK; + break; + case '5': + modifiers |= GDK_BUTTON5_MASK; + break; + } + pos += 12; + } + else if (!strncmp (pos, "RELEASE_MASK", 12)) + { + modifiers |= GDK_RELEASE_MASK; + pos += 12; + } + else + pos++; + } + else + pos++; + } + return modifiers; } static gchar * glade_gtk_modifier_string_from_bits (GdkModifierType modifiers) { - GString *string = g_string_new (""); + GString *string = g_string_new (""); - if (modifiers & GDK_SHIFT_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_SHIFT_MASK"); + if (modifiers & GDK_SHIFT_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_SHIFT_MASK"); } - if (modifiers & GDK_LOCK_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_LOCK_MASK"); + if (modifiers & GDK_LOCK_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_LOCK_MASK"); } - if (modifiers & GDK_CONTROL_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_CONTROL_MASK"); + if (modifiers & GDK_CONTROL_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_CONTROL_MASK"); } - if (modifiers & GDK_MOD1_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD1_MASK"); + if (modifiers & GDK_MOD1_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_MOD1_MASK"); } - if (modifiers & GDK_MOD2_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD2_MASK"); + if (modifiers & GDK_MOD2_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_MOD2_MASK"); } - if (modifiers & GDK_MOD3_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD3_MASK"); + if (modifiers & GDK_MOD3_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_MOD3_MASK"); } - if (modifiers & GDK_MOD4_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD4_MASK"); + if (modifiers & GDK_MOD4_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_MOD4_MASK"); } - if (modifiers & GDK_MOD5_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD5_MASK"); + if (modifiers & GDK_MOD5_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_MOD5_MASK"); } - if (modifiers & GDK_BUTTON1_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON1_MASK"); + if (modifiers & GDK_BUTTON1_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_BUTTON1_MASK"); } - if (modifiers & GDK_BUTTON2_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON2_MASK"); + if (modifiers & GDK_BUTTON2_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_BUTTON2_MASK"); } - if (modifiers & GDK_BUTTON3_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON3_MASK"); + if (modifiers & GDK_BUTTON3_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_BUTTON3_MASK"); } - if (modifiers & GDK_BUTTON4_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON4_MASK"); + if (modifiers & GDK_BUTTON4_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_BUTTON4_MASK"); } - if (modifiers & GDK_BUTTON5_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON5_MASK"); + if (modifiers & GDK_BUTTON5_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_BUTTON5_MASK"); } - if (modifiers & GDK_RELEASE_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_RELEASE_MASK"); + if (modifiers & GDK_RELEASE_MASK) + { + if (string->len > 0) + g_string_append (string, " | "); + g_string_append (string, "GDK_RELEASE_MASK"); } - if (string->len > 0) - return g_string_free (string, FALSE); + if (string->len > 0) + return g_string_free (string, FALSE); - g_string_free (string, TRUE); - return NULL; + g_string_free (string, TRUE); + return NULL; } GladeAccelInfo * -glade_accel_read (GladeXmlNode *node, - gboolean require_signal) +glade_accel_read (GladeXmlNode * node, gboolean require_signal) { - GladeAccelInfo *ainfo; - gchar *key, *modifiers, *signal; - - g_return_val_if_fail (node != NULL, NULL); - - if (!glade_xml_node_verify (node, GLADE_TAG_ACCEL)) - return NULL; - - /* Get from xml... */ - key = glade_xml_get_property_string_required - (node, GLADE_TAG_ACCEL_KEY, NULL); - if (require_signal) - signal = glade_xml_get_property_string_required (node, GLADE_TAG_ACCEL_SIGNAL, NULL); - else - signal = glade_xml_get_property_string (node, GLADE_TAG_ACCEL_SIGNAL); - - modifiers = glade_xml_get_property_string (node, GLADE_TAG_ACCEL_MODIFIERS); - - /* translate to GladeAccelInfo... */ - ainfo = g_new0 (GladeAccelInfo, 1); - ainfo->key = gdk_keyval_from_name(key); - ainfo->signal = signal; /* take string ownership... */ - ainfo->modifiers = glade_gtk_parse_modifiers (modifiers); - - g_free (modifiers); - - return ainfo; + GladeAccelInfo *ainfo; + gchar *key, *modifiers, *signal; + + g_return_val_if_fail (node != NULL, NULL); + + if (!glade_xml_node_verify (node, GLADE_TAG_ACCEL)) + return NULL; + + /* Get from xml... */ + key = glade_xml_get_property_string_required + (node, GLADE_TAG_ACCEL_KEY, NULL); + if (require_signal) + signal = + glade_xml_get_property_string_required (node, GLADE_TAG_ACCEL_SIGNAL, + NULL); + else + signal = glade_xml_get_property_string (node, GLADE_TAG_ACCEL_SIGNAL); + + modifiers = glade_xml_get_property_string (node, GLADE_TAG_ACCEL_MODIFIERS); + + /* translate to GladeAccelInfo... */ + ainfo = g_new0 (GladeAccelInfo, 1); + ainfo->key = gdk_keyval_from_name (key); + ainfo->signal = signal; /* take string ownership... */ + ainfo->modifiers = glade_gtk_parse_modifiers (modifiers); + + g_free (modifiers); + + return ainfo; } GladeXmlNode * -glade_accel_write (GladeAccelInfo *accel, - GladeXmlContext *context, - gboolean write_signal) +glade_accel_write (GladeAccelInfo * accel, + GladeXmlContext * context, gboolean write_signal) { - GladeXmlNode *accel_node; - gchar *modifiers; + GladeXmlNode *accel_node; + gchar *modifiers; - g_return_val_if_fail (accel != NULL, NULL); - g_return_val_if_fail (context != NULL, NULL); + g_return_val_if_fail (accel != NULL, NULL); + g_return_val_if_fail (context != NULL, NULL); - accel_node = glade_xml_node_new (context, GLADE_TAG_ACCEL); - modifiers = glade_gtk_modifier_string_from_bits (accel->modifiers); + accel_node = glade_xml_node_new (context, GLADE_TAG_ACCEL); + modifiers = glade_gtk_modifier_string_from_bits (accel->modifiers); - glade_xml_node_set_property_string (accel_node, GLADE_TAG_ACCEL_KEY, - gdk_keyval_name(accel->key)); + glade_xml_node_set_property_string (accel_node, GLADE_TAG_ACCEL_KEY, + gdk_keyval_name (accel->key)); - if (write_signal) - glade_xml_node_set_property_string (accel_node, GLADE_TAG_ACCEL_SIGNAL, - accel->signal); - glade_xml_node_set_property_string (accel_node, GLADE_TAG_ACCEL_MODIFIERS, - modifiers); + if (write_signal) + glade_xml_node_set_property_string (accel_node, GLADE_TAG_ACCEL_SIGNAL, + accel->signal); + glade_xml_node_set_property_string (accel_node, GLADE_TAG_ACCEL_MODIFIERS, + modifiers); - g_free (modifiers); + g_free (modifiers); - return accel_node; + return accel_node; } - diff --git a/plugins/gtk+/glade-accels.h b/plugins/gtk+/glade-accels.h index 2ff33f65..adcb35a7 100644 --- a/plugins/gtk+/glade-accels.h +++ b/plugins/gtk+/glade-accels.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ #ifndef __GLADE_ACCELS_H__ #define __GLADE_ACCELS_H__ diff --git a/plugins/gtk+/glade-activatable-editor.c b/plugins/gtk+/glade-activatable-editor.c index 2bbd09e0..49faf8e6 100644 --- a/plugins/gtk+/glade-activatable-editor.c +++ b/plugins/gtk+/glade-activatable-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,405 +27,423 @@ #include "glade-activatable-editor.h" -static void glade_activatable_editor_finalize (GObject *object); +static void glade_activatable_editor_finalize (GObject * object); -static void glade_activatable_editor_editable_init (GladeEditableIface *iface); +static void glade_activatable_editor_editable_init (GladeEditableIface * iface); -static void glade_activatable_editor_grab_focus (GtkWidget *widget); +static void glade_activatable_editor_grab_focus (GtkWidget * widget); -G_DEFINE_TYPE_WITH_CODE (GladeActivatableEditor, glade_activatable_editor, GTK_TYPE_VBOX, +G_DEFINE_TYPE_WITH_CODE (GladeActivatableEditor, glade_activatable_editor, + GTK_TYPE_VBOX, G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_activatable_editor_editable_init)); static void -glade_activatable_editor_class_init (GladeActivatableEditorClass *klass) +glade_activatable_editor_class_init (GladeActivatableEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_activatable_editor_finalize; - widget_class->grab_focus = glade_activatable_editor_grab_focus; + object_class->finalize = glade_activatable_editor_finalize; + widget_class->grab_focus = glade_activatable_editor_grab_focus; } static void -glade_activatable_editor_init (GladeActivatableEditor *self) +glade_activatable_editor_init (GladeActivatableEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeActivatableEditor *activatable_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeActivatableEditor * activatable_editor) { - if (activatable_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (activatable_editor))) - return; + if (activatable_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (activatable_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (activatable_editor), activatable_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (activatable_editor), + activatable_editor->loaded_widget); } static void -project_finalized (GladeActivatableEditor *activatable_editor, - GladeProject *where_project_was) +project_finalized (GladeActivatableEditor * activatable_editor, + GladeProject * where_project_was) { - activatable_editor->loaded_widget = NULL; + activatable_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (activatable_editor), NULL); + glade_editable_load (GLADE_EDITABLE (activatable_editor), NULL); } static void -glade_activatable_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_activatable_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (editable); - GList *l; - - activatable_editor->loading = TRUE; - - /* Since we watch the project*/ - if (activatable_editor->loaded_widget) - { - /* watch custom-child and use-stock properties here for reloads !!! */ - - g_signal_handlers_disconnect_by_func (G_OBJECT (activatable_editor->loaded_widget->project), - G_CALLBACK (project_changed), activatable_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (activatable_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - activatable_editor); - } - - /* Mark our widget... */ - activatable_editor->loaded_widget = widget; - - if (activatable_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (activatable_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), activatable_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (activatable_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - activatable_editor); - } - - /* load the embedded editable... */ - if (activatable_editor->embed) - glade_editable_load (GLADE_EDITABLE (activatable_editor->embed), widget); - - for (l = activatable_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - if (widget) - { - } - activatable_editor->loading = FALSE; + GladeActivatableEditor *activatable_editor = + GLADE_ACTIVATABLE_EDITOR (editable); + GList *l; + + activatable_editor->loading = TRUE; + + /* Since we watch the project */ + if (activatable_editor->loaded_widget) + { + /* watch custom-child and use-stock properties here for reloads !!! */ + + g_signal_handlers_disconnect_by_func (G_OBJECT + (activatable_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + activatable_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT + (activatable_editor->loaded_widget->project), + (GWeakNotify) project_finalized, activatable_editor); + } + + /* Mark our widget... */ + activatable_editor->loaded_widget = widget; + + if (activatable_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (activatable_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), + activatable_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (activatable_editor->loaded_widget->project), + (GWeakNotify) project_finalized, activatable_editor); + } + + /* load the embedded editable... */ + if (activatable_editor->embed) + glade_editable_load (GLADE_EDITABLE (activatable_editor->embed), widget); + + for (l = activatable_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + if (widget) + { + } + activatable_editor->loading = FALSE; } static void -glade_activatable_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_activatable_editor_set_show_name (GladeEditable * editable, + gboolean show_name) { - GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (editable); + GladeActivatableEditor *activatable_editor = + GLADE_ACTIVATABLE_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (activatable_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (activatable_editor->embed), + show_name); } static void -glade_activatable_editor_editable_init (GladeEditableIface *iface) +glade_activatable_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_activatable_editor_load; - iface->set_show_name = glade_activatable_editor_set_show_name; + iface->load = glade_activatable_editor_load; + iface->set_show_name = glade_activatable_editor_set_show_name; } static void -glade_activatable_editor_finalize (GObject *object) +glade_activatable_editor_finalize (GObject * object) { - GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (object); + GladeActivatableEditor *activatable_editor = + GLADE_ACTIVATABLE_EDITOR (object); - if (activatable_editor->properties) - g_list_free (activatable_editor->properties); - activatable_editor->properties = NULL; - activatable_editor->embed = NULL; + if (activatable_editor->properties) + g_list_free (activatable_editor->properties); + activatable_editor->properties = NULL; + activatable_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_activatable_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_activatable_editor_parent_class)->finalize (object); } static void -glade_activatable_editor_grab_focus (GtkWidget *widget) +glade_activatable_editor_grab_focus (GtkWidget * widget) { - GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (widget); + GladeActivatableEditor *activatable_editor = + GLADE_ACTIVATABLE_EDITOR (widget); - gtk_widget_grab_focus (activatable_editor->embed); + gtk_widget_grab_focus (activatable_editor->embed); } static void -table_attach (GtkWidget *table, - GtkWidget *child, - gint pos, gint row) +table_attach (GtkWidget * table, GtkWidget * child, gint pos, gint row) { - gtk_grid_attach (GTK_GRID (table), child, - pos, row, 1, 1); + gtk_grid_attach (GTK_GRID (table), child, pos, row, 1, 1); - if (pos) - gtk_widget_set_hexpand (child, TRUE); + if (pos) + gtk_widget_set_hexpand (child, TRUE); } static void -reset_property (GladeWidget *gwidget, - const gchar *property_name) +reset_property (GladeWidget * gwidget, const gchar * property_name) { - GladeProperty *property; - GValue value = { 0, }; - - if ((property = glade_widget_get_property (gwidget, property_name)) != NULL) - { - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - } + GladeProperty *property; + GValue value = { 0, }; + + if ((property = glade_widget_get_property (gwidget, property_name)) != NULL) + { + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + } } static GladeWidget * -get_image_widget (GladeWidget *widget) +get_image_widget (GladeWidget * widget) { - GtkWidget *image = NULL; + GtkWidget *image = NULL; - if (GTK_IS_IMAGE_MENU_ITEM (widget->object)) - image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget->object)); - return image ? glade_widget_get_from_gobject (image) : NULL; + if (GTK_IS_IMAGE_MENU_ITEM (widget->object)) + image = + gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget->object)); + return image ? glade_widget_get_from_gobject (image) : NULL; } static void -reset_properties (GladeWidget *gwidget, - GtkAction *action, - gboolean use_appearance, - gboolean use_appearance_changed) +reset_properties (GladeWidget * gwidget, + GtkAction * action, + gboolean use_appearance, gboolean use_appearance_changed) { - reset_property (gwidget, "visible"); - reset_property (gwidget, "sensitive"); - - if (GTK_IS_MENU_ITEM (gwidget->object)) - { - if (!use_appearance_changed) - reset_property (gwidget, "accel-group"); - - if (use_appearance) - { - GladeWidget *image; - GladeProperty *property; - - reset_property (gwidget, "stock"); - reset_property (gwidget, "use-underline"); - reset_property (gwidget, "use-stock"); - - /* Delete image... */ - if ((image = get_image_widget (gwidget)) != NULL) - { - GList list = { 0, }; - list.data = image; - glade_command_unlock_widget (image); - glade_command_delete (&list); - } - - property = glade_widget_get_property (gwidget, "label"); - glade_command_set_property (property, NULL); - } - else if (use_appearance_changed) - { - reset_property (gwidget, "stock"); - reset_property (gwidget, "use-underline"); - reset_property (gwidget, "use-stock"); - - reset_property (gwidget, "label"); - - } - } - else if (GTK_IS_TOOL_ITEM (gwidget->object)) - { - reset_property (gwidget, "visible-horizontal"); - reset_property (gwidget, "visible-vertical"); - reset_property (gwidget, "is-important"); - - if (use_appearance || use_appearance_changed) - { - reset_property (gwidget, "label-widget"); - reset_property (gwidget, "custom-label"); - reset_property (gwidget, "stock-id"); - reset_property (gwidget, "icon-name"); - reset_property (gwidget, "icon"); - reset_property (gwidget, "icon-widget"); - reset_property (gwidget, "image-mode"); - } - } - else if (GTK_IS_BUTTON (gwidget->object)) - { - reset_property (gwidget, "active"); - - - if (use_appearance) - { - - GtkWidget *button, *child; - GladeWidget *gchild = NULL; - GladeProperty *property; - - /* If theres a widget customly inside... command remove it first... */ - button = GTK_WIDGET (gwidget->object); - child = gtk_bin_get_child (GTK_BIN (button)); - if (child) - gchild = glade_widget_get_from_gobject (child); - - if (gchild && gchild->parent == gwidget) - { - GList widgets = { 0, }; - widgets.data = gchild; - glade_command_delete (&widgets); - } - - reset_property (gwidget, "custom-child"); - reset_property (gwidget, "stock"); - //reset_property (gwidget, "use-stock"); - - property = glade_widget_get_property (gwidget, "label"); - glade_command_set_property (property, ""); - - } else if (use_appearance_changed) { - reset_property (gwidget, "label"); - reset_property (gwidget, "custom-child"); - reset_property (gwidget, "stock"); - //reset_property (gwidget, "use-stock"); - } - } - /* Make sure none of our property resets screw with the current selection, - * since we rely on the selection during commit time. - */ - glade_project_selection_set (gwidget->project, gwidget->object, TRUE); + reset_property (gwidget, "visible"); + reset_property (gwidget, "sensitive"); + + if (GTK_IS_MENU_ITEM (gwidget->object)) + { + if (!use_appearance_changed) + reset_property (gwidget, "accel-group"); + + if (use_appearance) + { + GladeWidget *image; + GladeProperty *property; + + reset_property (gwidget, "stock"); + reset_property (gwidget, "use-underline"); + reset_property (gwidget, "use-stock"); + + /* Delete image... */ + if ((image = get_image_widget (gwidget)) != NULL) + { + GList list = { 0, }; + list.data = image; + glade_command_unlock_widget (image); + glade_command_delete (&list); + } + + property = glade_widget_get_property (gwidget, "label"); + glade_command_set_property (property, NULL); + } + else if (use_appearance_changed) + { + reset_property (gwidget, "stock"); + reset_property (gwidget, "use-underline"); + reset_property (gwidget, "use-stock"); + + reset_property (gwidget, "label"); + + } + } + else if (GTK_IS_TOOL_ITEM (gwidget->object)) + { + reset_property (gwidget, "visible-horizontal"); + reset_property (gwidget, "visible-vertical"); + reset_property (gwidget, "is-important"); + + if (use_appearance || use_appearance_changed) + { + reset_property (gwidget, "label-widget"); + reset_property (gwidget, "custom-label"); + reset_property (gwidget, "stock-id"); + reset_property (gwidget, "icon-name"); + reset_property (gwidget, "icon"); + reset_property (gwidget, "icon-widget"); + reset_property (gwidget, "image-mode"); + } + } + else if (GTK_IS_BUTTON (gwidget->object)) + { + reset_property (gwidget, "active"); + + + if (use_appearance) + { + + GtkWidget *button, *child; + GladeWidget *gchild = NULL; + GladeProperty *property; + + /* If theres a widget customly inside... command remove it first... */ + button = GTK_WIDGET (gwidget->object); + child = gtk_bin_get_child (GTK_BIN (button)); + if (child) + gchild = glade_widget_get_from_gobject (child); + + if (gchild && gchild->parent == gwidget) + { + GList widgets = { 0, }; + widgets.data = gchild; + glade_command_delete (&widgets); + } + + reset_property (gwidget, "custom-child"); + reset_property (gwidget, "stock"); + //reset_property (gwidget, "use-stock"); + + property = glade_widget_get_property (gwidget, "label"); + glade_command_set_property (property, ""); + + } + else if (use_appearance_changed) + { + reset_property (gwidget, "label"); + reset_property (gwidget, "custom-child"); + reset_property (gwidget, "stock"); + //reset_property (gwidget, "use-stock"); + } + } + /* Make sure none of our property resets screw with the current selection, + * since we rely on the selection during commit time. + */ + glade_project_selection_set (gwidget->project, gwidget->object, TRUE); } static void -related_action_pre_commit (GladeEditorProperty *property, - GValue *value, - GladeActivatableEditor *activatable_editor) +related_action_pre_commit (GladeEditorProperty * property, + GValue * value, + GladeActivatableEditor * activatable_editor) { - GladeWidget *gwidget = activatable_editor->loaded_widget; - GtkAction *action = g_value_get_object (value); - gboolean use_appearance = FALSE; + GladeWidget *gwidget = activatable_editor->loaded_widget; + GtkAction *action = g_value_get_object (value); + gboolean use_appearance = FALSE; - glade_widget_property_get (gwidget, "use-action-appearance", &use_appearance); + glade_widget_property_get (gwidget, "use-action-appearance", &use_appearance); - glade_command_push_group (_("Setting %s action"), gwidget->name); + glade_command_push_group (_("Setting %s action"), gwidget->name); - reset_properties (gwidget, action, use_appearance, FALSE); + reset_properties (gwidget, action, use_appearance, FALSE); } static void -related_action_post_commit (GladeEditorProperty *property, - GValue *value, - GladeActivatableEditor *activatable_editor) +related_action_post_commit (GladeEditorProperty * property, + GValue * value, + GladeActivatableEditor * activatable_editor) { - glade_command_pop_group (); + glade_command_pop_group (); } static void -use_appearance_pre_commit (GladeEditorProperty *property, - GValue *value, - GladeActivatableEditor *activatable_editor) +use_appearance_pre_commit (GladeEditorProperty * property, + GValue * value, + GladeActivatableEditor * activatable_editor) { - GladeWidget *gwidget = activatable_editor->loaded_widget; - GtkAction *action = NULL; - gboolean use_appearance = g_value_get_boolean (value); + GladeWidget *gwidget = activatable_editor->loaded_widget; + GtkAction *action = NULL; + gboolean use_appearance = g_value_get_boolean (value); - glade_widget_property_get (gwidget, "related-action", &action); + glade_widget_property_get (gwidget, "related-action", &action); - glade_command_push_group (use_appearance ? - _("Setting %s to use action appearance") : - _("Setting %s to not use action appearance"), - gwidget->name); + glade_command_push_group (use_appearance ? + _("Setting %s to use action appearance") : + _("Setting %s to not use action appearance"), + gwidget->name); - reset_properties (gwidget, action, use_appearance, TRUE); + reset_properties (gwidget, action, use_appearance, TRUE); } static void -use_appearance_post_commit (GladeEditorProperty *property, - GValue *value, - GladeActivatableEditor *activatable_editor) +use_appearance_post_commit (GladeEditorProperty * property, + GValue * value, + GladeActivatableEditor * activatable_editor) { - glade_command_pop_group (); + glade_command_pop_group (); } GtkWidget * -glade_activatable_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_activatable_editor_new (GladeWidgetAdaptor * adaptor, + GladeEditable * embed) { - GladeActivatableEditor *activatable_editor; - GladeEditorProperty *eprop; - GtkWidget *table, *frame, *alignment, *label; - gchar *str; - gint row = 0; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - activatable_editor = g_object_new (GLADE_TYPE_ACTIVATABLE_EDITOR, NULL); - activatable_editor->embed = GTK_WIDGET (embed); - - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (activatable_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - str = g_strdup_printf ("<b>%s</b>", _("Action")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (activatable_editor), frame, FALSE, FALSE, 4); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - - gtk_container_add (GTK_CONTAINER (alignment), table); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "related-action", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - activatable_editor->properties = g_list_prepend (activatable_editor->properties, eprop); - - g_signal_connect (G_OBJECT (eprop), "commit", - G_CALLBACK (related_action_pre_commit), activatable_editor); - g_signal_connect_after (G_OBJECT (eprop), "commit", - G_CALLBACK (related_action_post_commit), activatable_editor); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "use-action-appearance", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - activatable_editor->properties = g_list_prepend (activatable_editor->properties, eprop); - - gtk_widget_show_all (GTK_WIDGET (activatable_editor)); - - g_signal_connect (G_OBJECT (eprop), "commit", - G_CALLBACK (use_appearance_pre_commit), activatable_editor); - g_signal_connect_after (G_OBJECT (eprop), "commit", - G_CALLBACK (use_appearance_post_commit), activatable_editor); - - return GTK_WIDGET (activatable_editor); + GladeActivatableEditor *activatable_editor; + GladeEditorProperty *eprop; + GtkWidget *table, *frame, *alignment, *label; + gchar *str; + gint row = 0; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + activatable_editor = g_object_new (GLADE_TYPE_ACTIVATABLE_EDITOR, NULL); + activatable_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (activatable_editor), GTK_WIDGET (embed), FALSE, + FALSE, 0); + + str = g_strdup_printf ("<b>%s</b>", _("Action")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (activatable_editor), frame, FALSE, FALSE, 4); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + + gtk_container_add (GTK_CONTAINER (alignment), table); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "related-action", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + activatable_editor->properties = + g_list_prepend (activatable_editor->properties, eprop); + + g_signal_connect (G_OBJECT (eprop), "commit", + G_CALLBACK (related_action_pre_commit), activatable_editor); + g_signal_connect_after (G_OBJECT (eprop), "commit", + G_CALLBACK (related_action_post_commit), + activatable_editor); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "use-action-appearance", FALSE, + TRUE); + table_attach (table, eprop->item_label, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + activatable_editor->properties = + g_list_prepend (activatable_editor->properties, eprop); + + gtk_widget_show_all (GTK_WIDGET (activatable_editor)); + + g_signal_connect (G_OBJECT (eprop), "commit", + G_CALLBACK (use_appearance_pre_commit), activatable_editor); + g_signal_connect_after (G_OBJECT (eprop), "commit", + G_CALLBACK (use_appearance_post_commit), + activatable_editor); + + return GTK_WIDGET (activatable_editor); } diff --git a/plugins/gtk+/glade-activatable-editor.h b/plugins/gtk+/glade-activatable-editor.h index 1a666972..9383457e 100644 --- a/plugins/gtk+/glade-activatable-editor.h +++ b/plugins/gtk+/glade-activatable-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-attributes.c b/plugins/gtk+/glade-attributes.c index 836b2ef9..1eecdbc1 100755..100644 --- a/plugins/gtk+/glade-attributes.c +++ b/plugins/gtk+/glade-attributes.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * glade-attributes.c - Editing support for pango attributes * @@ -36,65 +35,66 @@ #define GLADE_RESPONSE_CLEAR 42 static GList * -glade_attr_list_copy (GList *attrs) +glade_attr_list_copy (GList * attrs) { - GList *ret = NULL, *list; - GladeAttribute *attr, *dup_attr; + GList *ret = NULL, *list; + GladeAttribute *attr, *dup_attr; - for (list = attrs; list; list = list->next) - { - attr = list->data; + for (list = attrs; list; list = list->next) + { + attr = list->data; - dup_attr = g_new0 (GladeAttribute, 1); - dup_attr->type = attr->type; - dup_attr->start = attr->start; - dup_attr->end = attr->end; - g_value_init (&(dup_attr->value), G_VALUE_TYPE (&(attr->value))); - g_value_copy (&(attr->value), &(dup_attr->value)); + dup_attr = g_new0 (GladeAttribute, 1); + dup_attr->type = attr->type; + dup_attr->start = attr->start; + dup_attr->end = attr->end; + g_value_init (&(dup_attr->value), G_VALUE_TYPE (&(attr->value))); + g_value_copy (&(attr->value), &(dup_attr->value)); - ret = g_list_prepend (ret, dup_attr); - } + ret = g_list_prepend (ret, dup_attr); + } - return g_list_reverse (ret); + return g_list_reverse (ret); } void -glade_attr_list_free (GList *attrs) +glade_attr_list_free (GList * attrs) { - GList *list; - GladeAttribute *attr; + GList *list; + GladeAttribute *attr; - for (list = attrs; list; list = list->next) - { - attr = list->data; + for (list = attrs; list; list = list->next) + { + attr = list->data; - g_value_unset (&(attr->value)); - g_free (attr); - } - g_list_free (attrs); + g_value_unset (&(attr->value)); + g_free (attr); + } + g_list_free (attrs); } GType glade_attr_glist_get_type (void) { - static GType type_id = 0; - - if (!type_id) - type_id = g_boxed_type_register_static - ("GladeAttrGList", - (GBoxedCopyFunc) glade_attr_list_copy, - (GBoxedFreeFunc) glade_attr_list_free); - return type_id; + static GType type_id = 0; + + if (!type_id) + type_id = g_boxed_type_register_static + ("GladeAttrGList", + (GBoxedCopyFunc) glade_attr_list_copy, + (GBoxedFreeFunc) glade_attr_list_free); + return type_id; } /************************************************************** * GladeEditorProperty stuff here **************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; +typedef struct +{ + GladeEditorProperty parent_instance; + + GtkTreeModel *model; - GtkTreeModel *model; - } GladeEPropAttrs; GLADE_MAKE_EPROP (GladeEPropAttrs, glade_eprop_attrs) @@ -103,1024 +103,1018 @@ GLADE_MAKE_EPROP (GladeEPropAttrs, glade_eprop_attrs) #define GLADE_IS_EPROP_ATTRS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ATTRS)) #define GLADE_IS_EPROP_ATTRS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ATTRS)) #define GLADE_EPROP_ATTRS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ATTRS, GladeEPropAttrsClass)) - -enum { - - /* Main Data */ - COLUMN_NAME, /* The title string for PangoAttrType */ - COLUMN_NAME_WEIGHT, /* For bold names */ - COLUMN_TYPE, /* The PangoAttrType */ - COLUMN_EDIT_TYPE, /* The AttrEditType (below) */ - COLUMN_VALUE, /* The value */ - COLUMN_START, /* attribute start value */ - COLUMN_END, /* attribute end value */ - - /* Editor renderer related */ - COLUMN_TOGGLE_ACTIVE, /* whether the toggle renderer is being used */ - COLUMN_TOGGLE_DOWN, /* whether the toggle should be displayed in "downstate" */ - - COLUMN_BUTTON_ACTIVE, /* whether the GladeCellRendererButton is to be used (to launch dialogs) */ - COLUMN_TEXT, /* text attribute value for all text derived renderers */ - COLUMN_TEXT_STYLE, /* whether to make italic */ - COLUMN_TEXT_FG, /* forground colour of the text */ - - COLUMN_COMBO_ACTIVE, /* whether the combobox renderer is being used */ - COLUMN_COMBO_MODEL, /* the model for the dropdown list */ - - COLUMN_SPIN_ACTIVE, /* whether the spin renderer is being used */ - COLUMN_SPIN_DIGITS, /* How many decimal points to show (used to edit float values) */ - - NUM_COLUMNS -}; - - -typedef enum { - EDIT_TOGGLE = 0, - EDIT_COMBO, - EDIT_SPIN, - EDIT_COLOR, - EDIT_INVALID -} AttrEditType; + enum + { + + /* Main Data */ + COLUMN_NAME, /* The title string for PangoAttrType */ + COLUMN_NAME_WEIGHT, /* For bold names */ + COLUMN_TYPE, /* The PangoAttrType */ + COLUMN_EDIT_TYPE, /* The AttrEditType (below) */ + COLUMN_VALUE, /* The value */ + COLUMN_START, /* attribute start value */ + COLUMN_END, /* attribute end value */ + + /* Editor renderer related */ + COLUMN_TOGGLE_ACTIVE, /* whether the toggle renderer is being used */ + COLUMN_TOGGLE_DOWN, /* whether the toggle should be displayed in "downstate" */ + + COLUMN_BUTTON_ACTIVE, /* whether the GladeCellRendererButton is to be used (to launch dialogs) */ + COLUMN_TEXT, /* text attribute value for all text derived renderers */ + COLUMN_TEXT_STYLE, /* whether to make italic */ + COLUMN_TEXT_FG, /* forground colour of the text */ + + COLUMN_COMBO_ACTIVE, /* whether the combobox renderer is being used */ + COLUMN_COMBO_MODEL, /* the model for the dropdown list */ + + COLUMN_SPIN_ACTIVE, /* whether the spin renderer is being used */ + COLUMN_SPIN_DIGITS, /* How many decimal points to show (used to edit float values) */ + + NUM_COLUMNS + }; + + + typedef enum + { + EDIT_TOGGLE = 0, + EDIT_COMBO, + EDIT_SPIN, + EDIT_COLOR, + EDIT_INVALID + } AttrEditType; #define ACTIVATE_COLUMN_FROM_TYPE(type) \ ((type) == EDIT_TOGGLE ? COLUMN_TOGGLE_ACTIVE : \ (type) == EDIT_SPIN ? COLUMN_SPIN_ACTIVE : \ (type) == EDIT_COMBO ? COLUMN_COMBO_ACTIVE: COLUMN_BUTTON_ACTIVE) -static GtkListStore * -get_enum_model_for_combo (PangoAttrType type) + static GtkListStore *get_enum_model_for_combo (PangoAttrType type) { - static GtkListStore *style_store = NULL, - *weight_store = NULL, *variant_store = NULL, - *stretch_store = NULL, *gravity_store = NULL, - *gravity_hint_store = NULL, *default_store = NULL; - - switch (type) - { - case PANGO_ATTR_STYLE: - if (!style_store) - style_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_STYLE, TRUE); - return style_store; - - case PANGO_ATTR_WEIGHT: - if (!weight_store) - weight_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_WEIGHT, TRUE); - return weight_store; - - case PANGO_ATTR_VARIANT: - if (!variant_store) - variant_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_VARIANT, TRUE); - return variant_store; - - case PANGO_ATTR_STRETCH: - if (!stretch_store) - stretch_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_STRETCH, TRUE); - return stretch_store; - - case PANGO_ATTR_GRAVITY: - if (!gravity_store) - gravity_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_GRAVITY, TRUE); - return gravity_store; - - case PANGO_ATTR_GRAVITY_HINT: - if (!gravity_hint_store) - gravity_hint_store = glade_utils_liststore_from_enum_type (PANGO_TYPE_GRAVITY_HINT, TRUE); - return gravity_hint_store; - - default: - if (!default_store) - default_store = gtk_list_store_new (1, G_TYPE_STRING); - return default_store; - } + static GtkListStore *style_store = NULL, + *weight_store = NULL, *variant_store = NULL, + *stretch_store = NULL, *gravity_store = NULL, + *gravity_hint_store = NULL, *default_store = NULL; + + switch (type) + { + case PANGO_ATTR_STYLE: + if (!style_store) + style_store = + glade_utils_liststore_from_enum_type (PANGO_TYPE_STYLE, TRUE); + return style_store; + + case PANGO_ATTR_WEIGHT: + if (!weight_store) + weight_store = + glade_utils_liststore_from_enum_type (PANGO_TYPE_WEIGHT, TRUE); + return weight_store; + + case PANGO_ATTR_VARIANT: + if (!variant_store) + variant_store = + glade_utils_liststore_from_enum_type (PANGO_TYPE_VARIANT, TRUE); + return variant_store; + + case PANGO_ATTR_STRETCH: + if (!stretch_store) + stretch_store = + glade_utils_liststore_from_enum_type (PANGO_TYPE_STRETCH, TRUE); + return stretch_store; + + case PANGO_ATTR_GRAVITY: + if (!gravity_store) + gravity_store = + glade_utils_liststore_from_enum_type (PANGO_TYPE_GRAVITY, TRUE); + return gravity_store; + + case PANGO_ATTR_GRAVITY_HINT: + if (!gravity_hint_store) + gravity_hint_store = + glade_utils_liststore_from_enum_type (PANGO_TYPE_GRAVITY_HINT, + TRUE); + return gravity_hint_store; + + default: + if (!default_store) + default_store = gtk_list_store_new (1, G_TYPE_STRING); + return default_store; + } } static gboolean -append_empty_row (GtkListStore *store, - PangoAttrType type) +append_empty_row (GtkListStore * store, PangoAttrType type) { - const gchar *name = NULL; - GtkListStore *model = get_enum_model_for_combo (type); - GtkTreeIter iter; - AttrEditType edit_type = EDIT_INVALID; - - switch (type) - { - /* PangoAttrLanguage */ - case PANGO_ATTR_LANGUAGE: - - break; - /* PangoAttrInt */ - case PANGO_ATTR_STYLE: - edit_type = EDIT_COMBO; - name = C_("textattr", "Style"); - break; - case PANGO_ATTR_WEIGHT: - edit_type = EDIT_COMBO; - name = C_("textattr", "Weight"); - break; - case PANGO_ATTR_VARIANT: - edit_type = EDIT_COMBO; - name = C_("textattr", "Variant"); - break; - case PANGO_ATTR_STRETCH: - edit_type = EDIT_COMBO; - name = C_("textattr", "Stretch"); - break; - case PANGO_ATTR_UNDERLINE: - edit_type = EDIT_TOGGLE; - name = C_("textattr", "Underline"); - break; - case PANGO_ATTR_STRIKETHROUGH: - edit_type = EDIT_TOGGLE; - name = C_("textattr", "Strikethrough"); - break; - case PANGO_ATTR_GRAVITY: - edit_type = EDIT_COMBO; - name = C_("textattr", "Gravity"); - break; - case PANGO_ATTR_GRAVITY_HINT: - edit_type = EDIT_COMBO; - name = C_("textattr", "Gravity Hint"); - break; - - /* PangoAttrString */ - case PANGO_ATTR_FAMILY: - /* Use a simple editable text renderer ? */ - break; - - /* PangoAttrSize */ - case PANGO_ATTR_SIZE: - edit_type = EDIT_SPIN; - name = C_("textattr", "Size"); - break; - case PANGO_ATTR_ABSOLUTE_SIZE: - edit_type = EDIT_SPIN; - name = C_("textattr", "Absolute Size"); - break; - - /* PangoAttrColor */ - /* Colours need editors... */ - case PANGO_ATTR_FOREGROUND: - edit_type = EDIT_COLOR; - name = C_("textattr", "Foreground Color"); - break; - case PANGO_ATTR_BACKGROUND: - edit_type = EDIT_COLOR; - name = C_("textattr", "Background Color"); - break; - case PANGO_ATTR_UNDERLINE_COLOR: - edit_type = EDIT_COLOR; - name = C_("textattr", "Underline Color"); - break; - case PANGO_ATTR_STRIKETHROUGH_COLOR: - edit_type = EDIT_COLOR; - name = C_("textattr", "Strikethrough Color"); - break; - - /* PangoAttrShape */ - case PANGO_ATTR_SHAPE: - /* Unsupported for now */ - break; - /* PangoAttrFloat */ - case PANGO_ATTR_SCALE: - edit_type = EDIT_SPIN; - name = C_("textattr", "Scale"); - break; - - case PANGO_ATTR_INVALID: - case PANGO_ATTR_LETTER_SPACING: - case PANGO_ATTR_RISE: - case PANGO_ATTR_FALLBACK: - case PANGO_ATTR_FONT_DESC: - default: - break; - } - - if (name) - { - gtk_list_store_append (store, &iter); - - gtk_list_store_set (store, &iter, - COLUMN_TOGGLE_ACTIVE, FALSE, - COLUMN_SPIN_ACTIVE, FALSE, - COLUMN_COMBO_ACTIVE, FALSE, - COLUMN_BUTTON_ACTIVE, FALSE, - -1); - - gtk_list_store_set (store, &iter, - COLUMN_NAME, name, - COLUMN_TYPE, type, - COLUMN_EDIT_TYPE, edit_type, - COLUMN_NAME_WEIGHT, PANGO_WEIGHT_NORMAL, - COLUMN_TEXT, _("<Enter Value>"), - COLUMN_TEXT_STYLE, PANGO_STYLE_ITALIC, - COLUMN_TEXT_FG, "Grey", - COLUMN_COMBO_MODEL, model, - ACTIVATE_COLUMN_FROM_TYPE (edit_type), TRUE, - -1); - return TRUE; - } - return FALSE; + const gchar *name = NULL; + GtkListStore *model = get_enum_model_for_combo (type); + GtkTreeIter iter; + AttrEditType edit_type = EDIT_INVALID; + + switch (type) + { + /* PangoAttrLanguage */ + case PANGO_ATTR_LANGUAGE: + + break; + /* PangoAttrInt */ + case PANGO_ATTR_STYLE: + edit_type = EDIT_COMBO; + name = C_ ("textattr", "Style"); + break; + case PANGO_ATTR_WEIGHT: + edit_type = EDIT_COMBO; + name = C_ ("textattr", "Weight"); + break; + case PANGO_ATTR_VARIANT: + edit_type = EDIT_COMBO; + name = C_ ("textattr", "Variant"); + break; + case PANGO_ATTR_STRETCH: + edit_type = EDIT_COMBO; + name = C_ ("textattr", "Stretch"); + break; + case PANGO_ATTR_UNDERLINE: + edit_type = EDIT_TOGGLE; + name = C_ ("textattr", "Underline"); + break; + case PANGO_ATTR_STRIKETHROUGH: + edit_type = EDIT_TOGGLE; + name = C_ ("textattr", "Strikethrough"); + break; + case PANGO_ATTR_GRAVITY: + edit_type = EDIT_COMBO; + name = C_ ("textattr", "Gravity"); + break; + case PANGO_ATTR_GRAVITY_HINT: + edit_type = EDIT_COMBO; + name = C_ ("textattr", "Gravity Hint"); + break; + + /* PangoAttrString */ + case PANGO_ATTR_FAMILY: + /* Use a simple editable text renderer ? */ + break; + + /* PangoAttrSize */ + case PANGO_ATTR_SIZE: + edit_type = EDIT_SPIN; + name = C_ ("textattr", "Size"); + break; + case PANGO_ATTR_ABSOLUTE_SIZE: + edit_type = EDIT_SPIN; + name = C_ ("textattr", "Absolute Size"); + break; + + /* PangoAttrColor */ + /* Colours need editors... */ + case PANGO_ATTR_FOREGROUND: + edit_type = EDIT_COLOR; + name = C_ ("textattr", "Foreground Color"); + break; + case PANGO_ATTR_BACKGROUND: + edit_type = EDIT_COLOR; + name = C_ ("textattr", "Background Color"); + break; + case PANGO_ATTR_UNDERLINE_COLOR: + edit_type = EDIT_COLOR; + name = C_ ("textattr", "Underline Color"); + break; + case PANGO_ATTR_STRIKETHROUGH_COLOR: + edit_type = EDIT_COLOR; + name = C_ ("textattr", "Strikethrough Color"); + break; + + /* PangoAttrShape */ + case PANGO_ATTR_SHAPE: + /* Unsupported for now */ + break; + /* PangoAttrFloat */ + case PANGO_ATTR_SCALE: + edit_type = EDIT_SPIN; + name = C_ ("textattr", "Scale"); + break; + + case PANGO_ATTR_INVALID: + case PANGO_ATTR_LETTER_SPACING: + case PANGO_ATTR_RISE: + case PANGO_ATTR_FALLBACK: + case PANGO_ATTR_FONT_DESC: + default: + break; + } + + if (name) + { + gtk_list_store_append (store, &iter); + + gtk_list_store_set (store, &iter, + COLUMN_TOGGLE_ACTIVE, FALSE, + COLUMN_SPIN_ACTIVE, FALSE, + COLUMN_COMBO_ACTIVE, FALSE, + COLUMN_BUTTON_ACTIVE, FALSE, -1); + + gtk_list_store_set (store, &iter, + COLUMN_NAME, name, + COLUMN_TYPE, type, + COLUMN_EDIT_TYPE, edit_type, + COLUMN_NAME_WEIGHT, PANGO_WEIGHT_NORMAL, + COLUMN_TEXT, _("<Enter Value>"), + COLUMN_TEXT_STYLE, PANGO_STYLE_ITALIC, + COLUMN_TEXT_FG, "Grey", + COLUMN_COMBO_MODEL, model, + ACTIVATE_COLUMN_FROM_TYPE (edit_type), TRUE, -1); + return TRUE; + } + return FALSE; } static gboolean -is_empty_row (GtkTreeModel *model, - GtkTreeIter *iter) +is_empty_row (GtkTreeModel * model, GtkTreeIter * iter) { - PangoAttrType attr_type; - AttrEditType edit_type; - gboolean bval; - gchar *strval = NULL; - gboolean empty_row = FALSE; - - /* First get the basic values */ - gtk_tree_model_get (model, iter, - COLUMN_TYPE, &attr_type, - COLUMN_EDIT_TYPE, &edit_type, - COLUMN_TOGGLE_DOWN, &bval, - COLUMN_TEXT, &strval, - -1); - - /* Ignore all other types */ - switch (edit_type) - { - case EDIT_TOGGLE: - if (!bval) - empty_row = TRUE; - break; - case EDIT_COMBO: - if (!strval || !strcmp (strval, _("Unset")) || !strcmp (strval, _("<Enter Value>"))) - empty_row = TRUE; - break; - case EDIT_SPIN: - /* XXX Interesting... can we get the defaults ? what can we do to let the user - * unset the value ?? - */ - if (!strval || !strcmp (strval, "0") || !strcmp (strval, _("<Enter Value>"))) - empty_row = TRUE; - break; - case EDIT_COLOR: - if (!strval || strval[0] == '\0' || !strcmp (strval, _("<Enter Value>"))) - empty_row = TRUE; - break; - case EDIT_INVALID: - default: - break; - } - g_free (strval); - - return empty_row; + PangoAttrType attr_type; + AttrEditType edit_type; + gboolean bval; + gchar *strval = NULL; + gboolean empty_row = FALSE; + + /* First get the basic values */ + gtk_tree_model_get (model, iter, + COLUMN_TYPE, &attr_type, + COLUMN_EDIT_TYPE, &edit_type, + COLUMN_TOGGLE_DOWN, &bval, COLUMN_TEXT, &strval, -1); + + /* Ignore all other types */ + switch (edit_type) + { + case EDIT_TOGGLE: + if (!bval) + empty_row = TRUE; + break; + case EDIT_COMBO: + if (!strval || !strcmp (strval, _("Unset")) || + !strcmp (strval, _("<Enter Value>"))) + empty_row = TRUE; + break; + case EDIT_SPIN: + /* XXX Interesting... can we get the defaults ? what can we do to let the user + * unset the value ?? + */ + if (!strval || !strcmp (strval, "0") || + !strcmp (strval, _("<Enter Value>"))) + empty_row = TRUE; + break; + case EDIT_COLOR: + if (!strval || strval[0] == '\0' || + !strcmp (strval, _("<Enter Value>"))) + empty_row = TRUE; + break; + case EDIT_INVALID: + default: + break; + } + g_free (strval); + + return empty_row; } static GType type_from_attr_type (PangoAttrType type) { - GType gtype = 0; - - switch (type) - { - case PANGO_ATTR_LANGUAGE: - case PANGO_ATTR_FAMILY: - return G_TYPE_STRING; - - case PANGO_ATTR_STYLE: return PANGO_TYPE_STYLE; - case PANGO_ATTR_WEIGHT: return PANGO_TYPE_WEIGHT; - case PANGO_ATTR_VARIANT: return PANGO_TYPE_VARIANT; - case PANGO_ATTR_STRETCH: return PANGO_TYPE_STRETCH; - case PANGO_ATTR_GRAVITY: return PANGO_TYPE_GRAVITY; - case PANGO_ATTR_GRAVITY_HINT: return PANGO_TYPE_GRAVITY_HINT; - - case PANGO_ATTR_UNDERLINE: - case PANGO_ATTR_STRIKETHROUGH: - return G_TYPE_BOOLEAN; - - case PANGO_ATTR_SIZE: - case PANGO_ATTR_ABSOLUTE_SIZE: - return G_TYPE_INT; - - case PANGO_ATTR_SCALE: - return G_TYPE_DOUBLE; - - /* PangoAttrColor */ - case PANGO_ATTR_FOREGROUND: - case PANGO_ATTR_BACKGROUND: - case PANGO_ATTR_UNDERLINE_COLOR: - case PANGO_ATTR_STRIKETHROUGH_COLOR: - /* boxed colours */ - return GDK_TYPE_COLOR; - - /* PangoAttrShape */ - case PANGO_ATTR_SHAPE: - /* Unsupported for now */ - break; - - case PANGO_ATTR_INVALID: - case PANGO_ATTR_LETTER_SPACING: - case PANGO_ATTR_RISE: - case PANGO_ATTR_FALLBACK: - case PANGO_ATTR_FONT_DESC: - default: - break; - } - - - return gtype; + GType gtype = 0; + + switch (type) + { + case PANGO_ATTR_LANGUAGE: + case PANGO_ATTR_FAMILY: + return G_TYPE_STRING; + + case PANGO_ATTR_STYLE: + return PANGO_TYPE_STYLE; + case PANGO_ATTR_WEIGHT: + return PANGO_TYPE_WEIGHT; + case PANGO_ATTR_VARIANT: + return PANGO_TYPE_VARIANT; + case PANGO_ATTR_STRETCH: + return PANGO_TYPE_STRETCH; + case PANGO_ATTR_GRAVITY: + return PANGO_TYPE_GRAVITY; + case PANGO_ATTR_GRAVITY_HINT: + return PANGO_TYPE_GRAVITY_HINT; + + case PANGO_ATTR_UNDERLINE: + case PANGO_ATTR_STRIKETHROUGH: + return G_TYPE_BOOLEAN; + + case PANGO_ATTR_SIZE: + case PANGO_ATTR_ABSOLUTE_SIZE: + return G_TYPE_INT; + + case PANGO_ATTR_SCALE: + return G_TYPE_DOUBLE; + + /* PangoAttrColor */ + case PANGO_ATTR_FOREGROUND: + case PANGO_ATTR_BACKGROUND: + case PANGO_ATTR_UNDERLINE_COLOR: + case PANGO_ATTR_STRIKETHROUGH_COLOR: + /* boxed colours */ + return GDK_TYPE_COLOR; + + /* PangoAttrShape */ + case PANGO_ATTR_SHAPE: + /* Unsupported for now */ + break; + + case PANGO_ATTR_INVALID: + case PANGO_ATTR_LETTER_SPACING: + case PANGO_ATTR_RISE: + case PANGO_ATTR_FALLBACK: + case PANGO_ATTR_FONT_DESC: + default: + break; + } + + + return gtype; } gchar * -glade_gtk_string_from_attr (GladeAttribute *gattr) +glade_gtk_string_from_attr (GladeAttribute * gattr) { - gchar *ret = NULL; - gint ival; - gdouble fval; - GdkColor *color; - - switch (gattr->type) - { - case PANGO_ATTR_LANGUAGE: - case PANGO_ATTR_FAMILY: - ret = g_value_dup_string (&(gattr->value)); - break; - - case PANGO_ATTR_STYLE: - case PANGO_ATTR_WEIGHT: - case PANGO_ATTR_VARIANT: - case PANGO_ATTR_STRETCH: - case PANGO_ATTR_GRAVITY: - case PANGO_ATTR_GRAVITY_HINT: - - /* Enums ... */ - ival = g_value_get_enum (&(gattr->value)); - ret = glade_utils_enum_string_from_value (G_VALUE_TYPE (&(gattr->value)), ival); - break; - - - case PANGO_ATTR_UNDERLINE: - case PANGO_ATTR_STRIKETHROUGH: - /* Booleans */ - if (g_value_get_boolean (&(gattr->value))) - ret = g_strdup_printf ("True"); - else - ret = g_strdup_printf ("False"); - break; - - /* PangoAttrSize */ - case PANGO_ATTR_SIZE: - case PANGO_ATTR_ABSOLUTE_SIZE: - /* ints */ - ival = g_value_get_int (&(gattr->value)); - ret = g_strdup_printf ("%d", ival); - break; - - /* PangoAttrFloat */ - case PANGO_ATTR_SCALE: - /* doubles */ - fval = g_value_get_double (&(gattr->value)); - ret = g_strdup_printf ("%f", fval); - break; - - /* PangoAttrColor */ - case PANGO_ATTR_FOREGROUND: - case PANGO_ATTR_BACKGROUND: - case PANGO_ATTR_UNDERLINE_COLOR: - case PANGO_ATTR_STRIKETHROUGH_COLOR: - /* boxed colours */ - color = g_value_get_boxed (&(gattr->value)); - ret = gdk_color_to_string (color); - break; - - /* PangoAttrShape */ - case PANGO_ATTR_SHAPE: - /* Unsupported for now */ - break; - - case PANGO_ATTR_INVALID: - case PANGO_ATTR_LETTER_SPACING: - case PANGO_ATTR_RISE: - case PANGO_ATTR_FALLBACK: - case PANGO_ATTR_FONT_DESC: - default: - break; - } - - return ret; + gchar *ret = NULL; + gint ival; + gdouble fval; + GdkColor *color; + + switch (gattr->type) + { + case PANGO_ATTR_LANGUAGE: + case PANGO_ATTR_FAMILY: + ret = g_value_dup_string (&(gattr->value)); + break; + + case PANGO_ATTR_STYLE: + case PANGO_ATTR_WEIGHT: + case PANGO_ATTR_VARIANT: + case PANGO_ATTR_STRETCH: + case PANGO_ATTR_GRAVITY: + case PANGO_ATTR_GRAVITY_HINT: + + /* Enums ... */ + ival = g_value_get_enum (&(gattr->value)); + ret = + glade_utils_enum_string_from_value (G_VALUE_TYPE (&(gattr->value)), + ival); + break; + + + case PANGO_ATTR_UNDERLINE: + case PANGO_ATTR_STRIKETHROUGH: + /* Booleans */ + if (g_value_get_boolean (&(gattr->value))) + ret = g_strdup_printf ("True"); + else + ret = g_strdup_printf ("False"); + break; + + /* PangoAttrSize */ + case PANGO_ATTR_SIZE: + case PANGO_ATTR_ABSOLUTE_SIZE: + /* ints */ + ival = g_value_get_int (&(gattr->value)); + ret = g_strdup_printf ("%d", ival); + break; + + /* PangoAttrFloat */ + case PANGO_ATTR_SCALE: + /* doubles */ + fval = g_value_get_double (&(gattr->value)); + ret = g_strdup_printf ("%f", fval); + break; + + /* PangoAttrColor */ + case PANGO_ATTR_FOREGROUND: + case PANGO_ATTR_BACKGROUND: + case PANGO_ATTR_UNDERLINE_COLOR: + case PANGO_ATTR_STRIKETHROUGH_COLOR: + /* boxed colours */ + color = g_value_get_boxed (&(gattr->value)); + ret = gdk_color_to_string (color); + break; + + /* PangoAttrShape */ + case PANGO_ATTR_SHAPE: + /* Unsupported for now */ + break; + + case PANGO_ATTR_INVALID: + case PANGO_ATTR_LETTER_SPACING: + case PANGO_ATTR_RISE: + case PANGO_ATTR_FALLBACK: + case PANGO_ATTR_FONT_DESC: + default: + break; + } + + return ret; } static gint -enum_value_from_string (PangoAttrType type, const gchar *strval) +enum_value_from_string (PangoAttrType type, const gchar * strval) { - GEnumClass *enum_class; - GEnumValue *enum_value; - gint value = 0; - - enum_class = g_type_class_ref (type_from_attr_type (type)); - if ((enum_value = g_enum_get_value_by_nick (enum_class, strval)) != NULL) - value = enum_value->value; - else - g_critical ("Couldnt find enum value for %s, type %s", - strval, g_type_name (type_from_attr_type (type))); - - g_type_class_unref (enum_class); - - return value; + GEnumClass *enum_class; + GEnumValue *enum_value; + gint value = 0; + + enum_class = g_type_class_ref (type_from_attr_type (type)); + if ((enum_value = g_enum_get_value_by_nick (enum_class, strval)) != NULL) + value = enum_value->value; + else + g_critical ("Couldnt find enum value for %s, type %s", + strval, g_type_name (type_from_attr_type (type))); + + g_type_class_unref (enum_class); + + return value; } GladeAttribute * -glade_gtk_attribute_from_string (PangoAttrType type, - const gchar *strval) +glade_gtk_attribute_from_string (PangoAttrType type, const gchar * strval) { - GladeAttribute *gattr; - GdkColor color; - - gattr = g_new0 (GladeAttribute, 1); - gattr->type = type; - gattr->start = 0; - gattr->end = G_MAXUINT; - - switch (type) - { - case PANGO_ATTR_LANGUAGE: - case PANGO_ATTR_FAMILY: - case PANGO_ATTR_FONT_DESC: - g_value_init (&(gattr->value), G_TYPE_STRING); - g_value_set_string (&(gattr->value), strval); - break; - - case PANGO_ATTR_STYLE: - case PANGO_ATTR_WEIGHT: - case PANGO_ATTR_VARIANT: - case PANGO_ATTR_STRETCH: - case PANGO_ATTR_GRAVITY: - case PANGO_ATTR_GRAVITY_HINT: - - /* Enums ... */ - g_value_init (&(gattr->value), type_from_attr_type (type)); - g_value_set_enum (&(gattr->value), enum_value_from_string (type, strval)); - break; - - - case PANGO_ATTR_UNDERLINE: - case PANGO_ATTR_STRIKETHROUGH: - /* Booleans */ - g_value_init (&(gattr->value), G_TYPE_BOOLEAN); - g_value_set_boolean (&(gattr->value), TRUE); - break; - - /* PangoAttrSize */ - case PANGO_ATTR_SIZE: - case PANGO_ATTR_ABSOLUTE_SIZE: - /* ints */ - g_value_init (&(gattr->value), G_TYPE_INT); - g_value_set_int (&(gattr->value), strtol (strval, NULL, 10)); - break; - - /* PangoAttrFloat */ - case PANGO_ATTR_SCALE: - /* doubles */ - g_value_init (&(gattr->value), G_TYPE_DOUBLE); - g_value_set_double (&(gattr->value), strtod (strval, NULL)); - break; - - /* PangoAttrColor */ - case PANGO_ATTR_FOREGROUND: - case PANGO_ATTR_BACKGROUND: - case PANGO_ATTR_UNDERLINE_COLOR: - case PANGO_ATTR_STRIKETHROUGH_COLOR: - /* boxed colours */ - if (gdk_color_parse (strval, &color)) - { - g_value_init (&(gattr->value), GDK_TYPE_COLOR); - g_value_set_boxed (&(gattr->value), &color); - } - else - g_critical ("Unable to parse color attribute '%s'", strval); - - break; - - /* PangoAttrShape */ - case PANGO_ATTR_SHAPE: - /* Unsupported for now */ - break; - - case PANGO_ATTR_INVALID: - case PANGO_ATTR_LETTER_SPACING: - case PANGO_ATTR_RISE: - case PANGO_ATTR_FALLBACK: - default: - break; - } - - return gattr; + GladeAttribute *gattr; + GdkColor color; + + gattr = g_new0 (GladeAttribute, 1); + gattr->type = type; + gattr->start = 0; + gattr->end = G_MAXUINT; + + switch (type) + { + case PANGO_ATTR_LANGUAGE: + case PANGO_ATTR_FAMILY: + case PANGO_ATTR_FONT_DESC: + g_value_init (&(gattr->value), G_TYPE_STRING); + g_value_set_string (&(gattr->value), strval); + break; + + case PANGO_ATTR_STYLE: + case PANGO_ATTR_WEIGHT: + case PANGO_ATTR_VARIANT: + case PANGO_ATTR_STRETCH: + case PANGO_ATTR_GRAVITY: + case PANGO_ATTR_GRAVITY_HINT: + + /* Enums ... */ + g_value_init (&(gattr->value), type_from_attr_type (type)); + g_value_set_enum (&(gattr->value), + enum_value_from_string (type, strval)); + break; + + + case PANGO_ATTR_UNDERLINE: + case PANGO_ATTR_STRIKETHROUGH: + /* Booleans */ + g_value_init (&(gattr->value), G_TYPE_BOOLEAN); + g_value_set_boolean (&(gattr->value), TRUE); + break; + + /* PangoAttrSize */ + case PANGO_ATTR_SIZE: + case PANGO_ATTR_ABSOLUTE_SIZE: + /* ints */ + g_value_init (&(gattr->value), G_TYPE_INT); + g_value_set_int (&(gattr->value), strtol (strval, NULL, 10)); + break; + + /* PangoAttrFloat */ + case PANGO_ATTR_SCALE: + /* doubles */ + g_value_init (&(gattr->value), G_TYPE_DOUBLE); + g_value_set_double (&(gattr->value), strtod (strval, NULL)); + break; + + /* PangoAttrColor */ + case PANGO_ATTR_FOREGROUND: + case PANGO_ATTR_BACKGROUND: + case PANGO_ATTR_UNDERLINE_COLOR: + case PANGO_ATTR_STRIKETHROUGH_COLOR: + /* boxed colours */ + if (gdk_color_parse (strval, &color)) + { + g_value_init (&(gattr->value), GDK_TYPE_COLOR); + g_value_set_boxed (&(gattr->value), &color); + } + else + g_critical ("Unable to parse color attribute '%s'", strval); + + break; + + /* PangoAttrShape */ + case PANGO_ATTR_SHAPE: + /* Unsupported for now */ + break; + + case PANGO_ATTR_INVALID: + case PANGO_ATTR_LETTER_SPACING: + case PANGO_ATTR_RISE: + case PANGO_ATTR_FALLBACK: + default: + break; + } + + return gattr; } static void -sync_object (GladeEPropAttrs *eprop_attrs, - gboolean use_command) +sync_object (GladeEPropAttrs * eprop_attrs, gboolean use_command) { - GList *attributes = NULL; - GladeAttribute *gattr; - GtkTreeIter iter; - PangoAttrType type; - AttrEditType edit_type; - gchar *strval = NULL; - gboolean valid; - - valid = gtk_tree_model_iter_children (eprop_attrs->model, &iter, NULL); - - while (valid) - { - - if (!is_empty_row (eprop_attrs->model, &iter)) - { - gtk_tree_model_get (eprop_attrs->model, &iter, - COLUMN_TYPE, &type, - COLUMN_EDIT_TYPE, &edit_type, - COLUMN_TEXT, &strval, - -1); - - gattr = glade_gtk_attribute_from_string (type, (edit_type == EDIT_TOGGLE) ? "" : strval); - strval = (g_free (strval), NULL); - - attributes = g_list_prepend (attributes, gattr); - - } - valid = gtk_tree_model_iter_next (eprop_attrs->model, &iter); - } - - if (use_command) - { - GValue value = { 0, }; - - g_value_init (&value, GLADE_TYPE_ATTR_GLIST); - g_value_take_boxed (&value, g_list_reverse (attributes)); - glade_editor_property_commit (GLADE_EDITOR_PROPERTY (eprop_attrs), &value); - g_value_unset (&value); - } - else - { - glade_property_set (GLADE_EDITOR_PROPERTY (eprop_attrs)->property, - g_list_reverse (attributes)); - glade_attr_list_free (attributes); - } + GList *attributes = NULL; + GladeAttribute *gattr; + GtkTreeIter iter; + PangoAttrType type; + AttrEditType edit_type; + gchar *strval = NULL; + gboolean valid; + + valid = gtk_tree_model_iter_children (eprop_attrs->model, &iter, NULL); + + while (valid) + { + + if (!is_empty_row (eprop_attrs->model, &iter)) + { + gtk_tree_model_get (eprop_attrs->model, &iter, + COLUMN_TYPE, &type, + COLUMN_EDIT_TYPE, &edit_type, + COLUMN_TEXT, &strval, -1); + + gattr = + glade_gtk_attribute_from_string (type, + (edit_type == + EDIT_TOGGLE) ? "" : strval); + strval = (g_free (strval), NULL); + + attributes = g_list_prepend (attributes, gattr); + + } + valid = gtk_tree_model_iter_next (eprop_attrs->model, &iter); + } + + if (use_command) + { + GValue value = { 0, }; + + g_value_init (&value, GLADE_TYPE_ATTR_GLIST); + g_value_take_boxed (&value, g_list_reverse (attributes)); + glade_editor_property_commit (GLADE_EDITOR_PROPERTY (eprop_attrs), + &value); + g_value_unset (&value); + } + else + { + glade_property_set (GLADE_EDITOR_PROPERTY (eprop_attrs)->property, + g_list_reverse (attributes)); + glade_attr_list_free (attributes); + } } static GtkTreeIter * -get_row_by_type (GtkTreeModel *model, - PangoAttrType type) +get_row_by_type (GtkTreeModel * model, PangoAttrType type) { - GtkTreeIter iter, *ret_iter = NULL; - gboolean valid; - PangoAttrType iter_type; - - valid = gtk_tree_model_iter_children (model, &iter, NULL); - - while (valid) - { - gtk_tree_model_get (model, &iter, - COLUMN_TYPE, &iter_type, - -1); - - if (iter_type == type) - { - ret_iter = gtk_tree_iter_copy (&iter); - break; - } - valid = gtk_tree_model_iter_next (model, &iter); - } - return ret_iter; + GtkTreeIter iter, *ret_iter = NULL; + gboolean valid; + PangoAttrType iter_type; + + valid = gtk_tree_model_iter_children (model, &iter, NULL); + + while (valid) + { + gtk_tree_model_get (model, &iter, COLUMN_TYPE, &iter_type, -1); + + if (iter_type == type) + { + ret_iter = gtk_tree_iter_copy (&iter); + break; + } + valid = gtk_tree_model_iter_next (model, &iter); + } + return ret_iter; } static void -value_icon_activate (GtkCellRendererToggle *cell_renderer, - gchar *path, - GladeEPropAttrs *eprop_attrs) +value_icon_activate (GtkCellRendererToggle * cell_renderer, + gchar * path, GladeEPropAttrs * eprop_attrs) { - GtkWidget *dialog; - GtkWidget *colorsel; - GtkTreeIter iter; - PangoAttrType type; - AttrEditType edit_type; - GdkColor color; - gchar *text = NULL, *new_text; + GtkWidget *dialog; + GtkWidget *colorsel; + GtkTreeIter iter; + PangoAttrType type; + AttrEditType edit_type; + GdkColor color; + gchar *text = NULL, *new_text; - /* Find type etc */ - if (!gtk_tree_model_get_iter_from_string (eprop_attrs->model, &iter, path)) - return; + /* Find type etc */ + if (!gtk_tree_model_get_iter_from_string (eprop_attrs->model, &iter, path)) + return; - gtk_tree_model_get (eprop_attrs->model, &iter, - COLUMN_TEXT, &text, - COLUMN_TYPE, &type, - COLUMN_EDIT_TYPE, &edit_type, - -1); + gtk_tree_model_get (eprop_attrs->model, &iter, + COLUMN_TEXT, &text, + COLUMN_TYPE, &type, COLUMN_EDIT_TYPE, &edit_type, -1); - /* Launch dialog etc. */ - switch (edit_type) - { - case EDIT_COLOR: - dialog = gtk_color_selection_dialog_new (_("Select a color")); + /* Launch dialog etc. */ + switch (edit_type) + { + case EDIT_COLOR: + dialog = gtk_color_selection_dialog_new (_("Select a color")); - colorsel = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog)); + colorsel = + gtk_color_selection_dialog_get_color_selection + (GTK_COLOR_SELECTION_DIALOG (dialog)); - /* Get response etc... */ - if (text && gdk_color_parse (text, &color)) - gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (colorsel), &color); + /* Get response etc... */ + if (text && gdk_color_parse (text, &color)) + gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (colorsel), + &color); - gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (colorsel), &color); + gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (colorsel), + &color); - new_text = gdk_color_to_string (&color); + new_text = gdk_color_to_string (&color); - gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, - COLUMN_TEXT, new_text, - COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, - COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL, - COLUMN_TEXT_FG, "Black", - -1); - g_free (new_text); + gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, + COLUMN_TEXT, new_text, + COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, + COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL, + COLUMN_TEXT_FG, "Black", -1); + g_free (new_text); - gtk_widget_destroy (dialog); - break; - default: - break; - } + gtk_widget_destroy (dialog); + break; + default: + break; + } - sync_object (eprop_attrs, FALSE); + sync_object (eprop_attrs, FALSE); - g_free (text); + g_free (text); } static void -value_toggled (GtkCellRendererToggle *cell_renderer, - gchar *path, - GladeEPropAttrs *eprop_attrs) +value_toggled (GtkCellRendererToggle * cell_renderer, + gchar * path, GladeEPropAttrs * eprop_attrs) { - gboolean active; - GtkTreeIter iter; - PangoAttrType type; + gboolean active; + GtkTreeIter iter; + PangoAttrType type; - if (!gtk_tree_model_get_iter_from_string (eprop_attrs->model, &iter, path)) - return; + if (!gtk_tree_model_get_iter_from_string (eprop_attrs->model, &iter, path)) + return; - gtk_tree_model_get (eprop_attrs->model, &iter, - COLUMN_TOGGLE_DOWN, &active, - COLUMN_TYPE, &type, - -1); + gtk_tree_model_get (eprop_attrs->model, &iter, + COLUMN_TOGGLE_DOWN, &active, COLUMN_TYPE, &type, -1); - gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, - COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, - COLUMN_TOGGLE_DOWN, !active, - -1); + gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, + COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, + COLUMN_TOGGLE_DOWN, !active, -1); - sync_object (eprop_attrs, FALSE); + sync_object (eprop_attrs, FALSE); } static void -value_combo_spin_edited (GtkCellRendererText *cell, - const gchar *path, - const gchar *new_text, - GladeEPropAttrs *eprop_attrs) +value_combo_spin_edited (GtkCellRendererText * cell, + const gchar * path, + const gchar * new_text, GladeEPropAttrs * eprop_attrs) { - GtkTreeIter iter; - PangoAttrType type; - - if (!gtk_tree_model_get_iter_from_string (eprop_attrs->model, &iter, path)) - return; - - gtk_tree_model_get (eprop_attrs->model, &iter, - COLUMN_TYPE, &type, - -1); - - /* Reset the column */ - if (new_text && strcmp (new_text, _("None")) == 0) - { - gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, - COLUMN_TEXT, _("<Enter Value>"), - COLUMN_NAME_WEIGHT, PANGO_WEIGHT_NORMAL, - COLUMN_TEXT_STYLE, PANGO_STYLE_ITALIC, - COLUMN_TEXT_FG, "Grey", - -1); - } - else - gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, - COLUMN_TEXT, new_text, - COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, - COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL, - COLUMN_TEXT_FG, "Black", - -1); - - sync_object (eprop_attrs, FALSE); + GtkTreeIter iter; + PangoAttrType type; + + if (!gtk_tree_model_get_iter_from_string (eprop_attrs->model, &iter, path)) + return; + + gtk_tree_model_get (eprop_attrs->model, &iter, COLUMN_TYPE, &type, -1); + + /* Reset the column */ + if (new_text && strcmp (new_text, _("None")) == 0) + { + gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, + COLUMN_TEXT, _("<Enter Value>"), + COLUMN_NAME_WEIGHT, PANGO_WEIGHT_NORMAL, + COLUMN_TEXT_STYLE, PANGO_STYLE_ITALIC, + COLUMN_TEXT_FG, "Grey", -1); + } + else + gtk_list_store_set (GTK_LIST_STORE (eprop_attrs->model), &iter, + COLUMN_TEXT, new_text, + COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, + COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL, + COLUMN_TEXT_FG, "Black", -1); + + sync_object (eprop_attrs, FALSE); } static GtkWidget * -glade_eprop_attrs_view (GladeEditorProperty *eprop) +glade_eprop_attrs_view (GladeEditorProperty * eprop) { - GladeEPropAttrs *eprop_attrs = GLADE_EPROP_ATTRS (eprop); - GtkWidget *view_widget; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - GtkAdjustment *adjustment; - - eprop_attrs->model = (GtkTreeModel *)gtk_list_store_new - (NUM_COLUMNS, - /* Main Data */ - G_TYPE_STRING, // COLUMN_NAME - G_TYPE_INT, // COLUMN_NAME_WEIGHT - G_TYPE_INT, // COLUMN_TYPE - G_TYPE_INT, // COLUMN_EDIT_TYPE - G_TYPE_POINTER, // COLUMN_VALUE - G_TYPE_UINT, // COLUMN_START - G_TYPE_UINT, // COLUMN_END - /* Editor renderer related */ - G_TYPE_BOOLEAN, // COLUMN_TOGGLE_ACTIVE - G_TYPE_BOOLEAN, // COLUMN_TOGGLE_DOWN - G_TYPE_BOOLEAN, // COLUMN_BUTTON_ACTIVE - G_TYPE_STRING, // COLUMN_TEXT - G_TYPE_INT, // COLUMN_TEXT_STYLE - G_TYPE_STRING, // COLUMN_TEXT_FG - G_TYPE_BOOLEAN, // COLUMN_COMBO_ACTIVE - GTK_TYPE_LIST_STORE, // COLUMN_COMBO_MODEL - G_TYPE_BOOLEAN, // COLUMN_SPIN_ACTIVE - G_TYPE_UINT); // COLUMN_SPIN_DIGITS - - view_widget = gtk_tree_view_new_with_model (eprop_attrs->model); - gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view_widget), FALSE); - gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view_widget), FALSE); - - /********************* attribute name column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); - column = gtk_tree_view_column_new_with_attributes - (_("Attribute"), renderer, - "text", COLUMN_NAME, - "weight", COLUMN_NAME_WEIGHT, - NULL); - - gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - /********************* attribute value column *********************/ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Value")); - - /* Toggle renderer */ - renderer = gtk_cell_renderer_toggle_new (); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "activatable", COLUMN_TOGGLE_ACTIVE, - "visible", COLUMN_TOGGLE_ACTIVE, - "active", COLUMN_TOGGLE_DOWN, - NULL); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (value_toggled), eprop); - - - /* Text renderer */ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "editable", COLUMN_BUTTON_ACTIVE, - "visible", COLUMN_BUTTON_ACTIVE, - "text", COLUMN_TEXT, - "style", COLUMN_TEXT_STYLE, - "foreground", COLUMN_TEXT_FG, - NULL); - - /* Icon renderer */ - renderer = glade_cell_renderer_icon_new (); - g_object_set (G_OBJECT (renderer), - "icon-name", GTK_STOCK_EDIT, - NULL); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "activatable", COLUMN_BUTTON_ACTIVE, - "visible", COLUMN_BUTTON_ACTIVE, - NULL); - - g_signal_connect (G_OBJECT (renderer), "activate", - G_CALLBACK (value_icon_activate), eprop); - - /* Combo renderer */ - renderer = gtk_cell_renderer_combo_new (); - g_object_set (G_OBJECT (renderer), "text-column", 0, "has-entry", FALSE, NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_attributes (column, renderer, - "editable", COLUMN_COMBO_ACTIVE, - "visible", COLUMN_COMBO_ACTIVE, - "model", COLUMN_COMBO_MODEL, - "text", COLUMN_TEXT, - "style", COLUMN_TEXT_STYLE, - "foreground", COLUMN_TEXT_FG, - NULL); - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_combo_spin_edited), eprop); - - - /* Spin renderer */ - renderer = gtk_cell_renderer_spin_new (); - adjustment = (GtkAdjustment *)gtk_adjustment_new (0, -G_MAXDOUBLE, G_MAXDOUBLE, 100, 100, 100); - g_object_set (G_OBJECT (renderer), "adjustment", adjustment, NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_attributes (column, renderer, - "visible", COLUMN_SPIN_ACTIVE, - "editable", COLUMN_SPIN_ACTIVE, - "text", COLUMN_TEXT, - "style", COLUMN_TEXT_STYLE, - "foreground", COLUMN_TEXT_FG, - "digits", COLUMN_SPIN_DIGITS, - NULL); - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_combo_spin_edited), eprop); - - gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - return view_widget; + GladeEPropAttrs *eprop_attrs = GLADE_EPROP_ATTRS (eprop); + GtkWidget *view_widget; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkAdjustment *adjustment; + + eprop_attrs->model = (GtkTreeModel *) gtk_list_store_new (NUM_COLUMNS, + /* Main Data */ + G_TYPE_STRING, // COLUMN_NAME + G_TYPE_INT, // COLUMN_NAME_WEIGHT + G_TYPE_INT, // COLUMN_TYPE + G_TYPE_INT, // COLUMN_EDIT_TYPE + G_TYPE_POINTER, // COLUMN_VALUE + G_TYPE_UINT, // COLUMN_START + G_TYPE_UINT, // COLUMN_END + /* Editor renderer related */ + G_TYPE_BOOLEAN, // COLUMN_TOGGLE_ACTIVE + G_TYPE_BOOLEAN, // COLUMN_TOGGLE_DOWN + G_TYPE_BOOLEAN, // COLUMN_BUTTON_ACTIVE + G_TYPE_STRING, // COLUMN_TEXT + G_TYPE_INT, // COLUMN_TEXT_STYLE + G_TYPE_STRING, // COLUMN_TEXT_FG + G_TYPE_BOOLEAN, // COLUMN_COMBO_ACTIVE + GTK_TYPE_LIST_STORE, // COLUMN_COMBO_MODEL + G_TYPE_BOOLEAN, // COLUMN_SPIN_ACTIVE + G_TYPE_UINT); // COLUMN_SPIN_DIGITS + + view_widget = gtk_tree_view_new_with_model (eprop_attrs->model); + gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view_widget), FALSE); + gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view_widget), FALSE); + + /********************* attribute name column *********************/ + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); + column = gtk_tree_view_column_new_with_attributes + (_("Attribute"), renderer, + "text", COLUMN_NAME, "weight", COLUMN_NAME_WEIGHT, NULL); + + gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); + + /********************* attribute value column *********************/ + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (column, _("Value")); + + /* Toggle renderer */ + renderer = gtk_cell_renderer_toggle_new (); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "activatable", COLUMN_TOGGLE_ACTIVE, + "visible", COLUMN_TOGGLE_ACTIVE, + "active", COLUMN_TOGGLE_DOWN, NULL); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (value_toggled), eprop); + + + /* Text renderer */ + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "editable", COLUMN_BUTTON_ACTIVE, + "visible", COLUMN_BUTTON_ACTIVE, + "text", COLUMN_TEXT, + "style", COLUMN_TEXT_STYLE, + "foreground", COLUMN_TEXT_FG, NULL); + + /* Icon renderer */ + renderer = glade_cell_renderer_icon_new (); + g_object_set (G_OBJECT (renderer), "icon-name", GTK_STOCK_EDIT, NULL); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "activatable", COLUMN_BUTTON_ACTIVE, + "visible", COLUMN_BUTTON_ACTIVE, NULL); + + g_signal_connect (G_OBJECT (renderer), "activate", + G_CALLBACK (value_icon_activate), eprop); + + /* Combo renderer */ + renderer = gtk_cell_renderer_combo_new (); + g_object_set (G_OBJECT (renderer), "text-column", 0, "has-entry", FALSE, + NULL); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_set_attributes (column, renderer, + "editable", COLUMN_COMBO_ACTIVE, + "visible", COLUMN_COMBO_ACTIVE, + "model", COLUMN_COMBO_MODEL, + "text", COLUMN_TEXT, + "style", COLUMN_TEXT_STYLE, + "foreground", COLUMN_TEXT_FG, NULL); + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_combo_spin_edited), eprop); + + + /* Spin renderer */ + renderer = gtk_cell_renderer_spin_new (); + adjustment = + (GtkAdjustment *) gtk_adjustment_new (0, -G_MAXDOUBLE, G_MAXDOUBLE, 100, + 100, 100); + g_object_set (G_OBJECT (renderer), "adjustment", adjustment, NULL); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_set_attributes (column, renderer, + "visible", COLUMN_SPIN_ACTIVE, + "editable", COLUMN_SPIN_ACTIVE, + "text", COLUMN_TEXT, + "style", COLUMN_TEXT_STYLE, + "foreground", COLUMN_TEXT_FG, + "digits", COLUMN_SPIN_DIGITS, NULL); + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_combo_spin_edited), eprop); + + gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); + + return view_widget; } static void -glade_eprop_attrs_populate_view (GladeEditorProperty *eprop, - GtkTreeView *view) +glade_eprop_attrs_populate_view (GladeEditorProperty * eprop, + GtkTreeView * view) { - GList *attributes, *list; - GtkListStore *model = (GtkListStore *)gtk_tree_view_get_model (view); - GtkTreeIter *iter; - GladeAttribute *gattr; - gchar *text; - - attributes = g_value_get_boxed (eprop->property->value); - - append_empty_row (model, PANGO_ATTR_LANGUAGE); - append_empty_row (model, PANGO_ATTR_STYLE); - append_empty_row (model, PANGO_ATTR_WEIGHT); - append_empty_row (model, PANGO_ATTR_VARIANT); - append_empty_row (model, PANGO_ATTR_STRETCH); - append_empty_row (model, PANGO_ATTR_UNDERLINE); - append_empty_row (model, PANGO_ATTR_STRIKETHROUGH); - append_empty_row (model, PANGO_ATTR_GRAVITY); - append_empty_row (model, PANGO_ATTR_GRAVITY_HINT); - append_empty_row (model, PANGO_ATTR_FAMILY); - append_empty_row (model, PANGO_ATTR_SIZE); - append_empty_row (model, PANGO_ATTR_ABSOLUTE_SIZE); - append_empty_row (model, PANGO_ATTR_FOREGROUND); - append_empty_row (model, PANGO_ATTR_BACKGROUND); - append_empty_row (model, PANGO_ATTR_UNDERLINE_COLOR); - append_empty_row (model, PANGO_ATTR_STRIKETHROUGH_COLOR); - append_empty_row (model, PANGO_ATTR_SHAPE); - append_empty_row (model, PANGO_ATTR_SCALE); - - /* XXX Populate here ... - */ - for (list = attributes; list; list = list->next) - { - gattr = list->data; - - if ((iter = get_row_by_type (GTK_TREE_MODEL (model), gattr->type))) - { - text = glade_gtk_string_from_attr (gattr); - - gtk_list_store_set (GTK_LIST_STORE (model), iter, - COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, - COLUMN_TEXT, text, - COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL, - COLUMN_TEXT_FG, "Black", - -1); - - if (gattr->type == PANGO_ATTR_UNDERLINE || - gattr->type == PANGO_ATTR_STRIKETHROUGH) - gtk_list_store_set (GTK_LIST_STORE (model), iter, - COLUMN_TOGGLE_DOWN, g_value_get_boolean (&(gattr->value)), - -1); - - g_free (text); - gtk_tree_iter_free (iter); - } - - } + GList *attributes, *list; + GtkListStore *model = (GtkListStore *) gtk_tree_view_get_model (view); + GtkTreeIter *iter; + GladeAttribute *gattr; + gchar *text; + + attributes = g_value_get_boxed (eprop->property->value); + + append_empty_row (model, PANGO_ATTR_LANGUAGE); + append_empty_row (model, PANGO_ATTR_STYLE); + append_empty_row (model, PANGO_ATTR_WEIGHT); + append_empty_row (model, PANGO_ATTR_VARIANT); + append_empty_row (model, PANGO_ATTR_STRETCH); + append_empty_row (model, PANGO_ATTR_UNDERLINE); + append_empty_row (model, PANGO_ATTR_STRIKETHROUGH); + append_empty_row (model, PANGO_ATTR_GRAVITY); + append_empty_row (model, PANGO_ATTR_GRAVITY_HINT); + append_empty_row (model, PANGO_ATTR_FAMILY); + append_empty_row (model, PANGO_ATTR_SIZE); + append_empty_row (model, PANGO_ATTR_ABSOLUTE_SIZE); + append_empty_row (model, PANGO_ATTR_FOREGROUND); + append_empty_row (model, PANGO_ATTR_BACKGROUND); + append_empty_row (model, PANGO_ATTR_UNDERLINE_COLOR); + append_empty_row (model, PANGO_ATTR_STRIKETHROUGH_COLOR); + append_empty_row (model, PANGO_ATTR_SHAPE); + append_empty_row (model, PANGO_ATTR_SCALE); + + /* XXX Populate here ... + */ + for (list = attributes; list; list = list->next) + { + gattr = list->data; + + if ((iter = get_row_by_type (GTK_TREE_MODEL (model), gattr->type))) + { + text = glade_gtk_string_from_attr (gattr); + + gtk_list_store_set (GTK_LIST_STORE (model), iter, + COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD, + COLUMN_TEXT, text, + COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL, + COLUMN_TEXT_FG, "Black", -1); + + if (gattr->type == PANGO_ATTR_UNDERLINE || + gattr->type == PANGO_ATTR_STRIKETHROUGH) + gtk_list_store_set (GTK_LIST_STORE (model), iter, + COLUMN_TOGGLE_DOWN, + g_value_get_boolean (&(gattr->value)), -1); + + g_free (text); + gtk_tree_iter_free (iter); + } + + } } static void -glade_eprop_attrs_show_dialog (GtkWidget *dialog_button, - GladeEditorProperty *eprop) +glade_eprop_attrs_show_dialog (GtkWidget * dialog_button, + GladeEditorProperty * eprop) { - GladeEPropAttrs *eprop_attrs = GLADE_EPROP_ATTRS (eprop); - GtkWidget *dialog, *parent, *vbox, *sw, *tree_view; - GladeProject *project; - GList *old_attributes; - gint res; - - project = glade_widget_get_project (eprop->property->widget); - parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop)); - - - /* Keep a copy for commit time... */ - old_attributes = g_value_dup_boxed (eprop->property->value); - - dialog = gtk_dialog_new_with_buttons (_("Setup Text Attributes"), - GTK_WINDOW (parent), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - - gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - vbox, TRUE, TRUE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 200); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - tree_view = glade_eprop_attrs_view (eprop); - glade_eprop_attrs_populate_view (eprop, GTK_TREE_VIEW (tree_view)); - - gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); - - gtk_widget_show (tree_view); - gtk_container_add (GTK_CONTAINER (sw), tree_view); - - /* Run the dialog */ - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) - { - /* Update from old attributes so that there a property change - * sitting on the undo stack. - */ - glade_property_set (eprop->property, old_attributes); - sync_object (eprop_attrs, TRUE); - } - else if (res == GLADE_RESPONSE_CLEAR) - { - GValue value = { 0, }; - g_value_init (&value, GLADE_TYPE_ATTR_GLIST); - g_value_set_boxed (&value, NULL); - glade_editor_property_commit (eprop, &value); - g_value_unset (&value); - } - - /* Clean up ... - */ - gtk_widget_destroy (dialog); - - g_object_unref (G_OBJECT (eprop_attrs->model)); - eprop_attrs->model = NULL; - - glade_attr_list_free (old_attributes); + GladeEPropAttrs *eprop_attrs = GLADE_EPROP_ATTRS (eprop); + GtkWidget *dialog, *parent, *vbox, *sw, *tree_view; + GladeProject *project; + GList *old_attributes; + gint res; + + project = glade_widget_get_project (eprop->property->widget); + parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop)); + + + /* Keep a copy for commit time... */ + old_attributes = g_value_dup_boxed (eprop->property->value); + + dialog = gtk_dialog_new_with_buttons (_("Setup Text Attributes"), + GTK_WINDOW (parent), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + + vbox = gtk_vbox_new (FALSE, 6); + gtk_widget_show (vbox); + + gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); + + gtk_box_pack_start (GTK_BOX + (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox, + TRUE, TRUE, 0); + + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (sw); + gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); + gtk_widget_set_size_request (sw, 400, 200); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); + + tree_view = glade_eprop_attrs_view (eprop); + glade_eprop_attrs_populate_view (eprop, GTK_TREE_VIEW (tree_view)); + + gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); + + gtk_widget_show (tree_view); + gtk_container_add (GTK_CONTAINER (sw), tree_view); + + /* Run the dialog */ + res = gtk_dialog_run (GTK_DIALOG (dialog)); + if (res == GTK_RESPONSE_OK) + { + /* Update from old attributes so that there a property change + * sitting on the undo stack. + */ + glade_property_set (eprop->property, old_attributes); + sync_object (eprop_attrs, TRUE); + } + else if (res == GLADE_RESPONSE_CLEAR) + { + GValue value = { 0, }; + g_value_init (&value, GLADE_TYPE_ATTR_GLIST); + g_value_set_boxed (&value, NULL); + glade_editor_property_commit (eprop, &value); + g_value_unset (&value); + } + + /* Clean up ... + */ + gtk_widget_destroy (dialog); + + g_object_unref (G_OBJECT (eprop_attrs->model)); + eprop_attrs->model = NULL; + + glade_attr_list_free (old_attributes); } static void -glade_eprop_attrs_finalize (GObject *object) +glade_eprop_attrs_finalize (GObject * object) { - /* Chain up */ - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); + /* Chain up */ + GObjectClass *parent_class = + g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -glade_eprop_attrs_load (GladeEditorProperty *eprop, - GladeProperty *property) +glade_eprop_attrs_load (GladeEditorProperty * eprop, GladeProperty * property) { - GladeEditorPropertyClass *parent_class = - g_type_class_peek_parent (G_OBJECT_GET_CLASS (eprop)); + GladeEditorPropertyClass *parent_class = + g_type_class_peek_parent (G_OBJECT_GET_CLASS (eprop)); - /* No displayable attributes in eprop, just a button. */ - parent_class->load (eprop, property); + /* No displayable attributes in eprop, just a button. */ + parent_class->load (eprop, property); } static GtkWidget * -glade_eprop_attrs_create_input (GladeEditorProperty *eprop) +glade_eprop_attrs_create_input (GladeEditorProperty * eprop) { - GtkWidget *hbox; - GtkWidget *button; + GtkWidget *hbox; + GtkWidget *button; - hbox = gtk_hbox_new (FALSE, 0); + hbox = gtk_hbox_new (FALSE, 0); - button = gtk_button_new_from_stock (GTK_STOCK_EDIT); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + button = gtk_button_new_from_stock (GTK_STOCK_EDIT); + gtk_widget_show (button); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_attrs_show_dialog), - eprop); + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (glade_eprop_attrs_show_dialog), eprop); - return hbox; + return hbox; } diff --git a/plugins/gtk+/glade-attributes.h b/plugins/gtk+/glade-attributes.h index be1bd392..93aae06a 100755..100644 --- a/plugins/gtk+/glade-attributes.h +++ b/plugins/gtk+/glade-attributes.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ #ifndef __GLADE_ATTRIBUTES_H__ #define __GLADE_ATTRIBUTES_H__ diff --git a/plugins/gtk+/glade-button-editor.c b/plugins/gtk+/glade-button-editor.c index 53e43512..5b988c0b 100644 --- a/plugins/gtk+/glade-button-editor.c +++ b/plugins/gtk+/glade-button-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,11 +27,11 @@ #include "glade-button-editor.h" -static void glade_button_editor_finalize (GObject *object); +static void glade_button_editor_finalize (GObject * object); -static void glade_button_editor_editable_init (GladeEditableIface *iface); +static void glade_button_editor_editable_init (GladeEditableIface * iface); -static void glade_button_editor_grab_focus (GtkWidget *widget); +static void glade_button_editor_grab_focus (GtkWidget * widget); G_DEFINE_TYPE_WITH_CODE (GladeButtonEditor, glade_button_editor, GTK_TYPE_VBOX, @@ -41,494 +40,534 @@ G_DEFINE_TYPE_WITH_CODE (GladeButtonEditor, glade_button_editor, GTK_TYPE_VBOX, static void -glade_button_editor_class_init (GladeButtonEditorClass *klass) +glade_button_editor_class_init (GladeButtonEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_button_editor_finalize; - widget_class->grab_focus = glade_button_editor_grab_focus; + object_class->finalize = glade_button_editor_finalize; + widget_class->grab_focus = glade_button_editor_grab_focus; } static void -glade_button_editor_init (GladeButtonEditor *self) +glade_button_editor_init (GladeButtonEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeButtonEditor *button_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeButtonEditor * button_editor) { - if (button_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (button_editor))) - return; + if (button_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (button_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (button_editor), button_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -project_finalized (GladeButtonEditor *button_editor, - GladeProject *where_project_was) +project_finalized (GladeButtonEditor * button_editor, + GladeProject * where_project_was) { - button_editor->loaded_widget = NULL; + button_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (button_editor), NULL); + glade_editable_load (GLADE_EDITABLE (button_editor), NULL); } static void -glade_button_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_button_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (editable); - GladeWidget *gchild = NULL; - GtkWidget *child, *button; - gboolean use_stock = FALSE, use_appearance = FALSE; - GList *l; - - button_editor->loading = TRUE; - - /* Since we watch the project*/ - if (button_editor->loaded_widget) - { - /* watch custom-child and use-stock properties here for reloads !!! */ - - g_signal_handlers_disconnect_by_func (G_OBJECT (button_editor->loaded_widget->project), - G_CALLBACK (project_changed), button_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (button_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - button_editor); - } - - /* Mark our widget... */ - button_editor->loaded_widget = widget; - - if (button_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (button_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), button_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (button_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - button_editor); - } - - /* load the embedded editable... */ - if (button_editor->embed) - glade_editable_load (GLADE_EDITABLE (button_editor->embed), widget); - - for (l = button_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - - if (widget) - { - glade_widget_property_get (widget, "use-action-appearance", &use_appearance); - - button = GTK_WIDGET (widget->object); - child = gtk_bin_get_child (GTK_BIN (button)); - if (child) - gchild = glade_widget_get_from_gobject (child); - - /* Setup radio and sensitivity states */ - if ((gchild && gchild->parent) || // a widget is manually inside - GLADE_IS_PLACEHOLDER (child)) // placeholder there, custom mode - { - /* Custom */ - gtk_widget_set_sensitive (button_editor->standard_frame, FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->custom_radio), TRUE); - } - else - { - /* Standard */ - gtk_widget_set_sensitive (button_editor->standard_frame, TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->standard_radio), TRUE); - - glade_widget_property_get (widget, "use-stock", &use_stock); - - if (use_stock) - { - gtk_widget_set_sensitive (button_editor->stock_frame, TRUE); - gtk_widget_set_sensitive (button_editor->label_frame, FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->stock_radio), TRUE); - } - else - { - gtk_widget_set_sensitive (button_editor->stock_frame, FALSE); - gtk_widget_set_sensitive (button_editor->label_frame, TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->label_radio), TRUE); - } - } - - if (use_appearance) - gtk_widget_set_sensitive (button_editor->custom_radio, FALSE); - else - gtk_widget_set_sensitive (button_editor->custom_radio, TRUE); - - } - button_editor->loading = FALSE; + GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (editable); + GladeWidget *gchild = NULL; + GtkWidget *child, *button; + gboolean use_stock = FALSE, use_appearance = FALSE; + GList *l; + + button_editor->loading = TRUE; + + /* Since we watch the project */ + if (button_editor->loaded_widget) + { + /* watch custom-child and use-stock properties here for reloads !!! */ + + g_signal_handlers_disconnect_by_func (G_OBJECT + (button_editor->loaded_widget->project), + G_CALLBACK (project_changed), + button_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (button_editor->loaded_widget->project), + (GWeakNotify) project_finalized, button_editor); + } + + /* Mark our widget... */ + button_editor->loaded_widget = widget; + + if (button_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (button_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), button_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (button_editor->loaded_widget->project), + (GWeakNotify) project_finalized, button_editor); + } + + /* load the embedded editable... */ + if (button_editor->embed) + glade_editable_load (GLADE_EDITABLE (button_editor->embed), widget); + + for (l = button_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + + if (widget) + { + glade_widget_property_get (widget, "use-action-appearance", + &use_appearance); + + button = GTK_WIDGET (widget->object); + child = gtk_bin_get_child (GTK_BIN (button)); + if (child) + gchild = glade_widget_get_from_gobject (child); + + /* Setup radio and sensitivity states */ + if ((gchild && gchild->parent) || // a widget is manually inside + GLADE_IS_PLACEHOLDER (child)) // placeholder there, custom mode + { + /* Custom */ + gtk_widget_set_sensitive (button_editor->standard_frame, FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (button_editor->custom_radio), TRUE); + } + else + { + /* Standard */ + gtk_widget_set_sensitive (button_editor->standard_frame, TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (button_editor->standard_radio), TRUE); + + glade_widget_property_get (widget, "use-stock", &use_stock); + + if (use_stock) + { + gtk_widget_set_sensitive (button_editor->stock_frame, TRUE); + gtk_widget_set_sensitive (button_editor->label_frame, FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (button_editor->stock_radio), TRUE); + } + else + { + gtk_widget_set_sensitive (button_editor->stock_frame, FALSE); + gtk_widget_set_sensitive (button_editor->label_frame, TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (button_editor->label_radio), TRUE); + } + } + + if (use_appearance) + gtk_widget_set_sensitive (button_editor->custom_radio, FALSE); + else + gtk_widget_set_sensitive (button_editor->custom_radio, TRUE); + + } + button_editor->loading = FALSE; } static void -glade_button_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_button_editor_set_show_name (GladeEditable * editable, gboolean show_name) { - GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (editable); + GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (button_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (button_editor->embed), + show_name); } static void -glade_button_editor_editable_init (GladeEditableIface *iface) +glade_button_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_button_editor_load; - iface->set_show_name = glade_button_editor_set_show_name; + iface->load = glade_button_editor_load; + iface->set_show_name = glade_button_editor_set_show_name; } static void -glade_button_editor_finalize (GObject *object) +glade_button_editor_finalize (GObject * object) { - GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (object); + GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (object); - if (button_editor->properties) - g_list_free (button_editor->properties); - button_editor->properties = NULL; - button_editor->embed = NULL; + if (button_editor->properties) + g_list_free (button_editor->properties); + button_editor->properties = NULL; + button_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_button_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_button_editor_parent_class)->finalize (object); } static void -glade_button_editor_grab_focus (GtkWidget *widget) +glade_button_editor_grab_focus (GtkWidget * widget) { - GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (widget); + GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (widget); - gtk_widget_grab_focus (button_editor->embed); + gtk_widget_grab_focus (button_editor->embed); } /* Secion control radio button callbacks: */ static void -standard_toggled (GtkWidget *widget, - GladeButtonEditor *button_editor) +standard_toggled (GtkWidget * widget, GladeButtonEditor * button_editor) { - GladeProperty *property; - GladeWidget *gchild = NULL; - GtkWidget *child, *button; - GValue value = { 0, }; - gboolean use_appearance = FALSE; - - if (button_editor->loading || !button_editor->loaded_widget) - return; - - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->standard_radio))) - return; - - button_editor->modifying = TRUE; - - glade_command_push_group (_("Setting %s to use standard configuration"), - button_editor->loaded_widget->name); - - /* If theres a widget customly inside... command remove it first... */ - button = GTK_WIDGET (button_editor->loaded_widget->object); - child = gtk_bin_get_child (GTK_BIN (button)); - if (child) - gchild = glade_widget_get_from_gobject (child); - - if (gchild && gchild->parent == button_editor->loaded_widget) - { - GList widgets = { 0, }; - widgets.data = gchild; - glade_command_delete (&widgets); - } - - property = glade_widget_get_property (button_editor->loaded_widget, "custom-child"); - glade_command_set_property (property, FALSE); - - /* Setup reasonable defaults for button label. */ - property = glade_widget_get_property (button_editor->loaded_widget, "stock"); - glade_command_set_property (property, NULL); - - property = glade_widget_get_property (button_editor->loaded_widget, "use-stock"); - glade_command_set_property (property, FALSE); - - glade_widget_property_get (button_editor->loaded_widget, "use-action-appearance", &use_appearance); - if (!use_appearance) - { - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - } - - glade_command_pop_group (); - - button_editor->modifying = FALSE; - - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + GladeProperty *property; + GladeWidget *gchild = NULL; + GtkWidget *child, *button; + GValue value = { 0, }; + gboolean use_appearance = FALSE; + + if (button_editor->loading || !button_editor->loaded_widget) + return; + + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->standard_radio))) + return; + + button_editor->modifying = TRUE; + + glade_command_push_group (_("Setting %s to use standard configuration"), + button_editor->loaded_widget->name); + + /* If theres a widget customly inside... command remove it first... */ + button = GTK_WIDGET (button_editor->loaded_widget->object); + child = gtk_bin_get_child (GTK_BIN (button)); + if (child) + gchild = glade_widget_get_from_gobject (child); + + if (gchild && gchild->parent == button_editor->loaded_widget) + { + GList widgets = { 0, }; + widgets.data = gchild; + glade_command_delete (&widgets); + } + + property = + glade_widget_get_property (button_editor->loaded_widget, "custom-child"); + glade_command_set_property (property, FALSE); + + /* Setup reasonable defaults for button label. */ + property = glade_widget_get_property (button_editor->loaded_widget, "stock"); + glade_command_set_property (property, NULL); + + property = + glade_widget_get_property (button_editor->loaded_widget, "use-stock"); + glade_command_set_property (property, FALSE); + + glade_widget_property_get (button_editor->loaded_widget, + "use-action-appearance", &use_appearance); + if (!use_appearance) + { + property = + glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + } + + glade_command_pop_group (); + + button_editor->modifying = FALSE; + + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -custom_toggled (GtkWidget *widget, - GladeButtonEditor *button_editor) +custom_toggled (GtkWidget * widget, GladeButtonEditor * button_editor) { - GladeProperty *property; + GladeProperty *property; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->custom_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->custom_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a custom child"), - button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a custom child"), + button_editor->loaded_widget->name); - /* clear out some things... */ - property = glade_widget_get_property (button_editor->loaded_widget, "image"); - glade_command_set_property (property, NULL); + /* clear out some things... */ + property = glade_widget_get_property (button_editor->loaded_widget, "image"); + glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "use-stock"); - glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (button_editor->loaded_widget, "use-stock"); + glade_command_set_property (property, FALSE); - property = glade_widget_get_property (button_editor->loaded_widget, "stock"); - glade_command_set_property (property, NULL); + property = glade_widget_get_property (button_editor->loaded_widget, "stock"); + glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_command_set_property (property, NULL); + property = glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_command_set_property (property, NULL); - /* Add a placeholder via the custom-child property... */ - property = glade_widget_get_property (button_editor->loaded_widget, "custom-child"); - glade_command_set_property (property, TRUE); + /* Add a placeholder via the custom-child property... */ + property = + glade_widget_get_property (button_editor->loaded_widget, "custom-child"); + glade_command_set_property (property, TRUE); - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -stock_toggled (GtkWidget *widget, - GladeButtonEditor *button_editor) +stock_toggled (GtkWidget * widget, GladeButtonEditor * button_editor) { - GladeProperty *property; - gboolean use_appearance = FALSE; + GladeProperty *property; + gboolean use_appearance = FALSE; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->stock_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->stock_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a stock button"), button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a stock button"), + button_editor->loaded_widget->name); - /* clear out stuff... */ - property = glade_widget_get_property (button_editor->loaded_widget, "image"); - glade_command_set_property (property, NULL); + /* clear out stuff... */ + property = glade_widget_get_property (button_editor->loaded_widget, "image"); + glade_command_set_property (property, NULL); - glade_widget_property_get (button_editor->loaded_widget, "use-action-appearance", &use_appearance); - if (!use_appearance) - { - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_command_set_property (property, ""); - } + glade_widget_property_get (button_editor->loaded_widget, + "use-action-appearance", &use_appearance); + if (!use_appearance) + { + property = + glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_command_set_property (property, ""); + } - property = glade_widget_get_property (button_editor->loaded_widget, "use-stock"); - glade_command_set_property (property, TRUE); + property = + glade_widget_get_property (button_editor->loaded_widget, "use-stock"); + glade_command_set_property (property, TRUE); - property = glade_widget_get_property (button_editor->loaded_widget, "stock"); - glade_command_set_property (property, NULL); + property = glade_widget_get_property (button_editor->loaded_widget, "stock"); + glade_command_set_property (property, NULL); - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -label_toggled (GtkWidget *widget, - GladeButtonEditor *button_editor) +label_toggled (GtkWidget * widget, GladeButtonEditor * button_editor) { - GladeProperty *property; - GValue value = { 0, }; - gboolean use_appearance = FALSE; + GladeProperty *property; + GValue value = { 0, }; + gboolean use_appearance = FALSE; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->label_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->label_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a label and image"), button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a label and image"), + button_editor->loaded_widget->name); - property = glade_widget_get_property (button_editor->loaded_widget, "stock"); - glade_command_set_property (property, NULL); + property = glade_widget_get_property (button_editor->loaded_widget, "stock"); + glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "use-stock"); - glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (button_editor->loaded_widget, "use-stock"); + glade_command_set_property (property, FALSE); - glade_widget_property_get (button_editor->loaded_widget, "use-action-appearance", &use_appearance); - if (!use_appearance) - { - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - } + glade_widget_property_get (button_editor->loaded_widget, + "use-action-appearance", &use_appearance); + if (!use_appearance) + { + property = + glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + } - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -table_attach (GtkWidget *table, - GtkWidget *child, - gint pos, gint row) +table_attach (GtkWidget * table, GtkWidget * child, gint pos, gint row) { - gtk_grid_attach (GTK_GRID (table), child, - pos, row, 1, 1); + gtk_grid_attach (GTK_GRID (table), child, pos, row, 1, 1); - if (pos) - gtk_widget_set_hexpand (child, TRUE); + if (pos) + gtk_widget_set_hexpand (child, TRUE); } GtkWidget * -glade_button_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_button_editor_new (GladeWidgetAdaptor * adaptor, GladeEditable * embed) { - GladeButtonEditor *button_editor; - GladeEditorProperty *eprop; - GtkWidget *vbox, *table, *frame; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - button_editor = g_object_new (GLADE_TYPE_BUTTON_EDITOR, NULL); - button_editor->embed = GTK_WIDGET (embed); - - button_editor->standard_radio = gtk_radio_button_new_with_label (NULL, _("Configure button content")); - button_editor->custom_radio = gtk_radio_button_new_with_label_from_widget - (GTK_RADIO_BUTTON (button_editor->standard_radio), _("Add custom button content")); - - button_editor->stock_radio = gtk_radio_button_new_with_label (NULL, _("Stock button")); - button_editor->label_radio = gtk_radio_button_new_with_label_from_widget - (GTK_RADIO_BUTTON (button_editor->stock_radio), _("Label with optional image")); - - g_signal_connect (G_OBJECT (button_editor->standard_radio), "toggled", - G_CALLBACK (standard_toggled), button_editor); - g_signal_connect (G_OBJECT (button_editor->custom_radio), "toggled", - G_CALLBACK (custom_toggled), button_editor); - g_signal_connect (G_OBJECT (button_editor->stock_radio), "toggled", - G_CALLBACK (stock_toggled), button_editor); - g_signal_connect (G_OBJECT (button_editor->label_radio), "toggled", - G_CALLBACK (label_toggled), button_editor); - - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (button_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - /* Standard frame... */ - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), button_editor->standard_radio); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 8); - - button_editor->standard_frame = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (button_editor->standard_frame), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), button_editor->standard_frame); - - vbox = gtk_vbox_new (FALSE, 8); - gtk_container_add (GTK_CONTAINER (button_editor->standard_frame), vbox); - - /* Populate stock frame here... */ - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_frame_set_label_widget (GTK_FRAME (frame), button_editor->stock_radio); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 4); - - button_editor->stock_frame = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (button_editor->stock_frame), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), button_editor->stock_frame); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (button_editor->stock_frame), table); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "stock", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "image-position", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - /* Populate label frame here... */ - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_frame_set_label_widget (GTK_FRAME (frame), button_editor->label_radio); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 4); - - button_editor->label_frame = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (button_editor->label_frame), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), button_editor->label_frame); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (button_editor->label_frame), table); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "use-underline", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "image", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 2); - table_attach (table, GTK_WIDGET (eprop), 1, 2); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "image-position", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 3); - table_attach (table, GTK_WIDGET (eprop), 1, 3); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - /* Custom radio button on the bottom */ - gtk_box_pack_start (GTK_BOX (button_editor), button_editor->custom_radio, FALSE, FALSE, 0); - - gtk_widget_show_all (GTK_WIDGET (button_editor)); - - return GTK_WIDGET (button_editor); + GladeButtonEditor *button_editor; + GladeEditorProperty *eprop; + GtkWidget *vbox, *table, *frame; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + button_editor = g_object_new (GLADE_TYPE_BUTTON_EDITOR, NULL); + button_editor->embed = GTK_WIDGET (embed); + + button_editor->standard_radio = + gtk_radio_button_new_with_label (NULL, _("Configure button content")); + button_editor->custom_radio = + gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON + (button_editor-> + standard_radio), + _ + ("Add custom button content")); + + button_editor->stock_radio = + gtk_radio_button_new_with_label (NULL, _("Stock button")); + button_editor->label_radio = + gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON + (button_editor->stock_radio), + _ + ("Label with optional image")); + + g_signal_connect (G_OBJECT (button_editor->standard_radio), "toggled", + G_CALLBACK (standard_toggled), button_editor); + g_signal_connect (G_OBJECT (button_editor->custom_radio), "toggled", + G_CALLBACK (custom_toggled), button_editor); + g_signal_connect (G_OBJECT (button_editor->stock_radio), "toggled", + G_CALLBACK (stock_toggled), button_editor); + g_signal_connect (G_OBJECT (button_editor->label_radio), "toggled", + G_CALLBACK (label_toggled), button_editor); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (button_editor), GTK_WIDGET (embed), FALSE, FALSE, + 0); + + /* Standard frame... */ + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), button_editor->standard_radio); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 8); + + button_editor->standard_frame = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (button_editor->standard_frame), 6, + 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), button_editor->standard_frame); + + vbox = gtk_vbox_new (FALSE, 8); + gtk_container_add (GTK_CONTAINER (button_editor->standard_frame), vbox); + + /* Populate stock frame here... */ + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_frame_set_label_widget (GTK_FRAME (frame), button_editor->stock_radio); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 4); + + button_editor->stock_frame = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (button_editor->stock_frame), 6, 0, + 12, 0); + gtk_container_add (GTK_CONTAINER (frame), button_editor->stock_frame); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (button_editor->stock_frame), table); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "stock", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "image-position", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + /* Populate label frame here... */ + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_frame_set_label_widget (GTK_FRAME (frame), button_editor->label_radio); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 4); + + button_editor->label_frame = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (button_editor->label_frame), 6, 0, + 12, 0); + gtk_container_add (GTK_CONTAINER (frame), button_editor->label_frame); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (button_editor->label_frame), table); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "use-underline", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "image", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 2); + table_attach (table, GTK_WIDGET (eprop), 1, 2); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "image-position", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 3); + table_attach (table, GTK_WIDGET (eprop), 1, 3); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + /* Custom radio button on the bottom */ + gtk_box_pack_start (GTK_BOX (button_editor), button_editor->custom_radio, + FALSE, FALSE, 0); + + gtk_widget_show_all (GTK_WIDGET (button_editor)); + + return GTK_WIDGET (button_editor); } diff --git a/plugins/gtk+/glade-button-editor.h b/plugins/gtk+/glade-button-editor.h index e4544ad6..837c4c5d 100644 --- a/plugins/gtk+/glade-button-editor.h +++ b/plugins/gtk+/glade-button-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-cell-renderer-editor.c b/plugins/gtk+/glade-cell-renderer-editor.c index ac7811eb..9b2ac733 100644 --- a/plugins/gtk+/glade-cell-renderer-editor.c +++ b/plugins/gtk+/glade-cell-renderer-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -29,387 +28,423 @@ #include "glade-column-types.h" -static void glade_cell_renderer_editor_finalize (GObject *object); +static void glade_cell_renderer_editor_finalize (GObject * object); -static void glade_cell_renderer_editor_editable_init (GladeEditableIface *iface); +static void glade_cell_renderer_editor_editable_init (GladeEditableIface * + iface); -static void glade_cell_renderer_editor_grab_focus (GtkWidget *widget); +static void glade_cell_renderer_editor_grab_focus (GtkWidget * widget); -typedef struct { - GladeCellRendererEditor *editor; +typedef struct +{ + GladeCellRendererEditor *editor; - GtkWidget *attributes_check; - GladePropertyClass *pclass; - GladePropertyClass *attr_pclass; - GladePropertyClass *use_attr_pclass; + GtkWidget *attributes_check; + GladePropertyClass *pclass; + GladePropertyClass *attr_pclass; + GladePropertyClass *use_attr_pclass; - GtkWidget *use_prop_label; - GtkWidget *use_attr_label; - GtkWidget *use_prop_eprop; - GtkWidget *use_attr_eprop; + GtkWidget *use_prop_label; + GtkWidget *use_attr_label; + GtkWidget *use_prop_eprop; + GtkWidget *use_attr_eprop; } CheckTab; -G_DEFINE_TYPE_WITH_CODE (GladeCellRendererEditor, glade_cell_renderer_editor, GTK_TYPE_VBOX, +G_DEFINE_TYPE_WITH_CODE (GladeCellRendererEditor, glade_cell_renderer_editor, + GTK_TYPE_VBOX, G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_cell_renderer_editor_editable_init)); static void -glade_cell_renderer_editor_class_init (GladeCellRendererEditorClass *klass) +glade_cell_renderer_editor_class_init (GladeCellRendererEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_cell_renderer_editor_finalize; - widget_class->grab_focus = glade_cell_renderer_editor_grab_focus; + object_class->finalize = glade_cell_renderer_editor_finalize; + widget_class->grab_focus = glade_cell_renderer_editor_grab_focus; } static void -glade_cell_renderer_editor_init (GladeCellRendererEditor *self) +glade_cell_renderer_editor_init (GladeCellRendererEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeCellRendererEditor *renderer_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeCellRendererEditor * renderer_editor) { - if (renderer_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (renderer_editor))) - return; + if (renderer_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (renderer_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (renderer_editor), renderer_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (renderer_editor), + renderer_editor->loaded_widget); } static void -project_finalized (GladeCellRendererEditor *renderer_editor, - GladeProject *where_project_was) +project_finalized (GladeCellRendererEditor * renderer_editor, + GladeProject * where_project_was) { - renderer_editor->loaded_widget = NULL; + renderer_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (renderer_editor), NULL); + glade_editable_load (GLADE_EDITABLE (renderer_editor), NULL); } static void -glade_cell_renderer_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_cell_renderer_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeCellRendererEditor *renderer_editor = GLADE_CELL_RENDERER_EDITOR (editable); - GList *l; - - renderer_editor->loading = TRUE; - - /* Since we watch the project*/ - if (renderer_editor->loaded_widget) - { - g_signal_handlers_disconnect_by_func (G_OBJECT (renderer_editor->loaded_widget->project), - G_CALLBACK (project_changed), renderer_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (renderer_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - renderer_editor); - } - - /* Mark our widget... */ - renderer_editor->loaded_widget = widget; - - if (renderer_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (renderer_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), renderer_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (renderer_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - renderer_editor); - } - - /* load the embedded editable... */ - if (renderer_editor->embed) - glade_editable_load (GLADE_EDITABLE (renderer_editor->embed), widget); - - for (l = renderer_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - if (widget) - { - for (l = renderer_editor->checks; l; l = l->next) - { - CheckTab *tab = l->data; - gboolean use_attr = FALSE; - - glade_widget_property_get (widget, tab->use_attr_pclass->id, &use_attr); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tab->attributes_check), use_attr); - - - if (use_attr) - { - // gtk_widget_show (tab->use_attr_label); - gtk_widget_show (tab->use_attr_eprop); - //gtk_widget_hide (tab->use_prop_label); - gtk_widget_hide (tab->use_prop_eprop); - } - else - { - gtk_widget_show (tab->use_prop_label); - gtk_widget_show (tab->use_prop_eprop); - gtk_widget_hide (tab->use_attr_label); - gtk_widget_hide (tab->use_attr_eprop); - } - } - } - renderer_editor->loading = FALSE; + GladeCellRendererEditor *renderer_editor = + GLADE_CELL_RENDERER_EDITOR (editable); + GList *l; + + renderer_editor->loading = TRUE; + + /* Since we watch the project */ + if (renderer_editor->loaded_widget) + { + g_signal_handlers_disconnect_by_func (G_OBJECT + (renderer_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + renderer_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (renderer_editor->loaded_widget->project), + (GWeakNotify) project_finalized, renderer_editor); + } + + /* Mark our widget... */ + renderer_editor->loaded_widget = widget; + + if (renderer_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (renderer_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), + renderer_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (renderer_editor->loaded_widget->project), + (GWeakNotify) project_finalized, renderer_editor); + } + + /* load the embedded editable... */ + if (renderer_editor->embed) + glade_editable_load (GLADE_EDITABLE (renderer_editor->embed), widget); + + for (l = renderer_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + if (widget) + { + for (l = renderer_editor->checks; l; l = l->next) + { + CheckTab *tab = l->data; + gboolean use_attr = FALSE; + + glade_widget_property_get (widget, tab->use_attr_pclass->id, + &use_attr); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (tab->attributes_check), use_attr); + + + if (use_attr) + { + // gtk_widget_show (tab->use_attr_label); + gtk_widget_show (tab->use_attr_eprop); + //gtk_widget_hide (tab->use_prop_label); + gtk_widget_hide (tab->use_prop_eprop); + } + else + { + gtk_widget_show (tab->use_prop_label); + gtk_widget_show (tab->use_prop_eprop); + gtk_widget_hide (tab->use_attr_label); + gtk_widget_hide (tab->use_attr_eprop); + } + } + } + renderer_editor->loading = FALSE; } static void -glade_cell_renderer_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_cell_renderer_editor_set_show_name (GladeEditable * editable, + gboolean show_name) { - GladeCellRendererEditor *renderer_editor = GLADE_CELL_RENDERER_EDITOR (editable); + GladeCellRendererEditor *renderer_editor = + GLADE_CELL_RENDERER_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (renderer_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (renderer_editor->embed), + show_name); } static void -glade_cell_renderer_editor_editable_init (GladeEditableIface *iface) +glade_cell_renderer_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_cell_renderer_editor_load; - iface->set_show_name = glade_cell_renderer_editor_set_show_name; + iface->load = glade_cell_renderer_editor_load; + iface->set_show_name = glade_cell_renderer_editor_set_show_name; } static void -glade_cell_renderer_editor_finalize (GObject *object) +glade_cell_renderer_editor_finalize (GObject * object) { - GladeCellRendererEditor *renderer_editor = GLADE_CELL_RENDERER_EDITOR (object); + GladeCellRendererEditor *renderer_editor = + GLADE_CELL_RENDERER_EDITOR (object); - g_list_foreach (renderer_editor->checks, (GFunc)g_free, NULL); - g_list_free (renderer_editor->checks); - g_list_free (renderer_editor->properties); + g_list_foreach (renderer_editor->checks, (GFunc) g_free, NULL); + g_list_free (renderer_editor->checks); + g_list_free (renderer_editor->properties); - renderer_editor->properties = NULL; - renderer_editor->checks = NULL; - renderer_editor->embed = NULL; + renderer_editor->properties = NULL; + renderer_editor->checks = NULL; + renderer_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_cell_renderer_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_cell_renderer_editor_parent_class)->finalize (object); } static void -glade_cell_renderer_editor_grab_focus (GtkWidget *widget) +glade_cell_renderer_editor_grab_focus (GtkWidget * widget) { - GladeCellRendererEditor *renderer_editor = GLADE_CELL_RENDERER_EDITOR (widget); + GladeCellRendererEditor *renderer_editor = + GLADE_CELL_RENDERER_EDITOR (widget); - gtk_widget_grab_focus (renderer_editor->embed); + gtk_widget_grab_focus (renderer_editor->embed); } static void -attributes_toggled (GtkWidget *widget, - CheckTab *tab) +attributes_toggled (GtkWidget * widget, CheckTab * tab) { - GladeCellRendererEditor *renderer_editor = tab->editor; - GladeProperty *property; - GValue value = { 0, }; - - if (renderer_editor->loading || !renderer_editor->loaded_widget) - return; - - renderer_editor->modifying = TRUE; - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tab->attributes_check))) - { - - glade_command_push_group (_("Setting %s to use the %s property as an attribute"), - renderer_editor->loaded_widget->name, tab->pclass->id); - - - property = glade_widget_get_property (renderer_editor->loaded_widget, tab->pclass->id); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - - property = glade_widget_get_property (renderer_editor->loaded_widget, tab->use_attr_pclass->id); - glade_command_set_property (property, TRUE); - - glade_command_pop_group (); - - - } - else - { - glade_command_push_group (_("Setting %s to use the %s property directly"), - renderer_editor->loaded_widget->name, tab->pclass->id); - - - property = glade_widget_get_property (renderer_editor->loaded_widget, tab->attr_pclass->id); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - - property = glade_widget_get_property (renderer_editor->loaded_widget, tab->use_attr_pclass->id); - glade_command_set_property (property, FALSE); - - glade_command_pop_group (); - } - renderer_editor->modifying = FALSE; - - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (renderer_editor), - renderer_editor->loaded_widget); -} - -static gint -property_class_comp (gconstpointer a, gconstpointer b) -{ - const GladePropertyClass *ca = a, *cb = b; - - if (ca->pspec->owner_type == cb->pspec->owner_type) - { - gdouble result = ca->weight - cb->weight; - /* Avoid cast to int */ - if (result < 0.0) return -1; - else if (result > 0.0) return 1; - else return 0; - } - else - { - if (g_type_is_a (ca->pspec->owner_type, cb->pspec->owner_type)) - return (ca->common || ca->packing) ? 1 : -1; - else - return (ca->common || ca->packing) ? -1 : 1; - } -} - -static GList * -get_sorted_properties (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) -{ - GList *l, *list = NULL; - - for (l = adaptor->properties; l; l = g_list_next (l)) - { - GladePropertyClass *klass = l->data; - - if (GLADE_PROPERTY_CLASS_IS_TYPE (klass, type) && - (glade_property_class_is_visible (klass))) - { - list = g_list_prepend (list, klass); - } - } - return g_list_sort (list, property_class_comp); -} - - -GtkWidget * -glade_cell_renderer_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type, - GladeEditable *embed) -{ - GladeCellRendererEditor *renderer_editor; - GladeEditorProperty *eprop; - GladePropertyClass *pclass, *attr_pclass, *use_attr_pclass; - GList *list, *sorted; - GtkWidget *hbox_left, *hbox_right, *grid; - gchar *str; - gint row = 0; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + GladeCellRendererEditor *renderer_editor = tab->editor; + GladeProperty *property; + GValue value = { 0, }; - renderer_editor = g_object_new (GLADE_TYPE_CELL_RENDERER_EDITOR, NULL); - renderer_editor->embed = GTK_WIDGET (embed); + if (renderer_editor->loading || !renderer_editor->loaded_widget) + return; - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (renderer_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); + renderer_editor->modifying = TRUE; - /* Next pack in a grid for all the renderers */ - grid = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (grid), 4); - gtk_box_pack_start (GTK_BOX (renderer_editor), grid, FALSE, FALSE, 0); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tab->attributes_check))) + { - sorted = get_sorted_properties (adaptor, type); + glade_command_push_group (_ + ("Setting %s to use the %s property as an attribute"), + renderer_editor->loaded_widget->name, + tab->pclass->id); - /* For each normal property, if we have an attr- and use-attr- counterpart, load - * a check button property pair into the table... - */ - for (list = sorted; list; list = list->next) - { - gchar *attr_name; - gchar *use_attr_name; - pclass = list->data; + property = + glade_widget_get_property (renderer_editor->loaded_widget, + tab->pclass->id); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); - if (pclass->virt) - continue; + property = + glade_widget_get_property (renderer_editor->loaded_widget, + tab->use_attr_pclass->id); + glade_command_set_property (property, TRUE); - attr_name = g_strdup_printf ("attr-%s", pclass->id); - use_attr_name = g_strdup_printf ("use-attr-%s", pclass->id); + glade_command_pop_group (); - attr_pclass = glade_widget_adaptor_get_property_class (adaptor, attr_name); - use_attr_pclass = glade_widget_adaptor_get_property_class (adaptor, use_attr_name); - if (attr_pclass && use_attr_pclass) - { - CheckTab *tab = g_new0 (CheckTab, 1); + } + else + { + glade_command_push_group (_("Setting %s to use the %s property directly"), + renderer_editor->loaded_widget->name, + tab->pclass->id); - tab->editor = renderer_editor; - tab->pclass = pclass; - tab->attr_pclass = attr_pclass; - tab->use_attr_pclass = use_attr_pclass; - /* Label appearance... */ - hbox_left = gtk_hbox_new (FALSE, 0); - hbox_right = gtk_hbox_new (FALSE, 0); - gtk_widget_set_hexpand (hbox_right, TRUE); + property = + glade_widget_get_property (renderer_editor->loaded_widget, + tab->attr_pclass->id); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); - tab->attributes_check = gtk_check_button_new (); - str = g_strdup_printf (_("Retrieve %s from model (type %s)"), - pclass->name, g_type_name (pclass->pspec->value_type)); - gtk_widget_set_tooltip_text (tab->attributes_check, str); - g_free (str); + property = + glade_widget_get_property (renderer_editor->loaded_widget, + tab->use_attr_pclass->id); + glade_command_set_property (property, FALSE); - gtk_box_pack_start (GTK_BOX (hbox_left), tab->attributes_check, FALSE, FALSE, 4); + glade_command_pop_group (); + } + renderer_editor->modifying = FALSE; - /* Edit property */ - eprop = glade_widget_adaptor_create_eprop (adaptor, pclass, TRUE); - gtk_box_pack_start (GTK_BOX (hbox_left), eprop->item_label, TRUE, TRUE, 4); - gtk_box_pack_start (GTK_BOX (hbox_right), GTK_WIDGET (eprop), FALSE, FALSE, 4); - renderer_editor->properties = g_list_prepend (renderer_editor->properties, eprop); - - tab->use_prop_label = eprop->item_label; - tab->use_prop_eprop = GTK_WIDGET (eprop); - - /* Edit attribute */ - eprop = glade_widget_adaptor_create_eprop (adaptor, attr_pclass, TRUE); - gtk_box_pack_start (GTK_BOX (hbox_right), GTK_WIDGET (eprop), FALSE, FALSE, 4); - renderer_editor->properties = g_list_prepend (renderer_editor->properties, eprop); - - gtk_grid_attach (GTK_GRID (grid), hbox_left, 0, row, 1, 1); - gtk_grid_attach (GTK_GRID (grid), hbox_right, 1, row++, 1, 1); - - tab->use_attr_label = eprop->item_label; - tab->use_attr_eprop = GTK_WIDGET (eprop); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (renderer_editor), + renderer_editor->loaded_widget); +} - g_signal_connect (G_OBJECT (tab->attributes_check), "toggled", - G_CALLBACK (attributes_toggled), tab); +static gint +property_class_comp (gconstpointer a, gconstpointer b) +{ + const GladePropertyClass *ca = a, *cb = b; + + if (ca->pspec->owner_type == cb->pspec->owner_type) + { + gdouble result = ca->weight - cb->weight; + /* Avoid cast to int */ + if (result < 0.0) + return -1; + else if (result > 0.0) + return 1; + else + return 0; + } + else + { + if (g_type_is_a (ca->pspec->owner_type, cb->pspec->owner_type)) + return (ca->common || ca->packing) ? 1 : -1; + else + return (ca->common || ca->packing) ? -1 : 1; + } +} - renderer_editor->checks = g_list_prepend (renderer_editor->checks, tab); - } - g_free (attr_name); - g_free (use_attr_name); - } - g_list_free (sorted); +static GList * +get_sorted_properties (GladeWidgetAdaptor * adaptor, GladeEditorPageType type) +{ + GList *l, *list = NULL; + + for (l = adaptor->properties; l; l = g_list_next (l)) + { + GladePropertyClass *klass = l->data; + + if (GLADE_PROPERTY_CLASS_IS_TYPE (klass, type) && + (glade_property_class_is_visible (klass))) + { + list = g_list_prepend (list, klass); + } + } + return g_list_sort (list, property_class_comp); +} - gtk_widget_show_all (GTK_WIDGET (renderer_editor)); - return GTK_WIDGET (renderer_editor); +GtkWidget * +glade_cell_renderer_editor_new (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type, GladeEditable * embed) +{ + GladeCellRendererEditor *renderer_editor; + GladeEditorProperty *eprop; + GladePropertyClass *pclass, *attr_pclass, *use_attr_pclass; + GList *list, *sorted; + GtkWidget *hbox_left, *hbox_right, *grid; + gchar *str; + gint row = 0; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + renderer_editor = g_object_new (GLADE_TYPE_CELL_RENDERER_EDITOR, NULL); + renderer_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (renderer_editor), GTK_WIDGET (embed), FALSE, + FALSE, 0); + + /* Next pack in a grid for all the renderers */ + grid = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (grid), 4); + gtk_box_pack_start (GTK_BOX (renderer_editor), grid, FALSE, FALSE, 0); + + sorted = get_sorted_properties (adaptor, type); + + /* For each normal property, if we have an attr- and use-attr- counterpart, load + * a check button property pair into the table... + */ + for (list = sorted; list; list = list->next) + { + gchar *attr_name; + gchar *use_attr_name; + + pclass = list->data; + + if (pclass->virt) + continue; + + attr_name = g_strdup_printf ("attr-%s", pclass->id); + use_attr_name = g_strdup_printf ("use-attr-%s", pclass->id); + + attr_pclass = + glade_widget_adaptor_get_property_class (adaptor, attr_name); + use_attr_pclass = + glade_widget_adaptor_get_property_class (adaptor, use_attr_name); + + if (attr_pclass && use_attr_pclass) + { + CheckTab *tab = g_new0 (CheckTab, 1); + + tab->editor = renderer_editor; + tab->pclass = pclass; + tab->attr_pclass = attr_pclass; + tab->use_attr_pclass = use_attr_pclass; + + /* Label appearance... */ + hbox_left = gtk_hbox_new (FALSE, 0); + hbox_right = gtk_hbox_new (FALSE, 0); + gtk_widget_set_hexpand (hbox_right, TRUE); + + tab->attributes_check = gtk_check_button_new (); + str = g_strdup_printf (_("Retrieve %s from model (type %s)"), + pclass->name, + g_type_name (pclass->pspec->value_type)); + gtk_widget_set_tooltip_text (tab->attributes_check, str); + g_free (str); + + gtk_box_pack_start (GTK_BOX (hbox_left), tab->attributes_check, FALSE, + FALSE, 4); + + /* Edit property */ + eprop = glade_widget_adaptor_create_eprop (adaptor, pclass, TRUE); + gtk_box_pack_start (GTK_BOX (hbox_left), eprop->item_label, TRUE, + TRUE, 4); + gtk_box_pack_start (GTK_BOX (hbox_right), GTK_WIDGET (eprop), FALSE, + FALSE, 4); + renderer_editor->properties = + g_list_prepend (renderer_editor->properties, eprop); + + tab->use_prop_label = eprop->item_label; + tab->use_prop_eprop = GTK_WIDGET (eprop); + + /* Edit attribute */ + eprop = + glade_widget_adaptor_create_eprop (adaptor, attr_pclass, TRUE); + gtk_box_pack_start (GTK_BOX (hbox_right), GTK_WIDGET (eprop), FALSE, + FALSE, 4); + renderer_editor->properties = + g_list_prepend (renderer_editor->properties, eprop); + + gtk_grid_attach (GTK_GRID (grid), hbox_left, 0, row, 1, 1); + gtk_grid_attach (GTK_GRID (grid), hbox_right, 1, row++, 1, 1); + + tab->use_attr_label = eprop->item_label; + tab->use_attr_eprop = GTK_WIDGET (eprop); + + g_signal_connect (G_OBJECT (tab->attributes_check), "toggled", + G_CALLBACK (attributes_toggled), tab); + + renderer_editor->checks = + g_list_prepend (renderer_editor->checks, tab); + } + g_free (attr_name); + g_free (use_attr_name); + } + g_list_free (sorted); + + gtk_widget_show_all (GTK_WIDGET (renderer_editor)); + + return GTK_WIDGET (renderer_editor); } /*************************************************************************** @@ -417,12 +452,12 @@ glade_cell_renderer_editor_new (GladeWidgetAdaptor *adaptor, ***************************************************************************/ typedef struct { - GladeEditorProperty parent_instance; + GladeEditorProperty parent_instance; - GtkTreeModel *columns; + GtkTreeModel *columns; - GtkWidget *spin; - GtkWidget *combo; + GtkWidget *spin; + GtkWidget *combo; } GladeEPropCellAttribute; GLADE_MAKE_EPROP (GladeEPropCellAttribute, glade_eprop_cell_attribute) @@ -431,186 +466,188 @@ GLADE_MAKE_EPROP (GladeEPropCellAttribute, glade_eprop_cell_attribute) #define GLADE_IS_EPROP_CELL_ATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_CELL_ATTRIBUTE)) #define GLADE_IS_EPROP_CELL_ATTRIBUTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_CELL_ATTRIBUTE)) #define GLADE_EPROP_CELL_ATTRIBUTE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_CELL_ATTRIBUTE, GladeEPropCellAttributeClass)) - -static void -glade_eprop_cell_attribute_finalize (GObject *object) + static void glade_eprop_cell_attribute_finalize (GObject * object) { - /* Chain up */ - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); - //GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (object); + /* Chain up */ + GObjectClass *parent_class = + g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); + //GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (object); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); } GladeWidget * -glade_cell_renderer_get_model (GladeWidget *renderer) +glade_cell_renderer_get_model (GladeWidget * renderer) { - GladeWidget *model = NULL; - - /* Keep inline with all new cell layouts !!! */ - if (renderer->parent && GTK_IS_TREE_VIEW_COLUMN (renderer->parent->object)) - { - GladeWidget *column = renderer->parent; - - if (column->parent && GTK_IS_TREE_VIEW (column->parent->object)) - { - GladeWidget *view = column->parent; - GtkTreeModel *real_model = NULL; - glade_widget_property_get (view, "model", &real_model); - if (real_model) - model = glade_widget_get_from_gobject (real_model); - } - } - else if (renderer->parent && GTK_IS_ICON_VIEW (renderer->parent->object)) - { - GladeWidget *view = renderer->parent; - GtkTreeModel *real_model = NULL; - glade_widget_property_get (view, "model", &real_model); - if (real_model) - model = glade_widget_get_from_gobject (real_model); - } - else if (renderer->parent && GTK_IS_COMBO_BOX (renderer->parent->object)) - { - GladeWidget *combo = renderer->parent; - GtkTreeModel *real_model = NULL; - glade_widget_property_get (combo, "model", &real_model); - if (real_model) - model = glade_widget_get_from_gobject (real_model); - } - - return model; + GladeWidget *model = NULL; + + /* Keep inline with all new cell layouts !!! */ + if (renderer->parent && GTK_IS_TREE_VIEW_COLUMN (renderer->parent->object)) + { + GladeWidget *column = renderer->parent; + + if (column->parent && GTK_IS_TREE_VIEW (column->parent->object)) + { + GladeWidget *view = column->parent; + GtkTreeModel *real_model = NULL; + glade_widget_property_get (view, "model", &real_model); + if (real_model) + model = glade_widget_get_from_gobject (real_model); + } + } + else if (renderer->parent && GTK_IS_ICON_VIEW (renderer->parent->object)) + { + GladeWidget *view = renderer->parent; + GtkTreeModel *real_model = NULL; + glade_widget_property_get (view, "model", &real_model); + if (real_model) + model = glade_widget_get_from_gobject (real_model); + } + else if (renderer->parent && GTK_IS_COMBO_BOX (renderer->parent->object)) + { + GladeWidget *combo = renderer->parent; + GtkTreeModel *real_model = NULL; + glade_widget_property_get (combo, "model", &real_model); + if (real_model) + model = glade_widget_get_from_gobject (real_model); + } + + return model; } static void -glade_eprop_cell_attribute_load (GladeEditorProperty *eprop, - GladeProperty *property) +glade_eprop_cell_attribute_load (GladeEditorProperty * eprop, + GladeProperty * property) { - GladeEditorPropertyClass *parent_class = - g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); - GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (eprop); - - /* Chain up in a clean state... */ - parent_class->load (eprop, property); - - if (property) - { - GladeWidget *gmodel; - GtkListStore *store = GTK_LIST_STORE (eprop_attribute->columns); - GtkTreeIter iter; - - gtk_list_store_clear (store); - - /* Generate model and set active iter */ - if ((gmodel = glade_cell_renderer_get_model (property->widget)) != NULL) - { - GList *columns = NULL, *l; - - glade_widget_property_get (gmodel, "columns", &columns); - - gtk_list_store_append (store, &iter); - /* translators: the adjective not the verb */ - gtk_list_store_set (store, &iter, 0, _("unset"), -1); - - for (l = columns; l; l = l->next) - { - GladeColumnType *column = l->data; - gchar *str = g_strdup_printf ("%s - %s", column->column_name, - column->type_name); - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, str, -1); - - g_free (str); - } - - gtk_combo_box_set_active (GTK_COMBO_BOX (eprop_attribute->combo), - CLAMP (g_value_get_int (property->value) + 1, - 0, g_list_length (columns) + 1)); - - gtk_widget_set_sensitive (eprop_attribute->combo, TRUE); - } - else - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, _("no model"), -1); - gtk_combo_box_set_active (GTK_COMBO_BOX (eprop_attribute->combo), 0); - gtk_widget_set_sensitive (eprop_attribute->combo, FALSE); - } - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_attribute->spin), - (gdouble)g_value_get_int (property->value)); - } + GladeEditorPropertyClass *parent_class = + g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); + GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (eprop); + + /* Chain up in a clean state... */ + parent_class->load (eprop, property); + + if (property) + { + GladeWidget *gmodel; + GtkListStore *store = GTK_LIST_STORE (eprop_attribute->columns); + GtkTreeIter iter; + + gtk_list_store_clear (store); + + /* Generate model and set active iter */ + if ((gmodel = glade_cell_renderer_get_model (property->widget)) != NULL) + { + GList *columns = NULL, *l; + + glade_widget_property_get (gmodel, "columns", &columns); + + gtk_list_store_append (store, &iter); + /* translators: the adjective not the verb */ + gtk_list_store_set (store, &iter, 0, _("unset"), -1); + + for (l = columns; l; l = l->next) + { + GladeColumnType *column = l->data; + gchar *str = g_strdup_printf ("%s - %s", column->column_name, + column->type_name); + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, str, -1); + + g_free (str); + } + + gtk_combo_box_set_active (GTK_COMBO_BOX (eprop_attribute->combo), + CLAMP (g_value_get_int (property->value) + + 1, 0, g_list_length (columns) + 1)); + + gtk_widget_set_sensitive (eprop_attribute->combo, TRUE); + } + else + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, _("no model"), -1); + gtk_combo_box_set_active (GTK_COMBO_BOX (eprop_attribute->combo), 0); + gtk_widget_set_sensitive (eprop_attribute->combo, FALSE); + } + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_attribute->spin), + (gdouble) g_value_get_int (property->value)); + } } static void -combo_changed (GtkWidget *combo, - GladeEditorProperty *eprop) +combo_changed (GtkWidget * combo, GladeEditorProperty * eprop) { - GValue val = { 0, }; + GValue val = { 0, }; - if (eprop->loading) return; + if (eprop->loading) + return; - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, (gint)gtk_combo_box_get_active (GTK_COMBO_BOX (combo)) - 1); - glade_editor_property_commit (eprop, &val); - g_value_unset (&val); + g_value_init (&val, G_TYPE_INT); + g_value_set_int (&val, + (gint) gtk_combo_box_get_active (GTK_COMBO_BOX (combo)) - 1); + glade_editor_property_commit (eprop, &val); + g_value_unset (&val); } static void -spin_changed (GtkWidget *spin, - GladeEditorProperty *eprop) +spin_changed (GtkWidget * spin, GladeEditorProperty * eprop) { - GValue val = { 0, }; + GValue val = { 0, }; - if (eprop->loading) return; + if (eprop->loading) + return; - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin))); - glade_editor_property_commit (eprop, &val); - g_value_unset (&val); + g_value_init (&val, G_TYPE_INT); + g_value_set_int (&val, gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin))); + glade_editor_property_commit (eprop, &val); + g_value_unset (&val); } static GtkWidget * -glade_eprop_cell_attribute_create_input (GladeEditorProperty *eprop) +glade_eprop_cell_attribute_create_input (GladeEditorProperty * eprop) { - GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (eprop); - GtkWidget *hbox; - GtkAdjustment *adjustment; - GtkCellRenderer *cell; + GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (eprop); + GtkWidget *hbox; + GtkAdjustment *adjustment; + GtkCellRenderer *cell; - hbox = gtk_hbox_new (FALSE, 2); + hbox = gtk_hbox_new (FALSE, 2); - adjustment = glade_property_class_make_adjustment (eprop->klass); - eprop_attribute->spin = gtk_spin_button_new (adjustment, 1.0, 0); + adjustment = glade_property_class_make_adjustment (eprop->klass); + eprop_attribute->spin = gtk_spin_button_new (adjustment, 1.0, 0); - eprop_attribute->columns = (GtkTreeModel *)gtk_list_store_new (1, G_TYPE_STRING); - eprop_attribute->combo = gtk_combo_box_new_with_model (eprop_attribute->columns); + eprop_attribute->columns = + (GtkTreeModel *) gtk_list_store_new (1, G_TYPE_STRING); + eprop_attribute->combo = + gtk_combo_box_new_with_model (eprop_attribute->columns); - gtk_combo_box_set_popup_fixed_width (GTK_COMBO_BOX (eprop_attribute->combo), FALSE); + gtk_combo_box_set_popup_fixed_width (GTK_COMBO_BOX (eprop_attribute->combo), + FALSE); - /* Add cell renderer */ - cell = gtk_cell_renderer_text_new (); - g_object_set (cell, - "xpad", 0, - "xalign", 0.0F, - "ellipsize", PANGO_ELLIPSIZE_END, - "width-chars", 10, - NULL); + /* Add cell renderer */ + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, + "xpad", 0, + "xalign", 0.0F, + "ellipsize", PANGO_ELLIPSIZE_END, "width-chars", 10, NULL); - gtk_cell_layout_clear (GTK_CELL_LAYOUT (eprop_attribute->combo)); + gtk_cell_layout_clear (GTK_CELL_LAYOUT (eprop_attribute->combo)); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (eprop_attribute->combo), cell, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (eprop_attribute->combo), cell, - "text", 0, NULL); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (eprop_attribute->combo), cell, + TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (eprop_attribute->combo), + cell, "text", 0, NULL); - gtk_box_pack_start (GTK_BOX (hbox), eprop_attribute->spin, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), eprop_attribute->combo, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), eprop_attribute->spin, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), eprop_attribute->combo, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (eprop_attribute->combo), "changed", - G_CALLBACK (combo_changed), eprop); - g_signal_connect (G_OBJECT (eprop_attribute->spin), "value-changed", - G_CALLBACK (spin_changed), eprop); + g_signal_connect (G_OBJECT (eprop_attribute->combo), "changed", + G_CALLBACK (combo_changed), eprop); + g_signal_connect (G_OBJECT (eprop_attribute->spin), "value-changed", + G_CALLBACK (spin_changed), eprop); - return hbox; + return hbox; } diff --git a/plugins/gtk+/glade-cell-renderer-editor.h b/plugins/gtk+/glade-cell-renderer-editor.h index 5d963496..da9f8423 100644 --- a/plugins/gtk+/glade-cell-renderer-editor.h +++ b/plugins/gtk+/glade-cell-renderer-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-column-types.c b/plugins/gtk+/glade-column-types.c index 3d884b06..6ddd1c61 100644 --- a/plugins/gtk+/glade-column-types.c +++ b/plugins/gtk+/glade-column-types.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Juan Pablo Ugarte. * @@ -34,205 +33,214 @@ enum { - COLUMN_NAME, - COLUMN_COLUMN_NAME, - COLUMN_TYPE_EDITABLE, - COLUMN_NAME_EDITABLE, - COLUMN_TYPE_FOREGROUND, - COLUMN_TYPE_STYLE, - N_COLUMNS + COLUMN_NAME, + COLUMN_COLUMN_NAME, + COLUMN_TYPE_EDITABLE, + COLUMN_NAME_EDITABLE, + COLUMN_TYPE_FOREGROUND, + COLUMN_TYPE_STYLE, + N_COLUMNS }; static GtkTreeModel *types_model = NULL; -static gint -find_by_type_name (const gchar *a, const gchar *b) +static gint +find_by_type_name (const gchar * a, const gchar * b) { - return strcmp (a, b); + return strcmp (a, b); } static void -column_types_store_populate_enums_flags (GtkListStore *store, - gboolean enums) -{ - GtkTreeIter iter; - GList *types = NULL, *list, *l; - GList *adaptors = glade_widget_adaptor_list_adaptors (); - - for (list = adaptors; list; list = list->next) - { - GladeWidgetAdaptor *adaptor = list->data; - GladePropertyClass *pclass; - - for (l = adaptor->properties; l; l = l->next) - { - pclass = l->data; - - /* special case out a few of these... */ - if (strcmp (g_type_name (pclass->pspec->value_type), "GladeGtkGnomeUIInfo") == 0 || - strcmp (g_type_name (pclass->pspec->value_type), "GladeStock") == 0 || - strcmp (g_type_name (pclass->pspec->value_type), "GladeStockImage") == 0 || - strcmp (g_type_name (pclass->pspec->value_type), "GladeGtkImageType") == 0 || - strcmp (g_type_name (pclass->pspec->value_type), "GladeGtkButtonType") == 0 || - strcmp (g_type_name (pclass->pspec->value_type), "GladeGnomeDruidPagePosition") == 0 || - strcmp (g_type_name (pclass->pspec->value_type), "GladeGnomeIconListSelectionMode") == 0 || - strcmp (g_type_name (pclass->pspec->value_type), "GladeGnomeMessageBoxType") == 0) - continue; - - if ((enums ? G_TYPE_IS_ENUM (pclass->pspec->value_type) : - G_TYPE_IS_FLAGS (pclass->pspec->value_type)) && - !g_list_find_custom (types, g_type_name (pclass->pspec->value_type), - (GCompareFunc)find_by_type_name)) - types = g_list_prepend (types, g_strdup (g_type_name (pclass->pspec->value_type))); - - } - } - g_list_free (adaptors); - - types = g_list_sort (types, (GCompareFunc)find_by_type_name); - - for (l = types; l; l = l->next) - { - gchar *type_name = l->data; - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COLUMN_NAME, type_name, - -1); - g_free (type_name); - } - g_list_free (types); +column_types_store_populate_enums_flags (GtkListStore * store, gboolean enums) +{ + GtkTreeIter iter; + GList *types = NULL, *list, *l; + GList *adaptors = glade_widget_adaptor_list_adaptors (); + + for (list = adaptors; list; list = list->next) + { + GladeWidgetAdaptor *adaptor = list->data; + GladePropertyClass *pclass; + + for (l = adaptor->properties; l; l = l->next) + { + pclass = l->data; + + /* special case out a few of these... */ + if (strcmp + (g_type_name (pclass->pspec->value_type), + "GladeGtkGnomeUIInfo") == 0 || + strcmp (g_type_name (pclass->pspec->value_type), + "GladeStock") == 0 || + strcmp (g_type_name (pclass->pspec->value_type), + "GladeStockImage") == 0 || + strcmp (g_type_name (pclass->pspec->value_type), + "GladeGtkImageType") == 0 || + strcmp (g_type_name (pclass->pspec->value_type), + "GladeGtkButtonType") == 0 || + strcmp (g_type_name (pclass->pspec->value_type), + "GladeGnomeDruidPagePosition") == 0 || + strcmp (g_type_name (pclass->pspec->value_type), + "GladeGnomeIconListSelectionMode") == 0 || + strcmp (g_type_name (pclass->pspec->value_type), + "GladeGnomeMessageBoxType") == 0) + continue; + + if ((enums ? G_TYPE_IS_ENUM (pclass->pspec->value_type) : + G_TYPE_IS_FLAGS (pclass->pspec->value_type)) && + !g_list_find_custom (types, + g_type_name (pclass->pspec->value_type), + (GCompareFunc) find_by_type_name)) + types = + g_list_prepend (types, + g_strdup (g_type_name + (pclass->pspec->value_type))); + + } + } + g_list_free (adaptors); + + types = g_list_sort (types, (GCompareFunc) find_by_type_name); + + for (l = types; l; l = l->next) + { + gchar *type_name = l->data; + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COLUMN_NAME, type_name, -1); + g_free (type_name); + } + g_list_free (types); } static void -column_types_store_populate (GtkListStore *store) -{ - GtkTreeIter iter; - gint i; - GType types[] = { - G_TYPE_CHAR, - G_TYPE_UCHAR, - G_TYPE_BOOLEAN, - G_TYPE_INT, - G_TYPE_UINT, - G_TYPE_LONG, - G_TYPE_ULONG, - G_TYPE_INT64, - G_TYPE_UINT64, - G_TYPE_FLOAT, - G_TYPE_DOUBLE, - G_TYPE_STRING, - G_TYPE_POINTER, - G_TYPE_OBJECT, - GDK_TYPE_PIXBUF}; - - for (i = 0; i < sizeof (types) / sizeof (GType); i++) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COLUMN_NAME, g_type_name (types[i]), - -1); - } - - column_types_store_populate_enums_flags (store, TRUE); - column_types_store_populate_enums_flags (store, FALSE); +column_types_store_populate (GtkListStore * store) +{ + GtkTreeIter iter; + gint i; + GType types[] = { + G_TYPE_CHAR, + G_TYPE_UCHAR, + G_TYPE_BOOLEAN, + G_TYPE_INT, + G_TYPE_UINT, + G_TYPE_LONG, + G_TYPE_ULONG, + G_TYPE_INT64, + G_TYPE_UINT64, + G_TYPE_FLOAT, + G_TYPE_DOUBLE, + G_TYPE_STRING, + G_TYPE_POINTER, + G_TYPE_OBJECT, + GDK_TYPE_PIXBUF + }; + + for (i = 0; i < sizeof (types) / sizeof (GType); i++) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + COLUMN_NAME, g_type_name (types[i]), -1); + } + + column_types_store_populate_enums_flags (store, TRUE); + column_types_store_populate_enums_flags (store, FALSE); } GList * -glade_column_list_copy (GList *list) -{ - GList *l, *retval = NULL; - - for (l = list; l; l = g_list_next (l)) - { - GladeColumnType *data = l->data; - GladeColumnType *new_data = - glade_column_type_new (data->type_name, data->column_name); - - retval = g_list_prepend (retval, new_data); - } - - return g_list_reverse (retval); +glade_column_list_copy (GList * list) +{ + GList *l, *retval = NULL; + + for (l = list; l; l = g_list_next (l)) + { + GladeColumnType *data = l->data; + GladeColumnType *new_data = + glade_column_type_new (data->type_name, data->column_name); + + retval = g_list_prepend (retval, new_data); + } + + return g_list_reverse (retval); } GladeColumnType * -glade_column_type_new (const gchar *type_name, - const gchar *column_name) +glade_column_type_new (const gchar * type_name, const gchar * column_name) { - GladeColumnType *column = g_slice_new0 (GladeColumnType); + GladeColumnType *column = g_slice_new0 (GladeColumnType); - column->type_name = g_strdup (type_name); - column->column_name = g_strdup (column_name); + column->type_name = g_strdup (type_name); + column->column_name = g_strdup (column_name); - return column; + return column; } void -glade_column_type_free (GladeColumnType *column) +glade_column_type_free (GladeColumnType * column) { - g_free (column->type_name); - g_free (column->column_name); - g_slice_free (GladeColumnType, column); + g_free (column->type_name); + g_free (column->column_name); + g_slice_free (GladeColumnType, column); } void -glade_column_list_free (GList *list) +glade_column_list_free (GList * list) { - g_list_foreach (list, (GFunc)glade_column_type_free, NULL); - g_list_free (list); + g_list_foreach (list, (GFunc) glade_column_type_free, NULL); + g_list_free (list); } GladeColumnType * -glade_column_list_find_column (GList *list, const gchar *column_name) -{ - GladeColumnType *column = NULL, *iter; - GList *l; - - for (l = g_list_first (list); l; l = l->next) - { - iter = l->data; - if (strcmp (column_name, iter->column_name) == 0) - { - column = iter; - break; - } - } - - return column; +glade_column_list_find_column (GList * list, const gchar * column_name) +{ + GladeColumnType *column = NULL, *iter; + GList *l; + + for (l = g_list_first (list); l; l = l->next) + { + iter = l->data; + if (strcmp (column_name, iter->column_name) == 0) + { + column = iter; + break; + } + } + + return column; } GType glade_column_type_list_get_type (void) { - static GType type_id = 0; + static GType type_id = 0; - if (!type_id) - { - type_id = g_boxed_type_register_static - ("GladeColumnTypeList", - (GBoxedCopyFunc) glade_column_list_copy, - (GBoxedFreeFunc) glade_column_list_free); - } - return type_id; + if (!type_id) + { + type_id = g_boxed_type_register_static + ("GladeColumnTypeList", + (GBoxedCopyFunc) glade_column_list_copy, + (GBoxedFreeFunc) glade_column_list_free); + } + return type_id; } /**************************** GladeEditorProperty *****************************/ typedef struct { - GladeEditorProperty parent_instance; + GladeEditorProperty parent_instance; - GtkListStore *store; - GtkTreeView *view; - GtkTreeSelection *selection; + GtkListStore *store; + GtkTreeView *view; + GtkTreeSelection *selection; - GladeNameContext *context; + GladeNameContext *context; - gboolean adding_column; - gboolean want_focus; - gboolean setting_cursor; + gboolean adding_column; + gboolean want_focus; + gboolean setting_cursor; - GtkTreeViewColumn *name_column; - GtkTreeViewColumn *type_column; + GtkTreeViewColumn *name_column; + GtkTreeViewColumn *type_column; } GladeEPropColumnTypes; GLADE_MAKE_EPROP (GladeEPropColumnTypes, glade_eprop_column_types) @@ -241,641 +249,647 @@ GLADE_MAKE_EPROP (GladeEPropColumnTypes, glade_eprop_column_types) #define GLADE_IS_EPROP_COLUMN_TYPES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_COLUMN_TYPES)) #define GLADE_IS_EPROP_COLUMN_TYPES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_COLUMN_TYPES)) #define GLADE_EPROP_COLUMN_TYPES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_COLUMN_TYPES, GladeEPropColumnTypesClass)) - -static void -glade_eprop_column_types_finalize (GObject *object) + static void glade_eprop_column_types_finalize (GObject * object) { - /* Chain up */ - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); + /* Chain up */ + GObjectClass *parent_class = + g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); } static gint -get_extra_column (GNode *data_tree, GList *columns) +get_extra_column (GNode * data_tree, GList * columns) { - GladeModelData *data; - GNode *iter; - gint idx = -1; + GladeModelData *data; + GNode *iter; + gint idx = -1; - /* extra columns trail at the end so walk backwards... */ - for (iter = g_node_last_child (data_tree->children); iter; iter = iter->prev) - { - data = iter->data; + /* extra columns trail at the end so walk backwards... */ + for (iter = g_node_last_child (data_tree->children); iter; iter = iter->prev) + { + data = iter->data; - if (!glade_column_list_find_column (columns, data->name)) - { - idx = g_node_child_position (data_tree->children, iter); - break; - } + if (!glade_column_list_find_column (columns, data->name)) + { + idx = g_node_child_position (data_tree->children, iter); + break; + } - } - return idx; + } + return idx; } static void -eprop_column_adjust_rows (GladeEditorProperty *eprop, GList *columns) -{ - GladeColumnType *column; - GNode *data_tree = NULL; - GladeWidget *widget = eprop->property->widget; - GList *list; - GladeProperty *property; - gint idx; - - property = glade_widget_get_property (widget, "data"); - glade_property_get (property, &data_tree); - if (!data_tree) - return; - data_tree = glade_model_data_tree_copy (data_tree); - - /* Add mising columns and reorder... */ - for (list = g_list_last (columns); list; list = list->prev) - { - GType data_type; - - column = list->data; - - data_type = g_type_from_name (column->type_name); - - if ((idx = glade_model_data_column_index (data_tree, column->column_name)) < 0) - { - glade_model_data_insert_column (data_tree, - data_type, - column->column_name, - 0); - - } - else - glade_model_data_reorder_column (data_tree, idx, 0); - - } - - /* Remove trailing obsolete */ - while ((idx = get_extra_column (data_tree, columns)) >= 0) - glade_model_data_remove_column (data_tree, idx); - - glade_command_set_property (property, data_tree); - glade_model_data_tree_free (data_tree); +eprop_column_adjust_rows (GladeEditorProperty * eprop, GList * columns) +{ + GladeColumnType *column; + GNode *data_tree = NULL; + GladeWidget *widget = eprop->property->widget; + GList *list; + GladeProperty *property; + gint idx; + + property = glade_widget_get_property (widget, "data"); + glade_property_get (property, &data_tree); + if (!data_tree) + return; + data_tree = glade_model_data_tree_copy (data_tree); + + /* Add mising columns and reorder... */ + for (list = g_list_last (columns); list; list = list->prev) + { + GType data_type; + + column = list->data; + + data_type = g_type_from_name (column->type_name); + + if ((idx = + glade_model_data_column_index (data_tree, column->column_name)) < 0) + { + glade_model_data_insert_column (data_tree, + data_type, column->column_name, 0); + + } + else + glade_model_data_reorder_column (data_tree, idx, 0); + + } + + /* Remove trailing obsolete */ + while ((idx = get_extra_column (data_tree, columns)) >= 0) + glade_model_data_remove_column (data_tree, idx); + + glade_command_set_property (property, data_tree); + glade_model_data_tree_free (data_tree); } static void -eprop_column_append (GladeEditorProperty *eprop, - const gchar *type_name, - const gchar *column_name) +eprop_column_append (GladeEditorProperty * eprop, + const gchar * type_name, const gchar * column_name) { - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - GList *columns = NULL; - GladeColumnType *data; - GValue value = { 0, }; + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GList *columns = NULL; + GladeColumnType *data; + GValue value = { 0, }; - glade_property_get (eprop->property, &columns); - if (columns) - columns = glade_column_list_copy (columns); + glade_property_get (eprop->property, &columns); + if (columns) + columns = glade_column_list_copy (columns); - data = glade_column_type_new (type_name, column_name); + data = glade_column_type_new (type_name, column_name); - columns = g_list_append (columns, data); + columns = g_list_append (columns, data); - eprop_types->adding_column = TRUE; - glade_command_push_group (_("Setting columns on %s"), - glade_widget_get_name (eprop->property->widget)); + eprop_types->adding_column = TRUE; + glade_command_push_group (_("Setting columns on %s"), + glade_widget_get_name (eprop->property->widget)); - g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); - g_value_take_boxed (&value, columns); - glade_editor_property_commit (eprop, &value); + g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); + g_value_take_boxed (&value, columns); + glade_editor_property_commit (eprop, &value); - eprop_column_adjust_rows (eprop, columns); - g_value_unset (&value); + eprop_column_adjust_rows (eprop, columns); + g_value_unset (&value); - glade_command_pop_group (); + glade_command_pop_group (); - eprop_types->adding_column = FALSE; + eprop_types->adding_column = FALSE; } static gboolean -eprop_treeview_key_press (GtkWidget *treeview, - GdkEventKey *event, - GladeEditorProperty *eprop) +eprop_treeview_key_press (GtkWidget * treeview, + GdkEventKey * event, GladeEditorProperty * eprop) { - /* Remove from list and commit value, dont touch the liststore except in load() */ - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - GtkTreeIter iter; - GList *columns = NULL; - GladeColumnType *column; - GValue value = { 0, }; - gchar *column_name; + /* Remove from list and commit value, dont touch the liststore except in load() */ + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GtkTreeIter iter; + GList *columns = NULL; + GladeColumnType *column; + GValue value = { 0, }; + gchar *column_name; - if (event->keyval == GDK_KEY_Delete && - gtk_tree_selection_get_selected (eprop_types->selection, NULL, &iter)) - { - gtk_tree_model_get (GTK_TREE_MODEL (eprop_types->store), &iter, - COLUMN_COLUMN_NAME, &column_name, -1); + if (event->keyval == GDK_KEY_Delete && + gtk_tree_selection_get_selected (eprop_types->selection, NULL, &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (eprop_types->store), &iter, + COLUMN_COLUMN_NAME, &column_name, -1); - /* Cant delete the symbolic "add new" row */ - if (!column_name) - return TRUE; + /* Cant delete the symbolic "add new" row */ + if (!column_name) + return TRUE; - glade_property_get (eprop->property, &columns); - if (columns) - columns = glade_column_list_copy (columns); - g_assert (columns); + glade_property_get (eprop->property, &columns); + if (columns) + columns = glade_column_list_copy (columns); + g_assert (columns); - /* Find and remove the offending column... */ - column = glade_column_list_find_column (columns, column_name); - g_assert (column); - columns = g_list_remove (columns, column); - glade_column_type_free (column); + /* Find and remove the offending column... */ + column = glade_column_list_find_column (columns, column_name); + g_assert (column); + columns = g_list_remove (columns, column); + glade_column_type_free (column); - glade_command_push_group (_("Setting columns on %s"), - glade_widget_get_name (eprop->property->widget)); + glade_command_push_group (_("Setting columns on %s"), + glade_widget_get_name (eprop->property-> + widget)); - eprop_types->want_focus = TRUE; + eprop_types->want_focus = TRUE; - g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); - g_value_take_boxed (&value, columns); - glade_editor_property_commit (eprop, &value); + g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); + g_value_take_boxed (&value, columns); + glade_editor_property_commit (eprop, &value); - eprop_column_adjust_rows (eprop, columns); - g_value_unset (&value); - glade_command_pop_group (); + eprop_column_adjust_rows (eprop, columns); + g_value_unset (&value); + glade_command_pop_group (); - g_free (column_name); + g_free (column_name); - eprop_types->want_focus = FALSE; + eprop_types->want_focus = FALSE; - } + } - return (event->keyval == GDK_KEY_Delete); + return (event->keyval == GDK_KEY_Delete); } static gboolean -columns_changed_idle (GladeEditorProperty *eprop) -{ - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - GladeColumnType *column; - GValue value = { 0, }; - GList *new_list = NULL, *columns = NULL, *list; - GtkTreeIter iter; - gchar *column_name; - - glade_property_get (eprop->property, &columns); - g_assert (columns); - columns = glade_column_list_copy (columns); - - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_types->store), &iter)) - { - do - { - column_name = NULL; - gtk_tree_model_get (GTK_TREE_MODEL (eprop_types->store), &iter, - COLUMN_COLUMN_NAME, &column_name, -1); - if (!column_name) - continue; - - column = glade_column_list_find_column (columns, column_name); - g_assert (column); - - new_list = g_list_prepend (new_list, column); - g_free (column_name); - } - while (gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_types->store), &iter)); - } - - /* any missing columns to free ? */ - for (list = columns; list; list = list->next) - { - if (!g_list_find (new_list, list->data)) - glade_column_type_free ((GladeColumnType *)list->data); - } - g_list_free (columns); - - glade_command_push_group (_("Setting columns on %s"), - glade_widget_get_name (eprop->property->widget)); - - g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); - g_value_take_boxed (&value, g_list_reverse (new_list)); - glade_editor_property_commit (eprop, &value); - - eprop_column_adjust_rows (eprop, new_list); - g_value_unset (&value); - glade_command_pop_group (); - - return FALSE; +columns_changed_idle (GladeEditorProperty * eprop) +{ + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GladeColumnType *column; + GValue value = { 0, }; + GList *new_list = NULL, *columns = NULL, *list; + GtkTreeIter iter; + gchar *column_name; + + glade_property_get (eprop->property, &columns); + g_assert (columns); + columns = glade_column_list_copy (columns); + + if (gtk_tree_model_get_iter_first + (GTK_TREE_MODEL (eprop_types->store), &iter)) + { + do + { + column_name = NULL; + gtk_tree_model_get (GTK_TREE_MODEL (eprop_types->store), &iter, + COLUMN_COLUMN_NAME, &column_name, -1); + if (!column_name) + continue; + + column = glade_column_list_find_column (columns, column_name); + g_assert (column); + + new_list = g_list_prepend (new_list, column); + g_free (column_name); + } + while (gtk_tree_model_iter_next + (GTK_TREE_MODEL (eprop_types->store), &iter)); + } + + /* any missing columns to free ? */ + for (list = columns; list; list = list->next) + { + if (!g_list_find (new_list, list->data)) + glade_column_type_free ((GladeColumnType *) list->data); + } + g_list_free (columns); + + glade_command_push_group (_("Setting columns on %s"), + glade_widget_get_name (eprop->property->widget)); + + g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); + g_value_take_boxed (&value, g_list_reverse (new_list)); + glade_editor_property_commit (eprop, &value); + + eprop_column_adjust_rows (eprop, new_list); + g_value_unset (&value); + glade_command_pop_group (); + + return FALSE; } static void -eprop_treeview_row_deleted (GtkTreeModel *tree_model, - GtkTreePath *path, - GladeEditorProperty *eprop) +eprop_treeview_row_deleted (GtkTreeModel * tree_model, + GtkTreePath * path, GladeEditorProperty * eprop) { - if (eprop->loading) return; + if (eprop->loading) + return; - g_idle_add ((GSourceFunc)columns_changed_idle, eprop); + g_idle_add ((GSourceFunc) columns_changed_idle, eprop); } static void -eprop_column_add_new (GladeEPropColumnTypes *eprop_types) -{ - gtk_list_store_insert_with_values (eprop_types->store, NULL, -1, - COLUMN_NAME, _("< define a new column >"), - COLUMN_TYPE_EDITABLE, TRUE, - COLUMN_NAME_EDITABLE, FALSE, - COLUMN_TYPE_FOREGROUND, "Gray", - COLUMN_TYPE_STYLE, PANGO_STYLE_ITALIC, - -1); +eprop_column_add_new (GladeEPropColumnTypes * eprop_types) +{ + gtk_list_store_insert_with_values (eprop_types->store, NULL, -1, + COLUMN_NAME, _("< define a new column >"), + COLUMN_TYPE_EDITABLE, TRUE, + COLUMN_NAME_EDITABLE, FALSE, + COLUMN_TYPE_FOREGROUND, "Gray", + COLUMN_TYPE_STYLE, PANGO_STYLE_ITALIC, -1); } static void -eprop_column_load (GladeEPropColumnTypes *eprop_types, - const gchar *type_name, - const gchar *column_name) -{ - gtk_list_store_insert_with_values (eprop_types->store, NULL, -1, - COLUMN_NAME, type_name, - COLUMN_COLUMN_NAME, column_name, - COLUMN_TYPE_EDITABLE, FALSE, - COLUMN_NAME_EDITABLE, TRUE, - COLUMN_TYPE_FOREGROUND, "Black", - COLUMN_TYPE_STYLE, PANGO_STYLE_NORMAL, - -1); +eprop_column_load (GladeEPropColumnTypes * eprop_types, + const gchar * type_name, const gchar * column_name) +{ + gtk_list_store_insert_with_values (eprop_types->store, NULL, -1, + COLUMN_NAME, type_name, + COLUMN_COLUMN_NAME, column_name, + COLUMN_TYPE_EDITABLE, FALSE, + COLUMN_NAME_EDITABLE, TRUE, + COLUMN_TYPE_FOREGROUND, "Black", + COLUMN_TYPE_STYLE, PANGO_STYLE_NORMAL, -1); } static void -eprop_types_focus_cell (GladeEPropColumnTypes *eprop_types, gboolean use_path, gboolean add_cell, gboolean edit_cell) -{ - /* Focus and edit the first column of a newly added row */ - if (eprop_types->store) - { - GtkTreePath *new_item_path; - GtkTreeIter iter; - gint n_children; - gint needed_row; - - n_children = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (eprop_types->store), NULL); - - needed_row = n_children - (add_cell ? 1 : 2); - - if (use_path) - new_item_path = gtk_tree_path_new_from_string - (g_object_get_data (G_OBJECT (eprop_types), "current-path-str")); - else if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (eprop_types->store), - &iter, NULL, needed_row)) - new_item_path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_types->store), &iter); - else - return; - - eprop_types->setting_cursor = TRUE; - - gtk_widget_grab_focus (GTK_WIDGET (eprop_types->view)); - gtk_tree_view_expand_to_path (eprop_types->view, new_item_path); - - gtk_tree_view_set_cursor (eprop_types->view, new_item_path, - add_cell ? eprop_types->type_column : eprop_types->name_column, - edit_cell); - - eprop_types->setting_cursor = FALSE; - - gtk_tree_path_free (new_item_path); - } +eprop_types_focus_cell (GladeEPropColumnTypes * eprop_types, gboolean use_path, + gboolean add_cell, gboolean edit_cell) +{ + /* Focus and edit the first column of a newly added row */ + if (eprop_types->store) + { + GtkTreePath *new_item_path; + GtkTreeIter iter; + gint n_children; + gint needed_row; + + n_children = + gtk_tree_model_iter_n_children (GTK_TREE_MODEL (eprop_types->store), + NULL); + + needed_row = n_children - (add_cell ? 1 : 2); + + if (use_path) + new_item_path = gtk_tree_path_new_from_string + (g_object_get_data (G_OBJECT (eprop_types), "current-path-str")); + else if (gtk_tree_model_iter_nth_child + (GTK_TREE_MODEL (eprop_types->store), &iter, NULL, needed_row)) + new_item_path = + gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_types->store), + &iter); + else + return; + + eprop_types->setting_cursor = TRUE; + + gtk_widget_grab_focus (GTK_WIDGET (eprop_types->view)); + gtk_tree_view_expand_to_path (eprop_types->view, new_item_path); + + gtk_tree_view_set_cursor (eprop_types->view, new_item_path, + add_cell ? eprop_types-> + type_column : eprop_types->name_column, + edit_cell); + + eprop_types->setting_cursor = FALSE; + + gtk_tree_path_free (new_item_path); + } } static gboolean -eprop_types_focus_new (GladeEPropColumnTypes *eprop_types) +eprop_types_focus_new (GladeEPropColumnTypes * eprop_types) { - eprop_types_focus_cell (eprop_types, FALSE, TRUE, FALSE); - return FALSE; + eprop_types_focus_cell (eprop_types, FALSE, TRUE, FALSE); + return FALSE; } static gboolean -eprop_types_focus_name (GladeEPropColumnTypes *eprop_types) +eprop_types_focus_name (GladeEPropColumnTypes * eprop_types) { - eprop_types_focus_cell (eprop_types, FALSE, FALSE, TRUE); - return FALSE; + eprop_types_focus_cell (eprop_types, FALSE, FALSE, TRUE); + return FALSE; } static gboolean -eprop_types_focus_name_no_edit (GladeEPropColumnTypes *eprop_types) +eprop_types_focus_name_no_edit (GladeEPropColumnTypes * eprop_types) { - eprop_types_focus_cell (eprop_types, TRUE, FALSE, FALSE); - return FALSE; + eprop_types_focus_cell (eprop_types, TRUE, FALSE, FALSE); + return FALSE; } static void -glade_eprop_column_types_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEditorPropertyClass *parent_class = - g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - GList *l, *list = NULL; - - /* Chain up first */ - parent_class->load (eprop, property); - - if (eprop_types->context) - glade_name_context_destroy (eprop_types->context); - eprop_types->context = NULL; - - if (!property) return; - - eprop_types->context = glade_name_context_new (); - - g_signal_handlers_block_by_func (G_OBJECT (eprop_types->store), - eprop_treeview_row_deleted, eprop); - - /* Clear Store */ - gtk_list_store_clear (eprop_types->store); - - glade_property_get (property, &list); - - for (l = list; l; l = g_list_next (l)) - { - GladeColumnType *data = l->data; - - eprop_column_load (eprop_types, data->type_name, data->column_name); - glade_name_context_add_name (eprop_types->context, data->column_name); - } - - eprop_column_add_new (eprop_types); - - if (eprop_types->adding_column && list) - g_idle_add ((GSourceFunc)eprop_types_focus_name, eprop_types); - else if (eprop_types->want_focus) - g_idle_add ((GSourceFunc)eprop_types_focus_new, eprop_types); - - g_signal_handlers_unblock_by_func (G_OBJECT (eprop_types->store), - eprop_treeview_row_deleted, eprop); +glade_eprop_column_types_load (GladeEditorProperty * eprop, + GladeProperty * property) +{ + GladeEditorPropertyClass *parent_class = + g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GList *l, *list = NULL; + + /* Chain up first */ + parent_class->load (eprop, property); + + if (eprop_types->context) + glade_name_context_destroy (eprop_types->context); + eprop_types->context = NULL; + + if (!property) + return; + + eprop_types->context = glade_name_context_new (); + + g_signal_handlers_block_by_func (G_OBJECT (eprop_types->store), + eprop_treeview_row_deleted, eprop); + + /* Clear Store */ + gtk_list_store_clear (eprop_types->store); + + glade_property_get (property, &list); + + for (l = list; l; l = g_list_next (l)) + { + GladeColumnType *data = l->data; + + eprop_column_load (eprop_types, data->type_name, data->column_name); + glade_name_context_add_name (eprop_types->context, data->column_name); + } + + eprop_column_add_new (eprop_types); + + if (eprop_types->adding_column && list) + g_idle_add ((GSourceFunc) eprop_types_focus_name, eprop_types); + else if (eprop_types->want_focus) + g_idle_add ((GSourceFunc) eprop_types_focus_new, eprop_types); + + g_signal_handlers_unblock_by_func (G_OBJECT (eprop_types->store), + eprop_treeview_row_deleted, eprop); } static void -column_name_edited (GtkCellRendererText *cell, - const gchar *path, - const gchar *new_column_name, - GladeEditorProperty *eprop) -{ - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - GtkTreeIter iter; - gchar *old_column_name = NULL, *column_name; - GList *columns = NULL; - GladeColumnType *column; - GValue value = { 0, }; - GNode *data_tree = NULL; - GladeProperty *property; - - if (eprop_types->adding_column) - return; - - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_types->store), &iter, path)) - return; - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_types->store), &iter, COLUMN_COLUMN_NAME, &old_column_name, -1); - - if (new_column_name && old_column_name && - strcmp (new_column_name, old_column_name) == 0) - return; - - /* Attempt to rename the column, and commit if successfull... */ - glade_property_get (eprop->property, &columns); - if (columns) - columns = glade_column_list_copy (columns); - g_assert (columns); - - column = glade_column_list_find_column (columns, old_column_name); - - /* Bookkeep the exclusive names... */ - if (!new_column_name || !new_column_name[0] || - glade_name_context_has_name (eprop_types->context, new_column_name)) - column_name = glade_name_context_new_name (eprop_types->context, - new_column_name && new_column_name[0] ? - new_column_name : "column"); - else - column_name = g_strdup (new_column_name); - - glade_name_context_add_name (eprop_types->context, column_name); - glade_name_context_release_name (eprop_types->context, old_column_name); - - /* Set real column name */ - g_free (column->column_name); - column->column_name = column_name; - - /* The "columns" copy of this string doesnt last long... */ - column_name = g_strdup (column_name); - - glade_command_push_group (_("Setting columns on %s"), - glade_widget_get_name (eprop->property->widget)); - - eprop_types->want_focus = TRUE; - - g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); - g_value_take_boxed (&value, columns); - glade_editor_property_commit (eprop, &value); - g_value_unset (&value); - - property = glade_widget_get_property (eprop->property->widget, "data"); - glade_property_get (property, &data_tree); - if (data_tree) - { - data_tree = glade_model_data_tree_copy (data_tree); - glade_model_data_column_rename (data_tree, old_column_name, column_name); - glade_command_set_property (property, data_tree); - glade_model_data_tree_free (data_tree); - } - glade_command_pop_group (); - - eprop_types->want_focus = FALSE; - - g_free (old_column_name); - g_free (column_name); +column_name_edited (GtkCellRendererText * cell, + const gchar * path, + const gchar * new_column_name, GladeEditorProperty * eprop) +{ + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GtkTreeIter iter; + gchar *old_column_name = NULL, *column_name; + GList *columns = NULL; + GladeColumnType *column; + GValue value = { 0, }; + GNode *data_tree = NULL; + GladeProperty *property; + + if (eprop_types->adding_column) + return; + + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_types->store), &iter, path)) + return; + + gtk_tree_model_get (GTK_TREE_MODEL (eprop_types->store), &iter, + COLUMN_COLUMN_NAME, &old_column_name, -1); + + if (new_column_name && old_column_name && + strcmp (new_column_name, old_column_name) == 0) + return; + + /* Attempt to rename the column, and commit if successfull... */ + glade_property_get (eprop->property, &columns); + if (columns) + columns = glade_column_list_copy (columns); + g_assert (columns); + + column = glade_column_list_find_column (columns, old_column_name); + + /* Bookkeep the exclusive names... */ + if (!new_column_name || !new_column_name[0] || + glade_name_context_has_name (eprop_types->context, new_column_name)) + column_name = glade_name_context_new_name (eprop_types->context, + new_column_name && + new_column_name[0] ? + new_column_name : "column"); + else + column_name = g_strdup (new_column_name); + + glade_name_context_add_name (eprop_types->context, column_name); + glade_name_context_release_name (eprop_types->context, old_column_name); + + /* Set real column name */ + g_free (column->column_name); + column->column_name = column_name; + + /* The "columns" copy of this string doesnt last long... */ + column_name = g_strdup (column_name); + + glade_command_push_group (_("Setting columns on %s"), + glade_widget_get_name (eprop->property->widget)); + + eprop_types->want_focus = TRUE; + + g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); + g_value_take_boxed (&value, columns); + glade_editor_property_commit (eprop, &value); + g_value_unset (&value); + + property = glade_widget_get_property (eprop->property->widget, "data"); + glade_property_get (property, &data_tree); + if (data_tree) + { + data_tree = glade_model_data_tree_copy (data_tree); + glade_model_data_column_rename (data_tree, old_column_name, column_name); + glade_command_set_property (property, data_tree); + glade_model_data_tree_free (data_tree); + } + glade_command_pop_group (); + + eprop_types->want_focus = FALSE; + + g_free (old_column_name); + g_free (column_name); } static void -column_type_edited (GtkCellRendererText *cell, - const gchar *path, - const gchar *type_name, - GladeEditorProperty *eprop) -{ - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - GtkTreeIter iter; - gchar *column_name; - - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_types->store), &iter, path)) - return; - - if (type_name && type_name[0]) - { - column_name = glade_name_context_new_name (eprop_types->context, type_name); - eprop_column_append (eprop, type_name, column_name); - g_free (column_name); - } - else - { - eprop_types->want_focus = TRUE; - glade_editor_property_load (eprop, eprop->property); - eprop_types->want_focus = FALSE; - } +column_type_edited (GtkCellRendererText * cell, + const gchar * path, + const gchar * type_name, GladeEditorProperty * eprop) +{ + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GtkTreeIter iter; + gchar *column_name; + + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_types->store), &iter, path)) + return; + + if (type_name && type_name[0]) + { + column_name = + glade_name_context_new_name (eprop_types->context, type_name); + eprop_column_append (eprop, type_name, column_name); + g_free (column_name); + } + else + { + eprop_types->want_focus = TRUE; + glade_editor_property_load (eprop, eprop->property); + eprop_types->want_focus = FALSE; + } } static void -types_combo_editing_started (GtkCellRenderer *renderer, - GtkCellEditable *editable, - gchar *path, - GladeEditorProperty *eprop) +types_combo_editing_started (GtkCellRenderer * renderer, + GtkCellEditable * editable, + gchar * path, GladeEditorProperty * eprop) { - GtkEntryCompletion *completion = gtk_entry_completion_new (); + GtkEntryCompletion *completion = gtk_entry_completion_new (); - g_object_set_data_full (G_OBJECT (eprop), "current-path-str", g_strdup (path), g_free); + g_object_set_data_full (G_OBJECT (eprop), "current-path-str", g_strdup (path), + g_free); - gtk_entry_completion_set_model (completion, types_model); - gtk_entry_completion_set_text_column (completion, 0); - gtk_entry_completion_set_inline_completion (completion, TRUE); - gtk_entry_set_completion (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (editable))), completion); - g_object_unref (G_OBJECT (completion)); + gtk_entry_completion_set_model (completion, types_model); + gtk_entry_completion_set_text_column (completion, 0); + gtk_entry_completion_set_inline_completion (completion, TRUE); + gtk_entry_set_completion (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (editable))), + completion); + g_object_unref (G_OBJECT (completion)); } static void -types_combo_editing_canceled (GtkCellRenderer *renderer, - GladeEditorProperty *eprop) +types_combo_editing_canceled (GtkCellRenderer * renderer, + GladeEditorProperty * eprop) { - g_idle_add ((GSourceFunc)eprop_types_focus_new, eprop); + g_idle_add ((GSourceFunc) eprop_types_focus_new, eprop); } static void -types_name_editing_started (GtkCellRenderer *renderer, - GtkCellEditable *editable, - gchar *path_str, - GladeEditorProperty *eprop) +types_name_editing_started (GtkCellRenderer * renderer, + GtkCellEditable * editable, + gchar * path_str, GladeEditorProperty * eprop) { - g_object_set_data_full (G_OBJECT (eprop), "current-path-str", g_strdup (path_str), g_free); + g_object_set_data_full (G_OBJECT (eprop), "current-path-str", + g_strdup (path_str), g_free); } static void -types_name_editing_canceled (GtkCellRenderer *renderer, - GladeEditorProperty *eprop) +types_name_editing_canceled (GtkCellRenderer * renderer, + GladeEditorProperty * eprop) { - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - if (eprop_types->adding_column || eprop_types->setting_cursor) - return; + if (eprop_types->adding_column || eprop_types->setting_cursor) + return; - g_idle_add ((GSourceFunc)eprop_types_focus_name_no_edit, eprop); + g_idle_add ((GSourceFunc) eprop_types_focus_name_no_edit, eprop); } static GtkWidget * -glade_eprop_column_types_create_input (GladeEditorProperty *eprop) +glade_eprop_column_types_create_input (GladeEditorProperty * eprop) { - GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); - GtkWidget *vbox, *swin, *label; - GtkCellRenderer *cell; - gchar *string; + GladeEPropColumnTypes *eprop_types = GLADE_EPROP_COLUMN_TYPES (eprop); + GtkWidget *vbox, *swin, *label; + GtkCellRenderer *cell; + gchar *string; + + vbox = gtk_vbox_new (FALSE, 2); - vbox = gtk_vbox_new (FALSE, 2); - /* hbox = gtk_hbox_new (FALSE, 4); */ - if (!types_model) - { - /* We make sure to do this after all the adaptors are parsed - * because we load the enums/flags from the adaptors - */ - types_model = (GtkTreeModel *)gtk_list_store_new (1, - G_TYPE_STRING); - - column_types_store_populate (GTK_LIST_STORE (types_model)); - } - - - string = g_strdup_printf ("<b>%s</b>", _("Add and remove columns:")); - label = gtk_label_new (string); - g_free (string); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 2, 4); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0); - - swin = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), GTK_SHADOW_IN); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0); - - eprop_types->store = gtk_list_store_new (N_COLUMNS, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_BOOLEAN, - G_TYPE_BOOLEAN, - G_TYPE_STRING, - PANGO_TYPE_STYLE); - - g_signal_connect (eprop_types->store, "row-deleted", - G_CALLBACK (eprop_treeview_row_deleted), - eprop); - - eprop_types->view = (GtkTreeView *)gtk_tree_view_new_with_model (GTK_TREE_MODEL (eprop_types->store)); - eprop_types->selection = gtk_tree_view_get_selection (eprop_types->view); - - gtk_tree_view_set_reorderable (eprop_types->view, TRUE); - gtk_tree_view_set_enable_search (eprop_types->view, FALSE); - //gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); - - g_signal_connect (eprop_types->view, "key-press-event", - G_CALLBACK (eprop_treeview_key_press), - eprop); - - - /* type column */ - cell = gtk_cell_renderer_combo_new (); - g_object_set (G_OBJECT (cell), - "text-column", COLUMN_NAME, - "model", types_model, - NULL); - - g_signal_connect (G_OBJECT (cell), "editing-started", - G_CALLBACK (types_combo_editing_started), eprop); - - g_signal_connect (G_OBJECT (cell), "editing-canceled", - G_CALLBACK (types_combo_editing_canceled), eprop); - - g_signal_connect (G_OBJECT (cell), "edited", - G_CALLBACK (column_type_edited), eprop); - - eprop_types->type_column = - gtk_tree_view_column_new_with_attributes (_("Column type"), cell, - "foreground", COLUMN_TYPE_FOREGROUND, - "style", COLUMN_TYPE_STYLE, - "editable", COLUMN_TYPE_EDITABLE, - "text", COLUMN_NAME, - NULL); - - gtk_tree_view_column_set_expand (eprop_types->type_column, TRUE); - gtk_tree_view_append_column (eprop_types->view, eprop_types->type_column); - - /* name column */ - cell = gtk_cell_renderer_text_new (); - g_signal_connect (G_OBJECT (cell), "edited", - G_CALLBACK (column_name_edited), eprop); - - g_signal_connect (G_OBJECT (cell), "editing-started", - G_CALLBACK (types_name_editing_started), eprop); - - g_signal_connect (G_OBJECT (cell), "editing-canceled", - G_CALLBACK (types_name_editing_canceled), eprop); - - eprop_types->name_column = - gtk_tree_view_column_new_with_attributes (_("Column name"), cell, - "editable", COLUMN_NAME_EDITABLE, - "text", COLUMN_COLUMN_NAME, - NULL); - - gtk_tree_view_column_set_expand (eprop_types->name_column, TRUE); - - gtk_tree_view_append_column (eprop_types->view, eprop_types->name_column); - gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_types->view)); - - g_object_set (G_OBJECT (vbox), "height-request", 200, NULL); - - gtk_widget_show_all (vbox); - return vbox; + if (!types_model) + { + /* We make sure to do this after all the adaptors are parsed + * because we load the enums/flags from the adaptors + */ + types_model = (GtkTreeModel *) gtk_list_store_new (1, G_TYPE_STRING); + + column_types_store_populate (GTK_LIST_STORE (types_model)); + } + + + string = g_strdup_printf ("<b>%s</b>", _("Add and remove columns:")); + label = gtk_label_new (string); + g_free (string); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label), 2, 4); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0); + + swin = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), + GTK_SHADOW_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0); + + eprop_types->store = gtk_list_store_new (N_COLUMNS, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_BOOLEAN, + G_TYPE_BOOLEAN, + G_TYPE_STRING, PANGO_TYPE_STYLE); + + g_signal_connect (eprop_types->store, "row-deleted", + G_CALLBACK (eprop_treeview_row_deleted), eprop); + + eprop_types->view = + (GtkTreeView *) + gtk_tree_view_new_with_model (GTK_TREE_MODEL (eprop_types->store)); + eprop_types->selection = gtk_tree_view_get_selection (eprop_types->view); + + gtk_tree_view_set_reorderable (eprop_types->view, TRUE); + gtk_tree_view_set_enable_search (eprop_types->view, FALSE); + //gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); + + g_signal_connect (eprop_types->view, "key-press-event", + G_CALLBACK (eprop_treeview_key_press), eprop); + + + /* type column */ + cell = gtk_cell_renderer_combo_new (); + g_object_set (G_OBJECT (cell), + "text-column", COLUMN_NAME, "model", types_model, NULL); + + g_signal_connect (G_OBJECT (cell), "editing-started", + G_CALLBACK (types_combo_editing_started), eprop); + + g_signal_connect (G_OBJECT (cell), "editing-canceled", + G_CALLBACK (types_combo_editing_canceled), eprop); + + g_signal_connect (G_OBJECT (cell), "edited", + G_CALLBACK (column_type_edited), eprop); + + eprop_types->type_column = + gtk_tree_view_column_new_with_attributes (_("Column type"), cell, + "foreground", + COLUMN_TYPE_FOREGROUND, "style", + COLUMN_TYPE_STYLE, "editable", + COLUMN_TYPE_EDITABLE, "text", + COLUMN_NAME, NULL); + + gtk_tree_view_column_set_expand (eprop_types->type_column, TRUE); + gtk_tree_view_append_column (eprop_types->view, eprop_types->type_column); + + /* name column */ + cell = gtk_cell_renderer_text_new (); + g_signal_connect (G_OBJECT (cell), "edited", + G_CALLBACK (column_name_edited), eprop); + + g_signal_connect (G_OBJECT (cell), "editing-started", + G_CALLBACK (types_name_editing_started), eprop); + + g_signal_connect (G_OBJECT (cell), "editing-canceled", + G_CALLBACK (types_name_editing_canceled), eprop); + + eprop_types->name_column = + gtk_tree_view_column_new_with_attributes (_("Column name"), cell, + "editable", + COLUMN_NAME_EDITABLE, "text", + COLUMN_COLUMN_NAME, NULL); + + gtk_tree_view_column_set_expand (eprop_types->name_column, TRUE); + + gtk_tree_view_append_column (eprop_types->view, eprop_types->name_column); + gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_types->view)); + + g_object_set (G_OBJECT (vbox), "height-request", 200, NULL); + + gtk_widget_show_all (vbox); + return vbox; } diff --git a/plugins/gtk+/glade-column-types.h b/plugins/gtk+/glade-column-types.h index 1f818fe0..0714e5c4 100644 --- a/plugins/gtk+/glade-column-types.h +++ b/plugins/gtk+/glade-column-types.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Juan Pablo Ugarte. * diff --git a/plugins/gtk+/glade-entry-editor.c b/plugins/gtk+/glade-entry-editor.c index f3390e38..8be49826 100644 --- a/plugins/gtk+/glade-entry-editor.c +++ b/plugins/gtk+/glade-entry-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -29,11 +28,11 @@ #include "glade-image-editor.h" // For GladeImageEditMode -static void glade_entry_editor_finalize (GObject *object); +static void glade_entry_editor_finalize (GObject * object); -static void glade_entry_editor_editable_init (GladeEditableIface *iface); +static void glade_entry_editor_editable_init (GladeEditableIface * iface); -static void glade_entry_editor_grab_focus (GtkWidget *widget); +static void glade_entry_editor_grab_focus (GtkWidget * widget); G_DEFINE_TYPE_WITH_CODE (GladeEntryEditor, glade_entry_editor, GTK_TYPE_VBOX, @@ -42,244 +41,265 @@ G_DEFINE_TYPE_WITH_CODE (GladeEntryEditor, glade_entry_editor, GTK_TYPE_VBOX, static void -glade_entry_editor_class_init (GladeEntryEditorClass *klass) +glade_entry_editor_class_init (GladeEntryEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_entry_editor_finalize; - widget_class->grab_focus = glade_entry_editor_grab_focus; + object_class->finalize = glade_entry_editor_finalize; + widget_class->grab_focus = glade_entry_editor_grab_focus; } static void -glade_entry_editor_init (GladeEntryEditor *self) +glade_entry_editor_init (GladeEntryEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeEntryEditor *entry_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeEntryEditor * entry_editor) { - if (entry_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (entry_editor))) - return; + if (entry_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (entry_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (entry_editor), entry_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -project_finalized (GladeEntryEditor *entry_editor, - GladeProject *where_project_was) +project_finalized (GladeEntryEditor * entry_editor, + GladeProject * where_project_was) { - entry_editor->loaded_widget = NULL; + entry_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (entry_editor), NULL); + glade_editable_load (GLADE_EDITABLE (entry_editor), NULL); } static void -glade_entry_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_entry_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (editable); - GladeImageEditMode icon_mode; - gboolean use_buffer = FALSE; - GList *l; - - entry_editor->loading = TRUE; - - /* Since we watch the project*/ - if (entry_editor->loaded_widget) - { - /* watch custom-child and use-stock properties here for reloads !!! */ - - g_signal_handlers_disconnect_by_func (G_OBJECT (entry_editor->loaded_widget->project), - G_CALLBACK (project_changed), entry_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (entry_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - entry_editor); - } - - /* Mark our widget... */ - entry_editor->loaded_widget = widget; - - if (entry_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (entry_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), entry_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (entry_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - entry_editor); - } - - /* load the embedded editable... */ - if (entry_editor->embed) - glade_editable_load (GLADE_EDITABLE (entry_editor->embed), widget); - - for (l = entry_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - - if (widget) - { - glade_widget_property_get (widget, "use-entry-buffer", &use_buffer); - if (use_buffer) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->buffer_radio), TRUE); - else - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->text_radio), TRUE); - - - glade_widget_property_get (widget, "primary-icon-mode", &icon_mode); - switch (icon_mode) - { - case GLADE_IMAGE_MODE_STOCK: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->primary_stock_radio), TRUE); - break; - case GLADE_IMAGE_MODE_ICON: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->primary_icon_name_radio), TRUE); - break; - case GLADE_IMAGE_MODE_FILENAME: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->primary_pixbuf_radio), TRUE); - break; - default: - break; - } - - glade_widget_property_get (widget, "secondary-icon-mode", &icon_mode); - switch (icon_mode) - { - case GLADE_IMAGE_MODE_STOCK: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->secondary_stock_radio), TRUE); - break; - case GLADE_IMAGE_MODE_ICON: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->secondary_icon_name_radio), TRUE); - break; - case GLADE_IMAGE_MODE_FILENAME: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry_editor->secondary_pixbuf_radio), TRUE); - break; - default: - break; - } - } - entry_editor->loading = FALSE; + GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (editable); + GladeImageEditMode icon_mode; + gboolean use_buffer = FALSE; + GList *l; + + entry_editor->loading = TRUE; + + /* Since we watch the project */ + if (entry_editor->loaded_widget) + { + /* watch custom-child and use-stock properties here for reloads !!! */ + + g_signal_handlers_disconnect_by_func (G_OBJECT + (entry_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + entry_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (entry_editor->loaded_widget->project), + (GWeakNotify) project_finalized, entry_editor); + } + + /* Mark our widget... */ + entry_editor->loaded_widget = widget; + + if (entry_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (entry_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), entry_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (entry_editor->loaded_widget->project), + (GWeakNotify) project_finalized, entry_editor); + } + + /* load the embedded editable... */ + if (entry_editor->embed) + glade_editable_load (GLADE_EDITABLE (entry_editor->embed), widget); + + for (l = entry_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + + if (widget) + { + glade_widget_property_get (widget, "use-entry-buffer", &use_buffer); + if (use_buffer) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor->buffer_radio), TRUE); + else + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor->text_radio), TRUE); + + + glade_widget_property_get (widget, "primary-icon-mode", &icon_mode); + switch (icon_mode) + { + case GLADE_IMAGE_MODE_STOCK: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor->primary_stock_radio), + TRUE); + break; + case GLADE_IMAGE_MODE_ICON: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor-> + primary_icon_name_radio), TRUE); + break; + case GLADE_IMAGE_MODE_FILENAME: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor->primary_pixbuf_radio), + TRUE); + break; + default: + break; + } + + glade_widget_property_get (widget, "secondary-icon-mode", &icon_mode); + switch (icon_mode) + { + case GLADE_IMAGE_MODE_STOCK: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor->secondary_stock_radio), + TRUE); + break; + case GLADE_IMAGE_MODE_ICON: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor-> + secondary_icon_name_radio), TRUE); + break; + case GLADE_IMAGE_MODE_FILENAME: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (entry_editor-> + secondary_pixbuf_radio), TRUE); + break; + default: + break; + } + } + entry_editor->loading = FALSE; } static void -glade_entry_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_entry_editor_set_show_name (GladeEditable * editable, gboolean show_name) { - GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (editable); + GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (entry_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (entry_editor->embed), + show_name); } static void -glade_entry_editor_editable_init (GladeEditableIface *iface) +glade_entry_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_entry_editor_load; - iface->set_show_name = glade_entry_editor_set_show_name; + iface->load = glade_entry_editor_load; + iface->set_show_name = glade_entry_editor_set_show_name; } static void -glade_entry_editor_finalize (GObject *object) +glade_entry_editor_finalize (GObject * object) { - GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (object); + GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (object); - if (entry_editor->properties) - g_list_free (entry_editor->properties); - entry_editor->properties = NULL; - entry_editor->embed = NULL; + if (entry_editor->properties) + g_list_free (entry_editor->properties); + entry_editor->properties = NULL; + entry_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_entry_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_entry_editor_parent_class)->finalize (object); } static void -glade_entry_editor_grab_focus (GtkWidget *widget) +glade_entry_editor_grab_focus (GtkWidget * widget) { - GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (widget); + GladeEntryEditor *entry_editor = GLADE_ENTRY_EDITOR (widget); - gtk_widget_grab_focus (entry_editor->embed); + gtk_widget_grab_focus (entry_editor->embed); } static void -text_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +text_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor) { - GladeProperty *property; + GladeProperty *property; - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->text_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->text_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use static text"), entry_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use static text"), + entry_editor->loaded_widget->name); - property = glade_widget_get_property (entry_editor->loaded_widget, "buffer"); - glade_command_set_property (property, NULL); + property = glade_widget_get_property (entry_editor->loaded_widget, "buffer"); + glade_command_set_property (property, NULL); - property = glade_widget_get_property (entry_editor->loaded_widget, "use-entry-buffer"); - glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (entry_editor->loaded_widget, + "use-entry-buffer"); + glade_command_set_property (property, FALSE); - /* Text will only take effect after setting the property under the hood */ - property = glade_widget_get_property (entry_editor->loaded_widget, "text"); - glade_command_set_property (property, NULL); + /* Text will only take effect after setting the property under the hood */ + property = glade_widget_get_property (entry_editor->loaded_widget, "text"); + glade_command_set_property (property, NULL); - /* Incase the NULL text didnt change */ - glade_property_sync (property); + /* Incase the NULL text didnt change */ + glade_property_sync (property); - glade_command_pop_group (); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -buffer_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +buffer_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor) { - GladeProperty *property; + GladeProperty *property; - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->buffer_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->buffer_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an external buffer"), entry_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use an external buffer"), + entry_editor->loaded_widget->name); - /* Reset the text while still in static text mode */ - property = glade_widget_get_property (entry_editor->loaded_widget, "text"); - glade_command_set_property (property, NULL); + /* Reset the text while still in static text mode */ + property = glade_widget_get_property (entry_editor->loaded_widget, "text"); + glade_command_set_property (property, NULL); - property = glade_widget_get_property (entry_editor->loaded_widget, "use-entry-buffer"); - glade_command_set_property (property, TRUE); + property = + glade_widget_get_property (entry_editor->loaded_widget, + "use-entry-buffer"); + glade_command_set_property (property, TRUE); - glade_command_pop_group (); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } @@ -289,465 +309,549 @@ buffer_toggled (GtkWidget *widget, #define STOCK_NAME(primary) ((primary) ? "primary-icon-stock" : "secondary-icon-stock") static void -set_stock_mode (GladeEntryEditor *entry_editor, gboolean primary) +set_stock_mode (GladeEntryEditor * entry_editor, gboolean primary) { - GladeProperty *property; - GValue value = { 0, }; - - property = glade_widget_get_property (entry_editor->loaded_widget, ICON_NAME_NAME (primary)); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (entry_editor->loaded_widget, PIXBUF_NAME (primary)); - glade_command_set_property (property, NULL); - - property = glade_widget_get_property (entry_editor->loaded_widget, STOCK_NAME (primary)); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - - property = glade_widget_get_property (entry_editor->loaded_widget, ICON_MODE_NAME (primary)); - glade_command_set_property (property, GLADE_IMAGE_MODE_STOCK); + GladeProperty *property; + GValue value = { 0, }; + + property = + glade_widget_get_property (entry_editor->loaded_widget, + ICON_NAME_NAME (primary)); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (entry_editor->loaded_widget, + PIXBUF_NAME (primary)); + glade_command_set_property (property, NULL); + + property = + glade_widget_get_property (entry_editor->loaded_widget, + STOCK_NAME (primary)); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + + property = + glade_widget_get_property (entry_editor->loaded_widget, + ICON_MODE_NAME (primary)); + glade_command_set_property (property, GLADE_IMAGE_MODE_STOCK); } static void -set_icon_name_mode (GladeEntryEditor *entry_editor, gboolean primary) +set_icon_name_mode (GladeEntryEditor * entry_editor, gboolean primary) { - GladeProperty *property; - - property = glade_widget_get_property (entry_editor->loaded_widget, STOCK_NAME (primary)); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (entry_editor->loaded_widget, PIXBUF_NAME (primary)); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (entry_editor->loaded_widget, ICON_MODE_NAME (primary)); - glade_command_set_property (property, GLADE_IMAGE_MODE_ICON); + GladeProperty *property; + + property = + glade_widget_get_property (entry_editor->loaded_widget, + STOCK_NAME (primary)); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (entry_editor->loaded_widget, + PIXBUF_NAME (primary)); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (entry_editor->loaded_widget, + ICON_MODE_NAME (primary)); + glade_command_set_property (property, GLADE_IMAGE_MODE_ICON); } static void -set_pixbuf_mode (GladeEntryEditor *entry_editor, gboolean primary) +set_pixbuf_mode (GladeEntryEditor * entry_editor, gboolean primary) { - GladeProperty *property; - - property = glade_widget_get_property (entry_editor->loaded_widget, STOCK_NAME (primary)); - glade_command_set_property (property, NULL); - - property = glade_widget_get_property (entry_editor->loaded_widget, ICON_NAME_NAME (primary)); - glade_command_set_property (property, NULL); - - property = glade_widget_get_property (entry_editor->loaded_widget, ICON_MODE_NAME (primary)); - glade_command_set_property (property, GLADE_IMAGE_MODE_FILENAME); + GladeProperty *property; + + property = + glade_widget_get_property (entry_editor->loaded_widget, + STOCK_NAME (primary)); + glade_command_set_property (property, NULL); + + property = + glade_widget_get_property (entry_editor->loaded_widget, + ICON_NAME_NAME (primary)); + glade_command_set_property (property, NULL); + + property = + glade_widget_get_property (entry_editor->loaded_widget, + ICON_MODE_NAME (primary)); + glade_command_set_property (property, GLADE_IMAGE_MODE_FILENAME); } static void -primary_stock_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +primary_stock_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor) { - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->primary_stock_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->primary_stock_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a primary icon from stock"), entry_editor->loaded_widget->name); - set_stock_mode (entry_editor, TRUE); - glade_command_pop_group (); + glade_command_push_group (_("Setting %s to use a primary icon from stock"), + entry_editor->loaded_widget->name); + set_stock_mode (entry_editor, TRUE); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -primary_icon_name_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +primary_icon_name_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor) { - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->primary_icon_name_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->primary_icon_name_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a primary icon from the icon theme"), entry_editor->loaded_widget->name); - set_icon_name_mode (entry_editor, TRUE); - glade_command_pop_group (); + glade_command_push_group (_ + ("Setting %s to use a primary icon from the icon theme"), + entry_editor->loaded_widget->name); + set_icon_name_mode (entry_editor, TRUE); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -primary_pixbuf_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +primary_pixbuf_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor) { - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->primary_pixbuf_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->primary_pixbuf_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a primary icon from filename"), entry_editor->loaded_widget->name); - set_pixbuf_mode (entry_editor, TRUE); - glade_command_pop_group (); + glade_command_push_group (_("Setting %s to use a primary icon from filename"), + entry_editor->loaded_widget->name); + set_pixbuf_mode (entry_editor, TRUE); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -secondary_stock_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +secondary_stock_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor) { - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->secondary_stock_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->secondary_stock_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a secondary icon from stock"), entry_editor->loaded_widget->name); - set_stock_mode (entry_editor, FALSE); - glade_command_pop_group (); + glade_command_push_group (_("Setting %s to use a secondary icon from stock"), + entry_editor->loaded_widget->name); + set_stock_mode (entry_editor, FALSE); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -secondary_icon_name_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +secondary_icon_name_toggled (GtkWidget * widget, + GladeEntryEditor * entry_editor) { - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->secondary_icon_name_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->secondary_icon_name_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a secondary icon from the icon theme"), entry_editor->loaded_widget->name); - set_icon_name_mode (entry_editor, FALSE); - glade_command_pop_group (); + glade_command_push_group (_ + ("Setting %s to use a secondary icon from the icon theme"), + entry_editor->loaded_widget->name); + set_icon_name_mode (entry_editor, FALSE); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -secondary_pixbuf_toggled (GtkWidget *widget, - GladeEntryEditor *entry_editor) +secondary_pixbuf_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor) { - if (entry_editor->loading || !entry_editor->loaded_widget) - return; + if (entry_editor->loading || !entry_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (entry_editor->secondary_pixbuf_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (entry_editor->secondary_pixbuf_radio))) + return; - entry_editor->modifying = TRUE; + entry_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a secondary icon from filename"), entry_editor->loaded_widget->name); - set_pixbuf_mode (entry_editor, FALSE); - glade_command_pop_group (); + glade_command_push_group (_ + ("Setting %s to use a secondary icon from filename"), + entry_editor->loaded_widget->name); + set_pixbuf_mode (entry_editor, FALSE); + glade_command_pop_group (); - entry_editor->modifying = FALSE; + entry_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (entry_editor), - entry_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (entry_editor), + entry_editor->loaded_widget); } static void -table_attach (GtkWidget *table, - GtkWidget *child, - gint pos, gint row) +table_attach (GtkWidget * table, GtkWidget * child, gint pos, gint row) { - gtk_grid_attach (GTK_GRID (table), child, - pos, row, 1, 1); + gtk_grid_attach (GTK_GRID (table), child, pos, row, 1, 1); - if (pos) - gtk_widget_set_hexpand (child, TRUE); + if (pos) + gtk_widget_set_hexpand (child, TRUE); } GtkWidget * -glade_entry_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_entry_editor_new (GladeWidgetAdaptor * adaptor, GladeEditable * embed) { - GladeEntryEditor *entry_editor; - GladeEditorProperty *eprop; - GtkWidget *table, *frame, *alignment, *label, *hbox; - gchar *str; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - entry_editor = g_object_new (GLADE_TYPE_ENTRY_EDITOR, NULL); - entry_editor->embed = GTK_WIDGET (embed); - - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (entry_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - - /* Text... */ - str = g_strdup_printf ("<b>%s</b>", _("Text")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Text */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "text", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->text_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->text_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Buffer */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "buffer", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->buffer_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (entry_editor->text_radio)); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->buffer_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Progress... */ - str = g_strdup_printf ("<b>%s</b>", _("Progress")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Fraction */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "progress-fraction", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Pulse */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "progress-pulse-step", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Primary icon... */ - str = g_strdup_printf ("<b>%s</b>", _("Primary icon")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Pixbuf */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, PIXBUF_NAME(TRUE), FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->primary_pixbuf_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->primary_pixbuf_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Stock */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, STOCK_NAME(TRUE), FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->primary_stock_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (entry_editor->primary_pixbuf_radio)); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->primary_stock_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Icon name */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, ICON_NAME_NAME(TRUE), FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->primary_icon_name_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (entry_editor->primary_pixbuf_radio)); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->primary_icon_name_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 2); - table_attach (table, GTK_WIDGET (eprop), 1, 2); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Other primary icon related properties */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "primary-icon-activatable", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 3); - table_attach (table, GTK_WIDGET (eprop), 1, 3); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "primary-icon-sensitive", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 4); - table_attach (table, GTK_WIDGET (eprop), 1, 4); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "primary-icon-tooltip-text", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 5); - table_attach (table, GTK_WIDGET (eprop), 1, 5); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "primary-icon-tooltip-markup", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 6); - table_attach (table, GTK_WIDGET (eprop), 1, 6); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Secondary icon... */ - str = g_strdup_printf ("<b>%s</b>", _("Secondary icon")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Pixbuf */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, PIXBUF_NAME(FALSE), FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->secondary_pixbuf_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->secondary_pixbuf_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Stock */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, STOCK_NAME(FALSE), FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->secondary_stock_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (entry_editor->secondary_pixbuf_radio)); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->secondary_stock_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Icon name */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, ICON_NAME_NAME(FALSE), FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - entry_editor->secondary_icon_name_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (entry_editor->secondary_pixbuf_radio)); - gtk_box_pack_start (GTK_BOX (hbox), entry_editor->secondary_icon_name_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 2); - table_attach (table, GTK_WIDGET (eprop), 1, 2); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - /* Other secondary icon related properties */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "secondary-icon-activatable", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 3); - table_attach (table, GTK_WIDGET (eprop), 1, 3); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "secondary-icon-sensitive", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 4); - table_attach (table, GTK_WIDGET (eprop), 1, 4); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "secondary-icon-tooltip-text", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 5); - table_attach (table, GTK_WIDGET (eprop), 1, 5); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "secondary-icon-tooltip-markup", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 6); - table_attach (table, GTK_WIDGET (eprop), 1, 6); - entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); - - gtk_widget_show_all (GTK_WIDGET (entry_editor)); - - - /* Connect radio button signals... */ - g_signal_connect (G_OBJECT (entry_editor->text_radio), "toggled", - G_CALLBACK (text_toggled), entry_editor); - g_signal_connect (G_OBJECT (entry_editor->buffer_radio), "toggled", - G_CALLBACK (buffer_toggled), entry_editor); - - g_signal_connect (G_OBJECT (entry_editor->primary_stock_radio), "toggled", - G_CALLBACK (primary_stock_toggled), entry_editor); - g_signal_connect (G_OBJECT (entry_editor->primary_icon_name_radio), "toggled", - G_CALLBACK (primary_icon_name_toggled), entry_editor); - g_signal_connect (G_OBJECT (entry_editor->primary_pixbuf_radio), "toggled", - G_CALLBACK (primary_pixbuf_toggled), entry_editor); - - g_signal_connect (G_OBJECT (entry_editor->secondary_stock_radio), "toggled", - G_CALLBACK (secondary_stock_toggled), entry_editor); - g_signal_connect (G_OBJECT (entry_editor->secondary_icon_name_radio), "toggled", - G_CALLBACK (secondary_icon_name_toggled), entry_editor); - g_signal_connect (G_OBJECT (entry_editor->secondary_pixbuf_radio), "toggled", - G_CALLBACK (secondary_pixbuf_toggled), entry_editor); - - return GTK_WIDGET (entry_editor); + GladeEntryEditor *entry_editor; + GladeEditorProperty *eprop; + GtkWidget *table, *frame, *alignment, *label, *hbox; + gchar *str; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + entry_editor = g_object_new (GLADE_TYPE_ENTRY_EDITOR, NULL); + entry_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (entry_editor), GTK_WIDGET (embed), FALSE, FALSE, + 0); + + + /* Text... */ + str = g_strdup_printf ("<b>%s</b>", _("Text")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Text */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "text", FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->text_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->text_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Buffer */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "buffer", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->buffer_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (entry_editor->text_radio)); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->buffer_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Progress... */ + str = g_strdup_printf ("<b>%s</b>", _("Progress")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Fraction */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "progress-fraction", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Pulse */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "progress-pulse-step", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Primary icon... */ + str = g_strdup_printf ("<b>%s</b>", _("Primary icon")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Pixbuf */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, PIXBUF_NAME (TRUE), + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->primary_pixbuf_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->primary_pixbuf_radio, FALSE, + FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Stock */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, STOCK_NAME (TRUE), + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->primary_stock_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (entry_editor->primary_pixbuf_radio)); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->primary_stock_radio, FALSE, + FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Icon name */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, ICON_NAME_NAME (TRUE), + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->primary_icon_name_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (entry_editor->primary_pixbuf_radio)); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->primary_icon_name_radio, + FALSE, FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 2); + table_attach (table, GTK_WIDGET (eprop), 1, 2); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Other primary icon related properties */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "primary-icon-activatable", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 3); + table_attach (table, GTK_WIDGET (eprop), 1, 3); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "primary-icon-sensitive", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 4); + table_attach (table, GTK_WIDGET (eprop), 1, 4); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "primary-icon-tooltip-text", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 5); + table_attach (table, GTK_WIDGET (eprop), 1, 5); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "primary-icon-tooltip-markup", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 6); + table_attach (table, GTK_WIDGET (eprop), 1, 6); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Secondary icon... */ + str = g_strdup_printf ("<b>%s</b>", _("Secondary icon")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (entry_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Pixbuf */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, PIXBUF_NAME (FALSE), + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->secondary_pixbuf_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->secondary_pixbuf_radio, + FALSE, FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Stock */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, STOCK_NAME (FALSE), + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->secondary_stock_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (entry_editor->secondary_pixbuf_radio)); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->secondary_stock_radio, + FALSE, FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Icon name */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + ICON_NAME_NAME (FALSE), FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + entry_editor->secondary_icon_name_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (entry_editor->secondary_pixbuf_radio)); + gtk_box_pack_start (GTK_BOX (hbox), entry_editor->secondary_icon_name_radio, + FALSE, FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 2); + table_attach (table, GTK_WIDGET (eprop), 1, 2); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + /* Other secondary icon related properties */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "secondary-icon-activatable", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 3); + table_attach (table, GTK_WIDGET (eprop), 1, 3); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "secondary-icon-sensitive", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 4); + table_attach (table, GTK_WIDGET (eprop), 1, 4); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "secondary-icon-tooltip-text", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 5); + table_attach (table, GTK_WIDGET (eprop), 1, 5); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, + "secondary-icon-tooltip-markup", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 6); + table_attach (table, GTK_WIDGET (eprop), 1, 6); + entry_editor->properties = g_list_prepend (entry_editor->properties, eprop); + + gtk_widget_show_all (GTK_WIDGET (entry_editor)); + + + /* Connect radio button signals... */ + g_signal_connect (G_OBJECT (entry_editor->text_radio), "toggled", + G_CALLBACK (text_toggled), entry_editor); + g_signal_connect (G_OBJECT (entry_editor->buffer_radio), "toggled", + G_CALLBACK (buffer_toggled), entry_editor); + + g_signal_connect (G_OBJECT (entry_editor->primary_stock_radio), "toggled", + G_CALLBACK (primary_stock_toggled), entry_editor); + g_signal_connect (G_OBJECT (entry_editor->primary_icon_name_radio), "toggled", + G_CALLBACK (primary_icon_name_toggled), entry_editor); + g_signal_connect (G_OBJECT (entry_editor->primary_pixbuf_radio), "toggled", + G_CALLBACK (primary_pixbuf_toggled), entry_editor); + + g_signal_connect (G_OBJECT (entry_editor->secondary_stock_radio), "toggled", + G_CALLBACK (secondary_stock_toggled), entry_editor); + g_signal_connect (G_OBJECT (entry_editor->secondary_icon_name_radio), + "toggled", G_CALLBACK (secondary_icon_name_toggled), + entry_editor); + g_signal_connect (G_OBJECT (entry_editor->secondary_pixbuf_radio), "toggled", + G_CALLBACK (secondary_pixbuf_toggled), entry_editor); + + return GTK_WIDGET (entry_editor); } diff --git a/plugins/gtk+/glade-entry-editor.h b/plugins/gtk+/glade-entry-editor.h index 2c33c778..368888d8 100644 --- a/plugins/gtk+/glade-entry-editor.h +++ b/plugins/gtk+/glade-entry-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c index 92001f2a..bcb9698d 100644 --- a/plugins/gtk+/glade-gtk.c +++ b/plugins/gtk+/glade-gtk.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2001 Ximian, Inc. * Copyright (C) 2004 - 2008 Tristan Van Berkom, Juan Pablo Ugarte et al. @@ -68,53 +67,52 @@ GParamSpec * gladegtk_icon_size_spec (void) { - return g_param_spec_enum ("icon-size", _("Icon Size"), - _("Symbolic size to use for stock icon, icon set or named icon"), - GTK_TYPE_ICON_SIZE, - GTK_ICON_SIZE_BUTTON, - G_PARAM_READWRITE); + return g_param_spec_enum ("icon-size", _("Icon Size"), + _ + ("Symbolic size to use for stock icon, icon set or named icon"), + GTK_TYPE_ICON_SIZE, GTK_ICON_SIZE_BUTTON, + G_PARAM_READWRITE); } /* This function does absolutely nothing * (and is for use in overriding post_create functions). */ void -empty (GObject *container, GladeCreateReason reason) +empty (GObject * container, GladeCreateReason reason) { } /* This function is used to stop default handlers */ static void -glade_gtk_stop_emission_POINTER (gpointer instance, gpointer dummy, gpointer data) +glade_gtk_stop_emission_POINTER (gpointer instance, gpointer dummy, + gpointer data) { - g_signal_stop_emission (instance, GPOINTER_TO_UINT (data) , 0); + g_signal_stop_emission (instance, GPOINTER_TO_UINT (data), 0); } /* Initialize needed pspec types from here */ void -glade_gtk_init (const gchar *name) +glade_gtk_init (const gchar * name) { } /* ----------------------------- GtkWidget ------------------------------ */ gboolean -glade_gtk_widget_depends (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeWidget *another) +glade_gtk_widget_depends (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeWidget * another) { - if (GTK_IS_ICON_FACTORY (another->object) || - GTK_IS_ACTION (another->object) || - GTK_IS_ACTION_GROUP (another->object)) - return TRUE; + if (GTK_IS_ICON_FACTORY (another->object) || + GTK_IS_ACTION (another->object) || GTK_IS_ACTION_GROUP (another->object)) + return TRUE; - return GWA_GET_CLASS (G_TYPE_OBJECT)->depends (adaptor, widget, another); + return GWA_GET_CLASS (G_TYPE_OBJECT)->depends (adaptor, widget, another); } #define GLADE_TAG_A11Y_A11Y "accessibility" -#define GLADE_TAG_A11Y_ACTION_NAME "action_name" /* We should make -/_ synonymous */ +#define GLADE_TAG_A11Y_ACTION_NAME "action_name" /* We should make -/_ synonymous */ #define GLADE_TAG_A11Y_DESC "description" #define GLADE_TAG_A11Y_TARGET "target" #define GLADE_TAG_A11Y_TYPE "type" @@ -129,1867 +127,1813 @@ glade_gtk_widget_depends (GladeWidgetAdaptor *adaptor, static const gchar *atk_relations_list[] = { - "controlled-by", - "controller-for", - "labelled-by", - "label-for", - "member-of", - "node-child-of", - "flows-to", - "flows-from", - "subwindow-of", - "embeds", - "embedded-by", - "popup-for", - "parent-window-of", - "described-by", - "description-for", - NULL + "controlled-by", + "controller-for", + "labelled-by", + "label-for", + "member-of", + "node-child-of", + "flows-to", + "flows-from", + "subwindow-of", + "embeds", + "embedded-by", + "popup-for", + "parent-window-of", + "described-by", + "description-for", + NULL }; static void -glade_gtk_read_accels (GladeWidget *widget, - GladeXmlNode *node, - gboolean require_signal) +glade_gtk_read_accels (GladeWidget * widget, + GladeXmlNode * node, gboolean require_signal) { - GladeProperty *property; - GladeXmlNode *prop; - GladeAccelInfo *ainfo; - GValue *value = NULL; - GList *accels = NULL; + GladeProperty *property; + GladeXmlNode *prop; + GladeAccelInfo *ainfo; + GValue *value = NULL; + GList *accels = NULL; - for (prop = glade_xml_node_get_children (node); - prop; prop = glade_xml_node_next (prop)) - { - if (!glade_xml_node_verify_silent (prop, GLADE_TAG_ACCEL)) - continue; + for (prop = glade_xml_node_get_children (node); + prop; prop = glade_xml_node_next (prop)) + { + if (!glade_xml_node_verify_silent (prop, GLADE_TAG_ACCEL)) + continue; - if ((ainfo = glade_accel_read (prop, require_signal)) != NULL) - accels = g_list_prepend (accels, ainfo); - } + if ((ainfo = glade_accel_read (prop, require_signal)) != NULL) + accels = g_list_prepend (accels, ainfo); + } - if (accels) - { - value = g_new0 (GValue, 1); - g_value_init (value, GLADE_TYPE_ACCEL_GLIST); - g_value_take_boxed (value, accels); + if (accels) + { + value = g_new0 (GValue, 1); + g_value_init (value, GLADE_TYPE_ACCEL_GLIST); + g_value_take_boxed (value, accels); - property = glade_widget_get_property (widget, "accelerator"); - glade_property_set_value (property, value); + property = glade_widget_get_property (widget, "accelerator"); + glade_property_set_value (property, value); - g_value_unset (value); - g_free (value); - } + g_value_unset (value); + g_free (value); + } } static void -glade_gtk_parse_atk_props (GladeWidget *widget, - GladeXmlNode *node) -{ - GladeXmlNode *prop; - GladeProperty *property; - GValue *gvalue; - gchar *value, *name, *id, *comment; - gint translatable; - gboolean is_action; - - for (prop = glade_xml_node_get_children (node); - prop; prop = glade_xml_node_next (prop)) - { - if (glade_xml_node_verify_silent (prop, GLADE_TAG_A11Y_PROPERTY)) - is_action = FALSE; - else if (glade_xml_node_verify_silent (prop, GLADE_TAG_A11Y_ACTION)) - is_action = TRUE; - else - continue; - - if (!is_action && - !(name = glade_xml_get_property_string_required - (prop, GLADE_XML_TAG_NAME, NULL))) - continue; - else if (is_action && - !(name = glade_xml_get_property_string_required - (prop, GLADE_TAG_A11Y_ACTION_NAME, NULL))) - continue; - - - /* Make sure we are working with dashes and - * not underscores ... - */ - id = glade_util_read_prop_name (name); - g_free (name); - - /* We are namespacing the action properties internally - * just incase they clash (all property names must be - * unique...) - */ - if (is_action) - { - name = g_strdup_printf ("atk-%s", id); - g_free (id); - id = name; - } - - if ((property = glade_widget_get_property (widget, id)) != NULL) - { - /* Complex statement just getting the value here... */ - if ((!is_action && - !(value = glade_xml_get_content (prop))) || - (is_action && - !(value = glade_xml_get_property_string_required - (prop, GLADE_TAG_A11Y_DESC, NULL)))) - { - /* XXX should be a glade_xml_get_content_required()... */ - g_free (id); - continue; - } - - /* Set the parsed value on the property ... */ - gvalue = glade_property_class_make_gvalue_from_string - (property->klass, value, widget->project, widget); - glade_property_set_value (property, gvalue); - g_value_unset (gvalue); - g_free (gvalue); - - /* Deal with i18n... ... XXX Do i18n context !!! */ - translatable = glade_xml_get_property_boolean - (prop, GLADE_TAG_TRANSLATABLE, FALSE); - comment = glade_xml_get_property_string - (prop, GLADE_TAG_COMMENT); - - glade_property_i18n_set_translatable - (property, translatable); - glade_property_i18n_set_comment - (property, comment); - - g_free (comment); - g_free (value); - } - - g_free (id); - } -} +glade_gtk_parse_atk_props (GladeWidget * widget, GladeXmlNode * node) +{ + GladeXmlNode *prop; + GladeProperty *property; + GValue *gvalue; + gchar *value, *name, *id, *comment; + gint translatable; + gboolean is_action; + + for (prop = glade_xml_node_get_children (node); + prop; prop = glade_xml_node_next (prop)) + { + if (glade_xml_node_verify_silent (prop, GLADE_TAG_A11Y_PROPERTY)) + is_action = FALSE; + else if (glade_xml_node_verify_silent (prop, GLADE_TAG_A11Y_ACTION)) + is_action = TRUE; + else + continue; + + if (!is_action && + !(name = glade_xml_get_property_string_required + (prop, GLADE_XML_TAG_NAME, NULL))) + continue; + else if (is_action && + !(name = glade_xml_get_property_string_required + (prop, GLADE_TAG_A11Y_ACTION_NAME, NULL))) + continue; + + + /* Make sure we are working with dashes and + * not underscores ... + */ + id = glade_util_read_prop_name (name); + g_free (name); + + /* We are namespacing the action properties internally + * just incase they clash (all property names must be + * unique...) + */ + if (is_action) + { + name = g_strdup_printf ("atk-%s", id); + g_free (id); + id = name; + } -static void -glade_gtk_parse_atk_props_gtkbuilder (GladeWidget *widget, - GladeXmlNode *node) -{ - GladeXmlNode *child, *object_node; - gchar *internal; - - /* Search for internal "accessible" child and redirect parse from there */ - for (child = glade_xml_node_get_children (node); - child; child = glade_xml_node_next (child)) - { - if (glade_xml_node_verify_silent (child, GLADE_XML_TAG_CHILD)) - { - if ((internal = - glade_xml_get_property_string (child, GLADE_XML_TAG_INTERNAL_CHILD))) - { - if (!strcmp (internal, GLADE_TAG_A11Y_INTERNAL_NAME) && - (object_node = - glade_xml_search_child_required (child, GLADE_XML_TAG_WIDGET))) - glade_gtk_parse_atk_props (widget, object_node); - - g_free (internal); - } - } - } + if ((property = glade_widget_get_property (widget, id)) != NULL) + { + /* Complex statement just getting the value here... */ + if ((!is_action && + !(value = glade_xml_get_content (prop))) || + (is_action && + !(value = glade_xml_get_property_string_required + (prop, GLADE_TAG_A11Y_DESC, NULL)))) + { + /* XXX should be a glade_xml_get_content_required()... */ + g_free (id); + continue; + } + + /* Set the parsed value on the property ... */ + gvalue = glade_property_class_make_gvalue_from_string + (property->klass, value, widget->project, widget); + glade_property_set_value (property, gvalue); + g_value_unset (gvalue); + g_free (gvalue); + + /* Deal with i18n... ... XXX Do i18n context !!! */ + translatable = glade_xml_get_property_boolean + (prop, GLADE_TAG_TRANSLATABLE, FALSE); + comment = glade_xml_get_property_string (prop, GLADE_TAG_COMMENT); + + glade_property_i18n_set_translatable (property, translatable); + glade_property_i18n_set_comment (property, comment); + + g_free (comment); + g_free (value); + } + + g_free (id); + } } static void -glade_gtk_parse_atk_relation (GladeProperty *property, - GladeXmlNode *node) -{ - GladeXmlNode *prop; - gchar *type, *target, *id, *tmp; - gchar *string = NULL; - - for (prop = glade_xml_node_get_children (node); - prop; prop = glade_xml_node_next (prop)) - { - if (!glade_xml_node_verify_silent (prop, GLADE_TAG_A11Y_RELATION)) - continue; - - if (!(type = - glade_xml_get_property_string_required - (prop, GLADE_TAG_A11Y_TYPE, NULL))) - continue; - - if (!(target = - glade_xml_get_property_string_required - (prop, GLADE_TAG_A11Y_TARGET, NULL))) - { - g_free (type); - continue; - } - - id = glade_util_read_prop_name (type); - - if (!strcmp (id, property->klass->id)) - { - if (string == NULL) - string = g_strdup (target); - else - { - tmp = g_strdup_printf ("%s%s%s", string, - GPC_OBJECT_DELIMITER, target); - string = (g_free (string), tmp); - } - - } - - g_free (id); - g_free (type); - g_free (target); - } - - - /* we must synchronize this directly after loading this project - * (i.e. lookup the actual objects after they've been parsed and - * are present). this is a feature of object and object list properties - * that needs a better api. - */ - if (string) - { - g_object_set_data_full (G_OBJECT (property), "glade-loaded-object", - g_strdup (string), g_free); - } +glade_gtk_parse_atk_props_gtkbuilder (GladeWidget * widget, GladeXmlNode * node) +{ + GladeXmlNode *child, *object_node; + gchar *internal; + + /* Search for internal "accessible" child and redirect parse from there */ + for (child = glade_xml_node_get_children (node); + child; child = glade_xml_node_next (child)) + { + if (glade_xml_node_verify_silent (child, GLADE_XML_TAG_CHILD)) + { + if ((internal = + glade_xml_get_property_string (child, + GLADE_XML_TAG_INTERNAL_CHILD))) + { + if (!strcmp (internal, GLADE_TAG_A11Y_INTERNAL_NAME) && + (object_node = + glade_xml_search_child_required (child, + GLADE_XML_TAG_WIDGET))) + glade_gtk_parse_atk_props (widget, object_node); + + g_free (internal); + } + } + } } static void -glade_gtk_widget_read_atk_props (GladeWidget *widget, - GladeXmlNode *node) -{ - GladeXmlNode *atk_node; - GladeProperty *property; - gint i; +glade_gtk_parse_atk_relation (GladeProperty * property, GladeXmlNode * node) +{ + GladeXmlNode *prop; + gchar *type, *target, *id, *tmp; + gchar *string = NULL; + + for (prop = glade_xml_node_get_children (node); + prop; prop = glade_xml_node_next (prop)) + { + if (!glade_xml_node_verify_silent (prop, GLADE_TAG_A11Y_RELATION)) + continue; + + if (!(type = + glade_xml_get_property_string_required + (prop, GLADE_TAG_A11Y_TYPE, NULL))) + continue; + + if (!(target = + glade_xml_get_property_string_required + (prop, GLADE_TAG_A11Y_TARGET, NULL))) + { + g_free (type); + continue; + } + + id = glade_util_read_prop_name (type); - glade_gtk_parse_atk_props_gtkbuilder (widget, node); + if (!strcmp (id, property->klass->id)) + { + if (string == NULL) + string = g_strdup (target); + else + { + tmp = g_strdup_printf ("%s%s%s", string, + GPC_OBJECT_DELIMITER, target); + string = (g_free (string), tmp); + } + + } - if ((atk_node = - glade_xml_search_child (node, GLADE_TAG_A11Y_A11Y)) != NULL) - { - /* Properties & actions */ - glade_gtk_parse_atk_props (widget, atk_node); + g_free (id); + g_free (type); + g_free (target); + } + + + /* we must synchronize this directly after loading this project + * (i.e. lookup the actual objects after they've been parsed and + * are present). this is a feature of object and object list properties + * that needs a better api. + */ + if (string) + { + g_object_set_data_full (G_OBJECT (property), "glade-loaded-object", + g_strdup (string), g_free); + } +} - /* Relations */ - for (i = 0; atk_relations_list[i]; i++) - { - if ((property = - glade_widget_get_property (widget, - atk_relations_list[i]))) - glade_gtk_parse_atk_relation (property, atk_node); - else - g_warning ("Couldnt find atk relation %s", - atk_relations_list[i]); - } - } +static void +glade_gtk_widget_read_atk_props (GladeWidget * widget, GladeXmlNode * node) +{ + GladeXmlNode *atk_node; + GladeProperty *property; + gint i; + + glade_gtk_parse_atk_props_gtkbuilder (widget, node); + + if ((atk_node = glade_xml_search_child (node, GLADE_TAG_A11Y_A11Y)) != NULL) + { + /* Properties & actions */ + glade_gtk_parse_atk_props (widget, atk_node); + + /* Relations */ + for (i = 0; atk_relations_list[i]; i++) + { + if ((property = + glade_widget_get_property (widget, atk_relations_list[i]))) + glade_gtk_parse_atk_relation (property, atk_node); + else + g_warning ("Couldnt find atk relation %s", atk_relations_list[i]); + } + } } void -glade_gtk_widget_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_widget_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); - /* Read in accelerators */ - glade_gtk_read_accels (widget, node, TRUE); + /* Read in accelerators */ + glade_gtk_read_accels (widget, node, TRUE); - /* Read in atk props */ - glade_gtk_widget_read_atk_props (widget, node); + /* Read in atk props */ + glade_gtk_widget_read_atk_props (widget, node); } static void -glade_gtk_widget_write_atk_property (GladeProperty *property, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_widget_write_atk_property (GladeProperty * property, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *prop_node; - gchar *value; + GladeXmlNode *prop_node; + gchar *value; - glade_property_get (property, &value); - if (value && value[0]) - { - prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_PROPERTY); - glade_xml_node_append_child (node, prop_node); + glade_property_get (property, &value); + if (value && value[0]) + { + prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_PROPERTY); + glade_xml_node_append_child (node, prop_node); - glade_xml_node_set_property_string (prop_node, - GLADE_TAG_NAME, - property->klass->id); + glade_xml_node_set_property_string (prop_node, + GLADE_TAG_NAME, property->klass->id); - glade_xml_set_content (prop_node, value); + glade_xml_set_content (prop_node, value); - /* XXX Do context !!! */ - if (property->i18n_translatable) - glade_xml_node_set_property_string (prop_node, - GLADE_TAG_TRANSLATABLE, - GLADE_XML_TAG_I18N_TRUE); + /* XXX Do context !!! */ + if (property->i18n_translatable) + glade_xml_node_set_property_string (prop_node, + GLADE_TAG_TRANSLATABLE, + GLADE_XML_TAG_I18N_TRUE); - if (property->i18n_comment) - glade_xml_node_set_property_string (prop_node, - GLADE_TAG_COMMENT, - property->i18n_comment); - } + if (property->i18n_comment) + glade_xml_node_set_property_string (prop_node, + GLADE_TAG_COMMENT, + property->i18n_comment); + } } static void -glade_gtk_widget_write_atk_properties (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_widget_write_atk_properties (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *child_node, *object_node; - GladeProperty *name_prop, *desc_prop; + GladeXmlNode *child_node, *object_node; + GladeProperty *name_prop, *desc_prop; - name_prop = glade_widget_get_property (widget, "AtkObject::accessible-name"); - desc_prop = glade_widget_get_property (widget, "AtkObject::accessible-description"); + name_prop = glade_widget_get_property (widget, "AtkObject::accessible-name"); + desc_prop = + glade_widget_get_property (widget, "AtkObject::accessible-description"); - /* Create internal child here if any of these properties are non-null */ - if (!glade_property_default (name_prop) || - !glade_property_default (desc_prop)) - { - gchar *atkname = g_strdup_printf ("%s-atkobject", widget->name); + /* Create internal child here if any of these properties are non-null */ + if (!glade_property_default (name_prop) || + !glade_property_default (desc_prop)) + { + gchar *atkname = g_strdup_printf ("%s-atkobject", widget->name); - child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD); - glade_xml_node_append_child (node, child_node); + child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD); + glade_xml_node_append_child (node, child_node); - glade_xml_node_set_property_string (child_node, - GLADE_XML_TAG_INTERNAL_CHILD, - GLADE_TAG_A11Y_INTERNAL_NAME); + glade_xml_node_set_property_string (child_node, + GLADE_XML_TAG_INTERNAL_CHILD, + GLADE_TAG_A11Y_INTERNAL_NAME); - object_node = glade_xml_node_new (context, GLADE_XML_TAG_WIDGET); - glade_xml_node_append_child (child_node, object_node); + object_node = glade_xml_node_new (context, GLADE_XML_TAG_WIDGET); + glade_xml_node_append_child (child_node, object_node); - glade_xml_node_set_property_string (object_node, - GLADE_XML_TAG_CLASS, - "AtkObject"); + glade_xml_node_set_property_string (object_node, + GLADE_XML_TAG_CLASS, "AtkObject"); - glade_xml_node_set_property_string (object_node, - GLADE_XML_TAG_ID, - atkname); - - if (!glade_property_default (name_prop)) - glade_gtk_widget_write_atk_property (name_prop, context, object_node); - if (!glade_property_default (desc_prop)) - glade_gtk_widget_write_atk_property (desc_prop, context, object_node); + glade_xml_node_set_property_string (object_node, + GLADE_XML_TAG_ID, atkname); - g_free (atkname); - } + if (!glade_property_default (name_prop)) + glade_gtk_widget_write_atk_property (name_prop, context, object_node); + if (!glade_property_default (desc_prop)) + glade_gtk_widget_write_atk_property (desc_prop, context, object_node); + + g_free (atkname); + } } static void -glade_gtk_widget_write_atk_relation (GladeProperty *property, - GladeXmlContext *context, - GladeXmlNode *node) -{ - GladeXmlNode *prop_node; - gchar *value, **split; - gint i; - - if ((value = glade_widget_adaptor_string_from_value - (GLADE_WIDGET_ADAPTOR (property->klass->handle), - property->klass, property->value)) != NULL) - { - if ((split = g_strsplit (value, GPC_OBJECT_DELIMITER, 0)) != NULL) - { - for (i = 0; split[i] != NULL; i++) - { - prop_node = glade_xml_node_new (context, - GLADE_TAG_A11Y_RELATION); - glade_xml_node_append_child (node, prop_node); - - glade_xml_node_set_property_string (prop_node, - GLADE_TAG_A11Y_TYPE, - property->klass->id); - glade_xml_node_set_property_string (prop_node, - GLADE_TAG_A11Y_TARGET, - split[i]); - } - g_strfreev (split); - } - } +glade_gtk_widget_write_atk_relation (GladeProperty * property, + GladeXmlContext * context, + GladeXmlNode * node) +{ + GladeXmlNode *prop_node; + gchar *value, **split; + gint i; + + if ((value = glade_widget_adaptor_string_from_value + (GLADE_WIDGET_ADAPTOR (property->klass->handle), + property->klass, property->value)) != NULL) + { + if ((split = g_strsplit (value, GPC_OBJECT_DELIMITER, 0)) != NULL) + { + for (i = 0; split[i] != NULL; i++) + { + prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_RELATION); + glade_xml_node_append_child (node, prop_node); + + glade_xml_node_set_property_string (prop_node, + GLADE_TAG_A11Y_TYPE, + property->klass->id); + glade_xml_node_set_property_string (prop_node, + GLADE_TAG_A11Y_TARGET, + split[i]); + } + g_strfreev (split); + } + } } static void -glade_gtk_widget_write_atk_relations (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_widget_write_atk_relations (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeProperty *property; - gint i; + GladeProperty *property; + gint i; - for (i = 0; atk_relations_list[i]; i++) - { - if ((property = - glade_widget_get_property (widget, - atk_relations_list[i]))) - glade_gtk_widget_write_atk_relation (property, context, node); - else - g_warning ("Couldnt find atk relation %s on widget %s", - atk_relations_list[i], widget->name); - } + for (i = 0; atk_relations_list[i]; i++) + { + if ((property = + glade_widget_get_property (widget, atk_relations_list[i]))) + glade_gtk_widget_write_atk_relation (property, context, node); + else + g_warning ("Couldnt find atk relation %s on widget %s", + atk_relations_list[i], widget->name); + } } static void -glade_gtk_widget_write_atk_action (GladeProperty *property, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_widget_write_atk_action (GladeProperty * property, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *prop_node; - gchar *value = NULL; + GladeXmlNode *prop_node; + gchar *value = NULL; - glade_property_get (property, &value); + glade_property_get (property, &value); - if (value && value[0]) - { - prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_ACTION); - glade_xml_node_append_child (node, prop_node); + if (value && value[0]) + { + prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_ACTION); + glade_xml_node_append_child (node, prop_node); - glade_xml_node_set_property_string (prop_node, - GLADE_TAG_A11Y_ACTION_NAME, - &property->klass->id[4]); - glade_xml_node_set_property_string (prop_node, - GLADE_TAG_A11Y_DESC, - value); - } + glade_xml_node_set_property_string (prop_node, + GLADE_TAG_A11Y_ACTION_NAME, + &property->klass->id[4]); + glade_xml_node_set_property_string (prop_node, + GLADE_TAG_A11Y_DESC, value); + } } static void -glade_gtk_widget_write_atk_actions (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_widget_write_atk_actions (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeProperty *property; + GladeProperty *property; - if ((property = glade_widget_get_property (widget, "atk-click")) != NULL) - glade_gtk_widget_write_atk_action (property, context, node); - if ((property = glade_widget_get_property (widget, "atk-activate")) != NULL) - glade_gtk_widget_write_atk_action (property, context, node); - if ((property = glade_widget_get_property (widget, "atk-press")) != NULL) - glade_gtk_widget_write_atk_action (property, context, node); - if ((property = glade_widget_get_property (widget, "atk-release")) != NULL) - glade_gtk_widget_write_atk_action (property, context, node); + if ((property = glade_widget_get_property (widget, "atk-click")) != NULL) + glade_gtk_widget_write_atk_action (property, context, node); + if ((property = glade_widget_get_property (widget, "atk-activate")) != NULL) + glade_gtk_widget_write_atk_action (property, context, node); + if ((property = glade_widget_get_property (widget, "atk-press")) != NULL) + glade_gtk_widget_write_atk_action (property, context, node); + if ((property = glade_widget_get_property (widget, "atk-release")) != NULL) + glade_gtk_widget_write_atk_action (property, context, node); } static void -glade_gtk_widget_write_atk_props (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_widget_write_atk_props (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *atk_node; + GladeXmlNode *atk_node; - atk_node = glade_xml_node_new (context, GLADE_TAG_A11Y_A11Y); + atk_node = glade_xml_node_new (context, GLADE_TAG_A11Y_A11Y); - glade_gtk_widget_write_atk_relations (widget, context, atk_node); - glade_gtk_widget_write_atk_actions (widget, context, atk_node); + glade_gtk_widget_write_atk_relations (widget, context, atk_node); + glade_gtk_widget_write_atk_actions (widget, context, atk_node); - if (!glade_xml_node_get_children (atk_node)) - glade_xml_node_delete (atk_node); - else - glade_xml_node_append_child (node, atk_node); + if (!glade_xml_node_get_children (atk_node)) + glade_xml_node_delete (atk_node); + else + glade_xml_node_append_child (node, atk_node); - glade_gtk_widget_write_atk_properties (widget, context, node); + glade_gtk_widget_write_atk_properties (widget, context, node); } static void -glade_gtk_write_accels (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node, - gboolean write_signal) +glade_gtk_write_accels (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node, gboolean write_signal) { - GladeXmlNode *accel_node; - GladeProperty *property; - GList *list; + GladeXmlNode *accel_node; + GladeProperty *property; + GList *list; - /* Some child widgets may have disabled the property */ - if (!(property = glade_widget_get_property (widget, "accelerator"))) - return; + /* Some child widgets may have disabled the property */ + if (!(property = glade_widget_get_property (widget, "accelerator"))) + return; - for (list = g_value_get_boxed (property->value); - list; list = list->next) - { - GladeAccelInfo *accel = list->data; + for (list = g_value_get_boxed (property->value); list; list = list->next) + { + GladeAccelInfo *accel = list->data; - accel_node = glade_accel_write (accel, context, write_signal); - glade_xml_node_append_child (node, accel_node); - } + accel_node = glade_accel_write (accel, context, write_signal); + glade_xml_node_append_child (node, accel_node); + } } void -glade_gtk_widget_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_widget_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) { - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); - /* The core takes care of signals */ - glade_gtk_write_accels (widget, context, node, TRUE); - glade_gtk_widget_write_atk_props (widget, context, node); + /* The core takes care of signals */ + glade_gtk_write_accels (widget, context, node, TRUE); + glade_gtk_widget_write_atk_props (widget, context, node); } GladeEditorProperty * -glade_gtk_widget_create_eprop (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - gboolean use_command) -{ - GladeEditorProperty *eprop; - - /* chain up.. */ - if (klass->pspec->value_type == GLADE_TYPE_ACCEL_GLIST) - eprop = g_object_new (GLADE_TYPE_EPROP_ACCEL, - "property-class", klass, - "use-command", use_command, - NULL); - else - eprop = GWA_GET_CLASS - (G_TYPE_OBJECT)->create_eprop (adaptor, - klass, - use_command); - return eprop; +glade_gtk_widget_create_eprop (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, gboolean use_command) +{ + GladeEditorProperty *eprop; + + /* chain up.. */ + if (klass->pspec->value_type == GLADE_TYPE_ACCEL_GLIST) + eprop = g_object_new (GLADE_TYPE_EPROP_ACCEL, + "property-class", klass, + "use-command", use_command, NULL); + else + eprop = GWA_GET_CLASS + (G_TYPE_OBJECT)->create_eprop (adaptor, klass, use_command); + return eprop; } gchar * -glade_gtk_widget_string_from_value (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - const GValue *value) +glade_gtk_widget_string_from_value (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, + const GValue * value) { - if (klass->pspec->value_type == GLADE_TYPE_ACCEL_GLIST) - return glade_accels_make_string (g_value_get_boxed (value)); - else - return GWA_GET_CLASS - (G_TYPE_OBJECT)->string_from_value (adaptor, - klass, - value); + if (klass->pspec->value_type == GLADE_TYPE_ACCEL_GLIST) + return glade_accels_make_string (g_value_get_boxed (value)); + else + return GWA_GET_CLASS + (G_TYPE_OBJECT)->string_from_value (adaptor, klass, value); } static void -widget_parent_changed (GtkWidget *widget, - GParamSpec *pspec, - GladeWidgetAdaptor *adaptor) +widget_parent_changed (GtkWidget * widget, + GParamSpec * pspec, GladeWidgetAdaptor * adaptor) { - GladeWidget *gwidget = glade_widget_get_from_gobject (widget); + GladeWidget *gwidget = glade_widget_get_from_gobject (widget); - /* this could get called for a stale instance of an object - * being rebuilt for a contruct-only property. */ - if (!gwidget) - return; + /* this could get called for a stale instance of an object + * being rebuilt for a contruct-only property. */ + if (!gwidget) + return; - if (gwidget->parent && gwidget->parent->internal == NULL) - glade_widget_set_action_sensitive (gwidget, "remove_parent", TRUE); - else - glade_widget_set_action_sensitive (gwidget, "remove_parent", FALSE); + if (gwidget->parent && gwidget->parent->internal == NULL) + glade_widget_set_action_sensitive (gwidget, "remove_parent", TRUE); + else + glade_widget_set_action_sensitive (gwidget, "remove_parent", FALSE); } void -glade_gtk_widget_deep_post_create (GladeWidgetAdaptor *adaptor, - GObject *widget, - GladeCreateReason reason) +glade_gtk_widget_deep_post_create (GladeWidgetAdaptor * adaptor, + GObject * widget, GladeCreateReason reason) { - GladeWidget *gwidget = glade_widget_get_from_gobject (widget); + GladeWidget *gwidget = glade_widget_get_from_gobject (widget); + + /* Work around bug 472555 by resetting the default event mask, + * this way only user edits will be saved to the glade file. */ + if (reason == GLADE_CREATE_USER) + glade_widget_property_reset (gwidget, "events"); - /* Work around bug 472555 by resetting the default event mask, - * this way only user edits will be saved to the glade file. */ - if (reason == GLADE_CREATE_USER) - glade_widget_property_reset (gwidget, "events"); - - glade_widget_set_action_sensitive (gwidget, "remove_parent", FALSE); + glade_widget_set_action_sensitive (gwidget, "remove_parent", FALSE); - if (GWA_IS_TOPLEVEL (adaptor) || gwidget->internal) - glade_widget_set_action_sensitive (gwidget, "add_parent", FALSE); + if (GWA_IS_TOPLEVEL (adaptor) || gwidget->internal) + glade_widget_set_action_sensitive (gwidget, "add_parent", FALSE); - /* Watch parents/projects and set actions sensitive/insensitive */ - if (gwidget->internal == NULL) - g_signal_connect (G_OBJECT (widget), "notify::parent", - G_CALLBACK (widget_parent_changed), adaptor); - + /* Watch parents/projects and set actions sensitive/insensitive */ + if (gwidget->internal == NULL) + g_signal_connect (G_OBJECT (widget), "notify::parent", + G_CALLBACK (widget_parent_changed), adaptor); + } void -glade_gtk_widget_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_widget_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - /* FIXME: is this still needed with the new gtk+ tooltips? */ - if (!strcmp (id, "tooltip")) - { - id = "tooltip-text"; - } + /* FIXME: is this still needed with the new gtk+ tooltips? */ + if (!strcmp (id, "tooltip")) + { + id = "tooltip-text"; + } - GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value); + GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value); } void -glade_gtk_widget_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - GValue *value) +glade_gtk_widget_get_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, GValue * value) { - if (!strcmp (id, "tooltip")) - { - id = "tooltip-text"; - } - - GWA_GET_CLASS (G_TYPE_OBJECT)->get_property (adaptor, object, id, value); + if (!strcmp (id, "tooltip")) + { + id = "tooltip-text"; + } + + GWA_GET_CLASS (G_TYPE_OBJECT)->get_property (adaptor, object, id, value); +} + +static GList * +create_command_property_list (GladeWidget * gnew, GList * saved_props) +{ + GList *l, *command_properties = NULL; + + for (l = saved_props; l; l = l->next) + { + GladeProperty *property = l->data; + GladeProperty *orig_prop = + glade_widget_get_pack_property (gnew, property->klass->id); + GCSetPropData *pdata = g_new0 (GCSetPropData, 1); + + pdata->property = orig_prop; + pdata->old_value = g_new0 (GValue, 1); + pdata->new_value = g_new0 (GValue, 1); + + glade_property_get_value (orig_prop, pdata->old_value); + glade_property_get_value (property, pdata->new_value); + + command_properties = g_list_prepend (command_properties, pdata); + } + return g_list_reverse (command_properties); +} + + +void +glade_gtk_widget_action_activate (GladeWidgetAdaptor * adaptor, + GObject * object, const gchar * action_path) +{ + GladeWidget *gwidget = glade_widget_get_from_gobject (object), *gparent; + GList this_widget = { 0, }, that_widget = + { + 0,}; + GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (object)); + GladeProject *project; + + if (parent) + gparent = glade_widget_get_from_gobject (parent); + else + gparent = NULL; + + if (strcmp (action_path, "preview") == 0) + { + project = glade_widget_get_project (gwidget); + glade_project_preview (project, + glade_widget_get_from_gobject ((gpointer) object)); + } + else if (strcmp (action_path, "edit_separate") == 0) + { + GtkWidget *dialog = glade_editor_dialog_for_widget (gwidget); + gtk_widget_show_all (dialog); + } + else if (strcmp (action_path, "remove_parent") == 0) + { + GladeWidget *new_gparent; + + g_return_if_fail (gparent); + new_gparent = gparent->parent; + + glade_command_push_group (_("Removing parent of %s"), gwidget->name); + + /* Remove "this" widget */ + this_widget.data = gwidget; + glade_command_cut (&this_widget); + + /* Delete the parent */ + that_widget.data = gparent; + glade_command_delete (&that_widget); + + /* Add "this" widget to the new parent */ + glade_command_paste (&this_widget, new_gparent, NULL); + + glade_command_pop_group (); + } + else if (strncmp (action_path, "add_parent/", 11) == 0) + { + GType new_type = 0; + + if (strcmp (action_path + 11, "alignment") == 0) + new_type = GTK_TYPE_ALIGNMENT; + else if (strcmp (action_path + 11, "viewport") == 0) + new_type = GTK_TYPE_VIEWPORT; + else if (strcmp (action_path + 11, "eventbox") == 0) + new_type = GTK_TYPE_EVENT_BOX; + else if (strcmp (action_path + 11, "frame") == 0) + new_type = GTK_TYPE_FRAME; + else if (strcmp (action_path + 11, "aspect_frame") == 0) + new_type = GTK_TYPE_ASPECT_FRAME; + else if (strcmp (action_path + 11, "scrolled_window") == 0) + new_type = GTK_TYPE_SCROLLED_WINDOW; + else if (strcmp (action_path + 11, "expander") == 0) + new_type = GTK_TYPE_EXPANDER; + else if (strcmp (action_path + 11, "table") == 0) + new_type = GTK_TYPE_TABLE; + else if (strcmp (action_path + 11, "hbox") == 0) + new_type = GTK_TYPE_HBOX; + else if (strcmp (action_path + 11, "vbox") == 0) + new_type = GTK_TYPE_VBOX; + else if (strcmp (action_path + 11, "hpaned") == 0) + new_type = GTK_TYPE_HPANED; + else if (strcmp (action_path + 11, "vpaned") == 0) + new_type = GTK_TYPE_VPANED; + + + if (new_type) + { + GladeWidgetAdaptor *adaptor = + glade_widget_adaptor_get_by_type (new_type); + GList *saved_props, *prop_cmds; + GladeProject *project; + + /* Dont add non-scrollable widgets to scrolled windows... */ + if (gparent && + glade_util_check_and_warn_scrollable (gparent, adaptor, + glade_app_get_window ())) + return; + + glade_command_push_group (_("Adding parent %s for %s"), + adaptor->title, gwidget->name); + + /* Record packing properties */ + saved_props = + glade_widget_dup_properties (gwidget, gwidget->packing_properties, + FALSE, FALSE, FALSE); + + /* Remove "this" widget */ + this_widget.data = gwidget; + glade_command_cut (&this_widget); + + if (gparent) + project = glade_widget_get_project (gparent); + else + project = glade_app_get_project (); + + /* Create new widget and put it where the placeholder was */ + if ((that_widget.data = + glade_command_create (adaptor, gparent, NULL, project)) != NULL) + { + + /* Remove the alignment that we added in the frame's post_create... */ + if (new_type == GTK_TYPE_FRAME) + { + GObject *frame = glade_widget_get_object (that_widget.data); + GladeWidget *galign = + glade_widget_get_from_gobject (gtk_bin_get_child + (GTK_BIN (frame))); + GList to_delete = { 0, }; + + to_delete.data = galign; + glade_command_delete (&to_delete); + } + + /* Create heavy-duty glade-command properties stuff */ + prop_cmds = + create_command_property_list (that_widget.data, saved_props); + g_list_foreach (saved_props, (GFunc) g_object_unref, NULL); + g_list_free (saved_props); + + /* Apply the properties in an undoable way */ + if (prop_cmds) + glade_command_set_properties_list (glade_widget_get_project + (gparent), prop_cmds); + + /* Add "this" widget to the new parent */ + glade_command_paste (&this_widget, + GLADE_WIDGET (that_widget.data), NULL); + } + else + /* Create parent was cancelled, paste back to parent */ + glade_command_paste (&this_widget, gparent, NULL); + + glade_command_pop_group (); + } + } + else if (strcmp (action_path, "sizegroup_add") == 0) + { + /* Ignore dummy */ + } + else + GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor, + object, action_path); } static GList * -create_command_property_list (GladeWidget *gnew, GList *saved_props) -{ - GList *l, *command_properties = NULL; - - for (l = saved_props; l; l = l->next) - { - GladeProperty *property = l->data; - GladeProperty *orig_prop = glade_widget_get_pack_property (gnew, property->klass->id); - GCSetPropData *pdata = g_new0 (GCSetPropData, 1); - - pdata->property = orig_prop; - pdata->old_value = g_new0 (GValue, 1); - pdata->new_value = g_new0 (GValue, 1); - - glade_property_get_value (orig_prop, pdata->old_value); - glade_property_get_value (property, pdata->new_value); - - command_properties = g_list_prepend (command_properties, pdata); - } - return g_list_reverse (command_properties); -} - - -void -glade_gtk_widget_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) -{ - GladeWidget *gwidget = glade_widget_get_from_gobject (object), *gparent; - GList this_widget = { 0, }, that_widget = { 0, }; - GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (object)); - GladeProject *project; - - if (parent) - gparent = glade_widget_get_from_gobject (parent); - else - gparent = NULL; - - if (strcmp (action_path, "preview") == 0) - { - project = glade_widget_get_project (gwidget); - glade_project_preview (project, - glade_widget_get_from_gobject((gpointer)object) - ); - } - else if (strcmp (action_path, "edit_separate") == 0) - { - GtkWidget *dialog = - glade_editor_dialog_for_widget (gwidget); - gtk_widget_show_all (dialog); - } - else if (strcmp (action_path, "remove_parent") == 0) - { - GladeWidget *new_gparent; - - g_return_if_fail (gparent); - new_gparent = gparent->parent; - - glade_command_push_group (_("Removing parent of %s"), - gwidget->name); - - /* Remove "this" widget */ - this_widget.data = gwidget; - glade_command_cut (&this_widget); - - /* Delete the parent */ - that_widget.data = gparent; - glade_command_delete (&that_widget); - - /* Add "this" widget to the new parent */ - glade_command_paste(&this_widget, new_gparent, NULL); - - glade_command_pop_group (); - } - else if (strncmp (action_path, "add_parent/", 11) == 0) - { - GType new_type = 0; - - if (strcmp (action_path + 11, "alignment") == 0) - new_type = GTK_TYPE_ALIGNMENT; - else if (strcmp (action_path + 11, "viewport") == 0) - new_type = GTK_TYPE_VIEWPORT; - else if (strcmp (action_path + 11, "eventbox") == 0) - new_type = GTK_TYPE_EVENT_BOX; - else if (strcmp (action_path + 11, "frame") == 0) - new_type = GTK_TYPE_FRAME; - else if (strcmp (action_path + 11, "aspect_frame") == 0) - new_type = GTK_TYPE_ASPECT_FRAME; - else if (strcmp (action_path + 11, "scrolled_window") == 0) - new_type = GTK_TYPE_SCROLLED_WINDOW; - else if (strcmp (action_path + 11, "expander") == 0) - new_type = GTK_TYPE_EXPANDER; - else if (strcmp (action_path + 11, "table") == 0) - new_type = GTK_TYPE_TABLE; - else if (strcmp (action_path + 11, "hbox") == 0) - new_type = GTK_TYPE_HBOX; - else if (strcmp (action_path + 11, "vbox") == 0) - new_type = GTK_TYPE_VBOX; - else if (strcmp (action_path + 11, "hpaned") == 0) - new_type = GTK_TYPE_HPANED; - else if (strcmp (action_path + 11, "vpaned") == 0) - new_type = GTK_TYPE_VPANED; - - - if (new_type) - { - GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (new_type); - GList *saved_props, *prop_cmds; - GladeProject *project; - - /* Dont add non-scrollable widgets to scrolled windows... */ - if (gparent && - glade_util_check_and_warn_scrollable (gparent, adaptor, glade_app_get_window())) - return; - - glade_command_push_group (_("Adding parent %s for %s"), - adaptor->title, gwidget->name); - - /* Record packing properties */ - saved_props = glade_widget_dup_properties (gwidget, gwidget->packing_properties, FALSE, FALSE, FALSE); - - /* Remove "this" widget */ - this_widget.data = gwidget; - glade_command_cut (&this_widget); - - if (gparent) - project = glade_widget_get_project (gparent); - else - project = glade_app_get_project (); - - /* Create new widget and put it where the placeholder was */ - if ((that_widget.data = - glade_command_create (adaptor, gparent, NULL, project)) != NULL) - { - - /* Remove the alignment that we added in the frame's post_create... */ - if (new_type == GTK_TYPE_FRAME) - { - GObject *frame = glade_widget_get_object (that_widget.data); - GladeWidget *galign = glade_widget_get_from_gobject (gtk_bin_get_child (GTK_BIN (frame))); - GList to_delete = { 0, }; - - to_delete.data = galign; - glade_command_delete (&to_delete); - } - - /* Create heavy-duty glade-command properties stuff */ - prop_cmds = create_command_property_list (that_widget.data, saved_props); - g_list_foreach (saved_props, (GFunc)g_object_unref, NULL); - g_list_free (saved_props); - - /* Apply the properties in an undoable way */ - if (prop_cmds) - glade_command_set_properties_list (glade_widget_get_project (gparent), prop_cmds); - - /* Add "this" widget to the new parent */ - glade_command_paste(&this_widget, GLADE_WIDGET (that_widget.data), NULL); - } - else - /* Create parent was cancelled, paste back to parent */ - glade_command_paste(&this_widget, gparent, NULL); - - glade_command_pop_group (); - } - } - else if (strcmp (action_path, "sizegroup_add") == 0) - { - /* Ignore dummy */ - } - else - GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor, - object, - action_path); -} - -static GList *list_sizegroups (GladeWidget *gwidget) -{ - GladeProject *project = glade_widget_get_project (gwidget); - GList *groups = NULL; - const GList *list; - - for (list = glade_project_get_objects (project); list; list = list->next) - { - GladeWidget *iter = glade_widget_get_from_gobject (list->data); - if (GTK_IS_SIZE_GROUP (iter->object)) - groups = g_list_prepend (groups, iter); - } - return g_list_reverse (groups); +list_sizegroups (GladeWidget * gwidget) +{ + GladeProject *project = glade_widget_get_project (gwidget); + GList *groups = NULL; + const GList *list; + + for (list = glade_project_get_objects (project); list; list = list->next) + { + GladeWidget *iter = glade_widget_get_from_gobject (list->data); + if (GTK_IS_SIZE_GROUP (iter->object)) + groups = g_list_prepend (groups, iter); + } + return g_list_reverse (groups); } static void -glade_gtk_widget_add2group_cb (GtkMenuItem *item, GladeWidget *gwidget) +glade_gtk_widget_add2group_cb (GtkMenuItem * item, GladeWidget * gwidget) { - GladeWidget *group = g_object_get_data (G_OBJECT (item), "glade-group-widget"); - GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_SIZE_GROUP); - GList *widget_list = NULL, *new_list; - GladeProperty *property; + GladeWidget *group = + g_object_get_data (G_OBJECT (item), "glade-group-widget"); + GladeWidgetAdaptor *adaptor = + glade_widget_adaptor_get_by_type (GTK_TYPE_SIZE_GROUP); + GList *widget_list = NULL, *new_list; + GladeProperty *property; - if (group) - glade_command_push_group (_("Adding %s to Size Group %s"), gwidget->name, group->name); - else - glade_command_push_group (_("Adding %s to a new Size Group"), gwidget->name); + if (group) + glade_command_push_group (_("Adding %s to Size Group %s"), gwidget->name, + group->name); + else + glade_command_push_group (_("Adding %s to a new Size Group"), + gwidget->name); - if (!group) - /* Cant cancel a size group */ - group = glade_command_create (adaptor, NULL, NULL, glade_widget_get_project (gwidget)); - - property = glade_widget_get_property (group, "widgets"); - glade_property_get (property, &widget_list); - new_list = g_list_copy (widget_list); - if (!g_list_find (widget_list, gwidget->object)) - new_list = g_list_append (new_list, gwidget->object); - glade_command_set_property (property, new_list); + if (!group) + /* Cant cancel a size group */ + group = + glade_command_create (adaptor, NULL, NULL, + glade_widget_get_project (gwidget)); - g_list_free (new_list); - - glade_command_pop_group (); -} + property = glade_widget_get_property (group, "widgets"); + glade_property_get (property, &widget_list); + new_list = g_list_copy (widget_list); + if (!g_list_find (widget_list, gwidget->object)) + new_list = g_list_append (new_list, gwidget->object); + glade_command_set_property (property, new_list); + g_list_free (new_list); -GtkWidget * -glade_gtk_widget_action_submenu (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) -{ - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - GList *groups, *list; - - if (strcmp (action_path, "sizegroup_add") == 0) - { - GtkWidget *menu = gtk_menu_new (); - GtkWidget *separator, *item; - GladeWidget *group; - - if ((groups = list_sizegroups (gwidget)) != NULL) - { - for (list = groups; list; list = list->next) - { - group = list->data; - item = gtk_menu_item_new_with_label (group->name); - - g_object_set_data (G_OBJECT (item), "glade-group-widget", group); - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (glade_gtk_widget_add2group_cb), gwidget); - - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - } - g_list_free (groups); - - separator = gtk_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator); - gtk_widget_show (separator); - } - - /* Add trailing new... item */ - item = gtk_menu_item_new_with_label (_("New Size Group")); - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (glade_gtk_widget_add2group_cb), gwidget); - - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - return menu; - } - else if (GWA_GET_CLASS (G_TYPE_OBJECT)->action_submenu) - return GWA_GET_CLASS (G_TYPE_OBJECT)->action_submenu (adaptor, - object, - action_path); - - return NULL; + glade_command_pop_group (); } +GtkWidget * +glade_gtk_widget_action_submenu (GladeWidgetAdaptor * adaptor, + GObject * object, const gchar * action_path) +{ + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GList *groups, *list; + + if (strcmp (action_path, "sizegroup_add") == 0) + { + GtkWidget *menu = gtk_menu_new (); + GtkWidget *separator, *item; + GladeWidget *group; + + if ((groups = list_sizegroups (gwidget)) != NULL) + { + for (list = groups; list; list = list->next) + { + group = list->data; + item = gtk_menu_item_new_with_label (group->name); + + g_object_set_data (G_OBJECT (item), "glade-group-widget", group); + g_signal_connect (G_OBJECT (item), "activate", + G_CALLBACK (glade_gtk_widget_add2group_cb), + gwidget); + + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + } + g_list_free (groups); + + separator = gtk_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator); + gtk_widget_show (separator); + } -/* ----------------------------- GtkContainer ------------------------------ */ -void -glade_gtk_container_post_create (GladeWidgetAdaptor *adaptor, - GObject *container, - GladeCreateReason reason) -{ - GList *children; - g_return_if_fail (GTK_IS_CONTAINER (container)); - - if (reason == GLADE_CREATE_USER) - { - if ((children = gtk_container_get_children (GTK_CONTAINER (container))) == NULL) - gtk_container_add (GTK_CONTAINER (container), glade_placeholder_new ()); - else - g_list_free (children); - } -} + /* Add trailing new... item */ + item = gtk_menu_item_new_with_label (_("New Size Group")); + g_signal_connect (G_OBJECT (item), "activate", + G_CALLBACK (glade_gtk_widget_add2group_cb), gwidget); -void -glade_gtk_container_replace_child (GladeWidgetAdaptor *adaptor, - GtkWidget *container, - GtkWidget *current, - GtkWidget *new_widget) -{ - GParamSpec **param_spec; - GladePropertyClass *pclass; - GValue *value; - guint nproperties; - guint i; + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - if (gtk_widget_get_parent (current) != container) - return; + return menu; + } + else if (GWA_GET_CLASS (G_TYPE_OBJECT)->action_submenu) + return GWA_GET_CLASS (G_TYPE_OBJECT)->action_submenu (adaptor, + object, action_path); - param_spec = gtk_container_class_list_child_properties - (G_OBJECT_GET_CLASS (container), &nproperties); - value = g_malloc0 (sizeof(GValue) * nproperties); + return NULL; +} - for (i = 0; i < nproperties; i++) - { - g_value_init (&value[i], param_spec[i]->value_type); - gtk_container_child_get_property - (GTK_CONTAINER (container), current, param_spec[i]->name, &value[i]); - } - gtk_container_remove (GTK_CONTAINER (container), current); - gtk_container_add (GTK_CONTAINER (container), new_widget); - for (i = 0; i < nproperties; i++) - { - /* If the added widget is a placeholder then we - * want to keep all the "tranfer-on-paste" properties - * as default so that it looks fresh (transfer-on-paste - * properties dont effect the position/slot inside a - * contianer) - */ - if (GLADE_IS_PLACEHOLDER (new_widget)) - { - pclass = glade_widget_adaptor_get_pack_property_class - (adaptor, param_spec[i]->name); +/* ----------------------------- GtkContainer ------------------------------ */ +void +glade_gtk_container_post_create (GladeWidgetAdaptor * adaptor, + GObject * container, GladeCreateReason reason) +{ + GList *children; + g_return_if_fail (GTK_IS_CONTAINER (container)); + + if (reason == GLADE_CREATE_USER) + { + if ((children = + gtk_container_get_children (GTK_CONTAINER (container))) == NULL) + gtk_container_add (GTK_CONTAINER (container), glade_placeholder_new ()); + else + g_list_free (children); + } +} + +void +glade_gtk_container_replace_child (GladeWidgetAdaptor * adaptor, + GtkWidget * container, + GtkWidget * current, GtkWidget * new_widget) +{ + GParamSpec **param_spec; + GladePropertyClass *pclass; + GValue *value; + guint nproperties; + guint i; + + if (gtk_widget_get_parent (current) != container) + return; + + param_spec = gtk_container_class_list_child_properties + (G_OBJECT_GET_CLASS (container), &nproperties); + value = g_malloc0 (sizeof (GValue) * nproperties); + + for (i = 0; i < nproperties; i++) + { + g_value_init (&value[i], param_spec[i]->value_type); + gtk_container_child_get_property + (GTK_CONTAINER (container), current, param_spec[i]->name, &value[i]); + } + + gtk_container_remove (GTK_CONTAINER (container), current); + gtk_container_add (GTK_CONTAINER (container), new_widget); + + for (i = 0; i < nproperties; i++) + { + /* If the added widget is a placeholder then we + * want to keep all the "tranfer-on-paste" properties + * as default so that it looks fresh (transfer-on-paste + * properties dont effect the position/slot inside a + * contianer) + */ + if (GLADE_IS_PLACEHOLDER (new_widget)) + { + pclass = glade_widget_adaptor_get_pack_property_class + (adaptor, param_spec[i]->name); + + if (pclass && pclass->transfer_on_paste) + continue; + } - if (pclass && pclass->transfer_on_paste) - continue; - } + gtk_container_child_set_property + (GTK_CONTAINER (container), new_widget, param_spec[i]->name, + &value[i]); + } - gtk_container_child_set_property - (GTK_CONTAINER (container), new_widget, param_spec[i]->name, &value[i]); - } - - for (i = 0; i < nproperties; i++) - g_value_unset (&value[i]); + for (i = 0; i < nproperties; i++) + g_value_unset (&value[i]); - g_free (param_spec); - g_free (value); + g_free (param_spec); + g_free (value); } void -glade_gtk_container_add_child (GladeWidgetAdaptor *adaptor, - GtkWidget *container, - GtkWidget *child) +glade_gtk_container_add_child (GladeWidgetAdaptor * adaptor, + GtkWidget * container, GtkWidget * child) { - GtkWidget *container_child = NULL; + GtkWidget *container_child = NULL; - if (GTK_IS_BIN (container)) - container_child = gtk_bin_get_child (GTK_BIN (container)); + if (GTK_IS_BIN (container)) + container_child = gtk_bin_get_child (GTK_BIN (container)); - /* Get a placeholder out of the way before adding the child if its a GtkBin - */ - if (GTK_IS_BIN (container) && container_child != NULL && - GLADE_IS_PLACEHOLDER (container_child)) - gtk_container_remove (GTK_CONTAINER (container), container_child); + /* Get a placeholder out of the way before adding the child if its a GtkBin + */ + if (GTK_IS_BIN (container) && container_child != NULL && + GLADE_IS_PLACEHOLDER (container_child)) + gtk_container_remove (GTK_CONTAINER (container), container_child); - gtk_container_add (GTK_CONTAINER (container), child); + gtk_container_add (GTK_CONTAINER (container), child); } void -glade_gtk_container_remove_child (GladeWidgetAdaptor *adaptor, - GtkWidget *container, - GtkWidget *child) +glade_gtk_container_remove_child (GladeWidgetAdaptor * adaptor, + GtkWidget * container, GtkWidget * child) { - GList *children; - gtk_container_remove (GTK_CONTAINER (container), child); + GList *children; + gtk_container_remove (GTK_CONTAINER (container), child); - /* If this is the last one, add a placeholder by default. - */ - if ((children = gtk_container_get_children (GTK_CONTAINER (container))) == NULL) - { - gtk_container_add (GTK_CONTAINER (container), glade_placeholder_new ()); - } - else - g_list_free (children); + /* If this is the last one, add a placeholder by default. + */ + if ((children = + gtk_container_get_children (GTK_CONTAINER (container))) == NULL) + { + gtk_container_add (GTK_CONTAINER (container), glade_placeholder_new ()); + } + else + g_list_free (children); } void -glade_gtk_container_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) +glade_gtk_container_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + const GValue * value) { - if (gtk_widget_get_parent (GTK_WIDGET (child)) == GTK_WIDGET (container)) - gtk_container_child_set_property (GTK_CONTAINER (container), - GTK_WIDGET (child), - property_name, value); + if (gtk_widget_get_parent (GTK_WIDGET (child)) == GTK_WIDGET (container)) + gtk_container_child_set_property (GTK_CONTAINER (container), + GTK_WIDGET (child), property_name, value); } void -glade_gtk_container_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) +glade_gtk_container_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) { - if (gtk_widget_get_parent (GTK_WIDGET (child)) == GTK_WIDGET (container)) - gtk_container_child_get_property (GTK_CONTAINER (container), - GTK_WIDGET (child), - property_name, value); + if (gtk_widget_get_parent (GTK_WIDGET (child)) == GTK_WIDGET (container)) + gtk_container_child_get_property (GTK_CONTAINER (container), + GTK_WIDGET (child), property_name, value); } GList * -glade_gtk_container_get_children (GladeWidgetAdaptor *adaptor, - GtkContainer *container) +glade_gtk_container_get_children (GladeWidgetAdaptor * adaptor, + GtkContainer * container) { - return glade_util_container_get_all_children (container); + return glade_util_container_get_all_children (container); } GladeEditable * -glade_gtk_container_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_container_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); + return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); } /* ----------------------------- GtkBox ------------------------------ */ GladeWidget * -glade_gtk_create_fixed_widget (GladeWidgetAdaptor *adaptor, - const gchar *first_property_name, - va_list var_args) +glade_gtk_create_fixed_widget (GladeWidgetAdaptor * adaptor, + const gchar * first_property_name, + va_list var_args) { - return (GladeWidget *)g_object_new_valist (GLADE_TYPE_FIXED, first_property_name, var_args); + return (GladeWidget *) g_object_new_valist (GLADE_TYPE_FIXED, + first_property_name, var_args); } -typedef struct { - GtkWidget *widget; - gint position; +typedef struct +{ + GtkWidget *widget; + gint position; } GladeGtkBoxChild; static GList *glade_gtk_box_original_positions = NULL; static gboolean -glade_gtk_box_configure_child (GladeFixed *fixed, - GladeWidget *child, - GdkRectangle *rect, - GtkWidget *box) -{ - GList *list, *children; - GtkWidget *bchild; - GtkAllocation allocation, bchild_allocation; - gint point, trans_point, span, - iter_span, position, old_position, - offset, orig_offset; - gboolean found = FALSE; - - gtk_widget_get_allocation (GTK_WIDGET (child->object), &allocation); - if (GTK_IS_HBOX (box) || GTK_IS_HBUTTON_BOX (box)) - { - point = fixed->mouse_x; - span = allocation.width; - offset = rect->x; - orig_offset = fixed->child_x_origin; - } - else - { - point = fixed->mouse_y; - span = allocation.height; - offset = rect->y; - orig_offset = fixed->child_y_origin; - } - - glade_widget_pack_property_get - (child, "position", &old_position); - - children = gtk_container_get_children (GTK_CONTAINER (box)); - - for (list = children; list; list = list->next) - { - bchild = list->data; - - if (bchild == GTK_WIDGET (child->object)) - continue; - - /* Find the widget in the box where the center of - * this rectangle fits... and set the position to that - * position. - */ - - gtk_widget_get_allocation (GTK_WIDGET (bchild), &bchild_allocation); - if (GTK_IS_HBOX (box) || GTK_IS_HBUTTON_BOX (box)) - { - gtk_widget_translate_coordinates - (GTK_WIDGET (box), bchild, - point, 0, &trans_point, NULL); - - iter_span = bchild_allocation.width; - } - else - { - gtk_widget_translate_coordinates - (GTK_WIDGET (box), bchild, - 0, point, NULL, &trans_point); - iter_span = bchild_allocation.height; - } +glade_gtk_box_configure_child (GladeFixed * fixed, + GladeWidget * child, + GdkRectangle * rect, GtkWidget * box) +{ + GList *list, *children; + GtkWidget *bchild; + GtkAllocation allocation, bchild_allocation; + gint point, trans_point, span, + iter_span, position, old_position, offset, orig_offset; + gboolean found = FALSE; + + gtk_widget_get_allocation (GTK_WIDGET (child->object), &allocation); + if (GTK_IS_HBOX (box) || GTK_IS_HBUTTON_BOX (box)) + { + point = fixed->mouse_x; + span = allocation.width; + offset = rect->x; + orig_offset = fixed->child_x_origin; + } + else + { + point = fixed->mouse_y; + span = allocation.height; + offset = rect->y; + orig_offset = fixed->child_y_origin; + } + + glade_widget_pack_property_get (child, "position", &old_position); + + children = gtk_container_get_children (GTK_CONTAINER (box)); + + for (list = children; list; list = list->next) + { + bchild = list->data; + + if (bchild == GTK_WIDGET (child->object)) + continue; + + /* Find the widget in the box where the center of + * this rectangle fits... and set the position to that + * position. + */ + + gtk_widget_get_allocation (GTK_WIDGET (bchild), &bchild_allocation); + if (GTK_IS_HBOX (box) || GTK_IS_HBUTTON_BOX (box)) + { + gtk_widget_translate_coordinates + (GTK_WIDGET (box), bchild, point, 0, &trans_point, NULL); + + iter_span = bchild_allocation.width; + } + else + { + gtk_widget_translate_coordinates + (GTK_WIDGET (box), bchild, 0, point, NULL, &trans_point); + iter_span = bchild_allocation.height; + } #if 0 - gtk_container_child_get (GTK_CONTAINER (box), - bchild, - "position", &position, NULL); - g_print ("widget: %p pos %d, point %d, trans_point %d, iter_span %d\n", - bchild, position, point, trans_point, iter_span); + gtk_container_child_get (GTK_CONTAINER (box), + bchild, "position", &position, NULL); + g_print ("widget: %p pos %d, point %d, trans_point %d, iter_span %d\n", + bchild, position, point, trans_point, iter_span); #endif - if (iter_span <= span) - { - found = trans_point >= 0 && trans_point < iter_span; - } - else - { - if (offset > orig_offset) - found = trans_point >= iter_span - span && - trans_point < iter_span; - else if (offset < orig_offset) - found = trans_point >= 0 && - trans_point < span; - } - - if (found) - { - gtk_container_child_get (GTK_CONTAINER (box), - bchild, - "position", &position, NULL); + if (iter_span <= span) + { + found = trans_point >= 0 && trans_point < iter_span; + } + else + { + if (offset > orig_offset) + found = trans_point >= iter_span - span && trans_point < iter_span; + else if (offset < orig_offset) + found = trans_point >= 0 && trans_point < span; + } + + if (found) + { + gtk_container_child_get (GTK_CONTAINER (box), + bchild, "position", &position, NULL); #if 0 - g_print ("setting position of %s from %d to %d, " - "(point %d iter_span %d)\n", - child->name, old_position, position, trans_point, iter_span); + g_print ("setting position of %s from %d to %d, " + "(point %d iter_span %d)\n", + child->name, old_position, position, trans_point, iter_span); #endif - glade_widget_pack_property_set - (child, "position", position); - - break; - } + glade_widget_pack_property_set (child, "position", position); + + break; + } - } + } - g_list_free (children); + g_list_free (children); - return TRUE; + return TRUE; } static gboolean -glade_gtk_box_configure_begin (GladeFixed *fixed, - GladeWidget *child, - GtkWidget *box) +glade_gtk_box_configure_begin (GladeFixed * fixed, + GladeWidget * child, GtkWidget * box) { - GList *list, *children; - GtkWidget *bchild; + GList *list, *children; + GtkWidget *bchild; - g_assert (glade_gtk_box_original_positions == NULL); + g_assert (glade_gtk_box_original_positions == NULL); - children = gtk_container_get_children (GTK_CONTAINER (box)); + children = gtk_container_get_children (GTK_CONTAINER (box)); - for (list = children; list; list = list->next) - { - GladeGtkBoxChild *gbchild; - GladeWidget *gchild; - - bchild = list->data; - if ((gchild = glade_widget_get_from_gobject (bchild)) == NULL) - continue; + for (list = children; list; list = list->next) + { + GladeGtkBoxChild *gbchild; + GladeWidget *gchild; - gbchild = g_new0 (GladeGtkBoxChild, 1); - gbchild->widget = bchild; - glade_widget_pack_property_get (gchild, "position", - &gbchild->position); + bchild = list->data; + if ((gchild = glade_widget_get_from_gobject (bchild)) == NULL) + continue; - glade_gtk_box_original_positions = - g_list_prepend (glade_gtk_box_original_positions, gbchild); - } + gbchild = g_new0 (GladeGtkBoxChild, 1); + gbchild->widget = bchild; + glade_widget_pack_property_get (gchild, "position", &gbchild->position); - g_list_free (children); + glade_gtk_box_original_positions = + g_list_prepend (glade_gtk_box_original_positions, gbchild); + } - return TRUE; + g_list_free (children); + + return TRUE; } static gboolean -glade_gtk_box_configure_end (GladeFixed *fixed, - GladeWidget *child, - GtkWidget *box) +glade_gtk_box_configure_end (GladeFixed * fixed, + GladeWidget * child, GtkWidget * box) { - GList *list, *l, *children; - GList *prop_list = NULL; + GList *list, *l, *children; + GList *prop_list = NULL; - children = gtk_container_get_children (GTK_CONTAINER (box)); + children = gtk_container_get_children (GTK_CONTAINER (box)); - for (list = children; list; list = list->next) - { - GtkWidget *bchild = list->data; + for (list = children; list; list = list->next) + { + GtkWidget *bchild = list->data; - for (l = glade_gtk_box_original_positions; l; l = l->next) - { - GladeGtkBoxChild *gbchild = l->data; - GladeWidget *gchild = - glade_widget_get_from_gobject (gbchild->widget); + for (l = glade_gtk_box_original_positions; l; l = l->next) + { + GladeGtkBoxChild *gbchild = l->data; + GladeWidget *gchild = glade_widget_get_from_gobject (gbchild->widget); - if (bchild == gbchild->widget) - { - GCSetPropData *prop_data = g_new0 (GCSetPropData, 1); - prop_data->property = - glade_widget_get_pack_property - (gchild, "position"); + if (bchild == gbchild->widget) + { + GCSetPropData *prop_data = g_new0 (GCSetPropData, 1); + prop_data->property = + glade_widget_get_pack_property (gchild, "position"); - prop_data->old_value = g_new0 (GValue, 1); - prop_data->new_value = g_new0 (GValue, 1); + prop_data->old_value = g_new0 (GValue, 1); + prop_data->new_value = g_new0 (GValue, 1); - glade_property_get_value (prop_data->property, - prop_data->new_value); + glade_property_get_value (prop_data->property, + prop_data->new_value); - g_value_init (prop_data->old_value, G_TYPE_INT); - g_value_set_int (prop_data->old_value, gbchild->position); + g_value_init (prop_data->old_value, G_TYPE_INT); + g_value_set_int (prop_data->old_value, gbchild->position); - prop_list = g_list_prepend (prop_list, prop_data); - break; - } - } - } + prop_list = g_list_prepend (prop_list, prop_data); + break; + } + } + } - g_list_free (children); + g_list_free (children); - glade_command_push_group (_("Ordering children of %s"), - GLADE_WIDGET (fixed)->name); - glade_property_push_superuser (); - if (prop_list) - glade_command_set_properties_list (GLADE_WIDGET (fixed)->project, - prop_list); - glade_property_pop_superuser (); - glade_command_pop_group (); + glade_command_push_group (_("Ordering children of %s"), + GLADE_WIDGET (fixed)->name); + glade_property_push_superuser (); + if (prop_list) + glade_command_set_properties_list (GLADE_WIDGET (fixed)->project, + prop_list); + glade_property_pop_superuser (); + glade_command_pop_group (); - for (l = glade_gtk_box_original_positions; l; l = l->next) - g_free (l->data); + for (l = glade_gtk_box_original_positions; l; l = l->next) + g_free (l->data); - glade_gtk_box_original_positions = - (g_list_free (glade_gtk_box_original_positions), NULL); + glade_gtk_box_original_positions = + (g_list_free (glade_gtk_box_original_positions), NULL); - return TRUE; + return TRUE; } void -glade_gtk_box_post_create (GladeWidgetAdaptor *adaptor, - GObject *container, - GladeCreateReason reason) +glade_gtk_box_post_create (GladeWidgetAdaptor * adaptor, + GObject * container, GladeCreateReason reason) { - GladeWidget *gwidget = - glade_widget_get_from_gobject (container); + GladeWidget *gwidget = glade_widget_get_from_gobject (container); - /* Implement drag in GtkBox but not resize. - */ - g_object_set (gwidget, - "can-resize", FALSE, - NULL); + /* Implement drag in GtkBox but not resize. + */ + g_object_set (gwidget, "can-resize", FALSE, NULL); - g_signal_connect (G_OBJECT (gwidget), "configure-child", - G_CALLBACK (glade_gtk_box_configure_child), container); + g_signal_connect (G_OBJECT (gwidget), "configure-child", + G_CALLBACK (glade_gtk_box_configure_child), container); - g_signal_connect (G_OBJECT (gwidget), "configure-begin", - G_CALLBACK (glade_gtk_box_configure_begin), container); + g_signal_connect (G_OBJECT (gwidget), "configure-begin", + G_CALLBACK (glade_gtk_box_configure_begin), container); - g_signal_connect (G_OBJECT (gwidget), "configure-end", - G_CALLBACK (glade_gtk_box_configure_end), container); + g_signal_connect (G_OBJECT (gwidget), "configure-end", + G_CALLBACK (glade_gtk_box_configure_end), container); } static gint -sort_box_children (GtkWidget *widget_a, GtkWidget *widget_b) +sort_box_children (GtkWidget * widget_a, GtkWidget * widget_b) { - GtkWidget *box; - GladeWidget *gwidget_a, *gwidget_b; - gint position_a, position_b; + GtkWidget *box; + GladeWidget *gwidget_a, *gwidget_b; + gint position_a, position_b; - gwidget_a = glade_widget_get_from_gobject (widget_a); - gwidget_b = glade_widget_get_from_gobject (widget_b); + gwidget_a = glade_widget_get_from_gobject (widget_a); + gwidget_b = glade_widget_get_from_gobject (widget_b); - box = gtk_widget_get_parent (widget_a); + box = gtk_widget_get_parent (widget_a); - if (gwidget_a) - glade_widget_pack_property_get - (gwidget_a, "position", &position_a); - else - gtk_container_child_get (GTK_CONTAINER (box), - widget_a, - "position", &position_a, - NULL); + if (gwidget_a) + glade_widget_pack_property_get (gwidget_a, "position", &position_a); + else + gtk_container_child_get (GTK_CONTAINER (box), + widget_a, "position", &position_a, NULL); - if (gwidget_b) - glade_widget_pack_property_get - (gwidget_b, "position", &position_b); - else - gtk_container_child_get (GTK_CONTAINER (box), - widget_b, - "position", &position_b, - NULL); - return position_a - position_b; + if (gwidget_b) + glade_widget_pack_property_get (gwidget_b, "position", &position_b); + else + gtk_container_child_get (GTK_CONTAINER (box), + widget_b, "position", &position_b, NULL); + return position_a - position_b; } GList * -glade_gtk_box_get_children (GladeWidgetAdaptor *adaptor, - GtkContainer *container) -{ - GList *children = glade_util_container_get_all_children (container); - - return g_list_sort (children, (GCompareFunc)sort_box_children); -} - -void -glade_gtk_box_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - GladeWidget *gbox, *gchild, *gchild_iter; - GList *children, *list; - gboolean is_position; - gint old_position, iter_position, new_position; - static gboolean recursion = FALSE; - - g_return_if_fail (GTK_IS_BOX (container)); - g_return_if_fail (GTK_IS_WIDGET (child)); - g_return_if_fail (property_name != NULL || value != NULL); - - gbox = glade_widget_get_from_gobject (container); - gchild = glade_widget_get_from_gobject (child); - - g_return_if_fail (GLADE_IS_WIDGET (gbox)); - - if (gtk_widget_get_parent (GTK_WIDGET (child)) != GTK_WIDGET (container)) - return; - - /* Get old position */ - if ((is_position = (strcmp (property_name, "position") == 0)) != FALSE) - { - gtk_container_child_get (GTK_CONTAINER (container), - GTK_WIDGET (child), - property_name, &old_position, NULL); - - - /* Get the real value */ - new_position = g_value_get_int (value); - } - - if (is_position && recursion == FALSE) - { - children = glade_widget_adaptor_get_children - (gbox->adaptor, container); - - children = g_list_sort (children, (GCompareFunc)sort_box_children); - - for (list = children; list; list = list->next) - { - if ((gchild_iter = - glade_widget_get_from_gobject (list->data)) == NULL) - continue; - - if (gchild_iter == gchild) - { - gtk_box_reorder_child (GTK_BOX (container), - GTK_WIDGET (child), - new_position); - continue; - } - - /* Get the old value from glade */ - glade_widget_pack_property_get - (gchild_iter, "position", &iter_position); - - /* Search for the child at the old position and update it */ - if (iter_position == new_position && - glade_property_superuser () == FALSE) - { - /* Update glade with the real value */ - recursion = TRUE; - glade_widget_pack_property_set - (gchild_iter, "position", old_position); - recursion = FALSE; - continue; - } - else - { - gtk_box_reorder_child (GTK_BOX (container), - GTK_WIDGET (list->data), - iter_position); - } - } - - for (list = children; list; list = list->next) - { - if ((gchild_iter = - glade_widget_get_from_gobject (list->data)) == NULL) - continue; - - /* Refresh values yet again */ - glade_widget_pack_property_get - (gchild_iter, "position", &iter_position); - - gtk_box_reorder_child (GTK_BOX (container), - GTK_WIDGET (list->data), - iter_position); - - } - - if (children) - g_list_free (children); - } - - /* Chain Up */ - if (!is_position) - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, - child, - property_name, - value); - - gtk_container_check_resize (GTK_CONTAINER (container)); - -} - -void -glade_gtk_box_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - GValue *value) -{ - if (!strcmp (id, "size")) - { - GtkBox *box = GTK_BOX (object); - GList *children = gtk_container_get_children (GTK_CONTAINER (box)); - - g_value_reset (value); - g_value_set_int (value, g_list_length (children)); - g_list_free (children); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->get_property (adaptor, object, id, value); +glade_gtk_box_get_children (GladeWidgetAdaptor * adaptor, + GtkContainer * container) +{ + GList *children = glade_util_container_get_all_children (container); + + return g_list_sort (children, (GCompareFunc) sort_box_children); +} + +void +glade_gtk_box_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, GValue * value) +{ + GladeWidget *gbox, *gchild, *gchild_iter; + GList *children, *list; + gboolean is_position; + gint old_position, iter_position, new_position; + static gboolean recursion = FALSE; + + g_return_if_fail (GTK_IS_BOX (container)); + g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (property_name != NULL || value != NULL); + + gbox = glade_widget_get_from_gobject (container); + gchild = glade_widget_get_from_gobject (child); + + g_return_if_fail (GLADE_IS_WIDGET (gbox)); + + if (gtk_widget_get_parent (GTK_WIDGET (child)) != GTK_WIDGET (container)) + return; + + /* Get old position */ + if ((is_position = (strcmp (property_name, "position") == 0)) != FALSE) + { + gtk_container_child_get (GTK_CONTAINER (container), + GTK_WIDGET (child), + property_name, &old_position, NULL); + + + /* Get the real value */ + new_position = g_value_get_int (value); + } + + if (is_position && recursion == FALSE) + { + children = glade_widget_adaptor_get_children (gbox->adaptor, container); + + children = g_list_sort (children, (GCompareFunc) sort_box_children); + + for (list = children; list; list = list->next) + { + if ((gchild_iter = + glade_widget_get_from_gobject (list->data)) == NULL) + continue; + + if (gchild_iter == gchild) + { + gtk_box_reorder_child (GTK_BOX (container), + GTK_WIDGET (child), new_position); + continue; + } + + /* Get the old value from glade */ + glade_widget_pack_property_get + (gchild_iter, "position", &iter_position); + + /* Search for the child at the old position and update it */ + if (iter_position == new_position && + glade_property_superuser () == FALSE) + { + /* Update glade with the real value */ + recursion = TRUE; + glade_widget_pack_property_set + (gchild_iter, "position", old_position); + recursion = FALSE; + continue; + } + else + { + gtk_box_reorder_child (GTK_BOX (container), + GTK_WIDGET (list->data), iter_position); + } + } + + for (list = children; list; list = list->next) + { + if ((gchild_iter = + glade_widget_get_from_gobject (list->data)) == NULL) + continue; + + /* Refresh values yet again */ + glade_widget_pack_property_get + (gchild_iter, "position", &iter_position); + + gtk_box_reorder_child (GTK_BOX (container), + GTK_WIDGET (list->data), iter_position); + + } + + if (children) + g_list_free (children); + } + + /* Chain Up */ + if (!is_position) + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, + child, property_name, value); + + gtk_container_check_resize (GTK_CONTAINER (container)); + +} + +void +glade_gtk_box_get_property (GladeWidgetAdaptor * adaptor, + GObject * object, const gchar * id, GValue * value) +{ + if (!strcmp (id, "size")) + { + GtkBox *box = GTK_BOX (object); + GList *children = gtk_container_get_children (GTK_CONTAINER (box)); + + g_value_reset (value); + g_value_set_int (value, g_list_length (children)); + g_list_free (children); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->get_property (adaptor, object, id, + value); } static gint -glade_gtk_box_get_first_blank (GtkBox *box) +glade_gtk_box_get_first_blank (GtkBox * box) { - GList *child, *children; - GladeWidget *gwidget; - gint position; + GList *child, *children; + GladeWidget *gwidget; + gint position; - children = gtk_container_get_children (GTK_CONTAINER (box)); + children = gtk_container_get_children (GTK_CONTAINER (box)); - for (child = children, position = 0; - child && child->data; - child = child->next, position++) - { - GtkWidget *widget = child->data; + for (child = children, position = 0; + child && child->data; child = child->next, position++) + { + GtkWidget *widget = child->data; - if ((gwidget = glade_widget_get_from_gobject (widget)) != NULL) - { - gint gwidget_position; - GladeProperty *property = - glade_widget_get_pack_property (gwidget, "position"); - gwidget_position = g_value_get_int (property->value); + if ((gwidget = glade_widget_get_from_gobject (widget)) != NULL) + { + gint gwidget_position; + GladeProperty *property = + glade_widget_get_pack_property (gwidget, "position"); + gwidget_position = g_value_get_int (property->value); - if (gwidget_position > position) - break; - } - } + if (gwidget_position > position) + break; + } + } - g_list_free (children); + g_list_free (children); - return position; + return position; } static void -glade_gtk_box_set_size (GObject *object, const GValue *value) -{ - GtkBox *box; - GList *child, *children; - guint new_size, old_size, i; - - box = GTK_BOX (object); - g_return_if_fail (GTK_IS_BOX (box)); - - if (glade_util_object_is_loading (object)) - return; - - children = gtk_container_get_children (GTK_CONTAINER (box)); - - old_size = g_list_length (children); - new_size = g_value_get_int (value); - - if (old_size == new_size) - { - g_list_free (children); - return; - } - - /* Ensure placeholders first... - */ - for (i = 0; i < new_size; i++) - { - if (g_list_length(children) < (i + 1)) - { - GtkWidget *placeholder = glade_placeholder_new (); - gint blank = glade_gtk_box_get_first_blank (box); - - gtk_container_add (GTK_CONTAINER (box), placeholder); - gtk_box_reorder_child (box, placeholder, blank); - } - } - - /* The box has shrunk. Remove the widgets that are on those slots */ - for (child = g_list_last (children); - child && old_size > new_size; - child = g_list_last (children), old_size--) - { - GtkWidget *child_widget = child->data; - - /* Refuse to remove any widgets that are either GladeWidget objects - * or internal to the hierarchic entity (may be a composite widget, - * not all internal widgets have GladeWidgets). - */ - if (glade_widget_get_from_gobject (child_widget) || - GLADE_IS_PLACEHOLDER (child_widget) == FALSE) - break; - - g_object_ref (G_OBJECT (child_widget)); - gtk_container_remove (GTK_CONTAINER (box), child_widget); - gtk_widget_destroy (child_widget); - } - g_list_free (children); - -} - -void -glade_gtk_box_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - if (!strcmp (id, "size")) - glade_gtk_box_set_size (object, value); - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value); +glade_gtk_box_set_size (GObject * object, const GValue * value) +{ + GtkBox *box; + GList *child, *children; + guint new_size, old_size, i; + + box = GTK_BOX (object); + g_return_if_fail (GTK_IS_BOX (box)); + + if (glade_util_object_is_loading (object)) + return; + + children = gtk_container_get_children (GTK_CONTAINER (box)); + + old_size = g_list_length (children); + new_size = g_value_get_int (value); + + if (old_size == new_size) + { + g_list_free (children); + return; + } + + /* Ensure placeholders first... + */ + for (i = 0; i < new_size; i++) + { + if (g_list_length (children) < (i + 1)) + { + GtkWidget *placeholder = glade_placeholder_new (); + gint blank = glade_gtk_box_get_first_blank (box); + + gtk_container_add (GTK_CONTAINER (box), placeholder); + gtk_box_reorder_child (box, placeholder, blank); + } + } + + /* The box has shrunk. Remove the widgets that are on those slots */ + for (child = g_list_last (children); + child && old_size > new_size; child = g_list_last (children), old_size--) + { + GtkWidget *child_widget = child->data; + + /* Refuse to remove any widgets that are either GladeWidget objects + * or internal to the hierarchic entity (may be a composite widget, + * not all internal widgets have GladeWidgets). + */ + if (glade_widget_get_from_gobject (child_widget) || + GLADE_IS_PLACEHOLDER (child_widget) == FALSE) + break; + + g_object_ref (G_OBJECT (child_widget)); + gtk_container_remove (GTK_CONTAINER (box), child_widget); + gtk_widget_destroy (child_widget); + } + g_list_free (children); + } -static gboolean -glade_gtk_box_verify_size (GObject *object, const GValue *value) +void +glade_gtk_box_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - GtkBox *box = GTK_BOX(object); - GList *child, *children; - gboolean will_orphan = FALSE; - gint old_size; - gint new_size = g_value_get_int (value); + if (!strcmp (id, "size")) + glade_gtk_box_set_size (object, value); + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, + value); +} - children = gtk_container_get_children (GTK_CONTAINER (box)); - old_size = g_list_length (children); +static gboolean +glade_gtk_box_verify_size (GObject * object, const GValue * value) +{ + GtkBox *box = GTK_BOX (object); + GList *child, *children; + gboolean will_orphan = FALSE; + gint old_size; + gint new_size = g_value_get_int (value); + + children = gtk_container_get_children (GTK_CONTAINER (box)); + old_size = g_list_length (children); + + for (child = g_list_last (children); + child && old_size > new_size; + child = g_list_previous (child), old_size--) + { + GtkWidget *widget = child->data; + if (glade_widget_get_from_gobject (widget) != NULL) + { + /* In this case, refuse to shrink */ + will_orphan = TRUE; + break; + } + } - for (child = g_list_last (children); - child && old_size > new_size; - child = g_list_previous (child), old_size--) - { - GtkWidget *widget = child->data; - if (glade_widget_get_from_gobject (widget) != NULL) - { - /* In this case, refuse to shrink */ - will_orphan = TRUE; - break; - } - } - - g_list_free (children); + g_list_free (children); - return will_orphan ? FALSE : new_size >= 0; + return will_orphan ? FALSE : new_size >= 0; } gboolean -glade_gtk_box_verify_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_box_verify_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "size")) - return glade_gtk_box_verify_size (object, value); - else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) - return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, - id, value); + if (!strcmp (id, "size")) + return glade_gtk_box_verify_size (object, value); + else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) + return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, + id, value); - return TRUE; + return TRUE; } static void -fix_response_id_on_child (GladeWidget *gbox, - GObject *child, - gboolean add) -{ - GladeWidget *gchild; - const gchar *internal_name; - - gchild = glade_widget_get_from_gobject (child); - - /* Fix response id property on child buttons */ - if (gchild && GTK_IS_BUTTON (child)) - { - if (add && (internal_name = glade_widget_get_internal (gbox)) && - !strcmp (internal_name, "action_area")) - { - glade_widget_property_set_sensitive (gchild, "response-id", TRUE, NULL); - glade_widget_property_set_enabled (gchild, "response-id", TRUE); - } - else - { - glade_widget_property_set_sensitive (gchild, "response-id", FALSE, - RESPID_INSENSITIVE_MSG); - glade_widget_property_set_enabled (gchild, "response-id", FALSE); - - } - } -} - - -void -glade_gtk_box_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - GladeWidget *gbox, *gchild; - GladeProject *project; - GList *children; - gint num_children; - - g_return_if_fail (GTK_IS_BOX (object)); - g_return_if_fail (GTK_IS_WIDGET (child)); - - gbox = glade_widget_get_from_gobject (object); - project = glade_widget_get_project (gbox); - - /* - Try to remove the last placeholder if any, this way GtkBox`s size - will not be changed. - */ - if (glade_widget_superuser () == FALSE && - !GLADE_IS_PLACEHOLDER (child)) - { - GList *l, *children; - GtkBox *box = GTK_BOX (object); - - children = gtk_container_get_children (GTK_CONTAINER (box)); - - for (l = g_list_last (children); l; l = g_list_previous (l)) - { - GtkWidget *child_widget = l->data; - if (GLADE_IS_PLACEHOLDER (child_widget)) - { - gtk_container_remove (GTK_CONTAINER (box), child_widget); - break; - } - } - g_list_free (children); - } - - gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); - - children = gtk_container_get_children (GTK_CONTAINER (object)); - num_children = g_list_length (children); - g_list_free (children); - - glade_widget_property_set (gbox, "size", num_children); - - gchild = glade_widget_get_from_gobject (child); - - /* The "Remove Slot" operation only makes sence on placeholders, - * otherwise its a "Delete" operation on the child widget. - */ - if (gchild) - glade_widget_remove_pack_action (gchild, "remove_slot"); - - /* Packing props arent around when parenting during a glade_widget_dup() */ - if (gchild && gchild->packing_properties) - glade_widget_pack_property_set (gchild, "position", num_children - 1); - - - fix_response_id_on_child (gbox, child, TRUE); -} - -void -glade_gtk_box_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - GladeWidget *gbox; - gint size; - - g_return_if_fail (GTK_IS_BOX (object)); - g_return_if_fail (GTK_IS_WIDGET (child)); - - gbox = glade_widget_get_from_gobject (object); - - gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); - - if (glade_widget_superuser () == FALSE) - { - glade_widget_property_get (gbox, "size", &size); - glade_widget_property_set (gbox, "size", size); - } +fix_response_id_on_child (GladeWidget * gbox, GObject * child, gboolean add) +{ + GladeWidget *gchild; + const gchar *internal_name; + + gchild = glade_widget_get_from_gobject (child); + + /* Fix response id property on child buttons */ + if (gchild && GTK_IS_BUTTON (child)) + { + if (add && (internal_name = glade_widget_get_internal (gbox)) && + !strcmp (internal_name, "action_area")) + { + glade_widget_property_set_sensitive (gchild, "response-id", TRUE, + NULL); + glade_widget_property_set_enabled (gchild, "response-id", TRUE); + } + else + { + glade_widget_property_set_sensitive (gchild, "response-id", FALSE, + RESPID_INSENSITIVE_MSG); + glade_widget_property_set_enabled (gchild, "response-id", FALSE); + + } + } +} + + +void +glade_gtk_box_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + GladeWidget *gbox, *gchild; + GladeProject *project; + GList *children; + gint num_children; + + g_return_if_fail (GTK_IS_BOX (object)); + g_return_if_fail (GTK_IS_WIDGET (child)); + + gbox = glade_widget_get_from_gobject (object); + project = glade_widget_get_project (gbox); + + /* + Try to remove the last placeholder if any, this way GtkBox`s size + will not be changed. + */ + if (glade_widget_superuser () == FALSE && !GLADE_IS_PLACEHOLDER (child)) + { + GList *l, *children; + GtkBox *box = GTK_BOX (object); + + children = gtk_container_get_children (GTK_CONTAINER (box)); + + for (l = g_list_last (children); l; l = g_list_previous (l)) + { + GtkWidget *child_widget = l->data; + if (GLADE_IS_PLACEHOLDER (child_widget)) + { + gtk_container_remove (GTK_CONTAINER (box), child_widget); + break; + } + } + g_list_free (children); + } + + gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); + + children = gtk_container_get_children (GTK_CONTAINER (object)); + num_children = g_list_length (children); + g_list_free (children); + + glade_widget_property_set (gbox, "size", num_children); + + gchild = glade_widget_get_from_gobject (child); + + /* The "Remove Slot" operation only makes sence on placeholders, + * otherwise its a "Delete" operation on the child widget. + */ + if (gchild) + glade_widget_remove_pack_action (gchild, "remove_slot"); + + /* Packing props arent around when parenting during a glade_widget_dup() */ + if (gchild && gchild->packing_properties) + glade_widget_pack_property_set (gchild, "position", num_children - 1); + + + fix_response_id_on_child (gbox, child, TRUE); +} - fix_response_id_on_child (gbox, child, FALSE); +void +glade_gtk_box_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + GladeWidget *gbox; + gint size; + + g_return_if_fail (GTK_IS_BOX (object)); + g_return_if_fail (GTK_IS_WIDGET (child)); + + gbox = glade_widget_get_from_gobject (object); + + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); + + if (glade_widget_superuser () == FALSE) + { + glade_widget_property_get (gbox, "size", &size); + glade_widget_property_set (gbox, "size", size); + } + + fix_response_id_on_child (gbox, child, FALSE); } void -glade_gtk_box_replace_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *current, - GObject *new_widget) +glade_gtk_box_replace_child (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * current, GObject * new_widget) { - GladeWidget *gchild; - GladeWidget *gbox; + GladeWidget *gchild; + GladeWidget *gbox; - g_object_ref (G_OBJECT (current)); + g_object_ref (G_OBJECT (current)); - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->replace_child (adaptor, - container, - current, - new_widget); + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->replace_child (adaptor, + container, + current, new_widget); - if ((gchild = glade_widget_get_from_gobject (new_widget)) != NULL) - /* The "Remove Slot" operation only makes sence on placeholders, - * otherwise its a "Delete" operation on the child widget. - */ - glade_widget_remove_pack_action (gchild, "remove_slot"); + if ((gchild = glade_widget_get_from_gobject (new_widget)) != NULL) + /* The "Remove Slot" operation only makes sence on placeholders, + * otherwise its a "Delete" operation on the child widget. + */ + glade_widget_remove_pack_action (gchild, "remove_slot"); - gbox = glade_widget_get_from_gobject (container); - fix_response_id_on_child (gbox, current, FALSE); - fix_response_id_on_child (gbox, new_widget, TRUE); + gbox = glade_widget_get_from_gobject (container); + fix_response_id_on_child (gbox, current, FALSE); + fix_response_id_on_child (gbox, new_widget, TRUE); - g_object_unref (G_OBJECT (current)); + g_object_unref (G_OBJECT (current)); } GObject * -glade_gtk_box_get_internal_child (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *name) -{ - GList *children, *l; - GObject *child = NULL; - - g_return_val_if_fail (GTK_IS_BOX (object), NULL); - - children = l = gtk_container_get_children (GTK_CONTAINER (object)); - - while (l) - { - GladeWidget *gw = glade_widget_get_from_gobject (l->data); - - if (gw && gw->internal && strcmp (gw->internal, name) == 0) - { - child = G_OBJECT (l->data); - break; - } - - l= l->next; - } - g_list_free (children); - - return child; +glade_gtk_box_get_internal_child (GladeWidgetAdaptor * adaptor, + GObject * object, const gchar * name) +{ + GList *children, *l; + GObject *child = NULL; + + g_return_val_if_fail (GTK_IS_BOX (object), NULL); + + children = l = gtk_container_get_children (GTK_CONTAINER (object)); + + while (l) + { + GladeWidget *gw = glade_widget_get_from_gobject (l->data); + + if (gw && gw->internal && strcmp (gw->internal, name) == 0) + { + child = G_OBJECT (l->data); + break; + } + + l = l->next; + } + g_list_free (children); + + return child; } static void -glade_gtk_box_notebook_child_insert_remove_action (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *size_prop, - const gchar *group_format, - gboolean remove, - gboolean after); - -void -glade_gtk_box_child_action_activate (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *action_path) -{ - if (strcmp (action_path, "insert_after") == 0) - { - glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, - object, "size", - _("Insert placeholder to %s"), - FALSE, TRUE); - } - else if (strcmp (action_path, "insert_before") == 0) - { - glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, - object, "size", - _("Insert placeholder to %s"), - FALSE, FALSE); - } - else if (strcmp (action_path, "remove_slot") == 0) - { - glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, - object, "size", - _("Remove placeholder from %s"), - TRUE, FALSE); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor, - container, - object, - action_path); +glade_gtk_box_notebook_child_insert_remove_action (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * object, + const gchar * size_prop, + const gchar * group_format, + gboolean remove, + gboolean after); + +void +glade_gtk_box_child_action_activate (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * object, + const gchar * action_path) +{ + if (strcmp (action_path, "insert_after") == 0) + { + glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, + object, "size", + _ + ("Insert placeholder to %s"), + FALSE, TRUE); + } + else if (strcmp (action_path, "insert_before") == 0) + { + glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, + object, "size", + _ + ("Insert placeholder to %s"), + FALSE, FALSE); + } + else if (strcmp (action_path, "remove_slot") == 0) + { + glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, + object, "size", + _ + ("Remove placeholder from %s"), + TRUE, FALSE); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor, + container, + object, + action_path); } /* ----------------------------- GtkTable ------------------------------ */ -typedef struct { - /* comparable part: */ - GladeWidget *widget; - gint left_attach; - gint right_attach; - gint top_attach; - gint bottom_attach; +typedef struct +{ + /* comparable part: */ + GladeWidget *widget; + gint left_attach; + gint right_attach; + gint top_attach; + gint bottom_attach; } GladeGtkTableChild; -typedef enum { - DIR_UP, - DIR_DOWN, - DIR_LEFT, - DIR_RIGHT +typedef enum +{ + DIR_UP, + DIR_DOWN, + DIR_LEFT, + DIR_RIGHT } GladeTableDir; #define TABLE_CHILD_CMP_SIZE (sizeof (GladeWidget *) + (sizeof (gint) * 4)) @@ -1998,24 +1942,23 @@ static GladeGtkTableChild table_edit = { 0, }; static GladeGtkTableChild table_cur_attach = { 0, }; static void -glade_gtk_table_get_child_attachments (GtkWidget *table, - GtkWidget *child, - GtkTableChild *tchild) +glade_gtk_table_get_child_attachments (GtkWidget * table, + GtkWidget * child, + GtkTableChild * tchild) { - guint left, right, top, bottom; + guint left, right, top, bottom; - gtk_container_child_get (GTK_CONTAINER (table), child, - "left-attach", (guint *)&left, - "right-attach", (guint *)&right, - "bottom-attach", (guint *)&bottom, - "top-attach", (guint *)&top, - NULL); + gtk_container_child_get (GTK_CONTAINER (table), child, + "left-attach", (guint *) & left, + "right-attach", (guint *) & right, + "bottom-attach", (guint *) & bottom, + "top-attach", (guint *) & top, NULL); - tchild->widget = child; - tchild->left_attach = left; - tchild->right_attach = right; - tchild->top_attach = top; - tchild->bottom_attach = bottom; + tchild->widget = child; + tchild->left_attach = left; + tchild->right_attach = right; + tchild->top_attach = top; + tchild->bottom_attach = bottom; } @@ -2024,1526 +1967,1457 @@ glade_gtk_table_get_child_attachments (GtkWidget *table, * was found. */ static gint -glade_gtk_table_get_row_col_from_point (GtkTable *table, - gboolean row, - gint point) -{ - GtkTableChild tchild; - GtkAllocation allocation; - GList *list, *children; - gint span, trans_point, size, base, end; - - children = gtk_container_get_children (GTK_CONTAINER (table)); - - for (list = children; - list; - list = list->next) - { - glade_gtk_table_get_child_attachments (GTK_WIDGET (table), - GTK_WIDGET (list->data), &tchild); - - if (row) - gtk_widget_translate_coordinates - (GTK_WIDGET (table), tchild.widget, - 0, point, NULL, &trans_point); - else - gtk_widget_translate_coordinates - (GTK_WIDGET (table), tchild.widget, - point, 0, &trans_point, NULL); - - gtk_widget_get_allocation (tchild.widget, &allocation); - /* Find any widget in our row/column - */ - end = row ? allocation.height : allocation.width; - - if (trans_point >= 0 && - /* should be trans_point < end ... test FIXME ! */ - trans_point < end) - { - base = row ? tchild.top_attach : tchild.left_attach; - size = row ? allocation.height : allocation.width; - span = row ? (tchild.bottom_attach - tchild.top_attach) : - (tchild.right_attach - tchild.left_attach); - - return base + (trans_point * span / size); - } - } - g_list_free (children); - - return -1; +glade_gtk_table_get_row_col_from_point (GtkTable * table, + gboolean row, gint point) +{ + GtkTableChild tchild; + GtkAllocation allocation; + GList *list, *children; + gint span, trans_point, size, base, end; + + children = gtk_container_get_children (GTK_CONTAINER (table)); + + for (list = children; list; list = list->next) + { + glade_gtk_table_get_child_attachments (GTK_WIDGET (table), + GTK_WIDGET (list->data), &tchild); + + if (row) + gtk_widget_translate_coordinates + (GTK_WIDGET (table), tchild.widget, 0, point, NULL, &trans_point); + else + gtk_widget_translate_coordinates + (GTK_WIDGET (table), tchild.widget, point, 0, &trans_point, NULL); + + gtk_widget_get_allocation (tchild.widget, &allocation); + /* Find any widget in our row/column + */ + end = row ? allocation.height : allocation.width; + + if (trans_point >= 0 && + /* should be trans_point < end ... test FIXME ! */ + trans_point < end) + { + base = row ? tchild.top_attach : tchild.left_attach; + size = row ? allocation.height : allocation.width; + span = row ? (tchild.bottom_attach - tchild.top_attach) : + (tchild.right_attach - tchild.left_attach); + + return base + (trans_point * span / size); + } + } + g_list_free (children); + + return -1; } static gboolean -glade_gtk_table_point_crosses_threshold (GtkTable *table, - gboolean row, - gint num, - GladeTableDir dir, - gint point) -{ - - GtkTableChild tchild; - GtkAllocation allocation; - GList *list, *children; - gint span, trans_point, size, rowcol_size, base; - - children = gtk_container_get_children (GTK_CONTAINER (table)); - - for (list = children; list; list = list->next) - { - glade_gtk_table_get_child_attachments (GTK_WIDGET (table), - GTK_WIDGET (list->data), &tchild); - - /* Find any widget in our row/column - */ - if ((row && num >= tchild.top_attach && num < tchild.bottom_attach) || - (!row && num >= tchild.left_attach && num < tchild.right_attach)) - { - - if (row) - gtk_widget_translate_coordinates - (GTK_WIDGET (table), tchild.widget, - 0, point, NULL, &trans_point); - else - gtk_widget_translate_coordinates - (GTK_WIDGET (table), tchild.widget, - point, 0, &trans_point, NULL); - - span = row ? (tchild.bottom_attach - tchild.top_attach) : - (tchild.right_attach - tchild.left_attach); - gtk_widget_get_allocation (tchild.widget, &allocation); - size = row ? allocation.height : allocation.width; - - base = row ? tchild.top_attach : tchild.left_attach; - rowcol_size = size / span; - trans_point -= (num - base) * rowcol_size; +glade_gtk_table_point_crosses_threshold (GtkTable * table, + gboolean row, + gint num, + GladeTableDir dir, gint point) +{ + + GtkTableChild tchild; + GtkAllocation allocation; + GList *list, *children; + gint span, trans_point, size, rowcol_size, base; + + children = gtk_container_get_children (GTK_CONTAINER (table)); + + for (list = children; list; list = list->next) + { + glade_gtk_table_get_child_attachments (GTK_WIDGET (table), + GTK_WIDGET (list->data), &tchild); + + /* Find any widget in our row/column + */ + if ((row && num >= tchild.top_attach && num < tchild.bottom_attach) || + (!row && num >= tchild.left_attach && num < tchild.right_attach)) + { + + if (row) + gtk_widget_translate_coordinates + (GTK_WIDGET (table), tchild.widget, + 0, point, NULL, &trans_point); + else + gtk_widget_translate_coordinates + (GTK_WIDGET (table), tchild.widget, + point, 0, &trans_point, NULL); + + span = row ? (tchild.bottom_attach - tchild.top_attach) : + (tchild.right_attach - tchild.left_attach); + gtk_widget_get_allocation (tchild.widget, &allocation); + size = row ? allocation.height : allocation.width; + + base = row ? tchild.top_attach : tchild.left_attach; + rowcol_size = size / span; + trans_point -= (num - base) * rowcol_size; #if 0 - g_print ("dir: %s, widget size: %d, rowcol size: %d, " - "requested rowcol: %d, widget base rowcol: %d, trim: %d, " - "widget point: %d, thresh: %d\n", - dir == DIR_UP ? "up" : dir == DIR_DOWN ? "down" : - dir == DIR_LEFT ? "left" : "right", - size, rowcol_size, num, base, (num - base) * rowcol_size, - trans_point, - dir == DIR_UP || dir == DIR_LEFT ? - (rowcol_size / 2) : - (rowcol_size / 2)); + g_print ("dir: %s, widget size: %d, rowcol size: %d, " + "requested rowcol: %d, widget base rowcol: %d, trim: %d, " + "widget point: %d, thresh: %d\n", + dir == DIR_UP ? "up" : dir == DIR_DOWN ? "down" : + dir == DIR_LEFT ? "left" : "right", + size, rowcol_size, num, base, (num - base) * rowcol_size, + trans_point, + dir == DIR_UP || dir == DIR_LEFT ? + (rowcol_size / 2) : (rowcol_size / 2)); #endif - switch (dir) - { - case DIR_UP: - case DIR_LEFT: - return trans_point <= (rowcol_size / 2); - case DIR_DOWN: - case DIR_RIGHT: - return trans_point >= (rowcol_size / 2); - default: - break; - } - } - - } - - g_list_free (children); - - return FALSE; + switch (dir) + { + case DIR_UP: + case DIR_LEFT: + return trans_point <= (rowcol_size / 2); + case DIR_DOWN: + case DIR_RIGHT: + return trans_point >= (rowcol_size / 2); + default: + break; + } + } + + } + + g_list_free (children); + + return FALSE; } static gboolean -glade_gtk_table_get_attachments (GladeFixed *fixed, - GtkTable *table, - GdkRectangle *rect, - GladeGtkTableChild *configure) -{ - gint center_x, center_y, row, column; - guint n_columns, n_rows; - center_x = rect->x + (rect->width / 2); - center_y = rect->y + (rect->height / 2); - - column = glade_gtk_table_get_row_col_from_point - (table, FALSE, center_x); - - row = glade_gtk_table_get_row_col_from_point - (table, TRUE, center_y); - - /* its a start, now try to grow when the rect extents - * reach at least half way into the next row/column - */ - configure->left_attach = column; - configure->right_attach = column + 1; - configure->top_attach = row; - configure->bottom_attach = row +1; - - if (column >= 0 && row >= 0) - { - - g_object_get (table, - "n-columns", &n_columns, - "n-rows", &n_rows, - NULL); - - /* Check and expand left - */ - while (configure->left_attach > 0) - { - if (rect->x < fixed->child_x_origin && - fixed->operation != GLADE_CURSOR_DRAG && - GLADE_FIXED_CURSOR_LEFT (fixed->operation) == FALSE) - break; - - if (glade_gtk_table_point_crosses_threshold - (table, FALSE, configure->left_attach -1, - DIR_LEFT, rect->x) == FALSE) - break; - - configure->left_attach--; - } - - /* Check and expand right - */ - while (configure->right_attach < n_columns) - { - if (rect->x + rect->width > - fixed->child_x_origin + fixed->child_width_origin && - fixed->operation != GLADE_CURSOR_DRAG && - GLADE_FIXED_CURSOR_RIGHT (fixed->operation) == FALSE) - break; - - if (glade_gtk_table_point_crosses_threshold - (table, FALSE, configure->right_attach, - DIR_RIGHT, rect->x + rect->width) == FALSE) - break; - - configure->right_attach++; - } - - /* Check and expand top - */ - while (configure->top_attach > 0) - { - if (rect->y < fixed->child_y_origin && - fixed->operation != GLADE_CURSOR_DRAG && - GLADE_FIXED_CURSOR_TOP (fixed->operation) == FALSE) - break; - - if (glade_gtk_table_point_crosses_threshold - (table, TRUE, configure->top_attach -1, - DIR_UP, rect->y) == FALSE) - break; - - configure->top_attach--; - } - - /* Check and expand bottom - */ - while (configure->bottom_attach < n_rows) - { - if (rect->y + rect->height > - fixed->child_y_origin + fixed->child_height_origin && - fixed->operation != GLADE_CURSOR_DRAG && - GLADE_FIXED_CURSOR_BOTTOM (fixed->operation) == FALSE) - break; - - if (glade_gtk_table_point_crosses_threshold - (table, TRUE, configure->bottom_attach, - DIR_DOWN, rect->y + rect->height) == FALSE) - break; - - configure->bottom_attach++; - } - } - - /* Keep the same row/col span when performing a drag - */ - if (fixed->operation == GLADE_CURSOR_DRAG) - { - gint col_span = table_edit.right_attach - table_edit.left_attach; - gint row_span = table_edit.bottom_attach - table_edit.top_attach; - - if (rect->x < fixed->child_x_origin) - configure->right_attach = configure->left_attach + col_span; - else - configure->left_attach = configure->right_attach - col_span; - - if (rect->y < fixed->child_y_origin) - configure->bottom_attach = configure->top_attach + row_span; - else - configure->top_attach = configure->bottom_attach - row_span; - } else if (fixed->operation == GLADE_CURSOR_RESIZE_RIGHT) { - configure->left_attach = table_edit.left_attach; - configure->top_attach = table_edit.top_attach; - configure->bottom_attach = table_edit.bottom_attach; - } else if (fixed->operation == GLADE_CURSOR_RESIZE_LEFT) { - configure->right_attach = table_edit.right_attach; - configure->top_attach = table_edit.top_attach; - configure->bottom_attach = table_edit.bottom_attach; - } else if (fixed->operation == GLADE_CURSOR_RESIZE_TOP) { - configure->left_attach = table_edit.left_attach; - configure->right_attach = table_edit.right_attach; - configure->bottom_attach = table_edit.bottom_attach; - } else if (fixed->operation == GLADE_CURSOR_RESIZE_BOTTOM) { - configure->left_attach = table_edit.left_attach; - configure->right_attach = table_edit.right_attach; - configure->top_attach = table_edit.top_attach; - } - - return column >= 0 && row >= 0; +glade_gtk_table_get_attachments (GladeFixed * fixed, + GtkTable * table, + GdkRectangle * rect, + GladeGtkTableChild * configure) +{ + gint center_x, center_y, row, column; + guint n_columns, n_rows; + center_x = rect->x + (rect->width / 2); + center_y = rect->y + (rect->height / 2); + + column = glade_gtk_table_get_row_col_from_point (table, FALSE, center_x); + + row = glade_gtk_table_get_row_col_from_point (table, TRUE, center_y); + + /* its a start, now try to grow when the rect extents + * reach at least half way into the next row/column + */ + configure->left_attach = column; + configure->right_attach = column + 1; + configure->top_attach = row; + configure->bottom_attach = row + 1; + + if (column >= 0 && row >= 0) + { + + g_object_get (table, "n-columns", &n_columns, "n-rows", &n_rows, NULL); + + /* Check and expand left + */ + while (configure->left_attach > 0) + { + if (rect->x < fixed->child_x_origin && + fixed->operation != GLADE_CURSOR_DRAG && + GLADE_FIXED_CURSOR_LEFT (fixed->operation) == FALSE) + break; + + if (glade_gtk_table_point_crosses_threshold + (table, FALSE, configure->left_attach - 1, + DIR_LEFT, rect->x) == FALSE) + break; + + configure->left_attach--; + } + + /* Check and expand right + */ + while (configure->right_attach < n_columns) + { + if (rect->x + rect->width > + fixed->child_x_origin + fixed->child_width_origin && + fixed->operation != GLADE_CURSOR_DRAG && + GLADE_FIXED_CURSOR_RIGHT (fixed->operation) == FALSE) + break; + + if (glade_gtk_table_point_crosses_threshold + (table, FALSE, configure->right_attach, + DIR_RIGHT, rect->x + rect->width) == FALSE) + break; + + configure->right_attach++; + } + + /* Check and expand top + */ + while (configure->top_attach > 0) + { + if (rect->y < fixed->child_y_origin && + fixed->operation != GLADE_CURSOR_DRAG && + GLADE_FIXED_CURSOR_TOP (fixed->operation) == FALSE) + break; + + if (glade_gtk_table_point_crosses_threshold + (table, TRUE, configure->top_attach - 1, + DIR_UP, rect->y) == FALSE) + break; + + configure->top_attach--; + } + + /* Check and expand bottom + */ + while (configure->bottom_attach < n_rows) + { + if (rect->y + rect->height > + fixed->child_y_origin + fixed->child_height_origin && + fixed->operation != GLADE_CURSOR_DRAG && + GLADE_FIXED_CURSOR_BOTTOM (fixed->operation) == FALSE) + break; + + if (glade_gtk_table_point_crosses_threshold + (table, TRUE, configure->bottom_attach, + DIR_DOWN, rect->y + rect->height) == FALSE) + break; + + configure->bottom_attach++; + } + } + + /* Keep the same row/col span when performing a drag + */ + if (fixed->operation == GLADE_CURSOR_DRAG) + { + gint col_span = table_edit.right_attach - table_edit.left_attach; + gint row_span = table_edit.bottom_attach - table_edit.top_attach; + + if (rect->x < fixed->child_x_origin) + configure->right_attach = configure->left_attach + col_span; + else + configure->left_attach = configure->right_attach - col_span; + + if (rect->y < fixed->child_y_origin) + configure->bottom_attach = configure->top_attach + row_span; + else + configure->top_attach = configure->bottom_attach - row_span; + } + else if (fixed->operation == GLADE_CURSOR_RESIZE_RIGHT) + { + configure->left_attach = table_edit.left_attach; + configure->top_attach = table_edit.top_attach; + configure->bottom_attach = table_edit.bottom_attach; + } + else if (fixed->operation == GLADE_CURSOR_RESIZE_LEFT) + { + configure->right_attach = table_edit.right_attach; + configure->top_attach = table_edit.top_attach; + configure->bottom_attach = table_edit.bottom_attach; + } + else if (fixed->operation == GLADE_CURSOR_RESIZE_TOP) + { + configure->left_attach = table_edit.left_attach; + configure->right_attach = table_edit.right_attach; + configure->bottom_attach = table_edit.bottom_attach; + } + else if (fixed->operation == GLADE_CURSOR_RESIZE_BOTTOM) + { + configure->left_attach = table_edit.left_attach; + configure->right_attach = table_edit.right_attach; + configure->top_attach = table_edit.top_attach; + } + + return column >= 0 && row >= 0; } static gboolean -glade_gtk_table_configure_child (GladeFixed *fixed, - GladeWidget *child, - GdkRectangle *rect, - GtkWidget *table) -{ - GladeGtkTableChild configure = { child, }; - - /* Sometimes we are unable to find a widget in the appropriate column, - * usually because a placeholder hasnt had its size allocation yet. - */ - if (glade_gtk_table_get_attachments (fixed, GTK_TABLE (table), rect, &configure)) - { - if (memcmp (&configure, &table_cur_attach, TABLE_CHILD_CMP_SIZE) != 0) - { - - glade_property_push_superuser (); - glade_widget_pack_property_set (child, "left-attach", - configure.left_attach); - glade_widget_pack_property_set (child, "right-attach", - configure.right_attach); - glade_widget_pack_property_set (child, "top-attach", - configure.top_attach); - glade_widget_pack_property_set (child, "bottom-attach", - configure.bottom_attach); - glade_property_pop_superuser (); - - memcpy (&table_cur_attach, &configure, TABLE_CHILD_CMP_SIZE); - } - } - return TRUE; +glade_gtk_table_configure_child (GladeFixed * fixed, + GladeWidget * child, + GdkRectangle * rect, GtkWidget * table) +{ + GladeGtkTableChild configure = { child, }; + + /* Sometimes we are unable to find a widget in the appropriate column, + * usually because a placeholder hasnt had its size allocation yet. + */ + if (glade_gtk_table_get_attachments + (fixed, GTK_TABLE (table), rect, &configure)) + { + if (memcmp (&configure, &table_cur_attach, TABLE_CHILD_CMP_SIZE) != 0) + { + + glade_property_push_superuser (); + glade_widget_pack_property_set (child, "left-attach", + configure.left_attach); + glade_widget_pack_property_set (child, "right-attach", + configure.right_attach); + glade_widget_pack_property_set (child, "top-attach", + configure.top_attach); + glade_widget_pack_property_set (child, "bottom-attach", + configure.bottom_attach); + glade_property_pop_superuser (); + + memcpy (&table_cur_attach, &configure, TABLE_CHILD_CMP_SIZE); + } + } + return TRUE; } static gboolean -glade_gtk_table_configure_begin (GladeFixed *fixed, - GladeWidget *child, - GtkWidget *table) +glade_gtk_table_configure_begin (GladeFixed * fixed, + GladeWidget * child, GtkWidget * table) { - table_edit.widget = child; + table_edit.widget = child; - glade_widget_pack_property_get (child, "left-attach", - &table_edit.left_attach); - glade_widget_pack_property_get (child, "right-attach", - &table_edit.right_attach); - glade_widget_pack_property_get (child, "top-attach", - &table_edit.top_attach); - glade_widget_pack_property_get (child, "bottom-attach", - &table_edit.bottom_attach); + glade_widget_pack_property_get (child, "left-attach", + &table_edit.left_attach); + glade_widget_pack_property_get (child, "right-attach", + &table_edit.right_attach); + glade_widget_pack_property_get (child, "top-attach", &table_edit.top_attach); + glade_widget_pack_property_get (child, "bottom-attach", + &table_edit.bottom_attach); - memcpy (&table_cur_attach, &table_edit, TABLE_CHILD_CMP_SIZE); + memcpy (&table_cur_attach, &table_edit, TABLE_CHILD_CMP_SIZE); - return TRUE; + return TRUE; } static gboolean -glade_gtk_table_configure_end (GladeFixed *fixed, - GladeWidget *child, - GtkWidget *table) -{ - GladeGtkTableChild new_child = { child, }; - - glade_widget_pack_property_get (child, "left-attach", - &new_child.left_attach); - glade_widget_pack_property_get (child, "right-attach", - &new_child.right_attach); - glade_widget_pack_property_get (child, "top-attach", - &new_child.top_attach); - glade_widget_pack_property_get (child, "bottom-attach", - &new_child.bottom_attach); - - /* Compare the meaningfull part of the current edit. */ - if (memcmp (&new_child, &table_edit, TABLE_CHILD_CMP_SIZE) != 0) - { - GValue left_attach_value = { 0, }; - GValue right_attach_value = { 0, }; - GValue top_attach_value = { 0, }; - GValue bottom_attach_value = { 0, }; - - GValue new_left_attach_value = { 0, }; - GValue new_right_attach_value = { 0, }; - GValue new_top_attach_value = { 0, }; - GValue new_bottom_attach_value = { 0, }; - - GladeProperty *left_attach_prop, *right_attach_prop, - *top_attach_prop, *bottom_attach_prop; - - left_attach_prop = glade_widget_get_pack_property (child, "left-attach"); - right_attach_prop = glade_widget_get_pack_property (child, "right-attach"); - top_attach_prop = glade_widget_get_pack_property (child, "top-attach"); - bottom_attach_prop = glade_widget_get_pack_property (child, "bottom-attach"); - - g_return_val_if_fail (GLADE_IS_PROPERTY (left_attach_prop), FALSE); - g_return_val_if_fail (GLADE_IS_PROPERTY (right_attach_prop), FALSE); - g_return_val_if_fail (GLADE_IS_PROPERTY (top_attach_prop), FALSE); - g_return_val_if_fail (GLADE_IS_PROPERTY (bottom_attach_prop), FALSE); - - glade_property_get_value (left_attach_prop, &new_left_attach_value); - glade_property_get_value (right_attach_prop, &new_right_attach_value); - glade_property_get_value (top_attach_prop, &new_top_attach_value); - glade_property_get_value (bottom_attach_prop, &new_bottom_attach_value); - - g_value_init (&left_attach_value, G_TYPE_UINT); - g_value_init (&right_attach_value, G_TYPE_UINT); - g_value_init (&top_attach_value, G_TYPE_UINT); - g_value_init (&bottom_attach_value, G_TYPE_UINT); - - g_value_set_uint (&left_attach_value, table_edit.left_attach); - g_value_set_uint (&right_attach_value, table_edit.right_attach); - g_value_set_uint (&top_attach_value, table_edit.top_attach); - g_value_set_uint (&bottom_attach_value, table_edit.bottom_attach); - - glade_command_push_group (_("Placing %s inside %s"), - child->name, - GLADE_WIDGET (fixed)->name); - glade_command_set_properties - (left_attach_prop, &left_attach_value, &new_left_attach_value, - right_attach_prop, &right_attach_value, &new_right_attach_value, - top_attach_prop, &top_attach_value, &new_top_attach_value, - bottom_attach_prop, &bottom_attach_value, &new_bottom_attach_value, - NULL); - glade_command_pop_group (); - - g_value_unset (&left_attach_value); - g_value_unset (&right_attach_value); - g_value_unset (&top_attach_value); - g_value_unset (&bottom_attach_value); - g_value_unset (&new_left_attach_value); - g_value_unset (&new_right_attach_value); - g_value_unset (&new_top_attach_value); - g_value_unset (&new_bottom_attach_value); - } - - return TRUE; -} - -void -glade_gtk_table_post_create (GladeWidgetAdaptor *adaptor, - GObject *container, - GladeCreateReason reason) -{ - GladeWidget *gwidget = - glade_widget_get_from_gobject (container); - - g_signal_connect (G_OBJECT (gwidget), "configure-child", - G_CALLBACK (glade_gtk_table_configure_child), container); - - g_signal_connect (G_OBJECT (gwidget), "configure-begin", - G_CALLBACK (glade_gtk_table_configure_begin), container); - - g_signal_connect (G_OBJECT (gwidget), "configure-end", - G_CALLBACK (glade_gtk_table_configure_end), container); +glade_gtk_table_configure_end (GladeFixed * fixed, + GladeWidget * child, GtkWidget * table) +{ + GladeGtkTableChild new_child = { child, }; + + glade_widget_pack_property_get (child, "left-attach", &new_child.left_attach); + glade_widget_pack_property_get (child, "right-attach", + &new_child.right_attach); + glade_widget_pack_property_get (child, "top-attach", &new_child.top_attach); + glade_widget_pack_property_get (child, "bottom-attach", + &new_child.bottom_attach); + + /* Compare the meaningfull part of the current edit. */ + if (memcmp (&new_child, &table_edit, TABLE_CHILD_CMP_SIZE) != 0) + { + GValue left_attach_value = { 0, }; + GValue right_attach_value = { 0, }; + GValue top_attach_value = { 0, }; + GValue bottom_attach_value = { 0, }; + + GValue new_left_attach_value = { 0, }; + GValue new_right_attach_value = { 0, }; + GValue new_top_attach_value = { 0, }; + GValue new_bottom_attach_value = { 0, }; + + GladeProperty *left_attach_prop, *right_attach_prop, + *top_attach_prop, *bottom_attach_prop; + + left_attach_prop = glade_widget_get_pack_property (child, "left-attach"); + right_attach_prop = + glade_widget_get_pack_property (child, "right-attach"); + top_attach_prop = glade_widget_get_pack_property (child, "top-attach"); + bottom_attach_prop = + glade_widget_get_pack_property (child, "bottom-attach"); + + g_return_val_if_fail (GLADE_IS_PROPERTY (left_attach_prop), FALSE); + g_return_val_if_fail (GLADE_IS_PROPERTY (right_attach_prop), FALSE); + g_return_val_if_fail (GLADE_IS_PROPERTY (top_attach_prop), FALSE); + g_return_val_if_fail (GLADE_IS_PROPERTY (bottom_attach_prop), FALSE); + + glade_property_get_value (left_attach_prop, &new_left_attach_value); + glade_property_get_value (right_attach_prop, &new_right_attach_value); + glade_property_get_value (top_attach_prop, &new_top_attach_value); + glade_property_get_value (bottom_attach_prop, &new_bottom_attach_value); + + g_value_init (&left_attach_value, G_TYPE_UINT); + g_value_init (&right_attach_value, G_TYPE_UINT); + g_value_init (&top_attach_value, G_TYPE_UINT); + g_value_init (&bottom_attach_value, G_TYPE_UINT); + + g_value_set_uint (&left_attach_value, table_edit.left_attach); + g_value_set_uint (&right_attach_value, table_edit.right_attach); + g_value_set_uint (&top_attach_value, table_edit.top_attach); + g_value_set_uint (&bottom_attach_value, table_edit.bottom_attach); + + glade_command_push_group (_("Placing %s inside %s"), + child->name, GLADE_WIDGET (fixed)->name); + glade_command_set_properties + (left_attach_prop, &left_attach_value, &new_left_attach_value, + right_attach_prop, &right_attach_value, &new_right_attach_value, + top_attach_prop, &top_attach_value, &new_top_attach_value, + bottom_attach_prop, &bottom_attach_value, &new_bottom_attach_value, + NULL); + glade_command_pop_group (); + + g_value_unset (&left_attach_value); + g_value_unset (&right_attach_value); + g_value_unset (&top_attach_value); + g_value_unset (&bottom_attach_value); + g_value_unset (&new_left_attach_value); + g_value_unset (&new_right_attach_value); + g_value_unset (&new_top_attach_value); + g_value_unset (&new_bottom_attach_value); + } + + return TRUE; +} + +void +glade_gtk_table_post_create (GladeWidgetAdaptor * adaptor, + GObject * container, GladeCreateReason reason) +{ + GladeWidget *gwidget = glade_widget_get_from_gobject (container); + + g_signal_connect (G_OBJECT (gwidget), "configure-child", + G_CALLBACK (glade_gtk_table_configure_child), container); + + g_signal_connect (G_OBJECT (gwidget), "configure-begin", + G_CALLBACK (glade_gtk_table_configure_begin), container); + + g_signal_connect (G_OBJECT (gwidget), "configure-end", + G_CALLBACK (glade_gtk_table_configure_end), container); } static gboolean -glade_gtk_table_has_child (GtkTable *table, guint left_attach, guint top_attach) +glade_gtk_table_has_child (GtkTable * table, guint left_attach, + guint top_attach) { - GList *list, *children; - gboolean ret = FALSE; + GList *list, *children; + gboolean ret = FALSE; - children = gtk_container_get_children (GTK_CONTAINER (table)); + children = gtk_container_get_children (GTK_CONTAINER (table)); - for (list = children; - list && list->data; - list = list->next) - { - GtkTableChild child; + for (list = children; list && list->data; list = list->next) + { + GtkTableChild child; - glade_gtk_table_get_child_attachments (GTK_WIDGET (table), - GTK_WIDGET (list->data), &child); + glade_gtk_table_get_child_attachments (GTK_WIDGET (table), + GTK_WIDGET (list->data), &child); - if (left_attach >= child.left_attach && left_attach < child.right_attach && - top_attach >= child.top_attach && top_attach < child.bottom_attach) - { - ret = TRUE; - break; - } - } + if (left_attach >= child.left_attach && left_attach < child.right_attach + && top_attach >= child.top_attach && top_attach < child.bottom_attach) + { + ret = TRUE; + break; + } + } - g_list_free (children); + g_list_free (children); - return ret; + return ret; } static gboolean -glade_gtk_table_widget_exceeds_bounds (GtkTable *table, gint n_rows, gint n_cols) +glade_gtk_table_widget_exceeds_bounds (GtkTable * table, gint n_rows, + gint n_cols) { - GList *list, *children; - gboolean ret = FALSE; + GList *list, *children; + gboolean ret = FALSE; - children = gtk_container_get_children (GTK_CONTAINER (table)); + children = gtk_container_get_children (GTK_CONTAINER (table)); - for (list = children; - list && list->data; - list = list->next) - { - GtkTableChild child; + for (list = children; list && list->data; list = list->next) + { + GtkTableChild child; - glade_gtk_table_get_child_attachments (GTK_WIDGET (table), - GTK_WIDGET (list->data), &child); + glade_gtk_table_get_child_attachments (GTK_WIDGET (table), + GTK_WIDGET (list->data), &child); - if (GLADE_IS_PLACEHOLDER(child.widget) == FALSE && - (child.right_attach > n_cols || - child.bottom_attach > n_rows)) - { - ret = TRUE; - break; - } - } - return ret; + if (GLADE_IS_PLACEHOLDER (child.widget) == FALSE && + (child.right_attach > n_cols || child.bottom_attach > n_rows)) + { + ret = TRUE; + break; + } + } + return ret; } static void -glade_gtk_table_refresh_placeholders (GtkTable *table) -{ - GList *list, *children; - guint n_columns, n_rows; - gint i, j; - - g_object_get (table, - "n-columns", &n_columns, - "n-rows", &n_rows, - NULL); - - children = gtk_container_get_children (GTK_CONTAINER (table)); - - for (list = children; list && list->data; list = list->next) - { - if (GLADE_IS_PLACEHOLDER (list->data)) - gtk_container_remove (GTK_CONTAINER (table), - GTK_WIDGET (list->data)); - } - g_list_free (children); - - for (i = 0; i < n_columns; i++) - for (j = 0; j < n_rows; j++) - if (glade_gtk_table_has_child (table, i, j) == FALSE) - { - gtk_table_attach_defaults (table, - glade_placeholder_new (), - i, i + 1, j, j + 1); - } - gtk_container_check_resize (GTK_CONTAINER (table)); +glade_gtk_table_refresh_placeholders (GtkTable * table) +{ + GList *list, *children; + guint n_columns, n_rows; + gint i, j; + + g_object_get (table, "n-columns", &n_columns, "n-rows", &n_rows, NULL); + + children = gtk_container_get_children (GTK_CONTAINER (table)); + + for (list = children; list && list->data; list = list->next) + { + if (GLADE_IS_PLACEHOLDER (list->data)) + gtk_container_remove (GTK_CONTAINER (table), GTK_WIDGET (list->data)); + } + g_list_free (children); + + for (i = 0; i < n_columns; i++) + for (j = 0; j < n_rows; j++) + if (glade_gtk_table_has_child (table, i, j) == FALSE) + { + gtk_table_attach_defaults (table, + glade_placeholder_new (), + i, i + 1, j, j + 1); + } + gtk_container_check_resize (GTK_CONTAINER (table)); } static void -gtk_table_children_callback (GtkWidget *widget, - gpointer client_data) +gtk_table_children_callback (GtkWidget * widget, gpointer client_data) { - GList **children; + GList **children; - children = (GList**) client_data; - *children = g_list_prepend (*children, widget); + children = (GList **) client_data; + *children = g_list_prepend (*children, widget); } GList * -glade_gtk_table_get_children (GladeWidgetAdaptor *adaptor, - GtkContainer *container) +glade_gtk_table_get_children (GladeWidgetAdaptor * adaptor, + GtkContainer * container) { - GList *children = NULL; + GList *children = NULL; - g_return_val_if_fail (GTK_IS_TABLE (container), NULL); + g_return_val_if_fail (GTK_IS_TABLE (container), NULL); - gtk_container_forall (container, - gtk_table_children_callback, - &children); + gtk_container_forall (container, gtk_table_children_callback, &children); - /* GtkTable has the children list already reversed */ - return children; + /* GtkTable has the children list already reversed */ + return children; } void -glade_gtk_table_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_table_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_TABLE (object)); - g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (GTK_IS_TABLE (object)); + g_return_if_fail (GTK_IS_WIDGET (child)); - gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); + gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); - glade_gtk_table_refresh_placeholders (GTK_TABLE (object)); + glade_gtk_table_refresh_placeholders (GTK_TABLE (object)); } void -glade_gtk_table_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_table_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_TABLE (object)); - g_return_if_fail (GTK_IS_WIDGET (child)); - - gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); - - glade_gtk_table_refresh_placeholders (GTK_TABLE (object)); + g_return_if_fail (GTK_IS_TABLE (object)); + g_return_if_fail (GTK_IS_WIDGET (child)); + + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); + + glade_gtk_table_refresh_placeholders (GTK_TABLE (object)); } void -glade_gtk_table_replace_child (GladeWidgetAdaptor *adaptor, - GtkWidget *container, - GtkWidget *current, - GtkWidget *new_widget) +glade_gtk_table_replace_child (GladeWidgetAdaptor * adaptor, + GtkWidget * container, + GtkWidget * current, GtkWidget * new_widget) { - g_return_if_fail (GTK_IS_TABLE (container)); - g_return_if_fail (GTK_IS_WIDGET (current)); - g_return_if_fail (GTK_IS_WIDGET (new_widget)); - - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->replace_child (adaptor, - G_OBJECT (container), - G_OBJECT (current), - G_OBJECT (new_widget)); - - /* If we are replacing a GladeWidget, we must refresh placeholders - * because the widget may have spanned multiple rows/columns, we must - * not do so in the case we are pasting multiple widgets into a table, - * where destroying placeholders results in default packing properties - * (since the remaining placeholder templates no longer exist, only the - * first pasted widget would have proper packing properties). - */ - if (glade_widget_get_from_gobject (new_widget) == NULL) - glade_gtk_table_refresh_placeholders (GTK_TABLE (container)); + g_return_if_fail (GTK_IS_TABLE (container)); + g_return_if_fail (GTK_IS_WIDGET (current)); + g_return_if_fail (GTK_IS_WIDGET (new_widget)); + + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->replace_child (adaptor, + G_OBJECT (container), + G_OBJECT (current), + G_OBJECT (new_widget)); + + /* If we are replacing a GladeWidget, we must refresh placeholders + * because the widget may have spanned multiple rows/columns, we must + * not do so in the case we are pasting multiple widgets into a table, + * where destroying placeholders results in default packing properties + * (since the remaining placeholder templates no longer exist, only the + * first pasted widget would have proper packing properties). + */ + if (glade_widget_get_from_gobject (new_widget) == NULL) + glade_gtk_table_refresh_placeholders (GTK_TABLE (container)); } static void -glade_gtk_table_set_n_common (GObject *object, const GValue *value, gboolean for_rows) -{ - GladeWidget *widget; - GtkTable *table; - guint new_size, old_size, n_columns, n_rows; - - table = GTK_TABLE (object); - g_return_if_fail (GTK_IS_TABLE (table)); - - g_object_get (table, - "n-columns", &n_columns, - "n-rows", &n_rows, - NULL); - - new_size = g_value_get_uint (value); - old_size = for_rows ? n_rows : n_columns; - - if (new_size < 1) - return; - - if (glade_gtk_table_widget_exceeds_bounds - (table, - for_rows ? new_size : n_rows, - for_rows ? n_columns : new_size)) - /* Refuse to shrink if it means orphaning widgets */ - return; - - widget = glade_widget_get_from_gobject (GTK_WIDGET (table)); - g_return_if_fail (widget != NULL); - - if (for_rows) - gtk_table_resize (table, new_size, n_columns); - else - gtk_table_resize (table, n_rows, new_size); - - /* Fill table with placeholders */ - glade_gtk_table_refresh_placeholders (table); - - if (new_size < old_size) - { - /* Remove from the bottom up */ - GList *list, *children; - GList *list_to_free = NULL; - - children = gtk_container_get_children (GTK_CONTAINER (table)); - - for (list = children; - list && list->data; - list = list->next) - { - GtkTableChild child; - guint start, end; - - glade_gtk_table_get_child_attachments (GTK_WIDGET (table), - GTK_WIDGET (list->data), &child); - - start = for_rows ? child.top_attach : child.left_attach; - end = for_rows ? child.bottom_attach : child.right_attach; - - /* We need to completely remove it */ - if (start >= new_size) - { - list_to_free = g_list_prepend (list_to_free, child.widget); - continue; - } - - /* If the widget spans beyond the new border, - * we should resize it to fit on the new table */ - if (end > new_size) - gtk_container_child_set - (GTK_CONTAINER (table), GTK_WIDGET (child.widget), - for_rows ? "bottom_attach" : "right_attach", - new_size, NULL); - } - - g_list_free (children); - - if (list_to_free) - { - for (list = g_list_first(list_to_free); - list && list->data; - list = list->next) - { - g_object_ref (G_OBJECT (list->data)); - gtk_container_remove (GTK_CONTAINER (table), - GTK_WIDGET(list->data)); - /* This placeholder is no longer valid, force destroy */ - gtk_widget_destroy (GTK_WIDGET(list->data)); - } - g_list_free (list_to_free); - } - gtk_table_resize (table, - for_rows ? new_size : n_rows, - for_rows ? n_columns : new_size); - } -} - -void -glade_gtk_table_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - if (!strcmp (id, "n-rows")) - glade_gtk_table_set_n_common (object, value, TRUE); - else if (!strcmp (id, "n-columns")) - glade_gtk_table_set_n_common (object, value, FALSE); - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, - id, value); -} - -static gboolean -glade_gtk_table_verify_n_common (GObject *object, const GValue *value, gboolean for_rows) -{ - GtkTable *table = GTK_TABLE(object); - guint n_columns, n_rows, new_size = g_value_get_uint (value); - - g_object_get (table, - "n-columns", &n_columns, - "n-rows", &n_rows, - NULL); - - if (glade_gtk_table_widget_exceeds_bounds - (table, - for_rows ? new_size : n_rows, - for_rows ? n_columns : new_size)) - /* Refuse to shrink if it means orphaning widgets */ - return FALSE; - - return TRUE; +glade_gtk_table_set_n_common (GObject * object, const GValue * value, + gboolean for_rows) +{ + GladeWidget *widget; + GtkTable *table; + guint new_size, old_size, n_columns, n_rows; + + table = GTK_TABLE (object); + g_return_if_fail (GTK_IS_TABLE (table)); + + g_object_get (table, "n-columns", &n_columns, "n-rows", &n_rows, NULL); + + new_size = g_value_get_uint (value); + old_size = for_rows ? n_rows : n_columns; + + if (new_size < 1) + return; + + if (glade_gtk_table_widget_exceeds_bounds + (table, for_rows ? new_size : n_rows, for_rows ? n_columns : new_size)) + /* Refuse to shrink if it means orphaning widgets */ + return; + + widget = glade_widget_get_from_gobject (GTK_WIDGET (table)); + g_return_if_fail (widget != NULL); + + if (for_rows) + gtk_table_resize (table, new_size, n_columns); + else + gtk_table_resize (table, n_rows, new_size); + + /* Fill table with placeholders */ + glade_gtk_table_refresh_placeholders (table); + + if (new_size < old_size) + { + /* Remove from the bottom up */ + GList *list, *children; + GList *list_to_free = NULL; + + children = gtk_container_get_children (GTK_CONTAINER (table)); + + for (list = children; list && list->data; list = list->next) + { + GtkTableChild child; + guint start, end; + + glade_gtk_table_get_child_attachments (GTK_WIDGET (table), + GTK_WIDGET (list->data), + &child); + + start = for_rows ? child.top_attach : child.left_attach; + end = for_rows ? child.bottom_attach : child.right_attach; + + /* We need to completely remove it */ + if (start >= new_size) + { + list_to_free = g_list_prepend (list_to_free, child.widget); + continue; + } + + /* If the widget spans beyond the new border, + * we should resize it to fit on the new table */ + if (end > new_size) + gtk_container_child_set + (GTK_CONTAINER (table), GTK_WIDGET (child.widget), + for_rows ? "bottom_attach" : "right_attach", new_size, NULL); + } + + g_list_free (children); + + if (list_to_free) + { + for (list = g_list_first (list_to_free); + list && list->data; list = list->next) + { + g_object_ref (G_OBJECT (list->data)); + gtk_container_remove (GTK_CONTAINER (table), + GTK_WIDGET (list->data)); + /* This placeholder is no longer valid, force destroy */ + gtk_widget_destroy (GTK_WIDGET (list->data)); + } + g_list_free (list_to_free); + } + gtk_table_resize (table, + for_rows ? new_size : n_rows, + for_rows ? n_columns : new_size); + } +} + +void +glade_gtk_table_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + if (!strcmp (id, "n-rows")) + glade_gtk_table_set_n_common (object, value, TRUE); + else if (!strcmp (id, "n-columns")) + glade_gtk_table_set_n_common (object, value, FALSE); + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, + id, value); +} + +static gboolean +glade_gtk_table_verify_n_common (GObject * object, const GValue * value, + gboolean for_rows) +{ + GtkTable *table = GTK_TABLE (object); + guint n_columns, n_rows, new_size = g_value_get_uint (value); + + g_object_get (table, "n-columns", &n_columns, "n-rows", &n_rows, NULL); + + if (glade_gtk_table_widget_exceeds_bounds + (table, for_rows ? new_size : n_rows, for_rows ? n_columns : new_size)) + /* Refuse to shrink if it means orphaning widgets */ + return FALSE; + + return TRUE; } gboolean -glade_gtk_table_verify_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_table_verify_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "n-rows")) - return glade_gtk_table_verify_n_common (object, value, TRUE); - else if (!strcmp (id, "n-columns")) - return glade_gtk_table_verify_n_common (object, value, FALSE); - else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, - id, value); + if (!strcmp (id, "n-rows")) + return glade_gtk_table_verify_n_common (object, value, TRUE); + else if (!strcmp (id, "n-columns")) + return glade_gtk_table_verify_n_common (object, value, FALSE); + else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, + id, value); - return TRUE; + return TRUE; } void -glade_gtk_table_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) +glade_gtk_table_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, GValue * value) { - g_return_if_fail (GTK_IS_TABLE (container)); - g_return_if_fail (GTK_IS_WIDGET (child)); - g_return_if_fail (property_name != NULL && value != NULL); + g_return_if_fail (GTK_IS_TABLE (container)); + g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (property_name != NULL && value != NULL); - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, child, - property_name, value); - - if (strcmp (property_name, "bottom-attach") == 0 || - strcmp (property_name, "left-attach") == 0 || - strcmp (property_name, "right-attach") == 0 || - strcmp (property_name, "top-attach") == 0) - { - /* Refresh placeholders */ - glade_gtk_table_refresh_placeholders (GTK_TABLE (container)); - } + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, child, + property_name, value); + + if (strcmp (property_name, "bottom-attach") == 0 || + strcmp (property_name, "left-attach") == 0 || + strcmp (property_name, "right-attach") == 0 || + strcmp (property_name, "top-attach") == 0) + { + /* Refresh placeholders */ + glade_gtk_table_refresh_placeholders (GTK_TABLE (container)); + } } static gboolean -glade_gtk_table_verify_attach_common (GObject *object, - GValue *value, - guint *val, - const gchar *prop, - guint *prop_val, - const gchar *parent_prop, - guint *parent_val) -{ - GladeWidget *widget, *parent; - - widget = glade_widget_get_from_gobject (object); - g_return_val_if_fail (GLADE_IS_WIDGET (widget), TRUE); - parent = glade_widget_get_parent (widget); - g_return_val_if_fail (GLADE_IS_WIDGET (parent), TRUE); - - *val = g_value_get_uint (value); - glade_widget_property_get (widget, prop, prop_val); - glade_widget_property_get (parent, parent_prop, parent_val); - - return FALSE; +glade_gtk_table_verify_attach_common (GObject * object, + GValue * value, + guint * val, + const gchar * prop, + guint * prop_val, + const gchar * parent_prop, + guint * parent_val) +{ + GladeWidget *widget, *parent; + + widget = glade_widget_get_from_gobject (object); + g_return_val_if_fail (GLADE_IS_WIDGET (widget), TRUE); + parent = glade_widget_get_parent (widget); + g_return_val_if_fail (GLADE_IS_WIDGET (parent), TRUE); + + *val = g_value_get_uint (value); + glade_widget_property_get (widget, prop, prop_val); + glade_widget_property_get (parent, parent_prop, parent_val); + + return FALSE; } static gboolean -glade_gtk_table_verify_left_top_attach (GObject *object, - GValue *value, - const gchar *prop, - const gchar *parent_prop) -{ - guint val, prop_val, parent_val; - - if (glade_gtk_table_verify_attach_common (object, value, &val, - prop, &prop_val, - parent_prop, &parent_val)) - return FALSE; - - if (val >= parent_val || val >= prop_val) - return FALSE; - - return TRUE; +glade_gtk_table_verify_left_top_attach (GObject * object, + GValue * value, + const gchar * prop, + const gchar * parent_prop) +{ + guint val, prop_val, parent_val; + + if (glade_gtk_table_verify_attach_common (object, value, &val, + prop, &prop_val, + parent_prop, &parent_val)) + return FALSE; + + if (val >= parent_val || val >= prop_val) + return FALSE; + + return TRUE; } static gboolean -glade_gtk_table_verify_right_bottom_attach (GObject *object, - GValue *value, - const gchar *prop, - const gchar *parent_prop) -{ - guint val, prop_val, parent_val; - - if (glade_gtk_table_verify_attach_common (object, value, &val, - prop, &prop_val, - parent_prop, &parent_val)) - return FALSE; - - if (val <= prop_val || val > parent_val) - return FALSE; - - return TRUE; +glade_gtk_table_verify_right_bottom_attach (GObject * object, + GValue * value, + const gchar * prop, + const gchar * parent_prop) +{ + guint val, prop_val, parent_val; + + if (glade_gtk_table_verify_attach_common (object, value, &val, + prop, &prop_val, + parent_prop, &parent_val)) + return FALSE; + + if (val <= prop_val || val > parent_val) + return FALSE; + + return TRUE; } gboolean -glade_gtk_table_child_verify_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *id, - GValue *value) -{ - if (!strcmp (id, "left-attach")) - return glade_gtk_table_verify_left_top_attach (child, - value, - "right-attach", - "n-columns"); - else if (!strcmp (id, "right-attach")) - return glade_gtk_table_verify_right_bottom_attach (child, - value, - "left-attach", - "n-columns"); - else if (!strcmp (id, "top-attach")) - return glade_gtk_table_verify_left_top_attach (child, - value, - "bottom-attach", - "n-rows"); - else if (!strcmp (id, "bottom-attach")) - return glade_gtk_table_verify_right_bottom_attach (child, - value, - "top-attach", - "n-rows"); - else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_verify_property) - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_verify_property (adaptor, - container, child, - id, value); - - return TRUE; +glade_gtk_table_child_verify_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * id, GValue * value) +{ + if (!strcmp (id, "left-attach")) + return glade_gtk_table_verify_left_top_attach (child, + value, + "right-attach", "n-columns"); + else if (!strcmp (id, "right-attach")) + return glade_gtk_table_verify_right_bottom_attach (child, + value, + "left-attach", + "n-columns"); + else if (!strcmp (id, "top-attach")) + return glade_gtk_table_verify_left_top_attach (child, + value, + "bottom-attach", "n-rows"); + else if (!strcmp (id, "bottom-attach")) + return glade_gtk_table_verify_right_bottom_attach (child, + value, + "top-attach", "n-rows"); + else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_verify_property) + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_verify_property (adaptor, + container, child, + id, value); + + return TRUE; } static void -glade_gtk_table_child_insert_remove_action (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *group_format, - const gchar *n_row_col, - const gchar *attach1, /* should be smaller (top/left) attachment */ - const gchar *attach2, /* should be larger (bot/right) attachment */ - gboolean remove, - gboolean after) -{ - GladeWidget *parent; - GList *children, *l; - gint child_pos, size, offset; - - gtk_container_child_get (GTK_CONTAINER (container), - GTK_WIDGET (object), - after ? attach2 : attach1, &child_pos, NULL); - - parent = glade_widget_get_from_gobject (container); - glade_command_push_group (group_format, glade_widget_get_name (parent)); - - children = glade_widget_adaptor_get_children (adaptor, container); - /* Make sure widgets does not get destroyed */ - g_list_foreach (children, (GFunc) g_object_ref, NULL); - - glade_widget_property_get (parent, n_row_col, &size); - - if (remove) - { - GList *del = NULL; - /* Remove children first */ - for (l = children; l; l = g_list_next (l)) - { - GladeWidget *gchild = glade_widget_get_from_gobject (l->data); - gint pos1, pos2; - - /* Skip placeholders */ - if (gchild == NULL) continue; - - glade_widget_pack_property_get (gchild, attach1, &pos1); - glade_widget_pack_property_get (gchild, attach2, &pos2); - if ((pos1+1 == pos2) && ((after ? pos2 : pos1) == child_pos)) - { - del = g_list_prepend (del, gchild); - } - } - if (del) - { - glade_command_delete (del); - g_list_free (del); - } - offset = -1; - } - else - { - /* Expand the table */ - glade_command_set_property (glade_widget_get_property (parent, n_row_col), - size + 1); - offset = 1; - } - - /* Reorder children */ - for (l = children; l; l = g_list_next (l)) - { - GladeWidget *gchild = glade_widget_get_from_gobject (l->data); - gint pos; - - /* Skip placeholders */ - if (gchild == NULL) continue; - - /* if removing, do top/left before bot/right */ - if (remove) - { - /* adjust top-left attachment*/ - glade_widget_pack_property_get (gchild, attach1, &pos); - if(pos > child_pos || (after && pos == child_pos)) - { - glade_command_set_property (glade_widget_get_pack_property (gchild, attach1), pos+offset); - } - - /* adjust bottom-right attachment*/ - glade_widget_pack_property_get (gchild, attach2, &pos); - if(pos > child_pos || (after && pos == child_pos)) - { - glade_command_set_property (glade_widget_get_pack_property (gchild, attach2), pos+offset); - } - - } - /* if inserting, do bot/right before top/left */ - else - { - /* adjust bottom-right attachment*/ - glade_widget_pack_property_get (gchild, attach2, &pos); - if(pos > child_pos) - { - glade_command_set_property (glade_widget_get_pack_property (gchild, attach2), pos+offset); - } - - /* adjust top-left attachment*/ - glade_widget_pack_property_get (gchild, attach1, &pos); - if(pos >= child_pos) - { - glade_command_set_property (glade_widget_get_pack_property (gchild, attach1), pos+offset); - } - } - } - - if (remove) - { - /* Shrink the table */ - glade_command_set_property (glade_widget_get_property (parent, n_row_col), - size - 1); - } - - g_list_foreach (children, (GFunc) g_object_unref, NULL); - g_list_free (children); - - glade_command_pop_group (); -} - -void -glade_gtk_table_child_action_activate (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *action_path) -{ - if (strcmp (action_path, "insert_row/after") == 0) - { - glade_gtk_table_child_insert_remove_action (adaptor, container, object, - _("Insert Row on %s"), - "n-rows","top-attach", - "bottom-attach", - FALSE, TRUE); - } - else if (strcmp (action_path, "insert_row/before") == 0) - { - glade_gtk_table_child_insert_remove_action (adaptor, container, object, - _("Insert Row on %s"), - "n-rows","top-attach", - "bottom-attach", - FALSE, FALSE); - } - else if (strcmp (action_path, "insert_column/after") == 0) - { - glade_gtk_table_child_insert_remove_action (adaptor, container, object, - _("Insert Column on %s"), - "n-columns","left-attach", - "right-attach", - FALSE, TRUE); - } - else if (strcmp (action_path, "insert_column/before") == 0) - { - glade_gtk_table_child_insert_remove_action (adaptor, container, object, - _("Insert Column on %s"), - "n-columns","left-attach", - "right-attach", - FALSE, FALSE); - } - else if (strcmp (action_path, "remove_column") == 0) - { - glade_gtk_table_child_insert_remove_action (adaptor, container, object, - _("Remove Column on %s"), - "n-columns","left-attach", - "right-attach", - TRUE, FALSE); - } - else if (strcmp (action_path, "remove_row") == 0) - { - glade_gtk_table_child_insert_remove_action (adaptor, container, object, - _("Remove Row on %s"), - "n-rows","top-attach", - "bottom-attach", - TRUE, FALSE); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor, - container, - object, - action_path); +glade_gtk_table_child_insert_remove_action (GladeWidgetAdaptor * adaptor, GObject * container, GObject * object, const gchar * group_format, const gchar * n_row_col, const gchar * attach1, /* should be smaller (top/left) attachment */ + const gchar * attach2, /* should be larger (bot/right) attachment */ + gboolean remove, gboolean after) +{ + GladeWidget *parent; + GList *children, *l; + gint child_pos, size, offset; + + gtk_container_child_get (GTK_CONTAINER (container), + GTK_WIDGET (object), + after ? attach2 : attach1, &child_pos, NULL); + + parent = glade_widget_get_from_gobject (container); + glade_command_push_group (group_format, glade_widget_get_name (parent)); + + children = glade_widget_adaptor_get_children (adaptor, container); + /* Make sure widgets does not get destroyed */ + g_list_foreach (children, (GFunc) g_object_ref, NULL); + + glade_widget_property_get (parent, n_row_col, &size); + + if (remove) + { + GList *del = NULL; + /* Remove children first */ + for (l = children; l; l = g_list_next (l)) + { + GladeWidget *gchild = glade_widget_get_from_gobject (l->data); + gint pos1, pos2; + + /* Skip placeholders */ + if (gchild == NULL) + continue; + + glade_widget_pack_property_get (gchild, attach1, &pos1); + glade_widget_pack_property_get (gchild, attach2, &pos2); + if ((pos1 + 1 == pos2) && ((after ? pos2 : pos1) == child_pos)) + { + del = g_list_prepend (del, gchild); + } + } + if (del) + { + glade_command_delete (del); + g_list_free (del); + } + offset = -1; + } + else + { + /* Expand the table */ + glade_command_set_property (glade_widget_get_property (parent, n_row_col), + size + 1); + offset = 1; + } + + /* Reorder children */ + for (l = children; l; l = g_list_next (l)) + { + GladeWidget *gchild = glade_widget_get_from_gobject (l->data); + gint pos; + + /* Skip placeholders */ + if (gchild == NULL) + continue; + + /* if removing, do top/left before bot/right */ + if (remove) + { + /* adjust top-left attachment */ + glade_widget_pack_property_get (gchild, attach1, &pos); + if (pos > child_pos || (after && pos == child_pos)) + { + glade_command_set_property (glade_widget_get_pack_property + (gchild, attach1), pos + offset); + } + + /* adjust bottom-right attachment */ + glade_widget_pack_property_get (gchild, attach2, &pos); + if (pos > child_pos || (after && pos == child_pos)) + { + glade_command_set_property (glade_widget_get_pack_property + (gchild, attach2), pos + offset); + } + + } + /* if inserting, do bot/right before top/left */ + else + { + /* adjust bottom-right attachment */ + glade_widget_pack_property_get (gchild, attach2, &pos); + if (pos > child_pos) + { + glade_command_set_property (glade_widget_get_pack_property + (gchild, attach2), pos + offset); + } + + /* adjust top-left attachment */ + glade_widget_pack_property_get (gchild, attach1, &pos); + if (pos >= child_pos) + { + glade_command_set_property (glade_widget_get_pack_property + (gchild, attach1), pos + offset); + } + } + } + + if (remove) + { + /* Shrink the table */ + glade_command_set_property (glade_widget_get_property (parent, n_row_col), + size - 1); + } + + g_list_foreach (children, (GFunc) g_object_unref, NULL); + g_list_free (children); + + glade_command_pop_group (); +} + +void +glade_gtk_table_child_action_activate (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * object, + const gchar * action_path) +{ + if (strcmp (action_path, "insert_row/after") == 0) + { + glade_gtk_table_child_insert_remove_action (adaptor, container, object, + _("Insert Row on %s"), + "n-rows", "top-attach", + "bottom-attach", FALSE, TRUE); + } + else if (strcmp (action_path, "insert_row/before") == 0) + { + glade_gtk_table_child_insert_remove_action (adaptor, container, object, + _("Insert Row on %s"), + "n-rows", "top-attach", + "bottom-attach", + FALSE, FALSE); + } + else if (strcmp (action_path, "insert_column/after") == 0) + { + glade_gtk_table_child_insert_remove_action (adaptor, container, object, + _("Insert Column on %s"), + "n-columns", "left-attach", + "right-attach", FALSE, TRUE); + } + else if (strcmp (action_path, "insert_column/before") == 0) + { + glade_gtk_table_child_insert_remove_action (adaptor, container, object, + _("Insert Column on %s"), + "n-columns", "left-attach", + "right-attach", FALSE, FALSE); + } + else if (strcmp (action_path, "remove_column") == 0) + { + glade_gtk_table_child_insert_remove_action (adaptor, container, object, + _("Remove Column on %s"), + "n-columns", "left-attach", + "right-attach", TRUE, FALSE); + } + else if (strcmp (action_path, "remove_row") == 0) + { + glade_gtk_table_child_insert_remove_action (adaptor, container, object, + _("Remove Row on %s"), + "n-rows", "top-attach", + "bottom-attach", TRUE, FALSE); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor, + container, + object, + action_path); } /* ----------------------------- GtkFrame ------------------------------ */ void -glade_gtk_frame_post_create (GladeWidgetAdaptor *adaptor, - GObject *frame, - GladeCreateReason reason) -{ - static GladeWidgetAdaptor *label_adaptor = NULL, *alignment_adaptor = NULL; - GladeWidget *gframe, *glabel, *galignment; - GtkWidget *label; - gchar *label_text; - - if (reason != GLADE_CREATE_USER) - return; - - g_return_if_fail (GTK_IS_FRAME (frame)); - gframe = glade_widget_get_from_gobject (frame); - g_return_if_fail (GLADE_IS_WIDGET (gframe)); - - /* If we didnt put this object here or if frame is an aspect frame... */ - if (((label = gtk_frame_get_label_widget (GTK_FRAME (frame))) == NULL || - (glade_widget_get_from_gobject (label) == NULL)) && - (GTK_IS_ASPECT_FRAME (frame) == FALSE)) - { - - if (label_adaptor == NULL) - label_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); - if (alignment_adaptor == NULL) - alignment_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_ALIGNMENT); - - /* add label (as an internal child) */ - glabel = glade_widget_adaptor_create_widget (label_adaptor, FALSE, - "parent", gframe, - "project", glade_widget_get_project (gframe), - NULL); - - label_text = g_strdup_printf ("<b>%s</b>", glade_widget_get_name (gframe)); - glade_widget_property_set (glabel, "label", label_text); - glade_widget_property_set (glabel, "use-markup", "TRUE"); - g_free (label_text); - - g_object_set_data (glabel->object, "special-child-type", "label_item"); - glade_widget_add_child (gframe, glabel, FALSE); - - /* add alignment */ - galignment = glade_widget_adaptor_create_widget (alignment_adaptor, FALSE, - "parent", gframe, - "project", glade_widget_get_project (gframe), - NULL); - - glade_widget_property_set (galignment, "left-padding", 12); - glade_widget_add_child (gframe, galignment, FALSE); - } - - /* Chain Up */ - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->post_create (adaptor, frame, reason); -} - -void -glade_gtk_frame_replace_child (GladeWidgetAdaptor *adaptor, - GtkWidget *container, - GtkWidget *current, - GtkWidget *new_widget) -{ - gchar *special_child_type; - - special_child_type = - g_object_get_data (G_OBJECT (current), "special-child-type"); - - if (special_child_type && !strcmp (special_child_type, "label_item")) - { - g_object_set_data (G_OBJECT (new_widget), "special-child-type", "label_item"); - gtk_frame_set_label_widget (GTK_FRAME (container), new_widget); - return; - } - - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->replace_child (adaptor, - G_OBJECT (container), - G_OBJECT (current), - G_OBJECT (new_widget)); -} - -void -glade_gtk_frame_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - GtkWidget *bin_child; - gchar *special_child_type; - - special_child_type = g_object_get_data (child, "special-child-type"); - - if (special_child_type && !strcmp (special_child_type, "label")) - { - g_object_set_data (child, - "special-child-type", - "label_item"); - gtk_frame_set_label_widget (GTK_FRAME (object), - GTK_WIDGET (child)); - } - else if (special_child_type && - !strcmp (special_child_type, "label_item")) - { - gtk_frame_set_label_widget (GTK_FRAME (object), - GTK_WIDGET (child)); - } - else - { - /* Get a placeholder out of the way before adding the child - */ - bin_child = gtk_bin_get_child (GTK_BIN (object)); - if (bin_child) - { - if (GLADE_IS_PLACEHOLDER (bin_child)) - gtk_container_remove (GTK_CONTAINER (object), bin_child); - else - { - g_critical ("Cant add more than one widget to a GtkFrame"); - return; - } - } - gtk_container_add (GTK_CONTAINER (object), - GTK_WIDGET (child)); - } -} - -void -glade_gtk_frame_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - gchar *special_child_type; - - special_child_type = g_object_get_data (child, "special-child-type"); - if (special_child_type && - !strcmp (special_child_type, "label_item")) - { - gtk_frame_set_label_widget (GTK_FRAME (object), - glade_placeholder_new ()); - } - else - { - gtk_container_remove (GTK_CONTAINER (object), - GTK_WIDGET (child)); - gtk_container_add (GTK_CONTAINER (object), - glade_placeholder_new ()); - } +glade_gtk_frame_post_create (GladeWidgetAdaptor * adaptor, + GObject * frame, GladeCreateReason reason) +{ + static GladeWidgetAdaptor *label_adaptor = NULL, *alignment_adaptor = NULL; + GladeWidget *gframe, *glabel, *galignment; + GtkWidget *label; + gchar *label_text; + + if (reason != GLADE_CREATE_USER) + return; + + g_return_if_fail (GTK_IS_FRAME (frame)); + gframe = glade_widget_get_from_gobject (frame); + g_return_if_fail (GLADE_IS_WIDGET (gframe)); + + /* If we didnt put this object here or if frame is an aspect frame... */ + if (((label = gtk_frame_get_label_widget (GTK_FRAME (frame))) == NULL || + (glade_widget_get_from_gobject (label) == NULL)) && + (GTK_IS_ASPECT_FRAME (frame) == FALSE)) + { + + if (label_adaptor == NULL) + label_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); + if (alignment_adaptor == NULL) + alignment_adaptor = + glade_widget_adaptor_get_by_type (GTK_TYPE_ALIGNMENT); + + /* add label (as an internal child) */ + glabel = glade_widget_adaptor_create_widget (label_adaptor, FALSE, + "parent", gframe, + "project", + glade_widget_get_project + (gframe), NULL); + + label_text = + g_strdup_printf ("<b>%s</b>", glade_widget_get_name (gframe)); + glade_widget_property_set (glabel, "label", label_text); + glade_widget_property_set (glabel, "use-markup", "TRUE"); + g_free (label_text); + + g_object_set_data (glabel->object, "special-child-type", "label_item"); + glade_widget_add_child (gframe, glabel, FALSE); + + /* add alignment */ + galignment = glade_widget_adaptor_create_widget (alignment_adaptor, FALSE, + "parent", gframe, + "project", + glade_widget_get_project + (gframe), NULL); + + glade_widget_property_set (galignment, "left-padding", 12); + glade_widget_add_child (gframe, galignment, FALSE); + } + + /* Chain Up */ + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->post_create (adaptor, frame, reason); +} + +void +glade_gtk_frame_replace_child (GladeWidgetAdaptor * adaptor, + GtkWidget * container, + GtkWidget * current, GtkWidget * new_widget) +{ + gchar *special_child_type; + + special_child_type = + g_object_get_data (G_OBJECT (current), "special-child-type"); + + if (special_child_type && !strcmp (special_child_type, "label_item")) + { + g_object_set_data (G_OBJECT (new_widget), "special-child-type", + "label_item"); + gtk_frame_set_label_widget (GTK_FRAME (container), new_widget); + return; + } + + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->replace_child (adaptor, + G_OBJECT (container), + G_OBJECT (current), + G_OBJECT (new_widget)); +} + +void +glade_gtk_frame_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + GtkWidget *bin_child; + gchar *special_child_type; + + special_child_type = g_object_get_data (child, "special-child-type"); + + if (special_child_type && !strcmp (special_child_type, "label")) + { + g_object_set_data (child, "special-child-type", "label_item"); + gtk_frame_set_label_widget (GTK_FRAME (object), GTK_WIDGET (child)); + } + else if (special_child_type && !strcmp (special_child_type, "label_item")) + { + gtk_frame_set_label_widget (GTK_FRAME (object), GTK_WIDGET (child)); + } + else + { + /* Get a placeholder out of the way before adding the child + */ + bin_child = gtk_bin_get_child (GTK_BIN (object)); + if (bin_child) + { + if (GLADE_IS_PLACEHOLDER (bin_child)) + gtk_container_remove (GTK_CONTAINER (object), bin_child); + else + { + g_critical ("Cant add more than one widget to a GtkFrame"); + return; + } + } + gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); + } +} + +void +glade_gtk_frame_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + gchar *special_child_type; + + special_child_type = g_object_get_data (child, "special-child-type"); + if (special_child_type && !strcmp (special_child_type, "label_item")) + { + gtk_frame_set_label_widget (GTK_FRAME (object), glade_placeholder_new ()); + } + else + { + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); + gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ()); + } } static gboolean -write_special_child_label_item (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node, - GladeWriteWidgetFunc write_func) -{ - gchar *special_child_type = NULL; - GObject *child; - - child = widget->object; - if (child) - special_child_type = g_object_get_data (child, "special-child-type"); - - if (special_child_type && !strcmp (special_child_type, "label_item")) - { - g_object_set_data (child, - "special-child-type", - "label"); - write_func (adaptor, widget, context, node); - g_object_set_data (child, - "special-child-type", - "label_item"); - return TRUE; - } - else - return FALSE; -} - -void -glade_gtk_frame_write_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) -{ - - if (!write_special_child_label_item (adaptor, widget, context, node, - GWA_GET_CLASS(GTK_TYPE_CONTAINER)->write_child)) - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->write_child (adaptor, - widget, - context, - node); +write_special_child_label_item (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node, + GladeWriteWidgetFunc write_func) +{ + gchar *special_child_type = NULL; + GObject *child; + + child = widget->object; + if (child) + special_child_type = g_object_get_data (child, "special-child-type"); + + if (special_child_type && !strcmp (special_child_type, "label_item")) + { + g_object_set_data (child, "special-child-type", "label"); + write_func (adaptor, widget, context, node); + g_object_set_data (child, "special-child-type", "label_item"); + return TRUE; + } + else + return FALSE; +} + +void +glade_gtk_frame_write_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) +{ + + if (!write_special_child_label_item (adaptor, widget, context, node, + GWA_GET_CLASS (GTK_TYPE_CONTAINER)-> + write_child)) + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, node); } /* ----------------------------- GtkNotebook ------------------------------ */ -typedef struct +typedef struct { - gint pages; - gint page; + gint pages; + gint page; - GList *children; - GList *tabs; + GList *children; + GList *tabs; - GList *extra_children; - GList *extra_tabs; + GList *extra_children; + GList *extra_tabs; } NotebookChildren; static gboolean glade_gtk_notebook_setting_position = FALSE; static gint -notebook_child_compare_func (GtkWidget *widget_a, GtkWidget *widget_b) +notebook_child_compare_func (GtkWidget * widget_a, GtkWidget * widget_b) { - GladeWidget *gwidget_a, *gwidget_b; - gint pos_a = 0, pos_b = 0; + GladeWidget *gwidget_a, *gwidget_b; + gint pos_a = 0, pos_b = 0; + + gwidget_a = glade_widget_get_from_gobject (widget_a); + gwidget_b = glade_widget_get_from_gobject (widget_b); + + g_assert (gwidget_a && gwidget_b); + + glade_widget_pack_property_get (gwidget_a, "position", &pos_a); + glade_widget_pack_property_get (gwidget_b, "position", &pos_b); - gwidget_a = glade_widget_get_from_gobject (widget_a); - gwidget_b = glade_widget_get_from_gobject (widget_b); - - g_assert (gwidget_a && gwidget_b); - - glade_widget_pack_property_get (gwidget_a, "position", &pos_a); - glade_widget_pack_property_get (gwidget_b, "position", &pos_b); - - return pos_a - pos_b; + return pos_a - pos_b; } static gint -notebook_find_child (GtkWidget *check, - gpointer cmp_pos_p) +notebook_find_child (GtkWidget * check, gpointer cmp_pos_p) { - GladeWidget *gcheck; - gint position = 0, cmp_pos = GPOINTER_TO_INT (cmp_pos_p); - - gcheck = glade_widget_get_from_gobject (check); - g_assert (gcheck); - - glade_widget_pack_property_get (gcheck, "position", &position); + GladeWidget *gcheck; + gint position = 0, cmp_pos = GPOINTER_TO_INT (cmp_pos_p); - return position - cmp_pos; + gcheck = glade_widget_get_from_gobject (check); + g_assert (gcheck); + + glade_widget_pack_property_get (gcheck, "position", &position); + + return position - cmp_pos; } static gint -notebook_search_tab (GtkNotebook *notebook, - GtkWidget *tab) +notebook_search_tab (GtkNotebook * notebook, GtkWidget * tab) { - GtkWidget *page; - gint i; + GtkWidget *page; + gint i; - for (i = 0; i < gtk_notebook_get_n_pages (notebook); i++) - { - page = gtk_notebook_get_nth_page (notebook, i); + for (i = 0; i < gtk_notebook_get_n_pages (notebook); i++) + { + page = gtk_notebook_get_nth_page (notebook, i); - if (tab == gtk_notebook_get_tab_label (notebook, page)) - return i; - } - g_critical ("Unable to find tab position in a notebook"); - return -1; + if (tab == gtk_notebook_get_tab_label (notebook, page)) + return i; + } + g_critical ("Unable to find tab position in a notebook"); + return -1; } static GtkWidget * -notebook_get_filler (NotebookChildren *nchildren, gboolean page) -{ - GtkWidget *widget = NULL; - - if (page && nchildren->extra_children) - { - widget = nchildren->extra_children->data; - nchildren->extra_children = - g_list_remove (nchildren->extra_children, widget); - g_assert (widget); - } - else if (!page && nchildren->extra_tabs) - { - widget = nchildren->extra_tabs->data; - nchildren->extra_tabs = - g_list_remove (nchildren->extra_tabs, widget); - g_assert (widget); - } - - if (widget == NULL) - { - /* Need explicit reference here */ - widget = glade_placeholder_new (); - - g_object_ref (G_OBJECT (widget)); - - if (!page) - g_object_set_data (G_OBJECT (widget), - "special-child-type", "tab"); - - } - return widget; +notebook_get_filler (NotebookChildren * nchildren, gboolean page) +{ + GtkWidget *widget = NULL; + + if (page && nchildren->extra_children) + { + widget = nchildren->extra_children->data; + nchildren->extra_children = + g_list_remove (nchildren->extra_children, widget); + g_assert (widget); + } + else if (!page && nchildren->extra_tabs) + { + widget = nchildren->extra_tabs->data; + nchildren->extra_tabs = g_list_remove (nchildren->extra_tabs, widget); + g_assert (widget); + } + + if (widget == NULL) + { + /* Need explicit reference here */ + widget = glade_placeholder_new (); + + g_object_ref (G_OBJECT (widget)); + + if (!page) + g_object_set_data (G_OBJECT (widget), "special-child-type", "tab"); + + } + return widget; } static GtkWidget * -notebook_get_page (NotebookChildren *nchildren, gint position) +notebook_get_page (NotebookChildren * nchildren, gint position) { - GList *node; - GtkWidget *widget = NULL; + GList *node; + GtkWidget *widget = NULL; - if ((node = g_list_find_custom - (nchildren->children, - GINT_TO_POINTER (position), - (GCompareFunc)notebook_find_child)) != NULL) - { - widget = node->data; - nchildren->children = - g_list_remove (nchildren->children, widget); - } - else - widget = notebook_get_filler (nchildren, TRUE); + if ((node = g_list_find_custom + (nchildren->children, + GINT_TO_POINTER (position), + (GCompareFunc) notebook_find_child)) != NULL) + { + widget = node->data; + nchildren->children = g_list_remove (nchildren->children, widget); + } + else + widget = notebook_get_filler (nchildren, TRUE); - return widget; + return widget; } static GtkWidget * -notebook_get_tab (NotebookChildren *nchildren, gint position) +notebook_get_tab (NotebookChildren * nchildren, gint position) { - GList *node; - GtkWidget *widget = NULL; + GList *node; + GtkWidget *widget = NULL; - if ((node = g_list_find_custom - (nchildren->tabs, - GINT_TO_POINTER (position), - (GCompareFunc)notebook_find_child)) != NULL) - { - widget = node->data; - nchildren->tabs = - g_list_remove (nchildren->tabs, widget); - } - else - widget = notebook_get_filler (nchildren, FALSE); + if ((node = g_list_find_custom + (nchildren->tabs, + GINT_TO_POINTER (position), + (GCompareFunc) notebook_find_child)) != NULL) + { + widget = node->data; + nchildren->tabs = g_list_remove (nchildren->tabs, widget); + } + else + widget = notebook_get_filler (nchildren, FALSE); - return widget; + return widget; } static NotebookChildren * -glade_gtk_notebook_extract_children (GtkWidget *notebook) -{ - NotebookChildren *nchildren; - gchar *special_child_type; - GList *list, *children = - glade_util_container_get_all_children (GTK_CONTAINER (notebook)); - GladeWidget *gchild; - GtkWidget *page; - gint position = 0; - - nchildren = g_new0 (NotebookChildren, 1); - nchildren->pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); - nchildren->page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); - - /* Ref all the project widgets and build returned list first */ - for (list = children; list; list = list->next) - { - if ((gchild = glade_widget_get_from_gobject (list->data)) != NULL) - { - special_child_type = - g_object_get_data (G_OBJECT (list->data), - "special-child-type"); - - glade_widget_pack_property_get (gchild, "position", &position); - - g_object_ref (G_OBJECT (list->data)); - - /* Sort it into the proper struct member - */ - if (special_child_type == NULL) - { - if (g_list_find_custom (nchildren->children, - GINT_TO_POINTER (position), - (GCompareFunc)notebook_find_child)) - nchildren->extra_children = - g_list_insert_sorted - (nchildren->extra_children, list->data, - (GCompareFunc)notebook_child_compare_func); - else - nchildren->children = - g_list_insert_sorted - (nchildren->children, list->data, - (GCompareFunc)notebook_child_compare_func); - } else { - if (g_list_find_custom (nchildren->tabs, - GINT_TO_POINTER (position), - (GCompareFunc)notebook_find_child)) - nchildren->extra_tabs = - g_list_insert_sorted - (nchildren->extra_tabs, list->data, - (GCompareFunc)notebook_child_compare_func); - else - nchildren->tabs = - g_list_insert_sorted - (nchildren->tabs, list->data, - (GCompareFunc)notebook_child_compare_func); - } - } - } - - /* Remove all pages, resulting in the unparenting of all widgets including tab-labels. - */ - while (gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 0) - { - page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 0); - - /* Explicitly remove the tab label first */ - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), page, NULL); - gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), 0); - } - - if (children) - g_list_free (children); - - return nchildren; +glade_gtk_notebook_extract_children (GtkWidget * notebook) +{ + NotebookChildren *nchildren; + gchar *special_child_type; + GList *list, *children = + glade_util_container_get_all_children (GTK_CONTAINER (notebook)); + GladeWidget *gchild; + GtkWidget *page; + gint position = 0; + + nchildren = g_new0 (NotebookChildren, 1); + nchildren->pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); + nchildren->page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); + + /* Ref all the project widgets and build returned list first */ + for (list = children; list; list = list->next) + { + if ((gchild = glade_widget_get_from_gobject (list->data)) != NULL) + { + special_child_type = + g_object_get_data (G_OBJECT (list->data), "special-child-type"); + + glade_widget_pack_property_get (gchild, "position", &position); + + g_object_ref (G_OBJECT (list->data)); + + /* Sort it into the proper struct member + */ + if (special_child_type == NULL) + { + if (g_list_find_custom (nchildren->children, + GINT_TO_POINTER (position), + (GCompareFunc) notebook_find_child)) + nchildren->extra_children = + g_list_insert_sorted + (nchildren->extra_children, list->data, + (GCompareFunc) notebook_child_compare_func); + else + nchildren->children = + g_list_insert_sorted + (nchildren->children, list->data, + (GCompareFunc) notebook_child_compare_func); + } + else + { + if (g_list_find_custom (nchildren->tabs, + GINT_TO_POINTER (position), + (GCompareFunc) notebook_find_child)) + nchildren->extra_tabs = + g_list_insert_sorted + (nchildren->extra_tabs, list->data, + (GCompareFunc) notebook_child_compare_func); + else + nchildren->tabs = + g_list_insert_sorted + (nchildren->tabs, list->data, + (GCompareFunc) notebook_child_compare_func); + } + } + } + + /* Remove all pages, resulting in the unparenting of all widgets including tab-labels. + */ + while (gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 0) + { + page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 0); + + /* Explicitly remove the tab label first */ + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), page, NULL); + gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), 0); + } + + if (children) + g_list_free (children); + + return nchildren; } static void -glade_gtk_notebook_insert_children (GtkWidget *notebook, NotebookChildren *nchildren) +glade_gtk_notebook_insert_children (GtkWidget * notebook, + NotebookChildren * nchildren) { - gint i; - - /********************************************************* + gint i; + + /********************************************************* INSERT PAGES *********************************************************/ - for (i = 0; i < nchildren->pages; i++) - { - GtkWidget *page = notebook_get_page (nchildren, i); - GtkWidget *tab = notebook_get_tab (nchildren, i); - - gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), page, NULL, i); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), page, tab); - - g_object_unref (G_OBJECT (page)); - g_object_unref (G_OBJECT (tab)); - } - - /* Stay on the same page */ - gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), nchildren->page); - - /* Free the original lists now */ - if (nchildren->children) - g_list_free (nchildren->children); - - if (nchildren->tabs) - g_list_free (nchildren->tabs); - - if (nchildren->children || - nchildren->tabs || - nchildren->extra_children || - nchildren->extra_tabs) - g_critical ("Unbalanced children when inserting notebook children" - " (pages: %d tabs: %d extra pages: %d extra tabs %d)", - g_list_length (nchildren->children), - g_list_length (nchildren->tabs), - g_list_length (nchildren->extra_children), - g_list_length (nchildren->extra_tabs)); - - g_free (nchildren); + for (i = 0; i < nchildren->pages; i++) + { + GtkWidget *page = notebook_get_page (nchildren, i); + GtkWidget *tab = notebook_get_tab (nchildren, i); + + gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), page, NULL, i); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), page, tab); + + g_object_unref (G_OBJECT (page)); + g_object_unref (G_OBJECT (tab)); + } + + /* Stay on the same page */ + gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), nchildren->page); + + /* Free the original lists now */ + if (nchildren->children) + g_list_free (nchildren->children); + + if (nchildren->tabs) + g_list_free (nchildren->tabs); + + if (nchildren->children || + nchildren->tabs || nchildren->extra_children || nchildren->extra_tabs) + g_critical ("Unbalanced children when inserting notebook children" + " (pages: %d tabs: %d extra pages: %d extra tabs %d)", + g_list_length (nchildren->children), + g_list_length (nchildren->tabs), + g_list_length (nchildren->extra_children), + g_list_length (nchildren->extra_tabs)); + + g_free (nchildren); } static void -glade_gtk_notebook_switch_page (GtkNotebook *notebook, - GtkWidget *page, - guint page_num, - gpointer user_data) +glade_gtk_notebook_switch_page (GtkNotebook * notebook, + GtkWidget * page, + guint page_num, gpointer user_data) { - GladeWidget *gnotebook = glade_widget_get_from_gobject (notebook); + GladeWidget *gnotebook = glade_widget_get_from_gobject (notebook); - glade_widget_property_set (gnotebook, "page", page_num); + glade_widget_property_set (gnotebook, "page", page_num); } @@ -3551,1675 +3425,1706 @@ glade_gtk_notebook_switch_page (GtkNotebook *notebook, * the selected widget. */ static void -glade_gtk_notebook_selection_changed (GladeProject *project, - GladeWidget *gwidget) -{ - GladeWidget *selected; - GList *list; - gint i; - GtkWidget *page; - - if ((list = glade_project_selection_get (project)) != NULL && - g_list_length (list) == 1) - { - selected = glade_widget_get_from_gobject (list->data); - - /* Check if selected widget is inside the notebook */ - if (GTK_IS_WIDGET (selected->object) && - gtk_widget_is_ancestor (GTK_WIDGET (selected->object), - GTK_WIDGET (gwidget->object))) - { - /* Find and activate the page */ - for (i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (gwidget->object)); i++) - { - page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (gwidget->object), i); - if (GTK_WIDGET (selected->object) == page || - gtk_widget_is_ancestor (GTK_WIDGET (selected->object), - GTK_WIDGET (page))) - { - glade_widget_property_set (gwidget, "page", i); - return; - } - } - } - } +glade_gtk_notebook_selection_changed (GladeProject * project, + GladeWidget * gwidget) +{ + GladeWidget *selected; + GList *list; + gint i; + GtkWidget *page; + + if ((list = glade_project_selection_get (project)) != NULL && + g_list_length (list) == 1) + { + selected = glade_widget_get_from_gobject (list->data); + + /* Check if selected widget is inside the notebook */ + if (GTK_IS_WIDGET (selected->object) && + gtk_widget_is_ancestor (GTK_WIDGET (selected->object), + GTK_WIDGET (gwidget->object))) + { + /* Find and activate the page */ + for (i = 0; + i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (gwidget->object)); + i++) + { + page = + gtk_notebook_get_nth_page (GTK_NOTEBOOK (gwidget->object), i); + if (GTK_WIDGET (selected->object) == page || + gtk_widget_is_ancestor (GTK_WIDGET (selected->object), + GTK_WIDGET (page))) + { + glade_widget_property_set (gwidget, "page", i); + return; + } + } + } + } } static void -glade_gtk_notebook_project_changed (GladeWidget *gwidget, - GParamSpec *pspec, - gpointer userdata) +glade_gtk_notebook_project_changed (GladeWidget * gwidget, + GParamSpec * pspec, gpointer userdata) { - GladeProject - *project = glade_widget_get_project (gwidget), - *old_project = g_object_get_data (G_OBJECT (gwidget), "notebook-project-ptr"); - - if (old_project) - g_signal_handlers_disconnect_by_func (G_OBJECT (old_project), - G_CALLBACK (glade_gtk_notebook_selection_changed), - gwidget); + GladeProject + * project = glade_widget_get_project (gwidget), + *old_project = + g_object_get_data (G_OBJECT (gwidget), "notebook-project-ptr"); + + if (old_project) + g_signal_handlers_disconnect_by_func (G_OBJECT (old_project), + G_CALLBACK + (glade_gtk_notebook_selection_changed), + gwidget); - if (project) - g_signal_connect (G_OBJECT (project), "selection-changed", - G_CALLBACK (glade_gtk_notebook_selection_changed), gwidget); + if (project) + g_signal_connect (G_OBJECT (project), "selection-changed", + G_CALLBACK (glade_gtk_notebook_selection_changed), + gwidget); - g_object_set_data (G_OBJECT (gwidget), "notebook-project-ptr", project); + g_object_set_data (G_OBJECT (gwidget), "notebook-project-ptr", project); } void -glade_gtk_notebook_post_create (GladeWidgetAdaptor *adaptor, - GObject *notebook, - GladeCreateReason reason) +glade_gtk_notebook_post_create (GladeWidgetAdaptor * adaptor, + GObject * notebook, GladeCreateReason reason) { - GladeWidget *gwidget = glade_widget_get_from_gobject (notebook); + GladeWidget *gwidget = glade_widget_get_from_gobject (notebook); - gtk_notebook_popup_disable (GTK_NOTEBOOK (notebook)); + gtk_notebook_popup_disable (GTK_NOTEBOOK (notebook)); - g_signal_connect (G_OBJECT (gwidget), "notify::project", - G_CALLBACK (glade_gtk_notebook_project_changed), NULL); + g_signal_connect (G_OBJECT (gwidget), "notify::project", + G_CALLBACK (glade_gtk_notebook_project_changed), NULL); - glade_gtk_notebook_project_changed (gwidget, NULL, NULL); + glade_gtk_notebook_project_changed (gwidget, NULL, NULL); - g_signal_connect (G_OBJECT (notebook), "switch-page", - G_CALLBACK (glade_gtk_notebook_switch_page), NULL); + g_signal_connect (G_OBJECT (notebook), "switch-page", + G_CALLBACK (glade_gtk_notebook_switch_page), NULL); } static gint -glade_gtk_notebook_get_first_blank_page (GtkNotebook *notebook) -{ - GladeWidget *gwidget; - GtkWidget *widget; - gint position; - - for (position = 0; position < gtk_notebook_get_n_pages (notebook); position++) - { - widget = gtk_notebook_get_nth_page (notebook, position); - if ((gwidget = glade_widget_get_from_gobject (widget)) != NULL) - { - GladeProperty *property = - glade_widget_get_property (gwidget, "position"); - gint gwidget_position = g_value_get_int (property->value); - - if ((gwidget_position - position) > 0) - return position; - } - } - return position; +glade_gtk_notebook_get_first_blank_page (GtkNotebook * notebook) +{ + GladeWidget *gwidget; + GtkWidget *widget; + gint position; + + for (position = 0; position < gtk_notebook_get_n_pages (notebook); position++) + { + widget = gtk_notebook_get_nth_page (notebook, position); + if ((gwidget = glade_widget_get_from_gobject (widget)) != NULL) + { + GladeProperty *property = + glade_widget_get_property (gwidget, "position"); + gint gwidget_position = g_value_get_int (property->value); + + if ((gwidget_position - position) > 0) + return position; + } + } + return position; } static GladeWidget * -glade_gtk_notebook_generate_tab (GladeWidget *notebook, - gint page_id) +glade_gtk_notebook_generate_tab (GladeWidget * notebook, gint page_id) { - static GladeWidgetAdaptor *wadaptor = NULL; - gchar *str; - GladeWidget *glabel; + static GladeWidgetAdaptor *wadaptor = NULL; + gchar *str; + GladeWidget *glabel; + + if (wadaptor == NULL) + wadaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); - if (wadaptor == NULL) - wadaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); + glabel = glade_widget_adaptor_create_widget (wadaptor, FALSE, + "parent", notebook, + "project", + glade_widget_get_project + (notebook), NULL); - glabel = glade_widget_adaptor_create_widget (wadaptor, FALSE, - "parent", notebook, - "project", glade_widget_get_project (notebook), - NULL); - - str = g_strdup_printf ("page %d", page_id); - glade_widget_property_set (glabel, "label", str); - g_free (str); - - g_object_set_data (glabel->object, "special-child-type", "tab"); - gtk_widget_show (GTK_WIDGET (glabel->object)); + str = g_strdup_printf ("page %d", page_id); + glade_widget_property_set (glabel, "label", str); + g_free (str); - return glabel; + g_object_set_data (glabel->object, "special-child-type", "tab"); + gtk_widget_show (GTK_WIDGET (glabel->object)); + + return glabel; } static void -glade_gtk_notebook_set_n_pages (GObject *object, const GValue *value) -{ - GladeWidget *widget; - GtkNotebook *notebook; - GtkWidget *child_widget, *tab_widget; - gint new_size, i; - gint old_size; - - notebook = GTK_NOTEBOOK (object); - g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); - - widget = glade_widget_get_from_gobject (GTK_WIDGET (notebook)); - g_return_if_fail (widget != NULL); - - new_size = g_value_get_int (value); - old_size = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); - - /* Ensure base size of notebook */ - if (glade_widget_superuser () == FALSE) - { - for (i = gtk_notebook_get_n_pages (notebook); i < new_size; i++) - { - gint position = glade_gtk_notebook_get_first_blank_page (notebook); - GtkWidget *placeholder = glade_placeholder_new (); - GladeWidget *gtab; - - gtk_notebook_insert_page (notebook, placeholder, NULL, position); - - /* XXX Ugly hack amongst many, this one only creates project widgets - * when the 'n-pages' of a notebook is initially set, otherwise it puts - * placeholders. (this makes the job easier when doing "insert before/after") - */ - if (old_size == 0 && new_size > 1) - { - gtab = glade_gtk_notebook_generate_tab (widget, position + 1); - - /* Must pass through GladeWidget api so that packing props - * are correctly assigned. - */ - glade_widget_add_child (widget, gtab, FALSE); - } - else - { - GtkWidget *tab_placeholder = glade_placeholder_new (); - - g_object_set_data (G_OBJECT (tab_placeholder), "special-child-type", "tab"); - - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), placeholder, - tab_placeholder); - } - } - } - - /* - * Thing to remember is that GtkNotebook starts the - * page numbers from 0, not 1 (C-style). So we need to do - * old_size-1, where we're referring to "nth" widget. - */ - while (old_size > new_size) { - /* Get the last page and remove it (project objects have been cleared by - * the action code already). */ - child_widget = gtk_notebook_get_nth_page (notebook, old_size-1); - tab_widget = gtk_notebook_get_tab_label (notebook, child_widget); - - /* Ok there shouldnt be widget in the content area, that's - * the placeholder, we should clean up the project widget that - * we put in the tab here though (this happens in the case where - * we undo increasing the "pages" property). - */ - if (glade_widget_get_from_gobject (child_widget)) - g_critical ("Bug in notebook_set_n_pages()"); - - gtk_notebook_remove_page (notebook, old_size-1); - - old_size--; - } -} - -void -glade_gtk_notebook_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - if (!strcmp (id, "pages")) - glade_gtk_notebook_set_n_pages (object, value); - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, - id, value); +glade_gtk_notebook_set_n_pages (GObject * object, const GValue * value) +{ + GladeWidget *widget; + GtkNotebook *notebook; + GtkWidget *child_widget, *tab_widget; + gint new_size, i; + gint old_size; + + notebook = GTK_NOTEBOOK (object); + g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); + + widget = glade_widget_get_from_gobject (GTK_WIDGET (notebook)); + g_return_if_fail (widget != NULL); + + new_size = g_value_get_int (value); + old_size = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); + + /* Ensure base size of notebook */ + if (glade_widget_superuser () == FALSE) + { + for (i = gtk_notebook_get_n_pages (notebook); i < new_size; i++) + { + gint position = glade_gtk_notebook_get_first_blank_page (notebook); + GtkWidget *placeholder = glade_placeholder_new (); + GladeWidget *gtab; + + gtk_notebook_insert_page (notebook, placeholder, NULL, position); + + /* XXX Ugly hack amongst many, this one only creates project widgets + * when the 'n-pages' of a notebook is initially set, otherwise it puts + * placeholders. (this makes the job easier when doing "insert before/after") + */ + if (old_size == 0 && new_size > 1) + { + gtab = glade_gtk_notebook_generate_tab (widget, position + 1); + + /* Must pass through GladeWidget api so that packing props + * are correctly assigned. + */ + glade_widget_add_child (widget, gtab, FALSE); + } + else + { + GtkWidget *tab_placeholder = glade_placeholder_new (); + + g_object_set_data (G_OBJECT (tab_placeholder), + "special-child-type", "tab"); + + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), placeholder, + tab_placeholder); + } + } + } + + /* + * Thing to remember is that GtkNotebook starts the + * page numbers from 0, not 1 (C-style). So we need to do + * old_size-1, where we're referring to "nth" widget. + */ + while (old_size > new_size) + { + /* Get the last page and remove it (project objects have been cleared by + * the action code already). */ + child_widget = gtk_notebook_get_nth_page (notebook, old_size - 1); + tab_widget = gtk_notebook_get_tab_label (notebook, child_widget); + + /* Ok there shouldnt be widget in the content area, that's + * the placeholder, we should clean up the project widget that + * we put in the tab here though (this happens in the case where + * we undo increasing the "pages" property). + */ + if (glade_widget_get_from_gobject (child_widget)) + g_critical ("Bug in notebook_set_n_pages()"); + + gtk_notebook_remove_page (notebook, old_size - 1); + + old_size--; + } +} + +void +glade_gtk_notebook_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + if (!strcmp (id, "pages")) + glade_gtk_notebook_set_n_pages (object, value); + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, + id, value); } static gboolean -glade_gtk_notebook_verify_n_pages (GObject *object, const GValue *value) -{ - GtkNotebook *notebook = GTK_NOTEBOOK(object); - GtkWidget *child_widget, *tab_widget; - gint old_size, new_size = g_value_get_int (value); - - for (old_size = gtk_notebook_get_n_pages (notebook); - old_size > new_size; old_size--) { - /* Get the last widget. */ - child_widget = gtk_notebook_get_nth_page (notebook, old_size-1); - tab_widget = gtk_notebook_get_tab_label (notebook, child_widget); - - /* - * If we got it, and its not a placeholder, remove it - * from project. - */ - if (glade_widget_get_from_gobject (child_widget) || - glade_widget_get_from_gobject (tab_widget)) - return FALSE; - } - return TRUE; +glade_gtk_notebook_verify_n_pages (GObject * object, const GValue * value) +{ + GtkNotebook *notebook = GTK_NOTEBOOK (object); + GtkWidget *child_widget, *tab_widget; + gint old_size, new_size = g_value_get_int (value); + + for (old_size = gtk_notebook_get_n_pages (notebook); + old_size > new_size; old_size--) + { + /* Get the last widget. */ + child_widget = gtk_notebook_get_nth_page (notebook, old_size - 1); + tab_widget = gtk_notebook_get_tab_label (notebook, child_widget); + + /* + * If we got it, and its not a placeholder, remove it + * from project. + */ + if (glade_widget_get_from_gobject (child_widget) || + glade_widget_get_from_gobject (tab_widget)) + return FALSE; + } + return TRUE; } gboolean -glade_gtk_notebook_verify_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - if (!strcmp (id, "pages")) - return glade_gtk_notebook_verify_n_pages (object, value); - else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, - id, value); - - return TRUE; -} - -void -glade_gtk_notebook_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - GtkNotebook *notebook; - gint num_page, position = 0; - GtkWidget *last_page; - GladeWidget *gwidget; - gchar *special_child_type; - - notebook = GTK_NOTEBOOK (object); - - num_page = gtk_notebook_get_n_pages (notebook); - gwidget = glade_widget_get_from_gobject (object); - - /* Just append pages blindly when loading/dupping - */ - if (glade_widget_superuser ()) - { - special_child_type = g_object_get_data (child, "special-child-type"); - if (special_child_type && - !strcmp (special_child_type, "tab")) - { - last_page = gtk_notebook_get_nth_page (notebook, num_page - 1); - gtk_notebook_set_tab_label (notebook, last_page, - GTK_WIDGET (child)); - } - else - { - gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); - - glade_widget_property_set (gwidget, "pages", num_page + 1); - - gwidget = glade_widget_get_from_gobject (child); - if (gwidget && gwidget->packing_properties) - glade_widget_pack_property_set (gwidget, "position", num_page); - } - } - else - { - NotebookChildren *nchildren; - - /* Just destroy placeholders */ - if (GLADE_IS_PLACEHOLDER (child)) - gtk_widget_destroy (GTK_WIDGET (child)); - else - { - gwidget = glade_widget_get_from_gobject (child); - g_assert (gwidget); - - glade_widget_pack_property_get (gwidget, "position", &position); - - nchildren = glade_gtk_notebook_extract_children (GTK_WIDGET (notebook)); - - if (g_object_get_data (child, "special-child-type") != NULL) - { - if (g_list_find_custom (nchildren->tabs, - GINT_TO_POINTER (position), - (GCompareFunc)notebook_find_child)) - nchildren->extra_tabs = - g_list_insert_sorted - (nchildren->extra_tabs, child, - (GCompareFunc)notebook_child_compare_func); - else - nchildren->tabs = - g_list_insert_sorted - (nchildren->tabs, child, - (GCompareFunc)notebook_child_compare_func); - } - else - { - if (g_list_find_custom (nchildren->children, - GINT_TO_POINTER (position), - (GCompareFunc)notebook_find_child)) - nchildren->extra_children = - g_list_insert_sorted - (nchildren->extra_children, child, - (GCompareFunc)notebook_child_compare_func); - else - nchildren->children = - g_list_insert_sorted - (nchildren->children, child, - (GCompareFunc)notebook_child_compare_func); - } - - /* Takes an explicit reference when sitting on the list */ - g_object_ref (child); - - glade_gtk_notebook_insert_children (GTK_WIDGET (notebook), nchildren); - } - } -} - -void -glade_gtk_notebook_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - NotebookChildren *nchildren; - - nchildren = glade_gtk_notebook_extract_children (GTK_WIDGET (object)); - - if (g_list_find (nchildren->children, child)) - { - nchildren->children = - g_list_remove (nchildren->children, child); - g_object_unref (child); - } - else if (g_list_find (nchildren->extra_children, child)) - { - nchildren->extra_children = - g_list_remove (nchildren->extra_children, child); - g_object_unref (child); - } - else if (g_list_find (nchildren->tabs, child)) - { - nchildren->tabs = - g_list_remove (nchildren->tabs, child); - g_object_unref (child); - } - else if (g_list_find (nchildren->extra_tabs, child)) - { - nchildren->extra_tabs = - g_list_remove (nchildren->extra_tabs, child); - g_object_unref (child); - } - - glade_gtk_notebook_insert_children (GTK_WIDGET (object), nchildren); - -} - -void -glade_gtk_notebook_replace_child (GladeWidgetAdaptor *adaptor, - GtkWidget *container, - GtkWidget *current, - GtkWidget *new_widget) -{ - GtkNotebook *notebook; - GladeWidget *gcurrent, *gnew; - gint position = 0; - - notebook = GTK_NOTEBOOK (container); - - if ((gcurrent = glade_widget_get_from_gobject (current)) != NULL) - glade_widget_pack_property_get (gcurrent, "position", &position); - else - { - if ((position = gtk_notebook_page_num (notebook, current)) < 0) - { - position = notebook_search_tab (notebook, current); - g_assert (position >= 0); - } - } - - if (g_object_get_data (G_OBJECT (current), "special-child-type")) - g_object_set_data (G_OBJECT (new_widget), "special-child-type", "tab"); - - glade_gtk_notebook_remove_child (adaptor, - G_OBJECT (container), - G_OBJECT (current)); - - if (GLADE_IS_PLACEHOLDER (new_widget) == FALSE) - { - gnew = glade_widget_get_from_gobject (new_widget); - - glade_gtk_notebook_add_child (adaptor, - G_OBJECT (container), - G_OBJECT (new_widget)); - - if (glade_widget_pack_property_set (gnew, "position", position) == FALSE) - g_critical ("No position property found on new widget"); - } - else - gtk_widget_destroy (GTK_WIDGET (new_widget)); -} +glade_gtk_notebook_verify_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + if (!strcmp (id, "pages")) + return glade_gtk_notebook_verify_n_pages (object, value); + else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, + id, value); + + return TRUE; +} + +void +glade_gtk_notebook_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + GtkNotebook *notebook; + gint num_page, position = 0; + GtkWidget *last_page; + GladeWidget *gwidget; + gchar *special_child_type; + + notebook = GTK_NOTEBOOK (object); + + num_page = gtk_notebook_get_n_pages (notebook); + gwidget = glade_widget_get_from_gobject (object); + + /* Just append pages blindly when loading/dupping + */ + if (glade_widget_superuser ()) + { + special_child_type = g_object_get_data (child, "special-child-type"); + if (special_child_type && !strcmp (special_child_type, "tab")) + { + last_page = gtk_notebook_get_nth_page (notebook, num_page - 1); + gtk_notebook_set_tab_label (notebook, last_page, GTK_WIDGET (child)); + } + else + { + gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); + + glade_widget_property_set (gwidget, "pages", num_page + 1); + + gwidget = glade_widget_get_from_gobject (child); + if (gwidget && gwidget->packing_properties) + glade_widget_pack_property_set (gwidget, "position", num_page); + } + } + else + { + NotebookChildren *nchildren; + + /* Just destroy placeholders */ + if (GLADE_IS_PLACEHOLDER (child)) + gtk_widget_destroy (GTK_WIDGET (child)); + else + { + gwidget = glade_widget_get_from_gobject (child); + g_assert (gwidget); + + glade_widget_pack_property_get (gwidget, "position", &position); + + nchildren = + glade_gtk_notebook_extract_children (GTK_WIDGET (notebook)); + + if (g_object_get_data (child, "special-child-type") != NULL) + { + if (g_list_find_custom (nchildren->tabs, + GINT_TO_POINTER (position), + (GCompareFunc) notebook_find_child)) + nchildren->extra_tabs = + g_list_insert_sorted + (nchildren->extra_tabs, child, + (GCompareFunc) notebook_child_compare_func); + else + nchildren->tabs = + g_list_insert_sorted + (nchildren->tabs, child, + (GCompareFunc) notebook_child_compare_func); + } + else + { + if (g_list_find_custom (nchildren->children, + GINT_TO_POINTER (position), + (GCompareFunc) notebook_find_child)) + nchildren->extra_children = + g_list_insert_sorted + (nchildren->extra_children, child, + (GCompareFunc) notebook_child_compare_func); + else + nchildren->children = + g_list_insert_sorted + (nchildren->children, child, + (GCompareFunc) notebook_child_compare_func); + } + + /* Takes an explicit reference when sitting on the list */ + g_object_ref (child); + + glade_gtk_notebook_insert_children (GTK_WIDGET (notebook), nchildren); + } + } +} + +void +glade_gtk_notebook_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + NotebookChildren *nchildren; + + nchildren = glade_gtk_notebook_extract_children (GTK_WIDGET (object)); + + if (g_list_find (nchildren->children, child)) + { + nchildren->children = g_list_remove (nchildren->children, child); + g_object_unref (child); + } + else if (g_list_find (nchildren->extra_children, child)) + { + nchildren->extra_children = + g_list_remove (nchildren->extra_children, child); + g_object_unref (child); + } + else if (g_list_find (nchildren->tabs, child)) + { + nchildren->tabs = g_list_remove (nchildren->tabs, child); + g_object_unref (child); + } + else if (g_list_find (nchildren->extra_tabs, child)) + { + nchildren->extra_tabs = g_list_remove (nchildren->extra_tabs, child); + g_object_unref (child); + } + + glade_gtk_notebook_insert_children (GTK_WIDGET (object), nchildren); + +} + +void +glade_gtk_notebook_replace_child (GladeWidgetAdaptor * adaptor, + GtkWidget * container, + GtkWidget * current, GtkWidget * new_widget) +{ + GtkNotebook *notebook; + GladeWidget *gcurrent, *gnew; + gint position = 0; + + notebook = GTK_NOTEBOOK (container); + + if ((gcurrent = glade_widget_get_from_gobject (current)) != NULL) + glade_widget_pack_property_get (gcurrent, "position", &position); + else + { + if ((position = gtk_notebook_page_num (notebook, current)) < 0) + { + position = notebook_search_tab (notebook, current); + g_assert (position >= 0); + } + } + + if (g_object_get_data (G_OBJECT (current), "special-child-type")) + g_object_set_data (G_OBJECT (new_widget), "special-child-type", "tab"); + + glade_gtk_notebook_remove_child (adaptor, + G_OBJECT (container), G_OBJECT (current)); + + if (GLADE_IS_PLACEHOLDER (new_widget) == FALSE) + { + gnew = glade_widget_get_from_gobject (new_widget); + + glade_gtk_notebook_add_child (adaptor, + G_OBJECT (container), + G_OBJECT (new_widget)); + + if (glade_widget_pack_property_set (gnew, "position", position) == FALSE) + g_critical ("No position property found on new widget"); + } + else + gtk_widget_destroy (GTK_WIDGET (new_widget)); +} gboolean -glade_gtk_notebook_child_verify_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *id, - GValue *value) -{ - if (!strcmp (id, "position")) - return g_value_get_int (value) >= 0 && - g_value_get_int (value) < - gtk_notebook_get_n_pages (GTK_NOTEBOOK (container)); - else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_verify_property) - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_verify_property (adaptor, - container, child, - id, value); - - return TRUE; -} - -void -glade_gtk_notebook_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) -{ - NotebookChildren *nchildren; - - if (strcmp (property_name, "position") == 0) - { - /* If we are setting this internally, avoid feedback. */ - if (glade_gtk_notebook_setting_position || - glade_widget_superuser ()) - return; - - /* Just rebuild the notebook, property values are already set at this point */ - nchildren = glade_gtk_notebook_extract_children (GTK_WIDGET (container)); - glade_gtk_notebook_insert_children (GTK_WIDGET (container), nchildren); - } - /* packing properties are unsupported on tabs ... except "position" */ - else if (g_object_get_data (child, "special-child-type") == NULL) - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, child, - property_name, value); -} - -void -glade_gtk_notebook_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - gint position; - - if (strcmp (property_name, "position") == 0) - { - if (g_object_get_data (child, "special-child-type") != NULL) - { - if ((position = notebook_search_tab (GTK_NOTEBOOK (container), - GTK_WIDGET (child))) >= 0) - g_value_set_int (value, position); - else - g_value_set_int (value, 0); - } - else - gtk_container_child_get_property (GTK_CONTAINER (container), - GTK_WIDGET (child), - property_name, - value); - } - /* packing properties are unsupported on tabs ... except "position" */ - else if (g_object_get_data (child, "special-child-type") == NULL) - gtk_container_child_get_property (GTK_CONTAINER (container), - GTK_WIDGET (child), - property_name, - value); +glade_gtk_notebook_child_verify_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * id, GValue * value) +{ + if (!strcmp (id, "position")) + return g_value_get_int (value) >= 0 && + g_value_get_int (value) < + gtk_notebook_get_n_pages (GTK_NOTEBOOK (container)); + else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_verify_property) + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_verify_property (adaptor, + container, child, + id, value); + + return TRUE; +} + +void +glade_gtk_notebook_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + const GValue * value) +{ + NotebookChildren *nchildren; + + if (strcmp (property_name, "position") == 0) + { + /* If we are setting this internally, avoid feedback. */ + if (glade_gtk_notebook_setting_position || glade_widget_superuser ()) + return; + + /* Just rebuild the notebook, property values are already set at this point */ + nchildren = glade_gtk_notebook_extract_children (GTK_WIDGET (container)); + glade_gtk_notebook_insert_children (GTK_WIDGET (container), nchildren); + } + /* packing properties are unsupported on tabs ... except "position" */ + else if (g_object_get_data (child, "special-child-type") == NULL) + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, child, + property_name, value); +} + +void +glade_gtk_notebook_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) +{ + gint position; + + if (strcmp (property_name, "position") == 0) + { + if (g_object_get_data (child, "special-child-type") != NULL) + { + if ((position = notebook_search_tab (GTK_NOTEBOOK (container), + GTK_WIDGET (child))) >= 0) + g_value_set_int (value, position); + else + g_value_set_int (value, 0); + } + else + gtk_container_child_get_property (GTK_CONTAINER (container), + GTK_WIDGET (child), + property_name, value); + } + /* packing properties are unsupported on tabs ... except "position" */ + else if (g_object_get_data (child, "special-child-type") == NULL) + gtk_container_child_get_property (GTK_CONTAINER (container), + GTK_WIDGET (child), property_name, value); } static void -glade_gtk_box_notebook_child_insert_remove_action (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *size_prop, - const gchar *group_format, - gboolean remove, - gboolean after) -{ - GladeWidget *parent; - GList *children, *l; - gint child_pos, size, offset; - - if (GTK_IS_NOTEBOOK (container) && - g_object_get_data (object, "special-child-type")) - /* Its a Tab! */ - child_pos = notebook_search_tab (GTK_NOTEBOOK (container), - GTK_WIDGET (object)); - else - gtk_container_child_get (GTK_CONTAINER (container), - GTK_WIDGET (object), - "position", &child_pos, NULL); - - parent = glade_widget_get_from_gobject (container); - glade_command_push_group (group_format, glade_widget_get_name (parent)); - - /* Make sure widgets does not get destroyed */ - children = glade_widget_adaptor_get_children (adaptor, container); - g_list_foreach (children, (GFunc) g_object_ref, NULL); - - glade_widget_property_get (parent, size_prop, &size); - - if (remove) - { - GList *del = NULL; - offset = -1; - /* Remove children first */ - for (l = children; l; l = g_list_next (l)) - { - GladeWidget *gchild = glade_widget_get_from_gobject (l->data); - gint pos; - - /* Skip placeholders */ - if (gchild == NULL) continue; - - glade_widget_pack_property_get (gchild, "position", &pos); - if (pos == child_pos) del = g_list_prepend (del, gchild); - } - if (del) - { - glade_command_delete (del); - g_list_free (del); - } - } - else - { - /* Expand container */ - glade_command_set_property (glade_widget_get_property (parent, size_prop), - size + 1); - offset = 1; - } - - /* Reoder children (fix the position property tracking widget positions) */ - for (l = g_list_last (children); l; l = g_list_previous (l)) - { - GladeWidget *gchild = glade_widget_get_from_gobject (l->data); - gint pos; - - /* Skip placeholders */ - if (gchild == NULL) continue; - - glade_widget_pack_property_get (gchild, "position", &pos); - if ((after) ? pos > child_pos : pos >= child_pos) - glade_command_set_property (glade_widget_get_pack_property (gchild, "position"), - pos + offset); - } - - if (remove) - { - /* Shrink container */ - glade_command_set_property (glade_widget_get_property (parent, size_prop), - size - 1); - } - /* If it's a notebook we need to create an undoable tab now */ - else if (GTK_IS_NOTEBOOK (container)) - { - gint new_pos = after ? child_pos + 1 : child_pos; - GtkWidget *new_page; - GtkWidget *tab_placeholder; - GladeWidget *gtab; - GList list = { 0, }; - - new_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (container), new_pos); - - /* Deleting the project widget gives us a real placeholder now */ - new_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (container), new_pos); - tab_placeholder = gtk_notebook_get_tab_label (GTK_NOTEBOOK (container), new_page); - gtab = glade_gtk_notebook_generate_tab (parent, new_pos + 1); - list.data = gtab; - - glade_command_paste (&list, parent, GLADE_PLACEHOLDER (tab_placeholder)); - } - - g_list_foreach (children, (GFunc) g_object_unref, NULL); - g_list_free (children); - glade_command_pop_group (); -} - -void -glade_gtk_notebook_child_action_activate (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *action_path) -{ - if (strcmp (action_path, "insert_page_after") == 0) - { - glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, - object, "pages", - _("Insert page on %s"), - FALSE, TRUE); - } - else if (strcmp (action_path, "insert_page_before") == 0) - { - glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, - object, "pages", - _("Insert page on %s"), - FALSE, FALSE); - } - else if (strcmp (action_path, "remove_page") == 0) - { - glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, - object, "pages", - _("Remove page from %s"), - TRUE, TRUE); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor, - container, - object, - action_path); +glade_gtk_box_notebook_child_insert_remove_action (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * object, + const gchar * size_prop, + const gchar * group_format, + gboolean remove, + gboolean after) +{ + GladeWidget *parent; + GList *children, *l; + gint child_pos, size, offset; + + if (GTK_IS_NOTEBOOK (container) && + g_object_get_data (object, "special-child-type")) + /* Its a Tab! */ + child_pos = notebook_search_tab (GTK_NOTEBOOK (container), + GTK_WIDGET (object)); + else + gtk_container_child_get (GTK_CONTAINER (container), + GTK_WIDGET (object), "position", &child_pos, NULL); + + parent = glade_widget_get_from_gobject (container); + glade_command_push_group (group_format, glade_widget_get_name (parent)); + + /* Make sure widgets does not get destroyed */ + children = glade_widget_adaptor_get_children (adaptor, container); + g_list_foreach (children, (GFunc) g_object_ref, NULL); + + glade_widget_property_get (parent, size_prop, &size); + + if (remove) + { + GList *del = NULL; + offset = -1; + /* Remove children first */ + for (l = children; l; l = g_list_next (l)) + { + GladeWidget *gchild = glade_widget_get_from_gobject (l->data); + gint pos; + + /* Skip placeholders */ + if (gchild == NULL) + continue; + + glade_widget_pack_property_get (gchild, "position", &pos); + if (pos == child_pos) + del = g_list_prepend (del, gchild); + } + if (del) + { + glade_command_delete (del); + g_list_free (del); + } + } + else + { + /* Expand container */ + glade_command_set_property (glade_widget_get_property (parent, size_prop), + size + 1); + offset = 1; + } + + /* Reoder children (fix the position property tracking widget positions) */ + for (l = g_list_last (children); l; l = g_list_previous (l)) + { + GladeWidget *gchild = glade_widget_get_from_gobject (l->data); + gint pos; + + /* Skip placeholders */ + if (gchild == NULL) + continue; + + glade_widget_pack_property_get (gchild, "position", &pos); + if ((after) ? pos > child_pos : pos >= child_pos) + glade_command_set_property (glade_widget_get_pack_property + (gchild, "position"), pos + offset); + } + + if (remove) + { + /* Shrink container */ + glade_command_set_property (glade_widget_get_property (parent, size_prop), + size - 1); + } + /* If it's a notebook we need to create an undoable tab now */ + else if (GTK_IS_NOTEBOOK (container)) + { + gint new_pos = after ? child_pos + 1 : child_pos; + GtkWidget *new_page; + GtkWidget *tab_placeholder; + GladeWidget *gtab; + GList list = { 0, }; + + new_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (container), new_pos); + + /* Deleting the project widget gives us a real placeholder now */ + new_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (container), new_pos); + tab_placeholder = + gtk_notebook_get_tab_label (GTK_NOTEBOOK (container), new_page); + gtab = glade_gtk_notebook_generate_tab (parent, new_pos + 1); + list.data = gtab; + + glade_command_paste (&list, parent, GLADE_PLACEHOLDER (tab_placeholder)); + } + + g_list_foreach (children, (GFunc) g_object_unref, NULL); + g_list_free (children); + glade_command_pop_group (); +} + +void +glade_gtk_notebook_child_action_activate (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * object, + const gchar * action_path) +{ + if (strcmp (action_path, "insert_page_after") == 0) + { + glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, + object, "pages", + _("Insert page on %s"), + FALSE, TRUE); + } + else if (strcmp (action_path, "insert_page_before") == 0) + { + glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, + object, "pages", + _("Insert page on %s"), + FALSE, FALSE); + } + else if (strcmp (action_path, "remove_page") == 0) + { + glade_gtk_box_notebook_child_insert_remove_action (adaptor, container, + object, "pages", + _ + ("Remove page from %s"), + TRUE, TRUE); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor, + container, + object, + action_path); } /* ----------------------------- GtkPaned ------------------------------ */ void -glade_gtk_paned_post_create (GladeWidgetAdaptor *adaptor, - GObject *paned, - GladeCreateReason reason) -{ - g_return_if_fail (GTK_IS_PANED (paned)); - - if (reason == GLADE_CREATE_USER && gtk_paned_get_child1 (GTK_PANED (paned)) == NULL) - gtk_paned_add1 (GTK_PANED (paned), glade_placeholder_new ()); - - if (reason == GLADE_CREATE_USER && gtk_paned_get_child2 (GTK_PANED (paned)) == NULL) - gtk_paned_add2 (GTK_PANED (paned), glade_placeholder_new ()); -} - -void -glade_gtk_paned_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - GtkPaned *paned; - GtkWidget *child1, *child2; - gboolean loading; - - g_return_if_fail (GTK_IS_PANED (object)); - - paned = GTK_PANED (object); - loading = glade_util_object_is_loading (object); - - child1 = gtk_paned_get_child1 (paned); - child2 = gtk_paned_get_child2 (paned); - - if (loading == FALSE) - { - /* Remove a placeholder */ - if (child1 && GLADE_IS_PLACEHOLDER (child1)) - { - gtk_container_remove (GTK_CONTAINER (object), child1); - child1 = NULL; - } - else if (child2 && GLADE_IS_PLACEHOLDER (child2)) - { - gtk_container_remove (GTK_CONTAINER (object), child2); - child2 = NULL; - } - } - - /* Add the child */ - if (child1 == NULL) - gtk_paned_add1 (paned, GTK_WIDGET (child)); - else if (child2 == NULL) - gtk_paned_add2 (paned, GTK_WIDGET (child)); - - if (GLADE_IS_PLACEHOLDER (child) == FALSE && loading) - { - GladeWidget *gchild = glade_widget_get_from_gobject (child); - - if (gchild && gchild->packing_properties) - { - if (child1 == NULL) - glade_widget_pack_property_set (gchild, "first", TRUE); - else if (child2 == NULL) - glade_widget_pack_property_set (gchild, "first", FALSE); - } - } -} - -void -glade_gtk_paned_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); - - glade_gtk_paned_post_create (adaptor, object, GLADE_CREATE_USER); -} - -void -glade_gtk_paned_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) -{ - if (strcmp (property_name, "first") == 0) - { - GtkPaned *paned = GTK_PANED (container); - gboolean first = g_value_get_boolean (value); - GtkWidget *place, *wchild = GTK_WIDGET (child); - - place = (first) ? gtk_paned_get_child1 (paned) : - gtk_paned_get_child2 (paned); - - if (place && GLADE_IS_PLACEHOLDER (place)) - gtk_container_remove (GTK_CONTAINER (container), place); - - g_object_ref (child); - gtk_container_remove (GTK_CONTAINER (container), wchild); - if (first) - gtk_paned_add1 (paned, wchild); - else - gtk_paned_add2 (paned, wchild); - g_object_unref (child); - - /* Ensure placeholders */ - if (glade_util_object_is_loading (child) == FALSE) - { - if ((place = gtk_paned_get_child1 (paned)) == NULL) - gtk_paned_add1 (paned, glade_placeholder_new ()); - - if ((place = gtk_paned_get_child2 (paned)) == NULL) - gtk_paned_add2 (paned, glade_placeholder_new ()); - } - } - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, child, - property_name, value); -} - -void -glade_gtk_paned_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - if (strcmp (property_name, "first") == 0) - g_value_set_boolean (value, GTK_WIDGET (child) == - gtk_paned_get_child1 (GTK_PANED (container))); - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_get_property (adaptor, - container, child, - property_name, value); +glade_gtk_paned_post_create (GladeWidgetAdaptor * adaptor, + GObject * paned, GladeCreateReason reason) +{ + g_return_if_fail (GTK_IS_PANED (paned)); + + if (reason == GLADE_CREATE_USER && + gtk_paned_get_child1 (GTK_PANED (paned)) == NULL) + gtk_paned_add1 (GTK_PANED (paned), glade_placeholder_new ()); + + if (reason == GLADE_CREATE_USER && + gtk_paned_get_child2 (GTK_PANED (paned)) == NULL) + gtk_paned_add2 (GTK_PANED (paned), glade_placeholder_new ()); +} + +void +glade_gtk_paned_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + GtkPaned *paned; + GtkWidget *child1, *child2; + gboolean loading; + + g_return_if_fail (GTK_IS_PANED (object)); + + paned = GTK_PANED (object); + loading = glade_util_object_is_loading (object); + + child1 = gtk_paned_get_child1 (paned); + child2 = gtk_paned_get_child2 (paned); + + if (loading == FALSE) + { + /* Remove a placeholder */ + if (child1 && GLADE_IS_PLACEHOLDER (child1)) + { + gtk_container_remove (GTK_CONTAINER (object), child1); + child1 = NULL; + } + else if (child2 && GLADE_IS_PLACEHOLDER (child2)) + { + gtk_container_remove (GTK_CONTAINER (object), child2); + child2 = NULL; + } + } + + /* Add the child */ + if (child1 == NULL) + gtk_paned_add1 (paned, GTK_WIDGET (child)); + else if (child2 == NULL) + gtk_paned_add2 (paned, GTK_WIDGET (child)); + + if (GLADE_IS_PLACEHOLDER (child) == FALSE && loading) + { + GladeWidget *gchild = glade_widget_get_from_gobject (child); + + if (gchild && gchild->packing_properties) + { + if (child1 == NULL) + glade_widget_pack_property_set (gchild, "first", TRUE); + else if (child2 == NULL) + glade_widget_pack_property_set (gchild, "first", FALSE); + } + } +} + +void +glade_gtk_paned_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); + + glade_gtk_paned_post_create (adaptor, object, GLADE_CREATE_USER); +} + +void +glade_gtk_paned_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + const GValue * value) +{ + if (strcmp (property_name, "first") == 0) + { + GtkPaned *paned = GTK_PANED (container); + gboolean first = g_value_get_boolean (value); + GtkWidget *place, *wchild = GTK_WIDGET (child); + + place = (first) ? gtk_paned_get_child1 (paned) : + gtk_paned_get_child2 (paned); + + if (place && GLADE_IS_PLACEHOLDER (place)) + gtk_container_remove (GTK_CONTAINER (container), place); + + g_object_ref (child); + gtk_container_remove (GTK_CONTAINER (container), wchild); + if (first) + gtk_paned_add1 (paned, wchild); + else + gtk_paned_add2 (paned, wchild); + g_object_unref (child); + + /* Ensure placeholders */ + if (glade_util_object_is_loading (child) == FALSE) + { + if ((place = gtk_paned_get_child1 (paned)) == NULL) + gtk_paned_add1 (paned, glade_placeholder_new ()); + + if ((place = gtk_paned_get_child2 (paned)) == NULL) + gtk_paned_add2 (paned, glade_placeholder_new ()); + } + } + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, child, + property_name, value); +} + +void +glade_gtk_paned_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, GValue * value) +{ + if (strcmp (property_name, "first") == 0) + g_value_set_boolean (value, GTK_WIDGET (child) == + gtk_paned_get_child1 (GTK_PANED (container))); + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_get_property (adaptor, + container, child, + property_name, value); } /* ----------------------------- GtkExpander ------------------------------ */ void -glade_gtk_expander_post_create (GladeWidgetAdaptor *adaptor, - GObject *expander, - GladeCreateReason reason) -{ - static GladeWidgetAdaptor *wadaptor = NULL; - GladeWidget *gexpander, *glabel; - GtkWidget *label; - - if (wadaptor == NULL) - wadaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); - - if (reason != GLADE_CREATE_USER) return; - - g_return_if_fail (GTK_IS_EXPANDER (expander)); - gexpander = glade_widget_get_from_gobject (expander); - g_return_if_fail (GLADE_IS_WIDGET (gexpander)); - - /* If we didnt put this object here... */ - if ((label = gtk_expander_get_label_widget (GTK_EXPANDER (expander))) == NULL || - (glade_widget_get_from_gobject (label) == NULL)) - { - glabel = glade_widget_adaptor_create_widget (wadaptor, FALSE, - "parent", gexpander, - "project", glade_widget_get_project (gexpander), - NULL); - - glade_widget_property_set (glabel, "label", "expander"); - - g_object_set_data (glabel->object, "special-child-type", "label_item"); - glade_widget_add_child (gexpander, glabel, FALSE); - } - - gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE); - - gtk_container_add (GTK_CONTAINER (expander), glade_placeholder_new ()); - -} - -void -glade_gtk_expander_replace_child (GladeWidgetAdaptor *adaptor, - GtkWidget *container, - GtkWidget *current, - GtkWidget *new_widget) -{ - gchar *special_child_type; - - special_child_type = - g_object_get_data (G_OBJECT (current), "special-child-type"); - - if (special_child_type && !strcmp (special_child_type, "label_item")) - { - g_object_set_data (G_OBJECT (new_widget), "special-child-type", "label_item"); - gtk_expander_set_label_widget (GTK_EXPANDER (container), new_widget); - return; - } - - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->replace_child (adaptor, - G_OBJECT (container), - G_OBJECT (current), - G_OBJECT (new_widget)); -} - - -void -glade_gtk_expander_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - gchar *special_child_type; - - special_child_type = g_object_get_data (child, "special-child-type"); - - if (special_child_type && - !strcmp (special_child_type, "label")) - { - g_object_set_data (child, - "special-child-type", - "label_item"); - gtk_expander_set_label_widget (GTK_EXPANDER (object), - GTK_WIDGET (child)); - } - else if (special_child_type && - !strcmp (special_child_type, "label_item")) - { - gtk_expander_set_label_widget (GTK_EXPANDER (object), - GTK_WIDGET (child)); - } - else - /* Chain Up */ - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->add (adaptor, object, child); -} - -void -glade_gtk_expander_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) -{ - gchar *special_child_type; - - special_child_type = g_object_get_data (child, "special-child-type"); - if (special_child_type && - !strcmp (special_child_type, "label_item")) - { - gtk_expander_set_label_widget (GTK_EXPANDER (object), - glade_placeholder_new ()); - } - else - { - gtk_container_remove (GTK_CONTAINER (object), - GTK_WIDGET (child)); - gtk_container_add (GTK_CONTAINER (object), - glade_placeholder_new ()); - } -} +glade_gtk_expander_post_create (GladeWidgetAdaptor * adaptor, + GObject * expander, GladeCreateReason reason) +{ + static GladeWidgetAdaptor *wadaptor = NULL; + GladeWidget *gexpander, *glabel; + GtkWidget *label; + + if (wadaptor == NULL) + wadaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); + + if (reason != GLADE_CREATE_USER) + return; + + g_return_if_fail (GTK_IS_EXPANDER (expander)); + gexpander = glade_widget_get_from_gobject (expander); + g_return_if_fail (GLADE_IS_WIDGET (gexpander)); + + /* If we didnt put this object here... */ + if ((label = gtk_expander_get_label_widget (GTK_EXPANDER (expander))) == NULL + || (glade_widget_get_from_gobject (label) == NULL)) + { + glabel = glade_widget_adaptor_create_widget (wadaptor, FALSE, + "parent", gexpander, + "project", + glade_widget_get_project + (gexpander), NULL); + + glade_widget_property_set (glabel, "label", "expander"); + + g_object_set_data (glabel->object, "special-child-type", "label_item"); + glade_widget_add_child (gexpander, glabel, FALSE); + } + + gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE); + + gtk_container_add (GTK_CONTAINER (expander), glade_placeholder_new ()); + +} void -glade_gtk_expander_write_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_expander_replace_child (GladeWidgetAdaptor * adaptor, + GtkWidget * container, + GtkWidget * current, GtkWidget * new_widget) { + gchar *special_child_type; + + special_child_type = + g_object_get_data (G_OBJECT (current), "special-child-type"); + + if (special_child_type && !strcmp (special_child_type, "label_item")) + { + g_object_set_data (G_OBJECT (new_widget), "special-child-type", + "label_item"); + gtk_expander_set_label_widget (GTK_EXPANDER (container), new_widget); + return; + } - if (!write_special_child_label_item (adaptor, widget, context, node, - GWA_GET_CLASS(GTK_TYPE_CONTAINER)->write_child)) - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->write_child (adaptor, - widget, - context, - node); + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->replace_child (adaptor, + G_OBJECT (container), + G_OBJECT (current), + G_OBJECT (new_widget)); +} + + +void +glade_gtk_expander_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + gchar *special_child_type; + + special_child_type = g_object_get_data (child, "special-child-type"); + + if (special_child_type && !strcmp (special_child_type, "label")) + { + g_object_set_data (child, "special-child-type", "label_item"); + gtk_expander_set_label_widget (GTK_EXPANDER (object), GTK_WIDGET (child)); + } + else if (special_child_type && !strcmp (special_child_type, "label_item")) + { + gtk_expander_set_label_widget (GTK_EXPANDER (object), GTK_WIDGET (child)); + } + else + /* Chain Up */ + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->add (adaptor, object, child); +} + +void +glade_gtk_expander_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + gchar *special_child_type; + + special_child_type = g_object_get_data (child, "special-child-type"); + if (special_child_type && !strcmp (special_child_type, "label_item")) + { + gtk_expander_set_label_widget (GTK_EXPANDER (object), + glade_placeholder_new ()); + } + else + { + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); + gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ()); + } +} + +void +glade_gtk_expander_write_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) +{ + + if (!write_special_child_label_item (adaptor, widget, context, node, + GWA_GET_CLASS (GTK_TYPE_CONTAINER)-> + write_child)) + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, node); } /* -------------------------------- GtkEntry -------------------------------- */ gboolean -glade_gtk_entry_depends (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeWidget *another) +glade_gtk_entry_depends (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeWidget * another) { - if (GTK_IS_ENTRY_BUFFER (another->object)) - return TRUE; + if (GTK_IS_ENTRY_BUFFER (another->object)) + return TRUE; - return GWA_GET_CLASS (GTK_TYPE_WIDGET)->depends (adaptor, widget, another); + return GWA_GET_CLASS (GTK_TYPE_WIDGET)->depends (adaptor, widget, another); } static void -glade_gtk_entry_changed (GtkEditable *editable, GladeWidget *gentry) +glade_gtk_entry_changed (GtkEditable * editable, GladeWidget * gentry) { - const gchar *text, *text_prop; - GladeProperty *prop; - gboolean use_buffer; + const gchar *text, *text_prop; + GladeProperty *prop; + gboolean use_buffer; + + if (glade_widget_superuser ()) + return; - if (glade_widget_superuser ()) - return; + text = gtk_entry_get_text (GTK_ENTRY (editable)); - text = gtk_entry_get_text (GTK_ENTRY (editable)); - - glade_widget_property_get (gentry, "text", &text_prop); - glade_widget_property_get (gentry, "use-entry-buffer", &use_buffer); - - if (use_buffer == FALSE && g_strcmp0 (text, text_prop)) - { - if ((prop = glade_widget_get_property (gentry, "text"))) - glade_command_set_property (prop, text); - } + glade_widget_property_get (gentry, "text", &text_prop); + glade_widget_property_get (gentry, "use-entry-buffer", &use_buffer); + + if (use_buffer == FALSE && g_strcmp0 (text, text_prop)) + { + if ((prop = glade_widget_get_property (gentry, "text"))) + glade_command_set_property (prop, text); + } } void -glade_gtk_entry_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_entry_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *gentry; - - g_return_if_fail (GTK_IS_ENTRY (object)); - gentry = glade_widget_get_from_gobject (object); - g_return_if_fail (GLADE_IS_WIDGET (gentry)); - - g_signal_connect (object, "changed", - G_CALLBACK (glade_gtk_entry_changed), gentry); + GladeWidget *gentry; + + g_return_if_fail (GTK_IS_ENTRY (object)); + gentry = glade_widget_get_from_gobject (object); + g_return_if_fail (GLADE_IS_WIDGET (gentry)); + + g_signal_connect (object, "changed", + G_CALLBACK (glade_gtk_entry_changed), gentry); } GladeEditable * -glade_gtk_entry_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) -{ - GladeEditable *editable; - - /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_WIDGET)->create_editable (adaptor, type); - - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_entry_editor_new (adaptor, editable); - - return editable; -} - - -void -glade_gtk_entry_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - GladeImageEditMode mode; - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - GladeProperty *property = glade_widget_get_property (gwidget, id); - - if (!strcmp (id, "use-entry-buffer")) - { - glade_widget_property_set_sensitive (gwidget, "text", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "buffer", FALSE, NOT_SELECTED_MSG); - - if (g_value_get_boolean (value)) - glade_widget_property_set_sensitive (gwidget, "buffer", TRUE, NULL); - else - glade_widget_property_set_sensitive (gwidget, "text", TRUE, NULL); - } - else if (!strcmp (id, "primary-icon-mode")) - { - mode = g_value_get_int (value); - - glade_widget_property_set_sensitive (gwidget, "primary-icon-stock", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "primary-icon-name", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "primary-icon-pixbuf", FALSE, NOT_SELECTED_MSG); - - switch (mode) { - case GLADE_IMAGE_MODE_STOCK: - glade_widget_property_set_sensitive (gwidget, "primary-icon-stock", TRUE, NULL); - break; - case GLADE_IMAGE_MODE_ICON: - glade_widget_property_set_sensitive (gwidget, "primary-icon-name", TRUE, NULL); - break; - case GLADE_IMAGE_MODE_FILENAME: - glade_widget_property_set_sensitive (gwidget, "primary-icon-pixbuf", TRUE, NULL); - break; - } - } - else if (!strcmp (id, "secondary-icon-mode")) - { - mode = g_value_get_int (value); - - glade_widget_property_set_sensitive (gwidget, "secondary-icon-stock", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "secondary-icon-name", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "secondary-icon-pixbuf", FALSE, NOT_SELECTED_MSG); - - switch (mode) { - case GLADE_IMAGE_MODE_STOCK: - glade_widget_property_set_sensitive (gwidget, "secondary-icon-stock", TRUE, NULL); - break; - case GLADE_IMAGE_MODE_ICON: - glade_widget_property_set_sensitive (gwidget, "secondary-icon-name", TRUE, NULL); - break; - case GLADE_IMAGE_MODE_FILENAME: - glade_widget_property_set_sensitive (gwidget, "secondary-icon-pixbuf", TRUE, NULL); - break; - } - } - else if (!strcmp (id, "primary-icon-tooltip-text") || - !strcmp (id, "primary-icon-tooltip-markup")) - { - /* Avoid a silly crash in GTK+ */ - if (gtk_entry_get_icon_storage_type (GTK_ENTRY (object), - GTK_ENTRY_ICON_PRIMARY) != GTK_IMAGE_EMPTY) - GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); - } - else if (!strcmp (id, "secondary-icon-tooltip-text") || - !strcmp (id, "secondary-icon-tooltip-markup")) - { - /* Avoid a silly crash in GTK+ */ - if (gtk_entry_get_icon_storage_type (GTK_ENTRY (object), - GTK_ENTRY_ICON_SECONDARY) != GTK_IMAGE_EMPTY) - GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); - } - else if (!strcmp (id, "text")) - { - g_signal_handlers_block_by_func (object, glade_gtk_entry_changed, gwidget); - - if (g_value_get_string (value)) - gtk_entry_set_text (GTK_ENTRY (object), g_value_get_string (value)); - else - gtk_entry_set_text (GTK_ENTRY (object), ""); - - g_signal_handlers_unblock_by_func (object, glade_gtk_entry_changed, gwidget); - - } - else if (GPC_VERSION_CHECK (property->klass, gtk_major_version, gtk_minor_version + 1)) - GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); -} - -void -glade_gtk_entry_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - GladeProperty *property; - - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); - - if (glade_widget_property_original_default (widget, "text") == FALSE) - { - property = glade_widget_get_property (widget, "text"); - glade_widget_property_set (widget, "use-entry-buffer", FALSE); - - glade_property_sync (property); - } - else - { - gint target_minor, target_major; - - glade_project_get_target_version (widget->project, "gtk+", &target_major, &target_minor); - - property = glade_widget_get_property (widget, "buffer"); - - /* Only default to the buffer setting if the project version supports it. */ - if (GPC_VERSION_CHECK (property->klass, target_major, target_minor)) - { - glade_widget_property_set (widget, "use-entry-buffer", TRUE); - glade_property_sync (property); - } - else - glade_widget_property_set (widget, "use-entry-buffer", FALSE); - } - - if (glade_widget_property_original_default (widget, "primary-icon-name") == FALSE) - { - property = glade_widget_get_property (widget, "primary-icon-name"); - glade_widget_property_set (widget, "primary-icon-mode", GLADE_IMAGE_MODE_ICON); - } - else if (glade_widget_property_original_default (widget, "primary-icon-pixbuf") == FALSE) - { - property = glade_widget_get_property (widget, "primary-icon-pixbuf"); - glade_widget_property_set (widget, "primary-icon-mode", GLADE_IMAGE_MODE_FILENAME); - } - else/* if (glade_widget_property_original_default (widget, "stock") == FALSE) */ - { - property = glade_widget_get_property (widget, "primary-icon-stock"); - glade_widget_property_set (widget, "primary-icon-mode", GLADE_IMAGE_MODE_STOCK); - } - - glade_property_sync (property); - - if (glade_widget_property_original_default (widget, "secondary-icon-name") == FALSE) - { - property = glade_widget_get_property (widget, "secondary-icon-name"); - glade_widget_property_set (widget, "secondary-icon-mode", GLADE_IMAGE_MODE_ICON); - } - else if (glade_widget_property_original_default (widget, "secondary-icon-pixbuf") == FALSE) - { - property = glade_widget_get_property (widget, "secondary-icon-pixbuf"); - glade_widget_property_set (widget, "secondary-icon-mode", GLADE_IMAGE_MODE_FILENAME); - } - else/* if (glade_widget_property_original_default (widget, "stock") == FALSE) */ - { - property = glade_widget_get_property (widget, "secondary-icon-stock"); - glade_widget_property_set (widget, "secondary-icon-mode", GLADE_IMAGE_MODE_STOCK); - } - - glade_property_sync (property); +glade_gtk_entry_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) +{ + GladeEditable *editable; + + /* Get base editable */ + editable = GWA_GET_CLASS (GTK_TYPE_WIDGET)->create_editable (adaptor, type); + + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_entry_editor_new (adaptor, editable); + + return editable; +} + + +void +glade_gtk_entry_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + GladeImageEditMode mode; + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GladeProperty *property = glade_widget_get_property (gwidget, id); + + if (!strcmp (id, "use-entry-buffer")) + { + glade_widget_property_set_sensitive (gwidget, "text", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "buffer", FALSE, + NOT_SELECTED_MSG); + + if (g_value_get_boolean (value)) + glade_widget_property_set_sensitive (gwidget, "buffer", TRUE, NULL); + else + glade_widget_property_set_sensitive (gwidget, "text", TRUE, NULL); + } + else if (!strcmp (id, "primary-icon-mode")) + { + mode = g_value_get_int (value); + + glade_widget_property_set_sensitive (gwidget, "primary-icon-stock", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "primary-icon-name", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "primary-icon-pixbuf", + FALSE, NOT_SELECTED_MSG); + + switch (mode) + { + case GLADE_IMAGE_MODE_STOCK: + glade_widget_property_set_sensitive (gwidget, "primary-icon-stock", + TRUE, NULL); + break; + case GLADE_IMAGE_MODE_ICON: + glade_widget_property_set_sensitive (gwidget, "primary-icon-name", + TRUE, NULL); + break; + case GLADE_IMAGE_MODE_FILENAME: + glade_widget_property_set_sensitive (gwidget, "primary-icon-pixbuf", + TRUE, NULL); + break; + } + } + else if (!strcmp (id, "secondary-icon-mode")) + { + mode = g_value_get_int (value); + + glade_widget_property_set_sensitive (gwidget, "secondary-icon-stock", + FALSE, NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "secondary-icon-name", + FALSE, NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "secondary-icon-pixbuf", + FALSE, NOT_SELECTED_MSG); + + switch (mode) + { + case GLADE_IMAGE_MODE_STOCK: + glade_widget_property_set_sensitive (gwidget, + "secondary-icon-stock", TRUE, + NULL); + break; + case GLADE_IMAGE_MODE_ICON: + glade_widget_property_set_sensitive (gwidget, "secondary-icon-name", + TRUE, NULL); + break; + case GLADE_IMAGE_MODE_FILENAME: + glade_widget_property_set_sensitive (gwidget, + "secondary-icon-pixbuf", TRUE, + NULL); + break; + } + } + else if (!strcmp (id, "primary-icon-tooltip-text") || + !strcmp (id, "primary-icon-tooltip-markup")) + { + /* Avoid a silly crash in GTK+ */ + if (gtk_entry_get_icon_storage_type (GTK_ENTRY (object), + GTK_ENTRY_ICON_PRIMARY) != + GTK_IMAGE_EMPTY) + GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, + value); + } + else if (!strcmp (id, "secondary-icon-tooltip-text") || + !strcmp (id, "secondary-icon-tooltip-markup")) + { + /* Avoid a silly crash in GTK+ */ + if (gtk_entry_get_icon_storage_type (GTK_ENTRY (object), + GTK_ENTRY_ICON_SECONDARY) != + GTK_IMAGE_EMPTY) + GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, + value); + } + else if (!strcmp (id, "text")) + { + g_signal_handlers_block_by_func (object, glade_gtk_entry_changed, + gwidget); + + if (g_value_get_string (value)) + gtk_entry_set_text (GTK_ENTRY (object), g_value_get_string (value)); + else + gtk_entry_set_text (GTK_ENTRY (object), ""); + + g_signal_handlers_unblock_by_func (object, glade_gtk_entry_changed, + gwidget); + + } + else if (GPC_VERSION_CHECK + (property->klass, gtk_major_version, gtk_minor_version + 1)) + GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); +} + +void +glade_gtk_entry_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + GladeProperty *property; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); + + if (glade_widget_property_original_default (widget, "text") == FALSE) + { + property = glade_widget_get_property (widget, "text"); + glade_widget_property_set (widget, "use-entry-buffer", FALSE); + + glade_property_sync (property); + } + else + { + gint target_minor, target_major; + + glade_project_get_target_version (widget->project, "gtk+", &target_major, + &target_minor); + + property = glade_widget_get_property (widget, "buffer"); + + /* Only default to the buffer setting if the project version supports it. */ + if (GPC_VERSION_CHECK (property->klass, target_major, target_minor)) + { + glade_widget_property_set (widget, "use-entry-buffer", TRUE); + glade_property_sync (property); + } + else + glade_widget_property_set (widget, "use-entry-buffer", FALSE); + } + + if (glade_widget_property_original_default (widget, "primary-icon-name") == + FALSE) + { + property = glade_widget_get_property (widget, "primary-icon-name"); + glade_widget_property_set (widget, "primary-icon-mode", + GLADE_IMAGE_MODE_ICON); + } + else if (glade_widget_property_original_default + (widget, "primary-icon-pixbuf") == FALSE) + { + property = glade_widget_get_property (widget, "primary-icon-pixbuf"); + glade_widget_property_set (widget, "primary-icon-mode", + GLADE_IMAGE_MODE_FILENAME); + } + else /* if (glade_widget_property_original_default (widget, "stock") == FALSE) */ + { + property = glade_widget_get_property (widget, "primary-icon-stock"); + glade_widget_property_set (widget, "primary-icon-mode", + GLADE_IMAGE_MODE_STOCK); + } + + glade_property_sync (property); + + if (glade_widget_property_original_default (widget, "secondary-icon-name") == + FALSE) + { + property = glade_widget_get_property (widget, "secondary-icon-name"); + glade_widget_property_set (widget, "secondary-icon-mode", + GLADE_IMAGE_MODE_ICON); + } + else if (glade_widget_property_original_default + (widget, "secondary-icon-pixbuf") == FALSE) + { + property = glade_widget_get_property (widget, "secondary-icon-pixbuf"); + glade_widget_property_set (widget, "secondary-icon-mode", + GLADE_IMAGE_MODE_FILENAME); + } + else /* if (glade_widget_property_original_default (widget, "stock") == FALSE) */ + { + property = glade_widget_get_property (widget, "secondary-icon-stock"); + glade_widget_property_set (widget, "secondary-icon-mode", + GLADE_IMAGE_MODE_STOCK); + } + + glade_property_sync (property); } /* ----------------------------- GtkFixed/GtkLayout ------------------------------ */ #if 0 static void -glade_gtk_fixed_layout_finalize(GdkPixmap *backing) +glade_gtk_fixed_layout_finalize (GdkPixmap * backing) { - g_object_unref(backing); + g_object_unref (backing); } #endif static void -glade_gtk_fixed_layout_realize (GtkWidget *widget) +glade_gtk_fixed_layout_realize (GtkWidget * widget) { #if _FIXME_FIXME_CAIRO_ - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (fixed_bg_xpm); - GdkPixmap *backing; - - gdk_pixbuf_render_pixmap_and_mask (pixbuf, &backing, NULL, 1); - - if (GTK_IS_LAYOUT (widget)) - gdk_window_set_back_pixmap (gtk_layout_get_bin_window (GTK_LAYOUT (widget)), - backing, FALSE); - else - gdk_window_set_back_pixmap (gtk_widget_get_window (widget), backing, FALSE); - - /* For cleanup later - */ - g_object_weak_ref(G_OBJECT(widget), - (GWeakNotify)glade_gtk_fixed_layout_finalize, backing); + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (fixed_bg_xpm); + GdkPixmap *backing; + + gdk_pixbuf_render_pixmap_and_mask (pixbuf, &backing, NULL, 1); + + if (GTK_IS_LAYOUT (widget)) + gdk_window_set_back_pixmap (gtk_layout_get_bin_window (GTK_LAYOUT (widget)), + backing, FALSE); + else + gdk_window_set_back_pixmap (gtk_widget_get_window (widget), backing, FALSE); + + /* For cleanup later + */ + g_object_weak_ref (G_OBJECT (widget), + (GWeakNotify) glade_gtk_fixed_layout_finalize, backing); #endif } static void -glade_gtk_fixed_layout_sync_size_requests (GtkWidget *widget) +glade_gtk_fixed_layout_sync_size_requests (GtkWidget * widget) { - GList *children, *l; + GList *children, *l; + + if ((children = gtk_container_get_children (GTK_CONTAINER (widget))) != NULL) + { + for (l = children; l; l = l->next) + { + GtkWidget *child = l->data; + GladeWidget *gchild = glade_widget_get_from_gobject (child); + gint width = -1, height = -1; - if ((children = gtk_container_get_children (GTK_CONTAINER (widget))) != NULL) - { - for (l = children; l; l = l->next) - { - GtkWidget *child = l->data; - GladeWidget *gchild = glade_widget_get_from_gobject (child); - gint width = -1, height = -1; + if (!gchild) + continue; - if (!gchild) - continue; + glade_widget_property_get (gchild, "width-request", &width); + glade_widget_property_get (gchild, "height-request", &height); - glade_widget_property_get (gchild, "width-request", &width); - glade_widget_property_get (gchild, "height-request", &height); - - gtk_widget_set_size_request (child, width, height); - - } - g_list_free (children); - } + gtk_widget_set_size_request (child, width, height); + + } + g_list_free (children); + } } void -glade_gtk_fixed_layout_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_fixed_layout_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - /* This is needed at least to set a backing pixmap. */ - gtk_widget_set_has_window (GTK_WIDGET (object), FALSE); + /* This is needed at least to set a backing pixmap. */ + gtk_widget_set_has_window (GTK_WIDGET (object), FALSE); - /* For backing pixmap - */ - g_signal_connect_after(object, "realize", - G_CALLBACK(glade_gtk_fixed_layout_realize), NULL); + /* For backing pixmap + */ + g_signal_connect_after (object, "realize", + G_CALLBACK (glade_gtk_fixed_layout_realize), NULL); - /* Sync up size request at project load time */ - if (reason == GLADE_CREATE_LOAD) - g_signal_connect_after(object, "realize", - G_CALLBACK(glade_gtk_fixed_layout_sync_size_requests), NULL); + /* Sync up size request at project load time */ + if (reason == GLADE_CREATE_LOAD) + g_signal_connect_after (object, "realize", + G_CALLBACK + (glade_gtk_fixed_layout_sync_size_requests), NULL); } void -glade_gtk_fixed_layout_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_fixed_layout_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_CONTAINER (object)); - g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (GTK_IS_CONTAINER (object)); + g_return_if_fail (GTK_IS_WIDGET (child)); - gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); + gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); } void -glade_gtk_fixed_layout_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_fixed_layout_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_CONTAINER (object)); - g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (GTK_IS_CONTAINER (object)); + g_return_if_fail (GTK_IS_WIDGET (child)); - gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); } /* ----------------------------- GtkWindow ------------------------------ */ static void -glade_gtk_window_read_accel_groups (GladeWidget *widget, - GladeXmlNode *node) -{ - GladeXmlNode *groups_node; - GladeProperty *property; - gchar *string = NULL; - - if ((groups_node = - glade_xml_search_child (node, GLADE_TAG_ACCEL_GROUPS)) != NULL) - { - GladeXmlNode *node; - - for (node = glade_xml_node_get_children (groups_node); - node; node = glade_xml_node_next (node)) - { - gchar *group_name, *tmp; - - if (!glade_xml_node_verify (node, GLADE_TAG_ACCEL_GROUP)) - continue; - - group_name = glade_xml_get_property_string_required - (node, GLADE_TAG_NAME, NULL); - - if (string == NULL) - string = group_name; - else if (group_name != NULL) - { - tmp = g_strdup_printf ("%s%s%s", string, GPC_OBJECT_DELIMITER, group_name); - string = (g_free (string), tmp); - g_free (group_name); - } - } - } - - if (string) - { - property = glade_widget_get_property (widget, "accel-groups"); - g_assert (property); - - /* we must synchronize this directly after loading this project - * (i.e. lookup the actual objects after they've been parsed and - * are present). - */ - g_object_set_data_full (G_OBJECT (property), - "glade-loaded-object", - string, g_free); - } -} - -void -glade_gtk_window_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); - - glade_gtk_window_read_accel_groups (widget, node); -} +glade_gtk_window_read_accel_groups (GladeWidget * widget, GladeXmlNode * node) +{ + GladeXmlNode *groups_node; + GladeProperty *property; + gchar *string = NULL; + + if ((groups_node = + glade_xml_search_child (node, GLADE_TAG_ACCEL_GROUPS)) != NULL) + { + GladeXmlNode *node; + + for (node = glade_xml_node_get_children (groups_node); + node; node = glade_xml_node_next (node)) + { + gchar *group_name, *tmp; + + if (!glade_xml_node_verify (node, GLADE_TAG_ACCEL_GROUP)) + continue; + + group_name = glade_xml_get_property_string_required + (node, GLADE_TAG_NAME, NULL); + + if (string == NULL) + string = group_name; + else if (group_name != NULL) + { + tmp = + g_strdup_printf ("%s%s%s", string, GPC_OBJECT_DELIMITER, + group_name); + string = (g_free (string), tmp); + g_free (group_name); + } + } + } + if (string) + { + property = glade_widget_get_property (widget, "accel-groups"); + g_assert (property); -static void -glade_gtk_window_write_accel_groups (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) + /* we must synchronize this directly after loading this project + * (i.e. lookup the actual objects after they've been parsed and + * are present). + */ + g_object_set_data_full (G_OBJECT (property), + "glade-loaded-object", string, g_free); + } +} + +void +glade_gtk_window_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - GladeXmlNode *groups_node, *group_node; - GList *groups = NULL, *list; - GladeWidget *agroup; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); + + glade_gtk_window_read_accel_groups (widget, node); +} - groups_node = glade_xml_node_new (context, GLADE_TAG_ACCEL_GROUPS); - if (glade_widget_property_get (widget, "accel-groups", &groups)) - { - for (list = groups; list; list = list->next) - { - agroup = glade_widget_get_from_gobject (list->data); - group_node = glade_xml_node_new (context, GLADE_TAG_ACCEL_GROUP); - glade_xml_node_append_child (groups_node, group_node); - glade_xml_node_set_property_string (group_node, GLADE_TAG_NAME, agroup->name); - } - } +static void +glade_gtk_window_write_accel_groups (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) +{ + GladeXmlNode *groups_node, *group_node; + GList *groups = NULL, *list; + GladeWidget *agroup; + + groups_node = glade_xml_node_new (context, GLADE_TAG_ACCEL_GROUPS); + + if (glade_widget_property_get (widget, "accel-groups", &groups)) + { + for (list = groups; list; list = list->next) + { + agroup = glade_widget_get_from_gobject (list->data); + group_node = glade_xml_node_new (context, GLADE_TAG_ACCEL_GROUP); + glade_xml_node_append_child (groups_node, group_node); + glade_xml_node_set_property_string (group_node, GLADE_TAG_NAME, + agroup->name); + } + } + + if (!glade_xml_node_get_children (groups_node)) + glade_xml_node_delete (groups_node); + else + glade_xml_node_append_child (node, groups_node); - if (!glade_xml_node_get_children (groups_node)) - glade_xml_node_delete (groups_node); - else - glade_xml_node_append_child (node, groups_node); - } void -glade_gtk_window_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_window_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) { - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_WIDGET)->write_widget (adaptor, widget, context, node); + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_WIDGET)->write_widget (adaptor, widget, context, + node); - glade_gtk_window_write_accel_groups (widget, context, node); + glade_gtk_window_write_accel_groups (widget, context, node); } /* ----------------------------- GtkDialog(s) ------------------------------ */ static void -glade_gtk_dialog_stop_offending_signals (GtkWidget *widget) -{ - static gpointer hierarchy = NULL, screen; - - if (hierarchy == NULL) - { - hierarchy = GUINT_TO_POINTER (g_signal_lookup ("hierarchy-changed", - GTK_TYPE_WIDGET)); - screen = GUINT_TO_POINTER (g_signal_lookup ("screen-changed", - GTK_TYPE_WIDGET)); - } - - g_signal_connect (widget, "hierarchy-changed", - G_CALLBACK (glade_gtk_stop_emission_POINTER), - hierarchy); - g_signal_connect (widget, "screen-changed", - G_CALLBACK (glade_gtk_stop_emission_POINTER), - screen); +glade_gtk_dialog_stop_offending_signals (GtkWidget * widget) +{ + static gpointer hierarchy = NULL, screen; + + if (hierarchy == NULL) + { + hierarchy = GUINT_TO_POINTER (g_signal_lookup ("hierarchy-changed", + GTK_TYPE_WIDGET)); + screen = GUINT_TO_POINTER (g_signal_lookup ("screen-changed", + GTK_TYPE_WIDGET)); + } + + g_signal_connect (widget, "hierarchy-changed", + G_CALLBACK (glade_gtk_stop_emission_POINTER), hierarchy); + g_signal_connect (widget, "screen-changed", + G_CALLBACK (glade_gtk_stop_emission_POINTER), screen); } static void -glade_gtk_file_chooser_default_forall (GtkWidget *widget, gpointer data) -{ - /* Since GtkFileChooserDefault is not exposed we check if its a - * GtkFileChooser - */ - if (GTK_IS_FILE_CHOOSER (widget)) - { - - /* Finally we can connect to the signals we want to stop its - * default handler. Since both signals has the same signature - * we use one callback for both :) - */ - glade_gtk_dialog_stop_offending_signals (widget); - } +glade_gtk_file_chooser_default_forall (GtkWidget * widget, gpointer data) +{ + /* Since GtkFileChooserDefault is not exposed we check if its a + * GtkFileChooser + */ + if (GTK_IS_FILE_CHOOSER (widget)) + { + + /* Finally we can connect to the signals we want to stop its + * default handler. Since both signals has the same signature + * we use one callback for both :) + */ + glade_gtk_dialog_stop_offending_signals (widget); + } } static void -glade_gtk_file_chooser_forall (GtkWidget *widget, gpointer data) -{ - /* GtkFileChooserWidget packs a GtkFileChooserDefault */ - if (GTK_IS_FILE_CHOOSER_WIDGET (widget)) - gtk_container_forall (GTK_CONTAINER (widget), - glade_gtk_file_chooser_default_forall, - NULL); -} - -void -glade_gtk_dialog_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) -{ - GtkDialog *dialog = GTK_DIALOG (object); - GladeWidget *widget; - GladeWidget *vbox_widget, *actionarea_widget, *colorsel, *fontsel; - GladeWidget *ok_button = NULL, *cancel_button = NULL, - *help_button = NULL, *apply_button = NULL; - - g_return_if_fail (GTK_IS_DIALOG (dialog)); - - widget = glade_widget_get_from_gobject (GTK_WIDGET (dialog)); - if (!widget) - return; - - if (reason == GLADE_CREATE_USER) - { - /* HIG complient border-width defaults on dialogs */ - glade_widget_property_set (widget, "border-width", 5); - } - - if (GTK_IS_COLOR_SELECTION_DIALOG (object)) - { - GtkWidget *child; - - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_OK); - ok_button = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "ok_button", "colorsel", FALSE, reason); - - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_CANCEL); - cancel_button = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "cancel_button", "colorsel", FALSE, reason); - - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_HELP); - help_button = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "help_button", "colorsel", FALSE, reason); - - child = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog)); - colorsel = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "color_selection", "colorsel", FALSE, reason); - - /* Set this to 1 at load time, if there are any children then - * size will adjust appropriately (otherwise the default "3" gets - * set and we end up with extra placeholders). - */ - if (reason == GLADE_CREATE_LOAD) - glade_widget_property_set (colorsel, "size", 1); - - } - else if (GTK_IS_FONT_SELECTION_DIALOG (object)) - { - GtkWidget *child; - - child = gtk_font_selection_dialog_get_ok_button (GTK_FONT_SELECTION_DIALOG (dialog)); - ok_button = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "ok_button", "fontsel", FALSE, reason); - - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_APPLY); - apply_button = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "apply_button", "fontsel", FALSE, reason); - - child = gtk_font_selection_dialog_get_cancel_button (GTK_FONT_SELECTION_DIALOG (dialog)); - cancel_button = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "cancel_button", "fontsel", FALSE, reason); +glade_gtk_file_chooser_forall (GtkWidget * widget, gpointer data) +{ + /* GtkFileChooserWidget packs a GtkFileChooserDefault */ + if (GTK_IS_FILE_CHOOSER_WIDGET (widget)) + gtk_container_forall (GTK_CONTAINER (widget), + glade_gtk_file_chooser_default_forall, NULL); +} + +void +glade_gtk_dialog_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) +{ + GtkDialog *dialog = GTK_DIALOG (object); + GladeWidget *widget; + GladeWidget *vbox_widget, *actionarea_widget, *colorsel, *fontsel; + GladeWidget *ok_button = NULL, *cancel_button = NULL, + *help_button = NULL, *apply_button = NULL; + + g_return_if_fail (GTK_IS_DIALOG (dialog)); + + widget = glade_widget_get_from_gobject (GTK_WIDGET (dialog)); + if (!widget) + return; + + if (reason == GLADE_CREATE_USER) + { + /* HIG complient border-width defaults on dialogs */ + glade_widget_property_set (widget, "border-width", 5); + } + + if (GTK_IS_COLOR_SELECTION_DIALOG (object)) + { + GtkWidget *child; + + child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_OK); + ok_button = glade_widget_adaptor_create_internal + (widget, G_OBJECT (child), "ok_button", "colorsel", FALSE, reason); + + child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_CANCEL); + cancel_button = glade_widget_adaptor_create_internal + (widget, G_OBJECT (child), + "cancel_button", "colorsel", FALSE, reason); + + child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_HELP); + help_button = glade_widget_adaptor_create_internal + (widget, G_OBJECT (child), "help_button", "colorsel", FALSE, reason); + + child = + gtk_color_selection_dialog_get_color_selection + (GTK_COLOR_SELECTION_DIALOG (dialog)); + colorsel = + glade_widget_adaptor_create_internal (widget, G_OBJECT (child), + "color_selection", "colorsel", + FALSE, reason); + + /* Set this to 1 at load time, if there are any children then + * size will adjust appropriately (otherwise the default "3" gets + * set and we end up with extra placeholders). + */ + if (reason == GLADE_CREATE_LOAD) + glade_widget_property_set (colorsel, "size", 1); + + } + else if (GTK_IS_FONT_SELECTION_DIALOG (object)) + { + GtkWidget *child; + + child = + gtk_font_selection_dialog_get_ok_button (GTK_FONT_SELECTION_DIALOG + (dialog)); + ok_button = + glade_widget_adaptor_create_internal (widget, G_OBJECT (child), + "ok_button", "fontsel", FALSE, + reason); + + child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_APPLY); + apply_button = glade_widget_adaptor_create_internal + (widget, G_OBJECT (child), "apply_button", "fontsel", FALSE, reason); + + child = + gtk_font_selection_dialog_get_cancel_button (GTK_FONT_SELECTION_DIALOG + (dialog)); + cancel_button = + glade_widget_adaptor_create_internal (widget, G_OBJECT (child), + "cancel_button", "fontsel", + FALSE, reason); #if GTK_CHECK_VERSION (2, 24, 0) - child = gtk_font_selection_dialog_get_font_selection - (GTK_FONT_SELECTION_DIALOG (dialog)); + child = gtk_font_selection_dialog_get_font_selection + (GTK_FONT_SELECTION_DIALOG (dialog)); #else - child = GTK_FONT_SELECTION_DIALOG (dialog)->fontsel; + child = GTK_FONT_SELECTION_DIALOG (dialog)->fontsel; #endif - fontsel = glade_widget_adaptor_create_internal - (widget, G_OBJECT (child), - "font_selection", "fontsel", FALSE, reason); - - /* Set this to 1 at load time, if there are any children then - * size will adjust appropriately (otherwise the default "3" gets - * set and we end up with extra placeholders). - */ - if (reason == GLADE_CREATE_LOAD) - glade_widget_property_set (fontsel, "size", 2); - } - else - { - /* We need to stop default emissions of "hierarchy-changed" and - * "screen-changed" of GtkFileChooserDefault to avoid an abort() - * when doing a reparent. - * GtkFileChooserDialog packs a GtkFileChooserWidget in - * his internal vbox. - */ - if (GTK_IS_FILE_CHOOSER_DIALOG (object)) - gtk_container_forall (GTK_CONTAINER (gtk_dialog_get_content_area (dialog)), - glade_gtk_file_chooser_forall, - NULL); - - vbox_widget = glade_widget_adaptor_create_internal - (widget, G_OBJECT(gtk_dialog_get_content_area (dialog)), - "vbox", "dialog", FALSE, reason); - - actionarea_widget = glade_widget_adaptor_create_internal - (vbox_widget, G_OBJECT(gtk_dialog_get_action_area (dialog)), - "action_area", "dialog", FALSE, reason); - - /* These properties are controlled by the GtkDialog style properties: - * "content-area-border", "button-spacing" and "action-area-border", - * so we must disable thier use. - */ - glade_widget_remove_property (vbox_widget, "border-width"); - glade_widget_remove_property (actionarea_widget, "border-width"); - glade_widget_remove_property (actionarea_widget, "spacing"); - - /* Only set these on the original create. */ - if (reason == GLADE_CREATE_USER) - { - - /* HIG complient spacing defaults on dialogs */ - glade_widget_property_set (vbox_widget, "spacing", 2); - - if (GTK_IS_MESSAGE_DIALOG (object)) - glade_widget_property_set (vbox_widget, "size", 2); - else if (GTK_IS_ABOUT_DIALOG (object)) - glade_widget_property_set (vbox_widget, "size", 3); - else if (GTK_IS_FILE_CHOOSER_DIALOG (object)) - glade_widget_property_set (vbox_widget, "size", 3); - else - glade_widget_property_set (vbox_widget, "size", 2); - - glade_widget_property_set (actionarea_widget, "size", 2); - glade_widget_property_set (actionarea_widget, "layout-style", GTK_BUTTONBOX_END); - } - } + fontsel = glade_widget_adaptor_create_internal + (widget, G_OBJECT (child), + "font_selection", "fontsel", FALSE, reason); + + /* Set this to 1 at load time, if there are any children then + * size will adjust appropriately (otherwise the default "3" gets + * set and we end up with extra placeholders). + */ + if (reason == GLADE_CREATE_LOAD) + glade_widget_property_set (fontsel, "size", 2); + } + else + { + /* We need to stop default emissions of "hierarchy-changed" and + * "screen-changed" of GtkFileChooserDefault to avoid an abort() + * when doing a reparent. + * GtkFileChooserDialog packs a GtkFileChooserWidget in + * his internal vbox. + */ + if (GTK_IS_FILE_CHOOSER_DIALOG (object)) + gtk_container_forall (GTK_CONTAINER + (gtk_dialog_get_content_area (dialog)), + glade_gtk_file_chooser_forall, NULL); + + vbox_widget = glade_widget_adaptor_create_internal + (widget, G_OBJECT (gtk_dialog_get_content_area (dialog)), + "vbox", "dialog", FALSE, reason); + + actionarea_widget = glade_widget_adaptor_create_internal + (vbox_widget, G_OBJECT (gtk_dialog_get_action_area (dialog)), + "action_area", "dialog", FALSE, reason); + + /* These properties are controlled by the GtkDialog style properties: + * "content-area-border", "button-spacing" and "action-area-border", + * so we must disable thier use. + */ + glade_widget_remove_property (vbox_widget, "border-width"); + glade_widget_remove_property (actionarea_widget, "border-width"); + glade_widget_remove_property (actionarea_widget, "spacing"); + + /* Only set these on the original create. */ + if (reason == GLADE_CREATE_USER) + { + + /* HIG complient spacing defaults on dialogs */ + glade_widget_property_set (vbox_widget, "spacing", 2); + + if (GTK_IS_MESSAGE_DIALOG (object)) + glade_widget_property_set (vbox_widget, "size", 2); + else if (GTK_IS_ABOUT_DIALOG (object)) + glade_widget_property_set (vbox_widget, "size", 3); + else if (GTK_IS_FILE_CHOOSER_DIALOG (object)) + glade_widget_property_set (vbox_widget, "size", 3); + else + glade_widget_property_set (vbox_widget, "size", 2); + + glade_widget_property_set (actionarea_widget, "size", 2); + glade_widget_property_set (actionarea_widget, "layout-style", + GTK_BUTTONBOX_END); + } + } } GtkWidget * -glade_gtk_dialog_get_internal_child (GladeWidgetAdaptor *adaptor, - GtkDialog *dialog, - const gchar *name) -{ - GtkWidget *child = NULL; - - g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); - - if (GTK_IS_COLOR_SELECTION_DIALOG (dialog)) - { - if (strcmp ("ok_button", name) == 0) - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_OK); - else if (strcmp ("cancel_button", name) == 0) - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_CANCEL); - else if (strcmp ("help_button", name) == 0) - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_HELP); - else if (strcmp ("color_selection", name) == 0) - child = gtk_color_selection_dialog_get_color_selection - (GTK_COLOR_SELECTION_DIALOG (dialog)); - } - else if (GTK_IS_FONT_SELECTION_DIALOG (dialog)) - { - - if (strcmp ("ok_button", name) == 0) - child = gtk_font_selection_dialog_get_ok_button (GTK_FONT_SELECTION_DIALOG (dialog)); - else if (strcmp ("apply_button", name) == 0) - child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_APPLY); - else if (strcmp ("cancel_button", name) == 0) - child = gtk_font_selection_dialog_get_cancel_button - (GTK_FONT_SELECTION_DIALOG (dialog)); - else if (strcmp ("font_selection", name) == 0) - { +glade_gtk_dialog_get_internal_child (GladeWidgetAdaptor * adaptor, + GtkDialog * dialog, const gchar * name) +{ + GtkWidget *child = NULL; + + g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); + + if (GTK_IS_COLOR_SELECTION_DIALOG (dialog)) + { + if (strcmp ("ok_button", name) == 0) + child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_OK); + else if (strcmp ("cancel_button", name) == 0) + child = + gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_CANCEL); + else if (strcmp ("help_button", name) == 0) + child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_HELP); + else if (strcmp ("color_selection", name) == 0) + child = gtk_color_selection_dialog_get_color_selection + (GTK_COLOR_SELECTION_DIALOG (dialog)); + } + else if (GTK_IS_FONT_SELECTION_DIALOG (dialog)) + { + + if (strcmp ("ok_button", name) == 0) + child = + gtk_font_selection_dialog_get_ok_button (GTK_FONT_SELECTION_DIALOG + (dialog)); + else if (strcmp ("apply_button", name) == 0) + child = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_APPLY); + else if (strcmp ("cancel_button", name) == 0) + child = gtk_font_selection_dialog_get_cancel_button + (GTK_FONT_SELECTION_DIALOG (dialog)); + else if (strcmp ("font_selection", name) == 0) + { #if GTK_CHECK_VERSION (2, 24, 0) - child = gtk_font_selection_dialog_get_font_selection - (GTK_FONT_SELECTION_DIALOG (dialog)); + child = gtk_font_selection_dialog_get_font_selection + (GTK_FONT_SELECTION_DIALOG (dialog)); #else - child = GTK_FONT_SELECTION_DIALOG (dialog)->fontsel; + child = GTK_FONT_SELECTION_DIALOG (dialog)->fontsel; #endif - } - } - else - { - /* Default generic dialog handling - */ - if (strcmp ("vbox", name) == 0) - child = gtk_dialog_get_content_area (dialog); - else if (strcmp ("action_area", name) == 0) - child = gtk_dialog_get_action_area (dialog); - } + } + } + else + { + /* Default generic dialog handling + */ + if (strcmp ("vbox", name) == 0) + child = gtk_dialog_get_content_area (dialog); + else if (strcmp ("action_area", name) == 0) + child = gtk_dialog_get_action_area (dialog); + } - return child; + return child; } GList * -glade_gtk_dialog_get_children (GladeWidgetAdaptor *adaptor, - GtkDialog *dialog) +glade_gtk_dialog_get_children (GladeWidgetAdaptor * adaptor, GtkDialog * dialog) { - GList *list = NULL; + GList *list = NULL; - g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); + g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); - list = glade_util_container_get_all_children (GTK_CONTAINER (dialog)); + list = glade_util_container_get_all_children (GTK_CONTAINER (dialog)); - if (GTK_IS_COLOR_SELECTION_DIALOG (dialog)) - { - GtkWidget *widget; - - widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_OK); - if (widget) list = g_list_prepend (list, widget); + if (GTK_IS_COLOR_SELECTION_DIALOG (dialog)) + { + GtkWidget *widget; - widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_CANCEL); - if (widget) list = g_list_prepend (list, widget); + widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_OK); + if (widget) + list = g_list_prepend (list, widget); - widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_HELP); - if (widget) list = g_list_prepend (list, widget); + widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_CANCEL); + if (widget) + list = g_list_prepend (list, widget); - widget = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog)); - if (widget) list = g_list_prepend (list, widget); - } - else if (GTK_IS_FONT_SELECTION_DIALOG (dialog)) - { - GtkWidget *widget; + widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_HELP); + if (widget) + list = g_list_prepend (list, widget); - widget = gtk_font_selection_dialog_get_ok_button (GTK_FONT_SELECTION_DIALOG (dialog)); - if (widget) list = g_list_prepend (list, widget); + widget = + gtk_color_selection_dialog_get_color_selection + (GTK_COLOR_SELECTION_DIALOG (dialog)); + if (widget) + list = g_list_prepend (list, widget); + } + else if (GTK_IS_FONT_SELECTION_DIALOG (dialog)) + { + GtkWidget *widget; - widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_APPLY); - if (widget) list = g_list_prepend (list, widget); + widget = + gtk_font_selection_dialog_get_ok_button (GTK_FONT_SELECTION_DIALOG + (dialog)); + if (widget) + list = g_list_prepend (list, widget); - widget = gtk_font_selection_dialog_get_cancel_button (GTK_FONT_SELECTION_DIALOG (dialog)); - if (widget) list = g_list_prepend (list, widget); + widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_APPLY); + if (widget) + list = g_list_prepend (list, widget); + + widget = + gtk_font_selection_dialog_get_cancel_button (GTK_FONT_SELECTION_DIALOG + (dialog)); + if (widget) + list = g_list_prepend (list, widget); #if GTK_CHECK_VERSION (2, 24, 0) - widget = gtk_font_selection_dialog_get_font_selection (GTK_FONT_SELECTION_DIALOG (dialog)); + widget = + gtk_font_selection_dialog_get_font_selection + (GTK_FONT_SELECTION_DIALOG (dialog)); #else - widget = GTK_FONT_SELECTION_DIALOG (dialog)->fontsel; + widget = GTK_FONT_SELECTION_DIALOG (dialog)->fontsel; #endif - if (widget) list = g_list_prepend (list, widget); - } - return list; + if (widget) + list = g_list_prepend (list, widget); + } + return list; } @@ -5229,323 +5134,331 @@ glade_gtk_dialog_get_children (GladeWidgetAdaptor *adaptor, static void -glade_gtk_dialog_read_responses (GladeWidget *widget, - GladeXmlNode *widgets_node) -{ - GladeXmlNode *node; - GladeWidget *action_widget; - - for (node = glade_xml_node_get_children (widgets_node); - node; node = glade_xml_node_next (node)) - { - gchar *widget_name, *response; - - if (!glade_xml_node_verify (node, GLADE_TAG_ACTION_WIDGET)) - continue; - - response = glade_xml_get_property_string_required (node, GLADE_TAG_RESPONSE, NULL); - widget_name = glade_xml_get_content (node); - - if ((action_widget = - glade_project_get_widget_by_name (widget->project, widget, widget_name)) != NULL) - { - glade_widget_property_set (action_widget, "response-id", - g_ascii_strtoll (response, NULL, 10)); - } +glade_gtk_dialog_read_responses (GladeWidget * widget, + GladeXmlNode * widgets_node) +{ + GladeXmlNode *node; + GladeWidget *action_widget; + + for (node = glade_xml_node_get_children (widgets_node); + node; node = glade_xml_node_next (node)) + { + gchar *widget_name, *response; + + if (!glade_xml_node_verify (node, GLADE_TAG_ACTION_WIDGET)) + continue; + + response = + glade_xml_get_property_string_required (node, GLADE_TAG_RESPONSE, + NULL); + widget_name = glade_xml_get_content (node); + + if ((action_widget = + glade_project_get_widget_by_name (widget->project, widget, + widget_name)) != NULL) + { + glade_widget_property_set (action_widget, "response-id", + g_ascii_strtoll (response, NULL, 10)); + } - g_free (response); - g_free (widget_name); - } + g_free (response); + g_free (widget_name); + } } void -glade_gtk_dialog_read_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_dialog_read_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - GladeXmlNode *widgets_node; + GladeXmlNode *widgets_node; - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->read_child (adaptor, widget, node); + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->read_child (adaptor, widget, node); - node = glade_xml_node_get_parent (node); + node = glade_xml_node_get_parent (node); - if ((widgets_node = glade_xml_search_child (node, GLADE_TAG_ACTION_WIDGETS)) != NULL) - glade_gtk_dialog_read_responses (widget, widgets_node); + if ((widgets_node = + glade_xml_search_child (node, GLADE_TAG_ACTION_WIDGETS)) != NULL) + glade_gtk_dialog_read_responses (widget, widgets_node); } static void -glade_gtk_dialog_write_responses (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_dialog_write_responses (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *widget_node; - GtkDialog *dialog = GTK_DIALOG (widget->object); - GList *l, *action_widgets = - gtk_container_get_children (GTK_CONTAINER (gtk_dialog_get_action_area (dialog))); + GladeXmlNode *widget_node; + GtkDialog *dialog = GTK_DIALOG (widget->object); + GList *l, *action_widgets = + gtk_container_get_children (GTK_CONTAINER + (gtk_dialog_get_action_area (dialog))); + + for (l = action_widgets; l; l = l->next) + { + GladeWidget *action_widget; + GladeProperty *property; + gchar *str; - for (l = action_widgets; l; l = l->next) - { - GladeWidget *action_widget; - GladeProperty *property; - gchar *str; + if ((action_widget = glade_widget_get_from_gobject (l->data)) == NULL) + continue; - if ((action_widget = glade_widget_get_from_gobject (l->data)) == NULL) - continue; + if ((property = + glade_widget_get_property (action_widget, "response-id")) == NULL) + continue; - if ((property = glade_widget_get_property (action_widget, "response-id")) == NULL) - continue; - - widget_node = glade_xml_node_new (context, GLADE_TAG_ACTION_WIDGET); - glade_xml_node_append_child (node, widget_node); + widget_node = glade_xml_node_new (context, GLADE_TAG_ACTION_WIDGET); + glade_xml_node_append_child (node, widget_node); - str = glade_property_class_make_string_from_gvalue (property->klass, property->value); + str = + glade_property_class_make_string_from_gvalue (property->klass, + property->value); - glade_xml_node_set_property_string (widget_node, GLADE_TAG_RESPONSE, str); - glade_xml_set_content (widget_node, action_widget->name); + glade_xml_node_set_property_string (widget_node, GLADE_TAG_RESPONSE, str); + glade_xml_set_content (widget_node, action_widget->name); - g_free (str); - } + g_free (str); + } - g_list_free (action_widgets); + g_list_free (action_widgets); } void -glade_gtk_dialog_write_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_dialog_write_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) { - GladeXmlNode *widgets_node; - GladeWidget *parent; - GladeProject *project; + GladeXmlNode *widgets_node; + GladeWidget *parent; + GladeProject *project; - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, node); + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, + node); - parent = widget->parent; - project = widget->project; + parent = widget->parent; + project = widget->project; - if (parent && GTK_IS_DIALOG (parent->object)) - { - widgets_node = glade_xml_node_new (context, GLADE_TAG_ACTION_WIDGETS); + if (parent && GTK_IS_DIALOG (parent->object)) + { + widgets_node = glade_xml_node_new (context, GLADE_TAG_ACTION_WIDGETS); - glade_gtk_dialog_write_responses (parent, context, widgets_node); + glade_gtk_dialog_write_responses (parent, context, widgets_node); - if (!glade_xml_node_get_children (widgets_node)) - glade_xml_node_delete (widgets_node); - else - glade_xml_node_append_child (node, widgets_node); - } + if (!glade_xml_node_get_children (widgets_node)) + glade_xml_node_delete (widgets_node); + else + glade_xml_node_append_child (node, widgets_node); + } } /*--------------------------- GtkMessageDialog ---------------------------------*/ static gboolean -glade_gtk_message_dialog_reset_image (GtkMessageDialog *dialog) +glade_gtk_message_dialog_reset_image (GtkMessageDialog * dialog) { - GtkWidget *image; - gint message_type; + GtkWidget *image; + gint message_type; - g_object_get (dialog, "message-type", &message_type, NULL); - if (message_type != GTK_MESSAGE_OTHER) - return FALSE; + g_object_get (dialog, "message-type", &message_type, NULL); + if (message_type != GTK_MESSAGE_OTHER) + return FALSE; - image = gtk_message_dialog_get_image (dialog); - if (glade_widget_get_from_gobject (image)) - { - gtk_message_dialog_set_image (dialog, - gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG)); - gtk_widget_show (image); + image = gtk_message_dialog_get_image (dialog); + if (glade_widget_get_from_gobject (image)) + { + gtk_message_dialog_set_image (dialog, + gtk_image_new_from_stock (NULL, + GTK_ICON_SIZE_DIALOG)); + gtk_widget_show (image); - return TRUE; - } - else - return FALSE; + return TRUE; + } + else + return FALSE; } -enum { - MD_IMAGE_ACTION_INVALID, - MD_IMAGE_ACTION_RESET, - MD_IMAGE_ACTION_SET +enum +{ + MD_IMAGE_ACTION_INVALID, + MD_IMAGE_ACTION_RESET, + MD_IMAGE_ACTION_SET }; static gint -glade_gtk_message_dialog_image_determine_action (GtkMessageDialog *dialog, - const GValue *value, - GtkWidget **image, - GladeWidget **gimage) -{ - GtkWidget *dialog_image = gtk_message_dialog_get_image (dialog); - - *image = g_value_get_object (value); - - if (*image == NULL) - if (glade_widget_get_from_gobject (dialog_image)) - return MD_IMAGE_ACTION_RESET; - else - return MD_IMAGE_ACTION_INVALID; - else - { - *image = GTK_WIDGET (*image); - if (dialog_image == *image) - return MD_IMAGE_ACTION_INVALID; - if (gtk_widget_get_parent (*image)) - return MD_IMAGE_ACTION_INVALID; - - *gimage = glade_widget_get_from_gobject (*image); - - if (!*gimage) - { - g_warning ("Setting property to an object outside the project"); - return MD_IMAGE_ACTION_INVALID; - } - - if (glade_widget_get_parent (*gimage) || GWA_IS_TOPLEVEL ((*gimage)->adaptor)) - return MD_IMAGE_ACTION_INVALID; - - return MD_IMAGE_ACTION_SET; - } -} - -void -glade_gtk_message_dialog_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object); - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - - g_return_if_fail (gwidget); - - if (strcmp (id, "image") == 0) - { - GtkWidget *image = NULL; - GladeWidget *gimage = NULL; - gint rslt; - - rslt = glade_gtk_message_dialog_image_determine_action (dialog, value, - &image, &gimage); - switch (rslt) - { - case MD_IMAGE_ACTION_INVALID: - return; - case MD_IMAGE_ACTION_RESET: - glade_gtk_message_dialog_reset_image (dialog); - return; - case MD_IMAGE_ACTION_SET: - break; /* continue setting the property */ - } - - if (gtk_widget_get_parent (image)) - g_critical ("Image should have no parent now"); - - gtk_message_dialog_set_image (dialog, image); - - { - /* syncing "message-type" property */ - GladeProperty *property; - - property = glade_widget_get_property (gwidget, "message-type"); - if (!glade_property_equals (property, GTK_MESSAGE_OTHER)) - glade_command_set_property (property, GTK_MESSAGE_OTHER); - } - } - else - { - /* We must reset the image to internal, - * external image would otherwise become internal - */ - if (!strcmp (id, "message-type") && - g_value_get_enum (value) != GTK_MESSAGE_OTHER) - { - GladeProperty *property; - - property = glade_widget_get_property (gwidget, "image"); - if (!glade_property_equals (property, NULL)) - glade_command_set_property (property, NULL); - } - /* Chain up, even if property us message-type because - * it's not fully handled here - */ - GWA_GET_CLASS (GTK_TYPE_DIALOG)->set_property (adaptor, object, - id, value); - } +glade_gtk_message_dialog_image_determine_action (GtkMessageDialog * dialog, + const GValue * value, + GtkWidget ** image, + GladeWidget ** gimage) +{ + GtkWidget *dialog_image = gtk_message_dialog_get_image (dialog); + + *image = g_value_get_object (value); + + if (*image == NULL) + if (glade_widget_get_from_gobject (dialog_image)) + return MD_IMAGE_ACTION_RESET; + else + return MD_IMAGE_ACTION_INVALID; + else + { + *image = GTK_WIDGET (*image); + if (dialog_image == *image) + return MD_IMAGE_ACTION_INVALID; + if (gtk_widget_get_parent (*image)) + return MD_IMAGE_ACTION_INVALID; + + *gimage = glade_widget_get_from_gobject (*image); + + if (!*gimage) + { + g_warning ("Setting property to an object outside the project"); + return MD_IMAGE_ACTION_INVALID; + } + + if (glade_widget_get_parent (*gimage) || + GWA_IS_TOPLEVEL ((*gimage)->adaptor)) + return MD_IMAGE_ACTION_INVALID; + + return MD_IMAGE_ACTION_SET; + } +} + +void +glade_gtk_message_dialog_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object); + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + + g_return_if_fail (gwidget); + + if (strcmp (id, "image") == 0) + { + GtkWidget *image = NULL; + GladeWidget *gimage = NULL; + gint rslt; + + rslt = glade_gtk_message_dialog_image_determine_action (dialog, value, + &image, &gimage); + switch (rslt) + { + case MD_IMAGE_ACTION_INVALID: + return; + case MD_IMAGE_ACTION_RESET: + glade_gtk_message_dialog_reset_image (dialog); + return; + case MD_IMAGE_ACTION_SET: + break; /* continue setting the property */ + } + + if (gtk_widget_get_parent (image)) + g_critical ("Image should have no parent now"); + + gtk_message_dialog_set_image (dialog, image); + + { + /* syncing "message-type" property */ + GladeProperty *property; + + property = glade_widget_get_property (gwidget, "message-type"); + if (!glade_property_equals (property, GTK_MESSAGE_OTHER)) + glade_command_set_property (property, GTK_MESSAGE_OTHER); + } + } + else + { + /* We must reset the image to internal, + * external image would otherwise become internal + */ + if (!strcmp (id, "message-type") && + g_value_get_enum (value) != GTK_MESSAGE_OTHER) + { + GladeProperty *property; + + property = glade_widget_get_property (gwidget, "image"); + if (!glade_property_equals (property, NULL)) + glade_command_set_property (property, NULL); + } + /* Chain up, even if property us message-type because + * it's not fully handled here + */ + GWA_GET_CLASS (GTK_TYPE_DIALOG)->set_property (adaptor, object, + id, value); + } } gboolean -glade_gtk_message_dialog_verify_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - if (!strcmp (id, "image")) - { - GtkWidget *image; GladeWidget *gimage; - - gboolean retval = MD_IMAGE_ACTION_INVALID != - glade_gtk_message_dialog_image_determine_action (GTK_MESSAGE_DIALOG (object), - value, &image, &gimage); - - return retval; - } - else - if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) - return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, - id, value); - else - return TRUE; -} - -void -glade_gtk_message_dialog_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - GValue *value) -{ - if (!strcmp (property_name, "image")) - { - GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object); - GtkWidget *image = gtk_message_dialog_get_image (dialog); - - if (!glade_widget_get_from_gobject (image)) - g_value_set_object (value, NULL); - else - g_value_set_object (value, image); - } - else - GWA_GET_CLASS (GTK_TYPE_DIALOG)->get_property (adaptor, object, - property_name, value); +glade_gtk_message_dialog_verify_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, + const GValue * value) +{ + if (!strcmp (id, "image")) + { + GtkWidget *image; + GladeWidget *gimage; + + gboolean retval = MD_IMAGE_ACTION_INVALID != + glade_gtk_message_dialog_image_determine_action (GTK_MESSAGE_DIALOG + (object), + value, &image, + &gimage); + + return retval; + } + else if (GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property) + return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->verify_property (adaptor, object, + id, value); + else + return TRUE; +} + +void +glade_gtk_message_dialog_get_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + GValue * value) +{ + if (!strcmp (property_name, "image")) + { + GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object); + GtkWidget *image = gtk_message_dialog_get_image (dialog); + + if (!glade_widget_get_from_gobject (image)) + g_value_set_object (value, NULL); + else + g_value_set_object (value, image); + } + else + GWA_GET_CLASS (GTK_TYPE_DIALOG)->get_property (adaptor, object, + property_name, value); } /* ----------------------------- GtkFileChooserWidget ------------------------------ */ void -glade_gtk_file_chooser_widget_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_file_chooser_widget_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, + GladeCreateReason reason) { - gtk_container_forall (GTK_CONTAINER (object), - glade_gtk_file_chooser_default_forall, - NULL); + gtk_container_forall (GTK_CONTAINER (object), + glade_gtk_file_chooser_default_forall, NULL); } void -glade_gtk_file_chooser_button_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_file_chooser_button_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, + const GValue * value) { - /* Avoid a warning */ - if (!strcmp (id, "action")) - { - if (g_value_get_enum (value) == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER || - g_value_get_enum (value) == GTK_FILE_CHOOSER_ACTION_SAVE) - return; - } + /* Avoid a warning */ + if (!strcmp (id, "action")) + { + if (g_value_get_enum (value) == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER || + g_value_get_enum (value) == GTK_FILE_CHOOSER_ACTION_SAVE) + return; + } - GWA_GET_CLASS (GTK_TYPE_BOX)->set_property (adaptor, - object, - id, value); + GWA_GET_CLASS (GTK_TYPE_BOX)->set_property (adaptor, object, id, value); } /* ----------------------------- GtkFontButton ------------------------------ */ @@ -5553,1309 +5466,1347 @@ glade_gtk_file_chooser_button_set_property (GladeWidgetAdaptor *adaptor, * glade property through the glade-command api. */ static void -glade_gtk_font_button_refresh_font_name (GtkFontButton *button, - GladeWidget *gbutton) +glade_gtk_font_button_refresh_font_name (GtkFontButton * button, + GladeWidget * gbutton) { - GladeProperty *property; - - if ((property = - glade_widget_get_property (gbutton, "font-name")) != NULL) - glade_command_set_property (property, - gtk_font_button_get_font_name (button)); + GladeProperty *property; + + if ((property = glade_widget_get_property (gbutton, "font-name")) != NULL) + glade_command_set_property (property, + gtk_font_button_get_font_name (button)); } /* ----------------------------- GtkColorButton ------------------------------ */ static void -glade_gtk_color_button_refresh_color (GtkColorButton *button, - GladeWidget *gbutton) +glade_gtk_color_button_refresh_color (GtkColorButton * button, + GladeWidget * gbutton) { - GladeProperty *property; - GdkColor color = { 0, }; - - if ((property = glade_widget_get_property (gbutton, "color")) != NULL) - glade_command_set_property (property, &color); + GladeProperty *property; + GdkColor color = { 0, }; + + if ((property = glade_widget_get_property (gbutton, "color")) != NULL) + glade_command_set_property (property, &color); } void -glade_gtk_color_button_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_color_button_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "color")) - { - if (g_value_get_boxed (value)) - gtk_color_button_set_color (GTK_COLOR_BUTTON (object), - (GdkColor *)g_value_get_boxed (value)); - } - else - GWA_GET_CLASS (GTK_TYPE_BUTTON)->set_property (adaptor, - object, - id, value); + if (!strcmp (id, "color")) + { + if (g_value_get_boxed (value)) + gtk_color_button_set_color (GTK_COLOR_BUTTON (object), + (GdkColor *) g_value_get_boxed (value)); + } + else + GWA_GET_CLASS (GTK_TYPE_BUTTON)->set_property (adaptor, object, id, value); } /* ----------------------------- GtkButton ------------------------------ */ -static void -sync_use_appearance (GladeWidget *gwidget) +static void +sync_use_appearance (GladeWidget * gwidget) { - GladeProperty *prop = glade_widget_get_property (gwidget, "use-action-appearance"); - gboolean use_appearance = FALSE; + GladeProperty *prop = + glade_widget_get_property (gwidget, "use-action-appearance"); + gboolean use_appearance = FALSE; - /* This is the kind of thing we avoid doing at project load time ;-) */ - if (glade_widget_superuser ()) - return; + /* This is the kind of thing we avoid doing at project load time ;-) */ + if (glade_widget_superuser ()) + return; - glade_property_get (prop, &use_appearance); - if (use_appearance) - { - glade_property_set (prop, FALSE); - glade_property_set (prop, TRUE); - } + glade_property_get (prop, &use_appearance); + if (use_appearance) + { + glade_property_set (prop, FALSE); + glade_property_set (prop, TRUE); + } } /* shared between menuitems and toolitems too */ static void -evaluate_activatable_property_sensitivity (GObject *object, - const gchar *id, - const GValue *value) -{ - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - - if (!strcmp (id, "related-action")) - { - GtkAction *action = g_value_get_object (value); - - if (action) - { - glade_widget_property_set_sensitive (gwidget, "visible", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "sensitive", FALSE, ACTION_APPEARANCE_MSG); - - glade_widget_property_set_sensitive (gwidget, "accel-group", FALSE, ACTION_APPEARANCE_MSG); - } else { - glade_widget_property_set_sensitive (gwidget, "visible", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "sensitive", TRUE, NULL); - - glade_widget_property_set_sensitive (gwidget, "accel-group", TRUE, NULL); - } - - } - else if (!strcmp (id, "use-action-appearance")) - { - gboolean use_appearance = g_value_get_boolean (value); - - - if (use_appearance) - { - glade_widget_property_set_sensitive (gwidget, "label", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "use-underline", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "stock", FALSE, ACTION_APPEARANCE_MSG); - //glade_widget_property_set_sensitive (gwidget, "use-stock", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "image", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "custom-child", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "stock-id", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "label-widget", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "icon-name", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "icon-widget", FALSE, ACTION_APPEARANCE_MSG); - glade_widget_property_set_sensitive (gwidget, "icon", FALSE, ACTION_APPEARANCE_MSG); - } else { - glade_widget_property_set_sensitive (gwidget, "label", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "use-underline", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "stock", TRUE, NULL); - //glade_widget_property_set_sensitive (gwidget, "use-stock", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "image", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "custom-child", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "stock-id", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "label-widget", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "icon-name", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "icon-widget", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "icon", TRUE, NULL); - } - } +evaluate_activatable_property_sensitivity (GObject * object, + const gchar * id, + const GValue * value) +{ + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + + if (!strcmp (id, "related-action")) + { + GtkAction *action = g_value_get_object (value); + + if (action) + { + glade_widget_property_set_sensitive (gwidget, "visible", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "sensitive", FALSE, + ACTION_APPEARANCE_MSG); + + glade_widget_property_set_sensitive (gwidget, "accel-group", FALSE, + ACTION_APPEARANCE_MSG); + } + else + { + glade_widget_property_set_sensitive (gwidget, "visible", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "sensitive", TRUE, + NULL); + + glade_widget_property_set_sensitive (gwidget, "accel-group", TRUE, + NULL); + } + + } + else if (!strcmp (id, "use-action-appearance")) + { + gboolean use_appearance = g_value_get_boolean (value); + + + if (use_appearance) + { + glade_widget_property_set_sensitive (gwidget, "label", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "use-underline", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "stock", FALSE, + ACTION_APPEARANCE_MSG); + //glade_widget_property_set_sensitive (gwidget, "use-stock", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "image", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "custom-child", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "stock-id", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "label-widget", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "icon-name", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "icon-widget", FALSE, + ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "icon", FALSE, + ACTION_APPEARANCE_MSG); + } + else + { + glade_widget_property_set_sensitive (gwidget, "label", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "use-underline", TRUE, + NULL); + glade_widget_property_set_sensitive (gwidget, "stock", TRUE, NULL); + //glade_widget_property_set_sensitive (gwidget, "use-stock", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "image", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "custom-child", TRUE, + NULL); + glade_widget_property_set_sensitive (gwidget, "stock-id", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "label-widget", TRUE, + NULL); + glade_widget_property_set_sensitive (gwidget, "icon-name", TRUE, + NULL); + glade_widget_property_set_sensitive (gwidget, "icon-widget", TRUE, + NULL); + glade_widget_property_set_sensitive (gwidget, "icon", TRUE, NULL); + } + } } GladeEditable * -glade_gtk_button_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_button_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; - - /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); - - if (type == GLADE_PAGE_GENERAL) - { - editable = (GladeEditable *)glade_activatable_editor_new (adaptor, editable); - return (GladeEditable *)glade_button_editor_new (adaptor, editable); - } - return editable; + GladeEditable *editable; + + /* Get base editable */ + editable = + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); + + if (type == GLADE_PAGE_GENERAL) + { + editable = + (GladeEditable *) glade_activatable_editor_new (adaptor, editable); + return (GladeEditable *) glade_button_editor_new (adaptor, editable); + } + return editable; } void -glade_gtk_button_post_create (GladeWidgetAdaptor *adaptor, - GObject *button, - GladeCreateReason reason) +glade_gtk_button_post_create (GladeWidgetAdaptor * adaptor, + GObject * button, GladeCreateReason reason) { - GladeWidget *gbutton = glade_widget_get_from_gobject (button); + GladeWidget *gbutton = glade_widget_get_from_gobject (button); + + g_return_if_fail (GTK_IS_BUTTON (button)); + g_return_if_fail (GLADE_IS_WIDGET (gbutton)); - g_return_if_fail (GTK_IS_BUTTON (button)); - g_return_if_fail (GLADE_IS_WIDGET (gbutton)); + if (GTK_IS_FONT_BUTTON (button)) + g_signal_connect + (button, "font-set", + G_CALLBACK (glade_gtk_font_button_refresh_font_name), gbutton); + else if (GTK_IS_COLOR_BUTTON (button)) + g_signal_connect + (button, "color-set", + G_CALLBACK (glade_gtk_color_button_refresh_color), gbutton); - if (GTK_IS_FONT_BUTTON (button)) - g_signal_connect - (button, "font-set", - G_CALLBACK (glade_gtk_font_button_refresh_font_name), gbutton); - else if (GTK_IS_COLOR_BUTTON (button)) - g_signal_connect - (button, "color-set", - G_CALLBACK (glade_gtk_color_button_refresh_color), gbutton); - - /* Disabled response-id until its in an action area */ - glade_widget_property_set_sensitive (gbutton, "response-id", FALSE, - RESPID_INSENSITIVE_MSG); - glade_widget_property_set_enabled (gbutton, "response-id", FALSE); -} - -void -glade_gtk_button_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - GladeWidget *widget = glade_widget_get_from_gobject (object); - GladeProperty *property = glade_widget_get_property (widget, id); - - evaluate_activatable_property_sensitivity (object, id, value); - - if (strcmp (id, "custom-child") == 0) - { - GtkWidget *child = gtk_bin_get_child (GTK_BIN (object)); - - if (g_value_get_boolean (value)) - { - if (child) - gtk_container_remove (GTK_CONTAINER (object), child); - - gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ()); - } - else if (child && GLADE_IS_PLACEHOLDER (child)) - gtk_container_remove (GTK_CONTAINER (object), child); - } - else if (strcmp (id, "stock") == 0) - { - gboolean use_stock = FALSE; - glade_widget_property_get (widget, "use-stock", &use_stock); - if (use_stock) - gtk_button_set_label (GTK_BUTTON (object), g_value_get_string (value)); - } - else if (strcmp (id, "use-stock") == 0) - { - /* I guess its my bug in GTK+, we need to resync the appearance property - * on GtkButton when the GtkButton:use-stock property changes. - */ - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, - id, value); - sync_use_appearance (widget); - } - else if (GPC_VERSION_CHECK (property->klass, gtk_major_version, gtk_minor_version + 1)) - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, - id, value); -} - -void -glade_gtk_button_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - gboolean use_stock; - gchar *label = NULL; - - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->read_widget (adaptor, widget, node); - - /* Update the stock property */ - glade_widget_property_get (widget, "use-stock", &use_stock); - if (use_stock) - { - glade_widget_property_get (widget, "label", &label); - glade_widget_property_set (widget, "stock", label); - } -} - -void -glade_gtk_button_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) -{ - GladeProperty *prop; - gboolean use_stock; - gchar *stock = NULL; - - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* Do not save GtkColorButton and GtkFontButton label property */ - if (!(GTK_IS_COLOR_BUTTON (widget->object) || GTK_IS_FONT_BUTTON (widget->object))) - { - /* Make a copy of the GladeProperty, - * override its value and ensure non-translatable if use-stock is TRUE - */ - prop = glade_widget_get_property (widget, "label"); - prop = glade_property_dup (prop, widget); - glade_widget_property_get (widget, "use-stock", &use_stock); - if (use_stock) - { - glade_widget_property_get (widget, "stock", &stock); - glade_property_i18n_set_translatable (prop, FALSE); - glade_property_set (prop, stock); - } - glade_property_write (prop, context, node); - g_object_unref (G_OBJECT (prop)); - } - - /* Write out other normal properties and any other class derived custom properties after ... */ - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->write_widget (adaptor, widget, context, node); + /* Disabled response-id until its in an action area */ + glade_widget_property_set_sensitive (gbutton, "response-id", FALSE, + RESPID_INSENSITIVE_MSG); + glade_widget_property_set_enabled (gbutton, "response-id", FALSE); +} + +void +glade_gtk_button_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + GladeWidget *widget = glade_widget_get_from_gobject (object); + GladeProperty *property = glade_widget_get_property (widget, id); + + evaluate_activatable_property_sensitivity (object, id, value); + + if (strcmp (id, "custom-child") == 0) + { + GtkWidget *child = gtk_bin_get_child (GTK_BIN (object)); + + if (g_value_get_boolean (value)) + { + if (child) + gtk_container_remove (GTK_CONTAINER (object), child); + + gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ()); + } + else if (child && GLADE_IS_PLACEHOLDER (child)) + gtk_container_remove (GTK_CONTAINER (object), child); + } + else if (strcmp (id, "stock") == 0) + { + gboolean use_stock = FALSE; + glade_widget_property_get (widget, "use-stock", &use_stock); + if (use_stock) + gtk_button_set_label (GTK_BUTTON (object), g_value_get_string (value)); + } + else if (strcmp (id, "use-stock") == 0) + { + /* I guess its my bug in GTK+, we need to resync the appearance property + * on GtkButton when the GtkButton:use-stock property changes. + */ + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, + id, value); + sync_use_appearance (widget); + } + else if (GPC_VERSION_CHECK + (property->klass, gtk_major_version, gtk_minor_version + 1)) + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, + value); +} + +void +glade_gtk_button_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + gboolean use_stock; + gchar *label = NULL; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->read_widget (adaptor, widget, node); + + /* Update the stock property */ + glade_widget_property_get (widget, "use-stock", &use_stock); + if (use_stock) + { + glade_widget_property_get (widget, "label", &label); + glade_widget_property_set (widget, "stock", label); + } +} + +void +glade_gtk_button_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) +{ + GladeProperty *prop; + gboolean use_stock; + gchar *stock = NULL; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* Do not save GtkColorButton and GtkFontButton label property */ + if (! + (GTK_IS_COLOR_BUTTON (widget->object) || + GTK_IS_FONT_BUTTON (widget->object))) + { + /* Make a copy of the GladeProperty, + * override its value and ensure non-translatable if use-stock is TRUE + */ + prop = glade_widget_get_property (widget, "label"); + prop = glade_property_dup (prop, widget); + glade_widget_property_get (widget, "use-stock", &use_stock); + if (use_stock) + { + glade_widget_property_get (widget, "stock", &stock); + glade_property_i18n_set_translatable (prop, FALSE); + glade_property_set (prop, stock); + } + glade_property_write (prop, context, node); + g_object_unref (G_OBJECT (prop)); + } + + /* Write out other normal properties and any other class derived custom properties after ... */ + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->write_widget (adaptor, widget, context, + node); } /* ----------------------------- GtkImage ------------------------------ */ void -glade_gtk_image_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_image_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - GladeProperty *property; + GladeProperty *property; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); - - if (glade_widget_property_original_default (widget, "icon-name") == FALSE) - { - property = glade_widget_get_property (widget, "icon-name"); - glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_ICON); - } - else if (glade_widget_property_original_default (widget, "pixbuf") == FALSE) - { - property = glade_widget_get_property (widget, "pixbuf"); - glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_FILENAME); - } - else/* if (glade_widget_property_original_default (widget, "stock") == FALSE) */ - { - property = glade_widget_get_property (widget, "stock"); - glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_STOCK); - } + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); - glade_property_sync (property); + if (glade_widget_property_original_default (widget, "icon-name") == FALSE) + { + property = glade_widget_get_property (widget, "icon-name"); + glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_ICON); + } + else if (glade_widget_property_original_default (widget, "pixbuf") == FALSE) + { + property = glade_widget_get_property (widget, "pixbuf"); + glade_widget_property_set (widget, "image-mode", + GLADE_IMAGE_MODE_FILENAME); + } + else /* if (glade_widget_property_original_default (widget, "stock") == FALSE) */ + { + property = glade_widget_get_property (widget, "stock"); + glade_widget_property_set (widget, "image-mode", GLADE_IMAGE_MODE_STOCK); + } + + glade_property_sync (property); } void -glade_gtk_image_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_image_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) { - GladeXmlNode *prop_node; - GladeProperty *size_prop; - GtkIconSize icon_size; - gchar *value; + GladeXmlNode *prop_node; + GladeProperty *size_prop; + GtkIconSize icon_size; + gchar *value; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and write all the normal properties (including "use-stock")... */ - GWA_GET_CLASS (GTK_TYPE_WIDGET)->write_widget (adaptor, widget, context, node); + /* First chain up and write all the normal properties (including "use-stock")... */ + GWA_GET_CLASS (GTK_TYPE_WIDGET)->write_widget (adaptor, widget, context, + node); - /* We have to save icon-size as an integer, the core will take care of - * loading the int value though. - */ - size_prop = glade_widget_get_property (widget, "icon-size"); - if (!glade_property_original_default (size_prop)) - { - prop_node = glade_xml_node_new (context, GLADE_TAG_PROPERTY); - glade_xml_node_append_child (node, prop_node); + /* We have to save icon-size as an integer, the core will take care of + * loading the int value though. + */ + size_prop = glade_widget_get_property (widget, "icon-size"); + if (!glade_property_original_default (size_prop)) + { + prop_node = glade_xml_node_new (context, GLADE_TAG_PROPERTY); + glade_xml_node_append_child (node, prop_node); - glade_xml_node_set_property_string (prop_node, GLADE_TAG_NAME, size_prop->klass->id); + glade_xml_node_set_property_string (prop_node, GLADE_TAG_NAME, + size_prop->klass->id); - glade_property_get (size_prop, &icon_size); - value = g_strdup_printf ("%d", icon_size); - glade_xml_set_content (prop_node, value); - g_free (value); - } + glade_property_get (size_prop, &icon_size); + value = g_strdup_printf ("%d", icon_size); + glade_xml_set_content (prop_node, value); + g_free (value); + } } static void -glade_gtk_image_set_image_mode (GObject *object, const GValue *value) -{ - GladeWidget *gwidget; - GladeImageEditMode type; - - gwidget = glade_widget_get_from_gobject (object); - g_return_if_fail (GTK_IS_IMAGE (object)); - g_return_if_fail (GLADE_IS_WIDGET (gwidget)); - - glade_widget_property_set_sensitive (gwidget, "stock", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "icon-name", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "pixbuf", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gwidget, "icon-size", FALSE, - _("This property only applies to stock images")); - glade_widget_property_set_sensitive (gwidget, "pixel-size", FALSE, - _("This property only applies to named icons")); - - switch ((type = g_value_get_int (value))) - { - case GLADE_IMAGE_MODE_STOCK: - glade_widget_property_set_sensitive (gwidget, "stock", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "icon-size", TRUE, NULL); - break; - - case GLADE_IMAGE_MODE_ICON: - glade_widget_property_set_sensitive (gwidget, "icon-name", TRUE, NULL); - glade_widget_property_set_sensitive (gwidget, "pixel-size", TRUE, NULL); - break; - - case GLADE_IMAGE_MODE_FILENAME: - glade_widget_property_set_sensitive (gwidget, "pixbuf", TRUE, NULL); - default: - break; - } -} - -void -glade_gtk_image_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - GValue *value) -{ - if (!strcmp (id, "icon-size")) - { - /* Make the int an enum... */ - GValue int_value = { 0, }; - g_value_init (&int_value, G_TYPE_INT); - GWA_GET_CLASS (GTK_TYPE_WIDGET)->get_property (adaptor, object, id, &int_value); - g_value_set_enum (value, g_value_get_int (&int_value)); - g_value_unset (&int_value); - } - else - GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, - id, value); -} - -void -glade_gtk_image_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - if (!strcmp (id, "image-mode")) - glade_gtk_image_set_image_mode (object, value); - else if (!strcmp (id, "icon-size")) - { - /* Make the enum an int... */ - GValue int_value = { 0, }; - g_value_init (&int_value, G_TYPE_INT); - g_value_set_int (&int_value, g_value_get_enum (value)); - GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, &int_value); - g_value_unset (&int_value); - } - else - { - GladeWidget *widget = glade_widget_get_from_gobject (object); - GladeImageEditMode mode = 0; - - glade_widget_property_get (widget, "image-mode", &mode); - - /* avoid setting properties in the wrong mode... */ - switch (mode) - { - case GLADE_IMAGE_MODE_STOCK: - if (!strcmp (id, "icon-name") || - !strcmp (id, "pixbuf")) - return; - break; - case GLADE_IMAGE_MODE_ICON: - if (!strcmp (id, "stock") || - !strcmp (id, "pixbuf")) - return; - break; - case GLADE_IMAGE_MODE_FILENAME: - if (!strcmp (id, "stock") || - !strcmp (id, "icon-name")) - return; - default: - break; - } - - GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, - id, value); - } +glade_gtk_image_set_image_mode (GObject * object, const GValue * value) +{ + GladeWidget *gwidget; + GladeImageEditMode type; + + gwidget = glade_widget_get_from_gobject (object); + g_return_if_fail (GTK_IS_IMAGE (object)); + g_return_if_fail (GLADE_IS_WIDGET (gwidget)); + + glade_widget_property_set_sensitive (gwidget, "stock", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "icon-name", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "pixbuf", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gwidget, "icon-size", FALSE, + _ + ("This property only applies to stock images")); + glade_widget_property_set_sensitive (gwidget, "pixel-size", FALSE, + _ + ("This property only applies to named icons")); + + switch ((type = g_value_get_int (value))) + { + case GLADE_IMAGE_MODE_STOCK: + glade_widget_property_set_sensitive (gwidget, "stock", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "icon-size", TRUE, NULL); + break; + + case GLADE_IMAGE_MODE_ICON: + glade_widget_property_set_sensitive (gwidget, "icon-name", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "pixel-size", TRUE, NULL); + break; + + case GLADE_IMAGE_MODE_FILENAME: + glade_widget_property_set_sensitive (gwidget, "pixbuf", TRUE, NULL); + default: + break; + } +} + +void +glade_gtk_image_get_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, GValue * value) +{ + if (!strcmp (id, "icon-size")) + { + /* Make the int an enum... */ + GValue int_value = { 0, }; + g_value_init (&int_value, G_TYPE_INT); + GWA_GET_CLASS (GTK_TYPE_WIDGET)->get_property (adaptor, object, id, + &int_value); + g_value_set_enum (value, g_value_get_int (&int_value)); + g_value_unset (&int_value); + } + else + GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); +} + +void +glade_gtk_image_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + if (!strcmp (id, "image-mode")) + glade_gtk_image_set_image_mode (object, value); + else if (!strcmp (id, "icon-size")) + { + /* Make the enum an int... */ + GValue int_value = { 0, }; + g_value_init (&int_value, G_TYPE_INT); + g_value_set_int (&int_value, g_value_get_enum (value)); + GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, + &int_value); + g_value_unset (&int_value); + } + else + { + GladeWidget *widget = glade_widget_get_from_gobject (object); + GladeImageEditMode mode = 0; + + glade_widget_property_get (widget, "image-mode", &mode); + + /* avoid setting properties in the wrong mode... */ + switch (mode) + { + case GLADE_IMAGE_MODE_STOCK: + if (!strcmp (id, "icon-name") || !strcmp (id, "pixbuf")) + return; + break; + case GLADE_IMAGE_MODE_ICON: + if (!strcmp (id, "stock") || !strcmp (id, "pixbuf")) + return; + break; + case GLADE_IMAGE_MODE_FILENAME: + if (!strcmp (id, "stock") || !strcmp (id, "icon-name")) + return; + default: + break; + } + + GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, + id, value); + } } GladeEditable * -glade_gtk_image_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_image_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_WIDGET)->create_editable (adaptor, type); + /* Get base editable */ + editable = GWA_GET_CLASS (GTK_TYPE_WIDGET)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_image_editor_new (adaptor, editable); + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_image_editor_new (adaptor, editable); - return editable; + return editable; } /* ----------------------------- GtkMenu ------------------------------ */ GObject * -glade_gtk_menu_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) +glade_gtk_menu_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam * construct_properties) { - GladeWidgetAdaptor *adaptor; - GObject *ret_obj; - - ret_obj = GWA_GET_OCLASS(GTK_TYPE_CONTAINER)->constructor - (type, n_construct_properties, construct_properties); + GladeWidgetAdaptor *adaptor; + GObject *ret_obj; - adaptor = GLADE_WIDGET_ADAPTOR (ret_obj); + ret_obj = GWA_GET_OCLASS (GTK_TYPE_CONTAINER)->constructor + (type, n_construct_properties, construct_properties); - glade_widget_adaptor_action_remove (adaptor, "add_parent"); - glade_widget_adaptor_action_remove (adaptor, "remove_parent"); + adaptor = GLADE_WIDGET_ADAPTOR (ret_obj); - return ret_obj; + glade_widget_adaptor_action_remove (adaptor, "add_parent"); + glade_widget_adaptor_action_remove (adaptor, "remove_parent"); + + return ret_obj; } /* ----------------------------- GtkMenuShell ------------------------------ */ void -glade_gtk_menu_shell_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_menu_shell_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - - g_return_if_fail (GTK_IS_MENU_SHELL (object)); - g_return_if_fail (GTK_IS_MENU_ITEM (child)); - gtk_menu_shell_append (GTK_MENU_SHELL (object), GTK_WIDGET (child)); + g_return_if_fail (GTK_IS_MENU_SHELL (object)); + g_return_if_fail (GTK_IS_MENU_ITEM (child)); + + gtk_menu_shell_append (GTK_MENU_SHELL (object), GTK_WIDGET (child)); } void -glade_gtk_menu_shell_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_menu_shell_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_MENU_SHELL (object)); - g_return_if_fail (GTK_IS_MENU_ITEM (child)); - - gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); + g_return_if_fail (GTK_IS_MENU_SHELL (object)); + g_return_if_fail (GTK_IS_MENU_ITEM (child)); + + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); } static gint -glade_gtk_menu_shell_get_item_position (GObject *container, GObject *child) -{ - gint position = 0; - GList *list = gtk_container_get_children (GTK_CONTAINER (container)); - - while (list) - { - if (G_OBJECT (list->data) == child) break; - - list = list->next; - position++; - } - - g_list_free (list); - - return position; -} - -void -glade_gtk_menu_shell_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GTK_IS_MENU_SHELL (container)); - g_return_if_fail (GTK_IS_MENU_ITEM (child)); - - if (strcmp (property_name, "position") == 0) - { - g_value_set_int (value, - glade_gtk_menu_shell_get_item_position (container, - child)); - } - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_get_property (adaptor, - container, - child, - property_name, - value); -} - -void -glade_gtk_menu_shell_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GTK_IS_MENU_SHELL (container)); - g_return_if_fail (GTK_IS_MENU_ITEM (child)); - g_return_if_fail (property_name != NULL || value != NULL); - - if (strcmp (property_name, "position") == 0) - { - GladeWidget *gitem; - gint position; - - gitem = glade_widget_get_from_gobject (child); - g_return_if_fail (GLADE_IS_WIDGET (gitem)); - - position = g_value_get_int (value); - - if (position < 0) - { - position = glade_gtk_menu_shell_get_item_position (container, child); - g_value_set_int (value, position); - } - - g_object_ref (child); - gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (child)); - gtk_menu_shell_insert (GTK_MENU_SHELL (container), GTK_WIDGET (child), position); - g_object_unref (child); - - } - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, child, - property_name, value); +glade_gtk_menu_shell_get_item_position (GObject * container, GObject * child) +{ + gint position = 0; + GList *list = gtk_container_get_children (GTK_CONTAINER (container)); + + while (list) + { + if (G_OBJECT (list->data) == child) + break; + + list = list->next; + position++; + } + + g_list_free (list); + + return position; +} + +void +glade_gtk_menu_shell_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) +{ + g_return_if_fail (GTK_IS_MENU_SHELL (container)); + g_return_if_fail (GTK_IS_MENU_ITEM (child)); + + if (strcmp (property_name, "position") == 0) + { + g_value_set_int (value, + glade_gtk_menu_shell_get_item_position (container, + child)); + } + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_get_property (adaptor, + container, + child, property_name, value); +} + +void +glade_gtk_menu_shell_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) +{ + g_return_if_fail (GTK_IS_MENU_SHELL (container)); + g_return_if_fail (GTK_IS_MENU_ITEM (child)); + g_return_if_fail (property_name != NULL || value != NULL); + + if (strcmp (property_name, "position") == 0) + { + GladeWidget *gitem; + gint position; + + gitem = glade_widget_get_from_gobject (child); + g_return_if_fail (GLADE_IS_WIDGET (gitem)); + + position = g_value_get_int (value); + + if (position < 0) + { + position = glade_gtk_menu_shell_get_item_position (container, child); + g_value_set_int (value, position); + } + + g_object_ref (child); + gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (child)); + gtk_menu_shell_insert (GTK_MENU_SHELL (container), GTK_WIDGET (child), + position); + g_object_unref (child); + + } + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, child, + property_name, value); } static gchar * -glade_gtk_menu_shell_tool_item_get_display_name (GladeBaseEditor *editor, - GladeWidget *gchild, - gpointer user_data) -{ - GObject *child = glade_widget_get_object (gchild); - gchar *name; - - if (GTK_IS_SEPARATOR_MENU_ITEM (child) || - GTK_IS_SEPARATOR_TOOL_ITEM (child)) - name = _("<separator>"); - else if (GTK_IS_MENU_ITEM (child)) - glade_widget_property_get (gchild, "label", &name); - else if (GTK_IS_TOOL_BUTTON (child)) - { - glade_widget_property_get (gchild, "label", &name); - if (name == NULL || strlen (name) == 0) - glade_widget_property_get (gchild, "stock-id", &name); - } - else - name = _("<custom>"); - - return g_strdup (name); +glade_gtk_menu_shell_tool_item_get_display_name (GladeBaseEditor * editor, + GladeWidget * gchild, + gpointer user_data) +{ + GObject *child = glade_widget_get_object (gchild); + gchar *name; + + if (GTK_IS_SEPARATOR_MENU_ITEM (child) || GTK_IS_SEPARATOR_TOOL_ITEM (child)) + name = _("<separator>"); + else if (GTK_IS_MENU_ITEM (child)) + glade_widget_property_get (gchild, "label", &name); + else if (GTK_IS_TOOL_BUTTON (child)) + { + glade_widget_property_get (gchild, "label", &name); + if (name == NULL || strlen (name) == 0) + glade_widget_property_get (gchild, "stock-id", &name); + } + else + name = _("<custom>"); + + return g_strdup (name); } static GladeWidget * -glade_gtk_menu_shell_item_get_parent (GladeWidget *gparent, GObject *parent) -{ - GtkWidget *submenu = NULL; - - if (GTK_IS_MENU_TOOL_BUTTON (parent)) - submenu = gtk_menu_tool_button_get_menu (GTK_MENU_TOOL_BUTTON (parent)); - else if (GTK_IS_MENU_ITEM (parent)) - submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)); - - if (submenu) - gparent = glade_widget_get_from_gobject (submenu); - else - gparent = glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_MENU), - gparent, NULL, glade_widget_get_project (gparent)); - - return gparent; -} - -static GladeWidget * -glade_gtk_menu_shell_build_child (GladeBaseEditor *editor, - GladeWidget *gparent, - GType type, - gpointer data) -{ - GObject *parent = glade_widget_get_object (gparent); - GladeWidget *gitem_new; - - if (GTK_IS_SEPARATOR_MENU_ITEM (parent)) - return NULL; - - /* Get or build real parent */ - if (GTK_IS_MENU_ITEM (parent) || GTK_IS_MENU_TOOL_BUTTON (parent)) - gparent = glade_gtk_menu_shell_item_get_parent (gparent, parent); - - /* Build child */ - gitem_new = glade_command_create (glade_widget_adaptor_get_by_type (type), - gparent, NULL, - glade_widget_get_project (gparent)); - - if (type != GTK_TYPE_SEPARATOR_MENU_ITEM) - { - glade_widget_property_set (gitem_new, "label", - glade_widget_get_name (gitem_new)); - glade_widget_property_set (gitem_new, "use-underline", TRUE); - } - - return gitem_new; +glade_gtk_menu_shell_item_get_parent (GladeWidget * gparent, GObject * parent) +{ + GtkWidget *submenu = NULL; + + if (GTK_IS_MENU_TOOL_BUTTON (parent)) + submenu = gtk_menu_tool_button_get_menu (GTK_MENU_TOOL_BUTTON (parent)); + else if (GTK_IS_MENU_ITEM (parent)) + submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent)); + + if (submenu) + gparent = glade_widget_get_from_gobject (submenu); + else + gparent = + glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_MENU), + gparent, NULL, + glade_widget_get_project (gparent)); + + return gparent; +} + +static GladeWidget * +glade_gtk_menu_shell_build_child (GladeBaseEditor * editor, + GladeWidget * gparent, + GType type, gpointer data) +{ + GObject *parent = glade_widget_get_object (gparent); + GladeWidget *gitem_new; + + if (GTK_IS_SEPARATOR_MENU_ITEM (parent)) + return NULL; + + /* Get or build real parent */ + if (GTK_IS_MENU_ITEM (parent) || GTK_IS_MENU_TOOL_BUTTON (parent)) + gparent = glade_gtk_menu_shell_item_get_parent (gparent, parent); + + /* Build child */ + gitem_new = glade_command_create (glade_widget_adaptor_get_by_type (type), + gparent, NULL, + glade_widget_get_project (gparent)); + + if (type != GTK_TYPE_SEPARATOR_MENU_ITEM) + { + glade_widget_property_set (gitem_new, "label", + glade_widget_get_name (gitem_new)); + glade_widget_property_set (gitem_new, "use-underline", TRUE); + } + + return gitem_new; } static gboolean -glade_gtk_menu_shell_delete_child (GladeBaseEditor *editor, - GladeWidget *gparent, - GladeWidget *gchild, - gpointer data) -{ - GObject *item = glade_widget_get_object (gparent); - GtkWidget *submenu = NULL; - GList list = {0, }; - gint n_children = 0; - - if (GTK_IS_MENU_ITEM (item) && - (submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))) - { - GList *l = gtk_container_get_children (GTK_CONTAINER (submenu)); - n_children = g_list_length (l); - g_list_free (l); - } - - if (submenu && n_children == 1) - list.data = glade_widget_get_parent (gchild); - else - list.data = gchild; - - /* Remove widget */ - glade_command_delete (&list); - - return TRUE; +glade_gtk_menu_shell_delete_child (GladeBaseEditor * editor, + GladeWidget * gparent, + GladeWidget * gchild, gpointer data) +{ + GObject *item = glade_widget_get_object (gparent); + GtkWidget *submenu = NULL; + GList list = { 0, }; + gint n_children = 0; + + if (GTK_IS_MENU_ITEM (item) && + (submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))) + { + GList *l = gtk_container_get_children (GTK_CONTAINER (submenu)); + n_children = g_list_length (l); + g_list_free (l); + } + + if (submenu && n_children == 1) + list.data = glade_widget_get_parent (gchild); + else + list.data = gchild; + + /* Remove widget */ + glade_command_delete (&list); + + return TRUE; } static gboolean -glade_gtk_menu_shell_move_child (GladeBaseEditor *editor, - GladeWidget *gparent, - GladeWidget *gchild, - gpointer data) -{ - GObject *parent = glade_widget_get_object (gparent); - GObject *child = glade_widget_get_object (gchild); - GladeWidget *old_parent = gchild->parent; - GList list = {0, }; - - if (GTK_IS_SEPARATOR_MENU_ITEM (parent) || - GTK_IS_SEPARATOR_TOOL_ITEM (parent)) - return FALSE; - - if (GTK_IS_MENU_ITEM (child) && GTK_IS_TOOLBAR (parent)) - return FALSE; - - if (GTK_IS_TOOL_ITEM (child) && - (GTK_IS_MENU (parent) || GTK_IS_MENU_BAR (parent) || GTK_IS_MENU_ITEM (parent))) - return FALSE; - - if (GTK_IS_TOOL_ITEM (parent) && - (!GTK_IS_MENU_TOOL_BUTTON (parent) || !GTK_IS_MENU_ITEM (child))) - return FALSE; - - if (GTK_IS_MENU_ITEM (parent) || GTK_IS_MENU_TOOL_BUTTON (parent)) - gparent = glade_gtk_menu_shell_item_get_parent (gparent, parent); - - if (gparent != glade_widget_get_parent (gchild)) - { - list.data = gchild; - glade_command_dnd (&list, gparent, NULL); - } - - /* Delete dangling childless menus */ - if (GTK_IS_MENU (old_parent->object) && - old_parent->parent && GTK_IS_MENU_ITEM (old_parent->parent->object)) - { - GList del = { 0, }, *children; - - children = gtk_container_get_children (GTK_CONTAINER (old_parent->object)); - if (!children) - { - del.data = old_parent; - glade_command_delete (&del); - } - g_list_free (children); - } - - return TRUE; +glade_gtk_menu_shell_move_child (GladeBaseEditor * editor, + GladeWidget * gparent, + GladeWidget * gchild, gpointer data) +{ + GObject *parent = glade_widget_get_object (gparent); + GObject *child = glade_widget_get_object (gchild); + GladeWidget *old_parent = gchild->parent; + GList list = { 0, }; + + if (GTK_IS_SEPARATOR_MENU_ITEM (parent) || + GTK_IS_SEPARATOR_TOOL_ITEM (parent)) + return FALSE; + + if (GTK_IS_MENU_ITEM (child) && GTK_IS_TOOLBAR (parent)) + return FALSE; + + if (GTK_IS_TOOL_ITEM (child) && + (GTK_IS_MENU (parent) || GTK_IS_MENU_BAR (parent) || + GTK_IS_MENU_ITEM (parent))) + return FALSE; + + if (GTK_IS_TOOL_ITEM (parent) && + (!GTK_IS_MENU_TOOL_BUTTON (parent) || !GTK_IS_MENU_ITEM (child))) + return FALSE; + + if (GTK_IS_MENU_ITEM (parent) || GTK_IS_MENU_TOOL_BUTTON (parent)) + gparent = glade_gtk_menu_shell_item_get_parent (gparent, parent); + + if (gparent != glade_widget_get_parent (gchild)) + { + list.data = gchild; + glade_command_dnd (&list, gparent, NULL); + } + + /* Delete dangling childless menus */ + if (GTK_IS_MENU (old_parent->object) && + old_parent->parent && GTK_IS_MENU_ITEM (old_parent->parent->object)) + { + GList del = { 0, } + , *children; + + children = + gtk_container_get_children (GTK_CONTAINER (old_parent->object)); + if (!children) + { + del.data = old_parent; + glade_command_delete (&del); + } + g_list_free (children); + } + + return TRUE; } static gboolean -glade_gtk_menu_shell_change_type (GladeBaseEditor *editor, - GladeWidget *gchild, - GType type, - gpointer data) -{ - GObject *child = glade_widget_get_object (gchild); - - - if ((type == GTK_TYPE_SEPARATOR_MENU_ITEM && - gtk_menu_item_get_submenu (GTK_MENU_ITEM (child))) || - (GTK_IS_MENU_TOOL_BUTTON (child) && - gtk_menu_tool_button_get_menu (GTK_MENU_TOOL_BUTTON (child)))) - return TRUE; - - /* Delete the internal image of an image menu item before going ahead and changing types. */ - if (GTK_IS_IMAGE_MENU_ITEM (child)) - { - GList list = { 0, }; - GtkWidget *image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (child)); - GladeWidget *widget; - - if (image && (widget = glade_widget_get_from_gobject (image))) - { - list.data = widget; - glade_command_unlock_widget (widget); - glade_command_delete (&list); - } - } - - return FALSE; +glade_gtk_menu_shell_change_type (GladeBaseEditor * editor, + GladeWidget * gchild, + GType type, gpointer data) +{ + GObject *child = glade_widget_get_object (gchild); + + + if ((type == GTK_TYPE_SEPARATOR_MENU_ITEM && + gtk_menu_item_get_submenu (GTK_MENU_ITEM (child))) || + (GTK_IS_MENU_TOOL_BUTTON (child) && + gtk_menu_tool_button_get_menu (GTK_MENU_TOOL_BUTTON (child)))) + return TRUE; + + /* Delete the internal image of an image menu item before going ahead and changing types. */ + if (GTK_IS_IMAGE_MENU_ITEM (child)) + { + GList list = { 0, }; + GtkWidget *image = + gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (child)); + GladeWidget *widget; + + if (image && (widget = glade_widget_get_from_gobject (image))) + { + list.data = widget; + glade_command_unlock_widget (widget); + glade_command_delete (&list); + } + } + + return FALSE; } static void -glade_gtk_toolbar_child_selected (GladeBaseEditor *editor, - GladeWidget *gchild, - gpointer data) +glade_gtk_toolbar_child_selected (GladeBaseEditor * editor, + GladeWidget * gchild, gpointer data) { - GObject *child = glade_widget_get_object (gchild); - GType type = G_OBJECT_TYPE (child); - - glade_base_editor_add_label (editor, _("Tool Item")); - - glade_base_editor_add_default_properties (editor, gchild); - - glade_base_editor_add_label (editor, _("Properties")); - glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL); - - if (type == GTK_TYPE_SEPARATOR_TOOL_ITEM) return; + GObject *child = glade_widget_get_object (gchild); + GType type = G_OBJECT_TYPE (child); + + glade_base_editor_add_label (editor, _("Tool Item")); + + glade_base_editor_add_default_properties (editor, gchild); + + glade_base_editor_add_label (editor, _("Properties")); + glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL); - glade_base_editor_add_label (editor, _("Packing")); - glade_base_editor_add_properties (editor, gchild, TRUE, - "expand", "homogeneous", NULL); + if (type == GTK_TYPE_SEPARATOR_TOOL_ITEM) + return; + + glade_base_editor_add_label (editor, _("Packing")); + glade_base_editor_add_properties (editor, gchild, TRUE, + "expand", "homogeneous", NULL); } static void -glade_gtk_menu_shell_tool_item_child_selected (GladeBaseEditor *editor, - GladeWidget *gchild, - gpointer data) -{ - GObject *child = glade_widget_get_object (gchild); - GType type = G_OBJECT_TYPE (child); - - if (GTK_IS_TOOL_ITEM (child)) - { - glade_gtk_toolbar_child_selected (editor, gchild, data); - return; - } - glade_base_editor_add_label (editor, _("Menu Item")); - - glade_base_editor_add_default_properties (editor, gchild); - - if (GTK_IS_SEPARATOR_MENU_ITEM (child)) return; - - glade_base_editor_add_label (editor, _("Properties")); - - if (type != GTK_TYPE_IMAGE_MENU_ITEM) - glade_base_editor_add_properties (editor, gchild, FALSE, "label", "tooltip", NULL); - - if (type == GTK_TYPE_IMAGE_MENU_ITEM) - glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL); - else if (type == GTK_TYPE_CHECK_MENU_ITEM) - glade_base_editor_add_properties (editor, gchild, FALSE, - "active", "draw-as-radio", - "inconsistent", NULL); - else if (type == GTK_TYPE_RADIO_MENU_ITEM) - glade_base_editor_add_properties (editor, gchild, FALSE, - "active", "group", NULL); +glade_gtk_menu_shell_tool_item_child_selected (GladeBaseEditor * editor, + GladeWidget * gchild, + gpointer data) +{ + GObject *child = glade_widget_get_object (gchild); + GType type = G_OBJECT_TYPE (child); + + if (GTK_IS_TOOL_ITEM (child)) + { + glade_gtk_toolbar_child_selected (editor, gchild, data); + return; + } + glade_base_editor_add_label (editor, _("Menu Item")); + + glade_base_editor_add_default_properties (editor, gchild); + + if (GTK_IS_SEPARATOR_MENU_ITEM (child)) + return; + + glade_base_editor_add_label (editor, _("Properties")); + + if (type != GTK_TYPE_IMAGE_MENU_ITEM) + glade_base_editor_add_properties (editor, gchild, FALSE, "label", "tooltip", + NULL); + + if (type == GTK_TYPE_IMAGE_MENU_ITEM) + glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL); + else if (type == GTK_TYPE_CHECK_MENU_ITEM) + glade_base_editor_add_properties (editor, gchild, FALSE, + "active", "draw-as-radio", + "inconsistent", NULL); + else if (type == GTK_TYPE_RADIO_MENU_ITEM) + glade_base_editor_add_properties (editor, gchild, FALSE, + "active", "group", NULL); } static void -glade_gtk_menu_shell_launch_editor (GObject *object, gchar *title) -{ - GladeBaseEditor *editor; - GtkWidget *window; - - /* Editor */ - editor = glade_base_editor_new (object, NULL, - _("Normal item"), GTK_TYPE_MENU_ITEM, - _("Image item"), GTK_TYPE_IMAGE_MENU_ITEM, - _("Check item"), GTK_TYPE_CHECK_MENU_ITEM, - _("Radio item"), GTK_TYPE_RADIO_MENU_ITEM, - _("Separator item"), GTK_TYPE_SEPARATOR_MENU_ITEM, - NULL); - - glade_base_editor_append_types (editor, GTK_TYPE_MENU_ITEM, - _("Normal item"), GTK_TYPE_MENU_ITEM, - _("Image item"), GTK_TYPE_IMAGE_MENU_ITEM, - _("Check item"), GTK_TYPE_CHECK_MENU_ITEM, - _("Radio item"), GTK_TYPE_RADIO_MENU_ITEM, - _("Separator item"), GTK_TYPE_SEPARATOR_MENU_ITEM, - NULL); - - g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_menu_shell_tool_item_get_display_name), NULL); - g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_menu_shell_tool_item_child_selected), NULL); - g_signal_connect (editor, "change-type", G_CALLBACK (glade_gtk_menu_shell_change_type), NULL); - g_signal_connect (editor, "build-child", G_CALLBACK (glade_gtk_menu_shell_build_child), NULL); - g_signal_connect (editor, "delete-child", G_CALLBACK (glade_gtk_menu_shell_delete_child), NULL); - g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_menu_shell_move_child), NULL); - - gtk_widget_show (GTK_WIDGET (editor)); - - window = glade_base_editor_pack_new_window (editor, title, NULL); - gtk_widget_show (window); -} - -void -glade_gtk_menu_shell_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) -{ - if (strcmp (action_path, "launch_editor") == 0) - { - if (GTK_IS_MENU_BAR (object)) - glade_gtk_menu_shell_launch_editor (object, _("Edit Menu Bar")); - else if (GTK_IS_MENU (object)) - glade_gtk_menu_shell_launch_editor (object, _("Edit Menu")); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, - object, - action_path); - - gtk_menu_shell_deactivate (GTK_MENU_SHELL (object)); +glade_gtk_menu_shell_launch_editor (GObject * object, gchar * title) +{ + GladeBaseEditor *editor; + GtkWidget *window; + + /* Editor */ + editor = glade_base_editor_new (object, NULL, + _("Normal item"), GTK_TYPE_MENU_ITEM, + _("Image item"), GTK_TYPE_IMAGE_MENU_ITEM, + _("Check item"), GTK_TYPE_CHECK_MENU_ITEM, + _("Radio item"), GTK_TYPE_RADIO_MENU_ITEM, + _("Separator item"), + GTK_TYPE_SEPARATOR_MENU_ITEM, NULL); + + glade_base_editor_append_types (editor, GTK_TYPE_MENU_ITEM, + _("Normal item"), GTK_TYPE_MENU_ITEM, + _("Image item"), GTK_TYPE_IMAGE_MENU_ITEM, + _("Check item"), GTK_TYPE_CHECK_MENU_ITEM, + _("Radio item"), GTK_TYPE_RADIO_MENU_ITEM, + _("Separator item"), + GTK_TYPE_SEPARATOR_MENU_ITEM, NULL); + + g_signal_connect (editor, "get-display-name", + G_CALLBACK + (glade_gtk_menu_shell_tool_item_get_display_name), NULL); + g_signal_connect (editor, "child-selected", + G_CALLBACK (glade_gtk_menu_shell_tool_item_child_selected), + NULL); + g_signal_connect (editor, "change-type", + G_CALLBACK (glade_gtk_menu_shell_change_type), NULL); + g_signal_connect (editor, "build-child", + G_CALLBACK (glade_gtk_menu_shell_build_child), NULL); + g_signal_connect (editor, "delete-child", + G_CALLBACK (glade_gtk_menu_shell_delete_child), NULL); + g_signal_connect (editor, "move-child", + G_CALLBACK (glade_gtk_menu_shell_move_child), NULL); + + gtk_widget_show (GTK_WIDGET (editor)); + + window = glade_base_editor_pack_new_window (editor, title, NULL); + gtk_widget_show (window); +} + +void +glade_gtk_menu_shell_action_activate (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * action_path) +{ + if (strcmp (action_path, "launch_editor") == 0) + { + if (GTK_IS_MENU_BAR (object)) + glade_gtk_menu_shell_launch_editor (object, _("Edit Menu Bar")); + else if (GTK_IS_MENU (object)) + glade_gtk_menu_shell_launch_editor (object, _("Edit Menu")); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, + object, action_path); + + gtk_menu_shell_deactivate (GTK_MENU_SHELL (object)); } /* ----------------------------- GtkMenuItem ------------------------------ */ /* ... shared with toolitems ... */ GladeEditable * -glade_gtk_activatable_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_activatable_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); + /* Get base editable */ + editable = + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_activatable_editor_new (adaptor, editable); + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_activatable_editor_new (adaptor, editable); - return editable; + return editable; } void -glade_gtk_menu_item_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) +glade_gtk_menu_item_action_activate (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * action_path) { - GObject *obj = NULL, *shell = NULL; - GladeWidget *w = glade_widget_get_from_gobject (object); - - while ((w = glade_widget_get_parent (w))) - { - obj = glade_widget_get_object (w); - if (GTK_IS_MENU_SHELL (obj)) shell = obj; - } + GObject *obj = NULL, *shell = NULL; + GladeWidget *w = glade_widget_get_from_gobject (object); + + while ((w = glade_widget_get_parent (w))) + { + obj = glade_widget_get_object (w); + if (GTK_IS_MENU_SHELL (obj)) + shell = obj; + } - if (strcmp (action_path, "launch_editor") == 0) - { - if (shell) - object = shell; + if (strcmp (action_path, "launch_editor") == 0) + { + if (shell) + object = shell; - if (GTK_IS_MENU_BAR (object)) - glade_gtk_menu_shell_launch_editor (object, _("Edit Menu Bar")); - else if (GTK_IS_MENU (object)) - glade_gtk_menu_shell_launch_editor (object, _("Edit Menu")); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, - object, - action_path); + if (GTK_IS_MENU_BAR (object)) + glade_gtk_menu_shell_launch_editor (object, _("Edit Menu Bar")); + else if (GTK_IS_MENU (object)) + glade_gtk_menu_shell_launch_editor (object, _("Edit Menu")); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, + object, action_path); - if (shell) - gtk_menu_shell_deactivate (GTK_MENU_SHELL (shell)); + if (shell) + gtk_menu_shell_deactivate (GTK_MENU_SHELL (shell)); } GObject * -glade_gtk_menu_item_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) +glade_gtk_menu_item_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam * construct_properties) { - GladeWidgetAdaptor *adaptor; - GObject *ret_obj; + GladeWidgetAdaptor *adaptor; + GObject *ret_obj; - ret_obj = GWA_GET_OCLASS(GTK_TYPE_CONTAINER)->constructor - (type, n_construct_properties, construct_properties); + ret_obj = GWA_GET_OCLASS (GTK_TYPE_CONTAINER)->constructor + (type, n_construct_properties, construct_properties); - adaptor = GLADE_WIDGET_ADAPTOR (ret_obj); + adaptor = GLADE_WIDGET_ADAPTOR (ret_obj); - glade_widget_adaptor_action_remove (adaptor, "add_parent"); - glade_widget_adaptor_action_remove (adaptor, "remove_parent"); + glade_widget_adaptor_action_remove (adaptor, "add_parent"); + glade_widget_adaptor_action_remove (adaptor, "remove_parent"); - return ret_obj; + return ret_obj; } void -glade_gtk_menu_item_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_menu_item_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *gitem; + GladeWidget *gitem; + + gitem = glade_widget_get_from_gobject (object); - gitem = glade_widget_get_from_gobject (object); - - if (GTK_IS_SEPARATOR_MENU_ITEM (object)) return; - - if (gtk_bin_get_child (GTK_BIN (object)) == NULL) - { - GtkWidget *label = gtk_label_new (""); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (object), label); - } + if (GTK_IS_SEPARATOR_MENU_ITEM (object)) + return; + + if (gtk_bin_get_child (GTK_BIN (object)) == NULL) + { + GtkWidget *label = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_container_add (GTK_CONTAINER (object), label); + } } GList * -glade_gtk_menu_item_get_children (GladeWidgetAdaptor *adaptor, - GObject *object) +glade_gtk_menu_item_get_children (GladeWidgetAdaptor * adaptor, + GObject * object) { - GList *list = NULL; - GtkWidget *child; - - g_return_val_if_fail (GTK_IS_MENU_ITEM (object), NULL); - - if ((child = gtk_menu_item_get_submenu (GTK_MENU_ITEM (object)))) - list = g_list_append (list, child); + GList *list = NULL; + GtkWidget *child; + + g_return_val_if_fail (GTK_IS_MENU_ITEM (object), NULL); - return list; + if ((child = gtk_menu_item_get_submenu (GTK_MENU_ITEM (object)))) + list = g_list_append (list, child); + + return list; } void -glade_gtk_menu_item_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, GObject *child) +glade_gtk_menu_item_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_MENU_ITEM (object)); - g_return_if_fail (GTK_IS_MENU (child)); - - if (GTK_IS_SEPARATOR_MENU_ITEM (object)) - { - g_warning ("You shouldn't try to add a GtkMenu to a GtkSeparatorMenuItem"); - return; - } - - g_object_set_data (child, - "special-child-type", - "submenu"); + g_return_if_fail (GTK_IS_MENU_ITEM (object)); + g_return_if_fail (GTK_IS_MENU (child)); + + if (GTK_IS_SEPARATOR_MENU_ITEM (object)) + { + g_warning + ("You shouldn't try to add a GtkMenu to a GtkSeparatorMenuItem"); + return; + } - gtk_menu_item_set_submenu (GTK_MENU_ITEM (object), GTK_WIDGET (child)); + g_object_set_data (child, "special-child-type", "submenu"); + + gtk_menu_item_set_submenu (GTK_MENU_ITEM (object), GTK_WIDGET (child)); } void -glade_gtk_menu_item_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, GObject *child) +glade_gtk_menu_item_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_MENU_ITEM (object)); - g_return_if_fail (GTK_IS_MENU (child)); - - gtk_menu_item_set_submenu (GTK_MENU_ITEM (object), NULL); + g_return_if_fail (GTK_IS_MENU_ITEM (object)); + g_return_if_fail (GTK_IS_MENU (child)); + + gtk_menu_item_set_submenu (GTK_MENU_ITEM (object), NULL); } static void -glade_gtk_menu_item_set_label (GObject *object, const GValue *value) +glade_gtk_menu_item_set_label (GObject * object, const GValue * value) { - GladeWidget *gitem; - GtkWidget *label; - gboolean use_underline; + GladeWidget *gitem; + GtkWidget *label; + gboolean use_underline; - gitem = glade_widget_get_from_gobject (object); + gitem = glade_widget_get_from_gobject (object); - label = gtk_bin_get_child (GTK_BIN (object)); - gtk_label_set_text (GTK_LABEL (label), g_value_get_string (value)); + label = gtk_bin_get_child (GTK_BIN (object)); + gtk_label_set_text (GTK_LABEL (label), g_value_get_string (value)); - /* Update underline incase... */ - glade_widget_property_get (gitem, "use-underline", &use_underline); - gtk_label_set_use_underline (GTK_LABEL (label), use_underline); + /* Update underline incase... */ + glade_widget_property_get (gitem, "use-underline", &use_underline); + gtk_label_set_use_underline (GTK_LABEL (label), use_underline); } static void -glade_gtk_menu_item_set_use_underline (GObject *object, const GValue *value) +glade_gtk_menu_item_set_use_underline (GObject * object, const GValue * value) { - GtkWidget *label; + GtkWidget *label; - label = gtk_bin_get_child (GTK_BIN (object)); - gtk_label_set_use_underline (GTK_LABEL (label), g_value_get_boolean (value)); + label = gtk_bin_get_child (GTK_BIN (object)); + gtk_label_set_use_underline (GTK_LABEL (label), g_value_get_boolean (value)); } void -glade_gtk_menu_item_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_menu_item_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - GladeProperty *property = glade_widget_get_property (gwidget, id); - - evaluate_activatable_property_sensitivity (object, id, value); + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GladeProperty *property = glade_widget_get_property (gwidget, id); + + evaluate_activatable_property_sensitivity (object, id, value); - if (!strcmp (id, "use-underline")) - glade_gtk_menu_item_set_use_underline (object, value); - else if (!strcmp (id, "label")) - glade_gtk_menu_item_set_label (object, value); - else if (GPC_VERSION_CHECK (property->klass, gtk_major_version, gtk_minor_version + 1)) - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, - id, value); + if (!strcmp (id, "use-underline")) + glade_gtk_menu_item_set_use_underline (object, value); + else if (!strcmp (id, "label")) + glade_gtk_menu_item_set_label (object, value); + else if (GPC_VERSION_CHECK + (property->klass, gtk_major_version, gtk_minor_version + 1)) + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, + value); } /* ----------------------------- GtkImageMenuItem ------------------------------ */ GList * -glade_gtk_image_menu_item_get_children (GladeWidgetAdaptor *adaptor, - GObject *object) +glade_gtk_image_menu_item_get_children (GladeWidgetAdaptor * adaptor, + GObject * object) { - GList *list = NULL; - GtkWidget *child; - GladeWidget *gitem; - - gitem = glade_widget_get_from_gobject (object); - - if ((child = gtk_menu_item_get_submenu (GTK_MENU_ITEM (object)))) - list = g_list_append (list, child); - - return list; + GList *list = NULL; + GtkWidget *child; + GladeWidget *gitem; + + gitem = glade_widget_get_from_gobject (object); + + if ((child = gtk_menu_item_get_submenu (GTK_MENU_ITEM (object)))) + list = g_list_append (list, child); + + return list; } void -glade_gtk_image_menu_item_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, GObject *child) +glade_gtk_image_menu_item_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_MENU_ITEM (object)); + g_return_if_fail (GTK_IS_MENU_ITEM (object)); - if (GTK_IS_IMAGE (child)) - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (object), GTK_WIDGET (child)); - else - GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->add (adaptor, object, child); + if (GTK_IS_IMAGE (child)) + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (object), + GTK_WIDGET (child)); + else + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->add (adaptor, object, child); } void -glade_gtk_image_menu_item_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, GObject *child) +glade_gtk_image_menu_item_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - g_return_if_fail (GTK_IS_MENU_ITEM (object)); - - if (GTK_IS_IMAGE (child)) - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (object), NULL); - else - GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->remove (adaptor, object, child); + g_return_if_fail (GTK_IS_MENU_ITEM (object)); + + if (GTK_IS_IMAGE (child)) + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (object), NULL); + else + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->remove (adaptor, object, child); } static void -glade_gtk_image_menu_item_set_use_stock (GObject *object, const GValue *value) +glade_gtk_image_menu_item_set_use_stock (GObject * object, const GValue * value) { - GladeWidget *widget = glade_widget_get_from_gobject (object); - gboolean use_stock; - - use_stock = g_value_get_boolean (value); + GladeWidget *widget = glade_widget_get_from_gobject (object); + gboolean use_stock; - /* Set some things */ - if (use_stock) - { - glade_widget_property_set_sensitive (widget, "stock", TRUE, NULL); - glade_widget_property_set_sensitive (widget, "accel-group", TRUE, NULL); - } - else - { - glade_widget_property_set_sensitive (widget, "stock", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (widget, "accel-group", FALSE, NOT_SELECTED_MSG); - } + use_stock = g_value_get_boolean (value); - gtk_image_menu_item_set_use_stock (GTK_IMAGE_MENU_ITEM (object), use_stock); + /* Set some things */ + if (use_stock) + { + glade_widget_property_set_sensitive (widget, "stock", TRUE, NULL); + glade_widget_property_set_sensitive (widget, "accel-group", TRUE, NULL); + } + else + { + glade_widget_property_set_sensitive (widget, "stock", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (widget, "accel-group", FALSE, + NOT_SELECTED_MSG); + } - sync_use_appearance (widget); + gtk_image_menu_item_set_use_stock (GTK_IMAGE_MENU_ITEM (object), use_stock); + + sync_use_appearance (widget); } static gboolean -glade_gtk_image_menu_item_set_label (GObject *object, const GValue *value) +glade_gtk_image_menu_item_set_label (GObject * object, const GValue * value) { - GladeWidget *gitem; - GtkWidget *label; - gboolean use_underline = FALSE, use_stock = FALSE; - const gchar *text; + GladeWidget *gitem; + GtkWidget *label; + gboolean use_underline = FALSE, use_stock = FALSE; + const gchar *text; + + gitem = glade_widget_get_from_gobject (object); + label = gtk_bin_get_child (GTK_BIN (object)); - gitem = glade_widget_get_from_gobject (object); - label = gtk_bin_get_child (GTK_BIN (object)); + glade_widget_property_get (gitem, "use-stock", &use_stock); + glade_widget_property_get (gitem, "use-underline", &use_underline); + text = g_value_get_string (value); - glade_widget_property_get (gitem, "use-stock", &use_stock); - glade_widget_property_get (gitem, "use-underline", &use_underline); - text = g_value_get_string (value); + /* In "use-stock" mode we dont have a GladeWidget child image */ + if (use_stock) + { + GtkWidget *image; + GtkStockItem item; - /* In "use-stock" mode we dont have a GladeWidget child image */ - if (use_stock) - { - GtkWidget *image; - GtkStockItem item; + image = + gtk_image_new_from_stock (g_value_get_string (value), + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (object), image); - image = gtk_image_new_from_stock (g_value_get_string (value), GTK_ICON_SIZE_MENU); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (object), image); + if (use_underline) + gtk_label_set_use_underline (GTK_LABEL (label), TRUE); - if (use_underline) - gtk_label_set_use_underline (GTK_LABEL (label), TRUE); + /* Get the label string... */ + if (text && gtk_stock_lookup (text, &item)) + gtk_label_set_label (GTK_LABEL (label), item.label); + else + gtk_label_set_label (GTK_LABEL (label), text ? text : ""); - /* Get the label string... */ - if (text && gtk_stock_lookup (text, &item)) - gtk_label_set_label (GTK_LABEL (label), item.label); - else - gtk_label_set_label (GTK_LABEL (label), text ? text : ""); + return TRUE; + } - return TRUE; - } - - return FALSE; + return FALSE; } static void -glade_gtk_image_menu_item_set_stock (GObject *object, const GValue *value) +glade_gtk_image_menu_item_set_stock (GObject * object, const GValue * value) { - GladeWidget *gitem; - gboolean use_stock = FALSE; + GladeWidget *gitem; + gboolean use_stock = FALSE; - gitem = glade_widget_get_from_gobject (object); + gitem = glade_widget_get_from_gobject (object); - glade_widget_property_get (gitem, "use-stock", &use_stock); + glade_widget_property_get (gitem, "use-stock", &use_stock); - /* Forward the work along to the label handler... */ - if (use_stock) - glade_gtk_image_menu_item_set_label (object, value); + /* Forward the work along to the label handler... */ + if (use_stock) + glade_gtk_image_menu_item_set_label (object, value); } void -glade_gtk_image_menu_item_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_image_menu_item_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "stock")) - glade_gtk_image_menu_item_set_stock (object, value); - else if (!strcmp (id, "use-stock")) - glade_gtk_image_menu_item_set_use_stock (object, value); - else if (!strcmp (id, "label")) - { - if (!glade_gtk_image_menu_item_set_label (object, value)) - GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->set_property (adaptor, object, - id, value); - } - else - GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->set_property (adaptor, object, - id, value); + if (!strcmp (id, "stock")) + glade_gtk_image_menu_item_set_stock (object, value); + else if (!strcmp (id, "use-stock")) + glade_gtk_image_menu_item_set_use_stock (object, value); + else if (!strcmp (id, "label")) + { + if (!glade_gtk_image_menu_item_set_label (object, value)) + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->set_property (adaptor, object, + id, value); + } + else + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->set_property (adaptor, object, + id, value); } static void -glade_gtk_image_menu_item_parse_finished (GladeProject *project, - GladeWidget *widget) +glade_gtk_image_menu_item_parse_finished (GladeProject * project, + GladeWidget * widget) { - GladeWidget *gimage; - GtkWidget *image = NULL; - glade_widget_property_get (widget, "image", &image); - - if (image && (gimage = glade_widget_get_from_gobject (image))) - glade_widget_lock (widget, gimage); + GladeWidget *gimage; + GtkWidget *image = NULL; + glade_widget_property_get (widget, "image", &image); + + if (image && (gimage = glade_widget_get_from_gobject (image))) + glade_widget_lock (widget, gimage); } void -glade_gtk_image_menu_item_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_image_menu_item_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlNode * node) { - GladeProperty *property; - gboolean use_stock; - gchar *label = NULL; + GladeProperty *property; + gboolean use_stock; + gchar *label = NULL; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->read_widget (adaptor, widget, node); + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->read_widget (adaptor, widget, node); - glade_widget_property_get (widget, "use-stock", &use_stock); - if (use_stock) - { - property = glade_widget_get_property (widget, "label"); + glade_widget_property_get (widget, "use-stock", &use_stock); + if (use_stock) + { + property = glade_widget_get_property (widget, "label"); - glade_property_get (property, &label); - glade_widget_property_set (widget, "use-underline", TRUE); - glade_widget_property_set (widget, "stock", label); - glade_property_sync (property); - } + glade_property_get (property, &label); + glade_widget_property_set (widget, "use-underline", TRUE); + glade_widget_property_set (widget, "stock", label); + glade_property_sync (property); + } - /* Update sensitivity of related properties... */ - property = glade_widget_get_property (widget, "use-stock"); - glade_property_sync (property); + /* Update sensitivity of related properties... */ + property = glade_widget_get_property (widget, "use-stock"); + glade_property_sync (property); - /* Run this after the load so that image is resolved. */ - g_signal_connect (G_OBJECT (widget->project), "parse-finished", - G_CALLBACK (glade_gtk_image_menu_item_parse_finished), - widget); + /* Run this after the load so that image is resolved. */ + g_signal_connect (G_OBJECT (widget->project), "parse-finished", + G_CALLBACK (glade_gtk_image_menu_item_parse_finished), + widget); } void -glade_gtk_image_menu_item_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_image_menu_item_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeProperty *label_prop; - gboolean use_stock; - gchar *stock; + GladeProperty *label_prop; + gboolean use_stock; + gchar *stock; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* Make a copy of the GladeProperty, override its value if use-stock is TRUE */ - label_prop = glade_widget_get_property (widget, "label"); - label_prop = glade_property_dup (label_prop, widget); - glade_widget_property_get (widget, "use-stock", &use_stock); - if (use_stock) - { - glade_widget_property_get (widget, "stock", &stock); - glade_property_set (label_prop, stock); - glade_property_i18n_set_translatable (label_prop, FALSE); - } - glade_property_write (label_prop, context, node); - g_object_unref (G_OBJECT (label_prop)); + /* Make a copy of the GladeProperty, override its value if use-stock is TRUE */ + label_prop = glade_widget_get_property (widget, "label"); + label_prop = glade_property_dup (label_prop, widget); + glade_widget_property_get (widget, "use-stock", &use_stock); + if (use_stock) + { + glade_widget_property_get (widget, "stock", &stock); + glade_property_set (label_prop, stock); + glade_property_i18n_set_translatable (label_prop, FALSE); + } + glade_property_write (label_prop, context, node); + g_object_unref (G_OBJECT (label_prop)); - /* Chain up and write all the normal properties ... */ - GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->write_widget (adaptor, widget, context, node); + /* Chain up and write all the normal properties ... */ + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->write_widget (adaptor, widget, context, + node); } @@ -6864,1453 +6815,1503 @@ glade_gtk_image_menu_item_write_widget (GladeWidgetAdaptor *adaptor, */ GladeEditable * -glade_gtk_image_menu_item_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_image_menu_item_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->create_editable (adaptor, type); + /* Get base editable */ + editable = + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_image_item_editor_new (adaptor, editable); + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_image_item_editor_new (adaptor, editable); - return editable; + return editable; } /* ----------------------------- GtkRadioMenuItem ------------------------------ */ static void -glade_gtk_radio_menu_item_set_group (GObject *object, const GValue *value) +glade_gtk_radio_menu_item_set_group (GObject * object, const GValue * value) { - GObject *val; - - g_return_if_fail (GTK_IS_RADIO_MENU_ITEM (object)); - - if ((val = g_value_get_object (value))) - { - GSList *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (val)); - - if (! g_slist_find (group, GTK_RADIO_MENU_ITEM (object))) - gtk_radio_menu_item_set_group (GTK_RADIO_MENU_ITEM (object), group); - } + GObject *val; + + g_return_if_fail (GTK_IS_RADIO_MENU_ITEM (object)); + + if ((val = g_value_get_object (value))) + { + GSList *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (val)); + + if (!g_slist_find (group, GTK_RADIO_MENU_ITEM (object))) + gtk_radio_menu_item_set_group (GTK_RADIO_MENU_ITEM (object), group); + } } void -glade_gtk_radio_menu_item_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_radio_menu_item_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "group")) - glade_gtk_radio_menu_item_set_group (object, value); - else - GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->set_property (adaptor, object, - id, value); + if (!strcmp (id, "group")) + glade_gtk_radio_menu_item_set_group (object, value); + else + GWA_GET_CLASS (GTK_TYPE_MENU_ITEM)->set_property (adaptor, object, + id, value); } /* ----------------------------- GtkMenuBar ------------------------------ */ -static GladeWidget * -glade_gtk_menu_bar_append_new_submenu (GladeWidget *parent, GladeProject *project) -{ - static GladeWidgetAdaptor *submenu_adaptor = NULL; - GladeWidget *gsubmenu; - - if (submenu_adaptor == NULL) - submenu_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_MENU); - - gsubmenu = glade_widget_adaptor_create_widget (submenu_adaptor, FALSE, - "parent", parent, - "project", project, - NULL); - - glade_widget_add_child (parent, gsubmenu, FALSE); - - return gsubmenu; -} - -static GladeWidget * -glade_gtk_menu_bar_append_new_item (GladeWidget *parent, - GladeProject *project, - const gchar *label, - gboolean use_stock) -{ - static GladeWidgetAdaptor *item_adaptor = NULL, *image_item_adaptor, *separator_adaptor; - GladeWidget *gitem; - - if (item_adaptor == NULL) - { - item_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_MENU_ITEM); - image_item_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_IMAGE_MENU_ITEM); - separator_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_SEPARATOR_MENU_ITEM); - } - - if (label) - { - gitem = glade_widget_adaptor_create_widget ((use_stock) ? image_item_adaptor : item_adaptor, - FALSE, "parent", parent, - "project", project, - NULL); - - glade_widget_property_set (gitem, "use-underline", TRUE); - - if (use_stock) - { - glade_widget_property_set (gitem, "use-stock", TRUE); - glade_widget_property_set (gitem, "stock", label); - } - else - glade_widget_property_set (gitem, "label", label); - } - else - { - gitem = glade_widget_adaptor_create_widget (separator_adaptor, - FALSE, "parent", parent, - "project", project, - NULL); - } - - glade_widget_add_child (parent, gitem, FALSE); - - return gitem; -} - -void -glade_gtk_menu_bar_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) -{ - GladeProject *project; - GladeWidget *gmenubar, *gitem, *gsubmenu; - - g_return_if_fail (GTK_IS_MENU_BAR (object)); - gmenubar = glade_widget_get_from_gobject (object); - g_return_if_fail (GLADE_IS_WIDGET (gmenubar)); - - if (reason != GLADE_CREATE_USER) return; - - project = glade_widget_get_project (gmenubar); - - /* File */ - gitem = glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_File"), FALSE); - gsubmenu = glade_gtk_menu_bar_append_new_submenu (gitem, project); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-new", TRUE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-open", TRUE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-save", TRUE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-save-as", TRUE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, NULL, FALSE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-quit", TRUE); - - /* Edit */ - gitem = glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_Edit"), FALSE); - gsubmenu = glade_gtk_menu_bar_append_new_submenu (gitem, project); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-cut", TRUE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-copy", TRUE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-paste", TRUE); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-delete", TRUE); - - /* View */ - gitem = glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_View"), FALSE); - - /* Help */ - gitem = glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_Help"), FALSE); - gsubmenu = glade_gtk_menu_bar_append_new_submenu (gitem, project); - glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-about", TRUE); +static GladeWidget * +glade_gtk_menu_bar_append_new_submenu (GladeWidget * parent, + GladeProject * project) +{ + static GladeWidgetAdaptor *submenu_adaptor = NULL; + GladeWidget *gsubmenu; + + if (submenu_adaptor == NULL) + submenu_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_MENU); + + gsubmenu = glade_widget_adaptor_create_widget (submenu_adaptor, FALSE, + "parent", parent, + "project", project, NULL); + + glade_widget_add_child (parent, gsubmenu, FALSE); + + return gsubmenu; +} + +static GladeWidget * +glade_gtk_menu_bar_append_new_item (GladeWidget * parent, + GladeProject * project, + const gchar * label, gboolean use_stock) +{ + static GladeWidgetAdaptor *item_adaptor = + NULL, *image_item_adaptor, *separator_adaptor; + GladeWidget *gitem; + + if (item_adaptor == NULL) + { + item_adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_MENU_ITEM); + image_item_adaptor = + glade_widget_adaptor_get_by_type (GTK_TYPE_IMAGE_MENU_ITEM); + separator_adaptor = + glade_widget_adaptor_get_by_type (GTK_TYPE_SEPARATOR_MENU_ITEM); + } + + if (label) + { + gitem = + glade_widget_adaptor_create_widget ((use_stock) ? image_item_adaptor : + item_adaptor, FALSE, "parent", + parent, "project", project, NULL); + + glade_widget_property_set (gitem, "use-underline", TRUE); + + if (use_stock) + { + glade_widget_property_set (gitem, "use-stock", TRUE); + glade_widget_property_set (gitem, "stock", label); + } + else + glade_widget_property_set (gitem, "label", label); + } + else + { + gitem = glade_widget_adaptor_create_widget (separator_adaptor, + FALSE, "parent", parent, + "project", project, NULL); + } + + glade_widget_add_child (parent, gitem, FALSE); + + return gitem; +} + +void +glade_gtk_menu_bar_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) +{ + GladeProject *project; + GladeWidget *gmenubar, *gitem, *gsubmenu; + + g_return_if_fail (GTK_IS_MENU_BAR (object)); + gmenubar = glade_widget_get_from_gobject (object); + g_return_if_fail (GLADE_IS_WIDGET (gmenubar)); + + if (reason != GLADE_CREATE_USER) + return; + + project = glade_widget_get_project (gmenubar); + + /* File */ + gitem = + glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_File"), FALSE); + gsubmenu = glade_gtk_menu_bar_append_new_submenu (gitem, project); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-new", TRUE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-open", TRUE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-save", TRUE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-save-as", TRUE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, NULL, FALSE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-quit", TRUE); + + /* Edit */ + gitem = + glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_Edit"), FALSE); + gsubmenu = glade_gtk_menu_bar_append_new_submenu (gitem, project); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-cut", TRUE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-copy", TRUE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-paste", TRUE); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-delete", TRUE); + + /* View */ + gitem = + glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_View"), FALSE); + + /* Help */ + gitem = + glade_gtk_menu_bar_append_new_item (gmenubar, project, _("_Help"), FALSE); + gsubmenu = glade_gtk_menu_bar_append_new_submenu (gitem, project); + glade_gtk_menu_bar_append_new_item (gsubmenu, project, "gtk-about", TRUE); } /* ----------------------------- GtkToolBar ------------------------------ */ /* need to unset/reset toolbar style when property is disabled/enabled */ static void -property_toolbar_style_notify_enabled (GladeProperty *property, - GParamSpec *spec, - GtkToolbar *toolbar) -{ - GtkToolbarStyle style; - - if (glade_property_get_enabled (property)) - { - glade_property_get (property, &style); - gtk_toolbar_set_style (toolbar, style); - } - else - gtk_toolbar_unset_style (toolbar); -} - -void -glade_gtk_toolbar_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) -{ - GladeWidget *widget; - GladeProperty *toolbar_style_property; - - widget = glade_widget_get_from_gobject (object); - toolbar_style_property = glade_widget_get_property (widget, "toolbar-style"); - - g_signal_connect (toolbar_style_property, "notify::enabled", - G_CALLBACK (property_toolbar_style_notify_enabled), - object); -} - -void -glade_gtk_toolbar_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GTK_IS_TOOLBAR (container)); - if (GTK_IS_TOOL_ITEM (child) == FALSE) return; - - if (strcmp (property_name, "position") == 0) - { - g_value_set_int (value, - gtk_toolbar_get_item_index (GTK_TOOLBAR (container), - GTK_TOOL_ITEM (child))); - } - else - { /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_get_property (adaptor, - container, child, - property_name, value); - } -} - -void -glade_gtk_toolbar_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GTK_IS_TOOLBAR (container)); - g_return_if_fail (GTK_IS_TOOL_ITEM (child)); - - g_return_if_fail (property_name != NULL || value != NULL); - - if (strcmp (property_name, "position") == 0) - { - GtkToolbar *toolbar = GTK_TOOLBAR (container); - gint position, size; - - position = g_value_get_int (value); - size = gtk_toolbar_get_n_items (toolbar); - - if (position >= size) position = size - 1; - - g_object_ref (child); - gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (child)); - gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (child), position); - g_object_unref (child); - } - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, child, - property_name, value); -} - -void -glade_gtk_toolbar_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, GObject *child) -{ - GtkToolbar *toolbar; - GtkToolItem *item; - - g_return_if_fail (GTK_IS_TOOLBAR (object)); - g_return_if_fail (GTK_IS_TOOL_ITEM (child)); - - toolbar = GTK_TOOLBAR (object); - item = GTK_TOOL_ITEM (child); - - gtk_toolbar_insert (toolbar, item, -1); - - if (glade_util_object_is_loading (object)) - { - GladeWidget *gchild = glade_widget_get_from_gobject (child); - - /* Packing props arent around when parenting during a glade_widget_dup() */ - if (gchild && gchild->packing_properties) - glade_widget_pack_property_set (gchild, "position", - gtk_toolbar_get_item_index (toolbar, item)); - } -} - -void -glade_gtk_toolbar_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, GObject *child) -{ - gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); +property_toolbar_style_notify_enabled (GladeProperty * property, + GParamSpec * spec, GtkToolbar * toolbar) +{ + GtkToolbarStyle style; + + if (glade_property_get_enabled (property)) + { + glade_property_get (property, &style); + gtk_toolbar_set_style (toolbar, style); + } + else + gtk_toolbar_unset_style (toolbar); +} + +void +glade_gtk_toolbar_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) +{ + GladeWidget *widget; + GladeProperty *toolbar_style_property; + + widget = glade_widget_get_from_gobject (object); + toolbar_style_property = glade_widget_get_property (widget, "toolbar-style"); + + g_signal_connect (toolbar_style_property, "notify::enabled", + G_CALLBACK (property_toolbar_style_notify_enabled), object); +} + +void +glade_gtk_toolbar_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) +{ + g_return_if_fail (GTK_IS_TOOLBAR (container)); + if (GTK_IS_TOOL_ITEM (child) == FALSE) + return; + + if (strcmp (property_name, "position") == 0) + { + g_value_set_int (value, + gtk_toolbar_get_item_index (GTK_TOOLBAR (container), + GTK_TOOL_ITEM (child))); + } + else + { /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_get_property (adaptor, + container, child, + property_name, value); + } +} + +void +glade_gtk_toolbar_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) +{ + g_return_if_fail (GTK_IS_TOOLBAR (container)); + g_return_if_fail (GTK_IS_TOOL_ITEM (child)); + + g_return_if_fail (property_name != NULL || value != NULL); + + if (strcmp (property_name, "position") == 0) + { + GtkToolbar *toolbar = GTK_TOOLBAR (container); + gint position, size; + + position = g_value_get_int (value); + size = gtk_toolbar_get_n_items (toolbar); + + if (position >= size) + position = size - 1; + + g_object_ref (child); + gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (child)); + gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (child), position); + g_object_unref (child); + } + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, child, + property_name, value); +} + +void +glade_gtk_toolbar_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + GtkToolbar *toolbar; + GtkToolItem *item; + + g_return_if_fail (GTK_IS_TOOLBAR (object)); + g_return_if_fail (GTK_IS_TOOL_ITEM (child)); + + toolbar = GTK_TOOLBAR (object); + item = GTK_TOOL_ITEM (child); + + gtk_toolbar_insert (toolbar, item, -1); + + if (glade_util_object_is_loading (object)) + { + GladeWidget *gchild = glade_widget_get_from_gobject (child); + + /* Packing props arent around when parenting during a glade_widget_dup() */ + if (gchild && gchild->packing_properties) + glade_widget_pack_property_set (gchild, "position", + gtk_toolbar_get_item_index (toolbar, + item)); + } +} + +void +glade_gtk_toolbar_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) +{ + gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); } static void -glade_gtk_toolbar_launch_editor (GladeWidgetAdaptor *adaptor, - GObject *toolbar) -{ - GladeBaseEditor *editor; - GtkWidget *window; - - /* Editor */ - editor = glade_base_editor_new (toolbar, NULL, - _("Button"), GTK_TYPE_TOOL_BUTTON, - _("Toggle"), GTK_TYPE_TOGGLE_TOOL_BUTTON, - _("Radio"), GTK_TYPE_RADIO_TOOL_BUTTON, - _("Menu"), GTK_TYPE_MENU_TOOL_BUTTON, - _("Custom"), GTK_TYPE_TOOL_ITEM, - _("Separator"), GTK_TYPE_SEPARATOR_TOOL_ITEM, - NULL); - - - glade_base_editor_append_types (editor, GTK_TYPE_MENU_TOOL_BUTTON, - _("Normal"), GTK_TYPE_MENU_ITEM, - _("Image"), GTK_TYPE_IMAGE_MENU_ITEM, - _("Check"), GTK_TYPE_CHECK_MENU_ITEM, - _("Radio"), GTK_TYPE_RADIO_MENU_ITEM, - _("Separator"), GTK_TYPE_SEPARATOR_MENU_ITEM, - NULL); - - glade_base_editor_append_types (editor, GTK_TYPE_MENU_ITEM, - _("Normal"), GTK_TYPE_MENU_ITEM, - _("Image"), GTK_TYPE_IMAGE_MENU_ITEM, - _("Check"), GTK_TYPE_CHECK_MENU_ITEM, - _("Radio"), GTK_TYPE_RADIO_MENU_ITEM, - _("Separator"), GTK_TYPE_SEPARATOR_MENU_ITEM, - NULL); - - g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_menu_shell_tool_item_get_display_name), NULL); - g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_menu_shell_tool_item_child_selected), NULL); - g_signal_connect (editor, "change-type", G_CALLBACK (glade_gtk_menu_shell_change_type), NULL); - g_signal_connect (editor, "build-child", G_CALLBACK (glade_gtk_menu_shell_build_child), NULL); - g_signal_connect (editor, "delete-child", G_CALLBACK (glade_gtk_menu_shell_delete_child), NULL); - g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_menu_shell_move_child), NULL); - - gtk_widget_show (GTK_WIDGET (editor)); - - window = glade_base_editor_pack_new_window (editor, _("Tool Bar Editor"), NULL); - gtk_widget_show (window); -} - -void -glade_gtk_toolbar_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) -{ - if (strcmp (action_path, "launch_editor") == 0) - { - glade_gtk_toolbar_launch_editor (adaptor, object); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, - object, - action_path); +glade_gtk_toolbar_launch_editor (GladeWidgetAdaptor * adaptor, + GObject * toolbar) +{ + GladeBaseEditor *editor; + GtkWidget *window; + + /* Editor */ + editor = glade_base_editor_new (toolbar, NULL, + _("Button"), GTK_TYPE_TOOL_BUTTON, + _("Toggle"), GTK_TYPE_TOGGLE_TOOL_BUTTON, + _("Radio"), GTK_TYPE_RADIO_TOOL_BUTTON, + _("Menu"), GTK_TYPE_MENU_TOOL_BUTTON, + _("Custom"), GTK_TYPE_TOOL_ITEM, + _("Separator"), GTK_TYPE_SEPARATOR_TOOL_ITEM, + NULL); + + + glade_base_editor_append_types (editor, GTK_TYPE_MENU_TOOL_BUTTON, + _("Normal"), GTK_TYPE_MENU_ITEM, + _("Image"), GTK_TYPE_IMAGE_MENU_ITEM, + _("Check"), GTK_TYPE_CHECK_MENU_ITEM, + _("Radio"), GTK_TYPE_RADIO_MENU_ITEM, + _("Separator"), GTK_TYPE_SEPARATOR_MENU_ITEM, + NULL); + + glade_base_editor_append_types (editor, GTK_TYPE_MENU_ITEM, + _("Normal"), GTK_TYPE_MENU_ITEM, + _("Image"), GTK_TYPE_IMAGE_MENU_ITEM, + _("Check"), GTK_TYPE_CHECK_MENU_ITEM, + _("Radio"), GTK_TYPE_RADIO_MENU_ITEM, + _("Separator"), GTK_TYPE_SEPARATOR_MENU_ITEM, + NULL); + + g_signal_connect (editor, "get-display-name", + G_CALLBACK + (glade_gtk_menu_shell_tool_item_get_display_name), NULL); + g_signal_connect (editor, "child-selected", + G_CALLBACK (glade_gtk_menu_shell_tool_item_child_selected), + NULL); + g_signal_connect (editor, "change-type", + G_CALLBACK (glade_gtk_menu_shell_change_type), NULL); + g_signal_connect (editor, "build-child", + G_CALLBACK (glade_gtk_menu_shell_build_child), NULL); + g_signal_connect (editor, "delete-child", + G_CALLBACK (glade_gtk_menu_shell_delete_child), NULL); + g_signal_connect (editor, "move-child", + G_CALLBACK (glade_gtk_menu_shell_move_child), NULL); + + gtk_widget_show (GTK_WIDGET (editor)); + + window = + glade_base_editor_pack_new_window (editor, _("Tool Bar Editor"), NULL); + gtk_widget_show (window); +} + +void +glade_gtk_toolbar_action_activate (GladeWidgetAdaptor * adaptor, + GObject * object, const gchar * action_path) +{ + if (strcmp (action_path, "launch_editor") == 0) + { + glade_gtk_toolbar_launch_editor (adaptor, object); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, + object, action_path); } /* ----------------------------- GtkToolItem ------------------------------ */ GObject * -glade_gtk_tool_item_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) +glade_gtk_tool_item_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam * construct_properties) { - GladeWidgetAdaptor *adaptor; - GObject *ret_obj; - - ret_obj = GWA_GET_OCLASS(GTK_TYPE_CONTAINER)->constructor - (type, n_construct_properties, construct_properties); + GladeWidgetAdaptor *adaptor; + GObject *ret_obj; + + ret_obj = GWA_GET_OCLASS (GTK_TYPE_CONTAINER)->constructor + (type, n_construct_properties, construct_properties); - adaptor = GLADE_WIDGET_ADAPTOR (ret_obj); + adaptor = GLADE_WIDGET_ADAPTOR (ret_obj); - glade_widget_adaptor_action_remove (adaptor, "add_parent"); - glade_widget_adaptor_action_remove (adaptor, "remove_parent"); + glade_widget_adaptor_action_remove (adaptor, "add_parent"); + glade_widget_adaptor_action_remove (adaptor, "remove_parent"); - return ret_obj; + return ret_obj; } void -glade_gtk_tool_item_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_tool_item_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - g_return_if_fail (GTK_IS_TOOL_ITEM (object)); - - if (GTK_IS_SEPARATOR_TOOL_ITEM (object)) return; - - if (reason == GLADE_CREATE_USER && - gtk_bin_get_child (GTK_BIN (object)) == NULL) - gtk_container_add (GTK_CONTAINER (object), - glade_placeholder_new ()); + g_return_if_fail (GTK_IS_TOOL_ITEM (object)); + + if (GTK_IS_SEPARATOR_TOOL_ITEM (object)) + return; + + if (reason == GLADE_CREATE_USER && + gtk_bin_get_child (GTK_BIN (object)) == NULL) + gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ()); } void -glade_gtk_tool_item_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_tool_item_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - GladeProperty *property = glade_widget_get_property (gwidget, id); + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GladeProperty *property = glade_widget_get_property (gwidget, id); - //evaluate_activatable_property_sensitivity (object, id, value); - if (GPC_VERSION_CHECK (property->klass, gtk_major_version, gtk_minor_version + 1)) - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, - object, - id, value); + //evaluate_activatable_property_sensitivity (object, id, value); + if (GPC_VERSION_CHECK + (property->klass, gtk_major_version, gtk_minor_version + 1)) + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, + value); } /* ----------------------------- GtkToolButton ------------------------------ */ GladeEditable * -glade_gtk_tool_button_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_tool_button_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->create_editable (adaptor, type); + /* Get base editable */ + editable = + GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_tool_button_editor_new (adaptor, editable); + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_tool_button_editor_new (adaptor, editable); - return editable; + return editable; } static void -glade_gtk_tool_button_set_image_mode (GObject *object, const GValue *value) -{ - GladeWidget *gbutton; - - g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); - gbutton = glade_widget_get_from_gobject (object); - - glade_widget_property_set_sensitive (gbutton, "stock-id", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gbutton, "icon-name", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gbutton, "icon-widget", FALSE, NOT_SELECTED_MSG); - - switch (g_value_get_int (value)) - { - case GLADE_TB_MODE_STOCK: - glade_widget_property_set_sensitive (gbutton, "stock-id", TRUE, NULL); - break; - case GLADE_TB_MODE_ICON: - glade_widget_property_set_sensitive (gbutton, "icon-name", TRUE, NULL); - break; - case GLADE_TB_MODE_CUSTOM: - glade_widget_property_set_sensitive (gbutton, "icon-widget", TRUE, NULL); - break; - default: - break; - } +glade_gtk_tool_button_set_image_mode (GObject * object, const GValue * value) +{ + GladeWidget *gbutton; + + g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); + gbutton = glade_widget_get_from_gobject (object); + + glade_widget_property_set_sensitive (gbutton, "stock-id", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gbutton, "icon-name", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gbutton, "icon-widget", FALSE, + NOT_SELECTED_MSG); + + switch (g_value_get_int (value)) + { + case GLADE_TB_MODE_STOCK: + glade_widget_property_set_sensitive (gbutton, "stock-id", TRUE, NULL); + break; + case GLADE_TB_MODE_ICON: + glade_widget_property_set_sensitive (gbutton, "icon-name", TRUE, NULL); + break; + case GLADE_TB_MODE_CUSTOM: + glade_widget_property_set_sensitive (gbutton, "icon-widget", TRUE, + NULL); + break; + default: + break; + } } static void -glade_gtk_tool_button_set_custom_label (GObject *object, const GValue *value) +glade_gtk_tool_button_set_custom_label (GObject * object, const GValue * value) { - GladeWidget *gbutton; - - g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); - gbutton = glade_widget_get_from_gobject (object); + GladeWidget *gbutton; + + g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); + gbutton = glade_widget_get_from_gobject (object); - glade_widget_property_set_sensitive (gbutton, "label", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (gbutton, "label-widget", FALSE, NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gbutton, "label", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (gbutton, "label-widget", FALSE, + NOT_SELECTED_MSG); - if (g_value_get_boolean (value)) - glade_widget_property_set_sensitive (gbutton, "label-widget", TRUE, NULL); - else - glade_widget_property_set_sensitive (gbutton, "label", TRUE, NULL); + if (g_value_get_boolean (value)) + glade_widget_property_set_sensitive (gbutton, "label-widget", TRUE, NULL); + else + glade_widget_property_set_sensitive (gbutton, "label", TRUE, NULL); } static void -glade_gtk_tool_button_set_label (GObject *object, const GValue *value) +glade_gtk_tool_button_set_label (GObject * object, const GValue * value) { - const gchar *label; - - g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); - - label = g_value_get_string (value); - - if (label && strlen (label) == 0) label = NULL; - - gtk_tool_button_set_label (GTK_TOOL_BUTTON (object), label); + const gchar *label; + + g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); + + label = g_value_get_string (value); + + if (label && strlen (label) == 0) + label = NULL; + + gtk_tool_button_set_label (GTK_TOOL_BUTTON (object), label); } static void -glade_gtk_tool_button_set_stock_id (GObject *object, const GValue *value) +glade_gtk_tool_button_set_stock_id (GObject * object, const GValue * value) { - const gchar *stock_id; - - g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); - - stock_id = g_value_get_string (value); - - if (stock_id && strlen (stock_id) == 0) stock_id = NULL; - - gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (object), stock_id); + const gchar *stock_id; + + g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); + + stock_id = g_value_get_string (value); + + if (stock_id && strlen (stock_id) == 0) + stock_id = NULL; + + gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (object), stock_id); } static void -glade_gtk_tool_button_set_icon_name (GObject *object, const GValue *value) +glade_gtk_tool_button_set_icon_name (GObject * object, const GValue * value) { - const gchar *name; - - g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); + const gchar *name; + + g_return_if_fail (GTK_IS_TOOL_BUTTON (object)); - name = g_value_get_string (value); + name = g_value_get_string (value); - if (name && strlen (name) == 0) name = NULL; - - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (object), name); + if (name && strlen (name) == 0) + name = NULL; + + gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (object), name); } void -glade_gtk_tool_button_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_tool_button_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "image-mode")) - glade_gtk_tool_button_set_image_mode (object, value); - else if (!strcmp (id, "icon-name")) - glade_gtk_tool_button_set_icon_name (object, value); - else if (!strcmp (id, "stock-id")) - glade_gtk_tool_button_set_stock_id (object, value); - else if (!strcmp (id, "label")) - glade_gtk_tool_button_set_label (object, value); - else if (!strcmp (id, "custom-label")) - glade_gtk_tool_button_set_custom_label (object, value); - else - GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->set_property (adaptor, - object, - id, value); + if (!strcmp (id, "image-mode")) + glade_gtk_tool_button_set_image_mode (object, value); + else if (!strcmp (id, "icon-name")) + glade_gtk_tool_button_set_icon_name (object, value); + else if (!strcmp (id, "stock-id")) + glade_gtk_tool_button_set_stock_id (object, value); + else if (!strcmp (id, "label")) + glade_gtk_tool_button_set_label (object, value); + else if (!strcmp (id, "custom-label")) + glade_gtk_tool_button_set_custom_label (object, value); + else + GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->set_property (adaptor, + object, id, value); } static void -glade_gtk_tool_button_parse_finished (GladeProject *project, - GladeWidget *widget) -{ - gchar *stock_str = NULL, *icon_name = NULL; - gint stock_id = 0; - GtkWidget *label_widget = NULL, *image_widget = NULL; - - glade_widget_property_get (widget, "stock-id", &stock_str); - glade_widget_property_get (widget, "icon-name", &icon_name); - glade_widget_property_get (widget, "icon-widget", &image_widget); - glade_widget_property_get (widget, "label-widget", &label_widget); - - if (label_widget) - glade_widget_property_set (widget, "custom-label", TRUE); - else - glade_widget_property_set (widget, "custom-label", FALSE); - - if (image_widget) - glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_CUSTOM); - else if (icon_name) - glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_ICON); - else if (stock_str) - { - /* Update the stock property */ - stock_id = glade_utils_enum_value_from_string (GLADE_TYPE_STOCK_IMAGE, stock_str); - if (stock_id < 0) - stock_id = 0; - glade_widget_property_set (widget, "glade-stock", stock_id); - - glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_STOCK); - } - else - glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_STOCK); -} - -void -glade_gtk_tool_button_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->read_widget (adaptor, widget, node); - - /* Run this after the load so that icon-widget is resolved. */ - g_signal_connect (glade_widget_get_project (widget), - "parse-finished", - G_CALLBACK (glade_gtk_tool_button_parse_finished), - widget); +glade_gtk_tool_button_parse_finished (GladeProject * project, + GladeWidget * widget) +{ + gchar *stock_str = NULL, *icon_name = NULL; + gint stock_id = 0; + GtkWidget *label_widget = NULL, *image_widget = NULL; + + glade_widget_property_get (widget, "stock-id", &stock_str); + glade_widget_property_get (widget, "icon-name", &icon_name); + glade_widget_property_get (widget, "icon-widget", &image_widget); + glade_widget_property_get (widget, "label-widget", &label_widget); + + if (label_widget) + glade_widget_property_set (widget, "custom-label", TRUE); + else + glade_widget_property_set (widget, "custom-label", FALSE); + + if (image_widget) + glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_CUSTOM); + else if (icon_name) + glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_ICON); + else if (stock_str) + { + /* Update the stock property */ + stock_id = + glade_utils_enum_value_from_string (GLADE_TYPE_STOCK_IMAGE, + stock_str); + if (stock_id < 0) + stock_id = 0; + glade_widget_property_set (widget, "glade-stock", stock_id); + + glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_STOCK); + } + else + glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_STOCK); +} + +void +glade_gtk_tool_button_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->read_widget (adaptor, widget, node); + + /* Run this after the load so that icon-widget is resolved. */ + g_signal_connect (glade_widget_get_project (widget), + "parse-finished", + G_CALLBACK (glade_gtk_tool_button_parse_finished), widget); } /* ----------------------------- GtkMenuToolButton ------------------------------ */ GList * -glade_gtk_menu_tool_button_get_children (GladeWidgetAdaptor *adaptor, GtkMenuToolButton *button) +glade_gtk_menu_tool_button_get_children (GladeWidgetAdaptor * adaptor, + GtkMenuToolButton * button) { - GList *list = NULL; - GtkWidget *menu = gtk_menu_tool_button_get_menu (button); + GList *list = NULL; + GtkWidget *menu = gtk_menu_tool_button_get_menu (button); - list = glade_util_container_get_all_children (GTK_CONTAINER (button)); + list = glade_util_container_get_all_children (GTK_CONTAINER (button)); - /* Ensure that we only return one 'menu' */ - if (menu && g_list_find (list, menu) == NULL) - list = g_list_append (list, menu); + /* Ensure that we only return one 'menu' */ + if (menu && g_list_find (list, menu) == NULL) + list = g_list_append (list, menu); - return list; + return list; } void -glade_gtk_menu_tool_button_add_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_menu_tool_button_add_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - if (GTK_IS_MENU (child)) - { - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (object), GTK_WIDGET (child)); - } - else - GWA_GET_CLASS (GTK_TYPE_TOOL_BUTTON)->add (adaptor, object, child); + if (GTK_IS_MENU (child)) + { + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (object), + GTK_WIDGET (child)); + } + else + GWA_GET_CLASS (GTK_TYPE_TOOL_BUTTON)->add (adaptor, object, child); } void -glade_gtk_menu_tool_button_remove_child (GladeWidgetAdaptor *adaptor, - GObject *object, - GObject *child) +glade_gtk_menu_tool_button_remove_child (GladeWidgetAdaptor * adaptor, + GObject * object, GObject * child) { - if (GTK_IS_MENU (child)) - { - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (object), NULL); - } - else - GWA_GET_CLASS (GTK_TYPE_TOOL_BUTTON)->remove (adaptor, object, child); + if (GTK_IS_MENU (child)) + { + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (object), NULL); + } + else + GWA_GET_CLASS (GTK_TYPE_TOOL_BUTTON)->remove (adaptor, object, child); } /* ----------------------------- GtkLabel ------------------------------ */ void -glade_gtk_label_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_label_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *glabel = glade_widget_get_from_gobject (object); + GladeWidget *glabel = glade_widget_get_from_gobject (object); - if (reason == GLADE_CREATE_USER) - glade_widget_property_set_sensitive (glabel, "mnemonic-widget", FALSE, MNEMONIC_INSENSITIVE_MSG); + if (reason == GLADE_CREATE_USER) + glade_widget_property_set_sensitive (glabel, "mnemonic-widget", FALSE, + MNEMONIC_INSENSITIVE_MSG); } static void -glade_gtk_label_set_label (GObject *object, const GValue *value) +glade_gtk_label_set_label (GObject * object, const GValue * value) { - GladeWidget *glabel; - gboolean use_markup = FALSE, use_underline = FALSE; + GladeWidget *glabel; + gboolean use_markup = FALSE, use_underline = FALSE; + + glabel = glade_widget_get_from_gobject (object); + glade_widget_property_get (glabel, "use-markup", &use_markup); + + if (use_markup) + gtk_label_set_markup (GTK_LABEL (object), g_value_get_string (value)); + else + gtk_label_set_text (GTK_LABEL (object), g_value_get_string (value)); - glabel = glade_widget_get_from_gobject (object); - glade_widget_property_get (glabel, "use-markup", &use_markup); - - if (use_markup) - gtk_label_set_markup (GTK_LABEL (object), g_value_get_string (value)); - else - gtk_label_set_text (GTK_LABEL (object), g_value_get_string (value)); - - glade_widget_property_get (glabel, "use-underline", &use_underline); - if (use_underline) - gtk_label_set_use_underline (GTK_LABEL (object), use_underline); + glade_widget_property_get (glabel, "use-underline", &use_underline); + if (use_underline) + gtk_label_set_use_underline (GTK_LABEL (object), use_underline); } static void -glade_gtk_label_set_attributes (GObject *object, const GValue *value) -{ - GladeAttribute *gattr; - PangoAttribute *attribute; - PangoLanguage *language; - PangoAttrList *attrs = NULL; - GdkColor *color; - GList *list; - - for (list = g_value_get_boxed (value); list; list = list->next) - { - gattr = list->data; - - attribute = NULL; - - switch (gattr->type) - { - /* PangoAttrLanguage */ - case PANGO_ATTR_LANGUAGE: - if ((language = pango_language_from_string (g_value_get_string (&gattr->value)))) - attribute = pango_attr_language_new (language); - break; - /* PangoAttrInt */ - case PANGO_ATTR_STYLE: - attribute = pango_attr_style_new (g_value_get_enum (&(gattr->value))); - break; - case PANGO_ATTR_WEIGHT: - attribute = pango_attr_weight_new (g_value_get_enum (&(gattr->value))); - break; - case PANGO_ATTR_VARIANT: - attribute = pango_attr_variant_new (g_value_get_enum (&(gattr->value))); - break; - case PANGO_ATTR_STRETCH: - attribute = pango_attr_stretch_new (g_value_get_enum (&(gattr->value))); - break; - case PANGO_ATTR_UNDERLINE: - attribute = pango_attr_underline_new (g_value_get_boolean (&(gattr->value))); - break; - case PANGO_ATTR_STRIKETHROUGH: - attribute = pango_attr_strikethrough_new (g_value_get_boolean (&(gattr->value))); - break; - case PANGO_ATTR_GRAVITY: - attribute = pango_attr_gravity_new (g_value_get_enum (&(gattr->value))); - break; - case PANGO_ATTR_GRAVITY_HINT: - attribute = pango_attr_gravity_hint_new (g_value_get_enum (&(gattr->value))); - break; - - /* PangoAttrString */ - case PANGO_ATTR_FAMILY: - attribute = pango_attr_family_new (g_value_get_string (&(gattr->value))); - break; - - /* PangoAttrSize */ - case PANGO_ATTR_SIZE: - attribute = pango_attr_size_new (g_value_get_int (&(gattr->value))); - break; - case PANGO_ATTR_ABSOLUTE_SIZE: - attribute = pango_attr_size_new_absolute (g_value_get_int (&(gattr->value))); - break; - - /* PangoAttrColor */ - case PANGO_ATTR_FOREGROUND: - color = g_value_get_boxed (&(gattr->value)); - attribute = pango_attr_foreground_new (color->red, color->green, color->blue); - break; - case PANGO_ATTR_BACKGROUND: - color = g_value_get_boxed (&(gattr->value)); - attribute = pango_attr_background_new (color->red, color->green, color->blue); - break; - case PANGO_ATTR_UNDERLINE_COLOR: - color = g_value_get_boxed (&(gattr->value)); - attribute = pango_attr_underline_color_new (color->red, color->green, color->blue); - break; - case PANGO_ATTR_STRIKETHROUGH_COLOR: - color = g_value_get_boxed (&(gattr->value)); - attribute = pango_attr_strikethrough_color_new (color->red, color->green, color->blue); - break; - - /* PangoAttrShape */ - case PANGO_ATTR_SHAPE: - /* Unsupported for now */ - break; - /* PangoAttrFloat */ - case PANGO_ATTR_SCALE: - attribute = pango_attr_scale_new (g_value_get_double (&(gattr->value))); - break; - - case PANGO_ATTR_INVALID: - case PANGO_ATTR_LETTER_SPACING: - case PANGO_ATTR_RISE: - case PANGO_ATTR_FALLBACK: - case PANGO_ATTR_FONT_DESC: - default: - break; - } - - if (attribute) - { - if (!attrs) - attrs = pango_attr_list_new (); - pango_attr_list_insert (attrs, attribute); - - } - } - - gtk_label_set_attributes (GTK_LABEL (object), attrs); +glade_gtk_label_set_attributes (GObject * object, const GValue * value) +{ + GladeAttribute *gattr; + PangoAttribute *attribute; + PangoLanguage *language; + PangoAttrList *attrs = NULL; + GdkColor *color; + GList *list; + + for (list = g_value_get_boxed (value); list; list = list->next) + { + gattr = list->data; + + attribute = NULL; + + switch (gattr->type) + { + /* PangoAttrLanguage */ + case PANGO_ATTR_LANGUAGE: + if ((language = + pango_language_from_string (g_value_get_string + (&gattr->value)))) + attribute = pango_attr_language_new (language); + break; + /* PangoAttrInt */ + case PANGO_ATTR_STYLE: + attribute = + pango_attr_style_new (g_value_get_enum (&(gattr->value))); + break; + case PANGO_ATTR_WEIGHT: + attribute = + pango_attr_weight_new (g_value_get_enum (&(gattr->value))); + break; + case PANGO_ATTR_VARIANT: + attribute = + pango_attr_variant_new (g_value_get_enum (&(gattr->value))); + break; + case PANGO_ATTR_STRETCH: + attribute = + pango_attr_stretch_new (g_value_get_enum (&(gattr->value))); + break; + case PANGO_ATTR_UNDERLINE: + attribute = + pango_attr_underline_new (g_value_get_boolean + (&(gattr->value))); + break; + case PANGO_ATTR_STRIKETHROUGH: + attribute = + pango_attr_strikethrough_new (g_value_get_boolean + (&(gattr->value))); + break; + case PANGO_ATTR_GRAVITY: + attribute = + pango_attr_gravity_new (g_value_get_enum (&(gattr->value))); + break; + case PANGO_ATTR_GRAVITY_HINT: + attribute = + pango_attr_gravity_hint_new (g_value_get_enum + (&(gattr->value))); + break; + + /* PangoAttrString */ + case PANGO_ATTR_FAMILY: + attribute = + pango_attr_family_new (g_value_get_string (&(gattr->value))); + break; + + /* PangoAttrSize */ + case PANGO_ATTR_SIZE: + attribute = pango_attr_size_new (g_value_get_int (&(gattr->value))); + break; + case PANGO_ATTR_ABSOLUTE_SIZE: + attribute = + pango_attr_size_new_absolute (g_value_get_int + (&(gattr->value))); + break; + + /* PangoAttrColor */ + case PANGO_ATTR_FOREGROUND: + color = g_value_get_boxed (&(gattr->value)); + attribute = + pango_attr_foreground_new (color->red, color->green, + color->blue); + break; + case PANGO_ATTR_BACKGROUND: + color = g_value_get_boxed (&(gattr->value)); + attribute = + pango_attr_background_new (color->red, color->green, + color->blue); + break; + case PANGO_ATTR_UNDERLINE_COLOR: + color = g_value_get_boxed (&(gattr->value)); + attribute = + pango_attr_underline_color_new (color->red, color->green, + color->blue); + break; + case PANGO_ATTR_STRIKETHROUGH_COLOR: + color = g_value_get_boxed (&(gattr->value)); + attribute = + pango_attr_strikethrough_color_new (color->red, color->green, + color->blue); + break; + + /* PangoAttrShape */ + case PANGO_ATTR_SHAPE: + /* Unsupported for now */ + break; + /* PangoAttrFloat */ + case PANGO_ATTR_SCALE: + attribute = + pango_attr_scale_new (g_value_get_double (&(gattr->value))); + break; + + case PANGO_ATTR_INVALID: + case PANGO_ATTR_LETTER_SPACING: + case PANGO_ATTR_RISE: + case PANGO_ATTR_FALLBACK: + case PANGO_ATTR_FONT_DESC: + default: + break; + } + + if (attribute) + { + if (!attrs) + attrs = pango_attr_list_new (); + pango_attr_list_insert (attrs, attribute); + + } + } + + gtk_label_set_attributes (GTK_LABEL (object), attrs); } static void -glade_gtk_label_set_content_mode (GObject *object, const GValue *value) -{ - GladeLabelContentMode mode = g_value_get_int (value); - GladeWidget *glabel; - - glabel = glade_widget_get_from_gobject (object); - - glade_widget_property_set_sensitive (glabel, "glade-attributes", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (glabel, "use-markup", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (glabel, "pattern", FALSE, NOT_SELECTED_MSG); - - switch (mode) - { - case GLADE_LABEL_MODE_ATTRIBUTES: - glade_widget_property_set_sensitive (glabel, "glade-attributes", TRUE, NULL); - break; - case GLADE_LABEL_MODE_MARKUP: - glade_widget_property_set_sensitive (glabel, "use-markup", TRUE, NULL); - break; - case GLADE_LABEL_MODE_PATTERN: - glade_widget_property_set_sensitive (glabel, "pattern", TRUE, NULL); - break; - default: - break; - } +glade_gtk_label_set_content_mode (GObject * object, const GValue * value) +{ + GladeLabelContentMode mode = g_value_get_int (value); + GladeWidget *glabel; + + glabel = glade_widget_get_from_gobject (object); + + glade_widget_property_set_sensitive (glabel, "glade-attributes", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (glabel, "use-markup", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (glabel, "pattern", FALSE, + NOT_SELECTED_MSG); + + switch (mode) + { + case GLADE_LABEL_MODE_ATTRIBUTES: + glade_widget_property_set_sensitive (glabel, "glade-attributes", TRUE, + NULL); + break; + case GLADE_LABEL_MODE_MARKUP: + glade_widget_property_set_sensitive (glabel, "use-markup", TRUE, NULL); + break; + case GLADE_LABEL_MODE_PATTERN: + glade_widget_property_set_sensitive (glabel, "pattern", TRUE, NULL); + break; + default: + break; + } } static void -glade_gtk_label_set_use_max_width (GObject *object, const GValue *value) +glade_gtk_label_set_use_max_width (GObject * object, const GValue * value) { - GladeWidget *glabel; - - glabel = glade_widget_get_from_gobject (object); + GladeWidget *glabel; - glade_widget_property_set_sensitive (glabel, "width-chars", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (glabel, "max-width-chars", FALSE, NOT_SELECTED_MSG); + glabel = glade_widget_get_from_gobject (object); - if (g_value_get_boolean (value)) - glade_widget_property_set_sensitive (glabel, "max-width-chars", TRUE, NULL); - else - glade_widget_property_set_sensitive (glabel, "width-chars", TRUE, NULL); + glade_widget_property_set_sensitive (glabel, "width-chars", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (glabel, "max-width-chars", FALSE, + NOT_SELECTED_MSG); + + if (g_value_get_boolean (value)) + glade_widget_property_set_sensitive (glabel, "max-width-chars", TRUE, NULL); + else + glade_widget_property_set_sensitive (glabel, "width-chars", TRUE, NULL); } static void -glade_gtk_label_set_wrap_mode (GObject *object, const GValue *value) +glade_gtk_label_set_wrap_mode (GObject * object, const GValue * value) { - GladeLabelWrapMode mode = g_value_get_int (value); - GladeWidget *glabel; - - glabel = glade_widget_get_from_gobject (object); + GladeLabelWrapMode mode = g_value_get_int (value); + GladeWidget *glabel; + + glabel = glade_widget_get_from_gobject (object); - glade_widget_property_set_sensitive (glabel, "single-line-mode", FALSE, NOT_SELECTED_MSG); - glade_widget_property_set_sensitive (glabel, "wrap-mode", FALSE, NOT_SELECTED_MSG); - - if (mode == GLADE_LABEL_SINGLE_LINE) - glade_widget_property_set_sensitive (glabel, "single-line-mode", TRUE, NULL); - else if (mode == GLADE_LABEL_WRAP_MODE) - glade_widget_property_set_sensitive (glabel, "wrap-mode", TRUE, NULL); + glade_widget_property_set_sensitive (glabel, "single-line-mode", FALSE, + NOT_SELECTED_MSG); + glade_widget_property_set_sensitive (glabel, "wrap-mode", FALSE, + NOT_SELECTED_MSG); + + if (mode == GLADE_LABEL_SINGLE_LINE) + glade_widget_property_set_sensitive (glabel, "single-line-mode", TRUE, + NULL); + else if (mode == GLADE_LABEL_WRAP_MODE) + glade_widget_property_set_sensitive (glabel, "wrap-mode", TRUE, NULL); } static void -glade_gtk_label_set_use_underline (GObject *object, const GValue *value) +glade_gtk_label_set_use_underline (GObject * object, const GValue * value) { - GladeWidget *glabel; - - glabel = glade_widget_get_from_gobject (object); + GladeWidget *glabel; + + glabel = glade_widget_get_from_gobject (object); - if (g_value_get_boolean (value)) - glade_widget_property_set_sensitive (glabel, "mnemonic-widget", TRUE, NULL); - else - glade_widget_property_set_sensitive (glabel, "mnemonic-widget", FALSE, MNEMONIC_INSENSITIVE_MSG); + if (g_value_get_boolean (value)) + glade_widget_property_set_sensitive (glabel, "mnemonic-widget", TRUE, NULL); + else + glade_widget_property_set_sensitive (glabel, "mnemonic-widget", FALSE, + MNEMONIC_INSENSITIVE_MSG); - gtk_label_set_use_underline (GTK_LABEL (object), g_value_get_boolean (value)); + gtk_label_set_use_underline (GTK_LABEL (object), g_value_get_boolean (value)); } static void -glade_gtk_label_set_ellipsize (GObject *object, const GValue *value) +glade_gtk_label_set_ellipsize (GObject * object, const GValue * value) { - GladeWidget *glabel; - const gchar *insensitive_msg = _("This property does not apply when Ellipsize is set."); - - glabel = glade_widget_get_from_gobject (object); + GladeWidget *glabel; + const gchar *insensitive_msg = + _("This property does not apply when Ellipsize is set."); + + glabel = glade_widget_get_from_gobject (object); - if (!glade_widget_property_original_default (glabel, "ellipsize")) - glade_widget_property_set_sensitive (glabel, "angle", FALSE, insensitive_msg); - else - glade_widget_property_set_sensitive (glabel, "angle", TRUE, NULL); + if (!glade_widget_property_original_default (glabel, "ellipsize")) + glade_widget_property_set_sensitive (glabel, "angle", FALSE, + insensitive_msg); + else + glade_widget_property_set_sensitive (glabel, "angle", TRUE, NULL); - gtk_label_set_ellipsize (GTK_LABEL (object), g_value_get_enum (value)); + gtk_label_set_ellipsize (GTK_LABEL (object), g_value_get_enum (value)); } static void -glade_gtk_label_set_angle (GObject *object, const GValue *value) -{ - GladeWidget *glabel; - const gchar *insensitive_msg = _("This property does not apply when Angle is set."); - - glabel = glade_widget_get_from_gobject (object); - - if (!glade_widget_property_original_default (glabel, "angle")) - glade_widget_property_set_sensitive (glabel, "ellipsize", FALSE, insensitive_msg); - else - glade_widget_property_set_sensitive (glabel, "ellipsize", TRUE, NULL); - - gtk_label_set_angle (GTK_LABEL (object), g_value_get_double (value)); -} - -void -glade_gtk_label_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) -{ - if (!strcmp (id, "label")) - glade_gtk_label_set_label (object, value); - else if (!strcmp (id, "glade-attributes")) - glade_gtk_label_set_attributes (object, value); - else if (!strcmp (id, "label-content-mode")) - glade_gtk_label_set_content_mode (object, value); - else if (!strcmp (id, "use-max-width")) - glade_gtk_label_set_use_max_width (object, value); - else if (!strcmp (id, "label-wrap-mode")) - glade_gtk_label_set_wrap_mode (object, value); - else if (!strcmp (id, "use-underline")) - glade_gtk_label_set_use_underline (object, value); - else if (!strcmp (id, "ellipsize")) - glade_gtk_label_set_ellipsize (object, value); - else if (!strcmp (id, "angle")) - glade_gtk_label_set_angle (object, value); - else - GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); +glade_gtk_label_set_angle (GObject * object, const GValue * value) +{ + GladeWidget *glabel; + const gchar *insensitive_msg = + _("This property does not apply when Angle is set."); + + glabel = glade_widget_get_from_gobject (object); + + if (!glade_widget_property_original_default (glabel, "angle")) + glade_widget_property_set_sensitive (glabel, "ellipsize", FALSE, + insensitive_msg); + else + glade_widget_property_set_sensitive (glabel, "ellipsize", TRUE, NULL); + + gtk_label_set_angle (GTK_LABEL (object), g_value_get_double (value)); +} + +void +glade_gtk_label_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) +{ + if (!strcmp (id, "label")) + glade_gtk_label_set_label (object, value); + else if (!strcmp (id, "glade-attributes")) + glade_gtk_label_set_attributes (object, value); + else if (!strcmp (id, "label-content-mode")) + glade_gtk_label_set_content_mode (object, value); + else if (!strcmp (id, "use-max-width")) + glade_gtk_label_set_use_max_width (object, value); + else if (!strcmp (id, "label-wrap-mode")) + glade_gtk_label_set_wrap_mode (object, value); + else if (!strcmp (id, "use-underline")) + glade_gtk_label_set_use_underline (object, value); + else if (!strcmp (id, "ellipsize")) + glade_gtk_label_set_ellipsize (object, value); + else if (!strcmp (id, "angle")) + glade_gtk_label_set_angle (object, value); + else + GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); } static void -glade_gtk_parse_attributes (GladeWidget *widget, - GladeXmlNode *node) -{ - PangoAttrType attr_type; - GladeXmlNode *prop; - GladeAttribute *attr; - GList *attrs = NULL; - gchar *name, *value; - - for (prop = glade_xml_node_get_children (node); - prop; prop = glade_xml_node_next (prop)) - { - if (!glade_xml_node_verify (prop, GLADE_TAG_ATTRIBUTE)) - continue; - - if (!(name = glade_xml_get_property_string_required - (prop, GLADE_XML_TAG_NAME, NULL))) - continue; - - if (!(value = glade_xml_get_property_string_required - (prop, GLADE_TAG_VALUE, NULL))) - { - /* for a while, Glade was broken and was storing - * attributes in the node contents */ - if (!(value = glade_xml_get_content (prop))) - { - g_free (name); - continue; - } - } - - if ((attr_type = - glade_utils_enum_value_from_string (PANGO_TYPE_ATTR_TYPE, name)) == 0) - continue; - - /* Parse attribute and add to list */ - if ((attr = glade_gtk_attribute_from_string (attr_type, value)) != NULL) - attrs = g_list_prepend (attrs, attr); - - /* XXX deal with start/end here ... */ - - g_free (name); - g_free (value); - } - - glade_widget_property_set (widget, "glade-attributes", g_list_reverse (attrs)); - glade_attr_list_free (attrs); +glade_gtk_parse_attributes (GladeWidget * widget, GladeXmlNode * node) +{ + PangoAttrType attr_type; + GladeXmlNode *prop; + GladeAttribute *attr; + GList *attrs = NULL; + gchar *name, *value; + + for (prop = glade_xml_node_get_children (node); + prop; prop = glade_xml_node_next (prop)) + { + if (!glade_xml_node_verify (prop, GLADE_TAG_ATTRIBUTE)) + continue; + + if (!(name = glade_xml_get_property_string_required + (prop, GLADE_XML_TAG_NAME, NULL))) + continue; + + if (!(value = glade_xml_get_property_string_required + (prop, GLADE_TAG_VALUE, NULL))) + { + /* for a while, Glade was broken and was storing + * attributes in the node contents */ + if (!(value = glade_xml_get_content (prop))) + { + g_free (name); + continue; + } + } + + if ((attr_type = + glade_utils_enum_value_from_string (PANGO_TYPE_ATTR_TYPE, + name)) == 0) + continue; + + /* Parse attribute and add to list */ + if ((attr = glade_gtk_attribute_from_string (attr_type, value)) != NULL) + attrs = g_list_prepend (attrs, attr); + + /* XXX deal with start/end here ... */ + + g_free (name); + g_free (value); + } + + glade_widget_property_set (widget, "glade-attributes", + g_list_reverse (attrs)); + glade_attr_list_free (attrs); } static void -glade_gtk_label_read_attributes (GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_label_read_attributes (GladeWidget * widget, GladeXmlNode * node) { - GladeXmlNode *attrs_node; + GladeXmlNode *attrs_node; - if ((attrs_node = - glade_xml_search_child (node, GLADE_TAG_ATTRIBUTES)) != NULL) - { - /* Generic attributes parsing */ - glade_gtk_parse_attributes (widget, attrs_node); - } + if ((attrs_node = + glade_xml_search_child (node, GLADE_TAG_ATTRIBUTES)) != NULL) + { + /* Generic attributes parsing */ + glade_gtk_parse_attributes (widget, attrs_node); + } } void -glade_gtk_label_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_label_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - GladeProperty *prop; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + GladeProperty *prop; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node); - glade_gtk_label_read_attributes (widget, node); + glade_gtk_label_read_attributes (widget, node); - /* sync label property after a load... */ - prop = glade_widget_get_property (widget, "label"); - glade_gtk_label_set_label (widget->object, prop->value); + /* sync label property after a load... */ + prop = glade_widget_get_property (widget, "label"); + glade_gtk_label_set_label (widget->object, prop->value); - /* Resolve "label-content-mode" virtual control property */ - if (!glade_widget_property_original_default (widget, "use-markup")) - glade_widget_property_set (widget, "label-content-mode", GLADE_LABEL_MODE_MARKUP); - else if (!glade_widget_property_original_default (widget, "pattern")) - glade_widget_property_set (widget, "label-content-mode", GLADE_LABEL_MODE_PATTERN); - else - glade_widget_property_set (widget, "label-content-mode", GLADE_LABEL_MODE_ATTRIBUTES); + /* Resolve "label-content-mode" virtual control property */ + if (!glade_widget_property_original_default (widget, "use-markup")) + glade_widget_property_set (widget, "label-content-mode", + GLADE_LABEL_MODE_MARKUP); + else if (!glade_widget_property_original_default (widget, "pattern")) + glade_widget_property_set (widget, "label-content-mode", + GLADE_LABEL_MODE_PATTERN); + else + glade_widget_property_set (widget, "label-content-mode", + GLADE_LABEL_MODE_ATTRIBUTES); - /* Resolve "label-wrap-mode" virtual control property */ - if (!glade_widget_property_original_default (widget, "single-line-mode")) - glade_widget_property_set (widget, "label-wrap-mode", GLADE_LABEL_SINGLE_LINE); - else if (!glade_widget_property_original_default (widget, "wrap")) - glade_widget_property_set (widget, "label-wrap-mode", GLADE_LABEL_WRAP_MODE); - else - glade_widget_property_set (widget, "label-wrap-mode", GLADE_LABEL_WRAP_FREE); + /* Resolve "label-wrap-mode" virtual control property */ + if (!glade_widget_property_original_default (widget, "single-line-mode")) + glade_widget_property_set (widget, "label-wrap-mode", + GLADE_LABEL_SINGLE_LINE); + else if (!glade_widget_property_original_default (widget, "wrap")) + glade_widget_property_set (widget, "label-wrap-mode", + GLADE_LABEL_WRAP_MODE); + else + glade_widget_property_set (widget, "label-wrap-mode", + GLADE_LABEL_WRAP_FREE); - /* Resolve "use-max-width" virtual control property */ - if (!glade_widget_property_original_default (widget, "max-width-chars")) - glade_widget_property_set (widget, "use-max-width", TRUE); - else - glade_widget_property_set (widget, "use-max-width", TRUE); - - if (glade_widget_property_original_default (widget, "use-markup")) - glade_widget_property_set_sensitive (widget, "mnemonic-widget", - FALSE, MNEMONIC_INSENSITIVE_MSG); + /* Resolve "use-max-width" virtual control property */ + if (!glade_widget_property_original_default (widget, "max-width-chars")) + glade_widget_property_set (widget, "use-max-width", TRUE); + else + glade_widget_property_set (widget, "use-max-width", TRUE); + + if (glade_widget_property_original_default (widget, "use-markup")) + glade_widget_property_set_sensitive (widget, "mnemonic-widget", + FALSE, MNEMONIC_INSENSITIVE_MSG); } static void -glade_gtk_label_write_attributes (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_label_write_attributes (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *attr_node; - GList *attrs = NULL, *l; - GladeAttribute *gattr; - gchar *attr_type; - gchar *attr_value; + GladeXmlNode *attr_node; + GList *attrs = NULL, *l; + GladeAttribute *gattr; + gchar *attr_type; + gchar *attr_value; - if (!glade_widget_property_get (widget, "glade-attributes", &attrs) || !attrs) - return; + if (!glade_widget_property_get (widget, "glade-attributes", &attrs) || !attrs) + return; - for (l = attrs; l; l = l->next) - { - gattr = l->data; + for (l = attrs; l; l = l->next) + { + gattr = l->data; - attr_type = glade_utils_enum_string_from_value (PANGO_TYPE_ATTR_TYPE, gattr->type); - attr_value = glade_gtk_string_from_attr (gattr); + attr_type = + glade_utils_enum_string_from_value (PANGO_TYPE_ATTR_TYPE, + gattr->type); + attr_value = glade_gtk_string_from_attr (gattr); - attr_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTE); - glade_xml_node_append_child (node, attr_node); + attr_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTE); + glade_xml_node_append_child (node, attr_node); - glade_xml_node_set_property_string (attr_node, GLADE_TAG_NAME, attr_type); - glade_xml_node_set_property_string (attr_node, GLADE_TAG_VALUE, attr_value); - } + glade_xml_node_set_property_string (attr_node, GLADE_TAG_NAME, attr_type); + glade_xml_node_set_property_string (attr_node, GLADE_TAG_VALUE, + attr_value); + } } void -glade_gtk_label_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_label_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) { - GladeXmlNode *attrs_node; + GladeXmlNode *attrs_node; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (GTK_TYPE_WIDGET)->write_widget (adaptor, widget, context, node); + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (GTK_TYPE_WIDGET)->write_widget (adaptor, widget, context, + node); - attrs_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTES); + attrs_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTES); - glade_gtk_label_write_attributes (widget, context, attrs_node); + glade_gtk_label_write_attributes (widget, context, attrs_node); - if (!glade_xml_node_get_children (attrs_node)) - glade_xml_node_delete (attrs_node); - else - glade_xml_node_append_child (node, attrs_node); + if (!glade_xml_node_get_children (attrs_node)) + glade_xml_node_delete (attrs_node); + else + glade_xml_node_append_child (node, attrs_node); } gchar * -glade_gtk_label_string_from_value (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - const GValue *value) -{ - if (klass->pspec->value_type == GLADE_TYPE_ATTR_GLIST) - { - GList *l, *list = g_value_get_boxed (value); - GString *string = g_string_new (""); - gchar *str; - - for (l = list; l; l = g_list_next (l)) - { - GladeAttribute *attr = l->data; - - /* Return something usefull at least to for the backend to compare */ - gchar *attr_str = glade_gtk_string_from_attr (attr); - g_string_append_printf (string, "%d=%s ", attr->type, attr_str); - g_free (attr_str); - } - str = string->str; - g_string_free (string, FALSE); - return str; - } - else - return GWA_GET_CLASS - (GTK_TYPE_WIDGET)->string_from_value (adaptor, - klass, - value); +glade_gtk_label_string_from_value (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, + const GValue * value) +{ + if (klass->pspec->value_type == GLADE_TYPE_ATTR_GLIST) + { + GList *l, *list = g_value_get_boxed (value); + GString *string = g_string_new (""); + gchar *str; + + for (l = list; l; l = g_list_next (l)) + { + GladeAttribute *attr = l->data; + + /* Return something usefull at least to for the backend to compare */ + gchar *attr_str = glade_gtk_string_from_attr (attr); + g_string_append_printf (string, "%d=%s ", attr->type, attr_str); + g_free (attr_str); + } + str = string->str; + g_string_free (string, FALSE); + return str; + } + else + return GWA_GET_CLASS + (GTK_TYPE_WIDGET)->string_from_value (adaptor, klass, value); } GladeEditorProperty * -glade_gtk_label_create_eprop (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - gboolean use_command) -{ - GladeEditorProperty *eprop; - - /* chain up.. */ - if (klass->pspec->value_type == GLADE_TYPE_ATTR_GLIST) - { - eprop = g_object_new (GLADE_TYPE_EPROP_ATTRS, - "property-class", klass, - "use-command", use_command, - NULL); - } - else - eprop = GWA_GET_CLASS - (GTK_TYPE_WIDGET)->create_eprop (adaptor, - klass, - use_command); - return eprop; +glade_gtk_label_create_eprop (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, gboolean use_command) +{ + GladeEditorProperty *eprop; + + /* chain up.. */ + if (klass->pspec->value_type == GLADE_TYPE_ATTR_GLIST) + { + eprop = g_object_new (GLADE_TYPE_EPROP_ATTRS, + "property-class", klass, + "use-command", use_command, NULL); + } + else + eprop = GWA_GET_CLASS + (GTK_TYPE_WIDGET)->create_eprop (adaptor, klass, use_command); + return eprop; } GladeEditable * -glade_gtk_label_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_label_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_WIDGET)->create_editable (adaptor, type); + /* Get base editable */ + editable = GWA_GET_CLASS (GTK_TYPE_WIDGET)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_label_editor_new (adaptor, editable); + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_label_editor_new (adaptor, editable); - return editable; + return editable; } /* ----------------------------- GtkTextBuffer ------------------------------ */ static void -glade_gtk_entry_buffer_changed (GtkTextBuffer *buffer, - GParamSpec *pspec, - GladeWidget *gbuffy) +glade_gtk_entry_buffer_changed (GtkTextBuffer * buffer, + GParamSpec * pspec, GladeWidget * gbuffy) { - const gchar *text_prop = NULL; - GladeProperty *prop; - gchar *text = NULL; - - if (glade_widget_superuser ()) - return; + const gchar *text_prop = NULL; + GladeProperty *prop; + gchar *text = NULL; - g_object_get (buffer, "text", &text, NULL); + if (glade_widget_superuser ()) + return; - if ((prop = glade_widget_get_property (gbuffy, "text"))) - { - glade_property_get (prop, &text_prop); + g_object_get (buffer, "text", &text, NULL); - if (text_prop == NULL || g_strcmp0 (text, text_prop)) - glade_command_set_property (prop, text); - } - g_free (text); + if ((prop = glade_widget_get_property (gbuffy, "text"))) + { + glade_property_get (prop, &text_prop); + + if (text_prop == NULL || g_strcmp0 (text, text_prop)) + glade_command_set_property (prop, text); + } + g_free (text); } void -glade_gtk_entry_buffer_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_entry_buffer_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *gbuffy; - - gbuffy = glade_widget_get_from_gobject (object); - - g_signal_connect (object, "notify::text", - G_CALLBACK (glade_gtk_entry_buffer_changed), - gbuffy); + GladeWidget *gbuffy; + + gbuffy = glade_widget_get_from_gobject (object); + + g_signal_connect (object, "notify::text", + G_CALLBACK (glade_gtk_entry_buffer_changed), gbuffy); } void -glade_gtk_entry_buffer_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_entry_buffer_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - GladeProperty *property = glade_widget_get_property (gwidget, id); + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GladeProperty *property = glade_widget_get_property (gwidget, id); - if (!strcmp (id, "text")) - { - g_signal_handlers_block_by_func (object, glade_gtk_entry_buffer_changed, gwidget); + if (!strcmp (id, "text")) + { + g_signal_handlers_block_by_func (object, glade_gtk_entry_buffer_changed, + gwidget); - if (g_value_get_string (value)) - gtk_entry_buffer_set_text (GTK_ENTRY_BUFFER (object), g_value_get_string (value), -1); - else - gtk_entry_buffer_set_text (GTK_ENTRY_BUFFER (object), "", -1); + if (g_value_get_string (value)) + gtk_entry_buffer_set_text (GTK_ENTRY_BUFFER (object), + g_value_get_string (value), -1); + else + gtk_entry_buffer_set_text (GTK_ENTRY_BUFFER (object), "", -1); - g_signal_handlers_unblock_by_func (object, glade_gtk_entry_buffer_changed, gwidget); + g_signal_handlers_unblock_by_func (object, glade_gtk_entry_buffer_changed, + gwidget); - } - else if (GPC_VERSION_CHECK (property->klass, gtk_major_version, gtk_minor_version + 1)) - GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value); + } + else if (GPC_VERSION_CHECK + (property->klass, gtk_major_version, gtk_minor_version + 1)) + GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value); } /* ----------------------------- GtkTextBuffer ------------------------------ */ static void -glade_gtk_text_buffer_changed (GtkTextBuffer *buffer, GladeWidget *gbuffy) +glade_gtk_text_buffer_changed (GtkTextBuffer * buffer, GladeWidget * gbuffy) { - const gchar *text_prop = NULL; - GladeProperty *prop; - gchar *text = NULL; - - g_object_get (buffer, "text", &text, NULL); + const gchar *text_prop = NULL; + GladeProperty *prop; + gchar *text = NULL; - if ((prop = glade_widget_get_property (gbuffy, "text"))) - { - glade_property_get (prop, &text_prop); + g_object_get (buffer, "text", &text, NULL); - if (g_strcmp0 (text, text_prop)) - glade_command_set_property (prop, text); - } - g_free (text); + if ((prop = glade_widget_get_property (gbuffy, "text"))) + { + glade_property_get (prop, &text_prop); + + if (g_strcmp0 (text, text_prop)) + glade_command_set_property (prop, text); + } + g_free (text); } void -glade_gtk_text_buffer_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_text_buffer_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *gbuffy; - - gbuffy = glade_widget_get_from_gobject (object); - - g_signal_connect (object, "changed", - G_CALLBACK (glade_gtk_text_buffer_changed), - gbuffy); + GladeWidget *gbuffy; + + gbuffy = glade_widget_get_from_gobject (object); + + g_signal_connect (object, "changed", + G_CALLBACK (glade_gtk_text_buffer_changed), gbuffy); } void -glade_gtk_text_buffer_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_text_buffer_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - GladeProperty *property = glade_widget_get_property (gwidget, id); + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GladeProperty *property = glade_widget_get_property (gwidget, id); - if (!strcmp (id, "text")) - { - g_signal_handlers_block_by_func (object, glade_gtk_text_buffer_changed, gwidget); + if (!strcmp (id, "text")) + { + g_signal_handlers_block_by_func (object, glade_gtk_text_buffer_changed, + gwidget); - if (g_value_get_string (value)) - gtk_text_buffer_set_text (GTK_TEXT_BUFFER (object), g_value_get_string (value), -1); - else - gtk_text_buffer_set_text (GTK_TEXT_BUFFER (object), "", -1); + if (g_value_get_string (value)) + gtk_text_buffer_set_text (GTK_TEXT_BUFFER (object), + g_value_get_string (value), -1); + else + gtk_text_buffer_set_text (GTK_TEXT_BUFFER (object), "", -1); - g_signal_handlers_unblock_by_func (object, glade_gtk_text_buffer_changed, gwidget); + g_signal_handlers_unblock_by_func (object, glade_gtk_text_buffer_changed, + gwidget); - } - else if (GPC_VERSION_CHECK (property->klass, gtk_major_version, gtk_minor_version + 1)) - GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value); + } + else if (GPC_VERSION_CHECK + (property->klass, gtk_major_version, gtk_minor_version + 1)) + GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value); } /* ----------------------------- GtkTextView ------------------------------ */ static gboolean -glade_gtk_text_view_stop_double_click (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) +glade_gtk_text_view_stop_double_click (GtkWidget * widget, + GdkEventButton * event, + gpointer user_data) { - /* Return True if the event is double or triple click */ - return (event->type == GDK_2BUTTON_PRESS || - event->type == GDK_3BUTTON_PRESS); + /* Return True if the event is double or triple click */ + return (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS); } void -glade_gtk_text_view_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_text_view_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *gtext; - - gtext = glade_widget_get_from_gobject (object); + GladeWidget *gtext; + + gtext = glade_widget_get_from_gobject (object); - /* This makes gtk_text_view_set_buffer() stop complaing */ - gtk_drag_dest_set (GTK_WIDGET (object), 0, NULL, 0, 0); + /* This makes gtk_text_view_set_buffer() stop complaing */ + gtk_drag_dest_set (GTK_WIDGET (object), 0, NULL, 0, 0); - /* Glade hangs when a TextView gets a double click. So we stop them */ - g_signal_connect (object, "button-press-event", - G_CALLBACK (glade_gtk_text_view_stop_double_click), - NULL); + /* Glade hangs when a TextView gets a double click. So we stop them */ + g_signal_connect (object, "button-press-event", + G_CALLBACK (glade_gtk_text_view_stop_double_click), NULL); } void -glade_gtk_text_view_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) +glade_gtk_text_view_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + const GValue * value) { - if (strcmp (property_name, "buffer") == 0) - { - if (!g_value_get_object (value)) - return; - } + if (strcmp (property_name, "buffer") == 0) + { + if (!g_value_get_object (value)) + return; + } - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, - object, - property_name, - value); + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, + object, + property_name, value); } /* ----------------------------- GtkComboBox ------------------------------ */ void -glade_gtk_combo_box_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_combo_box_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *widget = glade_widget_get_from_gobject (object); + GladeWidget *widget = glade_widget_get_from_gobject (object); - if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (object))) - glade_widget_adaptor_create_internal - (widget, G_OBJECT (gtk_bin_get_child (GTK_BIN (object))), - "entry", "comboboxentry", FALSE, reason); + if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (object))) + glade_widget_adaptor_create_internal + (widget, G_OBJECT (gtk_bin_get_child (GTK_BIN (object))), + "entry", "comboboxentry", FALSE, reason); } void -glade_gtk_combo_box_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_combo_box_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "entry-text-column")) - { - /* Avoid warnings */ - if (g_value_get_int (value) >= 0) - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, - object, - id, value); - } - else if (!strcmp (id, "text-column")) - { - if (g_value_get_int (value) >= 0) - gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (object), - g_value_get_int (value)); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, - object, - id, value); + if (!strcmp (id, "entry-text-column")) + { + /* Avoid warnings */ + if (g_value_get_int (value) >= 0) + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, + object, id, value); + } + else if (!strcmp (id, "text-column")) + { + if (g_value_get_int (value) >= 0) + gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (object), + g_value_get_int (value)); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, + object, id, value); } -GList *glade_gtk_cell_layout_get_children (GladeWidgetAdaptor *adaptor, GObject *container); +GList *glade_gtk_cell_layout_get_children (GladeWidgetAdaptor * adaptor, + GObject * container); GList * -glade_gtk_combo_box_get_children (GladeWidgetAdaptor *adaptor, GtkComboBox *combo) +glade_gtk_combo_box_get_children (GladeWidgetAdaptor * adaptor, + GtkComboBox * combo) { - GList *list = NULL; + GList *list = NULL; - list = glade_gtk_cell_layout_get_children (adaptor, G_OBJECT (combo)); + list = glade_gtk_cell_layout_get_children (adaptor, G_OBJECT (combo)); - /* return the internal entry. - * - * FIXME: for recent gtk+ we have no comboboxentry - * but a "has-entry" property instead - */ - if (gtk_combo_box_get_has_entry (combo)) - list = g_list_append (list, gtk_bin_get_child (GTK_BIN (combo))); + /* return the internal entry. + * + * FIXME: for recent gtk+ we have no comboboxentry + * but a "has-entry" property instead + */ + if (gtk_combo_box_get_has_entry (combo)) + list = g_list_append (list, gtk_bin_get_child (GTK_BIN (combo))); - return list; + return list; } GObject * -glade_gtk_combo_box_get_internal_child (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *name) +glade_gtk_combo_box_get_internal_child (GladeWidgetAdaptor * adaptor, + GObject * object, const gchar * name) { - GObject *child = NULL; - g_return_val_if_fail (GTK_IS_COMBO_BOX (object), NULL); - - if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (object)) && strcmp ("entry", name) == 0) - child = G_OBJECT (gtk_bin_get_child (GTK_BIN (object))); + GObject *child = NULL; + g_return_val_if_fail (GTK_IS_COMBO_BOX (object), NULL); - return child; + if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (object)) && + strcmp ("entry", name) == 0) + child = G_OBJECT (gtk_bin_get_child (GTK_BIN (object))); + + return child; } /* ----------------------------- GtkSpinButton ------------------------------ */ static void -glade_gtk_spin_button_set_adjustment (GObject *object, const GValue *value) +glade_gtk_spin_button_set_adjustment (GObject * object, const GValue * value) { - GObject *adjustment; - GtkAdjustment *adj; - - g_return_if_fail (GTK_IS_SPIN_BUTTON (object)); - - adjustment = g_value_get_object (value); - - if (adjustment && GTK_IS_ADJUSTMENT (adjustment)) - { - adj = GTK_ADJUSTMENT (adjustment); + GObject *adjustment; + GtkAdjustment *adj; + + g_return_if_fail (GTK_IS_SPIN_BUTTON (object)); + + adjustment = g_value_get_object (value); - if (gtk_adjustment_get_page_size (adj) > 0) - { - GladeWidget *gadj = glade_widget_get_from_gobject (adj); + if (adjustment && GTK_IS_ADJUSTMENT (adjustment)) + { + adj = GTK_ADJUSTMENT (adjustment); - /* Silently set any spin-button adjustment page size to 0 */ - glade_widget_property_set (gadj, "page-size", 0.0F); - gtk_adjustment_set_page_size (adj, 0); - } + if (gtk_adjustment_get_page_size (adj) > 0) + { + GladeWidget *gadj = glade_widget_get_from_gobject (adj); - gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (object), adj); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (object), - gtk_adjustment_get_value (adj)); - } + /* Silently set any spin-button adjustment page size to 0 */ + glade_widget_property_set (gadj, "page-size", 0.0F); + gtk_adjustment_set_page_size (adj, 0); + } + + gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (object), adj); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (object), + gtk_adjustment_get_value (adj)); + } } void -glade_gtk_spin_button_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *id, - const GValue *value) +glade_gtk_spin_button_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * id, const GValue * value) { - if (!strcmp (id, "adjustment")) - glade_gtk_spin_button_set_adjustment (object, value); - else - GWA_GET_CLASS (GTK_TYPE_ENTRY)->set_property (adaptor, - object, - id, value); + if (!strcmp (id, "adjustment")) + glade_gtk_spin_button_set_adjustment (object, value); + else + GWA_GET_CLASS (GTK_TYPE_ENTRY)->set_property (adaptor, object, id, value); } /* ------------------------------ GtkAssistant ------------------------------ */ static void -glade_gtk_assistant_append_new_page (GladeWidget *parent, - GladeProject *project, - const gchar *label, - GtkAssistantPageType type) -{ - static GladeWidgetAdaptor *adaptor = NULL; - GladeWidget *page; - - if (adaptor == NULL) - adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); - - page = glade_widget_adaptor_create_widget (adaptor, FALSE, - "parent", parent, - "project", project, - NULL); - - glade_widget_add_child (parent, page, FALSE); - - glade_widget_property_set (page, "label", label); - glade_widget_pack_property_set (page, "page-type", type); +glade_gtk_assistant_append_new_page (GladeWidget * parent, + GladeProject * project, + const gchar * label, + GtkAssistantPageType type) +{ + static GladeWidgetAdaptor *adaptor = NULL; + GladeWidget *page; + + if (adaptor == NULL) + adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL); + + page = glade_widget_adaptor_create_widget (adaptor, FALSE, + "parent", parent, + "project", project, NULL); + + glade_widget_add_child (parent, page, FALSE); + + glade_widget_property_set (page, "label", label); + glade_widget_pack_property_set (page, "page-type", type); } + /* GtkAssistant is a very weird widget, why is it derived from GtkWindow instead of GtkNotebook I do not know! @@ -8319,482 +8320,480 @@ glade_gtk_assistant_append_new_page (GladeWidget *parent, update its navigation buttons! */ static void -glade_gtk_assistant_update_page_type (GtkAssistant *assistant) -{ - gint i, current, pages; - GtkWidget *page; - - current = gtk_assistant_get_current_page (assistant); - pages = gtk_assistant_get_n_pages (assistant) - 1; - if (pages < 0) return; - - /* Last Page */ - page = gtk_assistant_get_nth_page (assistant, pages); - gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); - - /* First page */ - page = gtk_assistant_get_nth_page (assistant, 0); - gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_INTRO); - - /* In betwen pages */ - for (i = 1; i < pages; i++) - { - page = gtk_assistant_get_nth_page (assistant, i); - gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT); - - } - - /* Now we have set page-type in every page, force button update */ - for (i = 0; i <= pages; i++) - { - page = gtk_assistant_get_nth_page (assistant, i); - gtk_assistant_set_page_complete (assistant, page, TRUE); - gtk_assistant_set_current_page (assistant, i); - gtk_assistant_update_buttons_state (assistant); - } - - if (current >= 0) gtk_assistant_set_current_page (assistant, current); +glade_gtk_assistant_update_page_type (GtkAssistant * assistant) +{ + gint i, current, pages; + GtkWidget *page; + + current = gtk_assistant_get_current_page (assistant); + pages = gtk_assistant_get_n_pages (assistant) - 1; + if (pages < 0) + return; + + /* Last Page */ + page = gtk_assistant_get_nth_page (assistant, pages); + gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); + + /* First page */ + page = gtk_assistant_get_nth_page (assistant, 0); + gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_INTRO); + + /* In betwen pages */ + for (i = 1; i < pages; i++) + { + page = gtk_assistant_get_nth_page (assistant, i); + gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT); + + } + + /* Now we have set page-type in every page, force button update */ + for (i = 0; i <= pages; i++) + { + page = gtk_assistant_get_nth_page (assistant, i); + gtk_assistant_set_page_complete (assistant, page, TRUE); + gtk_assistant_set_current_page (assistant, i); + gtk_assistant_update_buttons_state (assistant); + } + + if (current >= 0) + gtk_assistant_set_current_page (assistant, current); } static gint -glade_gtk_assistant_get_page (GtkAssistant *assistant, GtkWidget *page) +glade_gtk_assistant_get_page (GtkAssistant * assistant, GtkWidget * page) { - gint i, pages = gtk_assistant_get_n_pages (assistant); - - for (i = 0; i < pages; i++) - if (gtk_assistant_get_nth_page (assistant, i) == page) - return i; - - return -1; + gint i, pages = gtk_assistant_get_n_pages (assistant); + + for (i = 0; i < pages; i++) + if (gtk_assistant_get_nth_page (assistant, i) == page) + return i; + + return -1; } static void -glade_gtk_assistant_update_position (GtkAssistant *assistant) +glade_gtk_assistant_update_position (GtkAssistant * assistant) { - gint i, pages = gtk_assistant_get_n_pages (assistant); - - for (i = 0; i < pages; i++) - { - GtkWidget *page = gtk_assistant_get_nth_page (assistant, i); - GladeWidget *gpage = glade_widget_get_from_gobject (G_OBJECT (page)); - if (gpage) glade_widget_pack_property_set (gpage, "position", i); - } + gint i, pages = gtk_assistant_get_n_pages (assistant); + + for (i = 0; i < pages; i++) + { + GtkWidget *page = gtk_assistant_get_nth_page (assistant, i); + GladeWidget *gpage = glade_widget_get_from_gobject (G_OBJECT (page)); + if (gpage) + glade_widget_pack_property_set (gpage, "position", i); + } } static void -glade_gtk_assistant_parse_finished (GladeProject *project, - GObject *object) -{ - GtkAssistant *assistant = GTK_ASSISTANT (object); - gint pages = gtk_assistant_get_n_pages (assistant); - - if (pages) - { - /* also sets pages "complete" and thus allows navigation under glade */ - glade_gtk_assistant_update_page_type (assistant); - - gtk_assistant_set_current_page (assistant, 0); - glade_widget_property_set (glade_widget_get_from_gobject (object), - "n-pages", pages); - } -} - -void -glade_gtk_assistant_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) -{ - GladeWidget *parent = glade_widget_get_from_gobject (object); - GladeProject *project = glade_widget_get_project (parent); - - if (reason == GLADE_CREATE_LOAD) - { - g_signal_connect (project, "parse-finished", - G_CALLBACK (glade_gtk_assistant_parse_finished), - object); - return; - } - - if (reason == GLADE_CREATE_USER) - { - glade_gtk_assistant_append_new_page (parent, project, - _("Introduction page"), - GTK_ASSISTANT_PAGE_INTRO); - - glade_gtk_assistant_append_new_page (parent, project, - _("Content page"), - GTK_ASSISTANT_PAGE_CONTENT); - - glade_gtk_assistant_append_new_page (parent, project, - _("Confirmation page"), - GTK_ASSISTANT_PAGE_CONFIRM); - - gtk_assistant_set_current_page (GTK_ASSISTANT (object), 0); - - glade_widget_property_set (parent, "n-pages", 3); - } -} - -void -glade_gtk_assistant_add_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) -{ - GtkAssistant *assistant = GTK_ASSISTANT (container); - GtkWidget *widget = GTK_WIDGET (child); - - gtk_assistant_append_page (assistant, widget); -} - -void -glade_gtk_assistant_remove_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) -{ - GtkAssistant *assistant = GTK_ASSISTANT (container); - GladeWidget *gassistant = glade_widget_get_from_gobject (container); - - gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (child)); - glade_widget_property_set (gassistant, "n-pages", - gtk_assistant_get_n_pages (assistant)); -} - -void -glade_gtk_assistant_replace_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *current, - GObject *new_object) -{ - GtkAssistant *assistant = GTK_ASSISTANT (container); - GtkWidget *page = GTK_WIDGET (new_object), *old_page = GTK_WIDGET (current); - gint pos = glade_gtk_assistant_get_page (assistant, old_page); - gboolean set_current = gtk_assistant_get_current_page (assistant) == pos; - - gtk_container_remove (GTK_CONTAINER (container), old_page); - - gtk_assistant_insert_page (assistant, page, pos); - glade_gtk_assistant_update_page_type (assistant); - - if (set_current) gtk_assistant_set_current_page (assistant, pos); +glade_gtk_assistant_parse_finished (GladeProject * project, GObject * object) +{ + GtkAssistant *assistant = GTK_ASSISTANT (object); + gint pages = gtk_assistant_get_n_pages (assistant); + + if (pages) + { + /* also sets pages "complete" and thus allows navigation under glade */ + glade_gtk_assistant_update_page_type (assistant); + + gtk_assistant_set_current_page (assistant, 0); + glade_widget_property_set (glade_widget_get_from_gobject (object), + "n-pages", pages); + } } -gboolean -glade_gtk_assistant_verify_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) -{ - if (strcmp (property_name, "n-pages") == 0) - return g_value_get_int (value) >= - gtk_assistant_get_n_pages (GTK_ASSISTANT (object)); - - /* Chain Up */ - if (GWA_GET_CLASS (GTK_TYPE_WINDOW)->verify_property == NULL) - return TRUE; - return GWA_GET_CLASS (GTK_TYPE_WINDOW)->verify_property (adaptor, - object, - property_name, - value); -} - -void -glade_gtk_assistant_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) -{ - if (strcmp (property_name, "n-pages") == 0) - { - GtkAssistant *assistant = GTK_ASSISTANT (object); - gint size, i; - - for (i = gtk_assistant_get_n_pages (GTK_ASSISTANT (object)), - size = g_value_get_int (value); i < size; i++) - gtk_assistant_append_page (assistant, glade_placeholder_new ()); - - glade_gtk_assistant_update_page_type (assistant); - - return; - } - - /* Chain Up */ - GWA_GET_CLASS (GTK_TYPE_WINDOW)->set_property (adaptor, - object, - property_name, - value); -} - -void -glade_gtk_assistant_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - GValue *value) -{ - if (strcmp (property_name, "n-pages") == 0) - { - g_value_set_int (value, - gtk_assistant_get_n_pages (GTK_ASSISTANT (object))); - return; - } - - /* Chain Up */ - GWA_GET_CLASS (GTK_TYPE_WINDOW)->get_property (adaptor, - object, - property_name, - value); -} - -void -glade_gtk_assistant_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) -{ - if (strcmp (property_name, "position") == 0) - { - GtkAssistant *assistant = GTK_ASSISTANT (container); - GtkWidget *widget = GTK_WIDGET (child); - gint pos, size; - gboolean set_current; - - if ((pos = g_value_get_int (value)) < 0) return; - if (pos == glade_gtk_assistant_get_page (assistant, widget)) - return; - set_current = gtk_assistant_get_current_page (assistant) == - glade_gtk_assistant_get_page (assistant, widget); - - size = gtk_assistant_get_n_pages (assistant); - - g_object_ref (child); - gtk_container_remove (GTK_CONTAINER (container), widget); - gtk_assistant_insert_page (assistant, widget, pos); - g_object_unref (child); - - if (set_current) gtk_assistant_set_current_page (assistant, pos); - - glade_gtk_assistant_update_page_type (assistant); - - glade_gtk_assistant_update_position (assistant); - - return; - } - - /* Chain Up */ - GWA_GET_CLASS (GTK_TYPE_WINDOW)->child_set_property (adaptor, - container, - child, - property_name, - value); -} - -void -glade_gtk_assistant_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - if (strcmp (property_name, "position") == 0) - { - gint pos; - pos = glade_gtk_assistant_get_page (GTK_ASSISTANT (container), - GTK_WIDGET (child)); - if (pos >= 0) g_value_set_int (value, pos); - return; - } - - /* Chain Up */ - GWA_GET_CLASS (GTK_TYPE_WINDOW)->child_get_property (adaptor, - container, - child, - property_name, - value); +void +glade_gtk_assistant_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) +{ + GladeWidget *parent = glade_widget_get_from_gobject (object); + GladeProject *project = glade_widget_get_project (parent); + + if (reason == GLADE_CREATE_LOAD) + { + g_signal_connect (project, "parse-finished", + G_CALLBACK (glade_gtk_assistant_parse_finished), + object); + return; + } + + if (reason == GLADE_CREATE_USER) + { + glade_gtk_assistant_append_new_page (parent, project, + _("Introduction page"), + GTK_ASSISTANT_PAGE_INTRO); + + glade_gtk_assistant_append_new_page (parent, project, + _("Content page"), + GTK_ASSISTANT_PAGE_CONTENT); + + glade_gtk_assistant_append_new_page (parent, project, + _("Confirmation page"), + GTK_ASSISTANT_PAGE_CONFIRM); + + gtk_assistant_set_current_page (GTK_ASSISTANT (object), 0); + + glade_widget_property_set (parent, "n-pages", 3); + } } -/*--------------------------- GtkRadioButton ---------------------------------*/ void -glade_gtk_radio_button_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) -{ - if (strcmp (property_name, "group") == 0) - { - GtkRadioButton *radio = g_value_get_object (value); - /* g_object_set () on this property produces a bogus warning, - * so we better use the API GtkRadioButton provides. - */ - gtk_radio_button_set_group (GTK_RADIO_BUTTON (object), - radio ? gtk_radio_button_get_group (radio) : NULL); - return; - } - - /* Chain Up */ - GWA_GET_CLASS (GTK_TYPE_CHECK_BUTTON)->set_property (adaptor, - object, - property_name, - value); +glade_gtk_assistant_add_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) +{ + GtkAssistant *assistant = GTK_ASSISTANT (container); + GtkWidget *widget = GTK_WIDGET (child); + + gtk_assistant_append_page (assistant, widget); +} + +void +glade_gtk_assistant_remove_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) +{ + GtkAssistant *assistant = GTK_ASSISTANT (container); + GladeWidget *gassistant = glade_widget_get_from_gobject (container); + + gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (child)); + glade_widget_property_set (gassistant, "n-pages", + gtk_assistant_get_n_pages (assistant)); +} + +void +glade_gtk_assistant_replace_child (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * current, GObject * new_object) +{ + GtkAssistant *assistant = GTK_ASSISTANT (container); + GtkWidget *page = GTK_WIDGET (new_object), *old_page = GTK_WIDGET (current); + gint pos = glade_gtk_assistant_get_page (assistant, old_page); + gboolean set_current = gtk_assistant_get_current_page (assistant) == pos; + + gtk_container_remove (GTK_CONTAINER (container), old_page); + + gtk_assistant_insert_page (assistant, page, pos); + glade_gtk_assistant_update_page_type (assistant); + + if (set_current) + gtk_assistant_set_current_page (assistant, pos); } -/*--------------------------- GtkSizeGroup ---------------------------------*/ gboolean -glade_gtk_size_group_depends (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeWidget *another) +glade_gtk_assistant_verify_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + const GValue * value) { - if (GTK_IS_WIDGET (another->object)) - return TRUE; + if (strcmp (property_name, "n-pages") == 0) + return g_value_get_int (value) >= + gtk_assistant_get_n_pages (GTK_ASSISTANT (object)); - return GWA_GET_CLASS (G_TYPE_OBJECT)->depends (adaptor, widget, another); + /* Chain Up */ + if (GWA_GET_CLASS (GTK_TYPE_WINDOW)->verify_property == NULL) + return TRUE; + return GWA_GET_CLASS (GTK_TYPE_WINDOW)->verify_property (adaptor, + object, + property_name, + value); } -#define GLADE_TAG_SIZEGROUP_WIDGETS "widgets" -#define GLADE_TAG_SIZEGROUP_WIDGET "widget" +void +glade_gtk_assistant_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + const GValue * value) +{ + if (strcmp (property_name, "n-pages") == 0) + { + GtkAssistant *assistant = GTK_ASSISTANT (object); + gint size, i; -static void -glade_gtk_size_group_read_widgets (GladeWidget *widget, - GladeXmlNode *node) + for (i = gtk_assistant_get_n_pages (GTK_ASSISTANT (object)), + size = g_value_get_int (value); i < size; i++) + gtk_assistant_append_page (assistant, glade_placeholder_new ()); + + glade_gtk_assistant_update_page_type (assistant); + + return; + } + + /* Chain Up */ + GWA_GET_CLASS (GTK_TYPE_WINDOW)->set_property (adaptor, + object, property_name, value); +} + +void +glade_gtk_assistant_get_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, GValue * value) +{ + if (strcmp (property_name, "n-pages") == 0) + { + g_value_set_int (value, + gtk_assistant_get_n_pages (GTK_ASSISTANT (object))); + return; + } + + /* Chain Up */ + GWA_GET_CLASS (GTK_TYPE_WINDOW)->get_property (adaptor, + object, property_name, value); +} + +void +glade_gtk_assistant_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + const GValue * value) { - GladeXmlNode *widgets_node; - GladeProperty *property; - gchar *string = NULL; + if (strcmp (property_name, "position") == 0) + { + GtkAssistant *assistant = GTK_ASSISTANT (container); + GtkWidget *widget = GTK_WIDGET (child); + gint pos, size; + gboolean set_current; - if ((widgets_node = - glade_xml_search_child (node, GLADE_TAG_SIZEGROUP_WIDGETS)) != NULL) - { - GladeXmlNode *node; + if ((pos = g_value_get_int (value)) < 0) + return; + if (pos == glade_gtk_assistant_get_page (assistant, widget)) + return; + set_current = gtk_assistant_get_current_page (assistant) == + glade_gtk_assistant_get_page (assistant, widget); - for (node = glade_xml_node_get_children (widgets_node); - node; node = glade_xml_node_next (node)) - { - gchar *widget_name, *tmp; - - if (!glade_xml_node_verify (node, GLADE_TAG_SIZEGROUP_WIDGET)) - continue; + size = gtk_assistant_get_n_pages (assistant); - widget_name = glade_xml_get_property_string_required - (node, GLADE_TAG_NAME, NULL); - - if (string == NULL) - string = widget_name; - else if (widget_name != NULL) - { - tmp = g_strdup_printf ("%s%s%s", string, GPC_OBJECT_DELIMITER, widget_name); - string = (g_free (string), tmp); - g_free (widget_name); - } - } - } + g_object_ref (child); + gtk_container_remove (GTK_CONTAINER (container), widget); + gtk_assistant_insert_page (assistant, widget, pos); + g_object_unref (child); + if (set_current) + gtk_assistant_set_current_page (assistant, pos); - if (string) - { - property = glade_widget_get_property (widget, "widgets"); - g_assert (property); + glade_gtk_assistant_update_page_type (assistant); - /* we must synchronize this directly after loading this project - * (i.e. lookup the actual objects after they've been parsed and - * are present). - */ - g_object_set_data_full (G_OBJECT (property), - "glade-loaded-object", - string, g_free); - } + glade_gtk_assistant_update_position (assistant); + + return; + } + + /* Chain Up */ + GWA_GET_CLASS (GTK_TYPE_WINDOW)->child_set_property (adaptor, + container, + child, + property_name, value); } void -glade_gtk_size_group_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_assistant_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) { - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (strcmp (property_name, "position") == 0) + { + gint pos; + pos = glade_gtk_assistant_get_page (GTK_ASSISTANT (container), + GTK_WIDGET (child)); + if (pos >= 0) + g_value_set_int (value, pos); + return; + } + + /* Chain Up */ + GWA_GET_CLASS (GTK_TYPE_WINDOW)->child_get_property (adaptor, + container, + child, + property_name, value); +} + +/*--------------------------- GtkRadioButton ---------------------------------*/ +void +glade_gtk_radio_button_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + const GValue * value) +{ + if (strcmp (property_name, "group") == 0) + { + GtkRadioButton *radio = g_value_get_object (value); + /* g_object_set () on this property produces a bogus warning, + * so we better use the API GtkRadioButton provides. + */ + gtk_radio_button_set_group (GTK_RADIO_BUTTON (object), + radio ? gtk_radio_button_get_group (radio) : + NULL); + return; + } + + /* Chain Up */ + GWA_GET_CLASS (GTK_TYPE_CHECK_BUTTON)->set_property (adaptor, + object, + property_name, value); +} - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); +/*--------------------------- GtkSizeGroup ---------------------------------*/ +gboolean +glade_gtk_size_group_depends (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeWidget * another) +{ + if (GTK_IS_WIDGET (another->object)) + return TRUE; - glade_gtk_size_group_read_widgets (widget, node); + return GWA_GET_CLASS (G_TYPE_OBJECT)->depends (adaptor, widget, another); } +#define GLADE_TAG_SIZEGROUP_WIDGETS "widgets" +#define GLADE_TAG_SIZEGROUP_WIDGET "widget" static void -glade_gtk_size_group_write_widgets (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_size_group_read_widgets (GladeWidget * widget, GladeXmlNode * node) +{ + GladeXmlNode *widgets_node; + GladeProperty *property; + gchar *string = NULL; + + if ((widgets_node = + glade_xml_search_child (node, GLADE_TAG_SIZEGROUP_WIDGETS)) != NULL) + { + GladeXmlNode *node; + + for (node = glade_xml_node_get_children (widgets_node); + node; node = glade_xml_node_next (node)) + { + gchar *widget_name, *tmp; + + if (!glade_xml_node_verify (node, GLADE_TAG_SIZEGROUP_WIDGET)) + continue; + + widget_name = glade_xml_get_property_string_required + (node, GLADE_TAG_NAME, NULL); + + if (string == NULL) + string = widget_name; + else if (widget_name != NULL) + { + tmp = + g_strdup_printf ("%s%s%s", string, GPC_OBJECT_DELIMITER, + widget_name); + string = (g_free (string), tmp); + g_free (widget_name); + } + } + } + + + if (string) + { + property = glade_widget_get_property (widget, "widgets"); + g_assert (property); + + /* we must synchronize this directly after loading this project + * (i.e. lookup the actual objects after they've been parsed and + * are present). + */ + g_object_set_data_full (G_OBJECT (property), + "glade-loaded-object", string, g_free); + } +} + +void +glade_gtk_size_group_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - GladeXmlNode *widgets_node, *widget_node; - GList *widgets = NULL, *list; - GladeWidget *awidget; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); + + glade_gtk_size_group_read_widgets (widget, node); +} - widgets_node = glade_xml_node_new (context, GLADE_TAG_SIZEGROUP_WIDGETS); - if (glade_widget_property_get (widget, "widgets", &widgets)) - { - for (list = widgets; list; list = list->next) - { - awidget = glade_widget_get_from_gobject (list->data); - widget_node = glade_xml_node_new (context, GLADE_TAG_SIZEGROUP_WIDGET); - glade_xml_node_append_child (widgets_node, widget_node); - glade_xml_node_set_property_string (widget_node, GLADE_TAG_NAME, awidget->name); - } - } +static void +glade_gtk_size_group_write_widgets (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) +{ + GladeXmlNode *widgets_node, *widget_node; + GList *widgets = NULL, *list; + GladeWidget *awidget; + + widgets_node = glade_xml_node_new (context, GLADE_TAG_SIZEGROUP_WIDGETS); + + if (glade_widget_property_get (widget, "widgets", &widgets)) + { + for (list = widgets; list; list = list->next) + { + awidget = glade_widget_get_from_gobject (list->data); + widget_node = + glade_xml_node_new (context, GLADE_TAG_SIZEGROUP_WIDGET); + glade_xml_node_append_child (widgets_node, widget_node); + glade_xml_node_set_property_string (widget_node, GLADE_TAG_NAME, + awidget->name); + } + } + + if (!glade_xml_node_get_children (widgets_node)) + glade_xml_node_delete (widgets_node); + else + glade_xml_node_append_child (node, widgets_node); - if (!glade_xml_node_get_children (widgets_node)) - glade_xml_node_delete (widgets_node); - else - glade_xml_node_append_child (node, widgets_node); - } void -glade_gtk_size_group_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_size_group_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); - glade_gtk_size_group_write_widgets (widget, context, node); + glade_gtk_size_group_write_widgets (widget, context, node); } void -glade_gtk_size_group_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) +glade_gtk_size_group_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + const GValue * value) { - if (!strcmp (property_name, "widgets")) - { - GSList *sg_widgets, *slist; - GList *widgets, *list; + if (!strcmp (property_name, "widgets")) + { + GSList *sg_widgets, *slist; + GList *widgets, *list; - /* remove old widgets */ - if ((sg_widgets = gtk_size_group_get_widgets (GTK_SIZE_GROUP (object))) != NULL) - { - /* copy since we are modifying an internal list */ - sg_widgets = g_slist_copy (sg_widgets); - for (slist = sg_widgets; slist; slist = slist->next) - gtk_size_group_remove_widget (GTK_SIZE_GROUP (object), GTK_WIDGET (slist->data)); - g_slist_free (sg_widgets); - } + /* remove old widgets */ + if ((sg_widgets = + gtk_size_group_get_widgets (GTK_SIZE_GROUP (object))) != NULL) + { + /* copy since we are modifying an internal list */ + sg_widgets = g_slist_copy (sg_widgets); + for (slist = sg_widgets; slist; slist = slist->next) + gtk_size_group_remove_widget (GTK_SIZE_GROUP (object), + GTK_WIDGET (slist->data)); + g_slist_free (sg_widgets); + } - /* add new widgets */ - if ((widgets = g_value_get_boxed (value)) != NULL) - { - for (list = widgets; list; list = list->next) - gtk_size_group_add_widget (GTK_SIZE_GROUP (object), GTK_WIDGET (list->data)); - } - } - else - GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, - property_name, value); + /* add new widgets */ + if ((widgets = g_value_get_boxed (value)) != NULL) + { + for (list = widgets; list; list = list->next) + gtk_size_group_add_widget (GTK_SIZE_GROUP (object), + GTK_WIDGET (list->data)); + } + } + else + GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, + property_name, value); } /*--------------------------- GtkIconFactory ---------------------------------*/ @@ -8808,394 +8807,404 @@ glade_gtk_size_group_set_property (GladeWidgetAdaptor *adaptor, #define GLADE_TAG_SIZE "size" void -glade_gtk_icon_factory_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_icon_factory_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - gtk_icon_factory_add_default (GTK_ICON_FACTORY (object)); + gtk_icon_factory_add_default (GTK_ICON_FACTORY (object)); } static void -glade_gtk_icon_factory_read_sources (GladeWidget *widget, - GladeXmlNode *node) -{ - GladeIconSources *sources; - GtkIconSource *source; - GladeXmlNode *sources_node, *source_node; - GValue *value; - GList *list; - gchar *current_icon_name = NULL; - GdkPixbuf *pixbuf; - - if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL) - return; - - sources = glade_icon_sources_new (); - - /* Here we expect all icon sets to remain together in the list. */ - for (source_node = glade_xml_node_get_children (sources_node); source_node; - source_node = glade_xml_node_next (source_node)) - { - gchar *icon_name; - gchar *str; - - if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE)) - continue; - - if (!(icon_name = - glade_xml_get_property_string_required (source_node, GLADE_TAG_STOCK_ID, NULL))) - continue; - - if (!(str = glade_xml_get_property_string_required (source_node, GLADE_TAG_FILENAME, NULL))) - { - g_free (icon_name); - continue; - } - - if (!current_icon_name || strcmp (current_icon_name, icon_name) != 0) - current_icon_name = (g_free (current_icon_name), g_strdup (icon_name)); - - source = gtk_icon_source_new (); - - /* Deal with the filename... */ - value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str, - widget->project, widget); - pixbuf = g_value_dup_object (value); - g_value_unset (value); - g_free (value); - - gtk_icon_source_set_pixbuf (source, pixbuf); - g_object_unref (G_OBJECT (pixbuf)); - g_free (str); - - /* Now the attributes... */ - if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_DIRECTION)) != NULL) - { - GtkTextDirection direction = - glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str); - gtk_icon_source_set_direction_wildcarded (source, FALSE); - gtk_icon_source_set_direction (source, direction); - g_free (str); - } - - if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL) - { - GtkIconSize size = - glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str); - gtk_icon_source_set_size_wildcarded (source, FALSE); - gtk_icon_source_set_size (source, size); - g_free (str); - } - - if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_STATE)) != NULL) - { - GtkStateType state = - glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str); - gtk_icon_source_set_state_wildcarded (source, FALSE); - gtk_icon_source_set_state (source, state); - g_free (str); - } - - if ((list = g_hash_table_lookup (sources->sources, g_strdup (current_icon_name))) != NULL) - { - GList *new_list = g_list_append (list, source); - - /* Warning: if we use g_list_prepend() the returned pointer will be different - * so we would have to replace the list pointer in the hash table. - * But before doing that we have to steal the old list pointer otherwise - * we would have to make a copy then add the new icon to finally replace the hash table - * value. - * Anyways if we choose to prepend we would have to reverse the list outside this loop - * so its better to append. - */ - if (new_list != list) - { - /* current g_list_append() returns the same pointer so this is not needed */ - g_hash_table_steal (sources->sources, current_icon_name); - g_hash_table_insert (sources->sources, g_strdup (current_icon_name), new_list); - } - } - else - { - list = g_list_append (NULL, source); - g_hash_table_insert (sources->sources, g_strdup (current_icon_name), list); - } - } - - if (g_hash_table_size (sources->sources) > 0) - glade_widget_property_set (widget, "sources", sources); - - glade_icon_sources_free (sources); -} - -void -glade_gtk_icon_factory_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and read in any normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); - - glade_gtk_icon_factory_read_sources (widget, node); -} - -typedef struct { - GladeXmlContext *context; - GladeXmlNode *node; -} SourceWriteTab; +glade_gtk_icon_factory_read_sources (GladeWidget * widget, GladeXmlNode * node) +{ + GladeIconSources *sources; + GtkIconSource *source; + GladeXmlNode *sources_node, *source_node; + GValue *value; + GList *list; + gchar *current_icon_name = NULL; + GdkPixbuf *pixbuf; + + if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL) + return; + + sources = glade_icon_sources_new (); + + /* Here we expect all icon sets to remain together in the list. */ + for (source_node = glade_xml_node_get_children (sources_node); source_node; + source_node = glade_xml_node_next (source_node)) + { + gchar *icon_name; + gchar *str; + + if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE)) + continue; + + if (!(icon_name = + glade_xml_get_property_string_required (source_node, + GLADE_TAG_STOCK_ID, NULL))) + continue; + + if (! + (str = + glade_xml_get_property_string_required (source_node, + GLADE_TAG_FILENAME, NULL))) + { + g_free (icon_name); + continue; + } -static void -write_icon_sources (gchar *icon_name, - GList *sources, - SourceWriteTab *tab) -{ - GladeXmlNode *source_node; - GtkIconSource *source; - GList *l; - gchar *string; + if (!current_icon_name || strcmp (current_icon_name, icon_name) != 0) + current_icon_name = (g_free (current_icon_name), g_strdup (icon_name)); + + source = gtk_icon_source_new (); + + /* Deal with the filename... */ + value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str, + widget->project, widget); + pixbuf = g_value_dup_object (value); + g_value_unset (value); + g_free (value); + + gtk_icon_source_set_pixbuf (source, pixbuf); + g_object_unref (G_OBJECT (pixbuf)); + g_free (str); + + /* Now the attributes... */ + if ((str = + glade_xml_get_property_string (source_node, + GLADE_TAG_DIRECTION)) != NULL) + { + GtkTextDirection direction = + glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str); + gtk_icon_source_set_direction_wildcarded (source, FALSE); + gtk_icon_source_set_direction (source, direction); + g_free (str); + } + + if ((str = + glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL) + { + GtkIconSize size = + glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str); + gtk_icon_source_set_size_wildcarded (source, FALSE); + gtk_icon_source_set_size (source, size); + g_free (str); + } + + if ((str = + glade_xml_get_property_string (source_node, + GLADE_TAG_STATE)) != NULL) + { + GtkStateType state = + glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str); + gtk_icon_source_set_state_wildcarded (source, FALSE); + gtk_icon_source_set_state (source, state); + g_free (str); + } + + if ((list = + g_hash_table_lookup (sources->sources, + g_strdup (current_icon_name))) != NULL) + { + GList *new_list = g_list_append (list, source); + + /* Warning: if we use g_list_prepend() the returned pointer will be different + * so we would have to replace the list pointer in the hash table. + * But before doing that we have to steal the old list pointer otherwise + * we would have to make a copy then add the new icon to finally replace the hash table + * value. + * Anyways if we choose to prepend we would have to reverse the list outside this loop + * so its better to append. + */ + if (new_list != list) + { + /* current g_list_append() returns the same pointer so this is not needed */ + g_hash_table_steal (sources->sources, current_icon_name); + g_hash_table_insert (sources->sources, + g_strdup (current_icon_name), new_list); + } + } + else + { + list = g_list_append (NULL, source); + g_hash_table_insert (sources->sources, g_strdup (current_icon_name), + list); + } + } + + if (g_hash_table_size (sources->sources) > 0) + glade_widget_property_set (widget, "sources", sources); + + glade_icon_sources_free (sources); +} - GdkPixbuf *pixbuf; +void +glade_gtk_icon_factory_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - for (l = sources; l; l = l->next) - { - source = l->data; + /* First chain up and read in any normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); - source_node = glade_xml_node_new (tab->context, GLADE_TAG_SOURCE); - glade_xml_node_append_child (tab->node, source_node); + glade_gtk_icon_factory_read_sources (widget, node); +} - glade_xml_node_set_property_string (source_node, GLADE_TAG_STOCK_ID, icon_name); +typedef struct +{ + GladeXmlContext *context; + GladeXmlNode *node; +} SourceWriteTab; - if (!gtk_icon_source_get_direction_wildcarded (source)) - { - GtkTextDirection direction = gtk_icon_source_get_direction (source); - string = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction); - glade_xml_node_set_property_string (source_node, GLADE_TAG_DIRECTION, string); - g_free (string); - } +static void +write_icon_sources (gchar * icon_name, GList * sources, SourceWriteTab * tab) +{ + GladeXmlNode *source_node; + GtkIconSource *source; + GList *l; + gchar *string; + + GdkPixbuf *pixbuf; + + for (l = sources; l; l = l->next) + { + source = l->data; + + source_node = glade_xml_node_new (tab->context, GLADE_TAG_SOURCE); + glade_xml_node_append_child (tab->node, source_node); + + glade_xml_node_set_property_string (source_node, GLADE_TAG_STOCK_ID, + icon_name); + + if (!gtk_icon_source_get_direction_wildcarded (source)) + { + GtkTextDirection direction = gtk_icon_source_get_direction (source); + string = + glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, + direction); + glade_xml_node_set_property_string (source_node, GLADE_TAG_DIRECTION, + string); + g_free (string); + } - if (!gtk_icon_source_get_size_wildcarded (source)) - { - GtkIconSize size = gtk_icon_source_get_size (source); - string = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size); - glade_xml_node_set_property_string (source_node, GLADE_TAG_SIZE, string); - g_free (string); - } + if (!gtk_icon_source_get_size_wildcarded (source)) + { + GtkIconSize size = gtk_icon_source_get_size (source); + string = + glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size); + glade_xml_node_set_property_string (source_node, GLADE_TAG_SIZE, + string); + g_free (string); + } - if (!gtk_icon_source_get_state_wildcarded (source)) - { - GtkStateType state = gtk_icon_source_get_state (source); - string = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state); - glade_xml_node_set_property_string (source_node, GLADE_TAG_STATE, string); - g_free (string); - } + if (!gtk_icon_source_get_state_wildcarded (source)) + { + GtkStateType state = gtk_icon_source_get_state (source); + string = + glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state); + glade_xml_node_set_property_string (source_node, GLADE_TAG_STATE, + string); + g_free (string); + } - pixbuf = gtk_icon_source_get_pixbuf (source); - string = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName"); + pixbuf = gtk_icon_source_get_pixbuf (source); + string = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName"); - glade_xml_node_set_property_string (source_node, - GLADE_TAG_FILENAME, - string); - } + glade_xml_node_set_property_string (source_node, + GLADE_TAG_FILENAME, string); + } } static void -glade_gtk_icon_factory_write_sources (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_icon_factory_write_sources (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *sources_node; - GladeIconSources *sources = NULL; - SourceWriteTab tab; + GladeXmlNode *sources_node; + GladeIconSources *sources = NULL; + SourceWriteTab tab; - glade_widget_property_get (widget, "sources", &sources); - if (!sources) - return; + glade_widget_property_get (widget, "sources", &sources); + if (!sources) + return; - sources_node = glade_xml_node_new (context, GLADE_TAG_SOURCES); + sources_node = glade_xml_node_new (context, GLADE_TAG_SOURCES); - tab.context = context; - tab.node = sources_node; - g_hash_table_foreach (sources->sources, (GHFunc)write_icon_sources, &tab); + tab.context = context; + tab.node = sources_node; + g_hash_table_foreach (sources->sources, (GHFunc) write_icon_sources, &tab); - if (!glade_xml_node_get_children (sources_node)) - glade_xml_node_delete (sources_node); - else - glade_xml_node_append_child (node, sources_node); + if (!glade_xml_node_get_children (sources_node)) + glade_xml_node_delete (sources_node); + else + glade_xml_node_append_child (node, sources_node); } void -glade_gtk_icon_factory_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_icon_factory_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* First chain up and write all the normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); + /* First chain up and write all the normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); - glade_gtk_icon_factory_write_sources (widget, context, node); + glade_gtk_icon_factory_write_sources (widget, context, node); } static void -apply_icon_sources (gchar *icon_name, - GList *sources, - GtkIconFactory *factory) +apply_icon_sources (gchar * icon_name, + GList * sources, GtkIconFactory * factory) { - GtkIconSource *source; - GtkIconSet *set; - GList *l; + GtkIconSource *source; + GtkIconSet *set; + GList *l; - set = gtk_icon_set_new (); + set = gtk_icon_set_new (); - for (l = sources; l; l = l->next) - { - source = gtk_icon_source_copy ((GtkIconSource *)l->data); - gtk_icon_set_add_source (set, source); - } + for (l = sources; l; l = l->next) + { + source = gtk_icon_source_copy ((GtkIconSource *) l->data); + gtk_icon_set_add_source (set, source); + } - gtk_icon_factory_add (factory, icon_name, set); + gtk_icon_factory_add (factory, icon_name, set); } static void -glade_gtk_icon_factory_set_sources (GObject *object, const GValue *value) +glade_gtk_icon_factory_set_sources (GObject * object, const GValue * value) { - GladeIconSources *sources = g_value_get_boxed (value); - if (sources) - g_hash_table_foreach (sources->sources, (GHFunc)apply_icon_sources, object); + GladeIconSources *sources = g_value_get_boxed (value); + if (sources) + g_hash_table_foreach (sources->sources, (GHFunc) apply_icon_sources, + object); } void -glade_gtk_icon_factory_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) +glade_gtk_icon_factory_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + const GValue * value) { - if (strcmp (property_name, "sources") == 0) - { - glade_gtk_icon_factory_set_sources (object, value); - } - else - /* Chain Up */ - GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, - object, - property_name, - value); + if (strcmp (property_name, "sources") == 0) + { + glade_gtk_icon_factory_set_sources (object, value); + } + else + /* Chain Up */ + GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, + object, property_name, value); } static void -serialize_icon_sources (gchar *icon_name, - GList *sources, - GString *string) -{ - GList *l; - - for (l = sources; l; l = g_list_next (l)) - { - GtkIconSource *source = l->data; - GdkPixbuf *pixbuf; - gchar *str; - - pixbuf = gtk_icon_source_get_pixbuf (source); - str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName"); - - g_string_append_printf (string, "%s[%s] ", icon_name, str); - - if (!gtk_icon_source_get_direction_wildcarded (source)) - { - GtkTextDirection direction = gtk_icon_source_get_direction (source); - str = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction); - g_string_append_printf (string, "dir-%s ", str); - g_free (str); - } - - if (!gtk_icon_source_get_size_wildcarded (source)) - { - GtkIconSize size = gtk_icon_source_get_size (source); - str = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size); - g_string_append_printf (string, "size-%s ", str); - g_free (str); - } - - if (!gtk_icon_source_get_state_wildcarded (source)) - { - GtkStateType state = gtk_icon_source_get_state (source); - str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state); - g_string_append_printf (string, "state-%s ", str); - g_free (str); - } - - g_string_append_printf (string, "| "); - } +serialize_icon_sources (gchar * icon_name, GList * sources, GString * string) +{ + GList *l; + + for (l = sources; l; l = g_list_next (l)) + { + GtkIconSource *source = l->data; + GdkPixbuf *pixbuf; + gchar *str; + + pixbuf = gtk_icon_source_get_pixbuf (source); + str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName"); + + g_string_append_printf (string, "%s[%s] ", icon_name, str); + + if (!gtk_icon_source_get_direction_wildcarded (source)) + { + GtkTextDirection direction = gtk_icon_source_get_direction (source); + str = + glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, + direction); + g_string_append_printf (string, "dir-%s ", str); + g_free (str); + } + + if (!gtk_icon_source_get_size_wildcarded (source)) + { + GtkIconSize size = gtk_icon_source_get_size (source); + str = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size); + g_string_append_printf (string, "size-%s ", str); + g_free (str); + } + + if (!gtk_icon_source_get_state_wildcarded (source)) + { + GtkStateType state = gtk_icon_source_get_state (source); + str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state); + g_string_append_printf (string, "state-%s ", str); + g_free (str); + } + + g_string_append_printf (string, "| "); + } } gchar * -glade_gtk_icon_factory_string_from_value (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - const GValue *value) +glade_gtk_icon_factory_string_from_value (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, + const GValue * value) { - GString *string; + GString *string; - if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES) - { - GladeIconSources *sources = g_value_get_boxed (value); - if (!sources) - return g_strdup (""); + if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES) + { + GladeIconSources *sources = g_value_get_boxed (value); + if (!sources) + return g_strdup (""); - string = g_string_new (""); - g_hash_table_foreach (sources->sources, (GHFunc)serialize_icon_sources, string); + string = g_string_new (""); + g_hash_table_foreach (sources->sources, (GHFunc) serialize_icon_sources, + string); - return g_string_free (string, FALSE); - } - else - return GWA_GET_CLASS - (G_TYPE_OBJECT)->string_from_value (adaptor, - klass, - value); + return g_string_free (string, FALSE); + } + else + return GWA_GET_CLASS + (G_TYPE_OBJECT)->string_from_value (adaptor, klass, value); } GladeEditorProperty * -glade_gtk_icon_factory_create_eprop (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - gboolean use_command) +glade_gtk_icon_factory_create_eprop (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, + gboolean use_command) { - GladeEditorProperty *eprop; + GladeEditorProperty *eprop; - if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES) - eprop = g_object_new (GLADE_TYPE_EPROP_ICON_SOURCES, - "property-class", klass, - "use-command", use_command, - NULL); - else - eprop = GWA_GET_CLASS - (G_TYPE_OBJECT)->create_eprop (adaptor, - klass, - use_command); - return eprop; + if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES) + eprop = g_object_new (GLADE_TYPE_EPROP_ICON_SOURCES, + "property-class", klass, + "use-command", use_command, NULL); + else + eprop = GWA_GET_CLASS + (G_TYPE_OBJECT)->create_eprop (adaptor, klass, use_command); + return eprop; } GladeEditable * -glade_gtk_icon_factory_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_icon_factory_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type); + /* Get base editable */ + editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_icon_factory_editor_new (adaptor, editable); + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_icon_factory_editor_new (adaptor, editable); - return editable; + return editable; } @@ -9210,1537 +9219,1562 @@ glade_gtk_icon_factory_create_editable (GladeWidgetAdaptor *adaptor, #define GLADE_TAG_COL "col" -static gboolean -glade_gtk_cell_layout_has_renderer (GtkCellLayout *layout, - GtkCellRenderer *renderer) +static gboolean +glade_gtk_cell_layout_has_renderer (GtkCellLayout * layout, + GtkCellRenderer * renderer) { - GList *cells = gtk_cell_layout_get_cells (layout); - gboolean has_renderer; + GList *cells = gtk_cell_layout_get_cells (layout); + gboolean has_renderer; - has_renderer = (g_list_find (cells, renderer) != NULL); + has_renderer = (g_list_find (cells, renderer) != NULL); - g_list_free (cells); + g_list_free (cells); - return has_renderer; + return has_renderer; } static gboolean -glade_gtk_cell_renderer_sync_attributes (GObject *object) -{ - - GtkCellLayout *layout; - GtkCellRenderer *cell; - GladeWidget *widget = glade_widget_get_from_gobject (object); - GladeWidget *gmodel; - GladeProperty *property; - gchar *attr_prop_name; - GList *l, *column_list = NULL; - gint columns = 0; - static gint attr_len = 0; - - if (!attr_len) - attr_len = strlen ("attr-"); +glade_gtk_cell_renderer_sync_attributes (GObject * object) +{ + + GtkCellLayout *layout; + GtkCellRenderer *cell; + GladeWidget *widget = glade_widget_get_from_gobject (object); + GladeWidget *gmodel; + GladeProperty *property; + gchar *attr_prop_name; + GList *l, *column_list = NULL; + gint columns = 0; + static gint attr_len = 0; + + if (!attr_len) + attr_len = strlen ("attr-"); + + /* Apply attributes to renderer when bound to a model in runtime */ + widget = glade_widget_get_from_gobject (object); + + if (widget->parent == NULL) + return FALSE; + + /* When creating widgets, sometimes the parent is set before parenting happens, + * here we have to be careful for that.. + */ + layout = GTK_CELL_LAYOUT (widget->parent->object); + cell = GTK_CELL_RENDERER (object); + + if (!glade_gtk_cell_layout_has_renderer (layout, cell)) + return FALSE; + + if ((gmodel = glade_cell_renderer_get_model (widget)) == NULL) + return FALSE; + + glade_widget_property_get (gmodel, "columns", &column_list); + columns = g_list_length (column_list); + + gtk_cell_layout_clear_attributes (layout, cell); + + for (l = widget->properties; l; l = l->next) + { + property = l->data; + + if (strncmp (property->klass->id, "attr-", attr_len) == 0) + { + GladeProperty *attr_prop; + gint column = g_value_get_int (property->value); + + attr_prop_name = &property->klass->id[attr_len]; + attr_prop = glade_widget_get_property (widget, attr_prop_name); + + if (column >= 0 && column < columns) + { + GladeColumnType *column_type = + (GladeColumnType *) g_list_nth_data (column_list, column); + GType column_gtype = g_type_from_name (column_type->type_name); + + if (column_gtype && + g_value_type_transformable (column_gtype, + attr_prop->klass->pspec-> + value_type)) + gtk_cell_layout_add_attribute (layout, cell, attr_prop_name, + column); + } + } + } - /* Apply attributes to renderer when bound to a model in runtime */ - widget = glade_widget_get_from_gobject (object); - - if (widget->parent == NULL) return FALSE; + return FALSE; +} - /* When creating widgets, sometimes the parent is set before parenting happens, - * here we have to be careful for that.. - */ - layout = GTK_CELL_LAYOUT (widget->parent->object); - cell = GTK_CELL_RENDERER (object); - if (!glade_gtk_cell_layout_has_renderer (layout, cell)) - return FALSE; +static gboolean +glade_gtk_cell_layout_sync_attributes (GObject * layout) +{ + GladeWidget *gwidget = glade_widget_get_from_gobject (layout); + GObject *cell; + GList *children, *l; - if ((gmodel = glade_cell_renderer_get_model (widget)) == NULL) - return FALSE; + children = glade_widget_adaptor_get_children (gwidget->adaptor, layout); + for (l = children; l; l = l->next) + { + cell = l->data; + if (!GTK_IS_CELL_RENDERER (cell)) + continue; - glade_widget_property_get (gmodel, "columns", &column_list); - columns = g_list_length (column_list); + glade_gtk_cell_renderer_sync_attributes (cell); + } + g_list_free (children); - gtk_cell_layout_clear_attributes (layout, cell); + return FALSE; +} - for (l = widget->properties; l; l = l->next) - { - property = l->data; +static void +glade_gtk_store_set_columns (GObject * object, const GValue * value) +{ + GList *l; + gint i, n; + GType *types; - if (strncmp (property->klass->id, "attr-", attr_len) == 0) - { - GladeProperty *attr_prop; - gint column = g_value_get_int (property->value); + for (i = 0, l = g_value_get_boxed (value), n = g_list_length (l), types = + g_new (GType, n); l; l = g_list_next (l), i++) + { + GladeColumnType *data = l->data; - attr_prop_name = &property->klass->id[attr_len]; - attr_prop = glade_widget_get_property (widget, attr_prop_name); + if (g_type_from_name (data->type_name) != G_TYPE_INVALID) + types[i] = g_type_from_name (data->type_name); + else + types[i] = G_TYPE_POINTER; + } - if (column >= 0 && column < columns) - { - GladeColumnType *column_type = (GladeColumnType *)g_list_nth_data (column_list, column); - GType column_gtype = g_type_from_name (column_type->type_name); + if (GTK_IS_LIST_STORE (object)) + gtk_list_store_set_column_types (GTK_LIST_STORE (object), n, types); + else + gtk_tree_store_set_column_types (GTK_TREE_STORE (object), n, types); - if (column_gtype && - g_value_type_transformable (column_gtype, attr_prop->klass->pspec->value_type)) - gtk_cell_layout_add_attribute (layout, cell, attr_prop_name, column); - } - } - } + g_free (types); +} - return FALSE; +static void +glade_gtk_store_set_data (GObject * object, const GValue * value) +{ + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GList *columns = NULL; + GNode *data_tree, *row, *iter; + gint colnum; + GtkTreeIter row_iter; + GladeModelData *data; + GType column_type; + + if (GTK_IS_LIST_STORE (object)) + gtk_list_store_clear (GTK_LIST_STORE (object)); + else + gtk_tree_store_clear (GTK_TREE_STORE (object)); + + glade_widget_property_get (gwidget, "columns", &columns); + data_tree = g_value_get_boxed (value); + + /* Nothing to enter without columns defined */ + if (!data_tree || !columns) + return; + + for (row = data_tree->children; row; row = row->next) + { + if (GTK_IS_LIST_STORE (object)) + gtk_list_store_append (GTK_LIST_STORE (object), &row_iter); + else + /* (for now no child data... ) */ + gtk_tree_store_append (GTK_TREE_STORE (object), &row_iter, NULL); + + for (colnum = 0, iter = row->children; iter; colnum++, iter = iter->next) + { + data = iter->data; + + if (!g_list_nth (columns, colnum)) + break; + + /* Abort if theres a type mismatch, the widget's being rebuilt + * and a sync will come soon with the right values + */ + column_type = + gtk_tree_model_get_column_type (GTK_TREE_MODEL (object), colnum); + if (G_VALUE_TYPE (&data->value) != column_type) + continue; + + if (GTK_IS_LIST_STORE (object)) + gtk_list_store_set_value (GTK_LIST_STORE (object), + &row_iter, colnum, &data->value); + else + gtk_tree_store_set_value (GTK_TREE_STORE (object), + &row_iter, colnum, &data->value); + } + } } +void +glade_gtk_store_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, const GValue * value) +{ + if (strcmp (property_name, "columns") == 0) + { + glade_gtk_store_set_columns (object, value); + } + else if (strcmp (property_name, "data") == 0) + { + glade_gtk_store_set_data (object, value); + } + else + /* Chain Up */ + GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, + object, property_name, value); +} -static gboolean -glade_gtk_cell_layout_sync_attributes (GObject *layout) +GladeEditorProperty * +glade_gtk_store_create_eprop (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, gboolean use_command) { - GladeWidget *gwidget = glade_widget_get_from_gobject (layout); - GObject *cell; - GList *children, *l; + GladeEditorProperty *eprop; - children = glade_widget_adaptor_get_children (gwidget->adaptor, layout); - for (l = children; l; l = l->next) - { - cell = l->data; - if (!GTK_IS_CELL_RENDERER (cell)) - continue; + /* chain up.. */ + if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST) + eprop = g_object_new (GLADE_TYPE_EPROP_COLUMN_TYPES, + "property-class", klass, + "use-command", use_command, NULL); + else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE) + eprop = g_object_new (GLADE_TYPE_EPROP_MODEL_DATA, + "property-class", klass, + "use-command", use_command, NULL); + else + eprop = GWA_GET_CLASS + (G_TYPE_OBJECT)->create_eprop (adaptor, klass, use_command); + return eprop; +} - glade_gtk_cell_renderer_sync_attributes (cell); - } - g_list_free (children); - return FALSE; +static void +glade_gtk_store_columns_changed (GladeProperty * property, + GValue * old_value, + GValue * new_value, GladeWidget * store) +{ + GList *l, *list, *children; + + /* Reset the attributes for all cell renderers referring to this store */ + for (l = store->prop_refs; l; l = l->next) + { + GladeWidget *referring_widget = GLADE_PROPERTY (l->data)->widget; + + if (GTK_IS_CELL_LAYOUT (referring_widget->object)) + glade_gtk_cell_layout_sync_attributes (referring_widget->object); + else if (GTK_IS_TREE_VIEW (referring_widget->object)) + { + children = + glade_widget_adaptor_get_children (referring_widget->adaptor, + referring_widget->object); + + for (list = children; list; list = list->next) + { + /* Clear the GtkTreeViewColumns... */ + if (GTK_IS_CELL_LAYOUT (list->data)) + glade_gtk_cell_layout_sync_attributes (G_OBJECT (list->data)); + } + + g_list_free (children); + } + } } -static void -glade_gtk_store_set_columns (GObject *object, - const GValue *value) +void +glade_gtk_store_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GList *l; - gint i, n; - GType *types; - - for (i = 0, l = g_value_get_boxed (value), n = g_list_length (l), types = g_new (GType, n); - l; l = g_list_next (l), i++) - { - GladeColumnType *data = l->data; - - if (g_type_from_name (data->type_name) != G_TYPE_INVALID) - types[i] = g_type_from_name (data->type_name); - else - types[i] = G_TYPE_POINTER; - } + GladeWidget *gwidget; + GladeProperty *property; - if (GTK_IS_LIST_STORE (object)) - gtk_list_store_set_column_types (GTK_LIST_STORE (object), n, types); - else - gtk_tree_store_set_column_types (GTK_TREE_STORE (object), n, types); + if (reason == GLADE_CREATE_REBUILD) + return; - g_free (types); -} - -static void -glade_gtk_store_set_data (GObject *object, - const GValue *value) -{ - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - GList *columns = NULL; - GNode *data_tree, *row, *iter; - gint colnum; - GtkTreeIter row_iter; - GladeModelData *data; - GType column_type; - - if (GTK_IS_LIST_STORE (object)) - gtk_list_store_clear (GTK_LIST_STORE (object)); - else - gtk_tree_store_clear (GTK_TREE_STORE (object)); - - glade_widget_property_get (gwidget, "columns", &columns); - data_tree = g_value_get_boxed (value); - - /* Nothing to enter without columns defined */ - if (!data_tree || !columns) - return; - - for (row = data_tree->children; row; row = row->next) - { - if (GTK_IS_LIST_STORE (object)) - gtk_list_store_append (GTK_LIST_STORE (object), &row_iter); - else - /* (for now no child data... ) */ - gtk_tree_store_append (GTK_TREE_STORE (object), &row_iter, NULL); - - for (colnum = 0, iter = row->children; iter; - colnum++, iter = iter->next) - { - data = iter->data; - - if (!g_list_nth (columns, colnum)) - break; - - /* Abort if theres a type mismatch, the widget's being rebuilt - * and a sync will come soon with the right values - */ - column_type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (object), colnum); - if (G_VALUE_TYPE (&data->value) != column_type) - continue; - - if (GTK_IS_LIST_STORE (object)) - gtk_list_store_set_value (GTK_LIST_STORE (object), - &row_iter, - colnum, &data->value); - else - gtk_tree_store_set_value (GTK_TREE_STORE (object), - &row_iter, - colnum, &data->value); - } - } -} - -void -glade_gtk_store_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) -{ - if (strcmp (property_name, "columns") == 0) - { - glade_gtk_store_set_columns (object, value); - } - else if (strcmp (property_name, "data") == 0) - { - glade_gtk_store_set_data (object, value); - } - else - /* Chain Up */ - GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, - object, - property_name, - value); -} + gwidget = glade_widget_get_from_gobject (object); + property = glade_widget_get_property (gwidget, "columns"); -GladeEditorProperty * -glade_gtk_store_create_eprop (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - gboolean use_command) -{ - GladeEditorProperty *eprop; - - /* chain up.. */ - if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST) - eprop = g_object_new (GLADE_TYPE_EPROP_COLUMN_TYPES, - "property-class", klass, - "use-command", use_command, - NULL); - else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE) - eprop = g_object_new (GLADE_TYPE_EPROP_MODEL_DATA, - "property-class", klass, - "use-command", use_command, - NULL); - else - eprop = GWA_GET_CLASS - (G_TYPE_OBJECT)->create_eprop (adaptor, - klass, - use_command); - return eprop; -} - - -static void -glade_gtk_store_columns_changed (GladeProperty *property, - GValue *old_value, - GValue *new_value, - GladeWidget *store) -{ - GList *l, *list, *children; - - /* Reset the attributes for all cell renderers referring to this store */ - for (l = store->prop_refs; l; l = l->next) - { - GladeWidget *referring_widget = GLADE_PROPERTY (l->data)->widget; - - if (GTK_IS_CELL_LAYOUT (referring_widget->object)) - glade_gtk_cell_layout_sync_attributes (referring_widget->object); - else if (GTK_IS_TREE_VIEW (referring_widget->object)) - { - children = glade_widget_adaptor_get_children (referring_widget->adaptor, - referring_widget->object); - - for (list = children; list; list = list->next) - { - /* Clear the GtkTreeViewColumns... */ - if (GTK_IS_CELL_LAYOUT (list->data)) - glade_gtk_cell_layout_sync_attributes (G_OBJECT (list->data)); - } - - g_list_free (children); - } - } -} - -void -glade_gtk_store_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) -{ - GladeWidget *gwidget; - GladeProperty *property; - - if (reason == GLADE_CREATE_REBUILD) - return; - - gwidget = glade_widget_get_from_gobject (object); - property = glade_widget_get_property (gwidget, "columns"); - - /* Here we watch the value-changed signal on the "columns" property, we need - * to reset all the Cell Renderer attributes when the underlying "columns" change, - * the reason we do it from "value-changed" is because GladeWidget prop references - * are unavailable while rebuilding an object, and the liststore needs to be rebuilt - * in order to set the columns. - * - * This signal will be envoked after applying the new column types to the store - * and before the views get any signal to update themselves from the changed model, - * perfect time to reset the attributes. - */ - g_signal_connect (G_OBJECT (property), "value-changed", - G_CALLBACK (glade_gtk_store_columns_changed), gwidget); + /* Here we watch the value-changed signal on the "columns" property, we need + * to reset all the Cell Renderer attributes when the underlying "columns" change, + * the reason we do it from "value-changed" is because GladeWidget prop references + * are unavailable while rebuilding an object, and the liststore needs to be rebuilt + * in order to set the columns. + * + * This signal will be envoked after applying the new column types to the store + * and before the views get any signal to update themselves from the changed model, + * perfect time to reset the attributes. + */ + g_signal_connect (G_OBJECT (property), "value-changed", + G_CALLBACK (glade_gtk_store_columns_changed), gwidget); } GladeEditable * -glade_gtk_store_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_store_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type); + /* Get base editable */ + editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL) - return (GladeEditable *)glade_store_editor_new (adaptor, editable); + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *) glade_store_editor_new (adaptor, editable); - return editable; + return editable; } gchar * -glade_gtk_store_string_from_value (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - const GValue *value) -{ - GString *string; - - if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST) - { - GList *l; - string = g_string_new (""); - for (l = g_value_get_boxed (value); l; l = g_list_next (l)) - { - GladeColumnType *data = l->data; - g_string_append_printf (string, (g_list_next (l)) ? "%s:%s|" : "%s:%s", - data->type_name, data->column_name); - } - return g_string_free (string, FALSE); - } - else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE) - { - GladeModelData *data; - GNode *data_tree, *row, *iter; - gint rownum; - gchar *str; - gboolean is_last; - - /* Return a unique string for the backend to compare */ - data_tree = g_value_get_boxed (value); - - if (!data_tree || !data_tree->children) - return g_strdup (""); - - string = g_string_new (""); - for (rownum = 0, row = data_tree->children; row; - rownum++, row = row->next) - { - for (iter = row->children; iter; iter = iter->next) - { - data = iter->data; - - if (!G_VALUE_TYPE (&data->value) || - G_VALUE_TYPE (&data->value) == G_TYPE_INVALID) - str = g_strdup ("(virtual)"); - else if (G_VALUE_TYPE (&data->value) != G_TYPE_POINTER) - str = glade_utils_string_from_value (&data->value); - else - str = g_strdup ("(null)"); - - is_last = !row->next && !iter->next; - g_string_append_printf (string, "%s[%d]:%s", - data->name, rownum, str); - - if (data->i18n_translatable) - g_string_append_printf (string, " translatable"); - if (data->i18n_context) - g_string_append_printf (string, " i18n-context:%s", data->i18n_context); - if (data->i18n_comment) - g_string_append_printf (string, " i18n-comment:%s", data->i18n_comment); - - if (!is_last) - g_string_append_printf (string, "|"); - - g_free (str); - } - } - return g_string_free (string, FALSE); - } - else - return GWA_GET_CLASS - (G_TYPE_OBJECT)->string_from_value (adaptor, - klass, - value); +glade_gtk_store_string_from_value (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, + const GValue * value) +{ + GString *string; + + if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST) + { + GList *l; + string = g_string_new (""); + for (l = g_value_get_boxed (value); l; l = g_list_next (l)) + { + GladeColumnType *data = l->data; + g_string_append_printf (string, + (g_list_next (l)) ? "%s:%s|" : "%s:%s", + data->type_name, data->column_name); + } + return g_string_free (string, FALSE); + } + else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE) + { + GladeModelData *data; + GNode *data_tree, *row, *iter; + gint rownum; + gchar *str; + gboolean is_last; + + /* Return a unique string for the backend to compare */ + data_tree = g_value_get_boxed (value); + + if (!data_tree || !data_tree->children) + return g_strdup (""); + + string = g_string_new (""); + for (rownum = 0, row = data_tree->children; row; + rownum++, row = row->next) + { + for (iter = row->children; iter; iter = iter->next) + { + data = iter->data; + + if (!G_VALUE_TYPE (&data->value) || + G_VALUE_TYPE (&data->value) == G_TYPE_INVALID) + str = g_strdup ("(virtual)"); + else if (G_VALUE_TYPE (&data->value) != G_TYPE_POINTER) + str = glade_utils_string_from_value (&data->value); + else + str = g_strdup ("(null)"); + + is_last = !row->next && !iter->next; + g_string_append_printf (string, "%s[%d]:%s", + data->name, rownum, str); + + if (data->i18n_translatable) + g_string_append_printf (string, " translatable"); + if (data->i18n_context) + g_string_append_printf (string, " i18n-context:%s", + data->i18n_context); + if (data->i18n_comment) + g_string_append_printf (string, " i18n-comment:%s", + data->i18n_comment); + + if (!is_last) + g_string_append_printf (string, "|"); + + g_free (str); + } + } + return g_string_free (string, FALSE); + } + else + return GWA_GET_CLASS + (G_TYPE_OBJECT)->string_from_value (adaptor, klass, value); } static void -glade_gtk_store_write_columns (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) -{ - GladeXmlNode *columns_node; - GladeProperty *prop; - GList *l; - - prop = glade_widget_get_property (widget, "columns"); - - columns_node = glade_xml_node_new (context, GLADE_TAG_COLUMNS); - - for (l = g_value_get_boxed (prop->value); l; l = g_list_next (l)) - { - GladeColumnType *data = l->data; - GladeXmlNode *column_node, *comment_node; - - /* Write column names in comments... */ - gchar *comment = g_strdup_printf (" column-name %s ", data->column_name); - comment_node = glade_xml_node_new_comment (context, comment); - glade_xml_node_append_child (columns_node, comment_node); - g_free (comment); - - column_node = glade_xml_node_new (context, GLADE_TAG_COLUMN); - glade_xml_node_append_child (columns_node, column_node); - glade_xml_node_set_property_string (column_node, GLADE_TAG_TYPE, - data->type_name); - } - - if (!glade_xml_node_get_children (columns_node)) - glade_xml_node_delete (columns_node); - else - glade_xml_node_append_child (node, columns_node); +glade_gtk_store_write_columns (GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) +{ + GladeXmlNode *columns_node; + GladeProperty *prop; + GList *l; + + prop = glade_widget_get_property (widget, "columns"); + + columns_node = glade_xml_node_new (context, GLADE_TAG_COLUMNS); + + for (l = g_value_get_boxed (prop->value); l; l = g_list_next (l)) + { + GladeColumnType *data = l->data; + GladeXmlNode *column_node, *comment_node; + + /* Write column names in comments... */ + gchar *comment = g_strdup_printf (" column-name %s ", data->column_name); + comment_node = glade_xml_node_new_comment (context, comment); + glade_xml_node_append_child (columns_node, comment_node); + g_free (comment); + + column_node = glade_xml_node_new (context, GLADE_TAG_COLUMN); + glade_xml_node_append_child (columns_node, column_node); + glade_xml_node_set_property_string (column_node, GLADE_TAG_TYPE, + data->type_name); + } + + if (!glade_xml_node_get_children (columns_node)) + glade_xml_node_delete (columns_node); + else + glade_xml_node_append_child (node, columns_node); } static void -glade_gtk_store_write_data (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) -{ - GladeXmlNode *data_node, *col_node, *row_node; - GList *columns = NULL; - GladeModelData *data; - GNode *data_tree = NULL, *row, *iter; - gint colnum; - - glade_widget_property_get (widget, "data", &data_tree); - glade_widget_property_get (widget, "columns", &columns); - - /* XXX log errors about data not fitting columns here when - * loggin is available - */ - if (!data_tree || !columns) - return; - - data_node = glade_xml_node_new (context, GLADE_TAG_DATA); - - for (row = data_tree->children; row; row = row->next) - { - row_node = glade_xml_node_new (context, GLADE_TAG_ROW); - glade_xml_node_append_child (data_node, row_node); - - for (colnum = 0, iter = row->children; iter; - colnum++, iter = iter->next) - { - gchar *string, *column_number; - - data = iter->data; - - /* Skip non-serializable data */ - if (G_VALUE_TYPE (&data->value) == 0 || - G_VALUE_TYPE (&data->value) == G_TYPE_POINTER) - continue; - - string = glade_utils_string_from_value (&data->value); - - /* XXX Log error: data col j exceeds columns on row i */ - if (!g_list_nth (columns, colnum)) - break; - - column_number = g_strdup_printf ("%d", colnum); - - col_node = glade_xml_node_new (context, GLADE_TAG_COL); - glade_xml_node_append_child (row_node, col_node); - glade_xml_node_set_property_string (col_node, GLADE_TAG_ID, - column_number); - glade_xml_set_content (col_node, string); - - if (data->i18n_translatable) - glade_xml_node_set_property_string (col_node, - GLADE_TAG_TRANSLATABLE, - GLADE_XML_TAG_I18N_TRUE); - if (data->i18n_context) - glade_xml_node_set_property_string (col_node, - GLADE_TAG_CONTEXT, - data->i18n_context); - if (data->i18n_comment) - glade_xml_node_set_property_string (col_node, - GLADE_TAG_COMMENT, - data->i18n_comment); - - - g_free (column_number); - g_free (string); - } - } - - if (!glade_xml_node_get_children (data_node)) - glade_xml_node_delete (data_node); - else - glade_xml_node_append_child (node, data_node); -} - - -void -glade_gtk_store_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) -{ - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and write all the normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); - - glade_gtk_store_write_columns (widget, context, node); - glade_gtk_store_write_data (widget, context, node); +glade_gtk_store_write_data (GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) +{ + GladeXmlNode *data_node, *col_node, *row_node; + GList *columns = NULL; + GladeModelData *data; + GNode *data_tree = NULL, *row, *iter; + gint colnum; + + glade_widget_property_get (widget, "data", &data_tree); + glade_widget_property_get (widget, "columns", &columns); + + /* XXX log errors about data not fitting columns here when + * loggin is available + */ + if (!data_tree || !columns) + return; + + data_node = glade_xml_node_new (context, GLADE_TAG_DATA); + + for (row = data_tree->children; row; row = row->next) + { + row_node = glade_xml_node_new (context, GLADE_TAG_ROW); + glade_xml_node_append_child (data_node, row_node); + + for (colnum = 0, iter = row->children; iter; colnum++, iter = iter->next) + { + gchar *string, *column_number; + + data = iter->data; + + /* Skip non-serializable data */ + if (G_VALUE_TYPE (&data->value) == 0 || + G_VALUE_TYPE (&data->value) == G_TYPE_POINTER) + continue; + + string = glade_utils_string_from_value (&data->value); + + /* XXX Log error: data col j exceeds columns on row i */ + if (!g_list_nth (columns, colnum)) + break; + + column_number = g_strdup_printf ("%d", colnum); + + col_node = glade_xml_node_new (context, GLADE_TAG_COL); + glade_xml_node_append_child (row_node, col_node); + glade_xml_node_set_property_string (col_node, GLADE_TAG_ID, + column_number); + glade_xml_set_content (col_node, string); + + if (data->i18n_translatable) + glade_xml_node_set_property_string (col_node, + GLADE_TAG_TRANSLATABLE, + GLADE_XML_TAG_I18N_TRUE); + if (data->i18n_context) + glade_xml_node_set_property_string (col_node, + GLADE_TAG_CONTEXT, + data->i18n_context); + if (data->i18n_comment) + glade_xml_node_set_property_string (col_node, + GLADE_TAG_COMMENT, + data->i18n_comment); + + + g_free (column_number); + g_free (string); + } + } + + if (!glade_xml_node_get_children (data_node)) + glade_xml_node_delete (data_node); + else + glade_xml_node_append_child (node, data_node); +} + + +void +glade_gtk_store_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, GladeXmlNode * node) +{ + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and write all the normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); + + glade_gtk_store_write_columns (widget, context, node); + glade_gtk_store_write_data (widget, context, node); } static void -glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node) -{ - GladeNameContext *context; - GladeXmlNode *columns_node; - GladeProperty *property; - GladeXmlNode *prop; - GList *types = NULL; - GValue value = {0,}; - gchar column_name[256]; - - column_name[0] = '\0'; - column_name[255] = '\0'; - - if ((columns_node = glade_xml_search_child (node, GLADE_TAG_COLUMNS)) == NULL) - return; - - context = glade_name_context_new (); - - for (prop = glade_xml_node_get_children_with_comments (columns_node); prop; - prop = glade_xml_node_next_with_comments (prop)) - { - GladeColumnType *data; - gchar *type, *comment_str, buffer[256]; - - if (!glade_xml_node_verify_silent (prop, GLADE_TAG_COLUMN) && - !glade_xml_node_is_comment (prop)) continue; - - if (glade_xml_node_is_comment (prop)) - { - comment_str = glade_xml_get_content (prop); - if (sscanf (comment_str, " column-name %s", buffer) == 1) - strncpy (column_name, buffer, 255); - - g_free (comment_str); - continue; - } - - type = glade_xml_get_property_string_required (prop, GLADE_TAG_TYPE, NULL); - - data = glade_column_type_new (type, NULL); - data->type_name = g_strdup (type); - data->column_name = column_name[0] ? g_strdup (column_name) : g_ascii_strdown (type, -1); - - if (glade_name_context_has_name (context, data->column_name)) - { - gchar *name = glade_name_context_new_name (context, data->column_name); - g_free (data->column_name); - data->column_name = name; - } - glade_name_context_add_name (context, data->column_name); - - types = g_list_prepend (types, data); - g_free (type); - - column_name[0] = '\0'; - } - - property = glade_widget_get_property (widget, "columns"); - g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); - g_value_take_boxed (&value, g_list_reverse (types)); - glade_property_set_value (property, &value); - g_value_unset (&value); +glade_gtk_store_read_columns (GladeWidget * widget, GladeXmlNode * node) +{ + GladeNameContext *context; + GladeXmlNode *columns_node; + GladeProperty *property; + GladeXmlNode *prop; + GList *types = NULL; + GValue value = { 0, }; + gchar column_name[256]; + + column_name[0] = '\0'; + column_name[255] = '\0'; + + if ((columns_node = glade_xml_search_child (node, GLADE_TAG_COLUMNS)) == NULL) + return; + + context = glade_name_context_new (); + + for (prop = glade_xml_node_get_children_with_comments (columns_node); prop; + prop = glade_xml_node_next_with_comments (prop)) + { + GladeColumnType *data; + gchar *type, *comment_str, buffer[256]; + + if (!glade_xml_node_verify_silent (prop, GLADE_TAG_COLUMN) && + !glade_xml_node_is_comment (prop)) + continue; + + if (glade_xml_node_is_comment (prop)) + { + comment_str = glade_xml_get_content (prop); + if (sscanf (comment_str, " column-name %s", buffer) == 1) + strncpy (column_name, buffer, 255); + + g_free (comment_str); + continue; + } + + type = + glade_xml_get_property_string_required (prop, GLADE_TAG_TYPE, NULL); + + data = glade_column_type_new (type, NULL); + data->type_name = g_strdup (type); + data->column_name = + column_name[0] ? g_strdup (column_name) : g_ascii_strdown (type, -1); + + if (glade_name_context_has_name (context, data->column_name)) + { + gchar *name = + glade_name_context_new_name (context, data->column_name); + g_free (data->column_name); + data->column_name = name; + } + glade_name_context_add_name (context, data->column_name); + + types = g_list_prepend (types, data); + g_free (type); + + column_name[0] = '\0'; + } + + property = glade_widget_get_property (widget, "columns"); + g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST); + g_value_take_boxed (&value, g_list_reverse (types)); + glade_property_set_value (property, &value); + g_value_unset (&value); } static void -glade_gtk_store_read_data (GladeWidget *widget, GladeXmlNode *node) -{ - GladeXmlNode *data_node, *row_node, *col_node; - GNode *data_tree, *row, *item; - GladeModelData *data; - GValue *value; - GList *column_types = NULL; - GladeColumnType *column_type; - gint colnum; - - if ((data_node = glade_xml_search_child (node, GLADE_TAG_DATA)) == NULL) - return; - - /* XXX FIXME: Warn that columns werent there when parsing */ - if (!glade_widget_property_get (widget, "columns", &column_types) || !column_types) - return; - - /* Create root... */ - data_tree = g_node_new (NULL); - - for (row_node = glade_xml_node_get_children (data_node); row_node; - row_node = glade_xml_node_next (row_node)) - { - gchar *value_str; - - if (!glade_xml_node_verify (row_node, GLADE_TAG_ROW)) - continue; - - row = g_node_new (NULL); - g_node_append (data_tree, row); - - /* XXX FIXME: we are assuming that the columns are listed in order */ - for (colnum = 0, col_node = glade_xml_node_get_children (row_node); col_node; - col_node = glade_xml_node_next (col_node)) - { - gint read_column; - - if (!glade_xml_node_verify (col_node, GLADE_TAG_COL)) - continue; - - read_column = glade_xml_get_property_int (col_node, GLADE_TAG_ID, -1); - if (read_column < 0) - { - g_critical ("Parsed negative column id"); - continue; - } - - /* Catch up for gaps in the list where unserializable types are involved */ - while (colnum < read_column) - { - column_type = g_list_nth_data (column_types, colnum); - - data = glade_model_data_new (G_TYPE_INVALID, column_type->column_name); - - item = g_node_new (data); - g_node_append (row, item); - - colnum++; - } - - if (!(column_type = g_list_nth_data (column_types, colnum))) - /* XXX Log this too... */ - continue; - - /* Ignore unloaded column types for the workspace */ - if (g_type_from_name (column_type->type_name) != G_TYPE_INVALID) - { - /* XXX Do we need object properties to somehow work at load time here ?? - * should we be doing this part in "finished" ? ... todo thinkso... - */ - value_str = glade_xml_get_content (col_node); - value = glade_utils_value_from_string - (g_type_from_name (column_type->type_name), value_str, widget->project, widget); - g_free (value_str); - - data = glade_model_data_new (g_type_from_name (column_type->type_name), - column_type->column_name); - - g_value_copy (value, &data->value); - g_value_unset (value); - g_free (value); - } - else - { - data = glade_model_data_new (G_TYPE_INVALID, column_type->column_name); - } - - data->i18n_translatable = glade_xml_get_property_boolean (col_node, GLADE_TAG_TRANSLATABLE, FALSE); - data->i18n_context = glade_xml_get_property_string (col_node, GLADE_TAG_CONTEXT); - data->i18n_comment = glade_xml_get_property_string (col_node, GLADE_TAG_COMMENT); - - item = g_node_new (data); - g_node_append (row, item); - - /* dont increment colnum on invalid xml tags... */ - colnum++; - } - } - - if (data_tree->children) - glade_widget_property_set (widget, "data", data_tree); - - glade_model_data_tree_free (data_tree); -} - -void -glade_gtk_store_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and read in all the normal properties.. */ - GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); - - glade_gtk_store_read_columns (widget, node); - - if (GTK_IS_LIST_STORE (widget->object)) - glade_gtk_store_read_data (widget, node); +glade_gtk_store_read_data (GladeWidget * widget, GladeXmlNode * node) +{ + GladeXmlNode *data_node, *row_node, *col_node; + GNode *data_tree, *row, *item; + GladeModelData *data; + GValue *value; + GList *column_types = NULL; + GladeColumnType *column_type; + gint colnum; + + if ((data_node = glade_xml_search_child (node, GLADE_TAG_DATA)) == NULL) + return; + + /* XXX FIXME: Warn that columns werent there when parsing */ + if (!glade_widget_property_get (widget, "columns", &column_types) || + !column_types) + return; + + /* Create root... */ + data_tree = g_node_new (NULL); + + for (row_node = glade_xml_node_get_children (data_node); row_node; + row_node = glade_xml_node_next (row_node)) + { + gchar *value_str; + + if (!glade_xml_node_verify (row_node, GLADE_TAG_ROW)) + continue; + + row = g_node_new (NULL); + g_node_append (data_tree, row); + + /* XXX FIXME: we are assuming that the columns are listed in order */ + for (colnum = 0, col_node = glade_xml_node_get_children (row_node); + col_node; col_node = glade_xml_node_next (col_node)) + { + gint read_column; + + if (!glade_xml_node_verify (col_node, GLADE_TAG_COL)) + continue; + + read_column = glade_xml_get_property_int (col_node, GLADE_TAG_ID, -1); + if (read_column < 0) + { + g_critical ("Parsed negative column id"); + continue; + } + + /* Catch up for gaps in the list where unserializable types are involved */ + while (colnum < read_column) + { + column_type = g_list_nth_data (column_types, colnum); + + data = + glade_model_data_new (G_TYPE_INVALID, + column_type->column_name); + + item = g_node_new (data); + g_node_append (row, item); + + colnum++; + } + + if (!(column_type = g_list_nth_data (column_types, colnum))) + /* XXX Log this too... */ + continue; + + /* Ignore unloaded column types for the workspace */ + if (g_type_from_name (column_type->type_name) != G_TYPE_INVALID) + { + /* XXX Do we need object properties to somehow work at load time here ?? + * should we be doing this part in "finished" ? ... todo thinkso... + */ + value_str = glade_xml_get_content (col_node); + value = glade_utils_value_from_string + (g_type_from_name (column_type->type_name), value_str, + widget->project, widget); + g_free (value_str); + + data = + glade_model_data_new (g_type_from_name + (column_type->type_name), + column_type->column_name); + + g_value_copy (value, &data->value); + g_value_unset (value); + g_free (value); + } + else + { + data = + glade_model_data_new (G_TYPE_INVALID, + column_type->column_name); + } + + data->i18n_translatable = + glade_xml_get_property_boolean (col_node, GLADE_TAG_TRANSLATABLE, + FALSE); + data->i18n_context = + glade_xml_get_property_string (col_node, GLADE_TAG_CONTEXT); + data->i18n_comment = + glade_xml_get_property_string (col_node, GLADE_TAG_COMMENT); + + item = g_node_new (data); + g_node_append (row, item); + + /* dont increment colnum on invalid xml tags... */ + colnum++; + } + } + + if (data_tree->children) + glade_widget_property_set (widget, "data", data_tree); + + glade_model_data_tree_free (data_tree); +} + +void +glade_gtk_store_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and read in all the normal properties.. */ + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); + + glade_gtk_store_read_columns (widget, node); + + if (GTK_IS_LIST_STORE (widget->object)) + glade_gtk_store_read_data (widget, node); } /*--------------------------- GtkCellRenderer ---------------------------------*/ -static void glade_gtk_treeview_launch_editor (GObject *treeview); - -void -glade_gtk_cell_renderer_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) -{ - if (strcmp (action_path, "launch_editor") == 0) - { - GladeWidget *w = glade_widget_get_from_gobject (object); - - while ((w = glade_widget_get_parent (w))) - { - if (GTK_IS_TREE_VIEW (w->object)) - { - glade_gtk_treeview_launch_editor (w->object); - break; - } - } - } - else - GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor, - object, - action_path); -} - -void -glade_gtk_cell_renderer_deep_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) -{ - GladePropertyClass *pclass; - GladeProperty *property; - GladeWidget *widget; - GList *l; - - widget = glade_widget_get_from_gobject (object); - - for (l = adaptor->properties; l; l = l->next) - { - pclass = l->data; - - if (strncmp (pclass->id, "use-attr-", strlen ("use-attr-")) == 0) - { - property = glade_widget_get_property (widget, pclass->id); - glade_property_sync (property); - } - } - - g_idle_add ((GSourceFunc)glade_gtk_cell_renderer_sync_attributes, widget->object); +static void glade_gtk_treeview_launch_editor (GObject * treeview); + +void +glade_gtk_cell_renderer_action_activate (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * action_path) +{ + if (strcmp (action_path, "launch_editor") == 0) + { + GladeWidget *w = glade_widget_get_from_gobject (object); + + while ((w = glade_widget_get_parent (w))) + { + if (GTK_IS_TREE_VIEW (w->object)) + { + glade_gtk_treeview_launch_editor (w->object); + break; + } + } + } + else + GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor, + object, action_path); +} + +void +glade_gtk_cell_renderer_deep_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, + GladeCreateReason reason) +{ + GladePropertyClass *pclass; + GladeProperty *property; + GladeWidget *widget; + GList *l; + + widget = glade_widget_get_from_gobject (object); + + for (l = adaptor->properties; l; l = l->next) + { + pclass = l->data; + + if (strncmp (pclass->id, "use-attr-", strlen ("use-attr-")) == 0) + { + property = glade_widget_get_property (widget, pclass->id); + glade_property_sync (property); + } + } + + g_idle_add ((GSourceFunc) glade_gtk_cell_renderer_sync_attributes, + widget->object); } GladeEditorProperty * -glade_gtk_cell_renderer_create_eprop (GladeWidgetAdaptor *adaptor, - GladePropertyClass *klass, - gboolean use_command) +glade_gtk_cell_renderer_create_eprop (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, + gboolean use_command) { - GladeEditorProperty *eprop; + GladeEditorProperty *eprop; - if (strncmp (klass->id, "attr-", strlen ("attr-")) == 0) - eprop = g_object_new (GLADE_TYPE_EPROP_CELL_ATTRIBUTE, - "property-class", klass, - "use-command", use_command, - NULL); - else - eprop = GWA_GET_CLASS - (G_TYPE_OBJECT)->create_eprop (adaptor, - klass, - use_command); - return eprop; + if (strncmp (klass->id, "attr-", strlen ("attr-")) == 0) + eprop = g_object_new (GLADE_TYPE_EPROP_CELL_ATTRIBUTE, + "property-class", klass, + "use-command", use_command, NULL); + else + eprop = GWA_GET_CLASS + (G_TYPE_OBJECT)->create_eprop (adaptor, klass, use_command); + return eprop; } GladeEditable * -glade_gtk_cell_renderer_create_editable (GladeWidgetAdaptor *adaptor, - GladeEditorPageType type) +glade_gtk_cell_renderer_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) { - GladeEditable *editable; + GladeEditable *editable; - /* Get base editable */ - editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type); + /* Get base editable */ + editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type); - if (type == GLADE_PAGE_GENERAL || type == GLADE_PAGE_COMMON) - return (GladeEditable *)glade_cell_renderer_editor_new (adaptor, type, editable); + if (type == GLADE_PAGE_GENERAL || type == GLADE_PAGE_COMMON) + return (GladeEditable *) glade_cell_renderer_editor_new (adaptor, type, + editable); - return editable; + return editable; } static void -glade_gtk_cell_renderer_set_use_attribute (GObject *object, - const gchar *property_name, - const GValue *value) +glade_gtk_cell_renderer_set_use_attribute (GObject * object, + const gchar * property_name, + const GValue * value) { - GladeWidget *widget = glade_widget_get_from_gobject (object); - gchar *attr_prop_name, *prop_msg, *attr_msg; + GladeWidget *widget = glade_widget_get_from_gobject (object); + gchar *attr_prop_name, *prop_msg, *attr_msg; - attr_prop_name = g_strdup_printf ("attr-%s", property_name); + attr_prop_name = g_strdup_printf ("attr-%s", property_name); - prop_msg = g_strdup_printf (_("%s is set to load %s from the model"), - widget->name, property_name); - attr_msg = g_strdup_printf (_("%s is set to manipulate %s directly"), - widget->name, attr_prop_name); + prop_msg = g_strdup_printf (_("%s is set to load %s from the model"), + widget->name, property_name); + attr_msg = g_strdup_printf (_("%s is set to manipulate %s directly"), + widget->name, attr_prop_name); - glade_widget_property_set_sensitive (widget, property_name, FALSE, prop_msg); - glade_widget_property_set_sensitive (widget, attr_prop_name, FALSE, attr_msg); + glade_widget_property_set_sensitive (widget, property_name, FALSE, prop_msg); + glade_widget_property_set_sensitive (widget, attr_prop_name, FALSE, attr_msg); - if (g_value_get_boolean (value)) - glade_widget_property_set_sensitive (widget, attr_prop_name, TRUE, NULL); - else - { - GladeProperty *property = glade_widget_get_property (widget, property_name); + if (g_value_get_boolean (value)) + glade_widget_property_set_sensitive (widget, attr_prop_name, TRUE, NULL); + else + { + GladeProperty *property = + glade_widget_get_property (widget, property_name); - glade_property_set_sensitive (property, TRUE, NULL); - glade_property_sync (property); - } + glade_property_set_sensitive (property, TRUE, NULL); + glade_property_sync (property); + } - g_free (prop_msg); - g_free (attr_msg); - g_free (attr_prop_name); + g_free (prop_msg); + g_free (attr_msg); + g_free (attr_prop_name); } static GladeProperty * -glade_gtk_cell_renderer_attribute_switch (GladeWidget *gwidget, - const gchar *property_name) +glade_gtk_cell_renderer_attribute_switch (GladeWidget * gwidget, + const gchar * property_name) { - GladeProperty *property; - gchar *use_attr_name = g_strdup_printf ("use-attr-%s", property_name); + GladeProperty *property; + gchar *use_attr_name = g_strdup_printf ("use-attr-%s", property_name); - property = glade_widget_get_property (gwidget, use_attr_name); - g_free (use_attr_name); + property = glade_widget_get_property (gwidget, use_attr_name); + g_free (use_attr_name); - return property; + return property; } static gboolean -glade_gtk_cell_renderer_property_enabled (GObject *object, - const gchar *property_name) +glade_gtk_cell_renderer_property_enabled (GObject * object, + const gchar * property_name) { - GladeProperty *property; - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - gboolean use_attr = TRUE; + GladeProperty *property; + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + gboolean use_attr = TRUE; - if ((property = - glade_gtk_cell_renderer_attribute_switch (gwidget, property_name)) != NULL) - glade_property_get (property, &use_attr); + if ((property = + glade_gtk_cell_renderer_attribute_switch (gwidget, + property_name)) != NULL) + glade_property_get (property, &use_attr); - return !use_attr; + return !use_attr; } void -glade_gtk_cell_renderer_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) +glade_gtk_cell_renderer_set_property (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * property_name, + const GValue * value) { - static gint use_attr_len = 0; - static gint attr_len = 0; + static gint use_attr_len = 0; + static gint attr_len = 0; - if (!attr_len) - { - use_attr_len = strlen ("use-attr-"); - attr_len = strlen ("attr-"); - } + if (!attr_len) + { + use_attr_len = strlen ("use-attr-"); + attr_len = strlen ("attr-"); + } - if (strncmp (property_name, "use-attr-", use_attr_len) == 0) - glade_gtk_cell_renderer_set_use_attribute (object, &property_name[use_attr_len], value); - else if (strncmp (property_name, "attr-", attr_len) == 0) - glade_gtk_cell_renderer_sync_attributes (object); - else if (glade_gtk_cell_renderer_property_enabled (object, property_name)) - /* Chain Up */ - GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, - object, - property_name, - value); + if (strncmp (property_name, "use-attr-", use_attr_len) == 0) + glade_gtk_cell_renderer_set_use_attribute (object, + &property_name[use_attr_len], + value); + else if (strncmp (property_name, "attr-", attr_len) == 0) + glade_gtk_cell_renderer_sync_attributes (object); + else if (glade_gtk_cell_renderer_property_enabled (object, property_name)) + /* Chain Up */ + GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, + object, property_name, value); } static void -glade_gtk_cell_renderer_write_properties (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_cell_renderer_write_properties (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeProperty *property, *prop; - gchar *attr_name; - GList *l; - static gint attr_len = 0; + GladeProperty *property, *prop; + gchar *attr_name; + GList *l; + static gint attr_len = 0; - if (!attr_len) - attr_len = strlen ("attr-"); + if (!attr_len) + attr_len = strlen ("attr-"); - for (l = widget->properties; l; l = l->next) - { - property = l->data; + for (l = widget->properties; l; l = l->next) + { + property = l->data; - if (strncmp (property->klass->id, "attr-", attr_len) == 0) - { - gchar *use_attr_str; - gboolean use_attr = FALSE; + if (strncmp (property->klass->id, "attr-", attr_len) == 0) + { + gchar *use_attr_str; + gboolean use_attr = FALSE; - use_attr_str = g_strdup_printf ("use-%s", property->klass->id); - glade_widget_property_get (widget, use_attr_str, &use_attr); + use_attr_str = g_strdup_printf ("use-%s", property->klass->id); + glade_widget_property_get (widget, use_attr_str, &use_attr); - attr_name = &property->klass->id[attr_len]; - prop = glade_widget_get_property (widget, attr_name); + attr_name = &property->klass->id[attr_len]; + prop = glade_widget_get_property (widget, attr_name); - if (!use_attr && prop) - glade_property_write (prop, context, node); + if (!use_attr && prop) + glade_property_write (prop, context, node); - g_free (use_attr_str); - } - } + g_free (use_attr_str); + } + } } void -glade_gtk_cell_renderer_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_cell_renderer_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* Write our normal properties, then chain up to write any other normal properties, - * then attributes - */ - glade_gtk_cell_renderer_write_properties (widget, context, node); + /* Write our normal properties, then chain up to write any other normal properties, + * then attributes + */ + glade_gtk_cell_renderer_write_properties (widget, context, node); - GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); + GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); } static void -glade_gtk_cell_renderer_parse_finished (GladeProject *project, - GladeWidget *widget) -{ - GladeProperty *property; - GList *l; - static gint attr_len = 0, use_attr_len = 0; - - /* Set "use-attr-*" everywhere that the object property is non-default - * - * We do this in the finished handler because some properties may be - * object type properties (which may be anywhere in the glade file). - */ - if (!attr_len) - { - attr_len = strlen ("attr-"); - use_attr_len = strlen ("use-attr-"); - } - - for (l = widget->properties; l; l = l->next) - { - GladeProperty *switch_prop; - property = l->data; - - if (strncmp (property->klass->id, "attr-", attr_len) != 0 && - strncmp (property->klass->id, "use-attr-", use_attr_len) != 0 && - (switch_prop = - glade_gtk_cell_renderer_attribute_switch (widget, property->klass->id)) != NULL) - { - if (glade_property_original_default (property)) - glade_property_set (switch_prop, TRUE); - else - glade_property_set (switch_prop, FALSE); - } - } -} - -void -glade_gtk_cell_renderer_read_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; - - /* First chain up and read in all the properties... */ - GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); - - g_signal_connect (widget->project, "parse-finished", - G_CALLBACK (glade_gtk_cell_renderer_parse_finished), - widget); +glade_gtk_cell_renderer_parse_finished (GladeProject * project, + GladeWidget * widget) +{ + GladeProperty *property; + GList *l; + static gint attr_len = 0, use_attr_len = 0; + + /* Set "use-attr-*" everywhere that the object property is non-default + * + * We do this in the finished handler because some properties may be + * object type properties (which may be anywhere in the glade file). + */ + if (!attr_len) + { + attr_len = strlen ("attr-"); + use_attr_len = strlen ("use-attr-"); + } + + for (l = widget->properties; l; l = l->next) + { + GladeProperty *switch_prop; + property = l->data; + + if (strncmp (property->klass->id, "attr-", attr_len) != 0 && + strncmp (property->klass->id, "use-attr-", use_attr_len) != 0 && + (switch_prop = + glade_gtk_cell_renderer_attribute_switch (widget, + property->klass->id)) != + NULL) + { + if (glade_property_original_default (property)) + glade_property_set (switch_prop, TRUE); + else + glade_property_set (switch_prop, FALSE); + } + } +} + +void +glade_gtk_cell_renderer_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + /* First chain up and read in all the properties... */ + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); + + g_signal_connect (widget->project, "parse-finished", + G_CALLBACK (glade_gtk_cell_renderer_parse_finished), + widget); } /*--------------------------- GtkCellLayout ---------------------------------*/ void -glade_gtk_cell_layout_add_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) +glade_gtk_cell_layout_add_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) { - GladeWidget *gmodel = NULL; - GladeWidget *grenderer = glade_widget_get_from_gobject (child); + GladeWidget *gmodel = NULL; + GladeWidget *grenderer = glade_widget_get_from_gobject (child); - if (GTK_IS_ICON_VIEW (container) && - (gmodel = glade_cell_renderer_get_model (grenderer)) != NULL) - gtk_icon_view_set_model (GTK_ICON_VIEW (container), NULL); + if (GTK_IS_ICON_VIEW (container) && + (gmodel = glade_cell_renderer_get_model (grenderer)) != NULL) + gtk_icon_view_set_model (GTK_ICON_VIEW (container), NULL); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (container), GTK_CELL_RENDERER (child), TRUE); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (container), + GTK_CELL_RENDERER (child), TRUE); - if (gmodel) - gtk_icon_view_set_model (GTK_ICON_VIEW (container), GTK_TREE_MODEL (gmodel->object)); + if (gmodel) + gtk_icon_view_set_model (GTK_ICON_VIEW (container), + GTK_TREE_MODEL (gmodel->object)); - glade_gtk_cell_renderer_sync_attributes (child); + glade_gtk_cell_renderer_sync_attributes (child); } void -glade_gtk_cell_layout_remove_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) +glade_gtk_cell_layout_remove_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) { - GtkCellLayout *layout = GTK_CELL_LAYOUT (container); - GList *l, *children = gtk_cell_layout_get_cells (layout); - - /* Add a reference to every cell except the one we want to remove */ - for (l = children; l; l = g_list_next (l)) - if (l->data != child) - g_object_ref (l->data); - else - l->data = NULL; + GtkCellLayout *layout = GTK_CELL_LAYOUT (container); + GList *l, *children = gtk_cell_layout_get_cells (layout); - /* remove every cell */ - gtk_cell_layout_clear (layout); + /* Add a reference to every cell except the one we want to remove */ + for (l = children; l; l = g_list_next (l)) + if (l->data != child) + g_object_ref (l->data); + else + l->data = NULL; - /* pack others cell renderers */ - for (l = children; l; l = g_list_next (l)) - { - if (l->data == NULL) continue; - - gtk_cell_layout_pack_start (layout, - GTK_CELL_RENDERER (l->data), TRUE); + /* remove every cell */ + gtk_cell_layout_clear (layout); - /* Remove our transient reference */ - g_object_unref (l->data); - } + /* pack others cell renderers */ + for (l = children; l; l = g_list_next (l)) + { + if (l->data == NULL) + continue; - g_list_free (children); + gtk_cell_layout_pack_start (layout, GTK_CELL_RENDERER (l->data), TRUE); + + /* Remove our transient reference */ + g_object_unref (l->data); + } + + g_list_free (children); } GList * -glade_gtk_cell_layout_get_children (GladeWidgetAdaptor *adaptor, - GObject *container) +glade_gtk_cell_layout_get_children (GladeWidgetAdaptor * adaptor, + GObject * container) { - return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (container)); + return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (container)); } void -glade_gtk_cell_layout_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - if (strcmp (property_name, "position") == 0) - { - GList *cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (container)); +glade_gtk_cell_layout_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) +{ + if (strcmp (property_name, "position") == 0) + { + GList *cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (container)); - /* We have to fake it, assume we are loading and always return the last item */ - g_value_set_int (value, g_list_length (cells) - 1); + /* We have to fake it, assume we are loading and always return the last item */ + g_value_set_int (value, g_list_length (cells) - 1); - g_list_free (cells); - } - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_get_property (adaptor, - container, child, - property_name, value); + g_list_free (cells); + } + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_get_property (adaptor, + container, child, + property_name, value); } void -glade_gtk_cell_layout_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) +glade_gtk_cell_layout_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + const GValue * value) { - if (strcmp (property_name, "position") == 0) - { - /* Need verify on position property !!! XXX */ - gtk_cell_layout_reorder (GTK_CELL_LAYOUT (container), GTK_CELL_RENDERER (child), - g_value_get_int (value)); - } - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, child, - property_name, value); + if (strcmp (property_name, "position") == 0) + { + /* Need verify on position property !!! XXX */ + gtk_cell_layout_reorder (GTK_CELL_LAYOUT (container), + GTK_CELL_RENDERER (child), + g_value_get_int (value)); + } + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, child, + property_name, value); } static void -glade_gtk_cell_renderer_read_attributes (GladeWidget *widget, GladeXmlNode *node) -{ - GladeXmlNode *attrs_node; - GladeProperty *attr_prop, *use_attr_prop; - GladeXmlNode *prop; - gchar *name, *column_str, *attr_prop_name, *use_attr_name; - - if ((attrs_node = glade_xml_search_child (node, GLADE_TAG_ATTRIBUTES)) == NULL) - return; - - for (prop = glade_xml_node_get_children (attrs_node); prop; - prop = glade_xml_node_next (prop)) - { - - if (!glade_xml_node_verify_silent (prop, GLADE_TAG_ATTRIBUTE)) continue; - - name = glade_xml_get_property_string_required (prop, GLADE_TAG_NAME, NULL); - column_str = glade_xml_get_content (prop); - attr_prop_name = g_strdup_printf ("attr-%s", name); - use_attr_name = g_strdup_printf ("use-attr-%s", name); - - attr_prop = glade_widget_get_property (widget, attr_prop_name); - use_attr_prop = glade_widget_get_property (widget, use_attr_name); - - if (attr_prop && use_attr_prop) - { - gboolean use_attribute = FALSE; - glade_property_get (use_attr_prop, &use_attribute); - - if (use_attribute) - glade_property_set (attr_prop, g_ascii_strtoll (column_str, NULL, 10)); - } - - g_free (name); - g_free (column_str); - g_free (attr_prop_name); - g_free (use_attr_name); - - } -} - -void -glade_gtk_cell_layout_read_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) -{ - GladeXmlNode *widget_node; - GladeWidget *child_widget; - gchar *internal_name; - - if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD)) - return; - - internal_name = glade_xml_get_property_string (node, GLADE_XML_TAG_INTERNAL_CHILD); - - if ((widget_node = - glade_xml_search_child (node, GLADE_XML_TAG_WIDGET)) != NULL) - { - - if (internal_name) - g_warning ("Cell layout reading internal %s\n", internal_name); - - /* Combo box is a special brand of cell-layout, it can also have the internal entry */ - if ((child_widget = glade_widget_read (widget->project, - widget, widget_node, - internal_name)) != NULL) - { - /* Dont set any packing properties on internal children here, - * its possible but just not relevant for known celllayouts... - * i.e. maybe GtkTreeViewColumn will expose the internal button ? - * but no need for packing properties there either. - */ - if (!internal_name) - { - glade_widget_add_child (widget, child_widget, FALSE); - - glade_gtk_cell_renderer_read_attributes (child_widget, node); - - g_idle_add ((GSourceFunc)glade_gtk_cell_renderer_sync_attributes, - child_widget->object); - } - } - } - g_free (internal_name); +glade_gtk_cell_renderer_read_attributes (GladeWidget * widget, + GladeXmlNode * node) +{ + GladeXmlNode *attrs_node; + GladeProperty *attr_prop, *use_attr_prop; + GladeXmlNode *prop; + gchar *name, *column_str, *attr_prop_name, *use_attr_name; + + if ((attrs_node = + glade_xml_search_child (node, GLADE_TAG_ATTRIBUTES)) == NULL) + return; + + for (prop = glade_xml_node_get_children (attrs_node); prop; + prop = glade_xml_node_next (prop)) + { + + if (!glade_xml_node_verify_silent (prop, GLADE_TAG_ATTRIBUTE)) + continue; + + name = + glade_xml_get_property_string_required (prop, GLADE_TAG_NAME, NULL); + column_str = glade_xml_get_content (prop); + attr_prop_name = g_strdup_printf ("attr-%s", name); + use_attr_name = g_strdup_printf ("use-attr-%s", name); + + attr_prop = glade_widget_get_property (widget, attr_prop_name); + use_attr_prop = glade_widget_get_property (widget, use_attr_name); + + if (attr_prop && use_attr_prop) + { + gboolean use_attribute = FALSE; + glade_property_get (use_attr_prop, &use_attribute); + + if (use_attribute) + glade_property_set (attr_prop, + g_ascii_strtoll (column_str, NULL, 10)); + } + + g_free (name); + g_free (column_str); + g_free (attr_prop_name); + g_free (use_attr_name); + + } } -static void -glade_gtk_cell_renderer_write_attributes (GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +void +glade_gtk_cell_layout_read_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - GladeProperty *property; - GladeXmlNode *attrs_node; - gchar *attr_name; - GList *l; - static gint attr_len = 0; + GladeXmlNode *widget_node; + GladeWidget *child_widget; + gchar *internal_name; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD)) + return; + + internal_name = + glade_xml_get_property_string (node, GLADE_XML_TAG_INTERNAL_CHILD); - if (!attr_len) - attr_len = strlen ("attr-"); + if ((widget_node = + glade_xml_search_child (node, GLADE_XML_TAG_WIDGET)) != NULL) + { - attrs_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTES); + if (internal_name) + g_warning ("Cell layout reading internal %s\n", internal_name); - for (l = widget->properties; l; l = l->next) - { - property = l->data; + /* Combo box is a special brand of cell-layout, it can also have the internal entry */ + if ((child_widget = glade_widget_read (widget->project, + widget, widget_node, + internal_name)) != NULL) + { + /* Dont set any packing properties on internal children here, + * its possible but just not relevant for known celllayouts... + * i.e. maybe GtkTreeViewColumn will expose the internal button ? + * but no need for packing properties there either. + */ + if (!internal_name) + { + glade_widget_add_child (widget, child_widget, FALSE); - if (strncmp (property->klass->id, "attr-", attr_len) == 0) - { - GladeXmlNode *attr_node; - gchar *column_str, *use_attr_str; - gboolean use_attr = FALSE; + glade_gtk_cell_renderer_read_attributes (child_widget, node); - use_attr_str = g_strdup_printf ("use-%s", property->klass->id); - glade_widget_property_get (widget, use_attr_str, &use_attr); + g_idle_add ((GSourceFunc) glade_gtk_cell_renderer_sync_attributes, + child_widget->object); + } + } + } + g_free (internal_name); +} - if (use_attr && g_value_get_int (property->value) >= 0) - { - column_str = g_strdup_printf ("%d", g_value_get_int (property->value)); - attr_name = &property->klass->id[attr_len]; - - attr_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTE); - glade_xml_node_append_child (attrs_node, attr_node); - glade_xml_node_set_property_string (attr_node, GLADE_TAG_NAME, - attr_name); - glade_xml_set_content (attr_node, column_str); - g_free (column_str); - } - g_free (use_attr_str); - } - } +static void +glade_gtk_cell_renderer_write_attributes (GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) +{ + GladeProperty *property; + GladeXmlNode *attrs_node; + gchar *attr_name; + GList *l; + static gint attr_len = 0; + + if (!attr_len) + attr_len = strlen ("attr-"); + + attrs_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTES); + + for (l = widget->properties; l; l = l->next) + { + property = l->data; + + if (strncmp (property->klass->id, "attr-", attr_len) == 0) + { + GladeXmlNode *attr_node; + gchar *column_str, *use_attr_str; + gboolean use_attr = FALSE; + + use_attr_str = g_strdup_printf ("use-%s", property->klass->id); + glade_widget_property_get (widget, use_attr_str, &use_attr); + + if (use_attr && g_value_get_int (property->value) >= 0) + { + column_str = + g_strdup_printf ("%d", g_value_get_int (property->value)); + attr_name = &property->klass->id[attr_len]; + + attr_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTE); + glade_xml_node_append_child (attrs_node, attr_node); + glade_xml_node_set_property_string (attr_node, GLADE_TAG_NAME, + attr_name); + glade_xml_set_content (attr_node, column_str); + g_free (column_str); + } + g_free (use_attr_str); + } + } - if (!glade_xml_node_get_children (attrs_node)) - glade_xml_node_delete (attrs_node); - else - glade_xml_node_append_child (node, attrs_node); + if (!glade_xml_node_get_children (attrs_node)) + glade_xml_node_delete (attrs_node); + else + glade_xml_node_append_child (node, attrs_node); } void -glade_gtk_cell_layout_write_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_cell_layout_write_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *child_node; + GladeXmlNode *child_node; - child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD); - glade_xml_node_append_child (node, child_node); + child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD); + glade_xml_node_append_child (node, child_node); - /* ComboBox can have an internal entry */ - if (widget->internal) - glade_xml_node_set_property_string (child_node, - GLADE_XML_TAG_INTERNAL_CHILD, - widget->internal); + /* ComboBox can have an internal entry */ + if (widget->internal) + glade_xml_node_set_property_string (child_node, + GLADE_XML_TAG_INTERNAL_CHILD, + widget->internal); - /* Write out the widget */ - glade_widget_write (widget, context, child_node); + /* Write out the widget */ + glade_widget_write (widget, context, child_node); - glade_gtk_cell_renderer_write_attributes (widget, context, child_node); + glade_gtk_cell_renderer_write_attributes (widget, context, child_node); } static gchar * -glade_gtk_cell_layout_get_display_name (GladeBaseEditor *editor, - GladeWidget *gchild, - gpointer user_data) +glade_gtk_cell_layout_get_display_name (GladeBaseEditor * editor, + GladeWidget * gchild, + gpointer user_data) { - GObject *child = glade_widget_get_object (gchild); - gchar *name; - - if (GTK_IS_TREE_VIEW_COLUMN (child)) - glade_widget_property_get (gchild, "title", &name); - else - name = gchild->name; - - return g_strdup (name); + GObject *child = glade_widget_get_object (gchild); + gchar *name; + + if (GTK_IS_TREE_VIEW_COLUMN (child)) + glade_widget_property_get (gchild, "title", &name); + else + name = gchild->name; + + return g_strdup (name); } static void -glade_gtk_cell_layout_child_selected (GladeBaseEditor *editor, - GladeWidget *gchild, - gpointer data) -{ - GObject *child = glade_widget_get_object (gchild); - - glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ? - _("Tree View Column") : _("Cell Renderer")); - - glade_base_editor_add_default_properties (editor, gchild); - - glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ? - _("Properties") : _("Properties and Attributes")); - glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL); - - if (GTK_IS_CELL_RENDERER (child)) - { - glade_base_editor_add_label (editor, _("Common Properties and Attributes")); - glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_COMMON); - } +glade_gtk_cell_layout_child_selected (GladeBaseEditor * editor, + GladeWidget * gchild, gpointer data) +{ + GObject *child = glade_widget_get_object (gchild); + + glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ? + _("Tree View Column") : _("Cell Renderer")); + + glade_base_editor_add_default_properties (editor, gchild); + + glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ? + _("Properties") : + _("Properties and Attributes")); + glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL); + + if (GTK_IS_CELL_RENDERER (child)) + { + glade_base_editor_add_label (editor, + _("Common Properties and Attributes")); + glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_COMMON); + } } static gboolean -glade_gtk_cell_layout_move_child (GladeBaseEditor *editor, - GladeWidget *gparent, - GladeWidget *gchild, - gpointer data) -{ - GObject *parent = glade_widget_get_object (gparent); - GObject *child = glade_widget_get_object (gchild); - GList list = { 0, }; - - if (GTK_IS_TREE_VIEW (parent) && !GTK_IS_TREE_VIEW_COLUMN (child)) - return FALSE; - if (GTK_IS_CELL_LAYOUT (parent) && !GTK_IS_CELL_RENDERER (child)) - return FALSE; - if (GTK_IS_CELL_RENDERER (parent)) - return FALSE; - - if (gparent != glade_widget_get_parent (gchild)) - { - list.data = gchild; - glade_command_dnd (&list, gparent, NULL); - } - - return TRUE; +glade_gtk_cell_layout_move_child (GladeBaseEditor * editor, + GladeWidget * gparent, + GladeWidget * gchild, gpointer data) +{ + GObject *parent = glade_widget_get_object (gparent); + GObject *child = glade_widget_get_object (gchild); + GList list = { 0, }; + + if (GTK_IS_TREE_VIEW (parent) && !GTK_IS_TREE_VIEW_COLUMN (child)) + return FALSE; + if (GTK_IS_CELL_LAYOUT (parent) && !GTK_IS_CELL_RENDERER (child)) + return FALSE; + if (GTK_IS_CELL_RENDERER (parent)) + return FALSE; + + if (gparent != glade_widget_get_parent (gchild)) + { + list.data = gchild; + glade_command_dnd (&list, gparent, NULL); + } + + return TRUE; } static void -glade_gtk_cell_layout_launch_editor (GObject *layout) -{ - GladeWidget *widget = glade_widget_get_from_gobject (layout); - GladeBaseEditor *editor; - GladeEditable *layout_editor; - GtkWidget *window; - - layout_editor = glade_widget_adaptor_create_editable (widget->adaptor, GLADE_PAGE_GENERAL); - layout_editor = (GladeEditable *)glade_tree_view_editor_new (widget->adaptor, layout_editor); - - /* Editor */ - editor = glade_base_editor_new (layout, layout_editor, - _("Text"), GTK_TYPE_CELL_RENDERER_TEXT, - _("Accelerator"), GTK_TYPE_CELL_RENDERER_ACCEL, - _("Combo"), GTK_TYPE_CELL_RENDERER_COMBO, - _("Spin"), GTK_TYPE_CELL_RENDERER_SPIN, - _("Pixbuf"), GTK_TYPE_CELL_RENDERER_PIXBUF, - _("Progress"), GTK_TYPE_CELL_RENDERER_PROGRESS, - _("Toggle"), GTK_TYPE_CELL_RENDERER_TOGGLE, - _("Spinner"), GTK_TYPE_CELL_RENDERER_SPINNER, - NULL); - - g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_cell_layout_get_display_name), NULL); - g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_cell_layout_child_selected), NULL); - g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_cell_layout_move_child), NULL); - - gtk_widget_show (GTK_WIDGET (editor)); - - window = glade_base_editor_pack_new_window (editor, - GTK_IS_ICON_VIEW (layout) ? - _("Icon View Editor") : _("Combo Editor"), - NULL); - gtk_widget_show (window); +glade_gtk_cell_layout_launch_editor (GObject * layout) +{ + GladeWidget *widget = glade_widget_get_from_gobject (layout); + GladeBaseEditor *editor; + GladeEditable *layout_editor; + GtkWidget *window; + + layout_editor = + glade_widget_adaptor_create_editable (widget->adaptor, + GLADE_PAGE_GENERAL); + layout_editor = + (GladeEditable *) glade_tree_view_editor_new (widget->adaptor, + layout_editor); + + /* Editor */ + editor = glade_base_editor_new (layout, layout_editor, + _("Text"), GTK_TYPE_CELL_RENDERER_TEXT, + _("Accelerator"), + GTK_TYPE_CELL_RENDERER_ACCEL, _("Combo"), + GTK_TYPE_CELL_RENDERER_COMBO, _("Spin"), + GTK_TYPE_CELL_RENDERER_SPIN, _("Pixbuf"), + GTK_TYPE_CELL_RENDERER_PIXBUF, _("Progress"), + GTK_TYPE_CELL_RENDERER_PROGRESS, _("Toggle"), + GTK_TYPE_CELL_RENDERER_TOGGLE, _("Spinner"), + GTK_TYPE_CELL_RENDERER_SPINNER, NULL); + + g_signal_connect (editor, "get-display-name", + G_CALLBACK (glade_gtk_cell_layout_get_display_name), NULL); + g_signal_connect (editor, "child-selected", + G_CALLBACK (glade_gtk_cell_layout_child_selected), NULL); + g_signal_connect (editor, "move-child", + G_CALLBACK (glade_gtk_cell_layout_move_child), NULL); + + gtk_widget_show (GTK_WIDGET (editor)); + + window = glade_base_editor_pack_new_window (editor, + GTK_IS_ICON_VIEW (layout) ? + _("Icon View Editor") : + _("Combo Editor"), NULL); + gtk_widget_show (window); } static void -glade_gtk_cell_layout_launch_editor_action (GObject *object) +glade_gtk_cell_layout_launch_editor_action (GObject * object) { - GladeWidget *w = glade_widget_get_from_gobject (object); - - do - { - if (GTK_IS_TREE_VIEW (w->object)) - { - glade_gtk_treeview_launch_editor (w->object); - break; - } - else if (GTK_IS_ICON_VIEW (w->object)) - { - glade_gtk_cell_layout_launch_editor (w->object); - break; - } - else if (GTK_IS_COMBO_BOX (w->object)) - { - glade_gtk_cell_layout_launch_editor (w->object); - break; - } + GladeWidget *w = glade_widget_get_from_gobject (object); - } while ((w = glade_widget_get_parent (w))); + do + { + if (GTK_IS_TREE_VIEW (w->object)) + { + glade_gtk_treeview_launch_editor (w->object); + break; + } + else if (GTK_IS_ICON_VIEW (w->object)) + { + glade_gtk_cell_layout_launch_editor (w->object); + break; + } + else if (GTK_IS_COMBO_BOX (w->object)) + { + glade_gtk_cell_layout_launch_editor (w->object); + break; + } + + } + while ((w = glade_widget_get_parent (w))); } void -glade_gtk_cell_layout_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) +glade_gtk_cell_layout_action_activate (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * action_path) { - if (strcmp (action_path, "launch_editor") == 0) - glade_gtk_cell_layout_launch_editor_action (object); - else - GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor, - object, - action_path); + if (strcmp (action_path, "launch_editor") == 0) + glade_gtk_cell_layout_launch_editor_action (object); + else + GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor, + object, action_path); } void -glade_gtk_cell_layout_action_activate_as_widget (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) +glade_gtk_cell_layout_action_activate_as_widget (GladeWidgetAdaptor * adaptor, + GObject * object, + const gchar * action_path) { - if (strcmp (action_path, "launch_editor") == 0) - glade_gtk_cell_layout_launch_editor_action (object); - else - GWA_GET_CLASS (GTK_TYPE_WIDGET)->action_activate (adaptor, - object, - action_path); + if (strcmp (action_path, "launch_editor") == 0) + glade_gtk_cell_layout_launch_editor_action (object); + else + GWA_GET_CLASS (GTK_TYPE_WIDGET)->action_activate (adaptor, + object, action_path); } /*--------------------------- GtkTreeView ---------------------------------*/ static void -glade_gtk_treeview_launch_editor (GObject *treeview) +glade_gtk_treeview_launch_editor (GObject * treeview) { - GladeWidget *widget = glade_widget_get_from_gobject (treeview); - GladeBaseEditor *editor; - GladeEditable *treeview_editor; - GtkWidget *window; + GladeWidget *widget = glade_widget_get_from_gobject (treeview); + GladeBaseEditor *editor; + GladeEditable *treeview_editor; + GtkWidget *window; + + treeview_editor = + glade_widget_adaptor_create_editable (widget->adaptor, + GLADE_PAGE_GENERAL); + treeview_editor = + (GladeEditable *) glade_tree_view_editor_new (widget->adaptor, + treeview_editor); - treeview_editor = glade_widget_adaptor_create_editable (widget->adaptor, GLADE_PAGE_GENERAL); - treeview_editor = (GladeEditable *)glade_tree_view_editor_new (widget->adaptor, treeview_editor); + /* Editor */ + editor = glade_base_editor_new (treeview, treeview_editor, + _("Column"), GTK_TYPE_TREE_VIEW_COLUMN, NULL); - /* Editor */ - editor = glade_base_editor_new (treeview, treeview_editor, - _("Column"), GTK_TYPE_TREE_VIEW_COLUMN, - NULL); + glade_base_editor_append_types (editor, GTK_TYPE_TREE_VIEW_COLUMN, + _("Text"), GTK_TYPE_CELL_RENDERER_TEXT, + _("Accelerator"), + GTK_TYPE_CELL_RENDERER_ACCEL, _("Combo"), + GTK_TYPE_CELL_RENDERER_COMBO, _("Spin"), + GTK_TYPE_CELL_RENDERER_SPIN, _("Pixbuf"), + GTK_TYPE_CELL_RENDERER_PIXBUF, _("Progress"), + GTK_TYPE_CELL_RENDERER_PROGRESS, _("Toggle"), + GTK_TYPE_CELL_RENDERER_TOGGLE, _("Spinner"), + GTK_TYPE_CELL_RENDERER_SPINNER, NULL); - glade_base_editor_append_types (editor, GTK_TYPE_TREE_VIEW_COLUMN, - _("Text"), GTK_TYPE_CELL_RENDERER_TEXT, - _("Accelerator"), GTK_TYPE_CELL_RENDERER_ACCEL, - _("Combo"), GTK_TYPE_CELL_RENDERER_COMBO, - _("Spin"), GTK_TYPE_CELL_RENDERER_SPIN, - _("Pixbuf"), GTK_TYPE_CELL_RENDERER_PIXBUF, - _("Progress"), GTK_TYPE_CELL_RENDERER_PROGRESS, - _("Toggle"), GTK_TYPE_CELL_RENDERER_TOGGLE, - _("Spinner"), GTK_TYPE_CELL_RENDERER_SPINNER, - NULL); + g_signal_connect (editor, "get-display-name", + G_CALLBACK (glade_gtk_cell_layout_get_display_name), NULL); + g_signal_connect (editor, "child-selected", + G_CALLBACK (glade_gtk_cell_layout_child_selected), NULL); + g_signal_connect (editor, "move-child", + G_CALLBACK (glade_gtk_cell_layout_move_child), NULL); - g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_cell_layout_get_display_name), NULL); - g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_cell_layout_child_selected), NULL); - g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_cell_layout_move_child), NULL); + gtk_widget_show (GTK_WIDGET (editor)); - gtk_widget_show (GTK_WIDGET (editor)); - - window = glade_base_editor_pack_new_window (editor, _("Tree View Editor"), NULL); - gtk_widget_show (window); + window = + glade_base_editor_pack_new_window (editor, _("Tree View Editor"), NULL); + gtk_widget_show (window); } void -glade_gtk_treeview_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) +glade_gtk_treeview_action_activate (GladeWidgetAdaptor * adaptor, + GObject * object, const gchar * action_path) { - if (strcmp (action_path, "launch_editor") == 0) - { - glade_gtk_treeview_launch_editor (object); - } - else - GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, - object, - action_path); + if (strcmp (action_path, "launch_editor") == 0) + { + glade_gtk_treeview_launch_editor (object); + } + else + GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, + object, action_path); } static gint -glade_gtk_treeview_get_column_index (GtkTreeView *view, - GtkTreeViewColumn *column) -{ - GtkTreeViewColumn *iter; - gint i; - - for (i = 0; (iter = gtk_tree_view_get_column (view, i)) != NULL; i++) - if (iter == column) - return i; - - return -1; -} - -void -glade_gtk_treeview_get_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - if (strcmp (property_name, "position") == 0) - g_value_set_int (value, - glade_gtk_treeview_get_column_index (GTK_TREE_VIEW (container), - GTK_TREE_VIEW_COLUMN (child))); - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_get_property (adaptor, - container, child, - property_name, value); -} - -void -glade_gtk_treeview_set_child_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) -{ - if (strcmp (property_name, "position") == 0) - { - - gtk_tree_view_remove_column (GTK_TREE_VIEW (container), - GTK_TREE_VIEW_COLUMN (child)); - gtk_tree_view_insert_column (GTK_TREE_VIEW (container), - GTK_TREE_VIEW_COLUMN (child), - g_value_get_int (value)); - } - else - /* Chain Up */ - GWA_GET_CLASS - (GTK_TYPE_CONTAINER)->child_set_property (adaptor, - container, child, - property_name, value); +glade_gtk_treeview_get_column_index (GtkTreeView * view, + GtkTreeViewColumn * column) +{ + GtkTreeViewColumn *iter; + gint i; + + for (i = 0; (iter = gtk_tree_view_get_column (view, i)) != NULL; i++) + if (iter == column) + return i; + + return -1; +} + +void +glade_gtk_treeview_get_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + GValue * value) +{ + if (strcmp (property_name, "position") == 0) + g_value_set_int (value, + glade_gtk_treeview_get_column_index (GTK_TREE_VIEW + (container), + GTK_TREE_VIEW_COLUMN + (child))); + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_get_property (adaptor, + container, child, + property_name, value); +} + +void +glade_gtk_treeview_set_child_property (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * child, + const gchar * property_name, + const GValue * value) +{ + if (strcmp (property_name, "position") == 0) + { + + gtk_tree_view_remove_column (GTK_TREE_VIEW (container), + GTK_TREE_VIEW_COLUMN (child)); + gtk_tree_view_insert_column (GTK_TREE_VIEW (container), + GTK_TREE_VIEW_COLUMN (child), + g_value_get_int (value)); + } + else + /* Chain Up */ + GWA_GET_CLASS + (GTK_TYPE_CONTAINER)->child_set_property (adaptor, + container, child, + property_name, value); } GList * -glade_gtk_treeview_get_children (GladeWidgetAdaptor *adaptor, - GtkTreeView *view) +glade_gtk_treeview_get_children (GladeWidgetAdaptor * adaptor, + GtkTreeView * view) { - return gtk_tree_view_get_columns (view); + return gtk_tree_view_get_columns (view); } /* XXX FIXME: We should hide the actual "fixed-height-mode" setting from @@ -10751,246 +10785,239 @@ glade_gtk_treeview_get_children (GladeWidgetAdaptor *adaptor, _("Columns must have a fixed size inside a treeview with fixed height mode set") void -glade_gtk_treeview_add_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) +glade_gtk_treeview_add_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) { - GtkTreeView *view = GTK_TREE_VIEW (container); - GtkTreeViewColumn *column; - GladeWidget *gcolumn; + GtkTreeView *view = GTK_TREE_VIEW (container); + GtkTreeViewColumn *column; + GladeWidget *gcolumn; - if (!GTK_IS_TREE_VIEW_COLUMN (child)) - return; + if (!GTK_IS_TREE_VIEW_COLUMN (child)) + return; - if (gtk_tree_view_get_fixed_height_mode (view)) - { - gcolumn = glade_widget_get_from_gobject (child); - glade_widget_property_set (gcolumn, "sizing", GTK_TREE_VIEW_COLUMN_FIXED); - glade_widget_property_set_sensitive (gcolumn, "sizing", FALSE, - INSENSITIVE_COLUMN_SIZING_MSG); - } + if (gtk_tree_view_get_fixed_height_mode (view)) + { + gcolumn = glade_widget_get_from_gobject (child); + glade_widget_property_set (gcolumn, "sizing", GTK_TREE_VIEW_COLUMN_FIXED); + glade_widget_property_set_sensitive (gcolumn, "sizing", FALSE, + INSENSITIVE_COLUMN_SIZING_MSG); + } - column = GTK_TREE_VIEW_COLUMN (child); - gtk_tree_view_append_column (view, column); + column = GTK_TREE_VIEW_COLUMN (child); + gtk_tree_view_append_column (view, column); - glade_gtk_cell_layout_sync_attributes (G_OBJECT (column)); + glade_gtk_cell_layout_sync_attributes (G_OBJECT (column)); } void -glade_gtk_treeview_remove_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) +glade_gtk_treeview_remove_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) { - GtkTreeView *view = GTK_TREE_VIEW (container); - GtkTreeViewColumn *column; + GtkTreeView *view = GTK_TREE_VIEW (container); + GtkTreeViewColumn *column; - if (!GTK_IS_TREE_VIEW_COLUMN (child)) - return; + if (!GTK_IS_TREE_VIEW_COLUMN (child)) + return; - column = GTK_TREE_VIEW_COLUMN (child); - gtk_tree_view_remove_column (view, column); + column = GTK_TREE_VIEW_COLUMN (child); + gtk_tree_view_remove_column (view, column); } void -glade_gtk_treeview_replace_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *current, - GObject *new_column) +glade_gtk_treeview_replace_child (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * current, GObject * new_column) { - GtkTreeView *view = GTK_TREE_VIEW (container); - GList *columns; - GtkTreeViewColumn *column; - GladeWidget *gcolumn; - gint index; + GtkTreeView *view = GTK_TREE_VIEW (container); + GList *columns; + GtkTreeViewColumn *column; + GladeWidget *gcolumn; + gint index; - if (!GTK_IS_TREE_VIEW_COLUMN (current)) - return; + if (!GTK_IS_TREE_VIEW_COLUMN (current)) + return; - column = GTK_TREE_VIEW_COLUMN (current); + column = GTK_TREE_VIEW_COLUMN (current); - columns = gtk_tree_view_get_columns (view); - index = g_list_index (columns, column); - g_list_free (columns); + columns = gtk_tree_view_get_columns (view); + index = g_list_index (columns, column); + g_list_free (columns); - gtk_tree_view_remove_column (view, column); - column = GTK_TREE_VIEW_COLUMN (new_column); + gtk_tree_view_remove_column (view, column); + column = GTK_TREE_VIEW_COLUMN (new_column); - gtk_tree_view_insert_column (view, column, index); + gtk_tree_view_insert_column (view, column, index); - if (gtk_tree_view_get_fixed_height_mode (view)) - { - gcolumn = glade_widget_get_from_gobject (column); - glade_widget_property_set (gcolumn, "sizing", GTK_TREE_VIEW_COLUMN_FIXED); - glade_widget_property_set_sensitive (gcolumn, "sizing", FALSE, - INSENSITIVE_COLUMN_SIZING_MSG); - } + if (gtk_tree_view_get_fixed_height_mode (view)) + { + gcolumn = glade_widget_get_from_gobject (column); + glade_widget_property_set (gcolumn, "sizing", GTK_TREE_VIEW_COLUMN_FIXED); + glade_widget_property_set_sensitive (gcolumn, "sizing", FALSE, + INSENSITIVE_COLUMN_SIZING_MSG); + } - glade_gtk_cell_layout_sync_attributes (G_OBJECT (column)); + glade_gtk_cell_layout_sync_attributes (G_OBJECT (column)); } gboolean -glade_gtk_treeview_depends (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeWidget *another) +glade_gtk_treeview_depends (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeWidget * another) { - if (GTK_IS_TREE_MODEL (another->object)) - return TRUE; + if (GTK_IS_TREE_MODEL (another->object)) + return TRUE; - return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->depends (adaptor, widget, another); + return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->depends (adaptor, widget, another); } /*--------------------------- GtkAdjustment ---------------------------------*/ void -glade_gtk_adjustment_write_widget (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_adjustment_write_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeProperty *prop; + GladeProperty *prop; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) - return; + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; - /* Ensure proper order of adjustment properties by writing them here. */ - prop = glade_widget_get_property (widget, "lower"); - glade_property_write (prop, context, node); + /* Ensure proper order of adjustment properties by writing them here. */ + prop = glade_widget_get_property (widget, "lower"); + glade_property_write (prop, context, node); - prop = glade_widget_get_property (widget, "upper"); - glade_property_write (prop, context, node); + prop = glade_widget_get_property (widget, "upper"); + glade_property_write (prop, context, node); - prop = glade_widget_get_property (widget, "value"); - glade_property_write (prop, context, node); + prop = glade_widget_get_property (widget, "value"); + glade_property_write (prop, context, node); - GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); + GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); } /*--------------------------- GtkAction ---------------------------------*/ void -glade_gtk_action_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) +glade_gtk_action_post_create (GladeWidgetAdaptor * adaptor, + GObject * object, GladeCreateReason reason) { - GladeWidget *gwidget = glade_widget_get_from_gobject (object); + GladeWidget *gwidget = glade_widget_get_from_gobject (object); - if (reason == GLADE_CREATE_REBUILD) - return; + if (reason == GLADE_CREATE_REBUILD) + return; - if (!gtk_action_get_name (GTK_ACTION (object))) - glade_widget_property_set (gwidget, "name", "untitled"); + if (!gtk_action_get_name (GTK_ACTION (object))) + glade_widget_property_set (gwidget, "name", "untitled"); } /*--------------------------- GtkActionGroup ---------------------------------*/ void -glade_gtk_action_group_add_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) +glade_gtk_action_group_add_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) { - if (GTK_IS_ACTION (child)) - { - /* Dont really add/remove actions (because name conflicts inside groups) - */ - GladeWidget *ggroup = glade_widget_get_from_gobject (container); - GladeWidget *gaction = glade_widget_get_from_gobject (child); - GList *actions = g_object_get_data (G_OBJECT (ggroup), "glade-actions"); + if (GTK_IS_ACTION (child)) + { + /* Dont really add/remove actions (because name conflicts inside groups) + */ + GladeWidget *ggroup = glade_widget_get_from_gobject (container); + GladeWidget *gaction = glade_widget_get_from_gobject (child); + GList *actions = g_object_get_data (G_OBJECT (ggroup), "glade-actions"); - actions = g_list_copy (actions); - actions = g_list_prepend (actions, child); + actions = g_list_copy (actions); + actions = g_list_prepend (actions, child); - g_object_set_data_full (G_OBJECT (ggroup), "glade-actions", actions, - (GDestroyNotify)g_list_free); + g_object_set_data_full (G_OBJECT (ggroup), "glade-actions", actions, + (GDestroyNotify) g_list_free); - glade_widget_property_set_sensitive (gaction, "accelerator", TRUE, NULL); - } + glade_widget_property_set_sensitive (gaction, "accelerator", TRUE, NULL); + } } void -glade_gtk_action_group_remove_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) +glade_gtk_action_group_remove_child (GladeWidgetAdaptor * adaptor, + GObject * container, GObject * child) { - if (GTK_IS_ACTION (child)) - { - /* Dont really add/remove actions (because name conflicts inside groups) - */ - const gchar *insensitive_msg = _("The accelerator can only be set when inside an Action Group."); - GladeWidget *ggroup = glade_widget_get_from_gobject (container); - GladeWidget *gaction = glade_widget_get_from_gobject (child); - GList *actions = g_object_get_data (G_OBJECT (ggroup), "glade-actions"); + if (GTK_IS_ACTION (child)) + { + /* Dont really add/remove actions (because name conflicts inside groups) + */ + const gchar *insensitive_msg = + _("The accelerator can only be set when inside an Action Group."); + GladeWidget *ggroup = glade_widget_get_from_gobject (container); + GladeWidget *gaction = glade_widget_get_from_gobject (child); + GList *actions = g_object_get_data (G_OBJECT (ggroup), "glade-actions"); - actions = g_list_copy (actions); - actions = g_list_remove (actions, child); + actions = g_list_copy (actions); + actions = g_list_remove (actions, child); - g_object_set_data_full (G_OBJECT (ggroup), "glade-actions", actions, - (GDestroyNotify)g_list_free); + g_object_set_data_full (G_OBJECT (ggroup), "glade-actions", actions, + (GDestroyNotify) g_list_free); - glade_widget_property_set_sensitive (gaction, "accelerator", FALSE, insensitive_msg); - } + glade_widget_property_set_sensitive (gaction, "accelerator", FALSE, + insensitive_msg); + } } void -glade_gtk_action_group_replace_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *current, - GObject *new_action) +glade_gtk_action_group_replace_child (GladeWidgetAdaptor * adaptor, + GObject * container, + GObject * current, GObject * new_action) { - glade_gtk_action_group_remove_child (adaptor, container, current); - glade_gtk_action_group_add_child (adaptor, container, new_action); + glade_gtk_action_group_remove_child (adaptor, container, current); + glade_gtk_action_group_add_child (adaptor, container, new_action); } GList * -glade_gtk_action_group_get_children (GladeWidgetAdaptor *adaptor, - GObject *container) +glade_gtk_action_group_get_children (GladeWidgetAdaptor * adaptor, + GObject * container) { - GladeWidget *ggroup = glade_widget_get_from_gobject (container); - GList *actions = g_object_get_data (G_OBJECT (ggroup), "glade-actions"); + GladeWidget *ggroup = glade_widget_get_from_gobject (container); + GList *actions = g_object_get_data (G_OBJECT (ggroup), "glade-actions"); - return g_list_copy (actions); + return g_list_copy (actions); } void -glade_gtk_action_group_read_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlNode *node) +glade_gtk_action_group_read_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) { - GladeXmlNode *widget_node; - GladeWidget *child_widget; + GladeXmlNode *widget_node; + GladeWidget *child_widget; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD)) + return; - if (!glade_xml_node_verify (node, GLADE_XML_TAG_CHILD)) - return; - - if ((widget_node = - glade_xml_search_child (node, GLADE_XML_TAG_WIDGET)) != NULL) - { - if ((child_widget = glade_widget_read (widget->project, - widget, widget_node, - NULL)) != NULL) - { - glade_widget_add_child (widget, child_widget, FALSE); + if ((widget_node = + glade_xml_search_child (node, GLADE_XML_TAG_WIDGET)) != NULL) + { + if ((child_widget = glade_widget_read (widget->project, + widget, widget_node, + NULL)) != NULL) + { + glade_widget_add_child (widget, child_widget, FALSE); - /* Read in accelerator */ - glade_gtk_read_accels (child_widget, node, FALSE); - } - } + /* Read in accelerator */ + glade_gtk_read_accels (child_widget, node, FALSE); + } + } } void -glade_gtk_action_group_write_child (GladeWidgetAdaptor *adaptor, - GladeWidget *widget, - GladeXmlContext *context, - GladeXmlNode *node) +glade_gtk_action_group_write_child (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, + GladeXmlContext * context, + GladeXmlNode * node) { - GladeXmlNode *child_node; + GladeXmlNode *child_node; - child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD); - glade_xml_node_append_child (node, child_node); + child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD); + glade_xml_node_append_child (node, child_node); - /* Write out the widget */ - glade_widget_write (widget, context, child_node); + /* Write out the widget */ + glade_widget_write (widget, context, child_node); - /* Write accelerator here */ - glade_gtk_write_accels (widget, context, child_node, FALSE); + /* Write accelerator here */ + glade_gtk_write_accels (widget, context, child_node, FALSE); } diff --git a/plugins/gtk+/glade-gtk.h b/plugins/gtk+/glade-gtk.h index d4e0a30c..d85e4a6d 100644 --- a/plugins/gtk+/glade-gtk.h +++ b/plugins/gtk+/glade-gtk.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ #ifndef __GLADE_GTK_H__ #define __GLADE_GTK_H__ diff --git a/plugins/gtk+/glade-icon-factory-editor.c b/plugins/gtk+/glade-icon-factory-editor.c index 222bf02f..a34d12fe 100644 --- a/plugins/gtk+/glade-icon-factory-editor.c +++ b/plugins/gtk+/glade-icon-factory-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,181 +27,190 @@ #include "glade-icon-factory-editor.h" -static void glade_icon_factory_editor_finalize (GObject *object); +static void glade_icon_factory_editor_finalize (GObject * object); -static void glade_icon_factory_editor_editable_init (GladeEditableIface *iface); +static void glade_icon_factory_editor_editable_init (GladeEditableIface * + iface); -static void glade_icon_factory_editor_grab_focus (GtkWidget *widget); +static void glade_icon_factory_editor_grab_focus (GtkWidget * widget); -G_DEFINE_TYPE_WITH_CODE (GladeIconFactoryEditor, glade_icon_factory_editor, GTK_TYPE_VBOX, +G_DEFINE_TYPE_WITH_CODE (GladeIconFactoryEditor, glade_icon_factory_editor, + GTK_TYPE_VBOX, G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_icon_factory_editor_editable_init)); static void -glade_icon_factory_editor_class_init (GladeIconFactoryEditorClass *klass) +glade_icon_factory_editor_class_init (GladeIconFactoryEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_icon_factory_editor_finalize; - widget_class->grab_focus = glade_icon_factory_editor_grab_focus; + object_class->finalize = glade_icon_factory_editor_finalize; + widget_class->grab_focus = glade_icon_factory_editor_grab_focus; } static void -glade_icon_factory_editor_init (GladeIconFactoryEditor *self) +glade_icon_factory_editor_init (GladeIconFactoryEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeIconFactoryEditor *factory_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeIconFactoryEditor * factory_editor) { - if (!gtk_widget_get_mapped (GTK_WIDGET (factory_editor))) - return; + if (!gtk_widget_get_mapped (GTK_WIDGET (factory_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (factory_editor), factory_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (factory_editor), + factory_editor->loaded_widget); } static void -project_finalized (GladeIconFactoryEditor *factory_editor, - GladeProject *where_project_was) +project_finalized (GladeIconFactoryEditor * factory_editor, + GladeProject * where_project_was) { - factory_editor->loaded_widget = NULL; + factory_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (factory_editor), NULL); + glade_editable_load (GLADE_EDITABLE (factory_editor), NULL); } static void -glade_icon_factory_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_icon_factory_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (editable); - GList *l; - - /* Since we watch the project*/ - if (factory_editor->loaded_widget) - { - g_signal_handlers_disconnect_by_func (G_OBJECT (factory_editor->loaded_widget->project), - G_CALLBACK (project_changed), factory_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (factory_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - factory_editor); - } - - /* Mark our widget... */ - factory_editor->loaded_widget = widget; - - if (factory_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (factory_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), factory_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (factory_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - factory_editor); - } - - /* load the embedded editable... */ - if (factory_editor->embed) - glade_editable_load (GLADE_EDITABLE (factory_editor->embed), widget); - - for (l = factory_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); + GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (editable); + GList *l; + + /* Since we watch the project */ + if (factory_editor->loaded_widget) + { + g_signal_handlers_disconnect_by_func (G_OBJECT + (factory_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + factory_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (factory_editor->loaded_widget->project), + (GWeakNotify) project_finalized, factory_editor); + } + + /* Mark our widget... */ + factory_editor->loaded_widget = widget; + + if (factory_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (factory_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), + factory_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (factory_editor->loaded_widget->project), + (GWeakNotify) project_finalized, factory_editor); + } + + /* load the embedded editable... */ + if (factory_editor->embed) + glade_editable_load (GLADE_EDITABLE (factory_editor->embed), widget); + + for (l = factory_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); } static void -glade_icon_factory_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_icon_factory_editor_set_show_name (GladeEditable * editable, + gboolean show_name) { - GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (editable); + GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (factory_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (factory_editor->embed), + show_name); } static void -glade_icon_factory_editor_editable_init (GladeEditableIface *iface) +glade_icon_factory_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_icon_factory_editor_load; - iface->set_show_name = glade_icon_factory_editor_set_show_name; + iface->load = glade_icon_factory_editor_load; + iface->set_show_name = glade_icon_factory_editor_set_show_name; } static void -glade_icon_factory_editor_finalize (GObject *object) +glade_icon_factory_editor_finalize (GObject * object) { - GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (object); + GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (object); - if (factory_editor->properties) - g_list_free (factory_editor->properties); - factory_editor->properties = NULL; - factory_editor->embed = NULL; + if (factory_editor->properties) + g_list_free (factory_editor->properties); + factory_editor->properties = NULL; + factory_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_icon_factory_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_icon_factory_editor_parent_class)->finalize (object); } static void -glade_icon_factory_editor_grab_focus (GtkWidget *widget) +glade_icon_factory_editor_grab_focus (GtkWidget * widget) { - GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (widget); + GladeIconFactoryEditor *factory_editor = GLADE_ICON_FACTORY_EDITOR (widget); - gtk_widget_grab_focus (factory_editor->embed); + gtk_widget_grab_focus (factory_editor->embed); } GtkWidget * -glade_icon_factory_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_icon_factory_editor_new (GladeWidgetAdaptor * adaptor, + GladeEditable * embed) { - GladeIconFactoryEditor *factory_editor; - GladeEditorProperty *eprop; - GtkWidget *label, *alignment, *frame, *vbox; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - factory_editor = g_object_new (GLADE_TYPE_ICON_FACTORY_EDITOR, NULL); - factory_editor->embed = GTK_WIDGET (embed); - - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (factory_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - /* Label item in frame label widget on top... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "sources", FALSE, TRUE); - factory_editor->properties = g_list_prepend (factory_editor->properties, eprop); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (factory_editor), frame, FALSE, FALSE, 12); - - /* Alignment/Vbox in frame... */ - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (alignment), vbox); - - /* Add descriptive label */ - label = gtk_label_new (_("First add a stock name in the entry below, " - "then add and define sources for that icon " - "in the treeview.")); - gtk_label_set_line_wrap (GTK_LABEL(label), TRUE); - gtk_label_set_line_wrap_mode (GTK_LABEL(label), PANGO_WRAP_WORD); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 8); - - gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 8); - - gtk_widget_show_all (GTK_WIDGET (factory_editor)); - - return GTK_WIDGET (factory_editor); + GladeIconFactoryEditor *factory_editor; + GladeEditorProperty *eprop; + GtkWidget *label, *alignment, *frame, *vbox; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + factory_editor = g_object_new (GLADE_TYPE_ICON_FACTORY_EDITOR, NULL); + factory_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (factory_editor), GTK_WIDGET (embed), FALSE, + FALSE, 0); + + /* Label item in frame label widget on top... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "sources", FALSE, + TRUE); + factory_editor->properties = + g_list_prepend (factory_editor->properties, eprop); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (factory_editor), frame, FALSE, FALSE, 12); + + /* Alignment/Vbox in frame... */ + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (alignment), vbox); + + /* Add descriptive label */ + label = gtk_label_new (_("First add a stock name in the entry below, " + "then add and define sources for that icon " + "in the treeview.")); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 8); + + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 8); + + gtk_widget_show_all (GTK_WIDGET (factory_editor)); + + return GTK_WIDGET (factory_editor); } diff --git a/plugins/gtk+/glade-icon-factory-editor.h b/plugins/gtk+/glade-icon-factory-editor.h index dca9cc82..571758e3 100644 --- a/plugins/gtk+/glade-icon-factory-editor.h +++ b/plugins/gtk+/glade-icon-factory-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-icon-sources.c b/plugins/gtk+/glade-icon-sources.c index d259517f..9b6da8a0 100644 --- a/plugins/gtk+/glade-icon-sources.c +++ b/plugins/gtk+/glade-icon-sources.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -30,110 +29,109 @@ #include "glade-icon-sources.h" static GList * -icon_set_copy (GList *set) +icon_set_copy (GList * set) { - GList *dup_set = NULL, *l; - GtkIconSource *source; - - for (l = set; l; l = l->next) - { - source = gtk_icon_source_copy ((GtkIconSource *)l->data); - dup_set = g_list_prepend (dup_set, source); - } - return g_list_reverse (dup_set); + GList *dup_set = NULL, *l; + GtkIconSource *source; + + for (l = set; l; l = l->next) + { + source = gtk_icon_source_copy ((GtkIconSource *) l->data); + dup_set = g_list_prepend (dup_set, source); + } + return g_list_reverse (dup_set); } static void -icon_set_free (GList *list) +icon_set_free (GList * list) { - g_list_foreach (list, (GFunc)gtk_icon_source_free, NULL); - g_list_free (list); + g_list_foreach (list, (GFunc) gtk_icon_source_free, NULL); + g_list_free (list); } GladeIconSources * glade_icon_sources_new (void) { - GladeIconSources *sources = g_new0 (GladeIconSources, 1); + GladeIconSources *sources = g_new0 (GladeIconSources, 1); - sources->sources = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)icon_set_free); - return sources; + sources->sources = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) icon_set_free); + return sources; } static void -icon_sources_dup (gchar *icon_name, - GList *set, - GladeIconSources *dup) +icon_sources_dup (gchar * icon_name, GList * set, GladeIconSources * dup) { - GList *dup_set = icon_set_copy (set); - g_hash_table_insert (dup->sources, g_strdup (icon_name), dup_set); + GList *dup_set = icon_set_copy (set); + g_hash_table_insert (dup->sources, g_strdup (icon_name), dup_set); } GladeIconSources * -glade_icon_sources_copy (GladeIconSources *sources) +glade_icon_sources_copy (GladeIconSources * sources) { - if (!sources) - return NULL; + if (!sources) + return NULL; - GladeIconSources *dup = glade_icon_sources_new (); + GladeIconSources *dup = glade_icon_sources_new (); - g_hash_table_foreach (sources->sources, (GHFunc)icon_sources_dup, dup); + g_hash_table_foreach (sources->sources, (GHFunc) icon_sources_dup, dup); - return dup; + return dup; } void -glade_icon_sources_free (GladeIconSources *sources) +glade_icon_sources_free (GladeIconSources * sources) { - if (sources) - { - g_hash_table_destroy (sources->sources); - g_free (sources); - } + if (sources) + { + g_hash_table_destroy (sources->sources); + g_free (sources); + } } GType glade_icon_sources_get_type (void) { - static GType type_id = 0; - - if (!type_id) - type_id = g_boxed_type_register_static - ("GladeIconSources", - (GBoxedCopyFunc) glade_icon_sources_copy, - (GBoxedFreeFunc) glade_icon_sources_free); - return type_id; + static GType type_id = 0; + + if (!type_id) + type_id = g_boxed_type_register_static + ("GladeIconSources", + (GBoxedCopyFunc) glade_icon_sources_copy, + (GBoxedFreeFunc) glade_icon_sources_free); + return type_id; } /**************************** GladeEditorProperty *****************************/ -enum { - COLUMN_TEXT, /* Used for display/editing purposes */ - COLUMN_TEXT_WEIGHT, /* Whether the text is bold (icon-name parent rows) */ - COLUMN_TEXT_EDITABLE, /* parent icon-name displays are not editable */ - COLUMN_ICON_NAME, /* store the icon name regardless */ - COLUMN_LIST_INDEX, /* denotes the position in the GList of the actual property value (or -1) */ - COLUMN_DIRECTION_ACTIVE, - COLUMN_DIRECTION, - COLUMN_SIZE_ACTIVE, - COLUMN_SIZE, - COLUMN_STATE_ACTIVE, - COLUMN_STATE, - NUM_COLUMNS +enum +{ + COLUMN_TEXT, /* Used for display/editing purposes */ + COLUMN_TEXT_WEIGHT, /* Whether the text is bold (icon-name parent rows) */ + COLUMN_TEXT_EDITABLE, /* parent icon-name displays are not editable */ + COLUMN_ICON_NAME, /* store the icon name regardless */ + COLUMN_LIST_INDEX, /* denotes the position in the GList of the actual property value (or -1) */ + COLUMN_DIRECTION_ACTIVE, + COLUMN_DIRECTION, + COLUMN_SIZE_ACTIVE, + COLUMN_SIZE, + COLUMN_STATE_ACTIVE, + COLUMN_STATE, + NUM_COLUMNS }; typedef struct { - GladeEditorProperty parent_instance; + GladeEditorProperty parent_instance; - GtkTreeView *view; - GtkTreeStore *store; - GtkListStore *icon_names_store; - GtkTreeViewColumn *filename_column; - GtkWidget *combo; + GtkTreeView *view; + GtkTreeStore *store; + GtkListStore *icon_names_store; + GtkTreeViewColumn *filename_column; + GtkWidget *combo; } GladeEPropIconSources; GLADE_MAKE_EPROP (GladeEPropIconSources, glade_eprop_icon_sources) @@ -142,850 +140,869 @@ GLADE_MAKE_EPROP (GladeEPropIconSources, glade_eprop_icon_sources) #define GLADE_IS_EPROP_ICON_SOURCES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ICON_SOURCES)) #define GLADE_IS_EPROP_ICON_SOURCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ICON_SOURCES)) #define GLADE_EPROP_ICON_SOURCES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ICON_SOURCES, GladeEPropIconSourcesClass)) - -static void -glade_eprop_icon_sources_finalize (GObject *object) + static void glade_eprop_icon_sources_finalize (GObject * object) { - /* Chain up */ - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); - //GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (object); + /* Chain up */ + GObjectClass *parent_class = + g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); + //GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (object); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -populate_store_foreach (const gchar *icon_name, - GList *sources, - GladeEPropIconSources *eprop_sources) +populate_store_foreach (const gchar * icon_name, + GList * sources, GladeEPropIconSources * eprop_sources) { - GtkIconSource *source; - GtkTreeIter parent_iter, iter; - GList *l; - - /* Update the comboboxentry's store here... */ - gtk_list_store_append (eprop_sources->icon_names_store, &iter); - gtk_list_store_set (eprop_sources->icon_names_store, &iter, 0, icon_name, -1); - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (eprop_sources->combo), &iter); - - /* Dont set COLUMN_ICON_NAME here */ - gtk_tree_store_append (eprop_sources->store, &parent_iter, NULL); - gtk_tree_store_set (eprop_sources->store, &parent_iter, - COLUMN_TEXT, icon_name, - COLUMN_TEXT_EDITABLE, FALSE, - COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_BOLD, - -1); - - for (l = sources; l; l = l->next) - { - GdkPixbuf *pixbuf; - gchar *str; - - source = l->data; - pixbuf = gtk_icon_source_get_pixbuf (source); - str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName"); - - gtk_tree_store_append (eprop_sources->store, &iter, &parent_iter); - gtk_tree_store_set (eprop_sources->store, &iter, - COLUMN_ICON_NAME, icon_name, - COLUMN_LIST_INDEX, g_list_index (sources, source), - COLUMN_TEXT, str, - COLUMN_TEXT_EDITABLE, TRUE, - COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_NORMAL, - -1); - - if (!gtk_icon_source_get_direction_wildcarded (source)) - { - GtkTextDirection direction = gtk_icon_source_get_direction (source); - str = glade_utils_enum_string_from_value_displayable (GTK_TYPE_TEXT_DIRECTION, direction); - gtk_tree_store_set (eprop_sources->store, &iter, - COLUMN_DIRECTION_ACTIVE, TRUE, - COLUMN_DIRECTION, str, - -1); - g_free (str); - } - - if (!gtk_icon_source_get_size_wildcarded (source)) - { - GtkIconSize size = gtk_icon_source_get_size (source); - str = glade_utils_enum_string_from_value_displayable (GTK_TYPE_ICON_SIZE, size); - gtk_tree_store_set (eprop_sources->store, &iter, - COLUMN_SIZE_ACTIVE, TRUE, - COLUMN_SIZE, str, - -1); - g_free (str); - } - - if (!gtk_icon_source_get_state_wildcarded (source)) - { - GtkStateType state = gtk_icon_source_get_state (source); - str = glade_utils_enum_string_from_value_displayable (GTK_TYPE_STATE_TYPE, state); - gtk_tree_store_set (eprop_sources->store, &iter, - COLUMN_STATE_ACTIVE, TRUE, - COLUMN_STATE, str, - -1); - g_free (str); - } - - if (!l->next) - { - GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_sources->store), - &iter); - gtk_tree_view_expand_to_path (GTK_TREE_VIEW (eprop_sources->view), - path); - gtk_tree_path_free (path); - } - } + GtkIconSource *source; + GtkTreeIter parent_iter, iter; + GList *l; + + /* Update the comboboxentry's store here... */ + gtk_list_store_append (eprop_sources->icon_names_store, &iter); + gtk_list_store_set (eprop_sources->icon_names_store, &iter, 0, icon_name, -1); + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (eprop_sources->combo), &iter); + + /* Dont set COLUMN_ICON_NAME here */ + gtk_tree_store_append (eprop_sources->store, &parent_iter, NULL); + gtk_tree_store_set (eprop_sources->store, &parent_iter, + COLUMN_TEXT, icon_name, + COLUMN_TEXT_EDITABLE, FALSE, + COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_BOLD, -1); + + for (l = sources; l; l = l->next) + { + GdkPixbuf *pixbuf; + gchar *str; + + source = l->data; + pixbuf = gtk_icon_source_get_pixbuf (source); + str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName"); + + gtk_tree_store_append (eprop_sources->store, &iter, &parent_iter); + gtk_tree_store_set (eprop_sources->store, &iter, + COLUMN_ICON_NAME, icon_name, + COLUMN_LIST_INDEX, g_list_index (sources, source), + COLUMN_TEXT, str, + COLUMN_TEXT_EDITABLE, TRUE, + COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_NORMAL, -1); + + if (!gtk_icon_source_get_direction_wildcarded (source)) + { + GtkTextDirection direction = gtk_icon_source_get_direction (source); + str = + glade_utils_enum_string_from_value_displayable + (GTK_TYPE_TEXT_DIRECTION, direction); + gtk_tree_store_set (eprop_sources->store, &iter, + COLUMN_DIRECTION_ACTIVE, TRUE, COLUMN_DIRECTION, + str, -1); + g_free (str); + } + + if (!gtk_icon_source_get_size_wildcarded (source)) + { + GtkIconSize size = gtk_icon_source_get_size (source); + str = + glade_utils_enum_string_from_value_displayable + (GTK_TYPE_ICON_SIZE, size); + gtk_tree_store_set (eprop_sources->store, &iter, COLUMN_SIZE_ACTIVE, + TRUE, COLUMN_SIZE, str, -1); + g_free (str); + } + + if (!gtk_icon_source_get_state_wildcarded (source)) + { + GtkStateType state = gtk_icon_source_get_state (source); + str = + glade_utils_enum_string_from_value_displayable + (GTK_TYPE_STATE_TYPE, state); + gtk_tree_store_set (eprop_sources->store, &iter, COLUMN_STATE_ACTIVE, + TRUE, COLUMN_STATE, str, -1); + g_free (str); + } + + if (!l->next) + { + GtkTreePath *path = + gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_sources->store), + &iter); + gtk_tree_view_expand_to_path (GTK_TREE_VIEW (eprop_sources->view), + path); + gtk_tree_path_free (path); + } + } } static void -populate_store (GladeEPropIconSources *eprop_sources) +populate_store (GladeEPropIconSources * eprop_sources) { - GladeIconSources *sources = NULL; + GladeIconSources *sources = NULL; - gtk_tree_store_clear (eprop_sources->store); - gtk_list_store_clear (eprop_sources->icon_names_store); + gtk_tree_store_clear (eprop_sources->store); + gtk_list_store_clear (eprop_sources->icon_names_store); - if (!GLADE_EDITOR_PROPERTY (eprop_sources)->property) - return; + if (!GLADE_EDITOR_PROPERTY (eprop_sources)->property) + return; - glade_property_get (GLADE_EDITOR_PROPERTY (eprop_sources)->property, &sources); + glade_property_get (GLADE_EDITOR_PROPERTY (eprop_sources)->property, + &sources); - if (sources) - g_hash_table_foreach (sources->sources, (GHFunc)populate_store_foreach, eprop_sources); + if (sources) + g_hash_table_foreach (sources->sources, (GHFunc) populate_store_foreach, + eprop_sources); } static void -glade_eprop_icon_sources_load (GladeEditorProperty *eprop, - GladeProperty *property) +glade_eprop_icon_sources_load (GladeEditorProperty * eprop, + GladeProperty * property) { - GladeEditorPropertyClass *parent_class = - g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); - GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); + GladeEditorPropertyClass *parent_class = + g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); + GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); - /* Chain up in a clean state... */ - parent_class->load (eprop, property); + /* Chain up in a clean state... */ + parent_class->load (eprop, property); - populate_store (eprop_sources); + populate_store (eprop_sources); - gtk_widget_queue_draw (GTK_WIDGET (eprop_sources->view)); + gtk_widget_queue_draw (GTK_WIDGET (eprop_sources->view)); } static gboolean -reload_icon_sources_idle (GladeEditorProperty *eprop) +reload_icon_sources_idle (GladeEditorProperty * eprop) { - glade_editor_property_load (eprop, eprop->property); - return FALSE; + glade_editor_property_load (eprop, eprop->property); + return FALSE; } static void -add_clicked (GtkWidget *button, - GladeEPropIconSources *eprop_sources) +add_clicked (GtkWidget * button, GladeEPropIconSources * eprop_sources) { - /* Remember to set focus on the cell and activate it ! */ - GtkTreeIter *parent_iter = NULL, iter, new_parent_iter; - GtkTreePath *new_item_path; - gchar *icon_name; - gchar *selected_icon_name = NULL; - gint index; - - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (eprop_sources->combo), &iter)) - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->icon_names_store), &iter, - 0, &selected_icon_name, -1); - - if (!selected_icon_name) - return; - - /* Find the right parent iter to add a child to... */ - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_sources->store), &iter)) - { - do { - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, - COLUMN_TEXT, &icon_name, - -1); - - if (icon_name && - strcmp (icon_name, selected_icon_name) == 0) - parent_iter = gtk_tree_iter_copy (&iter); - - g_free (icon_name); - - } while (parent_iter == NULL && - gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_sources->store), &iter)); - } - - /* check if we're already adding one here... */ - if (parent_iter && - gtk_tree_model_iter_children (GTK_TREE_MODEL (eprop_sources->store), &iter, parent_iter)) - { - do { - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, - COLUMN_LIST_INDEX, &index, - -1); - - /* Iter is set, expand and return. */ - if (index < 0) - goto expand_to_path_and_focus; - - } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_sources->store), &iter)); - } - - - if (!parent_iter) - { - /* Dont set COLUMN_ICON_NAME here */ - gtk_tree_store_append (eprop_sources->store, &new_parent_iter, NULL); - gtk_tree_store_set (eprop_sources->store, &new_parent_iter, - COLUMN_TEXT, selected_icon_name, - COLUMN_TEXT_EDITABLE, FALSE, - COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_BOLD, - -1); - parent_iter = gtk_tree_iter_copy (&new_parent_iter); - } - - gtk_tree_store_append (eprop_sources->store, &iter, parent_iter); - gtk_tree_store_set (eprop_sources->store, &iter, - COLUMN_ICON_NAME, selected_icon_name, - COLUMN_TEXT_EDITABLE, TRUE, - COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_NORMAL, - COLUMN_LIST_INDEX, -1, - -1); - - /* By now iter is valid. */ - expand_to_path_and_focus: - new_item_path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_sources->store), &iter); - - gtk_widget_grab_focus (GTK_WIDGET (eprop_sources->view)); - gtk_tree_view_expand_to_path (eprop_sources->view, new_item_path); - gtk_tree_view_set_cursor (eprop_sources->view, new_item_path, - eprop_sources->filename_column, TRUE); - - g_free (selected_icon_name); - gtk_tree_iter_free (parent_iter); + /* Remember to set focus on the cell and activate it ! */ + GtkTreeIter *parent_iter = NULL, iter, new_parent_iter; + GtkTreePath *new_item_path; + gchar *icon_name; + gchar *selected_icon_name = NULL; + gint index; + + if (gtk_combo_box_get_active_iter + (GTK_COMBO_BOX (eprop_sources->combo), &iter)) + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->icon_names_store), &iter, + 0, &selected_icon_name, -1); + + if (!selected_icon_name) + return; + + /* Find the right parent iter to add a child to... */ + if (gtk_tree_model_get_iter_first + (GTK_TREE_MODEL (eprop_sources->store), &iter)) + { + do + { + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, + COLUMN_TEXT, &icon_name, -1); + + if (icon_name && strcmp (icon_name, selected_icon_name) == 0) + parent_iter = gtk_tree_iter_copy (&iter); + + g_free (icon_name); + + } + while (parent_iter == NULL && + gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_sources->store), + &iter)); + } + + /* check if we're already adding one here... */ + if (parent_iter && + gtk_tree_model_iter_children (GTK_TREE_MODEL (eprop_sources->store), + &iter, parent_iter)) + { + do + { + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, + COLUMN_LIST_INDEX, &index, -1); + + /* Iter is set, expand and return. */ + if (index < 0) + goto expand_to_path_and_focus; + + } + while (gtk_tree_model_iter_next + (GTK_TREE_MODEL (eprop_sources->store), &iter)); + } + + + if (!parent_iter) + { + /* Dont set COLUMN_ICON_NAME here */ + gtk_tree_store_append (eprop_sources->store, &new_parent_iter, NULL); + gtk_tree_store_set (eprop_sources->store, &new_parent_iter, + COLUMN_TEXT, selected_icon_name, + COLUMN_TEXT_EDITABLE, FALSE, + COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_BOLD, -1); + parent_iter = gtk_tree_iter_copy (&new_parent_iter); + } + + gtk_tree_store_append (eprop_sources->store, &iter, parent_iter); + gtk_tree_store_set (eprop_sources->store, &iter, + COLUMN_ICON_NAME, selected_icon_name, + COLUMN_TEXT_EDITABLE, TRUE, + COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_NORMAL, + COLUMN_LIST_INDEX, -1, -1); + + /* By now iter is valid. */ +expand_to_path_and_focus: + new_item_path = + gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_sources->store), &iter); + + gtk_widget_grab_focus (GTK_WIDGET (eprop_sources->view)); + gtk_tree_view_expand_to_path (eprop_sources->view, new_item_path); + gtk_tree_view_set_cursor (eprop_sources->view, new_item_path, + eprop_sources->filename_column, TRUE); + + g_free (selected_icon_name); + gtk_tree_iter_free (parent_iter); } static GtkIconSource * -get_icon_source (GladeIconSources *sources, - const gchar *icon_name, - gint index) +get_icon_source (GladeIconSources * sources, + const gchar * icon_name, gint index) { - GList *source_list = - g_hash_table_lookup (sources->sources, icon_name); - - if (source_list) - { - if (index < 0) - return NULL; - else - return (GtkIconSource *)g_list_nth_data (source_list, index); - } - return NULL; + GList *source_list = g_hash_table_lookup (sources->sources, icon_name); + + if (source_list) + { + if (index < 0) + return NULL; + else + return (GtkIconSource *) g_list_nth_data (source_list, index); + } + return NULL; } static void -update_icon_sources (GladeEditorProperty *eprop, - GladeIconSources *icon_sources) +update_icon_sources (GladeEditorProperty * eprop, + GladeIconSources * icon_sources) { - GValue value = { 0, }; - - g_value_init (&value, GLADE_TYPE_ICON_SOURCES); - g_value_take_boxed (&value, icon_sources); - glade_editor_property_commit (eprop, &value); - g_value_unset (&value); + GValue value = { 0, }; + + g_value_init (&value, GLADE_TYPE_ICON_SOURCES); + g_value_take_boxed (&value, icon_sources); + glade_editor_property_commit (eprop, &value); + g_value_unset (&value); } static void -delete_clicked (GtkWidget *button, - GladeEditorProperty *eprop) +delete_clicked (GtkWidget * button, GladeEditorProperty * eprop) { - GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); - GtkTreeIter iter; - GladeIconSources *icon_sources = NULL; - GList *list, *sources, *new_list_head; - gchar *icon_name; - gint index = 0; - - /* NOTE: This will trigger row-deleted below... */ - if (!gtk_tree_selection_get_selected - (gtk_tree_view_get_selection (eprop_sources->view), NULL, &iter)) - return; - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, - COLUMN_ICON_NAME, &icon_name, - COLUMN_LIST_INDEX, &index, - -1); - - /* Could be the user pressed add and then delete without touching the - * new item. - */ - if (index < 0) - { - g_idle_add ((GSourceFunc)reload_icon_sources_idle, eprop); - return; - } - - glade_property_get (eprop->property, &icon_sources); - if (icon_sources) - { - icon_sources = glade_icon_sources_copy (icon_sources); - - if ((sources = g_hash_table_lookup (icon_sources->sources, icon_name)) != NULL) - { - new_list_head = icon_set_copy (sources); - - list = g_list_nth (new_list_head, index); - new_list_head = g_list_remove_link (new_list_head, list); - - gtk_icon_source_free ((GtkIconSource *)list->data); - g_list_free (list); - - /* We copied all that above cause this will free the old list */ - g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), - new_list_head); - - } - update_icon_sources (eprop, icon_sources); - } - g_free (icon_name); + GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); + GtkTreeIter iter; + GladeIconSources *icon_sources = NULL; + GList *list, *sources, *new_list_head; + gchar *icon_name; + gint index = 0; + + /* NOTE: This will trigger row-deleted below... */ + if (!gtk_tree_selection_get_selected + (gtk_tree_view_get_selection (eprop_sources->view), NULL, &iter)) + return; + + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, + COLUMN_ICON_NAME, &icon_name, + COLUMN_LIST_INDEX, &index, -1); + + /* Could be the user pressed add and then delete without touching the + * new item. + */ + if (index < 0) + { + g_idle_add ((GSourceFunc) reload_icon_sources_idle, eprop); + return; + } + + glade_property_get (eprop->property, &icon_sources); + if (icon_sources) + { + icon_sources = glade_icon_sources_copy (icon_sources); + + if ((sources = + g_hash_table_lookup (icon_sources->sources, icon_name)) != NULL) + { + new_list_head = icon_set_copy (sources); + + list = g_list_nth (new_list_head, index); + new_list_head = g_list_remove_link (new_list_head, list); + + gtk_icon_source_free ((GtkIconSource *) list->data); + g_list_free (list); + + /* We copied all that above cause this will free the old list */ + g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), + new_list_head); + + } + update_icon_sources (eprop, icon_sources); + } + g_free (icon_name); } static void -value_filename_edited (GtkCellRendererText *cell, - const gchar *path, - const gchar *new_text, - GladeEditorProperty *eprop) +value_filename_edited (GtkCellRendererText * cell, + const gchar * path, + const gchar * new_text, GladeEditorProperty * eprop) { - GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); - GtkTreeIter iter; - GladeIconSources *icon_sources = NULL; - GtkIconSource *source; - gchar *icon_name; - gint index = -1; - GValue *value; - GdkPixbuf *pixbuf; - GList *source_list; - - if (!new_text || !new_text[0]) - { - g_idle_add ((GSourceFunc)reload_icon_sources_idle, eprop); - return; - } - - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) - return; - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, - COLUMN_ICON_NAME, &icon_name, - COLUMN_LIST_INDEX, &index, - -1); - - /* get new pixbuf value... */ - value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, new_text, - eprop->property->widget->project, - eprop->property->widget); - pixbuf = g_value_get_object (value); - - - glade_property_get (eprop->property, &icon_sources); - if (icon_sources) - { - icon_sources = glade_icon_sources_copy (icon_sources); - - if (index >= 0 && (source = get_icon_source (icon_sources, icon_name, index)) != NULL) - gtk_icon_source_set_pixbuf (source, pixbuf); - else - { - - source = gtk_icon_source_new (); - gtk_icon_source_set_pixbuf (source, pixbuf); - - if ((source_list = g_hash_table_lookup (icon_sources->sources, - icon_name)) != NULL) - { - source_list = g_list_append (source_list, source); - } - else - { - source_list = g_list_prepend (NULL, source); - g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), source_list); - } - } - } - else - { - icon_sources = glade_icon_sources_new (); - source = gtk_icon_source_new (); - gtk_icon_source_set_pixbuf (source, pixbuf); - - source_list = g_list_prepend (NULL, source); - g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), source_list); - } - - g_value_unset (value); - g_free (value); - - update_icon_sources (eprop, icon_sources); + GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); + GtkTreeIter iter; + GladeIconSources *icon_sources = NULL; + GtkIconSource *source; + gchar *icon_name; + gint index = -1; + GValue *value; + GdkPixbuf *pixbuf; + GList *source_list; + + if (!new_text || !new_text[0]) + { + g_idle_add ((GSourceFunc) reload_icon_sources_idle, eprop); + return; + } + + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) + return; + + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, + COLUMN_ICON_NAME, &icon_name, + COLUMN_LIST_INDEX, &index, -1); + + /* get new pixbuf value... */ + value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, new_text, + eprop->property->widget->project, + eprop->property->widget); + pixbuf = g_value_get_object (value); + + + glade_property_get (eprop->property, &icon_sources); + if (icon_sources) + { + icon_sources = glade_icon_sources_copy (icon_sources); + + if (index >= 0 && + (source = get_icon_source (icon_sources, icon_name, index)) != NULL) + gtk_icon_source_set_pixbuf (source, pixbuf); + else + { + + source = gtk_icon_source_new (); + gtk_icon_source_set_pixbuf (source, pixbuf); + + if ((source_list = g_hash_table_lookup (icon_sources->sources, + icon_name)) != NULL) + { + source_list = g_list_append (source_list, source); + } + else + { + source_list = g_list_prepend (NULL, source); + g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), + source_list); + } + } + } + else + { + icon_sources = glade_icon_sources_new (); + source = gtk_icon_source_new (); + gtk_icon_source_set_pixbuf (source, pixbuf); + + source_list = g_list_prepend (NULL, source); + g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), + source_list); + } + + g_value_unset (value); + g_free (value); + + update_icon_sources (eprop, icon_sources); } static void -value_attribute_toggled (GtkCellRendererToggle *cell_renderer, - gchar *path, - GladeEditorProperty *eprop) +value_attribute_toggled (GtkCellRendererToggle * cell_renderer, + gchar * path, GladeEditorProperty * eprop) { - GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); - GtkTreeIter iter; - GladeIconSources *icon_sources = NULL; - GtkIconSource *source; - gchar *icon_name; - gint index, edit_column; - gboolean edit_column_active = FALSE; - - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) - return; - - edit_column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell_renderer), "attribute-column")); - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, - COLUMN_ICON_NAME, &icon_name, - COLUMN_LIST_INDEX, &index, - edit_column, &edit_column_active, - -1); - - glade_property_get (eprop->property, &icon_sources); - - if (icon_sources) - icon_sources = glade_icon_sources_copy (icon_sources); - - if (icon_sources && (source = get_icon_source (icon_sources, icon_name, index)) != NULL) - { - /* Note the reverse meaning of active toggles vs. wildcarded sources... */ - switch (edit_column) - { - case COLUMN_DIRECTION_ACTIVE: - gtk_icon_source_set_direction_wildcarded (source, edit_column_active); - break; - case COLUMN_SIZE_ACTIVE: - gtk_icon_source_set_size_wildcarded (source, edit_column_active); - break; - case COLUMN_STATE_ACTIVE: - gtk_icon_source_set_state_wildcarded (source, edit_column_active); - break; - default: - break; - } - - update_icon_sources (eprop, icon_sources); - g_free (icon_name); - return; - } - - if (icon_sources) - glade_icon_sources_free (icon_sources); - g_free (icon_name); - return; + GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); + GtkTreeIter iter; + GladeIconSources *icon_sources = NULL; + GtkIconSource *source; + gchar *icon_name; + gint index, edit_column; + gboolean edit_column_active = FALSE; + + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) + return; + + edit_column = + GPOINTER_TO_INT (g_object_get_data + (G_OBJECT (cell_renderer), "attribute-column")); + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, + COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index, + edit_column, &edit_column_active, -1); + + glade_property_get (eprop->property, &icon_sources); + + if (icon_sources) + icon_sources = glade_icon_sources_copy (icon_sources); + + if (icon_sources && + (source = get_icon_source (icon_sources, icon_name, index)) != NULL) + { + /* Note the reverse meaning of active toggles vs. wildcarded sources... */ + switch (edit_column) + { + case COLUMN_DIRECTION_ACTIVE: + gtk_icon_source_set_direction_wildcarded (source, + edit_column_active); + break; + case COLUMN_SIZE_ACTIVE: + gtk_icon_source_set_size_wildcarded (source, edit_column_active); + break; + case COLUMN_STATE_ACTIVE: + gtk_icon_source_set_state_wildcarded (source, edit_column_active); + break; + default: + break; + } + + update_icon_sources (eprop, icon_sources); + g_free (icon_name); + return; + } + + if (icon_sources) + glade_icon_sources_free (icon_sources); + g_free (icon_name); + return; } static void -value_attribute_edited (GtkCellRendererText *cell, - const gchar *path, - const gchar *new_text, - GladeEditorProperty *eprop) +value_attribute_edited (GtkCellRendererText * cell, + const gchar * path, + const gchar * new_text, GladeEditorProperty * eprop) { - GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); - GtkTreeIter iter; - GladeIconSources *icon_sources = NULL; - GtkIconSource *source; - gchar *icon_name; - gint index, edit_column; - - if (!new_text || !new_text[0]) - return; - - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) - return; - - edit_column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "attribute-column")); - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, - COLUMN_ICON_NAME, &icon_name, - COLUMN_LIST_INDEX, &index, - -1); - - glade_property_get (eprop->property, &icon_sources); - - if (icon_sources) - icon_sources = glade_icon_sources_copy (icon_sources); - - if (icon_sources && (source = get_icon_source (icon_sources, icon_name, index)) != NULL) - { - GtkTextDirection direction; - GtkIconSize size; - GtkStateType state; - - switch (edit_column) - { - case COLUMN_DIRECTION: - direction = glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, new_text); - gtk_icon_source_set_direction (source, direction); - break; - case COLUMN_SIZE: - size = glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, new_text); - gtk_icon_source_set_size (source, size); - break; - case COLUMN_STATE: - state = glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, new_text); - gtk_icon_source_set_state (source, state); - break; - default: - break; - } - - update_icon_sources (eprop, icon_sources); - g_free (icon_name); - return; - } - - if (icon_sources) - glade_icon_sources_free (icon_sources); - g_free (icon_name); - return; + GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); + GtkTreeIter iter; + GladeIconSources *icon_sources = NULL; + GtkIconSource *source; + gchar *icon_name; + gint index, edit_column; + + if (!new_text || !new_text[0]) + return; + + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) + return; + + edit_column = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "attribute-column")); + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, + COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index, + -1); + + glade_property_get (eprop->property, &icon_sources); + + if (icon_sources) + icon_sources = glade_icon_sources_copy (icon_sources); + + if (icon_sources && + (source = get_icon_source (icon_sources, icon_name, index)) != NULL) + { + GtkTextDirection direction; + GtkIconSize size; + GtkStateType state; + + switch (edit_column) + { + case COLUMN_DIRECTION: + direction = + glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, + new_text); + gtk_icon_source_set_direction (source, direction); + break; + case COLUMN_SIZE: + size = + glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, + new_text); + gtk_icon_source_set_size (source, size); + break; + case COLUMN_STATE: + state = + glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, + new_text); + gtk_icon_source_set_state (source, state); + break; + default: + break; + } + + update_icon_sources (eprop, icon_sources); + g_free (icon_name); + return; + } + + if (icon_sources) + glade_icon_sources_free (icon_sources); + g_free (icon_name); + return; } static gboolean -icon_sources_query_tooltip (GtkWidget *widget, - gint x, - gint y, - gboolean keyboard_mode, - GtkTooltip *tooltip, - GladeEPropIconSources *eprop_sources) +icon_sources_query_tooltip (GtkWidget * widget, + gint x, + gint y, + gboolean keyboard_mode, + GtkTooltip * tooltip, + GladeEPropIconSources * eprop_sources) { - GtkTreePath *path = NULL; - GtkTreeIter iter; - GtkTreeViewColumn *column = NULL; - gint bin_x = x, bin_y = y, col; - gchar *icon_name = NULL; - gboolean show_now = FALSE; - - if (keyboard_mode) - return FALSE; - - gtk_tree_view_convert_widget_to_bin_window_coords (eprop_sources->view, - x, y, &bin_x, &bin_y); - - if (gtk_tree_view_get_path_at_pos (eprop_sources->view, - bin_x, bin_y, - &path, &column, NULL, NULL)) - { - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) - { - col = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (column), "column-id")); - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, - COLUMN_ICON_NAME, &icon_name, -1); - - /* no tooltips on the parent rows */ - if (icon_name) - { - gchar *tooltip_text = NULL; - show_now = TRUE; - - switch (col) - { - case COLUMN_TEXT: - tooltip_text = - g_strdup_printf (_("Enter a filename or a relative or full path for this " - "source of '%s' (Glade will only ever load them in " - "the runtime from your project directory)."), - icon_name); - break; - case COLUMN_DIRECTION_ACTIVE: - tooltip_text = - g_strdup_printf (_("Set whether you want to specify a text direction " - "for this source of '%s'"), icon_name); - break; - case COLUMN_DIRECTION: - tooltip_text = - g_strdup_printf (_("Set the text direction for this source of '%s'"), - icon_name); - break; - case COLUMN_SIZE_ACTIVE: - tooltip_text = - g_strdup_printf (_("Set whether you want to specify an icon size " - "for this source of '%s'"), icon_name); - break; - case COLUMN_SIZE: - tooltip_text = - g_strdup_printf (_("Set the icon size for this source of '%s'"), - icon_name); - break; - case COLUMN_STATE_ACTIVE: - tooltip_text = - g_strdup_printf (_("Set whether you want to specify a state " - "for this source of '%s'"), icon_name); - break; - case COLUMN_STATE: - tooltip_text = - g_strdup_printf (_("Set the state for this source of '%s'"), - icon_name); - default: - break; - - } - - gtk_tooltip_set_text (tooltip, tooltip_text); - g_free (tooltip_text); - g_free (icon_name); - - - gtk_tree_view_set_tooltip_cell (eprop_sources->view, - tooltip, path, column, NULL); - - } - } - gtk_tree_path_free (path); - } - return show_now; + GtkTreePath *path = NULL; + GtkTreeIter iter; + GtkTreeViewColumn *column = NULL; + gint bin_x = x, bin_y = y, col; + gchar *icon_name = NULL; + gboolean show_now = FALSE; + + if (keyboard_mode) + return FALSE; + + gtk_tree_view_convert_widget_to_bin_window_coords (eprop_sources->view, + x, y, &bin_x, &bin_y); + + if (gtk_tree_view_get_path_at_pos (eprop_sources->view, + bin_x, bin_y, &path, &column, NULL, NULL)) + { + if (gtk_tree_model_get_iter + (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) + { + col = + GPOINTER_TO_INT (g_object_get_data + (G_OBJECT (column), "column-id")); + + gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, + COLUMN_ICON_NAME, &icon_name, -1); + + /* no tooltips on the parent rows */ + if (icon_name) + { + gchar *tooltip_text = NULL; + show_now = TRUE; + + switch (col) + { + case COLUMN_TEXT: + tooltip_text = + g_strdup_printf (_ + ("Enter a filename or a relative or full path for this " + "source of '%s' (Glade will only ever load them in " + "the runtime from your project directory)."), + icon_name); + break; + case COLUMN_DIRECTION_ACTIVE: + tooltip_text = + g_strdup_printf (_ + ("Set whether you want to specify a text direction " + "for this source of '%s'"), + icon_name); + break; + case COLUMN_DIRECTION: + tooltip_text = + g_strdup_printf (_ + ("Set the text direction for this source of '%s'"), + icon_name); + break; + case COLUMN_SIZE_ACTIVE: + tooltip_text = + g_strdup_printf (_ + ("Set whether you want to specify an icon size " + "for this source of '%s'"), + icon_name); + break; + case COLUMN_SIZE: + tooltip_text = + g_strdup_printf (_ + ("Set the icon size for this source of '%s'"), + icon_name); + break; + case COLUMN_STATE_ACTIVE: + tooltip_text = + g_strdup_printf (_ + ("Set whether you want to specify a state " + "for this source of '%s'"), + icon_name); + break; + case COLUMN_STATE: + tooltip_text = + g_strdup_printf (_ + ("Set the state for this source of '%s'"), + icon_name); + default: + break; + + } + + gtk_tooltip_set_text (tooltip, tooltip_text); + g_free (tooltip_text); + g_free (icon_name); + + + gtk_tree_view_set_tooltip_cell (eprop_sources->view, + tooltip, path, column, NULL); + + } + } + gtk_tree_path_free (path); + } + return show_now; } static GtkTreeView * -build_view (GladeEditorProperty *eprop) +build_view (GladeEditorProperty * eprop) { - GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); - static GtkListStore *direction_store = NULL, *size_store = NULL, *state_store = NULL; - GtkTreeView *view = (GtkTreeView *)gtk_tree_view_new (); - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - if (!direction_store) - { - direction_store = glade_utils_liststore_from_enum_type (GTK_TYPE_TEXT_DIRECTION, FALSE); - size_store = glade_utils_liststore_from_enum_type (GTK_TYPE_ICON_SIZE, FALSE); - state_store = glade_utils_liststore_from_enum_type (GTK_TYPE_STATE_TYPE, FALSE); - } - - /* Filename / icon name column/renderer */ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_filename_edited), eprop); - - eprop_sources->filename_column = - gtk_tree_view_column_new_with_attributes (_("File Name"), renderer, - "text", COLUMN_TEXT, - "weight", COLUMN_TEXT_WEIGHT, - "editable", COLUMN_TEXT_EDITABLE, - NULL); - gtk_tree_view_column_set_expand (eprop_sources->filename_column, TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), eprop_sources->filename_column); - - g_object_set_data (G_OBJECT (eprop_sources->filename_column), "column-id", - GINT_TO_POINTER (COLUMN_TEXT)); - - /********************* Size *********************/ - /* Attribute active portion */ - renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); - g_object_set_data (G_OBJECT (renderer), "attribute-column", - GINT_TO_POINTER (COLUMN_SIZE_ACTIVE)); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (value_attribute_toggled), eprop); - - column = gtk_tree_view_column_new_with_attributes - ("dummy", renderer, - "visible", COLUMN_TEXT_EDITABLE, - "active", COLUMN_SIZE_ACTIVE, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_object_set_data (G_OBJECT (column), "column-id", - GINT_TO_POINTER (COLUMN_SIZE_ACTIVE)); - - /* Attribute portion */ - renderer = gtk_cell_renderer_combo_new (); - g_object_set (G_OBJECT (renderer), "editable", TRUE, "has-entry", FALSE, - "text-column", 0, "model", size_store, NULL); - g_object_set_data (G_OBJECT (renderer), "attribute-column", - GINT_TO_POINTER (COLUMN_SIZE)); - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_attribute_edited), eprop); - - column = gtk_tree_view_column_new_with_attributes - ("dummy", renderer, - "visible", COLUMN_TEXT_EDITABLE, - "editable", COLUMN_SIZE_ACTIVE, - "text", COLUMN_SIZE, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_object_set_data (G_OBJECT (column), "column-id", - GINT_TO_POINTER (COLUMN_SIZE)); - - - /********************* State *********************/ - /* Attribute active portion */ - renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); - g_object_set_data (G_OBJECT (renderer), "attribute-column", - GINT_TO_POINTER (COLUMN_STATE_ACTIVE)); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (value_attribute_toggled), eprop); - - column = gtk_tree_view_column_new_with_attributes - ("dummy", renderer, - "visible", COLUMN_TEXT_EDITABLE, - "active", COLUMN_STATE_ACTIVE, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_object_set_data (G_OBJECT (column), "column-id", - GINT_TO_POINTER (COLUMN_STATE_ACTIVE)); - - /* Attribute portion */ - renderer = gtk_cell_renderer_combo_new (); - g_object_set (G_OBJECT (renderer), "editable", TRUE, "has-entry", FALSE, - "text-column", 0, "model", state_store, NULL); - g_object_set_data (G_OBJECT (renderer), "attribute-column", - GINT_TO_POINTER (COLUMN_STATE)); - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_attribute_edited), eprop); - - column = gtk_tree_view_column_new_with_attributes - ("dummy", renderer, - "visible", COLUMN_TEXT_EDITABLE, - "editable", COLUMN_STATE_ACTIVE, - "text", COLUMN_STATE, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_object_set_data (G_OBJECT (column), "column-id", - GINT_TO_POINTER (COLUMN_STATE)); - - - /********************* Direction *********************/ - /* Attribute active portion */ - renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); - g_object_set_data (G_OBJECT (renderer), "attribute-column", - GINT_TO_POINTER (COLUMN_DIRECTION_ACTIVE)); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (value_attribute_toggled), eprop); - - column = gtk_tree_view_column_new_with_attributes - ("dummy", renderer, - "visible", COLUMN_TEXT_EDITABLE, - "active", COLUMN_DIRECTION_ACTIVE, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_object_set_data (G_OBJECT (column), "column-id", - GINT_TO_POINTER (COLUMN_DIRECTION_ACTIVE)); - - /* Attribute portion */ - renderer = gtk_cell_renderer_combo_new (); - g_object_set (G_OBJECT (renderer), "editable", TRUE, "has-entry", FALSE, - "text-column", 0, "model", direction_store, NULL); - g_object_set_data (G_OBJECT (renderer), "attribute-column", - GINT_TO_POINTER (COLUMN_DIRECTION)); - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_attribute_edited), eprop); - - column = gtk_tree_view_column_new_with_attributes - ("dummy", renderer, - "visible", COLUMN_TEXT_EDITABLE, - "editable", COLUMN_DIRECTION_ACTIVE, - "text", COLUMN_DIRECTION, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_object_set_data (G_OBJECT (column), "column-id", - GINT_TO_POINTER (COLUMN_DIRECTION)); - - - /* Connect ::query-tooltip here for fancy tooltips... */ - g_object_set (G_OBJECT (view), "has-tooltip", TRUE, NULL); - g_signal_connect (G_OBJECT (view), "query-tooltip", - G_CALLBACK (icon_sources_query_tooltip), eprop); - - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE); - gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view), FALSE); - - return view; + GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); + static GtkListStore *direction_store = NULL, *size_store = + NULL, *state_store = NULL; + GtkTreeView *view = (GtkTreeView *) gtk_tree_view_new (); + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + if (!direction_store) + { + direction_store = + glade_utils_liststore_from_enum_type (GTK_TYPE_TEXT_DIRECTION, FALSE); + size_store = + glade_utils_liststore_from_enum_type (GTK_TYPE_ICON_SIZE, FALSE); + state_store = + glade_utils_liststore_from_enum_type (GTK_TYPE_STATE_TYPE, FALSE); + } + + /* Filename / icon name column/renderer */ + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_filename_edited), eprop); + + eprop_sources->filename_column = + gtk_tree_view_column_new_with_attributes (_("File Name"), renderer, + "text", COLUMN_TEXT, + "weight", COLUMN_TEXT_WEIGHT, + "editable", + COLUMN_TEXT_EDITABLE, NULL); + gtk_tree_view_column_set_expand (eprop_sources->filename_column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), + eprop_sources->filename_column); + + g_object_set_data (G_OBJECT (eprop_sources->filename_column), "column-id", + GINT_TO_POINTER (COLUMN_TEXT)); + + /********************* Size *********************/ + /* Attribute active portion */ + renderer = gtk_cell_renderer_toggle_new (); + g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); + g_object_set_data (G_OBJECT (renderer), "attribute-column", + GINT_TO_POINTER (COLUMN_SIZE_ACTIVE)); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (value_attribute_toggled), eprop); + + column = gtk_tree_view_column_new_with_attributes + ("dummy", renderer, + "visible", COLUMN_TEXT_EDITABLE, "active", COLUMN_SIZE_ACTIVE, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); + g_object_set_data (G_OBJECT (column), "column-id", + GINT_TO_POINTER (COLUMN_SIZE_ACTIVE)); + + /* Attribute portion */ + renderer = gtk_cell_renderer_combo_new (); + g_object_set (G_OBJECT (renderer), "editable", TRUE, "has-entry", FALSE, + "text-column", 0, "model", size_store, NULL); + g_object_set_data (G_OBJECT (renderer), "attribute-column", + GINT_TO_POINTER (COLUMN_SIZE)); + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_attribute_edited), eprop); + + column = gtk_tree_view_column_new_with_attributes + ("dummy", renderer, + "visible", COLUMN_TEXT_EDITABLE, + "editable", COLUMN_SIZE_ACTIVE, "text", COLUMN_SIZE, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); + g_object_set_data (G_OBJECT (column), "column-id", + GINT_TO_POINTER (COLUMN_SIZE)); + + + /********************* State *********************/ + /* Attribute active portion */ + renderer = gtk_cell_renderer_toggle_new (); + g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); + g_object_set_data (G_OBJECT (renderer), "attribute-column", + GINT_TO_POINTER (COLUMN_STATE_ACTIVE)); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (value_attribute_toggled), eprop); + + column = gtk_tree_view_column_new_with_attributes + ("dummy", renderer, + "visible", COLUMN_TEXT_EDITABLE, "active", COLUMN_STATE_ACTIVE, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); + g_object_set_data (G_OBJECT (column), "column-id", + GINT_TO_POINTER (COLUMN_STATE_ACTIVE)); + + /* Attribute portion */ + renderer = gtk_cell_renderer_combo_new (); + g_object_set (G_OBJECT (renderer), "editable", TRUE, "has-entry", FALSE, + "text-column", 0, "model", state_store, NULL); + g_object_set_data (G_OBJECT (renderer), "attribute-column", + GINT_TO_POINTER (COLUMN_STATE)); + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_attribute_edited), eprop); + + column = gtk_tree_view_column_new_with_attributes + ("dummy", renderer, + "visible", COLUMN_TEXT_EDITABLE, + "editable", COLUMN_STATE_ACTIVE, "text", COLUMN_STATE, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); + g_object_set_data (G_OBJECT (column), "column-id", + GINT_TO_POINTER (COLUMN_STATE)); + + + /********************* Direction *********************/ + /* Attribute active portion */ + renderer = gtk_cell_renderer_toggle_new (); + g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); + g_object_set_data (G_OBJECT (renderer), "attribute-column", + GINT_TO_POINTER (COLUMN_DIRECTION_ACTIVE)); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (value_attribute_toggled), eprop); + + column = gtk_tree_view_column_new_with_attributes + ("dummy", renderer, + "visible", COLUMN_TEXT_EDITABLE, + "active", COLUMN_DIRECTION_ACTIVE, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); + g_object_set_data (G_OBJECT (column), "column-id", + GINT_TO_POINTER (COLUMN_DIRECTION_ACTIVE)); + + /* Attribute portion */ + renderer = gtk_cell_renderer_combo_new (); + g_object_set (G_OBJECT (renderer), "editable", TRUE, "has-entry", FALSE, + "text-column", 0, "model", direction_store, NULL); + g_object_set_data (G_OBJECT (renderer), "attribute-column", + GINT_TO_POINTER (COLUMN_DIRECTION)); + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_attribute_edited), eprop); + + column = gtk_tree_view_column_new_with_attributes + ("dummy", renderer, + "visible", COLUMN_TEXT_EDITABLE, + "editable", COLUMN_DIRECTION_ACTIVE, "text", COLUMN_DIRECTION, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); + g_object_set_data (G_OBJECT (column), "column-id", + GINT_TO_POINTER (COLUMN_DIRECTION)); + + + /* Connect ::query-tooltip here for fancy tooltips... */ + g_object_set (G_OBJECT (view), "has-tooltip", TRUE, NULL); + g_signal_connect (G_OBJECT (view), "query-tooltip", + G_CALLBACK (icon_sources_query_tooltip), eprop); + + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE); + gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view), FALSE); + + return view; } static void -icon_name_entry_activated (GtkEntry *entry, - GladeEPropIconSources *eprop_sources) +icon_name_entry_activated (GtkEntry * entry, + GladeEPropIconSources * eprop_sources) { - GtkTreeIter iter; - const gchar *text = gtk_entry_get_text (entry); + GtkTreeIter iter; + const gchar *text = gtk_entry_get_text (entry); - if (!text || !text[0]) - return; + if (!text || !text[0]) + return; - gtk_list_store_append (eprop_sources->icon_names_store, &iter); - gtk_list_store_set (eprop_sources->icon_names_store, &iter, - 0, text, -1); - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (eprop_sources->combo), &iter); + gtk_list_store_append (eprop_sources->icon_names_store, &iter); + gtk_list_store_set (eprop_sources->icon_names_store, &iter, 0, text, -1); + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (eprop_sources->combo), &iter); } static GtkWidget * -glade_eprop_icon_sources_create_input (GladeEditorProperty *eprop) +glade_eprop_icon_sources_create_input (GladeEditorProperty * eprop) { - GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); - GtkWidget *vbox, *hbox, *button, *swin; - - vbox = gtk_vbox_new (FALSE, 2); - hbox = gtk_hbox_new (FALSE, 4); - - /* hbox with comboboxentry add/remove source buttons on the right... */ - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - eprop_sources->icon_names_store = gtk_list_store_new (1, G_TYPE_STRING); - eprop_sources->combo = gtk_combo_box_new_with_entry (); - gtk_combo_box_set_model (GTK_COMBO_BOX (eprop_sources->combo), - GTK_TREE_MODEL (eprop_sources->icon_names_store)); - g_signal_connect (G_OBJECT (gtk_bin_get_child (GTK_BIN (eprop_sources->combo))), "activate", - G_CALLBACK (icon_name_entry_activated), eprop); - - gtk_box_pack_start (GTK_BOX (hbox), eprop_sources->combo, TRUE, TRUE, 0); - button = gtk_button_new (); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_ADD, - GTK_ICON_SIZE_BUTTON)); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (add_clicked), - eprop_sources); - - button = gtk_button_new (); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON)); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (delete_clicked), - eprop_sources); - - /* Pack treeview/swindow on the left... */ - swin = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), GTK_SHADOW_IN); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0); - - eprop_sources->view = build_view (eprop); - gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_sources->view)); - - g_object_set (G_OBJECT (vbox), "height-request", 350, NULL); - - eprop_sources->store = gtk_tree_store_new (NUM_COLUMNS, - G_TYPE_STRING, // COLUMN_TEXT - G_TYPE_INT, // COLUMN_TEXT_WEIGHT - G_TYPE_BOOLEAN, // COLUMN_TEXT_EDITABLE - G_TYPE_STRING, // COLUMN_ICON_NAME - G_TYPE_INT, // COLUMN_LIST_INDEX - G_TYPE_BOOLEAN, // COLUMN_DIRECTION_ACTIVE - G_TYPE_STRING, // COLUMN_DIRECTION - G_TYPE_BOOLEAN, // COLUMN_SIZE_ACTIVE - G_TYPE_STRING, // COLUMN_SIZE - G_TYPE_BOOLEAN, // COLUMN_STATE_ACTIVE, - G_TYPE_STRING); // COLUMN_STATE - - gtk_tree_view_set_model (eprop_sources->view, GTK_TREE_MODEL (eprop_sources->store)); - g_object_unref (G_OBJECT (eprop_sources->store)); // <-- pass ownership here - - gtk_widget_show_all (vbox); - return vbox; + GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); + GtkWidget *vbox, *hbox, *button, *swin; + + vbox = gtk_vbox_new (FALSE, 2); + hbox = gtk_hbox_new (FALSE, 4); + + /* hbox with comboboxentry add/remove source buttons on the right... */ + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + + eprop_sources->icon_names_store = gtk_list_store_new (1, G_TYPE_STRING); + eprop_sources->combo = gtk_combo_box_new_with_entry (); + gtk_combo_box_set_model (GTK_COMBO_BOX (eprop_sources->combo), + GTK_TREE_MODEL (eprop_sources->icon_names_store)); + g_signal_connect (G_OBJECT + (gtk_bin_get_child (GTK_BIN (eprop_sources->combo))), + "activate", G_CALLBACK (icon_name_entry_activated), eprop); + + gtk_box_pack_start (GTK_BOX (hbox), eprop_sources->combo, TRUE, TRUE, 0); + button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_ADD, + GTK_ICON_SIZE_BUTTON)); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (add_clicked), eprop_sources); + + button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_REMOVE, + GTK_ICON_SIZE_BUTTON)); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (delete_clicked), eprop_sources); + + /* Pack treeview/swindow on the left... */ + swin = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), + GTK_SHADOW_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0); + + eprop_sources->view = build_view (eprop); + gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_sources->view)); + + g_object_set (G_OBJECT (vbox), "height-request", 350, NULL); + + eprop_sources->store = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING, // COLUMN_TEXT + G_TYPE_INT, // COLUMN_TEXT_WEIGHT + G_TYPE_BOOLEAN, // COLUMN_TEXT_EDITABLE + G_TYPE_STRING, // COLUMN_ICON_NAME + G_TYPE_INT, // COLUMN_LIST_INDEX + G_TYPE_BOOLEAN, // COLUMN_DIRECTION_ACTIVE + G_TYPE_STRING, // COLUMN_DIRECTION + G_TYPE_BOOLEAN, // COLUMN_SIZE_ACTIVE + G_TYPE_STRING, // COLUMN_SIZE + G_TYPE_BOOLEAN, // COLUMN_STATE_ACTIVE, + G_TYPE_STRING); // COLUMN_STATE + + gtk_tree_view_set_model (eprop_sources->view, + GTK_TREE_MODEL (eprop_sources->store)); + g_object_unref (G_OBJECT (eprop_sources->store)); // <-- pass ownership here + + gtk_widget_show_all (vbox); + return vbox; } diff --git a/plugins/gtk+/glade-icon-sources.h b/plugins/gtk+/glade-icon-sources.h index b671293c..5d05f594 100644 --- a/plugins/gtk+/glade-icon-sources.h +++ b/plugins/gtk+/glade-icon-sources.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-image-editor.c b/plugins/gtk+/glade-image-editor.c index c3f4450d..6123ab1d 100644 --- a/plugins/gtk+/glade-image-editor.c +++ b/plugins/gtk+/glade-image-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,11 +27,11 @@ #include "glade-image-editor.h" -static void glade_image_editor_finalize (GObject *object); +static void glade_image_editor_finalize (GObject * object); -static void glade_image_editor_editable_init (GladeEditableIface *iface); +static void glade_image_editor_editable_init (GladeEditableIface * iface); -static void glade_image_editor_grab_focus (GtkWidget *widget); +static void glade_image_editor_grab_focus (GtkWidget * widget); G_DEFINE_TYPE_WITH_CODE (GladeImageEditor, glade_image_editor, GTK_TYPE_VBOX, @@ -41,392 +40,415 @@ G_DEFINE_TYPE_WITH_CODE (GladeImageEditor, glade_image_editor, GTK_TYPE_VBOX, static void -glade_image_editor_class_init (GladeImageEditorClass *klass) +glade_image_editor_class_init (GladeImageEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_image_editor_finalize; - widget_class->grab_focus = glade_image_editor_grab_focus; + object_class->finalize = glade_image_editor_finalize; + widget_class->grab_focus = glade_image_editor_grab_focus; } static void -glade_image_editor_init (GladeImageEditor *self) +glade_image_editor_init (GladeImageEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeImageEditor *image_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeImageEditor * image_editor) { - if (image_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (image_editor))) - return; + if (image_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (image_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (image_editor), image_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (image_editor), + image_editor->loaded_widget); } static void -project_finalized (GladeImageEditor *image_editor, - GladeProject *where_project_was) +project_finalized (GladeImageEditor * image_editor, + GladeProject * where_project_was) { - image_editor->loaded_widget = NULL; + image_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (image_editor), NULL); + glade_editable_load (GLADE_EDITABLE (image_editor), NULL); } static void -glade_image_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_image_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (editable); - GladeImageEditMode image_mode = 0; - GList *l; - - image_editor->loading = TRUE; - - /* Since we watch the project*/ - if (image_editor->loaded_widget) - { - /* watch custom-child and use-stock properties here for reloads !!! */ - - g_signal_handlers_disconnect_by_func (G_OBJECT (image_editor->loaded_widget->project), - G_CALLBACK (project_changed), image_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (image_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - image_editor); - } - - /* Mark our widget... */ - image_editor->loaded_widget = widget; - - if (image_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (image_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), image_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (image_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - image_editor); - } - - /* load the embedded editable... */ - if (image_editor->embed) - glade_editable_load (GLADE_EDITABLE (image_editor->embed), widget); - - for (l = image_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - if (widget) - { - glade_widget_property_get (widget, "image-mode", &image_mode); - - switch (image_mode) - { - case GLADE_IMAGE_MODE_STOCK: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (image_editor->stock_radio), TRUE); - break; - case GLADE_IMAGE_MODE_ICON: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (image_editor->icon_radio), TRUE); - break; - case GLADE_IMAGE_MODE_FILENAME: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (image_editor->file_radio), TRUE); - break; - default: - break; - } - } - image_editor->loading = FALSE; + GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (editable); + GladeImageEditMode image_mode = 0; + GList *l; + + image_editor->loading = TRUE; + + /* Since we watch the project */ + if (image_editor->loaded_widget) + { + /* watch custom-child and use-stock properties here for reloads !!! */ + + g_signal_handlers_disconnect_by_func (G_OBJECT + (image_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + image_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (image_editor->loaded_widget->project), + (GWeakNotify) project_finalized, image_editor); + } + + /* Mark our widget... */ + image_editor->loaded_widget = widget; + + if (image_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (image_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), image_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (image_editor->loaded_widget->project), + (GWeakNotify) project_finalized, image_editor); + } + + /* load the embedded editable... */ + if (image_editor->embed) + glade_editable_load (GLADE_EDITABLE (image_editor->embed), widget); + + for (l = image_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + if (widget) + { + glade_widget_property_get (widget, "image-mode", &image_mode); + + switch (image_mode) + { + case GLADE_IMAGE_MODE_STOCK: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (image_editor->stock_radio), TRUE); + break; + case GLADE_IMAGE_MODE_ICON: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (image_editor->icon_radio), TRUE); + break; + case GLADE_IMAGE_MODE_FILENAME: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (image_editor->file_radio), TRUE); + break; + default: + break; + } + } + image_editor->loading = FALSE; } static void -glade_image_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_image_editor_set_show_name (GladeEditable * editable, gboolean show_name) { - GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (editable); + GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (image_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (image_editor->embed), + show_name); } static void -glade_image_editor_editable_init (GladeEditableIface *iface) +glade_image_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_image_editor_load; - iface->set_show_name = glade_image_editor_set_show_name; + iface->load = glade_image_editor_load; + iface->set_show_name = glade_image_editor_set_show_name; } static void -glade_image_editor_finalize (GObject *object) +glade_image_editor_finalize (GObject * object) { - GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (object); + GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (object); - if (image_editor->properties) - g_list_free (image_editor->properties); - image_editor->properties = NULL; - image_editor->embed = NULL; + if (image_editor->properties) + g_list_free (image_editor->properties); + image_editor->properties = NULL; + image_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_image_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_image_editor_parent_class)->finalize (object); } static void -glade_image_editor_grab_focus (GtkWidget *widget) +glade_image_editor_grab_focus (GtkWidget * widget) { - GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (widget); + GladeImageEditor *image_editor = GLADE_IMAGE_EDITOR (widget); - gtk_widget_grab_focus (image_editor->embed); + gtk_widget_grab_focus (image_editor->embed); } static void -table_attach (GtkWidget *table, - GtkWidget *child, - gint pos, gint row) +table_attach (GtkWidget * table, GtkWidget * child, gint pos, gint row) { - gtk_grid_attach (GTK_GRID (table), child, - pos, row, 1, 1); + gtk_grid_attach (GTK_GRID (table), child, pos, row, 1, 1); - if (pos) - gtk_widget_set_hexpand (child, TRUE); + if (pos) + gtk_widget_set_hexpand (child, TRUE); } static void -set_stock_mode (GladeImageEditor *image_editor) +set_stock_mode (GladeImageEditor * image_editor) { - GladeProperty *property; - GValue value = { 0, }; - - property = glade_widget_get_property (image_editor->loaded_widget, "icon-name"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (image_editor->loaded_widget, "pixbuf"); - glade_command_set_property (property, NULL); - - property = glade_widget_get_property (image_editor->loaded_widget, "stock"); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - - property = glade_widget_get_property (image_editor->loaded_widget, "image-mode"); - glade_command_set_property (property, GLADE_IMAGE_MODE_STOCK); + GladeProperty *property; + GValue value = { 0, }; + + property = + glade_widget_get_property (image_editor->loaded_widget, "icon-name"); + glade_command_set_property (property, NULL); + property = glade_widget_get_property (image_editor->loaded_widget, "pixbuf"); + glade_command_set_property (property, NULL); + + property = glade_widget_get_property (image_editor->loaded_widget, "stock"); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + + property = + glade_widget_get_property (image_editor->loaded_widget, "image-mode"); + glade_command_set_property (property, GLADE_IMAGE_MODE_STOCK); } static void -set_icon_mode (GladeImageEditor *image_editor) +set_icon_mode (GladeImageEditor * image_editor) { - GladeProperty *property; - - property = glade_widget_get_property (image_editor->loaded_widget, "stock"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (image_editor->loaded_widget, "pixbuf"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (image_editor->loaded_widget, "image-mode"); - glade_command_set_property (property, GLADE_IMAGE_MODE_ICON); + GladeProperty *property; + + property = glade_widget_get_property (image_editor->loaded_widget, "stock"); + glade_command_set_property (property, NULL); + property = glade_widget_get_property (image_editor->loaded_widget, "pixbuf"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (image_editor->loaded_widget, "image-mode"); + glade_command_set_property (property, GLADE_IMAGE_MODE_ICON); } static void -set_file_mode (GladeImageEditor *image_editor) +set_file_mode (GladeImageEditor * image_editor) { - GladeProperty *property; - - property = glade_widget_get_property (image_editor->loaded_widget, "stock"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (image_editor->loaded_widget, "icon-name"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (image_editor->loaded_widget, "image-mode"); - glade_command_set_property (property, GLADE_IMAGE_MODE_FILENAME); + GladeProperty *property; + + property = glade_widget_get_property (image_editor->loaded_widget, "stock"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (image_editor->loaded_widget, "icon-name"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (image_editor->loaded_widget, "image-mode"); + glade_command_set_property (property, GLADE_IMAGE_MODE_FILENAME); } static void -stock_toggled (GtkWidget *widget, - GladeImageEditor *image_editor) +stock_toggled (GtkWidget * widget, GladeImageEditor * image_editor) { - if (image_editor->loading || !image_editor->loaded_widget) - return; + if (image_editor->loading || !image_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (image_editor->stock_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (image_editor->stock_radio))) + return; - image_editor->modifying = TRUE; + image_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an image from stock"), image_editor->loaded_widget->name); - set_stock_mode (image_editor); - glade_command_pop_group (); + glade_command_push_group (_("Setting %s to use an image from stock"), + image_editor->loaded_widget->name); + set_stock_mode (image_editor); + glade_command_pop_group (); - image_editor->modifying = FALSE; + image_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (image_editor), - image_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (image_editor), + image_editor->loaded_widget); } static void -icon_toggled (GtkWidget *widget, - GladeImageEditor *image_editor) +icon_toggled (GtkWidget * widget, GladeImageEditor * image_editor) { - if (image_editor->loading || !image_editor->loaded_widget) - return; + if (image_editor->loading || !image_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (image_editor->icon_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (image_editor->icon_radio))) + return; - image_editor->modifying = TRUE; + image_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an image from the icon theme"), image_editor->loaded_widget->name); - set_icon_mode (image_editor); - glade_command_pop_group (); + glade_command_push_group (_("Setting %s to use an image from the icon theme"), + image_editor->loaded_widget->name); + set_icon_mode (image_editor); + glade_command_pop_group (); - image_editor->modifying = FALSE; + image_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (image_editor), - image_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (image_editor), + image_editor->loaded_widget); } static void -file_toggled (GtkWidget *widget, - GladeImageEditor *image_editor) +file_toggled (GtkWidget * widget, GladeImageEditor * image_editor) { - if (image_editor->loading || !image_editor->loaded_widget) - return; + if (image_editor->loading || !image_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (image_editor->file_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (image_editor->file_radio))) + return; - image_editor->modifying = TRUE; + image_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an image from filename"), image_editor->loaded_widget->name); - set_file_mode (image_editor); - glade_command_pop_group (); + glade_command_push_group (_("Setting %s to use an image from filename"), + image_editor->loaded_widget->name); + set_file_mode (image_editor); + glade_command_pop_group (); - image_editor->modifying = FALSE; + image_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (image_editor), - image_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (image_editor), + image_editor->loaded_widget); } GtkWidget * -glade_image_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_image_editor_new (GladeWidgetAdaptor * adaptor, GladeEditable * embed) { - GladeImageEditor *image_editor; - GladeEditorProperty *eprop; - GtkWidget *table, *frame, *alignment, *label, *hbox; - gchar *str; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - image_editor = g_object_new (GLADE_TYPE_IMAGE_EDITOR, NULL); - image_editor->embed = GTK_WIDGET (embed); - - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (image_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - /* Image content frame... */ - str = g_strdup_printf ("<b>%s</b>", _("Edit Image")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (image_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Stock image... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "stock", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - image_editor->stock_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), image_editor->stock_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - image_editor->properties = g_list_prepend (image_editor->properties, eprop); - - /* Icon theme image... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-name", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - image_editor->icon_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (image_editor->stock_radio)); - gtk_box_pack_start (GTK_BOX (hbox), image_editor->icon_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - image_editor->properties = g_list_prepend (image_editor->properties, eprop); - - /* Filename... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "pixbuf", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - image_editor->file_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (image_editor->stock_radio)); - gtk_box_pack_start (GTK_BOX (hbox), image_editor->file_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 2); - table_attach (table, GTK_WIDGET (eprop), 1, 2); - image_editor->properties = g_list_prepend (image_editor->properties, eprop); - - /* Image size frame... */ - str = g_strdup_printf ("<b>%s</b>", _("Set Image Size")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (image_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Icon Size... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-size", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - image_editor->properties = g_list_prepend (image_editor->properties, eprop); - - /* Pixel Size... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "pixel-size", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - image_editor->properties = g_list_prepend (image_editor->properties, eprop); - - /* Connect radio button signals... */ - g_signal_connect (G_OBJECT (image_editor->stock_radio), "toggled", - G_CALLBACK (stock_toggled), image_editor); - g_signal_connect (G_OBJECT (image_editor->icon_radio), "toggled", - G_CALLBACK (icon_toggled), image_editor); - g_signal_connect (G_OBJECT (image_editor->file_radio), "toggled", - G_CALLBACK (file_toggled), image_editor); - - gtk_widget_show_all (GTK_WIDGET (image_editor)); - - return GTK_WIDGET (image_editor); + GladeImageEditor *image_editor; + GladeEditorProperty *eprop; + GtkWidget *table, *frame, *alignment, *label, *hbox; + gchar *str; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + image_editor = g_object_new (GLADE_TYPE_IMAGE_EDITOR, NULL); + image_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (image_editor), GTK_WIDGET (embed), FALSE, FALSE, + 0); + + /* Image content frame... */ + str = g_strdup_printf ("<b>%s</b>", _("Edit Image")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (image_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Stock image... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "stock", FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + image_editor->stock_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), image_editor->stock_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + image_editor->properties = g_list_prepend (image_editor->properties, eprop); + + /* Icon theme image... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-name", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + image_editor->icon_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (image_editor->stock_radio)); + gtk_box_pack_start (GTK_BOX (hbox), image_editor->icon_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + image_editor->properties = g_list_prepend (image_editor->properties, eprop); + + /* Filename... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "pixbuf", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + image_editor->file_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (image_editor->stock_radio)); + gtk_box_pack_start (GTK_BOX (hbox), image_editor->file_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 2); + table_attach (table, GTK_WIDGET (eprop), 1, 2); + image_editor->properties = g_list_prepend (image_editor->properties, eprop); + + /* Image size frame... */ + str = g_strdup_printf ("<b>%s</b>", _("Set Image Size")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (image_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Icon Size... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-size", FALSE, + TRUE); + table_attach (table, eprop->item_label, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + image_editor->properties = g_list_prepend (image_editor->properties, eprop); + + /* Pixel Size... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "pixel-size", FALSE, + TRUE); + table_attach (table, eprop->item_label, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + image_editor->properties = g_list_prepend (image_editor->properties, eprop); + + /* Connect radio button signals... */ + g_signal_connect (G_OBJECT (image_editor->stock_radio), "toggled", + G_CALLBACK (stock_toggled), image_editor); + g_signal_connect (G_OBJECT (image_editor->icon_radio), "toggled", + G_CALLBACK (icon_toggled), image_editor); + g_signal_connect (G_OBJECT (image_editor->file_radio), "toggled", + G_CALLBACK (file_toggled), image_editor); + + gtk_widget_show_all (GTK_WIDGET (image_editor)); + + return GTK_WIDGET (image_editor); } diff --git a/plugins/gtk+/glade-image-editor.h b/plugins/gtk+/glade-image-editor.h index 11b655f1..e589cf24 100644 --- a/plugins/gtk+/glade-image-editor.h +++ b/plugins/gtk+/glade-image-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-image-item-editor.c b/plugins/gtk+/glade-image-item-editor.c index 531437fb..abbdb53b 100644 --- a/plugins/gtk+/glade-image-item-editor.c +++ b/plugins/gtk+/glade-image-item-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,408 +27,428 @@ #include "glade-image-item-editor.h" -static void glade_image_item_editor_finalize (GObject *object); +static void glade_image_item_editor_finalize (GObject * object); -static void glade_image_item_editor_editable_init (GladeEditableIface *iface); +static void glade_image_item_editor_editable_init (GladeEditableIface * iface); -static void glade_image_item_editor_grab_focus (GtkWidget *widget); +static void glade_image_item_editor_grab_focus (GtkWidget * widget); -G_DEFINE_TYPE_WITH_CODE (GladeImageItemEditor, glade_image_item_editor, GTK_TYPE_VBOX, +G_DEFINE_TYPE_WITH_CODE (GladeImageItemEditor, glade_image_item_editor, + GTK_TYPE_VBOX, G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_image_item_editor_editable_init)); static void -glade_image_item_editor_class_init (GladeImageItemEditorClass *klass) +glade_image_item_editor_class_init (GladeImageItemEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_image_item_editor_finalize; - widget_class->grab_focus = glade_image_item_editor_grab_focus; + object_class->finalize = glade_image_item_editor_finalize; + widget_class->grab_focus = glade_image_item_editor_grab_focus; } static void -glade_image_item_editor_init (GladeImageItemEditor *self) +glade_image_item_editor_init (GladeImageItemEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeImageItemEditor *item_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeImageItemEditor * item_editor) { - if (item_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (item_editor))) - return; + if (item_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (item_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (item_editor), item_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (item_editor), + item_editor->loaded_widget); } static void -project_finalized (GladeImageItemEditor *item_editor, - GladeProject *where_project_was) +project_finalized (GladeImageItemEditor * item_editor, + GladeProject * where_project_was) { - item_editor->loaded_widget = NULL; + item_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (item_editor), NULL); + glade_editable_load (GLADE_EDITABLE (item_editor), NULL); } static GladeWidget * -get_image_widget (GladeWidget *widget) +get_image_widget (GladeWidget * widget) { - GtkWidget *image; - image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget->object)); - return image ? glade_widget_get_from_gobject (image) : NULL; + GtkWidget *image; + image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget->object)); + return image ? glade_widget_get_from_gobject (image) : NULL; } static void -glade_image_item_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_image_item_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (editable); - GladeWidget *image_widget; - GList *l; - gboolean use_stock = FALSE; - - item_editor->loading = TRUE; - - /* Since we watch the project*/ - if (item_editor->loaded_widget) - { - g_signal_handlers_disconnect_by_func (G_OBJECT (item_editor->loaded_widget->project), - G_CALLBACK (project_changed), item_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (item_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - item_editor); - } - - /* Mark our widget... */ - item_editor->loaded_widget = widget; - - if (item_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (item_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), item_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (item_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - item_editor); - } - - /* load the embedded editable... */ - if (item_editor->embed) - glade_editable_load (GLADE_EDITABLE (item_editor->embed), widget); - - if (item_editor->embed_image) - { - /* Finalize safe code here... */ - if (widget && (image_widget = get_image_widget (widget))) - glade_editable_load (GLADE_EDITABLE (item_editor->embed_image), image_widget); - else - glade_editable_load (GLADE_EDITABLE (item_editor->embed_image), NULL); - } - for (l = item_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - if (widget) - { - glade_widget_property_get (widget, "use-stock", &use_stock); - - gtk_widget_set_sensitive (item_editor->embed_frame, !use_stock); - gtk_widget_set_sensitive (item_editor->label_frame, !use_stock); - - if (use_stock) - gtk_toggle_button_set_active - (GTK_TOGGLE_BUTTON (item_editor->stock_radio), TRUE); - else - gtk_toggle_button_set_active - (GTK_TOGGLE_BUTTON (item_editor->custom_radio), TRUE); - } - item_editor->loading = FALSE; + GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (editable); + GladeWidget *image_widget; + GList *l; + gboolean use_stock = FALSE; + + item_editor->loading = TRUE; + + /* Since we watch the project */ + if (item_editor->loaded_widget) + { + g_signal_handlers_disconnect_by_func (G_OBJECT + (item_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + item_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (item_editor->loaded_widget->project), + (GWeakNotify) project_finalized, item_editor); + } + + /* Mark our widget... */ + item_editor->loaded_widget = widget; + + if (item_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (item_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), item_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (item_editor->loaded_widget->project), + (GWeakNotify) project_finalized, item_editor); + } + + /* load the embedded editable... */ + if (item_editor->embed) + glade_editable_load (GLADE_EDITABLE (item_editor->embed), widget); + + if (item_editor->embed_image) + { + /* Finalize safe code here... */ + if (widget && (image_widget = get_image_widget (widget))) + glade_editable_load (GLADE_EDITABLE (item_editor->embed_image), + image_widget); + else + glade_editable_load (GLADE_EDITABLE (item_editor->embed_image), NULL); + } + for (l = item_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + if (widget) + { + glade_widget_property_get (widget, "use-stock", &use_stock); + + gtk_widget_set_sensitive (item_editor->embed_frame, !use_stock); + gtk_widget_set_sensitive (item_editor->label_frame, !use_stock); + + if (use_stock) + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (item_editor->stock_radio), TRUE); + else + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (item_editor->custom_radio), TRUE); + } + item_editor->loading = FALSE; } static void -glade_image_item_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_image_item_editor_set_show_name (GladeEditable * editable, + gboolean show_name) { - GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (editable); + GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (item_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (item_editor->embed), show_name); } static void -glade_image_item_editor_editable_init (GladeEditableIface *iface) +glade_image_item_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_image_item_editor_load; - iface->set_show_name = glade_image_item_editor_set_show_name; + iface->load = glade_image_item_editor_load; + iface->set_show_name = glade_image_item_editor_set_show_name; } static void -glade_image_item_editor_finalize (GObject *object) +glade_image_item_editor_finalize (GObject * object) { - GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (object); + GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (object); - if (item_editor->properties) - g_list_free (item_editor->properties); - item_editor->properties = NULL; - item_editor->embed_image = NULL; - item_editor->embed = NULL; + if (item_editor->properties) + g_list_free (item_editor->properties); + item_editor->properties = NULL; + item_editor->embed_image = NULL; + item_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_image_item_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_image_item_editor_parent_class)->finalize (object); } static void -glade_image_item_editor_grab_focus (GtkWidget *widget) +glade_image_item_editor_grab_focus (GtkWidget * widget) { - GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (widget); + GladeImageItemEditor *item_editor = GLADE_IMAGE_ITEM_EDITOR (widget); - gtk_widget_grab_focus (item_editor->embed); + gtk_widget_grab_focus (item_editor->embed); } static void -stock_toggled (GtkWidget *widget, - GladeImageItemEditor *item_editor) +stock_toggled (GtkWidget * widget, GladeImageItemEditor * item_editor) { - GladeProperty *property; - GladeWidget *image, *loaded; + GladeProperty *property; + GladeWidget *image, *loaded; - if (item_editor->loading || !item_editor->loaded_widget) - return; + if (item_editor->loading || !item_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (item_editor->stock_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (item_editor->stock_radio))) + return; - item_editor->modifying = TRUE; - loaded = item_editor->loaded_widget; + item_editor->modifying = TRUE; + loaded = item_editor->loaded_widget; - glade_command_push_group (_("Setting %s to use a stock item"), loaded->name); + glade_command_push_group (_("Setting %s to use a stock item"), loaded->name); - property = glade_widget_get_property (loaded, "label"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (loaded, "use-underline"); - glade_command_set_property (property, FALSE); + property = glade_widget_get_property (loaded, "label"); + glade_command_set_property (property, NULL); + property = glade_widget_get_property (loaded, "use-underline"); + glade_command_set_property (property, FALSE); - /* Delete image... */ - if ((image = get_image_widget (loaded)) != NULL) - { - GList list = { 0, }; - list.data = image; - glade_command_unlock_widget (image); - glade_command_delete (&list); - glade_project_selection_set (loaded->project, loaded->object, TRUE); - } + /* Delete image... */ + if ((image = get_image_widget (loaded)) != NULL) + { + GList list = { 0, }; + list.data = image; + glade_command_unlock_widget (image); + glade_command_delete (&list); + glade_project_selection_set (loaded->project, loaded->object, TRUE); + } - property = glade_widget_get_property (loaded, "use-stock"); - glade_command_set_property (property, TRUE); + property = glade_widget_get_property (loaded, "use-stock"); + glade_command_set_property (property, TRUE); - glade_command_pop_group (); + glade_command_pop_group (); - item_editor->modifying = FALSE; + item_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (item_editor), item_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (item_editor), + item_editor->loaded_widget); } static void -custom_toggled (GtkWidget *widget, - GladeImageItemEditor *item_editor) +custom_toggled (GtkWidget * widget, GladeImageItemEditor * item_editor) { - GladeProperty *property; + GladeProperty *property; - if (item_editor->loading || !item_editor->loaded_widget) - return; + if (item_editor->loading || !item_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (item_editor->custom_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (item_editor->custom_radio))) + return; - item_editor->modifying = TRUE; + item_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a label and image"), item_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a label and image"), + item_editor->loaded_widget->name); - /* First clear stock... */ - property = glade_widget_get_property (item_editor->loaded_widget, "stock"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (item_editor->loaded_widget, "use-stock"); - glade_command_set_property (property, FALSE); + /* First clear stock... */ + property = glade_widget_get_property (item_editor->loaded_widget, "stock"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (item_editor->loaded_widget, "use-stock"); + glade_command_set_property (property, FALSE); - /* Now setup default label and create image... */ - property = glade_widget_get_property (item_editor->loaded_widget, "label"); - glade_command_set_property (property, item_editor->loaded_widget->adaptor->generic_name); - property = glade_widget_get_property (item_editor->loaded_widget, "use-underline"); - glade_command_set_property (property, FALSE); + /* Now setup default label and create image... */ + property = glade_widget_get_property (item_editor->loaded_widget, "label"); + glade_command_set_property (property, + item_editor->loaded_widget->adaptor-> + generic_name); + property = + glade_widget_get_property (item_editor->loaded_widget, "use-underline"); + glade_command_set_property (property, FALSE); - /* There shouldnt be an image widget here... */ - if (!get_image_widget (item_editor->loaded_widget)) - { - /* item_editor->loaded_widget may be set to NULL after the create_command. */ - GladeWidget *loaded = item_editor->loaded_widget; - GladeWidget *image; + /* There shouldnt be an image widget here... */ + if (!get_image_widget (item_editor->loaded_widget)) + { + /* item_editor->loaded_widget may be set to NULL after the create_command. */ + GladeWidget *loaded = item_editor->loaded_widget; + GladeWidget *image; - property = glade_widget_get_property (loaded, "image"); + property = glade_widget_get_property (loaded, "image"); - image = glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_IMAGE), - NULL, NULL, glade_widget_get_project (loaded)); + image = + glade_command_create (glade_widget_adaptor_get_by_type + (GTK_TYPE_IMAGE), NULL, NULL, + glade_widget_get_project (loaded)); - glade_command_set_property (property, image->object); + glade_command_set_property (property, image->object); - /* Make sure nobody deletes this... */ - glade_command_lock_widget (loaded, image); + /* Make sure nobody deletes this... */ + glade_command_lock_widget (loaded, image); - /* reload widget by selection ;-) */ - glade_project_selection_set (loaded->project, loaded->object, TRUE); - } - glade_command_pop_group (); + /* reload widget by selection ;-) */ + glade_project_selection_set (loaded->project, loaded->object, TRUE); + } + glade_command_pop_group (); - item_editor->modifying = FALSE; + item_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (item_editor), - item_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (item_editor), + item_editor->loaded_widget); } static void -table_attach (GtkWidget *table, - GtkWidget *child, - gint pos, gint row) +table_attach (GtkWidget * table, GtkWidget * child, gint pos, gint row) { - gtk_grid_attach (GTK_GRID (table), child, - pos, row, 1, 1); + gtk_grid_attach (GTK_GRID (table), child, pos, row, 1, 1); - if (pos) - gtk_widget_set_hexpand (child, TRUE); + if (pos) + gtk_widget_set_hexpand (child, TRUE); } GtkWidget * -glade_image_item_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_image_item_editor_new (GladeWidgetAdaptor * adaptor, + GladeEditable * embed) { - GladeImageItemEditor *item_editor; - GladeEditorProperty *eprop; - GtkWidget *label, *alignment, *frame, *main_table, *table, *vbox; - gchar *str; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - item_editor = g_object_new (GLADE_TYPE_IMAGE_ITEM_EDITOR, NULL); - item_editor->embed = GTK_WIDGET (embed); - - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (item_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - /* Put a radio button to control use-stock here on top... */ - main_table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (main_table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (main_table), 4); - gtk_box_pack_start (GTK_BOX (item_editor), main_table, FALSE, FALSE, 8); - - item_editor->stock_radio = gtk_radio_button_new_with_label (NULL, _("Stock Item:")); - table_attach (main_table, item_editor->stock_radio, 0, 0); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_grid_attach (GTK_GRID (main_table), alignment, 0, 1, 2, 1); - gtk_widget_set_hexpand (alignment, TRUE); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* The stock item */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "stock", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - item_editor->properties = g_list_prepend (item_editor->properties, eprop); - - /* An accel group for the item's accelerator */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "accel-group", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - item_editor->properties = g_list_prepend (item_editor->properties, eprop); - - /* Now put a radio button in the same table for the custom image editing */ - item_editor->custom_radio = gtk_radio_button_new_with_label_from_widget - (GTK_RADIO_BUTTON (item_editor->stock_radio), - _("Custom label and image:")); - table_attach (main_table, item_editor->custom_radio, 0, 2); - vbox = gtk_vbox_new (FALSE, 0); - gtk_grid_attach (GTK_GRID (main_table), vbox, 0, 3, 2, 1); - gtk_widget_set_hexpand (vbox, TRUE); - - /* Label area frame... */ - str = g_strdup_printf ("<b>%s</b>", _("Edit Label")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 12); - item_editor->label_frame = frame; - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* The menu label... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - item_editor->properties = g_list_prepend (item_editor->properties, eprop); - - /* Whether to use-underline... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "use-underline", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - item_editor->properties = g_list_prepend (item_editor->properties, eprop); - - /* Internal Image area... */ - str = g_strdup_printf ("<b>%s</b>", _("Edit Image")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 12); - item_editor->embed_frame = frame; - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - item_editor->embed_image = (GtkWidget *)glade_widget_adaptor_create_editable - (glade_widget_adaptor_get_by_type (GTK_TYPE_IMAGE), GLADE_PAGE_GENERAL); - glade_editable_set_show_name (GLADE_EDITABLE (item_editor->embed_image), FALSE); - gtk_container_add (GTK_CONTAINER (alignment), item_editor->embed_image); - - /* Now hook up to our signals... */ - g_signal_connect (G_OBJECT (item_editor->stock_radio), "toggled", - G_CALLBACK (stock_toggled), item_editor); - g_signal_connect (G_OBJECT (item_editor->custom_radio), "toggled", - G_CALLBACK (custom_toggled), item_editor); - - - gtk_widget_show_all (GTK_WIDGET (item_editor)); - - return GTK_WIDGET (item_editor); + GladeImageItemEditor *item_editor; + GladeEditorProperty *eprop; + GtkWidget *label, *alignment, *frame, *main_table, *table, *vbox; + gchar *str; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + item_editor = g_object_new (GLADE_TYPE_IMAGE_ITEM_EDITOR, NULL); + item_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (item_editor), GTK_WIDGET (embed), FALSE, FALSE, + 0); + + /* Put a radio button to control use-stock here on top... */ + main_table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (main_table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (main_table), 4); + gtk_box_pack_start (GTK_BOX (item_editor), main_table, FALSE, FALSE, 8); + + item_editor->stock_radio = + gtk_radio_button_new_with_label (NULL, _("Stock Item:")); + table_attach (main_table, item_editor->stock_radio, 0, 0); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_grid_attach (GTK_GRID (main_table), alignment, 0, 1, 2, 1); + gtk_widget_set_hexpand (alignment, TRUE); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* The stock item */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "stock", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + item_editor->properties = g_list_prepend (item_editor->properties, eprop); + + /* An accel group for the item's accelerator */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "accel-group", FALSE, + TRUE); + table_attach (table, eprop->item_label, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + item_editor->properties = g_list_prepend (item_editor->properties, eprop); + + /* Now put a radio button in the same table for the custom image editing */ + item_editor->custom_radio = gtk_radio_button_new_with_label_from_widget + (GTK_RADIO_BUTTON (item_editor->stock_radio), + _("Custom label and image:")); + table_attach (main_table, item_editor->custom_radio, 0, 2); + vbox = gtk_vbox_new (FALSE, 0); + gtk_grid_attach (GTK_GRID (main_table), vbox, 0, 3, 2, 1); + gtk_widget_set_hexpand (vbox, TRUE); + + /* Label area frame... */ + str = g_strdup_printf ("<b>%s</b>", _("Edit Label")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 12); + item_editor->label_frame = frame; + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* The menu label... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + item_editor->properties = g_list_prepend (item_editor->properties, eprop); + + /* Whether to use-underline... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "use-underline", + FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + item_editor->properties = g_list_prepend (item_editor->properties, eprop); + + /* Internal Image area... */ + str = g_strdup_printf ("<b>%s</b>", _("Edit Image")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 12); + item_editor->embed_frame = frame; + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + item_editor->embed_image = (GtkWidget *) glade_widget_adaptor_create_editable + (glade_widget_adaptor_get_by_type (GTK_TYPE_IMAGE), GLADE_PAGE_GENERAL); + glade_editable_set_show_name (GLADE_EDITABLE (item_editor->embed_image), + FALSE); + gtk_container_add (GTK_CONTAINER (alignment), item_editor->embed_image); + + /* Now hook up to our signals... */ + g_signal_connect (G_OBJECT (item_editor->stock_radio), "toggled", + G_CALLBACK (stock_toggled), item_editor); + g_signal_connect (G_OBJECT (item_editor->custom_radio), "toggled", + G_CALLBACK (custom_toggled), item_editor); + + + gtk_widget_show_all (GTK_WIDGET (item_editor)); + + return GTK_WIDGET (item_editor); } diff --git a/plugins/gtk+/glade-image-item-editor.h b/plugins/gtk+/glade-image-item-editor.h index 9ec84fe7..bcef41d7 100644 --- a/plugins/gtk+/glade-image-item-editor.h +++ b/plugins/gtk+/glade-image-item-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-label-editor.c b/plugins/gtk+/glade-label-editor.c index 0fb9f124..56f05546 100644 --- a/plugins/gtk+/glade-label-editor.c +++ b/plugins/gtk+/glade-label-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,11 +27,11 @@ #include "glade-label-editor.h" -static void glade_label_editor_finalize (GObject *object); +static void glade_label_editor_finalize (GObject * object); -static void glade_label_editor_editable_init (GladeEditableIface *iface); +static void glade_label_editor_editable_init (GladeEditableIface * iface); -static void glade_label_editor_grab_focus (GtkWidget *widget); +static void glade_label_editor_grab_focus (GtkWidget * widget); G_DEFINE_TYPE_WITH_CODE (GladeLabelEditor, glade_label_editor, GTK_TYPE_VBOX, @@ -41,189 +40,203 @@ G_DEFINE_TYPE_WITH_CODE (GladeLabelEditor, glade_label_editor, GTK_TYPE_VBOX, static void -glade_label_editor_class_init (GladeLabelEditorClass *klass) +glade_label_editor_class_init (GladeLabelEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_label_editor_finalize; - widget_class->grab_focus = glade_label_editor_grab_focus; + object_class->finalize = glade_label_editor_finalize; + widget_class->grab_focus = glade_label_editor_grab_focus; } static void -glade_label_editor_init (GladeLabelEditor *self) +glade_label_editor_init (GladeLabelEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeLabelEditor *label_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeLabelEditor * label_editor) { - if (label_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (label_editor))) - return; + if (label_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (label_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (label_editor), label_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } static void -project_finalized (GladeLabelEditor *label_editor, - GladeProject *where_project_was) +project_finalized (GladeLabelEditor * label_editor, + GladeProject * where_project_was) { - label_editor->loaded_widget = NULL; + label_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (label_editor), NULL); + glade_editable_load (GLADE_EDITABLE (label_editor), NULL); } static void -glade_label_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_label_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (editable); - GList *l; - - label_editor->loading = TRUE; - - /* Since we watch the project*/ - if (label_editor->loaded_widget) - { - /* watch custom-child and use-stock properties here for reloads !!! */ - - g_signal_handlers_disconnect_by_func (G_OBJECT (label_editor->loaded_widget->project), - G_CALLBACK (project_changed), label_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (label_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - label_editor); - } - - /* Mark our widget... */ - label_editor->loaded_widget = widget; - - if (label_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (label_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), label_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (label_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - label_editor); - } - - /* load the embedded editable... */ - if (label_editor->embed) - glade_editable_load (GLADE_EDITABLE (label_editor->embed), widget); - - for (l = label_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - if (widget) - { - GladeLabelContentMode content_mode; - GladeLabelWrapMode wrap_mode; - static PangoAttrList *bold_attr_list = NULL; - gboolean use_max_width; - - if (!bold_attr_list) - { - PangoAttribute *attr; - bold_attr_list = pango_attr_list_new (); - attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); - pango_attr_list_insert (bold_attr_list, attr); - } - - glade_widget_property_get (widget, "label-content-mode", &content_mode); - glade_widget_property_get (widget, "label-wrap-mode", &wrap_mode); - glade_widget_property_get (widget, "use-max-width", &use_max_width); - - switch (content_mode) - { - case GLADE_LABEL_MODE_ATTRIBUTES: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->attributes_radio), TRUE); - break; - case GLADE_LABEL_MODE_MARKUP: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->markup_radio), TRUE); - break; - case GLADE_LABEL_MODE_PATTERN: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->pattern_radio), TRUE); - break; - default: - break; - } - - if (wrap_mode == GLADE_LABEL_WRAP_FREE) - gtk_label_set_attributes (GTK_LABEL (label_editor->wrap_free_label), bold_attr_list); - else - gtk_label_set_attributes (GTK_LABEL (label_editor->wrap_free_label), NULL); - - switch (wrap_mode) - { - case GLADE_LABEL_WRAP_FREE: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->wrap_free_radio), TRUE); - break; - case GLADE_LABEL_SINGLE_LINE: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->single_radio), TRUE); - break; - case GLADE_LABEL_WRAP_MODE: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->wrap_mode_radio), TRUE); - break; - default: - break; - } - - if (use_max_width) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->max_width_radio), TRUE); - else - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label_editor->width_radio), TRUE); - - } - label_editor->loading = FALSE; + GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (editable); + GList *l; + + label_editor->loading = TRUE; + + /* Since we watch the project */ + if (label_editor->loaded_widget) + { + /* watch custom-child and use-stock properties here for reloads !!! */ + + g_signal_handlers_disconnect_by_func (G_OBJECT + (label_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + label_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (label_editor->loaded_widget->project), + (GWeakNotify) project_finalized, label_editor); + } + + /* Mark our widget... */ + label_editor->loaded_widget = widget; + + if (label_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (label_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), label_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (label_editor->loaded_widget->project), + (GWeakNotify) project_finalized, label_editor); + } + + /* load the embedded editable... */ + if (label_editor->embed) + glade_editable_load (GLADE_EDITABLE (label_editor->embed), widget); + + for (l = label_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + if (widget) + { + GladeLabelContentMode content_mode; + GladeLabelWrapMode wrap_mode; + static PangoAttrList *bold_attr_list = NULL; + gboolean use_max_width; + + if (!bold_attr_list) + { + PangoAttribute *attr; + bold_attr_list = pango_attr_list_new (); + attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); + pango_attr_list_insert (bold_attr_list, attr); + } + + glade_widget_property_get (widget, "label-content-mode", &content_mode); + glade_widget_property_get (widget, "label-wrap-mode", &wrap_mode); + glade_widget_property_get (widget, "use-max-width", &use_max_width); + + switch (content_mode) + { + case GLADE_LABEL_MODE_ATTRIBUTES: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->attributes_radio), + TRUE); + break; + case GLADE_LABEL_MODE_MARKUP: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->markup_radio), TRUE); + break; + case GLADE_LABEL_MODE_PATTERN: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->pattern_radio), TRUE); + break; + default: + break; + } + + if (wrap_mode == GLADE_LABEL_WRAP_FREE) + gtk_label_set_attributes (GTK_LABEL (label_editor->wrap_free_label), + bold_attr_list); + else + gtk_label_set_attributes (GTK_LABEL (label_editor->wrap_free_label), + NULL); + + switch (wrap_mode) + { + case GLADE_LABEL_WRAP_FREE: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->wrap_free_radio), + TRUE); + break; + case GLADE_LABEL_SINGLE_LINE: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->single_radio), TRUE); + break; + case GLADE_LABEL_WRAP_MODE: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->wrap_mode_radio), + TRUE); + break; + default: + break; + } + + if (use_max_width) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->max_width_radio), TRUE); + else + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (label_editor->width_radio), TRUE); + + } + label_editor->loading = FALSE; } static void -glade_label_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_label_editor_set_show_name (GladeEditable * editable, gboolean show_name) { - GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (editable); + GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (label_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (label_editor->embed), + show_name); } static void -glade_label_editor_editable_init (GladeEditableIface *iface) +glade_label_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_label_editor_load; - iface->set_show_name = glade_label_editor_set_show_name; + iface->load = glade_label_editor_load; + iface->set_show_name = glade_label_editor_set_show_name; } static void -glade_label_editor_finalize (GObject *object) +glade_label_editor_finalize (GObject * object) { - GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (object); + GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (object); - if (label_editor->properties) - g_list_free (label_editor->properties); - label_editor->properties = NULL; - label_editor->embed = NULL; + if (label_editor->properties) + g_list_free (label_editor->properties); + label_editor->properties = NULL; + label_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_label_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_label_editor_parent_class)->finalize (object); } static void -glade_label_editor_grab_focus (GtkWidget *widget) +glade_label_editor_grab_focus (GtkWidget * widget) { - GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (widget); + GladeLabelEditor *label_editor = GLADE_LABEL_EDITOR (widget); - gtk_widget_grab_focus (label_editor->embed); + gtk_widget_grab_focus (label_editor->embed); } @@ -231,102 +244,118 @@ glade_label_editor_grab_focus (GtkWidget *widget) label-content-mode radios **********************************************************************/ static void -attributes_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +attributes_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->attributes_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->attributes_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an attribute list"), label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use an attribute list"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "use-markup"); - glade_command_set_property (property, FALSE); - property = glade_widget_get_property (label_editor->loaded_widget, "pattern"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (label_editor->loaded_widget, "label-content-mode"); - glade_command_set_property (property, GLADE_LABEL_MODE_ATTRIBUTES); + property = + glade_widget_get_property (label_editor->loaded_widget, "use-markup"); + glade_command_set_property (property, FALSE); + property = glade_widget_get_property (label_editor->loaded_widget, "pattern"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (label_editor->loaded_widget, + "label-content-mode"); + glade_command_set_property (property, GLADE_LABEL_MODE_ATTRIBUTES); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } static void -markup_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +markup_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->markup_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->markup_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a Pango markup string"), label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a Pango markup string"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "pattern"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (label_editor->loaded_widget, "glade-attributes"); - glade_command_set_property (property, NULL); + property = glade_widget_get_property (label_editor->loaded_widget, "pattern"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (label_editor->loaded_widget, + "glade-attributes"); + glade_command_set_property (property, NULL); - property = glade_widget_get_property (label_editor->loaded_widget, "use-markup"); - glade_command_set_property (property, TRUE); - property = glade_widget_get_property (label_editor->loaded_widget, "label-content-mode"); - glade_command_set_property (property, GLADE_LABEL_MODE_MARKUP); + property = + glade_widget_get_property (label_editor->loaded_widget, "use-markup"); + glade_command_set_property (property, TRUE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "label-content-mode"); + glade_command_set_property (property, GLADE_LABEL_MODE_MARKUP); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } static void -pattern_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +pattern_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->pattern_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->pattern_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a pattern string"), label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a pattern string"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "glade-attributes"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (label_editor->loaded_widget, "use-markup"); - glade_command_set_property (property, FALSE); - property = glade_widget_get_property (label_editor->loaded_widget, "label-content-mode"); - glade_command_set_property (property, GLADE_LABEL_MODE_PATTERN); + property = + glade_widget_get_property (label_editor->loaded_widget, + "glade-attributes"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (label_editor->loaded_widget, "use-markup"); + glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "label-content-mode"); + glade_command_set_property (property, GLADE_LABEL_MODE_PATTERN); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } /********************************************************************** @@ -334,429 +363,483 @@ pattern_toggled (GtkWidget *widget, **********************************************************************/ static void -width_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +width_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->width_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->width_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to set desired width in characters"), - label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to set desired width in characters"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "max-width-chars"); - glade_command_set_property (property, -1); - property = glade_widget_get_property (label_editor->loaded_widget, "use-max-width"); - glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "max-width-chars"); + glade_command_set_property (property, -1); + property = + glade_widget_get_property (label_editor->loaded_widget, "use-max-width"); + glade_command_set_property (property, FALSE); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } static void -max_width_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +max_width_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->max_width_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->max_width_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to set maximum width in characters"), - label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to set maximum width in characters"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "width-chars"); - glade_command_set_property (property, -1); - property = glade_widget_get_property (label_editor->loaded_widget, "use-max-width"); - glade_command_set_property (property, TRUE); + property = + glade_widget_get_property (label_editor->loaded_widget, "width-chars"); + glade_command_set_property (property, -1); + property = + glade_widget_get_property (label_editor->loaded_widget, "use-max-width"); + glade_command_set_property (property, TRUE); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } /********************************************************************** label-wrap-mode radios **********************************************************************/ static void -wrap_free_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +wrap_free_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->wrap_free_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->wrap_free_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use normal line wrapping"), label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use normal line wrapping"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "single-line-mode"); - glade_command_set_property (property, FALSE); - property = glade_widget_get_property (label_editor->loaded_widget, "wrap-mode"); - glade_command_set_property (property, PANGO_WRAP_WORD); - property = glade_widget_get_property (label_editor->loaded_widget, "wrap"); - glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "single-line-mode"); + glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (label_editor->loaded_widget, "wrap-mode"); + glade_command_set_property (property, PANGO_WRAP_WORD); + property = glade_widget_get_property (label_editor->loaded_widget, "wrap"); + glade_command_set_property (property, FALSE); - property = glade_widget_get_property (label_editor->loaded_widget, "label-wrap-mode"); - glade_command_set_property (property, GLADE_LABEL_WRAP_FREE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "label-wrap-mode"); + glade_command_set_property (property, GLADE_LABEL_WRAP_FREE); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } static void -single_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +single_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->single_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->single_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a single line"), label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a single line"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "wrap-mode"); - glade_command_set_property (property, PANGO_WRAP_WORD); - property = glade_widget_get_property (label_editor->loaded_widget, "wrap"); - glade_command_set_property (property, FALSE); + property = + glade_widget_get_property (label_editor->loaded_widget, "wrap-mode"); + glade_command_set_property (property, PANGO_WRAP_WORD); + property = glade_widget_get_property (label_editor->loaded_widget, "wrap"); + glade_command_set_property (property, FALSE); - property = glade_widget_get_property (label_editor->loaded_widget, "single-line-mode"); - glade_command_set_property (property, TRUE); - property = glade_widget_get_property (label_editor->loaded_widget, "label-wrap-mode"); - glade_command_set_property (property, GLADE_LABEL_SINGLE_LINE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "single-line-mode"); + glade_command_set_property (property, TRUE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "label-wrap-mode"); + glade_command_set_property (property, GLADE_LABEL_SINGLE_LINE); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } static void -wrap_mode_toggled (GtkWidget *widget, - GladeLabelEditor *label_editor) +wrap_mode_toggled (GtkWidget * widget, GladeLabelEditor * label_editor) { - GladeProperty *property; + GladeProperty *property; - if (label_editor->loading || !label_editor->loaded_widget) - return; + if (label_editor->loading || !label_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (label_editor->wrap_mode_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (label_editor->wrap_mode_radio))) + return; - label_editor->modifying = TRUE; + label_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use specific Pango word wrapping"), - label_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use specific Pango word wrapping"), + label_editor->loaded_widget->name); - property = glade_widget_get_property (label_editor->loaded_widget, "single-line-mode"); - glade_command_set_property (property, FALSE); - property = glade_widget_get_property (label_editor->loaded_widget, "wrap"); - glade_command_set_property (property, TRUE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "single-line-mode"); + glade_command_set_property (property, FALSE); + property = glade_widget_get_property (label_editor->loaded_widget, "wrap"); + glade_command_set_property (property, TRUE); - property = glade_widget_get_property (label_editor->loaded_widget, "label-wrap-mode"); - glade_command_set_property (property, GLADE_LABEL_WRAP_MODE); + property = + glade_widget_get_property (label_editor->loaded_widget, + "label-wrap-mode"); + glade_command_set_property (property, GLADE_LABEL_WRAP_MODE); - glade_command_pop_group (); + glade_command_pop_group (); - label_editor->modifying = FALSE; + label_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (label_editor), - label_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (label_editor), + label_editor->loaded_widget); } static void -table_attach (GtkWidget *table, - GtkWidget *child, - gint pos, gint row) +table_attach (GtkWidget * table, GtkWidget * child, gint pos, gint row) { - gtk_grid_attach (GTK_GRID (table), child, - pos, row, 1, 1); + gtk_grid_attach (GTK_GRID (table), child, pos, row, 1, 1); - if (pos) - gtk_widget_set_hexpand (child, TRUE); + if (pos) + gtk_widget_set_hexpand (child, TRUE); } static void -append_label_appearance (GladeLabelEditor *label_editor, - GladeWidgetAdaptor *adaptor) +append_label_appearance (GladeLabelEditor * label_editor, + GladeWidgetAdaptor * adaptor) { - GladeEditorProperty *eprop, *markup_property; - GtkWidget *table, *frame, *alignment, *label, *hbox; - gchar *str; - - /* Label appearance... */ - str = g_strdup_printf ("<b>%s</b>", _("Edit label appearance")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (label_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Edit the label itself... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* Edit by attributes... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "glade-attributes", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - label_editor->attributes_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->attributes_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* Edit with label as pango markup strings... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "use-markup", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - label_editor->markup_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (label_editor->attributes_radio)); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->markup_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 2); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - markup_property = eprop; /* Its getting into a hidden row on the bottom... */ - - /* Add underscores from pattern string... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "pattern", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - label_editor->pattern_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (label_editor->attributes_radio)); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->pattern_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 3); - table_attach (table, GTK_WIDGET (eprop), 1, 3); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* Tie the invisible editor property to the table's life-cycle */ - g_object_set_data_full (G_OBJECT (table), "glade-markup-property-destroy-me", - markup_property, (GDestroyNotify)gtk_widget_destroy); + GladeEditorProperty *eprop, *markup_property; + GtkWidget *table, *frame, *alignment, *label, *hbox; + gchar *str; + + /* Label appearance... */ + str = g_strdup_printf ("<b>%s</b>", _("Edit label appearance")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (label_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Edit the label itself... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* Edit by attributes... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "glade-attributes", + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + label_editor->attributes_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->attributes_radio, FALSE, + FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* Edit with label as pango markup strings... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "use-markup", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + label_editor->markup_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (label_editor->attributes_radio)); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->markup_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 2); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + markup_property = eprop; /* Its getting into a hidden row on the bottom... */ + + /* Add underscores from pattern string... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "pattern", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + label_editor->pattern_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (label_editor->attributes_radio)); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->pattern_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 3); + table_attach (table, GTK_WIDGET (eprop), 1, 3); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* Tie the invisible editor property to the table's life-cycle */ + g_object_set_data_full (G_OBJECT (table), "glade-markup-property-destroy-me", + markup_property, (GDestroyNotify) gtk_widget_destroy); } static void -append_label_formatting (GladeLabelEditor *label_editor, - GladeWidgetAdaptor *adaptor) +append_label_formatting (GladeLabelEditor * label_editor, + GladeWidgetAdaptor * adaptor) { - GladeEditorProperty *eprop; - GtkWidget *table, *frame, *alignment, *label, *hbox; - gchar *str; - gint row = 0; - - /* Label formatting... */ - str = g_strdup_printf ("<b>%s</b>", _("Format label")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (label_editor), frame, FALSE, FALSE, 0); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* ellipsize... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "ellipsize", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* justify... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "justify", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* angle... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "angle", FALSE, TRUE); - table_attach (table, eprop->item_label, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* width-chars ... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "width-chars", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - label_editor->width_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->width_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* max-width-chars ... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "max-width-chars", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - label_editor->max_width_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (label_editor->width_radio)); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->max_width_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); + GladeEditorProperty *eprop; + GtkWidget *table, *frame, *alignment, *label, *hbox; + gchar *str; + gint row = 0; + + /* Label formatting... */ + str = g_strdup_printf ("<b>%s</b>", _("Format label")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (label_editor), frame, FALSE, FALSE, 0); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* ellipsize... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "ellipsize", FALSE, + TRUE); + table_attach (table, eprop->item_label, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* justify... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "justify", FALSE, + TRUE); + table_attach (table, eprop->item_label, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* angle... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "angle", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* width-chars ... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "width-chars", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + label_editor->width_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->width_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* max-width-chars ... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "max-width-chars", + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + label_editor->max_width_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (label_editor->width_radio)); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->max_width_radio, FALSE, + FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); } static void -append_label_wrapping (GladeLabelEditor *label_editor, - GladeWidgetAdaptor *adaptor) +append_label_wrapping (GladeLabelEditor * label_editor, + GladeWidgetAdaptor * adaptor) { - GladeEditorProperty *eprop, *single_line_eprop; - GtkWidget *table, *frame, *alignment, *label, *hbox; - gchar *str; - gint row = 0; - - /* Line Wrapping... */ - str = g_strdup_printf ("<b>%s</b>", _("Text line wrapping")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (label_editor), frame, FALSE, FALSE, 0); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Append defaut epropless radio... */ - hbox = gtk_hbox_new (FALSE, 0); - label_editor->wrap_free_radio = gtk_radio_button_new (NULL); - label_editor->wrap_free_label = gtk_label_new (_("Text wraps normally")); - gtk_misc_set_alignment (GTK_MISC (label_editor->wrap_free_label), 0.0F, 0.5F); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->wrap_free_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->wrap_free_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, row++); - - /* single-line-mode ... */ - single_line_eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "single-line-mode", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - label_editor->single_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (label_editor->wrap_free_radio)); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->single_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), single_line_eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, row++); - label_editor->properties = g_list_prepend (label_editor->properties, single_line_eprop); - - /* wrap-mode ... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "wrap-mode", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - label_editor->wrap_mode_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (label_editor->wrap_free_radio)); - gtk_box_pack_start (GTK_BOX (hbox), label_editor->wrap_mode_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, row); - table_attach (table, GTK_WIDGET (eprop), 1, row++); - label_editor->properties = g_list_prepend (label_editor->properties, eprop); - - /* Tie the invisible editor property to the table's life-cycle */ - g_object_set_data_full (G_OBJECT (table), "glade-single-line-property-destroy-me", - single_line_eprop, (GDestroyNotify)gtk_widget_destroy); + GladeEditorProperty *eprop, *single_line_eprop; + GtkWidget *table, *frame, *alignment, *label, *hbox; + gchar *str; + gint row = 0; + + /* Line Wrapping... */ + str = g_strdup_printf ("<b>%s</b>", _("Text line wrapping")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (label_editor), frame, FALSE, FALSE, 0); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Append defaut epropless radio... */ + hbox = gtk_hbox_new (FALSE, 0); + label_editor->wrap_free_radio = gtk_radio_button_new (NULL); + label_editor->wrap_free_label = gtk_label_new (_("Text wraps normally")); + gtk_misc_set_alignment (GTK_MISC (label_editor->wrap_free_label), 0.0F, 0.5F); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->wrap_free_radio, FALSE, + FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->wrap_free_label, TRUE, TRUE, + 2); + table_attach (table, hbox, 0, row++); + + /* single-line-mode ... */ + single_line_eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "single-line-mode", + FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + label_editor->single_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (label_editor->wrap_free_radio)); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->single_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), single_line_eprop->item_label, TRUE, TRUE, + 2); + table_attach (table, hbox, 0, row++); + label_editor->properties = + g_list_prepend (label_editor->properties, single_line_eprop); + + /* wrap-mode ... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "wrap-mode", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + label_editor->wrap_mode_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (label_editor->wrap_free_radio)); + gtk_box_pack_start (GTK_BOX (hbox), label_editor->wrap_mode_radio, FALSE, + FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, row); + table_attach (table, GTK_WIDGET (eprop), 1, row++); + label_editor->properties = g_list_prepend (label_editor->properties, eprop); + + /* Tie the invisible editor property to the table's life-cycle */ + g_object_set_data_full (G_OBJECT (table), + "glade-single-line-property-destroy-me", + single_line_eprop, + (GDestroyNotify) gtk_widget_destroy); } GtkWidget * -glade_label_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_label_editor_new (GladeWidgetAdaptor * adaptor, GladeEditable * embed) { - GladeLabelEditor *label_editor; + GladeLabelEditor *label_editor; - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - label_editor = g_object_new (GLADE_TYPE_LABEL_EDITOR, NULL); - label_editor->embed = GTK_WIDGET (embed); + label_editor = g_object_new (GLADE_TYPE_LABEL_EDITOR, NULL); + label_editor->embed = GTK_WIDGET (embed); - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (label_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (label_editor), GTK_WIDGET (embed), FALSE, FALSE, + 0); - append_label_appearance (label_editor, adaptor); - append_label_formatting (label_editor, adaptor); - append_label_wrapping (label_editor, adaptor); + append_label_appearance (label_editor, adaptor); + append_label_formatting (label_editor, adaptor); + append_label_wrapping (label_editor, adaptor); - /* Connect to our radio buttons.... */ - g_signal_connect (G_OBJECT (label_editor->attributes_radio), "toggled", - G_CALLBACK (attributes_toggled), label_editor); - g_signal_connect (G_OBJECT (label_editor->markup_radio), "toggled", - G_CALLBACK (markup_toggled), label_editor); - g_signal_connect (G_OBJECT (label_editor->pattern_radio), "toggled", - G_CALLBACK (pattern_toggled), label_editor); + /* Connect to our radio buttons.... */ + g_signal_connect (G_OBJECT (label_editor->attributes_radio), "toggled", + G_CALLBACK (attributes_toggled), label_editor); + g_signal_connect (G_OBJECT (label_editor->markup_radio), "toggled", + G_CALLBACK (markup_toggled), label_editor); + g_signal_connect (G_OBJECT (label_editor->pattern_radio), "toggled", + G_CALLBACK (pattern_toggled), label_editor); - g_signal_connect (G_OBJECT (label_editor->width_radio), "toggled", - G_CALLBACK (width_toggled), label_editor); - g_signal_connect (G_OBJECT (label_editor->max_width_radio), "toggled", - G_CALLBACK (max_width_toggled), label_editor); + g_signal_connect (G_OBJECT (label_editor->width_radio), "toggled", + G_CALLBACK (width_toggled), label_editor); + g_signal_connect (G_OBJECT (label_editor->max_width_radio), "toggled", + G_CALLBACK (max_width_toggled), label_editor); - g_signal_connect (G_OBJECT (label_editor->wrap_free_radio), "toggled", - G_CALLBACK (wrap_free_toggled), label_editor); - g_signal_connect (G_OBJECT (label_editor->single_radio), "toggled", - G_CALLBACK (single_toggled), label_editor); - g_signal_connect (G_OBJECT (label_editor->wrap_mode_radio), "toggled", - G_CALLBACK (wrap_mode_toggled), label_editor); + g_signal_connect (G_OBJECT (label_editor->wrap_free_radio), "toggled", + G_CALLBACK (wrap_free_toggled), label_editor); + g_signal_connect (G_OBJECT (label_editor->single_radio), "toggled", + G_CALLBACK (single_toggled), label_editor); + g_signal_connect (G_OBJECT (label_editor->wrap_mode_radio), "toggled", + G_CALLBACK (wrap_mode_toggled), label_editor); - gtk_widget_show_all (GTK_WIDGET (label_editor)); + gtk_widget_show_all (GTK_WIDGET (label_editor)); - return GTK_WIDGET (label_editor); + return GTK_WIDGET (label_editor); } diff --git a/plugins/gtk+/glade-label-editor.h b/plugins/gtk+/glade-label-editor.h index ac432b80..e501d345 100644 --- a/plugins/gtk+/glade-label-editor.h +++ b/plugins/gtk+/glade-label-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-model-data.c b/plugins/gtk+/glade-model-data.c index 993c31d5..86a7ed66 100644 --- a/plugins/gtk+/glade-model-data.c +++ b/plugins/gtk+/glade-model-data.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -32,246 +31,241 @@ #include "glade-column-types.h" GladeModelData * -glade_model_data_new (GType type, const gchar *column_name) +glade_model_data_new (GType type, const gchar * column_name) { - GladeModelData *data = g_new0 (GladeModelData, 1); - - if (type != 0) - g_value_init (&data->value, type); + GladeModelData *data = g_new0 (GladeModelData, 1); - if (type == G_TYPE_STRING) - data->i18n_translatable = TRUE; + if (type != 0) + g_value_init (&data->value, type); - data->name = g_strdup (column_name); + if (type == G_TYPE_STRING) + data->i18n_translatable = TRUE; - return data; + data->name = g_strdup (column_name); + + return data; } GladeModelData * -glade_model_data_copy (GladeModelData *data) +glade_model_data_copy (GladeModelData * data) { - if (!data) - return NULL; + if (!data) + return NULL; + + GladeModelData *dup = g_new0 (GladeModelData, 1); - GladeModelData *dup = g_new0 (GladeModelData, 1); - - if (G_VALUE_TYPE (&data->value) != 0) - { - g_value_init (&dup->value, G_VALUE_TYPE (&data->value)); - g_value_copy (&data->value, &dup->value); - } + if (G_VALUE_TYPE (&data->value) != 0) + { + g_value_init (&dup->value, G_VALUE_TYPE (&data->value)); + g_value_copy (&data->value, &dup->value); + } - dup->name = g_strdup (data->name); + dup->name = g_strdup (data->name); - dup->i18n_translatable = data->i18n_translatable; - dup->i18n_context = g_strdup (data->i18n_context); - dup->i18n_comment = g_strdup (data->i18n_comment); + dup->i18n_translatable = data->i18n_translatable; + dup->i18n_context = g_strdup (data->i18n_context); + dup->i18n_comment = g_strdup (data->i18n_comment); - return dup; + return dup; } void -glade_model_data_free (GladeModelData *data) +glade_model_data_free (GladeModelData * data) { - if (data) - { - if (G_VALUE_TYPE (&data->value) != 0) - g_value_unset (&data->value); - - g_free (data->name); - g_free (data->i18n_context); - g_free (data->i18n_comment); - g_free (data); - } + if (data) + { + if (G_VALUE_TYPE (&data->value) != 0) + g_value_unset (&data->value); + + g_free (data->name); + g_free (data->i18n_context); + g_free (data->i18n_comment); + g_free (data); + } } GNode * -glade_model_data_tree_copy (GNode *node) +glade_model_data_tree_copy (GNode * node) { - return g_node_copy_deep (node, (GCopyFunc)glade_model_data_copy, NULL); + return g_node_copy_deep (node, (GCopyFunc) glade_model_data_copy, NULL); } static void -model_data_traverse_free (GNode *node, - gpointer data) +model_data_traverse_free (GNode * node, gpointer data) { - glade_model_data_free ((GladeModelData *)node->data); + glade_model_data_free ((GladeModelData *) node->data); } void -glade_model_data_tree_free (GNode *node) +glade_model_data_tree_free (GNode * node) { - if (node) - { - g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1, - (GNodeTraverseFunc)model_data_traverse_free, NULL); - g_node_destroy (node); - } + if (node) + { + g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1, + (GNodeTraverseFunc) model_data_traverse_free, NULL); + g_node_destroy (node); + } } GladeModelData * -glade_model_data_tree_get_data (GNode *data_tree, gint row, gint colnum) +glade_model_data_tree_get_data (GNode * data_tree, gint row, gint colnum) { - GNode *node; + GNode *node; - g_return_val_if_fail (data_tree != NULL, NULL); + g_return_val_if_fail (data_tree != NULL, NULL); - if ((node = g_node_nth_child (data_tree, row)) != NULL) - if ((node = g_node_nth_child (node, colnum)) != NULL) - return (GladeModelData *)node->data; + if ((node = g_node_nth_child (data_tree, row)) != NULL) + if ((node = g_node_nth_child (node, colnum)) != NULL) + return (GladeModelData *) node->data; - return NULL; + return NULL; } void -glade_model_data_insert_column (GNode *node, - GType type, - const gchar *column_name, - gint nth) +glade_model_data_insert_column (GNode * node, + GType type, const gchar * column_name, gint nth) { - GNode *row, *item; - GladeModelData *data; + GNode *row, *item; + GladeModelData *data; - g_return_if_fail (node != NULL); + g_return_if_fail (node != NULL); - for (row = node->children; row; row = row->next) - { - g_return_if_fail (nth >= 0 && nth <= g_node_n_children (row)); + for (row = node->children; row; row = row->next) + { + g_return_if_fail (nth >= 0 && nth <= g_node_n_children (row)); - data = glade_model_data_new (type, column_name); - item = g_node_new (data); - g_node_insert (row, nth, item); - } + data = glade_model_data_new (type, column_name); + item = g_node_new (data); + g_node_insert (row, nth, item); + } } void -glade_model_data_remove_column (GNode *node, - gint nth) +glade_model_data_remove_column (GNode * node, gint nth) { - GNode *row, *item; - GladeModelData *data; + GNode *row, *item; + GladeModelData *data; - g_return_if_fail (node != NULL); + g_return_if_fail (node != NULL); - for (row = node->children; row; row = row->next) - { - g_return_if_fail (nth >= 0 && nth < g_node_n_children (row)); + for (row = node->children; row; row = row->next) + { + g_return_if_fail (nth >= 0 && nth < g_node_n_children (row)); - item = g_node_nth_child (row, nth); - data = item->data; + item = g_node_nth_child (row, nth); + data = item->data; - glade_model_data_free (data); - g_node_destroy (item); - } + glade_model_data_free (data); + g_node_destroy (item); + } } void -glade_model_data_reorder_column (GNode *node, - gint column, - gint nth) +glade_model_data_reorder_column (GNode * node, gint column, gint nth) { - GNode *row, *item; + GNode *row, *item; - g_return_if_fail (node != NULL); + g_return_if_fail (node != NULL); - for (row = node->children; row; row = row->next) - { - g_return_if_fail (nth >= 0 && nth < g_node_n_children (row)); + for (row = node->children; row; row = row->next) + { + g_return_if_fail (nth >= 0 && nth < g_node_n_children (row)); - item = g_node_nth_child (row, column); + item = g_node_nth_child (row, column); - g_node_unlink (item); - g_node_insert (row, nth, item); - } + g_node_unlink (item); + g_node_insert (row, nth, item); + } } gint -glade_model_data_column_index (GNode *node, - const gchar *column_name) +glade_model_data_column_index (GNode * node, const gchar * column_name) { - gint i; - GNode *item; - GladeModelData *data; - - g_return_val_if_fail (node != NULL, -1); - - for (i = 0, item = node->children->children; item; i++, item = item->next) - { - data = item->data; - if (strcmp (data->name, column_name) == 0) - return i; - } - return -1; + gint i; + GNode *item; + GladeModelData *data; + + g_return_val_if_fail (node != NULL, -1); + + for (i = 0, item = node->children->children; item; i++, item = item->next) + { + data = item->data; + if (strcmp (data->name, column_name) == 0) + return i; + } + return -1; } void -glade_model_data_column_rename (GNode *node, - const gchar *column_name, - const gchar *new_name) +glade_model_data_column_rename (GNode * node, + const gchar * column_name, + const gchar * new_name) { - gint idx; - GNode *row, *iter; - GladeModelData *data; - - g_return_if_fail (node != NULL); - - if ((idx = glade_model_data_column_index (node, column_name)) < 0) - return; - - for (row = node->children; row; row = row->next) - { - iter = g_node_nth_child (row, idx); - data = iter->data; - g_free (data->name); - data->name = g_strdup (new_name); - } + gint idx; + GNode *row, *iter; + GladeModelData *data; + + g_return_if_fail (node != NULL); + + if ((idx = glade_model_data_column_index (node, column_name)) < 0) + return; + + for (row = node->children; row; row = row->next) + { + iter = g_node_nth_child (row, idx); + data = iter->data; + g_free (data->name); + data->name = g_strdup (new_name); + } } GType glade_model_data_tree_get_type (void) { - static GType type_id = 0; - - if (!type_id) - type_id = g_boxed_type_register_static - ("GladeModelDataTree", - (GBoxedCopyFunc) glade_model_data_tree_copy, - (GBoxedFreeFunc) glade_model_data_tree_free); - return type_id; + static GType type_id = 0; + + if (!type_id) + type_id = g_boxed_type_register_static + ("GladeModelDataTree", + (GBoxedCopyFunc) glade_model_data_tree_copy, + (GBoxedFreeFunc) glade_model_data_tree_free); + return type_id; } /**************************** GladeEditorProperty *****************************/ -enum { - COLUMN_ROW = 0, /* row number */ - NUM_COLUMNS +enum +{ + COLUMN_ROW = 0, /* row number */ + NUM_COLUMNS }; -typedef enum { - SEQ_NONE, - SEQ_HORIZONTAL, - SEQ_VERTICAL +typedef enum +{ + SEQ_NONE, + SEQ_HORIZONTAL, + SEQ_VERTICAL } EditSequence; typedef struct { - GladeEditorProperty parent_instance; + GladeEditorProperty parent_instance; - GtkTreeView *view; - GtkListStore *store; - GtkTreeSelection *selection; - GNode *pending_data_tree; + GtkTreeView *view; + GtkListStore *store; + GtkTreeSelection *selection; + GNode *pending_data_tree; - EditSequence sequence; + EditSequence sequence; - /* Used for setting focus on newly added rows */ - gboolean adding_row; - gboolean want_focus; - gboolean want_next_focus; - gboolean setting_focus; - gint editing_row; - gint editing_column; + /* Used for setting focus on newly added rows */ + gboolean adding_row; + gboolean want_focus; + gboolean want_next_focus; + gboolean setting_focus; + gint editing_row; + gint editing_column; - guint next_focus_idle; + guint next_focus_idle; } GladeEPropModelData; GLADE_MAKE_EPROP (GladeEPropModelData, glade_eprop_model_data) @@ -280,996 +274,1002 @@ GLADE_MAKE_EPROP (GladeEPropModelData, glade_eprop_model_data) #define GLADE_IS_EPROP_MODEL_DATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_MODEL_DATA)) #define GLADE_IS_EPROP_MODEL_DATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_MODEL_DATA)) #define GLADE_EPROP_MODEL_DATA_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_MODEL_DATA, GladeEPropModelDataClass)) + static void eprop_data_focus_editing_cell (GladeEPropModelData * + eprop_data); - -static void eprop_data_focus_editing_cell (GladeEPropModelData *eprop_data); - -static void -append_row (GNode *node, GList *columns) + static void append_row (GNode * node, GList * columns) { - GladeModelData *data; - GladeColumnType *column; - GNode *row; - GList *list; - - g_assert (node && columns); - - row = g_node_new (NULL); - g_node_append (node, row); - - for (list = columns; list; list = list->next) - { - column = list->data; - data = glade_model_data_new (g_type_from_name (column->type_name), column->column_name); - g_node_append_data (row, data); - } + GladeModelData *data; + GladeColumnType *column; + GNode *row; + GList *list; + + g_assert (node && columns); + + row = g_node_new (NULL); + g_node_append (node, row); + + for (list = columns; list; list = list->next) + { + column = list->data; + data = + glade_model_data_new (g_type_from_name (column->type_name), + column->column_name); + g_node_append_data (row, data); + } } static void -clear_view (GladeEditorProperty *eprop) +clear_view (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GtkTreeViewColumn *column; - - /* Clear columns ... */ - while ((column = gtk_tree_view_get_column (eprop_data->view, 0)) != NULL) - gtk_tree_view_remove_column (eprop_data->view, column); - - /* Clear store ... (this will unref the old store) */ - gtk_tree_view_set_model (eprop_data->view, NULL); - + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GtkTreeViewColumn *column; + + /* Clear columns ... */ + while ((column = gtk_tree_view_get_column (eprop_data->view, 0)) != NULL) + gtk_tree_view_remove_column (eprop_data->view, column); + + /* Clear store ... (this will unref the old store) */ + gtk_tree_view_set_model (eprop_data->view, NULL); + } static gboolean -update_data_tree_idle (GladeEditorProperty *eprop) +update_data_tree_idle (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GValue value = { 0, }; - - g_value_init (&value, GLADE_TYPE_MODEL_DATA_TREE); - g_value_take_boxed (&value, eprop_data->pending_data_tree); - glade_editor_property_commit (eprop, &value); - g_value_unset (&value); - - eprop_data->pending_data_tree = NULL; - return FALSE; + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GValue value = { 0, }; + + g_value_init (&value, GLADE_TYPE_MODEL_DATA_TREE); + g_value_take_boxed (&value, eprop_data->pending_data_tree); + glade_editor_property_commit (eprop, &value); + g_value_unset (&value); + + eprop_data->pending_data_tree = NULL; + return FALSE; } static gboolean -update_and_focus_data_tree_idle (GladeEditorProperty *eprop) +update_and_focus_data_tree_idle (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - eprop_data->want_focus = TRUE; - eprop_data->want_next_focus = TRUE; - - update_data_tree_idle (eprop); + eprop_data->want_focus = TRUE; + eprop_data->want_next_focus = TRUE; - /* XXX Have to load it regardless if it changed, this is a slow and redundant way... */ - glade_editor_property_load (eprop, eprop->property); + update_data_tree_idle (eprop); - eprop_data->want_next_focus = FALSE; - eprop_data->want_focus = FALSE; + /* XXX Have to load it regardless if it changed, this is a slow and redundant way... */ + glade_editor_property_load (eprop, eprop->property); - return FALSE; + eprop_data->want_next_focus = FALSE; + eprop_data->want_focus = FALSE; + + return FALSE; } static gboolean -focus_next_data_tree_idle (GladeEditorProperty *eprop) +focus_next_data_tree_idle (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + + eprop_data->want_focus = TRUE; + eprop_data->want_next_focus = TRUE; - eprop_data->want_focus = TRUE; - eprop_data->want_next_focus = TRUE; + eprop_data_focus_editing_cell (eprop_data); - eprop_data_focus_editing_cell (eprop_data); + eprop_data->want_next_focus = FALSE; + eprop_data->want_focus = FALSE; - eprop_data->want_next_focus = FALSE; - eprop_data->want_focus = FALSE; + eprop_data->next_focus_idle = 0; - eprop_data->next_focus_idle = 0; - - return FALSE; + return FALSE; } static gboolean -focus_data_tree_idle (GladeEditorProperty *eprop) +focus_data_tree_idle (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - eprop_data->want_focus = TRUE; - eprop_data_focus_editing_cell (eprop_data); - eprop_data->want_focus = FALSE; + eprop_data->want_focus = TRUE; + eprop_data_focus_editing_cell (eprop_data); + eprop_data->want_focus = FALSE; - return FALSE; + return FALSE; } static void -glade_eprop_model_data_add_row (GladeEditorProperty *eprop) +glade_eprop_model_data_add_row (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GValue value = { 0, }; - GNode *node = NULL; - GList *columns = NULL; + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GValue value = { 0, }; + GNode *node = NULL; + GList *columns = NULL; - glade_property_get (eprop->property, &node); - glade_widget_property_get (eprop->property->widget, "columns", &columns); + glade_property_get (eprop->property, &node); + glade_widget_property_get (eprop->property->widget, "columns", &columns); - if (!columns) - return; + if (!columns) + return; - clear_view (eprop); + clear_view (eprop); - if (!node) - node = g_node_new (NULL); - else - node = glade_model_data_tree_copy (node); + if (!node) + node = g_node_new (NULL); + else + node = glade_model_data_tree_copy (node); - append_row (node, columns); + append_row (node, columns); - eprop_data->adding_row = TRUE; + eprop_data->adding_row = TRUE; - g_value_init (&value, GLADE_TYPE_MODEL_DATA_TREE); - g_value_take_boxed (&value, node); - glade_editor_property_commit (eprop, &value); - g_value_unset (&value); + g_value_init (&value, GLADE_TYPE_MODEL_DATA_TREE); + g_value_take_boxed (&value, node); + glade_editor_property_commit (eprop, &value); + g_value_unset (&value); - eprop_data->adding_row = FALSE; + eprop_data->adding_row = FALSE; } static void -glade_eprop_model_data_delete_selected (GladeEditorProperty *eprop) +glade_eprop_model_data_delete_selected (GladeEditorProperty * eprop) { - GtkTreeIter iter; - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GNode *data_tree = NULL, *row; - gint rownum = -1; - - /* NOTE: This will trigger row-deleted below... */ - if (!gtk_tree_selection_get_selected (eprop_data->selection, NULL, &iter)) - return; - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, - COLUMN_ROW, &rownum, - -1); - g_assert (rownum >= 0); - - /* if theres a sected row, theres data... */ - glade_property_get (eprop->property, &data_tree); - g_assert (data_tree); - - data_tree = glade_model_data_tree_copy (data_tree); - row = g_node_nth_child (data_tree, rownum); - - g_node_unlink (row); - glade_model_data_tree_free (row); - - if (eprop_data->pending_data_tree) - glade_model_data_tree_free (eprop_data->pending_data_tree); - - eprop_data->pending_data_tree = data_tree; - g_idle_add ((GSourceFunc)update_data_tree_idle, eprop); + GtkTreeIter iter; + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GNode *data_tree = NULL, *row; + gint rownum = -1; + + /* NOTE: This will trigger row-deleted below... */ + if (!gtk_tree_selection_get_selected (eprop_data->selection, NULL, &iter)) + return; + + gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, + COLUMN_ROW, &rownum, -1); + g_assert (rownum >= 0); + + /* if theres a sected row, theres data... */ + glade_property_get (eprop->property, &data_tree); + g_assert (data_tree); + + data_tree = glade_model_data_tree_copy (data_tree); + row = g_node_nth_child (data_tree, rownum); + + g_node_unlink (row); + glade_model_data_tree_free (row); + + if (eprop_data->pending_data_tree) + glade_model_data_tree_free (eprop_data->pending_data_tree); + + eprop_data->pending_data_tree = data_tree; + g_idle_add ((GSourceFunc) update_data_tree_idle, eprop); } static void -glade_eprop_model_data_add_clicked (GtkWidget *button, - GladeEditorProperty *eprop) +glade_eprop_model_data_add_clicked (GtkWidget * button, + GladeEditorProperty * eprop) { - glade_eprop_model_data_add_row (eprop); + glade_eprop_model_data_add_row (eprop); } static void -glade_eprop_model_data_delete_clicked (GtkWidget *button, - GladeEditorProperty *eprop) +glade_eprop_model_data_delete_clicked (GtkWidget * button, + GladeEditorProperty * eprop) { - glade_eprop_model_data_delete_selected (eprop); + glade_eprop_model_data_delete_selected (eprop); } static void -glade_eprop_model_sequence_changed (GtkWidget *combo, - GladeEditorProperty *eprop) +glade_eprop_model_sequence_changed (GtkWidget * combo, + GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - eprop_data->sequence = gtk_combo_box_get_active (GTK_COMBO_BOX (combo)); + eprop_data->sequence = gtk_combo_box_get_active (GTK_COMBO_BOX (combo)); } static gboolean -eprop_treeview_key_press (GtkWidget *treeview, - GdkEventKey *event, - GladeEditorProperty *eprop) +eprop_treeview_key_press (GtkWidget * treeview, + GdkEventKey * event, GladeEditorProperty * eprop) { - if (event->keyval == GDK_KEY_Delete) - { - glade_eprop_model_data_delete_selected (eprop); - return TRUE; - } - else if ((event->state & GDK_CONTROL_MASK) != 0 && - (event->keyval == GDK_KEY_n || event->keyval == GDK_KEY_N)) - { - glade_eprop_model_data_add_row (eprop); - return TRUE; - } - - return FALSE; -} + if (event->keyval == GDK_KEY_Delete) + { + glade_eprop_model_data_delete_selected (eprop); + return TRUE; + } + else if ((event->state & GDK_CONTROL_MASK) != 0 && + (event->keyval == GDK_KEY_n || event->keyval == GDK_KEY_N)) + { + glade_eprop_model_data_add_row (eprop); + return TRUE; + } + + return FALSE; +} static gboolean -data_changed_idle (GladeEditorProperty *eprop) +data_changed_idle (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GNode *data_tree = NULL, *new_tree, *row; - GtkTreeIter iter; - gint rownum; - - glade_property_get (eprop->property, &data_tree); - g_assert (data_tree); - - new_tree = g_node_new (NULL); - - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_data->store), &iter)) - { - do - { - gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, - COLUMN_ROW, &rownum, -1); - - - if ((row = g_node_nth_child (data_tree, rownum)) != NULL) - { - /* Make a new tree by copying row by row... */ - row = glade_model_data_tree_copy (row); - g_node_append (new_tree, row); - } - } - while (gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_data->store), &iter)); - } - - /* Were already in an idle, no need to idle from here... */ - if (eprop_data->pending_data_tree) - glade_model_data_tree_free (eprop_data->pending_data_tree); - eprop_data->pending_data_tree = new_tree; - update_data_tree_idle (eprop); - - return FALSE; + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GNode *data_tree = NULL, *new_tree, *row; + GtkTreeIter iter; + gint rownum; + + glade_property_get (eprop->property, &data_tree); + g_assert (data_tree); + + new_tree = g_node_new (NULL); + + if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_data->store), &iter)) + { + do + { + gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, + COLUMN_ROW, &rownum, -1); + + + if ((row = g_node_nth_child (data_tree, rownum)) != NULL) + { + /* Make a new tree by copying row by row... */ + row = glade_model_data_tree_copy (row); + g_node_append (new_tree, row); + } + } + while (gtk_tree_model_iter_next + (GTK_TREE_MODEL (eprop_data->store), &iter)); + } + + /* Were already in an idle, no need to idle from here... */ + if (eprop_data->pending_data_tree) + glade_model_data_tree_free (eprop_data->pending_data_tree); + eprop_data->pending_data_tree = new_tree; + update_data_tree_idle (eprop); + + return FALSE; } static void -eprop_treeview_row_deleted (GtkTreeModel *tree_model, - GtkTreePath *path, - GladeEditorProperty *eprop) +eprop_treeview_row_deleted (GtkTreeModel * tree_model, + GtkTreePath * path, GladeEditorProperty * eprop) { - if (eprop->loading) return; + if (eprop->loading) + return; - g_idle_add ((GSourceFunc)data_changed_idle, eprop); + g_idle_add ((GSourceFunc) data_changed_idle, eprop); } static void -glade_eprop_model_data_finalize (GObject *object) +glade_eprop_model_data_finalize (GObject * object) { - /* Chain up */ - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); - //GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (object); + /* Chain up */ + GObjectClass *parent_class = + g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); + //GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (object); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); } static GtkListStore * -eprop_model_data_generate_store (GladeEditorProperty *eprop) +eprop_model_data_generate_store (GladeEditorProperty * eprop) { - GtkListStore *store = NULL; - GladeModelData *iter_data, *row_data; - GNode *data_tree = NULL, *iter_node, *row_node; - GArray *gtypes = g_array_new (FALSE, TRUE, sizeof (GType)); - GtkTreeIter iter; - gint column_num, row_num; - GType index_type = G_TYPE_INT, string_type = G_TYPE_STRING, pointer_type = G_TYPE_POINTER; - - glade_property_get (eprop->property, &data_tree); - - if (!data_tree || !data_tree->children || !data_tree->children->children) - return NULL; - - /* Generate store with tailored column types */ - g_array_append_val (gtypes, index_type); - for (iter_node = data_tree->children->children; iter_node; iter_node = iter_node->next) - { - iter_data = iter_node->data; - if (G_VALUE_TYPE (&iter_data->value) == 0) - g_array_append_val (gtypes, pointer_type); - else if (G_VALUE_TYPE (&iter_data->value) == GDK_TYPE_PIXBUF) - g_array_append_val (gtypes, string_type); - else - g_array_append_val (gtypes, G_VALUE_TYPE (&iter_data->value)); - } - store = gtk_list_store_newv (gtypes->len, (GType *)gtypes->data); - g_array_free (gtypes, TRUE); - - /* Now populate the store with data */ - for (row_num = 0, row_node = data_tree->children; row_node; - row_num++, row_node = row_node->next) - { - row_data = row_node->data; - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, COLUMN_ROW, row_num, -1); - - for (column_num = NUM_COLUMNS, iter_node = row_node->children; iter_node; - column_num++, iter_node = iter_node->next) - { - iter_data = iter_node->data; - - if (G_VALUE_TYPE (&iter_data->value) == 0) - continue; - - /* Special case, show the filename in the cellrenderertext */ - if (G_VALUE_TYPE (&iter_data->value) == GDK_TYPE_PIXBUF) - { - GObject *object = g_value_get_object (&iter_data->value); - gchar *filename = NULL; - if (object) - filename = g_object_get_data (object, "GladeFileName"); - - gtk_list_store_set (store, &iter, - column_num, filename, - -1); - } - else - gtk_list_store_set_value (store, &iter, column_num, &iter_data->value); - } - } - return store; + GtkListStore *store = NULL; + GladeModelData *iter_data, *row_data; + GNode *data_tree = NULL, *iter_node, *row_node; + GArray *gtypes = g_array_new (FALSE, TRUE, sizeof (GType)); + GtkTreeIter iter; + gint column_num, row_num; + GType index_type = G_TYPE_INT, string_type = G_TYPE_STRING, pointer_type = + G_TYPE_POINTER; + + glade_property_get (eprop->property, &data_tree); + + if (!data_tree || !data_tree->children || !data_tree->children->children) + return NULL; + + /* Generate store with tailored column types */ + g_array_append_val (gtypes, index_type); + for (iter_node = data_tree->children->children; iter_node; + iter_node = iter_node->next) + { + iter_data = iter_node->data; + if (G_VALUE_TYPE (&iter_data->value) == 0) + g_array_append_val (gtypes, pointer_type); + else if (G_VALUE_TYPE (&iter_data->value) == GDK_TYPE_PIXBUF) + g_array_append_val (gtypes, string_type); + else + g_array_append_val (gtypes, G_VALUE_TYPE (&iter_data->value)); + } + store = gtk_list_store_newv (gtypes->len, (GType *) gtypes->data); + g_array_free (gtypes, TRUE); + + /* Now populate the store with data */ + for (row_num = 0, row_node = data_tree->children; row_node; + row_num++, row_node = row_node->next) + { + row_data = row_node->data; + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, COLUMN_ROW, row_num, -1); + + for (column_num = NUM_COLUMNS, iter_node = row_node->children; iter_node; + column_num++, iter_node = iter_node->next) + { + iter_data = iter_node->data; + + if (G_VALUE_TYPE (&iter_data->value) == 0) + continue; + + /* Special case, show the filename in the cellrenderertext */ + if (G_VALUE_TYPE (&iter_data->value) == GDK_TYPE_PIXBUF) + { + GObject *object = g_value_get_object (&iter_data->value); + gchar *filename = NULL; + if (object) + filename = g_object_get_data (object, "GladeFileName"); + + gtk_list_store_set (store, &iter, column_num, filename, -1); + } + else + gtk_list_store_set_value (store, &iter, column_num, + &iter_data->value); + } + } + return store; } static void -value_toggled (GtkCellRendererToggle *cell, - gchar *path, - GladeEditorProperty *eprop) +value_toggled (GtkCellRendererToggle * cell, + gchar * path, GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GtkTreeIter iter; - gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); - gint row; - GNode *data_tree = NULL; - GladeModelData *data; - gboolean active; + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GtkTreeIter iter; + gint colnum = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); + gint row; + GNode *data_tree = NULL; + GladeModelData *data; + gboolean active; - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_data->store), &iter, path)) - return; + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_data->store), &iter, path)) + return; - gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, - COLUMN_ROW, &row, - NUM_COLUMNS + colnum, &active, - -1); + gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, + COLUMN_ROW, &row, NUM_COLUMNS + colnum, &active, -1); - glade_property_get (eprop->property, &data_tree); + glade_property_get (eprop->property, &data_tree); - /* if we are editing, then there is data in the datatree */ - g_assert (data_tree); + /* if we are editing, then there is data in the datatree */ + g_assert (data_tree); - data_tree = glade_model_data_tree_copy (data_tree); + data_tree = glade_model_data_tree_copy (data_tree); - data = glade_model_data_tree_get_data (data_tree, row, colnum); + data = glade_model_data_tree_get_data (data_tree, row, colnum); - g_value_set_boolean (&data->value, !active); + g_value_set_boolean (&data->value, !active); - eprop_data->editing_row = row; - eprop_data->editing_column = colnum; - if (eprop_data->pending_data_tree) - glade_model_data_tree_free (eprop_data->pending_data_tree); + eprop_data->editing_row = row; + eprop_data->editing_column = colnum; + if (eprop_data->pending_data_tree) + glade_model_data_tree_free (eprop_data->pending_data_tree); - eprop_data->pending_data_tree = data_tree; - g_idle_add ((GSourceFunc)update_and_focus_data_tree_idle, eprop); + eprop_data->pending_data_tree = data_tree; + g_idle_add ((GSourceFunc) update_and_focus_data_tree_idle, eprop); } static void -value_i18n_activate (GladeCellRendererIcon *cell, - const gchar *path, - GladeEditorProperty *eprop) +value_i18n_activate (GladeCellRendererIcon * cell, + const gchar * path, GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GtkTreeIter iter; - gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); - gint row; - GNode *data_tree = NULL; - GladeModelData *data; - gchar *new_text; - - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_data->store), &iter, path)) - return; - - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, - COLUMN_ROW, &row, - -1); - - glade_property_get (eprop->property, &data_tree); - - /* if we are editing, then there is data in the datatree */ - g_assert (data_tree); - - data_tree = glade_model_data_tree_copy (data_tree); - - data = glade_model_data_tree_get_data (data_tree, row, colnum); - g_assert (G_VALUE_TYPE (&data->value) == G_TYPE_STRING); - - new_text = g_value_dup_string (&data->value); - - if (glade_editor_property_show_i18n_dialog (NULL, - &new_text, - &data->i18n_context, - &data->i18n_comment, - &data->i18n_translatable)) - { - g_value_set_string (&data->value, new_text); - - eprop_data->editing_row = row; - eprop_data->editing_column = colnum; - if (eprop_data->pending_data_tree) - glade_model_data_tree_free (eprop_data->pending_data_tree); - - eprop_data->pending_data_tree = data_tree; - g_idle_add ((GSourceFunc)update_and_focus_data_tree_idle, eprop); - } - else - glade_model_data_tree_free (data_tree); - - g_free (new_text); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GtkTreeIter iter; + gint colnum = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); + gint row; + GNode *data_tree = NULL; + GladeModelData *data; + gchar *new_text; + + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_data->store), &iter, path)) + return; + + + gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, + COLUMN_ROW, &row, -1); + + glade_property_get (eprop->property, &data_tree); + + /* if we are editing, then there is data in the datatree */ + g_assert (data_tree); + + data_tree = glade_model_data_tree_copy (data_tree); + + data = glade_model_data_tree_get_data (data_tree, row, colnum); + g_assert (G_VALUE_TYPE (&data->value) == G_TYPE_STRING); + + new_text = g_value_dup_string (&data->value); + + if (glade_editor_property_show_i18n_dialog (NULL, + &new_text, + &data->i18n_context, + &data->i18n_comment, + &data->i18n_translatable)) + { + g_value_set_string (&data->value, new_text); + + eprop_data->editing_row = row; + eprop_data->editing_column = colnum; + if (eprop_data->pending_data_tree) + glade_model_data_tree_free (eprop_data->pending_data_tree); + + eprop_data->pending_data_tree = data_tree; + g_idle_add ((GSourceFunc) update_and_focus_data_tree_idle, eprop); + } + else + glade_model_data_tree_free (data_tree); + + g_free (new_text); } static void -value_text_edited (GtkCellRendererText *cell, - const gchar *path, - const gchar *new_text, - GladeEditorProperty *eprop) +value_text_edited (GtkCellRendererText * cell, + const gchar * path, + const gchar * new_text, GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GtkTreeIter iter; - gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); - gint row; - GNode *data_tree = NULL; - GladeModelData *data; - GValue *value; - - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_data->store), &iter, path)) - return; - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, - COLUMN_ROW, &row, - -1); - - glade_property_get (eprop->property, &data_tree); - - /* if we are editing, then there is data in the datatree */ - g_assert (data_tree); - - data_tree = glade_model_data_tree_copy (data_tree); - - data = glade_model_data_tree_get_data (data_tree, row, colnum); - - /* Untranslate string and update value in tree. */ - if (G_VALUE_HOLDS_ENUM (&data->value) || G_VALUE_HOLDS_FLAGS (&data->value)) - value = glade_utils_value_from_string (G_VALUE_TYPE (&data->value), - glade_get_value_from_displayable - (G_VALUE_TYPE (&data->value), new_text), - eprop->property->widget->project, - eprop->property->widget); - else - value = glade_utils_value_from_string (G_VALUE_TYPE (&data->value), new_text, - eprop->property->widget->project, - eprop->property->widget); - - - g_value_copy (value, &data->value); - g_value_unset (value); - g_free (value); - - eprop_data->editing_row = row; - eprop_data->editing_column = colnum; - if (eprop_data->pending_data_tree) - glade_model_data_tree_free (eprop_data->pending_data_tree); - - eprop_data->pending_data_tree = data_tree; - g_idle_add ((GSourceFunc)update_and_focus_data_tree_idle, eprop); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GtkTreeIter iter; + gint colnum = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); + gint row; + GNode *data_tree = NULL; + GladeModelData *data; + GValue *value; + + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_data->store), &iter, path)) + return; + + gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, + COLUMN_ROW, &row, -1); + + glade_property_get (eprop->property, &data_tree); + + /* if we are editing, then there is data in the datatree */ + g_assert (data_tree); + + data_tree = glade_model_data_tree_copy (data_tree); + + data = glade_model_data_tree_get_data (data_tree, row, colnum); + + /* Untranslate string and update value in tree. */ + if (G_VALUE_HOLDS_ENUM (&data->value) || G_VALUE_HOLDS_FLAGS (&data->value)) + value = glade_utils_value_from_string (G_VALUE_TYPE (&data->value), + glade_get_value_from_displayable + (G_VALUE_TYPE (&data->value), + new_text), + eprop->property->widget->project, + eprop->property->widget); + else + value = + glade_utils_value_from_string (G_VALUE_TYPE (&data->value), new_text, + eprop->property->widget->project, + eprop->property->widget); + + + g_value_copy (value, &data->value); + g_value_unset (value); + g_free (value); + + eprop_data->editing_row = row; + eprop_data->editing_column = colnum; + if (eprop_data->pending_data_tree) + glade_model_data_tree_free (eprop_data->pending_data_tree); + + eprop_data->pending_data_tree = data_tree; + g_idle_add ((GSourceFunc) update_and_focus_data_tree_idle, eprop); } -static void -enum_flags_format_cell_data (GtkCellLayout *cell_layout, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) +static void +enum_flags_format_cell_data (GtkCellLayout * cell_layout, + GtkCellRenderer * cell, + GtkTreeModel * tree_model, + GtkTreeIter * iter, gpointer data) { - gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); - GValue value = { 0, }; - gchar *string; + gint colnum = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); + GValue value = { 0, }; + gchar *string; + + gtk_tree_model_get_value (tree_model, iter, NUM_COLUMNS + colnum, &value); - gtk_tree_model_get_value (tree_model, iter, - NUM_COLUMNS + colnum, &value); + string = glade_utils_string_from_value (&value); - string = glade_utils_string_from_value (&value); + g_object_set (cell, "text", string && string[0] ? + glade_get_displayable_value (G_VALUE_TYPE (&value), + string) : "", NULL); - g_object_set (cell, "text", string && string[0] ? - glade_get_displayable_value (G_VALUE_TYPE (&value), string) : "", NULL); - - g_free (string); + g_free (string); - g_value_unset (&value); + g_value_unset (&value); } static void -data_editing_started (GtkCellRenderer *cell, - GtkCellEditable *editable, - gchar *path, - GladeEditorProperty *eprop) +data_editing_started (GtkCellRenderer * cell, + GtkCellEditable * editable, + gchar * path, GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); - gint row; - GtkTreeIter iter; + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + gint colnum = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); + gint row; + GtkTreeIter iter; - if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_data->store), &iter, path)) - return; + if (!gtk_tree_model_get_iter_from_string + (GTK_TREE_MODEL (eprop_data->store), &iter, path)) + return; - gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, - COLUMN_ROW, &row, - -1); + gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, + COLUMN_ROW, &row, -1); - eprop_data->editing_row = row; - eprop_data->editing_column = colnum; + eprop_data->editing_row = row; + eprop_data->editing_column = colnum; } static void -data_editing_canceled (GtkCellRenderer *renderer, - GladeEditorProperty *eprop) +data_editing_canceled (GtkCellRenderer * renderer, GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - if (eprop_data->setting_focus) - return; + if (eprop_data->setting_focus) + return; - g_idle_add ((GSourceFunc)focus_data_tree_idle, eprop); + g_idle_add ((GSourceFunc) focus_data_tree_idle, eprop); } static GtkTreeViewColumn * -eprop_model_generate_column (GladeEditorProperty *eprop, - gint colnum, - GladeModelData *data) +eprop_model_generate_column (GladeEditorProperty * eprop, + gint colnum, GladeModelData * data) { - GtkTreeViewColumn *column = gtk_tree_view_column_new (); - GtkCellRenderer *renderer = NULL; - GtkAdjustment *adjustment; - GtkListStore *store; - GType type = G_TYPE_INVALID; - - gtk_tree_view_column_set_title (column, data->name); - gtk_tree_view_column_set_resizable (column, TRUE); - gtk_tree_view_column_set_expand (column, TRUE); - - type = G_VALUE_TYPE (&data->value); - - /* Support enum and flag types, and a hardcoded list of fundamental types */ - if (type == G_TYPE_CHAR || - type == G_TYPE_UCHAR || - type == G_TYPE_STRING || - type == GDK_TYPE_PIXBUF) - { - /* Text renderer */ - renderer = gtk_cell_renderer_text_new (); - - g_object_set (G_OBJECT (renderer), - "editable", TRUE, - "ellipsize", PANGO_ELLIPSIZE_END, - "width", 90, - NULL); - - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "text", NUM_COLUMNS + colnum, - NULL); - - if (type == G_TYPE_CHAR || - type == G_TYPE_UCHAR) - { - /* XXX restrict to 1 char !! */ - } - - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_text_edited), eprop); - - /* Trigger i18n dialog from here */ - if (type == G_TYPE_STRING) - { - GtkCellRenderer *icon_renderer = glade_cell_renderer_icon_new (); - - g_object_set (G_OBJECT (icon_renderer), - "activatable", TRUE, - "icon-name", GTK_STOCK_EDIT, - NULL); - - gtk_tree_view_column_pack_start (column, icon_renderer, FALSE); - - g_object_set_data (G_OBJECT (icon_renderer), "column-number", GINT_TO_POINTER (colnum)); - g_signal_connect (G_OBJECT (icon_renderer), "activate", - G_CALLBACK (value_i18n_activate), eprop); - } - - } - else if (type == G_TYPE_BOOLEAN) - { - /* Toggle renderer */ - renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "active", NUM_COLUMNS + colnum, - NULL); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (value_toggled), eprop); - } - /* Check renderer */ - else if (type == G_TYPE_INT || - type == G_TYPE_UINT || - type == G_TYPE_LONG || - type == G_TYPE_ULONG || - type == G_TYPE_INT64 || - type == G_TYPE_UINT64 || - type == G_TYPE_FLOAT || - type == G_TYPE_DOUBLE) - { - /* Spin renderer */ - renderer = gtk_cell_renderer_spin_new (); - adjustment = (GtkAdjustment *)gtk_adjustment_new (0, -G_MAXDOUBLE, G_MAXDOUBLE, 100, 100, 0); - g_object_set (G_OBJECT (renderer), - "editable", TRUE, - "adjustment", adjustment, - NULL); - - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_attributes (column, renderer, - "text", NUM_COLUMNS + colnum, - NULL); - - if (type == G_TYPE_FLOAT || - type == G_TYPE_DOUBLE) - g_object_set (G_OBJECT (renderer), "digits", 2, NULL); - - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_text_edited), eprop); - - } - else if (G_TYPE_IS_ENUM (type)) - { - /* Combo renderer */ - renderer = gtk_cell_renderer_combo_new (); - store = glade_utils_liststore_from_enum_type (type, FALSE); - g_object_set (G_OBJECT (renderer), - "editable", TRUE, - "text-column", 0, - "has-entry", FALSE, - "model", store, - NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_attributes (column, renderer, - "text", NUM_COLUMNS + colnum, - NULL); - - - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), - renderer, - (GtkCellLayoutDataFunc)enum_flags_format_cell_data, - NULL, NULL); - - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (value_text_edited), eprop); - - } - else if (G_TYPE_IS_FLAGS (type)) - { - /* Export a flags dialog from glade-editor-property... */ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "text", NUM_COLUMNS + colnum, - NULL); - - } - else /* All uneditable types at this point (currently we dont do object data here, TODO) */ - { - /* text renderer and object dialog (or raw text for pixbuf) */ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - } - - g_signal_connect (G_OBJECT (renderer), "editing-started", - G_CALLBACK (data_editing_started), eprop); - - g_signal_connect (G_OBJECT (renderer), "editing-canceled", - G_CALLBACK (data_editing_canceled), eprop); - - g_object_set_data (G_OBJECT (renderer), "column-number", GINT_TO_POINTER (colnum)); - g_object_set_data_full (G_OBJECT (column), "column-type", g_memdup (&type, sizeof (GType)), g_free); - - return column; + GtkTreeViewColumn *column = gtk_tree_view_column_new (); + GtkCellRenderer *renderer = NULL; + GtkAdjustment *adjustment; + GtkListStore *store; + GType type = G_TYPE_INVALID; + + gtk_tree_view_column_set_title (column, data->name); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_column_set_expand (column, TRUE); + + type = G_VALUE_TYPE (&data->value); + + /* Support enum and flag types, and a hardcoded list of fundamental types */ + if (type == G_TYPE_CHAR || + type == G_TYPE_UCHAR || type == G_TYPE_STRING || type == GDK_TYPE_PIXBUF) + { + /* Text renderer */ + renderer = gtk_cell_renderer_text_new (); + + g_object_set (G_OBJECT (renderer), + "editable", TRUE, + "ellipsize", PANGO_ELLIPSIZE_END, "width", 90, NULL); + + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "text", NUM_COLUMNS + colnum, NULL); + + if (type == G_TYPE_CHAR || type == G_TYPE_UCHAR) + { + /* XXX restrict to 1 char !! */ + } + + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_text_edited), eprop); + + /* Trigger i18n dialog from here */ + if (type == G_TYPE_STRING) + { + GtkCellRenderer *icon_renderer = glade_cell_renderer_icon_new (); + + g_object_set (G_OBJECT (icon_renderer), + "activatable", TRUE, "icon-name", GTK_STOCK_EDIT, NULL); + + gtk_tree_view_column_pack_start (column, icon_renderer, FALSE); + + g_object_set_data (G_OBJECT (icon_renderer), "column-number", + GINT_TO_POINTER (colnum)); + g_signal_connect (G_OBJECT (icon_renderer), "activate", + G_CALLBACK (value_i18n_activate), eprop); + } + + } + else if (type == G_TYPE_BOOLEAN) + { + /* Toggle renderer */ + renderer = gtk_cell_renderer_toggle_new (); + g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "active", NUM_COLUMNS + colnum, + NULL); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (value_toggled), eprop); + } + /* Check renderer */ + else if (type == G_TYPE_INT || + type == G_TYPE_UINT || + type == G_TYPE_LONG || + type == G_TYPE_ULONG || + type == G_TYPE_INT64 || + type == G_TYPE_UINT64 || + type == G_TYPE_FLOAT || type == G_TYPE_DOUBLE) + { + /* Spin renderer */ + renderer = gtk_cell_renderer_spin_new (); + adjustment = + (GtkAdjustment *) gtk_adjustment_new (0, -G_MAXDOUBLE, G_MAXDOUBLE, + 100, 100, 0); + g_object_set (G_OBJECT (renderer), "editable", TRUE, "adjustment", + adjustment, NULL); + + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_set_attributes (column, renderer, + "text", NUM_COLUMNS + colnum, NULL); + + if (type == G_TYPE_FLOAT || type == G_TYPE_DOUBLE) + g_object_set (G_OBJECT (renderer), "digits", 2, NULL); + + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_text_edited), eprop); + + } + else if (G_TYPE_IS_ENUM (type)) + { + /* Combo renderer */ + renderer = gtk_cell_renderer_combo_new (); + store = glade_utils_liststore_from_enum_type (type, FALSE); + g_object_set (G_OBJECT (renderer), + "editable", TRUE, + "text-column", 0, "has-entry", FALSE, "model", store, NULL); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_set_attributes (column, renderer, + "text", NUM_COLUMNS + colnum, NULL); + + + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), + renderer, + (GtkCellLayoutDataFunc) + enum_flags_format_cell_data, NULL, + NULL); + + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (value_text_edited), eprop); + + } + else if (G_TYPE_IS_FLAGS (type)) + { + /* Export a flags dialog from glade-editor-property... */ + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "text", NUM_COLUMNS + colnum, NULL); + + } + else /* All uneditable types at this point (currently we dont do object data here, TODO) */ + { + /* text renderer and object dialog (or raw text for pixbuf) */ + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + } + + g_signal_connect (G_OBJECT (renderer), "editing-started", + G_CALLBACK (data_editing_started), eprop); + + g_signal_connect (G_OBJECT (renderer), "editing-canceled", + G_CALLBACK (data_editing_canceled), eprop); + + g_object_set_data (G_OBJECT (renderer), "column-number", + GINT_TO_POINTER (colnum)); + g_object_set_data_full (G_OBJECT (column), "column-type", + g_memdup (&type, sizeof (GType)), g_free); + + return column; } static void -eprop_model_data_generate_columns (GladeEditorProperty *eprop) +eprop_model_data_generate_columns (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GladeModelData *iter_data; - GtkTreeViewColumn *column; - GNode *data_tree = NULL, *iter_node; - gint colnum; - - glade_property_get (eprop->property, &data_tree); - - if (!data_tree || !data_tree->children || !data_tree->children->children) - return; - - /* Append new columns */ - for (colnum = 0, iter_node = data_tree->children->children; iter_node; - colnum++, iter_node = iter_node->next) - { - iter_data = iter_node->data; - - column = eprop_model_generate_column (eprop, colnum, iter_data); - gtk_tree_view_append_column (eprop_data->view, column); - } + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GladeModelData *iter_data; + GtkTreeViewColumn *column; + GNode *data_tree = NULL, *iter_node; + gint colnum; + + glade_property_get (eprop->property, &data_tree); + + if (!data_tree || !data_tree->children || !data_tree->children->children) + return; + + /* Append new columns */ + for (colnum = 0, iter_node = data_tree->children->children; iter_node; + colnum++, iter_node = iter_node->next) + { + iter_data = iter_node->data; + + column = eprop_model_generate_column (eprop, colnum, iter_data); + gtk_tree_view_append_column (eprop_data->view, column); + } } static void -eprop_data_focus_new (GladeEPropModelData *eprop_data) +eprop_data_focus_new (GladeEPropModelData * eprop_data) { - /* Focus and edit the first column of a newly added row */ - if (eprop_data->store) - { - GtkTreePath *new_item_path; - GtkTreeIter iter; - GtkTreeViewColumn *column; - gint n_children; - - n_children = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (eprop_data->store), NULL); - - if ((column = gtk_tree_view_get_column (eprop_data->view, eprop_data->editing_column)) != NULL && - n_children > 0 && gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (eprop_data->store), - &iter, NULL, n_children - 1)) - - { - GType *column_type = g_object_get_data (G_OBJECT (column), "column-type"); - - new_item_path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_data->store), &iter); - - eprop_data->setting_focus = TRUE; - - gtk_widget_grab_focus (GTK_WIDGET (eprop_data->view)); - gtk_tree_view_expand_to_path (eprop_data->view, new_item_path); - gtk_tree_view_set_cursor (eprop_data->view, new_item_path, - column, *column_type != G_TYPE_BOOLEAN); - - eprop_data->setting_focus = FALSE; - - gtk_tree_path_free (new_item_path); - } - } + /* Focus and edit the first column of a newly added row */ + if (eprop_data->store) + { + GtkTreePath *new_item_path; + GtkTreeIter iter; + GtkTreeViewColumn *column; + gint n_children; + + n_children = + gtk_tree_model_iter_n_children (GTK_TREE_MODEL (eprop_data->store), + NULL); + + if ((column = + gtk_tree_view_get_column (eprop_data->view, + eprop_data->editing_column)) != NULL && + n_children > 0 && + gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (eprop_data->store), + &iter, NULL, n_children - 1)) + + { + GType *column_type = + g_object_get_data (G_OBJECT (column), "column-type"); + + new_item_path = + gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_data->store), + &iter); + + eprop_data->setting_focus = TRUE; + + gtk_widget_grab_focus (GTK_WIDGET (eprop_data->view)); + gtk_tree_view_expand_to_path (eprop_data->view, new_item_path); + gtk_tree_view_set_cursor (eprop_data->view, new_item_path, + column, *column_type != G_TYPE_BOOLEAN); + + eprop_data->setting_focus = FALSE; + + gtk_tree_path_free (new_item_path); + } + } } static void -eprop_data_focus_editing_cell (GladeEPropModelData *eprop_data) +eprop_data_focus_editing_cell (GladeEPropModelData * eprop_data) { - /* Focus and edit the first column of a newly added row */ - if (!eprop_data->setting_focus && eprop_data->store && eprop_data->want_focus && - eprop_data->editing_column >= 0 && eprop_data->editing_row >= 0) - { - GtkTreePath *item_path; - GtkTreeIter iter; - GtkTreeViewColumn *column; - gint row, col, rows, cols; - GList *column_list; - - column_list = gtk_tree_view_get_columns (eprop_data->view); - cols = g_list_length (column_list); - g_list_free (column_list); - - rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (eprop_data->store), NULL); - - col = eprop_data->editing_column; - row = eprop_data->editing_row; - - if (eprop_data->want_next_focus) - { - switch (eprop_data->sequence) - { - case SEQ_HORIZONTAL: - if (++col >= cols) - { - col = 0; - if (++row >= rows) - row = 0; - } - break; - case SEQ_VERTICAL: - if (++row >= rows) - { - row = 0; - if (++col >= cols) - col = 0; - } - break; - case SEQ_NONE: - default: - break; - } - } - - if ((column = gtk_tree_view_get_column (eprop_data->view, col)) != NULL && - gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (eprop_data->store), &iter, NULL, row)) - { - GType *column_type = g_object_get_data (G_OBJECT (column), "column-type"); - - item_path = gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_data->store), &iter); - - eprop_data->setting_focus = TRUE; - - gtk_widget_grab_focus (GTK_WIDGET (eprop_data->view)); - gtk_tree_view_expand_to_path (eprop_data->view, item_path); - gtk_tree_view_set_cursor (eprop_data->view, item_path, column, - eprop_data->want_next_focus && - eprop_data->sequence != SEQ_NONE && - *column_type != G_TYPE_BOOLEAN); - - gtk_tree_path_free (item_path); - - eprop_data->setting_focus = FALSE; - } - } + /* Focus and edit the first column of a newly added row */ + if (!eprop_data->setting_focus && eprop_data->store && eprop_data->want_focus + && eprop_data->editing_column >= 0 && eprop_data->editing_row >= 0) + { + GtkTreePath *item_path; + GtkTreeIter iter; + GtkTreeViewColumn *column; + gint row, col, rows, cols; + GList *column_list; + + column_list = gtk_tree_view_get_columns (eprop_data->view); + cols = g_list_length (column_list); + g_list_free (column_list); + + rows = + gtk_tree_model_iter_n_children (GTK_TREE_MODEL (eprop_data->store), + NULL); + + col = eprop_data->editing_column; + row = eprop_data->editing_row; + + if (eprop_data->want_next_focus) + { + switch (eprop_data->sequence) + { + case SEQ_HORIZONTAL: + if (++col >= cols) + { + col = 0; + if (++row >= rows) + row = 0; + } + break; + case SEQ_VERTICAL: + if (++row >= rows) + { + row = 0; + if (++col >= cols) + col = 0; + } + break; + case SEQ_NONE: + default: + break; + } + } + + if ((column = gtk_tree_view_get_column (eprop_data->view, col)) != NULL && + gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (eprop_data->store), + &iter, NULL, row)) + { + GType *column_type = + g_object_get_data (G_OBJECT (column), "column-type"); + + item_path = + gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_data->store), + &iter); + + eprop_data->setting_focus = TRUE; + + gtk_widget_grab_focus (GTK_WIDGET (eprop_data->view)); + gtk_tree_view_expand_to_path (eprop_data->view, item_path); + gtk_tree_view_set_cursor (eprop_data->view, item_path, column, + eprop_data->want_next_focus && + eprop_data->sequence != SEQ_NONE && + *column_type != G_TYPE_BOOLEAN); + + gtk_tree_path_free (item_path); + + eprop_data->setting_focus = FALSE; + } + } } static void -glade_eprop_model_data_load (GladeEditorProperty *eprop, - GladeProperty *property) +glade_eprop_model_data_load (GladeEditorProperty * eprop, + GladeProperty * property) { - GladeEditorPropertyClass *parent_class = - g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - - clear_view (eprop); - - /* Chain up in a clean state... */ - parent_class->load (eprop, property); - - gtk_tree_view_set_model (eprop_data->view, NULL); - if (!property) - return; - - if ((eprop_data->store = eprop_model_data_generate_store (eprop)) != NULL) - { - eprop_data->selection = gtk_tree_view_get_selection (eprop_data->view); - - /* Pass ownership of the store to the view... */ - gtk_tree_view_set_model (eprop_data->view, GTK_TREE_MODEL (eprop_data->store)); - g_object_unref (G_OBJECT (eprop_data->store)); - - g_signal_connect (G_OBJECT (eprop_data->store), "row-deleted", - G_CALLBACK (eprop_treeview_row_deleted), - eprop); - } - - /* Create new columns with renderers */ - eprop_model_data_generate_columns (eprop); - - if (eprop_data->store) - { - if (eprop_data->adding_row) - eprop_data_focus_new (eprop_data); - else if (eprop_data->want_focus && - eprop_data->editing_row >= 0 && eprop_data->editing_column >= 0) - { - if (eprop_data->want_next_focus && eprop_data->next_focus_idle == 0) - eprop_data->next_focus_idle = - g_idle_add ((GSourceFunc)focus_next_data_tree_idle, eprop); - else - eprop_data_focus_editing_cell (eprop_data); - } - } + GladeEditorPropertyClass *parent_class = + g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + + clear_view (eprop); + + /* Chain up in a clean state... */ + parent_class->load (eprop, property); + + gtk_tree_view_set_model (eprop_data->view, NULL); + if (!property) + return; + + if ((eprop_data->store = eprop_model_data_generate_store (eprop)) != NULL) + { + eprop_data->selection = gtk_tree_view_get_selection (eprop_data->view); + + /* Pass ownership of the store to the view... */ + gtk_tree_view_set_model (eprop_data->view, + GTK_TREE_MODEL (eprop_data->store)); + g_object_unref (G_OBJECT (eprop_data->store)); + + g_signal_connect (G_OBJECT (eprop_data->store), "row-deleted", + G_CALLBACK (eprop_treeview_row_deleted), eprop); + } + + /* Create new columns with renderers */ + eprop_model_data_generate_columns (eprop); + + if (eprop_data->store) + { + if (eprop_data->adding_row) + eprop_data_focus_new (eprop_data); + else if (eprop_data->want_focus && + eprop_data->editing_row >= 0 && eprop_data->editing_column >= 0) + { + if (eprop_data->want_next_focus && eprop_data->next_focus_idle == 0) + eprop_data->next_focus_idle = + g_idle_add ((GSourceFunc) focus_next_data_tree_idle, eprop); + else + eprop_data_focus_editing_cell (eprop_data); + } + } } static GtkWidget * -glade_eprop_model_data_create_input (GladeEditorProperty *eprop) +glade_eprop_model_data_create_input (GladeEditorProperty * eprop) { - GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); - GtkWidget *vbox, *hbox, *button, *swin, *label, *combo; - gchar *string; - - vbox = gtk_vbox_new (FALSE, 2); - - hbox = gtk_hbox_new (FALSE, 4); - - eprop_data->sequence = SEQ_NONE; - - /* hbox with add/remove row buttons on the right... */ - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - string = g_strdup_printf ("<b>%s</b>", _("Add and remove rows:")); - label = gtk_label_new (string); - g_free (string); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 2, 0); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - button = gtk_button_new (); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON)); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_model_data_add_clicked), - eprop_data); - - button = gtk_button_new (); - gtk_button_set_image (GTK_BUTTON (button), - gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON)); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_model_data_delete_clicked), - eprop_data); - - /* separator... */ - label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - - string = g_strdup_printf ("<b>%s</b>", _("Sequential editing:")); - label = gtk_label_new (string); - g_free (string); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 2, 0); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - combo = gtk_combo_box_text_new (); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Off")); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Horizontal")); - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Vertical")); - - - gtk_combo_box_set_active (GTK_COMBO_BOX (combo), eprop_data->sequence); - - gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (combo), "changed", - G_CALLBACK (glade_eprop_model_sequence_changed), - eprop_data); - - - /* Pack treeview/swindow on the left... */ - swin = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), GTK_SHADOW_IN); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0); - - eprop_data->view = (GtkTreeView *)gtk_tree_view_new (); - - g_signal_connect (eprop_data->view, "key-press-event", - G_CALLBACK (eprop_treeview_key_press), - eprop); - - gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (eprop_data->view), GTK_TREE_VIEW_GRID_LINES_BOTH); - gtk_tree_view_set_reorderable (GTK_TREE_VIEW (eprop_data->view), TRUE); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (eprop_data->view), TRUE); - gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_data->view)); - - g_object_set (G_OBJECT (vbox), "height-request", 300, NULL); - - gtk_widget_show_all (vbox); - return vbox; + GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); + GtkWidget *vbox, *hbox, *button, *swin, *label, *combo; + gchar *string; + + vbox = gtk_vbox_new (FALSE, 2); + + hbox = gtk_hbox_new (FALSE, 4); + + eprop_data->sequence = SEQ_NONE; + + /* hbox with add/remove row buttons on the right... */ + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + + string = g_strdup_printf ("<b>%s</b>", _("Add and remove rows:")); + label = gtk_label_new (string); + g_free (string); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label), 2, 0); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_ADD, + GTK_ICON_SIZE_BUTTON)); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (glade_eprop_model_data_add_clicked), + eprop_data); + + button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_stock (GTK_STOCK_REMOVE, + GTK_ICON_SIZE_BUTTON)); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (glade_eprop_model_data_delete_clicked), + eprop_data); + + /* separator... */ + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); + + string = g_strdup_printf ("<b>%s</b>", _("Sequential editing:")); + label = gtk_label_new (string); + g_free (string); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label), 2, 0); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + combo = gtk_combo_box_text_new (); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Off")); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Horizontal")); + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Vertical")); + + + gtk_combo_box_set_active (GTK_COMBO_BOX (combo), eprop_data->sequence); + + gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0); + + g_signal_connect (G_OBJECT (combo), "changed", + G_CALLBACK (glade_eprop_model_sequence_changed), + eprop_data); + + + /* Pack treeview/swindow on the left... */ + swin = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), + GTK_SHADOW_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0); + + eprop_data->view = (GtkTreeView *) gtk_tree_view_new (); + + g_signal_connect (eprop_data->view, "key-press-event", + G_CALLBACK (eprop_treeview_key_press), eprop); + + gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (eprop_data->view), + GTK_TREE_VIEW_GRID_LINES_BOTH); + gtk_tree_view_set_reorderable (GTK_TREE_VIEW (eprop_data->view), TRUE); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (eprop_data->view), TRUE); + gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_data->view)); + + g_object_set (G_OBJECT (vbox), "height-request", 300, NULL); + + gtk_widget_show_all (vbox); + return vbox; } diff --git a/plugins/gtk+/glade-model-data.h b/plugins/gtk+/glade-model-data.h index 63b6f400..b2add4ac 100644 --- a/plugins/gtk+/glade-model-data.h +++ b/plugins/gtk+/glade-model-data.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-store-editor.c b/plugins/gtk+/glade-store-editor.c index 1c601cd4..6f6675a4 100644 --- a/plugins/gtk+/glade-store-editor.c +++ b/plugins/gtk+/glade-store-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,11 +27,11 @@ #include "glade-store-editor.h" -static void glade_store_editor_finalize (GObject *object); +static void glade_store_editor_finalize (GObject * object); -static void glade_store_editor_editable_init (GladeEditableIface *iface); +static void glade_store_editor_editable_init (GladeEditableIface * iface); -static void glade_store_editor_grab_focus (GtkWidget *widget); +static void glade_store_editor_grab_focus (GtkWidget * widget); G_DEFINE_TYPE_WITH_CODE (GladeStoreEditor, glade_store_editor, GTK_TYPE_VBOX, @@ -41,198 +40,206 @@ G_DEFINE_TYPE_WITH_CODE (GladeStoreEditor, glade_store_editor, GTK_TYPE_VBOX, static void -glade_store_editor_class_init (GladeStoreEditorClass *klass) +glade_store_editor_class_init (GladeStoreEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_store_editor_finalize; - widget_class->grab_focus = glade_store_editor_grab_focus; + object_class->finalize = glade_store_editor_finalize; + widget_class->grab_focus = glade_store_editor_grab_focus; } static void -glade_store_editor_init (GladeStoreEditor *self) +glade_store_editor_init (GladeStoreEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeStoreEditor *store_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeStoreEditor * store_editor) { - if (!gtk_widget_get_mapped (GTK_WIDGET (store_editor))) - return; + if (!gtk_widget_get_mapped (GTK_WIDGET (store_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (store_editor), store_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (store_editor), + store_editor->loaded_widget); } static void -project_finalized (GladeStoreEditor *store_editor, - GladeProject *where_project_was) +project_finalized (GladeStoreEditor * store_editor, + GladeProject * where_project_was) { - store_editor->loaded_widget = NULL; + store_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (store_editor), NULL); + glade_editable_load (GLADE_EDITABLE (store_editor), NULL); } static void -glade_store_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_store_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (editable); - GList *l; - - /* Since we watch the project*/ - if (store_editor->loaded_widget) - { - /* watch custom-child and use-stock properties here for reloads !!! */ - - g_signal_handlers_disconnect_by_func (G_OBJECT (store_editor->loaded_widget->project), - G_CALLBACK (project_changed), store_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (store_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - store_editor); - } - - /* Mark our widget... */ - store_editor->loaded_widget = widget; - - if (store_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (store_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), store_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (store_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - store_editor); - } - - /* load the embedded editable... */ - if (store_editor->embed) - glade_editable_load (GLADE_EDITABLE (store_editor->embed), widget); - - for (l = store_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); + GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (editable); + GList *l; + + /* Since we watch the project */ + if (store_editor->loaded_widget) + { + /* watch custom-child and use-stock properties here for reloads !!! */ + + g_signal_handlers_disconnect_by_func (G_OBJECT + (store_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + store_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (store_editor->loaded_widget->project), + (GWeakNotify) project_finalized, store_editor); + } + + /* Mark our widget... */ + store_editor->loaded_widget = widget; + + if (store_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (store_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), store_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (store_editor->loaded_widget->project), + (GWeakNotify) project_finalized, store_editor); + } + + /* load the embedded editable... */ + if (store_editor->embed) + glade_editable_load (GLADE_EDITABLE (store_editor->embed), widget); + + for (l = store_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); } static void -glade_store_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_store_editor_set_show_name (GladeEditable * editable, gboolean show_name) { - GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (editable); + GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (store_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (store_editor->embed), + show_name); } static void -glade_store_editor_editable_init (GladeEditableIface *iface) +glade_store_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_store_editor_load; - iface->set_show_name = glade_store_editor_set_show_name; + iface->load = glade_store_editor_load; + iface->set_show_name = glade_store_editor_set_show_name; } static void -glade_store_editor_finalize (GObject *object) +glade_store_editor_finalize (GObject * object) { - GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (object); + GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (object); - if (store_editor->properties) - g_list_free (store_editor->properties); - store_editor->properties = NULL; - store_editor->embed = NULL; + if (store_editor->properties) + g_list_free (store_editor->properties); + store_editor->properties = NULL; + store_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_store_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_store_editor_parent_class)->finalize (object); } static void -glade_store_editor_grab_focus (GtkWidget *widget) +glade_store_editor_grab_focus (GtkWidget * widget) { - GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (widget); + GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (widget); - gtk_widget_grab_focus (store_editor->embed); + gtk_widget_grab_focus (store_editor->embed); } GtkWidget * -glade_store_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_store_editor_new (GladeWidgetAdaptor * adaptor, GladeEditable * embed) { - GladeStoreEditor *store_editor; - GladeEditorProperty *eprop; - GtkWidget *frame, *alignment, *label, *vbox; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - /* Pack the parent on top... */ - store_editor = g_object_new (GLADE_TYPE_STORE_EDITOR, NULL); - store_editor->embed = GTK_WIDGET (embed); - gtk_box_pack_start (GTK_BOX (store_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - /* -------------- The columns area here -------------- */ - /* Label item in frame label widget on top.. */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "columns", FALSE, TRUE); - store_editor->properties = g_list_prepend (store_editor->properties, eprop); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12); - - /* Alignment/Vbox in frame... */ - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (alignment), vbox); - - /* Add descriptive label */ - label = gtk_label_new (_("Define columns for your liststore; " - "giving them meaningful names will help you to retrieve " - "them when setting cell renderer attributes (press the " - "Delete key to remove the selected column)")); - gtk_label_set_line_wrap (GTK_LABEL(label), TRUE); - gtk_label_set_line_wrap_mode (GTK_LABEL(label), PANGO_WRAP_WORD); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6); - gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4); - - - if (adaptor->type == GTK_TYPE_LIST_STORE || - g_type_is_a (adaptor->type, GTK_TYPE_LIST_STORE)) - { - /* -------------- The data area here -------------- */ - /* Label item in frame label widget on top.. */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "data", FALSE, TRUE); - store_editor->properties = g_list_prepend (store_editor->properties, eprop); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12); - - /* Alignment/Vbox in frame... */ - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (alignment), vbox); - - /* Add descriptive label */ - label = gtk_label_new (_("Add remove and edit rows of data (you can optionally use Ctrl+N to add " - "new rows and the Delete key to remove the selected row)")); - gtk_label_set_line_wrap (GTK_LABEL(label), TRUE); - gtk_label_set_line_wrap_mode (GTK_LABEL(label), PANGO_WRAP_WORD); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6); - gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4); - } - - gtk_widget_show_all (GTK_WIDGET (store_editor)); - - return GTK_WIDGET (store_editor); + GladeStoreEditor *store_editor; + GladeEditorProperty *eprop; + GtkWidget *frame, *alignment, *label, *vbox; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + /* Pack the parent on top... */ + store_editor = g_object_new (GLADE_TYPE_STORE_EDITOR, NULL); + store_editor->embed = GTK_WIDGET (embed); + gtk_box_pack_start (GTK_BOX (store_editor), GTK_WIDGET (embed), FALSE, FALSE, + 0); + + /* -------------- The columns area here -------------- */ + /* Label item in frame label widget on top.. */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "columns", FALSE, + TRUE); + store_editor->properties = g_list_prepend (store_editor->properties, eprop); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12); + + /* Alignment/Vbox in frame... */ + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (alignment), vbox); + + /* Add descriptive label */ + label = gtk_label_new (_("Define columns for your liststore; " + "giving them meaningful names will help you to retrieve " + "them when setting cell renderer attributes (press the " + "Delete key to remove the selected column)")); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4); + + + if (adaptor->type == GTK_TYPE_LIST_STORE || + g_type_is_a (adaptor->type, GTK_TYPE_LIST_STORE)) + { + /* -------------- The data area here -------------- */ + /* Label item in frame label widget on top.. */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "data", FALSE, + TRUE); + store_editor->properties = + g_list_prepend (store_editor->properties, eprop); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12); + + /* Alignment/Vbox in frame... */ + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (alignment), vbox); + + /* Add descriptive label */ + label = + gtk_label_new (_ + ("Add remove and edit rows of data (you can optionally use Ctrl+N to add " + "new rows and the Delete key to remove the selected row)")); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4); + } + + gtk_widget_show_all (GTK_WIDGET (store_editor)); + + return GTK_WIDGET (store_editor); } diff --git a/plugins/gtk+/glade-store-editor.h b/plugins/gtk+/glade-store-editor.h index 6e9d4ee3..a6425b27 100644 --- a/plugins/gtk+/glade-store-editor.h +++ b/plugins/gtk+/glade-store-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-text-button.c b/plugins/gtk+/glade-text-button.c index 0961c05c..79308c2e 100644 --- a/plugins/gtk+/glade-text-button.c +++ b/plugins/gtk+/glade-text-button.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -32,14 +31,14 @@ typedef struct { - gchar *button_text; + gchar *button_text; } GladeTextButtonPrivate; -static void glade_text_button_finalize (GObject *object); +static void glade_text_button_finalize (GObject * object); -static void glade_text_button_cell_editable_init (GtkCellEditableIface *iface); +static void glade_text_button_cell_editable_init (GtkCellEditableIface * iface); -static void glade_text_button_grab_focus (GtkWidget *widget); +static void glade_text_button_grab_focus (GtkWidget * widget); G_DEFINE_TYPE_WITH_CODE (GladeTextButton, glade_text_button, GTK_TYPE_ALIGNMENT, @@ -48,114 +47,112 @@ G_DEFINE_TYPE_WITH_CODE (GladeTextButton, glade_text_button, GTK_TYPE_ALIGNMENT, static void -glade_text_button_class_init (GladeTextButtonClass *klass) +glade_text_button_class_init (GladeTextButtonClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_text_button_finalize; - widget_class->grab_focus = glade_text_button_grab_focus; + object_class->finalize = glade_text_button_finalize; + widget_class->grab_focus = glade_text_button_grab_focus; - g_type_class_add_private (object_class, sizeof (GladeTextButtonPrivate)); + g_type_class_add_private (object_class, sizeof (GladeTextButtonPrivate)); } static void -glade_text_button_init (GladeTextButton *self) +glade_text_button_init (GladeTextButton * self) { - GtkWidget *image; - - gtk_alignment_set_padding (GTK_ALIGNMENT (self), 1, 1, 2, 2); - - self->hbox = gtk_hbox_new (FALSE, 2); - - gtk_container_add (GTK_CONTAINER (self), self->hbox); - - self->entry = gtk_entry_new (); - gtk_box_pack_start (GTK_BOX (self->hbox), self->entry, TRUE, TRUE, 0); - - self->button = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (self->hbox), self->button, FALSE, FALSE, 0); - - image = gtk_image_new_from_stock (GTK_STOCK_EDIT, - GTK_ICON_SIZE_MENU); - gtk_widget_show (image); - gtk_container_add (GTK_CONTAINER (self->button), image); + GtkWidget *image; + + gtk_alignment_set_padding (GTK_ALIGNMENT (self), 1, 1, 2, 2); + + self->hbox = gtk_hbox_new (FALSE, 2); + + gtk_container_add (GTK_CONTAINER (self), self->hbox); + + self->entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (self->hbox), self->entry, TRUE, TRUE, 0); + + self->button = gtk_button_new (); + gtk_box_pack_start (GTK_BOX (self->hbox), self->button, FALSE, FALSE, 0); + + image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU); + gtk_widget_show (image); + gtk_container_add (GTK_CONTAINER (self->button), image); } static void -glade_text_button_clicked (GtkWidget *widget, - GladeTextButton *button) +glade_text_button_clicked (GtkWidget * widget, GladeTextButton * button) { - gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); - gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); + gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); + gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); } /* GtkCellEditable method implementations */ static void -glade_text_button_entry_activated (GtkEntry *entry, GladeTextButton *button) +glade_text_button_entry_activated (GtkEntry * entry, GladeTextButton * button) { - gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); - gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); + gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); + gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); } static gboolean -glade_text_button_key_press_event (GtkEntry *entry, - GdkEventKey *key_event, - GladeTextButton *button) +glade_text_button_key_press_event (GtkEntry * entry, + GdkEventKey * key_event, + GladeTextButton * button) { - if (key_event->keyval == GDK_KEY_Escape) - { - g_object_get (entry, - "editing-canceled", TRUE, - NULL); - gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); - gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); - - return TRUE; - } - - /* override focus */ - if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down) - { - gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); - gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); - return TRUE; - } - return FALSE; + if (key_event->keyval == GDK_KEY_Escape) + { + g_object_get (entry, "editing-canceled", TRUE, NULL); + gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); + gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); + + return TRUE; + } + + /* override focus */ + if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down) + { + gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (button)); + gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (button)); + return TRUE; + } + return FALSE; } static void -glade_text_button_start_editing (GtkCellEditable *cell_editable, - GdkEvent *event) +glade_text_button_start_editing (GtkCellEditable * cell_editable, + GdkEvent * event) { - g_signal_connect (GLADE_TEXT_BUTTON (cell_editable)->button, "clicked", - G_CALLBACK (glade_text_button_clicked), cell_editable); - g_signal_connect (GLADE_TEXT_BUTTON (cell_editable)->entry, "activate", - G_CALLBACK (glade_text_button_entry_activated), cell_editable); - g_signal_connect (cell_editable, "key-press-event", - G_CALLBACK (glade_text_button_key_press_event), cell_editable); + g_signal_connect (GLADE_TEXT_BUTTON (cell_editable)->button, "clicked", + G_CALLBACK (glade_text_button_clicked), cell_editable); + g_signal_connect (GLADE_TEXT_BUTTON (cell_editable)->entry, "activate", + G_CALLBACK (glade_text_button_entry_activated), + cell_editable); + g_signal_connect (cell_editable, "key-press-event", + G_CALLBACK (glade_text_button_key_press_event), + cell_editable); } static void -glade_text_button_cell_editable_init (GtkCellEditableIface *iface) +glade_text_button_cell_editable_init (GtkCellEditableIface * iface) { - iface->start_editing = glade_text_button_start_editing; + iface->start_editing = glade_text_button_start_editing; } static void -glade_text_button_finalize (GObject *object) +glade_text_button_finalize (GObject * object) { - G_OBJECT_CLASS (glade_text_button_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_text_button_parent_class)->finalize (object); } static void -glade_text_button_grab_focus (GtkWidget *widget) +glade_text_button_grab_focus (GtkWidget * widget) { - GladeTextButton *text_button = GLADE_TEXT_BUTTON (widget); + GladeTextButton *text_button = GLADE_TEXT_BUTTON (widget); - gtk_widget_grab_focus (text_button->entry); + gtk_widget_grab_focus (text_button->entry); } /** @@ -169,5 +166,5 @@ glade_text_button_grab_focus (GtkWidget *widget) GtkWidget * glade_text_button_new (void) { - return g_object_new (GLADE_TYPE_TEXT_BUTTON, NULL); + return g_object_new (GLADE_TYPE_TEXT_BUTTON, NULL); } diff --git a/plugins/gtk+/glade-text-button.h b/plugins/gtk+/glade-text-button.h index eb69c35b..20d500c2 100644 --- a/plugins/gtk+/glade-text-button.h +++ b/plugins/gtk+/glade-text-button.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-tool-button-editor.c b/plugins/gtk+/glade-tool-button-editor.c index fa71a532..eab6c9d6 100644 --- a/plugins/gtk+/glade-tool-button-editor.c +++ b/plugins/gtk+/glade-tool-button-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -28,489 +27,528 @@ #include "glade-tool-button-editor.h" -static void glade_tool_button_editor_finalize (GObject *object); +static void glade_tool_button_editor_finalize (GObject * object); -static void glade_tool_button_editor_editable_init (GladeEditableIface *iface); +static void glade_tool_button_editor_editable_init (GladeEditableIface * iface); -static void glade_tool_button_editor_grab_focus (GtkWidget *widget); +static void glade_tool_button_editor_grab_focus (GtkWidget * widget); -G_DEFINE_TYPE_WITH_CODE (GladeToolButtonEditor, glade_tool_button_editor, GTK_TYPE_VBOX, +G_DEFINE_TYPE_WITH_CODE (GladeToolButtonEditor, glade_tool_button_editor, + GTK_TYPE_VBOX, G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_tool_button_editor_editable_init)); static void -glade_tool_button_editor_class_init (GladeToolButtonEditorClass *klass) +glade_tool_button_editor_class_init (GladeToolButtonEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_tool_button_editor_finalize; - widget_class->grab_focus = glade_tool_button_editor_grab_focus; + object_class->finalize = glade_tool_button_editor_finalize; + widget_class->grab_focus = glade_tool_button_editor_grab_focus; } static void -glade_tool_button_editor_init (GladeToolButtonEditor *self) +glade_tool_button_editor_init (GladeToolButtonEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeToolButtonEditor *button_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeToolButtonEditor * button_editor) { - if (button_editor->modifying || - !gtk_widget_get_mapped (GTK_WIDGET (button_editor))) - return; + if (button_editor->modifying || + !gtk_widget_get_mapped (GTK_WIDGET (button_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (button_editor), button_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -project_finalized (GladeToolButtonEditor *button_editor, - GladeProject *where_project_was) +project_finalized (GladeToolButtonEditor * button_editor, + GladeProject * where_project_was) { - button_editor->loaded_widget = NULL; + button_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (button_editor), NULL); + glade_editable_load (GLADE_EDITABLE (button_editor), NULL); } static void -glade_tool_button_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_tool_button_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (editable); - gboolean custom_label = FALSE, use_appearance = FALSE; - GladeToolButtonImageMode image_mode = 0; - GList *l; - - button_editor->loading = TRUE; - - /* Since we watch the project*/ - if (button_editor->loaded_widget) - { - g_signal_handlers_disconnect_by_func (G_OBJECT (button_editor->loaded_widget->project), - G_CALLBACK (project_changed), button_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (button_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - button_editor); - } - - /* Mark our widget... */ - button_editor->loaded_widget = widget; - - if (button_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (button_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), button_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (button_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - button_editor); - } - - /* load the embedded editable... */ - if (button_editor->embed) - glade_editable_load (GLADE_EDITABLE (button_editor->embed), widget); - - for (l = button_editor->properties; l; l = l->next) - glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); - - if (widget) - { - glade_widget_property_get (widget, "image-mode", &image_mode); - glade_widget_property_get (widget, "custom-label", &custom_label); - glade_widget_property_get (widget, "use-action-appearance", &use_appearance); - - if (custom_label) - gtk_toggle_button_set_active - (GTK_TOGGLE_BUTTON (button_editor->custom_label_radio), TRUE); - else - gtk_toggle_button_set_active - (GTK_TOGGLE_BUTTON (button_editor->standard_label_radio), TRUE); - - switch (image_mode) - { - case GLADE_TB_MODE_STOCK: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->stock_radio), TRUE); - break; - case GLADE_TB_MODE_ICON: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->icon_radio), TRUE); - break; - case GLADE_TB_MODE_CUSTOM: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->custom_radio), TRUE); - break; - default: - break; - } - - if (use_appearance) - { - gtk_widget_set_sensitive (button_editor->label_table, FALSE); - gtk_widget_set_sensitive (button_editor->image_table, FALSE); - } - else - { - gtk_widget_set_sensitive (button_editor->label_table, TRUE); - gtk_widget_set_sensitive (button_editor->image_table, TRUE); - } - } - button_editor->loading = FALSE; + GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (editable); + gboolean custom_label = FALSE, use_appearance = FALSE; + GladeToolButtonImageMode image_mode = 0; + GList *l; + + button_editor->loading = TRUE; + + /* Since we watch the project */ + if (button_editor->loaded_widget) + { + g_signal_handlers_disconnect_by_func (G_OBJECT + (button_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + button_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (button_editor->loaded_widget->project), + (GWeakNotify) project_finalized, button_editor); + } + + /* Mark our widget... */ + button_editor->loaded_widget = widget; + + if (button_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (button_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), button_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (button_editor->loaded_widget->project), + (GWeakNotify) project_finalized, button_editor); + } + + /* load the embedded editable... */ + if (button_editor->embed) + glade_editable_load (GLADE_EDITABLE (button_editor->embed), widget); + + for (l = button_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), + widget); + + if (widget) + { + glade_widget_property_get (widget, "image-mode", &image_mode); + glade_widget_property_get (widget, "custom-label", &custom_label); + glade_widget_property_get (widget, "use-action-appearance", + &use_appearance); + + if (custom_label) + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (button_editor->custom_label_radio), TRUE); + else + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (button_editor->standard_label_radio), TRUE); + + switch (image_mode) + { + case GLADE_TB_MODE_STOCK: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (button_editor->stock_radio), TRUE); + break; + case GLADE_TB_MODE_ICON: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (button_editor->icon_radio), TRUE); + break; + case GLADE_TB_MODE_CUSTOM: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (button_editor->custom_radio), TRUE); + break; + default: + break; + } + + if (use_appearance) + { + gtk_widget_set_sensitive (button_editor->label_table, FALSE); + gtk_widget_set_sensitive (button_editor->image_table, FALSE); + } + else + { + gtk_widget_set_sensitive (button_editor->label_table, TRUE); + gtk_widget_set_sensitive (button_editor->image_table, TRUE); + } + } + button_editor->loading = FALSE; } static void -standard_label_toggled (GtkWidget *widget, - GladeToolButtonEditor *button_editor) +standard_label_toggled (GtkWidget * widget, + GladeToolButtonEditor * button_editor) { - GladeProperty *property; - GValue value = { 0, }; + GladeProperty *property; + GValue value = { 0, }; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->standard_label_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->standard_label_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use standard label text"), button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use standard label text"), + button_editor->loaded_widget->name); - property = glade_widget_get_property (button_editor->loaded_widget, "label-widget"); - glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "label-widget"); + glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); - property = glade_widget_get_property (button_editor->loaded_widget, "custom-label"); - glade_command_set_property (property, FALSE); + property = glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + property = + glade_widget_get_property (button_editor->loaded_widget, "custom-label"); + glade_command_set_property (property, FALSE); - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -custom_label_toggled (GtkWidget *widget, - GladeToolButtonEditor *button_editor) +custom_label_toggled (GtkWidget * widget, GladeToolButtonEditor * button_editor) { - GladeProperty *property; + GladeProperty *property; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->custom_label_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->custom_label_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use a custom label widget"), button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use a custom label widget"), + button_editor->loaded_widget->name); - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "custom-label"); - glade_command_set_property (property, TRUE); + property = glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "custom-label"); + glade_command_set_property (property, TRUE); - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -stock_toggled (GtkWidget *widget, - GladeToolButtonEditor *button_editor) +stock_toggled (GtkWidget * widget, GladeToolButtonEditor * button_editor) { - GladeProperty *property; + GladeProperty *property; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->stock_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->stock_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an image from stock"), button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use an image from stock"), + button_editor->loaded_widget->name); - property = glade_widget_get_property (button_editor->loaded_widget, "icon-name"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "icon"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "icon-widget"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "image-mode"); - glade_command_set_property (property, GLADE_TB_MODE_STOCK); + property = + glade_widget_get_property (button_editor->loaded_widget, "icon-name"); + glade_command_set_property (property, NULL); + property = glade_widget_get_property (button_editor->loaded_widget, "icon"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "icon-widget"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "image-mode"); + glade_command_set_property (property, GLADE_TB_MODE_STOCK); - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -icon_toggled (GtkWidget *widget, - GladeToolButtonEditor *button_editor) +icon_toggled (GtkWidget * widget, GladeToolButtonEditor * button_editor) { - GladeProperty *property; + GladeProperty *property; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->icon_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->icon_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an image from the icon theme"), button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use an image from the icon theme"), + button_editor->loaded_widget->name); - property = glade_widget_get_property (button_editor->loaded_widget, "stock-id"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "icon"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "icon-widget"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "image-mode"); - glade_command_set_property (property, GLADE_TB_MODE_ICON); + property = + glade_widget_get_property (button_editor->loaded_widget, "stock-id"); + glade_command_set_property (property, NULL); + property = glade_widget_get_property (button_editor->loaded_widget, "icon"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "icon-widget"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "image-mode"); + glade_command_set_property (property, GLADE_TB_MODE_ICON); - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -custom_toggled (GtkWidget *widget, - GladeToolButtonEditor *button_editor) +custom_toggled (GtkWidget * widget, GladeToolButtonEditor * button_editor) { - GladeProperty *property; + GladeProperty *property; - if (button_editor->loading || !button_editor->loaded_widget) - return; + if (button_editor->loading || !button_editor->loaded_widget) + return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->custom_radio))) - return; + if (!gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (button_editor->custom_radio))) + return; - button_editor->modifying = TRUE; + button_editor->modifying = TRUE; - glade_command_push_group (_("Setting %s to use an image from the icon theme"), button_editor->loaded_widget->name); + glade_command_push_group (_("Setting %s to use an image from the icon theme"), + button_editor->loaded_widget->name); - property = glade_widget_get_property (button_editor->loaded_widget, "stock-id"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "icon-name"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "icon"); - glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "image-mode"); - glade_command_set_property (property, GLADE_TB_MODE_CUSTOM); + property = + glade_widget_get_property (button_editor->loaded_widget, "stock-id"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "icon-name"); + glade_command_set_property (property, NULL); + property = glade_widget_get_property (button_editor->loaded_widget, "icon"); + glade_command_set_property (property, NULL); + property = + glade_widget_get_property (button_editor->loaded_widget, "image-mode"); + glade_command_set_property (property, GLADE_TB_MODE_CUSTOM); - glade_command_pop_group (); + glade_command_pop_group (); - button_editor->modifying = FALSE; + button_editor->modifying = FALSE; - /* reload buttons and sensitivity and stuff... */ - glade_editable_load (GLADE_EDITABLE (button_editor), - button_editor->loaded_widget); + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (button_editor), + button_editor->loaded_widget); } static void -glade_tool_button_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_tool_button_editor_set_show_name (GladeEditable * editable, + gboolean show_name) { - GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (editable); + GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (button_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (button_editor->embed), + show_name); } static void -glade_tool_button_editor_editable_init (GladeEditableIface *iface) +glade_tool_button_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_tool_button_editor_load; - iface->set_show_name = glade_tool_button_editor_set_show_name; + iface->load = glade_tool_button_editor_load; + iface->set_show_name = glade_tool_button_editor_set_show_name; } static void -glade_tool_button_editor_finalize (GObject *object) +glade_tool_button_editor_finalize (GObject * object) { - GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (object); + GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (object); - if (button_editor->properties) - g_list_free (button_editor->properties); - button_editor->properties = NULL; - button_editor->embed = NULL; + if (button_editor->properties) + g_list_free (button_editor->properties); + button_editor->properties = NULL; + button_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_tool_button_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_tool_button_editor_parent_class)->finalize (object); } static void -glade_tool_button_editor_grab_focus (GtkWidget *widget) +glade_tool_button_editor_grab_focus (GtkWidget * widget) { - GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (widget); + GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (widget); - gtk_widget_grab_focus (button_editor->embed); + gtk_widget_grab_focus (button_editor->embed); } static void -table_attach (GtkWidget *table, - GtkWidget *child, - gint pos, gint row) +table_attach (GtkWidget * table, GtkWidget * child, gint pos, gint row) { - gtk_grid_attach (GTK_GRID (table), child, - pos, row, 1, 1); + gtk_grid_attach (GTK_GRID (table), child, pos, row, 1, 1); - if (pos) - gtk_widget_set_hexpand (child, TRUE); + if (pos) + gtk_widget_set_hexpand (child, TRUE); } GtkWidget * -glade_tool_button_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_tool_button_editor_new (GladeWidgetAdaptor * adaptor, + GladeEditable * embed) { - GladeToolButtonEditor *button_editor; - GladeEditorProperty *eprop; - GtkWidget *label, *alignment, *frame, *table, *hbox; - gchar *str; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - button_editor = g_object_new (GLADE_TYPE_TOOL_BUTTON_EDITOR, NULL); - button_editor->embed = GTK_WIDGET (embed); - - /* Pack the parent on top... */ - gtk_box_pack_start (GTK_BOX (button_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); - - /* Label area frame... */ - str = g_strdup_printf ("<b>%s</b>", _("Edit Label")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 12); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - button_editor->label_table = table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Standard label... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - button_editor->standard_label_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), button_editor->standard_label_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - /* Custom label... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "label-widget", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - button_editor->custom_label_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (button_editor->standard_label_radio)); - gtk_box_pack_start (GTK_BOX (hbox), button_editor->custom_label_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - /* Image area frame... */ - str = g_strdup_printf ("<b>%s</b>", _("Edit Image")); - label = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - g_free (str); - frame = gtk_frame_new (NULL); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 8); - - alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); - gtk_container_add (GTK_CONTAINER (frame), alignment); - - button_editor->image_table = table = gtk_grid_new (); - gtk_orientable_set_orientation (GTK_ORIENTABLE (table), GTK_ORIENTATION_VERTICAL); - gtk_grid_set_row_spacing (GTK_GRID (table), 4); - - gtk_container_add (GTK_CONTAINER (alignment), table); - - /* Stock image... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "stock-id", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - button_editor->stock_radio = gtk_radio_button_new (NULL); - gtk_box_pack_start (GTK_BOX (hbox), button_editor->stock_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 0); - table_attach (table, GTK_WIDGET (eprop), 1, 0); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - /* Icon theme image... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-name", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - button_editor->icon_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (button_editor->stock_radio)); - gtk_box_pack_start (GTK_BOX (hbox), button_editor->icon_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 1); - table_attach (table, GTK_WIDGET (eprop), 1, 1); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - /* Custom embedded image widget... */ - eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-widget", FALSE, TRUE); - hbox = gtk_hbox_new (FALSE, 0); - button_editor->custom_radio = gtk_radio_button_new_from_widget - (GTK_RADIO_BUTTON (button_editor->stock_radio)); - gtk_box_pack_start (GTK_BOX (hbox), button_editor->custom_radio, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); - table_attach (table, hbox, 0, 2); - table_attach (table, GTK_WIDGET (eprop), 1, 2); - button_editor->properties = g_list_prepend (button_editor->properties, eprop); - - /* Connect radio button signals... */ - g_signal_connect (G_OBJECT (button_editor->standard_label_radio), "toggled", - G_CALLBACK (standard_label_toggled), button_editor); - g_signal_connect (G_OBJECT (button_editor->custom_label_radio), "toggled", - G_CALLBACK (custom_label_toggled), button_editor); - g_signal_connect (G_OBJECT (button_editor->stock_radio), "toggled", - G_CALLBACK (stock_toggled), button_editor); - g_signal_connect (G_OBJECT (button_editor->icon_radio), "toggled", - G_CALLBACK (icon_toggled), button_editor); - g_signal_connect (G_OBJECT (button_editor->custom_radio), "toggled", - G_CALLBACK (custom_toggled), button_editor); - - gtk_widget_show_all (GTK_WIDGET (button_editor)); - - return GTK_WIDGET (button_editor); + GladeToolButtonEditor *button_editor; + GladeEditorProperty *eprop; + GtkWidget *label, *alignment, *frame, *table, *hbox; + gchar *str; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + button_editor = g_object_new (GLADE_TYPE_TOOL_BUTTON_EDITOR, NULL); + button_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (button_editor), GTK_WIDGET (embed), FALSE, FALSE, + 0); + + /* Label area frame... */ + str = g_strdup_printf ("<b>%s</b>", _("Edit Label")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 12); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + button_editor->label_table = table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Standard label... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE); + hbox = gtk_hbox_new (FALSE, 0); + button_editor->standard_label_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), button_editor->standard_label_radio, + FALSE, FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + /* Custom label... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "label-widget", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + button_editor->custom_label_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (button_editor->standard_label_radio)); + gtk_box_pack_start (GTK_BOX (hbox), button_editor->custom_label_radio, FALSE, + FALSE, 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + /* Image area frame... */ + str = g_strdup_printf ("<b>%s</b>", _("Edit Image")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 8); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + button_editor->image_table = table = gtk_grid_new (); + gtk_orientable_set_orientation (GTK_ORIENTABLE (table), + GTK_ORIENTATION_VERTICAL); + gtk_grid_set_row_spacing (GTK_GRID (table), 4); + + gtk_container_add (GTK_CONTAINER (alignment), table); + + /* Stock image... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "stock-id", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + button_editor->stock_radio = gtk_radio_button_new (NULL); + gtk_box_pack_start (GTK_BOX (hbox), button_editor->stock_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 0); + table_attach (table, GTK_WIDGET (eprop), 1, 0); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + /* Icon theme image... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-name", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + button_editor->icon_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (button_editor->stock_radio)); + gtk_box_pack_start (GTK_BOX (hbox), button_editor->icon_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 1); + table_attach (table, GTK_WIDGET (eprop), 1, 1); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + /* Custom embedded image widget... */ + eprop = + glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-widget", FALSE, + TRUE); + hbox = gtk_hbox_new (FALSE, 0); + button_editor->custom_radio = gtk_radio_button_new_from_widget + (GTK_RADIO_BUTTON (button_editor->stock_radio)); + gtk_box_pack_start (GTK_BOX (hbox), button_editor->custom_radio, FALSE, FALSE, + 2); + gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2); + table_attach (table, hbox, 0, 2); + table_attach (table, GTK_WIDGET (eprop), 1, 2); + button_editor->properties = g_list_prepend (button_editor->properties, eprop); + + /* Connect radio button signals... */ + g_signal_connect (G_OBJECT (button_editor->standard_label_radio), "toggled", + G_CALLBACK (standard_label_toggled), button_editor); + g_signal_connect (G_OBJECT (button_editor->custom_label_radio), "toggled", + G_CALLBACK (custom_label_toggled), button_editor); + g_signal_connect (G_OBJECT (button_editor->stock_radio), "toggled", + G_CALLBACK (stock_toggled), button_editor); + g_signal_connect (G_OBJECT (button_editor->icon_radio), "toggled", + G_CALLBACK (icon_toggled), button_editor); + g_signal_connect (G_OBJECT (button_editor->custom_radio), "toggled", + G_CALLBACK (custom_toggled), button_editor); + + gtk_widget_show_all (GTK_WIDGET (button_editor)); + + return GTK_WIDGET (button_editor); } diff --git a/plugins/gtk+/glade-tool-button-editor.h b/plugins/gtk+/glade-tool-button-editor.h index 21bc1220..5ecdd1b6 100644 --- a/plugins/gtk+/glade-tool-button-editor.h +++ b/plugins/gtk+/glade-tool-button-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * diff --git a/plugins/gtk+/glade-treeview-editor.c b/plugins/gtk+/glade-treeview-editor.c index cfcb96e7..6bf3ed71 100644 --- a/plugins/gtk+/glade-treeview-editor.c +++ b/plugins/gtk+/glade-treeview-editor.c @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * @@ -27,238 +26,257 @@ #include "glade-treeview-editor.h" -static void glade_tree_view_editor_finalize (GObject *object); +static void glade_tree_view_editor_finalize (GObject * object); -static void glade_tree_view_editor_editable_init (GladeEditableIface *iface); +static void glade_tree_view_editor_editable_init (GladeEditableIface * iface); -static void glade_tree_view_editor_realize (GtkWidget *widget); -static void glade_tree_view_editor_grab_focus (GtkWidget *widget); +static void glade_tree_view_editor_realize (GtkWidget * widget); +static void glade_tree_view_editor_grab_focus (GtkWidget * widget); -G_DEFINE_TYPE_WITH_CODE (GladeTreeViewEditor, glade_tree_view_editor, GTK_TYPE_HBOX, +G_DEFINE_TYPE_WITH_CODE (GladeTreeViewEditor, glade_tree_view_editor, + GTK_TYPE_HBOX, G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_tree_view_editor_editable_init)); static void -glade_tree_view_editor_class_init (GladeTreeViewEditorClass *klass) +glade_tree_view_editor_class_init (GladeTreeViewEditorClass * klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = glade_tree_view_editor_finalize; + object_class->finalize = glade_tree_view_editor_finalize; - widget_class->realize = glade_tree_view_editor_realize; - widget_class->grab_focus = glade_tree_view_editor_grab_focus; + widget_class->realize = glade_tree_view_editor_realize; + widget_class->grab_focus = glade_tree_view_editor_grab_focus; } static void -glade_tree_view_editor_init (GladeTreeViewEditor *self) +glade_tree_view_editor_init (GladeTreeViewEditor * self) { } static void -project_changed (GladeProject *project, - GladeCommand *command, - gboolean execute, - GladeTreeViewEditor *view_editor) +project_changed (GladeProject * project, + GladeCommand * command, + gboolean execute, GladeTreeViewEditor * view_editor) { - if (!gtk_widget_get_mapped (GTK_WIDGET (view_editor))) - return; + if (!gtk_widget_get_mapped (GTK_WIDGET (view_editor))) + return; - /* Reload on all commands */ - glade_editable_load (GLADE_EDITABLE (view_editor), view_editor->loaded_widget); + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (view_editor), + view_editor->loaded_widget); } static void -project_finalized (GladeTreeViewEditor *view_editor, - GladeProject *where_project_was) +project_finalized (GladeTreeViewEditor * view_editor, + GladeProject * where_project_was) { - view_editor->loaded_widget = NULL; + view_editor->loaded_widget = NULL; - glade_editable_load (GLADE_EDITABLE (view_editor), NULL); + glade_editable_load (GLADE_EDITABLE (view_editor), NULL); } static GladeWidget * -get_model_widget (GladeWidget *view) +get_model_widget (GladeWidget * view) { - GtkTreeModel *model = NULL; + GtkTreeModel *model = NULL; - if (GTK_IS_TREE_VIEW (view->object)) - model = gtk_tree_view_get_model (GTK_TREE_VIEW (view->object)); - else if (GTK_IS_ICON_VIEW (view->object)) - model = gtk_icon_view_get_model (GTK_ICON_VIEW (view->object)); - else if (GTK_IS_COMBO_BOX (view->object)) - model = gtk_combo_box_get_model (GTK_COMBO_BOX (view->object)); + if (GTK_IS_TREE_VIEW (view->object)) + model = gtk_tree_view_get_model (GTK_TREE_VIEW (view->object)); + else if (GTK_IS_ICON_VIEW (view->object)) + model = gtk_icon_view_get_model (GTK_ICON_VIEW (view->object)); + else if (GTK_IS_COMBO_BOX (view->object)) + model = gtk_combo_box_get_model (GTK_COMBO_BOX (view->object)); - if (model) - return glade_widget_get_from_gobject (model); - - return NULL; + if (model) + return glade_widget_get_from_gobject (model); + + return NULL; } static void -glade_tree_view_editor_load (GladeEditable *editable, - GladeWidget *widget) +glade_tree_view_editor_load (GladeEditable * editable, GladeWidget * widget) { - GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (editable); - GladeWidget *model_widget; - - /* Since we watch the project*/ - if (view_editor->loaded_widget) - { - g_signal_handlers_disconnect_by_func (G_OBJECT (view_editor->loaded_widget->project), - G_CALLBACK (project_changed), view_editor); - - /* The widget could die unexpectedly... */ - g_object_weak_unref (G_OBJECT (view_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - view_editor); - } - - /* Mark our widget... */ - view_editor->loaded_widget = widget; - - if (view_editor->loaded_widget) - { - /* This fires for undo/redo */ - g_signal_connect (G_OBJECT (view_editor->loaded_widget->project), "changed", - G_CALLBACK (project_changed), view_editor); - - /* The widget/project could die unexpectedly... */ - g_object_weak_ref (G_OBJECT (view_editor->loaded_widget->project), - (GWeakNotify)project_finalized, - view_editor); - } - - /* load the embedded editable... */ - if (view_editor->embed) - glade_editable_load (GLADE_EDITABLE (view_editor->embed), widget); - - if (view_editor->embed_list_store && view_editor->embed_tree_store) - { - gtk_widget_hide (view_editor->no_model_message); - gtk_widget_hide (view_editor->embed_list_store); - gtk_widget_hide (view_editor->embed_tree_store); - glade_editable_load (GLADE_EDITABLE (view_editor->embed_list_store), NULL); - glade_editable_load (GLADE_EDITABLE (view_editor->embed_tree_store), NULL); - - /* Finalize safe code here... */ - if (widget && (model_widget = get_model_widget (widget))) - { - if (GTK_IS_LIST_STORE (model_widget->object)) - { - gtk_widget_show (view_editor->embed_list_store); - glade_editable_load (GLADE_EDITABLE (view_editor->embed_list_store), model_widget); - } - else if (GTK_IS_TREE_STORE (model_widget->object)) - { - gtk_widget_show (view_editor->embed_tree_store); - glade_editable_load (GLADE_EDITABLE (view_editor->embed_tree_store), model_widget); - } - else - gtk_widget_show (view_editor->no_model_message); - } - else - gtk_widget_show (view_editor->no_model_message); - } + GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (editable); + GladeWidget *model_widget; + + /* Since we watch the project */ + if (view_editor->loaded_widget) + { + g_signal_handlers_disconnect_by_func (G_OBJECT + (view_editor->loaded_widget-> + project), + G_CALLBACK (project_changed), + view_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (view_editor->loaded_widget->project), + (GWeakNotify) project_finalized, view_editor); + } + + /* Mark our widget... */ + view_editor->loaded_widget = widget; + + if (view_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (view_editor->loaded_widget->project), + "changed", G_CALLBACK (project_changed), view_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (view_editor->loaded_widget->project), + (GWeakNotify) project_finalized, view_editor); + } + + /* load the embedded editable... */ + if (view_editor->embed) + glade_editable_load (GLADE_EDITABLE (view_editor->embed), widget); + + if (view_editor->embed_list_store && view_editor->embed_tree_store) + { + gtk_widget_hide (view_editor->no_model_message); + gtk_widget_hide (view_editor->embed_list_store); + gtk_widget_hide (view_editor->embed_tree_store); + glade_editable_load (GLADE_EDITABLE (view_editor->embed_list_store), + NULL); + glade_editable_load (GLADE_EDITABLE (view_editor->embed_tree_store), + NULL); + + /* Finalize safe code here... */ + if (widget && (model_widget = get_model_widget (widget))) + { + if (GTK_IS_LIST_STORE (model_widget->object)) + { + gtk_widget_show (view_editor->embed_list_store); + glade_editable_load (GLADE_EDITABLE + (view_editor->embed_list_store), + model_widget); + } + else if (GTK_IS_TREE_STORE (model_widget->object)) + { + gtk_widget_show (view_editor->embed_tree_store); + glade_editable_load (GLADE_EDITABLE + (view_editor->embed_tree_store), + model_widget); + } + else + gtk_widget_show (view_editor->no_model_message); + } + else + gtk_widget_show (view_editor->no_model_message); + } } static void -glade_tree_view_editor_set_show_name (GladeEditable *editable, - gboolean show_name) +glade_tree_view_editor_set_show_name (GladeEditable * editable, + gboolean show_name) { - GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (editable); + GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (editable); - glade_editable_set_show_name (GLADE_EDITABLE (view_editor->embed), show_name); + glade_editable_set_show_name (GLADE_EDITABLE (view_editor->embed), show_name); } static void -glade_tree_view_editor_editable_init (GladeEditableIface *iface) +glade_tree_view_editor_editable_init (GladeEditableIface * iface) { - iface->load = glade_tree_view_editor_load; - iface->set_show_name = glade_tree_view_editor_set_show_name; + iface->load = glade_tree_view_editor_load; + iface->set_show_name = glade_tree_view_editor_set_show_name; } static void -glade_tree_view_editor_finalize (GObject *object) +glade_tree_view_editor_finalize (GObject * object) { - GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (object); + GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (object); - view_editor->embed_tree_store = NULL; - view_editor->embed_list_store = NULL; - view_editor->embed = NULL; + view_editor->embed_tree_store = NULL; + view_editor->embed_list_store = NULL; + view_editor->embed = NULL; - glade_editable_load (GLADE_EDITABLE (object), NULL); + glade_editable_load (GLADE_EDITABLE (object), NULL); - G_OBJECT_CLASS (glade_tree_view_editor_parent_class)->finalize (object); + G_OBJECT_CLASS (glade_tree_view_editor_parent_class)->finalize (object); } static void -glade_tree_view_editor_realize (GtkWidget *widget) +glade_tree_view_editor_realize (GtkWidget * widget) { - GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (widget); + GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (widget); - GTK_WIDGET_CLASS (glade_tree_view_editor_parent_class)->realize (widget); + GTK_WIDGET_CLASS (glade_tree_view_editor_parent_class)->realize (widget); - glade_editable_load (GLADE_EDITABLE (view_editor), view_editor->loaded_widget); + glade_editable_load (GLADE_EDITABLE (view_editor), + view_editor->loaded_widget); } static void -glade_tree_view_editor_grab_focus (GtkWidget *widget) +glade_tree_view_editor_grab_focus (GtkWidget * widget) { - GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (widget); + GladeTreeViewEditor *view_editor = GLADE_TREE_VIEW_EDITOR (widget); - gtk_widget_grab_focus (view_editor->embed); + gtk_widget_grab_focus (view_editor->embed); } GtkWidget * -glade_tree_view_editor_new (GladeWidgetAdaptor *adaptor, - GladeEditable *embed) +glade_tree_view_editor_new (GladeWidgetAdaptor * adaptor, GladeEditable * embed) { - GladeTreeViewEditor *view_editor; - GtkWidget *vbox, *separator; - gchar *str; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); - - view_editor = g_object_new (GLADE_TYPE_TREE_VIEW_EDITOR, NULL); - view_editor->embed = GTK_WIDGET (embed); - - /* Pack the parent on the left... */ - gtk_box_pack_start (GTK_BOX (view_editor), GTK_WIDGET (embed), TRUE, TRUE, 8); - - separator = gtk_vseparator_new (); - gtk_box_pack_start (GTK_BOX (view_editor), separator, FALSE, FALSE, 0); - - /* ...and the vbox with datastore/label on the right */ - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (view_editor), vbox, TRUE, TRUE, 8); - - str = g_strdup_printf ("<b>%s</b>", _("Choose a Data Model and define some\n" - "columns in the data store first")); - view_editor->no_model_message = gtk_label_new (str); - gtk_label_set_use_markup (GTK_LABEL (view_editor->no_model_message), TRUE); - gtk_label_set_justify (GTK_LABEL (view_editor->no_model_message), GTK_JUSTIFY_CENTER); - - g_free (str); - - gtk_box_pack_start (GTK_BOX (vbox), view_editor->no_model_message, TRUE, TRUE, 0); - - view_editor->embed_list_store = (GtkWidget *)glade_widget_adaptor_create_editable - (glade_widget_adaptor_get_by_type (GTK_TYPE_LIST_STORE), GLADE_PAGE_GENERAL); - glade_editable_set_show_name (GLADE_EDITABLE (view_editor->embed_list_store), FALSE); - gtk_box_pack_start (GTK_BOX (vbox), view_editor->embed_list_store, TRUE, TRUE, 0); - - view_editor->embed_tree_store = (GtkWidget *)glade_widget_adaptor_create_editable - (glade_widget_adaptor_get_by_type (GTK_TYPE_TREE_STORE), GLADE_PAGE_GENERAL); - glade_editable_set_show_name (GLADE_EDITABLE (view_editor->embed_tree_store), FALSE); - gtk_box_pack_start (GTK_BOX (vbox), view_editor->embed_tree_store, TRUE, TRUE, 0); - - gtk_widget_show_all (GTK_WIDGET (view_editor)); - - return GTK_WIDGET (view_editor); + GladeTreeViewEditor *view_editor; + GtkWidget *vbox, *separator; + gchar *str; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + view_editor = g_object_new (GLADE_TYPE_TREE_VIEW_EDITOR, NULL); + view_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on the left... */ + gtk_box_pack_start (GTK_BOX (view_editor), GTK_WIDGET (embed), TRUE, TRUE, 8); + + separator = gtk_vseparator_new (); + gtk_box_pack_start (GTK_BOX (view_editor), separator, FALSE, FALSE, 0); + + /* ...and the vbox with datastore/label on the right */ + vbox = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (view_editor), vbox, TRUE, TRUE, 8); + + str = g_strdup_printf ("<b>%s</b>", _("Choose a Data Model and define some\n" + "columns in the data store first")); + view_editor->no_model_message = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (view_editor->no_model_message), TRUE); + gtk_label_set_justify (GTK_LABEL (view_editor->no_model_message), + GTK_JUSTIFY_CENTER); + + g_free (str); + + gtk_box_pack_start (GTK_BOX (vbox), view_editor->no_model_message, TRUE, TRUE, + 0); + + view_editor->embed_list_store = + (GtkWidget *) + glade_widget_adaptor_create_editable (glade_widget_adaptor_get_by_type + (GTK_TYPE_LIST_STORE), + GLADE_PAGE_GENERAL); + glade_editable_set_show_name (GLADE_EDITABLE (view_editor->embed_list_store), + FALSE); + gtk_box_pack_start (GTK_BOX (vbox), view_editor->embed_list_store, TRUE, TRUE, + 0); + + view_editor->embed_tree_store = + (GtkWidget *) + glade_widget_adaptor_create_editable (glade_widget_adaptor_get_by_type + (GTK_TYPE_TREE_STORE), + GLADE_PAGE_GENERAL); + glade_editable_set_show_name (GLADE_EDITABLE (view_editor->embed_tree_store), + FALSE); + gtk_box_pack_start (GTK_BOX (vbox), view_editor->embed_tree_store, TRUE, TRUE, + 0); + + gtk_widget_show_all (GTK_WIDGET (view_editor)); + + return GTK_WIDGET (view_editor); } diff --git a/plugins/gtk+/glade-treeview-editor.h b/plugins/gtk+/glade-treeview-editor.h index 569a2dcb..cdc7bff4 100644 --- a/plugins/gtk+/glade-treeview-editor.h +++ b/plugins/gtk+/glade-treeview-editor.h @@ -1,4 +1,3 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2008 Tristan Van Berkom. * |