From bf24da0d80188964fd477d07dedad5221a85cb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 07:58:36 +0200 Subject: [PATCH 01/15] inspector: Add a type check We only connect to this signal if sl->obejct is a GtkAccessible, so only disconnect from it on the same condition. Fixes #2980 --- gtk/inspector/a11y.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gtk/inspector/a11y.c b/gtk/inspector/a11y.c index 8207c47d52..49934a4a0e 100644 --- a/gtk/inspector/a11y.c +++ b/gtk/inspector/a11y.c @@ -390,7 +390,8 @@ gtk_inspector_a11y_set_object (GtkInspectorA11y *sl, GtkWidget *stack; GtkStackPage *page; GtkATContext *context; - if (sl->object) + + if (sl->object && GTK_IS_ACCESSIBLE (sl->object)) { context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (sl->object)); g_signal_handlers_disconnect_by_func (context, refresh_all, sl); @@ -426,7 +427,7 @@ dispose (GObject *o) { GtkInspectorA11y *sl = GTK_INSPECTOR_A11Y (o); - if (sl->object) + if (sl->object && GTK_IS_ACCESSIBLE (sl->object)) { GtkATContext *context; From 954a144336160e0090aef9d3744a48fb3329e217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 08:07:43 +0200 Subject: [PATCH 02/15] mediastream demo: Add a weak pointer to the window Do what other demos do as well. Fixes 2983 --- demos/gtk-demo/paintable_mediastream.c | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/gtk-demo/paintable_mediastream.c b/demos/gtk-demo/paintable_mediastream.c index f9c4c42ffe..022c156d8a 100644 --- a/demos/gtk-demo/paintable_mediastream.c +++ b/demos/gtk-demo/paintable_mediastream.c @@ -293,6 +293,7 @@ do_paintable_mediastream (GtkWidget *do_widget) gtk_widget_get_display (do_widget)); gtk_window_set_title (GTK_WINDOW (window), "Nuclear MediaStream"); gtk_window_set_default_size (GTK_WINDOW (window), 300, 200); + g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window); nuclear = gtk_nuclear_media_stream_new (); gtk_media_stream_set_loop (GTK_MEDIA_STREAM (nuclear), TRUE); From 0822de1971245d575cad9b40d67d53b0490e211f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 08:41:55 +0200 Subject: [PATCH 03/15] textview: Only show "insert emoji" menu item if editable Fixes #2974 --- gtk/gtktextview.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 81f14a175c..528754e138 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -3107,6 +3107,7 @@ gtk_text_view_set_editable (GtkTextView *text_view, gtk_accessible_update_property (GTK_ACCESSIBLE (text_view), GTK_ACCESSIBLE_PROPERTY_READ_ONLY, !setting, -1); + gtk_text_view_update_emoji_action (text_view); g_object_notify (G_OBJECT (text_view), "editable"); } @@ -8531,7 +8532,8 @@ static void gtk_text_view_update_emoji_action (GtkTextView *text_view) { gtk_widget_action_set_enabled (GTK_WIDGET (text_view), "misc.insert-emoji", - (gtk_text_view_get_input_hints (text_view) & GTK_INPUT_HINT_NO_EMOJI) == 0); + (gtk_text_view_get_input_hints (text_view) & GTK_INPUT_HINT_NO_EMOJI) == 0 && + text_view->priv->editable); } static GMenuModel * From ebaea07286bcba051b3980a8c7308aab1eac031f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 08:56:34 +0200 Subject: [PATCH 04/15] inspector: Avoid some failing casts We might be inspecting a non-widget here, so can't just cast that. --- gtk/inspector/window.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c index 7d7ec56f4b..61b3a9aed9 100644 --- a/gtk/inspector/window.c +++ b/gtk/inspector/window.c @@ -919,9 +919,15 @@ update_go_buttons (GtkInspectorWindow *iw) switch (kind) { case CHILD_KIND_WIDGET: - update_go_button (iw->go_down_button, gtk_widget_get_first_child (GTK_WIDGET (object)) != NULL, "First child"); - update_go_button (iw->go_previous_button, gtk_widget_get_prev_sibling (GTK_WIDGET (object)) != NULL, "Previous sibling"); - update_go_button (iw->go_next_button, gtk_widget_get_next_sibling (GTK_WIDGET (object)) != NULL, "Next sibling"); + update_go_button (iw->go_down_button, + GTK_IS_WIDGET (object) &>k_widget_get_first_child (GTK_WIDGET (object)) != NULL, + "First child"); + update_go_button (iw->go_previous_button, + GTK_IS_WIDGET (object) && gtk_widget_get_prev_sibling (GTK_WIDGET (object)) != NULL, + "Previous sibling"); + update_go_button (iw->go_next_button, + GTK_IS_WIDGET (object) && gtk_widget_get_next_sibling (GTK_WIDGET (object)) != NULL, + "Next sibling"); gtk_widget_hide (iw->list_position_label); break; case CHILD_KIND_LISTITEM: From 547842e7f06a096a3c998b136889976219675d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 09:30:48 +0200 Subject: [PATCH 05/15] window: Keep titlebar after main child Fixes #2949 --- gtk/gtkwindow.c | 10 +++++----- testsuite/css/style/bloomfilter-not.nodes | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index c9da4da3d2..984e766be0 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -132,8 +132,8 @@ * * |[ * window.background - * ├── .titlebar [.default-decoration] - * ╰── + * ├── + * ╰── .titlebar [.default-decoration] * ]| * * GtkWindow has a main CSS node with name window and style class .background. @@ -2824,7 +2824,7 @@ gtk_window_set_titlebar (GtkWindow *window, gtk_window_enable_csd (window); priv->title_box = titlebar; - gtk_widget_insert_after (priv->title_box, widget, NULL); + gtk_widget_insert_before (priv->title_box, widget, NULL); gtk_widget_add_css_class (titlebar, GTK_STYLE_CLASS_TITLEBAR); @@ -4308,7 +4308,7 @@ gtk_window_realize (GtkWidget *widget) gtk_widget_add_css_class (priv->titlebar, GTK_STYLE_CLASS_TITLEBAR); gtk_widget_add_css_class (priv->titlebar, "default-decoration"); - gtk_widget_insert_after (priv->titlebar, widget, NULL); + gtk_widget_insert_before (priv->titlebar, widget, NULL); priv->title_box = priv->titlebar; } @@ -7084,7 +7084,7 @@ gtk_window_set_child (GtkWindow *window, if (child) { priv->child = child; - gtk_widget_set_parent (child, GTK_WIDGET (window)); + gtk_widget_insert_before (child, GTK_WIDGET (window), priv->title_box); } g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_CHILD]); diff --git a/testsuite/css/style/bloomfilter-not.nodes b/testsuite/css/style/bloomfilter-not.nodes index 05eed05b8c..97701dc4cb 100644 --- a/testsuite/css/style/bloomfilter-not.nodes +++ b/testsuite/css/style/bloomfilter-not.nodes @@ -1,4 +1,8 @@ window.background.csd:dir(ltr) + stack:dir(ltr) + box.horizontal:dir(ltr) + box.horizontal:dir(ltr) + box.horizontal:dir(ltr) headerbar.titlebar:dir(ltr) windowhandle:dir(ltr) box:dir(ltr) @@ -15,7 +19,3 @@ window.background.csd:dir(ltr) button.text-button.toggle:dir(ltr) label:dir(ltr) box.end.horizontal:dir(ltr) - stack:dir(ltr) - box.horizontal:dir(ltr) - box.horizontal:dir(ltr) - box.horizontal:dir(ltr) From 76f2396764c67427ba801105729ec56ba82703e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 10:31:38 +0200 Subject: [PATCH 06/15] popover: Use gtk_widget_add_css_class --- gtk/gtkpopover.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c index d77d225a1e..e670d7f40c 100644 --- a/gtk/gtkpopover.c +++ b/gtk/gtkpopover.c @@ -870,8 +870,7 @@ gtk_popover_init (GtkPopover *popover) gtk_widget_set_layout_manager (priv->contents_widget, gtk_bin_layout_new ()); gtk_widget_set_parent (priv->contents_widget, GTK_WIDGET (popover)); - gtk_css_node_add_class (gtk_widget_get_css_node (GTK_WIDGET (popover)), - g_quark_from_static_string (GTK_STYLE_CLASS_BACKGROUND)); + gtk_widget_add_css_class (widget, "background"); add_actions (popover); } From b37b85333df88f90a3cb8bd7f7a12680cd42ce15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 10:31:53 +0200 Subject: [PATCH 07/15] adwaita: Reset popover background in backdrop Otherwise it inherits the generic background color from .background Fixes #2766 --- gtk/theme/Adwaita/_common.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss index 104f09d707..a2f4eab20b 100644 --- a/gtk/theme/Adwaita/_common.scss +++ b/gtk/theme/Adwaita/_common.scss @@ -1738,6 +1738,10 @@ popover.background { box-shadow: 0 1px 2px transparentize(black, 0.7); } + &:backdrop { + background-color: transparent; + } + > contents { padding: 8px; border-radius: $popover_radius; From f5af18738b3514bdc8f1bf3f90a0a70fe994c83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 15:26:28 +0200 Subject: [PATCH 08/15] listbox: Add _append To have easy replacement API for gtk_container_add. --- docs/reference/gtk/gtk4-sections.txt | 1 + gtk/gtklistbox.c | 16 ++++++++++++++++ gtk/gtklistbox.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 85bcb0038c..cb4fced509 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -257,6 +257,7 @@ GtkListBoxUpdateHeaderFunc gtk_list_box_new gtk_list_box_prepend +gtk_list_box_append gtk_list_box_insert gtk_list_box_remove gtk_list_box_select_row diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index a95c87457a..443ac6fa2d 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -2584,6 +2584,22 @@ gtk_list_box_prepend (GtkListBox *box, gtk_list_box_insert (box, child, 0); } +/** + * gtk_list_box_append: + * @box: a #GtkListBox + * @child: the #GtkWidget to add + * + * Append a widget to the list. If a sort function is set, the widget will + * actually be inserted at the calculated position and this function has the + * same effect of gtk_container_add(). + */ +void +gtk_list_box_append (GtkListBox *box, + GtkWidget *child) +{ + gtk_list_box_insert (box, child, -1); +} + /** * gtk_list_box_insert: * @box: a #GtkListBox diff --git a/gtk/gtklistbox.h b/gtk/gtklistbox.h index b39f55154a..301a5707a5 100644 --- a/gtk/gtklistbox.h +++ b/gtk/gtklistbox.h @@ -168,6 +168,9 @@ GDK_AVAILABLE_IN_ALL void gtk_list_box_prepend (GtkListBox *box, GtkWidget *child); GDK_AVAILABLE_IN_ALL +void gtk_list_box_append (GtkListBox *box, + GtkWidget *child); +GDK_AVAILABLE_IN_ALL void gtk_list_box_insert (GtkListBox *box, GtkWidget *child, int position); From 2f65459fcc6f415af5472ceb67486212b8121b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 15:26:53 +0200 Subject: [PATCH 09/15] stack: Only compare page names if the new page has one --- gtk/gtkstack.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c index 51a39bfd1f..364def9be5 100644 --- a/gtk/gtkstack.c +++ b/gtk/gtkstack.c @@ -1348,14 +1348,17 @@ gtk_stack_add_page (GtkStack *stack, g_return_if_fail (child_info->widget != NULL); - for (l = priv->children; l != NULL; l = l->next) + if (child_info->name) { - GtkStackPage *info = l->data; - if (info->name && - g_strcmp0 (info->name, child_info->name) == 0) + for (l = priv->children; l != NULL; l = l->next) { - g_warning ("While adding page: duplicate child name in GtkStack: %s", child_info->name); - break; + GtkStackPage *info = l->data; + if (info->name && + g_strcmp0 (info->name, child_info->name) == 0) + { + g_warning ("While adding page: duplicate child name in GtkStack: %s", child_info->name); + break; + } } } From b489a1f6b55c42d1242ab047cc37c5c868de5133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 15:27:13 +0200 Subject: [PATCH 10/15] stack: Allow NULL names Does this work? --- gtk/gtkstack.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c index 364def9be5..5517c62220 100644 --- a/gtk/gtkstack.c +++ b/gtk/gtkstack.c @@ -1270,7 +1270,7 @@ stack_child_visibility_notify_cb (GObject *obj, * gtk_stack_add_titled: * @stack: a #GtkStack * @child: the widget to add - * @name: the name for @child + * @name: (nullable): the name for @child * @title: a human-readable title for @child * * Adds a child to @stack. @@ -1282,9 +1282,9 @@ stack_child_visibility_notify_cb (GObject *obj, */ GtkStackPage * gtk_stack_add_titled (GtkStack *stack, - GtkWidget *child, - const char *name, - const char *title) + GtkWidget *child, + const char *name, + const char *title) { g_return_val_if_fail (GTK_IS_STACK (stack), NULL); g_return_val_if_fail (GTK_IS_WIDGET (child), NULL); @@ -1296,7 +1296,7 @@ gtk_stack_add_titled (GtkStack *stack, * gtk_stack_add_named: * @stack: a #GtkStack * @child: the widget to add - * @name: the name for @child + * @name: (nullable): the name for @child or %NULL * * Adds a child to @stack. * The child is identified by the @name. @@ -1305,8 +1305,8 @@ gtk_stack_add_titled (GtkStack *stack, */ GtkStackPage * gtk_stack_add_named (GtkStack *stack, - GtkWidget *child, - const char *name) + GtkWidget *child, + const char *name) { g_return_val_if_fail (GTK_IS_STACK (stack), NULL); g_return_val_if_fail (GTK_IS_WIDGET (child), NULL); From e976825342510f1c019589eef2fb63742ece44eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 15:34:07 +0200 Subject: [PATCH 11/15] button: Use g_object_notify_by_pspec() --- gtk/gtkbutton.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index d85d65ca48..ca2d0607d9 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -1035,7 +1035,7 @@ gtk_button_set_child (GtkButton *button, gtk_widget_set_parent (priv->child, GTK_WIDGET (button)); gtk_button_set_child_type (button, WIDGET_CHILD); - g_object_notify (G_OBJECT (button), "child"); + g_object_notify_by_pspec (G_OBJECT (button), props[PROP_CHILD]); } /** From 65b79d258580e21085610cd0f89474346c9187c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 15:34:59 +0200 Subject: [PATCH 12/15] Avoid refering to old GtkContainer API in the docs --- gtk/gtkbutton.c | 2 +- gtk/gtkflowbox.c | 7 +++---- gtk/gtklistbox.c | 14 ++++++-------- gtk/gtkoverlay.c | 2 +- gtk/gtkscrolledwindow.c | 4 ++-- gtk/gtkviewport.c | 8 -------- 6 files changed, 13 insertions(+), 24 deletions(-) diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index ca2d0607d9..843c1f49a0 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -629,7 +629,7 @@ gtk_button_buildable_iface_init (GtkBuildableIface *iface) * gtk_button_new: * * Creates a new #GtkButton widget. To add a child widget to the button, - * use gtk_container_add(). + * use gtk_button_set_child(). * * Returns: The newly created #GtkButton widget. */ diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c index 2a40252675..93359aa77f 100644 --- a/gtk/gtkflowbox.c +++ b/gtk/gtkflowbox.c @@ -48,7 +48,7 @@ * The children of a GtkFlowBox can be dynamically sorted and filtered. * * Although a GtkFlowBox must have only #GtkFlowBoxChild children, - * you can add any kind of widget to it via gtk_container_add(), and + * you can add any kind of widget to it via gtk_flow_box_insert(), and * a GtkFlowBoxChild widget will automatically be inserted between * the box and the widget. * @@ -4042,8 +4042,7 @@ gtk_flow_box_insert_css_node (GtkFlowBox *box, * Inserts the @widget into @box at @position. * * If a sort function is set, the widget will actually be inserted - * at the calculated position and this function has the same effect - * as gtk_container_add(). + * at the calculated position. * * If @position is -1, or larger than the total number of children * in the @box, then the @widget will be appended to the end. @@ -4239,7 +4238,7 @@ gtk_flow_box_check_model_compat (GtkFlowBox *box) * If @model is %NULL, @box is left empty. * * It is undefined to add or remove widgets directly (for example, with - * gtk_flow_box_insert() or gtk_container_add()) while @box is bound to a + * gtk_flow_box_insert()) while @box is bound to a * model. * * Note that using a model is incompatible with the filtering and sorting diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 443ac6fa2d..9283312722 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -55,7 +55,8 @@ * button in it). * * Although a #GtkListBox must have only #GtkListBoxRow children you can - * add any kind of widget to it via gtk_container_add(), and a #GtkListBoxRow + * add any kind of widget to it via gtk_list_box_prepend(), + * gtk_list_box_append() and gtk_list_box_insert() and a #GtkListBoxRow * widget will automatically be inserted between the list and the widget. * * #GtkListBoxRows can be marked as activatable or selectable. If a row @@ -2574,8 +2575,7 @@ gtk_list_box_size_allocate (GtkWidget *widget, * @child: the #GtkWidget to add * * Prepend a widget to the list. If a sort function is set, the widget will - * actually be inserted at the calculated position and this function has the - * same effect of gtk_container_add(). + * actually be inserted at the calculated position. */ void gtk_list_box_prepend (GtkListBox *box, @@ -2590,8 +2590,7 @@ gtk_list_box_prepend (GtkListBox *box, * @child: the #GtkWidget to add * * Append a widget to the list. If a sort function is set, the widget will - * actually be inserted at the calculated position and this function has the - * same effect of gtk_container_add(). + * actually be inserted at the calculated position. */ void gtk_list_box_append (GtkListBox *box, @@ -2607,8 +2606,7 @@ gtk_list_box_append (GtkListBox *box, * @position: the position to insert @child in * * Insert the @child into the @box at @position. If a sort function is - * set, the widget will actually be inserted at the calculated position and - * this function has the same effect of gtk_container_add(). + * set, the widget will actually be inserted at the calculated position. * * If @position is -1, or larger than the total number of items in the * @box, then the @child will be appended to the end. @@ -3578,7 +3576,7 @@ gtk_list_box_check_model_compat (GtkListBox *box) * If @model is %NULL, @box is left empty. * * It is undefined to add or remove widgets directly (for example, with - * gtk_list_box_insert() or gtk_container_add()) while @box is bound to a + * gtk_list_box_insert()) while @box is bound to a * model. * * Note that using a model is incompatible with the filtering and sorting diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c index c1c641f012..050b8fd7ac 100644 --- a/gtk/gtkoverlay.c +++ b/gtk/gtkoverlay.c @@ -420,7 +420,7 @@ gtk_overlay_new (void) * Adds @widget to @overlay. * * The widget will be stacked on top of the main widget - * added with gtk_container_add(). + * added with gtk_overlay_set_child(). * * The position at which @widget is placed is determined * from its #GtkWidget:halign and #GtkWidget:valign properties. diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index eaac60a1f2..a2f8fcaf4e 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -68,12 +68,12 @@ * Widgets with native scrolling support, i.e. those whose classes implement the * #GtkScrollable interface, are added directly. For other types of widget, the * class #GtkViewport acts as an adaptor, giving scrollability to other widgets. - * GtkScrolledWindow’s implementation of gtk_container_add() intelligently + * gtk_scrolled_window_set_child() intelligently * accounts for whether or not the added child is a #GtkScrollable. If it isn’t, * #GtkScrolledWindow wraps the child in a #GtkViewport and adds that for you. * Therefore, you can just add any child widget and not worry about the details. * - * If gtk_container_add() has added a #GtkViewport for you, you can remove + * If gtk_scrolled_window_set_child() has added a #GtkViewport for you, you can remove * both your added child widget from the #GtkViewport, and the #GtkViewport * from the GtkScrolledWindow, like this: * diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c index e9f6a8cda5..f53a504c5e 100644 --- a/gtk/gtkviewport.c +++ b/gtk/gtkviewport.c @@ -49,14 +49,6 @@ * capabilities. Use GtkViewport to scroll child widgets such as * #GtkGrid, #GtkBox, and so on. * - * If a widget has native scrolling abilities, such as #GtkTextView, - * #GtkTreeView or #GtkIconView, it can be added to a #GtkScrolledWindow - * with gtk_container_add(). If a widget does not, you must first add the - * widget to a #GtkViewport, then add the viewport to the scrolled window. - * gtk_container_add() does this automatically if a child that does not - * implement #GtkScrollable is added to a #GtkScrolledWindow, so you can - * ignore the presence of the viewport. - * * The GtkViewport will start scrolling content only if allocated less * than the child widget’s minimum size in a given orientation. * From 415946eb0f3b76ba255fb7be5e3177a96edf67e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 19:24:54 +0200 Subject: [PATCH 13/15] togglebutton: Modernice source file Make this a little less ancient looking. --- gtk/gtktogglebutton.c | 194 +++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 108 deletions(-) diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c index 6a31c8f4d9..343efdb593 100644 --- a/gtk/gtktogglebutton.c +++ b/gtk/gtktogglebutton.c @@ -115,36 +115,86 @@ enum { NUM_PROPERTIES }; +static guint toggle_button_signals[LAST_SIGNAL] = { 0 }; static GParamSpec *toggle_button_props[NUM_PROPERTIES] = { NULL, }; -static gboolean gtk_toggle_button_mnemonic_activate (GtkWidget *widget, - gboolean group_cycling); -static void gtk_toggle_button_clicked (GtkButton *button); -static void gtk_toggle_button_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void gtk_toggle_button_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - - -static guint toggle_button_signals[LAST_SIGNAL] = { 0 }; - G_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON, G_ADD_PRIVATE (GtkToggleButton)) +static void +gtk_toggle_button_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object); + + switch (prop_id) + { + case PROP_ACTIVE: + gtk_toggle_button_set_active (tb, g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_toggle_button_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object); + GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (tb); + + switch (prop_id) + { + case PROP_ACTIVE: + g_value_set_boolean (value, priv->active); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static gboolean +gtk_toggle_button_mnemonic_activate (GtkWidget *widget, + gboolean group_cycling) +{ + /* + * We override the standard implementation in + * gtk_widget_real_mnemonic_activate() in order to focus the widget even + * if there is no mnemonic conflict. + */ + if (gtk_widget_get_can_focus (widget)) + gtk_widget_grab_focus (widget); + + if (!group_cycling) + gtk_widget_activate (widget); + + return TRUE; +} + +static void +gtk_toggle_button_clicked (GtkButton *button) +{ + GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button); + GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button); + + gtk_toggle_button_set_active (toggle_button, !priv->active); + + GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button); +} + static void gtk_toggle_button_class_init (GtkToggleButtonClass *class) { - GObjectClass *gobject_class; - GtkWidgetClass *widget_class; - GtkButtonClass *button_class; - - gobject_class = G_OBJECT_CLASS (class); - widget_class = (GtkWidgetClass*) class; - button_class = (GtkButtonClass*) class; + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + GtkButtonClass *button_class = GTK_BUTTON_CLASS (class); gobject_class->set_property = gtk_toggle_button_set_property; gobject_class->get_property = gtk_toggle_button_get_property; @@ -173,12 +223,12 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class) */ toggle_button_signals[TOGGLED] = g_signal_new (I_("toggled"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GtkToggleButtonClass, toggled), - NULL, NULL, - NULL, - G_TYPE_NONE, 0); + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkToggleButtonClass, toggled), + NULL, NULL, + NULL, + G_TYPE_NONE, 0); gtk_widget_class_set_css_name (widget_class, I_("button")); } @@ -201,7 +251,7 @@ gtk_toggle_button_init (GtkToggleButton *toggle_button) * * Returns: a new toggle button. */ -GtkWidget* +GtkWidget * gtk_toggle_button_new (void) { return g_object_new (GTK_TYPE_TOGGLE_BUTTON, NULL); @@ -215,7 +265,7 @@ gtk_toggle_button_new (void) * * Returns: a new toggle button. */ -GtkWidget* +GtkWidget * gtk_toggle_button_new_with_label (const char *label) { return g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL); @@ -232,54 +282,13 @@ gtk_toggle_button_new_with_label (const char *label) * * Returns: a new #GtkToggleButton */ -GtkWidget* +GtkWidget * gtk_toggle_button_new_with_mnemonic (const char *label) { - return g_object_new (GTK_TYPE_TOGGLE_BUTTON, - "label", label, - "use-underline", TRUE, - NULL); -} - -static void -gtk_toggle_button_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GtkToggleButton *tb; - - tb = GTK_TOGGLE_BUTTON (object); - - switch (prop_id) - { - case PROP_ACTIVE: - gtk_toggle_button_set_active (tb, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gtk_toggle_button_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object); - GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (tb); - - switch (prop_id) - { - case PROP_ACTIVE: - g_value_set_boolean (value, priv->active); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + return g_object_new (GTK_TYPE_TOGGLE_BUTTON, + "label", label, + "use-underline", TRUE, + NULL); } /** @@ -295,7 +304,7 @@ gtk_toggle_button_get_property (GObject *object, */ void gtk_toggle_button_set_active (GtkToggleButton *toggle_button, - gboolean is_active) + gboolean is_active) { GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button); @@ -356,34 +365,3 @@ gtk_toggle_button_toggled (GtkToggleButton *toggle_button) g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0); } - -static gboolean -gtk_toggle_button_mnemonic_activate (GtkWidget *widget, - gboolean group_cycling) -{ - /* - * We override the standard implementation in - * gtk_widget_real_mnemonic_activate() in order to focus the widget even - * if there is no mnemonic conflict. - */ - if (gtk_widget_get_can_focus (widget)) - gtk_widget_grab_focus (widget); - - if (!group_cycling) - gtk_widget_activate (widget); - - return TRUE; -} - -static void -gtk_toggle_button_clicked (GtkButton *button) -{ - GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button); - GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button); - - gtk_toggle_button_set_active (toggle_button, !priv->active); - - if (GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked) - GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button); -} - From f716daa483b51551127362a63b016abe81a4e20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 19:30:31 +0200 Subject: [PATCH 14/15] aboutdialog: Fix a code sample gdk_texture_new_from_file takes a GFile these days. --- gtk/gtkaboutdialog.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c index 2bafb769e3..7c1a1b0e81 100644 --- a/gtk/gtkaboutdialog.c +++ b/gtk/gtkaboutdialog.c @@ -95,7 +95,10 @@ * set the title property explicitly when constructing a GtkAboutDialog, * as shown in the following example: * |[ - * GdkTexture *example_logo = gdk_texture_new_from_file ("./logo.png", NULL); + * GFile *logo_file = g_file_new_for_path ("./logo.png"); + * GdkTexture *example_logo = gdk_texture_new_from_file (logo_file, NULL); + * g_object_unref (logo_file); + * * gtk_show_about_dialog (NULL, * "program-name", "ExampleCode", * "logo", example_logo, From 41b458fba7800ad56c906f80c66a3f1b3f716ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 1 Aug 2020 20:00:13 +0200 Subject: [PATCH 15/15] Fix and improve various code samples --- gtk/gtkdialog.c | 2 +- gtk/gtkdrawingarea.c | 15 +++++++++------ gtk/gtkeditable.c | 2 +- gtk/gtkfilechooser.c | 31 ++++++++++++++++++++----------- gtk/gtkfilechooserbutton.c | 2 +- gtk/gtkfilechoosernative.c | 12 +++++------- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index 9c1f05436e..82b3504199 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -730,7 +730,7 @@ gtk_dialog_new_empty (const char *title, * * Here’s a simple example: * |[ - * GtkWidget *main_app_window; // Window the dialog should show up on + * GtkWindow *main_app_window; // Window the dialog should show up on * GtkWidget *dialog; * GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT; * dialog = gtk_dialog_new_with_buttons ("My dialog", diff --git a/gtk/gtkdrawingarea.c b/gtk/gtkdrawingarea.c index 7306869910..65c7198d3c 100644 --- a/gtk/gtkdrawingarea.c +++ b/gtk/gtkdrawingarea.c @@ -85,10 +85,12 @@ static guint signals[LAST_SIGNAL] = { 0, }; * ## Simple GtkDrawingArea usage * * |[ - * void - * draw_function (GtkDrawingArea *area, cairo_t *cr, - * int width, int height, - * gpointer data) + * static void + * draw_function (GtkDrawingArea *area, + * cairo_t *cr, + * int width, + * int height, + * gpointer data) * { * GdkRGBA color; * GtkStyleContext *context; @@ -107,7 +109,8 @@ static guint signals[LAST_SIGNAL] = { 0, }; * cairo_fill (cr); * } * - * void main (int argc, char **argv) + * int + * main (int argc, char **argv) * { * gtk_init (); * @@ -117,7 +120,7 @@ static guint signals[LAST_SIGNAL] = { 0, }; * gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (area), * draw_function, * NULL, NULL); - * + * return 0; * } * ]| * diff --git a/gtk/gtkeditable.c b/gtk/gtkeditable.c index ea6d48b0c2..af0325f80f 100644 --- a/gtk/gtkeditable.c +++ b/gtk/gtkeditable.c @@ -40,7 +40,7 @@ * ## Forcing entry to uppercase. * * |[ - * #include ; + * #include * * void * insert_text_handler (GtkEditable *editable, diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c index f05b053f01..da188eb4f7 100644 --- a/gtk/gtkfilechooser.c +++ b/gtk/gtkfilechooser.c @@ -482,17 +482,26 @@ gtk_file_chooser_get_files (GtkFileChooser *chooser) * file and is saving it for the first time, do not call this function. * Instead, use something similar to this: * |[ - * if (document_is_new) - * { - * // the user just created a new document - * gtk_file_chooser_set_current_folder (chooser, default_file_for_saving); - * gtk_file_chooser_set_current_name (chooser, "Untitled document"); - * } - * else - * { - * // the user edited an existing document - * gtk_file_chooser_set_file (chooser, existing_file); - * } + * static void + * prepare_file_chooser (GtkFileChooser *chooser, + * GFile *existing_file) + * { + * gboolean document_is_new = (existing_file == NULL); + * + * if (document_is_new) + * { + * GFile *default_file_for_saving = g_file_new_for_path ("./out.txt"); + * // the user just created a new document + * gtk_file_chooser_set_current_folder (chooser, default_file_for_saving, NULL); + * gtk_file_chooser_set_current_name (chooser, "Untitled document"); + * g_object_unref (default_file_for_saving); + * } + * else + * { + * // the user edited an existing document + * gtk_file_chooser_set_file (chooser, existing_file, NULL); + * } + * } * ]| * * Returns: Not useful. diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index a530cb5909..f57c8f2a92 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -84,7 +84,7 @@ * * button = gtk_file_chooser_button_new (_("Select a file"), * GTK_FILE_CHOOSER_ACTION_OPEN); - * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button), cwd); + * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button), cwd, NULL); * g_object_unref (cwd); * } * ]| diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c index 7e050da9d7..08512ee079 100644 --- a/gtk/gtkfilechoosernative.c +++ b/gtk/gtkfilechoosernative.c @@ -68,7 +68,7 @@ * * |[ * static void - * on_response (GtkNativeDialog *dialog, + * on_response (GtkNativeDialog *native, * int response) * { * if (response == GTK_RESPONSE_ACCEPT) @@ -102,12 +102,12 @@ * * |[ * static void - * on_response (GtkNativeDialog *dialog, + * on_response (GtkNativeDialog *native, * int response) * { * if (response == GTK_RESPONSE_ACCEPT) * { - * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); + * GtkFileChooser *chooser = GTK_FILE_CHOOSER (native); * GFile *file = gtk_file_chooser_get_file (chooser); * * save_to_file (file); @@ -131,11 +131,9 @@ * chooser = GTK_FILE_CHOOSER (native); * * if (user_edited_a_new_document) - * gtk_file_chooser_set_current_name (chooser, - * _("Untitled document")); + * gtk_file_chooser_set_current_name (chooser, _("Untitled document")); * else - * gtk_file_chooser_set_filename (chooser, - * existing_filename); + * gtk_file_chooser_set_file (chooser, existing_file, NULL); * * g_signal_connect (native, "response", G_CALLBACK (on_response), NULL); * gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));