include/vcl/menu.hxx       |    1 
 vcl/source/window/menu.cxx |   51 ++++++++++++++++++---------------------------
 2 files changed, 21 insertions(+), 31 deletions(-)

New commits:
commit d4903bb537f8645e756f8621c26685f2fddb6217
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Dec 2 13:25:05 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Dec 2 19:27:23 2024 +0100

    vcl: Merge PopupMenu::PrepareRun into PopupMenu::ImplExecute
    
    Merge PopupMenu::PrepareRun into its only caller
    which makes it a little easier to follow the logic
    and track what's assigned to what local variable than
    when using many out params.
    
    Change-Id: Id967040a579e3f6532afa523215049bdb68f1cd0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177694
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx
index 0f6a0c414926..b60cdc42b39b 100644
--- a/include/vcl/menu.hxx
+++ b/include/vcl/menu.hxx
@@ -499,7 +499,6 @@ class VCL_DLLPUBLIC PopupMenu final : public Menu
 
 private:
     SAL_DLLPRIVATE MenuFloatingWindow * ImplGetFloatingWindow() const;
-    SAL_DLLPRIVATE bool PrepareRun(const VclPtr<vcl::Window>& pParentWin, 
tools::Rectangle& rRect, FloatWinPopupFlags& nPopupModeFlags, Menu* pSFrom, 
bool& bRealExecute, VclPtr<MenuFloatingWindow>&);
     SAL_DLLPRIVATE bool Run(const VclPtr<MenuFloatingWindow>&, bool 
bRealExecute, bool bPreSelectFirst, FloatWinPopupFlags nPopupModeFlags, Menu* 
pSFrom, const tools::Rectangle& rRect);
     SAL_DLLPRIVATE void FinishRun(const VclPtr<MenuFloatingWindow>&, const 
VclPtr<vcl::Window>& pParentWin, bool bRealExecute, bool bIsNativeMenu);
     SAL_DLLPRIVATE sal_uInt16 ImplExecute(const VclPtr<vcl::Window>& 
pParentWin, const tools::Rectangle& rRect, FloatWinPopupFlags nPopupModeFlags, 
Menu* pSFrom, bool bPreSelectFirst);
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 300ecf535980..63597fc9dee4 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -2853,14 +2853,16 @@ void PopupMenu::ImplFlushPendingSelect()
     }
 }
 
-bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& pParentWin, 
tools::Rectangle& rRect,
-                           FloatWinPopupFlags& nPopupModeFlags, Menu* pSFrom,
-                           bool& bRealExecute, VclPtr<MenuFloatingWindow>& 
pWin)
+sal_uInt16 PopupMenu::ImplExecute(const VclPtr<vcl::Window>& pParentWin, const 
tools::Rectangle& rRect,
+                                  FloatWinPopupFlags nPopupModeFlags, Menu* 
pSFrom, bool bPreSelectFirst)
 {
-    bRealExecute = false;
+    // tdf#126054 hold this until after function completes
+    VclPtr<PopupMenu> xThis(this);
+
+    bool bRealExecute = false;
     const sal_uInt16 nItemCount = GetItemCount();
     if (!pSFrom && (vcl::IsInPopupMenuExecute() || !nItemCount))
-        return false;
+        return 0;
 
     mpLayoutData.reset();
 
@@ -2887,7 +2889,8 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& 
pParentWin, tools::Rectang
     }
 
     SAL_WARN_IF(GetWindow(), "vcl", "Win?!");
-    rRect.SetPos(pParentWin->OutputToScreenPixel(rRect.TopLeft()));
+    tools::Rectangle aRect(rRect);
+    aRect.SetPos(pParentWin->OutputToScreenPixel(aRect.TopLeft()));
 
     nPopupModeFlags |= FloatWinPopupFlags::NoKeyClose | 
FloatWinPopupFlags::AllMouseButtonClose | FloatWinPopupFlags::GrabFocus;
     if (bRealExecute)
@@ -2901,13 +2904,13 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& 
pParentWin, tools::Rectang
     SetMenuFlags(nMenuFlagsSaved);
 
     if (pParentWin->isDisposed())
-        return false;
+        return 0;
 
     if ( bCanceled || bKilled )
-        return false;
+        return 0;
 
     if (!nItemCount)
-        return false;
+        return 0;
 
     // The flag MenuFlags::HideDisabledEntries is inherited.
     if ( pSFrom )
@@ -2934,7 +2937,7 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& 
pParentWin, tools::Rectang
         ImplCallEventListeners(VclEventId::MenuSubmenuChanged, nPos);
     }
 
