[gimp] app: split some utils out of gimppropgui.[ch] to gimppropgui-utils.[ch]



commit cb0757e1c51f3f529a29da70d240b852d0f06004
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jul 16 20:14:18 2017 +0200

    app: split some utils out of gimppropgui.[ch] to gimppropgui-utils.[ch]

 app/propgui/Makefile.am         |    4 +-
 app/propgui/gimppropgui-utils.c |  212 +++++++++++++++++++++++++++++++++++++++
 app/propgui/gimppropgui-utils.h |   32 ++++++
 app/propgui/gimppropgui.c       |  156 +----------------------------
 po/POTFILES.in                  |    1 +
 5 files changed, 250 insertions(+), 155 deletions(-)
---
diff --git a/app/propgui/Makefile.am b/app/propgui/Makefile.am
index f45d705..d54de75 100644
--- a/app/propgui/Makefile.am
+++ b/app/propgui/Makefile.am
@@ -38,4 +38,6 @@ libapppropgui_a_SOURCES = \
        gimppropgui-spiral.c                    \
        gimppropgui-spiral.h                    \
        gimppropgui-supernova.c                 \
-       gimppropgui-supernova.h
+       gimppropgui-supernova.h                 \
+       gimppropgui-utils.c                     \
+       gimppropgui-utils.h
diff --git a/app/propgui/gimppropgui-utils.c b/app/propgui/gimppropgui-utils.c
new file mode 100644
index 0000000..1beadac
--- /dev/null
+++ b/app/propgui/gimppropgui-utils.c
@@ -0,0 +1,212 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
+ *
+ * gimppropgui-utils.c
+ * Copyright (C) 2002-2017  Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "propgui-types.h"
+
+#include "widgets/gimpwidgets-utils.h"
+
+#include "gimppropgui-utils.h"
+
+#include "gimp-intl.h"
+
+
+/*  local function prototypes  */
+
+static void      gimp_prop_kelvin_presets_menu_position (GtkMenu        *menu,
+                                                         gint           *x,
+                                                         gint           *y,
+                                                         gboolean       *push_in,
+                                                         gpointer        user_data);
+static gboolean  gimp_prop_kelvin_presets_button_press  (GtkWidget      *widget,
+                                                         GdkEventButton *bevent,
+                                                         GtkMenu        *menu);
+static void      gimp_prop_kelvin_presets_activate      (GtkWidget      *widget,
+                                                         GObject        *config);
+static void      gimp_prop_random_seed_new_clicked      (GtkButton      *button,
+                                                         GtkAdjustment  *adj);
+
+
+/*  public functions  */
+
+GtkWidget *
+gimp_prop_kelvin_presets_new (GObject     *config,
+                              const gchar *property_name)
+{
+  GtkWidget *button;
+  GtkWidget *menu;
+  gint       i;
+
+  const struct
+  {
+    gdouble      kelvin;
+    const gchar *label;
+  }
+  kelvin_presets[] =
+  {
+    { 1700, N_("1,700 K – Match flame") },
+    { 1850, N_("1,850 K – Candle flame, sunset/sunrise") },
+    { 3000, N_("3,000 K – Soft (or warm) white compact fluorescent lamps") },
+    { 3000, N_("3,300 K – Incandescent lamps") },
+    { 3200, N_("3,200 K – Studio lamps, photofloods, etc.") },
+    { 3350, N_("3,350 K – Studio \"CP\" light") },
+    { 4100, N_("4,100 K – Moonlight") },
+    { 5000, N_("5,000 K – D50") },
+    { 5000, N_("5,000 K – Cool white/daylight compact fluorescent lamps") },
+    { 5000, N_("5,000 K – Horizon daylight") },
+    { 5500, N_("5,500 K – D55") },
+    { 5500, N_("5,500 K – Vertical daylight, electronic flash") },
+    { 6200, N_("6,200 K – Xenon short-arc lamp") },
+    { 6500, N_("6,500 K – D65") },
+    { 6500, N_("6,500 K – Daylight, overcast") },
+    { 7500, N_("7,500 K – D75") },
+    { 9300, N_("9,300 K") }
+  };
+
+  button = gtk_button_new ();
+  gtk_widget_set_can_focus (button, FALSE);
+  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+
+  gtk_button_set_image (GTK_BUTTON (button),
+                        gtk_image_new_from_icon_name (GIMP_ICON_MENU_LEFT,
+                                                      GTK_ICON_SIZE_MENU));
+
+  menu = gtk_menu_new ();
+  gtk_menu_attach_to_widget (GTK_MENU (menu), button, NULL);
+
+  g_signal_connect (button, "button-press-event",
+                    G_CALLBACK (gimp_prop_kelvin_presets_button_press),
+                    menu);
+
+  for (i = 0; i < G_N_ELEMENTS (kelvin_presets); i++)
+    {
+      GtkWidget *item;
+      gdouble   *kelvin;
+
+      item = gtk_menu_item_new_with_label (gettext (kelvin_presets[i].label));
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+      gtk_widget_show (item);
+
+      g_object_set_data_full (G_OBJECT (item), "property-name",
+                              g_strdup (property_name),
+                              (GDestroyNotify) g_free);
+
+      kelvin = g_new (gdouble, 1);
+      *kelvin = kelvin_presets[i].kelvin;
+
+      g_object_set_data_full (G_OBJECT (item), "kelvin",
+                              kelvin, (GDestroyNotify) g_free);
+
+      g_signal_connect (item, "activate",
+                        G_CALLBACK (gimp_prop_kelvin_presets_activate),
+                        config);
+
+    }
+
+  return button;
+}
+
+GtkWidget *
+gimp_prop_random_seed_new (GObject     *config,
+                           const gchar *property_name)
+{
+  GtkAdjustment *adj;
+  GtkWidget     *hbox;
+  GtkWidget     *spin;
+  GtkWidget     *button;
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
+
+  spin = gimp_prop_spin_button_new (config, property_name,
+                                    1.0, 10.0, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), spin, TRUE, TRUE, 0);
+  gtk_widget_show (spin);
+
+  button = gtk_button_new_with_label (_("New Seed"));
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+  gtk_widget_show (button);
+
+  adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
+
+  g_signal_connect (button, "clicked",
+                    G_CALLBACK (gimp_prop_random_seed_new_clicked),
+                    adj);
+
+  return hbox;
+}
+
+
+/*  private functions  */
+
+static void
+gimp_prop_kelvin_presets_menu_position (GtkMenu  *menu,
+                                        gint     *x,
+                                        gint     *y,
+                                        gboolean *push_in,
+                                        gpointer  user_data)
+{
+  gimp_button_menu_position (user_data, menu, GTK_POS_LEFT, x, y);
+}
+
+static gboolean
+gimp_prop_kelvin_presets_button_press (GtkWidget      *widget,
+                                       GdkEventButton *bevent,
+                                       GtkMenu        *menu)
+{
+  if (bevent->type == GDK_BUTTON_PRESS)
+    {
+      gtk_menu_popup (menu,
+                      NULL, NULL,
+                      gimp_prop_kelvin_presets_menu_position, widget,
+                      bevent->button, bevent->time);
+    }
+
+  return TRUE;
+}
+
+static void
+gimp_prop_kelvin_presets_activate (GtkWidget *widget,
+                                   GObject   *config)
+{
+  const gchar *property_name;
+  gdouble     *kelvin;
+
+  property_name = g_object_get_data (G_OBJECT (widget), "property-name");
+  kelvin        = g_object_get_data (G_OBJECT (widget), "kelvin");
+
+  if (property_name && kelvin)
+    g_object_set (config, property_name, *kelvin, NULL);
+}
+
+static void
+gimp_prop_random_seed_new_clicked (GtkButton     *button,
+                                   GtkAdjustment *adj)
+{
+  guint32 value = g_random_int_range (gtk_adjustment_get_lower (adj),
+                                      gtk_adjustment_get_upper (adj));
+
+  gtk_adjustment_set_value (adj, value);
+}
diff --git a/app/propgui/gimppropgui-utils.h b/app/propgui/gimppropgui-utils.h
new file mode 100644
index 0000000..42ab9c2
--- /dev/null
+++ b/app/propgui/gimppropgui-utils.h
@@ -0,0 +1,32 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
+ *
+ * gimppropgui-utils.h
+ * Copyright (C) 2002-2017  Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_PROP_GUI_UTILS_H__
+#define __GIMP_PROP_GUI_UTILS_H__
+
+
+GtkWidget * gimp_prop_kelvin_presets_new (GObject     *config,
+                                          const gchar *property_name);
+
+GtkWidget * gimp_prop_random_seed_new    (GObject     *config,
+                                          const gchar *property_name);
+
+
+#endif /* __GIMP_PROP_GUI_UTILS_H__ */
diff --git a/app/propgui/gimppropgui.c b/app/propgui/gimppropgui.c
index af69ed9..35988bc 100644
--- a/app/propgui/gimppropgui.c
+++ b/app/propgui/gimppropgui.c
@@ -22,14 +22,12 @@
 #include "config.h"
 
 #include <string.h>
