[gimp] libgimp, libgimpwidgets, plug-ins: improved GimpProcedureDialog API.



commit 7b6f2e5c2beca17f25c409c1a294ec27b5772078
Author: Jehan <jehan girinstud io>
Date:   Fri Nov 13 21:26:14 2020 +0100

    libgimp, libgimpwidgets, plug-ins: improved GimpProcedureDialog API.
    
    - New GimpLabelIntWidget which is a label associated to any widget with
      an integer "value" property.
    - New gimp_procedure_dialog_get_int_combo() which creates a labeled
      combo box from an integer property of the GimpProcedureConfig.
    - Renamed gimp_procedure_dialog_populate*() with
      gimp_procedure_dialog_fill*(). Naming is hard! I hesitated using
      _pack() as well (similarly to GtkBox API).
    - New gimp_procedure_dialog_fill_flowbox*() functions to create a
      GtkFlowBox filled with property widgets (or other container widgets as
      we can pack them one in another). This is an alternative way to build
      your GUI with sane defaults, with list of property names.

 libgimp/gimpproceduredialog.c       | 319 ++++++++++++++++++++++++++++++++----
 libgimp/gimpproceduredialog.h       |  46 ++++--
 libgimpwidgets/gimplabelintwidget.c | 252 ++++++++++++++++++++++++++++
 libgimpwidgets/gimplabelintwidget.h |  60 +++++++
 libgimpwidgets/gimpwidgets.h        |   1 +
 libgimpwidgets/meson.build          |   2 +
 plug-ins/file-fli/fli-gimp.c        |   2 +-
 7 files changed, 633 insertions(+), 49 deletions(-)
