From 8b0731b34f2d1ef3921ca684d8dcf777d8816c33 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 24 Mar 2023 03:45:24 +0100 Subject: [PATCH] gridview: Add GtkGridView::tab-behavior --- gtk/gtkgridview.c | 92 +++++++++++++++++++++++++++++++++++++++-------- gtk/gtkgridview.h | 6 ++++ 2 files changed, 83 insertions(+), 15 deletions(-) diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index 2fcccb58d3..b87792c7d9 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -26,11 +26,9 @@ #include "gtklistitemfactory.h" #include "gtklistitemmanagerprivate.h" #include "gtklistitemwidgetprivate.h" -#include "gtkmain.h" -#include "gtkprivate.h" -#include "gtksingleselection.h" -#include "gtkwidgetprivate.h" #include "gtkmultiselection.h" +#include "gtktypebuiltins.h" +#include "gtkwidgetprivate.h" /* Maximum number of list items created by the gridview. * For debugging, you can set this to G_MAXUINT to ensure @@ -105,12 +103,13 @@ struct _GtkGridViewClass enum { PROP_0, + PROP_ENABLE_RUBBERBAND, PROP_FACTORY, PROP_MAX_COLUMNS, PROP_MIN_COLUMNS, PROP_MODEL, PROP_SINGLE_CLICK_ACTIVATE, - PROP_ENABLE_RUBBERBAND, + PROP_TAB_BEHAVIOR, N_PROPS }; @@ -877,6 +876,10 @@ gtk_grid_view_get_property (GObject *object, switch (property_id) { + case PROP_ENABLE_RUBBERBAND: + g_value_set_boolean (value, gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self))); + break; + case PROP_FACTORY: g_value_set_object (value, self->factory); break; @@ -897,8 +900,8 @@ gtk_grid_view_get_property (GObject *object, g_value_set_boolean (value, self->single_click_activate); break; - case PROP_ENABLE_RUBBERBAND: - g_value_set_boolean (value, gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self))); + case PROP_TAB_BEHAVIOR: + g_value_set_enum (value, gtk_list_base_get_tab_behavior (GTK_LIST_BASE (self))); break; default: @@ -917,6 +920,10 @@ gtk_grid_view_set_property (GObject *object, switch (property_id) { + case PROP_ENABLE_RUBBERBAND: + gtk_grid_view_set_enable_rubberband (self, g_value_get_boolean (value)); + break; + case PROP_FACTORY: gtk_grid_view_set_factory (self, g_value_get_object (value)); break; @@ -937,8 +944,8 @@ gtk_grid_view_set_property (GObject *object, gtk_grid_view_set_single_click_activate (self, g_value_get_boolean (value)); break; - case PROP_ENABLE_RUBBERBAND: - gtk_grid_view_set_enable_rubberband (self, g_value_get_boolean (value)); + case PROP_TAB_BEHAVIOR: + gtk_grid_view_set_tab_behavior (self, g_value_get_enum (value)); break; default: @@ -987,6 +994,16 @@ gtk_grid_view_class_init (GtkGridViewClass *klass) gobject_class->get_property = gtk_grid_view_get_property; gobject_class->set_property = gtk_grid_view_set_property; + /** + * GtkGridView:enable-rubberband: (attributes org.gtk.Property.get=gtk_grid_view_get_enable_rubberband org.gtk.Property.set=gtk_grid_view_set_enable_rubberband) + * + * Allow rubberband selection. + */ + properties[PROP_ENABLE_RUBBERBAND] = + g_param_spec_boolean ("enable-rubberband", NULL, NULL, + FALSE, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + /** * GtkGridView:factory: (attributes org.gtk.Property.get=gtk_grid_view_get_factory org.gtk.Property.set=gtk_grid_view_set_factory) * @@ -1042,14 +1059,17 @@ gtk_grid_view_class_init (GtkGridViewClass *klass) G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); /** - * GtkGridView:enable-rubberband: (attributes org.gtk.Property.get=gtk_grid_view_get_enable_rubberband org.gtk.Property.set=gtk_grid_view_set_enable_rubberband) + * GtkGridView:tab-behavior: (attributes org.gtk.Property.get=gtk_grid_view_get_tab_behavior org.gtk.Property.set=gtk_grid_view_set_tab_behavior) * - * Allow rubberband selection. + * Behavior of the Tab key + * + * Since: 4.12 */ - properties[PROP_ENABLE_RUBBERBAND] = - g_param_spec_boolean ("enable-rubberband", NULL, NULL, - FALSE, - G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + properties[PROP_TAB_BEHAVIOR] = + g_param_spec_enum ("tab-behavior", NULL, NULL, + GTK_TYPE_LIST_TAB_BEHAVIOR, + GTK_LIST_TAB_ALL, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); g_object_class_install_properties (gobject_class, N_PROPS, properties); @@ -1417,3 +1437,45 @@ gtk_grid_view_get_enable_rubberband (GtkGridView *self) return gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self)); } + +/** + * gtk_grid_view_set_tab_behavior: (attributes org.gtk.Method.set_property=tab-behavior) + * @self: a `GtkGridView` + * @tab_behavior: The desired tab behavior + * + * Sets the behavior of the Tab and Shift+Tab keys. + * + * Since: 4.12 + */ +void +gtk_grid_view_set_tab_behavior (GtkGridView *self, + GtkListTabBehavior tab_behavior) +{ + g_return_if_fail (GTK_IS_GRID_VIEW (self)); + + if (tab_behavior == gtk_list_base_get_tab_behavior (GTK_LIST_BASE (self))) + return; + + gtk_list_base_set_tab_behavior (GTK_LIST_BASE (self), tab_behavior); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TAB_BEHAVIOR]); +} + +/** + * gtk_grid_view_get_tab_behavior: (attributes org.gtk.Method.get_property=tab-behavior) + * @self: a `GtkGridView` + * + * Gets the behavior set for the Tab key. + * + * Returns: The behavior of the Tab key + * + * Since: 4.12 + */ +gboolean +gtk_grid_view_get_tab_behavior (GtkGridView *self) +{ + g_return_val_if_fail (GTK_IS_GRID_VIEW (self), FALSE); + + return gtk_list_base_get_tab_behavior (GTK_LIST_BASE (self)); +} + diff --git a/gtk/gtkgridview.h b/gtk/gtkgridview.h index 18056ecef3..8ebfcb8cde 100644 --- a/gtk/gtkgridview.h +++ b/gtk/gtkgridview.h @@ -73,6 +73,12 @@ void gtk_grid_view_set_enable_rubberband (GtkGridView GDK_AVAILABLE_IN_ALL gboolean gtk_grid_view_get_enable_rubberband (GtkGridView *self); +GDK_AVAILABLE_IN_4_12 +void gtk_grid_view_set_tab_behavior (GtkGridView *self, + GtkListTabBehavior tab_behavior); +GDK_AVAILABLE_IN_4_12 +gboolean gtk_grid_view_get_tab_behavior (GtkGridView *self); + GDK_AVAILABLE_IN_ALL void gtk_grid_view_set_single_click_activate (GtkGridView *self, gboolean single_click_activate);