-#include <stdlib.h>
 
 #include <gegl.h>
 #include <gegl-paramspecs.h>
 #include <gtk/gtk.h>
 
 #include "libgimpcolor/gimpcolor.h"
-#include "libgimpbase/gimpbase.h"
 #include "libgimpconfig/gimpconfig.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -45,7 +43,6 @@
 #include "widgets/gimpmessagebox.h"
 #include "widgets/gimpspinscale.h"
 #include "widgets/gimppropwidgets.h"
-#include "widgets/gimpwidgets-utils.h"
 
 #include "gimppropgui.h"
 #include "gimppropgui-channel-mixer.h"
@@ -58,6 +55,7 @@
 #include "gimppropgui-hue-saturation.h"
 #include "gimppropgui-spiral.h"
 #include "gimppropgui-supernova.h"
+#include "gimppropgui-utils.h"
 
 #include "gimp-intl.h"
 
@@ -65,10 +63,6 @@
 #define HAS_KEY(p,k,v) gimp_gegl_param_spec_has_key (p, k, v)
 
 
-static GtkWidget   * gimp_prop_kelvin_presets_new      (GObject        *config,
-                                                        const gchar    *property_name);
-static void          gimp_prop_widget_new_seed_clicked (GtkButton      *button,
-                                                        GtkAdjustment  *adj);
 static gboolean      gimp_prop_string_to_boolean       (GBinding       *binding,
                                                         const GValue   *from_value,
                                                         GValue         *to_value,
@@ -127,26 +121,7 @@ gimp_prop_widget_new_from_pspec (GObject                  *config,
 
   if (GEGL_IS_PARAM_SPEC_SEED (pspec))
     {
-      GtkAdjustment *adj;
-      GtkWidget     *spin;
-      GtkWidget     *button;
-
-      widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
-
-      spin = gimp_prop_spin_button_new (config, pspec->name,
-                                        1.0, 10.0, 0);
-      gtk_box_pack_start (GTK_BOX (widget), spin, TRUE, TRUE, 0);
-      gtk_widget_show (spin);
-
-      button = gtk_button_new_with_label (_("New Seed"));
-      gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
-      gtk_widget_show (button);
-
-      adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
-
-      g_signal_connect (button, "clicked",
-                        G_CALLBACK (gimp_prop_widget_new_seed_clicked),
-                        adj);
+      widget = gimp_prop_random_seed_new (config, pspec->name);
 
       *label = g_param_spec_get_nick (pspec);
     }
@@ -451,7 +426,6 @@ static const struct
   const gchar        *config_type;
   GimpPropGuiNewFunc  gui_new_func;
 }
-
 gui_new_funcs[] =
 {
   { "GimpColorBalanceConfig",
@@ -594,132 +568,6 @@ gimp_prop_gui_bind_tooltip (GtkWidget *source,
 
 /*  private functions  */
 
-static void
-gimp_prop_kelvin_presets_menu_position (GtkMenu  *menu,
-                                        gint     *x,
-                                        gint     *y,
-                                        gboolean *push_in,
-                                        gpointer  user_data)
-{
-  gimp_button_menu_position (user_data, menu, GTK_POS_LEFT, x, y);
-}
-
-static gboolean
-gimp_prop_kelvin_presets_button_press (GtkWidget      *widget,
-                                       GdkEventButton *bevent,
-                                       GtkMenu        *menu)
-{
-  if (bevent->type == GDK_BUTTON_PRESS)
-    {
-      gtk_menu_popup (menu,
-                      NULL, NULL,
-                      gimp_prop_kelvin_presets_menu_position, widget,
-                      bevent->button, bevent->time);
-    }
-
-  return TRUE;
-}
-
-static void
-gimp_prop_kelvin_presets_activate (GtkWidget *widget,
-                                   GObject   *config)
-{
-  const gchar *property_name;
-  gdouble     *kelvin;
-
-  property_name = g_object_get_data (G_OBJECT (widget), "property-name");
-  kelvin        = g_object_get_data (G_OBJECT (widget), "kelvin");
-
-  if (property_name && kelvin)
-    g_object_set (config, property_name, *kelvin, NULL);
-}
-
-static GtkWidget *
-gimp_prop_kelvin_presets_new (GObject     *config,
-                              const gchar *property_name)
-{
-  GtkWidget *button;
-  GtkWidget *menu;
-  gint       i;
-
-  const struct
-  {
-    gdouble      kelvin;
-    const gchar *label;
-  }
-  kelvin_presets[] =
-  {
-    { 1700, N_("1,700 K – Match flame") },
-    { 1850, N_("1,850 K – Candle flame, sunset/sunrise") },
-    { 3000, N_("3,000 K – Soft (or warm) white compact fluorescent lamps") },
-    { 3000, N_("3,300 K – Incandescent lamps") },
-    { 3200, N_("3,200 K – Studio lamps, photofloods, etc.") },
-    { 3350, N_("3,350 K – Studio \"CP\" light") },
-    { 4100, N_("4,100 K – Moonlight") },
-    { 5000, N_("5,000 K – D50") },
-    { 5000, N_("5,000 K – Cool white/daylight compact fluorescent lamps") },
-    { 5000, N_("5,000 K – Horizon daylight") },
-    { 5500, N_("5,500 K – D55") },
-    { 5500, N_("5,500 K – Vertical daylight, electronic flash") },
-    { 6200, N_("6,200 K – Xenon short-arc lamp") },
-    { 6500, N_("6,500 K – D65") },
-    { 6500, N_("6,500 K – Daylight, overcast") },
-    { 7500, N_("7,500 K – D75") },
-    { 9300, N_("9,300 K") }
-  };
-
-  button = gtk_button_new ();
-  gtk_widget_set_can_focus (button, FALSE);
-  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
-
-  gtk_button_set_image (GTK_BUTTON (button),
-                        gtk_image_new_from_icon_name (GIMP_ICON_MENU_LEFT,
-                                                      GTK_ICON_SIZE_MENU));
-
-  menu = gtk_menu_new ();
-  gtk_menu_attach_to_widget (GTK_MENU (menu), button, NULL);
-
-  g_signal_connect (button, "button-press-event",
-                    G_CALLBACK (gimp_prop_kelvin_presets_button_press),
-                    menu);
-
-  for (i = 0; i < G_N_ELEMENTS (kelvin_presets); i++)
-    {
-      GtkWidget *item;
-      gdouble   *kelvin;
-
-      item = gtk_menu_item_new_with_label (gettext (kelvin_presets[i].label));
-      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-      gtk_widget_show (item);
-
-      g_object_set_data_full (G_OBJECT (item), "property-name",
-                              g_strdup (property_name), (GDestroyNotify) g_free);
-
-      kelvin = g_new (gdouble, 1);
-      *kelvin = kelvin_presets[i].kelvin;
-
-      g_object_set_data_full (G_OBJECT (item), "kelvin",
-                              kelvin, (GDestroyNotify) g_free);
-
-      g_signal_connect (item, "activate",
-                        G_CALLBACK (gimp_prop_kelvin_presets_activate),
-                        config);
-
-    }
-
-  return button;
-}
-
-static void
-gimp_prop_widget_new_seed_clicked (GtkButton     *button,
-                                   GtkAdjustment *adj)
-{
-  guint32 value = g_random_int_range (gtk_adjustment_get_lower (adj),
-                                      gtk_adjustment_get_upper (adj));
-
-  gtk_adjustment_set_value (adj, value);
-}
-
 static gboolean
 gimp_prop_string_to_boolean (GBinding     *binding,
                              const GValue *from_value,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 81ac5b9..3fa7b74 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -378,6 +378,7 @@ app/propgui/gimppropgui-generic.c
 app/propgui/gimppropgui-hue-saturation.c
 app/propgui/gimppropgui-spiral.c
 app/propgui/gimppropgui-supernova.c
+app/propgui/gimppropgui-utils.c
 app/propgui/gimppropgui.c
 
 app/text/gimpfont.c


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