]> git.lyx.org Git - lyx.git/blob - src/menus.C
citation patch from Angus
[lyx.git] / src / menus.C
1 /*
2  *  This file is part of
3  * ================================================== 
4  *
5  *       LyX, The Document Processor
6  *
7  *       Copyright 1995 Matthias Ettrich
8  *       Copyright 1995-2000 The LyX Team.
9  *
10  * ================================================== 
11  */
12
13 /* This file contains all the menu and submenu declarations.
14    The call backs are in lyx_cb.C */
15
16 /*
17  * REMEMBER:
18  * XFORMS can handle 10 (more with the new xforms, but not unlimited)
19  * popups at the same time
20  * so when you are finished looking at a pup free it (fl_freepup)
21  */
22
23 #include <config.h>
24
25 #ifdef __GNUG__
26 #pragma implementation
27 #endif
28
29 #include <algorithm>
30
31 #include "menus.h"
32 #include "version.h"
33 #include "lyxfont.h"
34 #include "lyx_main.h"
35 #include "lyxfunc.h"
36 #include "spellchecker.h"
37 #include "support/filetools.h"
38 #include "LyXView.h"
39 #include "lastfiles.h"
40 #include "bufferlist.h"
41 #include "lyx_gui_misc.h"
42 #include "minibuffer.h"
43 #include "intl.h"
44 #include "debug.h"
45 #include "lyxrc.h"
46 #include "lyxtext.h"
47 #include "gettext.h"
48 #include "layout.h"
49 #include "lyx_cb.h"
50 #include "bufferview_funcs.h"
51 #include "insets/insetref.h"
52 #include "insets/insettabular.h"
53 #include "tabular.h"
54 #include "exporter.h"
55
56 #include "frontends/Dialogs.h"
57
58 using std::vector;
59 using std::pair;
60 using std::endl;
61 using std::max;
62 using std::min;
63 using std::sort;
64
65 extern BufferList bufferlist;
66
67 // I would really prefere to see most or all of these 'extern's disappear.
68 // Their commands should be called through LyXFunc (IMO). (Lgb)
69
70 extern void MenuLayoutSave();
71 extern void ShowCredits();
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 //
460 // Here comes all the menu callbacks.
461 //
462
463 void Menus::ShowFileMenu(FL_OBJECT * ob, long)
464 {
465         Menus * men = static_cast<Menus*>(ob->u_vdata);
466
467         // Regarding the pseudo-menu-button:
468         // ok, ok this is a hack. It would be better to use the menus of the
469         // xforms 0.8 library. but then all popups have to be defined all the
470         // time, code rewriting would be necessary and contex-depending menus
471         // (i.e. the linux-doc-sgml stuff) are a bit more complicated. But of
472         // course it would be more proper (and little faster). So if anybody
473         // likes to do the cleanup, just do it. Matthias
474
475         // set the pseudo menu-button
476         fl_set_object_boxtype(ob, FL_UP_BOX);
477         fl_set_button(ob, 0);
478         fl_redraw_object(ob);
479
480         Buffer * tmpbuffer = men->_view->buffer();
481         LyXFunc * tmpfunc = men->_view->getLyXFunc();
482
483         bool LinuxDoc = tmpbuffer->isLinuxDoc();
484         bool DocBook  = tmpbuffer->isDocBook();
485         bool Literate = tmpbuffer->isLiterate();
486
487         // Import sub-menu
488
489         int SubFileImport = fl_defpup(FL_ObjWin(ob),
490                                       _("Import%t"
491                                         "|LaTeX...%x30"
492                                         "|Ascii Text as Lines...%x31"
493                                         "|Ascii Text as Paragraphs%x32"
494                                         "|Noweb%x33"
495                                         "|LinuxDoc%x34"));
496
497         fl_setpup_shortcut(SubFileImport, 30, scex(_("FIM|Ll#l#L")));
498         fl_setpup_shortcut(SubFileImport, 31, scex(_("FIM|Aa#a#A")));
499         fl_setpup_shortcut(SubFileImport, 32, scex(_("FIM|Pp#p#P")));
500         fl_setpup_shortcut(SubFileImport, 33, scex(_("FIM|Nn#n#N")));
501         fl_setpup_shortcut(SubFileImport, 34, scex(_("FIM|Dd#d#D")));
502
503         // Export sub-menu
504 #ifdef NEW_EXPORT
505         int SubFileExport = fl_defpup(FL_ObjWin(ob),
506                                       _("Export%t"));
507         vector<pair<string,string> > formats =
508                 Exporter::GetExportableFormats(tmpbuffer);
509         for (vector<pair<string,string> >::size_type i = 0;
510              i < formats.size(); ++i) {
511                 string entry = _("as ")
512                         + formats[i].second
513                         + "%x" + tostr(1000+i);
514                 fl_addtopup(SubFileExport, entry.c_str());
515         }
516 #else
517         // remember to make this handle linuxdoc too.
518         // and now docbook also.
519
520         int SubFileExport = 0;
521         if (!LinuxDoc && !DocBook)
522                 SubFileExport= fl_defpup(FL_ObjWin(ob),
523                                          _("Export%t"
524                                            "|as LaTeX...%x40"
525                                            "|as DVI...%x41"
526                                            "|as PostScript...%x42"
527                                            "|as Ascii Text...%x43"
528                                            "|as HTML...%x44"
529                                            "|Custom...%x45"));
530         else if(LinuxDoc)
531                 SubFileExport= fl_defpup(FL_ObjWin(ob),
532                                          _("Export%t"
533                                            "|as LinuxDoc...%x40"
534                                            "|as DVI...%x41"
535                                            "|as PostScript...%x42"
536                                            "|as Ascii Text...%x43"
537                                            "|as HTML...%x44"));
538         else if(DocBook)
539                 SubFileExport= fl_defpup(FL_ObjWin(ob),
540                                          _("Export%t"
541                                            "|as DocBook...%x40"
542                                            "|as DVI...%x41"
543                                            "|as PostScript...%x42"
544                                            "|as Ascii Text...%x43"
545                                            "|as HTML...%x44"));
546         fl_setpup_shortcut(SubFileExport, 40, scex(_("FEX|Ll#l#L")));
547         fl_setpup_shortcut(SubFileExport, 41, scex(_("FEX|Dd#d#D")));
548         fl_setpup_shortcut(SubFileExport, 42, scex(_("FEX|Pp#p#P")));
549         fl_setpup_shortcut(SubFileExport, 43, scex(_("FEX|Tt#t#T")));
550         fl_setpup_shortcut(SubFileExport, 44, scex(_("FEX|Hh#h#H")));
551
552         if (!LinuxDoc && !DocBook) {
553                 fl_setpup_shortcut(SubFileExport, 45, scex(_("FEX|mM#m#M")));
554         }
555 #endif
556         
557         int FileMenu = fl_defpup(FL_ObjWin(ob),
558                                  _("New..."
559                                    "|New from template..."
560                                    "|Open...%l"
561                                    "|Close"
562                                    "|Save"
563                                    "|Save As..."
564                                    "|Revert to saved%l"
565                                    "|View dvi"
566                                    "|View PostScript"
567                                    "|Update dvi"
568                                    "|Update PostScript"
569                                    "|Build program%l"
570                                    "|Print..."
571                                    "|Fax..."));
572
573         fl_setpup_shortcut(FileMenu, 1, scex(_("FM|Nn#n#N")));
574         fl_setpup_shortcut(FileMenu, 2, scex(_("FM|tT#t#T")));
575         fl_setpup_shortcut(FileMenu, 3, scex(_("FM|Oo#o#O")));
576         fl_setpup_shortcut(FileMenu, 4, scex(_("FM|Cc#c#C")));
577         fl_setpup_shortcut(FileMenu, 5, scex(_("FM|Ss#s#S")));
578         fl_setpup_shortcut(FileMenu, 6, scex(_("FM|Aa#a#A")));
579         fl_setpup_shortcut(FileMenu, 7, scex(_("FM|Rr#r#R")));
580         fl_setpup_shortcut(FileMenu, 8, scex(_("FM|dD#d#D")));
581         fl_setpup_shortcut(FileMenu, 9, scex(_("FM|wW#w#W")));
582         fl_setpup_shortcut(FileMenu, 10, scex(_("FM|vV#v#V")));
583         fl_setpup_shortcut(FileMenu, 11, scex(_("FM|Uu#u#U")));
584         fl_setpup_shortcut(FileMenu, 12, scex(_("FM|Bb#b#B")));
585         fl_setpup_shortcut(FileMenu, 13, scex(_("FM|Pp#p#P")));
586         fl_setpup_shortcut(FileMenu, 14, scex(_("FM|Ff#f#F")));
587
588         // These commands are disabled when the corresponding programs
589         // are not installed. I simply grey them out, since I do not
590         // want to change their number (JMarc)
591         bool hasLaTeX = lyxrc.latex_command != "none";
592
593         if (!hasLaTeX || lyxrc.view_dvi_command == "none") 
594                 fl_setpup_mode(FileMenu, 8, FL_PUP_GREY);
595         
596         if (!hasLaTeX || lyxrc.view_ps_command == "none") 
597                 fl_setpup_mode(FileMenu, 9, FL_PUP_GREY);
598         
599         if (!hasLaTeX) {
600                 fl_setpup_mode(FileMenu, 10, FL_PUP_GREY);
601                 fl_setpup_mode(FileMenu, 11, FL_PUP_GREY);
602         } 
603
604         if (lyxrc.literate_command == "none" || ! Literate) 
605                 fl_setpup_mode(FileMenu, 12, FL_PUP_GREY);
606
607         if (!hasLaTeX || lyxrc.print_command == "none") 
608                 fl_setpup_mode(FileMenu, 13, FL_PUP_GREY);
609
610         if (!hasLaTeX || lyxrc.fax_command == "none") 
611                 fl_setpup_mode(FileMenu, 14, FL_PUP_GREY);
612
613         bool hasReLyX = lyxrc.relyx_command != "none";
614         if (!hasReLyX) {
615                 // Disable import LaTeX and Noweb
616                 fl_setpup_mode(SubFileImport, 30, FL_PUP_GREY);
617                 fl_setpup_mode(SubFileImport, 33, FL_PUP_GREY);
618         }
619
620         if ( lyxrc.linuxdoc_to_lyx_command == "none")
621                 fl_setpup_mode(SubFileImport, 34, FL_PUP_GREY);
622
623 #ifndef NEW_EXPORT
624         if (!hasLaTeX) {
625                 // Disable export dvi and export postscript
626                 fl_setpup_mode(SubFileExport, 41, FL_PUP_GREY);
627                 fl_setpup_mode(SubFileExport, 42, FL_PUP_GREY);
628         }
629
630         if ((!LinuxDoc && !DocBook && lyxrc.html_command == "none") ||
631             ( LinuxDoc && lyxrc.linuxdoc_to_html_command == "none") ||
632             ( DocBook  && lyxrc.docbook_to_html_command  == "none")) {
633                 // Disable export HTML
634                 fl_setpup_mode(SubFileExport, 44, FL_PUP_GREY);
635         }
636 #endif
637
638         // xgettext:no-c-format
639         fl_addtopup(FileMenu, _("|Import%m"), SubFileImport);
640         // xgettext:no-c-format
641         fl_addtopup(FileMenu, _("|Export%m%l"), SubFileExport);
642         // xgettext:no-c-format
643         fl_addtopup(FileMenu, _("|Exit%l"));
644         fl_setpup_shortcut(FileMenu, 15, scex(_("FM|Ii#i#I")));
645         fl_setpup_shortcut(FileMenu, 16, scex(_("FM|Ee#e#E")));
646         fl_setpup_shortcut(FileMenu, 17, scex(_("FM|xX#x#X")));
647
648         // make the lastfiles menu
649         int ii = 1;
650         for (LastFiles::const_iterator cit = lastfiles->begin();
651              cit != lastfiles->end() && ii < 10; ++cit, ++ii) {
652                 string tmp = tostr(ii);
653                 string tmp2 = tmp + "#" + tmp;
654                 tmp += ". " + MakeDisplayPath((*cit), 30);
655                 fl_addtopup(FileMenu, tmp.c_str());
656                 fl_setpup_shortcut(FileMenu, 18 - 1 + ii, tmp2.c_str());
657         }
658
659         // place popup
660         fl_setpup_position(
661                 men->_view->getForm()->x + ob->x,
662                 men->_view->getForm()->y + ob->y + ob->h + 10);   
663         int choice = fl_dopup(FileMenu);
664         XFlush(fl_display);
665
666         // set the pseudo menu-button back
667         fl_set_object_boxtype(ob, FL_FLAT_BOX);
668         fl_redraw_object(ob);
669
670         switch (choice) {
671         case -1: case 0: // we won't do anything
672                 break;
673         case  1: tmpfunc->Dispatch(LFUN_MENUNEW); break;
674         case  2: tmpfunc->Dispatch(LFUN_MENUNEWTMPLT); break;
675         case  3: tmpfunc->Dispatch(LFUN_MENUOPEN); break;
676         case  4: tmpfunc->Dispatch(LFUN_CLOSEBUFFER); break;
677         case  5: tmpfunc->Dispatch(LFUN_MENUWRITE); break;
678         case  6: tmpfunc->Dispatch(LFUN_MENUWRITEAS); break;
679         case  7: tmpfunc->Dispatch(LFUN_MENURELOAD); break;
680 #ifdef NEW_EXPORT
681         case 8: tmpfunc->Dispatch(LFUN_PREVIEW, "dvi"); break;
682         case 9: tmpfunc->Dispatch(LFUN_PREVIEW, "ps"); break;
683         case 10: tmpfunc->Dispatch(LFUN_UPDATE, "dvi"); break;
684         case 11: tmpfunc->Dispatch(LFUN_UPDATE, "ps"); break;
685 #else
686         case  8: tmpfunc->Dispatch(LFUN_PREVIEW); break;
687         case  9: tmpfunc->Dispatch(LFUN_PREVIEWPS); break;
688         case 10: tmpfunc->Dispatch(LFUN_RUNLATEX); break;
689         case 11: tmpfunc->Dispatch(LFUN_RUNDVIPS); break;
690 #endif
691         case 12: tmpfunc->Dispatch(LFUN_BUILDPROG); break;
692         case 13: tmpfunc->Dispatch(LFUN_MENUPRINT); break;
693         case 14: tmpfunc->Dispatch(LFUN_FAX); break;
694         case 15: // import menu
695         case 30: tmpfunc->Dispatch(LFUN_IMPORT, "latex");
696                 break;
697         case 31: tmpfunc->Dispatch(LFUN_IMPORT, "ascii");
698                 break;
699         case 32: tmpfunc->Dispatch(LFUN_IMPORT, "asciiparagraph");
700                 break;
701         case 33: tmpfunc->Dispatch(LFUN_IMPORT, "noweb");
702                 break;
703         case 34: tmpfunc->Dispatch(LFUN_IMPORT, "linuxdoc");
704                 break;
705 #ifdef NEW_EXPORT
706         case 18:
707                 tmpfunc->Dispatch(LFUN_QUIT);
708                 break;
709         default:
710                 if (choice >= 1000)
711                         tmpfunc->Dispatch(LFUN_EXPORT,
712                                           formats[choice-1000].first.c_str());
713                 else
714                         men->currentView()
715                                 ->buffer(bufferlist
716                                          .loadLyXFile((*lastfiles)[choice - 18]));
717                 break;
718 #else
719         case 16: // export menu
720         case 40:
721                 if (!LinuxDoc && !DocBook)
722                         tmpfunc->Dispatch(LFUN_EXPORT, "latex");
723                 else if(LinuxDoc)
724                         tmpfunc->Dispatch(LFUN_EXPORT, "linuxdoc");
725                 else
726                         tmpfunc->Dispatch(LFUN_EXPORT, "docbook");
727                 break;
728         case 41: tmpfunc->Dispatch(LFUN_EXPORT, "dvi");
729                 break;
730         case 42: tmpfunc->Dispatch(LFUN_EXPORT, "postscript");
731                 break;
732         case 43: tmpfunc->Dispatch(LFUN_EXPORT, "ascii");
733                 break;
734         case 44: tmpfunc->Dispatch(LFUN_EXPORT, "html");
735                 break;
736         case 45: tmpfunc->Dispatch(LFUN_EXPORT, "custom"); 
737                 break;
738         case 17: tmpfunc->Dispatch(LFUN_QUIT); break;
739                 // Lastfiles:
740         case 18: // The first item with lastfiles.
741         default:
742                 men->currentView()
743                         ->buffer(bufferlist
744                                  .loadLyXFile((*lastfiles)[choice - 18]));
745                 break;
746 #endif
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 #ifndef NEW_TABULAR
913         if (men->currentView()->available() && 
914             men->currentView()->text->cursor.par()->table &&
915             !tmpbuffer->isReadonly()){
916                 LyXTable * table = men->currentView()->text->cursor.par()->table;
917
918                 fl_addtopup(SubEditTable, _("Table%t"));
919
920                 if (table->IsMultiColumn(men->currentView()->text->
921                                          NumberOfCell(men->currentView()->
922                                                       text->cursor.par(), 
923                                                       men->currentView()->
924                                                       text->cursor.pos())))
925                         fl_addtopup(SubEditTable, _("|Multicolumn%B%x44%l"));
926                 else
927                         fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
928                 fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
929      
930                 if (table->TopLine(men->currentView()->text->
931                                    NumberOfCell(men->currentView()->
932                                                 text->cursor.par(), 
933                                                 men->currentView()->text->
934                                                 cursor.pos())))
935                         fl_addtopup(SubEditTable, _("|Line Top%B%x36"));
936                 else
937                         fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
938                 fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
939      
940                 if (table->BottomLine(men->currentView()->text->
941                                       NumberOfCell(men->currentView()->
942                                                    text->cursor.par(), 
943                                                    men->currentView()->
944                                                    text->cursor.pos())))
945                         fl_addtopup(SubEditTable, _("|Line Bottom%B%x37"));
946                 else
947                         fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
948                 fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
949
950                 if (table->LeftLine(men->currentView()->text->
951                                     NumberOfCell(men->currentView()->
952                                                  text->cursor.par(), 
953                                                  men->currentView()->
954                                                  text->cursor.pos())))
955                         fl_addtopup(SubEditTable, _("|Line Left%B%x38"));
956                 else
957                         fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
958                 fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
959
960                 if (table->RightLine(men->currentView()->text->
961                                      NumberOfCell(men->currentView()->
962                                                   text->cursor.par(), 
963                                                   men->currentView()->
964                                                   text->cursor.pos())))
965                         fl_addtopup(SubEditTable, _("|Line Right%B%x39%l"));
966                 else
967                         fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
968                 fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
969
970                 int align =
971                         table->GetAlignment(men->currentView()->text->
972                                             NumberOfCell(men->currentView()->
973                                                          text->cursor.par(), 
974                                                          men->currentView()->
975                                                          text->cursor.pos()));
976                 if (align == LYX_ALIGN_LEFT)
977                         fl_addtopup(SubEditTable, _("|Align Left%R%x40"));
978                 else
979                         fl_addtopup(SubEditTable, _("|Align Left%r%x40"));
980                 fl_setpup_shortcut(SubEditTable, 40, scex(_("EMT|eE#e#E")));
981
982                 if (align == LYX_ALIGN_RIGHT)
983                         fl_addtopup(SubEditTable, _("|Align Right%R%x41"));
984                 else
985                         fl_addtopup(SubEditTable, _("|Align Right%r%x41"));
986                 fl_setpup_shortcut(SubEditTable, 41, scex(_("EMT|iI#i#I")));
987
988                 if (align == LYX_ALIGN_CENTER)
989                         fl_addtopup(SubEditTable, _("|Align Center%R%x42%l"));
990                 else
991                         fl_addtopup(SubEditTable, _("|Align Center%r%x42%l"));
992                 fl_setpup_shortcut(SubEditTable, 42, scex(_("EMT|Cc#c#C")));
993
994                 // xgettext:no-c-format
995                 fl_addtopup(SubEditTable, _("|Append Row%x32"));
996                 fl_setpup_shortcut(SubEditTable, 32, scex(_("EMT|oO#o#O")));
997                 // xgettext:no-c-format
998                 fl_addtopup(SubEditTable, _("|Append Column%x33%l"));
999                 fl_setpup_shortcut(SubEditTable, 33, scex(_("EMT|uU#u#U")));
1000                 // xgettext:no-c-format
1001                 fl_addtopup(SubEditTable, _("|Delete Row%x34"));
1002                 fl_setpup_shortcut(SubEditTable, 34, scex(_("EMT|wW#w#W")));
1003                 // xgettext:no-c-format
1004                 fl_addtopup(SubEditTable, _("|Delete Column%x35%l"));
1005                 fl_setpup_shortcut(SubEditTable, 35, scex(_("EMT|nN#n#N")));
1006                 // xgettext:no-c-format
1007                 fl_addtopup(SubEditTable, _("|Delete Table%x43"));
1008                 fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
1009         } else
1010 #endif
1011                 if (men->currentView()->the_locking_inset &&
1012                    (men->currentView()->the_locking_inset->LyxCode() ==
1013                     Inset::TABULAR_CODE) &&
1014                    !tmpbuffer->isReadonly()) {
1015                 InsetTabular * inset = static_cast<InsetTabular *>(men->currentView()->the_locking_inset);
1016                 LyXTabular * table = inset->tabular;
1017
1018                 fl_addtopup(SubEditTable, _("Table%t"));
1019
1020                 if (table->IsMultiColumn(inset->GetActCell()))
1021                         fl_addtopup(SubEditTable, _("|Multicolumn%B%x44%l"));
1022                 else
1023                         fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
1024                 fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
1025
1026                 if (table->TopLine(inset->GetActCell()))
1027                         fl_addtopup(SubEditTable, _("|Line Top%B%x36"));
1028                 else
1029                         fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
1030                 fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
1031      
1032                 if (table->BottomLine(inset->GetActCell()))
1033                         fl_addtopup(SubEditTable, _("|Line Bottom%B%x37"));
1034                 else
1035                         fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
1036                 fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
1037
1038                 if (table->LeftLine(inset->GetActCell()))
1039                         fl_addtopup(SubEditTable, _("|Line Left%B%x38"));
1040                 else
1041                         fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
1042                 fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
1043
1044                 if (table->RightLine(inset->GetActCell()))
1045                         fl_addtopup(SubEditTable, _("|Line Right%B%x39%l"));
1046                 else
1047                         fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
1048                 fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
1049
1050                 int align = table->GetAlignment(inset->GetActCell());
1051                 if (align == LYX_ALIGN_LEFT)
1052                         fl_addtopup(SubEditTable, _("|Align Left%R%x40"));
1053                 else
1054                         fl_addtopup(SubEditTable, _("|Align Left%r%x40"));
1055                 fl_setpup_shortcut(SubEditTable, 40, scex(_("EMT|eE#e#E")));
1056
1057                 if (align == LYX_ALIGN_RIGHT)
1058                         fl_addtopup(SubEditTable, _("|Align Right%R%x41"));
1059                 else
1060                         fl_addtopup(SubEditTable, _("|Align Right%r%x41"));
1061                 fl_setpup_shortcut(SubEditTable, 41, scex(_("EMT|iI#i#I")));
1062
1063                 if (align == LYX_ALIGN_CENTER)
1064                         fl_addtopup(SubEditTable, _("|Align Center%R%x42%l"));
1065                 else
1066                         fl_addtopup(SubEditTable, _("|Align Center%r%x42%l"));
1067                 fl_setpup_shortcut(SubEditTable, 42, scex(_("EMT|Cc#c#C")));
1068
1069                 // xgettext:no-c-format
1070                 fl_addtopup(SubEditTable, _("|Append Row%x32"));
1071                 fl_setpup_shortcut(SubEditTable, 32, scex(_("EMT|oO#o#O")));
1072                 // xgettext:no-c-format
1073                 fl_addtopup(SubEditTable, _("|Append Column%x33%l"));
1074                 fl_setpup_shortcut(SubEditTable, 33, scex(_("EMT|uU#u#U")));
1075                 // xgettext:no-c-format
1076                 fl_addtopup(SubEditTable, _("|Delete Row%x34"));
1077                 fl_setpup_shortcut(SubEditTable, 34, scex(_("EMT|wW#w#W")));
1078                 // xgettext:no-c-format
1079                 fl_addtopup(SubEditTable, _("|Delete Column%x35%l"));
1080                 fl_setpup_shortcut(SubEditTable, 35, scex(_("EMT|nN#n#N")));
1081                 // xgettext:no-c-format
1082                 fl_addtopup(SubEditTable, _("|Delete Table%x43"));
1083                 fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
1084         } else {
1085                 fl_addtopup(SubEditTable, _("Table%t"));
1086                 // xgettext:no-c-format
1087                 fl_addtopup(SubEditTable, _("|Insert table%x31"));
1088                 fl_setpup_shortcut(SubEditTable, 31, scex(_("EMT|Ii#i#I")));
1089         }
1090
1091         int SubVersionControl =         fl_newpup(FL_ObjWin(ob));
1092         fl_addtopup(SubVersionControl, _("Version Control%t"));
1093         if (tmpbuffer->lyxvc.inUse()) {
1094                 // xgettext:no-c-format
1095                 fl_addtopup(SubVersionControl, _("|Register%d%x51"));
1096                 if (tmpbuffer->isReadonly()) {
1097                         // signifies that the file is not checked out
1098                         // xgettext:no-c-format
1099                         fl_addtopup(SubVersionControl, _("|Check In Changes%d%x52"));
1100                         // xgettext:no-c-format
1101                         fl_addtopup(SubVersionControl, _("|Check Out for Edit%x53"));
1102                 } else {
1103                         // signifies that the file is checked out
1104                         // xgettext:no-c-format
1105                         fl_addtopup(SubVersionControl, _("|Check In Changes%x52"));
1106                         // xgettext:no-c-format
1107                         fl_addtopup(SubVersionControl, _("|Check Out for Edit%d%x53"));
1108                 }
1109                 // xgettext:no-c-format
1110                 fl_addtopup(SubVersionControl, _("|Revert to last version%x54"));
1111                 // xgettext:no-c-format
1112                 fl_addtopup(SubVersionControl, _("|Undo last check in%x55"));
1113                 // xgettext:no-c-format
1114                 fl_addtopup(SubVersionControl, _("|Show History%x56"));
1115         } else {
1116                 // xgettext:no-c-format
1117                 fl_addtopup(SubVersionControl, _("|Register%x51"));
1118         }
1119         // the shortcuts are not good.
1120         fl_setpup_shortcut(SubVersionControl, 51, scex(_("EMV|Rr#r#R")));
1121         fl_setpup_shortcut(SubVersionControl, 52, scex(_("EMV|Ii#i#I")));
1122         fl_setpup_shortcut(SubVersionControl, 53, scex(_("EMV|Oo#o#O")));
1123         fl_setpup_shortcut(SubVersionControl, 54, scex(_("EMV|lL#l#l")));
1124         fl_setpup_shortcut(SubVersionControl, 55, scex(_("EMV|Uu#u#U")));
1125         fl_setpup_shortcut(SubVersionControl, 56, scex(_("EMV|Hh#h#H")));
1126
1127         int EditMenu= fl_defpup(FL_ObjWin(ob),
1128                                 _("Undo"
1129                                   "|Redo %l"
1130                                   "|Cut"
1131                                   "|Copy"
1132                                   "|Paste%l"
1133                                   "|Find & Replace..."
1134                                   "|Go to Error"
1135                                   "|Go to Note"
1136                                   "|Floats & Insets%m"
1137                                   "|Table%m"
1138                                   "|Spellchecker...."
1139                                   "|Check TeX"
1140                                   "|Table of Contents..."
1141                                   "|List of Figures..."
1142                                   "|List of Tables..."
1143                                   "|List of Algorithms...%l"
1144                                   "|Version Control%m%l"
1145                                   "|View LaTeX log file%l"
1146                                   "|Paste Primary Selection as Lines"
1147                                   "|Paste Primary Selection as Paragraphs"),
1148                                 SubEditFloats, SubEditTable, SubVersionControl);
1149
1150         fl_setpup_shortcut(EditMenu, 1, scex(_("EM|Uu#u#U")));
1151         fl_setpup_shortcut(EditMenu, 2, scex(_("EM|Rr#r#R")));
1152         fl_setpup_shortcut(EditMenu, 3, scex(_("EM|Cc#c#C")));
1153         fl_setpup_shortcut(EditMenu, 4, scex(_("EM|oO#o#O")));
1154         fl_setpup_shortcut(EditMenu, 5, scex(_("EM|Pp#p#P")));
1155         fl_setpup_shortcut(EditMenu, 6, scex(_("EM|Ff#f#F")));
1156         fl_setpup_shortcut(EditMenu, 7, scex(_("EM|Ee#e#E")));
1157         fl_setpup_shortcut(EditMenu, 8, scex(_("EM|Nn#n#N")));
1158         fl_setpup_shortcut(EditMenu, 9, scex(_("EM|Ii#i#I")));
1159         //fl_setpup_shortcut(EditMenu, 10, scex(_("EM|Tt#t#T")));
1160         fl_setpup_shortcut(EditMenu, 11, scex(_("EM|Ss#s#S")));
1161         fl_setpup_shortcut(EditMenu, 12, scex(_("EM|hH#h#H")));
1162         fl_setpup_shortcut(EditMenu, 13, scex(_("EM|Tt#t#T")));
1163         //fl_setpup_shortcut(EditMenu, 14, scex(_("EM|Ff#f#F")));
1164         //fl_setpup_shortcut(EditMenu, 15, scex(_("EM|bB#b#B")));
1165         //fl_setpup_shortcut(EditMenu, 16, scex(_("EM|mM#m#M")));
1166         fl_setpup_shortcut(EditMenu, 17, scex(_("EM|Vv#v#V")));
1167         fl_setpup_shortcut(EditMenu, 18, scex(_("EM|wW#w#W")));
1168         fl_setpup_shortcut(EditMenu, 19, scex(_("EM|Ll#l#L")));
1169         fl_setpup_shortcut(EditMenu, 20, scex(_("EM|gG#g#G")));
1170       
1171         // disable unavailable entries.
1172         if(tmpbuffer->undostack.empty())
1173                 fl_setpup_mode(EditMenu, 1, FL_PUP_GREY);
1174         if(tmpbuffer->redostack.empty())
1175                 fl_setpup_mode(EditMenu, 2, FL_PUP_GREY);
1176         if(lyxrc.isp_command == "none") 
1177                 fl_setpup_mode(EditMenu, 11, FL_PUP_GREY);
1178         if(lyxrc.chktex_command == "none") 
1179                 fl_setpup_mode(EditMenu, 12, FL_PUP_GREY);
1180
1181         if (tmpbuffer->isReadonly()) {
1182                 fl_setpup_mode(EditMenu, 1, FL_PUP_GREY); 
1183                 fl_setpup_mode(EditMenu, 2, FL_PUP_GREY); 
1184                 fl_setpup_mode(EditMenu, 3, FL_PUP_GREY); 
1185                 fl_setpup_mode(EditMenu, 5, FL_PUP_GREY); 
1186                 fl_setpup_mode(EditMenu, 19, FL_PUP_GREY); 
1187                 fl_setpup_mode(EditMenu, 20, FL_PUP_GREY);
1188         }
1189         
1190         fl_setpup_position(men->_view->getForm()->x + ob->x,
1191                            men->_view->getForm()->y + ob->y +
1192                            ob->h + 10);   
1193         int choice = fl_dopup(EditMenu);
1194         XFlush(fl_display);
1195    
1196         // set the pseudo menu-button back
1197         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1198         fl_redraw_object(ob);
1199
1200         switch (choice) {
1201         case  1: tmpfunc->Dispatch(LFUN_UNDO); break;
1202         case  2: tmpfunc->Dispatch(LFUN_REDO); break;
1203         case  3: tmpfunc->Dispatch(LFUN_CUT); break;
1204         case  4: tmpfunc->Dispatch(LFUN_COPY); break;
1205         case  5: tmpfunc->Dispatch(LFUN_PASTE); break;
1206         case  6: tmpfunc->Dispatch(LFUN_MENUSEARCH); break;
1207         case  7: tmpfunc->Dispatch(LFUN_GOTOERROR); break;
1208         case  8: tmpfunc->Dispatch(LFUN_GOTONOTE); break;
1209         case  9: // floats & insets
1210                 break;
1211         case 10:// table 
1212                 break;
1213         case 11: tmpfunc->Dispatch(LFUN_SPELLCHECK); break;
1214         case 12: tmpfunc->Dispatch(LFUN_RUNCHKTEX); break;
1215         case 13: tmpfunc->Dispatch(LFUN_TOCVIEW); break;
1216         case 14: tmpfunc->Dispatch(LFUN_LOFVIEW); break;
1217         case 15: tmpfunc->Dispatch(LFUN_LOTVIEW); break;
1218         case 16: tmpfunc->Dispatch(LFUN_LOAVIEW); break;
1219         case 17: // version control
1220                 break;
1221         case 18: tmpfunc->Dispatch(LFUN_LATEX_LOG); break;
1222         case 19: tmpfunc->Dispatch(LFUN_PASTESELECTION, "line"); break;
1223         case 20: tmpfunc->Dispatch(LFUN_PASTESELECTION, "paragraph"); break;
1224
1225 #ifndef NEW_INSETS
1226         // floats & insets sub-menu
1227         case 21: men->currentView()->toggleFloat(); break;
1228         case 22: tmpfunc->Dispatch(LFUN_MELT); break;
1229         case 23: men->currentView()->allFloats(1, 0); break;
1230         case 24: men->currentView()->allFloats(0, 0); break;
1231         case 25: men->currentView()->allFloats(1, 1); break;
1232         case 26: men->currentView()->allFloats(0, 1); break;
1233         case 27: tmpfunc->Dispatch(LFUN_REMOVEERRORS); break;
1234 #endif
1235         case 31: tmpfunc->Dispatch(LFUN_DIALOG_TABULAR_INSERT); break;
1236                 // this is really temporary. We need new function in keybind.C
1237                 // These should set the minibuffer, too.
1238         case 32: case 33: case 34:
1239         case 35: case 36: case 37:
1240         case 38: case 39: case 40: 
1241         case 41: case 42: case 43:
1242         case 44: 
1243                 if (men->currentView()->available()) {
1244                         men->currentView()->hideCursor();
1245                         if (!men->currentView()->text->selection){
1246                                 men->currentView()->beforeChange(); 
1247                                 men->currentView()->update(BufferView::SELECT|BufferView::FITCUR);
1248                         }
1249                         if (men->currentView()->the_locking_inset &&
1250                             (men->currentView()->the_locking_inset->LyxCode()
1251                              == Inset::TABULAR_CODE)) {
1252                                 InsetTabular * inset =
1253                                     static_cast<InsetTabular *>
1254                                        (men->currentView()->the_locking_inset);
1255                                 inset->TabularFeatures(men->currentView(), choice - 32);
1256                         }
1257 #ifndef NEW_TABULAR
1258                         else {
1259                                 men->currentView()->text->
1260                                         TableFeatures(men->currentView(), choice - 32);
1261                                 men->currentView()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1262                         }
1263 #endif
1264                 }
1265                 break;
1266                 // version control sub-menu
1267         case 51: // register
1268                 tmpfunc->Dispatch(LFUN_VC_REGISTER);
1269                 break;
1270         case 52: // check in
1271                 tmpfunc->Dispatch(LFUN_VC_CHECKIN);
1272                 break;
1273         case 53: // check out
1274                 tmpfunc->Dispatch(LFUN_VC_CHECKOUT);
1275                 break;
1276         case 54: // revert to last
1277                 tmpfunc->Dispatch(LFUN_VC_REVERT);
1278                 break;
1279         case 55: // undo last
1280                 tmpfunc->Dispatch(LFUN_VC_UNDO);
1281                 break;
1282         case 56: // show history
1283                 tmpfunc->Dispatch(LFUN_VC_HISTORY);
1284                 break;
1285         }
1286
1287         fl_freepup(EditMenu);
1288         fl_freepup(SubEditFloats);
1289         fl_freepup(SubEditTable);
1290         fl_freepup(SubVersionControl);
1291 }
1292
1293 vector<int>::size_type const max_number_of_menus = 32;
1294 unsigned int const max_number_of_items = 25;
1295
1296 string Limit_string_length(string const & str) {
1297         string::size_type const max_item_length = 45;
1298
1299         if (str.size() > max_item_length)
1300                 return str.substr(0, max_item_length-3) + "...";
1301         else
1302                 return str;
1303 }
1304
1305 void Add_to_toc_menu(vector<Buffer::TocItem> const & toclist, 
1306                      unsigned int from, unsigned int to, int depth,
1307                      int menu, vector<int> & menus, FL_OBJECT * ob)
1308 {
1309         if (to - from <= max_number_of_items) {
1310                 for (unsigned int i = from; i < to; ++i) {
1311                         string entry(4 * max(0, toclist[i].depth - depth),' ');
1312                         entry += toclist[i].str;
1313                         entry = Limit_string_length(entry);
1314                         entry += "%x" + tostr(i + 1);
1315                         fl_addtopup(menu, entry.c_str());
1316                 }
1317         } else {
1318                 unsigned int pos = from;
1319                 unsigned int count = 0;
1320                 while (pos < to) {
1321                         ++count;
1322                         if (count > max_number_of_items) {
1323                                 fl_addtopup(menu, ". . .%d");
1324                                 break;
1325                         }
1326                         unsigned int new_pos = pos+1;
1327                         while (new_pos < to &&
1328                                toclist[new_pos].depth > depth)
1329                                 ++new_pos;
1330
1331                         string entry(4 * max(0, toclist[pos].depth - depth), ' ');
1332                         entry += toclist[pos].str;
1333                         entry = Limit_string_length(entry);
1334
1335                         if (new_pos == pos + 1) {
1336                                 entry += "%x";
1337                                 entry += tostr(pos + 1);
1338                                 fl_addtopup(menu, entry.c_str());
1339                         } else if (menus.size() < max_number_of_menus) {
1340                                 int menu2 = fl_newpup(FL_ObjWin(ob));
1341                                 menus.push_back(menu2);
1342                                 Add_to_toc_menu(toclist, pos, new_pos,
1343                                                 depth + 1, menu2, menus,ob);
1344                                 entry += "%m";
1345                                 fl_addtopup(menu, entry.c_str(), menu2);
1346                         } else {
1347                                 entry += "%d";
1348                                 fl_addtopup(menu, entry.c_str());
1349                         }
1350                         pos = new_pos;
1351                 }
1352         }
1353 }
1354
1355 int const BIG_NUM = 1048576;
1356
1357 void Menus::ShowTocMenu(FL_OBJECT * ob, long)
1358 {
1359         Menus * men = static_cast<Menus*>(ob->u_vdata);
1360         vector<int> menus;
1361
1362         // set the pseudo menu-button
1363         fl_set_object_boxtype(ob, FL_UP_BOX);
1364         fl_set_button(ob, 0);
1365         fl_redraw_object(ob);
1366    
1367         int TocMenu = fl_newpup(FL_ObjWin(ob));
1368         menus.push_back(TocMenu);
1369         vector<vector<Buffer::TocItem> > toclist =
1370                 men->currentView()->buffer()->getTocList();
1371
1372         //xgettext:no-c-format
1373         static char const * MenuNames[3] = { N_("List of Figures%m"),
1374         //xgettext:no-c-format
1375                                              N_("List of Tables%m"),
1376         //xgettext:no-c-format
1377                                              N_("List of Algorithms%m") };
1378
1379         int max_nonempty = 0;
1380         for (int j = 1; j <= 3; ++j)
1381                 if (!toclist[j].empty())
1382                         max_nonempty = j;
1383
1384         for (int j = 1; j <= 3; ++j)
1385                 if (!toclist[j].empty()) {
1386                         int menu2 = fl_newpup(FL_ObjWin(ob));
1387                         menus.push_back(menu2);
1388                         for (unsigned int i = 0; i < toclist[j].size(); ++i) {
1389                                 if (i > max_number_of_items) {
1390                                         fl_addtopup(menu2, ". . .%d");
1391                                         break;
1392                                 }
1393                                 string entry = Limit_string_length(toclist[j][i].str);
1394                                 entry += "%x" + tostr(i+1+j*BIG_NUM);
1395                                 fl_addtopup(menu2, entry.c_str());
1396                         }
1397                         if (j == max_nonempty) {
1398                                 string tmp = _(MenuNames[j-1]);
1399                                 tmp += "%l";
1400                                 fl_addtopup(TocMenu, tmp.c_str(), menu2);
1401                         } else
1402                                 fl_addtopup(TocMenu, _(MenuNames[j-1]), menu2);
1403                 }
1404
1405         Add_to_toc_menu(toclist[0], 0, toclist[0].size(), 0,
1406                         TocMenu, menus, ob);
1407
1408         fl_setpup_position(
1409                 men->_view->getForm()->x + ob->x,
1410                 men->_view->getForm()->y + ob->y + ob->h + 10);   
1411         int choice = fl_dopup(TocMenu);
1412         XFlush(fl_display);
1413
1414         // set the pseudo menu-button back
1415         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1416         fl_redraw_object(ob);
1417         if (choice == 0)
1418                 men->_view->getLyXFunc()->Dispatch(LFUN_TOCVIEW);
1419         else if (choice > 0) {
1420                 int type = choice / BIG_NUM;
1421                 int num = (choice % BIG_NUM) - 1;
1422                 BufferView *bv = men->currentView();
1423                 bv->beforeChange();
1424                 bv->text->SetCursor(bv, toclist[type][num].par, 0);
1425                 bv->text->sel_cursor = bv->text->cursor;
1426                 bv->update(BufferView::SELECT|BufferView::FITCUR);
1427         }
1428         for (unsigned int i = 0; i < menus.size(); ++i)
1429                 fl_freepup(menus[i]);
1430 }
1431
1432 void Add_to_refs_menu(vector<string> const & label_list, int offset,
1433                      int menu, vector<int> & menus, FL_OBJECT * ob)
1434 {
1435         typedef vector<string>::size_type size_type;
1436         size_type const max_number_of_items = 25;
1437         size_type const max_number_of_items2 = 20;
1438         string::size_type const max_item_length = 40;
1439         string::size_type const max_item_length2 = 20;
1440
1441         if (label_list.size() <= max_number_of_items)
1442                 for (size_type i = 0; i < label_list.size(); ++i) {
1443                         string entry = label_list[i];
1444                         if (entry.size() > max_item_length)
1445                                 entry = entry.substr(0, max_item_length-1) + "$";
1446                         entry += "%x" + tostr(i+offset);
1447                         fl_addtopup(menu, entry.c_str());
1448                 }
1449         else {
1450                 size_type count = 0;
1451                 for (size_type i = 0; i < label_list.size();
1452                      i += max_number_of_items2) {
1453                         ++count;
1454                         if (count > max_number_of_items) {
1455                                 fl_addtopup(menu, ". . .%d");
1456                                 break;
1457                         }
1458                         size_type j = min(label_list.size(),
1459                                           i+max_number_of_items2);
1460
1461                         string entry;
1462                         if (label_list[i].size() > max_item_length2)
1463                                 entry += label_list[i].substr(0, max_item_length2-1) + "$";
1464                         else
1465                                 entry += label_list[i];
1466                         entry += "..";
1467                         if (label_list[j-1].size() > max_item_length2)
1468                                 entry += label_list[j-1].substr(0, max_item_length2-1) + "$";
1469                         else
1470                                 entry += label_list[j-1];
1471
1472                         if (menus.size() < max_number_of_menus) {
1473                                 int menu2 = fl_newpup(FL_ObjWin(ob));
1474                                 menus.push_back(menu2);
1475                                 for (size_type k = i;  k < j; ++k) {
1476                                         string entry2 = label_list[k];
1477                                         if (entry2.size() > max_item_length)
1478                                                 entry2 = entry2.substr(0, max_item_length-1) + "$";
1479                                         entry2 += "%x" + tostr(k+offset);
1480                                         fl_addtopup(menu2, entry2.c_str());
1481                                 }
1482                                 entry += "%m";
1483                                 fl_addtopup(menu, entry.c_str(), menu2);
1484                         } else {
1485                                 entry += "%d";
1486                                 fl_addtopup(menu, entry.c_str());
1487                         }
1488                 }
1489         }
1490 }
1491
1492 void Menus::ShowRefsMenu(FL_OBJECT * ob, long)
1493 {
1494         vector<int> menus;
1495
1496         Menus * men = static_cast<Menus*>(ob->u_vdata);
1497
1498         // set the pseudo menu-button
1499         fl_set_object_boxtype(ob, FL_UP_BOX);
1500         fl_set_button(ob, 0);
1501         fl_redraw_object(ob);
1502    
1503         int RefsMenu = fl_newpup(FL_ObjWin(ob));
1504         menus.push_back(RefsMenu);
1505         Buffer * buffer = men->currentView()->buffer();
1506         vector<string> label_list = buffer->getLabelList();
1507         sort(label_list.begin(), label_list.end());
1508
1509         //xgettext:no-c-format
1510         static char const * MenuNames[6] = { N_("Insert Reference%m"),
1511         //xgettext:no-c-format
1512                                              N_("Insert Page Number%m"),
1513         //xgettext:no-c-format
1514                                              N_("Insert vref%m"),
1515         //xgettext:no-c-format
1516                                              N_("Insert vpageref%m"),
1517         //xgettext:no-c-format
1518                                              N_("Insert Pretty Ref%m"),
1519         //xgettext:no-c-format
1520                                              N_("Goto Reference%m") };
1521
1522         for (int j = 0; j < 6; ++j) {
1523                 if (menus.size() < max_number_of_menus) {
1524                         int menu2 = fl_newpup(FL_ObjWin(ob));
1525                         menus.push_back(menu2);
1526                         Add_to_refs_menu(label_list, (j+1)*BIG_NUM, menu2, menus, ob);
1527                         fl_addtopup(RefsMenu, _(MenuNames[j]), menu2);
1528                 } else {
1529                         string tmp = _(MenuNames[j]);
1530                         tmp += "%d";
1531                         fl_addtopup(RefsMenu, tmp.c_str());     
1532                 }
1533         }
1534         fl_addtopup(RefsMenu, _("Go Back"));
1535
1536         bool empty = label_list.empty();
1537         bool sgml = buffer->isSGML();
1538         bool readonly = buffer->isReadonly();
1539
1540         if (empty)
1541                 fl_setpup_mode(RefsMenu, 6, FL_PUP_GREY);
1542         if (empty || readonly) {
1543                 fl_setpup_mode(RefsMenu, 1, FL_PUP_GREY);
1544                 fl_setpup_mode(RefsMenu, 2, FL_PUP_GREY);
1545         }
1546         if (empty || readonly || sgml) {
1547                 fl_setpup_mode(RefsMenu, 3, FL_PUP_GREY);
1548                 fl_setpup_mode(RefsMenu, 4, FL_PUP_GREY);
1549                 fl_setpup_mode(RefsMenu, 5, FL_PUP_GREY);
1550         }
1551         if (men->currentView()->NoSavedPositions())
1552                 fl_setpup_mode(RefsMenu, 7, FL_PUP_GREY);       
1553
1554         fl_setpup_position(
1555                 men->_view->getForm()->x + ob->x,
1556                 men->_view->getForm()->y + ob->y + ob->h + 10);   
1557         int choice = fl_dopup(RefsMenu);
1558         XFlush(fl_display);
1559
1560         // set the pseudo menu-button back
1561         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1562         fl_redraw_object(ob);
1563
1564         if (choice == 7)
1565                 men->_view->getLyXFunc()->Dispatch(LFUN_REF_BACK);
1566         else if (choice >= BIG_NUM) {
1567                 int type = (choice / BIG_NUM) - 1;
1568                 int num = choice % BIG_NUM;
1569                 if (type >= 5)
1570                         men->_view->getLyXFunc()->Dispatch(LFUN_REF_GOTO,
1571                                                            label_list[num].c_str());
1572                 else {
1573                         static string const cmdname[5]
1574                                 = { "ref", "pageref", "vref", "vpageref", "prettyref"};
1575                         InsetCommandParams p( cmdname[type] );
1576                         p.setContents( label_list[num] );
1577                         men->currentView()->insertInset(new InsetRef(p));
1578                 }
1579         }
1580
1581         for (unsigned int i = 0; i < menus.size(); ++i)
1582                 fl_freepup(menus[i]);
1583 }
1584
1585
1586 void Menus::ShowLayoutMenu(FL_OBJECT * ob, long)
1587 {
1588         Menus * men = static_cast<Menus*>(ob->u_vdata);
1589
1590         if (!men->currentView()->available())
1591                 return;
1592         
1593         // set the pseudo menu-button
1594         fl_set_object_boxtype(ob, FL_UP_BOX);
1595         fl_set_button(ob, 0);
1596         fl_redraw_object(ob);
1597    
1598         Buffer * tmpbuffer = men->_view->buffer();
1599         LyXFunc * tmpfunc = men->_view->getLyXFunc();
1600
1601         int LayoutMenu = fl_newpup(FL_ObjWin(ob));
1602         fl_addtopup(LayoutMenu, _("Character..."
1603                                   "|Paragraph..."
1604                                   "|Document..."
1605                                   "|Paper..."
1606                                   "|Table..."
1607                                   "|Quotes...%l"
1608                                   "|Emphasize Style%b"
1609                                   "|Noun Style%b"
1610                                   "|Bold Style%b"
1611                                   "|TeX Style%b%l"
1612                                   "|Change Environment Depth"
1613                                   "|LaTeX Preamble..."
1614                                   "|Start of Appendix%l"
1615                                   "|Save layout as default"));
1616         fl_setpup_shortcut(LayoutMenu, 1, scex(_("LM|Cc#c#C")));
1617         fl_setpup_shortcut(LayoutMenu, 2, scex(_("LM|Pp#p#P")));
1618         fl_setpup_shortcut(LayoutMenu, 3, scex(_("LM|Dd#d#D")));
1619         fl_setpup_shortcut(LayoutMenu, 4, scex(_("LM|aA#a#A")));
1620         fl_setpup_shortcut(LayoutMenu, 5, scex(_("LM|eE#e#E")));
1621         fl_setpup_shortcut(LayoutMenu, 6, scex(_("LM|Qq#q#Q")));
1622         fl_setpup_shortcut(LayoutMenu, 7, scex(_("LM|mM#m#M")));
1623         fl_setpup_shortcut(LayoutMenu, 8, scex(_("LM|Nn#n#N")));
1624         fl_setpup_shortcut(LayoutMenu, 9, scex(_("LM|Bb#b#B")));
1625         fl_setpup_shortcut(LayoutMenu, 10, scex(_("LM|Tt#t#T")));
1626         fl_setpup_shortcut(LayoutMenu, 11, scex(_("LM|vV#v#V")));
1627         fl_setpup_shortcut(LayoutMenu, 12, scex(_("LM|Ll#l#L")));
1628         fl_setpup_shortcut(LayoutMenu, 13, scex(_("LM|xX#x#X")));
1629         fl_setpup_shortcut(LayoutMenu, 14, scex(_("LM|Ss#s#S")));
1630
1631         // Set values of checkboxes according to font
1632         LyXFont font = men->currentView()->text->real_current_font;
1633         if (font.emph() == LyXFont::ON)
1634                 fl_setpup_mode(LayoutMenu, 7, FL_PUP_CHECK);
1635         if (font.noun() == LyXFont::ON)
1636                 fl_setpup_mode(LayoutMenu, 8, FL_PUP_CHECK);
1637         if (font.series() == LyXFont::BOLD_SERIES)
1638                 fl_setpup_mode(LayoutMenu, 9, FL_PUP_CHECK);
1639         if (font.latex() == LyXFont::ON)
1640                 fl_setpup_mode(LayoutMenu, 10, FL_PUP_CHECK);
1641
1642         // Grey out unavailable entries
1643 #ifndef NEW_TABULAR
1644         if (!men->currentView()->text->cursor.par()->table)
1645                 fl_setpup_mode(LayoutMenu, 5, FL_PUP_GREY);
1646 #endif
1647         if (tmpbuffer->isReadonly()) {
1648                 fl_setpup_mode(LayoutMenu, 1, FL_PUP_GREY);
1649                 fl_setpup_mode(LayoutMenu, 6, FL_PUP_GREY);
1650                 fl_setpup_mode(LayoutMenu, 11, FL_PUP_GREY);
1651         }
1652
1653         fl_setpup_position(
1654                 men->_view->getForm()->x + ob->x,
1655                 men->_view->getForm()->y + ob->y + ob->h + 10);
1656         int choice = fl_dopup(LayoutMenu);
1657         XFlush(fl_display);
1658
1659         // set the pseudo menu-button back
1660         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1661         fl_redraw_object(ob);
1662
1663         switch (choice) {
1664         case 1:  tmpfunc->Dispatch(LFUN_LAYOUT_CHARACTER); break;
1665         case 2:  tmpfunc->Dispatch(LFUN_LAYOUT_PARAGRAPH); break;
1666         case 3:  tmpfunc->Dispatch(LFUN_LAYOUT_DOCUMENT);  break;
1667         case 4:  tmpfunc->Dispatch(LFUN_LAYOUT_PAPER); break;
1668         case 5:  tmpfunc->Dispatch(LFUN_LAYOUT_TABLE, "true"); break;
1669         case 6:  tmpfunc->Dispatch(LFUN_LAYOUT_QUOTES); break;
1670         case 7:  tmpfunc->Dispatch(LFUN_EMPH); break;
1671         case 8:  tmpfunc->Dispatch(LFUN_NOUN); break;
1672         case 9:  tmpfunc->Dispatch(LFUN_BOLD); break;
1673         case 10: tmpfunc->Dispatch(LFUN_TEX); break;
1674         case 11: tmpfunc->Dispatch(LFUN_DEPTH_PLUS); break;
1675         case 12: tmpfunc->Dispatch(LFUN_LAYOUT_PREAMBLE); break;
1676         case 13: tmpfunc->Dispatch(LFUN_APPENDIX); break;
1677         case 14: tmpfunc->Dispatch(LFUN_LAYOUT_SAVE_DEFAULT); break;
1678         }
1679         fl_freepup(LayoutMenu); 
1680 }
1681
1682
1683 void Menus::ShowInsertMenu(FL_OBJECT * ob, long)
1684 {
1685         Menus * men = static_cast<Menus*>(ob->u_vdata);
1686         
1687         // set the pseudo menu-button
1688         fl_set_object_boxtype(ob, FL_UP_BOX);
1689         fl_set_button(ob, 0);
1690         fl_redraw_object(ob);
1691  
1692         Buffer * tmpbuffer = men->_view->buffer();
1693         LyXFunc * tmpfunc = men->_view->getLyXFunc();
1694
1695         int SubInsertAscii = fl_defpup(FL_ObjWin(ob),
1696                                        _("Import ASCII file%t"
1697                                          "|As Lines%x41"
1698                                          "|As Paragraphs%x42"));
1699         
1700         fl_setpup_shortcut(SubInsertAscii, 41, scex(_("IMA|Ll#l#L")));
1701         fl_setpup_shortcut(SubInsertAscii, 42, scex(_("IMA|Pp#p#P")));
1702
1703         int SubInsertTableList= fl_defpup(FL_ObjWin(ob),
1704                                           _("Lists & TOC%t"
1705                                             "|Table of Contents%x21"
1706                                             "|List of Figures%x22"
1707                                             "|List of Tables%x23"
1708                                             "|List of Algorithms%x24"
1709                                             "|Index List%x25"
1710                                             "|BibTeX Reference%x26"));
1711         
1712         fl_setpup_shortcut(SubInsertTableList, 21, scex(_("IMT|Cc#c#C")));
1713         fl_setpup_shortcut(SubInsertTableList, 22, scex(_("IMT|Ff#f#F")));
1714         fl_setpup_shortcut(SubInsertTableList, 23, scex(_("IMT|Tt#t#T")));
1715         fl_setpup_shortcut(SubInsertTableList, 24, scex(_("IMT|Aa#a#A")));
1716         fl_setpup_shortcut(SubInsertTableList, 25, scex(_("IMT|Ii#i#I")));
1717         fl_setpup_shortcut(SubInsertTableList, 26, scex(_("IMT|Bb#b#B")));
1718
1719         int SubInsertFloatList = fl_defpup(FL_ObjWin(ob),
1720                                            _("Floats%t"
1721                                              "|Figure Float%x71"
1722                                              "|Table Float%x72"
1723                                              "|Wide Figure Float%x73"
1724                                              "|Wide Table Float%l%x74"
1725                                              "|Algorithm Float%x75"));
1726         
1727         fl_setpup_shortcut(SubInsertFloatList, 71, scex(_("IMF|gG#g#G")));
1728         fl_setpup_shortcut(SubInsertFloatList, 72, scex(_("IMF|Tt#t#T")));
1729         fl_setpup_shortcut(SubInsertFloatList, 73, scex(_("IMF|Ww#w#W")));
1730         fl_setpup_shortcut(SubInsertFloatList, 74, scex(_("IMF|iI#i#I")));
1731         fl_setpup_shortcut(SubInsertFloatList, 75, scex(_("IMF|Aa#a#A")));
1732         
1733         int SubInsertSpecial = fl_defpup(FL_ObjWin(ob),
1734                                          _("Special Character%t"
1735                                            "|HFill%x31"
1736                                            "|Hyphenation Point%x32"
1737                                            "|Protected Blank%x33"
1738                                            "|Linebreak%x34"
1739                                            "|Ellipsis (...)%x35"
1740                                            "|End of sentence period%x36"
1741                                            "|Ordinary Quote (\")%x37"
1742                                            "|Menu Separator %x38"));
1743
1744         fl_setpup_shortcut(SubInsertSpecial, 31, scex(_("IMS|Hh#h#H")));
1745         fl_setpup_shortcut(SubInsertSpecial, 32, scex(_("IMS|Pp#p#P")));
1746         fl_setpup_shortcut(SubInsertSpecial, 33, scex(_("IMS|Bb#b#B")));
1747         fl_setpup_shortcut(SubInsertSpecial, 34, scex(_("IMS|Ll#l#L")));
1748         fl_setpup_shortcut(SubInsertSpecial, 35, scex(_("IMS|iI#i#I")));
1749         fl_setpup_shortcut(SubInsertSpecial, 36, scex(_("IMS|Ee#e#E")));
1750         fl_setpup_shortcut(SubInsertSpecial, 37, scex(_("IMS|Qq#q#Q")));
1751         fl_setpup_shortcut(SubInsertSpecial, 38, scex(_("IMS|Mm#m#M")));
1752         
1753         int InsertMenu = fl_defpup(FL_ObjWin(ob),
1754                                    _("Figure..."
1755                                      "|Table...%l"
1756                                      "|Include File..." 
1757                                      "|Import ASCII File%m"
1758                                      "|Insert LyX File..."
1759                                      "|Insert external material...%l"
1760                                      "|Footnote"
1761                                      "|Margin Note"
1762                                      "|Floats%m%l"      
1763                                      "|Lists & TOC%m%l"
1764                                      "|Special Character%m%l"
1765                                      "|Note..."
1766                                      "|Label..."
1767                                      "|Cross-Reference..."
1768                                      "|Citation Reference..."
1769                                      "|Index entry..."
1770                                      "|Index entry of last word"),
1771                                    SubInsertAscii,
1772                                    SubInsertFloatList,  
1773                                    SubInsertTableList,
1774                                    SubInsertSpecial);
1775
1776         fl_setpup_shortcut(InsertMenu, 1, scex(_("IM|gG#g#G")));
1777         fl_setpup_shortcut(InsertMenu, 2, scex(_("IM|bB#b#B")));
1778         fl_setpup_shortcut(InsertMenu, 3, scex(_("IM|cC#c#C")));
1779         fl_setpup_shortcut(InsertMenu, 4, scex(_("IM|Aa#a#A")));
1780         fl_setpup_shortcut(InsertMenu, 5, scex(_("IM|Xx#x#X")));
1781         fl_setpup_shortcut(InsertMenu, 6, scex(_("IM|Ee#e#E")));
1782         fl_setpup_shortcut(InsertMenu, 7, scex(_("IM|Ff#f#F")));
1783         fl_setpup_shortcut(InsertMenu, 8, scex(_("IM|Mm#m#M")));
1784         fl_setpup_shortcut(InsertMenu, 9, scex(_("IM|oO#o#O")));
1785         fl_setpup_shortcut(InsertMenu, 10, scex(_("IM|Tt#t#T")));
1786         fl_setpup_shortcut(InsertMenu, 11, scex(_("IM|Ss#s#S")));
1787         fl_setpup_shortcut(InsertMenu, 12, scex(_("IM|Nn#n#N")));
1788         fl_setpup_shortcut(InsertMenu, 13, scex(_("IM|Ll#l#L")));
1789         fl_setpup_shortcut(InsertMenu, 14, scex(_("IM|rR#r#R")));     
1790         fl_setpup_shortcut(InsertMenu, 15, scex(_("IM|iI#i#I")));
1791         fl_setpup_shortcut(InsertMenu, 16, scex(_("IM|dD#d#D")));
1792         fl_setpup_shortcut(InsertMenu, 17, scex(_("IM|wW#w#W")));
1793
1794         fl_addtopup(InsertMenu, _("|URL..."));
1795         fl_setpup_shortcut(InsertMenu, 18, scex(_("IM|Uu#u#U")));
1796
1797         if (tmpbuffer->isReadonly()) {
1798                 for (int ii = 1; ii <= 17; ++ii)
1799                         fl_setpup_mode(InsertMenu, ii, FL_PUP_GREY);
1800                 fl_setpup_mode(InsertMenu, 18, FL_PUP_GREY);
1801         }
1802
1803         fl_setpup_position(
1804                 men->_view->getForm()->x + ob->x,
1805                 men->_view->getForm()->y + ob->y + ob->h + 10);
1806    
1807         int choice = fl_dopup(InsertMenu);
1808         XFlush(fl_display);
1809
1810         // set the pseudo menu-button back
1811         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1812         fl_redraw_object(ob);
1813
1814         if (men->currentView()->available()){
1815                 men->currentView()->hideCursor();
1816                 switch (choice) {
1817                 case 1: tmpfunc->Dispatch(LFUN_FIGURE); break;
1818                 case 2: tmpfunc->Dispatch(LFUN_DIALOG_TABULAR_INSERT); break;
1819                 case 3: tmpfunc->Dispatch(LFUN_CHILDINSERT); break;
1820                 case 4: // Insert ASCII file submenu
1821                         break;
1822                 case 5: tmpfunc->Dispatch(LFUN_FILE_INSERT); break;
1823                 case 41: tmpfunc->Dispatch(LFUN_FILE_INSERT_ASCII, "line"); break;
1824                 case 42: tmpfunc->Dispatch(LFUN_FILE_INSERT_ASCII, "paragraph"); break;
1825                 case 43: 
1826                         break;
1827
1828                 case 6: tmpfunc->Dispatch(LFUN_INSET_EXTERNAL); break;
1829
1830                 case 7:
1831 #ifndef NEW_INSETS
1832                         tmpfunc->Dispatch(LFUN_FOOTMELT); break;
1833 #else
1834                         tmpfunc->Dispatch(LFUN_INSET_FOOTNOTE);
1835                         break;
1836 #endif
1837                 case 8:
1838 #ifndef NEW_INSETS
1839                         tmpfunc->Dispatch(LFUN_MARGINMELT); break;
1840 #else
1841                         tmpfunc->Dispatch(LFUN_INSET_MARGINAL);
1842                         break;
1843 #endif
1844   
1845                 case 9: // Float sub-menu
1846                 case 71:
1847 #ifndef NEW_INSETS
1848                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "figure");
1849                         break;
1850 #else
1851                         tmpfunc->Dispatch(LFUN_INSET_FLOAT, "figure");
1852                         break;
1853 #endif
1854                 case 72:
1855 #ifndef NEW_INSETS
1856                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "table");
1857                         break;
1858 #else
1859                         tmpfunc->Dispatch(LFUN_INSET_FLOAT, "table");
1860                         break;
1861 #endif
1862                 case 73:
1863 #ifndef NEW_INSETS
1864                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "wide-fig");
1865                         break;
1866 #else
1867                         tmpfunc->Dispatch(LFUN_INSET_FLOAT, "figure");
1868                         break;
1869 #endif
1870                 case 74:
1871 #ifndef NEW_INSETS
1872                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "wide-tab");
1873                         break;
1874 #else
1875                         tmpfunc->Dispatch(LFUN_INSET_FLOAT, "table");
1876                         break;
1877 #endif
1878                 case 75:
1879 #ifndef NEW_INSETS
1880                         tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "algorithm");
1881                         break;
1882 #else
1883                         tmpfunc->Dispatch(LFUN_INSET_FLOAT, "algorithm");
1884                         break;
1885 #endif
1886                 case 10: // Table/List submenu
1887                         break;
1888                 case 21: tmpfunc->Dispatch(LFUN_TOC_INSERT); break;
1889                 case 22: tmpfunc->Dispatch(LFUN_LOF_INSERT); break;
1890                 case 23: tmpfunc->Dispatch(LFUN_LOT_INSERT); break;
1891                 case 24: tmpfunc->Dispatch(LFUN_LOA_INSERT); break;
1892                 case 25: tmpfunc->Dispatch(LFUN_INDEX_PRINT); break;
1893                 case 26: tmpfunc->Dispatch(LFUN_INSERT_BIBTEX); break;
1894
1895                 case 11: // Special Character submenu
1896                         break;
1897                 case 31: tmpfunc->Dispatch(LFUN_HFILL); break;
1898                 case 32: tmpfunc->Dispatch(LFUN_HYPHENATION); break;
1899                 case 33: tmpfunc->Dispatch(LFUN_PROTECTEDSPACE); break; 
1900                 case 34: tmpfunc->Dispatch(LFUN_BREAKLINE); break; 
1901                 case 35: tmpfunc->Dispatch(LFUN_LDOTS); break;
1902                 case 36: tmpfunc->Dispatch(LFUN_END_OF_SENTENCE); break;
1903                 case 37: tmpfunc->Dispatch(LFUN_QUOTE); break;
1904                 case 38: tmpfunc->Dispatch(LFUN_MENU_SEPARATOR); break;
1905
1906                 case 12: tmpfunc->Dispatch(LFUN_INSERT_NOTE); break;
1907                 case 13: tmpfunc->Dispatch(LFUN_INSERT_LABEL); break;
1908                 case 14: tmpfunc->Dispatch(LFUN_REF_INSERT); break;
1909                 case 15: tmpfunc->Dispatch(LFUN_CITATION_CREATE); break;
1910                 case 16: tmpfunc->Dispatch(LFUN_INDEX_CREATE); break;
1911                 case 17: tmpfunc->Dispatch(LFUN_INDEX_INSERT_LAST); break;
1912                 case 18: tmpfunc->Dispatch(LFUN_URL); break;
1913                 }
1914         }
1915         fl_freepup(InsertMenu);
1916         fl_freepup(SubInsertAscii);
1917         fl_freepup(SubInsertTableList);
1918         fl_freepup(SubInsertFloatList);
1919         fl_freepup(SubInsertSpecial);
1920 }
1921
1922
1923 void Menus::ShowMathMenu(FL_OBJECT * ob, long)
1924 {
1925         extern void math_insert_symbol(char const * s);
1926
1927         Menus * men = static_cast<Menus*>(ob->u_vdata);
1928
1929         // set the pseudo menu-button
1930         fl_set_object_boxtype(ob, FL_UP_BOX);
1931         fl_set_button(ob, 0);
1932         fl_redraw_object(ob);
1933
1934         Buffer * tmpbuffer = men->_view->buffer();
1935         LyXFunc * tmpfunc = men->_view->getLyXFunc();
1936
1937         int MathMenu = fl_defpup(FL_ObjWin(ob), 
1938                                  _("Fraction"
1939                                    "|Square root"
1940                                    "|Exponent"
1941                                    "|Index"
1942                                    "|Sum"
1943                                    "|Integral%l"
1944                                    "|Math mode"
1945                                    "|Display%l"
1946                                    "|Math Panel..."));
1947
1948         fl_setpup_shortcut(MathMenu, 1, scex(_("MM|Ff#f#F")));
1949         fl_setpup_shortcut(MathMenu, 2, scex(_("MM|Ss#s#S")));
1950         fl_setpup_shortcut(MathMenu, 3, scex(_("MM|Ee#e#E")));
1951         fl_setpup_shortcut(MathMenu, 4, scex(_("MM|xX#x#X")));
1952         fl_setpup_shortcut(MathMenu, 5, scex(_("MM|uU#u#U")));
1953         fl_setpup_shortcut(MathMenu, 6, scex(_("MM|Ii#i#I")));
1954         fl_setpup_shortcut(MathMenu, 7, scex(_("MM|Mm#m#M")));
1955         fl_setpup_shortcut(MathMenu, 8, scex(_("MM|Dd#d#D")));
1956         fl_setpup_shortcut(MathMenu, 9, scex(_("MM|Pp#p#P")));
1957
1958         if (tmpbuffer->isReadonly()) 
1959                 for (int ii = 1; ii <= 9; ++ii)
1960                         fl_setpup_mode(MathMenu, ii, FL_PUP_GREY);
1961
1962
1963         fl_setpup_position(
1964                 men->_view->getForm()->x + ob->x,
1965                 men->_view->getForm()->y + ob->y + ob->h + 10);   
1966         int choice = fl_dopup(MathMenu);  
1967         XFlush(fl_display);
1968
1969         // set the pseudo menu-button back
1970         fl_set_object_boxtype(ob, FL_FLAT_BOX);
1971         fl_redraw_object(ob);
1972
1973         if (men->currentView()->available())  {
1974                 switch (choice) {
1975                 case 1: /* frac */
1976                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "frac");
1977                         break;
1978                 case 2: /* sqrt */
1979                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "sqrt");
1980                         break;
1981                 case 3: /* Exponent */ 
1982                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "^");
1983                         break;
1984                 case 4: /* Index */
1985                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "_");
1986                         break;
1987                 case 5: /* sum */ 
1988                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "sum");
1989                         break;
1990                 case 6: /* int */
1991                         tmpfunc->Dispatch(LFUN_INSERT_MATH, "int");
1992                         break;
1993                 case 7:
1994                         tmpfunc->Dispatch(LFUN_MATH_MODE);
1995                         break;
1996                 case 8:
1997                         tmpfunc->Dispatch(LFUN_MATH_DISPLAY);
1998                         break;
1999                 case 9: /* Panel */
2000                         tmpfunc->Dispatch(LFUN_MATH_PANEL);
2001                         break;
2002                 }
2003                 men->currentView()->update(BufferView::SELECT|BufferView::FITCUR);
2004         } 
2005         fl_freepup(MathMenu);
2006 }
2007
2008
2009 void Menus::ShowOptionsMenu(FL_OBJECT * ob, long)
2010 {
2011         Menus * men = static_cast<Menus*>(ob->u_vdata);
2012
2013         // set the pseudo menu-button
2014         fl_set_object_boxtype(ob, FL_UP_BOX);
2015         fl_set_button(ob, 0);
2016         fl_redraw_object(ob);
2017
2018         //Buffer *tmpbuffer = men->_view->currentBuffer();
2019         LyXFunc * tmpfunc = men->_view->getLyXFunc();
2020
2021         int OptionsMenu = fl_defpup(FL_ObjWin(ob),
2022                                     _("|Spellchecker Options..."
2023                                       "|Keyboard...%l"
2024                                       "|Reconfigure"
2025                                       "|Preferences"));
2026
2027         fl_setpup_shortcut(OptionsMenu, 1, scex(_("OM|Ss#s#S")));
2028         fl_setpup_shortcut(OptionsMenu, 2, scex(_("OM|Kk#k#K")));
2029         fl_setpup_shortcut(OptionsMenu, 3, scex(_("OM|Rr#r#R")));
2030         fl_setpup_shortcut(OptionsMenu, 4, scex(_("OM|Pp#p#P")));
2031
2032         if(lyxrc.isp_command == "none") 
2033                 fl_setpup_mode(OptionsMenu, 2, FL_PUP_GREY);
2034
2035         fl_setpup_position(
2036                 men->_view->getForm()->x + ob->x,
2037                 men->_view->getForm()->y + ob->y + ob->h + 10);   
2038         int choice = fl_dopup(OptionsMenu);
2039         XFlush(fl_display);
2040
2041         // set the pseudo menu-button back
2042         fl_set_object_boxtype(ob, FL_FLAT_BOX);
2043         fl_redraw_object(ob);
2044         switch (choice){
2045         case 1: SpellCheckerOptions(); break;      
2046         case 2: men->_view->getIntl()->MenuKeymap(); break;
2047         case 3: tmpfunc->Dispatch(LFUN_RECONFIGURE); break;
2048         case 4: men->_view->getDialogs()->showPreferences(); break;
2049         default: break;
2050         }   
2051         fl_freepup(OptionsMenu);
2052 }
2053
2054
2055 void Menus::ShowBufferMenu(FL_OBJECT * ob, long)
2056 {
2057         Menus * men = static_cast<Menus*>(ob->u_vdata);
2058         
2059         // set the pseudo menu-button
2060         fl_set_object_boxtype(ob, FL_UP_BOX);
2061         fl_set_button(ob, 0);
2062         fl_redraw_object(ob);
2063    
2064         int BufferMenu = fl_newpup(FL_ObjWin(ob));
2065         vector<string> namevec = bufferlist.getFileNames();
2066         if (namevec.size() != 0) {
2067                 for (vector<string>::const_iterator cit = namevec.begin();
2068                      cit != namevec.end(); ++cit) {
2069                         string relbuf = MakeDisplayPath((*cit), 30);
2070                         fl_addtopup(BufferMenu, relbuf.c_str());
2071                 }
2072         } else {
2073                 fl_addtopup(BufferMenu, _("No Documents Open!%t"));
2074         }
2075    
2076         fl_setpup_position(
2077                 men->_view->getForm()->x + ob->x,
2078                 men->_view->getForm()->y + ob->y + ob->h + 10);   
2079         int choice = fl_dopup(BufferMenu);
2080         XFlush(fl_display);
2081
2082         // set the pseudo menu-button back
2083         fl_set_object_boxtype(ob, FL_FLAT_BOX);
2084         fl_redraw_object(ob);
2085         if (choice > 0) men->handleBufferMenu(choice - 1);
2086    
2087         fl_freepup(BufferMenu);
2088 }
2089
2090
2091 static
2092 char const * doc_files [] = {"Intro", "Tutorial", 
2093                              "UserGuide", "Extended",
2094                              "Customization", "Reference",
2095                              "FAQ", "TOC",  
2096                              "BUGS", "LyXConfig"}; 
2097
2098 void Menus::ShowHelpMenu(FL_OBJECT * ob, long)
2099 {
2100         Menus * men = static_cast<Menus*>(ob->u_vdata);
2101         LyXFunc * tmpfunc = men->_view->getLyXFunc();
2102
2103         // set the pseudo menu-button
2104         fl_set_object_boxtype(ob, FL_UP_BOX);
2105         fl_set_button(ob, 0);
2106         fl_redraw_object(ob);
2107    
2108         int HelpMenu = fl_defpup(FL_ObjWin(ob),
2109                                  _("Introduction"
2110                                    "|Tutorial"
2111                                    "|User's Guide"
2112                                    "|Extended Features"
2113                                    "|Customization"
2114                                    "|Reference Manual"
2115                                    "|FAQ"
2116                                    "|Table of Contents"
2117                                    "|Known Bugs"
2118                                    "|LaTeX Configuration%l"
2119                                    "|Copyright and Warranty..."
2120                                    "|Credits..."
2121                                    "|Version..."));
2122    
2123         fl_setpup_shortcut(HelpMenu,  1, scex(_("HM|Ii#I#i")));
2124         fl_setpup_shortcut(HelpMenu,  2, scex(_("HM|Tt#T#t")));
2125         fl_setpup_shortcut(HelpMenu,  3, scex(_("HM|Uu#U#u")));
2126         fl_setpup_shortcut(HelpMenu,  4, scex(_("HM|xX#x#X")));
2127         fl_setpup_shortcut(HelpMenu,  5, scex(_("HM|Cc#C#c")));
2128         fl_setpup_shortcut(HelpMenu,  6, scex(_("HM|Rr#R#r")));
2129         fl_setpup_shortcut(HelpMenu,  7, scex(_("HM|Ff#F#f")));
2130         fl_setpup_shortcut(HelpMenu,  8, scex(_("HM|aA#a#A")));
2131         fl_setpup_shortcut(HelpMenu,  9, scex(_("HM|Kk#K#k")));
2132         fl_setpup_shortcut(HelpMenu, 10, scex(_("HM|Ll#L#l")));
2133         fl_setpup_shortcut(HelpMenu, 11, scex(_("HM|oO#o#O")));
2134         fl_setpup_shortcut(HelpMenu, 12, scex(_("HM|eE#e#E")));
2135         fl_setpup_shortcut(HelpMenu, 13, scex(_("HM|Vv#v#V")));
2136
2137         fl_setpup_position(
2138                 men->_view->getForm()->x + ob->x,
2139                 men->_view->getForm()->y + ob->y + ob->h + 10);   
2140         int choice = fl_dopup(HelpMenu);
2141         XFlush(fl_display);
2142
2143         // set the pseudo menu-button back
2144         fl_set_object_boxtype(ob, FL_FLAT_BOX);
2145         fl_redraw_object(ob);
2146
2147         switch (choice) {
2148         case 1: case 2: case 3: case 4: case 5: 
2149         case 6: case 7: case 8: case 9: case 10:
2150                 ProhibitInput(men->currentView());
2151                 men->MenuDocu(doc_files[choice - 1]);
2152                 AllowInput(men->currentView());
2153                 break;
2154         case 11: tmpfunc->Dispatch(LFUN_HELP_COPYRIGHT); break;
2155         case 12: ShowCredits(); break;
2156         case 13:
2157                 ProhibitInput(men->currentView());
2158                 fl_show_message((string(_("LyX Version ")) + LYX_VERSION 
2159                                  + _(" of ") + LYX_RELEASE).c_str(),
2160                                 (_("Library directory: ")
2161                                  + MakeDisplayPath(system_lyxdir)).c_str(),
2162                                 (_("User directory: ") 
2163                                  + MakeDisplayPath(user_lyxdir)).c_str());
2164                 AllowInput(men->currentView());
2165                 break;
2166         }
2167         fl_freepup(HelpMenu);
2168 }
2169
2170
2171 void Menus::MenuDocu(string const & docname) 
2172 {
2173         string fname = i18nLibFileSearch("doc", docname, "lyx");
2174         if (fname.empty()) {
2175                 WriteAlert(_("Error!"),
2176                            _("Could not find requested Documentation file"),
2177                            fname);
2178                 return;
2179         }
2180         _view->getMiniBuffer()->Set(_("Opening help file"),
2181                                     MakeDisplayPath(fname), "...");
2182         currentView()->buffer(bufferlist.loadLyXFile(fname, false));
2183
2184         if (docname == "Reference")
2185                 _view->getLyXFunc()->Dispatch(LFUN_TOCVIEW);
2186 }
2187
2188
2189 void Menus::handleBufferMenu(int choice)
2190 {
2191         currentView()->buffer(bufferlist.getBuffer(choice));
2192 }