---
diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c
index 067f7a5c71..78e003e907 100644
--- a/libgimp/gimpproceduredialog.c
+++ b/libgimp/gimpproceduredialog.c
@@ -297,21 +297,27 @@ gimp_procedure_dialog_new (GimpProcedure       *procedure,
 
 /**
  * gimp_procedure_dialog_get_widget:
- * @dialog: the associated #GimpProcedureDialog.
- * @property: name of the property to build a dialog for. It must be a
- *            property of the #GimpProcedure @dialog has been created
- *            for.
+ * @dialog:      the associated #GimpProcedureDialog.
+ * @property:    name of the property to build a widget for. It must be
+ *               a property of the #GimpProcedure @dialog has been
+ *               created for.
  * @widget_type: alternative widget type. %G_TYPE_NONE will create the
  *               default type of widget for the associated property
  *               type.
  *
- * Creates a new property #GtkWidget for @property according to the
- * property type. For instance by default a %G_TYPE_PARAM_BOOLEAN
- * property will be represented by a #GtkCheckButton.
- * Alternative @widget_type are possible, such as a %G_TYPE_SWITCH for a
- * %G_TYPE_PARAM_BOOLEAN property. If the @widget_type is not
- * supported, the function will fail. To keep the default, set to
- * %G_TYPE_NONE).
+ * Creates a new #GtkWidget for @property according to the property
+ * type. The following types are possible:
+ *
+ * - %G_TYPE_PARAM_BOOLEAN: %GTK_TYPE_CHECK_BUTTON (default) or
+ *   %GTK_TYPE_SWITCH
+ * - %G_TYPE_PARAM_INT: %GIMP_TYPE_LABEL_SPIN (default) or
+ *   %GIMP_TYPE_SCALE_ENTRY or %GIMP_TYPE_SPIN_BUTTON (no label).
+ * - %G_TYPE_PARAM_STRING: %GTK_TYPE_ENTRY (default).
+ *
+ * If the @widget_type is not supported for the actual type of
+ * @property, the function will fail. To keep the default, set to
+ * %G_TYPE_NONE.
+ *
  * If a widget has already been created for this procedure, it will be
  * returned instead (even if with a different @widget_type).
  *
@@ -418,32 +424,109 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog,
 }
 
 /**
- * gimp_procedure_dialog_populate:
+ * gimp_procedure_dialog_get_int_combo:
+ * @dialog:   the associated #GimpProcedureDialog.
+ * @property: name of the int property to build a combo for. It must be
+ *            a property of the #GimpProcedure @dialog has been created
+ *            for.
+ * @store:    the #GimpIntStore which will be used by the combo box.
+ *
+ * Creates a new #GimpLabelIntWidget for @property which must
+ * necessarily be an integer or boolean property.
+ * This must be used instead of gimp_procedure_dialog_get_widget() when
+ * you want to create a combo box from an integer property.
+ *
+ * If a widget has already been created for this procedure, it will be
+ * returned instead (whatever its actual widget type).
+ *
+ * Returns: (transfer none): the #GtkWidget representing @property. The
+ *                           object belongs to @dialog and must not be
+ *                           freed.
+ */
+GtkWidget *
+gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
+                                     const gchar         *property,
+                                     GimpIntStore        *store)
+{
+  GtkWidget  *widget = NULL;
+  GParamSpec *pspec;
+
+  g_return_val_if_fail (property != NULL, NULL);
+
+  /* First check if it already exists. */
+  widget = g_hash_table_lookup (dialog->priv->widgets, property);
+
+  if (widget)
+    return widget;
+
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (dialog->priv->config),
+                                        property);
+  if (! pspec)
+    {
+      g_warning ("%s: parameter %s does not exist.",
+                 G_STRFUNC, property);
+      return NULL;
+    }
+
+  if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_BOOLEAN ||
+      G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT)
+    {
+      widget = gimp_prop_int_combo_box_new (G_OBJECT (dialog->priv->config),
+                                            property, store);
+      gtk_widget_set_vexpand (widget, FALSE);
+      gtk_widget_set_hexpand (widget, TRUE);
+      widget = gimp_label_int_widget_new (_(g_param_spec_get_nick (pspec)),
+                                          widget);
+    }
+
+  if (! widget)
+    {
+      g_warning ("%s: parameter '%s' of type %s not suitable as GimpIntComboBox",
+                 G_STRFUNC, property, G_PARAM_SPEC_TYPE_NAME (pspec));
+      return NULL;
+    }
+  else if (GIMP_IS_LABELED (widget))
+    {
+      GtkWidget *label = gimp_labeled_get_label (GIMP_LABELED (widget));
+
+      gtk_size_group_add_widget (dialog->priv->label_group, label);
+    }
+
+  g_hash_table_insert (dialog->priv->widgets, g_strdup (property), widget);
+
+  return widget;
+}
+
+/**
+ * gimp_procedure_dialog_fill:
  * @dialog: the #GimpProcedureDialog.
  * @first_property: the first property name.
  * @...: a %NULL-terminated list of other property names.
  *
- * Populated @dialog with the widgets corresponding to every listed
+ * Populate @dialog with the widgets corresponding to every listed
  * properties. If the list is empty, @dialog will be filled by the whole
  * list of properties of the associated #GimpProcedure, in the defined
  * order:
  * |[<!-- language="C" -->
- * gimp_procedure_dialog_populate (dialog, NULL);
+ * gimp_procedure_dialog_fill (dialog, NULL);
  * ]|
  * Nevertheless if you only wish to display a partial list of
  * properties, or if you wish to change the display order, then you have
  * to give an explicit list:
  * |[<!-- language="C" -->
- * gimp_procedure_dialog_populate (dialog, "property-1", "property-1", NULL);
+ * gimp_procedure_dialog_fill (dialog, "property-1", "property-2", NULL);
  * ]|
- * You do not have gimp_procedure_dialog_get_widget() before calling
- * this function unless you want a given property to be represented by
- * an alternative widget type.
+ *
+ * Note: you do not have to call gimp_procedure_dialog_get_widget() on
+ * every property before calling this function unless you want a given
+ * property to be represented by an alternative widget type. By default,
+ * each property will get a default representation according to its
+ * type.
  */
 void
