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).
This commit is contained in:
Jehan 2022-02-17 23:24:05 +01:00
parent 65077a605f
commit 97b81118aa
3 changed files with 57 additions and 19 deletions

View file

@ -246,6 +246,7 @@ gimp_label_color_set_property (GObject *object,
{ {
gtk_grid_attach (GTK_GRID (lcolor), priv->area, 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (lcolor), priv->area, 1, 0, 1, 1);
gtk_widget_show (priv->area); gtk_widget_show (priv->area);
g_signal_emit_by_name (object, "mnemonic-widget-changed", priv->area);
} }
} }
break; break;

View file

@ -40,6 +40,12 @@
* another widget. * another widget.
**/ **/
enum
{
MNEMONIC_WIDGET_CHANGED,
LAST_SIGNAL
};
enum enum
{ {
PROP_0, PROP_0,
@ -48,25 +54,29 @@ enum
typedef struct _GimpLabeledPrivate typedef struct _GimpLabeledPrivate
{ {
GtkWidget *label; GtkWidget *label;
GtkWidget *mnemonic_widget;
} GimpLabeledPrivate; } GimpLabeledPrivate;
static void gimp_labeled_constructed (GObject *object); static void gimp_labeled_constructed (GObject *object);
static void gimp_labeled_set_property (GObject *object, static void gimp_labeled_set_property (GObject *object,
guint property_id, guint property_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_labeled_get_property (GObject *object, static void gimp_labeled_get_property (GObject *object,
guint property_id, guint property_id,
GValue *value, GValue *value,
GParamSpec *pspec); 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) G_DEFINE_TYPE_WITH_PRIVATE (GimpLabeled, gimp_labeled, GTK_TYPE_GRID)
#define parent_class gimp_labeled_parent_class #define parent_class gimp_labeled_parent_class
static guint signals[LAST_SIGNAL] = { 0 };
static void static void
gimp_labeled_class_init (GimpLabeledClass *klass) 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->set_property = gimp_labeled_set_property;
object_class->get_property = gimp_labeled_get_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: * GimpLabeled:label:
* *
@ -103,6 +124,7 @@ gimp_labeled_constructed (GObject *object)
GimpLabeledClass *klass; GimpLabeledClass *klass;
GimpLabeled *labeled = GIMP_LABELED (object); GimpLabeled *labeled = GIMP_LABELED (object);
GimpLabeledPrivate *priv = gimp_labeled_get_instance_private (labeled); GimpLabeledPrivate *priv = gimp_labeled_get_instance_private (labeled);
GtkWidget *mnemonic_widget;
gint x = 0; gint x = 0;
gint y = 0; gint y = 0;
gint width = 1; gint width = 1;
@ -115,10 +137,10 @@ gimp_labeled_constructed (GObject *object)
klass = GIMP_LABELED_GET_CLASS (labeled); klass = GIMP_LABELED_GET_CLASS (labeled);
g_return_if_fail (klass->populate); 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) g_signal_emit (object, signals[MNEMONIC_WIDGET_CHANGED], 0,
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->label), priv->mnemonic_widget); mnemonic_widget);
gtk_grid_attach (GTK_GRID (labeled), priv->label, x, y, width, height); gtk_grid_attach (GTK_GRID (labeled), priv->label, x, y, width, height);
gtk_widget_show (priv->label); 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 */ /* Public functions */
/** /**

View file

@ -35,6 +35,11 @@ struct _GimpLabeledClass
{ {
GtkGridClass parent_class; GtkGridClass parent_class;
/* Signals */
void (* mnemonic_widget_changed) (GimpLabeled *labeled,
GtkWidget *widget);
/* Class methods */ /* Class methods */
/** /**
@ -50,11 +55,12 @@ struct _GimpLabeledClass
* Returns: (transfer none): the #GtkWidget which the label must be * Returns: (transfer none): the #GtkWidget which the label must be
* set as mnemonic to. * set as mnemonic to.
**/ **/
GtkWidget * (* populate) (GimpLabeled *labeled, GtkWidget * (* populate) (GimpLabeled *labeled,
gint *x, gint *x,
gint *y, gint *y,
gint *width, gint *width,
gint *height); gint *height);
/* Padding for future expansion */ /* Padding for future expansion */
void (* _gimp_reserved1) (void); void (* _gimp_reserved1) (void);