diff options
-rw-r--r-- | gtk/gtkactionbar.c | 8 | ||||
-rw-r--r-- | gtk/gtkcellview.c | 14 | ||||
-rw-r--r-- | gtk/gtkcenterbox.c | 6 | ||||
-rw-r--r-- | gtk/gtkcombobox.c | 11 | ||||
-rw-r--r-- | gtk/gtkcontainer.c | 20 | ||||
-rw-r--r-- | gtk/gtkdialog.c | 2 | ||||
-rw-r--r-- | gtk/gtkexpander.c | 10 | ||||
-rw-r--r-- | gtk/gtkframe.c | 8 | ||||
-rw-r--r-- | gtk/gtkheaderbar.c | 8 | ||||
-rw-r--r-- | gtk/gtkiconview.c | 14 | ||||
-rw-r--r-- | gtk/gtklistbox.c | 8 | ||||
-rw-r--r-- | gtk/gtknotebook.c | 53 | ||||
-rw-r--r-- | gtk/gtkoverlay.c | 25 | ||||
-rw-r--r-- | gtk/gtktreeview.c | 5 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 18 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 4 |
16 files changed, 144 insertions, 70 deletions
diff --git a/gtk/gtkactionbar.c b/gtk/gtkactionbar.c index d0f64669a6..e5e5ba7920 100644 --- a/gtk/gtkactionbar.c +++ b/gtk/gtkactionbar.c @@ -428,6 +428,8 @@ gtk_action_bar_init (GtkActionBar *action_bar) gtk_container_add (GTK_CONTAINER (priv->revealer), priv->center_box); } +static GtkBuildableIface *parent_buildable_iface; + static void gtk_action_bar_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, @@ -438,14 +440,10 @@ gtk_action_bar_buildable_add_child (GtkBuildable *buildable, if (type && strcmp (type, "center") == 0) gtk_action_bar_set_center_widget (action_bar, GTK_WIDGET (child)); - else if (!type) - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (action_bar, type); + parent_buildable_iface->add_child (buildable, builder, child, type); } -static GtkBuildableIface *parent_buildable_iface; - static void gtk_action_bar_buildable_interface_init (GtkBuildableIface *iface) { diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c index 0a0a4485a4..ae52674ac3 100644 --- a/gtk/gtkcellview.c +++ b/gtk/gtkcellview.c @@ -269,10 +269,22 @@ gtk_cell_view_class_init (GtkCellViewClass *klass) } static void +gtk_cell_view_buildable_add_child (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *type) +{ + if (GTK_IS_CELL_RENDERER (child)) + _gtk_cell_layout_buildable_add_child (buildable, builder, child, type); + else + parent_buildable_iface->add_child (buildable, builder, child, type); +} + +static void gtk_cell_view_buildable_init (GtkBuildableIface *iface) { parent_buildable_iface = g_type_interface_peek_parent (iface); - iface->add_child = _gtk_cell_layout_buildable_add_child; + iface->add_child = gtk_cell_view_buildable_add_child; iface->custom_tag_start = gtk_cell_view_buildable_custom_tag_start; iface->custom_tag_end = gtk_cell_view_buildable_custom_tag_end; } diff --git a/gtk/gtkcenterbox.c b/gtk/gtkcenterbox.c index 83d378f9a0..2d3354c0d7 100644 --- a/gtk/gtkcenterbox.c +++ b/gtk/gtkcenterbox.c @@ -88,6 +88,8 @@ enum { PROP_ORIENTATION }; +static GtkBuildableIface *parent_buildable_iface; + static void gtk_center_box_buildable_init (GtkBuildableIface *iface); G_DEFINE_TYPE_WITH_CODE (GtkCenterBox, gtk_center_box, GTK_TYPE_WIDGET, @@ -107,12 +109,14 @@ gtk_center_box_buildable_add_child (GtkBuildable *buildable, else if (g_strcmp0 (type, "end") == 0) gtk_center_box_set_end_widget (GTK_CENTER_BOX (buildable), GTK_WIDGET (child)); else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_CENTER_BOX (buildable), type); + parent_buildable_iface->add_child (buildable, builder, child, type); } static void gtk_center_box_buildable_init (GtkBuildableIface *iface) { + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_center_box_buildable_add_child; } diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index 25e325dc36..60190425ed 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -3053,13 +3053,10 @@ gtk_combo_box_buildable_add_child (GtkBuildable *buildable, GObject *child, const gchar *type) { - if (GTK_IS_WIDGET (child)) - { - parent_buildable_iface->add_child (buildable, builder, child, type); - return; - } - - _gtk_cell_layout_buildable_add_child (buildable, builder, child, type); + if (GTK_IS_CELL_RENDERER (child)) + _gtk_cell_layout_buildable_add_child (buildable, builder, child, type); + else + parent_buildable_iface->add_child (buildable, builder, child, type); } static gboolean diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index 888d9d59d2..731bdb1da0 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -392,18 +392,22 @@ gtk_container_buildable_add_child (GtkBuildable *buildable, GObject *child, const gchar *type) { - if (type) + if (GTK_IS_WIDGET (child) && + _gtk_widget_get_parent (GTK_WIDGET (child)) == NULL) { - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type); + if (type) + { + GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type); + } + else + { + gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); + } } - else if (GTK_IS_WIDGET (child) && - _gtk_widget_get_parent (GTK_WIDGET (child)) == NULL) + else { - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); + parent_buildable_iface->add_child (buildable, builder, child, type); } - else - g_warning ("Cannot add an object of type %s to a container of type %s", - g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable))); } static inline void diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index 103ab7cf9e..3c7acf5895 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -1560,7 +1560,7 @@ gtk_dialog_buildable_add_child (GtkBuildable *buildable, GtkDialogPrivate *priv = dialog->priv; if (type == NULL) - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); + parent_buildable_iface->add_child (buildable, builder, child, type); else if (g_str_equal (type, "titlebar")) { priv->headerbar = GTK_WIDGET (child); diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c index db794ee3e6..0777fc39a6 100644 --- a/gtk/gtkexpander.c +++ b/gtk/gtkexpander.c @@ -378,23 +378,25 @@ gtk_expander_init (GtkExpander *expander) GTK_PHASE_BUBBLE); } +static GtkBuildableIface *parent_buildable_iface; + static void gtk_expander_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type) { - if (!type) - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); - else if (strcmp (type, "label") == 0) + if (g_strcmp0 (type, "label") == 0) gtk_expander_set_label_widget (GTK_EXPANDER (buildable), GTK_WIDGET (child)); else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_EXPANDER (buildable), type); + parent_buildable_iface->add_child (buildable, builder, child, type); } static void gtk_expander_buildable_init (GtkBuildableIface *iface) { + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_expander_buildable_add_child; } diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c index 38dea2211d..62a8428dc6 100644 --- a/gtk/gtkframe.c +++ b/gtk/gtkframe.c @@ -206,9 +206,13 @@ gtk_frame_class_init (GtkFrameClass *class) gtk_widget_class_set_css_name (widget_class, I_("frame")); } +static GtkBuildableIface *parent_buildable_iface; + static void gtk_frame_buildable_init (GtkBuildableIface *iface) { + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_frame_buildable_add_child; } @@ -220,10 +224,8 @@ gtk_frame_buildable_add_child (GtkBuildable *buildable, { if (type && strcmp (type, "label") == 0) gtk_frame_set_label_widget (GTK_FRAME (buildable), GTK_WIDGET (child)); - else if (!type) - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_FRAME (buildable), type); + parent_buildable_iface->add_child (buildable, builder, child, type); } static void diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c index c5e3d5c8d8..6c42ebb845 100644 --- a/gtk/gtkheaderbar.c +++ b/gtk/gtkheaderbar.c @@ -1988,6 +1988,8 @@ gtk_header_bar_init (GtkHeaderBar *bar) construct_label_box (bar); } +static GtkBuildableIface *parent_buildable_iface; + static void gtk_header_bar_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, @@ -1996,15 +1998,15 @@ gtk_header_bar_buildable_add_child (GtkBuildable *buildable, { if (type && strcmp (type, "title") == 0) gtk_header_bar_set_custom_title (GTK_HEADER_BAR (buildable), GTK_WIDGET (child)); - else if (!type) - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_HEADER_BAR (buildable), type); + parent_buildable_iface->add_child (buildable, builder, child, type); } static void gtk_header_bar_buildable_init (GtkBuildableIface *iface) { + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_header_bar_buildable_add_child; } diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c index ff7ca21cd6..a1718c1790 100644 --- a/gtk/gtkiconview.c +++ b/gtk/gtkiconview.c @@ -889,10 +889,22 @@ gtk_icon_view_class_init (GtkIconViewClass *klass) } static void +gtk_icon_view_buildable_add_child (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *type) +{ + if (GTK_IS_CELL_RENDERER (child)) + _gtk_cell_layout_buildable_add_child (buildable, builder, child, type); + else + parent_buildable_iface->add_child (buildable, builder, child, type); +} + +static void gtk_icon_view_buildable_init (GtkBuildableIface *iface) { parent_buildable_iface = g_type_interface_peek_parent (iface); - iface->add_child = _gtk_cell_layout_buildable_add_child; + iface->add_child = gtk_icon_view_buildable_add_child; iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start; iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end; } diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 311661b8e2..c258836185 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -180,6 +180,8 @@ enum { #define BOX_PRIV(box) ((GtkListBoxPrivate*)gtk_list_box_get_instance_private ((GtkListBox*)(box))) #define ROW_PRIV(row) ((GtkListBoxRowPrivate*)gtk_list_box_row_get_instance_private ((GtkListBoxRow*)(row))) +static GtkBuildableIface *parent_buildable_iface; + static void gtk_list_box_buildable_interface_init (GtkBuildableIface *iface); static void gtk_list_box_row_actionable_iface_init (GtkActionableInterface *iface); @@ -3474,15 +3476,15 @@ gtk_list_box_buildable_add_child (GtkBuildable *buildable, { if (type && strcmp (type, "placeholder") == 0) gtk_list_box_set_placeholder (GTK_LIST_BOX (buildable), GTK_WIDGET (child)); - else if (!type) - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type); + parent_buildable_iface->add_child (buildable, builder, child, type); } static void gtk_list_box_buildable_interface_init (GtkBuildableIface *iface) { + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_list_box_buildable_add_child; } diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 57b554adb3..80abd55d56 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -1124,9 +1124,13 @@ gtk_notebook_init (GtkNotebook *notebook) GTK_STYLE_CLASS_FRAME); } +static GtkBuildableIface *parent_buildable_iface; + static void gtk_notebook_buildable_init (GtkBuildableIface *iface) { + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_notebook_buildable_add_child; } @@ -1138,31 +1142,38 @@ gtk_notebook_buildable_add_child (GtkBuildable *buildable, { GtkNotebook *notebook = GTK_NOTEBOOK (buildable); - if (type && strcmp (type, "tab") == 0) + if (GTK_IS_WIDGET (child)) { - GtkWidget * page; - - page = gtk_notebook_get_nth_page (notebook, -1); - /* To set the tab label widget, we must have already a child - * inside the tab container. */ - g_assert (page != NULL); - /* warn when Glade tries to overwrite label */ - if (gtk_notebook_get_tab_label (notebook, page)) - g_warning ("Overriding tab label for notebook"); - gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child)); - } - else if (type && strcmp (type, "action-start") == 0) - { - gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_START); + if (type && strcmp (type, "tab") == 0) + { + GtkWidget * page; + + page = gtk_notebook_get_nth_page (notebook, -1); + /* To set the tab label widget, we must have already a child + * inside the tab container. */ + g_assert (page != NULL); + /* warn when Glade tries to overwrite label */ + if (gtk_notebook_get_tab_label (notebook, page)) + g_warning ("Overriding tab label for notebook"); + gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child)); + } + else if (type && strcmp (type, "action-start") == 0) + { + gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_START); + } + else if (type && strcmp (type, "action-end") == 0) + { + gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_END); + } + else if (!type) + gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL); + else + GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type); } - else if (type && strcmp (type, "action-end") == 0) + else { - gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_END); + parent_buildable_iface->add_child (buildable, builder, child, type); } - else if (!type) - gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL); - else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type); } static gboolean diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c index 785865730d..0b2b44e3f0 100644 --- a/gtk/gtkoverlay.c +++ b/gtk/gtkoverlay.c @@ -838,27 +838,38 @@ gtk_overlay_init (GtkOverlay *overlay) gtk_widget_set_has_surface (GTK_WIDGET (overlay), FALSE); } +static GtkBuildableIface *parent_buildable_iface; + static void gtk_overlay_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type) { - if (type && strcmp (type, "overlay") == 0) - gtk_overlay_add_overlay (GTK_OVERLAY (buildable), GTK_WIDGET (child)); - else if (!type) + if (GTK_IS_WIDGET (child)) { - /* Make sure the main-child node is the first one */ - gtk_widget_insert_after (GTK_WIDGET (child), GTK_WIDGET (buildable), NULL); - _gtk_bin_set_child (GTK_BIN (buildable), GTK_WIDGET (child)); + if (type && strcmp (type, "overlay") == 0) + gtk_overlay_add_overlay (GTK_OVERLAY (buildable), GTK_WIDGET (child)); + else if (!type) + { + /* Make sure the main-child node is the first one */ + gtk_widget_insert_after (GTK_WIDGET (child), GTK_WIDGET (buildable), NULL); + _gtk_bin_set_child (GTK_BIN (buildable), GTK_WIDGET (child)); + } + else + GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type); } else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type); + { + parent_buildable_iface->add_child (buildable, builder, child, type); + } } static void gtk_overlay_buildable_init (GtkBuildableIface *iface) { + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_overlay_buildable_add_child; } diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index a00c0bd4dd..3b0795b1cd 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -1971,7 +1971,10 @@ gtk_tree_view_buildable_add_child (GtkBuildable *tree_view, GObject *child, const gchar *type) { - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (child)); + if (GTK_IS_TREE_VIEW_COLUMN (child)) + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (child)); + else + parent_buildable_iface->add_child (tree_view, builder, child, type); } static GObject * diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index b4361c65f7..50286e39a2 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -9947,7 +9947,23 @@ gtk_widget_buildable_add_child (GtkBuildable *buildable, GObject *child, const gchar *type) { - gtk_widget_set_parent (GTK_WIDGET (child), GTK_WIDGET (buildable)); + if (type != NULL) + { + GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type); + } + if (GTK_IS_WIDGET (child)) + { + gtk_widget_set_parent (GTK_WIDGET (child), GTK_WIDGET (buildable)); + } + else if (GTK_IS_EVENT_CONTROLLER (child)) + { + gtk_widget_add_controller (GTK_WIDGET (buildable), g_object_ref (GTK_EVENT_CONTROLLER (child))); + } + else + { + g_warning ("Cannot add an object of type %s to a widget of type %s", + g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable))); + } } static void diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 72ec97cac6..0b090e323c 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -2229,10 +2229,8 @@ gtk_window_buildable_add_child (GtkBuildable *buildable, { if (type && strcmp (type, "titlebar") == 0) gtk_window_set_titlebar (GTK_WINDOW (buildable), GTK_WIDGET (child)); - else if (!type) - gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child)); else - GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type); + parent_buildable_iface->add_child (buildable, builder, child, type); } static void |