summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-03-04 11:36:17 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-03-04 20:54:41 +0100
commite1f1def652ae9697038e4489435353d5f4e3b652 (patch)
treefe2fd2b0587402800d6fe5afa72d82f4d5612a07
parenta29c81a28892cccd5159bf6aa158fa514cf2a5b2 (diff)
use a single context menu handler at the valueset level
instead of a custom right click handler in the valueset and a separate context menu handler in its parent Change-Id: Ia174892beb72ab79a3ceda1ad8992ce90a410db9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111957 Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sd/source/ui/sidebar/MasterPagesSelector.cxx39
-rw-r--r--sd/source/ui/sidebar/MasterPagesSelector.hxx4
-rw-r--r--sd/source/ui/sidebar/PreviewValueSet.cxx18
-rw-r--r--sd/source/ui/sidebar/PreviewValueSet.hxx9
4 files changed, 27 insertions, 43 deletions
diff --git a/sd/source/ui/sidebar/MasterPagesSelector.cxx b/sd/source/ui/sidebar/MasterPagesSelector.cxx
index 9a0ca4bd2700..45f1968f4177 100644
--- a/sd/source/ui/sidebar/MasterPagesSelector.cxx
+++ b/sd/source/ui/sidebar/MasterPagesSelector.cxx
@@ -72,8 +72,8 @@ MasterPagesSelector::MasterPagesSelector (
{
mxPreviewValueSet->SetSelectHdl (
LINK(this, MasterPagesSelector, ClickHandler));
- mxPreviewValueSet->SetRightMouseClickHandler (
- LINK(this, MasterPagesSelector, RightClickHandler));
+ mxPreviewValueSet->SetContextMenuHandler (
+ LINK(this, MasterPagesSelector, ContextMenuHandler));
mxPreviewValueSet->SetStyle(mxPreviewValueSet->GetStyle() | WB_NO_DIRECTSELECT);
if ( GetDPIScaleFactor() > 1 )
@@ -167,27 +167,22 @@ IMPL_LINK_NOARG(MasterPagesSelector, ClickHandler, ValueSet*, void)
ExecuteCommand(gsDefaultClickAction);
}
-IMPL_LINK(MasterPagesSelector, RightClickHandler, const MouseEvent&, rEvent, void)
+IMPL_LINK(MasterPagesSelector, ContextMenuHandler, const Point*, pPos, void)
{
- // Here we only prepare the display of the context menu: the item under
- // the mouse is selected.
- mxPreviewValueSet->GrabFocus ();
- mxPreviewValueSet->ReleaseMouse();
- SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
- if (pViewFrame == nullptr)
- return;
-
- SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
- if (pDispatcher != nullptr)
+ if (pPos)
{
- sal_uInt16 nIndex = mxPreviewValueSet->GetItemId (rEvent.GetPosPixel());
+ // Here we only prepare the display of the context menu: on right
+ // click the item under the mouse is selected.
+ mxPreviewValueSet->GrabFocus();
+ mxPreviewValueSet->ReleaseMouse();
+
+ sal_uInt16 nIndex = mxPreviewValueSet->GetItemId(*pPos);
if (nIndex > 0)
- {
- mxPreviewValueSet->SelectItem (nIndex);
- // Now do the actual display of the context menu
- ShowContextMenu(&rEvent.GetPosPixel());
- }
+ mxPreviewValueSet->SelectItem(nIndex);
}
+
+ // Now do the actual display of the context menu
+ ShowContextMenu(pPos);
}
void MasterPagesSelector::ShowContextMenu(const Point* pPos)
@@ -221,12 +216,6 @@ void MasterPagesSelector::ShowContextMenu(const Point* pPos)
ExecuteCommand(xMenu->popup_at_rect(pParent, aRect));
}
-void MasterPagesSelector::Command (const CommandEvent& rEvent)
-{
- if (rEvent.GetCommand() == CommandEventId::ContextMenu)
- ShowContextMenu(rEvent.IsMouseEvent() ? &rEvent.GetMousePosPixel() : nullptr);
-}
-
void MasterPagesSelector::ProcessPopupMenu(weld::Menu& rMenu)
{
// Disable some entries.
diff --git a/sd/source/ui/sidebar/MasterPagesSelector.hxx b/sd/source/ui/sidebar/MasterPagesSelector.hxx
index 925fffa4f709..7ff83a92dadd 100644
--- a/sd/source/ui/sidebar/MasterPagesSelector.hxx
+++ b/sd/source/ui/sidebar/MasterPagesSelector.hxx
@@ -150,8 +150,6 @@ protected:
*/
virtual OUString GetContextMenuUIFile() const;
- virtual void Command (const CommandEvent& rEvent) override;
-
virtual void ProcessPopupMenu(weld::Menu& rMenu);
virtual void ExecuteCommand(const OString& rIdent);
@@ -163,7 +161,7 @@ private:
of an index for a token.
*/
DECL_LINK(ClickHandler, ValueSet*, void);
- DECL_LINK(RightClickHandler, const MouseEvent&, void);
+ DECL_LINK(ContextMenuHandler, const Point*, void);
DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent&, void);
void SetItem (
diff --git a/sd/source/ui/sidebar/PreviewValueSet.cxx b/sd/source/ui/sidebar/PreviewValueSet.cxx
index 7b83669ceaae..f752d60eb00d 100644
--- a/sd/source/ui/sidebar/PreviewValueSet.cxx
+++ b/sd/source/ui/sidebar/PreviewValueSet.cxx
@@ -18,7 +18,7 @@
*/
#include "PreviewValueSet.hxx"
-#include <vcl/event.hxx>
+#include <vcl/commandevent.hxx>
namespace sd::sidebar {
@@ -53,19 +53,17 @@ void PreviewValueSet::SetPreviewSize (const Size& rSize)
maPreviewSize = rSize;
}
-void PreviewValueSet::SetRightMouseClickHandler (const Link<const MouseEvent&,void>& rLink)
+void PreviewValueSet::SetContextMenuHandler(const Link<const Point*, void>& rLink)
{
- maRightMouseClickHandler = rLink;
+ maContextMenuHandler = rLink;
}
-bool PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent)
+bool PreviewValueSet::Command(const CommandEvent& rEvent)
{
- if (rEvent.IsRight())
- {
- maRightMouseClickHandler.Call(rEvent);
- return true;
- }
- return ValueSet::MouseButtonDown(rEvent);
+ if (rEvent.GetCommand() != CommandEventId::ContextMenu)
+ return ValueSet::Command(rEvent);
+ maContextMenuHandler.Call(rEvent.IsMouseEvent() ? &rEvent.GetMousePosPixel() : nullptr);
+ return true;
}
void PreviewValueSet::Resize()
diff --git a/sd/source/ui/sidebar/PreviewValueSet.hxx b/sd/source/ui/sidebar/PreviewValueSet.hxx
index c5e1f69eba1f..4ae84c60ceea 100644
--- a/sd/source/ui/sidebar/PreviewValueSet.hxx
+++ b/sd/source/ui/sidebar/PreviewValueSet.hxx
@@ -33,8 +33,10 @@ public:
virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
virtual ~PreviewValueSet() override;
- void SetRightMouseClickHandler(const Link<const MouseEvent&, void>& rLink);
+ void SetContextMenuHandler(const Link<const Point*, void>& rLink);
+
virtual void Resize() override;
+ virtual bool Command(const CommandEvent& rEvent) override;
void SetPreviewSize(const Size& rSize);
@@ -45,11 +47,8 @@ public:
*/
void Rearrange();
-protected:
- virtual bool MouseButtonDown(const MouseEvent& rEvent) override;
-
private:
- Link<const MouseEvent&, void> maRightMouseClickHandler;
+ Link<const Point*, void> maContextMenuHandler;
Size maPreviewSize;
sal_uInt16 CalculateColumnCount(int nWidth) const;