From 69e14ba02f3b194ef385a9d29bb98393c143b314 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 17 Jun 2020 23:42:21 -0400 Subject: [PATCH 1/3] Revert "notebook: Don't capture clicks" This reverts commit 37eb0496b60f3612f15fd9d0fb43a3e3f2ecc144. This change broke notebook scroll arrows. --- gtk/gtknotebook.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 858d68a7b0..7ccaf47a67 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -1432,6 +1432,7 @@ gtk_notebook_init (GtkNotebook *notebook) gesture = gtk_gesture_click_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_notebook_gesture_pressed), notebook); g_signal_connect (gesture, "released", G_CALLBACK (gtk_notebook_gesture_released), notebook); gtk_widget_add_controller (GTK_WIDGET (notebook), GTK_EVENT_CONTROLLER (gesture)); From 3141eaecd0004d632f283c55286d4fca4ae62acc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 18 Jun 2020 07:48:56 -0400 Subject: [PATCH 2/3] gtk-demo: Modernize the tag entry demo Use a layout manager, and reduce boilerplate. --- demos/gtk-demo/demotaggedentry.c | 114 ++++++++++--------------------- demos/gtk-demo/demotaggedentry.h | 36 ++-------- 2 files changed, 39 insertions(+), 111 deletions(-) diff --git a/demos/gtk-demo/demotaggedentry.c b/demos/gtk-demo/demotaggedentry.c index d66bbaed23..63794cdf5f 100644 --- a/demos/gtk-demo/demotaggedentry.c +++ b/demos/gtk-demo/demotaggedentry.c @@ -25,31 +25,36 @@ #include #include -typedef struct { +struct _DemoTaggedEntry +{ + GtkWidget parent_instance; + GtkWidget *box; GtkWidget *entry; -} DemoTaggedEntryPrivate; +}; + +struct _DemoTaggedEntryClass +{ + GtkWidgetClass parent_class; +}; static void demo_tagged_entry_editable_init (GtkEditableInterface *iface); G_DEFINE_TYPE_WITH_CODE (DemoTaggedEntry, demo_tagged_entry, GTK_TYPE_WIDGET, - G_ADD_PRIVATE (DemoTaggedEntry) G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, demo_tagged_entry_editable_init)) static void demo_tagged_entry_init (DemoTaggedEntry *entry) { - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); + entry->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_set_parent (entry->box, GTK_WIDGET (entry)); - priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_widget_set_parent (priv->box, GTK_WIDGET (entry)); - - priv->entry = gtk_text_new (); - gtk_widget_set_hexpand (priv->entry, TRUE); - gtk_widget_set_vexpand (priv->entry, TRUE); - gtk_widget_set_hexpand (priv->box, FALSE); - gtk_widget_set_vexpand (priv->box, FALSE); - gtk_box_append (GTK_BOX (priv->box), priv->entry); + entry->entry = gtk_text_new (); + gtk_widget_set_hexpand (entry->entry, TRUE); + gtk_widget_set_vexpand (entry->entry, TRUE); + gtk_widget_set_hexpand (entry->box, FALSE); + gtk_widget_set_vexpand (entry->box, FALSE); + gtk_box_append (GTK_BOX (entry->box), entry->entry); gtk_editable_init_delegate (GTK_EDITABLE (entry)); } @@ -57,23 +62,16 @@ static void demo_tagged_entry_dispose (GObject *object) { DemoTaggedEntry *entry = DEMO_TAGGED_ENTRY (object); - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - if (priv->entry) + if (entry->entry) gtk_editable_finish_delegate (GTK_EDITABLE (entry)); - g_clear_pointer (&priv->entry, gtk_widget_unparent); - g_clear_pointer (&priv->box, gtk_widget_unparent); + g_clear_pointer (&entry->entry, gtk_widget_unparent); + g_clear_pointer (&entry->box, gtk_widget_unparent); G_OBJECT_CLASS (demo_tagged_entry_parent_class)->dispose (object); } -static void -demo_tagged_entry_finalize (GObject *object) -{ - G_OBJECT_CLASS (demo_tagged_entry_parent_class)->finalize (object); -} - static void demo_tagged_entry_set_property (GObject *object, guint prop_id, @@ -98,44 +96,12 @@ demo_tagged_entry_get_property (GObject *object, G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } -static void -demo_tagged_entry_measure (GtkWidget *widget, - GtkOrientation orientation, - int for_size, - int *minimum, - int *natural, - int *minimum_baseline, - int *natural_baseline) -{ - DemoTaggedEntry *entry = DEMO_TAGGED_ENTRY (widget); - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - - gtk_widget_measure (priv->box, orientation, for_size, - minimum, natural, - minimum_baseline, natural_baseline); -} - -static void -demo_tagged_entry_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline) -{ - DemoTaggedEntry *entry = DEMO_TAGGED_ENTRY (widget); - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - - gtk_widget_size_allocate (priv->box, - &(GtkAllocation) { 0, 0, width, height }, - baseline); -} - static gboolean demo_tagged_entry_grab_focus (GtkWidget *widget) { DemoTaggedEntry *entry = DEMO_TAGGED_ENTRY (widget); - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - return gtk_widget_grab_focus (priv->entry); + return gtk_widget_grab_focus (entry->entry); } static void @@ -145,16 +111,14 @@ demo_tagged_entry_class_init (DemoTaggedEntryClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->dispose = demo_tagged_entry_dispose; - object_class->finalize = demo_tagged_entry_finalize; object_class->get_property = demo_tagged_entry_get_property; object_class->set_property = demo_tagged_entry_set_property; - widget_class->measure = demo_tagged_entry_measure; - widget_class->size_allocate = demo_tagged_entry_size_allocate; widget_class->grab_focus = demo_tagged_entry_grab_focus; - + gtk_editable_install_properties (object_class, 1); + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE); gtk_widget_class_set_css_name (widget_class, "entry"); } @@ -162,10 +126,7 @@ demo_tagged_entry_class_init (DemoTaggedEntryClass *klass) static GtkEditable * demo_tagged_entry_get_delegate (GtkEditable *editable) { - DemoTaggedEntry *entry = DEMO_TAGGED_ENTRY (editable); - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - - return GTK_EDITABLE (priv->entry); + return GTK_EDITABLE (DEMO_TAGGED_ENTRY (editable)->entry); } static void @@ -184,11 +145,9 @@ void demo_tagged_entry_add_tag (DemoTaggedEntry *entry, GtkWidget *tag) { - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - g_return_if_fail (DEMO_IS_TAGGED_ENTRY (entry)); - gtk_box_append (GTK_BOX (priv->box), tag); + gtk_box_append (GTK_BOX (entry->box), tag); } void @@ -196,30 +155,27 @@ demo_tagged_entry_insert_tag_after (DemoTaggedEntry *entry, GtkWidget *tag, GtkWidget *sibling) { - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - g_return_if_fail (DEMO_IS_TAGGED_ENTRY (entry)); if (sibling == NULL) - gtk_box_append (GTK_BOX (priv->box), tag); + gtk_box_append (GTK_BOX (entry->box), tag); else - gtk_box_insert_child_after (GTK_BOX (priv->box), tag, sibling); + gtk_box_insert_child_after (GTK_BOX (entry->box), tag, sibling); } void demo_tagged_entry_remove_tag (DemoTaggedEntry *entry, GtkWidget *tag) { - DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry); - g_return_if_fail (DEMO_IS_TAGGED_ENTRY (entry)); - gtk_box_remove (GTK_BOX (priv->box), tag); + gtk_box_remove (GTK_BOX (entry->box), tag); } struct _DemoTaggedEntryTag { GtkWidget parent; + GtkWidget *box; GtkWidget *label; GtkWidget *button; @@ -250,11 +206,11 @@ static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE (DemoTaggedEntryTag, demo_tagged_entry_tag, GTK_TYPE_WIDGET) static void -on_released (GtkGestureClick *gesture, - int n_press, - double x, - double y, - DemoTaggedEntryTag *tag) +on_released (GtkGestureClick *gesture, + int n_press, + double x, + double y, + DemoTaggedEntryTag *tag) { g_signal_emit (tag, signals[SIGNAL_CLICKED], 0); } diff --git a/demos/gtk-demo/demotaggedentry.h b/demos/gtk-demo/demotaggedentry.h index aef2c34509..9724fa58d4 100644 --- a/demos/gtk-demo/demotaggedentry.h +++ b/demos/gtk-demo/demotaggedentry.h @@ -25,39 +25,11 @@ G_BEGIN_DECLS -#define DEMO_TYPE_TAGGED_ENTRY (demo_tagged_entry_get_type ()) -#define DEMO_TAGGED_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEMO_TYPE_TAGGED_ENTRY, DemoTaggedEntry)) -#define DEMO_TAGGED_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEMO_TYPE_TAGGED_ENTRY, DemoTaggedEntryClass)) -#define DEMO_IS_TAGGED_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEMO_TYPE_TAGGED_ENTRY)) -#define DEMO_IS_TAGGED_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEMO_TYPE_TAGGED_ENTRY)) -#define DEMO_TAGGED_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEMO_TYPE_TAGGED_ENTRY, DemoTaggedEntryClass)) +#define DEMO_TYPE_TAGGED_ENTRY (demo_tagged_entry_get_type ()) +G_DECLARE_FINAL_TYPE (DemoTaggedEntry, demo_tagged_entry, DEMO, TAGGED_ENTRY, GtkWidget) -typedef struct _DemoTaggedEntry DemoTaggedEntry; -typedef struct _DemoTaggedEntryClass DemoTaggedEntryClass; - -struct _DemoTaggedEntry -{ - GtkWidget parent; -}; - -struct _DemoTaggedEntryClass -{ - GtkWidgetClass parent_class; -}; - -#define DEMO_TYPE_TAGGED_ENTRY_TAG (demo_tagged_entry_tag_get_type ()) -#define DEMO_TAGGED_ENTRY_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEMO_TYPE_TAGGED_ENTRY_TAG, DemoTaggedEntryTag)) -#define DEMO_TAGGED_ENTRY_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEMO_TYPE_TAGGED_ENTRY_TAG, DemoTaggedEntryTag)) -#define DEMO_IS_TAGGED_ENTRY_TAG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEMO_TYPE_TAGGED_ENTRY_TAG)) -#define DEMO_IS_TAGGED_ENTRY_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEMO_TYPE_TAGGED_ENTRY_TAG)) -#define DEMO_TAGGED_ENTRY_TAG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEMO_TYPE_TAGGED_ENTRY_TAG, DemoTaggedEntryTagClass)) - -typedef struct _DemoTaggedEntryTag DemoTaggedEntryTag; -typedef struct _DemoTaggedEntryTagClass DemoTaggedEntryTagClass; - - -GType demo_tagged_entry_get_type (void) G_GNUC_CONST; -GType demo_tagged_entry_tag_get_type (void) G_GNUC_CONST; +#define DEMO_TYPE_TAGGED_ENTRY_TAG (demo_tagged_entry_tag_get_type ()) +G_DECLARE_FINAL_TYPE (DemoTaggedEntryTag, demo_tagged_entry_tag, DEMO, TAGGED_ENTRY_TAG, GtkWidget) GtkWidget * demo_tagged_entry_new (void); From 55936087e0e4ad1bbc6c03040f9c0c7536636280 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 19 Jun 2020 11:40:54 -0400 Subject: [PATCH 3/3] columview: Fix cell creation We were getting lost in the columnview internal structure here. The rows are children of the listview, not of the columnview itself. --- gtk/gtkcolumnviewcolumn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c index 708ff6cb5b..c0aaf631bb 100644 --- a/gtk/gtkcolumnviewcolumn.c +++ b/gtk/gtkcolumnviewcolumn.c @@ -519,12 +519,14 @@ gtk_column_view_column_get_allocation (GtkColumnViewColumn *self, static void gtk_column_view_column_create_cells (GtkColumnViewColumn *self) { + GtkListView *list; GtkWidget *row; if (self->first_cell) return; - for (row = gtk_widget_get_first_child (GTK_WIDGET (self->view)); + list = gtk_column_view_get_list_view (GTK_COLUMN_VIEW (self->view)); + for (row = gtk_widget_get_first_child (GTK_WIDGET (list)); row != NULL; row = gtk_widget_get_next_sibling (row)) {