[Libreoffice-commits] core.git: sd/qa sw/qa

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 1 16:35:31 UTC 2019


 sd/qa/unit/tiledrendering/tiledrendering.cxx   |   59 +----
 sw/qa/extras/tiledrendering/tiledrendering.cxx |  257 ++++++-------------------
 2 files changed, 83 insertions(+), 233 deletions(-)

New commits:
commit c9d6de20d9a64481ca3dd0f099b752a4ef11a46e
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Aug 1 14:32:58 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Aug 1 18:34:40 2019 +0200

    clean up ViewCallback nicely in sw and sd
    
    Change-Id: I471768083e46b43df37b500bb51dfa13a1b54b75
    Reviewed-on: https://gerrit.libreoffice.org/76797
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 1b1d84b334dd..f629d29ab8e4 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -949,6 +949,8 @@ void SdTiledRenderingTest::testResizeTableColumn()
 /// A view callback tracks callbacks invoked on one specific view.
 class ViewCallback
 {
+    SfxViewShell* mpViewShell;
+    int mnView;
 public:
     bool m_bGraphicSelectionInvalidated;
     bool m_bGraphicViewSelectionInvalidated;
@@ -971,6 +973,15 @@ public:
           m_bTilesInvalidated(false),
           m_bViewSelectionSet(false)
     {
+        mpViewShell = SfxViewShell::Current();
+        mpViewShell->registerLibreOfficeKitViewCallback(&ViewCallback::callback, this);
+        mnView = SfxLokHelper::getView();
+    }
+
+    ~ViewCallback()
+    {
+        SfxLokHelper::setView(mnView);
+        mpViewShell->registerLibreOfficeKitViewCallback(nullptr, nullptr);
     }
 
     static void callback(int nType, const char* pPayload, void* pData)
@@ -1057,10 +1068,8 @@ void SdTiledRenderingTest::testViewCursors()
     // Create two views.
     SdXImpressDocument* pXImpressDocument = createDoc("shape.odp");
     ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
     SfxLokHelper::createView();
     ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
 
     // Select the shape in the second view.
     sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
@@ -1074,8 +1083,6 @@ void SdTiledRenderingTest::testViewCursors()
     CPPUNIT_ASSERT(aView1.m_bGraphicViewSelectionInvalidated);
     // Second view notices that there was a selection change in its own view.
     CPPUNIT_ASSERT(aView2.m_bGraphicSelectionInvalidated);
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 void SdTiledRenderingTest::testViewCursorParts()
@@ -1085,11 +1092,9 @@ void SdTiledRenderingTest::testViewCursorParts()
     // Create two views.
     SdXImpressDocument* pXImpressDocument = createDoc("shape.odp");
     ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
     SfxLokHelper::createView();
     pXImpressDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
     ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
 
     // Select the shape in the second view.
     sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
@@ -1113,9 +1118,6 @@ void SdTiledRenderingTest::testViewCursorParts()
     // First view ignores view selection, as it would be for part 1, and it's in part 0.
     // This failed when the "part" was always 0 in the callback.
     CPPUNIT_ASSERT(!aView1.m_bGraphicViewSelectionInvalidated);
-
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 void SdTiledRenderingTest::testCursorViews()
@@ -1124,9 +1126,8 @@ void SdTiledRenderingTest::testCursorViews()
 
     // Create the first view.
     SdXImpressDocument* pXImpressDocument = createDoc("title-shape.odp");
-    ViewCallback aView1;
     int nView1 = SfxLokHelper::getView();
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1;
 
     // Begin text edit on the only object on the slide.
     sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
@@ -1149,8 +1150,6 @@ void SdTiledRenderingTest::testCursorViews()
     // second view as well, even if the second view was created after begin
     // text edit in the first view.
     ViewCallback aView2;
-    aView2.m_bViewLock = false;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
     // This failed: the second view didn't get a lock notification, even if the
     // first view already started text edit.
     CPPUNIT_ASSERT(aView2.m_bViewLock);
@@ -1162,9 +1161,6 @@ void SdTiledRenderingTest::testCursorViews()
     // This failed: the second view was not invalidated when pressing a key in
     // the first view.
     CPPUNIT_ASSERT(aView2.m_bTilesInvalidated);
-
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 void SdTiledRenderingTest::testViewLock()
@@ -1174,7 +1170,6 @@ void SdTiledRenderingTest::testViewLock()
     // Load a document that has a shape and create two views.
     SdXImpressDocument* pXImpressDocument = createDoc("shape.odp");
     ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
     SfxLokHelper::createView();
     pXImpressDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
 
@@ -1192,9 +1187,6 @@ void SdTiledRenderingTest::testViewLock()
     // the first view.
     pView->SdrEndTextEdit();
     CPPUNIT_ASSERT(!aView1.m_bViewLock);
-
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 void SdTiledRenderingTest::testUndoLimiting()
@@ -1247,7 +1239,6 @@ void SdTiledRenderingTest::testCreateViewGraphicSelection()
     // Load a document and register a callback.
     SdXImpressDocument* pXImpressDocument = createDoc("shape.odp");
     ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
 
     // Select the only shape in the document and assert that the graphic selection is changed.
     sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
@@ -1269,14 +1260,9 @@ void SdTiledRenderingTest::testCreateViewGraphicSelection()
     // Check that when the first view has a shape selected and we register a
     // callback on the second view, then it gets a "graphic view selection".
     ViewCallback aView2;
-    aView2.m_bGraphicViewSelectionInvalidated = false;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
     // This failed, the created new view had no "view selection" of the first
     // view's selected shape.
     CPPUNIT_ASSERT(aView2.m_bGraphicViewSelectionInvalidated);
-
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 void SdTiledRenderingTest::testCreateViewTextCursor()
@@ -1286,7 +1272,6 @@ void SdTiledRenderingTest::testCreateViewTextCursor()
     // Load a document and register a callback.
     SdXImpressDocument* pXImpressDocument = createDoc("title-shape.odp");
     ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
 
     // Begin text edit.
     pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::TAB);
