[Glade-devel] fill_empty method (was Helping out)



--=-Eh9i34+wwewcTiyZpvRW
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Sat, 2003-10-04 at 13:29, Joaquin Cuenca Abela wrote:
I'm also done with glade-widget-class, so please commit any pending
changes.


Attached there is a patch which turns fill_empty (the function which
takes care of filling the containers with placeholders) into a method of
GladeWidgetClass, since a generic function, like the one we have now,
doesn't work for every widget.
I made the patch some time ago and today I updated it to the current
cvs, but before committing I'd like to hear your opinions on some
issues.

1) For most of the containers fill_empty would simply do
gtk_container_add (GTK_CONTAINER(widget->widget),glade_placeholder_new ());
so I'd like to know which is the preferred way to handle this common
case. Among others I can at least think of 3 ways:
- Every widget has its <FillEmptyFunction> (ugly)
- Have a gtkcontainer.xml which declares the common <FillEmptyFunction>
and widgets inheriting from it can override the method if needed (I
don't know how to do it in practice)
- Handle it in glade_widget_fill_empty() and only the widgets which need
something different have a not NULL fill_empty method (this is what it
is in the patch now)

2) Somewhat related to the above. Some widgets (e.g. GtkButton) are
containers, but do not have to be filled with placeholders, this can be
handled in two way:
- adding more logic to glade_widget_fill_empty (like the current cvs
works)
- these widgets override the fill_empty method with the ignore()
function

3) With the attached patch applied [vh]box get wrong their size (e.g 4
placeholders instead of 3). The bug can be papered over be overriding
the fill_empty method of [vh]box with ignore(), but there seems to be
something wrong in glade_gtk_box_set_size... btw how do I set a gdb
breakpoint in glade_gtk_box_set_size now that it is in a shared library?

4) In the patch I only included glade_gtk_dialog_fill_empty and
glade_gtk_paned_fill_empty; of course also other widgets need to
override the method. With regard to GtkPaned, is it possible to create a
gtkpaned.xml, put the <FillEmptyFunction> there and have GtkVPaned and
GtkHPaned automagically inherit it or should both gtkhpaned.xml and
gtkvpaned.xml be created?

5) Last but not least note that the change allows to add the missing
placeholder to some containers (actually only gtkdialog in the patch
attached), but adding widgets to those containers doesn't work:
replace_placeholder method needs separate fixing and the problem of
"internal children" (eg GtkDialog->vbox) needs to be adressed.


I'm sorry to have so many questions about a so little patch, but I
thought they were worth asking.


ciao
        paolo

--=-Eh9i34+wwewcTiyZpvRW
Content-Disposition: attachment; filename=fillempty.patch
Content-Type: text/x-patch; name=fillempty.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

? autom4te.cache
? glade-3.desktop
? src/glade-3
Index: src/glade-gtk.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-gtk.c,v
retrieving revision 1.31
diff -u -r1.31 glade-gtk.c
--- src/glade-gtk.c     4 Oct 2003 10:36:30 -0000       1.31
+++ src/glade-gtk.c     4 Oct 2003 17:13:23 -0000
@@ -566,3 +566,20 @@
        }
 }
 
+/* ------------------------------------ Fill Empty functions ------------------------------- */
+void
+glade_gtk_dialog_fill_empty (GObject *dialog, GValue *notused)
+{
+       GtkWidget *vbox = GTK_DIALOG (dialog)->vbox;
+
+       gtk_box_pack_start_defaults (GTK_BOX (vbox), glade_placeholder_new ());
+}
+
+void
+glade_gtk_paned_fill_empty (GObject *paned, GValue *notused)
+{
+       gtk_paned_add1 (GTK_PANED (paned), glade_placeholder_new ());
+       gtk_paned_add2 (GTK_PANED (paned), glade_placeholder_new ());
+}
+
+
Index: src/glade-widget-class.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-widget-class.c,v
retrieving revision 1.40
diff -u -r1.40 glade-widget-class.c
--- src/glade-widget-class.c    4 Oct 2003 10:36:30 -0000       1.40
+++ src/glade-widget-class.c    4 Oct 2003 17:13:25 -0000
@@ -301,31 +301,41 @@
        GladeXmlNode *properties;
        GladeXmlNode *node;
        char *post_create_function_name;
+       char *fill_empty_function_name;
 
        g_return_val_if_fail (filename != NULL, FALSE);
 
        context = glade_xml_context_new_from_path (filename, NULL, GLADE_TAG_GLADE_WIDGET_CLASS);
