summaryrefslogtreecommitdiff
path: root/gtk/gtkgridview.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-10-20 08:13:36 +0200
committerMatthias Clasen <mclasen@redhat.com>2020-05-30 19:26:46 -0400
commitba0122fd028538c85c9f5ecf859687833e697643 (patch)
tree9425b5d4ae30edcb05ff0aa5ae1c6917ad6f5b6f /gtk/gtkgridview.c
parentaffd2737d5dde94ae10c7e6cad6d80f7187e54de (diff)
downloadgtk+-ba0122fd028538c85c9f5ecf859687833e697643.tar.gz
gridview: Add activation
Diffstat (limited to 'gtk/gtkgridview.c')
-rw-r--r--gtk/gtkgridview.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 18b95b7507..543a4b01d4 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -108,11 +108,17 @@ enum
N_PROPS
};
+enum {
+ ACTIVATE,
+ LAST_SIGNAL
+};
+
G_DEFINE_TYPE_WITH_CODE (GtkGridView, gtk_grid_view, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
static GParamSpec *properties[N_PROPS] = { NULL, };
+static guint signals[LAST_SIGNAL] = { 0 };
static void G_GNUC_UNUSED
dump (GtkGridView *self)
@@ -1209,6 +1215,24 @@ gtk_grid_view_select_item_action (GtkWidget *widget,
}
static void
+gtk_grid_view_activate_item (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter)
+{
+ GtkGridView *self = GTK_GRID_VIEW (widget);
+ guint pos;
+
+ if (!g_variant_check_format_string (parameter, "u", FALSE))
+ return;
+
+ g_variant_get (parameter, "u", &pos);
+ if (self->model == NULL || pos >= g_list_model_get_n_items (self->model))
+ return;
+
+ g_signal_emit (widget, signals[ACTIVATE], 0, pos);
+}
+
+static void
gtk_grid_view_class_init (GtkGridViewClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
@@ -1306,6 +1330,42 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
g_object_class_install_properties (gobject_class, N_PROPS, properties);
/**
+ * GtkGridView::activate:
+ * @self: The #GtkGridView
+ * @position: position of item to activate
+ *
+ * The ::activate signal is emitted when a cell has been activated by the user,
+ * usually via activating the GtkGridView|list.activate-item action.
+ *
+ * This allows for a convenient way to handle activation in a gridview.
+ * See GtkListItem:activatable for details on how to use this signal.
+ */
+ signals[ACTIVATE] =
+ g_signal_new (I_("activate"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1,
+ G_TYPE_UINT);
+ g_signal_set_va_marshaller (signals[ACTIVATE],
+ G_TYPE_FROM_CLASS (gobject_class),
+ g_cclosure_marshal_VOID__UINTv);
+
+ /**
+ * GtkGridView|list.activate-item:
+ * @position: position of item to activate
+ *
+ * Activates the item given in @position by emitting the GtkGridView::activate
+ * signal.
+ */
+ gtk_widget_class_install_action (widget_class,
+ "list.activate-item",
+ "u",
+ gtk_grid_view_activate_item);
+
+ /**
* GtkGridView|list.select-item:
* @position: position of item to select
* @modify: %TRUE to toggle the existing selection, %FALSE to select