[gimp/gtk3-port: 161/224] libgimpwidgets: move all GimpChainButton members to a private struct



commit f3cd9a926e7cb91fdaf065720b888a08291eab09
Author: Michael Natterer <mitch gimp org>
Date:   Fri Dec 31 18:17:11 2010 +0100

    libgimpwidgets: move all GimpChainButton members to a private struct

 libgimpwidgets/gimpchainbutton.c |  122 +++++++++++++++++++++++++++----------
 libgimpwidgets/gimpchainbutton.h |   14 +---
 plug-ins/common/file-svg.c       |    2 +-
 plug-ins/common/file-wmf.c       |    2 +-
 4 files changed, 95 insertions(+), 45 deletions(-)
---
diff --git a/libgimpwidgets/gimpchainbutton.c b/libgimpwidgets/gimpchainbutton.c
index dd72689..334ff41 100644
--- a/libgimpwidgets/gimpchainbutton.c
+++ b/libgimpwidgets/gimpchainbutton.c
@@ -63,6 +63,25 @@ enum
   LAST_SIGNAL
 };
 
+
+typedef struct _GimpChainButtonPrivate GimpChainButtonPrivate;
+
+struct _GimpChainButtonPrivate
+{
+  GimpChainPosition  position;
+  gboolean           active;
+
+  GtkWidget         *button;
+  GtkWidget         *line1;
+  GtkWidget         *line2;
+  GtkWidget         *image;
+};
+
+#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
+                                                      GIMP_TYPE_CHAIN_BUTTON, \
+                                                      GimpChainButtonPrivate)
+
+
 static void      gimp_chain_button_constructed      (GObject         *object);
 static void      gimp_chain_button_set_property     (GObject         *object,
                                                      guint            property_id,
@@ -129,21 +148,25 @@ gimp_chain_button_class_init (GimpChainButtonClass *klass)
                                                       GIMP_CHAIN_TOP,
                                                       G_PARAM_CONSTRUCT_ONLY |
                                                       GIMP_PARAM_READWRITE));
+
+  g_type_class_add_private (object_class, sizeof (GimpChainButtonPrivate));
 }
 
 static void
 gimp_chain_button_init (GimpChainButton *button)
 {
-  button->position = GIMP_CHAIN_TOP;
-  button->active   = FALSE;
-  button->image    = gtk_image_new ();
-  button->button   = gtk_button_new ();
+  GimpChainButtonPrivate *private = GET_PRIVATE (button);
 
-  gtk_button_set_relief (GTK_BUTTON (button->button), GTK_RELIEF_NONE);
-  gtk_container_add (GTK_CONTAINER (button->button), button->image);
-  gtk_widget_show (button->image);
+  private->position = GIMP_CHAIN_TOP;
+  private->active   = FALSE;
+  private->image    = gtk_image_new ();
+  private->button   = gtk_button_new ();
 
-  g_signal_connect (button->button, "clicked",
+  gtk_button_set_relief (GTK_BUTTON (private->button), GTK_RELIEF_NONE);
+  gtk_container_add (GTK_CONTAINER (private->button), private->image);
+  gtk_widget_show (private->image);
+
+  g_signal_connect (private->button, "clicked",
                     G_CALLBACK (gimp_chain_button_clicked_callback),
                     button);
 }
@@ -151,40 +174,41 @@ gimp_chain_button_init (GimpChainButton *button)
 static void
 gimp_chain_button_constructed (GObject *object)
 {
-  GimpChainButton *button = GIMP_CHAIN_BUTTON (object);
+  GimpChainButton        *button  = GIMP_CHAIN_BUTTON (object);
+  GimpChainButtonPrivate *private = GET_PRIVATE (button);
 
   if (G_OBJECT_CLASS (parent_class)->constructed)
     G_OBJECT_CLASS (parent_class)->constructed (object);
 
-  button->line1 = gimp_chain_line_new (button->position, 1);
-  button->line2 = gimp_chain_line_new (button->position, -1);
+  private->line1 = gimp_chain_line_new (private->position, 1);
+  private->line2 = gimp_chain_line_new (private->position, -1);
 
   gimp_chain_button_update_image (button);
 
-  if (button->position & GIMP_CHAIN_LEFT) /* are we a vertical chainbutton? */
+  if (private->position & GIMP_CHAIN_LEFT) /* are we a vertical chainbutton? */
     {
       gtk_table_resize (GTK_TABLE (button), 3, 1);
-      gtk_table_attach (GTK_TABLE (button), button->button, 0, 1, 1, 2,
+      gtk_table_attach (GTK_TABLE (button), private->button, 0, 1, 1, 2,
                         GTK_SHRINK, GTK_SHRINK, 0, 0);
       gtk_table_attach_defaults (GTK_TABLE (button),
-                                 button->line1, 0, 1, 0, 1);
+                                 private->line1, 0, 1, 0, 1);
       gtk_table_attach_defaults (GTK_TABLE (button),
-                                 button->line2, 0, 1, 2, 3);
+                                 private->line2, 0, 1, 2, 3);
     }
   else
     {
       gtk_table_resize (GTK_TABLE (button), 1, 3);
-      gtk_table_attach (GTK_TABLE (button), button->button, 1, 2, 0, 1,
+      gtk_table_attach (GTK_TABLE (button), private->button, 1, 2, 0, 1,
                         GTK_SHRINK, GTK_SHRINK, 0, 0);
       gtk_table_attach_defaults (GTK_TABLE (button),
-                                 button->line1, 0, 1, 0, 1);
+                                 private->line1, 0, 1, 0, 1);
       gtk_table_attach_defaults (GTK_TABLE (button),
-                                 button->line2, 2, 3, 0, 1);
+                                 private->line2, 2, 3, 0, 1);
     }
 
