[Glade-devel] [patch, glade3] editor.c cleanup



--=-kEfnqdGM/VByYza0TRLJ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

The patch attached is a trivial cleanups of glade-editor.c: mainly
gtk_object -> g_object, some long-lines splitted and a couple of
functions moved near their callers.

ciao
        paolo

--=-kEfnqdGM/VByYza0TRLJ
Content-Disposition: attachment; filename=ed_cleanups.patch
Content-Type: text/x-patch; name=ed_cleanups.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

diff -upr gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog     2003-04-23 04:42:11.000000000 +0200
+++ glade3/ChangeLog    2003-04-24 18:05:07.000000000 +0200
@@ -1,3 +1,7 @@
+2003-04-24  Paolo Borelli <pborelli katamail com>
+
+       * src/glade-editor.c: cleanups (gtk_object -> g_object);
+
 2003-04-22  Joaquin Cuenca Abela  <e98cuenc yahoo com>
 
        * src/main.c: remove the command line that you usually get on a
diff -upr gnome2/glade3/src/glade-editor.c glade3/src/glade-editor.c
--- gnome2/glade3/src/glade-editor.c    2003-04-22 22:21:28.000000000 +0200
+++ glade3/src/glade-editor.c   2003-04-24 18:03:46.000000000 +0200
@@ -21,8 +21,6 @@
  */
 
 
-#define GLADE_PROPERY_TABLE_ROW_SPACING 2
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -236,44 +234,6 @@ glade_editor_widget_name_changed (GtkWid
        glade_widget_set_name (widget, new_name);
 }
 
-static void
-glade_editor_table_attach (GtkWidget *table, GtkWidget *child, gint pos, gint row)
-{
-       gtk_table_attach (GTK_TABLE (table), child,
-                         pos, pos+1, row, row +1,
-                         GTK_EXPAND | GTK_FILL, 0, 0, 0);
-}
-
-
-
-static GladeEditorTable *
-glade_editor_table_new (GladeWidgetClass *class)
-{
-       GladeEditorTable *table;
-
-       table = g_new0 (GladeEditorTable, 1);
-
-       table->glade_widget_class = class;
-       table->table_widget = gtk_table_new (0, 0, FALSE);
-       table->properties = NULL;
-       table->rows = 0;
-
-       gtk_table_set_row_spacings (GTK_TABLE (table->table_widget),
-                                   GLADE_PROPERY_TABLE_ROW_SPACING);
-
-       return table;
-}
-
-
-
-
-
-
-
-
-
-
-
 /* ================================ Property Changed ==================================== */
 static void
 glade_editor_property_changed_text_common (GladeProperty *property, const gchar *text)
