From 775ef6d809b714b6706b3d19b2ba3de5c77edf1d Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 6 Apr 2009 23:04:33 +0100 Subject: [PATCH] Fixes for MenuButton including stay depressed while menu is shown --- src/gui/widgets/menu-button.cpp | 18 ++++++++++++++---- src/gui/widgets/menu-button.hpp | 9 +++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/gui/widgets/menu-button.cpp b/src/gui/widgets/menu-button.cpp index 17ce30e60..6c78d5c67 100644 --- a/src/gui/widgets/menu-button.cpp +++ b/src/gui/widgets/menu-button.cpp @@ -36,14 +36,14 @@ const ArrowType arrowType = ARROW_DOWN; const ShadowType shadowType = SHADOW_NONE; MenuButton::MenuButton() : - Button(), + ToggleButton(), arrow(arrowType, shadowType) { setup_button(); } MenuButton::MenuButton(const StockID& stock_id) : - Button(), + ToggleButton(), image(stock_id, ICON_SIZE_MENU), caption(), arrow(arrowType, shadowType) @@ -58,8 +58,8 @@ MenuButton::MenuButton(const StockID& stock_id) : } MenuButton::MenuButton(const Glib::ustring& label, bool mnemonic) : - Button(), - caption(label), + ToggleButton(), + caption(label, mnemonic), arrow(arrowType, shadowType) { setup_button(); @@ -76,11 +76,15 @@ MenuButton::popup() { menu.popup( mem_fun(this, &MenuButton::on_menu_position), 0, gtk_get_current_event_time()); + set_active(); } void MenuButton::setup_button() { + menu.signal_deactivate().connect(mem_fun( + this, &MenuButton::on_menu_deactivated)); + arrow.set(ARROW_DOWN, SHADOW_NONE); hBox.pack_start(caption, PACK_EXPAND_WIDGET, CaptionPadding); @@ -96,6 +100,12 @@ MenuButton::on_pressed() popup(); } +void +MenuButton::on_menu_deactivated() +{ + set_active(false); +} + void MenuButton::on_menu_position(int& x, int& y, bool& push_in) { diff --git a/src/gui/widgets/menu-button.hpp b/src/gui/widgets/menu-button.hpp index deb71c8c0..0ebca1b0b 100644 --- a/src/gui/widgets/menu-button.hpp +++ b/src/gui/widgets/menu-button.hpp @@ -34,7 +34,7 @@ namespace widgets { /** * A button that display a menu when clicked on. **/ -class MenuButton : public Gtk::Button +class MenuButton : public Gtk::ToggleButton { public: @@ -86,7 +86,12 @@ protected: /** * An event handler for when the button is pressed. **/ - virtual void on_pressed(); + void on_pressed(); + + /** + * An event handler for when the menu is closed. + **/ + void on_menu_deactivated(); private: