1/* testverticalcells.c
2 *
3 * Copyright (C) 2010 Openismus GmbH
4 *
5 * Authors:
6 * Tristan Van Berkom <tristanvb@openismus.com>
7 *
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.
12 *
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.
17 *
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/>.
20 */
21
22#include "config.h"
23#include <gtk/gtk.h>
24
25typedef struct _TreeEntry TreeEntry;
26
27struct _TreeEntry {
28 const char *icon;
29 const char *info;
30 const char *description;
31 const char *fine_print;
32 const char *fine_print_color;
33 int progress;
34 TreeEntry *entries;
35};
36
37enum {
38 ICON_COLUMN,
39 INFO_COLUMN,
40 DESCRIPTION_COLUMN,
41 FINE_PRINT_COLUMN,
42 FINE_PRINT_COLOR_COLUMN,
43 PROGRESS_COLUMN,
44 NUM_COLUMNS
45};
46
47
48static TreeEntry info_entries[] =
49 {
50 {
51 "system-run",
52 "Will you\n"
53 "run this ?",
54 "Currently executing that thing... you might want to abort",
55 "and every day he went fishing for pigs in the sky",
56 "green",
57 83,
58 NULL
59 },
60 {
61 "dialog-password",
62 "This is the\n"
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",
66 "purple",
67 4,
68 NULL
69 },
70 { 0, },
71 };
72
73static TreeEntry directory_entries[] =
74 {
75 {
76 "document-open",
77 "We can edit\n"
78 "things in here",
79 "Time to edit your directory, almost finished now",
80 "she thought the best remedy for daydreams was going to be sleep",
81 "dark sea green",
82 99,
83 NULL
84 },
85 {
86 "text-x-generic",
87 "You have a\n"
88 "file here",
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",
91 "green yellow",
92 33,
93 NULL
94 },
95 {
96 "dialog-question",
97 "Any questions ?",
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",
100 "lavender",
101 73,
102 NULL
103 },
104 { 0, },
105 };
106
107static TreeEntry other_entries[] =
108 {
109 {
110 "zoom-fit-best",
111 "That's the\n"
112 "perfect fit",
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",
116 "dark salmon",
117 59,
118 NULL
119 },
120 {
121 "format-text-underline",
122 "Under the\n"
123 "line",
124 "Now underlining that this demo would look a lot niftier with some real content",
125 "it was indeed strange to catch a red salmon while fishing for pigs in the deep sky blue.",
126 "deep sky blue",
127 99,
128 NULL
129 },
130 { 0, },
131 };
132
133static TreeEntry add_entries[] =
134 {
135 {
136 "help-about",
137 "its about\n"
138 "to start",
139 "This is what it's all about",
140 "so he went ahead and added the 'help-about' icon to his story, thinking 'mint cream' would be the "
141 "right color for something like that",
142 "dark violet",
143 1,
144 NULL
145 },
146 {
147 "zoom-in",
148 "Watch it\n"
149 "Zoom !",
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",
152 "orchid",
153 6,
154 NULL
155 },
156 {
157 "zoom-out",
158 "Zoom Zoom\n"
159 "Zoom !",
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, "
162 "jill agreed",
163 "dark magenta",
164 46,
165 other_entries
166 },
167 { 0, },
168 };
169
170
171static TreeEntry main_entries[] =
172 {
173 {
174 "dialog-information",
175 "This is all\n"
176 "the info",
177 "We are currently informing you",
178 "once upon a time in a land far far away there was a guy named buba",
179 "red",
180 64,
181 info_entries
182 },
183 {
184 "dialog-warning",
185 "This is a\n"
186 "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",
189 "orange",
190 43,
191 NULL
192 },
193 {
194 "dialog-error",
195 "An error will\n"
196 "occur",
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",
199 "yellow",
200 98,
201 NULL
202 },
203 {
204 "folder",
205 "The directory",
206 "Currently scanning your directories.",
207 "jill didn't know what to make of the barking pigs either so she fed him sleeping pills",
208 "brown",
209 20,
210 directory_entries
211 },
212 {
213 "edit-delete",
214 "Now deleting\n"
215 "the whole thing",
216 "Time to delete the sucker",
217 "and he decided to just delete the whole conversation since it didn't make sense to him",
218 "dark orange",
219 26,
220 NULL
221 },
222 {
223 "list-add",
224 "Anything\n"
225 "to add ?",
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.",
228 "maroon",
229 72,
230 add_entries
231 },
232 {
233 "edit-redo",
234 "Time to\n"
235 "do it again",
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.",
238 "deep pink",
239 100,
240 NULL
241 },
242 { 0, },
243 };
244
245
246static void
247populate_model (GtkTreeStore *model,
248 GtkTreeIter *parent,
249 TreeEntry *entries)
250{
251 GtkTreeIter iter;
252 int i;
253
254 for (i = 0; entries[i].info != NULL; i++)
255 {
256 gtk_tree_store_append (tree_store: model, iter: &iter, parent);
257 gtk_tree_store_set (tree_store: model, iter: &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,
264 -1);
265
266 if (entries[i].entries)
267 populate_model (model, parent: &iter, entries: entries[i].entries);
268 }
269}
270
271static GtkTreeModel *
272create_model (void)
273{
274 GtkTreeStore *model;
275 int i;
276
277 model = gtk_tree_store_new (n_columns: NUM_COLUMNS,
278 G_TYPE_STRING,
279 G_TYPE_STRING,
280 G_TYPE_STRING,
281 G_TYPE_STRING,
282 G_TYPE_STRING,
283 G_TYPE_INT);
284
285 for (i = 0; i < 20; i++)
286 populate_model (model, NULL, entries: main_entries);
287
288 return GTK_TREE_MODEL (model);
289}
290
291static void
292quit_cb (GtkWidget *widget,
293 gpointer data)
294{
295 gboolean *done = data;
296
297 *done = TRUE;
298
299 g_main_context_wakeup (NULL);
300}
301
302int
303main (int argc, char **argv)
304{
305 GtkWidget *window;
306 GtkWidget *scrolled_window;
307 GtkWidget *tree_view;
308 GtkTreeModel *tree_model;
309 GtkCellRenderer *renderer;
310 GtkTreeViewColumn *column;
311 GtkCellArea *area;
312 gboolean done = FALSE;
313
314 gtk_init ();
315
316 if (g_getenv (variable: "RTL"))
317 gtk_widget_set_default_direction (dir: GTK_TEXT_DIR_RTL);
318
319 window = gtk_window_new ();
320 gtk_window_set_title (GTK_WINDOW (window), title: "Vertical cells in GtkTreeViewColumn example");
321 g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
322
323 scrolled_window = gtk_scrolled_window_new ();
324 gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (scrolled_window), TRUE);
325 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
326 hscrollbar_policy: GTK_POLICY_AUTOMATIC, vscrollbar_policy: GTK_POLICY_AUTOMATIC);
327 gtk_window_set_child (GTK_WINDOW (window), child: scrolled_window);
328
329 tree_model = create_model ();
330 tree_view = gtk_tree_view_new_with_model (model: tree_model);
331 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
332
333 /* First column */
334 column = gtk_tree_view_column_new ();
335
336 renderer = gtk_cell_renderer_pixbuf_new ();
337 g_object_set (object: renderer, first_property_name: "icon-size", GTK_ICON_SIZE_LARGE, NULL);
338 gtk_tree_view_column_pack_start (tree_column: column, cell: renderer, TRUE);
339 gtk_tree_view_column_set_attributes (tree_column: column, cell_renderer: renderer,
340 "icon-name", ICON_COLUMN, NULL);
341
342 renderer = gtk_cell_renderer_text_new ();
343 g_object_set (object: renderer, first_property_name: "scale", 1.2F, "weight", PANGO_WEIGHT_BOLD, NULL);
344 gtk_tree_view_column_pack_start (tree_column: column, cell: renderer, TRUE);
345 gtk_tree_view_column_set_attributes (tree_column: column, cell_renderer: renderer,
346 "text", INFO_COLUMN,
347 NULL);
348 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
349
350 /* Second (vertical) column */
351 column = gtk_tree_view_column_new ();
352 area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (column));
353 gtk_orientable_set_orientation (GTK_ORIENTABLE (area), orientation: GTK_ORIENTATION_VERTICAL);
354
355 renderer = gtk_cell_renderer_text_new ();
356 g_object_set (object: renderer, first_property_name: "ellipsize", PANGO_ELLIPSIZE_END, "editable", TRUE, NULL);
357 gtk_tree_view_column_pack_start (tree_column: column, cell: renderer, TRUE);
358 gtk_tree_view_column_set_attributes (tree_column: column, cell_renderer: renderer,
359 "text", DESCRIPTION_COLUMN,
360 NULL);
361
362 renderer = gtk_cell_renderer_progress_new ();
363 gtk_tree_view_column_pack_start (tree_column: column, cell: renderer, TRUE);
364 gtk_tree_view_column_set_attributes (tree_column: column, cell_renderer: renderer,
365 "value", PROGRESS_COLUMN,
366 NULL);
367
368 renderer = gtk_cell_renderer_text_new ();
369 g_object_set (object: renderer, first_property_name: "scale", 0.6F, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
370 gtk_tree_view_column_pack_start (tree_column: column, cell: renderer, TRUE);
371 gtk_tree_view_column_set_attributes (tree_column: column, cell_renderer: renderer,
372 "text", FINE_PRINT_COLUMN,
373 "foreground", FINE_PRINT_COLOR_COLUMN,
374 NULL);
375
376 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
377
378 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
379
380 gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), child: tree_view);
381
382 gtk_window_set_default_size (GTK_WINDOW (window),
383 width: 800, height: 400);
384
385 gtk_widget_show (widget: window);
386 while (!done)
387 g_main_context_iteration (NULL, TRUE);
388
389 return 0;
390}
391

source code of gtk/tests/testverticalcells.c