-       if (context != NULL) {
-               doc = glade_xml_context_get_doc (context);
-               node = glade_xml_doc_get_root (doc);
-
-               post_create_function_name = glade_xml_get_value_string (node, GLADE_TAG_POST_CREATE_FUNCTION);
-               if (post_create_function_name && widget_class->module) {
-                       if (!g_module_symbol (widget_class->module, post_create_function_name, (void **) 
&widget_class->post_create_function))
-                               g_warning ("Could not find %s\n", post_create_function_name);
-               }
-               g_free (post_create_function_name);
-
-               properties = glade_xml_search_child (node, GLADE_TAG_PROPERTIES);
-               /* if we found a <properties> tag on the xml file, we add the properties
-                * that we read from the xml file to the class */
-               if (properties != NULL)
-                       glade_property_class_list_add_from_node (properties, widget_class, 
&widget_class->properties);
+       if (!context)
+               return FALSE;
 
-               return TRUE;
+       doc = glade_xml_context_get_doc (context);
+       node = glade_xml_doc_get_root (doc);
+       if (!doc || !node)
+               return FALSE;
+
+       post_create_function_name = glade_xml_get_value_string (node, GLADE_TAG_POST_CREATE_FUNCTION);
+       if (post_create_function_name && widget_class->module) {
+               if (!g_module_symbol (widget_class->module, post_create_function_name, (void **) 
&widget_class->post_create_function))
+                       g_warning ("Could not find %s\n", post_create_function_name);
        }
+       g_free (post_create_function_name);
 
-       return FALSE;
+       fill_empty_function_name = glade_xml_get_value_string (node, GLADE_TAG_FILL_EMPTY_FUNCTION);
+       if (fill_empty_function_name && widget_class->module) {
+               if (!g_module_symbol (widget_class->module, fill_empty_function_name, (void **) 
&widget_class->fill_empty))
+                       g_warning ("Could not find %s\n", fill_empty_function_name);
+       }
+       g_free (fill_empty_function_name);
+
+       /* if we found a <properties> tag on the xml file, we add the properties
+        * that we read from the xml file to the class.
+        */
+       properties = glade_xml_search_child (node, GLADE_TAG_PROPERTIES);
+       if (properties)
+               glade_property_class_list_add_from_node (properties, widget_class, &widget_class->properties);
+
+       return TRUE;
 }
 
 /**
Index: src/glade-widget-class.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-widget-class.h,v
retrieving revision 1.23
diff -u -r1.23 glade-widget-class.h
--- src/glade-widget-class.h    4 Oct 2003 10:36:30 -0000       1.23
+++ src/glade-widget-class.h    4 Oct 2003 17:13:25 -0000
@@ -77,6 +77,8 @@
 
        void (*post_create_function) (GObject *gobject);
 
+       void (*fill_empty) (GtkWidget *widget);
+
        gboolean in_palette;
 };
 
Index: src/glade-widget.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-widget.c,v
retrieving revision 1.73
diff -u -r1.73 glade-widget.c
--- src/glade-widget.c  4 Oct 2003 10:36:30 -0000       1.73
+++ src/glade-widget.c  4 Oct 2003 17:13:28 -0000
@@ -680,35 +680,15 @@
 }
 
 static void
-glade_widget_fill_empty (GtkWidget *widget)
+glade_widget_fill_empty (GladeWidget *widget)
 {
-       GList *children;
-       gboolean empty = TRUE;
-
-       if (!GTK_IS_CONTAINER (widget))
+       if (!GTK_IS_CONTAINER (widget->widget))
                return;
-       
-       /* fill with placeholders the containers that are inside of this container */
-       children = gtk_container_get_children (GTK_CONTAINER (widget));
-
-       /* loop over the children of this container, and fill them with placeholders */
-       while (children != NULL) {
-               glade_widget_fill_empty (GTK_WIDGET (children->data));
-               children = children->next;
-               empty = FALSE;
-       }
-
-       if (empty) {
-               /* retrieve the desired number of placeholders that this widget should hold */
-               int nb_children = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), 
"glade_nb_placeholders"));
-               int i;
 
-               if (nb_children == 0 && GTK_IS_BIN (widget))
-                       nb_children = 1;
-
-               for (i = nb_children; i > 0; i--)
-                       gtk_container_add (GTK_CONTAINER (widget), glade_placeholder_new ());
-       }
+       if (widget->class->fill_empty)
+               widget->class->fill_empty (widget->widget);
+       else
+               gtk_container_add (GTK_CONTAINER (widget->widget), glade_placeholder_new ());
 }
 
 static GtkWidget *
@@ -904,8 +884,8 @@
        glade_widget_apply_queried_properties (widget, result);
 
        /* If we are a container, add the placeholders */
-       if (g_type_is_a (class->type,  GTK_TYPE_CONTAINER))
-               glade_widget_fill_empty (widget->widget);
+       if (g_type_is_a (class->type, GTK_TYPE_CONTAINER))
+               glade_widget_fill_empty (widget);
 
        if (result) 
                glade_property_query_result_destroy (result);