@@ -332,7 +292,7 @@ glade_editor_property_changed_text_view 
 
 static void
 glade_editor_property_changed_enum (GtkWidget *menu_item,
-                                     GladeEditorProperty *property)
+                                   GladeEditorProperty *property)
 {
        GladeChoice *choice;
        GValue *val;
@@ -343,7 +303,7 @@ glade_editor_property_changed_enum (GtkW
        if (property->property->loading)
                return;
        
-       choice = gtk_object_get_data (GTK_OBJECT (menu_item),
+       choice = g_object_get_data (G_OBJECT (menu_item),
                                      GLADE_ENUM_DATA_TAG);
        g_return_if_fail (choice != NULL);
 
@@ -392,7 +352,7 @@ glade_editor_property_changed_enabled (G
        
        state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
        gtk_widget_set_sensitive (spin, state);
-       property = gtk_object_get_user_data (GTK_OBJECT (button));
+       property = g_object_get_data (G_OBJECT (button), "user_data");
        property->property->enabled = state;
 }
 
@@ -409,7 +369,7 @@ glade_editor_property_changed_numeric (G
        if (property->property->loading)
                return;
 
-       numeric_type = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (spin), "NumericType"));
+       numeric_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (spin), "NumericType"));
        val = g_new0 (GValue, 1);
 
        switch (numeric_type) {
@@ -459,7 +419,8 @@ glade_editor_property_changed_boolean (G
        val = g_new0 (GValue, 1);
        g_value_init (val, G_TYPE_BOOLEAN);
        g_value_set_boolean (val, state);
-       glade_command_set_property (G_OBJECT (property->property->widget->widget), 
property->property->class->id, val);
+       glade_command_set_property (G_OBJECT (property->property->widget->widget),
+                                   property->property->class->id, val);
        g_free (val);
 }
 
@@ -485,7 +446,8 @@ glade_editor_property_changed_unichar (G
        val = g_new0 (GValue, 1);
        g_value_init (val, G_TYPE_UINT);
        g_value_set_uint (val, unich);
-       glade_command_set_property (G_OBJECT (property->property->widget->widget), 
property->property->class->id, val);
+       glade_command_set_property (G_OBJECT (property->property->widget->widget),
+                                   property->property->class->id, val);
        
        g_free (val);
        g_free (text);
@@ -496,7 +458,7 @@ static void glade_editor_property_delete
                                                  gint            end_pos)
 {
        gtk_editable_select_region (editable, 0, -1);
-       gtk_signal_emit_stop_by_name (GTK_OBJECT (editable), "delete_text");
+       g_signal_stop_emission_by_name (G_OBJECT (editable), "delete_text");
 }
 
 static void
@@ -506,39 +468,31 @@ glade_editor_property_insert_unichar (Gt
                                      gint        *position,
                                      gpointer     property)
 {
-       gtk_signal_handler_block_by_func (GTK_OBJECT (entry),
-                                         GTK_SIGNAL_FUNC (glade_editor_property_changed_unichar),
-                                         property);
-       gtk_signal_handler_block_by_func (GTK_OBJECT (entry),
-                                         GTK_SIGNAL_FUNC (glade_editor_property_insert_unichar),
-                                         property);
-       gtk_signal_handler_block_by_func (GTK_OBJECT (entry),
-                                         GTK_SIGNAL_FUNC (glade_editor_property_delete_unichar),
-                                         property);
+       g_signal_handlers_block_by_func (G_OBJECT (entry),
+                                        G_CALLBACK (glade_editor_property_changed_unichar),
+                                        property);
+       g_signal_handlers_block_by_func (G_OBJECT (entry),
+                                        G_CALLBACK (glade_editor_property_insert_unichar),
+                                        property);
+       g_signal_handlers_block_by_func (G_OBJECT (entry),
+                                        G_CALLBACK (glade_editor_property_delete_unichar),
+                                        property);
        gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
        *position = 0;
        gtk_editable_insert_text (GTK_EDITABLE (entry), text, 1, position);
-       gtk_signal_handler_unblock_by_func (GTK_OBJECT (entry),
-                                           GTK_SIGNAL_FUNC (glade_editor_property_changed_unichar),
-                                           property);
-       gtk_signal_handler_unblock_by_func (GTK_OBJECT (entry),
-                                           GTK_SIGNAL_FUNC (glade_editor_property_insert_unichar),
-                                           property);
-       gtk_signal_handler_unblock_by_func (GTK_OBJECT (entry),
-                                           GTK_SIGNAL_FUNC (glade_editor_property_delete_unichar),
-                                           property);
-       gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "insert_text");
+       g_signal_handlers_unblock_by_func (G_OBJECT (entry),
+                                          G_CALLBACK (glade_editor_property_changed_unichar),
+                                          property);
+       g_signal_handlers_unblock_by_func (G_OBJECT (entry),
+                                          G_CALLBACK (glade_editor_property_insert_unichar),
+                                          property);
+       g_signal_handlers_unblock_by_func (G_OBJECT (entry),
+                                          G_CALLBACK (glade_editor_property_delete_unichar),
+                                          property);
+       g_signal_stop_emission_by_name (G_OBJECT (entry), "insert_text");
        glade_editor_property_changed_unichar (entry, property);
 }
 
-
-
-
-
-
-
-
-
 /* ================================ Create inputs ==================================== */
 static GtkWidget *
 glade_editor_create_input_enum_item (GladeEditorProperty *property,
@@ -550,10 +504,11 @@ glade_editor_create_input_enum_item (Gla
        name = choice->name;
        menu_item = gtk_menu_item_new_with_label (name);
 
-       gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
-                           GTK_SIGNAL_FUNC (glade_editor_property_changed_enum), property);
+       g_signal_connect (G_OBJECT (menu_item), "activate",
+                         G_CALLBACK (glade_editor_property_changed_enum),
+                         property);
 
-       gtk_object_set_data (GTK_OBJECT (menu_item), GLADE_ENUM_DATA_TAG, choice);
+       g_object_set_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG, choice);
 
        return menu_item;
 }
