summaryrefslogtreecommitdiff
path: root/tests/testverticalcells.c
blob: 2f49022414fd3f745a540cd43870785ba963baad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/* testverticalcells.c
 *
 * Copyright (C) 2010 Openismus GmbH
 *
 * Authors:
 *      Tristan Van Berkom <tristanvb@openismus.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include <gtk/gtk.h>

typedef struct _TreeEntry TreeEntry;

struct _TreeEntry {
  const gchar *icon;
  const gchar *info;
  const gchar *description;
  const gchar *fine_print;
  const gchar *fine_print_color;
  gint progress;
  TreeEntry *entries;
};

enum {
  ICON_COLUMN,
  INFO_COLUMN,
  DESCRIPTION_COLUMN,
  FINE_PRINT_COLUMN,
  FINE_PRINT_COLOR_COLUMN,
  PROGRESS_COLUMN,
  NUM_COLUMNS
};


static TreeEntry info_entries[] =
  {
    { 
      "gtk-execute", 
      "Will you\n"
      "run this ?", 
      "Currently executing that thing... you might want to abort",
      "and every day he went fishing for pigs in the sky",
      "green",
      83,
      NULL
    },
    { 
      "gtk-dialog-authentication", 
      "This is the\n"
      "realest of the real", 
      "We are about to authenticate the actual realness, this could take some time",
      "one day he caught a giant ogre who barked and barked and barked",
      "purple",
      4,
      NULL
    },
    { 0, },
  };

static TreeEntry directory_entries[] =
  {
    { 
      "gtk-edit", 
      "We can edit\n"
      "things in here", 
      "Time to edit your directory, almost finished now",
      "she thought the best remedy for daydreams was going to be sleep",
      "dark sea green",
      99,
      NULL
    },
    { 
      "gtk-file", 
      "You have a\n"
      "file here", 
      "Who would of thought there would be a file in the directory ?",
      "after taking loads of sleeping pills he could still hear the pigs barking",
      "green yellow",
      33,
      NULL
    },
    { 
      "gtk-dialog-question", 
      "Any questions ?",
      "This file would like to ask you a question",
      "so he decided that the fine print underneath the progress bar probably made no sense at all",
      "lavender",
      73,
      NULL
    },
    { 0, },
  };

static TreeEntry other_entries[] =
  {
    { 
      "gtk-zoom-fit", 
      "Thats the\n"
      "perfect fit", 
      "Now fitting foo into bar using frobnicator",
      "using his nifty wide angle lense, he was able to catch a 'dark salmon', it was no flying pig "
      "however it was definitely a keeper",
      "dark salmon",
      59,
      NULL
    },
    { 
      "gtk-underline", 
      "Under the\n"
      "line", 
      "Now underlining that this demo would look alot niftier with some real content",
      "it was indeed strange to catch a red salmon while fishing for pigs in the deep sky blue.",
      "deep sky blue",
      99,
      NULL
    },
    { 0, },
  };

static TreeEntry add_entries[] =
  {
    { 
      "gtk-about", 
      "its about\n"
      "to start", 
      "This is what it's all about",
      "so he went ahead and added the 'gtk-about' icon to his story, thinking 'mint cream' would be the "
      "right color for something like that",
      "dark violet",
      1,
      NULL
    },
    { 
      "gtk-zoom-in", 
      "Watch it\n"
      "Zoom !", 
      "Now zooming into something",
      "while fishing for pigs in the sky, maybe he would have caught something faster if only he had zoomed in",
      "orchid",
      6,
      NULL
    },
    { 
      "gtk-zoom-out", 
      "Zoom Zoom\n"
      "Zoom !", 
      "Now zooming out of something else",
      "the daydream had a much prettier picture over all once he had zoomed out for the wide angle, "
      "jill agreed",
      "dark magenta",
      46,
      other_entries
    },
    { 0, },
  };


static TreeEntry main_entries[] =
  {
    { 
      "gtk-info", 
      "This is all\n"
      "the info", 
      "We are currently informing you",
      "once upon a time in a land far far away there was a guy named buba",
      "red",
      64,
      info_entries
    },
    { 
      "gtk-dialog-warning", 
      "This is a\n"
      "warning", 
      "We would like to warn you that your laptop might explode after we're done",
      "so he decided that he must be stark raving mad",
      "orange",
      43,
      NULL
    },
    { 
      "gtk-dialog-error", 
      "An error will\n"
      "occur", 
      "Once we're done here, dont worry... an error will surely occur.",
      "and went to a see a yellow physiotherapist who's name was jill",
      "yellow",
      98,
      NULL
    },
    { 
      "gtk-directory", 
      "The directory", 
      "Currently scanning your directories.",
      "jill didnt know what to make of the barking pigs either so she fed him sleeping pills",
      "brown",
      20,
      directory_entries
    },
    { 
      "gtk-delete", 
      "Now deleting\n"
      "the whole thing",
      "Time to delete the sucker",
      "and he decided to just delete the whole conversation since it didnt make sense to him",
      "dark orange",
      26,
      NULL
    },
    { 
      "gtk-add", 
      "Anything\n"
      "to add ?",
      "Now adding stuff... please be patient",
      "but on second thought, maybe he had something to add so that things could make a little less sense.",
      "maroon",
      72,
      add_entries
    },
    { 
      "gtk-redo", 
      "Time to\n"
      "do it again",
      "For the hell of it, lets add the content to the treeview over and over again !",
      "buba likes telling his story, so maybe he's going to tell it 20 times more.",
      "deep pink",
      100,
      NULL
    },
    { 0, },
  };


static void
populate_model (GtkTreeStore *model,
		GtkTreeIter  *parent,
		TreeEntry    *entries)
{
  GtkTreeIter iter;
  gint        i;

  for (i = 0; entries[i].info != NULL; i++)
    {
      gtk_tree_store_append (model, &iter, parent);
      gtk_tree_store_set (model, &iter,
			  ICON_COLUMN, entries[i].icon,
			  INFO_COLUMN, entries[i].info,
			  DESCRIPTION_COLUMN, entries[i].description,
			  FINE_PRINT_COLUMN, entries[i].fine_print,
			  FINE_PRINT_COLOR_COLUMN, entries[i].fine_print_color,
			  PROGRESS_COLUMN, entries[i].progress,
			  -1);

      if (entries[i].entries)
	populate_model (model, &iter, entries[i].entries);
    }
}

static GtkTreeModel *
create_model (void)
{
  GtkTreeStore *model;
  gint          i;

  model = gtk_tree_store_new (NUM_COLUMNS,
			      G_TYPE_STRING,
			      G_TYPE_STRING,
			      G_TYPE_STRING,
			      G_TYPE_STRING,
			      G_TYPE_STRING,
			      G_TYPE_INT);

  for (i = 0; i < 20; i++)
    populate_model (model, NULL, main_entries);

  return GTK_TREE_MODEL (model);
}

gint
main (gint argc, gchar **argv)
{
  GtkWidget *window;
  GtkWidget *scrolled_window;
  GtkWidget *tree_view;
  GtkTreeModel *tree_model;
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;
  GtkCellArea *area;
  
  gtk_init (&argc, &argv);

  if (g_getenv ("RTL"))
    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Vertical cells in GtkTreeViewColumn example");
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), 
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_container_add (GTK_CONTAINER (window), scrolled_window);

  tree_model = create_model ();
  tree_view = gtk_tree_view_new_with_model (tree_model);
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);

  /* First column */
  column = gtk_tree_view_column_new ();

  renderer = gtk_cell_renderer_pixbuf_new ();
  g_object_set (renderer, "stock-size", GTK_ICON_SIZE_DIALOG, NULL);
  gtk_tree_view_column_pack_start (column, renderer, TRUE);
  gtk_tree_view_column_set_attributes (column, renderer,
				       "stock-id", ICON_COLUMN, NULL);

  renderer = gtk_cell_renderer_text_new ();
  g_object_set (renderer, "scale", 1.2F, "weight", PANGO_WEIGHT_BOLD, NULL);
  gtk_tree_view_column_pack_start (column, renderer, TRUE);
  gtk_tree_view_column_set_attributes (column, renderer,
				       "text", INFO_COLUMN,
				       NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

  /* Second (vertical) column */
  column = gtk_tree_view_column_new ();
  area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (column));
  gtk_orientable_set_orientation (GTK_ORIENTABLE (area), GTK_ORIENTATION_VERTICAL);

  renderer = gtk_cell_renderer_text_new ();
  g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, "editable", TRUE, NULL);
  gtk_tree_view_column_pack_start (column, renderer, TRUE);
  gtk_tree_view_column_set_attributes (column, renderer,
				       "text", DESCRIPTION_COLUMN,
				       NULL);

  renderer = gtk_cell_renderer_progress_new ();
  gtk_tree_view_column_pack_start (column, renderer, TRUE);
  gtk_tree_view_column_set_attributes (column, renderer,
				       "value", PROGRESS_COLUMN,
				       NULL);

  renderer = gtk_cell_renderer_text_new ();
  g_object_set (renderer, "scale", 0.6F, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
  gtk_tree_view_column_pack_start (column, renderer, TRUE);
  gtk_tree_view_column_set_attributes (column, renderer,
				       "text", FINE_PRINT_COLUMN,
				       "foreground", FINE_PRINT_COLOR_COLUMN,
				       NULL);

  gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

  gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));

  gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
  
  gtk_window_set_default_size (GTK_WINDOW (window),
			       800, 400);

  gtk_widget_show_all (window);
  gtk_main ();

  return 0;
}