From d56711b5d82f8a77793a0857c2252565fda1b492 Mon Sep 17 00:00:00 2001 From: Alexander Mikhaylenko Date: Mon, 17 May 2021 18:05:05 +0500 Subject: [PATCH] listitemwidget: Have .activatable style class if the item is activatable Match GtkListBox, so it's possible to use the same styles for them. Update GtkListView and GtkGridView docs to reflect that, fix a few gtk-doc formatting leftovers along the way. --- gtk/gtkgridview.c | 11 ++++++----- gtk/gtklistitem.c | 3 +++ gtk/gtklistitemwidget.c | 14 ++++++++++++++ gtk/gtklistitemwidgetprivate.h | 2 ++ gtk/gtklistview.c | 14 ++++++++------ 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index f32400d3cd..3de7f2f7c2 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -64,17 +64,18 @@ * * ``` * gridview - * ├── child + * ├── child[.activatable] * │ - * ├── child + * ├── child[.activatable] * │ * ┊ * ╰── [rubberband] * ``` * - * `GtkGridView` uses a single CSS node with name gridview. Each child - * uses a single CSS node with name child. For rubberband selection, - * a subnode with name rubberband is used. + * `GtkGridView` uses a single CSS node with name `gridview`. Each child uses + * a single CSS node with name `child`. If the [property@Gtk.ListItem.activatable] + * property is set, the corresponding row will have the `.activatable` style + * class. For rubberband selection, a subnode with name `rubberband` is used. * * # Accessibility * diff --git a/gtk/gtklistitem.c b/gtk/gtklistitem.c index 89171369a5..b4371b8c93 100644 --- a/gtk/gtklistitem.c +++ b/gtk/gtklistitem.c @@ -460,5 +460,8 @@ gtk_list_item_set_activatable (GtkListItem *self, self->activatable = activatable; + if (self->owner) + gtk_list_item_widget_set_activatable (self->owner, activatable); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIVATABLE]); } diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c index 09ac15d1bf..2a98ef5c87 100644 --- a/gtk/gtklistitemwidget.c +++ b/gtk/gtklistitemwidget.c @@ -509,6 +509,8 @@ gtk_list_item_widget_default_setup (GtkListItemWidget *self, if (list_item->child) gtk_list_item_widget_add_child (self, list_item->child); + gtk_list_item_widget_set_activatable (self, list_item->activatable); + if (priv->item) g_object_notify (G_OBJECT (list_item), "item"); if (priv->position != GTK_INVALID_LIST_POSITION) @@ -531,6 +533,8 @@ gtk_list_item_widget_default_teardown (GtkListItemWidget *self, if (list_item->child) gtk_list_item_widget_remove_child (self, list_item->child); + gtk_list_item_widget_set_activatable (self, FALSE); + if (priv->item) g_object_notify (G_OBJECT (list_item), "item"); if (priv->position != GTK_INVALID_LIST_POSITION) @@ -612,6 +616,16 @@ gtk_list_item_widget_set_single_click_activate (GtkListItemWidget *self, g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SINGLE_CLICK_ACTIVATE]); } +void +gtk_list_item_widget_set_activatable (GtkListItemWidget *self, + gboolean activatable) +{ + if (activatable) + gtk_widget_add_css_class (GTK_WIDGET (self), "activatable"); + else + gtk_widget_remove_css_class (GTK_WIDGET (self), "activatable"); +} + void gtk_list_item_widget_add_child (GtkListItemWidget *self, GtkWidget *child) diff --git a/gtk/gtklistitemwidgetprivate.h b/gtk/gtklistitemwidgetprivate.h index 8f78b1a7a2..eca2d21c6b 100644 --- a/gtk/gtklistitemwidgetprivate.h +++ b/gtk/gtklistitemwidgetprivate.h @@ -74,6 +74,8 @@ void gtk_list_item_widget_set_factory (GtkListItemWidg void gtk_list_item_widget_set_single_click_activate (GtkListItemWidget *self, gboolean single_click_activate); +void gtk_list_item_widget_set_activatable (GtkListItemWidget *self, + gboolean activatable); void gtk_list_item_widget_add_child (GtkListItemWidget *self, GtkWidget *child); void gtk_list_item_widget_reorder_child (GtkListItemWidget *self, diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c index 63446efdb0..624bfbd4fd 100644 --- a/gtk/gtklistview.c +++ b/gtk/gtklistview.c @@ -117,18 +117,20 @@ * * ``` * listview[.separators][.rich-list][.navigation-sidebar][.data-table] - * ├── row + * ├── row[.activatable] * │ - * ├── row + * ├── row[.activatable] * │ * ┊ * ╰── [rubberband] * ``` * - * `GtkListView` uses a single CSS node named listview. It may carry the - * .separators style class, when `GtkListView`:show-separators property - * is set. Each child widget uses a single CSS node named row. For - * rubberband selection, a node with name rubberband is used. + * `GtkListView` uses a single CSS node named `listview`. It may carry the + * `.separators` style class, when [property@Gtk.ListView:show-separators] + * property is set. Each child widget uses a single CSS node named `row`. + * If the [property@Gtk.ListItem.activatable] property is set, the + * corresponding row will have the `.activatable` style class. For + * rubberband selection, a node with name `rubberband` is used. * * The main listview node may also carry style classes to select * the style of [list presentation](ListContainers.html#list-styles):