summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2021-03-25 17:21:35 +0100
committerJan Holesovsky <kendy@collabora.com>2021-03-29 14:43:49 +0200
commitec90261c6568476c0eb039d7f2e4af75a535baf2 (patch)
tree4243e1905c2616ef0ca84fade0a262d9fad6b98b
parentf34eac66e64a416739c36aa996c90ea1869b9f0d (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>
-rw-r--r--desktop/source/lib/init.cxx13
-rw-r--r--include/vcl/ITiledRenderable.hxx4
-rw-r--r--sc/inc/docuno.hxx2
-rw-r--r--sc/source/ui/unoobj/docuno.cxx2
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx68
-rw-r--r--sd/source/ui/inc/DrawViewShell.hxx2
-rw-r--r--sd/source/ui/inc/unomodel.hxx2
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx4
-rw-r--r--sd/source/ui/view/drviews1.cxx22
-rw-r--r--sw/inc/unotxdoc.hxx2
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx2
11 files changed, 104 insertions, 19 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 8c484bfa8897..5ac2212f211b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2981,7 +2981,7 @@ static int doc_getPart (LibreOfficeKitDocument* pThis)
return pDoc->getPart();
}
-static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
+static void doc_setPartImpl(LibreOfficeKitDocument* pThis, int nPart, bool bAllowChangeFocus = true)
{
comphelper::ProfileZone aZone("doc_setPart");
@@ -2995,7 +2995,12 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
return;
}
- pDoc->setPart( nPart );
+ pDoc->setPart( nPart, bAllowChangeFocus );
+}
+
+static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
+{
+ doc_setPartImpl(pThis, nPart, true);
}
static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart)
@@ -3310,7 +3315,7 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
nOrigPart = doc_getPart(pThis);
if (nPart != nOrigPart)
{
- doc_setPart(pThis, nPart);
+ doc_setPartImpl(pThis, nPart, false);
}
}
@@ -3318,7 +3323,7 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
if (!isText && nPart != nOrigPart)
{
- doc_setPart(pThis, nOrigPart);
+ doc_setPartImpl(pThis, nOrigPart, false);
}
if (!isText && nViewId != nOrigViewId)
{
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index e089592e41fa..b9dd458edd71 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -72,8 +72,10 @@ public:
/**
* Set the document "part", i.e. slide for a slideshow, and
* tab for a spreadsheet.
+ * bool bAllowChangeFocus - used to not disturb other users while editing when
+ * setPart is used for tile rendering only
*/
- virtual void setPart( int ) {}
+ virtual void setPart( int /*nPart*/, bool /*bAllowChangeFocus*/ = true ) {}
/**
* Get the number of parts -- see setPart for further details.
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index f2b507c2e4fa..d65cdd1f5ba3 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -312,7 +312,7 @@ public:
virtual Size getDocumentSize() override;
/// @see vcl::ITiledRenderable::setPart().
- virtual void setPart(int nPart) override;
+ virtual void setPart(int nPart, bool bAllowChangeFocus = true) override;
/// @see vcl::ITiledRenderable::getPart().
virtual int getPart() override;
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 9d2539a25bcd..1fb05739cea2 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -563,7 +563,7 @@ void ScModelObj::paintTile( VirtualDevice& rDevice,
nTilePosX, nTilePosY, nTileWidth, nTileHeight);
}
-void ScModelObj::setPart( int nPart )
+void ScModelObj::setPart( int nPart, bool /*bAllowChangeFocus*/ )
{
ScViewData* pViewData = ScDocShell::GetViewData();
ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 64e6196ae605..61940c1e8c2a 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -113,6 +113,7 @@ public:
void testCommentChangeImpress();
void testCommentChangeDraw();
void testMultiViewInsertDeletePage();
+ void testMultiViewInsertDeletePage2();
void testDisableUndoRepair();
void testDocumentRepair();
void testLanguageStatus();
@@ -165,6 +166,7 @@ public:
CPPUNIT_TEST(testCommentChangeImpress);
CPPUNIT_TEST(testCommentChangeDraw);
CPPUNIT_TEST(testMultiViewInsertDeletePage);
+ CPPUNIT_TEST(testMultiViewInsertDeletePage2);
CPPUNIT_TEST(testDisableUndoRepair);
CPPUNIT_TEST(testDocumentRepair);
CPPUNIT_TEST(testLanguageStatus);
@@ -1918,6 +1920,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(static_cast<sal_uInt16>(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 cd283c76fa57..daa2c36478e2 100644
--- a/sd/source/ui/inc/DrawViewShell.hxx
+++ b/sd/source/ui/inc/DrawViewShell.hxx
@@ -244,7 +244,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 08629b074b5b..60dfcb02f8d1 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -232,7 +232,7 @@ public:
long nTileWidth,
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 69c2a94dd946..21298e4da4af 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2283,13 +2283,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 3a370de8b33b..4a055184fb08 100644
--- a/sd/source/ui/view/drviews1.cxx
+++ b/sd/source/ui/view/drviews1.cxx
@@ -651,6 +651,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);
@@ -677,7 +678,8 @@ void DrawViewShell::ResetActualPage()
GetDoc()->SetSelected(pPage, false);
}
- maTabControl->SetCurPageId(maTabControl->GetPageId(nCurrentPageNum));
+ nNewPageId = maTabControl->GetPageId(nCurrentPageNum);
+ maTabControl->SetCurPageId(nNewPageId);
}
else // EditMode::MasterPage
{
@@ -697,12 +699,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);
+ if (nNewPageId != nCurrentPageId)
+ GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE,
+ SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
+ else
+ SwitchPage(nCurrentPageNum, false);
}
/**
@@ -817,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
@@ -922,7 +931,8 @@ bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage)
}
}
- mpDrawView->SdrEndTextEdit();
+ if (bAllowChangeFocus)
+ mpDrawView->SdrEndTextEdit();
mpActualPage = nullptr;
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index ffb4c790bd96..a1da4a7ceaa6 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -398,7 +398,7 @@ public:
/// @see vcl::ITiledRenderable::getDocumentSize().
virtual Size getDocumentSize() override;
/// @see vcl::ITiledRenderable::setPart().
- virtual void setPart(int nPart) override;
+ virtual void setPart(int nPart, bool bAllowChangeFocus = true) override;
/// @see vcl::ITiledRenderable::getParts().
virtual int getParts() override;
/// @see vcl::ITiledRenderable::getPart().
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 1f9a92724c2c..0a5fec9a18d5 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3172,7 +3172,7 @@ Size SwXTextDocument::getDocumentSize()
aDocSize.Height() + 2 * DOCUMENTBORDER);
}
-void SwXTextDocument::setPart(int nPart)
+void SwXTextDocument::setPart(int nPart, bool /*bAllowChangeFocus*/)
{
SolarMutexGuard aGuard;