-  gtk_widget_show (button->button);
-  gtk_widget_show (button->line1);
-  gtk_widget_show (button->line2);
+  gtk_widget_show (private->button);
+  gtk_widget_show (private->line1);
+  gtk_widget_show (private->line2);
 }
 
 static void
@@ -193,12 +217,12 @@ gimp_chain_button_set_property (GObject      *object,
                                 const GValue *value,
                                 GParamSpec   *pspec)
 {
-  GimpChainButton *button = GIMP_CHAIN_BUTTON (object);
+  GimpChainButtonPrivate *private = GET_PRIVATE (object);
 
   switch (property_id)
     {
     case PROP_POSITION:
-      button->position = g_value_get_enum (value);
+      private->position = g_value_get_enum (value);
       break;
 
     default:
@@ -213,12 +237,12 @@ gimp_chain_button_get_property (GObject    *object,
                                 GValue     *value,
                                 GParamSpec *pspec)
 {
-  GimpChainButton *button = GIMP_CHAIN_BUTTON (object);
+  GimpChainButtonPrivate *private = GET_PRIVATE (object);
 
   switch (property_id)
     {
     case PROP_POSITION:
-      g_value_set_enum (value, button->position);
+      g_value_set_enum (value, private->position);
       break;
 
     default:
@@ -265,11 +289,15 @@ void
 gimp_chain_button_set_active (GimpChainButton  *button,
                               gboolean          active)
 {
+  GimpChainButtonPrivate *private;
+
   g_return_if_fail (GIMP_IS_CHAIN_BUTTON (button));
 
-  if (button->active != active)
+  private = GET_PRIVATE (button);
+
+  if (private->active != active)
     {
-      button->active = active ? TRUE : FALSE;
+      private->active = active ? TRUE : FALSE;
 
       gimp_chain_button_update_image (button);
     }
@@ -286,18 +314,45 @@ gimp_chain_button_set_active (GimpChainButton  *button,
 gboolean
 gimp_chain_button_get_active (GimpChainButton *button)
 {
+  GimpChainButtonPrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_CHAIN_BUTTON (button), FALSE);
+
+  private = GET_PRIVATE (button);
+
+  return private->active;
+}
+
+/**
+ * gimp_chain_button_get_button
+ * @button: A #GimpChainButton.
+ *
+ * Returns: The #GimpChainButton's button.
+ *
+ * Since: GIMP 3.0
+ */
+GtkWidget *
+gimp_chain_button_get_button (GimpChainButton *button)
+{
+  GimpChainButtonPrivate *private;
+
   g_return_val_if_fail (GIMP_IS_CHAIN_BUTTON (button), FALSE);
 
-  return button->active;
+  private = GET_PRIVATE (button);
+
+  return private->button;
 }
 
+
+/*  private functions  */
+
 static void
 gimp_chain_button_clicked_callback (GtkWidget       *widget,
                                     GimpChainButton *button)
 {
-  g_return_if_fail (GIMP_IS_CHAIN_BUTTON (button));
+  GimpChainButtonPrivate *private = GET_PRIVATE (button);
 
-  gimp_chain_button_set_active (button, ! button->active);
+  gimp_chain_button_set_active (button, ! private->active);
 
   g_signal_emit (button, gimp_chain_button_signals[TOGGLED], 0);
 }
@@ -305,11 +360,12 @@ gimp_chain_button_clicked_callback (GtkWidget       *widget,
 static void
 gimp_chain_button_update_image (GimpChainButton *button)
 {
-  guint i;
+  GimpChainButtonPrivate *private = GET_PRIVATE (button);
+  guint                   i;
 
-  i = ((button->position & GIMP_CHAIN_LEFT) << 1) + (button->active ? 0 : 1);
+  i = ((private->position & GIMP_CHAIN_LEFT) << 1) + (private->active ? 0 : 1);
 
-  gtk_image_set_from_stock (GTK_IMAGE (button->image),
+  gtk_image_set_from_stock (GTK_IMAGE (private->image),
                             gimp_chain_stock_items[i],
                             GTK_ICON_SIZE_BUTTON);
 }
diff --git a/libgimpwidgets/gimpchainbutton.h b/libgimpwidgets/gimpchainbutton.h
index a74a40a..d4a9348 100644
--- a/libgimpwidgets/gimpchainbutton.h
+++ b/libgimpwidgets/gimpchainbutton.h
@@ -45,19 +45,11 @@ G_BEGIN_DECLS
 #define GIMP_CHAIN_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CHAIN_BUTTON, GimpChainButtonClass))
 
 
-typedef struct _GimpChainButtonClass  GimpChainButtonClass;
+typedef struct _GimpChainButtonClass GimpChainButtonClass;
 
 struct _GimpChainButton
 {
-  GtkTable           parent_instance;
-
-  GimpChainPosition  position;
-  gboolean           active;
-
-  GtkWidget         *button;
-  GtkWidget         *line1;
-  GtkWidget         *line2;
-  GtkWidget         *image;
+  GtkTable  parent_instance;
 };
 
 struct _GimpChainButtonClass
@@ -82,6 +74,8 @@ void        gimp_chain_button_set_active (GimpChainButton   *button,
                                           gboolean           active);
 gboolean    gimp_chain_button_get_active (GimpChainButton   *button);
 
+GtkWidget * gimp_chain_button_get_button (GimpChainButton   *button);
+
 
 G_END_DECLS
 
diff --git a/plug-ins/common/file-svg.c b/plug-ins/common/file-svg.c
index eb3e5b7..87c0d52 100644
--- a/plug-ins/common/file-svg.c
+++ b/plug-ins/common/file-svg.c
@@ -902,7 +902,7 @@ load_dialog (const gchar  *filename,
   gtk_table_attach_defaults (GTK_TABLE (table2), constrain, 1, 2, 0, 2);
   gtk_widget_show (constrain);
 
-  gimp_help_set_help_data (GIMP_CHAIN_BUTTON (constrain)->button,
+  gimp_help_set_help_data (gimp_chain_button_get_button (GIMP_CHAIN_BUTTON (constrain)),
                            _("Constrain aspect ratio"), NULL);
 
   gtk_widget_show (table2);
diff --git a/plug-ins/common/file-wmf.c b/plug-ins/common/file-wmf.c
index 798c05d..9df1ffd 100644
--- a/plug-ins/common/file-wmf.c
+++ b/plug-ins/common/file-wmf.c
@@ -683,7 +683,7 @@ load_dialog (const gchar *filename)
   gtk_table_attach_defaults (GTK_TABLE (table2), constrain, 1, 2, 0, 2);
   gtk_widget_show (constrain);
 
-  gimp_help_set_help_data (GIMP_CHAIN_BUTTON (constrain)->button,
+  gimp_help_set_help_data (gimp_chain_button_get_button (GIMP_CHAIN_BUTTON (constrain)),
                            _("Constrain aspect ratio"), NULL);
 
   gtk_widget_show (table2);



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