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.",
135 static TreeEntry add_entries[] =
141 "This is what it's all about",
142 "so he went ahead and added the 'gtk-about' icon to his story, thinking 'mint cream' would be the "
143 "right color for something like that",
152 "Now zooming into something",
153 "while fishing for pigs in the sky, maybe he would have caught something faster if only he had zoomed in",
162 "Now zooming out of something else",
163 "the daydream had a much prettier picture over all once he had zoomed out for the wide angle, "
173 static TreeEntry main_entries[] =
179 "We are currently informing you",
180 "once upon a time in a land far far away there was a guy named buba",
186 "gtk-dialog-warning",
189 "We would like to warn you that your laptop might explode after we're done",
190 "so he decided that he must be stark raving mad",
199 "Once we're done here, dont worry... an error will surely occur.",
200 "and went to a see a yellow physiotherapist who's name was jill",
208 "Currently scanning your directories.",
209 "jill didnt know what to make of the barking pigs either so she fed him sleeping pills",
218 "Time to delete the sucker",
219 "and he decided to just delete the whole conversation since it didnt make sense to him",
228 "Now adding stuff... please be patient",
229 "but on second thought, maybe he had something to add so that things could make a little less sense.",
238 "For the hell of it, lets add the content to the treeview over and over again !",
239 "buba likes telling his story, so maybe he's going to tell it 20 times more.",
249 populate_model (GtkTreeStore *model,
256 for (i = 0; entries[i].info != NULL; i++)
258 gtk_tree_store_append (model, &iter, parent);
259 gtk_tree_store_set (model, &iter,
260 ICON_COLUMN, entries[i].icon,
261 INFO_COLUMN, entries[i].info,
262 DESCRIPTION_COLUMN, entries[i].description,
263 FINE_PRINT_COLUMN, entries[i].fine_print,
264 FINE_PRINT_COLOR_COLUMN, entries[i].fine_print_color,
265 PROGRESS_COLUMN, entries[i].progress,
268 if (entries[i].entries)
269 populate_model (model, &iter, entries[i].entries);
273 static GtkTreeModel *
279 model = gtk_tree_store_new (NUM_COLUMNS,
287 for (i = 0; i < 20; i++)
288 populate_model (model, NULL, main_entries);
290 return GTK_TREE_MODEL (model);
294 main (gint argc, gchar **argv)
297 GtkWidget *scrolled_window;
298 GtkWidget *tree_view;
299 GtkTreeModel *tree_model;
300 GtkCellRenderer *renderer;
301 GtkTreeViewColumn *column;
304 gtk_init (&argc, &argv);
306 if (g_getenv ("RTL"))
307 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
309 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
310 gtk_window_set_title (GTK_WINDOW (window), "Vertical cells in GtkTreeViewColumn example");
311 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
313 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
314 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
315 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
316 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
317 gtk_container_add (GTK_CONTAINER (window), scrolled_window);
319 tree_model = create_model ();
320 tree_view = gtk_tree_view_new_with_model (tree_model);
321 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
324 column = gtk_tree_view_column_new ();
326 renderer = gtk_cell_renderer_pixbuf_new ();
327 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DIALOG, NULL);
328 gtk_tree_view_column_pack_start (column, renderer, TRUE);
329 gtk_tree_view_column_set_attributes (column, renderer,
330 "stock-id", ICON_COLUMN, NULL);
332 renderer = gtk_cell_renderer_text_new ();
333 g_object_set (renderer, "scale", 1.2F, "weight", PANGO_WEIGHT_BOLD, NULL);
334 gtk_tree_view_column_pack_start (column, renderer, TRUE);
335 gtk_tree_view_column_set_attributes (column, renderer,
338 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
340 /* Second (vertical) column */
341 column = gtk_tree_view_column_new ();
342 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (column));
343 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);
345 renderer = gtk_cell_renderer_text_new ();
346 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, "editable", TRUE, NULL);
347 gtk_tree_view_column_pack_start (column, renderer, TRUE);
348 gtk_tree_view_column_set_attributes (column, renderer,
349 "text", DESCRIPTION_COLUMN,
352 renderer = gtk_cell_renderer_progress_new ();
353 gtk_tree_view_column_pack_start (column, renderer, TRUE);
354 gtk_tree_view_column_set_attributes (column, renderer,
355 "value", PROGRESS_COLUMN,
358 renderer = gtk_cell_renderer_text_new ();
359 g_object_set (renderer, "scale", 0.6F, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
360 gtk_tree_view_column_pack_start (column, renderer, TRUE);
361 gtk_tree_view_column_set_attributes (column, renderer,
362 "text", FINE_PRINT_COLUMN,
363 "foreground", FINE_PRINT_COLOR_COLUMN,
366 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
368 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
370 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
372 gtk_window_set_default_size (GTK_WINDOW (window),
375 gtk_widget_show_all (window);