Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3394

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/94/3394/1

Convert SfxShellStack_Impl from SfxPtrArr to std::vector

Change-Id: I1ffd615a505029242a87337c9ef42c8156c42d70
---
M sfx2/inc/sfx2/dispatch.hxx
M sfx2/source/control/dispatch.cxx
2 files changed, 49 insertions(+), 54 deletions(-)



diff --git a/sfx2/inc/sfx2/dispatch.hxx b/sfx2/inc/sfx2/dispatch.hxx
index c7aaae3..2b02a5e 100644
--- a/sfx2/inc/sfx2/dispatch.hxx
+++ b/sfx2/inc/sfx2/dispatch.hxx
@@ -28,11 +28,11 @@
 #include <sfx2/bindings.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <map>
+#include <vector>
 
 class SfxSlotServer;
 class SfxShell;
 class SfxRequest;
-class SfxShellStack_Impl;
 class SfxHintPoster;
 class SfxViewFrame;
 class SfxBindings;
@@ -41,6 +41,8 @@
 class SfxModule;
 struct SfxDispatcher_Impl;
 
+typedef std::vector<SfxShell*> SfxShellStack_Impl;
+
 namespace com
 {
     namespace sun
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index 16a83a1..26fd6f0 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>  // due to bsearch
+#include <algorithm>
 
 #include <svtools/helpopt.hxx>
 
@@ -37,7 +38,6 @@
 #include "appdata.hxx"
 #include "sfx2/sfxhelp.hxx"
 #include <sfx2/dispatch.hxx>
-#include <sfx2/minstack.hxx>
 #include <sfx2/msg.hxx>
 #include <sfx2/objface.hxx>
 #include <sfx2/bindings.hxx>
@@ -66,8 +66,6 @@
 DBG_NAME(SfxDispatcherFillState)
 
 typedef std::vector<SfxRequest*> SfxRequestPtrArray;
-
-DECL_PTRSTACK(SfxShellStack_Impl, SfxShell*, 8, 4 );
 
 struct SfxToDo_Impl
 {
@@ -552,14 +550,15 @@
     for(std::deque<SfxToDo_Impl>::reverse_iterator i = pImp->aToDoStack.rbegin(); i != 
pImp->aToDoStack.rend(); ++i)
     {
         if(i->bPush)
-            aStack.Push(i->pCluster);
+            aStack.push_back(i->pCluster);
         else
         {
             SfxShell* pPopped(NULL);
             do
             {
-                DBG_ASSERT( aStack.Count(), "popping from empty stack" );
-                pPopped = aStack.Pop();
+                DBG_ASSERT( !aStack.empty(), "popping from empty stack" );
+                pPopped = aStack.back();
+                aStack.pop_back();
             }
             while(i->bUntil && pPopped != i->pCluster);
             DBG_ASSERT(pPopped == i->pCluster, "popping unpushed SfxInterface");
@@ -568,9 +567,9 @@
 
     sal_Bool bReturn;
     if ( bDeep )
-        bReturn = aStack.Contains(&rShell);
+        bReturn = std::find(aStack.begin(), aStack.end(), &rShell) != aStack.end();
     else
-        bReturn = aStack.Top() == &rShell;
+        bReturn = aStack.back() == &rShell;
     return bReturn;
 }
 
@@ -596,15 +595,15 @@
     SFX_STACK(SfxDispatcher::GetShellLevel);
     Flush();
 
-    for ( sal_uInt16 n = 0; n < pImp->aStack.Count(); ++n )
-        if ( pImp->aStack.Top( n ) == &rShell )
+    for ( sal_uInt16 n = 0; n < pImp->aStack.size(); ++n )
+        if ( *( pImp->aStack.rbegin() + n ) == &rShell )
             return n;
     if ( pImp->pParent )
     {
         sal_uInt16 nRet = pImp->pParent->GetShellLevel(rShell);
         if ( nRet == USHRT_MAX )
             return nRet;
-        return  nRet + pImp->aStack.Count();
+        return  nRet + pImp->aStack.size();
     }
 
     return USHRT_MAX;
@@ -624,9 +623,9 @@
 */
 
 {
-    sal_uInt16 nShellCount = pImp->aStack.Count();
+    sal_uInt16 nShellCount = pImp->aStack.size();
     if ( nIdx < nShellCount )
-        return pImp->aStack.Top(nIdx);
+        return *(pImp->aStack.rbegin() + nIdx);
     else if ( pImp->pParent )
         return pImp->pParent->GetShell( nIdx - nShellCount );
     return 0;
@@ -717,8 +716,8 @@
     if ( IsAppDispatcher() )
         return;
 
-    for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
-        pImp->aStack.Top( (sal_uInt16) i )->DoActivate_Impl(pImp->pFrame, bMDI);
+    for ( int i = int(pImp->aStack.size()) - 1; i >= 0; --i )
+        (*(pImp->aStack.rbegin() + i ))->DoActivate_Impl(pImp->pFrame, bMDI);
 
     if ( bMDI && pImp->pFrame )
     {
@@ -743,8 +742,8 @@
 
 void SfxDispatcher::DoParentActivate_Impl()
 {
-    for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
-        pImp->aStack.Top( (sal_uInt16) i )->ParentActivate();
+    for ( int i = int(pImp->aStack.size()) - 1; i >= 0; --i )
+        (*(pImp->aStack.rbegin() + i ))->ParentActivate();
 }
 
 //--------------------------------------------------------------------
@@ -798,8 +797,8 @@
     if ( IsAppDispatcher() && !pSfxApp->IsDowning() )
         return;
 
-    for ( sal_uInt16 i = 0; i < pImp->aStack.Count(); ++i )
-        pImp->aStack.Top(i)->DoDeactivate_Impl(pImp->pFrame, bMDI);
+    for ( sal_uInt16 i = 0; i < pImp->aStack.size(); ++i )
+        (*(pImp->aStack.rbegin() + i))->DoDeactivate_Impl(pImp->pFrame, bMDI);
 
     sal_Bool bHidePopups = bMDI && pImp->pFrame;
     if ( pNew && pImp->pFrame )
@@ -831,8 +830,8 @@
 
 void SfxDispatcher::DoParentDeactivate_Impl()
 {
-    for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
-        pImp->aStack.Top( (sal_uInt16) i )->ParentDeactivate();
+    for ( int i = int(pImp->aStack.size()) - 1; i >= 0; --i )
+        (*(pImp->aStack.rbegin() + i))->ParentDeactivate();
 }
 
 //--------------------------------------------------------------------
@@ -869,7 +868,7 @@
     SfxSlotServer aSvr;
     if ( _FindServer(nSlot, aSvr, bModal) )
     {
-        if ( bOwnShellsOnly && aSvr.GetShellLevel() >= pImp->aStack.Count() )
+        if ( bOwnShellsOnly && aSvr.GetShellLevel() >= pImp->aStack.size() )
             return sal_False;
 
         *ppShell = GetShell(aSvr.GetShellLevel());
@@ -916,10 +915,10 @@
         SfxDispatcher *pDispat = this;
         while ( pDispat )
         {
-            sal_uInt16 nShellCount = pDispat->pImp->aStack.Count();
+            sal_uInt16 nShellCount = pDispat->pImp->aStack.size();
             for ( sal_uInt16 n=0; n<nShellCount; n++ )
             {
-                if ( &rShell == pDispat->pImp->aStack.Top(n) )
+                if ( &rShell == *(pDispat->pImp->aStack.rbegin() + n) )
                 {
                     if ( eCallMode & SFX_CALLMODE_RECORD )
                         rReq.AllowRecording( sal_True );
@@ -959,13 +958,13 @@
 {
     // Count the number of Shells on the linked Dispatcher
     Flush();
-    sal_uInt16 nTotCount = pImp->aStack.Count();
+    sal_uInt16 nTotCount = pImp->aStack.size();
     if ( pImp->pParent )
     {
         SfxDispatcher *pParent = pImp->pParent;
         while ( pParent )
         {
-            nTotCount = nTotCount + pParent->pImp->aStack.Count();
+            nTotCount = nTotCount + pParent->pImp->aStack.size();
             pParent = pParent->pImp->pParent;
         }
     }
@@ -1413,7 +1412,7 @@
     SfxShell *pStatusBarShell = NULL;
 
     SfxSlotPool* pSlotPool = &SfxSlotPool::GetSlotPool( GetFrame() );
-    sal_uInt16 nTotCount = pImp->aStack.Count();
+    sal_uInt16 nTotCount = pImp->aStack.size();
     for ( sal_uInt16 nShell = nTotCount; nShell > 0; --nShell )
     {
         SfxShell *pShell = GetShell( nShell-1 );
@@ -1589,9 +1588,9 @@
         if(i->bPush)
         {
             // Actually push
-            DBG_ASSERT(!pImp->aStack.Contains(i->pCluster),
+            DBG_ASSERT( std::find(pImp->aStack.begin(), pImp->aStack.end(), i->pCluster) != 
pImp->aStack.end(),
                        "pushed SfxShell already on stack" );
-            pImp->aStack.Push(i->pCluster);
+            pImp->aStack.push_back(i->pCluster);
             i->pCluster->SetDisableFlags(pImp->nDisableFlags);
 
             // Mark the moved shell
@@ -1604,8 +1603,9 @@
             bool bFound = false;
             do
             {
-                DBG_ASSERT( pImp->aStack.Count(), "popping from empty stack" );
-                pPopped = pImp->aStack.Pop();
+                DBG_ASSERT( !pImp->aStack.empty(), "popping from empty stack" );
+                pPopped = pImp->aStack.back();
+                pImp->aStack.pop_back();
                 pPopped->SetDisableFlags( 0 );
                 bFound = (pPopped == i->pCluster);
 
@@ -1788,7 +1788,7 @@
 {
     // Maybe the parent is also belongs to a component
     SfxDispatcher *pParent = pImp->pParent;
-    sal_uInt16 nLevels = pImp->aStack.Count();
+    sal_uInt16 nLevels = pImp->aStack.size();
     while ( pParent && pParent->pImp->pFrame )
     {
         if ( pParent->pImp->pFrame->GetFrame().HasComponent() )
@@ -1805,7 +1805,7 @@
                 break;
         }
         else
-            nLevels = nLevels + pParent->pImp->aStack.Count();
+            nLevels = nLevels + pParent->pImp->aStack.size();
 
         pParent = pParent->pImp->pParent;
     }
@@ -1868,13 +1868,13 @@
 
     // Count the number of Shells in the linked dispatchers.
     Flush();
-    sal_uInt16 nTotCount = pImp->aStack.Count();
+    sal_uInt16 nTotCount = pImp->aStack.size();
     if ( pImp->pParent )
     {
         SfxDispatcher *pParent = pImp->pParent;
         while ( pParent )
         {
-            nTotCount = nTotCount + pParent->pImp->aStack.Count();
+            nTotCount = nTotCount + pParent->pImp->aStack.size();
             pParent = pParent->pImp->pParent;
         }
     }
@@ -1916,7 +1916,7 @@
         {
             sal_Bool bRet = pImp->pParent->_FindServer( nSlot, rServer, bModal );
             rServer.SetShellLevel
-                ( rServer.GetShellLevel() + pImp->aStack.Count() );
+                ( rServer.GetShellLevel() + pImp->aStack.size() );
             return bRet;
         }
         else
@@ -1927,7 +1927,7 @@
 
     // search through all the shells of the chained dispatchers
     // from top to bottom
-    sal_uInt16 nFirstShell = pImp->bModal && !bModal ? pImp->aStack.Count() : 0;
+    sal_uInt16 nFirstShell = pImp->bModal && !bModal ? pImp->aStack.size() : 0;
     for ( sal_uInt16 i = nFirstShell; i < nTotCount; ++i )
     {
         SfxShell *pObjShell = GetShell(i);
@@ -2071,7 +2071,7 @@
     if ( rDisp.pImp->bQuiet )
     {
         nConfigId = 0;
-        nShLevel = rDisp.pImp->aStack.Count();
+        nShLevel = rDisp.pImp->aStack.size();
     }
 
     Window *pWindow = pWin ? pWin : 
rDisp.pImp->pFrame->GetFrame().GetWorkWindow_Impl()->GetWindow();
@@ -2097,7 +2097,7 @@
     if ( rDisp.pImp->bQuiet )
     {
         nConfigId = 0;
-        nShLevel = rDisp.pImp->aStack.Count();
+        nShLevel = rDisp.pImp->aStack.size();
     }
 
     Window *pWindow = pWin ? pWin : 
rDisp.pImp->pFrame->GetFrame().GetWorkWindow_Impl()->GetWindow();
@@ -2259,10 +2259,10 @@
 
 sal_Bool SfxDispatcher::IsReadOnlyShell_Impl( sal_uInt16 nShell ) const
 {
-    sal_uInt16 nShellCount = pImp->aStack.Count();
+    sal_uInt16 nShellCount = pImp->aStack.size();
     if ( nShell < nShellCount )
     {
-        SfxShell* pShell = pImp->aStack.Top( nShell );
+        SfxShell* pShell = *( pImp->aStack.rbegin() + nShell );
         if( pShell->ISA( SfxModule ) || pShell->ISA( SfxApplication ) || pShell->ISA( SfxViewFrame 
) )
             return sal_False;
         else
@@ -2273,23 +2273,16 @@
     return sal_True;
 }
 
-// A dirty trick, to get hold of the methods of the private base class
-// SfxShellStack_Impl
-class StackAccess_Impl : public SfxShellStack_Implarr_
-{};
-
 void SfxDispatcher::RemoveShell_Impl( SfxShell& rShell )
 {
     Flush();
 
-    // The cast is because SfxShellStack_Impl member has non of its own
-    StackAccess_Impl& rStack = *((StackAccess_Impl*) (&pImp->aStack));
-    sal_uInt16 nCount = rStack.Count();
+    sal_uInt16 nCount = pImp->aStack.size();
     for ( sal_uInt16 n=0; n<nCount; ++n )
     {
-        if ( rStack[n] == &rShell )
+        if ( pImp->aStack[n] == &rShell )
         {
-            rStack.Remove( n );
+            pImp->aStack.erase( pImp->aStack.begin() + n );
             rShell.SetDisableFlags( 0 );
             rShell.DoDeactivate_Impl(pImp->pFrame, sal_True);
             break;
@@ -2339,8 +2332,8 @@
 void SfxDispatcher::SetDisableFlags( sal_uInt32 nFlags )
 {
     pImp->nDisableFlags = nFlags;
-    for ( int i = int(pImp->aStack.Count()) - 1; i >= 0; --i )
-        pImp->aStack.Top( (sal_uInt16) i )->SetDisableFlags( nFlags );
+    for ( SfxShellStack_Impl::const_reverse_iterator it = pImp->aStack.rbegin(); it != 
pImp->aStack.rend(); ++it )
+        (*it)->SetDisableFlags( nFlags );
 }
 
 sal_uInt32 SfxDispatcher::GetDisableFlags() const

-- 
To view, visit https://gerrit.libreoffice.org/3394
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1ffd615a505029242a87337c9ef42c8156c42d70
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Noel Grandin <noelgrandin@gmail.com>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.