-    pWin = VclPtrInstance<MenuFloatingWindow>(this, pParentWin, WB_BORDER | 
WB_SYSTEMWINDOW);
+    VclPtr<MenuFloatingWindow> pWin = VclPtrInstance<MenuFloatingWindow>(this, 
pParentWin, WB_BORDER | WB_SYSTEMWINDOW);
     if (comphelper::LibreOfficeKit::isActive() && get_id() == 
"editviewspellmenu")
     {
         VclPtr<vcl::Window> xNotifierParent = 
pParentWin->GetParentWithLOKNotifier();
@@ -2956,9 +2959,9 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& 
pParentWin, tools::Rectang
         vcl::Window* pDeskW = m_pWindow->GetWindow( GetWindowType::RealParent 
);
         if( ! pDeskW )
             pDeskW = m_pWindow;
-        AbsoluteScreenPixelPoint 
aDesktopTL(pDeskW->OutputToAbsoluteScreenPixel(rRect.TopLeft()));
+        AbsoluteScreenPixelPoint 
aDesktopTL(pDeskW->OutputToAbsoluteScreenPixel(aRect.TopLeft()));
         aDesktopRect = Application::GetScreenPosSizePixel(
-            
Application::GetBestScreen(AbsoluteScreenPixelRectangle(aDesktopTL, 
rRect.GetSize())));
+            
Application::GetBestScreen(AbsoluteScreenPixelRectangle(aDesktopTL, 
aRect.GetSize())));
     }
 
     tools::Long nMaxHeight = aDesktopRect.GetHeight();
@@ -2973,8 +2976,8 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& 
pParentWin, tools::Rectang
         if ( pRef->GetParent() )
             pRef = pRef->GetParent();
 
-        AbsoluteScreenPixelRectangle 
devRect(pRef->OutputToAbsoluteScreenPixel(rRect.TopLeft()),
-                                 
pRef->OutputToAbsoluteScreenPixel(rRect.BottomRight()));
+        AbsoluteScreenPixelRectangle 
devRect(pRef->OutputToAbsoluteScreenPixel(aRect.TopLeft()),
+                                             
pRef->OutputToAbsoluteScreenPixel(aRect.BottomRight()));
 
         tools::Long nHeightAbove = devRect.Top() - aDesktopRect.Top();
         tools::Long nHeightBelow = aDesktopRect.Bottom() - devRect.Bottom();
@@ -3003,7 +3006,10 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& 
pParentWin, tools::Rectang
 
     pWin->SetFocusId( xFocusId );
     pWin->SetOutputSizePixel( aSz );
-    return true;
+
+    const bool bNative = Run(pWin, bRealExecute, bPreSelectFirst, 
nPopupModeFlags, pSFrom, aRect);
+    FinishRun(pWin, pParentWin, bRealExecute, bNative);
+    return nSelectedId;
 }
 
 bool PopupMenu::Run(const VclPtr<MenuFloatingWindow>& pWin, const bool 
bRealExecute, const bool bPreSelectFirst,
@@ -3081,21 +3087,6 @@ void PopupMenu::FinishRun(const 
VclPtr<MenuFloatingWindow>& pWin, const VclPtr<v
     ImplFlushPendingSelect();
 }
 
-sal_uInt16 PopupMenu::ImplExecute(const VclPtr<vcl::Window>& pParentWin, const 
tools::Rectangle& rRect,
-                                  FloatWinPopupFlags nPopupModeFlags, Menu* 
pSFrom, bool bPreSelectFirst)
-{
-    // tdf#126054 hold this until after function completes
-    VclPtr<PopupMenu> xThis(this);
-    bool bRealExecute = false;
-    tools::Rectangle aRect(rRect);
-    VclPtr<MenuFloatingWindow> pWin;
-    if (!PrepareRun(pParentWin, aRect, nPopupModeFlags, pSFrom, bRealExecute, 
pWin))
-        return 0;
-    const bool bNative = Run(pWin, bRealExecute, bPreSelectFirst, 
nPopupModeFlags, pSFrom, aRect);
-    FinishRun(pWin, pParentWin, bRealExecute, bNative);
-    return nSelectedId;
-}
-
 sal_uInt16 PopupMenu::ImplCalcVisEntries( tools::Long nMaxHeight, sal_uInt16 
nStartEntry, sal_uInt16* pLastVisible ) const
 {
     nMaxHeight -= 2 * ImplGetFloatingWindow()->GetScrollerHeight();

Reply via email to