PageRenderTime 33ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://github.com/tybor/Liberty
Specman e | 477 lines | 21 code | 76 blank | 380 comment | 2 complexity | 83313924ebf166c5dad91a33da685367 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 TREE_STORE
 23
 24creation make
 25
 26feature  -- Creation
 27-- /* Tree View/Tree Store
 28--  *
 29--  * The GtkTreeStore is used to store data in tree form, to be
 30--  * used later on by a GtkTreeView to display it. This demo builds
 31--  * a simple GtkTreeStore and displays it. If you're new to the
 32--  * GtkTreeView widgets and associates, look into the GtkListStore
 33--  * example first.
 34--  *
 35--  */
 36
 37-- #include <gtk/gtk.h>
 38
 39-- static GtkWidget *window = NULL;
 40
 41-- /* TreeItem structure */
 42-- typedef struct _TreeItem TreeItem;
 43-- struct _TreeItem
 44-- {
 45--   const gchar    *label;
 46--   gboolean        alex;
 47--   gboolean        havoc;
 48--   gboolean        tim;
 49--   gboolean        owen;
 50--   gboolean        dave;
 51--   gboolean        world_holiday; /* shared by the European hackers */
 52--   TreeItem       *children;
 53-- };
 54
 55-- /* columns */
 56-- enum
 57-- {
 58--   HOLIDAY_NAME_COLUMN = 0,
 59--   ALEX_COLUMN,
 60--   HAVOC_COLUMN,
 61--   TIM_COLUMN,
 62--   OWEN_COLUMN,
 63--   DAVE_COLUMN,
 64
 65--   VISIBLE_COLUMN,
 66--   WORLD_COLUMN,
 67--   NUM_COLUMNS
 68-- };
 69
 70-- /* tree data */
 71-- static TreeItem january[] =
 72-- {
 73--   {"New Years Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
 74--   {"Presidential Inauguration", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
 75--   {"Martin Luther King Jr. day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
 76--   { NULL }
 77-- };
 78
 79-- static TreeItem february[] =
 80-- {
 81--   { "Presidents' Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
 82--   { "Groundhog Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
 83--   { "Valentine's Day", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, NULL },
 84--   { NULL }
 85-- };
 86
 87-- static TreeItem march[] =
 88-- {
 89--   { "National Tree Planting Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
 90--   { "St Patrick's Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
 91--   { NULL }
 92-- };
 93-- static TreeItem april[] =
 94-- {
 95--   { "April Fools' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
 96--   { "Army Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
 97--   { "Earth Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
 98--   { "Administrative Professionals' Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
 99--   { NULL }
100-- };
101
102-- static TreeItem may[] =
103-- {
104--   { "Nurses' Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
105--   { "National Day of Prayer", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
106--   { "Mothers' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
107--   { "Armed Forces Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
108--   { "Memorial Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
109--   { NULL }
110-- };
111
112-- static TreeItem june[] =
113-- {
114--   { "June Fathers' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
115--   { "Juneteenth (Liberation of Slaves)", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
116--   { "Flag Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
117--   { NULL }
118-- };
119
120-- static TreeItem july[] =
121-- {
122--   { "Parents' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
123--   { "Independence Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
124--   { NULL }
125-- };
126
127-- static TreeItem august[] =
128-- {
129--   { "Air Force Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
130--   { "Coast Guard Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
131--   { "Friendship Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
132--   { NULL }
133-- };
134
135-- static TreeItem september[] =
136-- {
137--   { "Grandparents' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
138--   { "Citizenship Day or Constitution Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
139--   { "Labor Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
140--   { NULL }
141-- };
142
143-- static TreeItem october[] =
144-- {
145--   { "National Children's Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
146--   { "Bosses' Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
147--   { "Sweetest Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
148--   { "Mother-in-Law's Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
149--   { "Navy Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
150--   { "Columbus Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
151--   { "Halloween", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
152--   { NULL }
153-- };
154
155-- static TreeItem november[] =
156-- {
157--   { "Marine Corps Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
158--   { "Veterans' Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
159--   { "Thanksgiving", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
160--   { NULL }
161-- };
162
163-- static TreeItem december[] =
164-- {
165--   { "Pearl Harbor Remembrance Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
166--   { "Christmas", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
167--   { "Kwanzaa", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
168--   { NULL }
169-- };
170
171
172-- static TreeItem toplevel[] =
173-- {
174--   {"January", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, january},
175--   {"February", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, february},
176--   {"March", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, march},
177--   {"April", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, april},
178--   {"May", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, may},
179--   {"June", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, june},
180--   {"July", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, july},
181--   {"August", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, august},
182--   {"September", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, september},
183--   {"October", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, october},
184--   {"November", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, november},
185--   {"December", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, december},
186--   {NULL}
187-- };
188
189
190-- static GtkTreeModel *
191-- create_model (void)
192-- {
193--   GtkTreeStore *model;
194--   GtkTreeIter iter;
195--   TreeItem *month = toplevel;
196
197--   /* create tree store */
198--   model = gtk_tree_store_new (NUM_COLUMNS,
199-- 			      G_TYPE_STRING,
200-- 			      G_TYPE_BOOLEAN,
201-- 			      G_TYPE_BOOLEAN,
202-- 			      G_TYPE_BOOLEAN,
203-- 			      G_TYPE_BOOLEAN,
204-- 			      G_TYPE_BOOLEAN,
205-- 			      G_TYPE_BOOLEAN,
206-- 			      G_TYPE_BOOLEAN);
207
208--   /* add data to the tree store */
209--   while (month->label)
210--     {
211--       TreeItem *holiday = month->children;
212
213--       gtk_tree_store_append (model, &iter, NULL);
214--       gtk_tree_store_set (model, &iter,
215-- 			  HOLIDAY_NAME_COLUMN, month->label,
216-- 			  ALEX_COLUMN, FALSE,
217-- 			  HAVOC_COLUMN, FALSE,
218-- 			  TIM_COLUMN, FALSE,
219-- 			  OWEN_COLUMN, FALSE,
220-- 			  DAVE_COLUMN, FALSE,
221-- 			  VISIBLE_COLUMN, FALSE,
222-- 			  WORLD_COLUMN, FALSE,
223-- 			  -1);
224
225--       /* add children */
226--       while (holiday->label)
227-- 	{
228-- 	  GtkTreeIter child_iter;
229
230-- 	  gtk_tree_store_append (model, &child_iter, &iter);
231-- 	  gtk_tree_store_set (model, &child_iter,
232-- 			      HOLIDAY_NAME_COLUMN, holiday->label,
233-- 			      ALEX_COLUMN, holiday->alex,
234-- 			      HAVOC_COLUMN, holiday->havoc,
235-- 			      TIM_COLUMN, holiday->tim,
236-- 			      OWEN_COLUMN, holiday->owen,
237-- 			      DAVE_COLUMN, holiday->dave,
238-- 			      VISIBLE_COLUMN, TRUE,
239-- 			      WORLD_COLUMN, holiday->world_holiday,
240-- 			      -1);
241
242-- 	  holiday++;
243-- 	}
244
245--       month++;
246--     }
247
248--   return GTK_TREE_MODEL (model);
249-- }
250
251-- static void
252-- item_toggled (GtkCellRendererToggle *cell,
253-- 	      gchar                 *path_str,
254-- 	      gpointer               data)
255-- {
256--   GtkTreeModel *model = (GtkTreeModel *)data;
257--   GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
258--   GtkTreeIter iter;
259--   gboolean toggle_item;
260
261--   gint *column;
262
263--   column = g_object_get_data (G_OBJECT (cell), "column");
264
265--   /* get toggled iter */
266--   gtk_tree_model_get_iter (model, &iter, path);
267--   gtk_tree_model_get (model, &iter, column, &toggle_item, -1);
268
269--   /* do something with the value */
270--   toggle_item ^= 1;
271
272--   /* set new value */
273--   gtk_tree_store_set (GTK_TREE_STORE (model), &iter, column,
274-- 		      toggle_item, -1);
275
276--   /* clean up */
277--   gtk_tree_path_free (path);
278-- }
279
280-- static void
281-- add_columns (GtkTreeView *treeview)
282-- {
283--   gint col_offset;
284--   GtkCellRenderer *renderer;
285--   GtkTreeViewColumn *column;
286--   GtkTreeModel *model = gtk_tree_view_get_model (treeview);
287
288--   /* column for holiday names */
289--   renderer = gtk_cell_renderer_text_new ();
290--   g_object_set (renderer, "xalign", 0.0, NULL);
291
292--   col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
293-- 							    -1, "Holiday",
294-- 							    renderer, "text",
295-- 							    HOLIDAY_NAME_COLUMN,
296-- 							    NULL);
297--   column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
298--   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
299
300--   /* alex column */
301--   renderer = gtk_cell_renderer_toggle_new ();
302--   g_object_set (renderer, "xalign", 0.0, NULL);
303--   g_object_set_data (G_OBJECT (renderer), "column", (gint *)ALEX_COLUMN);
304
305--   g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
306
307--   col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
308-- 							    -1, "Alex",
309-- 							    renderer,
310-- 							    "active",
311-- 							    ALEX_COLUMN,
312-- 							    "visible",
313-- 							    VISIBLE_COLUMN,
314-- 							    "activatable",
315-- 							    WORLD_COLUMN, NULL);
316
317--   column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
318--   gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
319-- 				   GTK_TREE_VIEW_COLUMN_FIXED);
320--   gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
321--   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
322
323--   /* havoc column */
324--   renderer = gtk_cell_renderer_toggle_new ();
325--   g_object_set (renderer, "xalign", 0.0, NULL);
326--   g_object_set_data (G_OBJECT (renderer), "column", (gint *)HAVOC_COLUMN);
327
328--   g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
329
330--   col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
331-- 							    -1, "Havoc",
332-- 							    renderer,
333-- 							    "active",
334-- 							    HAVOC_COLUMN,
335-- 							    "visible",
336-- 							    VISIBLE_COLUMN,
337-- 							    NULL);
338
339--   column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
340--   gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
341-- 				   GTK_TREE_VIEW_COLUMN_FIXED);
342--   gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
343--   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
344
345--   /* tim column */
346--   renderer = gtk_cell_renderer_toggle_new ();
347--   g_object_set (renderer, "xalign", 0.0, NULL);
348--   g_object_set_data (G_OBJECT (renderer), "column", (gint *)TIM_COLUMN);
349
350--   g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
351
352--   col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
353-- 							    -1, "Tim",
354-- 							    renderer,
355-- 							    "active",
356-- 							    TIM_COLUMN,
357-- 							    "visible",
358-- 							    VISIBLE_COLUMN,
359-- 							    "activatable",
360-- 							    WORLD_COLUMN, NULL);
361
362--   column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
363--   gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
364-- 				   GTK_TREE_VIEW_COLUMN_FIXED);
365--   gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
366--   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
367
368--   /* owen column */
369--   renderer = gtk_cell_renderer_toggle_new ();
370--   g_object_set (renderer, "xalign", 0.0, NULL);
371--   g_object_set_data (G_OBJECT (renderer), "column", (gint *)OWEN_COLUMN);
372
373--   g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
374
375--   col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
376-- 							    -1, "Owen",
377-- 							    renderer,
378-- 							    "active",
379-- 							    OWEN_COLUMN,
380-- 							    "visible",
381-- 							    VISIBLE_COLUMN,
382-- 							    NULL);
383
384--   column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
385--   gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
386-- 				   GTK_TREE_VIEW_COLUMN_FIXED);
387--   gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
388--   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
389
390--   /* dave column */
391--   renderer = gtk_cell_renderer_toggle_new ();
392--   g_object_set (renderer, "xalign", 0.0, NULL);
393--   g_object_set_data (G_OBJECT (renderer), "column", (gint *)DAVE_COLUMN);
394
395--   g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model);
396
397--   col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
398-- 							    -1, "Dave",
399-- 							    renderer,
400-- 							    "active",
401-- 							    DAVE_COLUMN,
402-- 							    "visible",
403-- 							    VISIBLE_COLUMN,
404-- 							    NULL);
405
406--   column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
407--   gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
408-- 				   GTK_TREE_VIEW_COLUMN_FIXED);
409--   gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
410--   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
411-- }
412
413-- GtkWidget *
414-- do_tree_store (GtkWidget *do_widget)
415-- {
416--   if (!window)
417--     {
418--       GtkWidget *vbox;
419--       GtkWidget *sw;
420--       GtkWidget *treeview;
421--       GtkTreeModel *model;
422
423--       /* create window, etc */
424--       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
425--       gtk_window_set_screen (GTK_WINDOW (window),
426-- 			     gtk_widget_get_screen (do_widget));
427--       gtk_window_set_title (GTK_WINDOW (window), "Card planning sheet");
428--       g_signal_connect (window, "destroy",
429-- 			G_CALLBACK (gtk_widget_destroyed), &window);
430
431--       vbox = gtk_vbox_new (FALSE, 8);
432--       gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
433--       gtk_container_add (GTK_CONTAINER (window), vbox);
434
435--       gtk_box_pack_start (GTK_BOX (vbox),
436-- 			  gtk_label_new ("Jonathan's Holiday Card Planning Sheet"),
437-- 			  FALSE, FALSE, 0);
438
439--       sw = gtk_scrolled_window_new (NULL, NULL);
440--       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
441-- 					   GTK_SHADOW_ETCHED_IN);
442--       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
443-- 				      GTK_POLICY_AUTOMATIC,
444-- 				      GTK_POLICY_AUTOMATIC);
445--       gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
446
447--       /* create model */
448--       model = create_model ();
449
450--       /* create tree view */
451--       treeview = gtk_tree_view_new_with_model (model);
452--       g_object_unref (model);
453--       gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
454--       gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
455-- 				   GTK_SELECTION_MULTIPLE);
456
457--       add_columns (GTK_TREE_VIEW (treeview));
458
459--       gtk_container_add (GTK_CONTAINER (sw), treeview);
460
461--       /* expand all rows after the treeview widget has been realized */
462--       g_signal_connect (treeview, "realize",
463-- 			G_CALLBACK (gtk_tree_view_expand_all), NULL);
464--       gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
465--     }
466
467--   if (!GTK_WIDGET_VISIBLE (window))
468--     gtk_widget_show_all (window);
469--   else
470--     {
471--       gtk_widget_destroy (window);
472--       window = NULL;
473--     }
474
475--   return window;
476-- }
477end