From 4b7435e31ac821d1738eda23a6688461efcbd311 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 2 Nov 2016 17:26:03 +0000 Subject: let menu button launch arbitrary floating windows and not just menus, this is like how the gtk equivalent can launch popovers Change-Id: I53ae96aab0c51d75405dba15ab8080d7315471e3 --- vcl/source/control/menubtn.cxx | 46 +++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx index b3a01670b245..6b62d8480ed9 100644 --- a/vcl/source/control/menubtn.cxx +++ b/vcl/source/control/menubtn.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -39,20 +40,29 @@ void MenuButton::ExecuteMenu() { Activate(); - if ( mpMenu ) + if (!mpMenu && !mpFloatingWindow) + return; + + Size aSize = GetSizePixel(); + SetPressed( true ); + EndSelection(); + if (mpMenu) { - Point aPos( 0, 1 ); - Size aSize = GetSizePixel(); - Rectangle aRect( aPos, aSize ); - SetPressed( true ); - EndSelection(); - mnCurItemId = mpMenu->Execute( this, aRect, PopupMenuFlags::ExecuteDown ); - SetPressed( false ); - if ( mnCurItemId ) - { - Select(); - mnCurItemId = 0; - } + Point aPos(0, 1); + Rectangle aRect(aPos, aSize ); + mnCurItemId = mpMenu->Execute(this, aRect, PopupMenuFlags::ExecuteDown); + } + else + { + Point aPos(GetParent()->OutputToScreenPixel(GetPosPixel())); + Rectangle aRect(aPos, aSize ); + mpFloatingWindow->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus); + } + SetPressed(false); + if (mnCurItemId) + { + Select(); + mnCurItemId = 0; } } @@ -152,7 +162,7 @@ void MenuButton::Select() maSelectHdl.Call( this ); } -void MenuButton::SetPopupMenu( PopupMenu* pNewMenu ) +void MenuButton::SetPopupMenu(PopupMenu* pNewMenu) { if (pNewMenu == mpMenu) return; @@ -160,6 +170,14 @@ void MenuButton::SetPopupMenu( PopupMenu* pNewMenu ) mpMenu = pNewMenu; } +void MenuButton::SetPopover(FloatingWindow* pFloatingWindow) +{ + if (pFloatingWindow == mpFloatingWindow) + return; + + mpFloatingWindow = pFloatingWindow; +} + //class MenuToggleButton ---------------------------------------------------- MenuToggleButton::MenuToggleButton( vcl::Window* pParent, WinBits nWinBits ) -- cgit