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