]> Pileus Git - ~andy/gtk/blob - tests/testverticalcells.c
Merge branch 'master' into broadway2
[~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     { 0, },
133   };
134
135 static TreeEntry add_entries[] =
136   {
137     { 
138       "gtk-about", 
139       "its about\n"
140       "to start", 
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",
144       "dark violet",
145       1,
146       NULL
147     },
148     { 
149       "gtk-zoom-in", 
150       "Watch it\n"
151       "Zoom !", 
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",
154       "orchid",
155       6,
156       NULL
157     },
158     { 
159       "gtk-zoom-out", 
160       "Zoom Zoom\n"
161       "Zoom !", 
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, "
164       "jill agreed",
165       "dark magenta",
166       46,
167       other_entries
168     },
169     { 0, },
170   };
171
172
173 static TreeEntry main_entries[] =
174   {
175     { 
176       "gtk-info", 
177       "This is all\n"
178       "the info", 
179       "We are currently informing you",
180       "once upon a time in a land far far away there was a guy named buba",
181       "red",
182       64,
183       info_entries
184     },
185     { 
186       "gtk-dialog-warning", 
187       "This is a\n"
188       "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",
191       "orange",
192       43,
193       NULL
194     },
195     { 
196       "gtk-dialog-error", 
197       "An error will\n"
198       "occur", 
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",
201       "yellow",
202       98,
203       NULL
204     },
205     { 
206       "gtk-directory", 
207       "The directory", 
208       "Currently scanning your directories.",
209       "jill didnt know what to make of the barking pigs either so she fed him sleeping pills",
210       "brown",
211       20,
212       directory_entries
213     },
214     { 
215       "gtk-delete", 
216       "Now deleting\n"
217       "the whole thing",
218       "Time to delete the sucker",
219       "and he decided to just delete the whole conversation since it didnt make sense to him",
220       "dark orange",
221       26,
222       NULL
223     },
224     { 
225       "gtk-add", 
226       "Anything\n"
227       "to add ?",
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.",
230       "maroon",
231       72,
232       add_entries
233     },
234     { 
235       "gtk-redo", 
236       "Time to\n"
237       "do it again",
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.",
240       "deep pink",
241       100,
242       NULL
243     },
244     { 0, },
245   };
246
247
248 static void
249 populate_model (GtkTreeStore *model,
250                 GtkTreeIter  *parent,
251                 TreeEntry    *entries)
252 {
253   GtkTreeIter iter;
254   gint        i;
255
256   for (i = 0; entries[i].info != NULL; i++)
257     {
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,
266                           -1);
267
268       if (entries[i].entries)
269         populate_model (model, &iter, entries[i].entries);
270     }
271 }
272
273 static GtkTreeModel *
274 create_model (void)
275 {
276   GtkTreeStore *model;
277   gint          i;
278
279   model = gtk_tree_store_new (NUM_COLUMNS,
280                               G_TYPE_STRING,
281                               G_TYPE_STRING,
282                               G_TYPE_STRING,
283                               G_TYPE_STRING,
284                               G_TYPE_STRING,
285                               G_TYPE_INT);
286
287   for (i = 0; i < 20; i++)
288     populate_model (model, NULL, main_entries);
289
290   return GTK_TREE_MODEL (model);
291 }
292
293 gint
294 main (gint argc, gchar **argv)
295 {
296   GtkWidget *window;
297   GtkWidget *scrolled_window;
298   GtkWidget *tree_view;
299   GtkTreeModel *tree_model;
300   GtkCellRenderer *renderer;
301   GtkTreeViewColumn *column;
302   GtkCellArea *area;
303   
304   gtk_init (&argc, &argv);
305
306   if (g_getenv ("RTL"))
307     gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
308
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);
312
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);
318
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);
322
323   /* First column */
324   column = gtk_tree_view_column_new ();
325
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);
331
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,
336                                        "text", INFO_COLUMN,
337                                        NULL);
338   gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
339
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);
344
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,
350                                        NULL);
351
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,
356                                        NULL);
357
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,
364                                        NULL);
365
366   gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
367
368   gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
369
370   gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
371   
372   gtk_window_set_default_size (GTK_WINDOW (window),
373                                800, 400);
374
375   gtk_widget_show_all (window);
376   gtk_main ();
377
378   return 0;
379 }