diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2016-10-06 23:29:40 +0200 |
---|---|---|
committer | Marco Cecchetti <mrcekets@gmail.com> | 2016-10-14 15:01:04 +0000 |
commit | a6c008b12cd2c2daf95a18eff0d72239588a5321 (patch) | |
tree | a756280dfb57b221e1350a56055ee92bd26544b6 | |
parent | c3fa866e768b67650b1e52308565e9344db0b4b4 (diff) |
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@gmail.com>
Tested-by: Marco Cecchetti <mrcekets@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/29657
-rw-r--r-- | sc/source/ui/inc/tabview.hxx | 59 | ||||
-rw-r--r-- | sc/source/ui/view/tabview.cxx | 1 | ||||
-rw-r--r-- | sc/source/ui/view/tabview3.cxx | 196 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwsh4.cxx | 12 |
4 files changed, 140 insertions, 128 deletions
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx index ceb1531e979a..f1f9431a2463 100644 --- a/sc/source/ui/inc/tabview.hxx +++ b/sc/source/ui/inc/tabview.hxx @@ -77,6 +77,63 @@ 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 { private: @@ -127,6 +184,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 e2fa248ee17f..dc5c221cfea7 100644 --- a/sc/source/ui/view/tabview.cxx +++ b/sc/source/ui/view/tabview.cxx @@ -208,6 +208,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 f574b0988949..68a37a94bd0c 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -98,6 +98,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 ) @@ -1894,132 +1971,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) - {} - 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; - VclPtr<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 892b7c71d354..2f27b5ee769b 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). |