1 /* GTK - The GIMP Toolkit
2 * testcellrenderertext.c: Tests for the various properties of GtkCellRendererText
3 * Copyright (C) 2005, Novell, Inc.
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.
26 #define COL_BACKGROUND 15
27 #define COL_LINE_NUM 16
28 #define NUM_COLS 17 /* change this when adding columns */
31 char *description
; /* 0 */
35 double xalign
; /* 4 */
36 double yalign
; /* 5 */
37 gboolean sensitive
; /* 6 */
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 */
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 */
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
;
114 list_store
= gtk_list_store_new (NUM_COLS
,
115 G_TYPE_STRING
, /* 0 */
116 G_TYPE_STRING
, /* 1 */
119 G_TYPE_DOUBLE
, /* 4 */
120 G_TYPE_DOUBLE
, /* 5 */
121 G_TYPE_BOOLEAN
, /* 6 */
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
;
141 g_snprintf (buf
, sizeof (buf
), "%d", i
);
143 gtk_list_store_append (list_store
, &iter
);
144 gtk_list_store_set (list_store
, &iter
,
157 12, p
->single_paragraph_mode
,
160 15, (i
% 2 == 0) ? "gray50" : "gray80",
169 create_tree (gboolean rtl
)
173 GtkListStore
*list_store
;
174 GtkTreeViewColumn
*column
;
175 GtkCellRenderer
*renderer
;
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
);
190 renderer
= gtk_cell_renderer_text_new ();
191 column
= gtk_tree_view_column_new_with_attributes ("#",
193 "text", COL_LINE_NUM
,
195 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
199 renderer
= gtk_cell_renderer_text_new ();
200 g_object_set (renderer
,
203 column
= gtk_tree_view_column_new_with_attributes ("Description",
207 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
211 renderer
= gtk_cell_renderer_text_new ();
212 column
= gtk_tree_view_column_new_with_attributes ("Test",
225 "single_paragraph_mode", 12,
228 "cell_background", 15,
230 gtk_tree_view_column_set_resizable (column
, TRUE
);
231 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
235 pixbuf
= gdk_pixbuf_new_from_file ("apple-red.png", NULL
);
237 renderer
= gtk_cell_renderer_pixbuf_new ();
238 g_object_set (renderer
,
243 column
= gtk_tree_view_column_new_with_attributes ("Empty",
246 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
252 main (int argc
, char **argv
)
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
);
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);
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
);