Index: src/glade.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade.h,v
retrieving revision 1.25
diff -u -r1.25 glade.h
--- src/glade.h 2 Sep 2003 15:20:01 -0000       1.25
+++ src/glade.h 4 Oct 2003 17:13:28 -0000
@@ -93,6 +93,7 @@
 #define GLADE_TAG_DEFAULT      "Default"
 #define GLADE_TAG_DISABLED     "Disabled"
 #define GLADE_TAG_POST_CREATE_FUNCTION "PostCreateFunction"
+#define GLADE_TAG_FILL_EMPTY_FUNCTION "FillEmptyFunction"
 #define GLADE_TAG_IN_PALETTE   "InPalette"
 
 #define GLADE_TAG_CATALOG      "GladeCatalog"
Index: widgets/gtk-base.xml
===================================================================
RCS file: /cvs/gnome/glade3/widgets/gtk-base.xml,v
retrieving revision 1.5
diff -u -r1.5 gtk-base.xml
--- widgets/gtk-base.xml        4 Oct 2003 10:36:31 -0000       1.5
+++ widgets/gtk-base.xml        4 Oct 2003 17:13:29 -0000
@@ -33,7 +33,7 @@
   <GladeWidget name="GtkImage" generic_name="image"/>
   <GladeWidget name="GtkDrawingArea" generic_name="drawingarea"/>
   
-  <GladeWidget name="GtkDialog" generic_name="dialog"/>
+  <GladeWidget name="GtkDialog" generic_name="dialog" filename="gtkdialog.xml"/>
   <GladeWidget name="GtkMessageDialog" generic_name="messagedialog" filename="gtkmessagedialog.xml"/>
   <GladeWidget name="GtkFileSelection" generic_name="fileselection"/>
   <GladeWidget name="GtkColorSelectionDialog" generic_name="colorselectiondialog"/>
Index: widgets/gtkdialog.xml
===================================================================
RCS file: /cvs/gnome/glade3/widgets/gtkdialog.xml,v
retrieving revision 1.3
diff -u -r1.3 gtkdialog.xml
--- widgets/gtkdialog.xml       24 Aug 2003 21:35:39 -0000      1.3
+++ widgets/gtkdialog.xml       4 Oct 2003 17:13:29 -0000
@@ -1,37 +1,21 @@
 <GladeWidgetClass>
 
-  <Name>GtkDialog</Name>
-  <GenericName>dialog</GenericName>
-  <Toplevel>True</Toplevel>
-  <Placeholder>True</Placeholder>
   <PostCreateFunction>glade_gtk_dialog_post_create</PostCreateFunction>
+  <FillEmptyFunction>glade_gtk_dialog_fill_empty</FillEmptyFunction>
 
   <Properties>
 
-    <Property Id="has-separator"/>
-    <Property Id="border-width"/>
-    <Property Id="title"/>
-    <Property Id="type"/>
-    <Property Id="window-position"/>
     <Property Id="modal">
       <SetFunction>ignore</SetFunction>
     </Property>
     <Property Id="default-width"  Default="0" Optional="True" OptionalDefault="False"/>
     <Property Id="default-height" Default="0" Optional="True" OptionalDefault="False"/>
-    <Property Id="allow-grow"/>
-    <Property Id="allow-shrink"/>
-
-    <Property Common="True" Id="sensitive"/>
     <Property Common="True" Id="tooltip" ParamSpec="False" Name="Tooltip">
       <Type>String</Type>
-      <SetFunction>glade_gtk_widget_set_tooltip</SetFunction>
-      <GetFunction>glade_gtk_widget_get_tooltip</GetFunction>
+      <SetFunction>ignore</SetFunction>
+      <GetFunction>ignore</GetFunction>
     </Property>
-    <Property Common="True" Id="can-default"/>
-    <Property Common="True" Id="has-default"/>
-    <Property Common="True" Id="can-focus"/>
-    <Property Common="True" Id="extension-events"/>
 
   </Properties>
-  
+
 </GladeWidgetClass>
Index: widgets/gtkmessagedialog.xml
===================================================================
RCS file: /cvs/gnome/glade3/widgets/gtkmessagedialog.xml,v
retrieving revision 1.5
diff -u -r1.5 gtkmessagedialog.xml
--- widgets/gtkmessagedialog.xml        4 Oct 2003 15:28:00 -0000       1.5
+++ widgets/gtkmessagedialog.xml        4 Oct 2003 17:13:29 -0000
@@ -22,8 +22,8 @@
     <Property Common="True" Id="sensitive"/>
     <Property Common="True" Id="tooltip" ParamSpec="False" Name="Tooltip">
       <Type>String</Type>
-      <SetFunction>ignore</SetFunction>
-      <GetFunction>ignore</GetFunction>
+      <SetFunction>glade_gtk_widget_set_tooltip</SetFunction>
+      <GetFunction>glade_gtk_widget_get_tooltip</GetFunction>
     </Property>
     <Property Common="True" Id="can-default"/>
     <Property Common="True" Id="has-default"/>

--=-Eh9i34+wwewcTiyZpvRW--





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