-gimp_procedure_dialog_populate (GimpProcedureDialog *dialog,
-                                const gchar         *first_property,
-                                ...)
+gimp_procedure_dialog_fill (GimpProcedureDialog *dialog,
+                            const gchar         *first_property,
+                            ...)
 {
   const gchar *prop_name = first_property;
   GList       *list      = NULL;
@@ -463,33 +546,39 @@ gimp_procedure_dialog_populate (GimpProcedureDialog *dialog,
     }
 
   list = g_list_reverse (list);
-  gimp_procedure_dialog_populate_list (dialog, list);
+  gimp_procedure_dialog_fill_list (dialog, list);
   if (list)
     g_list_free (list);
 }
 
 /**
- * gimp_procedure_dialog_populate_list: (rename-to gimp_procedure_dialog_populate)
+ * gimp_procedure_dialog_fill_list: (rename-to gimp_procedure_dialog_fill)
  * @dialog: the #GimpProcedureDialog.
  * @properties: (nullable) (element-type gchar*): the list of property names.
  *
- * Populated @dialog with the widgets corresponding to every listed
+ * Populate @dialog with the widgets corresponding to every listed
  * properties. If the list is %NULL, @dialog will be filled by the whole
  * list of properties of the associated #GimpProcedure, in the defined
  * order:
  * |[<!-- language="C" -->
- * gimp_procedure_dialog_populate_list (dialog, NULL);
+ * gimp_procedure_dialog_fill_list (dialog, NULL);
  * ]|
  * Nevertheless if you only wish to display a partial list of
  * properties, or if you wish to change the display order, then you have
  * to give an explicit list:
- * You do not have gimp_procedure_dialog_get_widget() before calling
- * this function unless you want a given property to be represented by
- * an alternative widget type.
+ * |[<!-- language="C" -->
+ * gimp_procedure_dialog_fill (dialog, "property-1", "property-2", NULL);
+ * ]|
+ *
+ * Note: you do not have to call gimp_procedure_dialog_get_widget() on
+ * every property before calling this function unless you want a given
+ * property to be represented by an alternative widget type. By default,
+ * each property will get a default representation according to its
+ * type.
  */
 void
