Add a color editor test
This tests using a color editor embedded in other ui.
This commit is contained in:
@ -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
|
||||
|
||||
59
tests/testcolorchooser2.c
Normal file
59
tests/testcolorchooser2.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
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;
|
||||
}
|
||||
29
tests/testcolorchooser2.ui
Normal file
29
tests/testcolorchooser2.ui
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">1</property>
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="spacing">10</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="entry">
|
||||
<property name="visible">1</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="text">unknown</property>
|
||||
<property name="width-chars">25</property>
|
||||
<property name="max-width-chars">25</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkColorChooserWidget" id="chooser">
|
||||
<property name="visible">1</property>
|
||||
<property name="show-editor">1</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
Reference in New Issue
Block a user