diff options
-rw-r--r-- | sw/inc/viscrs.hxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 37 | ||||
-rw-r--r-- | sw/source/core/crsr/crsrsh.cxx | 15 | ||||
-rw-r--r-- | sw/source/core/crsr/viscrs.cxx | 15 |
4 files changed, 59 insertions, 10 deletions
diff --git a/sw/inc/viscrs.hxx b/sw/inc/viscrs.hxx index 6fd615f8ac3e..b1ec3052786f 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 142ca1092c2c..048ade6c634b 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -73,6 +73,7 @@ public: void testRedlineUpdateCallback(); void testSetViewGraphicSelection(); void testCreateViewGraphicSelection(); + void testCreateViewTextSelection(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -110,6 +111,7 @@ public: CPPUNIT_TEST(testRedlineUpdateCallback); CPPUNIT_TEST(testSetViewGraphicSelection); CPPUNIT_TEST(testCreateViewGraphicSelection); + CPPUNIT_TEST(testCreateViewTextSelection); CPPUNIT_TEST_SUITE_END(); private: @@ -604,6 +606,7 @@ public: bool m_bViewCursorInvalidated; bool m_bOwnSelectionSet; bool m_bViewSelectionSet; + OString m_aViewSelection; bool m_bTilesInvalidated; bool m_bViewCursorVisible; bool m_bGraphicViewSelection; @@ -656,6 +659,7 @@ public: case LOK_CALLBACK_TEXT_VIEW_SELECTION: { m_bViewSelectionSet = true; + m_aViewSelection = aPayload; } break; case LOK_CALLBACK_VIEW_CURSOR_VISIBLE: @@ -1310,6 +1314,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 d0da7829cb09..72ed33c446d6 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -1226,7 +1226,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 @@ -1243,7 +1246,7 @@ bool SwCursorShell::GoNextCursor() if( !ActionPend() ) { UpdateCursor(); - m_pCurrentCursor->Show(); + m_pCurrentCursor->Show(nullptr); } return true; } @@ -1262,7 +1265,7 @@ bool SwCursorShell::GoPrevCursor() if( !ActionPend() ) { UpdateCursor(); - m_pCurrentCursor->Show(); + m_pCurrentCursor->Show(nullptr); } return true; } @@ -1294,7 +1297,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 ); @@ -1586,7 +1589,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()); @@ -2137,7 +2140,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(); @@ -2414,7 +2417,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 126df5fab78f..4ac52fbb1612 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()) @@ -621,8 +621,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); + } } } |