mirror of https://github.com/GNOME/gimp.git
libgimpwidgets: move all GimpColorHexEntry members to a private struct
This commit is contained in:
parent
c32681f4c3
commit
455f2e2e38
|
@ -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 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,
|
static gboolean gimp_color_hex_entry_events (GtkWidget *widget,
|
||||||
GdkEvent *event);
|
GdkEvent *event);
|
||||||
|
|
||||||
|
@ -93,25 +108,28 @@ gimp_color_hex_entry_class_init (GimpColorHexEntryClass *klass)
|
||||||
object_class->constructed = gimp_color_hex_entry_constructed;
|
object_class->constructed = gimp_color_hex_entry_constructed;
|
||||||
|
|
||||||
klass->color_changed = NULL;
|
klass->color_changed = NULL;
|
||||||
|
|
||||||
|
g_type_class_add_private (object_class, sizeof (GimpColorHexEntryPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_color_hex_entry_init (GimpColorHexEntry *entry)
|
gimp_color_hex_entry_init (GimpColorHexEntry *entry)
|
||||||
{
|
{
|
||||||
GtkEntryCompletion *completion;
|
GimpColorHexEntryPrivate *private = GET_PRIVATE (entry);
|
||||||
GtkCellRenderer *cell;
|
GtkEntryCompletion *completion;
|
||||||
GtkListStore *store;
|
GtkCellRenderer *cell;
|
||||||
GimpRGB *colors;
|
GtkListStore *store;
|
||||||
const gchar **names;
|
GimpRGB *colors;
|
||||||
gint num_colors;
|
const gchar **names;
|
||||||
gint i;
|
gint num_colors;
|
||||||
|
gint i;
|
||||||
|
|
||||||
/* GtkEntry's minimum size is way too large, set a reasonable one
|
/* GtkEntry's minimum size is way too large, set a reasonable one
|
||||||
* for our use case
|
* for our use case
|
||||||
*/
|
*/
|
||||||
gtk_entry_set_width_chars (GTK_ENTRY (entry), 8);
|
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);
|
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,
|
gimp_color_hex_entry_set_color (GimpColorHexEntry *entry,
|
||||||
const GimpRGB *color)
|
const GimpRGB *color)
|
||||||
{
|
{
|
||||||
|
GimpColorHexEntryPrivate *private;
|
||||||
|
|
||||||
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
|
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
|
||||||
g_return_if_fail (color != NULL);
|
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];
|
gchar buffer[8];
|
||||||
guchar r, g, b;
|
guchar r, g, b;
|
||||||
|
|
||||||
gimp_rgb_set (&entry->color, color->r, color->g, color->b);
|
gimp_rgb_set (&private->color, color->r, color->g, color->b);
|
||||||
gimp_rgb_clamp (&entry->color);
|
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);
|
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", r, g, b);
|
||||||
|
|
||||||
gtk_entry_set_text (GTK_ENTRY (entry), buffer);
|
gtk_entry_set_text (GTK_ENTRY (entry), buffer);
|
||||||
|
@ -231,17 +253,22 @@ void
|
||||||
gimp_color_hex_entry_get_color (GimpColorHexEntry *entry,
|
gimp_color_hex_entry_get_color (GimpColorHexEntry *entry,
|
||||||
GimpRGB *color)
|
GimpRGB *color)
|
||||||
{
|
{
|
||||||
|
GimpColorHexEntryPrivate *private;
|
||||||
|
|
||||||
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
|
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
|
||||||
g_return_if_fail (color != NULL);
|
g_return_if_fail (color != NULL);
|
||||||
|
|
||||||
*color = entry->color;
|
private = GET_PRIVATE (entry);
|
||||||
|
|
||||||
|
*color = private->color;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gimp_color_hex_entry_events (GtkWidget *widget,
|
gimp_color_hex_entry_events (GtkWidget *widget,
|
||||||
GdkEvent *event)
|
GdkEvent *event)
|
||||||
{
|
{
|
||||||
GimpColorHexEntry *entry = GIMP_COLOR_HEX_ENTRY (widget);
|
GimpColorHexEntry *entry = GIMP_COLOR_HEX_ENTRY (widget);
|
||||||
|
GimpColorHexEntryPrivate *private = GET_PRIVATE (entry);
|
||||||
|
|
||||||
switch (event->type)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
|
@ -264,7 +291,7 @@ gimp_color_hex_entry_events (GtkWidget *widget,
|
||||||
|
|
||||||
text = gtk_entry_get_text (GTK_ENTRY (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);
|
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", r, g, b);
|
||||||
|
|
||||||
if (g_ascii_strcasecmp (buffer, text) != 0)
|
if (g_ascii_strcasecmp (buffer, text) != 0)
|
||||||
|
|
|
@ -41,9 +41,7 @@ typedef struct _GimpColorHexEntryClass GimpColorHexEntryClass;
|
||||||
|
|
||||||
struct _GimpColorHexEntry
|
struct _GimpColorHexEntry
|
||||||
{
|
{
|
||||||
GtkEntry parent_instance;
|
GtkEntry parent_instance;
|
||||||
|
|
||||||
GimpRGB color;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpColorHexEntryClass
|
struct _GimpColorHexEntryClass
|
||||||
|
|
Loading…
Reference in New Issue