]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Menubar_pimpl.C
Move LaTeX and VC logs to GUI-I on xforms
[lyx.git] / src / frontends / xforms / Menubar_pimpl.C
1 /* This file is part of
2 * ======================================================
3
4 *           LyX, The Document Processor
5 *        
6 *           Copyright (C) 1999 The LyX Team.
7 *
8 *======================================================*/
9
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13
14 #include <config.h>
15
16 #include <algorithm>
17 #include "support/lstrings.h"
18 #include "support/LAssert.h"
19 #include "debug.h"
20 #include "LyXAction.h"
21 #include "lyxfunc.h"
22 #include "kbmap.h"
23 #include "buffer.h"
24 #include "LyXView.h"
25 #include "MenuBackend.h"
26 #include "Menubar_pimpl.h"
27
28 using std::endl;
29 using std::vector;
30 using std::max;
31 using std::min;
32
33 typedef vector<int>::size_type size_type;
34
35 extern kb_keymap * toplevel_keymap;
36 extern LyXAction lyxaction;
37
38 // Some constants
39 static const int MENU_LABEL_SIZE = FL_NORMAL_SIZE;
40 static const int mheight = 30;
41 static const int mbheight= 22;
42 // where to place the menubar?
43 static const int yloc = (mheight - mbheight)/2; //air + bw;
44 static const int mbadd = 20; // menu button add (to width)
45 // Some space between buttons on the menubar 
46 static const int air = 2;
47 static char const * menu_tabstop = "aa";
48 static char const * default_tabstop = "aaaaaaaa";
49 // We do not want to mix position values in a menu (like the index of
50 // a submenu) with the action numbers which convey actual information.
51 // Therefore we offset all the action values by an arbitrary large
52 // constant. 
53 static const int action_offset = 1000;
54
55
56 //Defined later, used in makeMenubar().
57 extern "C"
58 void C_Menubar_Pimpl_MenuCallback(FL_OBJECT * ob, long button);
59
60 // This is used a few times below.
61 static inline
62 int string_width(string const & str) 
63 {
64         return fl_get_string_widthTAB(FL_NORMAL_STYLE, MENU_LABEL_SIZE,
65                                       str.c_str(),
66                                       static_cast<int>(str.length()));
67 }
68
69
70 Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb) 
71         : owner_(view), menubackend_(&mb), current_group_(0)
72 {
73         for (MenuBackend::const_iterator menu = menubackend_->begin();
74             menu != menubackend_->end() ; ++menu) {
75                 if (menu->menubar()) {
76                         FL_OBJECT * group = fl_bgn_group();
77                         makeMenubar(*menu);
78                         fl_end_group();
79                         fl_hide_object(group);
80                         lyxerr[Debug::GUI]
81                                 << "Menubar::Pimpl::Pimpl: "
82                                 << "creating and hiding group " << group
83                                 << " for menubar " << menu->name() << endl;
84                         menubarmap_[menu->name()] = group;
85                 }
86         }
87 }
88
89
90 Menubar::Pimpl::~Pimpl() 
91 {
92         // Should we do something here?
93 }
94
95
96 void Menubar::Pimpl::makeMenubar(Menu const &menu)
97 {
98         FL_FORM * form = owner_->getForm(); 
99         int moffset = 0;
100
101         // Create menu frame if there is non yet.
102         FL_OBJECT * frame = fl_add_frame(FL_UP_FRAME, 0, 0,
103                                          form->w, mheight, "");
104         fl_set_object_resize(frame, FL_RESIZE_ALL);
105         fl_set_object_gravity(frame, NorthWestGravity, 
106                               NorthEastGravity);
107
108         for (Menu::const_iterator i = menu.begin(); 
109              i != menu.end(); ++i) {
110                 FL_OBJECT * obj;
111                 if (i->kind() != MenuItem::Submenu) {
112                         lyxerr << "ERROR: Menubar::Pimpl::createMenubar:"
113                                 " only submenus can appear in a menubar";
114                         break;
115                 }
116                 string label = i->label();
117                 string shortcut = "#" + i->shortcut();
118                 int width = string_width(label);
119                 obj = fl_add_button(FL_MENU_BUTTON,
120                                     air + moffset, yloc,
121                                     width + mbadd,
122                                     mbheight, 
123                                     label.c_str());
124                 fl_set_object_boxtype(obj, FL_FLAT_BOX);
125                 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
126                 fl_set_object_lsize(obj, MENU_LABEL_SIZE);
127                 fl_set_object_lstyle(obj, FL_NORMAL_STYLE);
128                 fl_set_object_resize(obj, FL_RESIZE_ALL);
129                 fl_set_object_gravity(obj, NorthWestGravity, 
130                                       NorthWestGravity);
131                 moffset += obj->w + air;
132                 fl_set_object_shortcut(obj, shortcut.c_str(), 1);
133                 fl_set_object_callback(obj, C_Menubar_Pimpl_MenuCallback, 1);
134
135                 ItemInfo * iteminfo = new ItemInfo(this, 
136                                                    new MenuItem(*i), obj);
137                 buttonlist_.push_back(iteminfo);
138                 obj->u_vdata = iteminfo;
139         }
140
141 }
142
143 void Menubar::Pimpl::set(string const & menu_name) 
144 {
145         lyxerr[Debug::GUI] << "Entering Menubar::Pimpl::set " 
146                            << "for menu `" << menu_name << "'" << endl;
147
148         if (menu_name != current_menu_name_) {
149                 MenubarMap::iterator mbit = menubarmap_.find(menu_name);
150
151                 if (mbit == menubarmap_.end()) {
152                         lyxerr << "ERROR:set: Unknown menu `" << menu_name
153                                << "'" << endl;
154                         return;
155                 }
156
157                 if (current_group_) {
158                         lyxerr[Debug::GUI] << "  hiding group "
159                                            << current_group_ << endl;
160                         fl_hide_object(current_group_);
161                 }
162                 
163                 lyxerr[Debug::GUI] << "  showing group "
164                                    << mbit->second << endl;
165                 fl_show_object(mbit->second);
166                 current_menu_name_ = menu_name;
167                 current_group_ = mbit->second;
168                 lyxerr[Debug::GUI] << "Menubar::Pimpl::set: Menubar set."
169                                    << endl;
170         }
171         else
172                 lyxerr [Debug::GUI] << "Menubar::Pimpl::set: Nothing to do."
173                                     << endl;
174
175
176 void Menubar::Pimpl::openByName(string const & name)
177 {
178         if (menubackend_->getMenu(current_menu_name_).hasSubmenu(name)) {
179                 for (ButtonList::const_iterator cit = buttonlist_.begin();
180                      cit != buttonlist_.end(); ++cit) {
181                         if ((*cit)->item_->submenu() == name) {
182                                 MenuCallback((*cit)->obj_, 1);
183                                 return;
184                         }
185                 }
186         }
187         lyxerr << "Menubar::Pimpl::openByName: menu "
188                << name << " not found" << endl;
189 }
190
191
192 static inline
193 string const limit_string_length(string const & str)
194 {
195         string::size_type const max_item_length = 45;
196
197         if (str.size() > max_item_length)
198                 return str.substr(0, max_item_length - 3) + "...";
199         else
200                 return str;
201 }
202
203
204 static
205 int get_new_submenu(vector<int> & smn, Window win)
206 {
207         static size_type max_number_of_menus = 32;
208         if (smn.size() >= max_number_of_menus)
209                 max_number_of_menus =
210                     fl_setpup_maxpup(static_cast<int>(2*smn.size()));
211         int menu = fl_newpup(win);
212         smn.push_back(menu);
213         return menu;
214 }
215
216
217 size_type const max_number_of_items = 25;
218
219 static inline
220 string const fixlabel(string const & str)
221 {
222 #if FL_REVISION < 89
223         return subst(str, '%', '?');
224 #else
225         return subst(str, "%", "%%");
226 #endif
227 }
228
229
230 void add_toc2(int menu, string const & extra_label,
231               vector<int> & smn, Window win,
232               vector<Buffer::TocItem> const & toc_list,
233               size_type from, size_type to, int depth)
234 {
235         int shortcut_count = 0;
236         if (to - from <= max_number_of_items) {
237                 for (size_type i = from; i < to; ++i) {
238                         int const action = lyxaction.
239                                 getPseudoAction(LFUN_GOTO_PARAGRAPH,
240                                                 tostr(toc_list[i].par->id()));
241                         string label(4 * max(0, toc_list[i].depth - depth),' ');
242                         label += fixlabel(toc_list[i].str);
243                         label = limit_string_length(label);
244                         label += "%x" + tostr(action + action_offset);
245                         if (i == to - 1 && depth == 0)
246                                 label += extra_label;
247                         if (toc_list[i].depth == depth
248                             && ++shortcut_count <= 9) {
249                                 label += "%h";
250                                 fl_addtopup(menu, label.c_str(),
251                                             tostr(shortcut_count).c_str());
252                         } else
253                                 fl_addtopup(menu, label.c_str());
254                 }
255         } else {
256                 size_type pos = from;
257                 size_type count = 0;
258                 while (pos < to) {
259                         ++count;
260                         if (count > max_number_of_items) {
261                                 int menu2 = get_new_submenu(smn, win);
262                                 add_toc2(menu2, extra_label, smn, win,
263                                          toc_list, pos, to, depth);
264                                 string label = _("More");
265                                 label += "...%m";
266                                 if (depth == 0)
267                                         label += extra_label;
268                                 fl_addtopup(menu, label.c_str(), menu2);
269                                 break;
270                         }
271                         size_type new_pos = pos+1;
272                         while (new_pos < to &&
273                                toc_list[new_pos].depth > depth)
274                                 ++new_pos;
275
276                         int const action = lyxaction.
277                                 getPseudoAction(LFUN_GOTO_PARAGRAPH,
278                                                 tostr(toc_list[pos].par->id()));
279                         string label(4 * max(0, toc_list[pos].depth - depth), ' ');
280                         label += fixlabel(toc_list[pos].str);
281                         label = limit_string_length(label);
282                         if (new_pos == to && depth == 0)
283                                 label += extra_label;
284                         string shortcut;
285                         if (toc_list[pos].depth == depth &&
286                             ++shortcut_count <= 9)
287                                 shortcut = tostr(shortcut_count);
288
289                         if (new_pos == pos + 1) {
290                                 label += "%x" + tostr(action + action_offset);
291                                 if (!shortcut.empty()) {
292                                         label += "%h";
293                                         fl_addtopup(menu, label.c_str(),
294                                                     shortcut.c_str());
295                                 } else
296                                         fl_addtopup(menu, label.c_str());
297                         } else {
298                                 int menu2 = get_new_submenu(smn, win);
299                                 add_toc2(menu2, extra_label, smn, win,
300                                          toc_list, pos, new_pos, depth+1);
301                                 label += "%m";
302                                 if (!shortcut.empty()) {
303                                         label += "%h";
304                                         fl_addtopup(menu, label.c_str(), menu2,
305                                                     shortcut.c_str());
306                                 } else
307                                         fl_addtopup(menu, label.c_str(), menu2);
308                         }
309                         pos = new_pos;
310                 }
311         }
312 }
313
314
315 void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
316                              vector<int> & smn, Window win)
317 {
318         //xgettext:no-c-format
319         static char const * MenuNames[3] = { N_("List of Figures%m"),
320         //xgettext:no-c-format
321                                              N_("List of Tables%m"),
322         //xgettext:no-c-format
323                                              N_("List of Algorithms%m") };
324
325         vector<vector<Buffer::TocItem> > toc_list =
326                 owner_->buffer()->getTocList();
327
328         // Handle LOF/LOT/LOA
329         int max_nonempty = 0;
330         for (int i = 1; i <= 3; ++i)
331                 if (!toc_list[i].empty())
332                         max_nonempty = i;
333
334         for (int j = 1; j <= 3; ++j)
335                 if (!toc_list[j].empty()) {
336                         int menu2 = get_new_submenu(smn, win);
337                         for (size_type i = 0; i < toc_list[j].size(); ++i) {
338                                 if (i > max_number_of_items) {
339                                         fl_addtopup(menu2, ". . .%d");
340                                         break;
341                                 }
342                                 int const action = lyxaction.
343                                         getPseudoAction(LFUN_GOTO_PARAGRAPH,
344                                                         tostr(toc_list[j][i].par->id()));
345                                 string label = fixlabel(toc_list[j][i].str);
346                                 label = limit_string_length(label);
347                                 label += "%x" + tostr(action + action_offset);
348                                 fl_addtopup(menu2, label.c_str());
349                         }
350                         if (j == max_nonempty) {
351                                 string label = _(MenuNames[j - 1]);
352                                 label += "%l";
353                                 fl_addtopup(menu, label.c_str(), menu2);
354                         } else
355                                 fl_addtopup(menu, _(MenuNames[j - 1]), menu2);
356                 }
357
358         // Handle normal TOC
359         if (max_nonempty == 0 && toc_list[0].empty()) {
360                 fl_addtopup(menu, (_("No Table of Contents%i")
361                                    + extra_label).c_str());
362                 return;
363         }
364
365         add_toc2(menu, extra_label, smn, win,
366                  toc_list[0], 0, toc_list[0].size(), 0);
367
368 }
369
370 void add_references2(int menu, vector<int> & smn, Window win,
371                      vector<string> const & label_list, string const & type)
372 {
373         size_type const max_number_of_items = 25;
374         size_type const max_number_of_items2 = 20;
375         string::size_type const max_item_length = 40;
376         string::size_type const max_item_length2 = 20;
377
378         if (label_list.size() <= max_number_of_items)
379                 for (size_type i = 0; i < label_list.size(); ++i) {
380                         int const action = (type == "goto")
381                                 ? lyxaction.getPseudoAction(LFUN_REF_GOTO, 
382                                                             label_list[i])
383                                 : lyxaction.getPseudoAction(LFUN_REF_INSERT,
384                                                             type + "|++||++|"
385                                                             + label_list[i]);
386                         string label = label_list[i];
387                         if (label.size() > max_item_length)
388                                 label = label.substr(0, max_item_length-1) + "$";
389                         label += "%x" + tostr(action + action_offset);
390                         fl_addtopup(menu, label.c_str());
391                 }
392         else {
393                 size_type count = 0;
394                 for (size_type i = 0; i < label_list.size();
395                      i += max_number_of_items2) {
396                         ++count;
397                         if (count > max_number_of_items) {
398                                 fl_addtopup(menu, ". . .%d");
399                                 break;
400                         }
401                         size_type j = min(label_list.size(),
402                                           i+max_number_of_items2);
403
404                         string label;
405                         label += (label_list[i].size() > max_item_length2)
406                                 ? label_list[i].substr(0, max_item_length2-1) + "$"
407                                 : label_list[i];
408                         label += "..";
409                         label += (label_list[j-1].size() > max_item_length2)
410                                 ? label_list[j-1].substr(0, max_item_length2-1) + "$"
411                                 : label += label_list[j-1];
412
413                         int menu2 = get_new_submenu(smn, win);
414                         for (size_type k = i;  k < j; ++k) {
415                                 int const action = (type == "goto")
416                                         ? lyxaction.getPseudoAction(LFUN_REF_GOTO, 
417                                                                     label_list[k])
418                                         : lyxaction.getPseudoAction(LFUN_REF_INSERT,
419                                                                     type + "|++||++|"
420                                                                     + label_list[k]);
421                                 string label2 = label_list[k];
422                                 if (label2.size() > max_item_length)
423                                         label2 = label2.substr(0, max_item_length-1) + "$";
424                                 label2 += "%x" + tostr(action + action_offset);
425                                 fl_addtopup(menu2, label2.c_str());
426                         }
427                         label += "%m";
428                         fl_addtopup(menu, label.c_str(), menu2);
429                 }
430         }
431 }
432
433
434 void Menubar::Pimpl::add_references(int menu, string const & extra_label,
435                                     vector<int> & smn, Window win)
436 {
437         //xgettext:no-c-format
438         static char const * MenuNames[6] = { N_("Insert Reference%m"),
439         //xgettext:no-c-format
440                                              N_("Insert Page Number%m"),
441         //xgettext:no-c-format
442                                              N_("Insert vref%m"),
443         //xgettext:no-c-format
444                                              N_("Insert vpageref%m"),
445         //xgettext:no-c-format
446                                              N_("Insert Pretty Ref%m"),
447         //xgettext:no-c-format
448                                              N_("Goto Reference%m") };
449
450         int const EMPTY = 1;
451         int const SGML = 2;
452         int const READONLY = 4;
453
454         static int MenuFlags[6] = {
455                 EMPTY | READONLY,
456                 EMPTY | READONLY,
457                 EMPTY | READONLY | SGML,
458                 EMPTY | READONLY | SGML,
459                 EMPTY | READONLY | SGML,
460                 EMPTY };
461
462         static string const MenuTypes[6] = {
463                 "ref", "pageref", "vref", "vpageref", "prettyref", "goto" };
464
465         vector<string> label_list = owner_->buffer()->getLabelList();
466
467         int flag = 0;
468         if (label_list.empty())
469                 flag += EMPTY;
470         if (owner_->buffer()->isSGML())
471                 flag += SGML;
472         if (owner_->buffer()->isReadonly())
473                 flag += READONLY;
474
475         int max_nonempty = -1;
476         for (int i = 0; i < 6; ++i)
477                 if ((MenuFlags[i] & flag) == 0)
478                         max_nonempty = i;
479
480         for (int i = 0; i < 6; ++i) {
481                 if ((MenuFlags[i] & flag) == 0) {
482                         string label = _(MenuNames[i]);
483                         if (i == max_nonempty)
484                                 label += extra_label;
485                         int menu2 = get_new_submenu(smn, win);
486                         add_references2(menu2, smn, win, label_list,
487                                         MenuTypes[i]);
488                         fl_addtopup(menu, label.c_str(), menu2);
489                 }
490         }
491 }
492
493
494 int Menubar::Pimpl::create_submenu(Window win, LyXView * view, 
495                                    string const & menu_name, 
496                                    vector<int> & smn) 
497 {
498         if (!menubackend_->hasMenu(menu_name)){ 
499                 lyxerr << "ERROR:create_submenu: Unknown menu `" 
500                        << menu_name << "'" << endl;
501                 return -1;
502         }
503         Menu md = Menu();
504         menubackend_->getMenu(menu_name).expand(md, owner_->buffer());
505
506         int menu = get_new_submenu(smn, win);
507         fl_setpup_softedge(menu, true);
508         fl_setpup_bw(menu, -1);
509         lyxerr[Debug::GUI] << "Adding menu " << menu 
510                            << " in deletion list" << endl;
511
512         // Compute the size of the largest label (because xforms is
513         // not able to support shortcuts correctly...)
514         int max_width = 0;
515         string widest_label;
516         Menu::const_iterator end = md.end();
517         for (Menu::const_iterator i = md.begin(); i != end; ++i) {
518                 MenuItem const & item = (*i);
519                 if (item.kind() == MenuItem::Command) {
520                         string label = item.label() + '\t';
521                         int width = string_width(label);
522                         if (width > max_width) {
523                                 max_width = width;
524                                 widest_label = label;
525                         }
526                 }
527         }
528         lyxerr[Debug::GUI] << "max_width=" << max_width 
529                            << ", widest_label=`" << widest_label 
530                            << "'" << endl;
531
532         // Compute where to put separators
533         vector<string> extra_labels(md.size());
534         vector<string>::iterator it = extra_labels.begin();
535         vector<string>::iterator last = it;
536         for (Menu::const_iterator i = md.begin(); i != end; ++i, ++it)
537                 if (i->kind() == MenuItem::Separator)
538                         *last = "%l";
539                 else if (!i->optional() ||
540                          !(view->getLyXFunc()->getStatus(i->action()) & LyXFunc::Disabled))
541                         last = it;
542
543         it = extra_labels.begin();
544         for (Menu::const_iterator i = md.begin(); i != end; ++i, ++it) {
545                 MenuItem const & item = (*i);
546                 string & extra_label = *it;
547
548                 switch (item.kind()) {
549                 case MenuItem::Command: {
550                         LyXFunc::func_status flag = 
551                                 view->getLyXFunc()->getStatus(item.action()); 
552
553                         // handle optional entries.
554                         if (item.optional() && (flag & LyXFunc::Disabled)) {
555                                 lyxerr[Debug::GUI] 
556                                         << "Skipping optional item " 
557                                         << item.label() << endl; 
558                                 break;
559                         }
560
561                         // Get the keys bound to this action, but keep only the
562                         // first one later
563                         string const accel = toplevel_keymap->findbinding(item.action());
564                         // Build the menu label from all the info
565                         string label = item.label();
566
567                         if (!accel.empty()) {
568                                 // Try to be clever and add  just enough
569                                 // tabs to align shortcuts.
570                                 do 
571                                         label += '\t';
572                                 while (string_width(label) < max_width + 5);
573                                 label += accel.substr(1,accel.find(']') - 1);
574                         }
575                         label += "%x" + tostr(item.action() + action_offset)
576                                 + extra_label;
577                         
578                         // Modify the entry using the function status
579                         string pupmode;
580                         if (flag & (LyXFunc::Disabled | LyXFunc::Unknown))
581                                 pupmode += "%i";
582                         if (flag & LyXFunc::ToggleOn)
583                                 pupmode += "%B";
584                         if (flag & LyXFunc::ToggleOff)
585                                 pupmode += "%b";
586                         label += pupmode;
587
588                         // Finally the menu shortcut
589                         string shortcut = item.shortcut();
590
591                         if (!shortcut.empty()) {
592                                 shortcut += lowercase(shortcut[0]);
593                                 label += "%h";
594                                 fl_addtopup(menu, label.c_str(), 
595                                             shortcut.c_str());
596                         } else
597                                 fl_addtopup(menu, label.c_str());
598                         
599                         lyxerr[Debug::GUI] << "Command: \""  
600                                            << lyxaction.getActionName(item.action())
601                                            << "\", binding \"" << accel
602                                            << "\", shortcut \"" << shortcut 
603                                            << "\"" << endl;
604                         break;
605                 }
606
607                 case MenuItem::Submenu: {
608                         int submenu = create_submenu(win, view, 
609                                                      item.submenu(), smn);
610                         if (submenu == -1)
611                                 return -1;
612                         string label = item.label();
613                         label += extra_label + "%m";
614                         string shortcut = item.shortcut();
615                         if (!shortcut.empty()) {
616                                 shortcut += lowercase(shortcut[0]);
617                                 label += "%h";
618                                 fl_addtopup(menu, label.c_str(),
619                                             submenu, shortcut.c_str());
620                         }
621                         else {
622                                 fl_addtopup(menu, label.c_str(), submenu);
623                         }
624                         break;
625                 }
626
627                 case MenuItem::Separator:
628                         // already done, and if it was the first one,
629                         // we just ignore it.
630                         break;
631
632                 case MenuItem::Toc:
633                         add_toc(menu, extra_label, smn, win);
634                         break;
635
636                 case MenuItem::References:
637                         add_references(menu, extra_label, smn, win);
638                         break;
639
640                 case MenuItem::Documents: 
641                 case MenuItem::Lastfiles: 
642                 case MenuItem::ViewFormats:
643                 case MenuItem::UpdateFormats:
644                 case MenuItem::ExportFormats:
645                 case MenuItem::ImportFormats:
646                         lyxerr << "Menubar::Pimpl::create_submenu: "
647                                 "this should not happen" << endl;
648                         break;
649
650                 }
651         }
652         return menu;
653 }
654
655
656 extern "C"
657 void C_Menubar_Pimpl_MenuCallback(FL_OBJECT * ob, long button)
658 {
659         Menubar::Pimpl::MenuCallback(ob, button);
660 }
661
662
663 void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
664 {
665         ItemInfo * iteminfo = static_cast<ItemInfo *>(ob->u_vdata);
666 //      lyxerr << "MenuCallback: ItemInfo address=" << iteminfo
667 //             << "Val=(pimpl_=" << iteminfo->pimpl_
668 //             << ", item_=" << iteminfo->item_
669 //             << ", obj_=" << iteminfo->obj_ << ")" <<endl;
670
671         LyXView * view = iteminfo->pimpl_->owner_;
672         MenuItem const * item = iteminfo->item_;
673
674         if (button == 1) {
675                 // set the pseudo menu-button
676                 fl_set_object_boxtype(ob, FL_DOWN_BOX);
677                 fl_set_button(ob, 0);
678                 fl_redraw_object(ob);
679         }
680
681         // Paranoia check
682         Assert(item->kind() == MenuItem::Submenu);
683         
684         // set tabstop length
685         fl_set_tabstop(menu_tabstop);
686         vector<int> submenus;
687         int menu = iteminfo->pimpl_->
688                 create_submenu(FL_ObjWin(ob), view, 
689                                item->submenu(), submenus);
690         if (menu != -1) {
691                 // place popup
692                 fl_setpup_position(view->getForm()->x + ob->x,
693                                    view->getForm()->y + ob->y + ob->h + 10);   
694                 int choice = fl_dopup(menu);
695                 
696                 if (button == 1) {
697                                 // set the pseudo menu-button back
698                         fl_set_object_boxtype(ob, FL_FLAT_BOX);
699                         fl_redraw_object(ob);
700                 }
701
702                 // If the action value is too low, then it is not a
703                 // valid action, but something else.
704                 if (choice >= action_offset + 1) {
705                         view->getLyXFunc()->Dispatch(choice - action_offset);
706                 }
707                 else {
708                         lyxerr[Debug::GUI]
709                                 << "MenuCallback: ignoring bogus action "
710                                 << choice << endl;
711                 }
712         }
713         else 
714                 lyxerr << "Error in MenuCallback" << endl;
715         
716         std::for_each(submenus.begin(), submenus.end(), fl_freepup);
717         // restore tabstop length
718         fl_set_tabstop(default_tabstop);
719
720 }