1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <ctk/ctk.h>

static void rgba_changed (CtkColorChooser *chooser, GParamSpec *pspec, gpointer data);

static void
text_activated (CtkEntry *entry, gpointer data)
{
  CdkRGBA rgba;
  const char *text;

  text = ctk_entry_get_text (entry);

  g_signal_handlers_block_by_func (entry, rgba_changed, entry);
  if (cdk_rgba_parse (&rgba, text))
    {
      CtkColorChooser *chooser = data;
      ctk_color_chooser_set_rgba (chooser, &rgba);
    }
  g_signal_handlers_unblock_by_func (entry, rgba_changed, entry);
}

static void
rgba_changed (CtkColorChooser *chooser,
	      GParamSpec      *pspec G_GNUC_UNUSED,
	      gpointer         data)
{
  CtkWidget *entry = data;
  CdkRGBA color;
  char *s;

  ctk_color_chooser_get_rgba (chooser, &color);
  s = cdk_rgba_to_string (&color);

  g_signal_handlers_block_by_func (entry, text_activated, chooser);
  ctk_entry_set_text (CTK_ENTRY (entry), s);
  g_signal_handlers_unblock_by_func (entry, text_activated, chooser);

  g_free (s);
}

int main (int   argc G_GNUC_UNUSED,
	  char *argv[] G_GNUC_UNUSED)<--- There is an unknown macro here somewhere. Configuration is required. If G_GNUC_UNUSED is a macro then please configure it.
{
  CtkWidget *window;
  CtkWidget *chooser;
  CtkWidget *entry;
  CtkBuilder *builder;

  ctk_init (NULL, NULL);

  builder = ctk_builder_new_from_file ("testcolorchooser2.ui");
  window = CTK_WIDGET (ctk_builder_get_object (builder, "window1"));
  chooser = CTK_WIDGET (ctk_builder_get_object (builder, "chooser"));
  entry = CTK_WIDGET (ctk_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);

  ctk_widget_show (window);

  ctk_main ();

  return 0;
}