diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-03-25 17:21:35 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-04-13 14:25:04 +0200 |
commit | bd93f5cec54350b6f07c5b7cd4987ea3762e3f40 (patch) | |
tree | 6f007978d9579d636d50cc96f0791f9452802666 /sd | |
parent | f6d1da91ccda960d1ee738d688a2cb374e576aef (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 cc11e2483991..55d724a6a069 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -114,6 +114,7 @@ public: void testCommentChangeImpress(); void testCommentChangeDraw(); void testMultiViewInsertDeletePage(); + void testMultiViewInsertDeletePage2(); void testDisableUndoRepair(); void testDocumentRepair(); void testLanguageStatus(); @@ -167,6 +168,7 @@ public: CPPUNIT_TEST(testCommentChangeImpress); CPPUNIT_TEST(testCommentChangeDraw); CPPUNIT_TEST(testMultiViewInsertDeletePage); + CPPUNIT_TEST(testMultiViewInsertDeletePage2); CPPUNIT_TEST(testDisableUndoRepair); CPPUNIT_TEST(testDocumentRepair); CPPUNIT_TEST(testLanguageStatus); @@ -1953,6 +1955,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 7f8e9b576529..288cf24866de 100644 --- a/sd/source/ui/inc/DrawViewShell.hxx +++ b/sd/source/ui/inc/DrawViewShell.hxx @@ -242,7 +242,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 ab3a723cf672..f5a02cbee597 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -231,7 +231,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 662477a28367..fcdb050d7843 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2282,13 +2282,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 f17f81799bae..db7cd452d860 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 }); } /** @@ -816,8 +823,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 @@ -921,7 +931,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); |