From 67898ededb895bc7027a0517b009f546d57936ed Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sun, 24 Aug 2003 16:24:19 +0000 Subject: fixed menu --- src/IconButton.cc | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/IconButton.cc b/src/IconButton.cc index a1e8cf0..1ca20b7 100644 --- a/src/IconButton.cc +++ b/src/IconButton.cc @@ -20,13 +20,15 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconButton.cc,v 1.6 2003/08/19 16:13:25 fluxgen Exp $ +// $Id: IconButton.cc,v 1.7 2003/08/24 16:24:19 fluxgen Exp $ #include "IconButton.hh" #include "FbTk/App.hh" #include "FbTk/EventManager.hh" +#include "fluxbox.hh" +#include "Screen.hh" #include "Window.hh" #include "WinClient.hh" #include "SimpleCommand.hh" @@ -40,6 +42,36 @@ #include #endif // SHAPE +namespace { + +class ShowMenu: public FbTk::Command { +public: + explicit ShowMenu(FluxboxWindow &win):m_win(win) { } + void execute() { + // get last button pos + const XEvent &event = Fluxbox::instance()->lastEvent(); + int x = event.xbutton.x_root - (m_win.menu().width() / 2); + int y = event.xbutton.y_root - (m_win.menu().height() / 2); + + if (x < 0) + x = 0; + else if (x + m_win.menu().width() > m_win.screen().width()) + x = m_win.screen().width() - m_win.menu().width(); + + if (y < 0) + y = 0; + else if (y + m_win.menu().height() > m_win.screen().height()) + y = m_win.screen().height() - m_win.menu().height(); + + m_win.menu().move(x, y); + m_win.menu().show(); + } +private: + FluxboxWindow &m_win; +}; + +} // end anonymous namespace + IconButton::IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font, FluxboxWindow &win): FbTk::TextButton(parent, font, win.winClient().title()), @@ -48,8 +80,9 @@ IconButton::IconButton(const FbTk::FbWindow &parent, const FbTk::Font &font, ExposureMask | ButtonPressMask | ButtonReleaseMask) { FbTk::RefCount focus(new FbTk::SimpleCommand(m_win, &FluxboxWindow::raiseAndFocus)); - setOnClick(focus); - + FbTk::RefCount menu(new ::ShowMenu(m_win)); + setOnClick(focus, 1); + setOnClick(menu, 3); m_win.hintSig().attach(this); FbTk::EventManager::instance()->add(*this, m_icon_window); -- cgit v0.11.2