@@ -601,8 +556,9 @@ glade_editor_create_input_text (GladeEdi
                
                entry = gtk_entry_new ();
 
-               gtk_signal_connect (GTK_OBJECT (entry), "changed",
-                                   GTK_SIGNAL_FUNC (glade_editor_property_changed_text), property);
+               g_signal_connect (G_OBJECT (entry), "changed",
+                                 G_CALLBACK (glade_editor_property_changed_text),
+                                 property);
 
                return entry;
        } else {
@@ -615,7 +571,7 @@ glade_editor_create_input_text (GladeEdi
                buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 
                g_signal_connect_data (G_OBJECT (buffer), "changed",
-                                      GTK_SIGNAL_FUNC (glade_editor_property_changed_text_view),
+                                      G_CALLBACK (glade_editor_property_changed_text_view),
                                       property, NULL, 0);
                
                return view;
@@ -626,7 +582,7 @@ glade_editor_create_input_text (GladeEdi
 
 static GtkWidget *
 glade_editor_create_input_numeric (GladeEditorProperty *property,
-                                                       GladeEditorNumericType numeric_type)
+                                  GladeEditorNumericType numeric_type)
 {
        GladePropertyClass *class;
        GtkAdjustment *adjustment;
@@ -639,12 +595,12 @@ glade_editor_create_input_numeric (Glade
        adjustment = glade_parameter_adjustment_new (class->parameters, class->def);
 
        spin  = gtk_spin_button_new (adjustment, 10,
-                                                   numeric_type == GLADE_EDITOR_INTEGER ? 0 : 2);
+                                    numeric_type == GLADE_EDITOR_INTEGER ? 0 : 2);
 
-       gtk_object_set_data (GTK_OBJECT (spin), "NumericType", GINT_TO_POINTER (numeric_type));
-       gtk_signal_connect (GTK_OBJECT (spin), "value_changed",
-                           GTK_SIGNAL_FUNC (glade_editor_property_changed_numeric),
-                           property);
+       g_object_set_data (G_OBJECT (spin), "NumericType", GINT_TO_POINTER (numeric_type));
+       g_signal_connect (G_OBJECT (spin), "value_changed",
+                         G_CALLBACK (glade_editor_property_changed_numeric),
+                         property);
 
        /* Some numeric types are optional, for example the default window size, so
         * they have a toggle button right next to the spin button. 
@@ -656,10 +612,10 @@ glade_editor_create_input_numeric (Glade
                hbox = gtk_hbox_new (FALSE, 0);
                gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0);
                gtk_box_pack_start (GTK_BOX (hbox), spin,  TRUE, TRUE, 0);
-               
-               gtk_signal_connect (GTK_OBJECT (check), "toggled",
-                                   GTK_SIGNAL_FUNC (glade_editor_property_changed_enabled),
-                                   property);
+
+               g_signal_connect (G_OBJECT (check), "toggled",
+                                 G_CALLBACK (glade_editor_property_changed_enabled),
+                                 property);
                return hbox;
        }
 
@@ -693,8 +649,9 @@ glade_editor_create_input_boolean (Glade
 
        button = gtk_toggle_button_new_with_label (_("No"));
 
-       gtk_signal_connect (GTK_OBJECT (button), "toggled",
-                           GTK_SIGNAL_FUNC (glade_editor_property_changed_boolean), property);
+       g_signal_connect (G_OBJECT (button), "toggled",
+                         G_CALLBACK (glade_editor_property_changed_boolean),
+                         property);
 
        return button;
 }
@@ -710,29 +667,40 @@ glade_editor_create_input_unichar (Glade
        /* it's 2 to prevent spirious beeps... */
        gtk_entry_set_max_length (GTK_ENTRY (entry), 2);
        
-       gtk_signal_connect (GTK_OBJECT (entry), "changed",
-                           GTK_SIGNAL_FUNC (glade_editor_property_changed_unichar), property);
-       gtk_signal_connect (GTK_OBJECT (entry), "insert_text",
-                           GTK_SIGNAL_FUNC (glade_editor_property_insert_unichar), property);
-       gtk_signal_connect (GTK_OBJECT (entry), "delete_text",
-                           GTK_SIGNAL_FUNC (glade_editor_property_delete_unichar), property);
+       g_signal_connect (G_OBJECT (entry), "changed",
+                         G_CALLBACK (glade_editor_property_changed_unichar), property);
+       g_signal_connect (G_OBJECT (entry), "insert_text",
+                         G_CALLBACK (glade_editor_property_insert_unichar), property);
+       g_signal_connect (G_OBJECT (entry), "delete_text",
+                         G_CALLBACK (glade_editor_property_delete_unichar), property);
 
        return entry;
 }
 
 static GtkWidget *
-glade_editor_create_input_object (GladeEditorProperty *property, GladeEditorTable *table)
+glade_editor_create_input_object (GladeEditorProperty *property,
+                                 GladeEditorTable *table)
 {
        g_return_val_if_fail (GLADE_IS_EDITOR_TABLE (table), NULL);
        g_return_val_if_fail (GLADE_IS_EDITOR_PROPERTY (property), NULL);
 
-       glade_editor_table_append_items (table, property->class->child, &property->children, FALSE);
+       glade_editor_table_append_items (table, property->class->child,
+                                        &property->children, FALSE);
 
        return NULL;
 }
 
+static void
+glade_editor_table_attach (GtkWidget *table, GtkWidget *child, gint pos, gint row)
+{
+       gtk_table_attach_defaults (GTK_TABLE (table), child,
+                                  pos, pos+1, row, row +1);
+
+}
+
 static GtkWidget *
-glade_editor_append_item_real (GladeEditorTable *table, GladeEditorProperty *property)
+glade_editor_append_item_real (GladeEditorTable *table,
+                              GladeEditorProperty *property)
 {
        GtkWidget *label;
        GtkWidget *input = NULL;
@@ -783,7 +751,6 @@ glade_editor_append_item_real (GladeEdit
                return gtk_label_new ("Implement me !");
        }
 
-
        label = glade_property_class_create_label (property->class);
        
        glade_editor_table_attach (table->table_widget, label, 0, table->rows);
@@ -823,9 +790,9 @@ glade_editor_table_append_standard_field
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
        entry = gtk_entry_new ();
        table->name_entry = entry;
-       gtk_signal_connect (GTK_OBJECT (entry), "changed",
-                           GTK_SIGNAL_FUNC (glade_editor_widget_name_changed),
-                           table->editor);
+       g_signal_connect (G_OBJECT (entry), "changed",
+                         G_CALLBACK (glade_editor_widget_name_changed),
+                         table->editor);
 
        glade_editor_table_attach (gtk_table, label, 0, table->rows);
        glade_editor_table_attach (gtk_table, entry, 1, table->rows);
@@ -894,16 +861,39 @@ glade_editor_on_edit_menu_click (GtkButt
                }
        }
 
-       /* if the user was able to click on the "Edit Menus...", that's because the menu bar was selected */
+       /* if the user was able to click on the "Edit Menus...",
+        * that's because the menu bar was selected
+        */
        g_assert (GTK_IS_MENU_BAR (menubar));
        
        menu_editor = glade_menu_editor_new (project, GTK_MENU_SHELL (menubar));
        gtk_widget_show (GTK_WIDGET (menu_editor));
 }
 
+#define GLADE_PROPERY_TABLE_ROW_SPACING 2
 
 static GladeEditorTable *
-glade_editor_table_create (GladeEditor *editor, GladeWidgetClass *class, gboolean common)
+glade_editor_table_new (GladeWidgetClass *class)
+{
+       GladeEditorTable *table;
+
+       table = g_new0 (GladeEditorTable, 1);
+
+       table->glade_widget_class = class;
+       table->table_widget = gtk_table_new (0, 0, FALSE);
+       table->properties = NULL;
+       table->rows = 0;
+
+       gtk_table_set_row_spacings (GTK_TABLE (table->table_widget),
+                                   GLADE_PROPERY_TABLE_ROW_SPACING);
+
+       return table;
+}
+
+static GladeEditorTable *
+glade_editor_table_create (GladeEditor *editor,
+                          GladeWidgetClass *class,
+                          gboolean common)
 {
        GladeEditorTable *table;
 
@@ -932,14 +922,15 @@ glade_editor_table_create (GladeEditor *
        }
 
        gtk_widget_show_all (table->table_widget);
-       editor->widget_tables = g_list_prepend (editor->widget_tables,
-                                               table);
+       editor->widget_tables = g_list_prepend (editor->widget_tables, table);
 
        return table;
 }
 
 static GladeEditorTable *
-glade_editor_get_table_from_class (GladeEditor *editor, GladeWidgetClass *class, gboolean common)
+glade_editor_get_table_from_class (GladeEditor *editor,
+                                  GladeWidgetClass *class,
+                                  gboolean common)
 {
        GladeEditorTable *table;
        GList *list;
@@ -1039,38 +1030,6 @@ glade_editor_load_class (GladeEditor *ed
        editor->loaded_class = class;
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 /* ================================ Load properties ================================== */
 static void
 glade_editor_property_set_tooltips (GladeEditorProperty *property)
@@ -1123,7 +1082,7 @@ glade_editor_property_load_integer (Glad
                gtk_widget_set_sensitive (GTK_WIDGET (spin), property->property->enabled);
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
                                              property->property->enabled);
-               gtk_object_set_user_data (GTK_OBJECT (button), property);
+               g_object_set_data (G_OBJECT (button), "user_data", property);
        } else {
                spin = property->input;
        }
@@ -1137,7 +1096,7 @@ glade_editor_property_load_integer (Glad
                val = g_value_get_float (property->property->value);
 
        gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), val);
-       gtk_object_set_user_data (GTK_OBJECT (spin), property);
+       g_object_set_data (G_OBJECT (spin), "user_data", property);
 }
 
 static void
