diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2016-09-28 12:20:10 +0200 |
---|---|---|
committer | Marco Cecchetti <mrcekets@gmail.com> | 2016-10-03 12:13:15 +0000 |
commit | 8ef20328866320cba9267027ea7284f8ec7edccf (patch) | |
tree | a5b8d1a16d2b5c991d17c7ca365f5e6d1cdc8a3c /sc/source | |
parent | cae57d2e588a4b5a104171e022b00abcc1605775 (diff) |
Calc: implemented parallel cell text editing
Change-Id: If8cc7a637cee6ba66813d55b25160fee13a2a219
Reviewed-on: https://gerrit.libreoffice.org/29410
Reviewed-by: Marco Cecchetti <mrcekets@gmail.com>
Tested-by: Marco Cecchetti <mrcekets@gmail.com>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/ui/inc/tabview.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin4.cxx | 86 | ||||
-rw-r--r-- | sc/source/ui/view/tabview3.cxx | 170 | ||||
-rw-r--r-- | sc/source/ui/view/tabview5.cxx | 20 | ||||
-rw-r--r-- | sc/source/ui/view/viewdata.cxx | 41 |
5 files changed, 319 insertions, 1 deletions
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx index 34793bf24b1e..4cd3d79fe19d 100644 --- a/sc/source/ui/inc/tabview.hxx +++ b/sc/source/ui/inc/tabview.hxx @@ -449,6 +449,9 @@ public: void InvalidateAttribs(); + void OnLibreOfficeKitTabChanged(); + void AddEditViewToOtherView(SfxViewShell* pViewShell, ScSplitPos eWhich); + void RemoveEditViewFromOtherView(SfxViewShell* pViewShell, ScSplitPos eWhich); void MakeEditView( ScEditEngineDefaulter* pEngine, SCCOL nCol, SCROW nRow ); void KillEditView( bool bNoPaint ); void UpdateEditView(); diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index b650fc4a293e..a52fc5bda7c8 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -967,6 +967,92 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& rTableI pCrsr->Show(); } + + if (comphelper::LibreOfficeKit::isActive()) + { + ScTabViewShell* pThisViewShell = pViewData->GetViewShell(); + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + + while (pViewShell) + { + if (pViewShell != pThisViewShell) + { + ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell); + if (pTabViewShell) + { + ScViewData& rOtherViewData = pTabViewShell->GetViewData(); + ScSplitPos eOtherWhich = rOtherViewData.GetEditActivePart(); + + bool bOtherEditMode = rOtherViewData.HasEditView(eOtherWhich); + SCCOL nCol1 = rOtherViewData.GetEditStartCol(); + SCROW nRow1 = rOtherViewData.GetEditStartRow(); + SCCOL nCol2 = rOtherViewData.GetEditEndCol(); + SCROW nRow2 = rOtherViewData.GetEditEndRow(); + bOtherEditMode = bOtherEditMode + && ( nCol2 >= nX1 && nCol1 <= nX2 && nRow2 >= nY1 && nRow1 <= nY2 ); + if (bOtherEditMode && rOtherViewData.GetRefTabNo() == nTab) + { + EditView* pOtherEditView = rOtherViewData.GetEditView(eOtherWhich); + Point aOtherScrPos = rOtherViewData.GetScrPos( nX1, nY1, eOtherWhich ); + if ( bLayoutRTL ) + { + long nEndPixel = pViewData->GetScrPos( nX2+1, maVisibleRange.mnRow1, eWhich ).X(); + aOtherScrPos.X() = nEndPixel + 1; + } + + long nScreenX = aOutputData.nScrX; + long nScreenY = aOutputData.nScrY; + long nScreenW = aOutputData.GetScrW(); + long nScreenH = aOutputData.GetScrH(); + + rDevice.SetLineColor(); + rDevice.SetFillColor(pEditView->GetBackgroundColor()); + Point aStart = rOtherViewData.GetScrPos( nCol1, nRow1, eOtherWhich ); + Point aEnd = rOtherViewData.GetScrPos( nCol2+1, nRow2+1, eOtherWhich ); + + // don't overwrite grid + long nLayoutSign = bLayoutRTL ? -1 : 1; + aEnd.X() -= 2 * nLayoutSign; + aEnd.Y() -= 2; + + Rectangle aBackground(aStart, aEnd); + + aBackground += Point(nScreenX, nScreenY); + rDevice.SetMapMode(aDrawMode); + + + // paint the background + rDevice.DrawRect(rDevice.PixelToLogic(aBackground)); + + if (bIsTiledRendering) + { + auto aOrigin = aOriginalMode.GetOrigin(); + aOrigin.setX(aOrigin.getX() / TWIPS_PER_PIXEL + nScrX); + aOrigin.setY(aOrigin.getY() / TWIPS_PER_PIXEL + nScrY); + static const double twipFactor = 15 * 1.76388889; // 26.45833335 + aOrigin = Point(aOrigin.getX() * twipFactor, + aOrigin.getY() * twipFactor); + MapMode aNew = rDevice.GetMapMode(); + aNew.SetOrigin(aOrigin); + rDevice.SetMapMode(aNew); + } + + pOtherEditView->Paint(rDevice.PixelToLogic(Rectangle(Point(nScreenX, nScreenY), Size(nScreenW, nScreenH))), &rDevice); + rDevice.SetMapMode(MAP_PIXEL); + } + + } + } + + pViewShell = SfxViewShell::GetNext(*pViewShell); + } + + } + + + + + if (pViewData->HasEditView(eWhich)) { // flush OverlayManager before changing the MapMode diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx index b3a2219642ba..0aaaa6dec6fb 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -27,6 +27,7 @@ #include <svx/sdr/overlay/overlaymanager.hxx> #include <svx/svdoole2.hxx> #include <sfx2/bindings.hxx> +#include <sfx2/lokhelper.hxx> #include <sfx2/viewfrm.hxx> #include <vcl/cursor.hxx> @@ -1888,6 +1889,175 @@ void ScTabView::SetTabNo( SCTAB nTab, bool bNew, bool bExtendSelection, bool bSa pRefDlg->ViewShellChanged(); } } + + OnLibreOfficeKitTabChanged(); + } +} + +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() (EditView* pView) + { + 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]); + } + } + } + } + } + + 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); +} + +void ScTabView::OnLibreOfficeKitTabChanged() +{ + if (comphelper::LibreOfficeKit::isActive()) + { + ScTabViewShell* pThisViewShell = aViewData.GetViewShell(); + SCTAB nThisTabNo = pThisViewShell->GetViewData().GetTabNo(); + auto lTabSwitch = + [pThisViewShell, nThisTabNo] (ScTabViewShell* pOtherViewShell) + { + ScViewData& rOtherViewData = pOtherViewShell->GetViewData(); + SCTAB nOtherTabNo = rOtherViewData.GetTabNo(); + if (nThisTabNo == nOtherTabNo) + { + for (int i = 0; i < 4; ++i) + { + if (rOtherViewData.HasEditView( (ScSplitPos)(i))) + { + pThisViewShell->AddEditViewToOtherView(pOtherViewShell, (ScSplitPos)(i)); + } + } + } + else + { + for (int i = 0; i < 4; ++i) + { + if (rOtherViewData.HasEditView( (ScSplitPos)(i))) + { + pThisViewShell->RemoveEditViewFromOtherView(pOtherViewShell, (ScSplitPos)(i)); + } + } + } + }; + + SfxLokHelper::forEachOtherView(pThisViewShell, lTabSwitch); } } diff --git a/sc/source/ui/view/tabview5.cxx b/sc/source/ui/view/tabview5.cxx index a9d3dcab6707..10a39b3a2555 100644 --- a/sc/source/ui/view/tabview5.cxx +++ b/sc/source/ui/view/tabview5.cxx @@ -25,6 +25,7 @@ #include <svx/svdoutl.hxx> #include <sfx2/bindings.hxx> #include <sfx2/dispatch.hxx> +#include <sfx2/lokhelper.hxx> #include <sfx2/objsh.hxx> #include "tabview.hxx" @@ -54,7 +55,6 @@ #include <officecfg/Office/Calc.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> - using namespace com::sun::star; void ScTabView::Init() @@ -159,6 +159,24 @@ ScTabView::~ScTabView() DELETEZ(pDrawOld); DELETEZ(pDrawActual); + if (comphelper::LibreOfficeKit::isActive()) + { + ScTabViewShell* pThisViewShell = GetViewData().GetViewShell(); + + auto lRemoveEditView = + [pThisViewShell] (ScTabViewShell* pOtherViewShell) + { + ScViewData& rOtherViewData = pOtherViewShell->GetViewData(); + for (int k = 0; k < 4; ++k) + { + if (rOtherViewData.HasEditView((ScSplitPos)(k))) + pThisViewShell->RemoveEditViewFromOtherView(pOtherViewShell, (ScSplitPos)(k)); + } + }; + + SfxLokHelper::forEachOtherView(pThisViewShell, lRemoveEditView); + } + aViewData.KillEditView(); // solange GridWin's noch existieren if (pDrawView) diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 240661d11c18..77d9f42df304 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -20,6 +20,7 @@ #include "scitems.hxx" #include <editeng/eeitem.hxx> +#include <sfx2/lokhelper.hxx> #include <sfx2/viewfrm.hxx> #include <editeng/adjustitem.hxx> #include <svx/algitem.hxx> @@ -76,6 +77,22 @@ using namespace com::sun::star; static bool bMoveArea = false; // Member? sal_uInt16 nEditAdjust = SVX_ADJUST_LEFT; // Member! +namespace { + +void lcl_LOKRemoveEditView(ScTabViewShell* pTabViewShell, ScSplitPos eWhich) +{ + if (comphelper::LibreOfficeKit::isActive()) + { + auto lRemoveEditView = + [pTabViewShell, eWhich] (ScTabViewShell* pOtherViewShell) + { pOtherViewShell->RemoveEditViewFromOtherView(pTabViewShell, eWhich); }; + + SfxLokHelper::forEachOtherView(pTabViewShell, lRemoveEditView); + } +} + +} // anonymous namespace + ScViewDataTable::ScViewDataTable() : eZoomType( SvxZoomType::PERCENT ), aZoomX( 1,1 ), @@ -958,12 +975,18 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich, { // if the view is already there don't call anything that changes the cursor position if (bEditActive[eWhich]) + { bWasThere = true; + } else + { + lcl_LOKRemoveEditView(GetViewShell(), eWhich); pEditView[eWhich]->SetEditEngine(pNewEngine); + } if (pEditView[eWhich]->GetWindow() != pWin) { + lcl_LOKRemoveEditView(GetViewShell(), eWhich); pEditView[eWhich]->SetWindow(pWin); OSL_FAIL("EditView Window has changed"); } @@ -1133,6 +1156,23 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich, pEditView[eWhich]->Invalidate(); // needed? // needed, wenn position changed + + if (comphelper::LibreOfficeKit::isActive()) + { + ScTabViewShell* pThisViewShell = GetViewShell(); + SCTAB nThisTabNo = GetTabNo(); + auto lAddEditView = + [pThisViewShell, nThisTabNo, eWhich] (ScTabViewShell* pOtherViewShell) + { + ScViewData& rOtherViewData = pOtherViewShell->GetViewData(); + SCTAB nOtherTabNo = rOtherViewData.GetTabNo(); + if (nThisTabNo == nOtherTabNo) + pOtherViewShell->AddEditViewToOtherView(pThisViewShell, eWhich); + }; + + SfxLokHelper::forEachOtherView(pThisViewShell, lAddEditView); + } + } IMPL_LINK_TYPED( ScViewData, EditEngineHdl, EditStatus&, rStatus, void ) @@ -1422,6 +1462,7 @@ void ScViewData::ResetEditView() { if (bEditActive[i]) { + lcl_LOKRemoveEditView(GetViewShell(), (ScSplitPos)(i)); pEngine = pEditView[i]->GetEditEngine(); pEngine->RemoveView(pEditView[i]); pEditView[i]->SetOutputArea( Rectangle() ); |