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

Miklos Vajna vmiklos at collabora.co.uk
Wed Aug 10 14:24:09 UTC 2016


 sfx2/source/view/lokhelper.cxx                 |   10 ++++++
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   37 +++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

New commits:
commit d6e8d4f773d970b69baedd8523a426f18a8d8eef
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Aug 10 15:51:51 2016 +0200

    sfx2: make SfxLokHelper::setView() set also the active frame
    
    Without this, comphelper::dispatchCommand() doesn't work on the current
    frame. This causes e.g. undo not working when only a given view is
    allowed to do undo.
    
    In the desktop case vcl::Window::ImplGrabFocus() calls both
    SfxViewFrame::MakeActive_Impl() and
    framework::Desktop::setActiveFrame(), but in the LOK case the first was
    called directly, that's how the active frame was outdated.
    
    Change-Id: If97a9de316b4c8dd49e55cd273bdb2dfe9866f38
    Reviewed-on: https://gerrit.libreoffice.org/28032
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 856a007..4113160 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -11,12 +11,17 @@
 
 #include <boost/property_tree/json_parser.hpp>
 
+#include <com/sun/star/frame/Desktop.hpp>
+
+#include <comphelper/processfactory.hxx>
 #include <sfx2/viewsh.hxx>
 #include <sfx2/request.hxx>
 #include <sfx2/viewfrm.hxx>
 
 #include <shellimpl.hxx>
 
+using namespace com::sun::star;
+
 int SfxLokHelper::createView()
 {
     SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
@@ -59,6 +64,11 @@ void SfxLokHelper::setView(int nId)
 
             SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
             pViewFrame->MakeActive_Impl(false);
+
+            // Make comphelper::dispatchCommand() find the correct frame.
+            uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
+            uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(comphelper::getProcessComponentContext());
+            xDesktop->setActiveFrame(xFrame);
             return;
         }
     }
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 7662682..1219d01 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -61,6 +61,7 @@ public:
     void testTextEditViewInvalidations();
     void testUndoInvalidations();
     void testUndoLimiting();
+    void testUndoDispatch();
     void testShapeTextUndoShells();
     void testShapeTextUndoGroupShells();
 
@@ -89,6 +90,7 @@ public:
     CPPUNIT_TEST(testTextEditViewInvalidations);
     CPPUNIT_TEST(testUndoInvalidations);
     CPPUNIT_TEST(testUndoLimiting);
+    CPPUNIT_TEST(testUndoDispatch);
     CPPUNIT_TEST(testShapeTextUndoShells);
     CPPUNIT_TEST(testShapeTextUndoGroupShells);
     CPPUNIT_TEST_SUITE_END();
@@ -923,6 +925,41 @@ void SwTiledRenderingTest::testUndoLimiting()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void SwTiledRenderingTest::testUndoDispatch()
+{
+    // Load a document and create two views.
+    comphelper::LibreOfficeKit::setActive();
+    SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
+    int nView1 = SfxLokHelper::getView();
+    SfxLokHelper::createView();
+    pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+    int nView2 = SfxLokHelper::getView();
+
+    // Insert a character in the first view.
+    SfxLokHelper::setView(nView1);
+    pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'c', 0);
+    pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0);
+
+    // Click before the first word in the second view.
+    SfxLokHelper::setView(nView2);
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
+    Point aStart = pShellCursor->GetSttPos();
+    aStart.setX(aStart.getX() - 1000);
+    pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aStart.getX(), aStart.getY(), 1, MOUSE_LEFT, 0);
+    pXTextDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, aStart.getX(), aStart.getY(), 1, MOUSE_LEFT, 0);
+    uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(comphelper::getProcessComponentContext());
+    uno::Reference<frame::XFrame> xFrame2 = xDesktop->getActiveFrame();
+
+    // Now switch back to the first view, and make sure that the active frame is updated.
+    SfxLokHelper::setView(nView1);
+    uno::Reference<frame::XFrame> xFrame1 = xDesktop->getActiveFrame();
+    // This failed: setView() did not update the active frame.
+    CPPUNIT_ASSERT(xFrame1 != xFrame2);
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 void SwTiledRenderingTest::testShapeTextUndoShells()
 {
     // Load a document and create a view.


More information about the Libreoffice-commits mailing list