libgimpwidgets: GimpColorHexEntry made final.

This commit is contained in:
Jehan 2024-10-16 21:40:41 +02:00
parent 555ce20248
commit 426caf7132
2 changed files with 23 additions and 53 deletions

View file

@ -62,10 +62,12 @@ enum
};
typedef struct _GimpColorHexEntryPrivate
struct _GimpColorHexEntry
{
GtkEntry parent_instance;
GeglColor *color;
} GimpColorHexEntryPrivate;
};
static void gimp_color_hex_entry_constructed (GObject *object);
@ -80,8 +82,7 @@ static gboolean gimp_color_hex_entry_matched (GtkEntryCompletion *completio
GimpColorHexEntry *entry);
G_DEFINE_TYPE_WITH_PRIVATE (GimpColorHexEntry, gimp_color_hex_entry,
GTK_TYPE_ENTRY)
G_DEFINE_TYPE (GimpColorHexEntry, gimp_color_hex_entry, GTK_TYPE_ENTRY)
#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_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpColorHexEntryClass, color_changed),
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
object_class->constructed = gimp_color_hex_entry_constructed;
object_class->finalize = gimp_color_hex_entry_finalize;
klass->color_changed = NULL;
}
static void
gimp_color_hex_entry_init (GimpColorHexEntry *entry)
{
GimpColorHexEntryPrivate *private;
GtkEntryCompletion *completion;
GtkCellRenderer *cell;
GtkListStore *store;
@ -118,8 +116,6 @@ gimp_color_hex_entry_init (GimpColorHexEntry *entry)
const gchar **names;
gint i;
private = gimp_color_hex_entry_get_instance_private (entry);
/* GtkEntry's minimum size is way too large, set a reasonable one
* for our use case
*/
@ -130,7 +126,7 @@ gimp_color_hex_entry_init (GimpColorHexEntry *entry)
"CSS. This entry also accepts CSS color names."),
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);
@ -191,9 +187,8 @@ static void
gimp_color_hex_entry_finalize (GObject *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);
}
@ -226,17 +221,14 @@ void
gimp_color_hex_entry_set_color (GimpColorHexEntry *entry,
GeglColor *color)
{
GimpColorHexEntryPrivate *private;
gchar buffer[8];
guchar rgb[3];
g_return_if_fail (GIMP_IS_COLOR_HEX_ENTRY (entry));
g_return_if_fail (GEGL_IS_COLOR (color));
private = gimp_color_hex_entry_get_instance_private (entry);
g_object_unref (private->color);
private->color = gegl_color_duplicate (color);
g_object_unref (entry->color);
entry->color = gegl_color_duplicate (color);
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]);
@ -262,13 +254,9 @@ gimp_color_hex_entry_set_color (GimpColorHexEntry *entry,
GeglColor *
gimp_color_hex_entry_get_color (GimpColorHexEntry *entry)
{
GimpColorHexEntryPrivate *private;
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 (private->color);
return gegl_color_duplicate (entry->color);
}
static gboolean
@ -276,7 +264,6 @@ gimp_color_hex_entry_events (GtkWidget *widget,
GdkEvent *event)
{
GimpColorHexEntry *entry = GIMP_COLOR_HEX_ENTRY (widget);
GimpColorHexEntryPrivate *private = gimp_color_hex_entry_get_instance_private (entry);
switch (event->type)
{
@ -299,7 +286,7 @@ gimp_color_hex_entry_events (GtkWidget *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]);
if (g_ascii_strcasecmp (buffer, text) != 0)

View file

@ -30,24 +30,7 @@ G_BEGIN_DECLS
#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)
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);
};
G_DECLARE_FINAL_TYPE (GimpColorHexEntry, gimp_color_hex_entry, GIMP, COLOR_HEX_ENTRY, GtkEntry)
GtkWidget * gimp_color_hex_entry_new (void);