1
by Michael Terry
Import upstream version 2.91.3 |
1 |
/* testtoolbar.c
|
2 |
*
|
|
3 |
* Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
|
|
4 |
* Copyright (C) 2002 James Henstridge <james@daa.com.au>
|
|
5 |
* Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
|
6 |
*
|
|
7 |
* This library is free software; you can redistribute it and/or
|
|
8 |
* modify it under the terms of the GNU Library General Public
|
|
9 |
* License as published by the Free Software Foundation; either
|
|
10 |
* version 2 of the License, or (at your option) any later version.
|
|
11 |
*
|
|
12 |
* This library is distributed in the hope that it will be useful,
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 |
* Library General Public License for more details.
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU Library General Public
|
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
18 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
1
by Michael Terry
Import upstream version 2.91.3 |
19 |
*/
|
20 |
#include "config.h" |
|
21 |
#include <gtk/gtk.h> |
|
22 |
#include "prop-editor.h" |
|
23 |
||
24 |
static void |
|
25 |
change_orientation (GtkWidget *button, GtkWidget *toolbar) |
|
26 |
{
|
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
27 |
GtkWidget *grid; |
1
by Michael Terry
Import upstream version 2.91.3 |
28 |
GtkOrientation orientation; |
29 |
||
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
30 |
grid = gtk_widget_get_parent (toolbar); |
1
by Michael Terry
Import upstream version 2.91.3 |
31 |
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) |
32 |
orientation = GTK_ORIENTATION_VERTICAL; |
|
33 |
else
|
|
34 |
orientation = GTK_ORIENTATION_HORIZONTAL; |
|
35 |
||
36 |
g_object_ref (toolbar); |
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
37 |
gtk_container_remove (GTK_CONTAINER (grid), toolbar); |
1
by Michael Terry
Import upstream version 2.91.3 |
38 |
gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), orientation); |
39 |
if (orientation == GTK_ORIENTATION_HORIZONTAL) |
|
40 |
{
|
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
41 |
gtk_widget_set_hexpand (toolbar, TRUE); |
42 |
gtk_widget_set_vexpand (toolbar, FALSE); |
|
43 |
gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 2, 1); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
44 |
}
|
45 |
else
|
|
46 |
{
|
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
47 |
gtk_widget_set_hexpand (toolbar, FALSE); |
48 |
gtk_widget_set_vexpand (toolbar, TRUE); |
|
49 |
gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 1, 5); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
50 |
}
|
51 |
g_object_unref (toolbar); |
|
52 |
}
|
|
53 |
||
54 |
static void |
|
55 |
change_show_arrow (GtkWidget *button, GtkWidget *toolbar) |
|
56 |
{
|
|
57 |
gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), |
|
58 |
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))); |
|
59 |
}
|
|
60 |
||
61 |
static void |
|
62 |
set_toolbar_style_toggled (GtkCheckButton *button, GtkToolbar *toolbar) |
|
63 |
{
|
|
64 |
GtkWidget *option_menu; |
|
65 |
int style; |
|
66 |
||
67 |
option_menu = g_object_get_data (G_OBJECT (button), "option-menu"); |
|
68 |
||
69 |
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) |
|
70 |
{
|
|
71 |
style = gtk_combo_box_get_active (GTK_COMBO_BOX (option_menu)); |
|
72 |
||
73 |
gtk_toolbar_set_style (toolbar, style); |
|
74 |
gtk_widget_set_sensitive (option_menu, TRUE); |
|
75 |
}
|
|
76 |
else
|
|
77 |
{
|
|
78 |
gtk_toolbar_unset_style (toolbar); |
|
79 |
gtk_widget_set_sensitive (option_menu, FALSE); |
|
80 |
}
|
|
81 |
}
|
|
82 |
||
83 |
static void |
|
84 |
change_toolbar_style (GtkWidget *option_menu, GtkWidget *toolbar) |
|
85 |
{
|
|
86 |
GtkToolbarStyle style; |
|
87 |
||
88 |
style = gtk_combo_box_get_active (GTK_COMBO_BOX (option_menu)); |
|
89 |
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style); |
|
90 |
}
|
|
91 |
||
92 |
static void |
|
93 |
set_visible_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, |
|
94 |
GtkTreeModel *model, GtkTreeIter *iter, gpointer data) |
|
95 |
{
|
|
96 |
GtkToolItem *tool_item; |
|
97 |
gboolean visible; |
|
98 |
||
99 |
gtk_tree_model_get (model, iter, 0, &tool_item, -1); |
|
100 |
||
101 |
g_object_get (tool_item, "visible", &visible, NULL); |
|
102 |
g_object_set (cell, "active", visible, NULL); |
|
103 |
g_object_unref (tool_item); |
|
104 |
}
|
|
105 |
||
106 |
static void |
|
107 |
visibile_toggled(GtkCellRendererToggle *cell, const gchar *path_str, |
|
108 |
GtkTreeModel *model) |
|
109 |
{
|
|
110 |
GtkTreePath *path; |
|
111 |
GtkTreeIter iter; |
|
112 |
GtkToolItem *tool_item; |
|
113 |
gboolean visible; |
|
114 |
||
115 |
path = gtk_tree_path_new_from_string (path_str); |
|
116 |
gtk_tree_model_get_iter (model, &iter, path); |
|
117 |
||
118 |
gtk_tree_model_get (model, &iter, 0, &tool_item, -1); |
|
119 |
g_object_get (tool_item, "visible", &visible, NULL); |
|
120 |
g_object_set (tool_item, "visible", !visible, NULL); |
|
121 |
g_object_unref (tool_item); |
|
122 |
||
123 |
gtk_tree_model_row_changed (model, path, &iter); |
|
124 |
gtk_tree_path_free (path); |
|
125 |
}
|
|
126 |
||
127 |
static void |
|
128 |
set_expand_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, |
|
129 |
GtkTreeModel *model, GtkTreeIter *iter, gpointer data) |
|
130 |
{
|
|
131 |
GtkToolItem *tool_item; |
|
132 |
||
133 |
gtk_tree_model_get (model, iter, 0, &tool_item, -1); |
|
134 |
||
135 |
g_object_set (cell, "active", gtk_tool_item_get_expand (tool_item), NULL); |
|
136 |
g_object_unref (tool_item); |
|
137 |
}
|
|
138 |
||
139 |
static void |
|
140 |
expand_toggled(GtkCellRendererToggle *cell, const gchar *path_str, |
|
141 |
GtkTreeModel *model) |
|
142 |
{
|
|
143 |
GtkTreePath *path; |
|
144 |
GtkTreeIter iter; |
|
145 |
GtkToolItem *tool_item; |
|
146 |
||
147 |
path = gtk_tree_path_new_from_string (path_str); |
|
148 |
gtk_tree_model_get_iter (model, &iter, path); |
|
149 |
||
150 |
gtk_tree_model_get (model, &iter, 0, &tool_item, -1); |
|
151 |
gtk_tool_item_set_expand (tool_item, !gtk_tool_item_get_expand (tool_item)); |
|
152 |
g_object_unref (tool_item); |
|
153 |
||
154 |
gtk_tree_model_row_changed (model, path, &iter); |
|
155 |
gtk_tree_path_free (path); |
|
156 |
}
|
|
157 |
||
158 |
static void |
|
159 |
set_homogeneous_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, |
|
160 |
GtkTreeModel *model, GtkTreeIter *iter, gpointer data) |
|
161 |
{
|
|
162 |
GtkToolItem *tool_item; |
|
163 |
||
164 |
gtk_tree_model_get (model, iter, 0, &tool_item, -1); |
|
165 |
||
166 |
g_object_set (cell, "active", gtk_tool_item_get_homogeneous (tool_item), NULL); |
|
167 |
g_object_unref (tool_item); |
|
168 |
}
|
|
169 |
||
170 |
static void |
|
171 |
homogeneous_toggled(GtkCellRendererToggle *cell, const gchar *path_str, |
|
172 |
GtkTreeModel *model) |
|
173 |
{
|
|
174 |
GtkTreePath *path; |
|
175 |
GtkTreeIter iter; |
|
176 |
GtkToolItem *tool_item; |
|
177 |
||
178 |
path = gtk_tree_path_new_from_string (path_str); |
|
179 |
gtk_tree_model_get_iter (model, &iter, path); |
|
180 |
||
181 |
gtk_tree_model_get (model, &iter, 0, &tool_item, -1); |
|
182 |
gtk_tool_item_set_homogeneous (tool_item, !gtk_tool_item_get_homogeneous (tool_item)); |
|
183 |
g_object_unref (tool_item); |
|
184 |
||
185 |
gtk_tree_model_row_changed (model, path, &iter); |
|
186 |
gtk_tree_path_free (path); |
|
187 |
}
|
|
188 |
||
189 |
||
190 |
static void |
|
191 |
set_important_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, |
|
192 |
GtkTreeModel *model, GtkTreeIter *iter, gpointer data) |
|
193 |
{
|
|
194 |
GtkToolItem *tool_item; |
|
195 |
||
196 |
gtk_tree_model_get (model, iter, 0, &tool_item, -1); |
|
197 |
||
198 |
g_object_set (cell, "active", gtk_tool_item_get_is_important (tool_item), NULL); |
|
199 |
g_object_unref (tool_item); |
|
200 |
}
|
|
201 |
||
202 |
static void |
|
203 |
important_toggled(GtkCellRendererToggle *cell, const gchar *path_str, |
|
204 |
GtkTreeModel *model) |
|
205 |
{
|
|
206 |
GtkTreePath *path; |
|
207 |
GtkTreeIter iter; |
|
208 |
GtkToolItem *tool_item; |
|
209 |
||
210 |
path = gtk_tree_path_new_from_string (path_str); |
|
211 |
gtk_tree_model_get_iter (model, &iter, path); |
|
212 |
||
213 |
gtk_tree_model_get (model, &iter, 0, &tool_item, -1); |
|
214 |
gtk_tool_item_set_is_important (tool_item, !gtk_tool_item_get_is_important (tool_item)); |
|
215 |
g_object_unref (tool_item); |
|
216 |
||
217 |
gtk_tree_model_row_changed (model, path, &iter); |
|
218 |
gtk_tree_path_free (path); |
|
219 |
}
|
|
220 |
||
221 |
static GtkListStore * |
|
222 |
create_items_list (GtkWidget **tree_view_p) |
|
223 |
{
|
|
224 |
GtkWidget *tree_view; |
|
225 |
GtkListStore *list_store; |
|
226 |
GtkCellRenderer *cell; |
|
227 |
||
228 |
list_store = gtk_list_store_new (2, GTK_TYPE_TOOL_ITEM, G_TYPE_STRING); |
|
229 |
||
230 |
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store)); |
|
231 |
||
232 |
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), |
|
233 |
-1, "Tool Item", |
|
234 |
gtk_cell_renderer_text_new (), |
|
235 |
"text", 1, NULL); |
|
236 |
||
237 |
cell = gtk_cell_renderer_toggle_new (); |
|
238 |
g_signal_connect (cell, "toggled", G_CALLBACK (visibile_toggled), |
|
239 |
list_store); |
|
240 |
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view), |
|
241 |
-1, "Visible", |
|
242 |
cell, |
|
243 |
set_visible_func, NULL, NULL); |
|
244 |
||
245 |
cell = gtk_cell_renderer_toggle_new (); |
|
246 |
g_signal_connect (cell, "toggled", G_CALLBACK (expand_toggled), |
|
247 |
list_store); |
|
248 |
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view), |
|
249 |
-1, "Expand", |
|
250 |
cell, |
|
251 |
set_expand_func, NULL, NULL); |
|
252 |
||
253 |
cell = gtk_cell_renderer_toggle_new (); |
|
254 |
g_signal_connect (cell, "toggled", G_CALLBACK (homogeneous_toggled), |
|
255 |
list_store); |
|
256 |
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view), |
|
257 |
-1, "Homogeneous", |
|
258 |
cell, |
|
259 |
set_homogeneous_func, NULL,NULL); |
|
260 |
||
261 |
cell = gtk_cell_renderer_toggle_new (); |
|
262 |
g_signal_connect (cell, "toggled", G_CALLBACK (important_toggled), |
|
263 |
list_store); |
|
264 |
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view), |
|
265 |
-1, "Important", |
|
266 |
cell, |
|
267 |
set_important_func, NULL,NULL); |
|
268 |
||
269 |
g_object_unref (list_store); |
|
270 |
||
271 |
*tree_view_p = tree_view; |
|
272 |
||
273 |
return list_store; |
|
274 |
}
|
|
275 |
||
276 |
static void |
|
277 |
add_item_to_list (GtkListStore *store, GtkToolItem *item, const gchar *text) |
|
278 |
{
|
|
279 |
GtkTreeIter iter; |
|
280 |
||
281 |
gtk_list_store_append (store, &iter); |
|
282 |
gtk_list_store_set (store, &iter, |
|
283 |
0, item, |
|
284 |
1, text, |
|
285 |
-1); |
|
286 |
||
287 |
}
|
|
288 |
||
289 |
static void |
|
290 |
bold_toggled (GtkToggleToolButton *button) |
|
291 |
{
|
|
292 |
g_message ("Bold toggled (active=%d)", |
|
293 |
gtk_toggle_tool_button_get_active (button)); |
|
294 |
}
|
|
295 |
||
296 |
static void |
|
297 |
set_icon_size_toggled (GtkCheckButton *button, GtkToolbar *toolbar) |
|
298 |
{
|
|
299 |
GtkWidget *option_menu; |
|
300 |
int icon_size; |
|
301 |
||
302 |
option_menu = g_object_get_data (G_OBJECT (button), "option-menu"); |
|
303 |
||
304 |
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) |
|
305 |
{
|
|
306 |
if (gtk_combo_box_get_active (GTK_COMBO_BOX (option_menu)) == 0) |
|
307 |
icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR; |
|
308 |
else
|
|
309 |
icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR; |
|
310 |
||
311 |
gtk_toolbar_set_icon_size (toolbar, icon_size); |
|
312 |
gtk_widget_set_sensitive (option_menu, TRUE); |
|
313 |
}
|
|
314 |
else
|
|
315 |
{
|
|
316 |
gtk_toolbar_unset_icon_size (toolbar); |
|
317 |
gtk_widget_set_sensitive (option_menu, FALSE); |
|
318 |
}
|
|
319 |
}
|
|
320 |
||
321 |
static void |
|
322 |
icon_size_history_changed (GtkComboBox *menu, GtkToolbar *toolbar) |
|
323 |
{
|
|
324 |
int icon_size; |
|
325 |
||
326 |
if (gtk_combo_box_get_active (menu) == 0) |
|
327 |
icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR; |
|
328 |
else
|
|
329 |
icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR; |
|
330 |
||
331 |
gtk_toolbar_set_icon_size (toolbar, icon_size); |
|
332 |
}
|
|
333 |
||
334 |
static gboolean |
|
335 |
toolbar_drag_drop (GtkWidget *widget, GdkDragContext *context, |
|
336 |
gint x, gint y, guint time, GtkWidget *label) |
|
337 |
{
|
|
338 |
gchar buf[32]; |
|
339 |
||
340 |
g_snprintf(buf, sizeof(buf), "%d", |
|
341 |
gtk_toolbar_get_drop_index (GTK_TOOLBAR (widget), x, y)); |
|
342 |
gtk_label_set_label (GTK_LABEL (label), buf); |
|
343 |
||
344 |
return TRUE; |
|
345 |
}
|
|
346 |
||
347 |
static GtkTargetEntry target_table[] = { |
|
348 |
{ "application/x-toolbar-item", 0, 0 } |
|
349 |
};
|
|
350 |
||
351 |
static GtkWidget * |
|
352 |
make_prop_editor (GObject *object) |
|
353 |
{
|
|
354 |
GtkWidget *prop_editor = create_prop_editor (object, 0); |
|
355 |
gtk_widget_show (prop_editor); |
|
356 |
return prop_editor; |
|
357 |
}
|
|
358 |
||
359 |
static void |
|
360 |
rtl_toggled (GtkCheckButton *check) |
|
361 |
{
|
|
362 |
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check))) |
|
363 |
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL); |
|
364 |
else
|
|
365 |
gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR); |
|
366 |
}
|
|
367 |
||
368 |
typedef struct |
|
369 |
{
|
|
370 |
int x; |
|
371 |
int y; |
|
372 |
} MenuPositionData; |
|
373 |
||
374 |
static void |
|
375 |
position_function (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) |
|
376 |
{
|
|
377 |
/* Do not do this in your own code */
|
|
378 |
||
379 |
MenuPositionData *position_data = user_data; |
|
380 |
||
381 |
if (x) |
|
382 |
*x = position_data->x; |
|
383 |
||
384 |
if (y) |
|
385 |
*y = position_data->y; |
|
386 |
||
387 |
if (push_in) |
|
388 |
*push_in = FALSE; |
|
389 |
}
|
|
390 |
||
391 |
static gboolean |
|
392 |
popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number) |
|
393 |
{
|
|
394 |
MenuPositionData position_data; |
|
395 |
||
396 |
GtkMenu *menu = GTK_MENU (gtk_menu_new ()); |
|
397 |
int i; |
|
398 |
||
399 |
for (i = 0; i < 5; i++) |
|
400 |
{
|
|
401 |
GtkWidget *item; |
|
402 |
gchar *label = g_strdup_printf ("Item _%d", i); |
|
403 |
item = gtk_menu_item_new_with_mnemonic (label); |
|
404 |
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); |
|
405 |
}
|
|
406 |
gtk_widget_show_all (GTK_WIDGET (menu)); |
|
407 |
||
408 |
if (button_number != -1) |
|
409 |
{
|
|
410 |
position_data.x = x; |
|
411 |
position_data.y = y; |
|
412 |
||
413 |
gtk_menu_popup (menu, NULL, NULL, position_function, |
|
414 |
&position_data, button_number, gtk_get_current_event_time()); |
|
415 |
}
|
|
416 |
else
|
|
417 |
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); |
|
418 |
||
419 |
return TRUE; |
|
420 |
}
|
|
421 |
||
422 |
static GtkToolItem *drag_item = NULL; |
|
423 |
||
424 |
static gboolean |
|
425 |
toolbar_drag_motion (GtkToolbar *toolbar, |
|
426 |
GdkDragContext *context, |
|
427 |
gint x, |
|
428 |
gint y, |
|
429 |
guint time, |
|
430 |
gpointer null) |
|
431 |
{
|
|
432 |
gint index; |
|
433 |
||
434 |
if (!drag_item) |
|
435 |
{
|
|
436 |
drag_item = gtk_tool_button_new (NULL, "A quite long button"); |
|
437 |
g_object_ref_sink (g_object_ref (drag_item)); |
|
438 |
}
|
|
439 |
||
440 |
gdk_drag_status (context, GDK_ACTION_MOVE, time); |
|
441 |
||
442 |
index = gtk_toolbar_get_drop_index (toolbar, x, y); |
|
443 |
||
444 |
gtk_toolbar_set_drop_highlight_item (toolbar, drag_item, index); |
|
445 |
||
446 |
return TRUE; |
|
447 |
}
|
|
448 |
||
449 |
static void |
|
450 |
toolbar_drag_leave (GtkToolbar *toolbar, |
|
451 |
GdkDragContext *context, |
|
452 |
guint time, |
|
453 |
gpointer null) |
|
454 |
{
|
|
455 |
if (drag_item) |
|
456 |
{
|
|
457 |
g_object_unref (drag_item); |
|
458 |
drag_item = NULL; |
|
459 |
}
|
|
460 |
||
461 |
gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0); |
|
462 |
}
|
|
463 |
||
464 |
static gboolean |
|
465 |
timeout_cb (GtkWidget *widget) |
|
466 |
{
|
|
467 |
static gboolean sensitive = TRUE; |
|
468 |
||
469 |
sensitive = !sensitive; |
|
470 |
||
471 |
gtk_widget_set_sensitive (widget, sensitive); |
|
472 |
||
473 |
return TRUE; |
|
474 |
}
|
|
475 |
||
476 |
static gboolean |
|
477 |
timeout_cb1 (GtkWidget *widget) |
|
478 |
{
|
|
479 |
static gboolean sensitive = TRUE; |
|
480 |
sensitive = !sensitive; |
|
481 |
gtk_widget_set_sensitive (widget, sensitive); |
|
482 |
return TRUE; |
|
483 |
}
|
|
484 |
||
485 |
gint
|
|
486 |
main (gint argc, gchar **argv) |
|
487 |
{
|
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
488 |
GtkWidget *window, *toolbar, *grid, *treeview, *scrolled_window; |
1
by Michael Terry
Import upstream version 2.91.3 |
489 |
GtkWidget *hbox, *hbox1, *hbox2, *checkbox, *option_menu, *menu; |
490 |
gint i; |
|
491 |
static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)", |
|
492 |
"both (horizontal)" }; |
|
493 |
GtkToolItem *item; |
|
494 |
GtkListStore *store; |
|
495 |
GtkWidget *image; |
|
496 |
GtkWidget *menuitem; |
|
497 |
GtkWidget *button; |
|
498 |
GtkWidget *label; |
|
499 |
GIcon *gicon; |
|
500 |
GSList *group; |
|
501 |
||
502 |
gtk_init (&argc, &argv); |
|
503 |
||
504 |
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
|
505 |
||
506 |
g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL); |
|
507 |
||
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
508 |
grid = gtk_grid_new (); |
509 |
gtk_container_add (GTK_CONTAINER (window), grid); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
510 |
|
511 |
toolbar = gtk_toolbar_new (); |
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
512 |
gtk_widget_set_vexpand (toolbar, TRUE); |
513 |
gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 2, 1); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
514 |
|
515 |
hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); |
|
516 |
gtk_container_set_border_width (GTK_CONTAINER (hbox1), 5); |
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
517 |
gtk_widget_set_vexpand (hbox1, TRUE); |
518 |
gtk_grid_attach (GTK_GRID (grid), hbox1, 1, 1, 1, 1); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
519 |
|
520 |
hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); |
|
521 |
gtk_container_set_border_width (GTK_CONTAINER (hbox2), 5); |
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
522 |
gtk_widget_set_vexpand (hbox2, TRUE); |
523 |
gtk_grid_attach (GTK_GRID (grid), hbox2, 1, 2, 1, 1); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
524 |
|
525 |
checkbox = gtk_check_button_new_with_mnemonic("_Vertical"); |
|
526 |
gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0); |
|
527 |
g_signal_connect (checkbox, "toggled", |
|
528 |
G_CALLBACK (change_orientation), toolbar); |
|
529 |
||
530 |
checkbox = gtk_check_button_new_with_mnemonic("_Show Arrow"); |
|
531 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE); |
|
532 |
gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0); |
|
533 |
g_signal_connect (checkbox, "toggled", |
|
534 |
G_CALLBACK (change_show_arrow), toolbar); |
|
535 |
||
536 |
checkbox = gtk_check_button_new_with_mnemonic("_Set Toolbar Style:"); |
|
537 |
g_signal_connect (checkbox, "toggled", G_CALLBACK (set_toolbar_style_toggled), toolbar); |
|
538 |
gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0); |
|
539 |
||
540 |
option_menu = gtk_combo_box_text_new (); |
|
541 |
gtk_widget_set_sensitive (option_menu, FALSE); |
|
542 |
g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu); |
|
543 |
||
544 |
for (i = 0; i < G_N_ELEMENTS (toolbar_styles); i++) |
|
545 |
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (option_menu), toolbar_styles[i]); |
|
546 |
gtk_combo_box_set_active (GTK_COMBO_BOX (option_menu), |
|
547 |
gtk_toolbar_get_style (GTK_TOOLBAR (toolbar))); |
|
548 |
gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0); |
|
549 |
g_signal_connect (option_menu, "changed", |
|
550 |
G_CALLBACK (change_toolbar_style), toolbar); |
|
551 |
||
552 |
checkbox = gtk_check_button_new_with_mnemonic("_Set Icon Size:"); |
|
553 |
g_signal_connect (checkbox, "toggled", G_CALLBACK (set_icon_size_toggled), toolbar); |
|
554 |
gtk_box_pack_start (GTK_BOX (hbox2), checkbox, FALSE, FALSE, 0); |
|
555 |
||
556 |
option_menu = gtk_combo_box_text_new (); |
|
557 |
g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu); |
|
558 |
gtk_widget_set_sensitive (option_menu, FALSE); |
|
559 |
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (option_menu), "small toolbar"); |
|
560 |
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (option_menu), "large toolbar"); |
|
561 |
||
562 |
gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0); |
|
563 |
g_signal_connect (option_menu, "changed", |
|
564 |
G_CALLBACK (icon_size_history_changed), toolbar); |
|
565 |
||
566 |
scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
|
567 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), |
|
568 |
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
569 |
gtk_widget_set_hexpand (scrolled_window, TRUE); |
570 |
gtk_widget_set_vexpand (scrolled_window, TRUE); |
|
571 |
gtk_grid_attach (GTK_GRID (grid), scrolled_window, 1, 3, 1, 1); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
572 |
|
573 |
store = create_items_list (&treeview); |
|
574 |
gtk_container_add (GTK_CONTAINER (scrolled_window), treeview); |
|
575 |
||
576 |
item = gtk_tool_button_new_from_stock (GTK_STOCK_NEW); |
|
577 |
gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Custom label"); |
|
578 |
gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), NULL); |
|
579 |
add_item_to_list (store, item, "New"); |
|
580 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
581 |
gdk_threads_add_timeout (3000, (GSourceFunc) timeout_cb, item); |
|
582 |
gtk_tool_item_set_expand (item, TRUE); |
|
583 |
||
584 |
menu = gtk_menu_new (); |
|
585 |
for (i = 0; i < 20; i++) |
|
586 |
{
|
|
587 |
char *text; |
|
588 |
text = g_strdup_printf ("Menuitem %d", i); |
|
589 |
menuitem = gtk_menu_item_new_with_label (text); |
|
590 |
g_free (text); |
|
591 |
gtk_widget_show (menuitem); |
|
592 |
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); |
|
593 |
}
|
|
594 |
||
595 |
item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN); |
|
596 |
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu); |
|
597 |
add_item_to_list (store, item, "Open"); |
|
598 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
599 |
gdk_threads_add_timeout (3000, (GSourceFunc) timeout_cb1, item); |
|
600 |
||
601 |
menu = gtk_menu_new (); |
|
602 |
for (i = 0; i < 20; i++) |
|
603 |
{
|
|
604 |
char *text; |
|
605 |
text = g_strdup_printf ("A%d", i); |
|
606 |
menuitem = gtk_menu_item_new_with_label (text); |
|
607 |
g_free (text); |
|
608 |
gtk_widget_show (menuitem); |
|
609 |
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); |
|
610 |
}
|
|
611 |
||
612 |
item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_BACK); |
|
613 |
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu); |
|
614 |
add_item_to_list (store, item, "BackWithHistory"); |
|
615 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
616 |
||
617 |
item = gtk_separator_tool_item_new (); |
|
618 |
add_item_to_list (store, item, "-----"); |
|
619 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
620 |
||
621 |
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG); |
|
622 |
item = gtk_tool_item_new (); |
|
623 |
gtk_widget_show (image); |
|
624 |
gtk_container_add (GTK_CONTAINER (item), image); |
|
625 |
add_item_to_list (store, item, "(Custom Item)"); |
|
626 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
627 |
||
628 |
item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK); |
|
629 |
add_item_to_list (store, item, "Back"); |
|
630 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
631 |
||
632 |
item = gtk_separator_tool_item_new (); |
|
633 |
add_item_to_list (store, item, "-----"); |
|
634 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
635 |
||
636 |
item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD); |
|
637 |
add_item_to_list (store, item, "Forward"); |
|
638 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
639 |
||
640 |
item = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_BOLD); |
|
641 |
g_signal_connect (item, "toggled", G_CALLBACK (bold_toggled), NULL); |
|
642 |
add_item_to_list (store, item, "Bold"); |
|
643 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
644 |
gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); |
|
645 |
||
646 |
item = gtk_separator_tool_item_new (); |
|
647 |
add_item_to_list (store, item, "-----"); |
|
648 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
649 |
gtk_tool_item_set_expand (item, TRUE); |
|
650 |
gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE); |
|
651 |
g_assert (gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0) != 0); |
|
652 |
||
653 |
item = gtk_radio_tool_button_new_from_stock (NULL, GTK_STOCK_JUSTIFY_LEFT); |
|
654 |
group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item)); |
|
655 |
add_item_to_list (store, item, "Left"); |
|
656 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
657 |
||
658 |
||
659 |
item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_CENTER); |
|
660 |
make_prop_editor (G_OBJECT (item)); |
|
661 |
||
662 |
group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item)); |
|
663 |
add_item_to_list (store, item, "Center"); |
|
664 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
665 |
||
666 |
item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_RIGHT); |
|
667 |
add_item_to_list (store, item, "Right"); |
|
668 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
669 |
||
670 |
item = gtk_tool_button_new (gtk_image_new_from_file ("apple-red.png"), "_Apple"); |
|
671 |
add_item_to_list (store, item, "Apple"); |
|
672 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
673 |
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (item), TRUE); |
|
674 |
||
675 |
gicon = g_content_type_get_icon ("video/ogg"); |
|
676 |
image = gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_LARGE_TOOLBAR); |
|
677 |
g_object_unref (gicon); |
|
678 |
item = gtk_tool_button_new (image, "Video"); |
|
679 |
add_item_to_list (store, item, "Video"); |
|
680 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
681 |
||
682 |
image = gtk_image_new_from_icon_name ("utilities-terminal", GTK_ICON_SIZE_LARGE_TOOLBAR); |
|
683 |
item = gtk_tool_button_new (image, "Terminal"); |
|
684 |
add_item_to_list (store, item, "Terminal"); |
|
685 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
686 |
||
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
687 |
image = gtk_spinner_new (); |
688 |
gtk_spinner_start (GTK_SPINNER (image)); |
|
689 |
item = gtk_tool_button_new (image, "Spinner"); |
|
690 |
add_item_to_list (store, item, "Spinner"); |
|
691 |
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |
|
692 |
||
1
by Michael Terry
Import upstream version 2.91.3 |
693 |
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); |
694 |
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
|
1.1.19
by Sebastien Bacher
Import upstream version 3.4.2 |
695 |
gtk_widget_set_hexpand (hbox, TRUE); |
696 |
gtk_grid_attach (GTK_GRID (grid), hbox, 1, 4, 1, 1); |
|
1
by Michael Terry
Import upstream version 2.91.3 |
697 |
|
698 |
button = gtk_button_new_with_label ("Drag me to the toolbar"); |
|
699 |
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); |
|
700 |
||
701 |
label = gtk_label_new ("Drop index:"); |
|
702 |
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); |
|
703 |
||
704 |
label = gtk_label_new (""); |
|
705 |
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); |
|
706 |
||
707 |
checkbox = gtk_check_button_new_with_mnemonic("_Right to left"); |
|
708 |
if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) |
|
709 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE); |
|
710 |
else
|
|
711 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), FALSE); |
|
712 |
g_signal_connect (checkbox, "toggled", G_CALLBACK (rtl_toggled), NULL); |
|
713 |
||
714 |
gtk_box_pack_end (GTK_BOX (hbox), checkbox, FALSE, FALSE, 0); |
|
715 |
||
716 |
gtk_drag_source_set (button, GDK_BUTTON1_MASK, |
|
717 |
target_table, G_N_ELEMENTS (target_table), |
|
718 |
GDK_ACTION_MOVE); |
|
719 |
gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP, |
|
720 |
target_table, G_N_ELEMENTS (target_table), |
|
721 |
GDK_ACTION_MOVE); |
|
722 |
g_signal_connect (toolbar, "drag_motion", |
|
723 |
G_CALLBACK (toolbar_drag_motion), NULL); |
|
724 |
g_signal_connect (toolbar, "drag_leave", |
|
725 |
G_CALLBACK (toolbar_drag_leave), NULL); |
|
726 |
g_signal_connect (toolbar, "drag_drop", |
|
727 |
G_CALLBACK (toolbar_drag_drop), label); |
|
728 |
||
729 |
gtk_widget_show_all (window); |
|
730 |
||
731 |
make_prop_editor (G_OBJECT (toolbar)); |
|
732 |
||
733 |
g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL); |
|
734 |
||
735 |
g_signal_connect (toolbar, "popup_context_menu", G_CALLBACK (popup_context_menu), NULL); |
|
736 |
||
737 |
gtk_main (); |
|
738 |
||
739 |
return 0; |
|
740 |
}
|