@@ -1195,7 +1154,7 @@ glade_editor_property_load_enum (GladeEd
        list = GTK_MENU_SHELL (GTK_OPTION_MENU (property->input)->menu)->children;
        for (; list != NULL; list = list->next) {
                GtkMenuItem *menu_item = list->data;
-               gtk_object_set_user_data (GTK_OBJECT (menu_item), property);
+               g_object_set_data (G_OBJECT (menu_item), "user_data",  property);
        }
 }
 
@@ -1230,7 +1189,7 @@ glade_editor_property_load_boolean (Glad
        g_return_if_fail (GTK_IS_LABEL (label));
        gtk_label_set_text (GTK_LABEL (label), text [state]);
        
-       gtk_object_set_user_data (GTK_OBJECT (property->input), property);
+       g_object_set_data (G_OBJECT (property->input), "user_data", property);
 }
 
 static void
@@ -1268,7 +1227,7 @@ glade_editor_property_load_text (GladeEd
                g_warning ("Invalid Text Widget type.");
        }
 
-       gtk_object_set_user_data (GTK_OBJECT (property->input), property);
+       g_object_set_data (G_OBJECT (property->input), "user_data", property);
 }
 
 static void
@@ -1292,14 +1251,15 @@ glade_editor_property_load_unichar (Glad
                gtk_editable_insert_text (editable, utf8st, 1, &insert_pos);
        }
 
