[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - sc/source

Marco Cecchetti marco.cecchetti at collabora.com
Sun Oct 9 20:53:23 UTC 2016


 sc/source/ui/inc/tabview.hxx   |   60 ++++++++++++
 sc/source/ui/view/tabview.cxx  |    1 
 sc/source/ui/view/tabview3.cxx |  197 ++++++++++++++++-------------------------
 sc/source/ui/view/tabvwsh4.cxx |   12 --
 4 files changed, 141 insertions(+), 129 deletions(-)

New commits:
commit 5fa5fff0ac058fbd081bf010a3680207d3238e2c
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Thu Oct 6 23:29:40 2016 +0200

    LOK: Calc: parallel cell editing: small code improvements
    
    - A single instance of ScExtraEditViewManager is created per
    ScTabView;
    
    - On destruction a counter is checked in order to be sure that all
    created edit views have been destroyed.
    
    - BoolLock has been replaced by comphelper::FlagRestorationGuard
    
    Change-Id: I6b0293c4d2e9151dff8b13601d0074c4b2567b25
    Reviewed-on: https://gerrit.libreoffice.org/29582
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>
    Tested-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index d2cc7fc..01e097a 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -80,6 +80,64 @@ public:
     virtual void    DataChanged( const DataChangedEvent& rDCEvt ) override;
 };
 
