[gimp] libgimpwidgets: add a "mnemonic-widget-changed" signal to GimpLabeled.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpwidgets: add a "mnemonic-widget-changed" signal to GimpLabeled.
- Date: Thu, 17 Feb 2022 22:26:07 +0000 (UTC)
commit 97b81118aab68a7c78c1b1747dbaa6d9e5929a43
Author: Jehan <jehan girinstud io>
Date: Thu Feb 17 23:24:05 2022 +0100
libgimpwidgets: add a "mnemonic-widget-changed" signal to GimpLabeled.
This allows to track changes of mnemonic widgets, as we do in
GimpLabelColor when we switch from editable to non-editable (or
reverse).
libgimpwidgets/gimplabelcolor.c | 1 +
libgimpwidgets/gimplabeled.c | 59 +++++++++++++++++++++++++++++++----------
libgimpwidgets/gimplabeled.h | 16 +++++++----
3 files changed, 57 insertions(+), 19 deletions(-)
---
diff --git a/libgimpwidgets/gimplabelcolor.c b/libgimpwidgets/gimplabelcolor.c
index ac0a2061ff..19a95d65e1 100644
--- a/libgimpwidgets/gimplabelcolor.c
+++ b/libgimpwidgets/gimplabelcolor.c
@@ -246,6 +246,7 @@ gimp_label_color_set_property (GObject *object,
{
gtk_grid_attach (GTK_GRID (lcolor), priv->area, 1, 0, 1, 1);
gtk_widget_show (priv->area);
+ g_signal_emit_by_name (object, "mnemonic-widget-changed", priv->area);
}
}
break;
diff --git a/libgimpwidgets/gimplabeled.c b/libgimpwidgets/gimplabeled.c
index 19c088c1e2..550356b635 100644
--- a/libgimpwidgets/gimplabeled.c
+++ b/libgimpwidgets/gimplabeled.c
@@ -40,6 +40,12 @@
* another widget.
**/
+enum
+{
+ MNEMONIC_WIDGET_CHANGED,
+ LAST_SIGNAL
+};
+
enum
{
PROP_0,
@@ -48,25 +54,29 @@ enum
typedef struct _GimpLabeledPrivate
{
- GtkWidget *label;
- GtkWidget *mnemonic_widget;
+ GtkWidget *label;
} GimpLabeledPrivate;
-static void gimp_labeled_constructed (GObject *object);
-static void gimp_labeled_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gimp_labeled_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
+static void gimp_labeled_constructed (GObject *object);
+static void gimp_labeled_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gimp_labeled_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void gimp_labeled_real_mnemonic_widget_changed (GimpLabeled *labeled,
+ GtkWidget *widget);
+
G_DEFINE_TYPE_WITH_PRIVATE (GimpLabeled, gimp_labeled, GTK_TYPE_GRID)
#define parent_class gimp_labeled_parent_class
+static guint signals[LAST_SIGNAL] = { 0 };
static void
gimp_labeled_class_init (GimpLabeledClass *klass)
@@ -77,6 +87,17 @@ gimp_labeled_class_init (GimpLabeledClass *klass)
object_class->set_property = gimp_labeled_set_property;
object_class->get_property = gimp_labeled_get_property;
+ signals[MNEMONIC_WIDGET_CHANGED] =
+ g_signal_new ("mnemonic-widget-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpLabeledClass, mnemonic_widget_changed),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 1,
+ GTK_TYPE_WIDGET);
+
+ klass->mnemonic_widget_changed = gimp_labeled_real_mnemonic_widget_changed;
+
/**
* GimpLabeled:label:
*
@@ -103,6 +124,7 @@ gimp_labeled_constructed (GObject *object)
GimpLabeledClass *klass;
GimpLabeled *labeled = GIMP_LABELED (object);
GimpLabeledPrivate *priv = gimp_labeled_get_instance_private (labeled);
+ GtkWidget *mnemonic_widget;
gint x = 0;
gint y = 0;
gint width = 1;
@@ -115,10 +137,10 @@ gimp_labeled_constructed (GObject *object)
klass = GIMP_LABELED_GET_CLASS (labeled);
g_return_if_fail (klass->populate);
- priv->mnemonic_widget = klass->populate (labeled, &x, &y, &width, &height);
+ mnemonic_widget = klass->populate (labeled, &x, &y, &width, &height);
- if (priv->mnemonic_widget)
- gtk_label_set_mnemonic_widget (GTK_LABEL (priv->label), priv->mnemonic_widget);
+ g_signal_emit (object, signals[MNEMONIC_WIDGET_CHANGED], 0,
+ mnemonic_widget);
gtk_grid_attach (GTK_GRID (labeled), priv->label, x, y, width, height);
gtk_widget_show (priv->label);
@@ -175,6 +197,15 @@ gimp_labeled_get_property (GObject *object,
}
}
+static void
+gimp_labeled_real_mnemonic_widget_changed (GimpLabeled *labeled,
+ GtkWidget *widget)
+{
+ GimpLabeledPrivate *priv = gimp_labeled_get_instance_private (labeled);
+
+ gtk_label_set_mnemonic_widget (GTK_LABEL (priv->label), widget);
+}
+
/* Public functions */
/**
diff --git a/libgimpwidgets/gimplabeled.h b/libgimpwidgets/gimplabeled.h
index e0a5aa019b..65c33e5b86 100644
--- a/libgimpwidgets/gimplabeled.h
+++ b/libgimpwidgets/gimplabeled.h
@@ -35,6 +35,11 @@ struct _GimpLabeledClass
{
GtkGridClass parent_class;
+ /* Signals */
+
+ void (* mnemonic_widget_changed) (GimpLabeled *labeled,
+ GtkWidget *widget);
+
/* Class methods */
/**
@@ -50,11 +55,12 @@ struct _GimpLabeledClass
* Returns: (transfer none): the #GtkWidget which the label must be
* set as mnemonic to.
**/
- GtkWidget * (* populate) (GimpLabeled *labeled,
- gint *x,
- gint *y,
- gint *width,
- gint *height);
+ GtkWidget * (* populate) (GimpLabeled *labeled,
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height);
+
/* Padding for future expansion */
void (* _gimp_reserved1) (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]