diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-03-25 17:21:35 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2021-04-14 13:42:29 +0200 |
commit | ce7bf351972bbfd64ca99e8d2fb4c5f77591c9e0 (patch) | |
tree | 1fc90ead121f9816baffa8cc669d7570423b4714 /sd | |
parent | 5900fd583a6b2ea5810a78f66e75b2910b34b7cc (diff) |
impress: don't exit textbox editing when new slide was added
When new slide is added by other user before currently visible slide
then SwitchPage is called and textbox editing is ended.
Avoid any focus change when setPart is called just for rendering
or SwitchPage is used on previously avtive slide (only slide numer changed).
Change-Id: I7fef42b863e0079acc84dadfc3f891548652b48f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113144
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113806
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 68 | ||||
-rw-r--r-- | sd/source/ui/inc/DrawViewShell.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/inc/unomodel.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/view/drviews1.cxx | 23 | ||||
-rw-r--r-- | sd/source/ui/view/drviews3.cxx | 14 |
6 files changed, 101 insertions, 12 deletions
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index ae4aab1b1e91..811c25a68660 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -115,6 +115,7 @@ public: void testCommentChangeImpress(); void testCommentChangeDraw(); void testMultiViewInsertDeletePage(); + void testMultiViewInsertDeletePage2(); void testDisableUndoRepair(); void testDocumentRepair(); void testLanguageStatus(); @@ -168,6 +169,7 @@ public: CPPUNIT_TEST(testCommentChangeImpress); CPPUNIT_TEST(testCommentChangeDraw); CPPUNIT_TEST(testMultiViewInsertDeletePage); + CPPUNIT_TEST(testMultiViewInsertDeletePage2); CPPUNIT_TEST(testDisableUndoRepair); CPPUNIT_TEST(testDocumentRepair); CPPUNIT_TEST(testLanguageStatus); @@ -1954,6 +1956,72 @@ void SdTiledRenderingTest::testMultiViewInsertDeletePage() CPPUNIT_ASSERT_EQUAL(4, pXImpressDocument->getPart()); } +void SdTiledRenderingTest::testMultiViewInsertDeletePage2() +{ + // Load the document. + SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp"); + ViewCallback aView1; + int nView1 = SfxLokHelper::getView(); + uno::Sequence<beans::PropertyValue> aArgs; + SdDrawDocument* pDoc = pXImpressDocument->GetDocShell()->GetDoc(); + + // Create second view + SfxLokHelper::createView(); + pXImpressDocument->initializeForTiledRendering(aArgs); + ViewCallback aView2; + int nView2 = SfxLokHelper::getView(); + + // the document has 8 slides + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), pDoc->GetSdPageCount(PageKind::Standard)); + + // Switch to 5th page in 2nd view + pXImpressDocument->setPart(4); + + // Begin text edit on the only object on the slide. + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + SdPage* pActualPage = pViewShell->GetActualPage(); + SdrObject* pObject1 = pActualPage->GetObj(0); + CPPUNIT_ASSERT(pObject1 != nullptr); + CPPUNIT_ASSERT_EQUAL(OBJ_TITLETEXT, pObject1->GetObjIdentifier()); + SdrTextObj* pTextObject = static_cast<SdrTextObj*>(pObject1); + + // Double-click outside the text to enter edit mode. + const ::tools::Rectangle aRect = pTextObject->GetCurrentBoundRect(); + const auto cornerX = convertMm100ToTwip(aRect.getX() + (aRect.getWidth() / 4)); + const auto cornerY = convertMm100ToTwip(aRect.getY() + (aRect.getHeight() / 4)); + pXImpressDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + cornerX, cornerY, + 2, MOUSE_LEFT, 0); + pXImpressDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, + cornerX, cornerY, + 2, MOUSE_LEFT, 0); + Scheduler::ProcessEventsToIdle(); + + // We must be in text editing mode and have cursor visible. + CPPUNIT_ASSERT(pViewShell->GetView()->IsTextEdit()); + + // Insert slide in 1st view + SfxLokHelper::setView(nView1); + comphelper::dispatchCommand(".uno:InsertPage", aArgs); + Scheduler::ProcessEventsToIdle(); + + // See if the current slide number changed in 2nd view too + SfxLokHelper::setView(nView2); + CPPUNIT_ASSERT_EQUAL(5, pXImpressDocument->getPart()); + + // Delete the page in 1st view now + SfxLokHelper::setView(nView1); + comphelper::dispatchCommand(".uno:DeletePage", aArgs); + Scheduler::ProcessEventsToIdle(); + + // See if current slide number changed in 2nd view too + SfxLokHelper::setView(nView2); + CPPUNIT_ASSERT_EQUAL(4, pXImpressDocument->getPart()); + + // We must be still in text editing mode and have cursor visible. + CPPUNIT_ASSERT(pViewShell->GetView()->IsTextEdit()); +} + void SdTiledRenderingTest::testDisableUndoRepair() { // Load the document. diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx index 5170883b3379..4213d12750cb 100644 --- a/sd/source/ui/inc/DrawViewShell.hxx +++ b/sd/source/ui/inc/DrawViewShell.hxx @@ -243,7 +243,7 @@ public: void ResetActualPage(); void ResetActualLayer(); - bool SwitchPage(sal_uInt16 nPage); + bool SwitchPage(sal_uInt16 nPage, bool bAllowChangeFocus = true); bool IsSwitchPageAllowed() const; /** diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index 483dca72f73a..2873e705ca6b 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -232,7 +232,7 @@ public: tools::Long nTileWidth, tools::Long nTileHeight ) override; virtual Size getDocumentSize() override; - virtual void setPart( int nPart ) override; + virtual void setPart( int nPart, bool bAllowChangeFocus = true ) override; virtual int getPart() override; virtual int getParts() override; virtual OUString getPartName( int nPart ) override; diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index b325c3c9e201..a246aab75b34 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2295,13 +2295,13 @@ OUString SdXImpressDocument::getPartInfo(int nPart) return aPartInfo; } -void SdXImpressDocument::setPart( int nPart ) +void SdXImpressDocument::setPart( int nPart, bool bAllowChangeFocus ) { DrawViewShell* pViewSh = GetViewShell(); if (!pViewSh) return; - pViewSh->SwitchPage( nPart ); + pViewSh->SwitchPage( nPart, bAllowChangeFocus ); } int SdXImpressDocument::getParts() diff --git a/sd/source/ui/view/drviews1.cxx b/sd/source/ui/view/drviews1.cxx index b1105e38872f..06462ecdf75c 100644 --- a/sd/source/ui/view/drviews1.cxx +++ b/sd/source/ui/view/drviews1.cxx @@ -71,6 +71,7 @@ #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <vcl/uitest/logger.hxx> #include <vcl/uitest/eventdescription.hxx> +#include <svl/intitem.hxx> using namespace com::sun::star; @@ -652,6 +653,7 @@ void DrawViewShell::ResetActualPage() return; sal_uInt16 nCurrentPageId = maTabControl->GetCurPageId(); + sal_uInt16 nNewPageId = nCurrentPageId; sal_uInt16 nCurrentPageNum = maTabControl->GetPagePos(nCurrentPageId); sal_uInt16 nPageCount = (meEditMode == EditMode::Page)?GetDoc()->GetSdPageCount(mePageKind):GetDoc()->GetMasterSdPageCount(mePageKind); @@ -678,7 +680,8 @@ void DrawViewShell::ResetActualPage() GetDoc()->SetSelected(pPage, false); } - maTabControl->SetCurPageId(maTabControl->GetPageId(nCurrentPageNum)); + nNewPageId = maTabControl->GetPageId(nCurrentPageNum); + maTabControl->SetCurPageId(nNewPageId); } else // EditMode::MasterPage { @@ -698,12 +701,16 @@ void DrawViewShell::ResetActualPage() nCurrentPageNum = i; } - maTabControl->SetCurPageId(maTabControl->GetPageId(nCurrentPageNum)); + nNewPageId = maTabControl->GetPageId(nCurrentPageNum); + maTabControl->SetCurPageId(nNewPageId); SwitchPage(nCurrentPageNum); } - GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE, - SfxCallMode::ASYNCHRON | SfxCallMode::RECORD); + bool bAllowChangeFocus = nNewPageId != nCurrentPageId; + SfxBoolItem aI(SID_SWITCHPAGE, bAllowChangeFocus); + GetViewFrame()->GetDispatcher()->ExecuteList(SID_SWITCHPAGE, + SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, + { &aI }); } /** @@ -818,8 +825,11 @@ bool DrawViewShell::IsVisible(sal_uInt16 nPage) /** * Switch to desired page. * nSelectPage refers to the current EditMode + * bAllowChangeFocus set to false when slide is inserted before current page + * and we need to only update the current page number, + * do not disturb editing in that case */ -bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage) +bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage, bool bAllowChangeFocus) { /** Under some circumstances there are nested calls to SwitchPage() and may crash the application (activation of form controls when the @@ -923,7 +933,8 @@ bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage) } } - mpDrawView->SdrEndTextEdit(); + if (bAllowChangeFocus) + mpDrawView->SdrEndTextEdit(); mpActualPage = nullptr; diff --git a/sd/source/ui/view/drviews3.cxx b/sd/source/ui/view/drviews3.cxx index ed28a4370ebc..545c7befeca4 100644 --- a/sd/source/ui/view/drviews3.cxx +++ b/sd/source/ui/view/drviews3.cxx @@ -106,6 +106,7 @@ void DrawViewShell::ExecCtrl(SfxRequest& rReq) // End text edit mode for some requests. sal_uInt16 nSlot = rReq.GetSlot(); + bool bAllowFocusChange = true; switch (nSlot) { case SID_OUTPUT_QUALITY_COLOR: @@ -114,6 +115,15 @@ void DrawViewShell::ExecCtrl(SfxRequest& rReq) case SID_OUTPUT_QUALITY_CONTRAST: // Do nothing. break; + case SID_SWITCHPAGE: + if (rReq.GetArgs() && rReq.GetArgs()->Count () == 1) + { + const SfxBoolItem* pAllowFocusChange = rReq.GetArg<SfxBoolItem>(SID_SWITCHPAGE); + bAllowFocusChange = pAllowFocusChange->GetValue(); + if (!bAllowFocusChange) + break; + } + BOOST_FALLTHROUGH; default: if ( mpDrawView->IsTextEdit() ) { @@ -137,7 +147,7 @@ void DrawViewShell::ExecCtrl(SfxRequest& rReq) const SfxItemSet *pArgs = rReq.GetArgs (); sal_uInt16 nSelectedPage = 0; - if (! pArgs) + if (! pArgs || pArgs->Count () == 1) { nSelectedPage = maTabControl->GetCurPagePos(); } @@ -183,7 +193,7 @@ void DrawViewShell::ExecCtrl(SfxRequest& rReq) if( GetDocSh() && (GetDocSh()->GetCreateMode() == SfxObjectCreateMode::EMBEDDED)) GetDocSh()->SetModified(); - SwitchPage(nSelectedPage); + SwitchPage(nSelectedPage, bAllowFocusChange); if(HasCurrentFunction(SID_BEZIER_EDIT)) GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON); |