+class ScExtraEditViewManager
+{
+public:
+    ScExtraEditViewManager(ScTabViewShell* pThisViewShell, VclPtr<ScGridWindow>* pGridWin)
+        : mpThisViewShell(pThisViewShell)
+        , mpGridWin(pGridWin)
+        , mpOtherEditView(nullptr)
+        , mpOtherEngine(nullptr)
+        , maSameEditViewChecker()
+        , nTotalActiveEditViews(0)
+    {}
+
+    ~ScExtraEditViewManager();
+
+    void Add(SfxViewShell* pViewShell, ScSplitPos eWhich)
+    {
+        Apply(pViewShell, eWhich, &ScExtraEditViewManager::Adder);
+    }
+
+    void Remove(SfxViewShell* pViewShell, ScSplitPos eWhich)
+    {
+        Apply(pViewShell, eWhich, &ScExtraEditViewManager::Remover);
+    }
+
+private:
+    class SameEditViewChecker
+    {
+    public:
+        SameEditViewChecker()
+            : mpOtherEditView(nullptr)
+            , mpWindow(nullptr)
+        {}
+        void SetEditView(EditView* pOtherEditView) { mpOtherEditView = pOtherEditView; }
+        void SetWindow(ScGridWindow* pWindow) { mpWindow = pWindow; }
+        bool operator() (const EditView* pView) const;
+
+    private:
+        EditView* mpOtherEditView;
+        ScGridWindow* mpWindow;
+    };
+
+private:
+    typedef void (ScExtraEditViewManager::* FuncType)(ScGridWindow* );
+
+    void Apply(SfxViewShell* pViewShell, ScSplitPos eWhich, FuncType fHandler);
+    void Adder(ScGridWindow* pWin);
+    void Remover(ScGridWindow* pWin);
+
+private:
+    ScTabViewShell* mpThisViewShell;
+    VclPtr<ScGridWindow>* mpGridWin;
+    EditView* mpOtherEditView;
+    EditEngine* mpOtherEngine;
+    SameEditViewChecker maSameEditViewChecker;
+    int nTotalActiveEditViews;
+};
+
+
 class ScTabView : boost::noncopyable
 {
 private:
@@ -130,6 +188,8 @@ private:
     VclPtr<ScGridWindow>       pTimerWindow;
     MouseEvent          aTimerMEvt;
 
+    ScExtraEditViewManager aExtraEditViewManager;
+
     sal_uLong               nTipVisible;
 
     long                nPrevDragPos;
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 8f8a66f..c5895ff 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -211,6 +211,7 @@ ScTabView::ScTabView( vcl::Window* pParent, ScDocShell& rDocSh, ScTabViewShell*
     pBrushDocument( nullptr ),
     pDrawBrushSet( nullptr ),
     pTimerWindow( nullptr ),
+    aExtraEditViewManager( pViewShell, pGridWin ),
     nTipVisible( 0 ),
     nPrevDragPos( 0 ),
     meBlockMode(None),
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index af57d3a..cd85deb 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -97,6 +97,83 @@ ScRange lcl_getSubRangeByIndex( const ScRange& rRange, sal_Int32 nIndex )
 
 using namespace com::sun::star;
 
+ScExtraEditViewManager::~ScExtraEditViewManager()
+{
+    assert(nTotalActiveEditViews == 0);
+}
+
+void ScExtraEditViewManager::Apply(SfxViewShell* pViewShell, ScSplitPos eWhich, FuncType fHandler)
+{
+    ScTabViewShell* pOtherViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
+    if (pOtherViewShell != nullptr && pOtherViewShell != mpThisViewShell)
+    {
+        mpOtherEditView = pOtherViewShell->GetViewData().GetEditView(eWhich);
+        if (mpOtherEditView != nullptr)
+        {
+            mpOtherEngine = mpOtherEditView->GetEditEngine();
+            if (mpOtherEngine != nullptr)
+            {
+                maSameEditViewChecker.SetEditView(mpOtherEditView);
+                for (int i = 0; i < 4; ++i)
+                {
+                    (this->*fHandler)(mpGridWin[i].get());
+                }
+            }
+        }
+    }
+}
+
+void ScExtraEditViewManager::Adder(ScGridWindow* pWin)
+{
+    if (pWin != nullptr)
+    {
+        EditEngine::ViewsType& rEditViews = mpOtherEngine->GetEditViews();
+        maSameEditViewChecker.SetWindow(pWin);
+        auto found = std::find_if(rEditViews.begin(), rEditViews.end(), maSameEditViewChecker);
+        if (found == rEditViews.end())
+        {
+            EditView* pThisEditView = new EditView( mpOtherEngine, pWin );
+            if (pThisEditView != nullptr)
+            {
+                pThisEditView->SetOutputArea(mpOtherEditView->GetOutputArea());
+                pThisEditView->SetVisArea(mpOtherEditView->GetVisArea());
+                mpOtherEngine->InsertView(pThisEditView);
+                ++nTotalActiveEditViews;
+            }
+        }
+    }
+}
+
+void ScExtraEditViewManager::Remover(ScGridWindow* pWin)
+{
+    if (pWin != nullptr)
+    {
+        EditEngine::ViewsType& rEditViews = mpOtherEngine->GetEditViews();
+        maSameEditViewChecker.SetWindow(pWin);
+        auto found = std::find_if(rEditViews.begin(), rEditViews.end(), maSameEditViewChecker);
+        if (found != rEditViews.end())
+        {
+            EditView* pView = *found;
+            if (pView)
+            {
+                mpOtherEngine->RemoveView(pView);
+                delete pView;
+                pView = nullptr;
+                --nTotalActiveEditViews;
+            }
+        }
+    }
+}
+
+bool ScExtraEditViewManager::SameEditViewChecker::operator() (const EditView* pView) const
+{
+    return ( pView != nullptr
+          && pView->GetWindow() == mpWindow
+          && pView->GetEditEngine() == mpOtherEditView->GetEditEngine()
+          && pView->GetOutputArea() == mpOtherEditView->GetOutputArea()
+          && pView->GetVisArea() == mpOtherEditView->GetVisArea() );
+}
+
 // ---  public functions
 
 void ScTabView::ClickCursor( SCCOL nPosX, SCROW nPosY, bool bControl )
@@ -1868,133 +1945,13 @@ void ScTabView::SetTabNo( SCTAB nTab, bool bNew, bool bExtendSelection, bool bSa
     }
 }
 
-class ExtraEditViewManager
-{
-public:
-    ExtraEditViewManager(ScTabViewShell* pThisViewShell, VclPtr<ScGridWindow>* pGridWin)
-        : mpThisViewShell(pThisViewShell)
-        , mpGridWin(pGridWin)
-        , mpOtherEditView(nullptr)
-        , mpOtherEngine(nullptr)
-        , mpEditViews(nullptr)
-        , maSameEditViewChecker()
-    {}
-
-    void Add(SfxViewShell* pViewShell, ScSplitPos eWhich)
-    {
-        Apply(pViewShell, eWhich, &ExtraEditViewManager::Adder);
-    }
-
-    void Remove(SfxViewShell* pViewShell, ScSplitPos eWhich)
-    {
-        Apply(pViewShell, eWhich, &ExtraEditViewManager::Remover);
-    }
-
-private:
-    class SameEditViewChecker
-    {
-    public:
-        SameEditViewChecker()
-            : mpOtherEditView(nullptr)
-            , mpWindow(nullptr)
-        {}
-        void SetEditView(EditView* pOtherEditView) { mpOtherEditView = pOtherEditView; }
-        void SetWindow(ScGridWindow* pWindow) { mpWindow = pWindow; }
-        bool operator() (const EditView* pView) const
-        {
-            return ( pView != nullptr
-                  && pView->GetWindow() == mpWindow
-                  && pView->GetEditEngine() == mpOtherEditView->GetEditEngine()
-                  && pView->GetOutputArea() == mpOtherEditView->GetOutputArea()
-                  && pView->GetVisArea() == mpOtherEditView->GetVisArea() );
-        }
-
-    private:
-        EditView* mpOtherEditView;
-        ScGridWindow* mpWindow;
-    };
-
-private:
-    typedef void (ExtraEditViewManager::* FuncType)(ScGridWindow* );
-
-    void Apply(SfxViewShell* pViewShell, ScSplitPos eWhich, FuncType fHandler)
-    {
-        ScTabViewShell* pOtherViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
-        if (pOtherViewShell != nullptr && pOtherViewShell != mpThisViewShell)
-        {
-            mpOtherEditView = pOtherViewShell->GetViewData().GetEditView(eWhich);
-            if (mpOtherEditView != nullptr)
-            {
-                mpOtherEngine = mpOtherEditView->GetEditEngine();
-                if (mpOtherEngine != nullptr)
-                {
-                    mpEditViews = &(mpOtherEngine->GetEditViews());
-                    maSameEditViewChecker.SetEditView(mpOtherEditView);
-                    for (int i = 0; i < 4; ++i)
-                    {
-                        (this->*fHandler)(mpGridWin[i].get());
-                    }
-                }
-            }
-        }
-    }
-
-    void Adder(ScGridWindow* pWin)
-    {
-        if (pWin != nullptr)
-        {
-            maSameEditViewChecker.SetWindow(pWin);
-            auto found = std::find_if(mpEditViews->begin(), mpEditViews->end(), maSameEditViewChecker);
-            if (found == mpEditViews->end())
-            {
-                EditView* pThisEditView = new EditView( mpOtherEngine, pWin );
-                if (pThisEditView != nullptr)
-                {
-                    pThisEditView->SetOutputArea(mpOtherEditView->GetOutputArea());
-                    pThisEditView->SetVisArea(mpOtherEditView->GetVisArea());
-                    mpOtherEngine->InsertView(pThisEditView);
-                }
-            }
-        }
-    }
-
-    void Remover(ScGridWindow* pWin)
-    {
-        if (pWin != nullptr)
-        {
-            maSameEditViewChecker.SetWindow(pWin);
-            auto found = std::find_if(mpEditViews->begin(), mpEditViews->end(), maSameEditViewChecker);
-            if (found != mpEditViews->end())
-            {
-                EditView* pView = *found;
-                if (pView)
-                {
-                    mpOtherEngine->RemoveView(pView);
-                    delete pView;
-                    pView = nullptr;
-                }
-            }
-        }
-    }
-
-private:
-    ScTabViewShell* mpThisViewShell;
-    VclPtr<ScGridWindow>* mpGridWin;
-    EditView* mpOtherEditView;
-    EditEngine* mpOtherEngine;
-    EditEngine::ViewsType* mpEditViews;
-    SameEditViewChecker maSameEditViewChecker;
-};
-
 void ScTabView::AddEditViewToOtherView(SfxViewShell* pViewShell, ScSplitPos eWhich)
 {
-    ExtraEditViewManager aExtraEditViewManager(aViewData.GetViewShell(), pGridWin);
     aExtraEditViewManager.Add(pViewShell, eWhich);
 }
 
 void ScTabView::RemoveEditViewFromOtherView(SfxViewShell* pViewShell, ScSplitPos eWhich)
 {
-    ExtraEditViewManager aExtraEditViewManager(aViewData.GetViewShell(), pGridWin);
     aExtraEditViewManager.Remove(pViewShell, eWhich);
 }
 
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index a57e952..4ef54ad 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -98,6 +98,7 @@
 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
 #include <com/sun/star/chart2/XChartType.hpp>
 #include <sfx2/lokhelper.hxx>
+#include <comphelper/flagguard.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
 
@@ -105,14 +106,6 @@ extern SfxViewShell* pScActiveViewShell;            // global.cxx
 
 using namespace com::sun::star;
 
-struct BoolLock
-{
-    bool& mflag;
-    explicit BoolLock( bool& flag ) : mflag(flag)
-    { mflag = true; }
-    ~BoolLock() { mflag = false; }
-};
-
 void ScTabViewShell::Activate(bool bMDI)
 {
     SfxViewShell::Activate(bMDI);
@@ -284,7 +277,8 @@ void ScTabViewShell::SetActive()
 
 bool ScTabViewShell::PrepareClose(bool bUI)
 {
-    BoolLock aBoolLock(bInPrepareClose);
+    comphelper::FlagRestorationGuard aFlagGuard(bInPrepareClose, true);
+
     // Call EnterHandler even in formula mode here,
     // so a formula change in an embedded object isn't lost
     // (ScDocShell::PrepareClose isn't called then).


More information about the Libreoffice-commits mailing list