{"id":908,"date":"2022-08-30T15:09:11","date_gmt":"2022-08-30T15:09:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/gtk-code-demos-compile-color-selector-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:09:11","modified_gmt":"2022-08-30T15:09:11","slug":"gtk-code-demos-compile-color-selector-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/gtk-code-demos-compile-color-selector-collection-of-common-programming-errors\/","title":{"rendered":"GTK+ Code Demos &#8211; compile Color Selector-Collection of common programming errors"},"content":{"rendered":"<p>I found out that Color Selector from the GTK+ Code Demos is a quite nice color chooser. Thus, I would like to use it as a standalone application without having to run <code>gtk-demos<\/code> every time.<\/p>\n<p>I tried to compile the example code which is:<\/p>\n<pre><code>#include \n\nstatic GtkWidget *window = NULL;\nstatic GtkWidget *da;\nstatic GdkColor color;\nstatic GtkWidget *frame;\n\n\/* Expose callback for the drawing area\n *\/\nstatic gboolean\nexpose_event_callback (GtkWidget      *widget, \n                       GdkEventExpose *event, \n                       gpointer        data)\n{\n  GdkWindow *window = gtk_widget_get_window (widget);\n\n  if (window)\n    {\n      GtkStyle *style;\n      cairo_t *cr;\n\n      style = gtk_widget_get_style (widget);\n\n      cr = gdk_cairo_create (window);\n\n      gdk_cairo_set_source_color (cr, &amp;style-&gt;bg[GTK_STATE_NORMAL]);\n      gdk_cairo_rectangle (cr, &amp;event-&gt;area);\n      cairo_fill (cr);\n\n      cairo_destroy (cr);\n    }\n\n  return TRUE;\n}\n\nstatic void\nchange_color_callback (GtkWidget *button,\n               gpointer   data)\n{\n  GtkWidget *dialog;\n  GtkColorSelection *colorsel;\n  gint response;\n\n  dialog = gtk_color_selection_dialog_new (\"Changing color\");\n\n  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));\n\n  colorsel = \n    GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog)));\n\n  gtk_color_selection_set_previous_color (colorsel, &amp;color);\n  gtk_color_selection_set_current_color (colorsel, &amp;color);\n  gtk_color_selection_set_has_palette (colorsel, TRUE);\n\n  response = gtk_dialog_run (GTK_DIALOG (dialog));\n\n  if (response == GTK_RESPONSE_OK)\n    {\n      gtk_color_selection_get_current_color (colorsel,\n                         &amp;color);\n\n      gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &amp;color);\n    }\n\n  gtk_widget_destroy (dialog);\n}\n\nGtkWidget *\ndo_colorsel (GtkWidget *do_widget)\n{\n  GtkWidget *vbox;\n  GtkWidget *button;\n  GtkWidget *alignment;\n\n  if (!window)\n    {\n      color.red = 0;\n      color.blue = 65535;\n      color.green = 0;\n\n      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);\n      gtk_window_set_screen (GTK_WINDOW (window),\n                 gtk_widget_get_screen (do_widget));\n      gtk_window_set_title (GTK_WINDOW (window), \"Color Selection\");\n\n      g_signal_connect (window, \"destroy\",\n            G_CALLBACK (gtk_widget_destroyed), &amp;window);\n\n      gtk_container_set_border_width (GTK_CONTAINER (window), 8);\n\n      vbox = gtk_vbox_new (FALSE, 8);\n      gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);\n      gtk_container_add (GTK_CONTAINER (window), vbox);\n\n      \/*\n       * Create the color swatch area\n       *\/\n\n\n      frame = gtk_frame_new (NULL);\n      gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);\n      gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);\n\n      da = gtk_drawing_area_new ();\n\n      g_signal_connect (da, \"expose_event\",\n            G_CALLBACK (expose_event_callback), NULL);\n\n      \/* set a minimum size *\/\n      gtk_widget_set_size_request (da, 200, 200);\n      \/* set the color *\/\n      gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &amp;color);\n\n      gtk_container_add (GTK_CONTAINER (frame), da);\n\n      alignment = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);\n\n      button = gtk_button_new_with_mnemonic (\"_Change the above color\");\n      gtk_container_add (GTK_CONTAINER (alignment), button);\n\n      gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);\n\n      g_signal_connect (button, \"clicked\",\n            G_CALLBACK (change_color_callback), NULL);\n    }\n\n  if (!gtk_widget_get_visible (window))\n    {\n      gtk_widget_show_all (window);\n    }\n  else\n    {\n      gtk_widget_destroy (window);\n      window = NULL;\n    }\n\n  return window;\n}\n<\/code><\/pre>\n<p>The error is:<\/p>\n<pre><code>[orschiro@thinkpad ~]$ gcc `pkg-config --cflags --libs gtk+-3.0` -o colorSelector colorSelector.ccolorSelector.c: In function \u2018expose_event_callback\u2019:\ncolorSelector.c:26:7: warning: \u2018gdk_cairo_set_source_color\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gdk\/gdkcairo.h:58): Use 'gdk_cairo_set_source_rgba' instead [-Wdeprecated-declarations]\ncolorSelector.c: In function \u2018change_color_callback\u2019:\ncolorSelector.c:44:3: warning: \u2018gtk_color_selection_dialog_new\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gtk\/deprecated\/gtkcolorseldialog.h:73): Use 'gtk_color_chooser_dialog_new' instead [-Wdeprecated-declarations]\ncolorSelector.c:49:5: warning: \u2018gtk_color_selection_dialog_get_color_selection\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gtk\/deprecated\/gtkcolorseldialog.h:75): Use 'GtkColorChooser' instead [-Wdeprecated-declarations]\ncolorSelector.c:51:3: warning: \u2018gtk_color_selection_set_previous_color\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gtk\/deprecated\/gtkcolorsel.h:148) [-Wdeprecated-declarations]\ncolorSelector.c:52:3: warning: \u2018gtk_color_selection_set_current_color\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gtk\/deprecated\/gtkcolorsel.h:142): Use 'gtk_color_chooser_set_rgba' instead [-Wdeprecated-declarations]\ncolorSelector.c:53:3: warning: \u2018gtk_color_selection_set_has_palette\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gtk\/deprecated\/gtkcolorsel.h:100) [-Wdeprecated-declarations]\ncolorSelector.c:59:7: warning: \u2018gtk_color_selection_get_current_color\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gtk\/deprecated\/gtkcolorsel.h:145): Use 'gtk_color_chooser_get_rgba' instead [-Wdeprecated-declarations]\ncolorSelector.c: In function \u2018do_colorsel\u2019:\ncolorSelector.c:91:7: warning: \u2018gtk_vbox_new\u2019 is deprecated (declared at \/usr\/include\/gtk-3.0\/gtk\/deprecated\/gtkvbox.h:60): Use 'gtk_box_new' instead [-Wdeprecated-declarations]\n\/usr\/lib\/gcc\/x86_64-unknown-linux-gnu\/4.7.2\/..\/..\/..\/..\/lib\/crt1.o: In function `_start':\n(.text+0x20): undefined reference to `main'\ncollect2: error: ld returned 1 exit status\n<\/code><\/pre>\n<p>Installed packages:<\/p>\n<pre><code>gtk2 2.24.14-1\ngtk3 3.6.2-1\ngcc-libs-multilib 4.7.2-2\ngcc-multilib 4.7.2-2\n<\/code><\/pre>\n<p>Could someone please explain me the error?<\/p>\n<ol>\n<li>\n<p>Your source code is incomplete, the <code>main<\/code> function is missing. gtk-demo is organised so it has a single <code>main<\/code> that calls some submodules and processes them the same way, and you&#8217;re missing that <code>main<\/code>.<\/p>\n<p>The other warning come from the fact that this example code you&#8217;re trying to compile was done for GTK 2, and you&#8217;re trying to build it against GTK 3.<\/p>\n<p>You&#8217;ll find all the missing parts in the gtk-demo directory of the GTK+ repository.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:56:59. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I found out that Color Selector from the GTK+ Code Demos is a quite nice color chooser. Thus, I would like to use it as a standalone application without having to run gtk-demos every time. I tried to compile the example code which is: #include static GtkWidget *window = NULL; static GtkWidget *da; static GdkColor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-908","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=908"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/908\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}