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, see <http://www.gnu.org/licenses/>.
25 typedef struct _TreeEntry TreeEntry;
30 const gchar *description;
31 const gchar *fine_print;
32 const gchar *fine_print_color;
42 FINE_PRINT_COLOR_COLUMN,
48 static TreeEntry info_entries[] =
54 "Currently executing that thing... you might want to abort",
55 "and every day he went fishing for pigs in the sky",
61 "gtk-dialog-authentication",
63 "realest of the real",
64 "We are about to authenticate the actual realness, this could take some time",
65 "one day he caught a giant ogre who barked and barked and barked",
73 static TreeEntry directory_entries[] =
79 "Time to edit your directory, almost finished now",
80 "she thought the best remedy for daydreams was going to be sleep",
89 "Who would of thought there would be a file in the directory ?",
90 "after taking loads of sleeping pills he could still hear the pigs barking",
96 "gtk-dialog-question",
98 "This file would like to ask you a question",
99 "so he decided that the fine print underneath the progress bar probably made no sense at all",
107 static TreeEntry other_entries[] =
113 "Now fitting foo into bar using frobnicator",
114 "using his nifty wide angle lense, he was able to catch a 'dark salmon', it was no flying pig "
115 "however it was definitely a keeper",
124 "Now underlining that this demo would look alot niftier with some real content",
125 "it was indeed strange to catch a red salmon while fishing for pigs in the deep sky blue.",
133 static TreeEntry add_entries[] =
139 "This is what it's all about",
140 "so he went ahead and added the 'gtk-about' icon to his story, thinking 'mint cream' would be the "
141 "right color for something like that",
150 "Now zooming into something",
151 "while fishing for pigs in the sky, maybe he would have caught something faster if only he had zoomed in",
160 "Now zooming out of something else",
161 "the daydream had a much prettier picture over all once he had zoomed out for the wide angle, "
171 static TreeEntry main_entries[] =
177 "We are currently informing you",
178 "once upon a time in a land far far away there was a guy named buba",
184 "gtk-dialog-warning",
187 "We would like to warn you that your laptop might explode after we're done",
188 "so he decided that he must be stark raving mad",
197 "Once we're done here, dont worry... an error will surely occur.",
198 "and went to a see a yellow physiotherapist who's name was jill",
206 "Currently scanning your directories.",
207 "jill didnt know what to make of the barking pigs either so she fed him sleeping pills",
216 "Time to delete the sucker",
217 "and he decided to just delete the whole conversation since it didnt make sense to him",
226 "Now adding stuff... please be patient",
227 "but on second thought, maybe he had something to add so that things could make a little less sense.",
236 "For the hell of it, lets add the content to the treeview over and over again !",
237 "buba likes telling his story, so maybe he's going to tell it 20 times more.",
247 populate_model (GtkTreeStore *model,
254 for (i = 0; entries[i].info != NULL; i++)
256 gtk_tree_store_append (model, &iter, parent);
257 gtk_tree_store_set (model, &iter,
258 ICON_COLUMN, entries[i].icon,
259 INFO_COLUMN, entries[i].info,
260 DESCRIPTION_COLUMN, entries[i].description,
261 FINE_PRINT_COLUMN, entries[i].fine_print,
262 FINE_PRINT_COLOR_COLUMN, entries[i].fine_print_color,
263 PROGRESS_COLUMN, entries[i].progress,
266 if (entries[i].entries)
267 populate_model (model, &iter, entries[i].entries);
271 static GtkTreeModel *
277 model = gtk_tree_store_new (NUM_COLUMNS,
285 for (i = 0; i < 20; i++)
286 populate_model (model, NULL, main_entries);
288 return GTK_TREE_MODEL (model);
292 main (gint argc, gchar **argv)
295 GtkWidget *scrolled_window;
296 GtkWidget *tree_view;
297 GtkTreeModel *tree_model;
298 GtkCellRenderer *renderer;
299 GtkTreeViewColumn *column;
302 gtk_init (&argc, &argv);
304 if (g_getenv ("RTL"))
305 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
307 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
308 gtk_window_set_title (GTK_WINDOW (window), "Vertical cells in GtkTreeViewColumn example");
309 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
311 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
312 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
313 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
314 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
315 gtk_container_add (GTK_CONTAINER (window), scrolled_window);
317 tree_model = create_model ();
318 tree_view = gtk_tree_view_new_with_model (tree_model);
319 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
322 column = gtk_tree_view_column_new ();
324 renderer = gtk_cell_renderer_pixbuf_new ();
325 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DIALOG, NULL);
326 gtk_tree_view_column_pack_start (column, renderer, TRUE);
327 gtk_tree_view_column_set_attributes (column, renderer,
328 "stock-id", ICON_COLUMN, NULL);
330 renderer = gtk_cell_renderer_text_new ();
331 g_object_set (renderer, "scale", 1.2F, "weight", PANGO_WEIGHT_BOLD, NULL);
332 gtk_tree_view_column_pack_start (column, renderer, TRUE);
333 gtk_tree_view_column_set_attributes (column, renderer,
336 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
338 /* Second (vertical) column */
339 column = gtk_tree_view_column_new ();
340 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (column));
341 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
343 renderer = gtk_cell_renderer_text_new ();
344 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, "editable", TRUE, NULL);
345 gtk_tree_view_column_pack_start (column, renderer, TRUE);
346 gtk_tree_view_column_set_attributes (column, renderer,
347 "text", DESCRIPTION_COLUMN,
350 renderer = gtk_cell_renderer_progress_new ();
351 gtk_tree_view_column_pack_start (column, renderer, TRUE);
352 gtk_tree_view_column_set_attributes (column, renderer,
353 "value", PROGRESS_COLUMN,
356 renderer = gtk_cell_renderer_text_new ();
357 g_object_set (renderer, "scale", 0.6F, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
358 gtk_tree_view_column_pack_start (column, renderer, TRUE);
359 gtk_tree_view_column_set_attributes (column, renderer,
360 "text", FINE_PRINT_COLUMN,
361 "foreground", FINE_PRINT_COLOR_COLUMN,
364 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
366 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
368 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
370 gtk_window_set_default_size (GTK_WINDOW (window),
373 gtk_widget_show_all (window);