From fa9c1708194a8c6d80511c14b70efdf38bbf8c33 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 26 Sep 2000 16:16:55 +0000 Subject: [PATCH] Fix xforms menus display problems git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1043 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 10 ++ src/frontends/xforms/Menubar_pimpl.C | 159 ++++++++++----------------- src/frontends/xforms/Menubar_pimpl.h | 18 ++- src/support/lyxlib.h | 6 +- 4 files changed, 88 insertions(+), 105 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7377cb66f7..faec284fa6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2000-09-26 Jean-Marc Lasgouttes + + * src/frontends/xforms/Menubar_pimpl.C: menu buttons are now + created in the constructors in different groups. Then set() just + have to show the groups as needed. This fixes the redraw problems + (and is how the old menu code worked). + + * src/support/lyxlib.h: declare the methods as static when we do + not have namespaces. + 2000-09-26 Juergen Vigna * src/buffer.C (asciiParagraph): new function. diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C index bd5bbec2b4..4826f525c1 100644 --- a/src/frontends/xforms/Menubar_pimpl.C +++ b/src/frontends/xforms/Menubar_pimpl.C @@ -54,17 +54,9 @@ const int air = 2; char const * menu_tabstop = "aa"; char const * default_tabstop = "aaaaaaaa"; - -Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb) - : frame_(0), owner_(view), menubackend_(&mb) -{ - // Should we do something here? -} - -Menubar::Pimpl::~Pimpl() -{ - // Should we do something here? -} +//Defined later, used in makeMenubar(). +extern "C" +void C_Menubar_Pimpl_MenuCallback(FL_OBJECT * ob, long button); // This is used a few times below. inline @@ -74,92 +66,50 @@ int string_width(string const & str) str.c_str(), str.length()); } -//Defined later, used in set(). -extern "C" -void C_Menubar_Pimpl_MenuCallback(FL_OBJECT * ob, long button); -void Menubar::Pimpl::set(string const & menu_name) +Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb) + : owner_(view), menubackend_(&mb), current_group_(0) { - lyxerr[Debug::GUI] << "Entering Menubar::Pimpl::set " - << "for menu `" << menu_name << "'" << endl; - - if (menu_name == current_menu) { - lyxerr[Debug::GUI] << "Nothing to do." << endl; - return; - } - - // If the backend has not been initialized yet, we use a - // default instead. - if (menubackend_->empty()) { - lyxerr << "Menubar::Pimpl::set: menubackend is empty! " - "using default values." << endl; - MenuBackend * mb = new MenuBackend(); - mb->defaults(); - menubackend_ = mb; + for(MenuBackend::const_iterator menu = menubackend_->begin(); + menu != menubackend_->end() ; ++menu) { + if (menu->menubar()) { + FL_OBJECT * group = fl_bgn_group(); + makeMenubar(*menu); + fl_end_group(); + fl_hide_object(group); + lyxerr[Debug::GUI] + << "Menubar::Pimpl::Pimpl: " + << "creating and hiding group " << group + << " for menubar " << menu->name() << endl; + menubarmap_[menu->name()] = group; + } } +} - if (!menubackend_->hasMenu(menu_name)){ - lyxerr << "ERROR:set: Unknown menu `" << menu_name - << "'" << endl; - return; - } - Menu menu = menubackend_->getMenu(menu_name); +Menubar::Pimpl::~Pimpl() +{ + // Should we do something here? +} - if (!menu.menubar()) { - lyxerr << "Only a menubar-type object can go in a " - "toplevel menu" << endl; - return; - } - current_menu = menu_name; +void Menubar::Pimpl::makeMenubar(Menu const &menu) +{ FL_FORM * form = owner_->getForm(); int moffset = 0; - bool form_was_open, form_was_frozen; - - if (fl_current_form == form) - form_was_open = true; - else if (fl_current_form == 0) { - form_was_open = false; - fl_addto_form(form); - } - else { - lyxerr << "Something is wrong: unknown form " - << fl_current_form << " is already open" - << "(main form is " << form << ")" << endl; - return; - } - if (form->frozen) - form_was_frozen = true; - else { - form_was_frozen = false; - fl_freeze_form(form); - } - - // Delete old buttons if there are some. - for(ButtonList::const_iterator cit = buttonlist_.begin(); - cit != buttonlist_.end(); ++cit) { - if ((*cit)->obj_) { - fl_delete_object((*cit)->obj_); - fl_free_object((*cit)->obj_); - } - delete (*cit); - } - buttonlist_.clear(); // Create menu frame if there is non yet. - if (!frame_) { - frame_ = fl_add_frame(FL_UP_FRAME, 0, 0, form->w, mheight, ""); - fl_set_object_resize(frame_, FL_RESIZE_ALL); - fl_set_object_gravity(frame_, NorthWestGravity, - NorthEastGravity); - } + FL_OBJECT * frame = fl_add_frame(FL_UP_FRAME, 0, 0, + form->w, mheight, ""); + fl_set_object_resize(frame, FL_RESIZE_ALL); + fl_set_object_gravity(frame, NorthWestGravity, + NorthEastGravity); for (Menu::const_iterator i = menu.begin(); i != menu.end(); ++i) { FL_OBJECT * obj; if (i->kind() != MenuItem::Submenu) { - lyxerr << "ERROR: Menubar::Pimpl::Pimpl:" + lyxerr << "ERROR: Menubar::Pimpl::createMenubar:" " only submenus can appear in a menubar"; break; } @@ -186,28 +136,41 @@ void Menubar::Pimpl::set(string const & menu_name) new MenuItem(*i), obj); buttonlist_.push_back(iteminfo); obj->u_vdata = iteminfo; -// lyxerr << "MenuCallback: ItemInfo address=" << iteminfo -// << " Val=(pimpl_=" << iteminfo->pimpl_ -// << ", item_=" << iteminfo->item_ -// << ", obj_=" << iteminfo->obj_ << ")" <obj_) { - fl_redraw_object((*cit)->obj_); +void Menubar::Pimpl::set(string const & menu_name) +{ + lyxerr[Debug::GUI] << "Entering Menubar::Pimpl::set " + << "for menu `" << menu_name << "'" << endl; + + if (menu_name != current_menu_name_) { + MenubarMap::iterator mbit = menubarmap_.find(menu_name); + + if (mbit == menubarmap_.end()) { + lyxerr << "ERROR:set: Unknown menu `" << menu_name + << "'" << endl; + return; } - } - lyxerr[Debug::GUI] << "Menubar set." << endl; + if (current_group_) { + lyxerr[Debug::GUI] << " hiding group " + << current_group_ << endl; + fl_hide_object(current_group_); + } + + lyxerr[Debug::GUI] << " showing group " + << mbit->second << endl; + fl_show_object(mbit->second); + current_menu_name_ = menu_name; + current_group_ = mbit->second; + lyxerr[Debug::GUI] << "Menubar::Pimpl::set: Menubar set." + << endl; + } + else + lyxerr [Debug::GUI] << "Menubar::Pimpl::set: Nothing to do." + << endl; } void Menubar::Pimpl::openByName(string const & name) diff --git a/src/frontends/xforms/Menubar_pimpl.h b/src/frontends/xforms/Menubar_pimpl.h index 24c2606006..7fbc5880ef 100644 --- a/src/frontends/xforms/Menubar_pimpl.h +++ b/src/frontends/xforms/Menubar_pimpl.h @@ -19,6 +19,7 @@ #endif #include +#include #include "LString.h" #include "frontends/Menubar.h" #include "commandtags.h" @@ -26,6 +27,7 @@ class LyXView; class MenuBackend; class MenuItem; +class Menu; #include "debug.h" @@ -72,15 +74,14 @@ public: /// update the state of the menuitems void update() {} private: - /// - FL_OBJECT * frame_; + // + void makeMenubar(Menu const &menu); + /// LyXView * owner_; /// MenuBackend const * menubackend_; /// - string current_menu; - /// struct ItemInfo { /// ItemInfo(Menubar::Pimpl * p, MenuItem const * i, @@ -98,5 +99,14 @@ private: typedef std::vector ButtonList; /// ButtonList buttonlist_; + + /// + typedef std::map MenubarMap; + /// + MenubarMap menubarmap_; + /// + string current_menu_name_; + /// + FL_OBJECT * current_group_; }; #endif diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index 89e1b3c8d5..4d8deccf39 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -89,11 +89,11 @@ struct lyx { /// static int putenv(char const * str); /// - int unlink(string const & file); + static int unlink(string const & file); /// - int rmdir(string const & file); + static int rmdir(string const & file); /// - int atoi(string const & nstr); + static int atoi(string const & nstr); }; #endif // CXX_WORKING_NAMESPACES #endif -- 2.39.5