PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/tybor/Liberty
Specman e | 195 lines | 21 code | 38 blank | 136 comment | 2 complexity | 4ef16b133b6b247862ba9df55a9e86e5 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 SIZEGROUP
 23
 24creation make
 25
 26feature
 27	
 28-- /* Size Groups
 29--  *
 30--  * GtkSizeGroup provides a mechanism for grouping a number of
 31--  * widgets together so they all request the same amount of space.
 32--  * This is typically useful when you want a column of widgets to 
 33--  * have the same size, but you can't use a GtkTable widget.
 34--  * 
 35--  * Note that size groups only affect the amount of space requested,
 36--  * not the size that the widgets finally receive. If you want the
 37--  * widgets in a GtkSizeGroup to actually be the same size, you need
 38--  * to pack them in such a way that they get the size they request
 39--  * and not more. For example, if you are packing your widgets
 40--  * into a table, you would not include the GTK_FILL flag.
 41--  */
 42
 43-- #include <gtk/gtk.h>
 44
 45-- static GtkWidget *window = NULL;
 46
 47-- /* Convenience function to create a combo box holding a number of strings
 48--  */
 49-- GtkWidget *
 50-- create_combo_box (const char **strings)
 51-- {
 52--   GtkWidget *combo_box;
 53--   const char **str;
 54
 55--   combo_box = gtk_combo_box_new_text ();
 56  
 57--   for (str = strings; *str; str++)
 58--     gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), *str);
 59
 60--   gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
 61
 62--   return combo_box;
 63-- }
 64
 65-- static void
 66-- add_row (GtkTable     *table,
 67-- 	 int           row,
 68-- 	 GtkSizeGroup *size_group,
 69-- 	 const char   *label_text,
 70-- 	 const char  **options)
 71-- {
 72--   GtkWidget *combo_box;
 73--   GtkWidget *label;
 74
 75--   label = gtk_label_new_with_mnemonic (label_text);
 76--   gtk_misc_set_alignment (GTK_MISC (label), 0, 1);
 77--   gtk_table_attach (GTK_TABLE (table), label,
 78-- 		    0, 1,                  row, row + 1,
 79-- 		    GTK_EXPAND | GTK_FILL, 0,
 80-- 		    0,                     0);
 81  
 82--   combo_box = create_combo_box (options);
 83--   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo_box);
 84--   gtk_size_group_add_widget (size_group, combo_box);
 85--   gtk_table_attach (GTK_TABLE (table), combo_box,
 86-- 		    1, 2,                  row, row + 1,
 87-- 		    0,                     0,
 88-- 		    0,                     0);
 89-- }
 90
 91-- static void
 92-- toggle_grouping (GtkToggleButton *check_button,
 93-- 		 GtkSizeGroup    *size_group)
 94-- {
 95--   GtkSizeGroupMode new_mode;
 96
 97--   /* GTK_SIZE_GROUP_NONE is not generally useful, but is useful
 98--    * here to show the effect of GTK_SIZE_GROUP_HORIZONTAL by
 99--    * contrast.
100--    */
101--   if (gtk_toggle_button_get_active (check_button))
102--     new_mode = GTK_SIZE_GROUP_HORIZONTAL;
103--   else
104--     new_mode = GTK_SIZE_GROUP_NONE;
105  
106--   gtk_size_group_set_mode (size_group, new_mode);
107-- }
108
109-- GtkWidget *
110-- do_sizegroup (GtkWidget *do_widget)
111-- {
112--   GtkWidget *table;
113--   GtkWidget *frame;
114--   GtkWidget *vbox;
115--   GtkWidget *check_button;
116--   GtkSizeGroup *size_group;
117
118--   static const char *color_options[] = {
119--     "Red", "Green", "Blue", NULL
120--   };
121  
122--   static const char *dash_options[] = {
123--     "Solid", "Dashed", "Dotted", NULL
124--   };
125  
126--   static const char *end_options[] = {
127--     "Square", "Round", "Arrow", NULL
128--   };
129  
130--   if (!window)
131--     {
132--       window = gtk_dialog_new_with_buttons ("GtkSizeGroup",
133-- 					    GTK_WINDOW (do_widget),
134-- 					    0,
135-- 					    GTK_STOCK_CLOSE,
136-- 					    GTK_RESPONSE_NONE,
137-- 					    NULL);
138--       gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
139		
140--       g_signal_connect (window, "response",
141-- 			G_CALLBACK (gtk_widget_destroy), NULL);
142--       g_signal_connect (window, "destroy",
143-- 			G_CALLBACK (gtk_widget_destroyed), &window);
144
145--       vbox = gtk_vbox_new (FALSE, 5);
146--       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 0);
147--       gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
148
149--       size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
150		
151--       /* Create one frame holding color options
152--        */
153--       frame = gtk_frame_new ("Color Options");
154--       gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
155
156--       table = gtk_table_new (2, 2, FALSE);
157--       gtk_container_set_border_width (GTK_CONTAINER (table), 5);
158--       gtk_table_set_row_spacings (GTK_TABLE (table), 5);
159--       gtk_table_set_col_spacings (GTK_TABLE (table), 10);
160--       gtk_container_add (GTK_CONTAINER (frame), table);
161
162--       add_row (GTK_TABLE (table), 0, size_group, "_Foreground", color_options);
163--       add_row (GTK_TABLE (table), 1, size_group, "_Background", color_options);
164
165--       /* And another frame holding line style options
166--        */
167--       frame = gtk_frame_new ("Line Options");
168--       gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
169
170--       table = gtk_table_new (2, 2, FALSE);
171--       gtk_container_set_border_width (GTK_CONTAINER (table), 5);
172--       gtk_table_set_row_spacings (GTK_TABLE (table), 5);
173--       gtk_table_set_col_spacings (GTK_TABLE (table), 10);
174--       gtk_container_add (GTK_CONTAINER (frame), table);
175
176--       add_row (GTK_TABLE (table), 0, size_group, "_Dashing", dash_options);
177--       add_row (GTK_TABLE (table), 1, size_group, "_Line ends", end_options);
178
179--       /* And a check button to turn grouping on and off */
180--       check_button = gtk_check_button_new_with_mnemonic ("_Enable grouping");
181--       gtk_box_pack_start (GTK_BOX (vbox), check_button, FALSE, FALSE, 0);
182		
183--       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
184--       g_signal_connect (check_button, "toggled",
185-- 			G_CALLBACK (toggle_grouping), size_group);
186--     }
187
188--   if (!GTK_WIDGET_VISIBLE (window))
189--     gtk_widget_show_all (window);
190--   else
191--     gtk_widget_destroy (window);
192
193--   return window;
194-- }
195end