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

Miklos Vajna vmiklos at collabora.co.uk
Mon Sep 12 18:08:12 UTC 2016


 sw/inc/viscrs.hxx                              |    2 -
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   37 +++++++++++++++++++++++++
 sw/source/core/crsr/crsrsh.cxx                 |   15 ++++++----
 sw/source/core/crsr/viscrs.cxx                 |   15 ++++++++--
 4 files changed, 59 insertions(+), 10 deletions(-)

New commits:
commit c4224e6cafa5aa5c604dfdc0daf7f145aa6c08be
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 12 17:05:10 2016 +0200

    sw: emit LOK_CALLBACK_TEXT_VIEW_SELECTION as part of registerCallback()
    
    Have a Writer text selection in the first view, create a new view, the
    second view doesn't see the selection. But the same works if the text
    selection is created when the second view was created earlier.
    
    Emit the selection state as part of SwCursorShell::NotifyCursor() to fix
    the problem.
    
    Change-Id: I7d71c9b58941c8ca8720b0e63e54bc757b1aaf61
    Reviewed-on: https://gerrit.libreoffice.org/28844
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sw/inc/viscrs.hxx b/sw/inc/viscrs.hxx
index 3635048..04ae4e5 100644
--- a/sw/inc/viscrs.hxx
+++ b/sw/inc/viscrs.hxx
@@ -137,7 +137,7 @@ public:
     /// @see SwSelPaintRects::FillStartEnd(), override for text selections.
     virtual void FillStartEnd(SwRect& rStart, SwRect& rEnd) const override;
 
-    void Show();            // Update and display all selections.
+    void Show(SfxViewShell* pViewShell); // Update and display all selections.
     void Hide();            // Hide all selections.
     void Invalidate( const SwRect& rRect );
 
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 49578f1..e61f23f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -72,6 +72,7 @@ public:
     void testRedlineUpdateCallback();
     void testSetViewGraphicSelection();
     void testCreateViewGraphicSelection();
+    void testCreateViewTextSelection();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -109,6 +110,7 @@ public:
     CPPUNIT_TEST(testRedlineUpdateCallback);
     CPPUNIT_TEST(testSetViewGraphicSelection);
     CPPUNIT_TEST(testCreateViewGraphicSelection);
+    CPPUNIT_TEST(testCreateViewTextSelection);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -603,6 +605,7 @@ public:
     bool m_bViewCursorInvalidated;
     bool m_bOwnSelectionSet;
     bool m_bViewSelectionSet;
+    OString m_aViewSelection;
     bool m_bTilesInvalidated;
     bool m_bViewCursorVisible;
     bool m_bGraphicViewSelection;
@@ -655,6 +658,7 @@ public:
         case LOK_CALLBACK_TEXT_VIEW_SELECTION:
         {
             m_bViewSelectionSet = true;
+            m_aViewSelection = aPayload;
         }
         break;
         case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
@@ -1309,6 +1313,39 @@ void SwTiledRenderingTest::testCreateViewGraphicSelection()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void SwTiledRenderingTest::testCreateViewTextSelection()
+{
+    // Load a document.
+    comphelper::LibreOfficeKit::setActive();
+    SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
+    ViewCallback aView1;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+
+    // Create a text selection:
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    // Move the cursor into the second word.
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 5, /*bBasicCall=*/false);
+    // Create a selection on the word.
+    pWrtShell->SelWrd();
+    SwShellCursor* pShellCursor = pWrtShell->getShellCursor(false);
+    // Did we indeed manage to select the second word?
+    CPPUNIT_ASSERT_EQUAL(OUString("bbb"), pShellCursor->GetText());
+
+    // Create a second view.
+    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);
+    // This failed, the second view didn't get the text selection of the first view.
+    CPPUNIT_ASSERT(!aView2.m_aViewSelection.isEmpty());
+
+    mxComponent->dispose();
+    mxComponent.clear();
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 2ed6187..bfa0bc0 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1194,7 +1194,10 @@ OUString SwCursorShell::getPageRectangles()
 
 void SwCursorShell::NotifyCursor(SfxViewShell* pViewShell) const
 {
+    // Cursor position and visibility.
     m_pVisibleCursor->SetPosAndShow(pViewShell);
+    // Text selection.
+    m_pCurrentCursor->Show(pViewShell);
 }
 
 /// go to the next SSelection
@@ -1211,7 +1214,7 @@ bool SwCursorShell::GoNextCursor()
     if( !ActionPend() )
     {
         UpdateCursor();
-        m_pCurrentCursor->Show();
+        m_pCurrentCursor->Show(nullptr);
     }
     return true;
 }
@@ -1230,7 +1233,7 @@ bool SwCursorShell::GoPrevCursor()
     if( !ActionPend() )
     {
         UpdateCursor();
-        m_pCurrentCursor->Show();
+        m_pCurrentCursor->Show(nullptr);
     }
     return true;
 }
@@ -1262,7 +1265,7 @@ void SwCursorShell::Paint(vcl::RenderContext& rRenderContext, const Rectangle &r
         {
             // so that right/bottom borders will not be cropped
             pAktCursor->Invalidate( VisArea() );
-            pAktCursor->Show();
+            pAktCursor->Show(nullptr);
         }
         else
             pAktCursor->Invalidate( aRect );
@@ -1554,7 +1557,7 @@ void SwCursorShell::UpdateCursor( sal_uInt16 eFlags, bool bIdleEnd )
             if( m_pTableCursor->IsCursorMovedUpdate() )
                 GetLayout()->MakeTableCursors( *m_pTableCursor );
             if( m_bHasFocus && !m_bBasicHideCursor )
-                m_pTableCursor->Show();
+                m_pTableCursor->Show(nullptr);
 
             // set Cursor-Points to the new Positions
             m_pTableCursor->GetPtPos().setX(m_aCharRect.Left());
@@ -2105,7 +2108,7 @@ void SwCursorShell::ShowCursors( bool bCursorVis )
 
     SET_CURR_SHELL( this );
     SwShellCursor* pAktCursor = m_pTableCursor ? m_pTableCursor : m_pCurrentCursor;
-    pAktCursor->Show();
+    pAktCursor->Show(nullptr);
 
     if( m_bSVCursorVis && bCursorVis ) // also show SV cursor again
         m_pVisibleCursor->Show();
@@ -2380,7 +2383,7 @@ bool SwCursorShell::SetVisibleCursor( const Point &rPt )
     if( IsScrollMDI( this, m_aCharRect ))
     {
         MakeVisible( m_aCharRect );
-        m_pCurrentCursor->Show();
+        m_pCurrentCursor->Show(nullptr);
     }
 
     {
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index e78c718..531ab88 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -600,7 +600,7 @@ void SwShellCursor::FillRects()
         GetShell()->GetLayout()->CalcFrameRects( *this );
 }
 
-void SwShellCursor::Show()
+void SwShellCursor::Show(SfxViewShell* pViewShell)
 {
     std::vector<OString> aSelectionRectangles;
     for(SwPaM& rPaM : GetRingContainer())
@@ -620,8 +620,17 @@ void SwShellCursor::Show()
             aRect.push_back(rSelectionRectangle);
         }
         OString sRect = comphelper::string::join("; ", aRect);
-        GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
-        SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
+        if (pViewShell)
+        {
+            // Just notify pViewShell about our existing selection.
+            if (pViewShell != GetShell()->GetSfxViewShell())
+                SfxLokHelper::notifyOtherView(GetShell()->GetSfxViewShell(), pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
+        }
+        else
+        {
+            GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
+            SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list