diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-08-22 21:45:44 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-09-01 09:25:35 +0200 |
commit | 2b026da90155b07c23becaacd493e1fcbab4a2d1 (patch) | |
tree | f5e298e301cd18a0b093576b266a645619848f63 | |
parent | move vector graphic search to View, so it works in multiple views (diff) | |
download | core-2b026da90155b07c23becaacd493e1fcbab4a2d1.tar.gz core-2b026da90155b07c23becaacd493e1fcbab4a2d1.zip |
sd: Make search bound to a view - to allow independent searching
Before if two windows are open, the search is not independent
because Outline class is not independent for a view (because of
FuSearch which remembers the view from when the it was created
and then an instance is stored in the DocShell).
This creates a SearchContext class stored on a View, which stores
the actual View bound FuSearch instance, fix us the calls.
Also move the VectorGraphicSearchContext back into Outline::Impl,
because it doesn't need to be bound to the view anymore.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101224
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 2ebc26aeefefe33ee6180862509e4971ff2dfc6f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101693
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 714767b3d521eefc46dd8158ee67610347863f9f)
Change-Id: I6a5ce71efafa378845eee4ac9574e2e4301138d2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101762
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | sd/source/ui/docshell/docshel3.cxx | 82 | ||||
-rw-r--r-- | sd/source/ui/docshell/docshell.cxx | 19 | ||||
-rw-r--r-- | sd/source/ui/func/fusearch.cxx | 9 | ||||
-rw-r--r-- | sd/source/ui/inc/DrawDocShell.hxx | 3 | ||||
-rw-r--r-- | sd/source/ui/inc/View.hxx | 32 | ||||
-rw-r--r-- | sd/source/ui/inc/fusearch.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/unoidl/DrawController.cxx | 6 | ||||
-rw-r--r-- | sd/source/ui/view/Outliner.cxx | 12 |
8 files changed, 108 insertions, 57 deletions
diff --git a/sd/source/ui/docshell/docshel3.cxx b/sd/source/ui/docshell/docshel3.cxx index 3d51bf023858..16dbcd36a5c3 100644 --- a/sd/source/ui/docshell/docshel3.cxx +++ b/sd/source/ui/docshell/docshel3.cxx @@ -175,30 +175,37 @@ void DrawDocShell::Execute( SfxRequest& rReq ) case FID_SEARCH_OFF: { - if( dynamic_cast< FuSearch* >(mxDocShellFunction.get()) ) + if (mpViewShell) { - // End Search&Replace in all docshells - SfxObjectShell* pFirstShell = SfxObjectShell::GetFirst(); - SfxObjectShell* pShell = pFirstShell; - - while (pShell) + sd::View* pView = mpViewShell->GetView(); + if (pView) { - if( dynamic_cast< const DrawDocShell *>( pShell ) != nullptr) + auto& rFunctionContext = pView->getSearchContext(); + rtl::Reference<FuSearch>& xFuSearch(rFunctionContext.getFunctionSearch()); + + if (xFuSearch.is()) { - static_cast<DrawDocShell*>(pShell)->CancelSearching(); - } + // End Search&Replace in all docshells + SfxObjectShell* pFirstShell = SfxObjectShell::GetFirst(); + SfxObjectShell* pShell = pFirstShell; - pShell = SfxObjectShell::GetNext(*pShell); + while (pShell) + { + auto pDrawDocShell = dynamic_cast<DrawDocShell*>(pShell); + if (pDrawDocShell) + pDrawDocShell->CancelSearching(); - if (pShell == pFirstShell) - { - pShell = nullptr; + pShell = SfxObjectShell::GetNext(*pShell); + + if (pShell == pFirstShell) + pShell = nullptr; + } + + rFunctionContext.resetSearchFunction(); + Invalidate(); + rReq.Done(); } } - - SetDocShellFunction(nullptr); - Invalidate(); - rReq.Done(); } } break; @@ -207,23 +214,30 @@ void DrawDocShell::Execute( SfxRequest& rReq ) { const SfxItemSet* pReqArgs = rReq.GetArgs(); - if ( pReqArgs ) + if (pReqArgs && mpViewShell) { - rtl::Reference< FuSearch > xFuSearch( dynamic_cast< FuSearch* >( GetDocShellFunction().get() ) ); - - if( !xFuSearch.is() && mpViewShell ) + sd::View* pView = mpViewShell->GetView(); + if (pView) { - ::sd::View* pView = mpViewShell->GetView(); - SetDocShellFunction( FuSearch::Create( mpViewShell, mpViewShell->GetActiveWindow(), pView, mpDoc, rReq ) ); - xFuSearch.set( dynamic_cast< FuSearch* >( GetDocShellFunction().get() ) ); - } + rtl::Reference<FuSearch> & xFuSearch = pView->getSearchContext().getFunctionSearch(); - if( xFuSearch.is() ) - { - const SvxSearchItem& rSearchItem = pReqArgs->Get(SID_SEARCH_ITEM); + if (!xFuSearch.is()) + { + xFuSearch = rtl::Reference<FuSearch>( + FuSearch::createPtr(mpViewShell, + mpViewShell->GetActiveWindow(), + pView, mpDoc, rReq)); + + pView->getSearchContext().setSearchFunction(xFuSearch); + } + + if (xFuSearch.is()) + { + const SvxSearchItem& rSearchItem = pReqArgs->Get(SID_SEARCH_ITEM); - SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(static_cast<SvxSearchItem*>( rSearchItem.Clone() ))); - xFuSearch->SearchAndReplace(&rSearchItem); + SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(static_cast<SvxSearchItem*>( rSearchItem.Clone() ))); + xFuSearch->SearchAndReplace(&rSearchItem); + } } } @@ -437,14 +451,6 @@ void DrawDocShell::Execute( SfxRequest& rReq ) } } -void DrawDocShell::SetDocShellFunction( const rtl::Reference<FuPoor>& xFunction ) -{ - if( mxDocShellFunction.is() ) - mxDocShellFunction->Dispose(); - - mxDocShellFunction = xFunction; -} - } // end of namespace sd /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/docshell/docshell.cxx b/sd/source/ui/docshell/docshell.cxx index 13e9dcd72771..b53cbc25e513 100644 --- a/sd/source/ui/docshell/docshell.cxx +++ b/sd/source/ui/docshell/docshell.cxx @@ -178,7 +178,15 @@ DrawDocShell::~DrawDocShell() mbInDestruction = true; - SetDocShellFunction(nullptr); + if (mpViewShell) + { + auto* pView = mpViewShell->GetView(); + if (pView) + { + auto & pSearchContext = pView->getSearchContext(); + pSearchContext.resetSearchFunction(); + } + } mpFontList.reset(); @@ -387,9 +395,14 @@ void DrawDocShell::UpdateTablePointers() void DrawDocShell::CancelSearching() { - if( dynamic_cast<FuSearch*>( mxDocShellFunction.get() ) ) + if (mpViewShell) { - SetDocShellFunction(nullptr); + auto* pView = mpViewShell->GetView(); + if (pView) + { + auto & pSearchContext = pView->getSearchContext(); + pSearchContext.resetSearchFunction(); + } } } diff --git a/sd/source/ui/func/fusearch.cxx b/sd/source/ui/func/fusearch.cxx index c0e0c95ff461..4cff72a07c80 100644 --- a/sd/source/ui/func/fusearch.cxx +++ b/sd/source/ui/func/fusearch.cxx @@ -63,13 +63,18 @@ FuSearch::FuSearch ( { } -rtl::Reference<FuPoor> FuSearch::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) +FuSearch* FuSearch::createPtr(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq) { - rtl::Reference<FuPoor> xFunc( new FuSearch( pViewSh, pWin, pView, pDoc, rReq ) ); + FuSearch* xFunc( new FuSearch( pViewSh, pWin, pView, pDoc, rReq ) ); xFunc->DoExecute(rReq); return xFunc; } +rtl::Reference<FuPoor> FuSearch::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) +{ + return rtl::Reference<FuPoor>(createPtr(pViewSh, pWin, pView, pDoc, rReq)); +} + void FuSearch::DoExecute( SfxRequest& ) { mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArraySpell ); diff --git a/sd/source/ui/inc/DrawDocShell.hxx b/sd/source/ui/inc/DrawDocShell.hxx index 84d6d277e40a..d41032ed4502 100644 --- a/sd/source/ui/inc/DrawDocShell.hxx +++ b/sd/source/ui/inc/DrawDocShell.hxx @@ -104,8 +104,6 @@ public: sd::ViewShell* GetViewShell() { return mpViewShell; } ::sd::FrameView* GetFrameView(); - const rtl::Reference<FuPoor>& GetDocShellFunction() const { return mxDocShellFunction; } - void SetDocShellFunction( const rtl::Reference<FuPoor>& xFunction ); SdDrawDocument* GetDoc() { return mpDoc;} DocumentType GetDocumentType() const { return meDocType; } @@ -209,7 +207,6 @@ protected: VclPtr<SfxPrinter> mpPrinter; ::sd::ViewShell* mpViewShell; std::unique_ptr<FontList> mpFontList; - rtl::Reference<FuPoor> mxDocShellFunction; DocumentType const meDocType; SfxStyleFamily mnStyleFamily; o3tl::array_view<sal_uInt16 const> diff --git a/sd/source/ui/inc/View.hxx b/sd/source/ui/inc/View.hxx index dc85e22d2b26..3dc1c6aae5fa 100644 --- a/sd/source/ui/inc/View.hxx +++ b/sd/source/ui/inc/View.hxx @@ -27,9 +27,9 @@ #include <svx/fmview.hxx> #include <svx/svdpage.hxx> #include <vcl/idle.hxx> -#include <VectorGraphicSearchContext.hxx> #include "smarttag.hxx" +#include "fusearch.hxx" class SdDrawDocument; class SdPage; @@ -67,6 +67,30 @@ public: void End(); }; +class SearchContext +{ +private: + rtl::Reference<FuSearch> maFunctionSearch; + +public: + rtl::Reference<FuSearch>& getFunctionSearch() + { + return maFunctionSearch; + } + + void setSearchFunction(rtl::Reference<FuSearch> const & xFunction) + { + resetSearchFunction(); + maFunctionSearch = xFunction; + } + + void resetSearchFunction() + { + if (maFunctionSearch.is()) + maFunctionSearch->Dispose(); + } +}; + class SAL_DLLPUBLIC_RTTI View : public FmFormView { public: @@ -221,8 +245,7 @@ public: void SetAuthor(const OUString& rAuthor) { m_sAuthor = rAuthor; } const OUString& GetAuthor() { return m_sAuthor; } - VectorGraphicSearchContext& getVectorGraphicSearchContext() { return aVectorGraphicSearchContext; } - + SearchContext& getSearchContext() { return maSearchContext; } protected: DECL_LINK( OnParagraphInsertedHdl, ::Outliner::ParagraphHdlParam, void ); DECL_LINK( OnParagraphRemovingHdl, ::Outliner::ParagraphHdlParam, void ); @@ -256,8 +279,7 @@ protected: private: ::std::unique_ptr<ViewClipboard> mpClipboard; OutlinerMasterViewFilter maMasterViewFilter; - - VectorGraphicSearchContext aVectorGraphicSearchContext; + SearchContext maSearchContext; OUString m_sAuthor; }; diff --git a/sd/source/ui/inc/fusearch.hxx b/sd/source/ui/inc/fusearch.hxx index 98351a25734b..1c4b94ca4431 100644 --- a/sd/source/ui/inc/fusearch.hxx +++ b/sd/source/ui/inc/fusearch.hxx @@ -32,6 +32,8 @@ class FuSearch final : public FuPoor public: static rtl::Reference<FuPoor> Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ); + static FuSearch* createPtr(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq); + virtual void DoExecute( SfxRequest& rReq ) override; void SearchAndReplace( const SvxSearchItem* pSearchItem ); diff --git a/sd/source/ui/unoidl/DrawController.cxx b/sd/source/ui/unoidl/DrawController.cxx index 8f7cd937efa4..c9d69de38ca0 100644 --- a/sd/source/ui/unoidl/DrawController.cxx +++ b/sd/source/ui/unoidl/DrawController.cxx @@ -140,9 +140,9 @@ void SAL_CALL DrawController::dispose() if ( pViewShell ) { pViewShell->DeactivateCurrentFunction(); - DrawDocShell* pDocShell = pViewShell->GetDocSh(); - if ( pDocShell != nullptr ) - pDocShell->SetDocShellFunction(nullptr); + auto* pView = pViewShell->GetView(); + if (pView) + pView->getSearchContext().resetSearchFunction(); } pViewShell.reset(); diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx index 984e939b0634..5365b8297562 100644 --- a/sd/source/ui/view/Outliner.cxx +++ b/sd/source/ui/view/Outliner.cxx @@ -115,6 +115,8 @@ public: */ void ReleaseOutlinerView(); + sd::VectorGraphicSearchContext& getVectorGraphicSearchContext() { return maVectorGraphicSearchContext; } + private: /** Flag that specifies whether we own the outline view pointed to by <member>mpOutlineView</member> and thus have to @@ -128,6 +130,8 @@ private: <member>mbOwnOutlineView</member> distinguishes between both cases. */ OutlinerView* mpOutlineView; + + sd::VectorGraphicSearchContext maVectorGraphicSearchContext; }; namespace @@ -636,6 +640,8 @@ bool SdOutliner::SearchAndReplaceAll() mnStartPageIndex = sal_uInt16(-1); return true; } + // Reset the iterator back to the beginning + maObjectIterator = sd::outliner::OutlinerContainer(this).begin(); // Search/replace until the end of the document is reached. bool bFoundMatch; @@ -753,7 +759,7 @@ void SdOutliner::sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell> & pV std::vector<sd::SearchSelection>* pSelections) { std::vector<::tools::Rectangle> aLogicRects; - auto& rVectorGraphicSearchContext = pViewShell->GetView()->getVectorGraphicSearchContext(); + auto& rVectorGraphicSearchContext = mpImpl->getVectorGraphicSearchContext(); if (rVectorGraphicSearchContext.mbCurrentIsVectorGraphic) { basegfx::B2DRectangle aSelectionHMM = getPDFSelection(rVectorGraphicSearchContext.mpVectorGraphicSearch, mpObj); @@ -844,7 +850,7 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti mpView = pViewShell->GetView(); mpWindow = pViewShell->GetActiveWindow(); pOutlinerView->SetWindow(mpWindow); - auto& rVectorGraphicSearchContext = mpView->getVectorGraphicSearchContext(); + auto& rVectorGraphicSearchContext = mpImpl->getVectorGraphicSearchContext(); if (nullptr != dynamic_cast<const sd::DrawViewShell*>(pViewShell.get())) { sal_uLong nMatchCount = 0; @@ -1201,7 +1207,7 @@ void SdOutliner::ProvideNextTextObject() mbFoundObject = false; // reset the vector search - auto& rVectorGraphicSearchContext = mpView->getVectorGraphicSearchContext(); + auto& rVectorGraphicSearchContext = mpImpl->getVectorGraphicSearchContext(); rVectorGraphicSearchContext.reset(); mpView->UnmarkAllObj (mpView->GetSdrPageView()); |