[gimp/gtk3-port: 192/215] libgimpwidgets: move all GimpColorButton members to a private struct
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 192/215] libgimpwidgets: move all GimpColorButton members to a private struct
- Date: Mon, 3 Jan 2011 15:14:31 +0000 (UTC)
commit a2103a723a93e9b7b1c88978cfd53912223ee349
Author: Michael Natterer <mitch gimp org>
Date: Fri Dec 31 17:35:10 2010 +0100
libgimpwidgets: move all GimpColorButton members to a private struct
app/widgets/gimpcolorpanel.c | 4 +-
libgimpwidgets/gimpcolorbutton.c | 266 +++++++++++++++++++++++++++-----------
libgimpwidgets/gimpcolorbutton.h | 49 ++++----
3 files changed, 216 insertions(+), 103 deletions(-)
---
diff --git a/app/widgets/gimpcolorpanel.c b/app/widgets/gimpcolorpanel.c
index b77a80f..973a31d 100644
--- a/app/widgets/gimpcolorpanel.c
+++ b/app/widgets/gimpcolorpanel.c
@@ -108,7 +108,7 @@ gimp_color_panel_button_press (GtkWidget *widget,
color_button = GIMP_COLOR_BUTTON (widget);
color_panel = GIMP_COLOR_PANEL (widget);
- ui_manager = GTK_UI_MANAGER (color_button->popup_menu);
+ ui_manager = gimp_color_button_get_ui_manager (color_button);
group = gtk_ui_manager_get_action_groups (ui_manager)->data;
@@ -160,7 +160,7 @@ gimp_color_panel_clicked (GtkButton *button)
{
panel->color_dialog =
gimp_color_dialog_new (NULL, panel->context,
- GIMP_COLOR_BUTTON (button)->title,
+ gimp_color_button_get_title (GIMP_COLOR_BUTTON (button)),
NULL, NULL,
GTK_WIDGET (button),
NULL, NULL,
diff --git a/libgimpwidgets/gimpcolorbutton.c b/libgimpwidgets/gimpcolorbutton.c
index a1af97c..6407f77 100644
--- a/libgimpwidgets/gimpcolorbutton.c
+++ b/libgimpwidgets/gimpcolorbutton.c
@@ -86,6 +86,24 @@ enum
};
+typedef struct _GimpColorButtonPrivate GimpColorButtonPrivate;
+
+struct _GimpColorButtonPrivate
+{
+ gchar *title;
+ gboolean continuous_update;
+
+ GtkWidget *color_area;
+ GtkWidget *dialog;
+
+ GtkUIManager *ui_manager;
+};
+
+#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
+ GIMP_TYPE_COLOR_BUTTON, \
+ GimpColorButtonPrivate)
+
+
static void gimp_color_button_class_init (GimpColorButtonClass *klass);
static void gimp_color_button_init (GimpColorButton *button,
GimpColorButtonClass *klass);
@@ -263,32 +281,34 @@ gimp_color_button_class_init (GimpColorButtonClass *klass)
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
+
+ g_type_class_add_private (object_class, sizeof (GimpColorButtonPrivate));
}
static void
gimp_color_button_init (GimpColorButton *button,
GimpColorButtonClass *klass)
{
- GtkActionGroup *group;
- GtkUIManager *ui_manager;
- gint i;
+ GimpColorButtonPrivate *private = GET_PRIVATE (button);
+ GtkActionGroup *group;
+ gint i;
- button->title = NULL;
- button->dialog = NULL;
+ private->title = NULL;
+ private->dialog = NULL;
- button->color_area = g_object_new (GIMP_TYPE_COLOR_AREA,
- "drag-mask", GDK_BUTTON1_MASK,
- NULL);
+ private->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 (private->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), private->color_area);
+ gtk_widget_show (private->color_area);
/* right-click opens a popup */
- button->popup_menu = ui_manager = gtk_ui_manager_new ();
+ private->ui_manager = gtk_ui_manager_new ();
group = gtk_action_group_new ("color-button");
@@ -316,11 +336,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 (private->ui_manager, group, -1);
g_object_unref (group);
gtk_ui_manager_add_ui_from_string
- (ui_manager,
+ (private->ui_manager,
"<ui>\n"
" <popup action=\"color-button-popup\">\n"
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_FG "\" />\n"
@@ -336,12 +356,12 @@ gimp_color_button_init (GimpColorButton *button,
static void
gimp_color_button_finalize (GObject *object)
{
- GimpColorButton *button = GIMP_COLOR_BUTTON (object);
+ GimpColorButtonPrivate *private = GET_PRIVATE (object);
- if (button->title)
+ if (private->title)
{
- g_free (button->title);
- button->title = NULL;
+ g_free (private->title);
+ private->title = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -350,24 +370,24 @@ gimp_color_button_finalize (GObject *object)
static void
gimp_color_button_dispose (GObject *object)
{
- GimpColorButton *button = GIMP_COLOR_BUTTON (object);
+ GimpColorButtonPrivate *private = GET_PRIVATE (object);
- if (button->dialog)
+ if (private->dialog)
{
- gtk_widget_destroy (button->dialog);
- button->dialog = NULL;
+ gtk_widget_destroy (private->dialog);
+ private->dialog = NULL;
}
- if (button->color_area)
+ if (private->color_area)
{
- gtk_widget_destroy (button->color_area);
- button->color_area = NULL;
+ gtk_widget_destroy (private->color_area);
+ private->color_area = NULL;
}
- if (button->popup_menu)
+ if (private->ui_manager)
{
- g_object_unref (button->popup_menu);
- button->popup_menu = NULL;
+ g_object_unref (private->ui_manager);
+ private->ui_manager = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
@@ -379,24 +399,24 @@ gimp_color_button_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GimpColorButton *button = GIMP_COLOR_BUTTON (object);
+ GimpColorButtonPrivate *private = GET_PRIVATE (object);
switch (property_id)
{
case PROP_TITLE:
- g_value_set_string (value, button->title);
+ g_value_set_string (value, private->title);
break;
case PROP_COLOR:
- g_object_get_property (G_OBJECT (button->color_area), "color", value);
+ g_object_get_property (G_OBJECT (private->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 (private->color_area), "type", value);
break;
case PROP_UPDATE:
- g_value_set_boolean (value, button->continuous_update);
+ g_value_set_boolean (value, private->continuous_update);
break;
default:
@@ -411,21 +431,22 @@ gimp_color_button_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GimpColorButton *button = GIMP_COLOR_BUTTON (object);
+ GimpColorButton *button = GIMP_COLOR_BUTTON (object);
+ GimpColorButtonPrivate *private = GET_PRIVATE (object);
switch (property_id)
{
case PROP_TITLE:
- g_free (button->title);
- button->title = g_value_dup_string (value);
+ g_free (private->title);
+ private->title = g_value_dup_string (value);
break;
case PROP_COLOR:
- g_object_set_property (G_OBJECT (button->color_area), "color", value);
+ g_object_set_property (G_OBJECT (private->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 (private->color_area), "type", value);
break;
case PROP_UPDATE:
@@ -442,11 +463,11 @@ static gboolean
gimp_color_button_button_press (GtkWidget *widget,
GdkEventButton *bevent)
{
- GimpColorButton *button = GIMP_COLOR_BUTTON (widget);
+ GimpColorButtonPrivate *private = GET_PRIVATE (widget);
if (bevent->button == 3)
{
- GtkWidget *menu = gtk_ui_manager_get_widget (button->popup_menu,
+ GtkWidget *menu = gtk_ui_manager_get_widget (private->ui_manager,
"/color-button-popup");
gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
@@ -456,20 +477,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 *private = 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) && private->dialog)
+ gtk_widget_hide (private->dialog);
if (GTK_WIDGET_CLASS (parent_class)->state_flags_changed)
GTK_WIDGET_CLASS (parent_class)->state_flags_changed (widget,
@@ -479,9 +497,10 @@ gimp_color_button_state_flags_changed (GtkWidget *widget,
static void
gimp_color_button_clicked (GtkButton *button)
{
- GimpColorButton *color_button = GIMP_COLOR_BUTTON (button);
+ GimpColorButton *color_button = GIMP_COLOR_BUTTON (button);
+ GimpColorButtonPrivate *private = GET_PRIVATE (button);
- if (! color_button->dialog)
+ if (! private->dialog)
{
GtkWidget *dialog;
GtkWidget *selection;
@@ -489,8 +508,8 @@ gimp_color_button_clicked (GtkButton *button)
gimp_color_button_get_color (color_button, &color);
- dialog = color_button->dialog =
- gimp_dialog_new (color_button->title, COLOR_SELECTION_KEY,
+ dialog = private->dialog =
+ gimp_dialog_new (private->title, COLOR_SELECTION_KEY,
gtk_widget_get_toplevel (GTK_WIDGET (button)), 0,
gimp_color_button_help_func, NULL,
@@ -511,7 +530,7 @@ gimp_color_button_clicked (GtkButton *button)
color_button);
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
- &color_button->dialog);
+ &private->dialog);
selection = gimp_color_selection_new ();
gtk_container_set_border_width (GTK_CONTAINER (selection), 6);
@@ -528,11 +547,11 @@ gimp_color_button_clicked (GtkButton *button)
G_CALLBACK (gimp_color_button_selection_changed),
button);
- g_object_set_data (G_OBJECT (color_button->dialog), COLOR_SELECTION_KEY,
+ g_object_set_data (G_OBJECT (private->dialog), COLOR_SELECTION_KEY,
selection);
}
- gtk_window_present (GTK_WINDOW (color_button->dialog));
+ gtk_window_present (GTK_WINDOW (private->dialog));
}
static GType
@@ -579,12 +598,61 @@ gimp_color_button_new (const gchar *title,
"color", color,
NULL);
- gtk_widget_set_size_request (GTK_WIDGET (button->color_area), width, height);
+ gtk_widget_set_size_request (GET_PRIVATE (button)->color_area, width, height);
return GTK_WIDGET (button);
}
/**
+ * gimp_color_button_set_title:
+ * @button: a #GimpColorButton.
+ * @color: the new title.
+ *
+ * Sets the @button dialog's title.
+ *
+ * Since: GIMP 3.0
+ **/
+void
+gimp_color_button_set_title (GimpColorButton *button,
+ const gchar *title)
+{
+ GimpColorButtonPrivate *private;
+
+ g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
+ g_return_if_fail (title != NULL);
+
+ private = GET_PRIVATE (button);
+
+ g_free (private->title);
+ private->title = g_strdup (title);
+
+ if (private->dialog)
+ gtk_window_set_title (GTK_WINDOW (private->dialog), title);
+
+ g_object_notify (G_OBJECT (button), "title");
+}
+
+/**
+ * gimp_color_button_get_title:
+ * @button: a #GimpColorButton.
+ *
+ * Returns: The @button dialog's title.
+ *
+ * Since: GIMP 3.0
+ **/
+const gchar *
+gimp_color_button_get_title (GimpColorButton *button)
+{
+ GimpColorButtonPrivate *private;
+
+ g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), NULL);
+
+ private = GET_PRIVATE (button);
+
+ return private->title;
+}
+
+/**
* gimp_color_button_set_color:
* @button: Pointer to a #GimpColorButton.
* @color: Pointer to the new #GimpRGB color.
@@ -595,10 +663,14 @@ void
gimp_color_button_set_color (GimpColorButton *button,
const GimpRGB *color)
{
+ GimpColorButtonPrivate *private;
+
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);
+ private = GET_PRIVATE (button);
+
+ gimp_color_area_set_color (GIMP_COLOR_AREA (private->color_area), color);
g_object_notify (G_OBJECT (button), "color");
}
@@ -614,10 +686,14 @@ void
gimp_color_button_get_color (GimpColorButton *button,
GimpRGB *color)
{
+ GimpColorButtonPrivate *private;
+
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);
+ private = GET_PRIVATE (button);
+
+ gimp_color_area_get_color (GIMP_COLOR_AREA (private->color_area), color);
}
/**
@@ -632,9 +708,13 @@ gimp_color_button_get_color (GimpColorButton *button,
gboolean
gimp_color_button_has_alpha (GimpColorButton *button)
{
+ GimpColorButtonPrivate *private;
+
g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
- return gimp_color_area_has_alpha (GIMP_COLOR_AREA (button->color_area));
+ private = GET_PRIVATE (button);
+
+ return gimp_color_area_has_alpha (GIMP_COLOR_AREA (private->color_area));
}
/**
@@ -648,9 +728,13 @@ void
gimp_color_button_set_type (GimpColorButton *button,
GimpColorAreaType type)
{
+ GimpColorButtonPrivate *private;
+
g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
- gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
+ private = GET_PRIVATE (button);
+
+ gimp_color_area_set_type (GIMP_COLOR_AREA (private->color_area), type);
g_object_notify (G_OBJECT (button), "type");
}
@@ -666,9 +750,13 @@ gimp_color_button_set_type (GimpColorButton *button,
gboolean
gimp_color_button_get_update (GimpColorButton *button)
{
+ GimpColorButtonPrivate *private;
+
g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), FALSE);
- return button->continuous_update;
+ private = GET_PRIVATE (button);
+
+ return private->continuous_update;
}
/**
@@ -684,21 +772,25 @@ void
gimp_color_button_set_update (GimpColorButton *button,
gboolean continuous)
{
+ GimpColorButtonPrivate *private;
+
g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
- if (continuous != button->continuous_update)
+ private = GET_PRIVATE (button);
+
+ if (continuous != private->continuous_update)
{
- button->continuous_update = continuous ? TRUE : FALSE;
+ private->continuous_update = continuous ? TRUE : FALSE;
- if (button->dialog)
+ if (private->dialog)
{
GimpColorSelection *selection;
GimpRGB color;
- selection = g_object_get_data (G_OBJECT (button->dialog),
+ selection = g_object_get_data (G_OBJECT (private->dialog),
COLOR_SELECTION_KEY);
- if (button->continuous_update)
+ if (private->continuous_update)
{
gimp_color_selection_get_color (selection, &color);
gimp_color_button_set_color (button, &color);
@@ -714,6 +806,25 @@ gimp_color_button_set_update (GimpColorButton *button,
}
}
+/**
+ * gimp_color_button_get_ui_manager:
+ * @button: a #GimpColorButton.
+ *
+ * Returns: The @button's #GtkUIManager.
+ *
+ * Since: GIMP 3.0
+ **/
+GtkUIManager *
+gimp_color_button_get_ui_manager (GimpColorButton *button)
+{
+ GimpColorButtonPrivate *private;
+
+ g_return_val_if_fail (GIMP_IS_COLOR_BUTTON (button), NULL);
+
+ private = GET_PRIVATE (button);
+
+ return private->ui_manager;
+}
/* private functions */
@@ -722,8 +833,9 @@ gimp_color_button_dialog_response (GtkWidget *dialog,
gint response_id,
GimpColorButton *button)
{
- GtkWidget *selection;
- GimpRGB color;
+ GimpColorButtonPrivate *private = GET_PRIVATE (button);
+ GtkWidget *selection;
+ GimpRGB color;
selection = g_object_get_data (G_OBJECT (dialog), COLOR_SELECTION_KEY);
@@ -734,7 +846,7 @@ gimp_color_button_dialog_response (GtkWidget *dialog,
break;
case GTK_RESPONSE_OK:
- if (! button->continuous_update)
+ if (! private->continuous_update)
{
gimp_color_selection_get_color (GIMP_COLOR_SELECTION (selection),
&color);
@@ -745,7 +857,7 @@ gimp_color_button_dialog_response (GtkWidget *dialog,
break;
default:
- if (button->continuous_update)
+ if (private->continuous_update)
{
gimp_color_selection_get_old_color (GIMP_COLOR_SELECTION (selection),
&color);
@@ -797,12 +909,14 @@ static void
gimp_color_button_area_changed (GtkWidget *color_area,
GimpColorButton *button)
{
- if (button->dialog)
+ GimpColorButtonPrivate *private = GET_PRIVATE (button);
+
+ if (private->dialog)
{
GimpColorSelection *selection;
GimpRGB color;
- selection = g_object_get_data (G_OBJECT (button->dialog),
+ selection = g_object_get_data (G_OBJECT (private->dialog),
COLOR_SELECTION_KEY);
gimp_color_button_get_color (button, &color);
@@ -825,19 +939,21 @@ static void
gimp_color_button_selection_changed (GtkWidget *selection,
GimpColorButton *button)
{
- if (button->continuous_update)
+ GimpColorButtonPrivate *private = GET_PRIVATE (button);
+
+ if (private->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 (private->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 (private->color_area), &color);
- g_signal_handlers_unblock_by_func (button->color_area,
+ g_signal_handlers_unblock_by_func (private->color_area,
gimp_color_button_area_changed,
button);
diff --git a/libgimpwidgets/gimpcolorbutton.h b/libgimpwidgets/gimpcolorbutton.h
index 3db5c04..0af4d6c 100644
--- a/libgimpwidgets/gimpcolorbutton.h
+++ b/libgimpwidgets/gimpcolorbutton.h
@@ -45,16 +45,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
@@ -68,33 +59,39 @@ 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);
};
-GType gimp_color_button_get_type (void) G_GNUC_CONST;
+GType gimp_color_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget * gimp_color_button_new (const gchar *title,
+ gint width,
+ gint height,
+ const GimpRGB *color,
+ GimpColorAreaType type);
-GtkWidget * gimp_color_button_new (const gchar *title,
- gint width,
- gint height,
- const GimpRGB *color,
- GimpColorAreaType type);
+void gimp_color_button_set_title (GimpColorButton *button,
+ const gchar *title);
+const gchar * gimp_color_button_get_title (GimpColorButton *button);
-void gimp_color_button_set_color (GimpColorButton *button,
- const GimpRGB *color);
-void gimp_color_button_get_color (GimpColorButton *button,
- GimpRGB *color);
+void gimp_color_button_set_color (GimpColorButton *button,
+ const GimpRGB *color);
+void gimp_color_button_get_color (GimpColorButton *button,
+ GimpRGB *color);
-gboolean gimp_color_button_has_alpha (GimpColorButton *button);
-void gimp_color_button_set_type (GimpColorButton *button,
- GimpColorAreaType type);
+gboolean gimp_color_button_has_alpha (GimpColorButton *button);
+void gimp_color_button_set_type (GimpColorButton *button,
+ GimpColorAreaType type);
-gboolean gimp_color_button_get_update (GimpColorButton *button);
-void gimp_color_button_set_update (GimpColorButton *button,
- gboolean continuous);
+gboolean gimp_color_button_get_update (GimpColorButton *button);
+void gimp_color_button_set_update (GimpColorButton *button,
+ gboolean continuous);
+GtkUIManager * gimp_color_button_get_ui_manager (GimpColorButton *button);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]