[gimp/gtk3-port: 155/240] libgimpwidgets: move all GimpColorHexEntry members to a private struct
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 155/240] libgimpwidgets: move all GimpColorHexEntry members to a private struct
- Date: Sat, 28 Apr 2018 18:36:00 +0000 (UTC)
commit a0975a03230d9c15873c389e7a76db0587975194
Author: Michael Natterer <mitch gimp org>
Date: Sun Jan 2 01:29:39 2011 +0100
libgimpwidgets: move all GimpColorHexEntry members to a private struct
libgimpwidgets/gimpcolorhexentry.c | 57 ++++++++++++++++++++++++++---------
libgimpwidgets/gimpcolorhexentry.h | 4 +--
2 files changed, 43 insertions(+), 18 deletions(-)
---
diff --git a/libgimpwidgets/gimpcolorhexentry.c b/libgimpwidgets/gimpcolorhexentry.c
index 7393506..42b4485 100644
--- a/libgimpwidgets/gimpcolorhexentry.c
+++ b/libgimpwidgets/gimpcolorhexentry.c
@@ -58,11 +58,26 @@ enum
};
+typedef struct _GimpColorHexEntryPrivate GimpColorHexEntryPrivate;
+
+struct _GimpColorHexEntryPrivate
+{
+ GimpRGB color;
+};
+
+#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ GIMP_TYPE_COLOR_HEX_ENTRY, \
+ GimpColorHexEntryPrivate))
+
+
static void gimp_color_hex_entry_constructed (GObject *object);
static gboolean gimp_color_hex_entry_events (GtkWidget *widget,
GdkEvent *event);
+static gboolean gimp_color_hex_entry_events (GtkWidget *widget,
+ GdkEvent *event);
+
static gboolean gimp_color_hex_entry_matched (GtkEntryCompletion *completion,
GtkTreeModel *model,
GtkTreeIter *iter,
@@ -93,25 +108,28 @@ gimp_color_hex_entry_class_init (GimpColorHexEntryClass *klass)
object_class->constructed = gimp_color_hex_entry_constructed;
klass->color_changed = NULL;
+
+ g_type_class_add_private (object_class, sizeof (GimpColorHexEntryPrivate));
}
static void
gimp_color_hex_entry_init (GimpColorHexEntry *entry)
{
- GtkEntryCompletion *completion;
- GtkCellRenderer *cell;
- GtkListStore *store;
- GimpRGB *colors;
- const gchar **names;
- gint num_colors;
- gint i;
+ GimpColorHexEntryPrivate *private = GET_PRIVATE (entry);
+ GtkEntryCompletion *completion;
+ GtkCellRenderer *cell;
+ GtkListStore *store;
+ GimpRGB *colors;
+ const gchar **names;
+ gint num_colors;
+ gint i;
/* GtkEntry's minimum size is way too large, set a reasonable one
* for our use case
*/
gtk_entry_set_width_chars (GTK_ENTRY (entry), 8);
- gimp_rgba_set (&entry->color, 0.0, 0.0, 0.0, 1.0);
+ gimp_rgba_set (&private->color, 0.0, 0.0, 0.0, 1.0);
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, GIMP_TYPE_RGB);
@@ -195,18 +213,22 @@ void
gimp_color_hex_entry_set_color (GimpColorHexEntry *entry,
const GimpRGB *color)
{
+ GimpColorHexEntryPrivate *private;
+
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
g_return_if_fail (color != NULL);
- if (gimp_rgb_distance (&entry->color, color) > 0.0)
+ private = GET_PRIVATE (entry);
+
+ if (gimp_rgb_distance (&private->color, color) > 0.0)
{
gchar buffer[8];
guchar r, g, b;
- gimp_rgb_set (&entry->color, color->r, color->g, color->b);
- gimp_rgb_clamp (&entry->color);
+ gimp_rgb_set (&private->color, color->r, color->g, color->b);
+ gimp_rgb_clamp (&private->color);
- gimp_rgb_get_uchar (&entry->color, &r, &g, &b);
+ gimp_rgb_get_uchar (&private->color, &r, &g, &b);
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", r, g, b);
gtk_entry_set_text (GTK_ENTRY (entry), buffer);
@@ -231,17 +253,22 @@ void
gimp_color_hex_entry_get_color (GimpColorHexEntry *entry,
GimpRGB *color)
{
+ GimpColorHexEntryPrivate *private;
+
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
g_return_if_fail (color != NULL);
- *color = entry->color;
+ private = GET_PRIVATE (entry);
+
+ *color = private->color;
}
static gboolean
gimp_color_hex_entry_events (GtkWidget *widget,
GdkEvent *event)
{
- GimpColorHexEntry *entry = GIMP_COLOR_HEX_ENTRY (widget);
+ GimpColorHexEntry *entry = GIMP_COLOR_HEX_ENTRY (widget);
+ GimpColorHexEntryPrivate *private = GET_PRIVATE (entry);
switch (event->type)
{
@@ -264,7 +291,7 @@ gimp_color_hex_entry_events (GtkWidget *widget,
text = gtk_entry_get_text (GTK_ENTRY (widget));
- gimp_rgb_get_uchar (&entry->color, &r, &g, &b);
+ gimp_rgb_get_uchar (&private->color, &r, &g, &b);
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", r, g, b);
if (g_ascii_strcasecmp (buffer, text) != 0)
diff --git a/libgimpwidgets/gimpcolorhexentry.h b/libgimpwidgets/gimpcolorhexentry.h
index 9f6ff1d..2585f5e 100644
--- a/libgimpwidgets/gimpcolorhexentry.h
+++ b/libgimpwidgets/gimpcolorhexentry.h
@@ -41,9 +41,7 @@ typedef struct _GimpColorHexEntryClass GimpColorHexEntryClass;
struct _GimpColorHexEntry
{
- GtkEntry parent_instance;
-
- GimpRGB color;
+ GtkEntry parent_instance;
};
struct _GimpColorHexEntryClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]