Compare commits
8 Commits
dropdown-s
...
async-colo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c42750efd | ||
|
|
ab833951db | ||
|
|
aa5041e65c | ||
|
|
4022786847 | ||
|
|
029bb9ad18 | ||
|
|
799fb41937 | ||
|
|
e6f4c596fa | ||
|
|
3d7fb26588 |
@@ -21,7 +21,75 @@
|
|||||||
#include "script-names.h"
|
#include "script-names.h"
|
||||||
#include "language-names.h"
|
#include "language-names.h"
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
/* {{{ ScriptLang object */
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (ScriptLang, script_lang, SCRIPT, LANG, GObject)
|
||||||
|
|
||||||
|
struct _ScriptLang
|
||||||
|
{
|
||||||
|
GObject parent;
|
||||||
|
|
||||||
|
char *langname;
|
||||||
|
unsigned int script_index;
|
||||||
|
unsigned int lang_index;
|
||||||
|
hb_tag_t lang_tag;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _ScriptLangClass
|
||||||
|
{
|
||||||
|
GObjectClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (ScriptLang, script_lang, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
static void
|
||||||
|
script_lang_init (ScriptLang *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
script_lang_finalize (GObject *object)
|
||||||
|
{
|
||||||
|
ScriptLang *self = SCRIPT_LANG (object);
|
||||||
|
|
||||||
|
g_free (self->langname);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (script_lang_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
script_lang_class_init (ScriptLangClass *class)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
|
||||||
|
object_class->finalize = script_lang_finalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ScriptLang *
|
||||||
|
script_lang_new (const char *langname,
|
||||||
|
unsigned int script_index,
|
||||||
|
unsigned int lang_index,
|
||||||
|
hb_tag_t lang_tag)
|
||||||
|
{
|
||||||
|
ScriptLang *self;
|
||||||
|
|
||||||
|
self = g_object_new (script_lang_get_type (), NULL);
|
||||||
|
|
||||||
|
self->langname = g_strdup (langname);
|
||||||
|
self->script_index = script_index;
|
||||||
|
self->lang_index = lang_index;
|
||||||
|
self->lang_tag = lang_tag;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
script_lang_get_langname (ScriptLang *self)
|
||||||
|
{
|
||||||
|
return g_strdup (self->langname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
#define MAKE_TAG(a,b,c,d) (unsigned int)(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
|
#define MAKE_TAG(a,b,c,d) (unsigned int)(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
|
||||||
|
|
||||||
@@ -95,6 +163,10 @@ demo_free (gpointer data)
|
|||||||
g_clear_pointer (&demo->axes, g_hash_table_unref);
|
g_clear_pointer (&demo->axes, g_hash_table_unref);
|
||||||
g_clear_pointer (&demo->text, g_free);
|
g_clear_pointer (&demo->text, g_free);
|
||||||
|
|
||||||
|
gtk_style_context_remove_provider_for_display (gdk_display_get_default (),
|
||||||
|
GTK_STYLE_PROVIDER (demo->provider));
|
||||||
|
g_object_unref (demo->provider);
|
||||||
|
|
||||||
g_free (demo);
|
g_free (demo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,8 +544,6 @@ update_display (void)
|
|||||||
GString *s;
|
GString *s;
|
||||||
char *text;
|
char *text;
|
||||||
gboolean has_feature;
|
gboolean has_feature;
|
||||||
GtkTreeIter iter;
|
|
||||||
GtkTreeModel *model;
|
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
GList *l;
|
GList *l;
|
||||||
PangoAttrList *attrs;
|
PangoAttrList *attrs;
|
||||||
@@ -576,14 +646,13 @@ update_display (void)
|
|||||||
|
|
||||||
features = g_string_free (s, FALSE);
|
features = g_string_free (s, FALSE);
|
||||||
|
|
||||||
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (demo->script_lang), &iter))
|
if (gtk_drop_down_get_selected (GTK_DROP_DOWN (demo->script_lang)) != 0)
|
||||||
{
|
{
|
||||||
hb_tag_t lang_tag;
|
ScriptLang *selected;
|
||||||
|
|
||||||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (demo->script_lang));
|
selected = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (demo->script_lang));
|
||||||
gtk_tree_model_get (model, &iter, 3, &lang_tag, -1);
|
|
||||||
|
|
||||||
lang = pango_language_from_string (hb_language_to_string (hb_ot_tag_to_language (lang_tag)));
|
lang = pango_language_from_string (hb_language_to_string (hb_ot_tag_to_language (selected->lang_tag)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
lang = NULL;
|
lang = NULL;
|
||||||
@@ -740,40 +809,30 @@ tag_pair_equal (gconstpointer a, gconstpointer b)
|
|||||||
return pair_a->script_tag == pair_b->script_tag && pair_a->lang_tag == pair_b->lang_tag;
|
return pair_a->script_tag == pair_b->script_tag && pair_a->lang_tag == pair_b->lang_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
script_sort_func (GtkTreeModel *model,
|
static GtkOrdering
|
||||||
GtkTreeIter *a,
|
script_sort (const void *item1,
|
||||||
GtkTreeIter *b,
|
const void *item2,
|
||||||
gpointer user_data)
|
void *data)
|
||||||
{
|
{
|
||||||
char *sa, *sb;
|
ScriptLang *a = (ScriptLang *)item1;
|
||||||
int ret;
|
ScriptLang *b = (ScriptLang *)item2;
|
||||||
|
|
||||||
gtk_tree_model_get (model, a, 0, &sa, -1);
|
return strcmp (a->langname, b->langname);
|
||||||
gtk_tree_model_get (model, b, 0, &sb, -1);
|
|
||||||
|
|
||||||
ret = strcmp (sa, sb);
|
|
||||||
|
|
||||||
g_free (sa);
|
|
||||||
g_free (sb);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_script_combo (void)
|
update_script_combo (void)
|
||||||
{
|
{
|
||||||
GtkListStore *store;
|
GListStore *store;
|
||||||
|
GtkSortListModel *sortmodel;
|
||||||
hb_font_t *hb_font;
|
hb_font_t *hb_font;
|
||||||
int i, j, k;
|
|
||||||
PangoFont *pango_font;
|
PangoFont *pango_font;
|
||||||
GHashTable *tags;
|
GHashTable *tags;
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
TagPair *pair;
|
TagPair *pair;
|
||||||
char *lang;
|
char *lang;
|
||||||
hb_tag_t active;
|
hb_tag_t active;
|
||||||
GtkTreeIter active_iter;
|
|
||||||
gboolean have_active = FALSE;
|
|
||||||
|
|
||||||
lang = gtk_font_chooser_get_language (GTK_FONT_CHOOSER (demo->font));
|
lang = gtk_font_chooser_get_language (GTK_FONT_CHOOSER (demo->font));
|
||||||
|
|
||||||
@@ -783,7 +842,7 @@ update_script_combo (void)
|
|||||||
|
|
||||||
g_free (lang);
|
g_free (lang);
|
||||||
|
|
||||||
store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
|
store = g_list_store_new (script_lang_get_type ());
|
||||||
|
|
||||||
pango_font = get_pango_font ();
|
pango_font = get_pango_font ();
|
||||||
hb_font = pango_font_get_hb_font (pango_font);
|
hb_font = pango_font_get_hb_font (pango_font);
|
||||||
@@ -807,19 +866,19 @@ update_script_combo (void)
|
|||||||
|
|
||||||
hb_face = hb_font_get_face (hb_font);
|
hb_face = hb_font_get_face (hb_font);
|
||||||
|
|
||||||
for (i= 0; i < 2; i++)
|
for (guint i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
hb_tag_t scripts[80];
|
hb_tag_t scripts[80];
|
||||||
unsigned int script_count = G_N_ELEMENTS (scripts);
|
unsigned int script_count = G_N_ELEMENTS (scripts);
|
||||||
|
|
||||||
hb_ot_layout_table_get_script_tags (hb_face, tables[i], 0, &script_count, scripts);
|
hb_ot_layout_table_get_script_tags (hb_face, tables[i], 0, &script_count, scripts);
|
||||||
for (j = 0; j < script_count; j++)
|
for (guint j = 0; j < script_count; j++)
|
||||||
{
|
{
|
||||||
hb_tag_t languages[80];
|
hb_tag_t languages[80];
|
||||||
unsigned int language_count = G_N_ELEMENTS (languages);
|
unsigned int language_count = G_N_ELEMENTS (languages);
|
||||||
|
|
||||||
hb_ot_layout_script_get_language_tags (hb_face, tables[i], j, 0, &language_count, languages);
|
hb_ot_layout_script_get_language_tags (hb_face, tables[i], j, 0, &language_count, languages);
|
||||||
for (k = 0; k < language_count; k++)
|
for (guint k = 0; k < language_count; k++)
|
||||||
{
|
{
|
||||||
pair = g_new (TagPair, 1);
|
pair = g_new (TagPair, 1);
|
||||||
pair->script_tag = scripts[j];
|
pair->script_tag = scripts[j];
|
||||||
@@ -839,7 +898,6 @@ update_script_combo (void)
|
|||||||
{
|
{
|
||||||
const char *langname;
|
const char *langname;
|
||||||
char langbuf[5];
|
char langbuf[5];
|
||||||
GtkTreeIter tree_iter;
|
|
||||||
|
|
||||||
if (pair->lang_tag == 0 && pair->script_tag == 0)
|
if (pair->lang_tag == 0 && pair->script_tag == 0)
|
||||||
langname = NC_("Language", "None");
|
langname = NC_("Language", "None");
|
||||||
@@ -856,31 +914,31 @@ update_script_combo (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_list_store_insert_with_values (store, &tree_iter, -1,
|
g_list_store_append (store, script_lang_new (langname,
|
||||||
0, langname,
|
pair->script_index,
|
||||||
1, pair->script_index,
|
pair->lang_index,
|
||||||
2, pair->lang_index,
|
pair->lang_tag));
|
||||||
3, pair->lang_tag,
|
|
||||||
-1);
|
|
||||||
if (pair->lang_tag == active)
|
|
||||||
{
|
|
||||||
have_active = TRUE;
|
|
||||||
active_iter = tree_iter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_destroy (tags);
|
g_hash_table_destroy (tags);
|
||||||
|
|
||||||
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
|
sortmodel = gtk_sort_list_model_new (G_LIST_MODEL (store),
|
||||||
script_sort_func, NULL, NULL);
|
GTK_SORTER (gtk_custom_sorter_new (script_sort, NULL, NULL)));
|
||||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
|
gtk_drop_down_set_model (GTK_DROP_DOWN (demo->script_lang), G_LIST_MODEL (sortmodel));
|
||||||
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
|
|
||||||
GTK_SORT_ASCENDING);
|
for (guint i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (sortmodel)); i++)
|
||||||
gtk_combo_box_set_model (GTK_COMBO_BOX (demo->script_lang), GTK_TREE_MODEL (store));
|
{
|
||||||
if (have_active)
|
ScriptLang *item = g_list_model_get_item (G_LIST_MODEL (sortmodel), i);
|
||||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (demo->script_lang), &active_iter);
|
g_object_unref (item);
|
||||||
else
|
|
||||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (demo->script_lang), 0);
|
if (item->lang_tag == active)
|
||||||
|
{
|
||||||
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (demo->script_lang), i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (sortmodel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@@ -905,27 +963,19 @@ static void
|
|||||||
update_features (void)
|
update_features (void)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
GtkTreeModel *model;
|
|
||||||
GtkTreeIter iter;
|
|
||||||
guint script_index, lang_index;
|
|
||||||
hb_tag_t lang_tag;
|
|
||||||
PangoFont *pango_font;
|
PangoFont *pango_font;
|
||||||
hb_font_t *hb_font;
|
hb_font_t *hb_font;
|
||||||
GList *l;
|
GList *l;
|
||||||
|
ScriptLang *selected;
|
||||||
|
|
||||||
/* set feature presence checks from the font features */
|
/* set feature presence checks from the font features */
|
||||||
|
|
||||||
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (demo->script_lang), &iter))
|
if (gtk_drop_down_get_selected (GTK_DROP_DOWN (demo->script_lang)) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (demo->script_lang));
|
selected = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (demo->script_lang));
|
||||||
gtk_tree_model_get (model, &iter,
|
|
||||||
1, &script_index,
|
|
||||||
2, &lang_index,
|
|
||||||
3, &lang_tag,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
if (lang_tag == 0) /* None is selected */
|
if (selected->lang_tag == 0) /* None is selected */
|
||||||
{
|
{
|
||||||
for (l = demo->feature_items; l; l = l->next)
|
for (l = demo->feature_items; l; l = l->next)
|
||||||
{
|
{
|
||||||
@@ -966,8 +1016,8 @@ update_features (void)
|
|||||||
|
|
||||||
hb_ot_layout_language_get_feature_tags (hb_face,
|
hb_ot_layout_language_get_feature_tags (hb_face,
|
||||||
tables[i],
|
tables[i],
|
||||||
script_index,
|
selected->script_index,
|
||||||
lang_index,
|
selected->lang_index,
|
||||||
0,
|
0,
|
||||||
&count,
|
&count,
|
||||||
features);
|
features);
|
||||||
@@ -989,8 +1039,8 @@ update_features (void)
|
|||||||
|
|
||||||
hb_ot_layout_language_find_feature (hb_face,
|
hb_ot_layout_language_find_feature (hb_face,
|
||||||
tables[i],
|
tables[i],
|
||||||
script_index,
|
selected->script_index,
|
||||||
lang_index,
|
selected->lang_index,
|
||||||
features[j],
|
features[j],
|
||||||
&feature_index);
|
&feature_index);
|
||||||
|
|
||||||
@@ -1324,8 +1374,7 @@ free_instance (gpointer data)
|
|||||||
static void
|
static void
|
||||||
add_instance (hb_face_t *face,
|
add_instance (hb_face_t *face,
|
||||||
unsigned int index,
|
unsigned int index,
|
||||||
GtkWidget *combo,
|
GtkStringList *strings)
|
||||||
int pos)
|
|
||||||
{
|
{
|
||||||
Instance *instance;
|
Instance *instance;
|
||||||
hb_ot_name_id_t name_id;
|
hb_ot_name_id_t name_id;
|
||||||
@@ -1341,20 +1390,20 @@ add_instance (hb_face_t *face,
|
|||||||
instance->index = index;
|
instance->index = index;
|
||||||
|
|
||||||
g_hash_table_add (demo->instances, instance);
|
g_hash_table_add (demo->instances, instance);
|
||||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), instance->name);
|
gtk_string_list_append (GTK_STRING_LIST (strings), instance->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
unset_instance (GtkAdjustment *adjustment)
|
unset_instance (GtkAdjustment *adjustment)
|
||||||
{
|
{
|
||||||
if (demo->instance_combo)
|
if (demo->instance_combo)
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (demo->instance_combo), 0);
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (demo->instance_combo), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
instance_changed (GtkComboBox *combo)
|
instance_changed (GtkDropDown *combo)
|
||||||
{
|
{
|
||||||
char *text;
|
const char *text;
|
||||||
Instance *instance;
|
Instance *instance;
|
||||||
Instance ikey;
|
Instance ikey;
|
||||||
int i;
|
int i;
|
||||||
@@ -1366,11 +1415,12 @@ instance_changed (GtkComboBox *combo)
|
|||||||
hb_font_t *hb_font;
|
hb_font_t *hb_font;
|
||||||
hb_face_t *hb_face;
|
hb_face_t *hb_face;
|
||||||
|
|
||||||
text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (combo));
|
text = gtk_string_list_get_string (GTK_STRING_LIST (gtk_drop_down_get_model (combo)),
|
||||||
|
gtk_drop_down_get_selected (combo));
|
||||||
if (text[0] == '\0')
|
if (text[0] == '\0')
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ikey.name = text;
|
ikey.name = (char *) text;
|
||||||
instance = g_hash_table_lookup (demo->instances, &ikey);
|
instance = g_hash_table_lookup (demo->instances, &ikey);
|
||||||
if (!instance)
|
if (!instance)
|
||||||
{
|
{
|
||||||
@@ -1411,7 +1461,6 @@ instance_changed (GtkComboBox *combo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
g_free (text);
|
|
||||||
g_clear_object (&pango_font);
|
g_clear_object (&pango_font);
|
||||||
g_free (ai);
|
g_free (ai);
|
||||||
g_free (coords);
|
g_free (coords);
|
||||||
@@ -1521,6 +1570,7 @@ update_font_variations (void)
|
|||||||
{
|
{
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *combo;
|
GtkWidget *combo;
|
||||||
|
GtkStringList *strings;
|
||||||
|
|
||||||
label = gtk_label_new ("Instance");
|
label = gtk_label_new ("Instance");
|
||||||
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
||||||
@@ -1528,26 +1578,28 @@ update_font_variations (void)
|
|||||||
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
||||||
gtk_grid_attach (GTK_GRID (demo->variations_grid), label, 0, -1, 1, 1);
|
gtk_grid_attach (GTK_GRID (demo->variations_grid), label, 0, -1, 1, 1);
|
||||||
|
|
||||||
combo = gtk_combo_box_text_new ();
|
strings = gtk_string_list_new (NULL);
|
||||||
|
combo = gtk_drop_down_new (G_LIST_MODEL (strings), NULL);
|
||||||
|
|
||||||
gtk_widget_set_halign (combo, GTK_ALIGN_START);
|
gtk_widget_set_halign (combo, GTK_ALIGN_START);
|
||||||
gtk_widget_set_valign (combo, GTK_ALIGN_BASELINE);
|
gtk_widget_set_valign (combo, GTK_ALIGN_BASELINE);
|
||||||
|
|
||||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "");
|
gtk_string_list_append (strings, "");
|
||||||
|
|
||||||
for (i = 0; i < hb_ot_var_get_named_instance_count (hb_face); i++)
|
for (i = 0; i < hb_ot_var_get_named_instance_count (hb_face); i++)
|
||||||
add_instance (hb_face, i, combo, i);
|
add_instance (hb_face, i, strings);
|
||||||
|
|
||||||
for (i = 0; i < hb_ot_var_get_named_instance_count (hb_face); i++)
|
for (i = 0; i < hb_ot_var_get_named_instance_count (hb_face); i++)
|
||||||
{
|
{
|
||||||
if (matches_instance (hb_face, i, n_axes, design_coords))
|
if (matches_instance (hb_face, i, n_axes, design_coords))
|
||||||
{
|
{
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i + 1);
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (combo), i + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_grid_attach (GTK_GRID (demo->variations_grid), combo, 1, -1, 3, 1);
|
gtk_grid_attach (GTK_GRID (demo->variations_grid), combo, 1, -1, 3, 1);
|
||||||
g_signal_connect (combo, "changed", G_CALLBACK (instance_changed), NULL);
|
g_signal_connect (combo, "notify::selecte", G_CALLBACK (instance_changed), NULL);
|
||||||
demo->instance_combo = combo;
|
demo->instance_combo = combo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1694,6 +1746,7 @@ do_font_features (GtkWidget *do_widget)
|
|||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkBuilderScope *scope;
|
GtkBuilderScope *scope;
|
||||||
GtkEventController *controller;
|
GtkEventController *controller;
|
||||||
|
GtkExpression *expression;
|
||||||
|
|
||||||
builder = gtk_builder_new ();
|
builder = gtk_builder_new ();
|
||||||
|
|
||||||
@@ -1727,6 +1780,9 @@ do_font_features (GtkWidget *do_widget)
|
|||||||
demo->description = GTK_WIDGET (gtk_builder_get_object (builder, "description"));
|
demo->description = GTK_WIDGET (gtk_builder_get_object (builder, "description"));
|
||||||
demo->font = GTK_WIDGET (gtk_builder_get_object (builder, "font"));
|
demo->font = GTK_WIDGET (gtk_builder_get_object (builder, "font"));
|
||||||
demo->script_lang = GTK_WIDGET (gtk_builder_get_object (builder, "script_lang"));
|
demo->script_lang = GTK_WIDGET (gtk_builder_get_object (builder, "script_lang"));
|
||||||
|
expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL, G_CALLBACK (script_lang_get_langname), NULL, NULL);
|
||||||
|
gtk_drop_down_set_expression (GTK_DROP_DOWN (demo->script_lang), expression);
|
||||||
|
gtk_expression_unref (expression);
|
||||||
demo->feature_list = GTK_WIDGET (gtk_builder_get_object (builder, "feature_list"));
|
demo->feature_list = GTK_WIDGET (gtk_builder_get_object (builder, "feature_list"));
|
||||||
demo->stack = GTK_WIDGET (gtk_builder_get_object (builder, "stack"));
|
demo->stack = GTK_WIDGET (gtk_builder_get_object (builder, "stack"));
|
||||||
demo->entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
|
demo->entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
|
||||||
@@ -1745,7 +1801,7 @@ do_font_features (GtkWidget *do_widget)
|
|||||||
demo->swin = GTK_WIDGET (gtk_builder_get_object (builder, "swin"));
|
demo->swin = GTK_WIDGET (gtk_builder_get_object (builder, "swin"));
|
||||||
|
|
||||||
demo->provider = gtk_css_provider_new ();
|
demo->provider = gtk_css_provider_new ();
|
||||||
gtk_style_context_add_provider (gtk_widget_get_style_context (demo->swin),
|
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
||||||
GTK_STYLE_PROVIDER (demo->provider), 800);
|
GTK_STYLE_PROVIDER (demo->provider), 800);
|
||||||
|
|
||||||
basic_value_changed (demo->size_adjustment, demo->size_entry);
|
basic_value_changed (demo->size_adjustment, demo->size_entry);
|
||||||
@@ -1824,3 +1880,5 @@ do_font_features (GtkWidget *do_widget)
|
|||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vim:set foldmethod=marker expandtab: */
|
||||||
|
|||||||
@@ -259,16 +259,10 @@
|
|||||||
<object class="GtkBox" id="feature_list">
|
<object class="GtkBox" id="feature_list">
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkComboBox" id="script_lang">
|
<object class="GtkDropDown" id="script_lang">
|
||||||
<property name="tooltip-text" translatable="yes">Language System</property>
|
<property name="tooltip-text" translatable="yes">Language System</property>
|
||||||
<property name="margin-top">10</property>
|
<property name="margin-top">10</property>
|
||||||
<signal name="changed" handler="font_features_script_changed" swapped="no"/>
|
<signal name="notify::selected" handler="font_features_script_changed" swapped="no"/>
|
||||||
<child>
|
|
||||||
<object class="GtkCellRendererText"/>
|
|
||||||
<attributes>
|
|
||||||
<attribute name="text">0</attribute>
|
|
||||||
</attributes>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|||||||
@@ -79,6 +79,8 @@
|
|||||||
#include <gtk/gtkcenterlayout.h>
|
#include <gtk/gtkcenterlayout.h>
|
||||||
#include <gtk/gtkcheckbutton.h>
|
#include <gtk/gtkcheckbutton.h>
|
||||||
#include <gtk/gtkcolorbutton.h>
|
#include <gtk/gtkcolorbutton.h>
|
||||||
|
#include <gtk/gtkcolorchoice.h>
|
||||||
|
#include <gtk/gtkcolorchoicebutton.h>
|
||||||
#include <gtk/gtkcolorchooser.h>
|
#include <gtk/gtkcolorchooser.h>
|
||||||
#include <gtk/gtkcolorchooserdialog.h>
|
#include <gtk/gtkcolorchooserdialog.h>
|
||||||
#include <gtk/gtkcolorchooserwidget.h>
|
#include <gtk/gtkcolorchooserwidget.h>
|
||||||
|
|||||||
195
gtk/gtkcolorchoice.c
Normal file
195
gtk/gtkcolorchoice.c
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
/*
|
||||||
|
* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2022 Red Hat, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This Library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This Library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "gtkcolorchoice.h"
|
||||||
|
#include "gtkcolorchooserwindowprivate.h"
|
||||||
|
#include "gtkcolorchooser.h"
|
||||||
|
#include "gtkbutton.h"
|
||||||
|
|
||||||
|
/* {{{ GObject implementation */
|
||||||
|
|
||||||
|
struct _GtkColorChoice
|
||||||
|
{
|
||||||
|
GObject parent_instance;
|
||||||
|
|
||||||
|
GtkWindow *parent;
|
||||||
|
char *title;
|
||||||
|
gboolean use_alpha;
|
||||||
|
|
||||||
|
GTask *task;
|
||||||
|
GtkColorChooserWindow *window;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (GtkColorChoice, gtk_color_choice, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_init (GtkColorChoice *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_finalize (GObject *object)
|
||||||
|
{
|
||||||
|
GtkColorChoice *self = GTK_COLOR_CHOICE (object);
|
||||||
|
|
||||||
|
g_assert (self->task == NULL);
|
||||||
|
g_assert (self->window == NULL);
|
||||||
|
|
||||||
|
g_free (self->title);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gtk_color_choice_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_class_init (GtkColorChoiceClass *class)
|
||||||
|
{
|
||||||
|
G_OBJECT_CLASS (class)->finalize = gtk_color_choice_finalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
/* {{{ Public API */
|
||||||
|
/* {{{ Constructor */
|
||||||
|
|
||||||
|
GtkColorChoice *
|
||||||
|
gtk_color_choice_new (GtkWindow *parent,
|
||||||
|
const char *title,
|
||||||
|
gboolean use_alpha)
|
||||||
|
{
|
||||||
|
GtkColorChoice *self;
|
||||||
|
|
||||||
|
self = g_object_new (GTK_TYPE_COLOR_CHOICE, NULL);
|
||||||
|
|
||||||
|
self->parent = parent;
|
||||||
|
self->title = g_strdup (title);
|
||||||
|
self->use_alpha = use_alpha;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
/* {{{ Async API */
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
RESPONSE_OK,
|
||||||
|
RESPONSE_CANCEL
|
||||||
|
};
|
||||||
|
|
||||||
|
static void response_cb (GtkColorChoice *self,
|
||||||
|
int response);
|
||||||
|
|
||||||
|
static void
|
||||||
|
cancelled_cb (GCancellable *cancellable,
|
||||||
|
GtkColorChoice *self)
|
||||||
|
{
|
||||||
|
response_cb (self, RESPONSE_CANCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
response_cb (GtkColorChoice *self,
|
||||||
|
int response)
|
||||||
|
{
|
||||||
|
GCancellable *cancellable;
|
||||||
|
|
||||||
|
g_assert (self->window != NULL);
|
||||||
|
g_assert (self->task != NULL);
|
||||||
|
|
||||||
|
cancellable = g_task_get_cancellable (self->task);
|
||||||
|
|
||||||
|
if (cancellable)
|
||||||
|
g_signal_handlers_disconnect_by_func (cancellable, cancelled_cb, self);
|
||||||
|
|
||||||
|
if (response == RESPONSE_OK)
|
||||||
|
{
|
||||||
|
GdkRGBA color;
|
||||||
|
|
||||||
|
gtk_color_chooser_window_save_color (GTK_COLOR_CHOOSER_WINDOW (self->window));
|
||||||
|
|
||||||
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (self->window), &color);
|
||||||
|
g_task_return_pointer (self->task, gdk_rgba_copy (&color), (GDestroyNotify) gdk_rgba_free);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_task_return_new_error (self->task, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Cancelled");
|
||||||
|
|
||||||
|
g_clear_pointer ((GtkWindow **)&self->window, gtk_window_destroy);
|
||||||
|
g_clear_object (&self->task);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ok_button_clicked (GtkButton *button,
|
||||||
|
GtkColorChoice *self)
|
||||||
|
{
|
||||||
|
response_cb (self, RESPONSE_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cancel_button_clicked (GtkButton *button,
|
||||||
|
GtkColorChoice *self)
|
||||||
|
{
|
||||||
|
response_cb (self, RESPONSE_CANCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_color_choice_choose (GtkColorChoice *self,
|
||||||
|
const GdkRGBA *initial_color,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkColorChooserWindow *window;
|
||||||
|
GTask *task;
|
||||||
|
|
||||||
|
g_return_if_fail (GTK_IS_COLOR_CHOICE (self));
|
||||||
|
|
||||||
|
window = GTK_COLOR_CHOOSER_WINDOW (gtk_color_chooser_window_new (self->title, self->parent));
|
||||||
|
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (window), self->use_alpha);
|
||||||
|
if (initial_color)
|
||||||
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (window), initial_color);
|
||||||
|
|
||||||
|
if (cancellable)
|
||||||
|
g_signal_connect (cancellable, "cancelled", G_CALLBACK (cancelled_cb), self);
|
||||||
|
|
||||||
|
g_signal_connect (gtk_color_chooser_window_get_ok_button (window), "clicked",
|
||||||
|
G_CALLBACK (ok_button_clicked), self);
|
||||||
|
g_signal_connect (gtk_color_chooser_window_get_cancel_button (window), "clicked",
|
||||||
|
G_CALLBACK (cancel_button_clicked), self);
|
||||||
|
|
||||||
|
task = g_task_new (self, cancellable, callback, user_data);
|
||||||
|
g_task_set_source_tag (task, gtk_color_choice_choose);
|
||||||
|
|
||||||
|
self->window = window;
|
||||||
|
self->task = task;
|
||||||
|
|
||||||
|
gtk_window_present (GTK_WINDOW (window));
|
||||||
|
}
|
||||||
|
|
||||||
|
GdkRGBA *
|
||||||
|
gtk_color_choice_choose_finish (GtkColorChoice *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
return g_task_propagate_pointer (G_TASK (result), error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* vim:set foldmethod=marker expandtab: */
|
||||||
52
gtk/gtkcolorchoice.h
Normal file
52
gtk/gtkcolorchoice.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||||
|
#error "Only <gtk/gtk.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gdk/gdk.h>
|
||||||
|
#include <gtk/gtkwindow.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GTK_TYPE_COLOR_CHOICE (gtk_color_choice_get_type ())
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
G_DECLARE_FINAL_TYPE (GtkColorChoice, gtk_color_choice, GTK, COLOR_CHOICE, GObject)
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
GtkColorChoice * gtk_color_choice_new (GtkWindow *parent,
|
||||||
|
const char *title,
|
||||||
|
gboolean use_alpha);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
void gtk_color_choice_choose (GtkColorChoice *choice,
|
||||||
|
const GdkRGBA *initial_color,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
GdkRGBA * gtk_color_choice_choose_finish (GtkColorChoice *self,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
409
gtk/gtkcolorchoicebutton.c
Normal file
409
gtk/gtkcolorchoicebutton.c
Normal file
@@ -0,0 +1,409 @@
|
|||||||
|
/*
|
||||||
|
* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2022 Red Hat, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This Library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This Library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "gtkcolorchoicebutton.h"
|
||||||
|
#include "gtkcolorchoice.h"
|
||||||
|
|
||||||
|
#include "gtkbinlayout.h"
|
||||||
|
#include "gtkbutton.h"
|
||||||
|
#include "gtkcolorswatchprivate.h"
|
||||||
|
#include "gtkdragsource.h"
|
||||||
|
#include "gtkdroptarget.h"
|
||||||
|
#include <glib/gi18n-lib.h>
|
||||||
|
//#include "gtkmain.h"
|
||||||
|
#include "gtkprivate.h"
|
||||||
|
//#include "gtksnapshot.h"
|
||||||
|
#include "gtkwidgetprivate.h"
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean drop (GtkDropTarget *dest,
|
||||||
|
const GValue *value,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkColorChoiceButton *self);
|
||||||
|
static GdkContentProvider *
|
||||||
|
drag_prepare (GtkDragSource *source,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkColorChoiceButton *self);
|
||||||
|
static void button_clicked (GtkColorChoiceButton *self);
|
||||||
|
|
||||||
|
/* {{{ GObject implementation */
|
||||||
|
|
||||||
|
struct _GtkColorChoiceButton
|
||||||
|
{
|
||||||
|
GtkWidget parent_instance;
|
||||||
|
|
||||||
|
GdkRGBA color;
|
||||||
|
gboolean use_alpha;
|
||||||
|
char *title;
|
||||||
|
|
||||||
|
GtkWidget *button;
|
||||||
|
GtkWidget *swatch;
|
||||||
|
GtkColorChoice *choice;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Properties */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_COLOR = 1,
|
||||||
|
PROP_USE_ALPHA,
|
||||||
|
PROP_TITLE,
|
||||||
|
NUM_PROPERTIES
|
||||||
|
};
|
||||||
|
|
||||||
|
static GParamSpec *properties[NUM_PROPERTIES];
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (GtkColorChoiceButton, gtk_color_choice_button, GTK_TYPE_WIDGET)
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_button_init (GtkColorChoiceButton *self)
|
||||||
|
{
|
||||||
|
PangoLayout *layout;
|
||||||
|
PangoRectangle rect;
|
||||||
|
GtkDragSource *source;
|
||||||
|
GtkDropTarget *dest;
|
||||||
|
|
||||||
|
self->use_alpha = TRUE;
|
||||||
|
self->title = g_strdup ("");
|
||||||
|
|
||||||
|
self->button = gtk_button_new ();
|
||||||
|
g_signal_connect_swapped (self->button, "clicked", G_CALLBACK (button_clicked), self);
|
||||||
|
gtk_widget_set_parent (self->button, GTK_WIDGET (self));
|
||||||
|
|
||||||
|
self->swatch = g_object_new (GTK_TYPE_COLOR_SWATCH,
|
||||||
|
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
|
||||||
|
"selectable", FALSE,
|
||||||
|
"has-menu", FALSE,
|
||||||
|
"can-drag", FALSE,
|
||||||
|
NULL);
|
||||||
|
gtk_widget_set_can_focus (self->swatch, FALSE);
|
||||||
|
gtk_widget_remove_css_class (self->swatch, "activatable");
|
||||||
|
|
||||||
|
layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), "Black");
|
||||||
|
pango_layout_get_pixel_extents (layout, NULL, &rect);
|
||||||
|
g_object_unref (layout);
|
||||||
|
|
||||||
|
gtk_widget_set_size_request (self->swatch, rect.width, rect.height);
|
||||||
|
|
||||||
|
gtk_button_set_child (GTK_BUTTON (self->button), self->swatch);
|
||||||
|
|
||||||
|
dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
|
||||||
|
g_signal_connect (dest, "drop", G_CALLBACK (drop), self);
|
||||||
|
gtk_widget_add_controller (GTK_WIDGET (self->button), GTK_EVENT_CONTROLLER (dest));
|
||||||
|
|
||||||
|
source = gtk_drag_source_new ();
|
||||||
|
g_signal_connect (source, "prepare", G_CALLBACK (drag_prepare), self);
|
||||||
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (source),
|
||||||
|
GTK_PHASE_CAPTURE);
|
||||||
|
gtk_widget_add_controller (self->button, GTK_EVENT_CONTROLLER (source));
|
||||||
|
gtk_widget_add_css_class (self->button, "color");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_button_set_property (GObject *object,
|
||||||
|
guint param_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkColorChoiceButton *self = GTK_COLOR_CHOICE_BUTTON (object);
|
||||||
|
|
||||||
|
switch (param_id)
|
||||||
|
{
|
||||||
|
case PROP_COLOR:
|
||||||
|
gtk_color_choice_button_set_color (self, g_value_get_boxed (value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_USE_ALPHA:
|
||||||
|
gtk_color_choice_button_set_use_alpha (self, g_value_get_boolean (value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_TITLE:
|
||||||
|
gtk_color_choice_button_set_title (self, g_value_get_string (value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_button_get_property (GObject *object,
|
||||||
|
guint param_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkColorChoiceButton *self = GTK_COLOR_CHOICE_BUTTON (object);
|
||||||
|
|
||||||
|
switch (param_id)
|
||||||
|
{
|
||||||
|
case PROP_COLOR:
|
||||||
|
g_value_set_boxed (value, &self->color);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_USE_ALPHA:
|
||||||
|
g_value_set_boolean (value, self->use_alpha);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_TITLE:
|
||||||
|
g_value_set_string (value, self->title);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_button_dispose (GObject *object)
|
||||||
|
{
|
||||||
|
GtkColorChoiceButton *self = GTK_COLOR_CHOICE_BUTTON (object);
|
||||||
|
|
||||||
|
g_clear_pointer (&self->button, gtk_widget_unparent);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gtk_color_choice_button_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_button_finalize (GObject *object)
|
||||||
|
{
|
||||||
|
GtkColorChoiceButton *self = GTK_COLOR_CHOICE_BUTTON (object);
|
||||||
|
|
||||||
|
g_free (self->title);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gtk_color_choice_button_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_choice_button_class_init (GtkColorChoiceButtonClass *class)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||||
|
|
||||||
|
object_class->get_property = gtk_color_choice_button_get_property;
|
||||||
|
object_class->set_property = gtk_color_choice_button_set_property;
|
||||||
|
object_class->dispose = gtk_color_choice_button_dispose;
|
||||||
|
object_class->finalize = gtk_color_choice_button_finalize;
|
||||||
|
|
||||||
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
||||||
|
widget_class->focus = gtk_widget_focus_child;
|
||||||
|
|
||||||
|
properties[PROP_COLOR] =
|
||||||
|
g_param_spec_boxed ("color", NULL, NULL,
|
||||||
|
GDK_TYPE_RGBA,
|
||||||
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
|
properties[PROP_USE_ALPHA] =
|
||||||
|
g_param_spec_boolean ("use-alpha", NULL, NULL,
|
||||||
|
TRUE,
|
||||||
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
|
properties[PROP_TITLE] =
|
||||||
|
g_param_spec_string ("title", NULL, NULL,
|
||||||
|
"",
|
||||||
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
|
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
|
||||||
|
|
||||||
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
||||||
|
gtk_widget_class_set_css_name (widget_class, "colorbutton");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
/* {{{ Private API, callbacks */
|
||||||
|
|
||||||
|
static guint
|
||||||
|
scale_round (double value,
|
||||||
|
double scale)
|
||||||
|
{
|
||||||
|
value = floor (value * scale + 0.5);
|
||||||
|
value = CLAMP (value, 0, scale);
|
||||||
|
return (guint)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
accessible_color_name (const GdkRGBA *color)
|
||||||
|
{
|
||||||
|
if (color->alpha < 1.0)
|
||||||
|
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"),
|
||||||
|
scale_round (color->red, 100),
|
||||||
|
scale_round (color->green, 100),
|
||||||
|
scale_round (color->blue, 100),
|
||||||
|
scale_round (color->alpha, 100));
|
||||||
|
else
|
||||||
|
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%"),
|
||||||
|
scale_round (color->red, 100),
|
||||||
|
scale_round (color->green, 100),
|
||||||
|
scale_round (color->blue, 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
drop (GtkDropTarget *dest,
|
||||||
|
const GValue *value,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkColorChoiceButton *self)
|
||||||
|
{
|
||||||
|
GdkRGBA *color = g_value_get_boxed (value);
|
||||||
|
|
||||||
|
gtk_color_choice_button_set_color (self, color);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GdkContentProvider *
|
||||||
|
drag_prepare (GtkDragSource *source,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkColorChoiceButton *self)
|
||||||
|
{
|
||||||
|
return gdk_content_provider_new_typed (GDK_TYPE_RGBA, &self->color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
color_chosen (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GtkColorChoice *choice = GTK_COLOR_CHOICE (source);
|
||||||
|
GtkColorChoiceButton *self = data;
|
||||||
|
GdkRGBA *color;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
color = gtk_color_choice_choose_finish (choice, result, &error);
|
||||||
|
if (color)
|
||||||
|
{
|
||||||
|
gtk_color_choice_button_set_color (self, color);
|
||||||
|
gdk_rgba_free (color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_print ("%s\n", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
button_clicked (GtkColorChoiceButton *self)
|
||||||
|
{
|
||||||
|
GtkRoot *root;
|
||||||
|
GtkWindow *parent = NULL;
|
||||||
|
GtkColorChoice *choice;
|
||||||
|
|
||||||
|
root = gtk_widget_get_root (GTK_WIDGET (self));
|
||||||
|
if (GTK_IS_WINDOW (root))
|
||||||
|
parent = GTK_WINDOW (root);
|
||||||
|
|
||||||
|
choice = gtk_color_choice_new (parent, self->title, self->use_alpha);
|
||||||
|
gtk_color_choice_choose (choice, &self->color, NULL, color_chosen, self);
|
||||||
|
g_object_unref (choice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
/* {{{ Public API */
|
||||||
|
/* {{{ Constructor */
|
||||||
|
|
||||||
|
GtkColorChoiceButton *
|
||||||
|
gtk_color_choice_button_new (void)
|
||||||
|
{
|
||||||
|
return g_object_new (GTK_TYPE_COLOR_CHOICE_BUTTON, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
/* {{{ Setters and Getters */
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_color_choice_button_set_color (GtkColorChoiceButton *self,
|
||||||
|
const GdkRGBA *color)
|
||||||
|
{
|
||||||
|
char *text;
|
||||||
|
|
||||||
|
g_return_if_fail (GTK_IS_COLOR_CHOICE_BUTTON (self));
|
||||||
|
g_return_if_fail (color != NULL);
|
||||||
|
|
||||||
|
if (gdk_rgba_equal (&self->color, color))
|
||||||
|
return;
|
||||||
|
|
||||||
|
self->color = *color;
|
||||||
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (self->swatch), color);
|
||||||
|
|
||||||
|
text = accessible_color_name (color);
|
||||||
|
gtk_accessible_update_property (GTK_ACCESSIBLE (self->swatch),
|
||||||
|
GTK_ACCESSIBLE_PROPERTY_LABEL, text,
|
||||||
|
-1);
|
||||||
|
g_free (text);
|
||||||
|
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const GdkRGBA *
|
||||||
|
gtk_color_choice_button_get_color (GtkColorChoiceButton *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_COLOR_CHOICE_BUTTON (self), NULL);
|
||||||
|
|
||||||
|
return &self->color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_color_choice_button_set_use_alpha (GtkColorChoiceButton *self,
|
||||||
|
gboolean use_alpha)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GTK_IS_COLOR_CHOICE_BUTTON (self));
|
||||||
|
|
||||||
|
if (self->use_alpha == use_alpha)
|
||||||
|
return;
|
||||||
|
|
||||||
|
self->use_alpha = use_alpha;
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USE_ALPHA]);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gtk_color_choice_button_get_use_alpha (GtkColorChoiceButton *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_COLOR_CHOICE_BUTTON (self), TRUE);
|
||||||
|
|
||||||
|
return self->use_alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_color_choice_button_set_title (GtkColorChoiceButton *self,
|
||||||
|
const char *title)
|
||||||
|
{
|
||||||
|
char *new_title;
|
||||||
|
|
||||||
|
g_return_if_fail (GTK_IS_COLOR_CHOICE_BUTTON (self));
|
||||||
|
g_return_if_fail (title != NULL);
|
||||||
|
|
||||||
|
if (g_str_equal (self->title, title))
|
||||||
|
return;
|
||||||
|
|
||||||
|
new_title = g_strdup (title);
|
||||||
|
g_free (self->title);
|
||||||
|
self->title = new_title;
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* vim:set foldmethod=marker expandtab: */
|
||||||
60
gtk/gtkcolorchoicebutton.h
Normal file
60
gtk/gtkcolorchoicebutton.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2022 Red Hat, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This Library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This Library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||||
|
#error "Only <gtk/gtk.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gtk/gtkwidget.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GTK_TYPE_COLOR_CHOICE_BUTTON (gtk_color_choice_button_get_type ())
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
G_DECLARE_FINAL_TYPE (GtkColorChoiceButton, gtk_color_choice_button, GTK, COLOR_CHOICE_BUTTON, GtkWidget)
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
GtkColorChoiceButton *
|
||||||
|
gtk_color_choice_button_new (void);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
void gtk_color_choice_button_set_color (GtkColorChoiceButton *self,
|
||||||
|
const GdkRGBA *color);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
const GdkRGBA * gtk_color_choice_button_get_color (GtkColorChoiceButton *self);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
void gtk_color_choice_button_set_use_alpha (GtkColorChoiceButton *self,
|
||||||
|
gboolean use_alpha);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
gboolean gtk_color_choice_button_get_use_alpha (GtkColorChoiceButton *self);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
void gtk_color_choice_button_set_title (GtkColorChoiceButton *self,
|
||||||
|
const char *title);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
const char * gtk_color_choice_button_get_title (GtkColorChoiceButton *self);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
278
gtk/gtkcolorchooserwindow.c
Normal file
278
gtk/gtkcolorchooserwindow.c
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2012 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "gtkwindow.h"
|
||||||
|
#include "gtkwindowprivate.h"
|
||||||
|
#include "gtkbutton.h"
|
||||||
|
#include "gtkbox.h"
|
||||||
|
#include "gtkprivate.h"
|
||||||
|
#include "gtksettings.h"
|
||||||
|
|
||||||
|
#include "gtkcolorchooserprivate.h"
|
||||||
|
#include "gtkcolorchooserwindowprivate.h"
|
||||||
|
#include "gtkcolorchooserwidget.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GtkColorChooserWindow:
|
||||||
|
*
|
||||||
|
* A window for choosing a color.
|
||||||
|
*
|
||||||
|
* 
|
||||||
|
*
|
||||||
|
* `GtkColorChooserWindow` implements the [iface@Gtk.ColorChooser] interface
|
||||||
|
* and does not provide much API of its own.
|
||||||
|
*
|
||||||
|
* To create a `GtkColorChooserWindow`, use [ctor@Gtk.ColorChooserWindow.new].
|
||||||
|
*
|
||||||
|
* To change the initially selected color, use
|
||||||
|
* [method@Gtk.ColorChooser.set_rgba]. To get the selected color use
|
||||||
|
* [method@Gtk.ColorChooser.get_rgba].
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct _GtkColorChooserWindow
|
||||||
|
{
|
||||||
|
GtkWindow parent_instance;
|
||||||
|
|
||||||
|
GtkWidget *chooser;
|
||||||
|
GtkWidget *ok_button;
|
||||||
|
GtkWidget *cancel_button;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_RGBA = 1,
|
||||||
|
PROP_USE_ALPHA,
|
||||||
|
PROP_SHOW_EDITOR
|
||||||
|
};
|
||||||
|
|
||||||
|
static void gtk_color_chooser_window_iface_init (GtkColorChooserInterface *iface);
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (GtkColorChooserWindow, gtk_color_chooser_window, GTK_TYPE_WINDOW,
|
||||||
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER,
|
||||||
|
gtk_color_chooser_window_iface_init))
|
||||||
|
|
||||||
|
static void
|
||||||
|
propagate_notify (GObject *o,
|
||||||
|
GParamSpec *pspec,
|
||||||
|
GtkColorChooserWindow *self)
|
||||||
|
{
|
||||||
|
g_object_notify (G_OBJECT (self), pspec->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
color_activated_cb (GtkColorChooser *chooser,
|
||||||
|
GdkRGBA *color,
|
||||||
|
GtkColorChooserWindow *window)
|
||||||
|
{
|
||||||
|
g_signal_emit_by_name (window->ok_button, "clicked");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_init (GtkColorChooserWindow *self)
|
||||||
|
{
|
||||||
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_unmap (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GTK_WIDGET_CLASS (gtk_color_chooser_window_parent_class)->unmap (widget);
|
||||||
|
|
||||||
|
/* We never want the window to come up with the editor,
|
||||||
|
* even if it was showing the editor the last time it was used.
|
||||||
|
*/
|
||||||
|
g_object_set (widget, "show-editor", FALSE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkColorChooserWindow *self = GTK_COLOR_CHOOSER_WINDOW (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_RGBA:
|
||||||
|
{
|
||||||
|
GdkRGBA color;
|
||||||
|
|
||||||
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (self), &color);
|
||||||
|
g_value_set_boxed (value, &color);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PROP_USE_ALPHA:
|
||||||
|
g_value_set_boolean (value, gtk_color_chooser_get_use_alpha (GTK_COLOR_CHOOSER (self->chooser)));
|
||||||
|
break;
|
||||||
|
case PROP_SHOW_EDITOR:
|
||||||
|
{
|
||||||
|
gboolean show_editor;
|
||||||
|
g_object_get (self->chooser, "show-editor", &show_editor, NULL);
|
||||||
|
g_value_set_boolean (value, show_editor);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkColorChooserWindow *self = GTK_COLOR_CHOOSER_WINDOW (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_RGBA:
|
||||||
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (self), g_value_get_boxed (value));
|
||||||
|
break;
|
||||||
|
case PROP_USE_ALPHA:
|
||||||
|
if (gtk_color_chooser_get_use_alpha (GTK_COLOR_CHOOSER (self->chooser)) != g_value_get_boolean (value))
|
||||||
|
{
|
||||||
|
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (self->chooser), g_value_get_boolean (value));
|
||||||
|
g_object_notify_by_pspec (object, pspec);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PROP_SHOW_EDITOR:
|
||||||
|
g_object_set (self->chooser,
|
||||||
|
"show-editor", g_value_get_boolean (value),
|
||||||
|
NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_dispose (GObject *object)
|
||||||
|
{
|
||||||
|
GtkColorChooserWindow *self = GTK_COLOR_CHOOSER_WINDOW (object);
|
||||||
|
|
||||||
|
g_clear_pointer (&self->chooser, gtk_widget_unparent);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gtk_color_chooser_window_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_class_init (GtkColorChooserWindowClass *class)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||||
|
|
||||||
|
object_class->dispose = gtk_color_chooser_window_dispose;
|
||||||
|
object_class->get_property = gtk_color_chooser_window_get_property;
|
||||||
|
object_class->set_property = gtk_color_chooser_window_set_property;
|
||||||
|
|
||||||
|
widget_class->unmap = gtk_color_chooser_window_unmap;
|
||||||
|
|
||||||
|
g_object_class_override_property (object_class, PROP_RGBA, "rgba");
|
||||||
|
g_object_class_override_property (object_class, PROP_USE_ALPHA, "use-alpha");
|
||||||
|
g_object_class_install_property (object_class, PROP_SHOW_EDITOR,
|
||||||
|
g_param_spec_boolean ("show-editor", NULL, NULL,
|
||||||
|
FALSE, GTK_PARAM_READWRITE));
|
||||||
|
|
||||||
|
gtk_widget_class_set_template_from_resource (widget_class,
|
||||||
|
"/org/gtk/libgtk/ui/gtkcolorchooserwindow.ui");
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, GtkColorChooserWindow, chooser);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, GtkColorChooserWindow, ok_button);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, GtkColorChooserWindow, cancel_button);
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, propagate_notify);
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, color_activated_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_get_rgba (GtkColorChooser *chooser,
|
||||||
|
GdkRGBA *color)
|
||||||
|
{
|
||||||
|
GtkColorChooserWindow *self = GTK_COLOR_CHOOSER_WINDOW (chooser);
|
||||||
|
|
||||||
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (self->chooser), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_set_rgba (GtkColorChooser *chooser,
|
||||||
|
const GdkRGBA *color)
|
||||||
|
{
|
||||||
|
GtkColorChooserWindow *self = GTK_COLOR_CHOOSER_WINDOW (chooser);
|
||||||
|
|
||||||
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (self->chooser), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_add_palette (GtkColorChooser *chooser,
|
||||||
|
GtkOrientation orientation,
|
||||||
|
int colors_per_line,
|
||||||
|
int n_colors,
|
||||||
|
GdkRGBA *colors)
|
||||||
|
{
|
||||||
|
GtkColorChooserWindow *self = GTK_COLOR_CHOOSER_WINDOW (chooser);
|
||||||
|
|
||||||
|
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (self->chooser),
|
||||||
|
orientation, colors_per_line, n_colors, colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_color_chooser_window_iface_init (GtkColorChooserInterface *iface)
|
||||||
|
{
|
||||||
|
iface->get_rgba = gtk_color_chooser_window_get_rgba;
|
||||||
|
iface->set_rgba = gtk_color_chooser_window_set_rgba;
|
||||||
|
iface->add_palette = gtk_color_chooser_window_add_palette;
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *
|
||||||
|
gtk_color_chooser_window_new (const char *title,
|
||||||
|
GtkWindow *parent)
|
||||||
|
{
|
||||||
|
return g_object_new (GTK_TYPE_COLOR_CHOOSER_WINDOW,
|
||||||
|
"title", title,
|
||||||
|
"transient-for", parent,
|
||||||
|
"modal", TRUE,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_color_chooser_window_save_color (GtkColorChooserWindow *self)
|
||||||
|
{
|
||||||
|
GdkRGBA color;
|
||||||
|
|
||||||
|
/* This causes the color chooser widget to save the
|
||||||
|
* selected and custom colors to GSettings.
|
||||||
|
*/
|
||||||
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (self), &color);
|
||||||
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (self), &color);
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *
|
||||||
|
gtk_color_chooser_window_get_ok_button (GtkColorChooserWindow *self)
|
||||||
|
{
|
||||||
|
return self->ok_button;
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *
|
||||||
|
gtk_color_chooser_window_get_cancel_button (GtkColorChooserWindow *self)
|
||||||
|
{
|
||||||
|
return self->cancel_button;
|
||||||
|
}
|
||||||
|
|
||||||
34
gtk/gtkcolorchooserwindowprivate.h
Normal file
34
gtk/gtkcolorchooserwindowprivate.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2012 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtk/gtkwindow.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GTK_TYPE_COLOR_CHOOSER_WINDOW (gtk_color_chooser_window_get_type ())
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (GtkColorChooserWindow, gtk_color_chooser_window, GTK, COLOR_CHOOSER_WINDOW, GtkWindow)
|
||||||
|
|
||||||
|
GtkWidget * gtk_color_chooser_window_new (const char *title,
|
||||||
|
GtkWindow *parent);
|
||||||
|
void gtk_color_chooser_window_save_color (GtkColorChooserWindow *self);
|
||||||
|
GtkWidget *gtk_color_chooser_window_get_ok_button (GtkColorChooserWindow *self);
|
||||||
|
GtkWidget *gtk_color_chooser_window_get_cancel_button (GtkColorChooserWindow *self);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
@@ -183,9 +183,12 @@ gtk_public_sources = files([
|
|||||||
'gtkcenterlayout.c',
|
'gtkcenterlayout.c',
|
||||||
'gtkcheckbutton.c',
|
'gtkcheckbutton.c',
|
||||||
'gtkcolorbutton.c',
|
'gtkcolorbutton.c',
|
||||||
|
'gtkcolorchoice.c',
|
||||||
|
'gtkcolorchoicebutton.c',
|
||||||
'gtkcolorchooser.c',
|
'gtkcolorchooser.c',
|
||||||
'gtkcolorchooserdialog.c',
|
'gtkcolorchooserdialog.c',
|
||||||
'gtkcolorchooserwidget.c',
|
'gtkcolorchooserwidget.c',
|
||||||
|
'gtkcolorchooserwindow.c',
|
||||||
'gtkcolorutils.c',
|
'gtkcolorutils.c',
|
||||||
'gtkcolumnview.c',
|
'gtkcolumnview.c',
|
||||||
'gtkcolumnviewcolumn.c',
|
'gtkcolumnviewcolumn.c',
|
||||||
@@ -439,6 +442,8 @@ gtk_public_headers = files([
|
|||||||
'gtkcenterlayout.h',
|
'gtkcenterlayout.h',
|
||||||
'gtkcheckbutton.h',
|
'gtkcheckbutton.h',
|
||||||
'gtkcolorbutton.h',
|
'gtkcolorbutton.h',
|
||||||
|
'gtkcolorchoice.h',
|
||||||
|
'gtkcolorchoicebutton.h',
|
||||||
'gtkcolorchooser.h',
|
'gtkcolorchooser.h',
|
||||||
'gtkcolorchooserdialog.h',
|
'gtkcolorchooserdialog.h',
|
||||||
'gtkcolorchooserwidget.h',
|
'gtkcolorchooserwidget.h',
|
||||||
|
|||||||
52
gtk/ui/gtkcolorchooserwindow.ui
Normal file
52
gtk/ui/gtkcolorchooserwindow.ui
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface domain="gtk40">
|
||||||
|
<template class="GtkColorChooserWindow" parent="GtkWindow">
|
||||||
|
<property name="title" translatable="yes">Select a Color</property>
|
||||||
|
<property name="resizable">0</property>
|
||||||
|
<property name="default-widget">ok_button</property>
|
||||||
|
<child type="titlebar">
|
||||||
|
<object class="GtkHeaderBar">
|
||||||
|
<property name="show-title-buttons">0</property>
|
||||||
|
<child type="start">
|
||||||
|
<object class="GtkButton" id="cancel_button">
|
||||||
|
<property name="use-underline">1</property>
|
||||||
|
<property name="label" translatable="yes">_Cancel</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="end">
|
||||||
|
<object class="GtkButton" id="ok_button">
|
||||||
|
<property name="label" translatable="yes">_Select</property>
|
||||||
|
<property name="use-underline">1</property>
|
||||||
|
<style>
|
||||||
|
<class name="suggested-action"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="orientation">1</property>
|
||||||
|
<property name="spacing">2</property>
|
||||||
|
<property name="margin-start">5</property>
|
||||||
|
<property name="margin-end">5</property>
|
||||||
|
<property name="margin-top">5</property>
|
||||||
|
<property name="margin-bottom">5</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkColorChooserWidget" id="chooser">
|
||||||
|
<property name="margin-start">5</property>
|
||||||
|
<property name="margin-end">5</property>
|
||||||
|
<property name="margin-top">5</property>
|
||||||
|
<property name="margin-bottom">5</property>
|
||||||
|
<property name="rgba">rgb(255,255,255)</property>
|
||||||
|
<property name="hexpand">1</property>
|
||||||
|
<property name="vexpand">1</property>
|
||||||
|
<signal name="color-activated" handler="color_activated_cb" swapped="no"/>
|
||||||
|
<signal name="notify::rgba" handler="propagate_notify" swapped="no"/>
|
||||||
|
<signal name="notify::show-editor" handler="propagate_notify" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
||||||
Reference in New Issue
Block a user