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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 17 14:50:30 UTC 2020


 sd/inc/VectorGraphicSearchContext.hxx |   35 ++++++++++++++++++++
 sd/source/ui/inc/View.hxx             |    6 +++
 sd/source/ui/view/Outliner.cxx        |   59 ++++++++++++++--------------------
 3 files changed, 66 insertions(+), 34 deletions(-)

New commits:
commit 74e2f2178fd8a0ad29c5dbcefb22a9778a75ae82
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Aug 16 12:06:30 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Aug 17 16:49:39 2020 +0200

    move vector graphic search to View, so it works in multiple views
    
    VectorGraphicSearch was instantiated for the Outline, which is
    the same for every view. The problem with this is that when we
    have multiple views, the search would interfere with each other,
    which is especially distracting in online when multiple users
    connect to the same document and try searching.
    This adds VectorGraphicSearchContext class, that is added to the
    View, which makes the search view dependent and multiple instances
    of VectorGraphicSearch are created, each one for its own view.
    
    Change-Id: Ia0f34647b30b35f4ddb84d33353990d635756905
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100837
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sd/inc/VectorGraphicSearchContext.hxx b/sd/inc/VectorGraphicSearchContext.hxx
new file mode 100644
index 000000000000..e6f978ca273c
--- /dev/null
+++ b/sd/inc/VectorGraphicSearchContext.hxx
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <vcl/VectorGraphicSearch.hxx>
+
+namespace sd
+{
+struct VectorGraphicSearchContext
+{
+    bool mbCurrentIsVectorGraphic;
+    std::unique_ptr<VectorGraphicSearch> mpVectorGraphicSearch;
+
+    VectorGraphicSearchContext()
+        : mbCurrentIsVectorGraphic(false)
+    {
+    }
+
+    void reset()
+    {
+        mbCurrentIsVectorGraphic = false;
+        mpVectorGraphicSearch.reset();
+    }
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/inc/View.hxx b/sd/source/ui/inc/View.hxx
index 5aba1fb326d9..d7da6fc2df12 100644
--- a/sd/source/ui/inc/View.hxx
+++ b/sd/source/ui/inc/View.hxx
@@ -27,6 +27,7 @@
 #include <svx/fmview.hxx>
 #include <svx/svdpage.hxx>
 #include <vcl/idle.hxx>
+#include <VectorGraphicSearchContext.hxx>
 
 #include "smarttag.hxx"
 
@@ -217,6 +218,8 @@ public:
     void SetAuthor(const OUString& rAuthor) { m_sAuthor = rAuthor; }
     const OUString& GetAuthor() const { return m_sAuthor; }
 
+    VectorGraphicSearchContext& getVectorGraphicSearchContext() { return aVectorGraphicSearchContext; }
+
 protected:
     DECL_LINK( OnParagraphInsertedHdl, ::Outliner::ParagraphHdlParam, void );
     DECL_LINK( OnParagraphRemovingHdl, ::Outliner::ParagraphHdlParam, void );
@@ -250,6 +253,9 @@ protected:
 private:
     ::std::unique_ptr<ViewClipboard> mpClipboard;
     OutlinerMasterViewFilter maMasterViewFilter;
+
+    VectorGraphicSearchContext aVectorGraphicSearchContext;
+
     OUString m_sAuthor;
 };
 
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index b6fc569b9b61..8ac435249f7a 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -21,7 +21,6 @@
 #include <boost/property_tree/json_parser.hpp>
 #include <vcl/settings.hxx>
 #include <vcl/svapp.hxx>
-#include <vcl/VectorGraphicSearch.hxx>
 
 #include <svl/srchitem.hxx>
 #include <svl/intitem.hxx>
@@ -61,6 +60,7 @@
 #include <comphelper/string.hxx>
 #include <comphelper/lok.hxx>
 #include <comphelper/scopeguard.hxx>
+#include <VectorGraphicSearchContext.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -99,11 +99,6 @@ public:
     */
     void ReleaseOutlinerView();
 
-    /** Search in vector graphic
-     */
-    bool mbCurrentIsVectorGraphic;
-    std::unique_ptr<VectorGraphicSearch> mpVectorGraphicSearch;
-
 private:
     /** Flag that specifies whether we own the outline view pointed to by
         <member>mpOutlineView</member> and thus have to
@@ -729,9 +724,10 @@ void SdOutliner::sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell> & pV
                                              std::vector<sd::SearchSelection>* pSelections)
 {
     std::vector<::tools::Rectangle> aLogicRects;
-    if (mpImpl->mbCurrentIsVectorGraphic)
+    auto& rVectorGraphicSearchContext = pViewShell->GetView()->getVectorGraphicSearchContext();
+    if (rVectorGraphicSearchContext.mbCurrentIsVectorGraphic)
     {
-        basegfx::B2DRectangle aSelectionHMM = getPDFSelection(mpImpl->mpVectorGraphicSearch, mpObj);
+        basegfx::B2DRectangle aSelectionHMM = getPDFSelection(rVectorGraphicSearchContext.mpVectorGraphicSearch, mpObj);
 
         tools::Rectangle aSelection(Point(aSelectionHMM.getMinX(), aSelectionHMM.getMinY()),
                                     Size(aSelectionHMM.getWidth(), aSelectionHMM.getHeight()));
@@ -787,7 +783,7 @@ void SdOutliner::sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell> & pV
         aPayload = aStream.str().c_str();
         rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
 
-        if (mpImpl->mbCurrentIsVectorGraphic)
+        if (rVectorGraphicSearchContext.mbCurrentIsVectorGraphic)
         {
             rSfxViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRectangles.getStr());
         }
@@ -819,12 +815,12 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti
         mpView = pViewShell->GetView();
         mpWindow = pViewShell->GetActiveWindow();
         pOutlinerView->SetWindow(mpWindow);
-
+        auto& rVectorGraphicSearchContext = mpView->getVectorGraphicSearchContext();
         if (nullptr != dynamic_cast<const sd::DrawViewShell*>(pViewShell.get()))
         {
             sal_uLong nMatchCount = 0;
 
-            if (mpImpl->mbCurrentIsVectorGraphic)
+            if (rVectorGraphicSearchContext.mbCurrentIsVectorGraphic)
             {
                 OUString const & rString = mpSearchItem->GetSearchString();
                 bool bBackwards = mpSearchItem->GetBackward();
@@ -834,14 +830,14 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti
                 aOptions.mbMatchCase = mpSearchItem->GetExact();
                 aOptions.mbMatchWholeWord = mpSearchItem->GetWordOnly();
 
-                bool bResult = mpImpl->mpVectorGraphicSearch->search(rString, aOptions);
+                bool bResult = rVectorGraphicSearchContext.mpVectorGraphicSearch->search(rString, aOptions);
 
                 if (bResult)
                 {
                     if (bBackwards)
-                        bResult = mpImpl->mpVectorGraphicSearch->previous();
+                        bResult = rVectorGraphicSearchContext.mpVectorGraphicSearch->previous();
                     else
-                        bResult = mpImpl->mpVectorGraphicSearch->next();
+                        bResult = rVectorGraphicSearchContext.mpVectorGraphicSearch->next();
                 }
 
                 if (bResult)
@@ -852,15 +848,14 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti
                     mpView->UnmarkAllObj(pPageView);
 
                     std::vector<basegfx::B2DRectangle> aSubSelections;
-                    basegfx::B2DRectangle aSubSelection = getPDFSelection(mpImpl->mpVectorGraphicSearch, mpObj);
+                    basegfx::B2DRectangle aSubSelection = getPDFSelection(rVectorGraphicSearchContext.mpVectorGraphicSearch, mpObj);
                     if (!aSubSelection.isEmpty())
                         aSubSelections.push_back(aSubSelection);
                     mpView->MarkObj(mpObj, pPageView, false, false, aSubSelections);
                 }
                 else
                 {
-                    mpImpl->mbCurrentIsVectorGraphic = false;
-                    mpImpl->mpVectorGraphicSearch.reset();
+                    rVectorGraphicSearchContext.reset();
                 }
             }
             else
@@ -889,7 +884,7 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti
             {
                 ProvideNextTextObject ();
 
-                if (!mbEndOfSearch && !mpImpl->mbCurrentIsVectorGraphic)
+                if (!mbEndOfSearch && !rVectorGraphicSearchContext.mbCurrentIsVectorGraphic)
                 {
                     // Remember the current position as the last one with a
                     // text object.
@@ -1177,8 +1172,8 @@ void SdOutliner::ProvideNextTextObject()
     mbFoundObject = false;
 
     // reset the vector search
-    mpImpl->mbCurrentIsVectorGraphic = false;
-    mpImpl->mpVectorGraphicSearch.reset();
+    auto& rVectorGraphicSearchContext = mpView->getVectorGraphicSearchContext();
+    rVectorGraphicSearchContext.reset();
 
     mpView->UnmarkAllObj (mpView->GetSdrPageView());
     try
@@ -1212,8 +1207,7 @@ void SdOutliner::ProvideNextTextObject()
             // LOK: do not descent to notes or master pages when searching
             bool bForbiddenPage = comphelper::LibreOfficeKit::isActive() && (maCurrentPosition.mePageKind != PageKind::Standard || maCurrentPosition.meEditMode != EditMode::Page);
 
-            mpImpl->mbCurrentIsVectorGraphic = false;
-            mpImpl->mpVectorGraphicSearch.reset();
+            rVectorGraphicSearchContext.reset();
 
             if (!bForbiddenPage)
             {
@@ -1230,7 +1224,7 @@ void SdOutliner::ProvideNextTextObject()
                 else if (meMode == SEARCH && isValidVectorGraphicObject(maCurrentPosition))
                 {
                     mpObj = maCurrentPosition.mxObject.get();
-                    mpImpl->mbCurrentIsVectorGraphic = true;
+                    rVectorGraphicSearchContext.mbCurrentIsVectorGraphic = true;
                 }
             }
 
@@ -1239,7 +1233,7 @@ void SdOutliner::ProvideNextTextObject()
 
             if (mpObj)
             {
-                if (mpImpl->mbCurrentIsVectorGraphic)
+                if (rVectorGraphicSearchContext.mbCurrentIsVectorGraphic)
                 {
                     // We know here the object is a SdrGrafObj and that it
                     // contains a vector graphic
@@ -1252,15 +1246,15 @@ void SdOutliner::ProvideNextTextObject()
                     aOptions.mbMatchCase = mpSearchItem->GetExact();
                     aOptions.mbMatchWholeWord = mpSearchItem->GetWordOnly();
 
-                    mpImpl->mpVectorGraphicSearch = std::make_unique<VectorGraphicSearch>(pGraphicObject->GetGraphic());
+                    rVectorGraphicSearchContext.mpVectorGraphicSearch = std::make_unique<VectorGraphicSearch>(pGraphicObject->GetGraphic());
 
-                    bool bResult = mpImpl->mpVectorGraphicSearch->search(rString, aOptions);
+                    bool bResult = rVectorGraphicSearchContext.mpVectorGraphicSearch->search(rString, aOptions);
                     if (bResult)
                     {
                         if (bBackwards)
-                            bResult = mpImpl->mpVectorGraphicSearch->previous();
+                            bResult = rVectorGraphicSearchContext.mpVectorGraphicSearch->previous();
                         else
-                            bResult = mpImpl->mpVectorGraphicSearch->next();
+                            bResult = rVectorGraphicSearchContext.mpVectorGraphicSearch->next();
                     }
 
                     if (bResult)
@@ -1275,7 +1269,7 @@ void SdOutliner::ProvideNextTextObject()
                         mpView->UnmarkAllObj(pPageView);
 
                         std::vector<basegfx::B2DRectangle> aSubSelections;
-                        basegfx::B2DRectangle aSubSelection = getPDFSelection(mpImpl->mpVectorGraphicSearch, mpObj);
+                        basegfx::B2DRectangle aSubSelection = getPDFSelection(rVectorGraphicSearchContext.mpVectorGraphicSearch, mpObj);
                         if (!aSubSelection.isEmpty())
                             aSubSelections.push_back(aSubSelection);
 
@@ -1285,8 +1279,7 @@ void SdOutliner::ProvideNextTextObject()
                     }
                     else
                     {
-                        mpImpl->mbCurrentIsVectorGraphic = false;
-                        mpImpl->mpVectorGraphicSearch.reset();
+                        rVectorGraphicSearchContext.reset();
                     }
                 }
                 else
@@ -1314,8 +1307,7 @@ void SdOutliner::ProvideNextTextObject()
         }
         else
         {
-            mpImpl->mbCurrentIsVectorGraphic = false;
-            mpImpl->mpVectorGraphicSearch.reset();
+            rVectorGraphicSearchContext.reset();
 
             if (meMode == SEARCH)
                 // Instead of doing a full-blown SetObject(), which would do the same -- but would also possibly switch pages.
@@ -1934,7 +1926,6 @@ weld::Window* SdOutliner::GetMessageBoxParent()
 
 SdOutliner::Implementation::Implementation()
     : meOriginalEditMode(EditMode::Page),
-      mbCurrentIsVectorGraphic(false),
       mbOwnOutlineView(false),
       mpOutlineView(nullptr)
 {


More information about the Libreoffice-commits mailing list