diff --git a/demos/gtk-demo/theming.ui b/demos/gtk-demo/theming.ui index dfcb83f77a..58fea83495 100644 --- a/demos/gtk-demo/theming.ui +++ b/demos/gtk-demo/theming.ui @@ -11,41 +11,36 @@ + 1 Normal 1 1 edit-find - - 1 - + 1 Active 1 1 edit-find 1 - - 1 - + 1 0 Insensitive 1 1 edit-find - - 1 - + 1 Raised 1 1 @@ -54,12 +49,10 @@ - - 1 - + 1 Raised Active 1 1 @@ -69,12 +62,10 @@ - - 1 - + 1 0 Insensitive Active 1 @@ -82,9 +73,6 @@ 1 1 - - 1 - @@ -149,68 +137,56 @@ + 1 Normal 1 list-add-symbolic - - 1 - + 1 Normal 1 list-add-symbolic - - 1 - + 1 Active 1 list-remove-symbolic 1 - - 1 - + 1 Active 1 list-remove-symbolic 1 - - 1 - + 1 0 Insensitive 1 edit-find-symbolic - - 1 - + 1 0 Insensitive Active 1 go-up-symbolic 1 - - 1 - diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index 54384ef057..67377698e7 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -417,7 +417,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus. gear_menu open-menu-symbolic - @@ -1593,7 +1592,6 @@ microphone-sensitivity-medium-symbolic center emblem-system-symbolic - @@ -2844,6 +2842,7 @@ microphone-sensitivity-medium-symbolic + 1 0 @@ -2851,9 +2850,6 @@ microphone-sensitivity-medium-symbolic - - 1 - diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 4504d86353..7cfc0407a0 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -6520,6 +6520,7 @@ gtk_popover_get_type GtkPopoverMenu GtkPopoverMenu gtk_popover_menu_new +gtk_popover_menu_add_submenu gtk_popover_menu_open_submenu diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c index cf2e39a26e..862ab757a3 100644 --- a/gtk/gtkpaned.c +++ b/gtk/gtkpaned.c @@ -164,6 +164,10 @@ enum { PROP_MIN_POSITION, PROP_MAX_POSITION, PROP_WIDE_HANDLE, + PROP_RESIZE_CHILD1, + PROP_RESIZE_CHILD2, + PROP_SHRINK_CHILD1, + PROP_SHRINK_CHILD2, LAST_PROP, /* GtkOrientable */ @@ -194,16 +198,6 @@ static void gtk_paned_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gtk_paned_set_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void gtk_paned_get_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - GValue *value, - GParamSpec *pspec); static void gtk_paned_finalize (GObject *object); static void gtk_paned_measure (GtkWidget *widget, GtkOrientation orientation, @@ -372,8 +366,6 @@ gtk_paned_class_init (GtkPanedClass *class) container_class->forall = gtk_paned_forall; container_class->child_type = gtk_paned_child_type; container_class->set_focus_child = gtk_paned_set_focus_child; - container_class->set_child_property = gtk_paned_set_child_property; - container_class->get_child_property = gtk_paned_get_child_property; paned_class->cycle_child_focus = gtk_paned_cycle_child_focus; paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus; @@ -439,40 +431,60 @@ gtk_paned_class_init (GtkPanedClass *class) FALSE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); - g_object_class_install_properties (object_class, LAST_PROP, paned_props); - - g_object_class_override_property (object_class, - PROP_ORIENTATION, - "orientation"); - - /** - * GtkPaned:resize: + * GtkPaned:resize-child1: * - * The "resize" child property determines whether the child expands and + * The "resize-child1" property determines whether the first child expands and * shrinks along with the paned widget. */ - gtk_container_class_install_child_property (container_class, - CHILD_PROP_RESIZE, - g_param_spec_boolean ("resize", - P_("Resize"), - P_("If TRUE, the child expands and shrinks along with the paned widget"), - TRUE, - GTK_PARAM_READWRITE)); + paned_props[PROP_RESIZE_CHILD1] = + g_param_spec_boolean ("resize-child1", + P_("Resize first child"), + P_("If TRUE, the first child expands and shrinks along with the paned widget"), + TRUE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); /** - * GtkPaned:shrink: + * GtkPaned:resize-child2: * - * The "shrink" child property determines whether the child can be made + * The "resize-child2" property determines whether the second child expands and + * shrinks along with the paned widget. + */ + paned_props[PROP_RESIZE_CHILD2] = + g_param_spec_boolean ("resize-child2", + P_("Resize second child"), + P_("If TRUE, the second child expands and shrinks along with the paned widget"), + TRUE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + + /** + * GtkPaned:shrink-child1: + * + * The "shrink-child1" property determines whether the first child can be made * smaller than its requisition. */ - gtk_container_class_install_child_property (container_class, - CHILD_PROP_SHRINK, - g_param_spec_boolean ("shrink", - P_("Shrink"), - P_("If TRUE, the child can be made smaller than its requisition"), - TRUE, - GTK_PARAM_READWRITE)); + paned_props[PROP_SHRINK_CHILD1] = + g_param_spec_boolean ("shrink-child1", + P_("Shrink first child"), + P_("If TRUE, the first child can be made smaller than its requisition"), + TRUE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + + /** + * GtkPaned:shrink-child2: + * + * The "shrink-child2" property determines whether the second child can be made + * smaller than its requisition. + */ + paned_props[PROP_SHRINK_CHILD2] = + g_param_spec_boolean ("shrink-child2", + P_("Shrink second child"), + P_("If TRUE, the second child can be made smaller than its requisition"), + TRUE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + + g_object_class_install_properties (object_class, LAST_PROP, paned_props); + g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation"); /** * GtkPaned::cycle-child-focus: @@ -847,6 +859,38 @@ gtk_paned_set_property (GObject *object, case PROP_WIDE_HANDLE: gtk_paned_set_wide_handle (paned, g_value_get_boolean (value)); break; + case PROP_RESIZE_CHILD1: + if (priv->child1_resize != g_value_get_boolean (value)) + { + priv->child1_resize = g_value_get_boolean (value); + g_object_notify_by_pspec (object, pspec); + gtk_widget_queue_resize (GTK_WIDGET (object)); + } + break; + case PROP_RESIZE_CHILD2: + if (priv->child2_resize != g_value_get_boolean (value)) + { + priv->child2_resize = g_value_get_boolean (value); + g_object_notify_by_pspec (object, pspec); + gtk_widget_queue_resize (GTK_WIDGET (object)); + } + break; + case PROP_SHRINK_CHILD1: + if (priv->child1_shrink != g_value_get_boolean (value)) + { + priv->child1_shrink = g_value_get_boolean (value); + g_object_notify_by_pspec (object, pspec); + gtk_widget_queue_resize (GTK_WIDGET (object)); + } + break; + case PROP_SHRINK_CHILD2: + if (priv->child2_shrink != g_value_get_boolean (value)) + { + priv->child2_shrink = g_value_get_boolean (value); + g_object_notify_by_pspec (object, pspec); + gtk_widget_queue_resize (GTK_WIDGET (object)); + } + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -882,95 +926,24 @@ gtk_paned_get_property (GObject *object, case PROP_WIDE_HANDLE: g_value_set_boolean (value, gtk_paned_get_wide_handle (paned)); break; + case PROP_RESIZE_CHILD1: + g_value_set_boolean (value, priv->child1_resize); + break; + case PROP_RESIZE_CHILD2: + g_value_set_boolean (value, priv->child2_resize); + break; + case PROP_SHRINK_CHILD1: + g_value_set_boolean (value, priv->child1_shrink); + break; + case PROP_SHRINK_CHILD2: + g_value_set_boolean (value, priv->child2_shrink); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } -static void -gtk_paned_set_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GtkPaned *paned = GTK_PANED (container); - GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - gboolean old_value, new_value; - - g_assert (child == priv->child1 || child == priv->child2); - - new_value = g_value_get_boolean (value); - switch (property_id) - { - case CHILD_PROP_RESIZE: - if (child == priv->child1) - { - old_value = priv->child1_resize; - priv->child1_resize = new_value; - } - else - { - old_value = priv->child2_resize; - priv->child2_resize = new_value; - } - break; - case CHILD_PROP_SHRINK: - if (child == priv->child1) - { - old_value = priv->child1_shrink; - priv->child1_shrink = new_value; - } - else - { - old_value = priv->child2_shrink; - priv->child2_shrink = new_value; - } - break; - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - old_value = -1; /* quiet gcc */ - break; - } - if (old_value != new_value) - gtk_widget_queue_resize (GTK_WIDGET (container)); -} - -static void -gtk_paned_get_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GtkPaned *paned = GTK_PANED (container); - GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - - if (child != priv->child1 && - child != priv->child2) - return; - - switch (property_id) - { - case CHILD_PROP_RESIZE: - if (child == priv->child1) - g_value_set_boolean (value, priv->child1_resize); - else - g_value_set_boolean (value, priv->child2_resize); - break; - case CHILD_PROP_SHRINK: - if (child == priv->child1) - g_value_set_boolean (value, priv->child1_shrink); - else - g_value_set_boolean (value, priv->child2_shrink); - break; - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - break; - } -} - static void gtk_paned_finalize (GObject *object) { @@ -1393,6 +1366,10 @@ gtk_paned_init (GtkPaned *paned) priv->in_recursion = FALSE; priv->original_position = -1; priv->max_position = G_MAXINT; + priv->child1_resize = TRUE; + priv->child2_resize = TRUE; + priv->child1_shrink = TRUE; + priv->child2_shrink = TRUE; _gtk_orientable_set_style_classes (GTK_ORIENTABLE (paned)); diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c index b5e0d47a2e..241f02857d 100644 --- a/gtk/gtkpopovermenu.c +++ b/gtk/gtkpopovermenu.c @@ -35,10 +35,13 @@ * In this respect, GtkPopoverMenu is more flexible than popovers * that are created from a #GMenuModel with gtk_popover_new_from_model(). * - * To add a child as a submenu, set the #GtkPopoverMenu:submenu - * child property to the name of the submenu. To let the user open - * this submenu, add a #GtkModelButton whose #GtkModelButton:menu-name - * property is set to the name you've given to the submenu. + * To add a child as a submenu, use gtk_popover_menu_add_submenu(). + * To let the user open this submenu, add a #GtkModelButton whose + * #GtkModelButton:menu-name property is set to the name you've given + * to the submenu. + * + * To add a named submenu in a ui file, set the #GtkWidget:name property + * of the widget that you are adding as a child of the popover menu. * * By convention, the first child of a submenu should be a #GtkModelButton * to switch back to the parent menu. Such a button should use the @@ -75,6 +78,7 @@ * * True * 10 + * more * * * True @@ -90,9 +94,6 @@ * * * - * - * more - * * * * ]| @@ -114,10 +115,6 @@ enum { PROP_VISIBLE_SUBMENU = 1 }; -enum { - CHILD_PROP_SUBMENU = 1, -}; - G_DEFINE_TYPE (GtkPopoverMenu, gtk_popover_menu, GTK_TYPE_POPOVER) static void @@ -176,12 +173,14 @@ gtk_popover_menu_add (GtkContainer *container, { const char *name; - if (gtk_stack_get_child_by_name (GTK_STACK (stack), "main")) + if (gtk_widget_get_name (child)) + name = gtk_widget_get_name (child); + else if (gtk_stack_get_child_by_name (GTK_STACK (stack), "main")) name = "submenu"; else name = "main"; - gtk_stack_add_named (GTK_STACK (stack), child, name); + gtk_popover_menu_add_submenu (GTK_POPOVER_MENU (container), child, name); } } @@ -199,66 +198,6 @@ gtk_popover_menu_remove (GtkContainer *container, gtk_container_remove (GTK_CONTAINER (stack), child); } -static void -gtk_popover_menu_get_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GtkWidget *stack; - - stack = gtk_bin_get_child (GTK_BIN (container)); - - if (child == stack) - return; - - switch (property_id) - { - case CHILD_PROP_SUBMENU: - { - gchar *name; - gtk_container_child_get (GTK_CONTAINER (stack), child, "name", &name, NULL); - g_value_set_string (value, name); - } - break; - - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - break; - } -} - -static void -gtk_popover_menu_set_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GtkWidget *stack; - - stack = gtk_bin_get_child (GTK_BIN (container)); - - if (child == stack) - return; - - switch (property_id) - { - case CHILD_PROP_SUBMENU: - { - const gchar *name; - name = g_value_get_string (value); - gtk_container_child_set (GTK_CONTAINER (stack), child, "name", name, NULL); - } - break; - - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - break; - } -} - static void gtk_popover_menu_get_property (GObject *object, guint property_id, @@ -318,8 +257,6 @@ gtk_popover_menu_class_init (GtkPopoverMenuClass *klass) container_class->add = gtk_popover_menu_add; container_class->remove = gtk_popover_menu_remove; - container_class->set_child_property = gtk_popover_menu_set_child_property; - container_class->get_child_property = gtk_popover_menu_get_child_property; g_object_class_install_property (object_class, PROP_VISIBLE_SUBMENU, @@ -328,21 +265,6 @@ gtk_popover_menu_class_init (GtkPopoverMenuClass *klass) P_("The name of the visible submenu"), NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - /** - * GtkPopoverMenu:submenu: - * - * The submenu child property specifies the name of the submenu - * If it is %NULL or "main", the child is used as the main menu, - * which is shown initially when the popover is mapped. - */ - gtk_container_class_install_child_property (container_class, - CHILD_PROP_SUBMENU, - g_param_spec_string ("submenu", - P_("Submenu"), - P_("The name of the submenu"), - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } /** @@ -384,3 +306,23 @@ gtk_popover_menu_open_submenu (GtkPopoverMenu *popover, stack = gtk_bin_get_child (GTK_BIN (popover)); gtk_stack_set_visible_child_name (GTK_STACK (stack), name); } + +/** + * gtk_popover_menu_add_submenu: + * @popover: a #GtkPopoverMenu + * @submenu: a widget to add as submenu + * @name: the name for the submenu + * + * Adds a submenu to the popover menu. + */ +void +gtk_popover_menu_add_submenu (GtkPopoverMenu *popover, + GtkWidget *submenu, + const char *name) +{ + GtkWidget *stack; + + stack = gtk_bin_get_child (GTK_BIN (popover)); + + gtk_stack_add_named (GTK_STACK (stack), submenu, name); +} diff --git a/gtk/gtkpopovermenu.h b/gtk/gtkpopovermenu.h index c920f5c627..bf041b02ea 100644 --- a/gtk/gtkpopovermenu.h +++ b/gtk/gtkpopovermenu.h @@ -52,9 +52,13 @@ GType gtk_popover_menu_get_type (void) G_GNUC_CONST; GDK_AVAILABLE_IN_ALL GtkWidget * gtk_popover_menu_new (void); +GDK_AVAILABLE_IN_ALL +void gtk_popover_menu_add_submenu (GtkPopoverMenu *popover, + GtkWidget *menu, + const char *name); GDK_AVAILABLE_IN_ALL void gtk_popover_menu_open_submenu (GtkPopoverMenu *popover, - const gchar *name); + const char *name); G_END_DECLS diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 6c455cb3d4..e160874573 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -76,7 +76,7 @@ * to the toolbar, add an instance of #GtkToolButton. * * Toolbar items can be visually grouped by adding instances of - * #GtkSeparatorToolItem to the toolbar. If the GtkToolbar child property + * #GtkSeparatorToolItem to the toolbar. If the GtkToolItem property * “expand” is #TRUE and the property #GtkSeparatorToolItem:draw is set to * #FALSE, the effect is to force all following items to the end of the toolbar. * @@ -150,13 +150,6 @@ enum { PROP_TOOLTIPS, }; -/* Child properties */ -enum { - CHILD_PROP_0, - CHILD_PROP_EXPAND, - CHILD_PROP_HOMOGENEOUS -}; - /* Signals */ enum { ORIENTATION_CHANGED, @@ -195,16 +188,6 @@ static void gtk_toolbar_move_focus (GtkWidget *widget, GtkDirectionType dir); static void gtk_toolbar_display_changed (GtkWidget *widget, GdkDisplay *previous_display); -static void gtk_toolbar_set_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void gtk_toolbar_get_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - GValue *value, - GParamSpec *pspec); static void gtk_toolbar_finalize (GObject *object); static void gtk_toolbar_dispose (GObject *object); static void gtk_toolbar_add (GtkContainer *container, @@ -386,8 +369,6 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) container_class->remove = gtk_toolbar_remove; container_class->forall = gtk_toolbar_forall; container_class->child_type = gtk_toolbar_child_type; - container_class->get_child_property = gtk_toolbar_get_child_property; - container_class->set_child_property = gtk_toolbar_set_child_property; klass->orientation_changed = gtk_toolbar_orientation_changed; klass->style_changed = gtk_toolbar_real_style_changed; @@ -494,23 +475,6 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) TRUE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - /* child properties */ - gtk_container_class_install_child_property (container_class, - CHILD_PROP_EXPAND, - g_param_spec_boolean ("expand", - P_("Expand"), - P_("Whether the item should receive extra space when the toolbar grows"), - FALSE, - GTK_PARAM_READWRITE)); - - gtk_container_class_install_child_property (container_class, - CHILD_PROP_HOMOGENEOUS, - g_param_spec_boolean ("homogeneous", - P_("Homogeneous"), - P_("Whether the item should be the same size as other homogeneous items"), - FALSE, - GTK_PARAM_READWRITE)); - binding_set = gtk_binding_set_by_class (klass); add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT); @@ -2002,54 +1966,6 @@ gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar, gtk_toolbar_begin_sliding (toolbar); } -static void -gtk_toolbar_get_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GtkToolItem *item = GTK_TOOL_ITEM (child); - - switch (property_id) - { - case CHILD_PROP_HOMOGENEOUS: - g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item)); - break; - - case CHILD_PROP_EXPAND: - g_value_set_boolean (value, gtk_tool_item_get_expand (item)); - break; - - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - break; - } -} - -static void -gtk_toolbar_set_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) - { - case CHILD_PROP_HOMOGENEOUS: - gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value)); - break; - - case CHILD_PROP_EXPAND: - gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value)); - break; - - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - break; - } -} - static void gtk_toolbar_add (GtkContainer *container, GtkWidget *widget) diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c index ab0f78b7ef..d21389d138 100644 --- a/gtk/gtktoolitem.c +++ b/gtk/gtktoolitem.c @@ -68,6 +68,8 @@ enum { PROP_VISIBLE_HORIZONTAL, PROP_VISIBLE_VERTICAL, PROP_IS_IMPORTANT, + PROP_HOMOGENEOUS, + PROP_EXPAND_ITEM, }; @@ -144,6 +146,22 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) FALSE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + g_object_class_install_property (object_class, + PROP_EXPAND_ITEM, + g_param_spec_boolean ("expand-item", + P_("Expand Item"), + P_("Whether the item should receive extra space when the toolbar grows"), + FALSE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + + g_object_class_install_property (object_class, + PROP_HOMOGENEOUS, + g_param_spec_boolean ("homogeneous", + P_("Homogeneous"), + P_("Whether the item should be the same size as other homogeneous items"), + FALSE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + /** * GtkToolItem::create-menu-proxy: * @tool_item: the object the signal was emitted on @@ -261,6 +279,12 @@ gtk_tool_item_set_property (GObject *object, case PROP_IS_IMPORTANT: gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value)); break; + case PROP_EXPAND_ITEM: + gtk_tool_item_set_expand (toolitem, g_value_get_boolean (value)); + break; + case PROP_HOMOGENEOUS: + gtk_tool_item_set_homogeneous (toolitem, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -286,6 +310,12 @@ gtk_tool_item_get_property (GObject *object, case PROP_IS_IMPORTANT: g_value_set_boolean (value, toolitem->priv->is_important); break; + case PROP_EXPAND_ITEM: + g_value_set_boolean (value, toolitem->priv->expand); + break; + case PROP_HOMOGENEOUS: + g_value_set_boolean (value, toolitem->priv->homogeneous); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -508,7 +538,7 @@ gtk_tool_item_set_expand (GtkToolItem *tool_item, if (tool_item->priv->expand != expand) { tool_item->priv->expand = expand; - gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand"); + g_object_notify (G_OBJECT (tool_item), "expand-item"); gtk_widget_queue_resize (GTK_WIDGET (tool_item)); } } @@ -550,7 +580,7 @@ gtk_tool_item_set_homogeneous (GtkToolItem *tool_item, if (tool_item->priv->homogeneous != homogeneous) { tool_item->priv->homogeneous = homogeneous; - gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous"); + g_object_notify (G_OBJECT (tool_item), "homogeneous"); gtk_widget_queue_resize (GTK_WIDGET (tool_item)); } } diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c index 76dc3ea840..e447ac447d 100644 --- a/gtk/tools/gtk-builder-tool-simplify.c +++ b/gtk/tools/gtk-builder-tool-simplify.c @@ -183,6 +183,42 @@ needs_explicit_setting (GParamSpec *pspec, return found; } +static gboolean +keep_for_rewrite (const char *class_name, + const char *prop_name, + gboolean packing) +{ + struct _Prop { + const char *class; + const char *property; + gboolean packing; + } props[] = { + { "GtkActionBar", "pack-type", 1 }, + { "GtkHeaderBar", "pack-type", 1 }, + { "GtkPopoverMenu", "submenu", 1 }, + { "GtkToolbar", "expand", 1 }, + { "GtkToolbar", "homogeneous", 1 }, + { "GtkPaned", "resize", 1 }, + { "GtkPaned", "shrink", 1 }, + }; + gboolean found; + gint k; + + found = FALSE; + for (k = 0; k < G_N_ELEMENTS (props); k++) + { + if (strcmp (class_name, props[k].class) == 0 && + strcmp (prop_name, props[k].property) == 0 && + packing == props[k].packing) + { + found = TRUE; + break; + } + } + + return found; +} + static gboolean is_pcdata_element (Element *element) { @@ -323,6 +359,23 @@ value_is_default (MyParserData *data, return ret; } +static gboolean +has_attribute (Element *elt, + const char *name, + const char *value) +{ + int i; + + for (i = 0; elt->attribute_names[i]; i++) + { + if (strcmp (elt->attribute_names[i], name) == 0 && + (value == NULL || strcmp (elt->attribute_values[i], value) == 0)) + return TRUE; + } + + return FALSE; +} + static const char * get_attribute_value (Element *element, const char *name) @@ -426,9 +479,7 @@ property_can_be_omitted (Element *element, property_name = (const gchar *)element->attribute_values[i]; } - if ((strcmp (class_name, "GtkActionBar") == 0 || - strcmp (class_name, "GtkHeaderBar") == 0) && - strcmp (property_name, "pack-type") == 0) + if (keep_for_rewrite (class_name, property_name, packing)) return FALSE; /* keep, will be rewritten */ if (translatable) @@ -646,23 +697,6 @@ rewrite_assistant (Element *element, element->children = new_children; } -static gboolean -has_attribute (Element *elt, - const char *name, - const char *value) -{ - int i; - - for (i = 0; elt->attribute_names[i]; i++) - { - if (strcmp (elt->attribute_names[i], name) == 0 && - (value == NULL || strcmp (elt->attribute_values[i], value) == 0)) - return TRUE; - } - - return FALSE; -} - static Element * rewrite_notebook_page (Element *child, Element *tab, MyParserData *data) { @@ -792,10 +826,18 @@ rewrite_pack_type_child (Element *element, { pack_type = elt2; elt->children = g_list_remove (elt->children, pack_type); + if (elt->children == NULL) + { + element->children = g_list_remove (element->children, elt); + free_element (elt); + } break; } } } + + if (pack_type) + break; } if (pack_type) @@ -837,6 +879,195 @@ rewrite_pack_type (Element *element, } } +static void +rewrite_child_prop_to_prop_child (Element *element, + MyParserData *data, + const char *child_prop, + const char *prop) +{ + Element *object = NULL; + Element *replaced = NULL; + GList *l, *ll; + + if (!g_str_equal (element->element_name, "child")) + return; + + for (l = element->children; l; l = l->next) + { + Element *elt = l->data; + + if (g_str_equal (elt->element_name, "object")) + object = elt; + + if (g_str_equal (elt->element_name, "packing")) + { + for (ll = elt->children; ll; ll = ll->next) + { + Element *elt2 = ll->data; + + if (g_str_equal (elt2->element_name, "property") && + has_attribute (elt2, "name", child_prop)) + { + replaced = elt2; + elt->children = g_list_remove (elt->children, replaced); + if (elt->children == NULL) + { + element->children = g_list_remove (element->children, elt); + free_element (elt); + } + break; + } + } + } + + if (replaced) + break; + } + + if (replaced) + { + Element *elt; + + elt = g_new0 (Element, 1); + elt->parent = element; + elt->element_name = g_strdup ("property"); + elt->attribute_names = g_new0 (char *, 2); + elt->attribute_names[0] = g_strdup ("name"); + elt->attribute_values = g_new0 (char *, 2); + elt->attribute_values[0] = g_strdup (prop); + elt->data = g_strdup (replaced->data); + + object->children = g_list_prepend (object->children, elt); + + free_element (replaced); + } +} + +static void +rewrite_child_prop_to_prop (Element *element, + MyParserData *data, + const char *child_prop, + const char *prop) +{ + GList *l; + + for (l = element->children; l; l = l->next) + { + Element *elt = l->data; + if (g_str_equal (elt->element_name, "child")) + rewrite_child_prop_to_prop_child (elt, data, child_prop, prop); + } +} + +static void +rewrite_paned_child (Element *element, + MyParserData *data, + Element *child, + const char *suffix) +{ + Element *resize = NULL; + Element *shrink = NULL; + GList *l, *ll; + + for (l = child->children; l; l = l->next) + { + Element *elt = l->data; + + if (g_str_equal (elt->element_name, "packing")) + { + for (ll = elt->children; ll; ll = ll->next) + { + Element *elt2 = ll->data; + + if (g_str_equal (elt2->element_name, "property") && + has_attribute (elt2, "name", "resize")) + resize = elt2; + if (g_str_equal (elt2->element_name, "property") && + has_attribute (elt2, "name", "shrink")) + shrink = elt2; + } + if (resize) + elt->children = g_list_remove (elt->children, resize); + if (shrink) + elt->children = g_list_remove (elt->children, shrink); + if (elt->children == NULL) + { + child->children = g_list_remove (child->children, elt); + free_element (elt); + } + } + + if (resize || shrink) + break; + } + + if (resize) + { + Element *elt; + + elt = g_new0 (Element, 1); + elt->parent = element; + elt->element_name = g_strdup ("property"); + elt->attribute_names = g_new0 (char *, 2); + elt->attribute_names[0] = g_strdup ("name"); + elt->attribute_values = g_new0 (char *, 2); + elt->attribute_values[0] = g_strconcat ("resize-", suffix, NULL); + elt->data = g_strdup (resize->data); + + element->children = g_list_prepend (element->children, elt); + + free_element (resize); + } + + if (shrink) + { + Element *elt; + + elt = g_new0 (Element, 1); + elt->parent = element; + elt->element_name = g_strdup ("property"); + elt->attribute_names = g_new0 (char *, 2); + elt->attribute_names[0] = g_strdup ("name"); + elt->attribute_values = g_new0 (char *, 2); + elt->attribute_values[0] = g_strconcat ("shrink-", suffix, NULL); + elt->data = g_strdup (shrink->data); + + element->children = g_list_prepend (element->children, elt); + + free_element (shrink); + } +} + +static void +rewrite_paned (Element *element, + MyParserData *data) +{ + Element *child1 = NULL; + Element *child2 = NULL; + GList *l; + + for (l = element->children; l; l = l->next) + { + Element *elt = l->data; + + if (g_str_equal (elt->element_name, "child")) + { + if (child1 == NULL) + child1 = elt; + else if (child2 == NULL) + child2 = elt; + else + break; + } + } + + if (child1) + rewrite_paned_child (element, data, child1, "child1"); + + if (child2) + rewrite_paned_child (element, data, child2, "child2"); +} + static gboolean simplify_element (Element *element, MyParserData *data) @@ -892,6 +1123,22 @@ simplify_element (Element *element, g_str_equal (get_class_name (element), "GtkHeaderBar"))) rewrite_pack_type (element, data); + if (g_str_equal (element->element_name, "object") && + g_str_equal (get_class_name (element), "GtkPopoverMenu")) + rewrite_child_prop_to_prop (element, data, "submenu", "name"); + + if (g_str_equal (element->element_name, "object") && + g_str_equal (get_class_name (element), "GtkToolbar")) + rewrite_child_prop_to_prop (element, data, "expand", "expand-item"); + + if (g_str_equal (element->element_name, "object") && + g_str_equal (get_class_name (element), "GtkToolbar")) + rewrite_child_prop_to_prop (element, data, "homogeneous", "homogeneous"); + + if (g_str_equal (element->element_name, "object") && + g_str_equal (get_class_name (element), "GtkPaned")) + rewrite_paned (element, data); + if (g_str_equal (element->element_name, "property") && property_has_been_removed (element, data)) return TRUE; diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui index be94879214..84ea0e9f98 100644 --- a/gtk/ui/gtkfilechooserwidget.ui +++ b/gtk/ui/gtkfilechooserwidget.ui @@ -9,6 +9,9 @@ 1 + 0 + 0 + 0 1 @@ -22,10 +25,6 @@ - - 0 - 0 - @@ -332,9 +331,6 @@ - - 0 - @@ -361,7 +357,6 @@ - diff --git a/tests/popover2.ui b/tests/popover2.ui index 2e406fb751..23d8098e67 100644 --- a/tests/popover2.ui +++ b/tests/popover2.ui @@ -1,13 +1,10 @@ - - True vertical - True vertical 12 12 @@ -15,7 +12,6 @@ 3 - True start Edit - True List top.set-view - 'list' - True - True + 'list' + 1 + 1 icon-list - True Grid top.set-view - 'grid' - True - True + 'grid' + 1 + 1 icon-grid @@ -278,21 +233,18 @@ - True top.action5 Item 5c - True top.action5 Item 5d - True vertical 12 12 @@ -300,7 +252,6 @@ 3 - True start Format - True Bold top.bold - True - True + 1 + 1 - True Italic top.italic - True - True + 1 + 1 icon-italic - True Strikethrough top.strikethrough - True - True + 1 + 1 icon-strikethrough - True Underline top.underline - True - True + 1 + 1 icon-underline @@ -368,7 +309,6 @@ - True vertical 12 12 @@ -376,7 +316,6 @@ 3 - True start 6666