/src/wrappers/gtk/examples/gtk-demo/colorsel.e

http://github.com/tybor/Liberty · Specman e · 164 lines · 21 code · 40 blank · 103 comment · 2 complexity · 554d53d0953a8855a65ae035821d01f8 MD5 · raw file

  1. indexing
  2. description: "."
  3. copyright: "[
  4. Copyright (C) 2006 Paolo Redaelli, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. class COLORSEL
  19. creation make
  20. feature
  21. -- /* Color Selector
  22. -- *
  23. -- * GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is
  24. -- * a prebuilt dialog containing a GtkColorSelection.
  25. -- *
  26. -- */
  27. -- #include <gtk/gtk.h>
  28. -- static GtkWidget *window = NULL;
  29. -- static GtkWidget *da;
  30. -- static GdkColor color;
  31. -- static GtkWidget *frame;
  32. -- /* Expose callback for the drawing area
  33. -- */
  34. -- static gboolean
  35. -- expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
  36. -- {
  37. -- if (widget->window)
  38. -- {
  39. -- GtkStyle *style;
  40. -- style = gtk_widget_get_style (widget);
  41. -- gdk_draw_rectangle (widget->window,
  42. -- style->bg_gc[GTK_STATE_NORMAL],
  43. -- TRUE,
  44. -- event->area.x, event->area.y,
  45. -- event->area.width, event->area.height);
  46. -- }
  47. -- return TRUE;
  48. -- }
  49. -- static void
  50. -- change_color_callback (GtkWidget *button,
  51. -- gpointer data)
  52. -- {
  53. -- GtkWidget *dialog;
  54. -- GtkColorSelection *colorsel;
  55. -- gint response;
  56. -- dialog = gtk_color_selection_dialog_new ("Changing color");
  57. -- gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
  58. -- colorsel = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (dialog)->colorsel);
  59. -- gtk_color_selection_set_previous_color (colorsel, &color);
  60. -- gtk_color_selection_set_current_color (colorsel, &color);
  61. -- gtk_color_selection_set_has_palette (colorsel, TRUE);
  62. -- response = gtk_dialog_run (GTK_DIALOG (dialog));
  63. -- if (response == GTK_RESPONSE_OK)
  64. -- {
  65. -- gtk_color_selection_get_current_color (colorsel,
  66. -- &color);
  67. -- gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color);
  68. -- }
  69. -- gtk_widget_destroy (dialog);
  70. -- }
  71. -- GtkWidget *
  72. -- do_colorsel (GtkWidget *do_widget)
  73. -- {
  74. -- GtkWidget *vbox;
  75. -- GtkWidget *button;
  76. -- GtkWidget *alignment;
  77. -- if (!window)
  78. -- {
  79. -- color.red = 0;
  80. -- color.blue = 65535;
  81. -- color.green = 0;
  82. -- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  83. -- gtk_window_set_screen (GTK_WINDOW (window),
  84. -- gtk_widget_get_screen (do_widget));
  85. -- gtk_window_set_title (GTK_WINDOW (window), "Color Selection");
  86. -- g_signal_connect (window, "destroy",
  87. -- G_CALLBACK (gtk_widget_destroyed), &window);
  88. -- gtk_container_set_border_width (GTK_CONTAINER (window), 8);
  89. -- vbox = gtk_vbox_new (FALSE, 8);
  90. -- gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
  91. -- gtk_container_add (GTK_CONTAINER (window), vbox);
  92. -- /*
  93. -- * Create the color swatch area
  94. -- */
  95. -- frame = gtk_frame_new (NULL);
  96. -- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  97. -- gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
  98. -- da = gtk_drawing_area_new ();
  99. -- g_signal_connect (da, "expose_event",
  100. -- G_CALLBACK (expose_event_callback), NULL);
  101. -- /* set a minimum size */
  102. -- gtk_widget_set_size_request (da, 200, 200);
  103. -- /* set the color */
  104. -- gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color);
  105. -- gtk_container_add (GTK_CONTAINER (frame), da);
  106. -- alignment = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
  107. -- button = gtk_button_new_with_mnemonic ("_Change the above color");
  108. -- gtk_container_add (GTK_CONTAINER (alignment), button);
  109. -- gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
  110. -- g_signal_connect (button, "clicked",
  111. -- G_CALLBACK (change_color_callback), NULL);
  112. -- }
  113. -- if (!GTK_WIDGET_VISIBLE (window))
  114. -- {
  115. -- gtk_widget_show_all (window);
  116. -- }
  117. -- else
  118. -- {
  119. -- gtk_widget_destroy (window);
  120. -- window = NULL;
  121. -- }
  122. -- return window;
  123. -- }
  124. end