testtreefocus.c 17.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* testtreefocus.c
 * Copyright (C) 2001 Red Hat, Inc
 * Author: Jonathan Blandford
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
16
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 18
 */

19
#include "config.h"
20 21 22 23 24 25
#include <gtk/gtk.h>

typedef struct _TreeStruct TreeStruct;
struct _TreeStruct
{
  const gchar *label;
26
  gboolean alex;
27
  gboolean havoc;
28
  gboolean tim;
29
  gboolean owen;
Jonathan Blandford's avatar
Jonathan Blandford committed
30
  gboolean dave;
31
  gboolean world_holiday; /* shared by the european hackers */
32 33 34
  TreeStruct *children;
};

Jonathan Blandford's avatar
Jonathan Blandford committed
35

36 37
static TreeStruct january[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
38 39 40
  {"New Years Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
  {"Presidential Inauguration", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
  {"Martin Luther King Jr. day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
41 42 43 44 45
  { NULL }
};

static TreeStruct february[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
46 47 48
  { "Presidents' Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
  { "Groundhog Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Valentine's Day", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, NULL },
49 50 51 52 53
  { NULL }
};

static TreeStruct march[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
54 55
  { "National Tree Planting Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "St Patrick's Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
56 57 58 59 60
  { NULL }
};

static TreeStruct april[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
61 62 63 64
  { "April Fools' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
  { "Army Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Earth Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
  { "Administrative Professionals' Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
65 66 67 68 69
  { NULL }
};

static TreeStruct may[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
70 71 72 73 74
  { "Nurses' Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "National Day of Prayer", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Mothers' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
  { "Armed Forces Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Memorial Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
75 76 77 78 79
  { NULL }
};

static TreeStruct june[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
80 81 82
  { "June Fathers' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
  { "Juneteenth (Liberation of Slaves)", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Flag Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
83 84 85 86 87
  { NULL }
};

static TreeStruct july[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
88 89
  { "Parents' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
  { "Independence Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
90 91 92 93 94
  { NULL }
};

static TreeStruct august[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
95 96 97
  { "Air Force Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Coast Guard Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Friendship Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
98 99 100 101 102
  { NULL }
};

static TreeStruct september[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
103 104 105
  { "Grandparents' Day", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
  { "Citizenship Day or Constitution Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Labor Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
106 107 108 109 110
  { NULL }
};

static TreeStruct october[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
111 112 113 114 115 116 117
  { "National Children's Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Bosses' Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Sweetest Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Mother-in-Law's Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Navy Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Columbus Day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
  { "Halloween", FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
118 119 120 121 122
  { NULL }
};

static TreeStruct november[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
123 124 125
  { "Marine Corps Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Veterans' Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
  { "Thanksgiving", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
126 127 128 129 130
  { NULL }
};

static TreeStruct december[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
131 132 133
  { "Pearl Harbor Remembrance Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  { "Christmas", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
  { "Kwanzaa", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
134 135 136 137 138 139
  { NULL }
};


static TreeStruct toplevel[] =
{
Jonathan Blandford's avatar
Jonathan Blandford committed
140 141 142 143 144 145 146 147 148 149 150 151
  {"January", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, january},
  {"February", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, february},
  {"March", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, march},
  {"April", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, april},
  {"May", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, may},
  {"June", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, june},
  {"July", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, july},
  {"August", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, august},
  {"September", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, september},
  {"October", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, october},
  {"November", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, november},
  {"December", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, december},
152 153 154 155 156 157 158
  {NULL}
};


enum
{
  HOLIDAY_COLUMN = 0,
159
  ALEX_COLUMN,
160
  HAVOC_COLUMN,
161
  TIM_COLUMN,
162
  OWEN_COLUMN,
Jonathan Blandford's avatar
Jonathan Blandford committed
163
  DAVE_COLUMN,
164
  VISIBLE_COLUMN,
165
  WORLD_COLUMN,
166 167 168 169 170 171 172 173 174 175
  NUM_COLUMNS
};

static GtkTreeModel *
make_model (void)
{
  GtkTreeStore *model;
  TreeStruct *month = toplevel;
  GtkTreeIter iter;

176 177 178 179 180 181 182 183 184
  model = gtk_tree_store_new (NUM_COLUMNS,
			      G_TYPE_STRING,
			      G_TYPE_BOOLEAN,
			      G_TYPE_BOOLEAN,
			      G_TYPE_BOOLEAN,
			      G_TYPE_BOOLEAN,
			      G_TYPE_BOOLEAN,
			      G_TYPE_BOOLEAN,
			      G_TYPE_BOOLEAN);
185 186 187 188 189 190 191 192

  while (month->label)
    {
      TreeStruct *holiday = month->children;

      gtk_tree_store_append (model, &iter, NULL);
      gtk_tree_store_set (model, &iter,
			  HOLIDAY_COLUMN, month->label,
193
			  ALEX_COLUMN, FALSE,
194
			  HAVOC_COLUMN, FALSE,
195
			  TIM_COLUMN, FALSE,
196
			  OWEN_COLUMN, FALSE,
Jonathan Blandford's avatar
Jonathan Blandford committed
197
			  DAVE_COLUMN, FALSE,
198
			  VISIBLE_COLUMN, FALSE,
199
			  WORLD_COLUMN, FALSE,
200 201 202 203 204 205 206 207
			  -1);
      while (holiday->label)
	{
	  GtkTreeIter child_iter;

	  gtk_tree_store_append (model, &child_iter, &iter);
	  gtk_tree_store_set (model, &child_iter,
			      HOLIDAY_COLUMN, holiday->label,
208
			      ALEX_COLUMN, holiday->alex,
209
			      HAVOC_COLUMN, holiday->havoc,
210
			      TIM_COLUMN, holiday->tim,
211
			      OWEN_COLUMN, holiday->owen,
Jonathan Blandford's avatar
Jonathan Blandford committed
212
			      DAVE_COLUMN, holiday->dave,
213
			      VISIBLE_COLUMN, TRUE,
214
			      WORLD_COLUMN, holiday->world_holiday,
215
			      -1);
216

217 218 219 220 221 222 223 224
	  holiday ++;
	}
      month ++;
    }

  return GTK_TREE_MODEL (model);
}

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
static void
alex_toggled (GtkCellRendererToggle *cell,
	      gchar                 *path_str,
	      gpointer               data)
{
  GtkTreeModel *model = (GtkTreeModel *) data;
  GtkTreeIter iter;
  GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
  gboolean alex;

  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, ALEX_COLUMN, &alex, -1);

  alex = !alex;
  gtk_tree_store_set (GTK_TREE_STORE (model), &iter, ALEX_COLUMN, alex, -1);

  gtk_tree_path_free (path);
}

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
static void
havoc_toggled (GtkCellRendererToggle *cell,
	       gchar                 *path_str,
	       gpointer               data)
{
  GtkTreeModel *model = (GtkTreeModel *) data;
  GtkTreeIter iter;
  GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
  gboolean havoc;

  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, HAVOC_COLUMN, &havoc, -1);

  havoc = !havoc;
  gtk_tree_store_set (GTK_TREE_STORE (model), &iter, HAVOC_COLUMN, havoc, -1);

  gtk_tree_path_free (path);
}
262

263 264
static void
owen_toggled (GtkCellRendererToggle *cell,
265 266
	      gchar                 *path_str,
	      gpointer               data)
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
{
  GtkTreeModel *model = (GtkTreeModel *) data;
  GtkTreeIter iter;
  GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
  gboolean owen;

  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, OWEN_COLUMN, &owen, -1);

  owen = !owen;
  gtk_tree_store_set (GTK_TREE_STORE (model), &iter, OWEN_COLUMN, owen, -1);

  gtk_tree_path_free (path);
}

282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
static void
tim_toggled (GtkCellRendererToggle *cell,
	     gchar                 *path_str,
	     gpointer               data)
{
  GtkTreeModel *model = (GtkTreeModel *) data;
  GtkTreeIter iter;
  GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
  gboolean tim;

  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, TIM_COLUMN, &tim, -1);

  tim = !tim;
  gtk_tree_store_set (GTK_TREE_STORE (model), &iter, TIM_COLUMN, tim, -1);

  gtk_tree_path_free (path);
}

Jonathan Blandford's avatar
Jonathan Blandford committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
static void
dave_toggled (GtkCellRendererToggle *cell,
	      gchar                 *path_str,
	      gpointer               data)
{
  GtkTreeModel *model = (GtkTreeModel *) data;
  GtkTreeIter iter;
  GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
  gboolean dave;

  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, DAVE_COLUMN, &dave, -1);

  dave = !dave;
  gtk_tree_store_set (GTK_TREE_STORE (model), &iter, DAVE_COLUMN, dave, -1);

  gtk_tree_path_free (path);
}

320 321 322 323 324 325 326 327 328 329 330
static void
set_indicator_size (GtkTreeViewColumn *column,
		    GtkCellRenderer *cell,
		    GtkTreeModel *model,
		    GtkTreeIter *iter,
		    gpointer data)
{
  gint size;
  GtkTreePath *path;

  path = gtk_tree_model_get_path (model, iter);
331
  size = gtk_tree_path_get_indices (path)[0]  * 2 + 10;
332 333 334 335 336
  gtk_tree_path_free (path);

  g_object_set (cell, "indicator_size", size, NULL);
}

337 338 339 340 341 342 343 344 345
int
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *vbox;
  GtkWidget *scrolled_window;
  GtkWidget *tree_view;
  GtkTreeModel *model;
  GtkCellRenderer *renderer;
346 347
  gint col_offset;
  GtkTreeViewColumn *column;
348 349 350 351

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
Jonathan Blandford's avatar
Jonathan Blandford committed
352
  gtk_window_set_title (GTK_WINDOW (window), "Card planning sheet");
Manish Singh's avatar
Manish Singh committed
353
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);
354
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
355 356 357 358 359 360 361 362 363 364
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Jonathan's Holiday Card Planning Sheet"), FALSE, FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);

  model = make_model ();
365
  tree_view = gtk_tree_view_new_with_model (model);
366
  gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
367
			       GTK_SELECTION_MULTIPLE);
368
  renderer = gtk_cell_renderer_text_new ();
369 370 371 372
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
							    -1, "Holiday",
							    renderer,
							    "text", HOLIDAY_COLUMN, NULL);
373 374
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
375 376 377

  /* Alex Column */
  renderer = gtk_cell_renderer_toggle_new ();
Manish Singh's avatar
Manish Singh committed
378
  g_signal_connect (renderer, "toggled", G_CALLBACK (alex_toggled), model);
379

380
  g_object_set (renderer, "xalign", 0.0, NULL);
381 382 383 384 385
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
							    -1, "Alex",
							    renderer,
							    "active", ALEX_COLUMN,
							    "visible", VISIBLE_COLUMN,
386
							    "activatable", WORLD_COLUMN,
387 388 389
							    NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
390
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
391
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
392 393

  /* Havoc Column */
394
  renderer = gtk_cell_renderer_toggle_new ();
Manish Singh's avatar
Manish Singh committed
395
  g_signal_connect (renderer, "toggled", G_CALLBACK (havoc_toggled), model);
396

397
  g_object_set (renderer, "xalign", 0.0, NULL);
398 399 400 401 402 403 404 405
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
							    -1, "Havoc",
							    renderer,
							    "active", HAVOC_COLUMN,
							    "visible", VISIBLE_COLUMN,
							    NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
406
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
407
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
408 409 410

  /* Tim Column */
  renderer = gtk_cell_renderer_toggle_new ();
Manish Singh's avatar
Manish Singh committed
411
  g_signal_connect (renderer, "toggled", G_CALLBACK (tim_toggled), model);
412

413
  g_object_set (renderer, "xalign", 0.0, NULL);
414 415
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Tim",
416
					       renderer,
417
					       "active", TIM_COLUMN,
418
					       "visible", VISIBLE_COLUMN,
419
					       "activatable", WORLD_COLUMN,
420
					       NULL);
421 422
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
423
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
424
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
425 426

  /* Owen Column */
427
  renderer = gtk_cell_renderer_toggle_new ();
Manish Singh's avatar
Manish Singh committed
428
  g_signal_connect (renderer, "toggled", G_CALLBACK (owen_toggled), model);
429
  g_object_set (renderer, "xalign", 0.0, NULL);
430
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
431 432 433 434 435
					       -1, "Owen",
					       renderer,
					       "active", OWEN_COLUMN,
					       "visible", VISIBLE_COLUMN,
					       NULL);
436 437
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
438
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
439
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
440

Jonathan Blandford's avatar
Jonathan Blandford committed
441 442
  /* Owen Column */
  renderer = gtk_cell_renderer_toggle_new ();
Manish Singh's avatar
Manish Singh committed
443
  g_signal_connect (renderer, "toggled", G_CALLBACK (dave_toggled), model);
444
  g_object_set (renderer, "xalign", 0.0, NULL);
Jonathan Blandford's avatar
Jonathan Blandford committed
445 446 447 448 449 450 451
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Dave",
					       renderer,
					       "active", DAVE_COLUMN,
					       "visible", VISIBLE_COLUMN,
					       NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
452
  gtk_tree_view_column_set_cell_data_func (column, renderer, set_indicator_size, NULL, NULL);
Jonathan Blandford's avatar
Jonathan Blandford committed
453
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
454
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
455
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
Jonathan Blandford's avatar
Jonathan Blandford committed
456 457 458

  gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);

Manish Singh's avatar
Manish Singh committed
459 460 461
  g_signal_connect (tree_view, "realize",
		    G_CALLBACK (gtk_tree_view_expand_all),
		    NULL);
Jonathan Blandford's avatar
Jonathan Blandford committed
462 463 464 465 466 467
  gtk_window_set_default_size (GTK_WINDOW (window),
			       650, 400);
  gtk_widget_show_all (window);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Model");
Manish Singh's avatar
Manish Singh committed
468
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);
469
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
Jonathan Blandford's avatar
Jonathan Blandford committed
470 471 472 473 474 475 476 477 478 479 480
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("The model revealed"), FALSE, FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);


  tree_view = gtk_tree_view_new_with_model (model);
Manish Singh's avatar
Manish Singh committed
481
  g_object_unref (model);
Jonathan Blandford's avatar
Jonathan Blandford committed
482 483 484

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Holiday Column",
485
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
486 487 488 489
					       "text", 0, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Alex Column",
490
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
491 492 493 494
					       "text", 1, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Havoc Column",
495
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
496 497 498 499
					       "text", 2, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Tim Column",
500
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
501 502 503 504
					       "text", 3, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Owen Column",
505
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
506 507 508 509
					       "text", 4, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Dave Column",
510
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
511 512 513 514
					       "text", 5, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Visible Column",
515
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
516 517 518 519
					       "text", 6, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "World Holiday",
520
					       gtk_cell_renderer_text_new (),
Jonathan Blandford's avatar
Jonathan Blandford committed
521 522
					       "text", 7, NULL);

Manish Singh's avatar
Manish Singh committed
523 524 525
  g_signal_connect (tree_view, "realize",
		    G_CALLBACK (gtk_tree_view_expand_all),
		    NULL);
Jonathan Blandford's avatar
Jonathan Blandford committed
526
			   
527 528
  gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);

Jonathan Blandford's avatar
Jonathan Blandford committed
529 530 531 532

  gtk_window_set_default_size (GTK_WINDOW (window),
			       650, 400);

533
  gtk_widget_show_all (window);
534 535 536 537 538
  gtk_main ();

  return 0;
}