let menu button launch arbitrary floating windows

and not just menus, this is like how the gtk equivalent can launch popovers

Change-Id: I53ae96aab0c51d75405dba15ab8080d7315471e3
This commit is contained in:
Caolán McNamara
2016-11-02 17:26:03 +00:00
parent 4f6028ad76
commit 4b7435e31a
2 changed files with 38 additions and 15 deletions

View File

@@ -23,6 +23,7 @@
#include <vcl/button.hxx>
#include <vcl/dllapi.h>
class FloatingWindow;
class Timer;
class PopupMenu;
class VclBuilder;
@@ -35,6 +36,7 @@ private:
Timer* mpMenuTimer;
VclPtr<PopupMenu> mpMenu;
VclPtr<FloatingWindow> mpFloatingWindow;
sal_uInt16 mnCurItemId;
bool mbDelayMenu;
Link<MenuButton*,void> maActivateHdl;
@@ -73,6 +75,9 @@ public:
void SetPopupMenu(PopupMenu* pNewMenu);
PopupMenu* GetPopupMenu() const { return mpMenu; }
void SetPopover(FloatingWindow* pFloatingWindow);
FloatingWindow* GetPopover() const { return mpFloatingWindow; }
sal_uInt16 GetCurItemId() const { return mnCurItemId; }
OString GetCurItemIdent() const;

View File

@@ -20,6 +20,7 @@
#include <tools/rc.h>
#include <vcl/decoview.hxx>
#include <vcl/event.hxx>
#include <vcl/floatwin.hxx>
#include <vcl/menu.hxx>
#include <vcl/timer.hxx>
#include <vcl/menubtn.hxx>
@@ -39,14 +40,24 @@ void MenuButton::ExecuteMenu()
{
Activate();
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);
}
else
{
Point aPos(GetParent()->OutputToScreenPixel(GetPosPixel()));
Rectangle aRect(aPos, aSize );
mpFloatingWindow->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus);
}
SetPressed(false);
if (mnCurItemId)
{
@@ -54,7 +65,6 @@ void MenuButton::ExecuteMenu()
mnCurItemId = 0;
}
}
}
OString MenuButton::GetCurItemIdent() const
{
@@ -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 )