]> git.sur5r.net Git - glabels/blob - glabels2/src/ui.c
62b67d4ecc56a87d56b837be2da05e7f1172e8c6
[glabels] / glabels2 / src / ui.c
1 /*
2  *  ui.c
3  *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels 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
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "ui.h"
24
25 #include <glib/gi18n.h>
26 #include <gconf/gconf-client.h>
27 #include <gtk/gtk.h>
28 #include <string.h>
29
30 #include "ui-util.h"
31 #include "ui-commands.h"
32 #include "file.h"
33 #include "prefs.h"
34 #include "stock.h"
35 #include "window.h"
36 #include "recent.h" 
37
38 #include "debug.h"
39
40
41 /*==========================================================================*/
42 /* Private macros and constants.                                            */
43 /*==========================================================================*/
44
45
46 /*==========================================================================*/
47 /* Private types.                                                           */
48 /*==========================================================================*/
49
50
51 /*==========================================================================*/
52 /* Local function prototypes                                                */
53 /*==========================================================================*/
54
55 static void view_ui_item_toggled_cb        (GtkToggleAction *action,
56                                             GtkUIManager    *ui);
57
58 static void set_app_main_toolbar_style     (GtkUIManager    *ui);
59
60 static void set_app_drawing_toolbar_style  (GtkUIManager    *ui);
61
62 static void set_view_style                 (GtkUIManager    *ui);
63
64 static void connect_proxy_cb               (GtkUIManager    *ui,
65                                             GtkAction       *action,
66                                             GtkWidget       *proxy,
67                                             glWindow        *window);
68
69 static void disconnect_proxy_cb            (GtkUIManager    *ui,
70                                             GtkAction       *action,
71                                             GtkWidget       *proxy,
72                                             glWindow        *window);
73
74 static void menu_item_select_cb            (GtkMenuItem     *proxy,
75                                             glWindow        *window);
76
77 static void menu_item_deselect_cb          (GtkMenuItem     *proxy,
78                                             glWindow        *window);
79
80
81 /*==========================================================================*/
82 /* Private globals                                                          */
83 /*==========================================================================*/
84
85 static GtkActionEntry entries[] = {
86
87         /* Menu entries. */
88         { "FileMenu",                NULL, N_("_File") },
89         { "FileRecentsMenu",         NULL, N_("Open Recent _Files") },
90         { "EditMenu",                NULL, N_("_Edit") },
91         { "ViewMenu",                NULL, N_("_View") },
92         { "ViewMainToolBarMenu",     NULL, N_("Customize Main Toolbar") },
93         { "ViewDrawingToolBarMenu",  NULL, N_("Customize Drawing Toolbar") },
94         { "ViewPropertyToolBarMenu", NULL, N_("Customize Properties Toolbar") },
95         { "ObjectsMenu",             NULL, N_("_Objects") },
96         { "ObjectsCreateMenu",       NULL, N_("_Create") },
97         { "ObjectsOrderMenu",        NULL, N_("_Order") },
98         { "ObjectsRotateFlipMenu",   NULL, N_("_Rotate/Flip") },
99         { "ObjectsAlignHorizMenu",   NULL, N_("Align _Horizontal") },
100         { "ObjectsAlignVertMenu",    NULL, N_("Align _Vertical") },
101         { "HelpMenu",                NULL, N_("_Help") },
102
103         /* Popup entries. */
104         { "ContextMenu", NULL, N_("Context Menu") },
105         { "EmptySelectionContextMenu", NULL, N_("Context Menu") },
106
107         /* File action entries. */
108         { "FileNew",
109           GTK_STOCK_NEW,
110           N_("_New"),
111           "<control>N",
112           N_("Create a new file"),
113           G_CALLBACK (gl_ui_cmd_file_new) },
114
115         { "FileOpen",
116           GTK_STOCK_OPEN,
117           N_("_Open..."),
118           "<control>O",
119           N_("Open a file"),
120           G_CALLBACK (gl_ui_cmd_file_open) },
121
122         { "FileSave",
123           GTK_STOCK_SAVE,
124           N_("_Save"),
125           "<control>S",
126           N_("Save current file"),
127           G_CALLBACK (gl_ui_cmd_file_save) },
128
129         { "FileSaveAs",
130           GTK_STOCK_SAVE,
131           N_("Save _As..."),
132           "<shift><control>S",
133           N_("Save the current file to a different name"),
134           G_CALLBACK (gl_ui_cmd_file_save_as) },
135
136         { "FilePrint",
137           GTK_STOCK_PRINT,
138           N_("_Print..."),
139           "<control>P",
140           N_("Print the current file"),
141           G_CALLBACK (gl_ui_cmd_file_print) },
142
143         { "FileProperties",
144           GTK_STOCK_PROPERTIES,
145           N_("Properties..."),
146           NULL,
147           N_("Modify document properties"),
148           G_CALLBACK (gl_ui_cmd_file_properties) },
149
150         { "FileTemplateDesigner",
151           NULL,
152           N_("Template _Designer..."),
153           NULL,
154           N_("Create a custom template"),
155           G_CALLBACK (gl_ui_cmd_file_template_designer) },
156
157         { "FileClose",
158           GTK_STOCK_CLOSE,
159           N_("_Close"),
160           "<alt>F4",
161           N_("Close the current file"),
162           G_CALLBACK (gl_ui_cmd_file_close) },
163
164         { "FileQuit",
165           GTK_STOCK_QUIT,
166           N_("_Quit"),
167           "<control>Q",
168           N_("Quit the program"),
169           G_CALLBACK (gl_ui_cmd_file_quit) },
170
171
172         /* Edit action entries. */
173         { "EditCut",
174           GTK_STOCK_CUT,
175           N_("Cut"),
176           "<control>X",
177           N_("Cut the selection"),
178           G_CALLBACK (gl_ui_cmd_edit_cut) },
179
180         { "EditCopy",
181           GTK_STOCK_COPY,
182           N_("Copy"),
183           "<control>C",
184           N_("Copy the selection"),
185           G_CALLBACK (gl_ui_cmd_edit_copy) },
186
187         { "EditPaste",
188           GTK_STOCK_PASTE,
189           N_("Paste"),
190           "<control>V",
191           N_("Paste the clipboard"),
192           G_CALLBACK (gl_ui_cmd_edit_paste) },
193
194         { "EditDelete",
195           NULL,
196           N_("Delete"),
197           NULL,
198           N_("Delete the selected objects"),
199           G_CALLBACK (gl_ui_cmd_edit_delete) },
200
201         { "EditSelectAll",
202           NULL,
203           N_("Select All"),
204           "<control>A",
205           N_("Select all objects"),
206           G_CALLBACK (gl_ui_cmd_edit_select_all) },
207
208         { "EditUnSelectAll",
209           NULL,
210           N_("Un-select All"),
211           NULL,
212           N_("Remove all selections"),
213           G_CALLBACK (gl_ui_cmd_edit_unselect_all) },
214
215         { "EditPreferences",
216           GTK_STOCK_PREFERENCES,
217           N_("Preferences"),
218           NULL,
219           N_("Configure the application"),
220           G_CALLBACK (gl_ui_cmd_edit_preferences) },
221
222
223         /* View action entries. */
224         { "ViewZoomIn",
225           GTK_STOCK_ZOOM_IN,
226           N_("Zoom in"),
227           NULL,
228           N_("Increase magnification"),
229           G_CALLBACK (gl_ui_cmd_view_zoomin) },
230
231         { "ViewZoomOut",
232           GTK_STOCK_ZOOM_OUT,
233           N_("Zoom out"),
234           NULL,
235           N_("Decrease magnification"),
236           G_CALLBACK (gl_ui_cmd_view_zoomout) },
237
238         { "ViewZoom1to1",
239           GTK_STOCK_ZOOM_100,
240           N_("Zoom 1 to 1"),
241           NULL,
242           N_("Restore scale to 100%"),
243           G_CALLBACK (gl_ui_cmd_view_zoom1to1) },
244
245         { "ViewZoomToFit",
246           GTK_STOCK_ZOOM_FIT,
247           N_("Zoom to fit"),
248           NULL,
249           N_("Set scale to fit window"),
250           G_CALLBACK (gl_ui_cmd_view_zoom_to_fit) },
251
252
253         /* Objects action entries. */
254         { "ObjectsArrowMode",
255           GL_STOCK_ARROW,
256           N_("Select Mode"),
257           NULL,
258           N_("Select, move and modify objects"),
259           G_CALLBACK (gl_ui_cmd_objects_arrow_mode) },
260
261         { "ObjectsCreateText",
262           GL_STOCK_TEXT,
263           N_("Text"),
264           NULL,
265           N_("Create text object"),
266           G_CALLBACK (gl_ui_cmd_objects_create_text) },
267
268         { "ObjectsCreateBox",
269           GL_STOCK_BOX,
270           N_("Box"),
271           NULL,
272           N_("Create box/rectangle object"),
273           G_CALLBACK (gl_ui_cmd_objects_create_box) },
274
275         { "ObjectsCreateLine",
276           GL_STOCK_LINE,
277           N_("Line"),
278           NULL,
279           N_("Create line object"),
280           G_CALLBACK (gl_ui_cmd_objects_create_line) },
281
282         { "ObjectsCreateEllipse",
283           GL_STOCK_ELLIPSE,
284           N_("Ellipse"),
285           NULL,
286           N_("Create ellipse/circle object"),
287           G_CALLBACK (gl_ui_cmd_objects_create_ellipse) },
288
289         { "ObjectsCreateImage",
290           GL_STOCK_IMAGE,
291           N_("Image"),
292           NULL,
293           N_("Create image object"),
294           G_CALLBACK (gl_ui_cmd_objects_create_image) },
295
296         { "ObjectsCreateBarcode",
297           GL_STOCK_BARCODE,
298           N_("Barcode"),
299           NULL,
300           N_("Create barcode object"),
301           G_CALLBACK (gl_ui_cmd_objects_create_barcode) },
302         
303         { "ObjectsRaise",
304           GL_STOCK_ORDER_TOP,
305           N_("Bring to front"),
306           NULL,
307           N_("Raise object to top"),
308           G_CALLBACK (gl_ui_cmd_objects_raise) },
309
310         { "ObjectsLower",
311           GL_STOCK_ORDER_BOTTOM,
312           N_("Send to back"),
313           NULL,
314           N_("Lower object to bottom"),
315           G_CALLBACK (gl_ui_cmd_objects_lower) },
316
317         { "ObjectsRotateLeft",
318           GL_STOCK_ROTATE_LEFT,
319           N_("Rotate left"),
320           NULL,
321           N_("Rotate object 90 degrees counter-clockwise"),
322           G_CALLBACK (gl_ui_cmd_objects_rotate_left) },
323
324         { "ObjectsRotateRight",
325           GL_STOCK_ROTATE_RIGHT,
326           N_("Rotate right"),
327           NULL,
328           N_("Rotate object 90 degrees clockwise"),
329           G_CALLBACK (gl_ui_cmd_objects_rotate_right) },
330
331         { "ObjectsFlipHorizontal",
332           GL_STOCK_FLIP_HORIZ,
333           N_("Flip horizontally"),
334           NULL,
335           N_("Flip object horizontally"),
336           G_CALLBACK (gl_ui_cmd_objects_flip_horiz) },
337
338         { "ObjectsFlipVertical",
339           GL_STOCK_FLIP_VERT,
340           N_("Flip vertically"),
341           NULL,
342           N_("Flip object vertically"),
343           G_CALLBACK (gl_ui_cmd_objects_flip_vert) },
344
345         { "ObjectsAlignLeft",
346           GL_STOCK_ALIGN_LEFT,
347           N_("Align left"),
348           NULL,
349           N_("Align objects to left edges"),
350           G_CALLBACK (gl_ui_cmd_objects_align_left) },
351
352         { "ObjectsAlignRight",
353           GL_STOCK_ALIGN_RIGHT,
354           N_("Align right"),
355           NULL,
356           N_("Align objects to right edges"),
357           G_CALLBACK (gl_ui_cmd_objects_align_right) },
358
359         { "ObjectsAlignHCenter",
360           GL_STOCK_ALIGN_HCENTER,
361           N_("Align horizontal center"),
362           NULL,
363           N_("Align objects to horizontal centers"),
364           G_CALLBACK (gl_ui_cmd_objects_align_hcenter) },
365
366         { "ObjectsAlignTop",
367           GL_STOCK_ALIGN_TOP,
368           N_("Align tops"),
369           NULL,
370           N_("Align objects to top edges"),
371           G_CALLBACK (gl_ui_cmd_objects_align_top) },
372
373         { "ObjectsAlignBottom",
374           GL_STOCK_ALIGN_BOTTOM,
375           N_("Align bottoms"),
376           NULL,
377           N_("Align objects to bottom edges"),
378           G_CALLBACK (gl_ui_cmd_objects_align_bottom) },
379
380         { "ObjectsAlignVCenter",
381           GL_STOCK_ALIGN_VCENTER,
382           N_("Align vertical center"),
383           NULL,
384           N_("Align objects to vertical centers"),
385           G_CALLBACK (gl_ui_cmd_objects_align_vcenter) },
386
387         { "ObjectsCenterHorizontal",
388           GL_STOCK_CENTER_HORIZ,
389           N_("Center horizontally"),
390           NULL,
391           N_("Center objects to horizontal label center"),
392           G_CALLBACK (gl_ui_cmd_objects_center_horiz) },
393
394         { "ObjectsCenterVertical",
395           GL_STOCK_CENTER_VERT,
396           N_("Center vertically"),
397           NULL,
398           N_("Center objects to vertical label center"),
399           G_CALLBACK (gl_ui_cmd_objects_center_vert) },
400
401         { "ObjectsMergeProperties",
402           GL_STOCK_MERGE,
403           N_("Merge properties"),
404           NULL,
405           N_("Edit merge properties"),
406           G_CALLBACK (gl_ui_cmd_objects_merge_properties) },
407
408
409         /* Help actions entries. */
410         { "HelpContents",
411           GTK_STOCK_HELP,
412           N_("Contents"),
413           "F1",
414           N_("Open glabels manual"),
415           G_CALLBACK (gl_ui_cmd_help_contents) },
416
417         { "HelpAbout",
418           GTK_STOCK_ABOUT,
419           N_("About..."),
420           NULL,
421           N_("About glabels"),
422           G_CALLBACK (gl_ui_cmd_help_about) },
423
424 };
425 static guint n_entries = G_N_ELEMENTS (entries);
426
427 static GtkToggleActionEntry toggle_entries[] = {
428
429         { "ViewPropertyToolBar",
430           NULL,
431           N_("Property toolbar"),
432           NULL,
433           N_("Change the visibility of the property toolbar in the current window"),
434           G_CALLBACK (gl_ui_cmd_view_property_bar_toggle),
435           TRUE },
436
437         { "ViewGrid",
438           NULL,
439           N_("Grid"),
440           NULL,
441           N_("Change the visibility of the grid in the current window"),
442           G_CALLBACK (gl_ui_cmd_view_grid_toggle),
443           TRUE },
444
445         { "ViewMarkup",
446           NULL,
447           N_("Markup"),
448           NULL,
449           N_("Change the visibility of markup lines in the current window"),
450           G_CALLBACK (gl_ui_cmd_view_markup_toggle),
451           TRUE },
452
453 };
454 static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
455
456 static GtkToggleActionEntry ui_toggle_entries[] = {
457
458         { "ViewMainToolBar",
459           NULL,
460           N_("Main toolbar"),
461           NULL,
462           N_("Change the visibility of the main toolbar in the current window"),
463           G_CALLBACK (view_ui_item_toggled_cb),
464           TRUE },
465
466         { "ViewDrawingToolBar",
467           NULL,
468           N_("Drawing toolbar"),
469           NULL,
470           N_("Change the visibility of the drawing toolbar in the current window"),
471           G_CALLBACK (view_ui_item_toggled_cb),
472           TRUE },
473
474 };
475 static guint n_ui_toggle_entries = G_N_ELEMENTS (ui_toggle_entries);
476
477 static const gchar *ui_info = 
478 "<ui>"
479 ""
480 "       <menubar name='MenuBar'>"
481 "               <menu action='FileMenu'>"
482 "                       <menuitem action='FileNew' />"
483 "                       <menuitem action='FileOpen' />"
484 "                       <menuitem action='FileRecentsMenu' />"
485 "                       <separator />"
486 "                       <menuitem action='FileSave' />"
487 "                       <menuitem action='FileSaveAs' />"
488 "                       <separator />"
489 "                       <menuitem action='FilePrint' />"
490 "                       <separator />"
491 "                       <menuitem action='FileProperties' />"
492 "                       <menuitem action='FileTemplateDesigner' />"
493 "                       <separator />"
494 "                       <menuitem action='FileClose' />"
495 "                       <menuitem action='FileQuit' />"
496 "               </menu>"
497 "               <menu action='EditMenu'>"
498 "                       <menuitem action='EditCut' />"
499 "                       <menuitem action='EditCopy' />"
500 "                       <menuitem action='EditPaste' />"
501 "                       <menuitem action='EditDelete' />"
502 "                       <separator />"
503 "                       <menuitem action='EditSelectAll' />"
504 "                       <menuitem action='EditUnSelectAll' />"
505 "                       <separator />"
506 "                       <menuitem action='EditPreferences' />"
507 "               </menu>"
508 "               <menu action='ViewMenu'>"
509 "                       <menuitem action='ViewMainToolBar' />"
510 "                       <menuitem action='ViewDrawingToolBar' />"
511 "                       <menuitem action='ViewPropertyToolBar' />"
512 "                       <separator />"
513 "                       <menuitem action='ViewGrid' />"
514 "                       <menuitem action='ViewMarkup' />"
515 "                       <separator />"
516 "                       <menuitem action='ViewZoomIn' />"
517 "                       <menuitem action='ViewZoomOut' />"
518 "                       <menuitem action='ViewZoom1to1' />"
519 "                       <menuitem action='ViewZoomToFit' />"
520 "               </menu>"
521 "               <menu action='ObjectsMenu'>"
522 "                       <menuitem action='ObjectsArrowMode' />"
523 "                       <menu action='ObjectsCreateMenu'>"
524 "                               <menuitem action='ObjectsCreateText' />"
525 "                               <menuitem action='ObjectsCreateBox' />"
526 "                               <menuitem action='ObjectsCreateLine' />"
527 "                               <menuitem action='ObjectsCreateEllipse' />"
528 "                               <menuitem action='ObjectsCreateImage' />"
529 "                               <menuitem action='ObjectsCreateBarcode' />"
530 "                       </menu>"
531 "                       <separator />"
532 "                       <menu action='ObjectsOrderMenu'>"
533 "                               <menuitem action='ObjectsRaise' />"
534 "                               <menuitem action='ObjectsLower' />"
535 "                       </menu>"
536 "                       <menu action='ObjectsRotateFlipMenu'>"
537 "                               <menuitem action='ObjectsRotateLeft' />"
538 "                               <menuitem action='ObjectsRotateRight' />"
539 "                               <menuitem action='ObjectsFlipHorizontal' />"
540 "                               <menuitem action='ObjectsFlipVertical' />"
541 "                       </menu>"
542 "                       <menu action='ObjectsAlignHorizMenu'>"
543 "                               <menuitem action='ObjectsAlignLeft' />"
544 "                               <menuitem action='ObjectsAlignHCenter' />"
545 "                               <menuitem action='ObjectsAlignRight' />"
546 "                               <menuitem action='ObjectsCenterHorizontal' />"
547 "                       </menu>"
548 "                       <menu action='ObjectsAlignVertMenu'>"
549 "                               <menuitem action='ObjectsAlignTop' />"
550 "                               <menuitem action='ObjectsAlignVCenter' />"
551 "                               <menuitem action='ObjectsAlignBottom' />"
552 "                               <menuitem action='ObjectsCenterVertical' />"
553 "                       </menu>"
554 "                       <separator />"
555 "                       <menuitem action='ObjectsMergeProperties' />"
556 "               </menu>"
557 "               <menu action='HelpMenu'>"
558 "                       <menuitem action='HelpContents' />"
559 "                       <menuitem action='HelpAbout' />"
560 "               </menu>"
561 "       </menubar>"
562 ""
563 "       <toolbar name='MainToolBar'>"
564 "               <toolitem action='FileNew' />"
565 "               <toolitem action='FileOpen' />"
566 "               <toolitem action='FileSave' />"
567 "               <separator />"
568 "               <toolitem action='FilePrint' />"
569 "               <separator />"
570 "               <toolitem action='EditCut' />"
571 "               <toolitem action='EditCopy' />"
572 "               <toolitem action='EditPaste' />"
573 "       </toolbar>"
574 ""
575 "       <toolbar name='DrawingToolBar'>"
576 "               <toolitem action='ObjectsArrowMode' />"
577 "               <separator />"
578 "               <toolitem action='ObjectsCreateText' />"
579 "               <toolitem action='ObjectsCreateBox' />"
580 "               <toolitem action='ObjectsCreateLine' />"
581 "               <toolitem action='ObjectsCreateEllipse' />"
582 "               <toolitem action='ObjectsCreateImage' />"
583 "               <toolitem action='ObjectsCreateBarcode' />"
584 "               <separator />"
585 "               <toolitem action='ViewZoomIn' />"
586 "               <toolitem action='ViewZoomOut' />"
587 "               <toolitem action='ViewZoom1to1' />"
588 "               <toolitem action='ViewZoomToFit' />"
589 "               <separator />"
590 "               <toolitem action='ObjectsMergeProperties' />"
591 "       </toolbar>"
592 ""
593 "       <popup action='ContextMenu'>"
594 "               <menu action='ObjectsOrderMenu'>"
595 "                       <menuitem action='ObjectsRaise' />"
596 "                       <menuitem action='ObjectsLower' />"
597 "               </menu>"
598 "               <menu action='ObjectsRotateFlipMenu'>"
599 "                       <menuitem action='ObjectsRotateLeft' />"
600 "                       <menuitem action='ObjectsRotateRight' />"
601 "                       <menuitem action='ObjectsFlipHorizontal' />"
602 "                       <menuitem action='ObjectsFlipVertical' />"
603 "               </menu>"
604 "               <menu action='ObjectsAlignHorizMenu'>"
605 "                       <menuitem action='ObjectsAlignLeft' />"
606 "                       <menuitem action='ObjectsAlignHCenter' />"
607 "                       <menuitem action='ObjectsAlignRight' />"
608 "                       <menuitem action='ObjectsCenterHorizontal' />"
609 "               </menu>"
610 "               <menu action='ObjectsAlignVertMenu'>"
611 "                       <menuitem action='ObjectsAlignTop' />"
612 "                       <menuitem action='ObjectsAlignVCenter' />"
613 "                       <menuitem action='ObjectsAlignBottom' />"
614 "                       <menuitem action='ObjectsCenterVertical' />"
615 "               </menu>"
616 "               <separator />"
617 "               <menuitem action='EditCut' />"
618 "               <menuitem action='EditCopy' />"
619 "               <menuitem action='EditPaste' />"
620 "               <menuitem action='EditDelete' />"
621 "       </popup>"
622 ""
623 "       <popup action='EmptySelectionContextMenu'>"
624 "               <menuitem action='EditPaste' />"
625 "       </popup>"
626 ""
627 "</ui>";
628
629
630 static gchar* doc_verbs [] = {
631         "/ui/MenuBar/FileMenu/FileProperties",
632         "/ui/MenuBar/FileMenu/FileSave",
633         "/ui/MenuBar/FileMenu/FileSaveAs",
634         "/ui/MenuBar/FileMenu/FilePrint",
635         "/ui/MenuBar/FileMenu/FileClose",
636         "/ui/MenuBar/EditMenu/EditCut",
637         "/ui/MenuBar/EditMenu/EditCopy",
638         "/ui/MenuBar/EditMenu/EditPaste",
639         "/ui/MenuBar/EditMenu/EditDelete",
640         "/ui/MenuBar/EditMenu/EditSelectAll",
641         "/ui/MenuBar/EditMenu/EditUnSelectAll",
642         "/ui/MenuBar/ViewMenu/ViewZoomIn",
643         "/ui/MenuBar/ViewMenu/ViewZoomOut",
644         "/ui/MenuBar/ViewMenu/ViewZoom1to1",
645         "/ui/MenuBar/ViewMenu/ViewZoomToFit",
646         "/ui/MenuBar/ViewMenu/ViewGrid",
647         "/ui/MenuBar/ViewMenu/ViewMarkup",
648         "/ui/MenuBar/ObjectsMenu/ObjectsArrowMode",
649         "/ui/MenuBar/ObjectsMenu/ObjectsCreateMenu/ObjectsCreateText",
650         "/ui/MenuBar/ObjectsMenu/ObjectsCreateMenu/ObjectsCreateLine",
651         "/ui/MenuBar/ObjectsMenu/ObjectsCreateMenu/ObjectsCreateBox",
652         "/ui/MenuBar/ObjectsMenu/ObjectsCreateMenu/ObjectsCreateEllipse",
653         "/ui/MenuBar/ObjectsMenu/ObjectsCreateMenu/ObjectsCreateImage",
654         "/ui/MenuBar/ObjectsMenu/ObjectsCreateMenu/ObjectsCreateBarcode",
655         "/ui/MenuBar/ObjectsMenu/ObjectsOrderMenu/ObjectsRaise",
656         "/ui/MenuBar/ObjectsMenu/ObjectsOrderMenu/ObjectsLower",
657         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsRotateLeft",
658         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsRotateRight",
659         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsFlipHorizontal",
660         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsFlipVertical",
661         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsAlignLeft",
662         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsAlignRight",
663         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsAlignHCenter",
664         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsCenterHorizontal",
665         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsAlignTop",
666         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsAlignBottom",
667         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsAlignVCenter",
668         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsCenterVertical",
669         "/ui/MenuBar/ObjectsMenu/ObjectsMergeProperties",
670
671         NULL
672 };
673
674 static gchar* doc_modified_verbs [] = {
675         "/ui/MenuBar/FileMenu/FileSave",
676
677         NULL
678 };
679
680 static gchar* selection_verbs [] = {
681         "/ui/MenuBar/EditMenu/EditCut",
682         "/ui/MenuBar/EditMenu/EditCopy",
683         "/ui/MenuBar/EditMenu/EditDelete",
684         "/ui/MenuBar/EditMenu/EditUnSelectAll",
685         "/ui/MenuBar/ObjectsMenu/ObjectsOrderMenu/ObjectsRaise",
686         "/ui/MenuBar/ObjectsMenu/ObjectsOrderMenu/ObjectsLower",
687         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsRotateLeft",
688         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsRotateRight",
689         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsFlipHorizontal",
690         "/ui/MenuBar/ObjectsMenu/ObjectsRotateFlipMenu/ObjectsFlipVertical",
691         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsCenterHorizontal",
692         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsCenterVertical",
693
694         NULL
695 };
696
697 static gchar* atomic_selection_verbs [] = {
698
699         NULL
700 };
701
702 static gchar* multi_selection_verbs [] = {
703         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsAlignLeft",
704         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsAlignRight",
705         "/ui/MenuBar/ObjectsMenu/ObjectsAlignHorizMenu/ObjectsAlignHCenter",
706         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsAlignTop",
707         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsAlignBottom",
708         "/ui/MenuBar/ObjectsMenu/ObjectsAlignVertMenu/ObjectsAlignVCenter",
709
710         NULL
711 };
712
713
714 /*****************************************************************************/
715 /** Initialize UI component for given window.                                */
716 /*****************************************************************************/
717 GtkUIManager *
718 gl_ui_new (glWindow *window)
719 {
720         GtkUIManager            *ui;
721         GtkActionGroup          *actions;
722         GError                  *error = NULL;
723         GtkWidget               *recent_menu;
724
725         gl_debug (DEBUG_UI, "START");
726
727         g_return_val_if_fail (window && GL_IS_WINDOW (window), NULL);
728
729         gl_debug (DEBUG_UI, "window = %p", window);
730
731         ui = gtk_ui_manager_new ();
732
733         g_signal_connect (ui, "connect_proxy",
734                           G_CALLBACK (connect_proxy_cb), window);
735         g_signal_connect (ui, "disconnect_proxy",
736                           G_CALLBACK (disconnect_proxy_cb), window);
737
738         actions = gtk_action_group_new ("Actions");
739         gtk_action_group_set_translation_domain (actions, NULL);
740         gtk_action_group_add_actions (actions, entries, n_entries, GTK_WINDOW (window));
741         gtk_action_group_add_toggle_actions (actions, 
742                                              toggle_entries, n_toggle_entries, 
743                                              window);
744         gtk_action_group_add_toggle_actions (actions, 
745                                              ui_toggle_entries, n_ui_toggle_entries, 
746                                              ui);
747
748         gtk_ui_manager_insert_action_group (ui, actions, 0);
749         gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (ui));
750
751         gl_debug (DEBUG_UI, "Creating ui from string");
752         if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, strlen (ui_info), &error)) {
753                 g_message ("building menus failed: %s", error->message);
754                 g_error_free (error);
755         }
756
757         /* Set the toolbar styles according to prefs */
758         set_app_main_toolbar_style (ui);
759         set_app_drawing_toolbar_style (ui);
760                 
761         /* Set view grid and markup visibility according to prefs */
762         set_view_style (ui);
763                 
764         /* add an Open Recents Submenu */
765         recent_menu  = gl_recent_create_menu ();
766         g_signal_connect (G_OBJECT (recent_menu), "item-activated",
767                           G_CALLBACK (gl_ui_cmd_file_open_recent), window);
768         gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget (ui, "/MenuBar/FileMenu/FileRecentsMenu")),
769                                    recent_menu);
770
771
772         gl_ui_util_set_verb_list_sensitive (ui, doc_verbs, FALSE);
773
774         gl_debug (DEBUG_UI, "END");
775
776         return ui;
777 }
778
779
780 /*****************************************************************************/
781 /** Unref wrapper.                                                           */
782 /*****************************************************************************/
783 void
784 gl_ui_unref (GtkUIManager *ui)
785 {
786         gl_debug (DEBUG_UI, "START");
787
788         g_object_unref(ui);
789
790         gl_debug (DEBUG_UI, "END");
791 }
792
793
794 /*****************************************************************************/
795 /** Update all verbs of given UI component.                                  */
796 /*****************************************************************************/
797 void
798 gl_ui_update_all (GtkUIManager *ui,
799                   glView       *view)
800 {
801         glLabel *label;
802
803         gl_debug (DEBUG_UI, "START");
804
805         gl_ui_util_set_verb_list_sensitive (ui, doc_verbs, TRUE);
806
807         label = view->label;
808         g_return_if_fail (label != NULL);
809
810         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/EditMenu/EditUndo",
811                                        gl_label_can_undo (label));
812         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/EditMenu/EditRedo",
813                                        gl_label_can_redo (label));
814
815         gl_ui_util_set_verb_list_sensitive (ui, doc_modified_verbs,
816                                             gl_label_is_modified (label));
817
818         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/ViewMenu/ViewZoomIn",
819                                        !gl_view_is_zoom_max (view));
820         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/ViewMenu/ViewZoomOut",
821                                        !gl_view_is_zoom_min (view));
822
823         gl_ui_util_set_verb_list_sensitive (ui, selection_verbs,
824                                             !gl_view_is_selection_empty (view));
825
826         gl_ui_util_set_verb_list_sensitive (ui, atomic_selection_verbs,
827                                             gl_view_is_selection_atomic (view));
828
829         gl_ui_util_set_verb_list_sensitive (ui, multi_selection_verbs,
830                                             !gl_view_is_selection_empty (view)
831                                             && !gl_view_is_selection_atomic (view));
832
833         gl_debug (DEBUG_UI, "END");
834 }
835
836
837 /*****************************************************************************/
838 /** Update all verbs of given UI component to "no document" state.           */
839 /*****************************************************************************/
840 void
841 gl_ui_update_nodoc (GtkUIManager *ui)
842 {
843         gl_debug (DEBUG_UI, "START");
844
845         gl_ui_util_set_verb_list_sensitive (ui, doc_verbs, FALSE);
846
847         gl_debug (DEBUG_UI, "END");
848 }
849
850
851 /*****************************************************************************/
852 /** Update label modified verbs of given UI component.                       */
853 /*****************************************************************************/
854 void
855 gl_ui_update_modified_verbs (GtkUIManager *ui,
856                              glLabel      *label)
857 {
858         gl_debug (DEBUG_UI, "START");
859
860         gl_ui_util_set_verb_list_sensitive (ui, 
861                                             doc_modified_verbs,
862                                             gl_label_is_modified (label));
863
864         gl_debug (DEBUG_UI, "END");
865 }
866
867
868 /*****************************************************************************/
869 /** Update verbs associated with selection state of given UI component.      */
870 /*****************************************************************************/
871 void
872 gl_ui_update_selection_verbs (GtkUIManager *ui,
873                               glView       *view)
874 {
875         gl_debug (DEBUG_UI, "START");
876
877         gl_ui_util_set_verb_list_sensitive (ui, selection_verbs,
878                                             !gl_view_is_selection_empty (view));
879
880         gl_ui_util_set_verb_list_sensitive (ui, atomic_selection_verbs,
881                                             gl_view_is_selection_atomic (view));
882
883         gl_ui_util_set_verb_list_sensitive (ui, multi_selection_verbs,
884                                             !gl_view_is_selection_empty (view)
885                                             && !gl_view_is_selection_atomic (view));
886
887         gl_debug (DEBUG_UI, "END");
888 }
889
890
891 /*****************************************************************************/
892 /** Update verbs associated with zoom level of given UI component.           */
893 /*****************************************************************************/
894 void
895 gl_ui_update_zoom_verbs (GtkUIManager *ui,
896                          glView       *view)
897 {
898         gl_debug (DEBUG_UI, "START");
899
900         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/ViewMenu/ViewZoomIn",
901                                        !gl_view_is_zoom_max (view));
902         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/ViewMenu/ViewZoomOut",
903                                        !gl_view_is_zoom_min (view));
904
905         gl_debug (DEBUG_UI, "END");
906 }
907
908
909 /*****************************************************************************/
910 /** Update undo/redo verbs of given UI component.                            */
911 /*****************************************************************************/
912 void
913 gl_ui_update_undo_redo_verbs (GtkUIManager *ui,
914                               glLabel      *label)
915 {
916         gl_debug (DEBUG_UI, "START");
917
918         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/EditMenu/EditUndo",
919                                        gl_label_can_undo (label));
920
921         gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/EditMenu/EditRedo",
922                                        gl_label_can_redo (label));
923
924         gl_debug (DEBUG_UI, "END");
925 }
926
927
928 /*---------------------------------------------------------------------------*/
929 /** PRIVATE.  View menu item toggled callback.                               */
930 /*---------------------------------------------------------------------------*/
931 static void
932 view_ui_item_toggled_cb (GtkToggleAction *action,
933                          GtkUIManager    *ui)
934 {
935         const gchar *name;
936         gboolean     state;
937
938         gl_debug (DEBUG_UI, "START");
939
940         g_return_if_fail (action && GTK_IS_TOGGLE_ACTION (action));
941
942         name  = gtk_action_get_name (GTK_ACTION (action));
943         state = gtk_toggle_action_get_active (action);
944
945         gl_debug (DEBUG_UI, "Action = %s, State = %d", name, state);
946
947         if (strcmp (name, "ViewMainToolBar") == 0)
948         {
949                 gl_prefs->main_toolbar_visible = state;
950                 set_app_main_toolbar_style (ui);
951                 gl_prefs_model_save_settings (gl_prefs);
952         }
953
954         if (strcmp (name, "ViewDrawingToolBar") == 0)
955         {
956                 gl_prefs->drawing_toolbar_visible = state;
957                 set_app_drawing_toolbar_style (ui);
958                 gl_prefs_model_save_settings (gl_prefs);
959         }
960
961         gl_debug (DEBUG_UI, "");
962 }
963
964
965 /*---------------------------------------------------------------------------*/
966 /** PRIVATE.  Set main toolbar style.                                        */
967 /*---------------------------------------------------------------------------*/
968 static void
969 set_app_main_toolbar_style (GtkUIManager *ui)
970 {
971         GtkWidget *toolbar;
972
973         gl_debug (DEBUG_UI, "START");
974
975         g_return_if_fail (ui && GTK_IS_UI_MANAGER (ui));
976                         
977         /* Updated view menu */
978         gl_ui_util_set_verb_state (ui, "/ui/ViewMenu/ViewMainToolBar",
979                                    gl_prefs->main_toolbar_visible);
980
981         toolbar = gtk_ui_manager_get_widget (ui, "/MainToolBar");
982
983         if (gl_prefs->main_toolbar_visible) {
984                 gtk_widget_show_all (toolbar);
985         } else {
986                 gtk_widget_hide (toolbar);
987         }
988         
989         gl_debug (DEBUG_UI, "END");
990 }
991
992
993 /*---------------------------------------------------------------------------*/
994 /** PRIVATE.  Set drawing toolbar style.                                     */
995 /*---------------------------------------------------------------------------*/
996 static void
997 set_app_drawing_toolbar_style (GtkUIManager *ui)
998 {
999         GtkWidget *toolbar;
1000
1001         gl_debug (DEBUG_UI, "START");
1002
1003         g_return_if_fail (ui && GTK_IS_UI_MANAGER (ui));
1004                         
1005         /* Updated view menu */
1006         gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenu/ViewDrawingToolBar",
1007                                    gl_prefs->drawing_toolbar_visible);
1008
1009         toolbar = gtk_ui_manager_get_widget (ui, "/DrawingToolBar");
1010
1011         gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
1012
1013         if (gl_prefs->drawing_toolbar_visible) {
1014                 gtk_widget_show_all (toolbar);
1015         } else {
1016                 gtk_widget_hide (toolbar);
1017         }
1018         
1019         gl_debug (DEBUG_UI, "END");
1020 }
1021
1022
1023 /*---------------------------------------------------------------------------*/
1024 /** PRIVATE.  Set visibility of grid and markup.                             */
1025 /*---------------------------------------------------------------------------*/
1026 static void
1027 set_view_style (GtkUIManager *ui)
1028 {
1029         gl_debug (DEBUG_UI, "START");
1030
1031         g_return_if_fail (ui && GTK_IS_UI_MANAGER(ui));
1032                         
1033         gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenu/ViewGrid",
1034                                    gl_prefs->grid_visible);
1035
1036         gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenu/ViewMarkup",
1037                                    gl_prefs->markup_visible);
1038
1039         gl_debug (DEBUG_UI, "END");
1040 }
1041
1042
1043 /*---------------------------------------------------------------------------*/
1044 /** PRIVATE.  Connect proxy callback.                                        */
1045 /*---------------------------------------------------------------------------*/
1046 static void
1047 connect_proxy_cb (GtkUIManager *ui,
1048                   GtkAction    *action,
1049                   GtkWidget    *proxy,
1050                   glWindow     *window)
1051 {
1052         if (GTK_IS_MENU_ITEM (proxy))
1053         {
1054                 g_signal_connect (proxy, "select",
1055                                   G_CALLBACK (menu_item_select_cb), window);
1056                 g_signal_connect (proxy, "deselect",
1057                                   G_CALLBACK (menu_item_deselect_cb), window);
1058         }
1059 }
1060
1061
1062 /*---------------------------------------------------------------------------*/
1063 /** PRIVATE.  Disconnect proxy callback.                                     */
1064 /*---------------------------------------------------------------------------*/
1065 static void
1066 disconnect_proxy_cb (GtkUIManager *ui,
1067                      GtkAction    *action,
1068                      GtkWidget    *proxy,
1069                      glWindow     *window)
1070 {
1071         if (GTK_IS_MENU_ITEM (proxy))
1072         {
1073                 g_signal_handlers_disconnect_by_func
1074                         (proxy, G_CALLBACK (menu_item_select_cb), window);
1075                 g_signal_handlers_disconnect_by_func
1076                         (proxy, G_CALLBACK (menu_item_deselect_cb), window);
1077         }
1078 }
1079
1080
1081 /*---------------------------------------------------------------------------*/
1082 /** PRIVATE.  Menu item select callback.                                     */
1083 /*---------------------------------------------------------------------------*/
1084 static void
1085 menu_item_select_cb (GtkMenuItem *proxy,
1086                      glWindow    *window)
1087 {
1088         GtkAction *action;
1089         char      *message;
1090
1091         g_return_if_fail (window && GL_IS_WINDOW (window));
1092         g_return_if_fail (window->status_bar && GTK_IS_STATUSBAR (window->status_bar));
1093
1094         action = g_object_get_data (G_OBJECT (proxy),  "gtk-action");
1095         g_return_if_fail (action != NULL);
1096         
1097         g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
1098         if (message)
1099         {
1100                 gtk_statusbar_push (GTK_STATUSBAR (window->status_bar),
1101                                     window->menu_tips_context_id, message);
1102                 g_free (message);
1103         }
1104 }
1105
1106
1107 /*---------------------------------------------------------------------------*/
1108 /** PRIVATE.  Menu item deselect callback.                                   */
1109 /*---------------------------------------------------------------------------*/
1110 static void
1111 menu_item_deselect_cb (GtkMenuItem *proxy,
1112                        glWindow    *window)
1113 {
1114         g_return_if_fail (window && GL_IS_WINDOW (window));
1115         g_return_if_fail (window->status_bar && GTK_IS_STATUSBAR (window->status_bar));
1116
1117         gtk_statusbar_pop (GTK_STATUSBAR (window->status_bar),
1118                            window->menu_tips_context_id);
1119 }
1120
1121
1122
1123 /*
1124  * Local Variables:       -- emacs
1125  * mode: C                -- emacs
1126  * c-basic-offset: 8      -- emacs
1127  * tab-width: 8           -- emacs
1128  * indent-tabs-mode: nil  -- emacs
1129  * End:                   -- emacs
1130  */