]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/test/guiGTK.c
cf59421cffecbdc2f92b6db7d99218e32798490d
[helm.git] / helm / DEVEL / mathml_editor / test / guiGTK.c
1 /* This file is part of EdiTeX, an editor of mathematical
2  * expressions based on TeX syntax.
3  * 
4  * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
5  *                    2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * For more information, please visit the project's home page
22  * http://helm.cs.unibo.it/editex/
23  * or send an email to <lpadovan@cs.unibo.it>
24  */
25
26 #include <config.h>
27 #include <stdio.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30
31 #include <gtkmathview.h>
32 #include "guiGTK.h"
33
34 #define XLINK_NS_URI "http://www.w3.org/1999/xlink"
35
36 static GtkWidget* window;
37 static GtkWidget* main_area;
38 static GtkWidget* scrolled_area;
39 static GtkMenuItem* anti_aliasing_item;
40 static GtkMenuItem* transparency_item;
41
42 static gpointer context = NULL;
43 static gchar* doc_name = NULL;
44 static GdomeElement* first_selected = NULL;
45 static GdomeElement* root_selected = NULL;
46
47 static void create_widget_set(gpointer);
48 static GtkWidget* get_main_menu(void);
49 static void file_open(GtkWidget*, gpointer);
50 static void file_re_open(GtkWidget*, gpointer);
51 static void file_close(GtkWidget*, gpointer);
52 static void file_output_tex(GtkWidget*, gpointer);
53 static void options_set_font_size(GtkWidget*, gpointer);
54 static void options_change_font_size(GtkWidget*, gboolean);
55 static void options_verbosity(GtkWidget*, guint);
56 static void options_anti_aliasing(GtkWidget*, gpointer);
57 static void options_transparency(GtkWidget*, gpointer);
58 static void edit_delete_selection(GtkWidget*, gpointer);
59 static void edit_select_parent(GtkWidget*, gpointer);
60 static void edit_reset_selection(GtkWidget*, gpointer);
61 static void edit_reset(GtkWidget*, gpointer);
62 static void edit_insert(GtkWidget*, gpointer);
63 static void help_about(GtkWidget*, gpointer);
64
65 static GtkItemFactoryEntry menu_items[] = {
66   { "/_File",                          NULL,         NULL,          0, "<Branch>" },
67   { "/File/_Open...",                  "<control>O", file_open,     0, NULL },
68   { "/File/_Reopen",                   NULL,         file_re_open,  0, NULL },
69   { "/File/_Close",                    "<control>W", file_close,    0, NULL },
70   { "/File/Output _TeX",               NULL,         file_output_tex, 0, NULL },
71   { "/File/sep1",                      NULL,         NULL,          0, "<Separator>" },
72   { "/File/_Quit",                     "<control>Q", gtk_main_quit, 0, NULL },
73
74   { "/_Edit",                          NULL, NULL,                  0,  "<Branch>" },
75   { "/Edit/Reset Selection",           NULL, edit_reset_selection,  0, NULL },
76   { "/Edit/Delete Selection",          NULL, edit_delete_selection, 0, NULL },
77   { "/Edit/Select Parent",             NULL, edit_select_parent,    0, NULL },
78   { "/Edit/sep1",                      NULL,         NULL,          0, "<Separator>" },
79   { "/Edit/_Reset",                    NULL, edit_reset,            0, NULL },
80   { "/Edit/Insert...",                 "<control>I", edit_insert,   0, NULL },
81
82   { "/_Options",                       NULL, NULL,                  0,  "<Branch>" },
83   { "/Options/Default _Font Size",     NULL, NULL,                  0,  "<Branch>" },
84   { "/Options/Default Font Size/Set...", NULL, options_set_font_size, 0,  NULL },
85   { "/Options/Default Font Size/sep1", NULL, NULL,                  0,  "<Separator>" },
86   { "/Options/Default Font Size/Larger", NULL, options_change_font_size, TRUE, NULL },
87   { "/Options/Default Font Size/Smaller", NULL, options_change_font_size, FALSE, NULL },
88   { "/Options/Verbosity",              NULL, NULL,                  0,  "<Branch>" },
89   { "/Options/Verbosity/_Errors",      NULL, options_verbosity,     0,  "<RadioItem>" },
90   { "/Options/Verbosity/_Warnings",    NULL, options_verbosity,     1,  "/Options/Verbosity/Errors" },
91   { "/Options/Verbosity/_Info",        NULL, options_verbosity,     2,  "/Options/Verbosity/Errors" },
92   { "/Options/Verbosity/_Debug",       NULL, options_verbosity,     3,  "/Options/Verbosity/Errors" },
93   { "/Options/sep1",                   NULL, NULL,                  0,  "<Separator>" },
94   { "/Options/_Anti Aliasing",         NULL, options_anti_aliasing, 0,  "<ToggleItem>" },
95   { "/Options/_Transparency",          NULL, options_transparency,  0,  "<ToggleItem>" },
96
97   { "/_Help" ,        NULL,         NULL,          0, "<LastBranch>" },
98   { "/Help/About...", NULL,         help_about,    0, NULL }
99 };
100
101 static void
102 quick_message(const char* msg)
103 {
104   GtkWidget* dialog;
105   GtkWidget* label;
106   GtkWidget* okay_button;
107      
108   /* Create the widgets */
109      
110   dialog = gtk_dialog_new();
111   label = gtk_label_new (msg);
112   okay_button = gtk_button_new_with_label("OK");
113
114   gtk_widget_set_usize(dialog, 300, 100);
115
116   /* Ensure that the dialog box is destroyed when the user clicks ok. */
117      
118   gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked",
119                              GTK_SIGNAL_FUNC (gtk_widget_destroy), dialog);
120   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
121                      okay_button);
122   
123   /* Add the label, and show everything we've added to the dialog. */
124   
125   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
126   gtk_widget_show_all (dialog);
127 }
128
129 static void
130 load_error_msg(const char* name)
131 {
132   char* msg = g_strdup_printf("Could not load\n`%s'", name);
133   quick_message(msg);
134   g_free(msg);
135 }
136
137 static guint edit_timeout_id;
138 extern void edit_timeout(gpointer);
139
140 void
141 GUI_init(int* argc, char*** argv, char* title, guint width, guint height, gpointer c)
142 {
143   gtk_init(argc, argv);
144
145   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
146   gtk_window_set_title(GTK_WINDOW(window), title);
147   gtk_window_set_default_size(GTK_WINDOW(window), width, height);
148   gtk_signal_connect(GTK_OBJECT(window), "delete_event", (GtkSignalFunc) gtk_main_quit, NULL);
149   create_widget_set(context);
150
151   gtk_widget_show(window);
152
153   context = c;
154   /*edit_timeout_id = gtk_timeout_add(50, edit_timeout, context);*/
155 }
156
157 void
158 GUI_uninit()
159 {
160   GdomeException exc = 0;
161
162   if (first_selected != NULL)
163     {
164       gdome_el_unref(first_selected, &exc);
165       g_assert(exc == 0);
166       first_selected = NULL;
167     }
168
169   if (root_selected != NULL)
170     {
171       gdome_el_unref(root_selected, &exc);
172       g_assert(exc == 0);
173       root_selected = NULL;
174     }
175
176   context = NULL;
177 }
178
179 int
180 GUI_load_document(GdomeDocument* doc)
181 {
182   GtkMathView* math_view;
183
184   g_return_val_if_fail(doc != NULL, -1);
185   g_return_val_if_fail(main_area != NULL, -1);
186   g_return_val_if_fail(GTK_IS_MATH_VIEW(main_area), -1);
187
188   math_view = GTK_MATH_VIEW(main_area);
189
190   if (!gtk_math_view_load_doc(math_view, doc)) return -1;
191
192   return 0;
193 }
194
195 void
196 GUI_freeze()
197 {
198   gtk_math_view_freeze(GTK_MATH_VIEW(main_area));
199 }
200
201 void
202 GUI_thaw()
203 {
204   gtk_math_view_thaw(GTK_MATH_VIEW(main_area));
205 }
206
207 void
208 GUI_unload_document()
209 {
210   GtkMathView* math_view;
211
212   g_return_if_fail(main_area != NULL);
213   g_return_if_fail(GTK_IS_MATH_VIEW(main_area));
214
215   math_view = GTK_MATH_VIEW(main_area);
216
217   gtk_math_view_unload(math_view);
218
219   if (doc_name != NULL) g_free(doc_name);
220   doc_name = NULL;
221 }
222
223 void
224 GUI_run()
225 {
226   gtk_main();
227 }
228
229 #if 0
230 void
231 GUI_set_font_manager(FontManagerId id)
232 {
233   gboolean t1;
234   GtkMathView* math_view;
235
236   g_return_if_fail(id != FONT_MANAGER_UNKNOWN);
237   g_return_if_fail(main_area != NULL);
238   g_return_if_fail(GTK_IS_MATH_VIEW(main_area));
239
240   t1 = id == FONT_MANAGER_T1;
241
242   math_view = GTK_MATH_VIEW(main_area);
243
244   gtk_math_view_freeze(math_view);
245
246   if (id != gtk_math_view_get_font_manager_type(math_view))
247     gtk_math_view_set_font_manager_type(math_view, id);
248
249   gtk_widget_set_sensitive(anti_aliasing_item, t1);
250   gtk_widget_set_sensitive(transparency_item, t1);
251
252   if (t1)
253     {
254       gtk_math_view_set_anti_aliasing(math_view, GTK_CHECK_MENU_ITEM(anti_aliasing_item)->active);
255       gtk_math_view_set_transparency(math_view, GTK_CHECK_MENU_ITEM(transparency_item)->active);
256     }
257
258   gtk_math_view_thaw(math_view);
259 }
260 #endif
261
262 static void
263 store_filename(GtkFileSelection* selector, GtkWidget* user_data)
264 {
265   gchar* selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION(user_data));
266   if (selected_filename != NULL)
267     GUI_load_document(selected_filename);
268 }
269
270 static void
271 file_close(GtkWidget* widget, gpointer data)
272 {
273   GUI_unload_document();
274 }
275
276 static void
277 file_re_open(GtkWidget* widget, gpointer data)
278 {
279   if (doc_name != NULL) {
280     GUI_load_document(doc_name);
281   }
282 }
283
284 static void
285 file_open(GtkWidget* widget, gpointer data)
286 {
287   GtkWidget* fs = gtk_file_selection_new("Open File");
288
289   gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
290                       "clicked", GTK_SIGNAL_FUNC (store_filename), (gpointer) fs);
291                              
292   /* Ensure that the dialog box is destroyed when the user clicks a button. */
293      
294   gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
295                              "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
296                              (gpointer) fs);
297
298   gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(fs)->cancel_button),
299                              "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
300                              (gpointer) fs);
301      
302   /* Display that dialog */
303      
304   gtk_widget_show (fs);
305 }
306
307 static void
308 file_output_tex(GtkWidget* widget, gpointer data)
309 {
310   g_assert(context != NULL);
311   edit_output_tex(context);
312 }
313
314 #if 0
315 static void
316 options_font_manager(GtkWidget* widget, FontManagerId id)
317 {
318   g_return_if_fail(id != FONT_MANAGER_UNKNOWN);
319   GUI_set_font_manager(id);
320 }
321 #endif
322
323 static void
324 options_anti_aliasing(GtkWidget* widget, gpointer data)
325 {
326   gboolean aa = gtk_math_view_get_anti_aliasing(GTK_MATH_VIEW(main_area));
327   gtk_math_view_set_anti_aliasing(GTK_MATH_VIEW(main_area), !aa);
328 }
329
330 static void
331 options_transparency(GtkWidget* widget, gpointer data)
332 {
333   gboolean t = gtk_math_view_get_transparency(GTK_MATH_VIEW(main_area));
334   gtk_math_view_set_transparency(GTK_MATH_VIEW(main_area), !t);
335 }
336
337 static void
338 options_verbosity(GtkWidget* widget, guint level)
339 {
340   gtk_math_view_set_log_verbosity(GTK_MATH_VIEW(main_area), level);
341 }
342
343 static void
344 edit_delete_selection(GtkWidget* widget, gpointer data)
345 {
346   if (root_selected != NULL)
347     {
348       GdomeException exc;
349       gtk_math_view_freeze(GTK_MATH_VIEW(main_area));
350       printf("about to remove element %p\n", root_selected);
351       delete_element(root_selected);
352       gdome_el_unref(root_selected, &exc);
353       g_assert(exc == 0);
354       root_selected = NULL;
355       gtk_math_view_thaw(GTK_MATH_VIEW(main_area));
356     }
357 }
358
359 static void
360 edit_select_parent(GtkWidget* widget, gpointer data)
361 {
362   if (root_selected != NULL)
363     {
364       GdomeException exc = 0;
365       GdomeElement* parent = gdome_n_parentNode(root_selected, &exc);
366       g_assert(exc == 0);
367       gdome_el_unref(root_selected, &exc);
368       g_assert(exc == 0);
369       root_selected = parent;
370       /* gtk_math_view_set_selection(GTK_MATH_VIEW(main_area), root_selected); */
371     }
372 }
373
374 static void
375 edit_reset_selection(GtkWidget* widget, gpointer data)
376 {
377   if (root_selected != NULL)
378     {
379       GdomeException exc = 0;
380       /* gtk_math_view_reset_selection(GTK_MATH_VIEW(main_area), root_selected); */
381       gdome_el_unref(root_selected, &exc);
382       g_assert(exc == 0);
383       root_selected = NULL;
384     }
385 }
386
387 static void
388 edit_reset(GtkWidget* widget, gpointer data)
389 {
390   g_assert(context != NULL);
391   edit_reset_tex(context);
392 }
393
394 static void
395 insert_tex(GtkWidget* widget, GtkEntry* entry)
396 {
397   gchar* text;
398   g_return_if_fail(entry != NULL);
399
400   text = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
401   edit_push_string(context, text);
402   g_free(text);
403 }
404
405 static void
406 edit_insert(GtkWidget* widget, gpointer data)
407 {
408   GtkWidget* dialog;
409   GtkWidget* entry;
410   GtkWidget* ok;
411   GtkWidget* cancel;
412
413   dialog = gtk_dialog_new();
414   entry = gtk_entry_new();
415   ok = gtk_button_new_with_label("OK");
416   cancel = gtk_button_new_with_label("Cancel");
417
418   gtk_signal_connect (GTK_OBJECT (ok), "clicked",
419                       GTK_SIGNAL_FUNC (insert_tex), (gpointer) entry);
420
421   gtk_signal_connect_object (GTK_OBJECT (ok), "clicked",
422                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
423
424   gtk_signal_connect_object (GTK_OBJECT (ok), "clicked",
425                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
426
427   gtk_signal_connect_object (GTK_OBJECT (cancel), "clicked",
428                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
429
430   gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), 5);
431
432   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), entry);
433   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), ok);
434   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), cancel);
435
436   gtk_widget_show_all (dialog);
437 }
438
439 static void
440 help_about(GtkWidget* widget, gpointer data)
441 {
442   GtkWidget* dialog;
443   GtkWidget* label;
444   GtkWidget* ok;
445
446   dialog = gtk_dialog_new();
447   label = gtk_label_new("\n    MathML Editor    \n    Copyright (C) 2003 Luca Padovani    \n");
448   ok = gtk_button_new_with_label("Close");
449
450   gtk_signal_connect_object (GTK_OBJECT (ok), "clicked",
451                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
452   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
453                      ok);
454
455   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
456
457   gtk_widget_show_all (dialog);
458 }
459
460 static void
461 change_default_font_size(GtkWidget* widget, GtkSpinButton* spin)
462 {
463   g_return_if_fail(spin != NULL);
464   gtk_math_view_set_font_size( GTK_MATH_VIEW(main_area), gtk_spin_button_get_value_as_int(spin));
465 }
466
467 static void
468 options_change_font_size(GtkWidget* widget, gboolean larger)
469 {
470   gfloat size = gtk_math_view_get_font_size (GTK_MATH_VIEW(main_area));
471   if (larger) size = size / 0.71;
472   else size = size * 0.71;
473   if (size < 1) size = 1;
474   gtk_math_view_set_font_size (GTK_MATH_VIEW(main_area), (gint) size + 0.5);
475 }
476
477 static void
478 options_set_font_size(GtkWidget* widget, gpointer data)
479 {
480   GtkWidget* dialog;
481   GtkWidget* label;
482   GtkWidget* ok;
483   GtkWidget* cancel;
484   GtkWidget* spin;
485   GtkObject* adj;
486
487   dialog = gtk_dialog_new();
488   label = gtk_label_new("Default font size:");
489   ok = gtk_button_new_with_label("OK");
490   cancel = gtk_button_new_with_label("Cancel");
491
492   adj = gtk_adjustment_new (gtk_math_view_get_font_size (GTK_MATH_VIEW(main_area)), 1, 200, 1, 1, 1);
493   spin = gtk_spin_button_new (GTK_ADJUSTMENT(adj), 1, 0);
494   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin), TRUE);
495
496   gtk_signal_connect (GTK_OBJECT (ok), "clicked",
497                       GTK_SIGNAL_FUNC (change_default_font_size), (gpointer) spin);
498
499   gtk_signal_connect_object (GTK_OBJECT (ok), "clicked",
500                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
501
502   gtk_signal_connect_object (GTK_OBJECT (ok), "clicked",
503                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
504
505   gtk_signal_connect_object (GTK_OBJECT (cancel), "clicked",
506                              GTK_SIGNAL_FUNC (gtk_widget_destroy), (gpointer) dialog);
507
508   gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), 5);
509
510   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), ok);
511   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), cancel);
512   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
513   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), spin);
514
515   gtk_widget_show_all (dialog);
516 }
517
518 static void
519 select_begin(GtkMathView* math_view, GdomeElement* first, gint state)
520 {
521   GdomeException exc = 0;
522
523   g_return_if_fail(math_view != NULL);
524   g_return_if_fail(GTK_IS_MATH_VIEW(math_view));
525   g_return_if_fail(first != NULL);
526
527   gtk_math_view_freeze(math_view);
528
529   if (root_selected != NULL)
530     {
531       gtk_math_view_unselect(math_view, root_selected);
532       gdome_el_unref(root_selected, &exc);
533       g_assert(exc == 0);
534     }
535
536   root_selected = first_selected = find_element_with_ref(first);
537
538   if (root_selected != NULL)
539     {
540       gtk_math_view_select(math_view, root_selected);
541       gdome_el_ref(root_selected, &exc);
542       g_assert(exc == 0);
543     }
544
545   gtk_math_view_thaw(math_view);
546 }
547
548 static void
549 select_over(GtkMathView* math_view, GdomeElement* elem, gint state)
550 {
551   GdomeElement* new_selected = NULL;
552   GdomeException exc = 0;
553
554   g_return_if_fail(math_view != NULL);
555   g_return_if_fail(GTK_IS_MATH_VIEW(math_view));
556   g_return_if_fail(elem != NULL);
557
558   if (first_selected == NULL || elem == NULL)
559     new_selected = NULL;
560   else
561     new_selected = find_common_ancestor_with_ref(first_selected, elem);
562
563   if (new_selected != root_selected)
564     {
565       gtk_math_view_freeze(math_view);
566       if (root_selected != NULL)
567         {
568           gtk_math_view_unselect(math_view, root_selected);
569           gdome_el_unref(root_selected, &exc);
570           g_assert(exc == 0);
571         }
572       root_selected = new_selected;
573       if (root_selected != NULL)
574         gtk_math_view_select(math_view, root_selected);
575       gtk_math_view_thaw(math_view);
576     }
577   else if (new_selected != NULL)
578     {
579       gdome_el_unref(new_selected, &exc);
580       g_assert(exc == 0);
581     }
582
583 }
584
585 static gboolean
586 key_press_event(gpointer c,
587                 GdkEventKey* event,
588                 GtkWidget* widget)
589 {
590   g_return_val_if_fail(widget != NULL, FALSE);
591   g_return_val_if_fail(event != NULL, FALSE);
592   g_return_val_if_fail(context != NULL, FALSE);
593
594   if (event->type != GDK_KEY_PRESS) return FALSE;
595
596   switch (event->keyval)
597     {
598     case GDK_BackSpace:
599       edit_drop(context, event->state & GDK_MOD1_MASK, event->state & GDK_CONTROL_MASK);
600       break;
601     case GDK_Tab:
602       edit_complete(context);
603       break;
604     default:
605       if ((event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0 && event->keyval < 0x80)
606         edit_push_char(context, event->keyval);
607       return FALSE;
608     }
609
610   return TRUE;
611 }
612
613 static void
614 create_widget_set(gpointer context)
615 {
616   GtkWidget* main_vbox;
617   GtkWidget* menu_bar;
618
619   main_vbox = gtk_vbox_new(FALSE, 1);
620   gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
621   gtk_container_add(GTK_CONTAINER(window), main_vbox);
622   gtk_widget_show(main_vbox);
623
624   menu_bar = get_main_menu();
625   gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0);
626   gtk_widget_show(menu_bar);
627
628   main_area = gtk_math_view_new(NULL, NULL);
629   gtk_widget_show(main_area);
630
631   //gtk_math_view_set_log_verbosity(GTK_MATH_VIEW(main_area), 3);
632
633   gtk_signal_connect_object (GTK_OBJECT (main_area),
634                              "select_begin", GTK_SIGNAL_FUNC (select_begin),
635                              (gpointer) main_area);
636
637   gtk_signal_connect_object (GTK_OBJECT (main_area),
638                              "select_over", GTK_SIGNAL_FUNC (select_over),
639                              (gpointer) main_area);
640
641   gtk_signal_connect_object (GTK_OBJECT(window),
642                              "key_press_event", GTK_SIGNAL_FUNC(key_press_event),
643                              context);
644
645   gtk_widget_add_events(GTK_WIDGET(main_area), GDK_KEY_PRESS_MASK);
646
647   scrolled_area = gtk_scrolled_window_new(NULL, NULL);
648   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_area),
649                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
650
651   gtk_widget_show(scrolled_area);
652   gtk_container_add(GTK_CONTAINER(scrolled_area), main_area);
653   gtk_box_pack_start(GTK_BOX(main_vbox), scrolled_area, TRUE, TRUE, 0);
654
655   gtk_widget_show(main_vbox);
656
657   if (gtk_math_view_get_anti_aliasing(GTK_MATH_VIEW(main_area)))
658     gtk_menu_item_activate(anti_aliasing_item);
659 }
660
661 GtkWidget*
662 get_main_menu()
663 {
664   GtkItemFactory* item_factory;
665   GtkAccelGroup* accel_group;
666   GtkWidget* menu_item;
667
668   gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
669
670   accel_group = gtk_accel_group_new();
671
672   item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
673
674   gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL);
675
676   gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
677
678   menu_item = gtk_item_factory_get_widget(item_factory, "/Options/Anti Aliasing");
679   anti_aliasing_item = GTK_MENU_ITEM(menu_item);
680
681   menu_item = gtk_item_factory_get_widget(item_factory, "/Options/Transparency");
682   transparency_item = GTK_MENU_ITEM(menu_item);
683
684   return gtk_item_factory_get_widget(item_factory, "<main>");
685 }