[gimp/gtk3-port: 149/262] libgimpwidgets: move all GimpColorButton members to a private struct



commit a8d3ed143b5d5b63853ce1dff88bed019c0a337a
Author: Michael Natterer <mitch gimp org>
Date:   Fri Dec 31 17:35:10 2010 +0100

    libgimpwidgets: move all GimpColorButton members to a private struct

 libgimpwidgets/gimpcolorbutton.c |  165 +++++++++++++++++++++++--------------
 libgimpwidgets/gimpcolorbutton.h |   12 +---
 2 files changed, 104 insertions(+), 73 deletions(-)
---
diff --git a/libgimpwidgets/gimpcolorbutton.c b/libgimpwidgets/gimpcolorbutton.c
index f428264..f5f6e7e 100644
--- a/libgimpwidgets/gimpcolorbutton.c
+++ b/libgimpwidgets/gimpcolorbutton.c
@@ -96,8 +96,15 @@ typedef struct _GimpColorButtonPrivate GimpColorButtonPrivate;
 
 struct _GimpColorButtonPrivate
 {
+  gchar           *title;
+  gboolean         continuous_update;
+
+  GtkWidget       *color_area;
+  GtkWidget       *dialog;
   GtkWidget       *selection;
 
+  GtkUIManager    *ui_manager;
+
   GimpColorConfig *config;
 };
 