-gimp_procedure_dialog_populate_list (GimpProcedureDialog *dialog,
-                                     GList               *properties)
+gimp_procedure_dialog_fill_list (GimpProcedureDialog *dialog,
+                                 GList               *properties)
 {
   GtkWidget *content_area;
   GList     *iter;
@@ -546,6 +635,176 @@ gimp_procedure_dialog_populate_list (GimpProcedureDialog *dialog,
     g_list_free (properties);
 }
 
+/**
+ * gimp_procedure_dialog_fill_flowbox:
+ * @dialog:         the #GimpProcedureDialog.
+ * @container_id:   a container identifier.
+ * @first_property: the first property name.
+ * @...:            a %NULL-terminated list of other property names.
+ *
+ * Creates and populates a new #GtkFlowBox with widgets corresponding to
+ * every listed properties. If the list is empty, the created flowbox
+ * will be filled by the whole list of properties of the associated
+ * #GimpProcedure, in the defined order. This is similar of how
+ * gimp_procedure_dialog_fill() works except that it creates a new
+ * widget which is not inside @dialog itself.
+ *
+ * The @container_id must be a unique ID which is neither the name of a
+ * property of the #GimpProcedureConfig associated to @dialog, nor is it
+ * the ID of any previously created container. This ID can later be used
+ * together with property names to be packed in other containers or
+ * inside @dialog itself.
+ *
+ * Returns: (transfer none): the #GtkFlowBox representing @property. The
+ *                           object belongs to @dialog and must not be
+ *                           freed.
+ */
+GtkWidget *
+gimp_procedure_dialog_fill_flowbox (GimpProcedureDialog *dialog,
+                                    const gchar         *container_id,
+                                    const gchar         *first_property,
+                                    ...)
+{
+  const gchar *prop_name = first_property;
+  GtkWidget   *flowbox;
+  GList       *list      = NULL;
+  va_list      va_args;
+
+  g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), NULL);
+  g_return_val_if_fail (container_id != NULL, NULL);
+
+  if (first_property)
+    {
+      va_start (va_args, first_property);
+
+      do
+        list = g_list_prepend (list, (gpointer) prop_name);
+      while ((prop_name = va_arg (va_args, const gchar *)));
+
+      va_end (va_args);
+    }
+
+  list = g_list_reverse (list);
+  flowbox = gimp_procedure_dialog_fill_flowbox_list (dialog, container_id, list);
+  if (list)
+    g_list_free (list);
+
+  return flowbox;
+}
+
+/**
+ * gimp_procedure_dialog_fill_flowbox_list: (rename-to gimp_procedure_dialog_fill_flowbox)
+ * @dialog:        the #GimpProcedureDialog.
+ * @container_id:  a container identifier.
+ * @properties: (nullable) (element-type gchar*): the list of property names.
+ *
+ * Creates and populates a new #GtkFlowBox with widgets corresponding to
+ * every listed @properties. If the list is empty, the created flowbox
+ * will be filled by the whole list of properties of the associated
+ * #GimpProcedure, in the defined order. This is similar of how
+ * gimp_procedure_dialog_fill() works except that it creates a new
+ * widget which is not inside @dialog itself.
+ *
+ * The @container_id must be a unique ID which is neither the name of a
+ * property of the #GimpProcedureConfig associated to @dialog, nor is it
+ * the ID of any previously created container. This ID can later be used
+ * together with property names to be packed in other containers or
+ * inside @dialog itself.
+ *
+ * Returns: (transfer none): the #GtkFlowBox representing @property. The
+ *                           object belongs to @dialog and must not be
+ *                           freed.
+ */
+GtkWidget *
+gimp_procedure_dialog_fill_flowbox_list (GimpProcedureDialog *dialog,
+                                         const gchar         *container_id,
+                                         GList               *properties)
+{
+  GtkWidget *flowbox;
+  GList     *iter;
+  gboolean   free_properties = FALSE;
+
+  g_return_val_if_fail (container_id != NULL, NULL);
+
+  if (g_object_class_find_property (G_OBJECT_GET_CLASS (dialog->priv->config),
+                                    container_id))
+    {
+      g_warning ("%s: container identifier '%s' cannot be an existing property name.",
+                 G_STRFUNC, container_id);
+      return NULL;
+    }
+
+  if ((flowbox = g_hash_table_lookup (dialog->priv->widgets, container_id)))
+    {
+      g_warning ("%s: container identifier '%s' was already configured.",
+                 G_STRFUNC, container_id);
+      return flowbox;
+    }
+
+  flowbox = gtk_flow_box_new ();
+
+  if (! properties)
+    {
+      GParamSpec **pspecs;
+      guint        n_pspecs;
+      gint         i;
+
+      pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (dialog->priv->config),
+                                               &n_pspecs);
+
+      for (i = 0; i < n_pspecs; i++)
+        {
+          const gchar *prop_name;
+          GParamSpec  *pspec = pspecs[i];
+
+          /*  skip our own properties  */
+          if (pspec->owner_type == GIMP_TYPE_PROCEDURE_CONFIG)
+            continue;
+
+          prop_name  = g_param_spec_get_name (pspec);
+          properties = g_list_prepend (properties, (gpointer) prop_name);
+        }
+
+      properties = g_list_reverse (properties);
+
+      if (properties)
+        free_properties = TRUE;
+    }
+
+  for (iter = properties; iter; iter = iter->next)
+    {
+      GtkWidget *widget;
+
+      widget = gimp_procedure_dialog_get_widget (dialog, iter->data, G_TYPE_NONE);
+      if (widget)
+        {
+          /* Reference the widget because the hash table will
+           * unreference it anyway when getting destroyed so we don't
+           * want to give the only reference to the parent widget.
+           */
+          g_object_ref (widget);
+          gtk_container_add (GTK_CONTAINER (flowbox), widget);
+          gtk_widget_show (widget);
+        }
+    }
+
+  if (free_properties)
+    g_list_free (properties);
+
+  g_hash_table_insert (dialog->priv->widgets, g_strdup (container_id), flowbox);
+
+  return flowbox;
+}
+
+/**
+ * gimp_procedure_dialog_run:
+ * @dialog: the #GimpProcedureDialog.
+ *
+ * Show @dialog and only returns when the user finished interacting with
+ * it (either validating choices or canceling).
+ *
+ * Returns: %TRUE if the dialog was validated, %FALSE otherwise.
+ */
 gboolean
 gimp_procedure_dialog_run (GimpProcedureDialog *dialog)
 {
diff --git a/libgimp/gimpproceduredialog.h b/libgimp/gimpproceduredialog.h
index 356c92345a..bad99aebc1 100644
--- a/libgimp/gimpproceduredialog.h
+++ b/libgimp/gimpproceduredialog.h
@@ -64,24 +64,34 @@ struct _GimpProcedureDialogClass
 };
 
 
