3 * Copyright (C) 2010 Openismus GmbH
6 * Tristan Van Berkom <tristanvb@openismus.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
27 typedef struct _TreeEntry TreeEntry;
32 const gchar *description;
33 const gchar *fine_print;
34 const gchar *fine_print_color;
44 FINE_PRINT_COLOR_COLUMN,
50 static TreeEntry info_entries[] =
56 "Currently executing that thing... you might want to abort",
57 "and every day he went fishing for pigs in the sky",
63 "gtk-dialog-authentication",
65 "realest of the real",
66 "We are about to authenticate the actual realness, this could take some time",
67 "one day he caught a giant ogre who barked and barked and barked",
75 static TreeEntry directory_entries[] =
81 "Time to edit your directory, almost finished now",
82 "she thought the best remedy for daydreams was going to be sleep",
91 "Who would of thought there would be a file in the directory ?",
92 "after taking loads of sleeping pills he could still hear the pigs barking",
98 "gtk-dialog-question",
100 "This file would like to ask you a question",
101 "so he decided that the fine print underneath the progress bar probably made no sense at all",
109 static TreeEntry other_entries[] =
115 "Now fitting foo into bar using frobnicator",
116 "using his nifty wide angle lense, he was able to catch a 'dark salmon', it was no flying pig "
117 "however it was definitely a keeper",
126 "Now underlining that this demo would look alot niftier with some real content",
127 "it was indeed strange to catch a red salmon while fishing for pigs in the deep sky blue.",
134 static TreeEntry add_entries[] =
140 "This is what it's all about",
141 "so he went ahead and added the 'gtk-about' icon to his story, thinking 'mint cream' would be the "
142 "right color for something like that",
151 "Now zooming into something",
152 "while fishing for pigs in the sky, maybe he would have caught something faster if only he had zoomed in",
161 "Now zooming out of something else",
162 "the daydream had a much prettier picture over all once he had zoomed out for the wide angle, "
172 static TreeEntry main_entries[] =
178 "We are currently informing you",
179 "once upon a time in a land far far away there was a guy named buba",
185 "gtk-dialog-warning",
188 "We would like to warn you that your laptop might explode after we're done",
189 "so he decided that he must be stark raving mad",
198 "Once we're done here, dont worry... an error will surely occur.",
199 "and went to a see a yellow physiotherapist who's name was jill",
207 "Currently scanning your directories.",
208 "jill didnt know what to make of the barking pigs either so she fed him sleeping pills",
217 "Time to delete the sucker",
218 "and he decided to just delete the whole conversation since it didnt make sense to him",
227 "Now adding stuff... please be patient",
228 "but on second thought, maybe he had something to add so that things could make a little less sense.",
237 "For the hell of it, lets add the content to the treeview over and over again !",
238 "buba likes telling his story, so maybe he's going to tell it 20 times more.",
248 populate_model (GtkTreeStore *model,
255 for (i = 0; entries[i].info != NULL; i++)
257 gtk_tree_store_append (model, &iter, parent);
258 gtk_tree_store_set (model, &iter,
259 ICON_COLUMN, entries[i].icon,
260 INFO_COLUMN, entries[i].info,
261 DESCRIPTION_COLUMN, entries[i].description,
262 FINE_PRINT_COLUMN, entries[i].fine_print,
263 FINE_PRINT_COLOR_COLUMN, entries[i].fine_print_color,
264 PROGRESS_COLUMN, entries[i].progress,
267 if (entries[i].entries)
268 populate_model (model, &iter, entries[i].entries);
272 static GtkTreeModel *
278 model = gtk_tree_store_new (NUM_COLUMNS,
286 for (i = 0; i < 20; i++)
287 populate_model (model, NULL, main_entries);
289 return GTK_TREE_MODEL (model);
293 main (gint argc, gchar **argv)
296 GtkWidget *scrolled_window;
297 GtkWidget *tree_view;
298 GtkTreeModel *tree_model;
299 GtkCellRenderer *renderer;
300 GtkTreeViewColumn *column;
303 gtk_init (&argc, &argv);
305 if (g_getenv ("RTL"))
306 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
308 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
309 gtk_window_set_title (GTK_WINDOW (window), "Vertical cells in GtkTreeViewColumn example");
310 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
312 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
313 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
314 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
315 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
316 gtk_container_add (GTK_CONTAINER (window), scrolled_window);
318 tree_model = create_model ();
319 tree_view = gtk_tree_view_new_with_model (tree_model);
320 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
323 column = gtk_tree_view_column_new ();
325 renderer = gtk_cell_renderer_pixbuf_new ();
326 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DIALOG, NULL);
327 gtk_tree_view_column_pack_start (column, renderer, TRUE);
328 gtk_tree_view_column_set_attributes (column, renderer,
329 "stock-id", ICON_COLUMN, NULL);
331 renderer = gtk_cell_renderer_text_new ();
332 g_object_set (renderer, "scale", 1.2F, "weight", PANGO_WEIGHT_BOLD, NULL);
333 gtk_tree_view_column_pack_start (column, renderer, TRUE);
334 gtk_tree_view_column_set_attributes (column, renderer,
337 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
339 /* Second (vertical) column */
340 column = gtk_tree_view_column_new ();
341 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (column));
342 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
344 renderer = gtk_cell_renderer_text_new ();
345 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
346 gtk_tree_view_column_pack_start (column, renderer, TRUE);
347 gtk_tree_view_column_set_attributes (column, renderer,
348 "text", DESCRIPTION_COLUMN,
351 renderer = gtk_cell_renderer_progress_new ();
352 gtk_tree_view_column_pack_start (column, renderer, TRUE);
353 gtk_tree_view_column_set_attributes (column, renderer,
354 "value", PROGRESS_COLUMN,
357 renderer = gtk_cell_renderer_text_new ();
358 g_object_set (renderer, "scale", 0.6F, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
359 gtk_tree_view_column_pack_start (column, renderer, TRUE);
360 gtk_tree_view_column_set_attributes (column, renderer,
361 "text", FINE_PRINT_COLUMN,
362 "foreground", FINE_PRINT_COLOR_COLUMN,
365 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
367 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
369 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
371 gtk_window_set_default_size (GTK_WINDOW (window),
374 gtk_widget_show_all (window);