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