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