sd/source/ui/view/ViewShellManager.cxx |   35 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 18 deletions(-)

New commits:
commit 34a63a22df48ee5aef35fde502aa59d5207fbdd9
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Nov 30 18:02:09 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Nov 30 15:25:05 2024 +0100

    sd: simplify UpdateShellStack
    
    Change-Id: I10a21d1d62afa6118b665c031cb6d70b1bc006ba
    Co-authored-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177497
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sd/source/ui/view/ViewShellManager.cxx 
b/sd/source/ui/view/ViewShellManager.cxx
index c2026022139c..7f150b3d4f1c 100644
--- a/sd/source/ui/view/ViewShellManager.cxx
+++ b/sd/source/ui/view/ViewShellManager.cxx
@@ -126,7 +126,7 @@ public:
     /** Remove all shells from the SFX stack above and including the given
         shell.
     */
-    void TakeShellsFromStack (const SfxShell* pShell);
+    void TakeShellsFromStack (const SfxShell& rShell);
 
     class UpdateLock
     {
@@ -466,12 +466,14 @@ void 
ViewShellManager::Implementation::DeactivateViewShell (const ViewShell& rSh
     if (iShell == maActiveViewShells.end())
         return;
 
+    // iShell points to a ShellDescriptor with mpShell pointing to rShell
+
     UpdateLock aLocker (*this);
 
     ShellDescriptor aDescriptor(*iShell);
-    
mrBase.GetDocShell()->Disconnect(dynamic_cast<ViewShell*>(aDescriptor.mpShell));
+    mrBase.GetDocShell()->Disconnect(&rShell);
     maActiveViewShells.erase(iShell);
-    TakeShellsFromStack(aDescriptor.mpShell);
+    TakeShellsFromStack(rShell);
 
     // Deactivate sub shells.
     SubShellList::iterator iList (maActiveSubShells.find(&rShell));
@@ -516,12 +518,14 @@ void ViewShellManager::Implementation::DeactivateShell 
(const SfxShell& rShell)
     if (iShell == maActiveViewShells.end())
         return;
 
+    // iShell points to a ShellDescriptor with mpShell pointing to rShell
+
     UpdateLock aLocker (*this);
 
     ShellDescriptor aDescriptor(*iShell);
-    
mrBase.GetDocShell()->Disconnect(dynamic_cast<ViewShell*>(aDescriptor.mpShell));
+    mrBase.GetDocShell()->Disconnect(dynamic_cast<const ViewShell*>(&rShell));
     maActiveViewShells.erase(iShell);
-    TakeShellsFromStack(aDescriptor.mpShell);
+    TakeShellsFromStack(rShell);
 
     // Deactivate sub shells.
     SubShellList::iterator iList (maActiveSubShells.find(&rShell));
@@ -589,7 +593,7 @@ void ViewShellManager::Implementation::DeactivateSubShell (
     // Remove the sub shell from both the internal structure as well as the
     // SFX shell stack above and including the sub shell.
     rList.erase(iShell);
-    TakeShellsFromStack(pShell);
+    TakeShellsFromStack(*pShell);
 
     DestroySubShell(aDescriptor);
 }
@@ -656,7 +660,7 @@ void ViewShellManager::Implementation::MoveToTop (const 
SfxShell& rShell)
 
         ShellDescriptor aDescriptor(*iShell);
 
-        TakeShellsFromStack(&rShell);
+        TakeShellsFromStack(rShell);
         maActiveViewShells.erase(iShell);
 
         maActiveViewShells.insert(maActiveViewShells.begin(), aDescriptor);
@@ -834,7 +838,7 @@ void ViewShellManager::Implementation::UpdateShellStack()
 #endif
 }
 
-void ViewShellManager::Implementation::TakeShellsFromStack (const SfxShell* 
pShell)
+void ViewShellManager::Implementation::TakeShellsFromStack (const SfxShell& 
rShell)
 {
     ::osl::MutexGuard aGuard (maMutex);
 
@@ -856,25 +860,20 @@ void 
ViewShellManager::Implementation::TakeShellsFromStack (const SfxShell* pShe
         SfxShell* pShellOnStack = mrBase.GetSubShell(nIndex);
         if (pShellOnStack == nullptr)
         {
-            // Set pShell to NULL to indicate the following code that the
-            // shell is not on the stack.
-            pShell = nullptr;
-            break;
+            // the shell is not on the stack.
+            return;
         }
-        else if (pShellOnStack == pShell)
+        else if (pShellOnStack == &rShell)
             break;
     }
 
-    if (pShell == nullptr)
-        return;
-
     // 1. Deactivate our shells on the stack before they are removed so
     // that during the Deactivation() calls the stack is still intact.
     for (sal_uInt16 nIndex=0; true; nIndex++)
     {
         SfxShell* pShellOnStack = mrBase.GetSubShell(nIndex);
         Deactivate(pShellOnStack);
-        if (pShellOnStack == pShell)
+        if (pShellOnStack == &rShell)
             break;
     }
 
@@ -884,7 +883,7 @@ void ViewShellManager::Implementation::TakeShellsFromStack 
(const SfxShell* pShe
         SfxShell* pShellOnStack = mrBase.GetSubShell(0);
         SAL_INFO("sd.view", __func__ << "removing shell " << pShellOnStack << 
" from stack");
         mrBase.RemoveSubShell(pShellOnStack);
-        if (pShellOnStack == pShell)
+        if (pShellOnStack == &rShell)
             break;
     }
 

Reply via email to