@@ -1311,8 +1296,6 @@ void SdTiledRenderingTest::testCreateViewTextCursor()
     SfxLokHelper::createView();
     pXImpressDocument->initializeForTiledRendering({});
     ViewCallback aView2;
-    aView2.m_bViewSelectionSet = false;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
     bool bFoundCursor = false;
     for (const auto& rInvalidation : aView1.m_aViewCursorInvalidations)
     {
@@ -1330,9 +1313,6 @@ void SdTiledRenderingTest::testCreateViewTextCursor()
     // This failed: the text view selection of the first view wasn't seen by
     // the second view.
     CPPUNIT_ASSERT(aView2.m_bViewSelectionSet);
-
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 void SdTiledRenderingTest::testTdf102223()
@@ -1383,7 +1363,6 @@ void SdTiledRenderingTest::testPostKeyEventInvalidation()
     SdXImpressDocument* pXImpressDocument = createDoc("2slides.odp");
     CPPUNIT_ASSERT_EQUAL(0, pXImpressDocument->getPart());
     ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
     sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
     SdrView* pView = pViewShell->GetView();
     pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
@@ -1397,7 +1376,6 @@ void SdTiledRenderingTest::testPostKeyEventInvalidation()
     SfxLokHelper::createView();
     pXImpressDocument->initializeForTiledRendering({});
     ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
     pXImpressDocument->setPart(1);
     sd::ViewShell* pViewShell2 = pXImpressDocument->GetDocShell()->GetViewShell();
     SdrView* pView2 = pViewShell2->GetView();
@@ -1416,9 +1394,6 @@ void SdTiledRenderingTest::testPostKeyEventInvalidation()
     Scheduler::ProcessEventsToIdle();
     // This failed: moving the cursor caused unexpected invalidation.
     CPPUNIT_ASSERT(!aView2.m_bTilesInvalidated);
-
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 /**
@@ -1646,7 +1621,6 @@ void SdTiledRenderingTest::testCommentCallbacks()
     }));
     ViewCallback aView1;
     int nView1 = SfxLokHelper::getView();
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
 
     SfxLokHelper::createView();
     uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
@@ -1655,7 +1629,6 @@ void SdTiledRenderingTest::testCommentCallbacks()
     }));
     pXImpressDocument->initializeForTiledRendering(aArgs);
     ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
     int nView2 = SfxLokHelper::getView();
 
     SfxLokHelper::setView(nView1);
@@ -1742,9 +1715,6 @@ void SdTiledRenderingTest::testCommentCallbacks()
     CPPUNIT_ASSERT_EQUAL(nComment1, aView1.m_aCommentCallbackResult.get<int>("id"));
     CPPUNIT_ASSERT_EQUAL(nComment1, aView2.m_aCommentCallbackResult.get<int>("id"));
 
-    mxComponent->dispose();
-    mxComponent.clear();
-
     comphelper::LibreOfficeKit::setTiledAnnotations(true);
 }
 
@@ -1755,7 +1725,6 @@ void SdTiledRenderingTest::testMultiViewInsertDeletePage()
     SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp");
     ViewCallback aView1;
     int nView1 = SfxLokHelper::getView();
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
     uno::Sequence<beans::PropertyValue> aArgs;
     SdDrawDocument* pDoc = pXImpressDocument->GetDocShell()->GetDoc();
 
@@ -1763,7 +1732,6 @@ void SdTiledRenderingTest::testMultiViewInsertDeletePage()
     SfxLokHelper::createView();
     pXImpressDocument->initializeForTiledRendering(aArgs);
     ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
     int nView2 = SfxLokHelper::getView();
 
     // the document has 8 slides
@@ -1789,9 +1757,6 @@ void SdTiledRenderingTest::testMultiViewInsertDeletePage()
     // See if current slide number changed in 2nd view too
     SfxLokHelper::setView(nView2);
     CPPUNIT_ASSERT_EQUAL(4, pXImpressDocument->getPart());
-
-    mxComponent->dispose();
-    mxComponent.clear();
 }
 
 void SdTiledRenderingTest::testDisableUndoRepair()
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 7fefaa2cf2cc..f5814504c16c 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -712,6 +712,8 @@ void SwTiledRenderingTest::testPartHash()
 /// A view callback tracks callbacks invoked on one specific view.
 class ViewCallback
 {
+    SfxViewShell* mpViewShell;
+    int mnView;
 public:
     bool m_bOwnCursorInvalidated;
     int m_nOwnCursorInvalidatedBy;
@@ -734,7 +736,7 @@ public:
     /// Redline table modified payload
     boost::property_tree::ptree m_aRedlineTableModified;
 
-    ViewCallback()
+    ViewCallback(SfxViewShell* pViewShell, std::function<void(ViewCallback&)> const & rBeforeInstallFunc = {})
         : m_bOwnCursorInvalidated(false),
           m_nOwnCursorInvalidatedBy(-1),
           m_bOwnCursorAtOrigin(false),
@@ -748,6 +750,19 @@ public:
           m_bViewLock(false),
           m_bCalled(false)
     {
+        // Because one call-site wants to set the bool fields up before the callback is installed
+        if (rBeforeInstallFunc)
+            rBeforeInstallFunc(*this);
+
+        mpViewShell = pViewShell;
+        mpViewShell->registerLibreOfficeKitViewCallback(&ViewCallback::callback, this);
+        mnView = SfxLokHelper::getView();
+    }
+
+    ~ViewCallback()
+    {
+        SfxLokHelper::setView(mnView);
+        mpViewShell->registerLibreOfficeKitViewCallback(nullptr, nullptr);
     }
 
     static void callback(int nType, const char* pPayload, void* pData)
@@ -899,12 +914,10 @@ void SwTiledRenderingTest::testMissingInvalidation()
 
     // Create two views.
     SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
     int nView1 = SfxLokHelper::getView();
     SfxLokHelper::createView();
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
     int nView2 = SfxLokHelper::getView();
 
     // First view: put the cursor into the first word.
@@ -927,11 +940,6 @@ void SwTiledRenderingTest::testMissingInvalidation()
     Scheduler::ProcessEventsToIdle();
     CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
     CPPUNIT_ASSERT(aView2.m_bTilesInvalidated);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testViewCursors()
@@ -939,13 +947,9 @@ void SwTiledRenderingTest::testViewCursors()
     comphelper::LibreOfficeKit::setActive();
 
     SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
-    int nView1 = SfxLokHelper::getView();
+    ViewCallback aView1(SfxViewShell::Current());
     SfxLokHelper::createView();
-    int nView2 = SfxLokHelper::getView();
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
     CPPUNIT_ASSERT(aView1.m_bOwnCursorInvalidated);
     CPPUNIT_ASSERT(aView1.m_bViewCursorInvalidated);
     CPPUNIT_ASSERT(aView2.m_bOwnCursorInvalidated);
@@ -973,11 +977,6 @@ void SwTiledRenderingTest::testViewCursors()
     CPPUNIT_ASSERT(aView1.m_bViewSelectionSet);
     CPPUNIT_ASSERT(aView2.m_bOwnSelectionSet);
     CPPUNIT_ASSERT(!aView2.m_bViewSelectionSet);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testShapeViewCursors()
@@ -986,14 +985,10 @@ void SwTiledRenderingTest::testShapeViewCursors()
 
     // Load a document and create a view, so we have 2 ones.
     SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
-    int nView1 = SfxLokHelper::getView();
+    ViewCallback aView1(SfxViewShell::Current());
     SfxLokHelper::createView();
-    int nView2 = SfxLokHelper::getView();
-    ViewCallback aView2;
     pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
     SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell();
 
     // Start shape text in the second view.
@@ -1021,11 +1016,6 @@ void SwTiledRenderingTest::testShapeViewCursors()
     CPPUNIT_ASSERT(aView1.m_bViewCursorInvalidated && aLastViewCursor1 != aView1.m_aViewCursor);
     CPPUNIT_ASSERT(aView2.m_bOwnCursorInvalidated && aLastOwnCursor2 != aView2.m_aOwnCursor);
     CPPUNIT_ASSERT_EQUAL(aLastViewCursor2, aView2.m_aViewCursor);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testViewCursorVisibility()
@@ -1034,14 +1024,10 @@ void SwTiledRenderingTest::testViewCursorVisibility()
 
     // Load a document that has a shape and create two views.
     SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
-    int nView1 = SfxLokHelper::getView();
+    ViewCallback aView1(SfxViewShell::Current());
     SfxLokHelper::createView();
-    int nView2 = SfxLokHelper::getView();
     pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
     // This failed, initially the view cursor in the second view wasn't visible.
     CPPUNIT_ASSERT(aView2.m_bViewCursorVisible);
 
@@ -1056,11 +1042,6 @@ void SwTiledRenderingTest::testViewCursorVisibility()
     Scheduler::ProcessEventsToIdle();
     // Make sure the "view/text" cursor of the first view gets a notification.
     CPPUNIT_ASSERT(!aView1.m_bViewCursorVisible);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testViewCursorCleanup()
@@ -1069,37 +1050,30 @@ void SwTiledRenderingTest::testViewCursorCleanup()
 
     // Load a document that has a shape and create two views.
     SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
-    int nView1 = SfxLokHelper::getView();
+    ViewCallback aView1(SfxViewShell::Current());
     int nView2 = SfxLokHelper::createView();
     pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
-
-    // Click on the shape in the second view.
-    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
-    SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    SdrObject* pObject = pPage->GetObj(0);
-    Point aCenter = pObject->GetSnapRect().Center();
-    aView1.m_bGraphicViewSelection = false;
-    pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aCenter.getX(), aCenter.getY(), 1, MOUSE_LEFT, 0);
-    pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, aCenter.getX(), aCenter.getY(), 1, MOUSE_LEFT, 0);
-    Scheduler::ProcessEventsToIdle();
-    // Make sure there is a graphic view selection on the first view.
-    CPPUNIT_ASSERT(aView1.m_bGraphicViewSelection);
-
+    {
+        ViewCallback aView2(SfxViewShell::Current());
+
+        // Click on the shape in the second view.
+        SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+        SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+        SdrObject* pObject = pPage->GetObj(0);
+        Point aCenter = pObject->GetSnapRect().Center();
+        aView1.m_bGraphicViewSelection = false;
+        pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aCenter.getX(), aCenter.getY(), 1, MOUSE_LEFT, 0);
+        pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, aCenter.getX(), aCenter.getY(), 1, MOUSE_LEFT, 0);
+        Scheduler::ProcessEventsToIdle();
+        // Make sure there is a graphic view selection on the first view.
+        CPPUNIT_ASSERT(aView1.m_bGraphicViewSelection);
+    }
     // Now destroy the second view.
     SfxLokHelper::destroyView(nView2);
     Scheduler::ProcessEventsToIdle();
     CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(1), SfxLokHelper::getViewsCount());
     // Make sure that the graphic view selection on the first view is cleaned up.
     CPPUNIT_ASSERT(!aView1.m_bGraphicViewSelection);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testViewLock()
@@ -1108,13 +1082,10 @@ void SwTiledRenderingTest::testViewLock()
 
     // Load a document that has a shape and create two views.
     SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
-    int nView1 = SfxLokHelper::getView();
-    int nView2 = SfxLokHelper::createView();
+    ViewCallback aView1(SfxViewShell::Current());
+    SfxLokHelper::createView();
     pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
 
     // Begin text edit in the second view and assert that the first gets a lock
     // notification.
@@ -1130,11 +1101,6 @@ void SwTiledRenderingTest::testViewLock()
     // the first view.
     pWrtShell->EndTextEdit();
     CPPUNIT_ASSERT(!aView1.m_bViewLock);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testTextEditViewInvalidations()
@@ -1142,13 +1108,10 @@ void SwTiledRenderingTest::testTextEditViewInvalidations()
     // Load a document that has a shape and create two views.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
-    int nView1 = SfxLokHelper::getView();
-    int nView2 = SfxLokHelper::createView();
+    ViewCallback aView1(SfxViewShell::Current());
+    SfxLokHelper::createView();
     pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
 
     // Begin text edit in the second view.
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
@@ -1169,11 +1132,6 @@ void SwTiledRenderingTest::testTextEditViewInvalidations()
     CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
 
     pWrtShell->EndTextEdit();
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testUndoInvalidations()
@@ -1181,14 +1139,11 @@ void SwTiledRenderingTest::testUndoInvalidations()
     // Load a document and create two views.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
     int nView1 = SfxLokHelper::getView();
     SfxLokHelper::createView();
     pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
-    int nView2 = SfxLokHelper::getView();
+    ViewCallback aView2(SfxViewShell::Current());
     SfxLokHelper::setView(nView1);
 
     // Insert a character the end of the document.
@@ -1210,11 +1165,6 @@ void SwTiledRenderingTest::testUndoInvalidations()
     CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
     // Undo was dispatched on the first view, this second view was not invalidated.
     CPPUNIT_ASSERT(aView2.m_bTilesInvalidated);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testUndoLimiting()
@@ -1397,8 +1347,7 @@ void SwTiledRenderingTest::testShapeTextUndoGroupShells()
     // Load a document and create a view.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
     sal_Int32 nView1 = SfxLokHelper::getView();
 
     // Begin text edit.
@@ -1431,13 +1380,9 @@ void SwTiledRenderingTest::testShapeTextUndoGroupShells()
 
     // Create a second view, and make sure that the new view sees the same
     // cursor position as the old one.
-    int nView2 = SfxLokHelper::createView();
+    SfxLokHelper::createView();
     pXTextDocument->initializeForTiledRendering({});
-    ViewCallback aView2;
-    aView2.m_aViewCursor = tools::Rectangle();
-    aView2.m_bViewSelectionSet = false;
-    aView2.m_bViewLock = false;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
     // Difference was 935 twips, the new view didn't see the editeng cursor of
     // the old one. The new difference should be <1px, but here we deal with twips.
     CPPUNIT_ASSERT(std::abs(aView1.m_aOwnCursor.Top() - aView2.m_aViewCursor.Top()) < 10);
@@ -1447,11 +1392,6 @@ void SwTiledRenderingTest::testShapeTextUndoGroupShells()
     // This was false, the new view wasn't aware of the shape text lock created
     // by the old view.
     CPPUNIT_ASSERT(aView2.m_bViewLock);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testTrackChanges()
@@ -1463,9 +1403,8 @@ void SwTiledRenderingTest::testTrackChanges()
     // Turn on track changes, type "zzz" at the end, and move to the start.
     uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY);
     xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true));
-    ViewCallback aView;
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
-    pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView);
+    ViewCallback aView(pWrtShell->GetSfxViewShell());
     pWrtShell->EndOfSection();
     pWrtShell->Insert("zzz");
     pWrtShell->StartOfSection();
@@ -1563,10 +1502,9 @@ void SwTiledRenderingTest::testSetViewGraphicSelection()
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc("frame.odt");
     int nView1 = SfxLokHelper::getView();
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
     // Create a second view, and switch back to the first view.
-    int nView2 = SfxLokHelper::createView();
+    SfxLokHelper::createView();
     pXTextDocument->initializeForTiledRendering({});
     SfxLokHelper::setView(nView1);
 
@@ -1582,11 +1520,6 @@ void SwTiledRenderingTest::testSetViewGraphicSelection()
     pWrtShell->ShellLoseFocus();
     // This failed, mark handles were hidden in the first view.
     CPPUNIT_ASSERT(!pView->areMarkHandlesHidden());
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testCreateViewGraphicSelection()
@@ -1594,8 +1527,7 @@ void SwTiledRenderingTest::testCreateViewGraphicSelection()
     // Load a document.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc("frame.odt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
 
     // Mark the textframe in the first view.
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
@@ -1608,28 +1540,20 @@ void SwTiledRenderingTest::testCreateViewGraphicSelection()
     CPPUNIT_ASSERT(aView1.m_bGraphicSelection);
 
     // Create a second view.
-    int nView1 = SfxLokHelper::getView();
-    int nView2 = SfxLokHelper::createView();
+    SfxLokHelper::createView();
     // This was false, creating a second view cleared the selection of the
     // first one.
     CPPUNIT_ASSERT(aView1.m_bGraphicSelection);
 
     // Make sure that the hidden text cursor isn't visible in the second view, either.
-    ViewCallback aView2;
-    aView2.m_bViewCursorVisible = true;
-    aView2.m_bGraphicViewSelection = false;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current(),
+        [](ViewCallback& rView) { rView.m_bViewCursorVisible = true; });
     // This was true, the second view didn't get the visibility of the text
     // cursor of the first view.
     CPPUNIT_ASSERT(!aView2.m_bViewCursorVisible);
     // This was false, the second view didn't get the graphic selection of the
     // first view.
     CPPUNIT_ASSERT(aView2.m_bGraphicViewSelection);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testCreateViewTextSelection()
@@ -1637,8 +1561,7 @@ void SwTiledRenderingTest::testCreateViewTextSelection()
     // Load a document.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
 
     // Create a text selection:
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
@@ -1651,20 +1574,12 @@ void SwTiledRenderingTest::testCreateViewTextSelection()
     CPPUNIT_ASSERT_EQUAL(OUString("bbb"), pShellCursor->GetText());
 
     // Create a second view.
-    int nView1 = SfxLokHelper::getView();
-    int nView2 = SfxLokHelper::createView();
+    SfxLokHelper::createView();
 
     // Make sure that the text selection is visible in the second view.
-    ViewCallback aView2;
-    aView2.m_bViewSelectionSet = true;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
     // This failed, the second view didn't get the text selection of the first view.
     CPPUNIT_ASSERT(!aView2.m_aViewSelection.isEmpty());
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testRedlineColors()
@@ -1693,8 +1608,7 @@ void SwTiledRenderingTest::testCommentEndTextEdit()
     // Create a document, type a character and remember the cursor position.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc();
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
     pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
     pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
     Scheduler::ProcessEventsToIdle();
@@ -1732,25 +1646,17 @@ void SwTiledRenderingTest::testCursorPosition()
     // Load a document and register a callback, should get an own cursor.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc();
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
 
     // Crete a second view, so the first view gets a collaborative cursor.
-    int nView1 = SfxLokHelper::getView();
-    int nView2 = SfxLokHelper::createView();
+    SfxLokHelper::createView();
     pXTextDocument->initializeForTiledRendering({});
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
 
     // Make sure the two are exactly the same.
     // This failed, own cursor was at '1418, 1418', collaborative cursor was at
     // '1425, 1425', due to pixel alignment.
     CPPUNIT_ASSERT_EQUAL(aView1.m_aOwnCursor.toString(), aView1.m_aViewCursor.toString());
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testPaintCallbacks()
@@ -1761,12 +1667,10 @@ void SwTiledRenderingTest::testPaintCallbacks()
     // Load a document and register a callback for the first view.
     comphelper::LibreOfficeKit::setActive();
     SwXTextDocument* pXTextDocument = createDoc();
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
-    int nView1 = SfxLokHelper::getView();
+    ViewCallback aView1(SfxViewShell::Current());
 
     // Create a second view and paint a tile on that second view.
-    int nView2 = SfxLokHelper::createView();
+    SfxLokHelper::createView();
     int nCanvasWidth = 256;
     int nCanvasHeight = 256;
     std::vector<unsigned char> aBuffer(nCanvasWidth * nCanvasHeight * 4);
@@ -1777,14 +1681,6 @@ void SwTiledRenderingTest::testPaintCallbacks()
     aView1.m_bCalled = false;
     pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/0, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
     CPPUNIT_ASSERT(!aView1.m_bCalled);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testUndoRepairResult()
@@ -1889,12 +1785,12 @@ void SwTiledRenderingTest::testDisableUndoRepair()
 
     // Create two views.
     SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
-    ViewCallback aView1;
+    ViewCallback aView1(SfxViewShell::Current());
     SwView* pView1 = dynamic_cast<SwView*>(SfxViewShell::Current());
     CPPUNIT_ASSERT(pView1);
     int nView1 = SfxLokHelper::getView();
     SfxLokHelper::createView();
-    ViewCallback aView2;
+    ViewCallback aView2(SfxViewShell::Current());
     SwView* pView2 = dynamic_cast<SwView*>(SfxViewShell::Current());
     CPPUNIT_ASSERT(pView2);
     int nView2 = SfxLokHelper::getView();
@@ -1942,11 +1838,6 @@ void SwTiledRenderingTest::testDisableUndoRepair()
     pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'l', 0);
     Scheduler::ProcessEventsToIdle();
     checkUndoRepairStates(pXTextDocument, pView1, pView2);
-
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testAllTrackedChanges()
@@ -2362,14 +2253,12 @@ void SwTiledRenderingTest::testVisCursorInvalidation()
     comphelper::LibreOfficeKit::setActive();
 
     SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
-    ViewCallback aView1;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+    ViewCallback aView1(SfxViewShell::Current());
     int nView1 = SfxLokHelper::getView();
 
     SfxLokHelper::createView();
     int nView2 = SfxLokHelper::getView();
-    ViewCallback aView2;
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    ViewCallback aView2(SfxViewShell::Current());
     Scheduler::ProcessEventsToIdle();
 
 
@@ -2430,10 +2319,6 @@ void SwTiledRenderingTest::testVisCursorInvalidation()
     CPPUNIT_ASSERT_EQUAL(nView2, aView2.m_nOwnCursorInvalidatedBy);
 
     comphelper::LibreOfficeKit::setViewIdForVisCursorInvalidation(false);
-    SfxLokHelper::setView(nView1);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
-    SfxLokHelper::setView(nView2);
-    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
 }
 
 void SwTiledRenderingTest::testDeselectCustomShape()


More information about the Libreoffice-commits mailing list