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