]> git.lyx.org Git - lyx.git/blob - src/menus.C
patch from Dekel
[lyx.git] / src / menus.C
1 /*
2  *  This file is part of
3  * ================================================== 
4  *
5  *       LyX, The Document Processor
6  *
7  *       Copyright 1995 Matthias Ettrich
8  *       Copyright 1995-2000 The LyX Team.
9  *
10  * ================================================== 
11  */
12
13 /* This file contains all the menu and submenu declarations.
14    The call backs are in lyx_cb.C */
15
16 /*
17  * REMEMBER:
18  * XFORMS can handle 10 (more with the new xforms, but not unlimited)
19  * popups at the same time
20  * so when you are finished looking at a pup free it (fl_freepup)
21  */
22
23 #include <config.h>
24
25 #ifdef __GNUG__
26 #pragma implementation
27 #endif
28
29 #include <algorithm>
30
31 #include "menus.h"
32 #include "version.h"
33 #include "lyxfont.h"
34 #include "lyx_main.h"
35 #include "lyxfunc.h"
36 #include "spellchecker.h"
37 #include "support/filetools.h"
38 #include "LyXView.h"
39 #include "lastfiles.h"
40 #include "bufferlist.h"
41 #include "lyx_gui_misc.h"
42 #include "minibuffer.h"
43 #include "intl.h"
44 #include "debug.h"
45 #include "lyxrc.h"
46 #include "lyxtext.h"
47 #include "gettext.h"
48 #include "layout.h"
49 #include "lyx_cb.h"
50 #include "bufferview_funcs.h"
51 #include "insets/insetref.h"
52 #include "insets/insettabular.h"
53 #include "tabular.h"
54
55 using std::vector;
56 using std::endl;
57 using std::max;
58 using std::sort;
59
60 extern FD_form_screen * fd_form_screen;
61 extern BufferList bufferlist;
62
63 // I would really prefere to see most or all of these 'extern's disappear.
64 // Their commands should be called through LyXFunc (IMO). (Lgb)
65
66 extern void MenuLayoutSave();
67 extern void ShowCredits();
68 extern void ShowCopyright();
69 extern void show_symbols_form(LyXFunc *);
70 extern void LaTeXOptions(BufferView *);
71
72 // A bunch of wrappers
73
74 extern "C" void C_Menus_ShowFileMenu(FL_OBJECT * ob, long data)
75 {
76         Menus::ShowFileMenu(ob, data);
77 }
78
79 extern "C" void C_Menus_ShowFileMenu2(FL_OBJECT * ob, long data)
80 {
81         Menus::ShowFileMenu2(ob, data);
82 }
83
84 extern "C" void C_Menus_ShowEditMenu(FL_OBJECT * ob, long data)
85 {
86         Menus::ShowEditMenu(ob, data);
87 }
88
89 extern "C" void C_Menus_ShowTocMenu(FL_OBJECT * ob, long data)
90 {
91         Menus::ShowTocMenu(ob, data);
92 }
93
94 extern "C" void C_Menus_ShowRefsMenu(FL_OBJECT * ob, long data)
95 {
96         Menus::ShowRefsMenu(ob, data);
97 }
98
99 extern "C" void C_Menus_ShowLayoutMenu(FL_OBJECT * ob, long data)
100 {
101         Menus::ShowLayoutMenu(ob, data);
102 }
103
104 extern "C" void C_Menus_ShowInsertMenu(FL_OBJECT * ob, long data)
105 {
106         Menus::ShowInsertMenu(ob, data);
107 }
108
109 extern "C" void C_Menus_ShowMathMenu(FL_OBJECT * ob, long data)
110 {
111         Menus::ShowMathMenu(ob, data);
112 }
113
114 extern "C" void C_Menus_ShowOptionsMenu(FL_OBJECT * ob, long data)
115 {
116         Menus::ShowOptionsMenu(ob, data);
117 }
118
119 extern "C" void C_Menus_ShowBufferMenu(FL_OBJECT * ob, long data)
120 {
121         Menus::ShowBufferMenu(ob, data);
122 }
123
124 extern "C" void C_Menus_ShowHelpMenu(FL_OBJECT * ob, long data)
125 {
126         Menus::ShowHelpMenu(ob, data);
127 }
128
129
130 Menus::Menus(LyXView * view, int air)
131         : _view(view)
132 {       
133         create_menus(air);
134         // deactivate the menu accelerators
135         fl_set_object_shortcut(menu_file, "", 1);
136         fl_set_object_shortcut(menu_file2, "", 1);
137         fl_set_object_shortcut(menu_edit, "", 1);
138         fl_set_object_shortcut(menu_toc, "", 1);
139         fl_set_object_shortcut(menu_refs, "", 1);
140         fl_set_object_shortcut(menu_layout, "", 1);
141         fl_set_object_shortcut(menu_math, "", 1);
142         fl_set_object_shortcut(menu_insert, "", 1);
143         fl_set_object_shortcut(menu_options, "", 1);
144         fl_set_object_shortcut(menu_options2, "", 1);
145         fl_set_object_shortcut(menu_buffer, "", 1);
146         fl_set_object_shortcut(menu_help, "", 1);
147         fl_set_object_shortcut(menu_help2, "", 1);
148         hideMenus();
149 }
150
151
152 inline
153 BufferView * Menus::currentView() 
154 {
155         return _view->view(); 
156 }
157
158
159 void Menus::showMenus()
160 {
161         fl_hide_object(menu_grp2);
162         fl_show_object(menu_grp1);
163 }
164
165
166 void Menus::hideMenus()
167 {
168         fl_hide_object(menu_grp1);
169         fl_show_object(menu_grp2);
170 }
171
172
173 void Menus::openByName(string const & menuName)
174         /* Opens the visible menu of given name, or simply does nothing
175            when the name is not known. NOTE THE EXTREMELY STUPID
176            IMPLEMENTATION! :-) There are probably hundred ways to do
177            this better, for instance, by scanning the menu objects and
178            testing for the given name. I leave this as an exercise for an
179            experienced GG (GUI Guy/Girl). RVDK_PATCH_5. */
180 {
181         if (menu_file->visible) {
182                 if (menuName == _("File"))
183                         ShowFileMenu(menu_file, 0);
184                 else if (menuName == _("Edit"))
185                         ShowEditMenu(menu_edit, 0);
186                 else if (menuName == _("TOC"))
187                         ShowTocMenu(menu_toc, 0);
188                 else if (menuName == _("Refs"))
189                         ShowRefsMenu(menu_refs, 0);
190                 else if (menuName == _("Layout"))
191                         ShowLayoutMenu(menu_layout, 0);
192                 else if (menuName == _("Insert"))
193                         ShowInsertMenu(menu_insert, 0);
194                 else if (menuName == _("Math"))
195                         ShowMathMenu(menu_math, 0);
196                 else if (menuName == _("Options"))
197                         ShowOptionsMenu(menu_options, 0);
198                 else if (menuName == _("Documents"))
199                         ShowBufferMenu(menu_buffer, 0);
200                 else if (menuName == _("Help"))
201                         ShowHelpMenu(menu_help, 0);
202                 else lyxerr << "The menu '" << menuName
203                             << "' is not available." << endl;
204         } else {
205                 if (menuName == _("File"))
206                         ShowFileMenu2(menu_file2, 0);
207                 else if (menuName == _("Options"))
208                         ShowOptionsMenu(menu_options2, 0);
209                 else if (menuName == _("Help"))
210                         ShowHelpMenu(menu_help2, 0);
211                 else lyxerr << "The menu '" << menuName
212                             << "' is not available." << endl;
213         }
214 }
215
216
217 void Menus::create_menus(int air)
218 {
219         FL_FORM * form = _view->getForm(); 
220
221         // Here I'd really like to see code like:
222         // addMenuBar();
223         FL_OBJECT * obj;
224
225         const int MENU_LABEL_SIZE = FL_NORMAL_SIZE;
226         const int mheight = 30;
227         const int mbheight= 22;
228         // where to place the menubar?
229         const int yloc = (mheight - mbheight)/2; //air + bw;
230         const int mbadd = 20; // menu button add (to width)
231         int moffset = 0;
232
233         // menubar frame
234         obj = fl_add_frame(FL_UP_FRAME, 0, 0, form->w, mheight, "");
235         fl_set_object_resize(obj, FL_RESIZE_ALL);
236         fl_set_object_gravity(obj, NorthWestGravity, NorthEastGravity);
237
238         menu_grp1 = fl_bgn_group();
239         
240         // File menu button
241         menu_file = obj = 
242                 fl_add_button(FL_TOUCH_BUTTON,
243                               air+moffset, yloc,
244                               fl_get_string_width(FL_BOLD_STYLE,
245                                                   MENU_LABEL_SIZE,
246                                                   _("File"),
247                                                   strlen(_("File"))) + mbadd,
248                               mbheight, _("File"));
249         moffset += obj->w + air;
250         fl_set_object_shortcut(obj, scex(_("MB|#F")), 1);
251         fl_set_object_callback(obj, C_Menus_ShowFileMenu, 0);
252         obj->u_vdata = this;
253         
254         // Edit menu button
255         menu_edit = obj = 
256                 fl_add_button(FL_TOUCH_BUTTON,
257                               moffset, yloc,
258                               fl_get_string_width(FL_BOLD_STYLE,
259                                                   MENU_LABEL_SIZE,
260                                                   _("Edit"),
261                                                   strlen(_("Edit"))) + mbadd,
262                               mbheight, _("Edit"));
263         moffset += obj->w + air;
264         fl_set_object_shortcut(obj, scex(_("MB|#E")), 1);
265         fl_set_object_callback(obj, C_Menus_ShowEditMenu, 0);
266         obj->u_vdata = this;
267         
268         /// TOC menu button
269         menu_toc = obj = 
270                 fl_add_button(FL_TOUCH_BUTTON,
271                               moffset, yloc,
272                               fl_get_string_width(FL_BOLD_STYLE,
273                                                   MENU_LABEL_SIZE,
274                                                   _("TOC"),
275                                                   strlen(_("TOC"))) + mbadd,
276                               mbheight, _("TOC"));
277         moffset += obj->w + air;
278         fl_set_object_shortcut(obj, scex(_("MB|#T")), 1);
279         fl_set_object_callback(obj, C_Menus_ShowTocMenu, 0);
280         obj->u_vdata = this;
281
282         /// Refs menu button
283         menu_refs = obj = 
284                 fl_add_button(FL_TOUCH_BUTTON,
285                               moffset, yloc,
286                               fl_get_string_width(FL_BOLD_STYLE,
287                                                   MENU_LABEL_SIZE,
288                                                   _("Refs"),
289                                                   strlen(_("Refs"))) + mbadd,
290                               mbheight, _("Refs"));
291         moffset += obj->w + air;
292         fl_set_object_shortcut(obj, scex(_("MB|#R")), 1);
293         fl_set_object_callback(obj, C_Menus_ShowRefsMenu, 0);
294         obj->u_vdata = this;
295
296         // Layout menu button
297         menu_layout = obj = 
298                 fl_add_button(FL_TOUCH_BUTTON,
299                               moffset, yloc,
300                               fl_get_string_width(FL_BOLD_STYLE,
301                                                   MENU_LABEL_SIZE,
302                                                   _("Layout"),
303                                                   strlen(_("Layout"))) + mbadd,
304                               mbheight, _("Layout"));
305         moffset += obj->w + air;
306         fl_set_object_shortcut(obj, scex(_("MB|#L")), 1);
307         fl_set_object_callback(obj, C_Menus_ShowLayoutMenu, 0);
308         obj->u_vdata = this;
309         
310         // Insert menu button button
311         menu_insert = obj = 
312                 fl_add_button(FL_TOUCH_BUTTON,
313                               moffset, yloc,
314                               fl_get_string_width(FL_BOLD_STYLE,
315                                                   MENU_LABEL_SIZE,
316                                                   _("Insert"),
317                                                   strlen(_("Insert"))) + mbadd,
318                               mbheight, _("Insert"));
319         moffset += obj->w + air;
320         fl_set_object_shortcut(obj, scex(_("MB|#I")), 1);
321         fl_set_object_callback(obj, C_Menus_ShowInsertMenu, 0);
322         obj->u_vdata = this;
323         
324         // Math menu button
325         menu_math = obj = 
326                 fl_add_button(FL_TOUCH_BUTTON,
327                               moffset, yloc,
328                               fl_get_string_width(FL_BOLD_STYLE,
329                                                   MENU_LABEL_SIZE,
330                                                   _("Math"),
331                                                   strlen(_("Math"))) + mbadd,
332                               mbheight, _("Math"));
333         moffset += obj->w + air;
334         fl_set_object_shortcut(obj, scex(_("MB|#M")), 1);
335         fl_set_object_callback(obj, C_Menus_ShowMathMenu, 0);
336         obj->u_vdata = this;
337         
338         // Options menu button
339         menu_options = obj = 
340                 fl_add_button(FL_TOUCH_BUTTON,
341                               moffset, yloc,
342                               fl_get_string_width(FL_BOLD_STYLE,
343                                                   MENU_LABEL_SIZE,
344                                                   _("Options"),
345                                                   strlen(_("Options"))) + mbadd,
346                               mbheight, _("Options"));
347         moffset += obj->w + air;
348         fl_set_object_shortcut(obj, scex(_("MB|#O")), 1);
349         fl_set_object_callback(obj, C_Menus_ShowOptionsMenu, 0);
350         obj->u_vdata = this;
351
352         // Documents menu button
353         menu_buffer = obj = 
354                 fl_add_button(FL_TOUCH_BUTTON,
355                               moffset, yloc,
356                               fl_get_string_width(FL_BOLD_STYLE,
357                                                   MENU_LABEL_SIZE,
358                                                   _("Documents"),
359                                                   strlen(_("Documents"))) + mbadd,
360                               mbheight, _("Documents"));
361         moffset += obj->w + air;
362         fl_set_object_shortcut(obj, scex(_("MB|#D")), 1);
363         fl_set_object_callback(obj, C_Menus_ShowBufferMenu, 0);
364         obj->u_vdata = this;
365         
366         // Help menu button
367         menu_help = obj = 
368                 fl_add_button(FL_TOUCH_BUTTON,
369                               moffset, yloc,
370                               fl_get_string_width(FL_BOLD_STYLE,
371                                                   MENU_LABEL_SIZE,
372                                                   _("Help"),
373                                                   strlen(_("Help"))) + mbadd,
374                               mbheight, _("Help"));
375         moffset += obj->w + air;
376         fl_set_object_shortcut(obj, scex(_("MB|#H")), 1);
377         fl_set_object_callback(obj, C_Menus_ShowHelpMenu, 0);
378         obj->u_vdata = this;
379         
380         fl_end_group();
381
382         // Set the menu buttons atrributes.
383         // Due to a bug in xforms we cant do this only an the group.
384         obj = menu_grp1->next;
385         do {
386                 fl_set_object_boxtype(obj, FL_FLAT_BOX);
387                 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
388                 fl_set_object_lsize(obj, MENU_LABEL_SIZE);
389                 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
390                 fl_set_object_resize(obj, FL_RESIZE_ALL);
391                 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
392                 obj= obj->next;
393         } while (obj != 0 && obj->objclass != FL_END_GROUP);
394
395         // group 2
396         moffset = 0;
397         menu_grp2 = fl_bgn_group();
398         
399         // File menu button
400         menu_file2 = obj = 
401                 fl_add_button(FL_TOUCH_BUTTON,
402                               air+moffset, yloc,
403                               fl_get_string_width(FL_BOLD_STYLE,
404                                                   MENU_LABEL_SIZE,
405                                                   _("File"),
406                                                   strlen(_("File"))) + mbadd,
407                               mbheight, _("File"));
408         moffset += obj->w + air;
409         fl_set_object_shortcut(obj, scex(_("MB|#F")), 1);
410         fl_set_object_callback(obj, C_Menus_ShowFileMenu2, 0);
411         obj->u_vdata = this;
412         
413         // Options menu button
414         menu_options2 = obj = 
415                 fl_add_button(FL_TOUCH_BUTTON,
416                               moffset, yloc,
417                               fl_get_string_width(FL_BOLD_STYLE,
418                                                   MENU_LABEL_SIZE,
419                                                   _("Options"),
420                                                   strlen(_("Options"))) +mbadd,
421                               mbheight, _("Options"));
422         moffset += obj->w + air;
423         fl_set_object_shortcut(obj, scex(_("MB|#O")), 1);
424         fl_set_object_callback(obj, C_Menus_ShowOptionsMenu, 0);
425         obj->u_vdata = this;
426
427         // Help menu button
428         menu_help2 = obj = 
429                 fl_add_button(FL_TOUCH_BUTTON,
430                               moffset, yloc,
431                               fl_get_string_width(FL_BOLD_STYLE,
432                                                   MENU_LABEL_SIZE,
433                                                   _("Help"),
434                                                   strlen(_("Help"))) + mbadd,
435                               mbheight, _("Help"));
436         moffset += obj->w + air;
437         fl_set_object_shortcut(obj, scex(_("MB|#H")), 1);
438         fl_set_object_callback(obj, C_Menus_ShowHelpMenu, 0);
439         obj->u_vdata = this;
440         
441         fl_end_group();
442
443         // Set the menu buttons atrributes.
444         // Due to a bug in xforms we cant do this only an the group.
445         obj = menu_grp2->next;
446         do {
447                 fl_set_object_boxtype(obj, FL_FLAT_BOX);
448                 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
449                 fl_set_object_lsize(obj, MENU_LABEL_SIZE);
450                 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
451                 fl_set_object_resize(obj, FL_RESIZE_ALL);
452                 fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
453                 obj= obj->next;
454         } while (obj != 0 && obj->objclass != FL_END_GROUP);
455 }
456
457
458 void Menus::ScreenOptions()
459 {
460         static int ow = -1, oh;
461
462         // this is not very nice....
463         fl_set_input(fd_form_screen->input_roman, 
464                      lyxrc.roman_font_name.c_str());
465         fl_set_input(fd_form_screen->input_sans, 
466                      lyxrc.sans_font_name.c_str());
467         fl_set_input(fd_form_screen->input_typewriter,
468                      lyxrc.typewriter_font_name.c_str());
469         fl_set_input(fd_form_screen->input_font_norm, 
470                      lyxrc.font_norm.c_str());
471         char tmpstring[10];
472         sprintf(tmpstring, "%d", lyxrc.zoom);
473         fl_set_input(fd_form_screen->intinput_size, tmpstring);
474         if (fd_form_screen->form_screen->visible) {
475                 fl_raise_form(fd_form_screen->form_screen);
476         } else {
477                 fl_show_form(fd_form_screen->form_screen,
478                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
479                              _("Screen Options"));
480                 if (ow < 0) {
481                         ow = fd_form_screen->form_screen->w;
482                         oh = fd_form_screen->form_screen->h;
483                 }
484                 fl_set_form_minsize(fd_form_screen->form_screen, ow, oh);
485         }
486 }
487
488
489 //
490 // Here comes all the menu callbacks.
491 //
492
493 void Menus::ShowFileMenu(FL_OBJECT * ob, long)
494 {
495         Menus * men = static_cast<Menus*>(ob->u_vdata);
496
497         // Regarding the pseudo-menu-button:
498         // ok, ok this is a hack. It would be better to use the menus of the
499         // xforms 0.8 library. but then all popups have to be defined all the
500         // time, code rewriting would be necessary and contex-depending menus
501         // (i.e. the linux-doc-sgml stuff) are a bit more complicated. But of
502         // course it would be more proper (and little faster). So if anybody
503         // likes to do the cleanup, just do it. Matthias
504
505         // set the pseudo menu-button
506         fl_set_object_boxtype(ob, FL_UP_BOX);
507         fl_set_button(ob, 0);
508         fl_redraw_object(ob);
509
510         Buffer * tmpbuffer = men->_view->buffer();
511         LyXFunc * tmpfunc = men->_view->getLyXFunc();
512
513         bool LinuxDoc = tmpbuffer->isLinuxDoc();
514         bool DocBook  = tmpbuffer->isDocBook();
515         bool Literate = tmpbuffer->isLiterate();
516
517         // Import sub-menu
518
519         int SubFileImport = fl_defpup(FL_ObjWin(ob),
520                                       _("Import%t"
521                                         "|LaTeX...%x30"
522                                         "|Ascii Text as Lines...%x31"
523                                         "|Ascii Text as Paragraphs%x32"
524                                         "|Noweb%x33"
525                                         "|LinuxDoc%x34"));
526
527         fl_setpup_shortcut(SubFileImport, 30, scex(_("FIM|Ll#l#L")));
528         fl_setpup_shortcut(SubFileImport, 31, scex(_("FIM|Aa#a#A")));
529         fl_setpup_shortcut(SubFileImport, 32, scex(_("FIM|Pp#p#P")));
530         fl_setpup_shortcut(SubFileImport, 33, scex(_("FIM|Nn#n#N")));
531         fl_setpup_shortcut(SubFileImport, 34, scex(_("FIM|Dd#d#D")));
532
533         // Export sub-menu
534
535         // remember to make this handle linuxdoc too.
536         // and now docbook also.
537         int SubFileExport = 0;
538         if (!LinuxDoc && !DocBook)
539                 SubFileExport= fl_defpup(FL_ObjWin(ob),
540                                          _("Export%t"
541                                            "|as LaTeX...%x40"
542                                            "|as DVI...%x41"
543                                            "|as PostScript...%x42"
544                                            "|as Ascii Text...%x43"
545                                            "|as HTML...%x44"
546                                            "|Custom...%x45"));
547         else if(LinuxDoc)
548                 SubFileExport= fl_defpup(FL_ObjWin(ob),
549                                          _("Export%t"
550                                            "|as LinuxDoc...%x40"
551                                            "|as DVI...%x41"
552                                            "|as PostScript...%x42"
553                                            "|as Ascii Text...%x43"
554                                            "|as HTML...%x44"));
555         else if(DocBook)
556                 SubFileExport= fl_defpup(FL_ObjWin(ob),
557                                          _("Export%t"
558                                            "|as DocBook...%x40"
559                                            "|as DVI...%x41"
560                                            "|as PostScript...%x42"
561                                            "|as Ascii Text...%x43"
562                                            "|as HTML...%x44"));
563
564         fl_setpup_shortcut(SubFileExport, 40, scex(_("FEX|Ll#l#L")));
565         fl_setpup_shortcut(SubFileExport, 41, scex(_("FEX|Dd#d#D")));
566         fl_setpup_shortcut(SubFileExport, 42, scex(_("FEX|Pp#p#P")));
567         fl_setpup_shortcut(SubFileExport, 43, scex(_("FEX|Tt#t#T")));
568         fl_setpup_shortcut(SubFileExport, 44, scex(_("FEX|Hh#h#H")));
569
570         if (!LinuxDoc && !DocBook) {
571                 fl_setpup_shortcut(SubFileExport, 45, scex(_("FEX|mM#m#M")));
572         }
573         
574         int FileMenu = fl_defpup(FL_ObjWin(ob),
575                                  _("New..."
576                                    "|New from template..."
577                                    "|Open...%l"
578                                    "|Close"
579                                    "|Save"
580                                    "|Save As..."
581                                    "|Revert to saved%l"
582                                    "|View dvi"
583                                    "|View PostScript"
584                                    "|Update dvi"
585                                    "|Update PostScript"
586                                    "|Build program%l"
587                                    "|Print..."
588                                    "|Fax..."));
589
590         fl_setpup_shortcut(FileMenu, 1, scex(_("FM|Nn#n#N")));
591         fl_setpup_shortcut(FileMenu, 2, scex(_("FM|tT#t#T")));
592         fl_setpup_shortcut(FileMenu, 3, scex(_("FM|Oo#o#O")));
593         fl_setpup_shortcut(FileMenu, 4, scex(_("FM|Cc#c#C")));
594         fl_setpup_shortcut(FileMenu, 5, scex(_("FM|Ss#s#S")));
595         fl_setpup_shortcut(FileMenu, 6, scex(_("FM|Aa#a#A")));
596         fl_setpup_shortcut(FileMenu, 7, scex(_("FM|Rr#r#R")));
597         fl_setpup_shortcut(FileMenu, 8, scex(_("FM|dD#d#D")));
598         fl_setpup_shortcut(FileMenu, 9, scex(_("FM|wW#w#W")));
599         fl_setpup_shortcut(FileMenu, 10, scex(_("FM|vV#v#V")));
600         fl_setpup_shortcut(FileMenu, 11, scex(_("FM|Uu#u#U")));
601         fl_setpup_shortcut(FileMenu, 12, scex(_("FM|Bb#b#B")));
602         fl_setpup_shortcut(FileMenu, 13, scex(_("FM|Pp#p#P")));
603         fl_setpup_shortcut(FileMenu, 14, scex(_("FM|Ff#f#F")));
604
605         // These commands are disabled when the corresponding programs
606         // are not installed. I simply grey them out, since I do not
607         // want to change their number (JMarc)
608         bool hasLaTeX = lyxrc.latex_command != "none";
609
610         if (!hasLaTeX || lyxrc.view_dvi_command == "none") 
611                 fl_setpup_mode(FileMenu, 8, FL_PUP_GREY);
612         
613         if (!hasLaTeX || lyxrc.view_ps_command == "none") 
614                 fl_setpup_mode(FileMenu, 9, FL_PUP_GREY);
615         
616         if (!hasLaTeX) {
617                 fl_setpup_mode(FileMenu, 10, FL_PUP_GREY);
618                 fl_setpup_mode(FileMenu, 11, FL_PUP_GREY);
619         } 
620
621         if (lyxrc.literate_command == "none" || ! Literate) 
622                 fl_setpup_mode(FileMenu, 12, FL_PUP_GREY);
623
624         if (!hasLaTeX || lyxrc.print_command == "none") 
625                 fl_setpup_mode(FileMenu, 13, FL_PUP_GREY);
626
627         if (!hasLaTeX || lyxrc.fax_command == "none") 
628                 fl_setpup_mode(FileMenu, 14, FL_PUP_GREY);
629
630         bool hasReLyX = lyxrc.relyx_command != "none";
631         if (!hasReLyX) {
632                 // Disable import LaTeX and Noweb
633                 fl_setpup_mode(SubFileImport, 30, FL_PUP_GREY);
634                 fl_setpup_mode(SubFileImport, 33, FL_PUP_GREY);
635         }
636
637         if ( lyxrc.linuxdoc_to_lyx_command == "none")
638                 fl_setpup_mode(SubFileImport, 34, FL_PUP_GREY);
639
640         if (!hasLaTeX) {
641                 // Disable export dvi and export postscript
642                 fl_setpup_mode(SubFileExport, 41, FL_PUP_GREY);
643                 fl_setpup_mode(SubFileExport, 42, FL_PUP_GREY);
644         }
645
646         if ((!LinuxDoc && !DocBook && lyxrc.html_command == "none") ||
647             ( LinuxDoc && lyxrc.linuxdoc_to_html_command == "none") ||
648             ( DocBook  && lyxrc.docbook_to_html_command  == "none")) {
649                 // Disable export HTML
650                 fl_setpup_mode(SubFileExport, 44, FL_PUP_GREY);
651         }
652
653         // xgettext:no-c-format
654         fl_addtopup(FileMenu, _("|Import%m"), SubFileImport);
655         // xgettext:no-c-format
656         fl_addtopup(FileMenu, _("|Export%m%l"), SubFileExport);
657         // xgettext:no-c-format
658         fl_addtopup(FileMenu, _("|Exit%l"));
659         fl_setpup_shortcut(FileMenu, 15, scex(_("FM|Ii#i#I")));
660         fl_setpup_shortcut(FileMenu, 16, scex(_("FM|Ee#e#E")));
661         fl_setpup_shortcut(FileMenu, 17, scex(_("FM|xX#x#X")));
662
663         // make the lastfiles menu
664         int ii = 1;
665         for (LastFiles::const_iterator cit = lastfiles->begin();
666              cit != lastfiles->end() && ii < 10; ++cit, ++ii) {
667                 string tmp = tostr(ii);
668                 string tmp2 = tmp + "#" + tmp;
669                 tmp += ". " + MakeDisplayPath((*cit), 30);
670                 fl_addtopup(FileMenu, tmp.c_str());
671                 fl_setpup_shortcut(FileMenu, 18 - 1 + ii, tmp2.c_str());
672         }
673
674         // place popup
675         fl_setpup_position(
676                 men->_view->getForm()->x + ob->x,
677                 men->_view->getForm()->y + ob->y + ob->h + 10);   
678         int choice = fl_dopup(FileMenu);
679         XFlush(fl_display);
680
681         // set the pseudo menu-button back
682         fl_set_object_boxtype(ob, FL_FLAT_BOX);
683         fl_redraw_object(ob);
684
685         switch (choice) {
686         case -1: case 0: // we won't do anything
687                 break;
688         case  1: tmpfunc->Dispatch(LFUN_MENUNEW); break;
689         case  2: tmpfunc->Dispatch(LFUN_MENUNEWTMPLT); break;
690         case  3: tmpfunc->Dispatch(LFUN_MENUOPEN); break;
691         case  4: tmpfunc->Dispatch(LFUN_CLOSEBUFFER); break;
692         case  5: tmpfunc->Dispatch(LFUN_MENUWRITE); break;
693         case  6: tmpfunc->Dispatch(LFUN_MENUWRITEAS); break;
694         case  7: tmpfunc->Dispatch(LFUN_MENURELOAD); break;
695         case  8: tmpfunc->Dispatch(LFUN_PREVIEW); break;
696         case  9: tmpfunc->Dispatch(LFUN_PREVIEWPS); break;
697         case 10: tmpfunc->Dispatch(LFUN_RUNLATEX); break;
698         case 11: tmpfunc->Dispatch(LFUN_RUNDVIPS); break;
699         case 12: tmpfunc->Dispatch(LFUN_BUILDPROG); break;
700         case 13: tmpfunc->Dispatch(LFUN_MENUPRINT); break;
701         case 14: tmpfunc->Dispatch(LFUN_FAX); break;
702         case 15: // import menu
703         case 30: tmpfunc->Dispatch(LFUN_IMPORT, "latex");
704                 break;
705         case 31: tmpfunc->Dispatch(LFUN_IMPORT, "ascii");
706                 break;
707         case 32: tmpfunc->Dispatch(LFUN_IMPORT, "asciiparagraph");
708                 break;
709         case 33: tmpfunc->Dispatch(LFUN_IMPORT, "noweb");
710                 break;
711         case 34: tmpfunc->Dispatch(LFUN_IMPORT, "linuxdoc");
712                 break;
713         case 16: // export menu
714         case 40:
715                 if (!LinuxDoc && !DocBook)
716                         tmpfunc->Dispatch(LFUN_EXPORT, "latex");
717                 else if(LinuxDoc)
718                         tmpfunc->Dispatch(LFUN_EXPORT, "linuxdoc");
719                 else
720                         tmpfunc->Dispatch(LFUN_EXPORT, "docbook");
721                 break;
722         case 41: tmpfunc->Dispatch(LFUN_EXPORT, "dvi");
723                 break;
724         case 42: tmpfunc->Dispatch(LFUN_EXPORT, "postscript");
725                 break;
726         case 43: tmpfunc->Dispatch(LFUN_EXPORT, "ascii");
727                 break;
728         case 44:
729                 if (!LinuxDoc && !DocBook)
730                         tmpfunc->Dispatch(LFUN_EXPORT, "html");
731                 else if(LinuxDoc)
732                         tmpfunc->Dispatch(LFUN_EXPORT, "html-linuxdoc");
733                 else
734                         tmpfunc->Dispatch(LFUN_EXPORT, "html-docbook");
735                 break;
736         case 45: tmpfunc->Dispatch(LFUN_EXPORT, "custom"); 
737                 break;
738         case 17: tmpfunc->Dispatch(LFUN_QUIT); break;
739                 // Lastfiles:
740         case 18: // The first item with lastfiles.
741         default:
742                 men->currentView()
743                         ->buffer(bufferlist
744                                  .loadLyXFile((*lastfiles)[choice - 18]));
745                 break;
746         }
747         fl_freepup(SubFileImport);
748         fl_freepup(SubFileExport);
749         fl_freepup(FileMenu);
750
751         AllowInput(men->currentView());
752 }
753
754
755 void Menus::ShowFileMenu2(FL_OBJECT * ob, long)
756 {
757         Menus * men = static_cast<Menus*>(ob->u_vdata);
758
759         // Regarding the pseudo-menu-button:
760         // ok, ok this is a hack. It would be better to use the menus of the
761         // xforms 0.8 library. but then all popups have to be defined all the
762         // time, code rewriting would be necessary and contex-depending menus
763         // (i.e. the linux-doc-sgml stuff) are a bit more complicated. But of
764         // course it would be more proper (and little faster). So if anybody
765         // likes to do the cleanup, just do it. Matthias
766
767         // set the pseudo menu-button
768         fl_set_object_boxtype(ob, FL_UP_BOX);
769         fl_set_button(ob, 0);
770         fl_redraw_object(ob);
771
772         LyXFunc * tmpfunc = men->_view->getLyXFunc();
773
774         // Import sub-menu
775         
776         int SubFileImport = fl_defpup(FL_ObjWin(ob),
777                                       _("Import%t"
778                                         "|LaTeX...%x15"
779                                         "|Ascii Text as Lines...%x16"
780                                         "|Ascii Text as Paragraphs...%x17"
781                                         "|Noweb...%x18"
782                                         "|LinuxDoc...%x19"));
783         
784         fl_setpup_shortcut(SubFileImport, 15, scex(_("FIM|Ll#l#L")));
785         fl_setpup_shortcut(SubFileImport, 16, scex(_("FIM|Aa#a#A")));
786         fl_setpup_shortcut(SubFileImport, 17, scex(_("FIM|Pp#p#P")));
787         fl_setpup_shortcut(SubFileImport, 18, scex(_("FIM|Nn#n#N")));
788         fl_setpup_shortcut(SubFileImport, 19, scex(_("FIM|Dd#d#D")));
789
790         bool hasReLyX = lyxrc.relyx_command != "none";
791         if (!hasReLyX) {
792                 // Disable import LaTeX and Noweb
793                 fl_setpup_mode(SubFileImport, 15, FL_PUP_GREY);
794                 fl_setpup_mode(SubFileImport, 18, FL_PUP_GREY);
795         }
796
797         if ( lyxrc.linuxdoc_to_lyx_command == "none")
798                 fl_setpup_mode(SubFileImport, 19, FL_PUP_GREY);
799
800         // This can be done cleaner later.
801         int FileMenu = fl_defpup(FL_ObjWin(ob), 
802                                  _("New..."
803                                    "|New from template..."
804                                    "|Open...%l"
805                                    "|Import%m%l"
806                                    "|Exit%l"), SubFileImport);
807         
808         fl_setpup_shortcut(FileMenu, 1, scex(_("FM|Nn#n#N")));
809         fl_setpup_shortcut(FileMenu, 2, scex(_("FM|tT#t#T")));
810         fl_setpup_shortcut(FileMenu, 3, scex(_("FM|Oo#o#O")));
811         fl_setpup_shortcut(FileMenu, 4, scex(_("FM|Ii#i#I")));
812         fl_setpup_shortcut(FileMenu, 5, scex(_("FM|xX#x#X")));
813         
814         // make the lastfiles menu
815         int ii = 1;
816         for (LastFiles::const_iterator cit = lastfiles->begin();
817              cit != lastfiles->end() && ii < 10; ++cit, ++ii) {
818                 string tmp = tostr(ii);
819                 string tmp2 = tmp + "#" + tmp;
820                 tmp += ". " + MakeDisplayPath((*cit), 30);
821                 fl_addtopup(FileMenu, tmp.c_str());
822                 fl_setpup_shortcut(FileMenu, 18 - 1 + ii, tmp2.c_str());
823         }
824
825         // place popup
826         fl_setpup_position(
827                 men->_view->getForm()->x + ob->x,
828                 men->_view->getForm()->y + ob->y + ob->h + 10);   
829         int choice = fl_dopup(FileMenu);
830         XFlush(fl_display);
831
832         // set the pseudo menu-button back
833         fl_set_object_boxtype(ob, FL_FLAT_BOX);
834         fl_redraw_object(ob);
835
836         switch (choice) {
837         case -1: case 0: // we won't do anything
838                 break;
839         case 1:
840                 tmpfunc->Dispatch(LFUN_MENUNEW);
841                 break;
842         case 2:
843                 tmpfunc->Dispatch(LFUN_MENUNEWTMPLT);
844                 break;
845         case 3:
846                 tmpfunc->Dispatch(LFUN_MENUOPEN);
847                 break;
848         case 4: // import menu
849         case 15: tmpfunc->Dispatch(LFUN_IMPORT, "latex");
850                 break;
851         case 16: tmpfunc->Dispatch(LFUN_IMPORT, "ascii");
852                 break;
853         case 17: tmpfunc->Dispatch(LFUN_IMPORT, "asciiparagraph");
854                 break;
855         case 18: tmpfunc->Dispatch(LFUN_IMPORT, "noweb");
856                 break;
857         case 19: tmpfunc->Dispatch(LFUN_IMPORT, "linuxdoc");
858                 break;
859         case 5:
860                 tmpfunc->Dispatch(LFUN_QUIT);
861                 break;
862                 // Lastfiles:
863         case 6: // The first item with lastfiles.
864         default:
865                 men->currentView()
866                         ->buffer(bufferlist
867                                  .loadLyXFile((*lastfiles)[choice - 6]));
868                 break;
869         }
870
871         fl_freepup(SubFileImport);
872         fl_freepup(FileMenu);
873         AllowInput(men->currentView());
874         return;
875 }
876
877
878 void Menus::ShowEditMenu(FL_OBJECT * ob, long)
879 {
880         Menus * men = static_cast<Menus*>(ob->u_vdata);
881         
882         // set the pseudo menu-button
883         fl_set_object_boxtype(ob, FL_UP_BOX);
884         fl_set_button(ob, 0);
885         fl_redraw_object(ob);
886
887         Buffer * tmpbuffer = men->_view->buffer();
888         LyXFunc * tmpfunc = men->_view->getLyXFunc();
889
890         // Floats & Insets submenu
891         int SubEditFloats= fl_defpup(FL_ObjWin(ob),
892                                      _("Floats & Insets%t"
893                                        "|Open/Close%x21"
894                                        "|Melt%x22"
895                                        "|Open All Footnotes/Margin Notes%x23"
896                                        "|Close All Footnotes/Margin Notes%x24"
897                                        "|Open All Figures/Tables%x25"
898                                        "|Close All Figures/Tables%x26%l"
899                                        "|Remove all Error Boxes%x27"));
900         
901         fl_setpup_shortcut(SubEditFloats, 21, scex(_("EMF|Oo#o#O")));
902         fl_setpup_shortcut(SubEditFloats, 22, scex(_("EMF|Mm#m#M")));
903         fl_setpup_shortcut(SubEditFloats, 23, scex(_("EMF|Aa#a#A")));
904         fl_setpup_shortcut(SubEditFloats, 24, scex(_("EMF|Cc#c#C")));
905         fl_setpup_shortcut(SubEditFloats, 25, scex(_("EMF|Ff#f#F")));
906         fl_setpup_shortcut(SubEditFloats, 26, scex(_("EMF|Tt#t#T")));
907         fl_setpup_shortcut(SubEditFloats, 27, scex(_("EMF|Rr#r#R")));
908
909         // Table submenu
910         int SubEditTable = fl_newpup(FL_ObjWin(ob));
911         if (men->currentView()->available() && 
912             men->currentView()->text->cursor.par->table &&
913             !tmpbuffer->isReadonly()){
914                 LyXTable *table = men->currentView()->text->cursor.par->table;
915
916                 fl_addtopup(SubEditTable, _("Table%t"));
917
918                 if (table->IsMultiColumn(men->currentView()->text->
919                                          NumberOfCell(men->currentView()->
920                                                       text->cursor.par, 
921                                                       men->currentView()->
922                                                       text->cursor.pos)))
923                         fl_addtopup(SubEditTable, _("|Multicolumn%B%x44%l"));
924                 else
925                         fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
926                 fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
927      
928                 if (table->TopLine(men->currentView()->text->
929                                    NumberOfCell(men->currentView()->
930                                                 text->cursor.par, 
931                                                 men->currentView()->text->
932                                                 cursor.pos)))
933                         fl_addtopup(SubEditTable, _("|Line Top%B%x36"));
934                 else
935                         fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
936                 fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
937      
938                 if (table->BottomLine(men->currentView()->text->
939                                       NumberOfCell(men->currentView()->
940                                                    text->cursor.par, 
941                                                    men->currentView()->
942                                                    text->cursor.pos)))
943                         fl_addtopup(SubEditTable, _("|Line Bottom%B%x37"));
944                 else
945                         fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
946                 fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
947
948                 if (table->LeftLine(men->currentView()->text->
949                                     NumberOfCell(men->currentView()->
950                                                  text->cursor.par, 
951                                                  men->currentView()->
952                                                  text->cursor.pos)))
953                         fl_addtopup(SubEditTable, _("|Line Left%B%x38"));
954                 else
955                         fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
956                 fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
957
958                 if (table->RightLine(men->currentView()->text->
959                                      NumberOfCell(men->currentView()->
960                                                   text->cursor.par, 
961                                                   men->currentView()->
962                                                   text->cursor.pos)))
963                         fl_addtopup(SubEditTable, _("|Line Right%B%x39%l"));
964                 else
965                         fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
966                 fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
967
968                 int align =
969                         table->GetAlignment(men->currentView()->text->
970                                             NumberOfCell(men->currentView()->
971                                                          text->cursor.par, 
972                                                          men->currentView()->
973                                                          text->cursor.pos));
974                 if (align == LYX_ALIGN_LEFT)
975                         fl_addtopup(SubEditTable, _("|Align Left%R%x40"));
976                 else
977                         fl_addtopup(SubEditTable, _("|Align Left%r%x40"));
978                 fl_setpup_shortcut(SubEditTable, 40, scex(_("EMT|eE#e#E")));
979
980                 if (align == LYX_ALIGN_RIGHT)
981                         fl_addtopup(SubEditTable, _("|Align Right%R%x41"));
982                 else
983                         fl_addtopup(SubEditTable, _("|Align Right%r%x41"));
984                 fl_setpup_shortcut(SubEditTable, 41, scex(_("EMT|iI#i#I")));
985
986                 if (align == LYX_ALIGN_CENTER)
987                         fl_addtopup(SubEditTable, _("|Align Center%R%x42%l"));
988                 else
989                         fl_addtopup(SubEditTable, _("|Align Center%r%x42%l"));
990                 fl_setpup_shortcut(SubEditTable, 42, scex(_("EMT|Cc#c#C")));
991
992                 // xgettext:no-c-format
993                 fl_addtopup(SubEditTable, _("|Append Row%x32"));
994                 fl_setpup_shortcut(SubEditTable, 32, scex(_("EMT|oO#o#O")));
995                 // xgettext:no-c-format
996                 fl_addtopup(SubEditTable, _("|Append Column%x33%l"));
997                 fl_setpup_shortcut(SubEditTable, 33, scex(_("EMT|uU#u#U")));
998                 // xgettext:no-c-format
999                 fl_addtopup(SubEditTable, _("|Delete Row%x34"));
1000                 fl_setpup_shortcut(SubEditTable, 34, scex(_("EMT|wW#w#W")));
1001                 // xgettext:no-c-format
1002                 fl_addtopup(SubEditTable, _("|Delete Column%x35%l"));
1003                 fl_setpup_shortcut(SubEditTable, 35, scex(_("EMT|nN#n#N")));
1004                 // xgettext:no-c-format
1005                 fl_addtopup(SubEditTable, _("|Delete Table%x43"));
1006                 fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
1007         } else if (men->currentView()->the_locking_inset &&
1008                    (men->currentView()->the_locking_inset->LyxCode() ==
1009                     Inset::TABULAR_CODE) &&
1010                    !tmpbuffer->isReadonly()) {
1011                 InsetTabular * inset = static_cast<InsetTabular *>(men->currentView()->the_locking_inset);
1012                 LyXTabular * table = inset->tabular;
1013
1014                 fl_addtopup(SubEditTable, _("Table%t"));
1015
1016                 if (table->IsMultiColumn(inset->GetActCell()))
1017                         fl_addtopup(SubEditTable, _("|Multicolumn%B%x44%l"));
1018                 else
1019                         fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
1020                 fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
1021
1022                 if (table->TopLine(inset->GetActCell()))
1023                         fl_addtopup(SubEditTable, _("|Line Top%B%x36"));
1024                 else
1025                         fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
1026                 fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
1027      
1028                 if (table->BottomLine(inset->GetActCell()))
1029                         fl_addtopup(SubEditTable, _("|Line Bottom%B%x37"));
1030                 else
1031                         fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
1032                 fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
1033
1034                 if (table->LeftLine(inset->GetActCell()))
1035                         fl_addtopup(SubEditTable, _("|Line Left%B%x38"));
1036                 else
1037                         fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
1038                 fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
1039
1040                 if (table->RightLine(inset->GetActCell()))
1041                         fl_addtopup(SubEditTable, _("|Line Right%B%x39%l"));
1042                 else
1043                         fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
1044                 fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
1045
1046                 int align = table->GetAlignment(inset->GetActCell());
1047                 if (align == LYX_ALIGN_LEFT)
1048                         fl_addtopup(SubEditTable, _("|Align Left%R%x40"));
1049                 else
1050                         fl_addtopup(SubEditTable, _("|Align Left%r%x40"));
1051                 fl_setpup_shortcut(SubEditTable, 40, scex(_("EMT|eE#e#E")));
1052
1053                 if (align == LYX_ALIGN_RIGHT)
1054                         fl_addtopup(SubEditTable, _("|Align Right%R%x41"));
1055                 else
1056                         fl_addtopup(SubEditTable, _("|Align Right%r%x41"));
1057                 fl_setpup_shortcut(SubEditTable, 41, scex(_("EMT|iI#i#I")));
1058
1059                 if (align == LYX_ALIGN_CENTER)
1060                         fl_addtopup(SubEditTable, _("|Align Center%R%x42%l"));
1061                 else
1062                         fl_addtopup(SubEditTable, _("|Align Center%r%x42%l"));
1063                 fl_setpup_shortcut(SubEditTable, 42, scex(_("EMT|Cc#c#C")));
1064
1065                 // xgettext:no-c-format
1066                 fl_addtopup(SubEditTable, _("|Append Row%x32"));
1067                 fl_setpup_shortcut(SubEditTable, 32, scex(_("EMT|oO#o#O")));
1068                 // xgettext:no-c-format
1069                 fl_addtopup(SubEditTable, _("|Append Column%x33%l"));
1070                 fl_setpup_shortcut(SubEditTable, 33, scex(_("EMT|uU#u#U")));
1071                 // xgettext:no-c-format
1072                 fl_addtopup(SubEditTable, _("|Delete Row%x34"));
1073                 fl_setpup_shortcut(SubEditTable, 34, scex(_("EMT|wW#w#W")));
1074                 // xgettext:no-c-format
1075                 fl_addtopup(SubEditTable, _("|Delete Column%x35%l"));
1076                 fl_setpup_shortcut(SubEditTable, 35, scex(_("EMT|nN#n#N")));
1077                 // xgettext:no-c-format
1078                 fl_addtopup(SubEditTable, _("|Delete Table%x43"));
1079                 fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
1080         } else {
1081                 fl_addtopup(SubEditTable, _("Table%t"));
1082                 // xgettext:no-c-format
1083                 fl_addtopup(SubEditTable, _("|Insert table%x31"));
1084                 fl_setpup_shortcut(SubEditTable, 31, scex(_("EMT|Ii#i#I")));
1085         }
1086
1087         int SubVersionControl =         fl_newpup(FL_ObjWin(ob));
1088         fl_addtopup(SubVersionControl, _("Version Control%t"));
1089         if (tmpbuffer->lyxvc.inUse()) {
1090                 // xgettext:no-c-format
1091                 fl_addtopup(SubVersionControl, _("|Register%d%x51"));
1092                 if (tmpbuffer->isReadonly()) {
1093                         // signifies that the file is not checked out
1094                         // xgettext:no-c-format
1095                         fl_addtopup(SubVersionControl, _("|Check In Changes%d%x52"));
1096                         // xgettext:no-c-format
1097                         fl_addtopup(SubVersionControl, _("|Check Out for Edit%x53"));
1098                 } else {
1099                         // signifies that the file is checked out
1100                         // xgettext:no-c-format
1101                         fl_addtopup(SubVersionControl, _("|Check In Changes%x52"));
1102                         // xgettext:no-c-format
1103                         fl_addtopup(SubVersionControl, _("|Check Out for Edit%d%x53"));
1104                 }
1105                 // xgettext:no-c-format
1106                 fl_addtopup(SubVersionControl, _("|Revert to last version%x54"));
1107                 // xgettext:no-c-format
1108                 fl_addtopup(SubVersionControl, _("|Undo last check in%x55"));
1109                 // xgettext:no-c-format
1110                 fl_addtopup(SubVersionControl, _("|Show History%x56"));
1111         } else {
1112                 // xgettext:no-c-format
1113                 fl_addtopup(SubVersionControl, _("|Register%x51"));
1114         }
1115         // the shortcuts are not good.
1116         fl_setpup_shortcut(SubVersionControl, 51, scex(_("EMV|Rr#r#R")));
1117         fl_setpup_shortcut(SubVersionControl, 52, scex(_("EMV|Ii#i#I")));
1118         fl_setpup_shortcut(SubVersionControl, 53, scex(_("EMV|Oo#o#O")));
1119         fl_setpup_shortcut(SubVersionControl, 54, scex(_("EMV|lL#l#l")));
1120         fl_setpup_shortcut(SubVersionControl, 55, scex(_("EMV|Uu#u#U")));
1121         fl_setpup_shortcut(SubVersionControl, 56, scex(_("EMV|Hh#h#H")));
1122
1123         int EditMenu= fl_defpup(FL_ObjWin(ob),
1124                                 _("Undo"
1125                                   "|Redo %l"
1126                                   "|Cut"
1127                                   "|Copy"
1128                                   "|Paste%l"
1129                                   "|Find & Replace..."
1130                                   "|Go to Error"
1131                                   "|Go to Note"
1132                                   "|Floats & Insets%m"
1133                                   "|Table%m"
1134                                   "|Spellchecker...."
1135                                   "|Check TeX"
1136                                   "|Table of Contents..."
1137                                   "|List of Figures..."
1138                                   "|List of Tables..."
1139                                   "|List of Algorithms...%l"
1140                                   "|Version Control%m%l"
1141                                   "|View LaTeX log file%l"
1142                                   "|Paste Primary Selection as Lines"
1143                                   "|Paste Primary Selection as Paragraphs"),
1144                                 SubEditFloats, SubEditTable, SubVersionControl);
1145
1146         fl_setpup_shortcut(EditMenu, 1, scex(_("EM|Uu#u#U")));
1147         fl_setpup_shortcut(EditMenu, 2, scex(_("EM|Rr#r#R")));
1148         fl_setpup_shortcut(EditMenu, 3, scex(_("EM|Cc#c#C")));
1149         fl_setpup_shortcut(EditMenu, 4, scex(_("EM|oO#o#O")));
1150         fl_setpup_shortcut(EditMenu, 5, scex(_("EM|Pp#p#P")));
1151         fl_setpup_shortcut(EditMenu, 6, scex(_("EM|Ff#f#F")));
1152         fl_setpup_shortcut(EditMenu, 7, scex(_("EM|Ee#e#E")));
1153         fl_setpup_shortcut(EditMenu, 8, scex(_("EM|Nn#n#N")));
1154         fl_setpup_shortcut(EditMenu, 9, scex(_("EM|Ii#i#I")));
1155         //fl_setpup_shortcut(EditMenu, 10, scex(_("EM|Tt#t#T")));
1156         fl_setpup_shortcut(EditMenu, 11, scex(_("EM|Ss#s#S")));
1157         fl_setpup_shortcut(EditMenu, 12, scex(_("EM|hH#h#H")));
1158         fl_setpup_shortcut(EditMenu, 13, scex(_("EM|Tt#t#T")));
1159         //fl_setpup_shortcut(EditMenu, 14, scex(_("EM|Ff#f#F")));
1160         //fl_setpup_shortcut(EditMenu, 15, scex(_("EM|bB#b#B")));
1161         //fl_setpup_shortcut(EditMenu, 16, scex(_("EM|mM#m#M")));
1162         fl_setpup_shortcut(EditMenu, 17, scex(_("EM|Vv#v#V")));
1163         fl_setpup_shortcut(EditMenu, 18, scex(_("EM|wW#w#W")));
1164         fl_setpup_shortcut(EditMenu, 19, scex(_("EM|Ll#l#L")));
1165         fl_setpup_shortcut(EditMenu, 20, scex(_("EM|gG#g#G")));
1166       
1167         // disable unavailable entries.
1168         if(tmpbuffer->undostack.empty())
1169                 fl_setpup_mode(EditMenu, 1, FL_PUP_GREY);
1170         if(tmpbuffer->redostack.empty())
1171                 fl_setpup_mode(EditMenu, 2, FL_PUP_GREY);
1172         if(lyxrc.isp_command == "none") 
1173                 fl_setpup_mode(EditMenu, 11, FL_PUP_GREY);
1174         if(lyxrc.chktex_command == "none") 
1175                 fl_setpup_mode(EditMenu, 12, FL_PUP_GREY);
1176
1177         if (tmpbuffer->isReadonly()) {
1178                 fl_setpup_mode(EditMenu, 1, FL_PUP_GREY); 
1179                 fl_setpup_mode(EditMenu, 2, FL_PUP_GREY); 
1180                 fl_setpup_mode(EditMenu, 3, FL_PUP_GREY); 
1181                 fl_setpup_mode(EditMenu, 5, FL_PUP_GREY); 
1182                 fl_setpup_mode(EditMenu, 19, FL_PUP_GREY); 
1183                 fl_setpup_mode(EditMenu, 20, FL_PUP_GREY);
1184         }
1185         
1186         fl_setpup_position(men->_view->getForm()->x + ob->x,
1187                            men->_view->getForm()->y + ob->y +
1188                            ob->h + 10);   
1189         int choice = fl_dopup(EditMenu);
1190         XFlush(fl_display);
1191    
1192         // set the pseudo menu-button back
1193         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1194         fl_redraw_object(ob);
1195
1196         switch (choice) {
1197         case  1: tmpfunc->Dispatch(LFUN_UNDO); break;
1198         case  2: tmpfunc->Dispatch(LFUN_REDO); break;
1199         case  3: tmpfunc->Dispatch(LFUN_CUT); break;
1200         case  4: tmpfunc->Dispatch(LFUN_COPY); break;
1201         case  5: tmpfunc->Dispatch(LFUN_PASTE); break;
1202         case  6: tmpfunc->Dispatch(LFUN_MENUSEARCH); break;
1203         case  7: tmpfunc->Dispatch(LFUN_GOTOERROR); break;
1204         case  8: tmpfunc->Dispatch(LFUN_GOTONOTE); break;
1205         case  9: // floats & insets
1206                 break;
1207         case 10:// table 
1208                 break;
1209         case 11: tmpfunc->Dispatch(LFUN_SPELLCHECK); break;
1210         case 12: tmpfunc->Dispatch(LFUN_RUNCHKTEX); break;
1211         case 13: tmpfunc->Dispatch(LFUN_TOCVIEW); break;
1212         case 14: tmpfunc->Dispatch(LFUN_LOFVIEW); break;
1213         case 15: tmpfunc->Dispatch(LFUN_LOTVIEW); break;
1214         case 16: tmpfunc->Dispatch(LFUN_LOAVIEW); break;
1215         case 17: // version control
1216                 break;
1217         case 18: tmpfunc->Dispatch(LFUN_LATEX_LOG); break;
1218         case 19: tmpfunc->Dispatch(LFUN_PASTESELECTION, "line"); break;
1219         case 20: tmpfunc->Dispatch(LFUN_PASTESELECTION, "paragraph"); break;
1220
1221                 // floats & insets sub-menu
1222         case 21: men->currentView()->toggleFloat(); break;
1223         case 22: tmpfunc->Dispatch(LFUN_MELT); break;
1224         case 23: men->currentView()->allFloats(1, 0); break;
1225         case 24: men->currentView()->allFloats(0, 0); break;
1226         case 25: men->currentView()->allFloats(1, 1); break;
1227         case 26: men->currentView()->allFloats(0, 1); break;
1228         case 27: tmpfunc->Dispatch(LFUN_REMOVEERRORS); break;
1229
1230         case 31: tmpfunc->Dispatch(LFUN_TABLE); break;
1231                 // this is really temporary. We need new function in keybind.C
1232                 // These should set the minibuffer, too.
1233         case 32: case 33: case 34:
1234         case 35: case 36: case 37:
1235         case 38: case 39: case 40: 
1236         case 41: case 42: case 43:
1237         case 44: 
1238                 if (men->currentView()->available()) {
1239                         men->currentView()->hideCursor();
1240                         if (!men->currentView()->text->selection){
1241                                 men->currentView()->beforeChange(); 
1242                                 men->currentView()->update(-2);
1243                         }
1244                         if (men->currentView()->the_locking_inset &&
1245                             (men->currentView()->the_locking_inset->LyxCode()
1246                              == Inset::TABULAR_CODE)) {
1247                                 InsetTabular * inset =
1248                                     static_cast<InsetTabular *>
1249                                        (men->currentView()->the_locking_inset);
1250                                 inset->TabularFeatures(men->currentView(), choice - 32);
1251                         } else {
1252                                 men->currentView()->text->
1253                                         TableFeatures(choice - 32);
1254                                 men->currentView()->update(1);
1255                         }
1256                 }
1257                 break;
1258                 // version control sub-menu
1259         case 51: // register
1260                 tmpfunc->Dispatch(LFUN_VC_REGISTER);
1261                 break;
1262         case 52: // check in
1263                 tmpfunc->Dispatch(LFUN_VC_CHECKIN);
1264                 break;
1265         case 53: // check out
1266                 tmpfunc->Dispatch(LFUN_VC_CHECKOUT);
1267                 break;
1268         case 54: // revert to last
1269                 tmpfunc->Dispatch(LFUN_VC_REVERT);
1270                 break;
1271         case 55: // undo last
1272                 tmpfunc->Dispatch(LFUN_VC_UNDO);
1273                 break;
1274         case 56: // show history
1275                 tmpfunc->Dispatch(LFUN_VC_HISTORY);
1276                 break;
1277         }
1278
1279         fl_freepup(EditMenu);
1280         fl_freepup(SubEditFloats);
1281         fl_freepup(SubEditTable);
1282         fl_freepup(SubVersionControl);
1283 }
1284
1285 vector<int>::size_type const max_number_of_menus = 32;
1286
1287 void Add_to_toc_menu(vector<Buffer::TocItem> const & toclist, 
1288                      unsigned int from, unsigned int to, int depth,
1289                      int menu, vector<int> & menus, FL_OBJECT * ob)
1290 {
1291         unsigned int const max_number_of_items = 25;
1292         string::size_type const max_item_length = 45;
1293         if (to - from <= max_number_of_items) {
1294                 for (unsigned int i = from; i < to; ++i) {
1295                         string entry(4 * max(0, toclist[i].depth - depth),' ');
1296                         entry += toclist[i].str;
1297                         if (entry.size() > max_item_length)
1298                                 entry = entry.substr(0, max_item_length-3) + "...";
1299                         entry += "%x";
1300                         entry += tostr(i + 1);
1301                         fl_addtopup(menu, entry.c_str());
1302                 }
1303         } else {
1304                 unsigned int pos = from;
1305                 unsigned int count = 0;
1306                 while (pos < to) {
1307                         ++count;
1308                         if (count > max_number_of_items) {
1309                                 fl_addtopup(menu, ". . .%d");
1310                                 break;
1311                         }
1312                         unsigned int new_pos = pos+1;
1313                         while (new_pos < to &&
1314                                toclist[new_pos].depth > depth)
1315                                 ++new_pos;
1316
1317                         string entry(4 * max(0, toclist[pos].depth - depth), ' ');
1318                         entry += toclist[pos].str;
1319                         if (entry.size() > max_item_length)
1320                                 entry = entry.substr(0, max_item_length-3) + "...";
1321
1322                         if (new_pos == pos + 1) {
1323                                 entry += "%x";
1324                                 entry += tostr(pos + 1);
1325                                 fl_addtopup(menu, entry.c_str());
1326                         } else if (menus.size() < max_number_of_menus) {
1327                                 int menu2 = fl_newpup(FL_ObjWin(ob));
1328                                 menus.push_back(menu2);
1329                                 Add_to_toc_menu(toclist, pos, new_pos,
1330                                                 depth + 1, menu2, menus,ob);
1331                                 entry += "%m";
1332                                 fl_addtopup(menu, entry.c_str(), menu2);
1333                         } else {
1334                                 entry += "%d";
1335                                 fl_addtopup(menu, entry.c_str());
1336                         }
1337                         pos = new_pos;
1338                 }
1339         }
1340 }
1341
1342 int const BIG_NUM = 1048576;
1343
1344 void Menus::ShowTocMenu(FL_OBJECT * ob, long)
1345 {
1346         Menus * men = static_cast<Menus*>(ob->u_vdata);
1347         vector<int> menus;
1348
1349         // set the pseudo menu-button
1350         fl_set_object_boxtype(ob, FL_UP_BOX);
1351         fl_set_button(ob, 0);
1352         fl_redraw_object(ob);
1353    
1354         int TocMenu = fl_newpup(FL_ObjWin(ob));
1355         menus.push_back(TocMenu);
1356         vector<vector<Buffer::TocItem> > toclist =
1357                 men->currentView()->buffer()->getTocList();
1358
1359         //xgettext:no-c-format
1360         static char const * MenuNames[3] = { N_("List of Figures%m"),
1361         //xgettext:no-c-format
1362                                              N_("List of Tables%m"),
1363         //xgettext:no-c-format
1364                                              N_("List of Algorithms%m") };
1365
1366         int max_nonempty = 0;
1367         for (int j = 1; j <= 3; ++j)
1368                 if (!toclist[j].empty())
1369                         max_nonempty = j;
1370
1371         for (int j = 1; j <= 3; ++j)
1372                 if (!toclist[j].empty()) {
1373                         int menu2 = fl_newpup(FL_ObjWin(ob));
1374                         menus.push_back(menu2);
1375                         for (unsigned int i = 0; i < toclist[j].size(); ++i)
1376                                 fl_addtopup(menu2,
1377                                             (toclist[j][i].str + "%x"
1378                                              + tostr(i+1+j*BIG_NUM)).c_str());
1379                         if (j == max_nonempty) {
1380                                 string tmp = _(MenuNames[j-1]);
1381                                 tmp += "%l";
1382                                 fl_addtopup(TocMenu, tmp.c_str(), menu2);
1383                         } else
1384                                 fl_addtopup(TocMenu, _(MenuNames[j-1]), menu2);
1385                 }
1386
1387         Add_to_toc_menu(toclist[0], 0, toclist[0].size(), 0,
1388                         TocMenu, menus, ob);
1389
1390         fl_setpup_position(
1391                 men->_view->getForm()->x + ob->x,
1392                 men->_view->getForm()->y + ob->y + ob->h + 10);   
1393         int choice = fl_dopup(TocMenu);
1394         XFlush(fl_display);
1395
1396         // set the pseudo menu-button back
1397         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1398         fl_redraw_object(ob);
1399         if (choice == 0)
1400                 men->_view->getLyXFunc()->Dispatch(LFUN_TOCVIEW);
1401         else if (choice > 0) {
1402                 int type = choice / BIG_NUM;
1403                 int num = (choice % BIG_NUM) - 1;
1404                 BufferView *bv = men->currentView();
1405                 bv->beforeChange();
1406                 bv->text->SetCursor(toclist[type][num].par, 0);
1407                 bv->text->sel_cursor = bv->text->cursor;
1408                 bv->update(0);
1409         }
1410         for (unsigned int i = 0; i < menus.size(); ++i)
1411                 fl_freepup(menus[i]);
1412 }
1413
1414 void Add_to_refs_menu(vector<string> const & label_list, int offset,
1415                      int menu, vector<int> & menus, FL_OBJECT * ob)
1416 {
1417         typedef vector<string>::size_type size_type;
1418         size_type const max_number_of_items = 25;
1419         size_type const max_number_of_items2 = 20;
1420
1421         if (label_list.size() <= max_number_of_items)
1422                 for (size_type i = 0; i < label_list.size(); ++i)
1423                         fl_addtopup(menu,
1424                                     (label_list[i] + "%x"
1425                                      +tostr(i+offset)).c_str());
1426         else {
1427                 size_type count = 0;
1428                 for (size_type i = 0; i < label_list.size();
1429                      i += max_number_of_items2) {
1430                         ++count;
1431                         if (count > max_number_of_items) {
1432                                 fl_addtopup(menu, ". . .%d");
1433                                 break;
1434                         }
1435                         size_type j = std::min(label_list.size(),
1436                                                i+max_number_of_items2);
1437                         string entry = label_list[i]+".."+label_list[j-1];
1438
1439                         if (menus.size() < max_number_of_menus) {
1440                                 int menu2 = fl_newpup(FL_ObjWin(ob));
1441                                 menus.push_back(menu2);
1442                                 for (size_type k = i;  k < j; ++k)
1443                                         fl_addtopup(menu2,
1444                                                     (label_list[k] + "%x"
1445                                                      + tostr(k+offset)).c_str());
1446                                 entry += "%m";
1447                                 fl_addtopup(menu, entry.c_str(), menu2);
1448                         } else {
1449                                 entry += "%d";
1450                                 fl_addtopup(menu, entry.c_str());
1451                         }
1452                 }
1453         }
1454 }
1455
1456 void Menus::ShowRefsMenu(FL_OBJECT * ob, long)
1457 {
1458         vector<int> menus;
1459
1460         Menus * men = static_cast<Menus*>(ob->u_vdata);
1461
1462         // set the pseudo menu-button
1463         fl_set_object_boxtype(ob, FL_UP_BOX);
1464         fl_set_button(ob, 0);
1465         fl_redraw_object(ob);
1466    
1467         int RefsMenu = fl_newpup(FL_ObjWin(ob));
1468         menus.push_back(RefsMenu);
1469         Buffer * buffer = men->currentView()->buffer();
1470         vector<string> label_list = buffer->getLabelList();
1471         sort(label_list.begin(), label_list.end());
1472
1473         //xgettext:no-c-format
1474         static char const * MenuNames[6] = { N_("Insert Reference%m"),
1475         //xgettext:no-c-format
1476                                              N_("Insert Page Number%m"),
1477         //xgettext:no-c-format
1478                                              N_("Insert vref%m"),
1479         //xgettext:no-c-format
1480                                              N_("Insert vpageref%m"),
1481         //xgettext:no-c-format
1482                                              N_("Insert Pretty Ref%m"),
1483         //xgettext:no-c-format
1484                                              N_("Goto Reference%m") };
1485
1486         for (int j = 0; j < 6; ++j) {
1487                 if (menus.size() < max_number_of_menus) {
1488                         int menu2 = fl_newpup(FL_ObjWin(ob));
1489                         menus.push_back(menu2);
1490                         Add_to_refs_menu(label_list, 1+j*BIG_NUM, menu2, menus, ob);
1491                         fl_addtopup(RefsMenu, _(MenuNames[j]), menu2);
1492                 } else {
1493                         string tmp = _(MenuNames[j]);
1494                         tmp += "%d";
1495                         fl_addtopup(RefsMenu, tmp.c_str());     
1496                 }
1497         }
1498
1499         bool empty = label_list.empty();
1500         bool sgml = buffer->isSGML();
1501         bool readonly = buffer->isReadonly();
1502
1503         if (empty)
1504                 fl_setpup_mode(RefsMenu, 6, FL_PUP_GREY);
1505         if (empty || readonly) {
1506                 fl_setpup_mode(RefsMenu, 1, FL_PUP_GREY);
1507                 fl_setpup_mode(RefsMenu, 2, FL_PUP_GREY);
1508         }
1509         if (empty || readonly || sgml) {
1510                 fl_setpup_mode(RefsMenu, 3, FL_PUP_GREY);
1511                 fl_setpup_mode(RefsMenu, 4, FL_PUP_GREY);
1512                 fl_setpup_mode(RefsMenu, 5, FL_PUP_GREY);
1513         }
1514
1515         fl_setpup_position(
1516                 men->_view->getForm()->x + ob->x,
1517                 men->_view->getForm()->y + ob->y + ob->h + 10);   
1518         int choice = fl_dopup(RefsMenu);
1519         XFlush(fl_display);
1520
1521         // set the pseudo menu-button back
1522         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1523         fl_redraw_object(ob);
1524
1525         if (choice > 0) {
1526                 int type = choice / BIG_NUM;
1527                 int num = (choice % BIG_NUM) - 1;
1528                 if (type >= 5)
1529                         men->_view->getLyXFunc()->Dispatch(LFUN_REFGOTO,
1530                                                            label_list[num].c_str());
1531                 else {
1532                         static string const commands[5]
1533                                 = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
1534                                     "\\prettyref"};
1535                         string t = commands[type] + "{" + label_list[num] + "}";
1536                         men->currentView()->insertInset(new InsetRef(t, buffer));
1537                 }
1538         }
1539
1540         for (unsigned int i = 0; i < menus.size(); ++i)
1541                 fl_freepup(menus[i]);
1542 }
1543
1544
1545 void Menus::ShowLayoutMenu(FL_OBJECT * ob, long)
1546 {
1547         Menus * men = static_cast<Menus*>(ob->u_vdata);
1548
1549         if (!men->currentView()->available())
1550                 return;
1551         
1552         // set the pseudo menu-button
1553         fl_set_object_boxtype(ob, FL_UP_BOX);
1554         fl_set_button(ob, 0);
1555         fl_redraw_object(ob);
1556    
1557         Buffer * tmpbuffer = men->_view->buffer();
1558         LyXFunc * tmpfunc = men->_view->getLyXFunc();
1559
1560         int LayoutMenu = fl_newpup(FL_ObjWin(ob));
1561         fl_addtopup(LayoutMenu, _("Character..."
1562                                   "|Paragraph..."
1563                                   "|Document..."
1564                                   "|Paper..."
1565                                   "|Table..."
1566                                   "|Quotes...%l"
1567                                   "|Emphasize Style%b"
1568                                   "|Noun Style%b"
1569                                   "|Bold Style%b"
1570                                   "|TeX Style%b%l"
1571                                   "|Change Environment Depth"
1572                                   "|LaTeX Preamble..."
1573                                   "|Start of Appendix%l"
1574                                   "|Save layout as default"));
1575         fl_setpup_shortcut(LayoutMenu, 1, scex(_("LM|Cc#c#C")));
1576         fl_setpup_shortcut(LayoutMenu, 2, scex(_("LM|Pp#p#P")));
1577         fl_setpup_shortcut(LayoutMenu, 3, scex(_("LM|Dd#d#D")));
1578         fl_setpup_shortcut(LayoutMenu, 4, scex(_("LM|aA#a#A")));
1579         fl_setpup_shortcut(LayoutMenu, 5, scex(_("LM|eE#e#E")));
1580         fl_setpup_shortcut(LayoutMenu, 6, scex(_("LM|Qq#q#Q")));
1581         fl_setpup_shortcut(LayoutMenu, 7, scex(_("LM|mM#m#M")));
1582         fl_setpup_shortcut(LayoutMenu, 8, scex(_("LM|Nn#n#N")));
1583         fl_setpup_shortcut(LayoutMenu, 9, scex(_("LM|Bb#b#B")));
1584         fl_setpup_shortcut(LayoutMenu, 10, scex(_("LM|Tt#t#T")));
1585         fl_setpup_shortcut(LayoutMenu, 11, scex(_("LM|vV#v#V")));
1586         fl_setpup_shortcut(LayoutMenu, 12, scex(_("LM|Ll#l#L")));
1587         fl_setpup_shortcut(LayoutMenu, 13, scex(_("LM|xX#x#X")));
1588         fl_setpup_shortcut(LayoutMenu, 14, scex(_("LM|Ss#s#S")));
1589
1590         // Set values of checkboxes according to font
1591         LyXFont font = men->currentView()->text->real_current_font;
1592         if (font.emph() == LyXFont::ON)
1593                 fl_setpup_mode(LayoutMenu, 7, FL_PUP_CHECK);
1594         if (font.noun() == LyXFont::ON)
1595                 fl_setpup_mode(LayoutMenu, 8, FL_PUP_CHECK);
1596         if (font.series() == LyXFont::BOLD_SERIES)
1597                 fl_setpup_mode(LayoutMenu, 9, FL_PUP_CHECK);
1598         if (font.latex() == LyXFont::ON)
1599                 fl_setpup_mode(LayoutMenu, 10, FL_PUP_CHECK);
1600            
1601         // Grey out unavailable entries
1602         if (!men->currentView()->text->cursor.par->table)
1603                 fl_setpup_mode(LayoutMenu, 5, FL_PUP_GREY);
1604
1605         if (tmpbuffer->isReadonly()) {
1606                 fl_setpup_mode(LayoutMenu, 1, FL_PUP_GREY);
1607                 fl_setpup_mode(LayoutMenu, 6, FL_PUP_GREY);
1608                 fl_setpup_mode(LayoutMenu, 11, FL_PUP_GREY);
1609         }
1610
1611         fl_setpup_position(
1612                 men->_view->getForm()->x + ob->x,
1613                 men->_view->getForm()->y + ob->y + ob->h + 10);
1614         int choice = fl_dopup(LayoutMenu);
1615         XFlush(fl_display);
1616
1617         // set the pseudo menu-button back
1618         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1619         fl_redraw_object(ob);
1620
1621         switch (choice) {
1622         case 1:  tmpfunc->Dispatch(LFUN_LAYOUT_CHARACTER); break;
1623         case 2:  tmpfunc->Dispatch(LFUN_LAYOUT_PARAGRAPH); break;
1624         case 3:  tmpfunc->Dispatch(LFUN_LAYOUT_DOCUMENT);  break;
1625         case 4:  tmpfunc->Dispatch(LFUN_LAYOUT_PAPER); break;
1626         case 5:  tmpfunc->Dispatch(LFUN_LAYOUT_TABLE, "true"); break;
1627         case 6:  tmpfunc->Dispatch(LFUN_LAYOUT_QUOTES); break;
1628         case 7:  tmpfunc->Dispatch(LFUN_EMPH); break;
1629         case 8:  tmpfunc->Dispatch(LFUN_NOUN); break;
1630         case 9:  tmpfunc->Dispatch(LFUN_BOLD); break;
1631         case 10: tmpfunc->Dispatch(LFUN_TEX); break;
1632         case 11: tmpfunc->Dispatch(LFUN_DEPTH_PLUS); break;
1633         case 12: tmpfunc->Dispatch(LFUN_LAYOUT_PREAMBLE); break;
1634         case 13: tmpfunc->Dispatch(LFUN_APPENDIX); break;
1635         case 14: tmpfunc->Dispatch(LFUN_LAYOUT_SAVE_DEFAULT); break;
1636         }
1637         fl_freepup(LayoutMenu); 
1638 }
1639
1640
1641 void Menus::ShowInsertMenu(FL_OBJECT * ob, long)
1642 {
1643         Menus * men = static_cast<Menus*>(ob->u_vdata);
1644         
1645         // set the pseudo menu-button
1646         fl_set_object_boxtype(ob, FL_UP_BOX);
1647         fl_set_button(ob, 0);
1648         fl_redraw_object(ob);
1649  
1650         Buffer * tmpbuffer = men->_view->buffer();
1651         LyXFunc * tmpfunc = men->_view->getLyXFunc();
1652
1653         int SubInsertAscii = fl_defpup(FL_ObjWin(ob),
1654                                        _("Import ASCII file%t"
1655                                          "|As Lines%x41"
1656                                          "|As Paragraphs%x42"));
1657         
1658         fl_setpup_shortcut(SubInsertAscii, 41, scex(_("IMA|Ll#l#L")));
1659         fl_setpup_shortcut(SubInsertAscii, 42, scex(_("IMA|Pp#p#P")));
1660
1661         int SubInsertTableList= fl_defpup(FL_ObjWin(ob),
1662                                           _("Lists & TOC%t"
1663                                             "|Table of Contents%x21"
1664                                             "|List of Figures%x22"
1665                                             "|List of Tables%x23"
1666                                             "|List of Algorithms%x24"
1667                                             "|Index List%x25"
1668                                             "|BibTeX Reference%x26"));
1669         
1670         fl_setpup_shortcut(SubInsertTableList, 21, scex(_("IMT|Cc#c#C")));
1671         fl_setpup_shortcut(SubInsertTableList, 22, scex(_("IMT|Ff#f#F")));
1672         fl_setpup_shortcut(SubInsertTableList, 23, scex(_("IMT|Tt#t#T")));
1673         fl_setpup_shortcut(SubInsertTableList, 24, scex(_("IMT|Aa#a#A")));
1674         fl_setpup_shortcut(SubInsertTableList, 25, scex(_("IMT|Ii#i#I")));
1675         fl_setpup_shortcut(SubInsertTableList, 26, scex(_("IMT|Bb#b#B")));
1676
1677         int SubInsertFloatList = fl_defpup(FL_ObjWin(ob),
1678                                            _("Floats%t"
1679                                              "|Figure Float%x71"
1680                                              "|Table Float%x72"
1681                                              "|Wide Figure Float%x73"
1682                                              "|Wide Table Float%l%x74"
1683                                              "|Algorithm Float%x75"));
1684         
1685         fl_setpup_shortcut(SubInsertFloatList, 71, scex(_("IMF|gG#g#G")));
1686         fl_setpup_shortcut(SubInsertFloatList, 72, scex(_("IMF|Tt#t#T")));
1687         fl_setpup_shortcut(SubInsertFloatList, 73, scex(_("IMF|Ww#w#W")));
1688         fl_setpup_shortcut(SubInsertFloatList, 74, scex(_("IMF|iI#i#I")));
1689         fl_setpup_shortcut(SubInsertFloatList, 75, scex(_("IMF|Aa#a#A")));
1690         
1691         int SubInsertSpecial = fl_defpup(FL_ObjWin(ob),
1692                                          _("Special Character%t"
1693                                            "|HFill%x31"
1694                                            "|Hyphenation Point%x32"
1695                                            "|Protected Blank%x33"
1696                                            "|Linebreak%x34"
1697                                            "|Ellipsis (...)%x35"
1698                                            "|End of sentence period%x36"
1699                                            "|Ordinary Quote (\")%x37"
1700                                            "|Menu Separator %x38"));
1701
1702         fl_setpup_shortcut(SubInsertSpecial, 31, scex(_("IMS|Hh#h#H")));
1703         fl_setpup_shortcut(SubInsertSpecial, 32, scex(_("IMS|Pp#p#P")));
1704         fl_setpup_shortcut(SubInsertSpecial, 33, scex(_("IMS|Bb#b#B")));
1705         fl_setpup_shortcut(SubInsertSpecial, 34, scex(_("IMS|Ll#l#L")));
1706         fl_setpup_shortcut(SubInsertSpecial, 35, scex(_("IMS|iI#i#I")));
1707         fl_setpup_shortcut(SubInsertSpecial, 36, scex(_("IMS|Ee#e#E")));
1708         fl_setpup_shortcut(SubInsertSpecial, 37, scex(_("IMS|Qq#q#Q")));
1709         fl_setpup_shortcut(SubInsertSpecial, 38, scex(_("IMS|Mm#m#M")));
1710         
1711         int InsertMenu = fl_defpup(FL_ObjWin(ob),
1712                                    _("Figure..."
1713                                      "|Table...%l"
1714                                      "|Include File..." 
1715                                      "|Import ASCII File%m"
1716                                      "|Insert LyX File...%l"
1717                                      "|Footnote"
1718                                      "|Margin Note"
1719                                      "|Floats%m%l"      
1720                                      "|Lists & TOC%m%l"
1721                                      "|Special Character%m%l"
1722                                      "|Note..."
1723                                      "|Label..."
1724                                      "|Cross-Reference..."
1725                                      "|Citation Reference..."
1726                                      "|Index entry..."
1727                                      "|Index entry of last word"),
1728                                    SubInsertAscii,
1729                                    SubInsertFloatList,  
1730                                    SubInsertTableList,
1731                                    SubInsertSpecial);
1732
1733         fl_setpup_shortcut(InsertMenu, 1, scex(_("IM|gG#g#G")));
1734         fl_setpup_shortcut(InsertMenu, 2, scex(_("IM|bB#b#B")));
1735         fl_setpup_shortcut(InsertMenu, 3, scex(_("IM|cC#c#C")));
1736         fl_setpup_shortcut(InsertMenu, 4, scex(_("IM|Aa#a#A")));
1737         fl_setpup_shortcut(InsertMenu, 5, scex(_("IM|Xx#x#X")));
1738         fl_setpup_shortcut(InsertMenu, 6, scex(_("IM|Ff#f#F")));
1739         fl_setpup_shortcut(InsertMenu, 7, scex(_("IM|Mm#m#M")));
1740         fl_setpup_shortcut(InsertMenu, 8, scex(_("IM|oO#o#O")));
1741         fl_setpup_shortcut(InsertMenu, 9, scex(_("IM|Tt#t#T")));
1742         fl_setpup_shortcut(InsertMenu, 10, scex(_("IM|Ss#s#S")));
1743         fl_setpup_shortcut(InsertMenu, 11, scex(_("IM|Nn#n#N")));
1744         fl_setpup_shortcut(InsertMenu, 12, scex(_("IM|Ll#l#L")));
1745         fl_setpup_shortcut(InsertMenu, 13, scex(_("IM|rR#r#R")));     
1746         fl_setpup_shortcut(InsertMenu, 14, scex(_("IM|iI#i#I")));
1747         fl_setpup_shortcut(InsertMenu, 15, scex(_("IM|dD#d#D")));
1748         fl_setpup_shortcut(InsertMenu, 16, scex(_("IM|wW#w#W")));
1749
1750         fl_addtopup(InsertMenu, _("|URL..."));
1751         fl_setpup_shortcut(InsertMenu, 17, scex(_("IM|Uu#u#U")));
1752
1753         if (tmpbuffer->isReadonly()) {
1754                 for (int ii = 1; ii <= 16; ++ii)
1755                         fl_setpup_mode(InsertMenu, ii, FL_PUP_GREY);
1756                 fl_setpup_mode(InsertMenu, 17, FL_PUP_GREY);
1757         }
1758
1759         fl_setpup_position(
1760                 men->_view->getForm()->x + ob->x,
1761                 men->_view->getForm()->y + ob->y + ob->h + 10);
1762    
1763         int choice = fl_dopup(InsertMenu);
1764         XFlush(fl_display);
1765
1766         // set the pseudo menu-button back
1767         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1768         fl_redraw_object(ob);
1769
1770         if (men->currentView()->available()){
1771                 men->currentView()->hideCursor();
1772                 switch (choice) {
1773                 case 1: tmpfunc->Dispatch(LFUN_FIGURE); break;
1774                 case 2: tmpfunc->Dispatch(LFUN_TABLE); break;
1775                 case 3: tmpfunc->Dispatch(LFUN_CHILDINSERT); break;
1776                 case 4: // Insert ASCII file submenu
1777                         break;
1778                 case 5: tmpfunc->Dispatch(LFUN_FILE_INSERT); break;
1779                 case 41: tmpfunc->Dispatch(LFUN_FILE_INSERT_ASCII, "line"); break;
1780                 case 42: tmpfunc->Dispatch(LFUN_FILE_INSERT_ASCII, "paragraph"); break;
1781                 case 43: 
1782                         break;
1783
1784                 case 6: tmpfunc->Dispatch(LFUN_FOOTMELT); break
1785                                                                   ;
1786                 case 7: tmpfunc->Dispatch(LFUN_MARGINMELT); break;
1787   
1788                 case 8: // Float sub-menu
1789                 case 71:
1790                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "figure");
1791                         break;
1792                 case 72:
1793                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "table");
1794                         break;
1795                 case 73:
1796                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "wide-fig");
1797                         break;
1798                 case 74:
1799                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "wide-tab");
1800                         break;
1801                 case 75:
1802                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "algorithm");
1803                         break;
1804
1805                 case 9: // Table/List submenu
1806                         break;
1807                 case 21: tmpfunc->Dispatch(LFUN_TOC_INSERT); break;
1808                 case 22: tmpfunc->Dispatch(LFUN_LOF_INSERT); break;
1809                 case 23: tmpfunc->Dispatch(LFUN_LOT_INSERT); break;
1810                 case 24: tmpfunc->Dispatch(LFUN_LOA_INSERT); break;
1811                 case 25: tmpfunc->Dispatch(LFUN_INDEX_PRINT); break;
1812                 case 26: tmpfunc->Dispatch(LFUN_INSERT_BIBTEX); break;
1813
1814                 case 10: // Special Character submenu
1815                         break;
1816                 case 31: tmpfunc->Dispatch(LFUN_HFILL); break;
1817                 case 32: tmpfunc->Dispatch(LFUN_HYPHENATION); break;
1818                 case 33: tmpfunc->Dispatch(LFUN_PROTECTEDSPACE); break; 
1819                 case 34: tmpfunc->Dispatch(LFUN_BREAKLINE); break; 
1820                 case 35: tmpfunc->Dispatch(LFUN_LDOTS); break;
1821                 case 36: tmpfunc->Dispatch(LFUN_END_OF_SENTENCE); break;
1822                 case 37: tmpfunc->Dispatch(LFUN_QUOTE); break;
1823                 case 38: tmpfunc->Dispatch(LFUN_MENU_SEPARATOR); break;
1824
1825                 case 11: tmpfunc->Dispatch(LFUN_INSERT_NOTE); break;
1826                 case 12: tmpfunc->Dispatch(LFUN_INSERT_LABEL); break;
1827                 case 13: tmpfunc->Dispatch(LFUN_INSERT_REF); break;
1828                 case 14: tmpfunc->Dispatch(LFUN_INSERT_CITATION); break;
1829                 case 15: tmpfunc->Dispatch(LFUN_INDEX_INSERT); break;
1830                 case 16: tmpfunc->Dispatch(LFUN_INDEX_INSERT_LAST); break;
1831                 case 17: tmpfunc->Dispatch(LFUN_URL); break;
1832                 }
1833         }
1834         fl_freepup(InsertMenu);
1835         fl_freepup(SubInsertAscii);
1836         fl_freepup(SubInsertTableList);
1837         fl_freepup(SubInsertFloatList);
1838         fl_freepup(SubInsertSpecial);
1839 }
1840
1841
1842 void Menus::ShowMathMenu(FL_OBJECT * ob, long)
1843 {
1844         extern void math_insert_symbol(char const * s);
1845
1846         Menus * men = static_cast<Menus*>(ob->u_vdata);
1847
1848         // set the pseudo menu-button
1849         fl_set_object_boxtype(ob, FL_UP_BOX);
1850         fl_set_button(ob, 0);
1851         fl_redraw_object(ob);
1852
1853         Buffer * tmpbuffer = men->_view->buffer();
1854         LyXFunc * tmpfunc = men->_view->getLyXFunc();
1855
1856         int MathMenu = fl_defpup(FL_ObjWin(ob), 
1857                                  _("Fraction"
1858                                    "|Square root"
1859                                    "|Exponent"
1860                                    "|Index"
1861                                    "|Sum"
1862                                    "|Integral%l"
1863                                    "|Math mode"
1864                                    "|Display%l"
1865                                    "|Math Panel..."));
1866
1867         fl_setpup_shortcut(MathMenu, 1, scex(_("MM|Ff#f#F")));
1868         fl_setpup_shortcut(MathMenu, 2, scex(_("MM|Ss#s#S")));
1869         fl_setpup_shortcut(MathMenu, 3, scex(_("MM|Ee#e#E")));
1870         fl_setpup_shortcut(MathMenu, 4, scex(_("MM|xX#x#X")));
1871         fl_setpup_shortcut(MathMenu, 5, scex(_("MM|uU#u#U")));
1872         fl_setpup_shortcut(MathMenu, 6, scex(_("MM|Ii#i#I")));
1873         fl_setpup_shortcut(MathMenu, 7, scex(_("MM|Mm#m#M")));
1874         fl_setpup_shortcut(MathMenu, 8, scex(_("MM|Dd#d#D")));
1875         fl_setpup_shortcut(MathMenu, 9, scex(_("MM|Pp#p#P")));
1876
1877         if (tmpbuffer->isReadonly()) 
1878                 for (int ii = 1; ii <= 9; ++ii)
1879                         fl_setpup_mode(MathMenu, ii, FL_PUP_GREY);
1880
1881
1882         fl_setpup_position(
1883                 men->_view->getForm()->x + ob->x,
1884                 men->_view->getForm()->y + ob->y + ob->h + 10);   
1885         int choice = fl_dopup(MathMenu);  
1886         XFlush(fl_display);
1887
1888         // set the pseudo menu-button back
1889         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1890         fl_redraw_object(ob);
1891
1892         if (men->currentView()->available())  {
1893                 switch (choice) {
1894                 case 1: /* frac */
1895                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "frac");
1896                         break;
1897                 case 2: /* sqrt */
1898                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "sqrt");
1899                         break;
1900                 case 3: /* Exponent */ 
1901                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "^");
1902                         break;
1903                 case 4: /* Index */
1904                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "_");
1905                         break;
1906                 case 5: /* sum */ 
1907                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "sum");
1908                         break;
1909                 case 6: /* int */
1910                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "int");
1911                         break;
1912                 case 7:
1913                         tmpfunc->Dispatch(LFUN_MATH_MODE);
1914                         break;
1915                 case 8:
1916                         tmpfunc->Dispatch(LFUN_MATH_DISPLAY);
1917                         break;
1918                 case 9: /* Panel */
1919                         show_symbols_form(tmpfunc);
1920                         break;
1921                 }
1922                 men->currentView()->update(0);
1923         } 
1924         fl_freepup(MathMenu);
1925 }
1926
1927
1928 void Menus::ShowOptionsMenu(FL_OBJECT * ob, long)
1929 {
1930         Menus * men = static_cast<Menus*>(ob->u_vdata);
1931
1932         // set the pseudo menu-button
1933         fl_set_object_boxtype(ob, FL_UP_BOX);
1934         fl_set_button(ob, 0);
1935         fl_redraw_object(ob);
1936
1937         //Buffer *tmpbuffer = men->_view->currentBuffer();
1938         LyXFunc * tmpfunc = men->_view->getLyXFunc();
1939
1940         int OptionsMenu = fl_defpup(FL_ObjWin(ob),
1941                                     _("Screen Fonts..."
1942                                       "|Spellchecker Options..."
1943                                       "|Keyboard..."
1944                                       "|LaTeX...%l"
1945                                       "|Reconfigure" ));
1946
1947         fl_setpup_shortcut(OptionsMenu, 1, scex(_("OM|Ff#f#F")));
1948         fl_setpup_shortcut(OptionsMenu, 2, scex(_("OM|Ss#s#S")));
1949         fl_setpup_shortcut(OptionsMenu, 3, scex(_("OM|Kk#k#K")));
1950         fl_setpup_shortcut(OptionsMenu, 4, scex(_("OM|Ll#l#L")));
1951         fl_setpup_shortcut(OptionsMenu, 5, scex(_("OM|Rr#r#R")));
1952
1953         if(lyxrc.isp_command == "none") 
1954                 fl_setpup_mode(OptionsMenu, 2, FL_PUP_GREY);
1955
1956         fl_setpup_position(
1957                 men->_view->getForm()->x + ob->x,
1958                 men->_view->getForm()->y + ob->y + ob->h + 10);   
1959         int choice = fl_dopup(OptionsMenu);
1960         XFlush(fl_display);
1961
1962         // set the pseudo menu-button back
1963         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1964         fl_redraw_object(ob);
1965         switch (choice){
1966         case 1: men->ScreenOptions(); break;
1967         case 2: SpellCheckerOptions(); break;      
1968         case 3: men->_view->getIntl()->MenuKeymap(); break;
1969         case 4: LaTeXOptions(men->_view->view()); break;
1970         case 5: tmpfunc->Dispatch(LFUN_RECONFIGURE); break;
1971         default: break;
1972         }   
1973         fl_freepup(OptionsMenu);
1974 }
1975
1976
1977 void Menus::ShowBufferMenu(FL_OBJECT * ob, long)
1978 {
1979         Menus * men = static_cast<Menus*>(ob->u_vdata);
1980         
1981         // set the pseudo menu-button
1982         fl_set_object_boxtype(ob, FL_UP_BOX);
1983         fl_set_button(ob, 0);
1984         fl_redraw_object(ob);
1985    
1986         int BufferMenu = fl_newpup(FL_ObjWin(ob));
1987         vector<string> namevec = bufferlist.getFileNames();
1988         if (namevec.size() != 0) {
1989                 for (vector<string>::const_iterator cit = namevec.begin();
1990                      cit != namevec.end(); ++cit) {
1991                         string relbuf = MakeDisplayPath((*cit), 30);
1992                         fl_addtopup(BufferMenu, relbuf.c_str());
1993                 }
1994         } else {
1995                 fl_addtopup(BufferMenu, _("No Documents Open!%t"));
1996         }
1997    
1998         fl_setpup_position(
1999                 men->_view->getForm()->x + ob->x,
2000                 men->_view->getForm()->y + ob->y + ob->h + 10);   
2001         int choice = fl_dopup(BufferMenu);
2002         XFlush(fl_display);
2003
2004         // set the pseudo menu-button back
2005         fl_set_object_boxtype(ob, FL_FLAT_BOX);
2006         fl_redraw_object(ob);
2007         if (choice > 0) men->handleBufferMenu(choice - 1);
2008    
2009         fl_freepup(BufferMenu);
2010 }
2011
2012
2013 static
2014 char const * doc_files [] = {"Intro", "Tutorial", 
2015                              "UserGuide", "Extended",
2016                              "Customization", "Reference",
2017                              "FAQ", "TOC",  
2018                              "BUGS", "LaTeXConfig"}; 
2019
2020 void Menus::ShowHelpMenu(FL_OBJECT * ob, long)
2021 {
2022         Menus * men = static_cast<Menus*>(ob->u_vdata);
2023
2024         // set the pseudo menu-button
2025         fl_set_object_boxtype(ob, FL_UP_BOX);
2026         fl_set_button(ob, 0);
2027         fl_redraw_object(ob);
2028    
2029         int HelpMenu = fl_defpup(FL_ObjWin(ob),
2030                                  _("Introduction"
2031                                    "|Tutorial"
2032                                    "|User's Guide"
2033                                    "|Extended Features"
2034                                    "|Customization"
2035                                    "|Reference Manual"
2036                                    "|FAQ"
2037                                    "|Table of Contents"
2038                                    "|Known Bugs"
2039                                    "|LaTeX Configuration%l"
2040                                    "|Copyright and Warranty..."
2041                                    "|Credits..."
2042                                    "|Version..."));
2043    
2044         fl_setpup_shortcut(HelpMenu,  1, scex(_("HM|Ii#I#i")));
2045         fl_setpup_shortcut(HelpMenu,  2, scex(_("HM|Tt#T#t")));
2046         fl_setpup_shortcut(HelpMenu,  3, scex(_("HM|Uu#U#u")));
2047         fl_setpup_shortcut(HelpMenu,  4, scex(_("HM|xX#x#X")));
2048         fl_setpup_shortcut(HelpMenu,  5, scex(_("HM|Cc#C#c")));
2049         fl_setpup_shortcut(HelpMenu,  6, scex(_("HM|Rr#R#r")));
2050         fl_setpup_shortcut(HelpMenu,  7, scex(_("HM|Ff#F#f")));
2051         fl_setpup_shortcut(HelpMenu,  8, scex(_("HM|aA#a#A")));
2052         fl_setpup_shortcut(HelpMenu,  9, scex(_("HM|Kk#K#k")));
2053         fl_setpup_shortcut(HelpMenu, 10, scex(_("HM|Ll#L#l")));
2054         fl_setpup_shortcut(HelpMenu, 11, scex(_("HM|oO#o#O")));
2055         fl_setpup_shortcut(HelpMenu, 12, scex(_("HM|eE#e#E")));
2056         fl_setpup_shortcut(HelpMenu, 13, scex(_("HM|Vv#v#V")));
2057
2058         fl_setpup_position(
2059                 men->_view->getForm()->x + ob->x,
2060                 men->_view->getForm()->y + ob->y + ob->h + 10);   
2061         int choice = fl_dopup(HelpMenu);
2062         XFlush(fl_display);
2063
2064         // set the pseudo menu-button back
2065         fl_set_object_boxtype(ob, FL_FLAT_BOX);
2066         fl_redraw_object(ob);
2067
2068         switch (choice) {
2069         case 1: case 2: case 3: case 4: case 5: 
2070         case 6: case 7: case 8: case 9: case 10:
2071                 ProhibitInput(men->currentView());
2072                 men->MenuDocu(doc_files[choice - 1]);
2073                 AllowInput(men->currentView());
2074                 break;
2075         case 11: ShowCopyright(); break;
2076         case 12: ShowCredits(); break;
2077         case 13:
2078                 ProhibitInput(men->currentView());
2079                 fl_show_message((string(_("LyX Version ")) + LYX_VERSION 
2080                                  + _(" of ") + LYX_RELEASE).c_str(),
2081                                 (_("Library directory: ")
2082                                  + MakeDisplayPath(system_lyxdir)).c_str(),
2083                                 (_("User directory: ") 
2084                                  + MakeDisplayPath(user_lyxdir)).c_str());
2085                 AllowInput(men->currentView());
2086                 break;
2087         }
2088         fl_freepup(HelpMenu);
2089 }
2090
2091
2092 void Menus::MenuDocu(string const & docname) 
2093 {
2094         string fname = i18nLibFileSearch("doc", docname, "lyx");
2095         if (fname.empty()) {
2096                 WriteAlert(_("Error!"),
2097                            _("Could not find requested Documentation file"),
2098                            fname);
2099                 return;
2100         }
2101         _view->getMiniBuffer()->Set(_("Opening help file"),
2102                                     MakeDisplayPath(fname), "...");
2103         currentView()->buffer(bufferlist.loadLyXFile(fname, false));
2104
2105         if (docname == "Reference")
2106                 _view->getLyXFunc()->Dispatch(LFUN_TOCVIEW);
2107 }
2108
2109
2110 void Menus::handleBufferMenu(int choice)
2111 {
2112         currentView()->buffer(bufferlist.getBuffer(choice));
2113 }