]> matita.cs.unibo.it Git - helm.git/blob - helm/helmpot/guiGTK.c
- new handling of links
[helm.git] / helm / helmpot / guiGTK.c
1 /*
2  * Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
3  * 
4  * This file is part of HelmPot, a minimal browser for HELM.
5  * 
6  * HelmPot is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * 
11  * HelmPot is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with HelmPot; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  * 
20  * For details, see the HelmPot World-Wide-Web page,
21  * http://cs.unibo.it/helm/helmview, or send a mail to
22  * <luca.padovani@cs.unibo.it>
23  */
24
25 #include <config.h>
26
27 #include <glib.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #if HAVE_UNISTD_H
32 # include <sys/types.h>
33 # include <sys/stat.h>
34 # include <fcntl.h>
35 # include <unistd.h>
36 #endif
37 #include <gtk/gtk.h>
38 #include <gdk/gdkkeysyms.h>
39
40 #include "gtkmathview.h"
41 #include "guiGTK.h"
42
43 #define XLINK_NS_URI "http://www.w3.org/1999/xlink"
44
45 #define pot_width 16
46 #define pot_height 16
47 PRIVATE unsigned char pot_bits[] = {
48    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x07,
49    0x00, 0x00, 0xe6, 0x2f, 0x34, 0x5f, 0xdc, 0x5f, 0xf8, 0x3f, 0xf8, 0x3f,
50    0xf0, 0x1f, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0x00};
51
52 #define pot_mask_width 16
53 #define pot_mask_height 16
54 static unsigned char pot_mask_bits[] = {
55    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xe0, 0x0f, 0xe0, 0x0f,
56    0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfc, 0x7f,
57    0xfc, 0x7f, 0xf8, 0x3f, 0xf0, 0x1f, 0x00, 0x00};
58
59 PRIVATE GtkWidget* window;
60 PRIVATE GtkWidget* main_area;
61 PRIVATE GtkWidget* scrolled_area;
62 PRIVATE GtkWidget* status_bar;
63 PRIVATE GtkMenuItem* kerning_item;
64 PRIVATE GtkMenuItem* anti_aliasing_item;
65 PRIVATE GtkMenuItem* font_size_item;
66 PRIVATE gchar* file_name = NULL;
67
68 PRIVATE GdkCursor* normal_cursor;
69 PRIVATE GdkCursor* link_cursor;  
70 PRIVATE GdkCursor* pot_cursor;
71
72 PRIVATE gboolean loading = FALSE;
73 PRIVATE guint statusbar_context;
74
75 PRIVATE void create_widget_set(void);
76 PRIVATE GtkWidget* get_main_menu(void);
77 PRIVATE void options_font_size(GtkWidget*, guint);
78 PRIVATE void options_font_manager(GtkWidget*, guint);
79 PRIVATE void options_verbosity(GtkWidget*, guint);
80 PRIVATE void options_kerning(GtkWidget*, gpointer);
81 PRIVATE void options_anti_aliasing(GtkWidget*, gpointer);
82 PRIVATE void help_about(GtkWidget*, gpointer);
83 PRIVATE void save_as(GtkWidget*);
84 PRIVATE void export_to_ps(GtkWidget*);
85
86 PRIVATE GtkItemFactoryEntry menu_items[] = {
87   { "/_File",                          NULL,         NULL,          0, "<Branch>" },
88   { "/File/Save _As...",               NULL,         save_as,       0, NULL },
89   { "/File/_Export to PostScript...",  NULL,         export_to_ps,  0, NULL },
90   { "/File/sep1",                      NULL,         NULL,          0, "<Separator>" },
91   { "/File/_Quit",                     "<control>Q", gtk_main_quit, 0, NULL },
92
93   { "/_Options",                       NULL, NULL,                  0,  "<Branch>" },
94   { "/Options/Default _Font Size",     NULL, NULL,                  0,  "<Branch>" },
95   { "/Options/Default Font Size/8pt",  NULL, options_font_size,     8,  "<RadioItem>" },
96   { "/Options/Default Font Size/10pt", NULL, options_font_size,     10, "/Options/Default Font Size/8pt" },
97   { "/Options/Default Font Size/12pt", NULL, options_font_size,     12, "/Options/Default Font Size/8pt" },
98   { "/Options/Default Font Size/14pt", NULL, options_font_size,     14, "/Options/Default Font Size/8pt" },
99   { "/Options/Default Font Size/18pt", NULL, options_font_size,     18, "/Options/Default Font Size/8pt" },
100   { "/Options/Default Font Size/24pt", NULL, options_font_size,     24, "/Options/Default Font Size/8pt" },
101   { "/Options/Font Manager",           NULL, NULL,                  0,  "<Branch>" },
102   { "/Options/Font Manager/_GTK",      NULL, options_font_manager,  0,  "<RadioItem>" },
103   { "/Options/Font Manager/_Type 1",   NULL, options_font_manager,  1,  "/Options/Font Manager/GTK" },
104   { "/Options/Verbosity",              NULL, NULL,                  0,  "<Branch>" },
105   { "/Options/Verbosity/_Errors",      NULL, options_verbosity,     0,  "<RadioItem>" },
106   { "/Options/Verbosity/_Warnings",    NULL, options_verbosity,     1,  "/Options/Verbosity/Errors" },
107   { "/Options/Verbosity/_Info",        NULL, options_verbosity,     2,  "/Options/Verbosity/Errors" },
108   { "/Options/Verbosity/_Debug",       NULL, options_verbosity,     3,  "/Options/Verbosity/Errors" },
109   { "/Options/sep1",                   NULL, NULL,                  0,  "<Separator>" },
110   { "/Options/_Kerning",               NULL, options_kerning,       0,  "<ToggleItem>" },
111   { "/Options/_Anti Aliasing",         NULL, options_anti_aliasing, 0,  "<ToggleItem>" },
112
113   { "/_Help" ,        NULL,         NULL,          0, "<LastBranch>" },
114   { "/Help/About...", NULL,         help_about,    0, NULL }
115 };
116
117 PRIVATE void
118 quick_message(const gchar* msg)
119 {
120   GtkWidget* dialog;
121   GtkWidget* label;
122   GtkWidget* okay_button;
123      
124   /* Create the widgets */
125      
126   dialog = gtk_dialog_new();
127   label = gtk_label_new (msg);
128   okay_button = gtk_button_new_with_label("OK");
129
130   gtk_widget_set_usize(dialog, 300, 100);
131
132   /* Ensure that the dialog box is destroyed when the user clicks ok. */
133      
134   gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked",
135                              GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT(dialog));
136   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
137                      okay_button);
138   
139   /* Add the label, and show everything we've added to the dialog. */
140   
141   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
142   gtk_widget_show_all (dialog);
143 }
144
145 PRIVATE void
146 load_error_msg(const gchar* name)
147 {
148   gchar* msg = g_strdup_printf("Could not load\n`%s'", name);
149   quick_message(msg);
150   g_free(msg);
151 }
152
153 PRIVATE void
154 save_error_msg(const gchar* name)
155 {
156   gchar* msg = g_strdup_printf("Could not save\n`%s'", name);
157   quick_message(msg);
158   g_free(msg);
159 }
160
161 void
162 GUI_init(gint* argc, gchar*** argv, gchar* title, guint width, guint height, GtkFunction f, guint32 timeout)
163 {
164   GdkPixmap* source;
165   GdkPixmap* mask;
166
167   GdkColor fg = { 0, 65535, 65535, 65535 };
168   GdkColor bg = { 0, 0, 0, 0 };
169
170   gtk_init(argc, argv);
171
172   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
173   gtk_window_set_title(GTK_WINDOW(window), title);
174   gtk_window_set_default_size(GTK_WINDOW(window), width, height);
175   gtk_signal_connect(GTK_OBJECT(window), "delete_event", (GtkSignalFunc) gtk_main_quit, NULL);
176   create_widget_set();
177
178   gtk_widget_show(window);
179
180   gtk_timeout_add(timeout, f, NULL);
181
182   normal_cursor = gdk_cursor_new(GDK_TOP_LEFT_ARROW);
183   link_cursor = gdk_cursor_new(GDK_HAND2);
184   
185   source = gdk_bitmap_create_from_data (NULL, pot_bits,
186                                         pot_width, pot_height);
187   mask = gdk_bitmap_create_from_data (NULL, pot_mask_bits,
188                                       pot_mask_width, pot_mask_height);
189   pot_cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
190   gdk_pixmap_unref (source);
191   gdk_pixmap_unref (mask);  
192 }
193
194 void
195 GUI_uninit()
196 {
197 }
198
199 int
200 GUI_load_document(const gchar* name)
201 {
202   GtkMathView* math_view;
203   GtkMathViewClass* klass;
204   gboolean res;
205
206   g_return_val_if_fail(name != NULL, -1);
207   g_return_val_if_fail(main_area != NULL, -1);
208   g_return_val_if_fail(GTK_IS_MATH_VIEW(main_area), -1);
209
210   math_view = GTK_MATH_VIEW(main_area);
211   g_return_val_if_fail(math_view != NULL, -1);
212
213   klass = (GtkMathViewClass*) gtk_type_class(gtk_math_view_get_type());
214   g_return_val_if_fail(klass != NULL, -1);
215
216   gdk_window_set_cursor(main_area->window, pot_cursor);  
217   loading = TRUE;
218   res = gtk_math_view_load(math_view, name);
219   gdk_window_set_cursor(main_area->window, normal_cursor);
220   loading = FALSE;
221
222   if (!res) {
223     load_error_msg(name);
224     return -1;
225   }
226
227   gtk_statusbar_pop(GTK_STATUSBAR(status_bar), statusbar_context);
228   if (strlen(name) > 40) name += strlen(name) - 40;
229   gtk_statusbar_push(GTK_STATUSBAR(status_bar), statusbar_context, name);
230
231   if (file_name != NULL) g_free(file_name);
232   file_name = g_strdup(name);
233
234   return 0;
235 }
236
237 void
238 GUI_unload_document()
239 {
240   GtkMathView* math_view;
241
242   g_return_if_fail(main_area != NULL);
243   g_return_if_fail(GTK_IS_MATH_VIEW(main_area));
244
245   math_view = GTK_MATH_VIEW(main_area);
246
247   gtk_math_view_unload(math_view);
248 }
249
250 void
251 GUI_run()
252 {
253   gtk_main();
254 }
255
256 PRIVATE void
257 options_font_size(GtkWidget* widget, guint size)
258 {
259   GtkMathView* math_view;
260
261   g_return_if_fail(main_area != NULL);
262   g_return_if_fail(GTK_IS_MATH_VIEW(main_area));
263
264   math_view = GTK_MATH_VIEW(main_area);
265
266   gtk_math_view_set_font_size(math_view, size);
267 }
268
269 PRIVATE void
270 options_font_manager(GtkWidget* widget, guint id)
271 {
272   GtkMathView* math_view;
273
274   g_return_if_fail(main_area != NULL);
275   g_return_if_fail(GTK_IS_MATH_VIEW(main_area));
276   
277   math_view = GTK_MATH_VIEW(main_area);
278
279   gtk_math_view_set_font_manager_type(math_view, id);
280 }
281
282 PRIVATE void
283 options_anti_aliasing(GtkWidget* widget, gpointer data)
284 {
285   gboolean aa = gtk_math_view_get_anti_aliasing(GTK_MATH_VIEW(main_area));
286   gtk_math_view_set_anti_aliasing(GTK_MATH_VIEW(main_area), !aa);
287 }
288
289 PRIVATE void
290 options_kerning(GtkWidget* widget, gpointer data)
291 {
292   gboolean k = gtk_math_view_get_kerning(GTK_MATH_VIEW(main_area));
293   gtk_math_view_set_kerning(GTK_MATH_VIEW(main_area), !k);
294 }
295
296 PRIVATE void
297 options_verbosity(GtkWidget* widget, guint level)
298 {
299   gtk_math_view_set_log_verbosity(GTK_MATH_VIEW(main_area), level);
300 }
301
302 PRIVATE void
303 help_about(GtkWidget* widget, gpointer data)
304 {
305   GtkWidget* dialog;
306   GtkWidget* label;
307   GtkWidget* ok;
308
309   dialog = gtk_dialog_new();
310   label = gtk_label_new("\n    HELM PoT    \n    Copyright (C) 2001 Luca Padovani    \n");
311   ok = gtk_button_new_with_label("Close");
312
313   gtk_signal_connect_object (GTK_OBJECT (ok), "clicked",
314                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
315   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
316                      ok);
317
318   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
319
320   gtk_widget_show_all (dialog);
321 }
322
323 PRIVATE void
324 export_filename(GtkFileSelection* selector, gpointer user_data)
325 {
326   FILE* f;
327   GtkMathView* math_view;
328   gchar* selected_filename;
329   
330   selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION(user_data));
331
332   math_view = GTK_MATH_VIEW(main_area);
333
334   f = fopen(selected_filename, "wt");
335   if (f == NULL) {
336     save_error_msg(selected_filename);
337     /*g_free(selected_filename);*/
338     return;
339   }
340
341   gtk_math_view_export_to_postscript(math_view,
342                                      (21 * SCALED_POINTS_PER_CM) / SCALED_POINTS_PER_PX,
343                                      (29 * SCALED_POINTS_PER_CM) / SCALED_POINTS_PER_PX,
344                                      SCALED_POINTS_PER_IN / SCALED_POINTS_PER_PX,
345                                      SCALED_POINTS_PER_IN / SCALED_POINTS_PER_PX,
346                                      FALSE,
347                                      f);
348
349   fclose(f);
350   /*g_free(selected_filename);*/
351 }
352
353 PRIVATE void
354 save_filename(GtkFileSelection* selector, gpointer user_data)
355 {
356   FILE* source;
357   FILE* dest;
358   gchar* buffer;
359   gchar* selected_filename;
360
361   if (file_name == NULL) return;
362
363   source = fopen(file_name, "rt");
364   if (source == NULL) {
365     load_error_msg(file_name);
366     return;
367   }
368
369   selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION(user_data));
370   if (selected_filename == NULL) return;
371
372   dest = fopen(selected_filename, "wt");
373   if (dest == NULL) {
374     save_error_msg(selected_filename);
375     /*g_free(selected_filename);*/
376     return;
377   }
378
379   /*g_free(selected_filename);*/
380
381   buffer = g_new(gchar, 2048);
382   while (!feof(source)) {
383     size_t n = fread(buffer, sizeof(gchar), 2048, source);
384     fwrite(buffer, sizeof(gchar), n, dest);
385   }
386
387   g_free(buffer);
388   fclose(source);
389   fclose(dest);
390 }
391
392 PRIVATE void
393 file_dialog(const gchar* title, GtkSignalFunc f)
394 {
395   GtkWidget* fs;
396
397   g_return_if_fail(title != NULL);
398   g_return_if_fail(f != NULL);
399
400   fs = gtk_file_selection_new(title);
401
402   gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
403                       "clicked", f, fs);
404                              
405   /* Ensure that the dialog box is destroyed when the user clicks a button. */
406      
407   gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
408                              "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
409                              (gpointer) fs);
410
411   gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(fs)->cancel_button),
412                              "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
413                              (gpointer) fs);
414      
415   /* Display that dialog */
416      
417   gtk_widget_show (fs);
418 }
419
420 PRIVATE void
421 export_to_ps(GtkWidget* widget)
422 {
423   file_dialog("Export to PostScript", export_filename);
424 #if 0
425   static GList* items = NULL;
426
427   GtkWidget* dialog;
428   GtkWidget* tmp;
429
430   if (items == NULL) {
431     items = g_list_append(items, "A4");
432     items = g_list_append(items, "A5");
433   }
434
435   dialog = gtk_dialog_new();
436   tmp = gtk_label_new("Paper size");
437   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), tmp);
438   tmp = gtk_combo_new();
439   gtk_combo_set_popdown_strings(GTK_COMBO(tmp), items);
440   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), tmp);
441 #if 0
442   tmp = gtk_check_button_new_with_label("Disable Colors");
443   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), tmp);
444 #endif
445
446   tmp = gtk_button_new_with_label("OK");
447   gtk_signal_connect_object(GTK_OBJECT(tmp), "clicked", GTK_SIGNAL_FUNC(export_to_ps_get_file_name), dialog);
448   gtk_signal_connect_object(GTK_OBJECT(tmp), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), dialog);
449   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), tmp);
450   tmp = gtk_button_new_with_label("Cancel");
451   gtk_signal_connect_object(GTK_OBJECT(tmp), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), dialog);
452   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), tmp);
453
454   gtk_widget_show_all(dialog);
455 #endif
456 }
457
458 PRIVATE void
459 save_as(GtkWidget* widget)
460 {
461   file_dialog("Save As...", save_filename);
462 }
463
464 PRIVATE void
465 element_changed(GtkMathView* math_view, mDOMNodeRef node)
466 {
467   g_return_if_fail(math_view != NULL);
468   g_return_if_fail(main_area != NULL);
469   g_return_if_fail(GTK_IS_MATH_VIEW(math_view));
470   /* fprintf(stderr, "node changed: %p %s\n", node, (node != NULL) ? mdom_node_get_name(node) : "-"); */
471
472   if (!loading) {
473     while (node != NULL && !mdom_node_has_attribute_ns(node, DOM_CONST_STRING("href"), XLINK_NS_URI))
474       node = mdom_node_get_parent(node);
475
476     if (node != NULL) {
477       gdk_window_set_cursor(main_area->window, link_cursor);
478     } else
479       gdk_window_set_cursor(main_area->window, normal_cursor);
480   }
481 }
482
483 PRIVATE void
484 selection_changed(GtkMathView* math_view, mDOMNodeRef node)
485 {
486   g_return_if_fail(math_view != NULL);
487   g_return_if_fail(GTK_IS_MATH_VIEW(math_view));
488
489   while (node != NULL && !mdom_node_has_attribute(node, DOM_CONST_STRING("xref")))
490     node = mdom_node_get_parent(node);
491
492   gtk_math_view_set_selection(math_view, node);
493 }
494
495 PRIVATE void
496 jump(mDOMConstStringRef href)
497 {
498   pid_t pid;
499   g_return_if_fail(href != NULL);
500
501   pid = fork();
502   if (pid == -1) exit(-1);
503   if (pid == 0) {
504     gchar* open_url = g_strdup_printf("openURL(%s,cic)", href);
505     gint fd;
506     
507     close(0);
508     close(1);
509     close(2);
510     
511     fd = open("/dev/null", O_RDWR);
512     dup(fd);
513     dup(fd);
514     
515     execlp("netscape", "netscape", "-noraise", "-remote", open_url, NULL);
516     perror("exec failed:");
517     exit(-1);
518   }
519 }
520
521 PRIVATE void
522 clicked(GtkMathView* math_view, gpointer user_data)
523 {
524   mDOMNodeRef p = gtk_math_view_get_element(math_view);
525   while (p != NULL && !mdom_node_has_attribute_ns(p, DOM_CONST_STRING("href"), XLINK_NS_URI))
526     p = mdom_node_get_parent(p);
527
528   if (p != NULL) {
529     mDOMStringRef href = mdom_node_get_attribute_ns(p, DOM_CONST_STRING("href"), XLINK_NS_URI);
530     g_assert(href != NULL);
531
532     jump(C_CONST_STRING(href));
533     mdom_string_free(href);
534   } else if (gtk_math_view_get_action(math_view) != NULL)
535     gtk_math_view_action_toggle(math_view);
536 }
537
538 PRIVATE void
539 create_widget_set()
540 {
541   GtkWidget* main_vbox;
542   GtkWidget* menu_bar;
543
544   main_vbox = gtk_vbox_new(FALSE, 1);
545   gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
546   gtk_container_add(GTK_CONTAINER(window), main_vbox);
547   gtk_widget_show(main_vbox);
548
549   menu_bar = get_main_menu();
550   gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0);
551   gtk_widget_show(menu_bar);
552
553   main_area = gtk_math_view_new(NULL, NULL);
554   gtk_widget_show(main_area);
555
556   gtk_signal_connect_object (GTK_OBJECT (main_area),
557                              "element_changed", GTK_SIGNAL_FUNC (element_changed),
558                              (gpointer) main_area);
559
560   gtk_signal_connect_object (GTK_OBJECT (main_area),
561                              "selection_changed", GTK_SIGNAL_FUNC (selection_changed),
562                              (gpointer) main_area);
563
564   gtk_signal_connect_object (GTK_OBJECT (main_area), 
565                              "clicked", GTK_SIGNAL_FUNC(clicked),
566                              (gpointer) main_area);
567                              
568   scrolled_area = gtk_scrolled_window_new(NULL, NULL);
569   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_area),
570                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
571   gtk_widget_show(scrolled_area);
572   gtk_container_add(GTK_CONTAINER(scrolled_area), main_area);
573   gtk_box_pack_start(GTK_BOX(main_vbox), scrolled_area, TRUE, TRUE, 0);
574
575   status_bar = gtk_statusbar_new();
576   gtk_widget_show(status_bar);
577   gtk_box_pack_start(GTK_BOX(main_vbox), status_bar, FALSE, TRUE, 0);
578   statusbar_context = gtk_statusbar_get_context_id(GTK_STATUSBAR(status_bar), "filename");
579
580   gtk_widget_show(main_vbox);
581
582   if (gtk_math_view_get_anti_aliasing(GTK_MATH_VIEW(main_area)))
583     gtk_menu_item_activate(anti_aliasing_item);
584
585   if (gtk_math_view_get_kerning(GTK_MATH_VIEW(main_area)))
586     gtk_menu_item_activate(kerning_item);
587
588   gtk_math_view_set_font_size(GTK_MATH_VIEW(main_area), DEFAULT_FONT_SIZE);
589   gtk_menu_item_activate(font_size_item);
590 }
591
592 GtkWidget*
593 get_main_menu()
594 {
595   GtkItemFactory* item_factory;
596   GtkAccelGroup* accel_group;
597   GtkWidget* menu_item;
598
599   gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
600
601   accel_group = gtk_accel_group_new();
602
603   item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
604
605   gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL);
606
607   gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
608
609   menu_item = gtk_item_factory_get_widget(item_factory, "/Options/Kerning");
610   kerning_item = GTK_MENU_ITEM(menu_item);
611
612   menu_item = gtk_item_factory_get_widget(item_factory, "/Options/Anti Aliasing");
613   anti_aliasing_item = GTK_MENU_ITEM(menu_item);
614
615   /* !!!BEWARE!!! the default font size must be kept aligned with the definition
616    * in defs.h
617    */
618   menu_item = gtk_item_factory_get_widget(item_factory, "/Options/Default Font Size/14pt");
619   font_size_item = GTK_MENU_ITEM(menu_item);
620
621   return gtk_item_factory_get_widget(item_factory, "<main>");
622 }