PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

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