diff --git a/tests/Makefile.am b/tests/Makefile.am index 7fd8a88c65..f5d319ac7d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -57,6 +57,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \ testcalendar \ testclipboard \ testcolorchooser \ + testcolorchooser2 \ testcombo \ testcombochange \ testcellrenderertext \ @@ -214,6 +215,7 @@ testcairo_DEPENDENCIES = $(TEST_DEPS) testcalendar_DEPENDENCIES = $(TEST_DEPS) testclipboard_DEPENDENCIES = $(TEST_DEPS) testcolorchooser_DEPENDENCIES = $(TEST_DEPS) +testcolorchooser2_DEPENDENCIES = $(TEST_DEPS) testcombo_DEPENDENCIES = $(TEST_DEPS) testcombochange_DEPENDENCIES = $(TEST_DEPS) testcellrenderertext_DEPENDENCIES = $(TEST_DEPS) @@ -524,6 +526,8 @@ testpixbuf_save_SOURCES = testpixbuf-save.c testcolorchooser_SOURCES = testcolorchooser.c +testcolorchooser2_SOURCES = testcolorchooser2.c + testkineticscrolling_SOURCES = testkineticscrolling.c teststack_SOURCES = teststack.c diff --git a/tests/testcolorchooser2.c b/tests/testcolorchooser2.c new file mode 100644 index 0000000000..c90962f55b --- /dev/null +++ b/tests/testcolorchooser2.c @@ -0,0 +1,59 @@ +#include + +static void rgba_changed (GtkColorChooser *chooser, GParamSpec *pspec, gpointer data); + +static void +text_activated (GtkEntry *entry, gpointer data) +{ + GtkColorChooser *chooser = data; + GdkRGBA rgba; + const char *text; + + text = gtk_entry_get_text (entry); + + g_signal_handlers_block_by_func (entry, rgba_changed, entry); + if (gdk_rgba_parse (&rgba, text)) + gtk_color_chooser_set_rgba (chooser, &rgba); + g_signal_handlers_unblock_by_func (entry, rgba_changed, entry); +} + +static void +rgba_changed (GtkColorChooser *chooser, GParamSpec *pspec, gpointer data) +{ + GtkWidget *entry = data; + GdkRGBA color; + char *s; + + gtk_color_chooser_get_rgba (chooser, &color); + s = gdk_rgba_to_string (&color); + + g_signal_handlers_block_by_func (entry, text_activated, chooser); + gtk_entry_set_text (GTK_ENTRY (entry), s); + g_signal_handlers_unblock_by_func (entry, text_activated, chooser); + + g_free (s); +} + +int main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *chooser; + GtkWidget *entry; + GtkBuilder *builder; + + gtk_init (NULL, NULL); + + builder = gtk_builder_new_from_file ("testcolorchooser2.ui"); + window = GTK_WIDGET (gtk_builder_get_object (builder, "window1")); + chooser = GTK_WIDGET (gtk_builder_get_object (builder, "chooser")); + entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry")); + + g_signal_connect (chooser, "notify::rgba", G_CALLBACK (rgba_changed), entry); + g_signal_connect (entry, "activate", G_CALLBACK (text_activated), chooser); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} diff --git a/tests/testcolorchooser2.ui b/tests/testcolorchooser2.ui new file mode 100644 index 0000000000..398dc4e25c --- /dev/null +++ b/tests/testcolorchooser2.ui @@ -0,0 +1,29 @@ + + + + + + 1 + horizontal + center + center + 10 + + + 1 + start + unknown + 25 + 25 + + + + + 1 + 1 + + + + + +