-GType       gimp_procedure_dialog_get_type      (void) G_GNUC_CONST;
-
-GtkWidget * gimp_procedure_dialog_new           (GimpProcedure       *procedure,
-                                                 GimpProcedureConfig *config,
-                                                 const gchar         *title);
-
-GtkWidget * gimp_procedure_dialog_get_widget    (GimpProcedureDialog *dialog,
-                                                 const gchar         *property,
-                                                 GType                widget_type);
-
-void        gimp_procedure_dialog_populate      (GimpProcedureDialog *dialog,
-                                                 const gchar         *first_property,
-                                                 ...);
-void        gimp_procedure_dialog_populate_list (GimpProcedureDialog *dialog,
-                                                 GList               *properties);
-
-
-gboolean    gimp_procedure_dialog_run           (GimpProcedureDialog *dialog);
+GType       gimp_procedure_dialog_get_type          (void) G_GNUC_CONST;
+
+GtkWidget * gimp_procedure_dialog_new               (GimpProcedure       *procedure,
+                                                     GimpProcedureConfig *config,
+                                                     const gchar         *title);
+
+GtkWidget * gimp_procedure_dialog_get_widget        (GimpProcedureDialog *dialog,
+                                                     const gchar         *property,
+                                                     GType                widget_type);
+GtkWidget * gimp_procedure_dialog_get_int_combo     (GimpProcedureDialog *dialog,
+                                                     const gchar         *property,
+                                                     GimpIntStore        *store);
+
+GtkWidget * gimp_procedure_dialog_fill_flowbox      (GimpProcedureDialog *dialog,
+                                                     const gchar         *container_id,
+                                                     const gchar         *first_property,
+                                                     ...);
+GtkWidget * gimp_procedure_dialog_fill_flowbox_list (GimpProcedureDialog *dialog,
+                                                     const gchar         *container_id,
+                                                     GList               *properties);
+
+void        gimp_procedure_dialog_fill              (GimpProcedureDialog *dialog,
+                                                     const gchar         *first_property,
+                                                     ...);
+void        gimp_procedure_dialog_fill_list         (GimpProcedureDialog *dialog,
+                                                     GList               *properties);
+
+gboolean    gimp_procedure_dialog_run               (GimpProcedureDialog *dialog);
 
 
 G_END_DECLS
