libgimpwidgets: move all GimpColorHexEntry members to a private struct

This commit is contained in:
Michael Natterer 2011-01-02 01:29:39 +01:00
parent c32681f4c3
commit 455f2e2e38
2 changed files with 43 additions and 18 deletions

View File

@ -58,8 +58,23 @@ 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);
@ -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)

View File

@ -41,9 +41,7 @@ typedef struct _GimpColorHexEntryClass GimpColorHexEntryClass;
struct _GimpColorHexEntry
{
GtkEntry parent_instance;
GimpRGB color;
GtkEntry parent_instance;
};
struct _GimpColorHexEntryClass