[Libreoffice-commits] core.git: include/svx svx/source

Aditya (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 31 17:03:21 UTC 2020


 include/svx/galleryobjectcollection.hxx         |   13 +++++++++++-
 include/svx/galtheme.hxx                        |   19 +-----------------
 svx/source/gallery2/galleryobjectcollection.cxx |   25 ++++++++++++++++++++++++
 svx/source/gallery2/galtheme.cxx                |   20 +++++--------------
 svx/source/unogallery/unogalitem.cxx            |    8 +++----
 svx/source/unogallery/unogaltheme.cxx           |    6 ++---
 6 files changed, 52 insertions(+), 39 deletions(-)

New commits:
commit 6e717f4552aa937cd2609a79199a5b40b38789a4
Author:     Aditya <adityasahu1511 at gmail.com>
AuthorDate: Thu Jul 30 15:04:27 2020 +0530
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Jul 31 19:02:41 2020 +0200

    svx:Move functions from GalleryTheme that belong to GalleryObjectCollection
    
    Move 3 functions from ImplGetObjectURL(sal_uInt32 nPos), ImplGetObjectURL(const
     INetURLObject& rURL) and ImplGetObjectPos(const GalleryObject* pObj) to
     GalleryObjectCollection as they deal with the m_aObjectList directly, and
     rename them respectively.
    
    Change-Id: I1e02b345d706c57db8801441fc955af9157cf565
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99789
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/svx/galleryobjectcollection.hxx b/include/svx/galleryobjectcollection.hxx
index 266d263e8b14..311434ec0352 100644
--- a/include/svx/galleryobjectcollection.hxx
+++ b/include/svx/galleryobjectcollection.hxx
@@ -19,23 +19,34 @@
 
 #pragma once
 
+#include <svx/svxdllapi.h>
+
+#include <tools/urlobj.hxx>
 #include <memory>
 #include <vector>
 
 struct GalleryObject;
 
-class GalleryObjectCollection
+class SVXCORE_DLLPUBLIC GalleryObjectCollection
 {
 private:
     std::vector<std::unique_ptr<GalleryObject>> m_aObjectList;
 
 public:
+    GalleryObjectCollection();
     std::vector<std::unique_ptr<GalleryObject>>& getObjectList() { return m_aObjectList; }
     std::unique_ptr<GalleryObject>& get(sal_uInt32 nPos) { return m_aObjectList[nPos]; }
     const std::unique_ptr<GalleryObject>& get(sal_uInt32 nPos) const { return m_aObjectList[nPos]; }
     sal_uInt32 size() const { return m_aObjectList.size(); }
 
+    const GalleryObject* searchObjectWithURL(const INetURLObject& rURL);
+    const GalleryObject* getForPosition(sal_uInt32 nPos) const;
+    sal_uInt32 searchPosWithObject(const GalleryObject* pObj);
+
     void clear();
+
+    GalleryObjectCollection(GalleryObjectCollection const&) = delete;
+    void operator=(GalleryObjectCollection const&) = delete;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx
index 5c3f537c2107..c0c1bf260670 100644
--- a/include/svx/galtheme.hxx
+++ b/include/svx/galtheme.hxx
@@ -89,21 +89,6 @@ private:
     std::unique_ptr<GalleryBinaryEngine> createGalleryBinaryEngine(bool bReadOnly);
     const std::unique_ptr<GalleryBinaryEngine>& getGalleryBinaryEngine() const { return mpGalleryBinaryEngine; }
 
-    SAL_DLLPRIVATE const GalleryObject* ImplGetGalleryObject(sal_uInt32 nPos) const
-    {
-        if (nPos < maGalleryObjectCollection.size())
-            return maGalleryObjectCollection.get(nPos).get();
-        return nullptr;
-    }
-    const GalleryObject* ImplGetGalleryObject(const INetURLObject& rURL);
-
-    SAL_DLLPRIVATE sal_uInt32   ImplGetGalleryObjectPos( const GalleryObject* pObj )
-                                {
-                                    for (sal_uInt32 i = 0, n = maGalleryObjectCollection.size(); i < n; ++i)
-                                        if ( pObj == maGalleryObjectCollection.get(i).get() )
-                                            return i;
-                                    return SAL_MAX_UINT32;
-                                }
     SAL_DLLPRIVATE void         ImplSetModified( bool bModified );
     SAL_DLLPRIVATE void         ImplBroadcast(sal_uInt32 nUpdatePos);
 
@@ -164,14 +149,14 @@ public:
     SAL_DLLPRIVATE SgaObjKind GetObjectKind(sal_uInt32 nPos) const
     {
         if (nPos < GetObjectCount())
-            return ImplGetGalleryObject( nPos )->eObjKind;
+            return maGalleryObjectCollection.getForPosition( nPos )->eObjKind;
         return SgaObjKind::NONE;
     }
 
     SAL_DLLPRIVATE const INetURLObject& GetObjectURL(sal_uInt32 nPos) const
                                 {
                                     DBG_ASSERT( nPos < GetObjectCount(), "Position out of range" );
-                                    return ImplGetGalleryObject( nPos )->aURL;
+                                    return maGalleryObjectCollection.getForPosition( nPos )->aURL;
                                 }
 
     SAL_DLLPRIVATE bool         GetThumb(sal_uInt32 nPos, BitmapEx& rBmp);
diff --git a/svx/source/gallery2/galleryobjectcollection.cxx b/svx/source/gallery2/galleryobjectcollection.cxx
index 0ab69de1a0a4..5080ed334916 100644
--- a/svx/source/gallery2/galleryobjectcollection.cxx
+++ b/svx/source/gallery2/galleryobjectcollection.cxx
@@ -20,6 +20,31 @@
 #include <galobj.hxx>
 #include <svx/galleryobjectcollection.hxx>
 
+GalleryObjectCollection::GalleryObjectCollection() {}
+
 void GalleryObjectCollection::clear() { m_aObjectList.clear(); }
 
+const GalleryObject* GalleryObjectCollection::searchObjectWithURL(const INetURLObject& rURL)
+{
+    for (auto const& i : m_aObjectList)
+        if (i->aURL == rURL)
+            return i.get();
+    return nullptr;
+}
+
+sal_uInt32 GalleryObjectCollection::searchPosWithObject(const GalleryObject* pObj)
+{
+    for (sal_uInt32 i = 0, n = size(); i < n; ++i)
+        if (pObj == get(i).get())
+            return i;
+    return SAL_MAX_UINT32;
+}
+
+const GalleryObject* GalleryObjectCollection::getForPosition(sal_uInt32 nPos) const
+{
+    if (nPos < size())
+        return get(nPos).get();
+    return nullptr;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 3c2bb6cc78c0..2bb71540cf29 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -94,14 +94,6 @@ std::unique_ptr<GalleryBinaryEngine> GalleryTheme::createGalleryBinaryEngine(boo
     return pGalleryBinaryEngine;
 }
 
-const GalleryObject* GalleryTheme::ImplGetGalleryObject(const INetURLObject& rURL)
-{
-    for (auto const& i : maGalleryObjectCollection.getObjectList())
-        if (i->aURL == rURL)
-            return i.get();
-    return nullptr;
-}
-
 void GalleryTheme::ImplBroadcast(sal_uInt32 nUpdatePos)
 {
     if( !IsBroadcasterLocked() )
@@ -162,7 +154,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
 
 std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
 {
-    return mpGalleryBinaryEngine->implReadSgaObject(ImplGetGalleryObject(nPos));
+    return mpGalleryBinaryEngine->implReadSgaObject(maGalleryObjectCollection.getForPosition(nPos));
 }
 
 void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath)
@@ -335,7 +327,7 @@ bool GalleryTheme::GetThumb(sal_uInt32 nPos, BitmapEx& rBmp)
 
 bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic)
 {
-    const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
+    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
     bool                    bRet = false;
 
     if( pObject )
@@ -460,7 +452,7 @@ bool GalleryTheme::InsertGraphic(const Graphic& rGraphic, sal_uInt32 nInsertPos)
 
 bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel)
 {
-    const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
+    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
     bool                    bRet = false;
 
     if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
@@ -482,7 +474,7 @@ bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos)
 
 bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream> const & rxModelStream)
 {
-    const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
+    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
     bool                    bRet = false;
 
     if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
@@ -506,7 +498,7 @@ bool GalleryTheme::InsertModelStream(const tools::SvRef<SotStorageStream>& rxMod
 
 bool GalleryTheme::GetURL(sal_uInt32 nPos, INetURLObject& rURL)
 {
-    const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
+    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
     bool                    bRet = false;
 
     if( pObject )
@@ -671,7 +663,7 @@ SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const
 
     for( sal_uInt32 i = 0; i < nCount; i++ )
     {
-        const GalleryObject* pObj = ImplGetGalleryObject( i );
+        const GalleryObject* pObj = maGalleryObjectCollection.getForPosition( i );
         OUString               aPath;
 
         if( SgaObjKind::SvDraw == pObj->eObjKind )
diff --git a/svx/source/unogallery/unogalitem.cxx b/svx/source/unogallery/unogalitem.cxx
index 48fb9e0da18c..0749dfdd2f44 100644
--- a/svx/source/unogallery/unogalitem.cxx
+++ b/svx/source/unogallery/unogalitem.cxx
@@ -268,7 +268,7 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt
 
                 if( pGalTheme )
                 {
-                    std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
+                    std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
 
                     if( pObj )
                     {
@@ -284,7 +284,7 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt
 
                 if( pGalTheme )
                 {
-                    std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
+                    std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
 
                     if( pObj )
                     {
@@ -306,7 +306,7 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt
                 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
                 Graphic         aGraphic;
 
-                if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), aGraphic ) )
+                if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), aGraphic ) )
                     *pValue <<= aGraphic.GetXGraphic();
             }
             break;
@@ -320,7 +320,7 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt
 
                     pModel->GetItemPool().FreezeIdRanges();
 
-                    if( pGalTheme && pGalTheme->GetModel( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), *pModel ) )
+                    if( pGalTheme && pGalTheme->GetModel( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), *pModel ) )
                     {
                         uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
 
diff --git a/svx/source/unogallery/unogaltheme.cxx b/svx/source/unogallery/unogaltheme.cxx
index d5b084f13cfa..e2fa7b93bc12 100644
--- a/svx/source/unogallery/unogaltheme.cxx
+++ b/svx/source/unogallery/unogaltheme.cxx
@@ -130,7 +130,7 @@ uno::Any SAL_CALL GalleryTheme::getByIndex( ::sal_Int32 nIndex )
         {
             throw lang::IndexOutOfBoundsException();
         }
-        const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( nIndex );
+        const GalleryObject* pObj = mpTheme->maGalleryObjectCollection.getForPosition( nIndex );
 
         if( pObj )
             aRet <<= uno::Reference< gallery::XGalleryItem >( new GalleryItem( *this, *pObj ) );
@@ -180,10 +180,10 @@ void SAL_CALL GalleryTheme::update(  )
 
             if( ( aURL.GetProtocol() != INetProtocol::NotValid ) && mpTheme->InsertURL( aURL, nIndex ) )
             {
-                const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( aURL );
+                const GalleryObject* pObj = mpTheme->maGalleryObjectCollection.searchObjectWithURL( aURL );
 
                 if( pObj )
-                    nRet = mpTheme->ImplGetGalleryObjectPos( pObj );
+                    nRet = mpTheme->maGalleryObjectCollection.searchPosWithObject( pObj );
             }
         }
         catch( ... )


More information about the Libreoffice-commits mailing list