mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
libgimpwidgets: GimpColorHexEntry made final.
This commit is contained in:
parent
555ce20248
commit
426caf7132
2 changed files with 23 additions and 53 deletions
|
@ -62,10 +62,12 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GimpColorHexEntryPrivate
|
struct _GimpColorHexEntry
|
||||||
{
|
{
|
||||||
|
GtkEntry parent_instance;
|
||||||
|
|
||||||
GeglColor *color;
|
GeglColor *color;
|
||||||
} GimpColorHexEntryPrivate;
|
};
|
||||||
|
|
||||||
|
|
||||||
static void gimp_color_hex_entry_constructed (GObject *object);
|
static void gimp_color_hex_entry_constructed (GObject *object);
|
||||||
|
@ -80,8 +82,7 @@ static gboolean gimp_color_hex_entry_matched (GtkEntryCompletion *completio
|
||||||
GimpColorHexEntry *entry);
|
GimpColorHexEntry *entry);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (GimpColorHexEntry, gimp_color_hex_entry,
|
G_DEFINE_TYPE (GimpColorHexEntry, gimp_color_hex_entry, GTK_TYPE_ENTRY)
|
||||||
GTK_TYPE_ENTRY)
|
|
||||||
|
|
||||||
#define parent_class gimp_color_hex_entry_parent_class
|
#define parent_class gimp_color_hex_entry_parent_class
|
||||||
|
|
||||||
|
@ -97,20 +98,17 @@ gimp_color_hex_entry_class_init (GimpColorHexEntryClass *klass)
|
||||||
g_signal_new ("color-changed",
|
g_signal_new ("color-changed",
|
||||||
G_TYPE_FROM_CLASS (klass),
|
G_TYPE_FROM_CLASS (klass),
|
||||||
G_SIGNAL_RUN_FIRST,
|
G_SIGNAL_RUN_FIRST,
|
||||||
G_STRUCT_OFFSET (GimpColorHexEntryClass, color_changed),
|
0,
|
||||||
NULL, NULL, NULL,
|
NULL, NULL, NULL,
|
||||||
G_TYPE_NONE, 0);
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
object_class->constructed = gimp_color_hex_entry_constructed;
|
object_class->constructed = gimp_color_hex_entry_constructed;
|
||||||
object_class->finalize = gimp_color_hex_entry_finalize;
|
object_class->finalize = gimp_color_hex_entry_finalize;
|
||||||
|
|
||||||
klass->color_changed = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_color_hex_entry_init (GimpColorHexEntry *entry)
|
gimp_color_hex_entry_init (GimpColorHexEntry *entry)
|
||||||
{
|
{
|
||||||
GimpColorHexEntryPrivate *private;
|
|
||||||
GtkEntryCompletion *completion;
|
GtkEntryCompletion *completion;
|
||||||
GtkCellRenderer *cell;
|
GtkCellRenderer *cell;
|
||||||
GtkListStore *store;
|
GtkListStore *store;
|
||||||
|
@ -118,8 +116,6 @@ gimp_color_hex_entry_init (GimpColorHexEntry *entry)
|
||||||
const gchar **names;
|
const gchar **names;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
private = gimp_color_hex_entry_get_instance_private (entry);
|
|
||||||
|
|
||||||
/* 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
|
||||||
*/
|
*/
|
||||||
|
@ -130,7 +126,7 @@ gimp_color_hex_entry_init (GimpColorHexEntry *entry)
|
||||||
"CSS. This entry also accepts CSS color names."),
|
"CSS. This entry also accepts CSS color names."),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
private->color = gegl_color_new ("black");
|
entry->color = gegl_color_new ("black");
|
||||||
|
|
||||||
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, GEGL_TYPE_COLOR);
|
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, GEGL_TYPE_COLOR);
|
||||||
|
|
||||||
|
@ -191,9 +187,8 @@ static void
|
||||||
gimp_color_hex_entry_finalize (GObject *object)
|
gimp_color_hex_entry_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
GimpColorHexEntry *entry = GIMP_COLOR_HEX_ENTRY (object);
|
GimpColorHexEntry *entry = GIMP_COLOR_HEX_ENTRY (object);
|
||||||
GimpColorHexEntryPrivate *private = gimp_color_hex_entry_get_instance_private (entry);
|
|
||||||
|
|
||||||
g_object_unref (private->color);
|
g_object_unref (entry->color);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
@ -226,17 +221,14 @@ void
|
||||||
gimp_color_hex_entry_set_color (GimpColorHexEntry *entry,
|
gimp_color_hex_entry_set_color (GimpColorHexEntry *entry,
|
||||||
GeglColor *color)
|
GeglColor *color)
|
||||||
{
|
{
|
||||||
GimpColorHexEntryPrivate *private;
|
|
||||||
gchar buffer[8];
|
gchar buffer[8];
|
||||||
guchar rgb[3];
|
guchar rgb[3];
|
||||||
|
|
||||||
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
|
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
|
||||||
g_return_if_fail (GEGL_IS_COLOR (color));
|
g_return_if_fail (GEGL_IS_COLOR (color));
|
||||||
|
|
||||||
private = gimp_color_hex_entry_get_instance_private (entry);
|
g_object_unref (entry->color);
|
||||||
|
entry->color = gegl_color_duplicate (color);
|
||||||
g_object_unref (private->color);
|
|
||||||
private->color = gegl_color_duplicate (color);
|
|
||||||
|
|
||||||
gegl_color_get_pixel (color, babl_format ("R'G'B' u8"), rgb);
|
gegl_color_get_pixel (color, babl_format ("R'G'B' u8"), rgb);
|
||||||
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", rgb[0], rgb[1], rgb[2]);
|
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", rgb[0], rgb[1], rgb[2]);
|
||||||
|
@ -262,13 +254,9 @@ gimp_color_hex_entry_set_color (GimpColorHexEntry *entry,
|
||||||
GeglColor *
|
GeglColor *
|
||||||
gimp_color_hex_entry_get_color (GimpColorHexEntry *entry)
|
gimp_color_hex_entry_get_color (GimpColorHexEntry *entry)
|
||||||
{
|
{
|
||||||
GimpColorHexEntryPrivate *private;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry), NULL);
|
g_return_val_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry), NULL);
|
||||||
|
|
||||||
private = gimp_color_hex_entry_get_instance_private (entry);
|
return gegl_color_duplicate (entry->color);
|
||||||
|
|
||||||
return gegl_color_duplicate (private->color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -276,7 +264,6 @@ 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 = gimp_color_hex_entry_get_instance_private (entry);
|
|
||||||
|
|
||||||
switch (event->type)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
|
@ -299,7 +286,7 @@ gimp_color_hex_entry_events (GtkWidget *widget,
|
||||||
|
|
||||||
text = gtk_entry_get_text (GTK_ENTRY (widget));
|
text = gtk_entry_get_text (GTK_ENTRY (widget));
|
||||||
|
|
||||||
gegl_color_get_pixel (private->color, babl_format ("R'G'B' u8"), rgb);
|
gegl_color_get_pixel (entry->color, babl_format ("R'G'B' u8"), rgb);
|
||||||
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", rgb[0], rgb[1], rgb[2]);
|
g_snprintf (buffer, sizeof (buffer), "%.2x%.2x%.2x", rgb[0], rgb[1], rgb[2]);
|
||||||
|
|
||||||
if (g_ascii_strcasecmp (buffer, text) != 0)
|
if (g_ascii_strcasecmp (buffer, text) != 0)
|
||||||
|
|
|
@ -30,24 +30,7 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
#define GIMP_TYPE_COLOR_HEX_ENTRY (gimp_color_hex_entry_get_type ())
|
#define GIMP_TYPE_COLOR_HEX_ENTRY (gimp_color_hex_entry_get_type ())
|
||||||
G_DECLARE_DERIVABLE_TYPE (GimpColorHexEntry, gimp_color_hex_entry, GIMP, COLOR_HEX_ENTRY, GtkEntry)
|
G_DECLARE_FINAL_TYPE (GimpColorHexEntry, gimp_color_hex_entry, GIMP, COLOR_HEX_ENTRY, GtkEntry)
|
||||||
|
|
||||||
struct _GimpColorHexEntryClass
|
|
||||||
{
|
|
||||||
GtkEntryClass parent_class;
|
|
||||||
|
|
||||||
void (* color_changed) (GimpColorHexEntry *entry);
|
|
||||||
|
|
||||||
/* Padding for future expansion */
|
|
||||||
void (* _gimp_reserved1) (void);
|
|
||||||
void (* _gimp_reserved2) (void);
|
|
||||||
void (* _gimp_reserved3) (void);
|
|
||||||
void (* _gimp_reserved4) (void);
|
|
||||||
void (* _gimp_reserved5) (void);
|
|
||||||
void (* _gimp_reserved6) (void);
|
|
||||||
void (* _gimp_reserved7) (void);
|
|
||||||
void (* _gimp_reserved8) (void);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
GtkWidget * gimp_color_hex_entry_new (void);
|
GtkWidget * gimp_color_hex_entry_new (void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue