diff --git a/src/ChangeLog b/src/ChangeLog index e0eb0352e6..a37a05a09e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2001-03-07 Lars Gullik Bjønnes + + * lyx_main.C: make toplevel_keymap a boost::scoped_ptr. + + * kbmap.[Ch]: make kb_key::table a boost::shared_ptr, remove + unneeded destructor. + + * intl.[Ch] (Intl): free the fd_form_keymap, make the fd_form_keymap + a standalone pointer again. + + * ColorHandler.[Ch]: make lyxColorHandler a boost::scoped_ptr + 2001-03-06 John Levon * Makefile.am: diff --git a/src/ColorHandler.C b/src/ColorHandler.C index 43ec7f4606..f1a9f29bd8 100644 --- a/src/ColorHandler.C +++ b/src/ColorHandler.C @@ -226,4 +226,4 @@ void LyXColorHandler::updateColor (LColor::color c) } // -LyXColorHandler * lyxColorHandler; +boost::scoped_ptr lyxColorHandler; diff --git a/src/ColorHandler.h b/src/ColorHandler.h index 44cbc9d44a..f78d3937e7 100644 --- a/src/ColorHandler.h +++ b/src/ColorHandler.h @@ -15,6 +15,8 @@ #pragma interface #endif +#include + // This is only included to provide stuff for the non-public sections #include @@ -56,6 +58,6 @@ private: }; /// -extern LyXColorHandler * lyxColorHandler; +extern boost::scoped_ptr lyxColorHandler; #endif diff --git a/src/frontends/Menubar.C b/src/frontends/Menubar.C index dbf60fabf4..e3740838f2 100644 --- a/src/frontends/Menubar.C +++ b/src/frontends/Menubar.C @@ -18,6 +18,7 @@ #endif #include "Menubar.h" +#include "MenuBackend.h" #include "Menubar_pimpl.h" Menubar::Menubar(LyXView * o, MenuBackend const & md) diff --git a/src/frontends/gnome/Menubar_pimpl.C b/src/frontends/gnome/Menubar_pimpl.C index b26d55e2e4..08a2306cbb 100644 --- a/src/frontends/gnome/Menubar_pimpl.C +++ b/src/frontends/gnome/Menubar_pimpl.C @@ -45,7 +45,7 @@ using std::endl; extern GLyxAppWin * mainAppWin; // Some constants -extern kb_keymap * toplevel_keymap; +extern boost::scoped_ptr toplevel_keymap; extern LyXAction lyxaction; extern BufferList bufferlist; extern LastFiles * lastfiles; diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 2dddf0be2a..1ab115a4e0 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,10 @@ +2001-03-07 Lars Gullik Bjønnes + + * Menubar_pimpl.h: make Pipl::ItemInfo::item_ a boost::shared_ptr, + make ButtonList contain boost::shared_ptr + + * Menubar_pimpl.C (~Pimpl): remove destructor + 2001-03-06 John Levon * Makefile.am: diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C index 6a26b0f450..85ebbff8d3 100644 --- a/src/frontends/xforms/Menubar_pimpl.C +++ b/src/frontends/xforms/Menubar_pimpl.C @@ -32,7 +32,7 @@ using std::min; typedef vector::size_type size_type; -extern kb_keymap * toplevel_keymap; +extern boost::scoped_ptr toplevel_keymap; extern LyXAction lyxaction; // Some constants @@ -87,12 +87,6 @@ Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb) } -Menubar::Pimpl::~Pimpl() -{ - // Should we do something here? -} - - void Menubar::Pimpl::makeMenubar(Menu const &menu) { FL_FORM * form = owner_->getForm(); @@ -132,10 +126,10 @@ void Menubar::Pimpl::makeMenubar(Menu const &menu) fl_set_object_shortcut(obj, shortcut.c_str(), 1); fl_set_object_callback(obj, C_Menubar_Pimpl_MenuCallback, 1); - ItemInfo * iteminfo = new ItemInfo(this, - new MenuItem(*i), obj); + boost::shared_ptr iteminfo(new ItemInfo(this, + new MenuItem(*i), obj)); buttonlist_.push_back(iteminfo); - obj->u_vdata = iteminfo; + obj->u_vdata = iteminfo.get(); } } @@ -541,7 +535,7 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button) // << ", obj_=" << iteminfo->obj_ << ")" <pimpl_->owner_; - MenuItem const * item = iteminfo->item_; + MenuItem const * item = iteminfo->item_.get(); if (button == 1) { // set the pseudo menu-button diff --git a/src/frontends/xforms/Menubar_pimpl.h b/src/frontends/xforms/Menubar_pimpl.h index 9ffce98ca3..611532d101 100644 --- a/src/frontends/xforms/Menubar_pimpl.h +++ b/src/frontends/xforms/Menubar_pimpl.h @@ -20,6 +20,7 @@ #include #include +#include #include "LString.h" #include "frontends/Menubar.h" #include "commandtags.h" @@ -37,8 +38,6 @@ public: /// Pimpl(LyXView *, MenuBackend const &); /// - ~Pimpl(); - /// void set(string const &); /// Opens a top-level submenu given its name void openByName(string const &); @@ -71,18 +70,19 @@ private: struct ItemInfo { /// ItemInfo(Menubar::Pimpl * p, MenuItem const * i, - FL_OBJECT * o) - : pimpl_(p), item_(i), obj_(o) {} + FL_OBJECT * o) + + : pimpl_(p), obj_(o) { item_.reset(i); } /// Menubar::Pimpl * pimpl_; /// - MenuItem const * item_; + boost::shared_ptr item_; /// FL_OBJECT * obj_; }; /// - typedef std::vector ButtonList; + typedef std::vector > ButtonList; /// ButtonList buttonlist_; diff --git a/src/intl.C b/src/intl.C index ce3adf1068..1dc2f58963 100644 --- a/src/intl.C +++ b/src/intl.C @@ -56,13 +56,14 @@ Intl::Intl() Intl::~Intl() { + fl_free(fd_form_keymap); r_.disconnect(); } void Intl::redraw() { - if (fd_form_keymap.get() && fd_form_keymap->KeyMap->visible) + if (fd_form_keymap && fd_form_keymap->KeyMap->visible) fl_redraw_form(fd_form_keymap->KeyMap); } @@ -110,7 +111,7 @@ void Intl::KeyMapOn(bool on) { keymapon = on; - if (!fd_form_keymap.get()) return; + if (!fd_form_keymap) return; fl_set_button(fd_form_keymap->KeyOffBtn, 0); fl_set_button(fd_form_keymap->KeyOnBtn, 0); @@ -249,7 +250,7 @@ void Intl::InitKeyMapper(bool on) Language->setcallback(LCombo, this); Language2->setcallback(LCombo, this); - fd_form_keymap.reset(create_form_KeyMap()); + fd_form_keymap = create_form_KeyMap(); // Add the Intl* pointer fd_form_keymap->AcceptChset->u_vdata = diff --git a/src/intl.h b/src/intl.h index 117d56966a..0faf1a6712 100644 --- a/src/intl.h +++ b/src/intl.h @@ -89,7 +89,7 @@ private: int otherkeymap; /// - boost::scoped_ptr fd_form_keymap; + FD_KeyMap * fd_form_keymap; /// boost::scoped_ptr Language; /// diff --git a/src/kbmap.C b/src/kbmap.C index 00462974ad..51d9ecbfdc 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -121,9 +121,9 @@ int kb_keymap::lookup(unsigned int key, unsigned int const msk0 = ((*cit).mod >> 16) & 0xffff; if ((*cit).code == key && (mod & ~msk0) == msk1) { // math found: - if ((*cit).table) { + if ((*cit).table.get()) { // this is a prefix key - set new map - seq->curmap = (*cit).table; + seq->curmap = (*cit).table.get(); return 0; } else { // final key - reset map @@ -191,13 +191,12 @@ int kb_keymap::defkey(kb_sequence * seq, int action, int idx /*= 0*/) << buf << "' is overriding old binding..." << endl; - if ((*it).table) { - delete (*it).table; - (*it).table = 0; + if ((*it).table.get()) { + (*it).table.reset(0); } (*it).action = action; return 0; - } else if (!(*it).table) { + } else if (!(*it).table.get()) { string buf; seq->print(buf, true); lyxerr << "Error: New binding for '" << buf @@ -217,33 +216,15 @@ int kb_keymap::defkey(kb_sequence * seq, int action, int idx /*= 0*/) (*newone).mod = modmsk; if (idx + 1 == seq->length) { (*newone).action = action; - (*newone).table = 0; + (*newone).table.reset(0); return 0; } else { - (*newone).table = new kb_keymap; + (*newone).table.reset(new kb_keymap); return (*newone).table->defkey(seq, action, idx + 1); } } -/* ---F+------------------------------------------------------------------ *\ - Function : kb_keymap::~kb_keymap - Called by : [destructor] - Purpose : free keymap and its descendents - Parameters: none - Returns : nothing -\* ---F------------------------------------------------------------------- */ - -kb_keymap::~kb_keymap() -{ - // This could be done by a destructor in kb_key. - Table::iterator end = table.end(); - for (Table::iterator it = table.begin(); it != end; ++it) { - delete (*it).table; - } -} - - string const kb_keymap::keyname(kb_key const & k) { string buf; @@ -261,7 +242,7 @@ string const kb_keymap::findbinding(int act) const Table::const_iterator end = table.end(); for (Table::const_iterator cit = table.begin(); cit != end; ++cit) { - if ((*cit).table) { + if ((*cit).table.get()) { string suffix = (*cit).table->findbinding(act); suffix = strip(suffix, ' '); suffix = strip(suffix, ']'); diff --git a/src/kbmap.h b/src/kbmap.h index 015bce9c37..3bc02f6a52 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -14,6 +14,7 @@ #endif #include +#include #include "LString.h" @@ -22,9 +23,6 @@ class kb_sequence; /// Defines key maps and actions for key sequences class kb_keymap { public: - /// - ~kb_keymap(); - /** Bind a key-sequence to an action. Returns 0 on success. Otherwise, position in string where error occured. */ @@ -49,7 +47,7 @@ private: unsigned int mod; /// Keymap for prefix keys - kb_keymap * table; + boost::shared_ptr table; /// Action for !prefix keys int action; diff --git a/src/lyx_gui.C b/src/lyx_gui.C index eee229e9bc..306d8749e9 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -151,7 +151,7 @@ LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI) ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(fl_get_display())) - height; // Initialize the LyXColorHandler - lyxColorHandler = new LyXColorHandler; + lyxColorHandler.reset(new LyXColorHandler); } diff --git a/src/lyx_main.C b/src/lyx_main.C index 0a02da911d..82dd64cbf9 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -64,7 +64,7 @@ LyXServer * lyxserver = 0; bool finished = false; // flag, that we are quitting the program // convenient to have it here. -kb_keymap * toplevel_keymap; +boost::scoped_ptr toplevel_keymap; LyX::LyX(int * argc, char * argv[]) @@ -78,8 +78,8 @@ LyX::LyX(int * argc, char * argv[]) bool gui = easyParse(argc, argv); // Global bindings (this must be done as early as possible.) (Lgb) - toplevel_keymap = new kb_keymap; - defaultKeyBindings(toplevel_keymap); + toplevel_keymap.reset(new kb_keymap); + defaultKeyBindings(toplevel_keymap.get()); // Make the GUI object, and let it take care of the // command line arguments that concerns it. @@ -432,7 +432,7 @@ void LyX::init(int */*argc*/, char **argv, bool gui) // Bind the X dead keys to the corresponding LyX functions if // necessary. if (lyxrc.override_x_deadkeys) - deadKeyBindings(toplevel_keymap); + deadKeyBindings(toplevel_keymap.get()); if (lyxerr.debugging(Debug::LYXRC)) { lyxrc.print(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index ce6ff5a939..6a031f73b1 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -102,7 +102,7 @@ extern int greek_kb_flag; extern bool selection_possible; extern void MenuSendto(); -extern kb_keymap * toplevel_keymap; +extern boost::scoped_ptr toplevel_keymap; extern void show_symbols_form(LyXFunc *); @@ -1519,8 +1519,8 @@ exit_with_message: void LyXFunc::setupLocalKeymap() { - keyseq.stdmap = keyseq.curmap = toplevel_keymap; - cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap; + keyseq.stdmap = keyseq.curmap = toplevel_keymap.get(); + cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get(); } diff --git a/src/lyxrc.C b/src/lyxrc.C index bfdb1ad4ce..b025554e31 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -40,7 +40,7 @@ using std::endl; using std::vector; extern LyXAction lyxaction; -extern kb_keymap * toplevel_keymap; +extern boost::scoped_ptr toplevel_keymap; static diff --git a/src/screen.C b/src/screen.C index b0b5390e63..51dc3eb9d0 100644 --- a/src/screen.C +++ b/src/screen.C @@ -65,7 +65,7 @@ LyXScreen::LyXScreen(WorkArea & o) void LyXScreen::setCursorColor() { - if (!lyxColorHandler) return; + if (!lyxColorHandler.get()) return; GC gc = lyxColorHandler->getGCForeground(LColor::cursor);