diff --git a/libgimpwidgets/gimplabelintwidget.c b/libgimpwidgets/gimplabelintwidget.c
new file mode 100644
index 0000000000..50033f07e3
--- /dev/null
+++ b/libgimpwidgets/gimplabelintwidget.c
@@ -0,0 +1,252 @@
+/* LIBGIMP - The GIMP Library
+ * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
+ *
+ * gimplabelintwidget.c
+ * Copyright (C) 2020 Jehan
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpcolor/gimpcolor.h"
+#include "libgimpmath/gimpmath.h"
+#include "libgimpbase/gimpbase.h"
+
+#include "gimplabelintwidget.h"
+
+
+/**
+ * SECTION: gimplabelintwidget
+ * @title: GimpLabelIntWidget
+ * @short_description: Widget containing a label and a widget with an
+ *                     integer "value" property.
+ *
+ * This widget is a subclass of #GimpLabeled.
+ **/
+
+enum
+{
+  VALUE_CHANGED,
+  LAST_SIGNAL
+};
+
+enum
+{
+  PROP_0,
+  PROP_VALUE,
+  PROP_WIDGET,
+};
+
+typedef struct _GimpLabelIntWidgetPrivate
+{
+  GimpLabeled    parent_instance;
+
+  GtkWidget     *widget;
+  gint           value;
+} GimpLabelIntWidgetPrivate;
+
+static void        gimp_label_int_widget_constructed       (GObject       *object);
+static void        gimp_label_int_widget_set_property      (GObject       *object,
+                                                            guint          property_id,
+                                                            const GValue  *value,
+                                                            GParamSpec    *pspec);
+static void        gimp_label_int_widget_get_property      (GObject       *object,
+                                                            guint          property_id,
+                                                            GValue        *value,
+                                                            GParamSpec    *pspec);
+
+static GtkWidget * gimp_label_int_widget_populate          (GimpLabeled   *widget,
+                                                            gint          *x,
+                                                            gint          *y,
+                                                            gint          *width,
+                                                            gint          *height);
+
+G_DEFINE_TYPE_WITH_PRIVATE (GimpLabelIntWidget, gimp_label_int_widget, GIMP_TYPE_LABELED)
+
+#define parent_class gimp_label_int_widget_parent_class
+
+static guint gimp_label_int_widget_signals[LAST_SIGNAL] = { 0 };
+
+static void
+gimp_label_int_widget_class_init (GimpLabelIntWidgetClass *klass)
+{
+  GObjectClass     *object_class  = G_OBJECT_CLASS (klass);
+  GimpLabeledClass *labeled_class = GIMP_LABELED_CLASS (klass);
+
+  gimp_label_int_widget_signals[VALUE_CHANGED] =
+    g_signal_new ("value-changed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GimpLabelIntWidgetClass, value_changed),
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE, 0);
+
+  object_class->constructed  = gimp_label_int_widget_constructed;
+  object_class->set_property = gimp_label_int_widget_set_property;
+  object_class->get_property = gimp_label_int_widget_get_property;
+
+  labeled_class->populate    = gimp_label_int_widget_populate;
+
+  /**
+   * GimpLabelIntWidget:value:
+   *
+   * The currently set value.
+   *
+   * Since: 3.0
+   **/
+  g_object_class_install_property (object_class, PROP_VALUE,
+                                   g_param_spec_int ("value", NULL,
+                                                     "Current value",
+                                                     G_MININT, G_MAXINT, 0,
+                                                     GIMP_PARAM_READWRITE));
+
+  /**
+   * GimpLabelIntWidget:widget:
+   *
+   * The widget holding an integer value.
+   *
+   * Since: 3.0
+   **/
+  g_object_class_install_property (object_class, PROP_WIDGET,
+                                   g_param_spec_object ("widget", NULL,
+                                                        "Integer widget",
+                                                        GTK_TYPE_WIDGET,
+                                                        GIMP_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+gimp_label_int_widget_init (GimpLabelIntWidget *widget)
+{
+}
+
+static void
+gimp_label_int_widget_constructed (GObject *object)
+{
+  GimpLabelIntWidget        *widget = GIMP_LABEL_INT_WIDGET (object);
+  GimpLabelIntWidgetPrivate *priv   = gimp_label_int_widget_get_instance_private (widget);
+
+  G_OBJECT_CLASS (parent_class)->constructed (object);
+
+  /* This is important to make this object into a property widget. It
+   * will allow config object to bind the "value" property of this
+   * widget, and therefore be updated automatically.
+   */
+  g_object_bind_property (G_OBJECT (priv->widget), "value",
+                          object,                  "value",
+                          G_BINDING_BIDIRECTIONAL |
+                          G_BINDING_SYNC_CREATE);
+}
+
+static void
+gimp_label_int_widget_set_property (GObject      *object,
+                                    guint         property_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  GimpLabelIntWidget        *widget = GIMP_LABEL_INT_WIDGET (object);
+  GimpLabelIntWidgetPrivate *priv   = gimp_label_int_widget_get_instance_private (widget);
+
+  switch (property_id)
+    {
+    case PROP_VALUE:
+      priv->value = g_value_get_int (value);
+      g_signal_emit (object, gimp_label_int_widget_signals[VALUE_CHANGED], 0);
+      break;
+    case PROP_WIDGET:
+      priv->widget = g_value_get_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_label_int_widget_get_property (GObject    *object,
+                                    guint       property_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  GimpLabelIntWidget        *widget = GIMP_LABEL_INT_WIDGET (object);
+  GimpLabelIntWidgetPrivate *priv   = gimp_label_int_widget_get_instance_private (widget);
+
+  switch (property_id)
+    {
+    case PROP_VALUE:
+      g_value_set_int (value, priv->value);
+      break;
+    case PROP_WIDGET:
+      g_value_set_object (value, priv->widget);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static GtkWidget *
+gimp_label_int_widget_populate (GimpLabeled *labeled,
+                                gint        *x,
+                                gint        *y,
+                                gint        *width,
+                                gint        *height)
+{
+  GimpLabelIntWidget        *widget = GIMP_LABEL_INT_WIDGET (labeled);
+  GimpLabelIntWidgetPrivate *priv   = gimp_label_int_widget_get_instance_private (widget);
+
+  gtk_grid_attach (GTK_GRID (widget), priv->widget, 1, 0, 1, 1);
+  gtk_widget_show (priv->widget);
+
+  return priv->widget;
+}
+
+/* Public Functions */
+
+/**
+ * gimp_label_int_widget_new:
+ * @text:   The text for the #GtkLabel.
+ * @widget: (transfer full): The #GtkWidget to use.
+ *
+ * Creates a new #GimpLabelIntWidget whose "value" property is bound to
+ * that of @widget (which must therefore have such an integer property).
+ *
+ * Returns: (transfer full): The new #GimpLabelIntWidget widget.
+ **/
+GtkWidget *
+gimp_label_int_widget_new (const gchar *text,
+                           GtkWidget   *widget)
+{
+  GtkWidget  *int_widget;
+  GParamSpec *pspec;
+
+  g_return_val_if_fail ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (widget),
+                                                               "value")) &&
+                        G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT,
+                        NULL);
+
+  int_widget = g_object_new (GIMP_TYPE_LABEL_INT_WIDGET,
+                             "label",  text,
+                             "widget", widget,
+                             NULL);
+
+  return int_widget;
+}
diff --git a/libgimpwidgets/gimplabelintwidget.h b/libgimpwidgets/gimplabelintwidget.h
new file mode 100644
index 0000000000..38c0c6ef2b
--- /dev/null
+++ b/libgimpwidgets/gimplabelintwidget.h
@@ -0,0 +1,60 @@
+/* LIBGIMP - The GIMP Library
+ * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
+ *
+ * gimplabelintwidget.h
+ * Copyright (C) 2020 Jehan
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+
+#if !defined (__GIMP_WIDGETS_H_INSIDE__) && !defined (GIMP_WIDGETS_COMPILATION)
+#error "Only <libgimpwidgets/gimpwidgets.h> can be included directly."
+#endif
+
+#ifndef __GIMP_LABEL_INT_WIDGET_H__
+#define __GIMP_LABEL_INT_WIDGET_H__
+
+#include <libgimpwidgets/gimplabeled.h>
+
+G_BEGIN_DECLS
+
+#define GIMP_TYPE_LABEL_INT_WIDGET (gimp_label_int_widget_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GimpLabelIntWidget, gimp_label_int_widget, GIMP, LABEL_INT_WIDGET, GimpLabeled)
+
+struct _GimpLabelIntWidgetClass
+{
+  GimpLabeledClass   parent_class;
+
+  /*  Signals */
+  void            (* value_changed)    (GtkWidget *int_widget);
+
+  /* Padding for future expansion */
+  void (* _gimp_reserved1) (void);
+  void (* _gimp_reserved2) (void);
+  void (* _gimp_reserved3) (void);
+  void (* _gimp_reserved4) (void);
+  void (* _gimp_reserved5) (void);
+  void (* _gimp_reserved6) (void);
+  void (* _gimp_reserved7) (void);
+  void (* _gimp_reserved8) (void);
+};
+
+GtkWidget  * gimp_label_int_widget_new       (const gchar   *text,
+                                              GtkWidget     *widget);
+
+
+G_END_DECLS
+
+#endif /* __GIMP_LABEL_INT_WIDGET_H__ */
diff --git a/libgimpwidgets/gimpwidgets.h b/libgimpwidgets/gimpwidgets.h
index 6b13e0ae45..48d87f20fa 100644
--- a/libgimpwidgets/gimpwidgets.h
+++ b/libgimpwidgets/gimpwidgets.h
@@ -62,6 +62,7 @@
 #include <libgimpwidgets/gimpintcombobox.h>
 #include <libgimpwidgets/gimpintstore.h>
 #include <libgimpwidgets/gimplabeled.h>
+#include <libgimpwidgets/gimplabelintwidget.h>
 #include <libgimpwidgets/gimplabelspin.h>
 #include <libgimpwidgets/gimpmemsizeentry.h>
 #include <libgimpwidgets/gimpnumberpairentry.h>
diff --git a/libgimpwidgets/meson.build b/libgimpwidgets/meson.build
index beec696930..488ce7ad5f 100644
--- a/libgimpwidgets/meson.build
+++ b/libgimpwidgets/meson.build
@@ -55,6 +55,7 @@ libgimpwidgets_sources_introspectable = files(
   'gimpintcombobox.c',
   'gimpintstore.c',
   'gimplabeled.c',
+  'gimplabelintwidget.c',
   'gimplabelspin.c',
   'gimpmemsizeentry.c',
   'gimpnumberpairentry.c',
@@ -129,6 +130,7 @@ libgimpwidgets_headers_introspectable = files(
   'gimpicons.h',
   'gimpintcombobox.h',
   'gimplabeled.h',
+  'gimplabelintwidget.h',
   'gimplabelspin.h',
   'gimpintstore.h',
   'gimpmemsizeentry.h',
diff --git a/plug-ins/file-fli/fli-gimp.c b/plug-ins/file-fli/fli-gimp.c
index 4c91ab920b..0a23b19d2d 100644
--- a/plug-ins/file-fli/fli-gimp.c
+++ b/plug-ins/file-fli/fli-gimp.c
@@ -973,7 +973,7 @@ save_dialog (GimpImage     *image,
   gimp_labeled_set_text (GIMP_LABELED (gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dialog),
                                                                          "to-frame", GIMP_TYPE_LABEL_SPIN)),
                          "_To:");
-  gimp_procedure_dialog_populate (GIMP_PROCEDURE_DIALOG (dialog), NULL);
+  gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog), NULL);
 
   gtk_widget_show (dialog);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]