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