sd/source/ui/docshell/docshel3.cxx | 82 +++++++++++++++++---------------- sd/source/ui/docshell/docshell.cxx | 19 ++++++- sd/source/ui/func/fusearch.cxx | 9 ++- sd/source/ui/inc/DrawDocShell.hxx | 3 - sd/source/ui/inc/View.hxx | 32 ++++++++++-- sd/source/ui/inc/fusearch.hxx | 2 sd/source/ui/unoidl/DrawController.cxx | 6 +- sd/source/ui/view/Outliner.cxx | 12 +++- 8 files changed, 108 insertions(+), 57 deletions(-)
New commits: commit 714767b3d521eefc46dd8158ee67610347863f9f Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Aug 22 21:45:44 2020 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Aug 31 13:29:43 2020 +0200 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 <qui...@gmail.com> (cherry picked from commit 2ebc26aeefefe33ee6180862509e4971ff2dfc6f) Change-Id: I6a5ce71efafa378845eee4ac9574e2e4301138d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101693 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sd/source/ui/docshell/docshel3.cxx b/sd/source/ui/docshell/docshel3.cxx index 9d8ce84cb538..01705c12cf75 100644 --- a/sd/source/ui/docshell/docshel3.cxx +++ b/sd/source/ui/docshell/docshel3.cxx @@ -166,30 +166,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; @@ -198,23 +205,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); + } } } @@ -424,14 +438,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 ad0ce701bdfe..5423e21bf16b 100644 --- a/sd/source/ui/docshell/docshell.cxx +++ b/sd/source/ui/docshell/docshell.cxx @@ -164,7 +164,15 @@ DrawDocShell::~DrawDocShell() mbInDestruction = true; - SetDocShellFunction(nullptr); + if (mpViewShell) + { + auto* pView = mpViewShell->GetView(); + if (pView) + { + auto & pSearchContext = pView->getSearchContext(); + pSearchContext.resetSearchFunction(); + } + } mpFontList.reset(); @@ -373,9 +381,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 817d357fa25b..ce51b59e7e47 100644 --- a/sd/source/ui/func/fusearch.cxx +++ b/sd/source/ui/func/fusearch.cxx @@ -57,13 +57,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 2c5ef9c46cdb..453185f184e5 100644 --- a/sd/source/ui/inc/DrawDocShell.hxx +++ b/sd/source/ui/inc/DrawDocShell.hxx @@ -106,8 +106,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; } @@ -211,7 +209,6 @@ protected: VclPtr<SfxPrinter> mpPrinter; ::sd::ViewShell* mpViewShell; std::unique_ptr<FontList> mpFontList; - rtl::Reference<FuPoor> mxDocShellFunction; DocumentType const meDocType; SfxStyleFamily mnStyleFamily; o3tl::span<sal_uInt16 const> diff --git a/sd/source/ui/inc/View.hxx b/sd/source/ui/inc/View.hxx index d7da6fc2df12..4693ce3e9596 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: @@ -218,8 +242,7 @@ public: void SetAuthor(const OUString& rAuthor) { m_sAuthor = rAuthor; } const OUString& GetAuthor() const { return m_sAuthor; } - VectorGraphicSearchContext& getVectorGraphicSearchContext() { return aVectorGraphicSearchContext; } - + SearchContext& getSearchContext() { return maSearchContext; } protected: DECL_LINK( OnParagraphInsertedHdl, ::Outliner::ParagraphHdlParam, void ); DECL_LINK( OnParagraphRemovingHdl, ::Outliner::ParagraphHdlParam, void ); @@ -253,8 +276,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 a3d43b454d6d..79e74911b215 100644 --- a/sd/source/ui/unoidl/DrawController.cxx +++ b/sd/source/ui/unoidl/DrawController.cxx @@ -142,9 +142,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 7f6a1853d753..2a6a41998e71 100644 --- a/sd/source/ui/view/Outliner.cxx +++ b/sd/source/ui/view/Outliner.cxx @@ -99,6 +99,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 @@ -112,6 +114,8 @@ private: <member>mbOwnOutlineView</member> distinguishes between both cases. */ OutlinerView* mpOutlineView; + + sd::VectorGraphicSearchContext maVectorGraphicSearchContext; }; namespace @@ -607,6 +611,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; @@ -724,7 +730,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); @@ -815,7 +821,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; @@ -1172,7 +1178,7 @@ void SdOutliner::ProvideNextTextObject() mbFoundObject = false; // reset the vector search - auto& rVectorGraphicSearchContext = mpView->getVectorGraphicSearchContext(); + auto& rVectorGraphicSearchContext = mpImpl->getVectorGraphicSearchContext(); rVectorGraphicSearchContext.reset(); mpView->UnmarkAllObj (mpView->GetSdrPageView()); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits