[gtk+] Make GtkListBoxRow GtkActionable.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Make GtkListBoxRow GtkActionable.
- Date: Wed, 3 Jan 2018 01:56:38 +0000 (UTC)
commit f1e3b503de4b6371de2172a31c76058f49537d14
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Nov 24 14:26:39 2017 +0100
Make GtkListBoxRow GtkActionable.
https://bugzilla.gnome.org/show_bug.cgi?id=741633
gtk/gtklistbox.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 100 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 03b35a5..f710bf1 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -17,6 +17,7 @@
#include "config.h"
+#include "gtkactionhelper.h"
#include "gtkadjustmentprivate.h"
#include "gtkcssnodeprivate.h"
#include "gtklistbox.h"
@@ -123,6 +124,7 @@ typedef struct
{
GSequenceIter *iter;
GtkWidget *header;
+ GtkActionHelper *action_helper;
gint y;
gint height;
guint visible :1;
@@ -160,19 +162,28 @@ enum {
ROW_PROP_0,
ROW_PROP_ACTIVATABLE,
ROW_PROP_SELECTABLE,
- LAST_ROW_PROPERTY
+
+ /* actionable properties */
+ ROW_PROP_ACTION_NAME,
+ ROW_PROP_ACTION_TARGET,
+
+ LAST_ROW_PROPERTY = ROW_PROP_ACTION_NAME
};
#define BOX_PRIV(box) ((GtkListBoxPrivate*)gtk_list_box_get_instance_private ((GtkListBox*)(box)))
#define ROW_PRIV(row) ((GtkListBoxRowPrivate*)gtk_list_box_row_get_instance_private ((GtkListBoxRow*)(row)))
-static void gtk_list_box_buildable_interface_init (GtkBuildableIface *iface);
+static void gtk_list_box_buildable_interface_init (GtkBuildableIface *iface);
+
+static void gtk_list_box_row_actionable_iface_init (GtkActionableInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkListBox, gtk_list_box, GTK_TYPE_CONTAINER,
G_ADD_PRIVATE (GtkListBox)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_list_box_buildable_interface_init))
-G_DEFINE_TYPE_WITH_PRIVATE (GtkListBoxRow, gtk_list_box_row, GTK_TYPE_BIN)
+G_DEFINE_TYPE_WITH_CODE (GtkListBoxRow, gtk_list_box_row, GTK_TYPE_BIN,
+ G_ADD_PRIVATE (GtkListBoxRow)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE, gtk_list_box_row_actionable_iface_init))
static void gtk_list_box_apply_filter_all (GtkListBox *box);
static void gtk_list_box_update_header (GtkListBox *box,
@@ -1742,7 +1753,14 @@ static void
gtk_list_box_activate (GtkListBox *box,
GtkListBoxRow *row)
{
- if (gtk_list_box_row_get_activatable (row))
+ GtkListBoxRowPrivate *priv = ROW_PRIV (row);
+
+ if (!gtk_list_box_row_get_activatable (row))
+ return;
+
+ if (priv->action_helper)
+ gtk_action_helper_activate (priv->action_helper);
+ else
g_signal_emit (box, signals[ROW_ACTIVATED], 0, row);
}
@@ -3311,6 +3329,32 @@ gtk_list_box_row_get_selectable (GtkListBoxRow *row)
}
static void
+gtk_list_box_row_set_action_name (GtkActionable *actionable,
+ const gchar *action_name)
+{
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW (actionable);
+ GtkListBoxRowPrivate *priv = ROW_PRIV (row);
+
+ if (!priv->action_helper)
+ priv->action_helper = gtk_action_helper_new (actionable);
+
+ gtk_action_helper_set_action_name (priv->action_helper, action_name);
+}
+
+static void
+gtk_list_box_row_set_action_target_value (GtkActionable *actionable,
+ GVariant *action_target)
+{
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW (actionable);
+ GtkListBoxRowPrivate *priv = ROW_PRIV (row);
+
+ if (!priv->action_helper)
+ priv->action_helper = gtk_action_helper_new (actionable);
+
+ gtk_action_helper_set_action_target_value (priv->action_helper, action_target);
+}
+
+static void
gtk_list_box_row_get_property (GObject *obj,
guint property_id,
GValue *value,
@@ -3326,6 +3370,12 @@ gtk_list_box_row_get_property (GObject *obj,
case ROW_PROP_SELECTABLE:
g_value_set_boolean (value, gtk_list_box_row_get_selectable (row));
break;
+ case ROW_PROP_ACTION_NAME:
+ g_value_set_string (value, gtk_action_helper_get_action_name (ROW_PRIV (row)->action_helper));
+ break;
+ case ROW_PROP_ACTION_TARGET:
+ g_value_set_variant (value, gtk_action_helper_get_action_target_value (ROW_PRIV (row)->action_helper));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@@ -3348,12 +3398,43 @@ gtk_list_box_row_set_property (GObject *obj,
case ROW_PROP_SELECTABLE:
gtk_list_box_row_set_selectable (row, g_value_get_boolean (value));
break;
+ case ROW_PROP_ACTION_NAME:
+ gtk_list_box_row_set_action_name (GTK_ACTIONABLE (row), g_value_get_string (value));
+ break;
+ case ROW_PROP_ACTION_TARGET:
+ gtk_list_box_row_set_action_target_value (GTK_ACTIONABLE (row), g_value_get_variant (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
}
}
+static const gchar *
+gtk_list_box_row_get_action_name (GtkActionable *actionable)
+{
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW (actionable);
+
+ return gtk_action_helper_get_action_name (ROW_PRIV (row)->action_helper);
+}
+
+static GVariant *
+gtk_list_box_row_get_action_target_value (GtkActionable *actionable)
+{
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW (actionable);
+
+ return gtk_action_helper_get_action_target_value (ROW_PRIV (row)->action_helper);
+}
+
+static void
+gtk_list_box_row_actionable_iface_init (GtkActionableInterface *iface)
+{
+ iface->get_action_name = gtk_list_box_row_get_action_name;
+ iface->set_action_name = gtk_list_box_row_set_action_name;
+ iface->get_action_target_value = gtk_list_box_row_get_action_target_value;
+ iface->set_action_target_value = gtk_list_box_row_set_action_target_value;
+}
+
static void
gtk_list_box_row_finalize (GObject *obj)
{
@@ -3363,6 +3444,17 @@ gtk_list_box_row_finalize (GObject *obj)
}
static void
+gtk_list_box_row_dispose (GObject *object)
+{
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW (object);
+ GtkListBoxRowPrivate *priv = ROW_PRIV (row);
+
+ g_clear_object (&priv->action_helper);
+
+ G_OBJECT_CLASS (gtk_list_box_row_parent_class)->dispose (object);
+}
+
+static void
gtk_list_box_row_grab_focus (GtkWidget *widget)
{
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
@@ -3387,6 +3479,7 @@ gtk_list_box_row_class_init (GtkListBoxRowClass *klass)
object_class->get_property = gtk_list_box_row_get_property;
object_class->set_property = gtk_list_box_row_set_property;
object_class->finalize = gtk_list_box_row_finalize;
+ object_class->dispose = gtk_list_box_row_dispose;
widget_class->show = gtk_list_box_row_show;
widget_class->hide = gtk_list_box_row_hide;
@@ -3437,6 +3530,9 @@ gtk_list_box_row_class_init (GtkListBoxRowClass *klass)
g_object_class_install_properties (object_class, LAST_ROW_PROPERTY, row_properties);
+ g_object_class_override_property (object_class, ROW_PROP_ACTION_NAME, "action-name");
+ g_object_class_override_property (object_class, ROW_PROP_ACTION_TARGET, "action-target");
+
gtk_widget_class_set_css_name (widget_class, I_("row"));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]