-       gtk_object_set_user_data (GTK_OBJECT (property->input), property);
+       g_object_set_data (G_OBJECT (property->input), "user_data", property);
 }
 
 /* We are recursing so we need the prototype beforehand. Don't you love C ? */
 static void glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget);
 
 static void
-glade_editor_property_load_object (GladeEditorProperty *property, GladeWidget *widget)
+glade_editor_property_load_object (GladeEditorProperty *property,
+                                  GladeWidget *widget)
 {
        GladeEditorProperty *child;
        GList *list;
@@ -1449,9 +1409,9 @@ glade_editor_property_connect_signals (G
 {
        GladeProperty *property = editor_property->property;
 
-       gtk_signal_connect (GTK_OBJECT (property), "changed",
-                           GTK_SIGNAL_FUNC (glade_editor_property_changed_cb),
-                           editor_property);
+       g_signal_connect (G_OBJECT (property), "changed",
+                         G_CALLBACK (glade_editor_property_changed_cb),
+                         editor_property);
 }
 
 static void
@@ -1537,8 +1497,9 @@ glade_editor_select_widget (GladeEditor 
 }
 
 void
-glade_editor_add_signal (GladeEditor *editor, guint signal_id,
-                             const char *callback_name)
+glade_editor_add_signal (GladeEditor *editor,
+                        guint signal_id,
+                        const char *callback_name)
 {
        const char *widget_name;
        const char *signal_name;

--=-kEfnqdGM/VByYza0TRLJ--





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]