[Libreoffice-commits] core.git: sd/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Mar 4 19:55:24 UTC 2021


 sd/source/ui/sidebar/MasterPagesSelector.cxx |   39 +++++++++------------------
 sd/source/ui/sidebar/MasterPagesSelector.hxx |    4 --
 sd/source/ui/sidebar/PreviewValueSet.cxx     |   18 +++++-------
 sd/source/ui/sidebar/PreviewValueSet.hxx     |    9 ++----
 4 files changed, 27 insertions(+), 43 deletions(-)

New commits:
commit e1f1def652ae9697038e4489435353d5f4e3b652
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Mar 4 11:36:17 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Mar 4 20:54:41 2021 +0100

    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 at redhat.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

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;


More information about the Libreoffice-commits mailing list