Add powerbox hook
[gtk-with-powerbox.git] / tests / testcellrenderertext.c
blobab51243c195cff5f1462da66d52f8ea98a42847c
1 /* GTK - The GIMP Toolkit
2 * testcellrenderertext.c: Tests for the various properties of GtkCellRendererText
3 * Copyright (C) 2005, Novell, Inc.
5 * Authors:
6 * Federico Mena-Quintero <federico@novell.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser 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.
24 #include <gtk/gtk.h>
26 #define COL_BACKGROUND 15
27 #define COL_LINE_NUM 16
28 #define NUM_COLS 17 /* change this when adding columns */
30 struct cell_params {
31 char *description; /* 0 */
32 char *test; /* 1 */
33 int xpad; /* 2 */
34 int ypad; /* 3 */
35 double xalign; /* 4 */
36 double yalign; /* 5 */
37 gboolean sensitive; /* 6 */
38 int width; /* 7 */
39 int height; /* 8 */
40 int width_chars; /* 9 */
41 int wrap_width; /* 10 */
42 PangoWrapMode wrap_mode; /* 11 */
43 gboolean single_paragraph_mode; /* 12 */
44 PangoEllipsizeMode ellipsize; /* 13 */
45 PangoAlignment alignment; /* 14 */
46 /* COL_BACKGROUND */ /* 15 */
47 /* COL_LINE_NUM */ /* 16 */
50 #define WO PANGO_WRAP_WORD
51 #define CH PANGO_WRAP_CHAR
52 #define WC PANGO_WRAP_WORD_CHAR
54 #define NO PANGO_ELLIPSIZE_NONE
55 #define ST PANGO_ELLIPSIZE_START
56 #define MI PANGO_ELLIPSIZE_MIDDLE
57 #define EN PANGO_ELLIPSIZE_END
59 #define AL PANGO_ALIGN_LEFT
60 #define AC PANGO_ALIGN_CENTER
61 #define AR PANGO_ALIGN_RIGHT
63 #define TESTL "LEFT JUSTIFIED This is really truly verily some very long text\n\330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205"
65 #define TESTC "CENTERED This is really truly verily some very long text\n\330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205"
67 #define TESTR "RIGHT JUSTIFIED This is really truly verily some very long text\n\330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205"
70 /* DO NOT CHANGE THE ROWS! They are numbered so that we can refer to
71 * problematic rows in bug reports. If you need a different test, just add a
72 * new row at the bottom. Also, please add your new row numbers to this column -------------------------------+
73 * to keep things tidy. v
75 static const struct cell_params cell_params[] = {
76 { "xp yp xa ya se wi he wc ww wm sp el", "", 0, 0, 0.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 0 */
78 /* Test alignment */
80 { "0 0 0 0 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 1 */
81 { "0 0 .5 0 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 2 */
82 { "0 0 1 0 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 3 */
83 { "0 0 0 .5 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 4 */
84 { "0 0 .5 .5 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 5 */
85 { "0 0 1 .5 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 6 */
86 { "0 0 0 1 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 7 */
87 { "0 0 .5 1 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 8 */
88 { "0 0 1 1 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 9 */
90 /* Test padding */
92 { "10 10 0 0 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 10 */
93 { "10 10 .5 0 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 11 */
94 { "10 10 1 0 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 12 */
95 { "10 10 0 .5 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 13 */
96 { "10 10 .5 .5 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 14 */
97 { "10 10 1 .5 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 15 */
98 { "10 10 0 1 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 16 */
99 { "10 10 .5 1 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 17 */
100 { "10 10 1 1 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 18 */
102 /* Test Pango alignment (not xalign) */
103 { "0 0 0 0 T -1 -1 -1 -1 CH F NO AL", TESTL, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, 20, WO, FALSE, NO , AL }, /* 19 */
104 { "0 0 0 0 T -1 -1 -1 -1 CH F NO AC", TESTC, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, 20, WO, FALSE, NO , AC }, /* 20 */
105 { "0 0 0 0 T -1 -1 -1 -1 CH F NO AR", TESTR, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, 20, WO, FALSE, NO , AR }, /* 21 */
108 static GtkListStore *
109 create_list_store (void)
111 GtkListStore *list_store;
112 int i;
114 list_store = gtk_list_store_new (NUM_COLS,
115 G_TYPE_STRING, /* 0 */
116 G_TYPE_STRING, /* 1 */
117 G_TYPE_INT, /* 2 */
118 G_TYPE_INT, /* 3 */
119 G_TYPE_DOUBLE, /* 4 */
120 G_TYPE_DOUBLE, /* 5 */
121 G_TYPE_BOOLEAN, /* 6 */
122 G_TYPE_INT, /* 7 */
123 G_TYPE_INT, /* 8 */
124 G_TYPE_INT, /* 9 */
125 G_TYPE_INT, /* 10 */
126 PANGO_TYPE_WRAP_MODE, /* 11 */
127 G_TYPE_BOOLEAN, /* 12 */
128 PANGO_TYPE_ELLIPSIZE_MODE, /* 13 */
129 PANGO_TYPE_ALIGNMENT, /* 14 */
130 G_TYPE_STRING, /* 15 */
131 G_TYPE_STRING); /* 16 */
133 for (i = 0; i < G_N_ELEMENTS (cell_params); i++)
135 const struct cell_params *p;
136 GtkTreeIter iter;
137 char buf[50];
139 p = cell_params + i;
141 g_snprintf (buf, sizeof (buf), "%d", i);
143 gtk_list_store_append (list_store, &iter);
144 gtk_list_store_set (list_store, &iter,
145 0, p->description,
146 1, p->test,
147 2, p->xpad,
148 3, p->ypad,
149 4, p->xalign,
150 5, p->yalign,
151 6, p->sensitive,
152 7, p->width,
153 8, p->height,
154 9, p->width_chars,
155 10, p->wrap_width,
156 11, p->wrap_mode,
157 12, p->single_paragraph_mode,
158 13, p->ellipsize,
159 14, p->alignment,
160 15, (i % 2 == 0) ? "gray50" : "gray80",
161 16, buf,
162 -1);
165 return list_store;
168 static GtkWidget *
169 create_tree (gboolean rtl)
171 GtkWidget *sw;
172 GtkWidget *treeview;
173 GtkListStore *list_store;
174 GtkTreeViewColumn *column;
175 GtkCellRenderer *renderer;
176 GdkPixbuf *pixbuf;
178 sw = gtk_scrolled_window_new (NULL, NULL);
179 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
180 gtk_widget_set_direction (sw, rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
182 list_store = create_list_store ();
184 treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
185 gtk_widget_set_direction (treeview, rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
186 gtk_container_add (GTK_CONTAINER (sw), treeview);
188 /* Line number */
190 renderer = gtk_cell_renderer_text_new ();
191 column = gtk_tree_view_column_new_with_attributes ("#",
192 renderer,
193 "text", COL_LINE_NUM,
194 NULL);
195 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
197 /* Description */
199 renderer = gtk_cell_renderer_text_new ();
200 g_object_set (renderer,
201 "font", "monospace",
202 NULL);
203 column = gtk_tree_view_column_new_with_attributes ("Description",
204 renderer,
205 "text", 0,
206 NULL);
207 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
209 /* Test text */
211 renderer = gtk_cell_renderer_text_new ();
212 column = gtk_tree_view_column_new_with_attributes ("Test",
213 renderer,
214 "text", 1,
215 "xpad", 2,
216 "ypad", 3,
217 "xalign", 4,
218 "yalign", 5,
219 "sensitive", 6,
220 "width", 7,
221 "height", 8,
222 "width_chars", 9,
223 "wrap_width", 10,
224 "wrap_mode", 11,
225 "single_paragraph_mode", 12,
226 "ellipsize", 13,
227 "alignment", 14,
228 "cell_background", 15,
229 NULL);
230 gtk_tree_view_column_set_resizable (column, TRUE);
231 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
233 /* Empty column */
235 pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL);
237 renderer = gtk_cell_renderer_pixbuf_new ();
238 g_object_set (renderer,
239 "pixbuf", pixbuf,
240 "xpad", 10,
241 "ypad", 10,
242 NULL);
243 column = gtk_tree_view_column_new_with_attributes ("Empty",
244 renderer,
245 NULL);
246 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
248 return sw;
252 main (int argc, char **argv)
254 GtkWidget *window;
255 GtkWidget *vbox;
256 GtkWidget *label;
257 GtkWidget *tree;
259 gtk_init (&argc, &argv);
261 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
262 g_signal_connect (window, "destroy",
263 G_CALLBACK (gtk_main_quit), NULL);
264 gtk_container_set_border_width (GTK_CONTAINER (window), 12);
266 vbox = gtk_vbox_new (FALSE, 12);
267 gtk_container_add (GTK_CONTAINER (window), vbox);
269 /* LTR */
271 label = gtk_label_new ("Left to right");
272 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
274 tree = create_tree (FALSE);
275 gtk_box_pack_start (GTK_BOX (vbox), tree, TRUE, TRUE, 0);
277 /* RTL */
279 label = gtk_label_new ("Right to left");
280 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
282 tree = create_tree (TRUE);
283 gtk_box_pack_start (GTK_BOX (vbox), tree, TRUE, TRUE, 0);
285 gtk_widget_show_all (window);
286 gtk_main ();
288 return 0;