From ef9565efd8431eed3f561154c58765d5a77be90a Mon Sep 17 00:00:00 2001 From: rathnor Date: Sun, 29 Aug 2004 12:35:29 +0000 Subject: fix crash bug when windowmenu doesn't include extramenus improve checking of existence/success of loading windowmenu file --- ChangeLog | 6 ++++++ src/FbTk/Menu.hh | 7 ++++--- src/MenuCreator.cc | 16 +++++++++------- src/MenuCreator.hh | 4 ++-- src/Window.cc | 18 +++++++++++++----- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 033a6ad..fa6d44a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ (Format: Year/Month/Day) Changes for 0.9.10: *04/08/29: + * Fix crash when extramenus not attached to windowmenu (Simon) + - and add checking that windowmenu file exists and sorta parses + Window.cc FbTk/Menu.hh MenuCreator.hh/cc + * Tweak toolbar size/position (esp when 100% width) (Simon) + - and fix menu size bug when initialising with no style + Toolbar.cc FbTk/MenuTheme.cc * Add back Workspace actions with deprecated message (Simon) - need transition time, remove when 1.0 has been widely used for a while FbCommandFactory.cc diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 57894b8..d5f6b83 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Menu.hh,v 1.38 2004/08/03 21:25:51 fluxgen Exp $ +// $Id: Menu.hh,v 1.39 2004/08/29 12:35:29 rathnor Exp $ #ifndef FBTK_MENU_HH #define FBTK_MENU_HH @@ -162,6 +162,9 @@ public: /// @return true if index is valid inline bool validIndex(int index) const { return (index < static_cast(numberOfItems()) && index >= 0); } + inline Menu *parent() { return m_parent; } + inline const Menu *parent() const { return m_parent; } + protected: inline void setTitleVisibility(bool b) { @@ -179,8 +182,6 @@ protected: unsigned int width= 0, unsigned int height= 0); virtual void redrawTitle(); virtual void internal_hide(); - inline Menu *parent() { return m_parent; } - inline const Menu *parent() const { return m_parent; } void update(FbTk::Subject *); void renderTransp(int x, int y, diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 374411d..9c3cb4f 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: MenuCreator.cc,v 1.11 2004/08/26 18:26:39 akir Exp $ +// $Id: MenuCreator.cc,v 1.12 2004/08/29 12:35:29 rathnor Exp $ #include "MenuCreator.hh" @@ -322,36 +322,38 @@ FbTk::Menu *MenuCreator::createFromFile(const std::string &filename, int screen_ } -void MenuCreator::createFromFile(const std::string &filename, +bool MenuCreator::createFromFile(const std::string &filename, FbTk::Menu &inject_into) { std::string real_filename = FbTk::StringUtil::expandFilename(filename); FbMenuParser parser(real_filename); if (!parser.isLoaded()) - return; + return false; std::string label; if (!getStart(parser, label)) - return; + return false; parseMenu(parser, inject_into); + return true; } -void MenuCreator::createFromFile(const std::string &filename, +bool MenuCreator::createFromFile(const std::string &filename, FbTk::Menu &inject_into, FluxboxWindow &win) { std::string real_filename = FbTk::StringUtil::expandFilename(filename); FbMenuParser parser(real_filename); if (!parser.isLoaded()) - return; + return false; std::string label; if (!getStart(parser, label)) - return; + return false; parseWindowMenu(parser, inject_into, win); + return true; } diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index d9625f3..f916bfd 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh @@ -36,8 +36,8 @@ public: static FbTk::Menu *createMenu(const std::string &label, int screen_num); static FbTk::Menu *createFromFile(const std::string &filename, int screen_num); static FbTk::Menu *createMenuType(const std::string &label, int screen_num); - static void createFromFile(const std::string &filename, FbTk::Menu &inject_into); - static void createFromFile(const std::string &filename, FbTk::Menu &inject_into, + static bool createFromFile(const std::string &filename, FbTk::Menu &inject_into); + static bool createFromFile(const std::string &filename, FbTk::Menu &inject_into, FluxboxWindow &win); static bool createWindowMenuItem(const std::string &type, const std::string &label, FbTk::Menu &inject_into, FluxboxWindow &win); diff --git a/src/Window.cc b/src/Window.cc index 2528a8c..c3f6190 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Window.cc,v 1.296 2004/08/13 12:39:02 fluxgen Exp $ +// $Id: Window.cc,v 1.297 2004/08/29 12:35:29 rathnor Exp $ #include "Window.hh" @@ -350,7 +350,14 @@ FluxboxWindow::~FluxboxWindow() { // still in the menu // (They need to be internal for most of the time so that if we // rebuild the menu, then they won't be removed. - mit->second->setInternalMenu(false); + if (mit->second->parent() == 0) { + // not attached to our windowmenu + // so we clean it up + delete mit->second; + } else { + // let the parent clean it up + mit->second->setInternalMenu(false); + } } #ifdef DEBUG @@ -3562,9 +3569,10 @@ void FluxboxWindow::setupMenu() { menu().removeAll(); // clear old items menu().disableTitle(); // not titlebar - if (!screen().windowMenuFilename().empty()) { - MenuCreator::createFromFile(screen().windowMenuFilename(), menu(), *this); - } else { + if (screen().windowMenuFilename().empty() || + ! MenuCreator::createFromFile(screen().windowMenuFilename(), menu(), *this)) + + { MenuCreator::createWindowMenuItem("shade", "", menu(), *this); MenuCreator::createWindowMenuItem("stick", "", menu(), *this); MenuCreator::createWindowMenuItem("maximize", "", menu(), *this); -- cgit v0.11.2