]> Pileus Git - ~andy/gtk/blob - tests/testverticalcells.c
Added g_getenv("RTL") to test rtl layouting.
[~andy/gtk] / tests / testverticalcells.c
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, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include "config.h"
25 #include <gtk/gtk.h>
26
27 typedef struct _TreeEntry TreeEntry;
28
29 struct _TreeEntry {
30   const gchar *icon;
31   const gchar *info;
32   const gchar *description;
33   const gchar *fine_print;
34   const gchar *fine_print_color;
35   gint progress;
36   TreeEntry *entries;
37 };
38
39 enum {
40   ICON_COLUMN,
41   INFO_COLUMN,
42   DESCRIPTION_COLUMN,
43   FINE_PRINT_COLUMN,
44   FINE_PRINT_COLOR_COLUMN,
45   PROGRESS_COLUMN,
46   NUM_COLUMNS
47 };
48
49
50 static TreeEntry info_entries[] =
51   {
52     { 
53       "gtk-execute", 
54       "Will you\n"
55       "run this ?", 
56       "Currently executing that thing... you might want to abort",
57       "and every day he went fishing for pigs in the sky",
58       "green",
59       83,
60       NULL
61     },
62     { 
63       "gtk-dialog-authentication", 
64       "This is the\n"
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",
68       "purple",
69       4,
70       NULL
71     },
72     { 0, },
73   };
74
75 static TreeEntry directory_entries[] =
76   {
77     { 
78       "gtk-edit", 
79       "We can edit\n"
80       "things in here", 
81       "Time to edit your directory, almost finished now",
82       "she thought the best remedy for daydreams was going to be sleep",
83       "dark sea green",
84       99,
85       NULL
86     },
87     { 
88       "gtk-file", 
89       "You have a\n"
90       "file here", 
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",
93       "green yellow",
94       33,
95       NULL
96     },
97     { 
98       "gtk-dialog-question", 
99       "Any questions ?",
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",
102       "lavender",
103       73,
104       NULL
105     },
106     { 0, },
107   };
108
109 static TreeEntry other_entries[] =
110   {
111     { 
112       "gtk-zoom-fit", 
113       "Thats the\n"
114       "perfect fit", 
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",
118       "dark salmon",
119       59,
120       NULL
121     },
122     { 
123       "gtk-underline", 
124       "Under the\n"
125       "line", 
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.",
128       "deep sky blue",
129       99,
130       NULL
131     },
132   };
133
134 static TreeEntry add_entries[] =
135   {
136     { 
137       "gtk-about", 
138       "its about\n"
139       "to start", 
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",
143       "dark violet",
144       1,
145       NULL
146     },
147     { 
148       "gtk-zoom-in", 
149       "Watch it\n"
150       "Zoom !", 
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",
153       "orchid",
154       6,
155       NULL
156     },
157     { 
158       "gtk-zoom-out", 
159       "Zoom Zoom\n"
160       "Zoom !", 
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, "
163       "jill agreed",
164       "dark magenta",
165       46,
166       other_entries
167     },
168     { 0, },
169   };
170
171
172 static TreeEntry main_entries[] =
173   {
174     { 
175       "gtk-info", 
176       "This is all\n"
177       "the info", 
178       "We are currently informing you",
179       "once upon a time in a land far far away there was a guy named buba",
180       "red",
181       64,
182       info_entries
183     },
184     { 
185       "gtk-dialog-warning", 
186       "This is a\n"
187       "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",
190       "orange",
191       43,
192       NULL
193     },
194     { 
195       "gtk-dialog-error", 
196       "An error will\n"
197       "occur", 
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",
200       "yellow",
201       98,
202       NULL
203     },
204     { 
205       "gtk-directory", 
206       "The directory", 
207       "Currently scanning your directories.",
208       "jill didnt know what to make of the barking pigs either so she fed him sleeping pills",
209       "brown",
210       20,
211       directory_entries
212     },
213     { 
214       "gtk-delete", 
215       "Now deleting\n"
216       "the whole thing",
217       "Time to delete the sucker",
218       "and he decided to just delete the whole conversation since it didnt make sense to him",
219       "dark orange",
220       26,
221       NULL
222     },
223     { 
224       "gtk-add", 
225       "Anything\n"
226       "to add ?",
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.",
229       "maroon",
230       72,
231       add_entries
232     },
233     { 
234       "gtk-redo", 
235       "Time to\n"
236       "do it again",
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.",
239       "deep pink",
240       100,
241       NULL
242     },
243     { 0, },
244   };
245
246
247 static void
248 populate_model (GtkTreeStore *model,
249                 GtkTreeIter  *parent,
250                 TreeEntry    *entries)
251 {
252   GtkTreeIter iter;
253   gint        i;
254
255   for (i = 0; entries[i].info != NULL; i++)
256     {
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,
265                           -1);
266
267       if (entries[i].entries)
268         populate_model (model, &iter, entries[i].entries);
269     }
270 }
271
272 static GtkTreeModel *
273 create_model (void)
274 {
275   GtkTreeStore *model;
276   gint          i;
277
278   model = gtk_tree_store_new (NUM_COLUMNS,
279                               G_TYPE_STRING,
280                               G_TYPE_STRING,
281                               G_TYPE_STRING,
282                               G_TYPE_STRING,
283                               G_TYPE_STRING,
284                               G_TYPE_INT);
285
286   for (i = 0; i < 20; i++)
287     populate_model (model, NULL, main_entries);
288
289   return GTK_TREE_MODEL (model);
290 }
291
292 gint
293 main (gint argc, gchar **argv)
294 {
295   GtkWidget *window;
296   GtkWidget *scrolled_window;
297   GtkWidget *tree_view;
298   GtkTreeModel *tree_model;
299   GtkCellRenderer *renderer;
300   GtkTreeViewColumn *column;
301   GtkCellArea *area;
302   
303   gtk_init (&argc, &argv);
304
305   if (g_getenv ("RTL"))
306     gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
307
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);
311
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);
317
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);
321
322   /* First column */
323   column = gtk_tree_view_column_new ();
324
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);
330
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,
335                                        "text", INFO_COLUMN,
336                                        NULL);
337   gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
338
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);
343
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,
349                                        NULL);
350
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,
355                                        NULL);
356
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,
363                                        NULL);
364
365   gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
366
367   gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
368
369   gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
370   
371   gtk_window_set_default_size (GTK_WINDOW (window),
372                                800, 400);
373
374   gtk_widget_show_all (window);
375   gtk_main ();
376
377   return 0;
378 }