@@ -340,23 +347,23 @@ static void
 gimp_color_button_init (GimpColorButton      *button,
                         GimpColorButtonClass *klass)
 {
-  GtkActionGroup *group;
-  GtkUIManager   *ui_manager;
-  gint            i;
+  GimpColorButtonPrivate *priv = GET_PRIVATE (button);
+  GtkActionGroup         *group;
+  gint                    i;
 
-  button->color_area = g_object_new (GIMP_TYPE_COLOR_AREA,
-                                     "drag-mask", GDK_BUTTON1_MASK,
-                                     NULL);
+  priv->color_area = g_object_new (GIMP_TYPE_COLOR_AREA,
+                                   "drag-mask", GDK_BUTTON1_MASK,
+                                   NULL);
 
-  g_signal_connect (button->color_area, "color-changed",
+  g_signal_connect (priv->color_area, "color-changed",
                     G_CALLBACK (gimp_color_button_area_changed),
                     button);
 
-  gtk_container_add (GTK_CONTAINER (button), button->color_area);
-  gtk_widget_show (button->color_area);
+  gtk_container_add (GTK_CONTAINER (button), priv->color_area);
+  gtk_widget_show (priv->color_area);
 
   /* right-click opens a popup */
-  button->popup_menu = ui_manager = gtk_ui_manager_new ();
+  priv->ui_manager = gtk_ui_manager_new ();
 
   group = gtk_action_group_new ("color-button");
 
@@ -384,11 +391,11 @@ gimp_color_button_init (GimpColorButton      *button,
       g_object_unref (action);
     }
 
-  gtk_ui_manager_insert_action_group (ui_manager, group, -1);
+  gtk_ui_manager_insert_action_group (priv->ui_manager, group, -1);
   g_object_unref (group);
 
   gtk_ui_manager_add_ui_from_string
-    (ui_manager,
+    (priv->ui_manager,
      "<ui>\n"
      "  <popup action=\"color-button-popup\">\n"
      "    <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_FG "\" />\n"
@@ -404,9 +411,9 @@ gimp_color_button_init (GimpColorButton      *button,
 static void
 gimp_color_button_finalize (GObject *object)
 {
-  GimpColorButton *button = GIMP_COLOR_BUTTON (object);
+  GimpColorButtonPrivate *priv = GET_PRIVATE (object);
 
-  g_clear_pointer (&button->title, g_free);
+  g_clear_pointer (&priv->title, g_free);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -417,12 +424,12 @@ gimp_color_button_dispose (GObject *object)
   GimpColorButton        *button = GIMP_COLOR_BUTTON (object);
   GimpColorButtonPrivate *priv   = GET_PRIVATE (button);
 
-  g_clear_pointer (&button->dialog, gtk_widget_destroy);
+  g_clear_pointer (&priv->dialog, gtk_widget_destroy);
   priv->selection = NULL;
 
-  g_clear_pointer (&button->color_area, gtk_widget_destroy);
+  g_clear_pointer (&priv->color_area, gtk_widget_destroy);
 
-  g_clear_object (&button->popup_menu);
+  g_clear_object (&priv->ui_manager);
 
   gimp_color_button_set_color_config (button, NULL);
 
@@ -441,19 +448,19 @@ gimp_color_button_get_property (GObject    *object,
   switch (property_id)
     {
     case PROP_TITLE:
-      g_value_set_string (value, button->title);
+      g_value_set_string (value, priv->title);
       break;
 
     case PROP_COLOR:
-      g_object_get_property (G_OBJECT (button->color_area), "color", value);
+      g_object_get_property (G_OBJECT (priv->color_area), "color", value);
       break;
 
     case PROP_TYPE:
-      g_object_get_property (G_OBJECT (button->color_area), "type", value);
+      g_object_get_property (G_OBJECT (priv->color_area), "type", value);
       break;
 
     case PROP_UPDATE:
-      g_value_set_boolean (value, button->continuous_update);
+      g_value_set_boolean (value, priv->continuous_update);
       break;
 
     case PROP_COLOR_CONFIG:
@@ -472,8 +479,9 @@ gimp_color_button_set_property (GObject      *object,
                                 const GValue *value,
                                 GParamSpec   *pspec)
 {
-  GimpColorButton *button = GIMP_COLOR_BUTTON (object);
-  gint             other;
+  GimpColorButton        *button = GIMP_COLOR_BUTTON (object);
+  GimpColorButtonPrivate *priv   = GET_PRIVATE (object);
+  gint                    other;
 
   switch (property_id)
     {
@@ -482,11 +490,11 @@ gimp_color_button_set_property (GObject      *object,
       break;
 
     case PROP_COLOR:
-      g_object_set_property (G_OBJECT (button->color_area), "color", value);
+      g_object_set_property (G_OBJECT (priv->color_area), "color", value);
       break;
 
     case PROP_TYPE:
-      g_object_set_property (G_OBJECT (button->color_area), "type", value);
+      g_object_set_property (G_OBJECT (priv->color_area), "type", value);
       break;
 
     case PROP_UPDATE:
@@ -494,14 +502,14 @@ gimp_color_button_set_property (GObject      *object,
       break;
 
     case PROP_AREA_WIDTH:
-      gtk_widget_get_size_request (button->color_area, NULL, &other);
-      gtk_widget_set_size_request (button->color_area,
+      gtk_widget_get_size_request (priv->color_area, NULL, &other);
+      gtk_widget_set_size_request (priv->color_area,
                                    g_value_get_int (value), other);
       break;
 
     case PROP_AREA_HEIGHT:
-      gtk_widget_get_size_request (button->color_area, &other, NULL);
-      gtk_widget_set_size_request (button->color_area,
+      gtk_widget_get_size_request (priv->color_area, &other, NULL);
+      gtk_widget_set_size_request (priv->color_area,
                                    other, g_value_get_int (value));
       break;
 
@@ -519,11 +527,11 @@ static gboolean
 gimp_color_button_button_press (GtkWidget      *widget,
                                 GdkEventButton *bevent)
 {
-  GimpColorButton *button = GIMP_COLOR_BUTTON (widget);
+  GimpColorButtonPrivate *priv = GET_PRIVATE (widget);
 
   if (gdk_event_triggers_context_menu ((GdkEvent *) bevent))
     {
-      GtkWidget *menu = gtk_ui_manager_get_widget (button->popup_menu,
+      GtkWidget *menu = gtk_ui_manager_get_widget (priv->ui_manager,
                                                    "/color-button-popup");
 
       gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
@@ -533,20 +541,17 @@ gimp_color_button_button_press (GtkWidget      *widget,
                       bevent->button, bevent->time);
     }
 
-  if (GTK_WIDGET_CLASS (parent_class)->button_press_event)
-    return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
-
-  return FALSE;
+  return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
 }
 
 static void
 gimp_color_button_state_flags_changed (GtkWidget     *widget,
                                        GtkStateFlags  previous_state)
 {
-  g_return_if_fail (GIMP_IS_COLOR_BUTTON (widget));
+  GimpColorButtonPrivate *priv = GET_PRIVATE (widget);
 
-  if (! gtk_widget_is_sensitive (widget) && GIMP_COLOR_BUTTON (widget)->dialog)
-    gtk_widget_hide (GIMP_COLOR_BUTTON (widget)->dialog);
+  if (! gtk_widget_is_sensitive (widget) && priv->dialog)
+    gtk_widget_hide (priv->dialog);
 
   if (GTK_WIDGET_CLASS (parent_class)->state_flags_changed)
     GTK_WIDGET_CLASS (parent_class)->state_flags_changed (widget,
@@ -560,12 +565,12 @@ gimp_color_button_clicked (GtkButton *button)
   GimpColorButtonPrivate *priv         = GET_PRIVATE (button);
   GimpRGB                 color;
 
-  if (! color_button->dialog)
+  if (! priv->dialog)
     {
       GtkWidget *dialog;
 
-      dialog = color_button->dialog =
-        gimp_dialog_new (color_button->title, "gimp-color-selection",
+      dialog = priv->dialog =
+        gimp_dialog_new (priv->title, "gimp-color-button",
                          gtk_widget_get_toplevel (GTK_WIDGET (button)), 0,
                          gimp_color_button_help_func, NULL,
 
@@ -588,7 +593,7 @@ gimp_color_button_clicked (GtkButton *button)
                         color_button);
       g_signal_connect (dialog, "destroy",
                         G_CALLBACK (gtk_widget_destroyed),
-                        &color_button->dialog);
+                        &priv->dialog);
 
       priv->selection = gimp_color_selection_new ();
       gtk_container_set_border_width (GTK_CONTAINER (priv->selection), 6);
@@ -619,7 +624,7 @@ gimp_color_button_clicked (GtkButton *button)
                                      gimp_color_button_selection_changed,
                                      button);
 
-  gtk_window_present (GTK_WINDOW (color_button->dialog));
+  gtk_window_present (GTK_WINDOW (priv->dialog));
 }
 
 static GType
@@ -682,14 +687,18 @@ void
 gimp_color_button_set_title (GimpColorButton *button,
                              const gchar     *title)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
   g_return_if_fail (title != NULL);
 
-  g_free (button->title);
-  button->title = g_strdup (title);
+  priv = GET_PRIVATE (button);
+
+  g_free (priv->title);
+  priv->title = g_strdup (title);
 
-  if (button->dialog)
-    gtk_window_set_title (GTK_WINDOW (button->dialog), title);
+  if (priv->dialog)
+    gtk_window_set_title (GTK_WINDOW (priv->dialog), title);
 
   g_object_notify (G_OBJECT (button), "title");
 }
@@ -705,9 +714,13 @@ gimp_color_button_set_title (GimpColorButton *button,
 const gchar *
 gimp_color_button_get_title (GimpColorButton *button)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), NULL);
 
-  return button->title;
+  priv = GET_PRIVATE (button);
+
+  return priv->title;
 }
 
 /**
@@ -721,10 +734,14 @@ void
 gimp_color_button_set_color (GimpColorButton *button,
                              const GimpRGB   *color)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
   g_return_if_fail (color != NULL);
 
-  gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
+  priv = GET_PRIVATE (button);
+
+  gimp_color_area_set_color (GIMP_COLOR_AREA (priv->color_area), color);
 
   g_object_notify (G_OBJECT (button), "color");
 }
@@ -740,10 +757,14 @@ void
 gimp_color_button_get_color (GimpColorButton *button,
                              GimpRGB         *color)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
   g_return_if_fail (color != NULL);
 
-  gimp_color_area_get_color (GIMP_COLOR_AREA (button->color_area), color);
+  priv = GET_PRIVATE (button);
+
+  gimp_color_area_get_color (GIMP_COLOR_AREA (priv->color_area), color);
 }
 
 /**
@@ -758,9 +779,13 @@ gimp_color_button_get_color (GimpColorButton *button,
 gboolean
 gimp_color_button_has_alpha (GimpColorButton *button)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
 
-  return gimp_color_area_has_alpha (GIMP_COLOR_AREA (button->color_area));
+  priv = GET_PRIVATE (button);
+
+  return gimp_color_area_has_alpha (GIMP_COLOR_AREA (priv->color_area));
 }
 
 /**
@@ -774,9 +799,13 @@ void
 gimp_color_button_set_type (GimpColorButton   *button,
                             GimpColorAreaType  type)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
 
-  gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
+  priv = GET_PRIVATE (button);
+
+  gimp_color_area_set_type (GIMP_COLOR_AREA (priv->color_area), type);
 
   g_object_notify (G_OBJECT (button), "type");
 }
@@ -792,9 +821,13 @@ gimp_color_button_set_type (GimpColorButton   *button,
 gboolean
 gimp_color_button_get_update (GimpColorButton *button)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
 
-  return button->continuous_update;
+  priv = GET_PRIVATE (button);
+
+  return priv->continuous_update;
 }
 
 /**
@@ -816,15 +849,15 @@ gimp_color_button_set_update (GimpColorButton *button,
 
   priv = GET_PRIVATE (button);
 
-  if (continuous != button->continuous_update)
+  if (continuous != priv->continuous_update)
     {
-      button->continuous_update = continuous ? TRUE : FALSE;
+      priv->continuous_update = continuous ? TRUE : FALSE;
 
       if (priv->selection)
         {
           GimpRGB color;
 
-          if (button->continuous_update)
+          if (priv->continuous_update)
             {
               gimp_color_selection_get_color (GIMP_COLOR_SELECTION (priv->selection),
                                               &color);
@@ -894,9 +927,13 @@ gimp_color_button_set_color_config (GimpColorButton *button,
 GtkUIManager *
 gimp_color_button_get_ui_manager (GimpColorButton *button)
 {
+  GimpColorButtonPrivate *priv;
+
   g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), NULL);
 
-  return button->popup_menu;
+  priv = GET_PRIVATE (button);
+
+  return priv->ui_manager;
 }
 
 
@@ -917,7 +954,7 @@ gimp_color_button_dialog_response (GtkWidget       *dialog,
       break;
 
     case GTK_RESPONSE_OK:
-      if (! button->continuous_update)
+      if (! priv->continuous_update)
         {
           gimp_color_selection_get_color (GIMP_COLOR_SELECTION (priv->selection),
                                           &color);
@@ -928,7 +965,7 @@ gimp_color_button_dialog_response (GtkWidget       *dialog,
       break;
 
     default:
-      if (button->continuous_update)
+      if (priv->continuous_update)
         {
           gimp_color_selection_get_old_color (GIMP_COLOR_SELECTION (priv->selection),
                                               &color);
@@ -1007,19 +1044,21 @@ static void
 gimp_color_button_selection_changed (GtkWidget       *selection,
                                      GimpColorButton *button)
 {
-  if (button->continuous_update)
+  GimpColorButtonPrivate *priv = GET_PRIVATE (button);
+
+  if (priv->continuous_update)
     {
       GimpRGB color;
 
       gimp_color_selection_get_color (GIMP_COLOR_SELECTION (selection), &color);
 
-      g_signal_handlers_block_by_func (button->color_area,
+      g_signal_handlers_block_by_func (priv->color_area,
                                        gimp_color_button_area_changed,
                                        button);
 
-      gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), &color);
+      gimp_color_area_set_color (GIMP_COLOR_AREA (priv->color_area), &color);
 
-      g_signal_handlers_unblock_by_func (button->color_area,
+      g_signal_handlers_unblock_by_func (priv->color_area,
                                          gimp_color_button_area_changed,
                                          button);
 
diff --git a/libgimpwidgets/gimpcolorbutton.h b/libgimpwidgets/gimpcolorbutton.h
index 1347488..4c4d0b5 100644
--- a/libgimpwidgets/gimpcolorbutton.h
+++ b/libgimpwidgets/gimpcolorbutton.h
@@ -49,16 +49,7 @@ typedef struct _GimpColorButtonClass  GimpColorButtonClass;
 
 struct _GimpColorButton
 {
-  GimpButton      parent_instance;
-
-  gchar          *title;
-  gboolean        continuous_update;
-
-  GtkWidget      *color_area;
-  GtkWidget      *dialog;
-
-  /*< private >*/
-  gpointer        popup_menu;
+  GimpButton  parent_instance;
 };
 
 struct _GimpColorButtonClass
@@ -72,6 +63,7 @@ struct _GimpColorButtonClass
   GType (* get_action_type) (GimpColorButton *button);
 
   /* Padding for future expansion */
+  void (* _gimp_reserved1) (void);
   void (* _gimp_reserved2) (void);
   void (* _gimp_reserved3) (void);
   void (* _gimp_reserved4) (void);


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