[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - framework/Library_fwk.mk framework/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Sun Nov 3 16:08:53 UTC 2019
framework/Library_fwk.mk | 2
framework/source/uiconfiguration/ImageArrayData.cxx | 91 -----------
framework/source/uiconfiguration/ImageList.cxx | 157 ++++++++++----------
framework/source/uiconfiguration/ImageList.hxx | 27 ++-
framework/source/uiconfiguration/ImplImageList.cxx | 71 ---------
framework/source/uiconfiguration/image.h | 67 --------
6 files changed, 101 insertions(+), 314 deletions(-)
New commits:
commit 03dff7bcdbf9865c5b44cea43f9914075085e901
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Jul 19 16:31:37 2019 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Nov 3 17:08:06 2019 +0100
simplify ImageList
we don't need an Impl pattern here
Change-Id: I93d0c5904a3aee8844987c7e36c19319d071d2f4
Reviewed-on: https://gerrit.libreoffice.org/75960
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
(cherry picked from commit 825e3f66497c673dd7ac11a8fce830874288977d)
Reviewed-on: https://gerrit.libreoffice.org/81964
diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk
index 9057aaa6048a..6d1f124f2f5a 100644
--- a/framework/Library_fwk.mk
+++ b/framework/Library_fwk.mk
@@ -113,9 +113,7 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
framework/source/services/taskcreatorsrv \
framework/source/services/urltransformer \
framework/source/uiconfiguration/CommandImageResolver \
- framework/source/uiconfiguration/ImageArrayData \
framework/source/uiconfiguration/ImageList \
- framework/source/uiconfiguration/ImplImageList \
framework/source/uiconfiguration/globalsettings \
framework/source/uiconfiguration/graphicnameaccess \
framework/source/uiconfiguration/imagemanager \
diff --git a/framework/source/uiconfiguration/ImageArrayData.cxx b/framework/source/uiconfiguration/ImageArrayData.cxx
deleted file mode 100644
index 570d2846ff77..000000000000
--- a/framework/source/uiconfiguration/ImageArrayData.cxx
+++ /dev/null
@@ -1,91 +0,0 @@
-/* -*- 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <vcl/outdev.hxx>
-#include <vcl/bitmapex.hxx>
-#include <vcl/alpha.hxx>
-#include <vcl/window.hxx>
-#include <vcl/bitmapaccess.hxx>
-#include <vcl/virdev.hxx>
-#include <vcl/image.hxx>
-#include <vcl/settings.hxx>
-#include <vcl/svapp.hxx>
-#include <vcl/ImageTree.hxx>
-
-#include "image.h"
-#include <memory>
-#include <sal/log.hxx>
-
-#if OSL_DEBUG_LEVEL > 0
-#include <rtl/strbuf.hxx>
-#endif
-
-ImageAryData::ImageAryData( const ImageAryData& rData ) :
- maName( rData.maName ),
- mnId( rData.mnId ),
- maBitmapEx( rData.maBitmapEx )
-{
-}
-
-ImageAryData::ImageAryData( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmap )
- : maName( aName ), mnId( nId ), maBitmapEx( aBitmap )
-{
-}
-
-ImageAryData::~ImageAryData()
-{
-}
-
-ImageAryData& ImageAryData::operator=( const ImageAryData& rData )
-{
- maName = rData.maName;
- mnId = rData.mnId;
- maBitmapEx = rData.maBitmapEx;
-
- return *this;
-}
-
-void ImageAryData::Load(const OUString &rPrefix)
-{
- OUString aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
-
- OUString aFileName = rPrefix;
- aFileName += maName;
-
- bool bSuccess = ImageTree::get().loadImage(aFileName, aIconTheme, maBitmapEx, true);
-
- /* If the uno command has parameters, passed in from a toolbar,
- * recover from failure by removing the parameters from the file name
- */
- if (!bSuccess && aFileName.indexOf("%3f") > 0)
- {
- sal_Int32 nStart = aFileName.indexOf("%3f");
- sal_Int32 nEnd = aFileName.lastIndexOf(".");
-
- aFileName = aFileName.replaceAt(nStart, nEnd - nStart, "");
- bSuccess = ImageTree::get().loadImage(aFileName, aIconTheme, maBitmapEx, true);
- }
-
- SAL_WARN_IF(!bSuccess, "fwk.uiconfiguration", "Failed to load image '" << aFileName
- << "' from icon theme '" << aIconTheme << "'");
-}
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/uiconfiguration/ImageList.cxx b/framework/source/uiconfiguration/ImageList.cxx
index 0bb10d3d2bdb..100e152b17fc 100644
--- a/framework/source/uiconfiguration/ImageList.cxx
+++ b/framework/source/uiconfiguration/ImageList.cxx
@@ -29,7 +29,6 @@
#include <vcl/image.hxx>
#include <vcl/imagerepository.hxx>
#include <vcl/ImageTree.hxx>
-#include "image.h"
#include "ImageList.hxx"
ImageList::ImageList()
@@ -41,48 +40,40 @@ ImageList::ImageList(const std::vector< OUString >& rNameVector,
{
SAL_INFO( "vcl", "vcl: ImageList::ImageList(const vector< OUString >& ..." );
- ImplInit( sal::static_int_cast< sal_uInt16 >( rNameVector.size() ), Size() );
+ maImages.reserve( rNameVector.size() );
- mpImplData->maPrefix = rPrefix;
+ maPrefix = rPrefix;
for( size_t i = 0; i < rNameVector.size(); ++i )
{
- mpImplData->AddImage( rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, BitmapEx() );
+ ImplAddImage( rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, BitmapEx() );
}
}
-void ImageList::ImplInit( sal_uInt16 nItems, const Size &rSize )
-{
- mpImplData.reset(new ImplImageList);
- mpImplData->maImages.reserve( nItems );
- mpImplData->maImageSize = rSize;
-}
-
// FIXME: Rather a performance hazard
BitmapEx ImageList::GetAsHorizontalStrip() const
{
- Size aSize( mpImplData->maImageSize );
- sal_uInt16 nCount = GetImageCount();
+ sal_uInt16 nCount = maImages.size();
if( !nCount )
return BitmapEx();
- aSize.setWidth( aSize.Width() * nCount );
+ Size aSize( maImageSize.Width() * nCount, maImageSize.Height() );
// Load any stragglers
for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
{
- ImageAryData *pData = mpImplData->maImages[ nIdx ].get();
+ ImageAryData *pData = maImages[ nIdx ].get();
if( pData->IsLoadable() )
- pData->Load( mpImplData->maPrefix );
+ ImplLoad(*pData);
}
- BitmapEx aTempl = mpImplData->maImages[ 0 ]->maBitmapEx;
+ BitmapEx aTempl = maImages[ 0 ]->maBitmapEx;
BitmapEx aResult( aTempl, Point(), aSize );
- tools::Rectangle aSrcRect( Point( 0, 0 ), mpImplData->maImageSize );
+ tools::Rectangle aSrcRect( Point( 0, 0 ), maImageSize );
for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
{
- tools::Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ),
- mpImplData->maImageSize );
- ImageAryData *pData = mpImplData->maImages[ nIdx ].get();
+ tools::Rectangle aDestRect( Point( nIdx * maImageSize.Width(), 0 ),
+ maImageSize );
+ ImageAryData *pData = maImages[ nIdx ].get();
aResult.CopyPixel( aDestRect, aSrcRect, &pData->maBitmapEx);
}
@@ -101,32 +92,32 @@ void ImageList::InsertFromHorizontalStrip( const BitmapEx &rBitmapEx,
DBG_ASSERT (rBitmapEx.GetSizePixel().Width() % nItems == 0,
"ImageList::InsertFromHorizontalStrip - very odd size");
aSize.setWidth( aSize.Width() / nItems );
- ImplInit( nItems, aSize );
+ maImages.clear();
+ maNameHash.clear();
+ maImages.reserve( nItems );
+ maImageSize = aSize;
+ maPrefix.clear();
for (sal_uInt16 nIdx = 0; nIdx < nItems; nIdx++)
{
BitmapEx aBitmap( rBitmapEx, Point( nIdx * aSize.Width(), 0 ), aSize );
- mpImplData->AddImage( rNameVector[ nIdx ], nIdx + 1, aBitmap );
+ ImplAddImage( rNameVector[ nIdx ], nIdx + 1, aBitmap );
}
}
sal_uInt16 ImageList::ImplGetImageId( const OUString& rImageName ) const
{
- ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
- if( pImg )
- return pImg->mnId;
- else
+ auto it = maNameHash.find( rImageName );
+ if (it == maNameHash.end())
return 0;
+ return it->second->mnId;
}
void ImageList::AddImage( const OUString& rImageName, const Image& rImage )
{
SAL_WARN_IF( GetImagePos( rImageName ) != IMAGELIST_IMAGE_NOTFOUND, "vcl", "ImageList::AddImage() - ImageName already exists" );
- if( !mpImplData )
- ImplInit( 0, rImage.GetSizePixel() );
-
- mpImplData->AddImage( rImageName, GetImageCount() + 1,
+ ImplAddImage( rImageName, GetImageCount() + 1,
rImage.GetBitmapEx() );
}
@@ -138,18 +129,18 @@ void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage )
{
//Just replace the bitmap rather than doing RemoveImage / AddImage
//which breaks index-based iteration.
- ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
+ ImageAryData *pImg = maNameHash[ rImageName ];
pImg->maBitmapEx = rImage.GetBitmapEx();
}
}
void ImageList::RemoveImage( sal_uInt16 nId )
{
- for( size_t i = 0; i < mpImplData->maImages.size(); ++i )
+ for( size_t i = 0; i < maImages.size(); ++i )
{
- if( mpImplData->maImages[ i ]->mnId == nId )
+ if( maImages[ i ]->mnId == nId )
{
- mpImplData->RemoveImage( static_cast< sal_uInt16 >( i ) );
+ ImplRemoveImage( static_cast< sal_uInt16 >( i ) );
break;
}
}
@@ -157,33 +148,27 @@ void ImageList::RemoveImage( sal_uInt16 nId )
Image ImageList::GetImage( const OUString& rImageName ) const
{
- if( mpImplData )
- {
- ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
-
- if( pImg )
- {
- if( pImg->IsLoadable() )
- pImg->Load( mpImplData->maPrefix );
- return Image( pImg->maBitmapEx );
- }
- }
-
- return Image();
+ auto it = maNameHash.find( rImageName );
+ if (it == maNameHash.end())
+ return Image();
+ ImageAryData *pImg = it->second;
+ if( pImg->IsLoadable() )
+ ImplLoad( *pImg );
+ return Image( pImg->maBitmapEx );
}
sal_uInt16 ImageList::GetImageCount() const
{
- return mpImplData ? static_cast< sal_uInt16 >( mpImplData->maImages.size() ) : 0;
+ return static_cast< sal_uInt16 >( maImages.size() );
}
sal_uInt16 ImageList::GetImagePos( const OUString& rImageName ) const
{
- if( mpImplData && !rImageName.isEmpty() )
+ if( !rImageName.isEmpty() )
{
- for( size_t i = 0; i < mpImplData->maImages.size(); i++ )
+ for( size_t i = 0; i < maImages.size(); i++ )
{
- if (mpImplData->maImages[i]->maName == rImageName)
+ if (maImages[i]->maName == rImageName)
return static_cast< sal_uInt16 >( i );
}
}
@@ -193,18 +178,12 @@ sal_uInt16 ImageList::GetImagePos( const OUString& rImageName ) const
sal_uInt16 ImageList::GetImageId( sal_uInt16 nPos ) const
{
- if( mpImplData && (nPos < GetImageCount()) )
- return mpImplData->maImages[ nPos ]->mnId;
-
- return 0;
+ return maImages[ nPos ]->mnId;
}
OUString ImageList::GetImageName( sal_uInt16 nPos ) const
{
- if( mpImplData && (nPos < GetImageCount()) )
- return mpImplData->maImages[ nPos ]->maName;
-
- return OUString();
+ return maImages[ nPos ]->maName;
}
void ImageList::GetImageNames( std::vector< OUString >& rNames ) const
@@ -213,30 +192,54 @@ void ImageList::GetImageNames( std::vector< OUString >& rNames ) const
rNames = std::vector< OUString >();
- if( mpImplData )
+ for(auto const & pImage : maImages)
{
- for(auto const & pImage : mpImplData->maImages)
- {
- const OUString& rName( pImage->maName );
- if( !rName.isEmpty())
- rNames.push_back( rName );
- }
+ const OUString& rName( pImage->maName );
+ if( !rName.isEmpty())
+ rNames.push_back( rName );
}
}
-bool ImageList::operator==( const ImageList& rImageList ) const
+void ImageList::ImplAddImage( const OUString &aName,
+ sal_uInt16 nId, const BitmapEx &aBitmapEx )
+{
+ ImageAryData *pImg = new ImageAryData{ aName, nId, aBitmapEx };
+ maImages.emplace_back( pImg );
+ if( !aName.isEmpty() )
+ maNameHash [ aName ] = pImg;
+}
+
+void ImageList::ImplRemoveImage( sal_uInt16 nPos )
+{
+ ImageAryData *pImg = maImages[ nPos ].get();
+ if( !pImg->maName.isEmpty() )
+ maNameHash.erase( pImg->maName );
+ maImages.erase( maImages.begin() + nPos );
+}
+
+void ImageList::ImplLoad(ImageAryData& rImageData) const
{
- bool bRet = false;
+ OUString aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
- if( rImageList.mpImplData == mpImplData )
- bRet = true;
- else if( !rImageList.mpImplData || !mpImplData )
- bRet = false;
- else if( rImageList.GetImageCount() == GetImageCount() &&
- rImageList.mpImplData->maImageSize == mpImplData->maImageSize )
- bRet = true; // strange semantic
+ OUString aFileName = maPrefix + rImageData.maName;
- return bRet;
+ bool bSuccess = ImageTree::get().loadImage(aFileName, aIconTheme, rImageData.maBitmapEx, true);
+
+ /* If the uno command has parameters, passed in from a toolbar,
+ * recover from failure by removing the parameters from the file name
+ */
+ if (!bSuccess && aFileName.indexOf("%3f") > 0)
+ {
+ sal_Int32 nStart = aFileName.indexOf("%3f");
+ sal_Int32 nEnd = aFileName.lastIndexOf(".");
+
+ aFileName = aFileName.replaceAt(nStart, nEnd - nStart, "");
+ bSuccess = ImageTree::get().loadImage(aFileName, aIconTheme, rImageData.maBitmapEx, true);
+ }
+
+ SAL_WARN_IF(!bSuccess, "fwk.uiconfiguration", "Failed to load image '" << aFileName
+ << "' from icon theme '" << aIconTheme << "'");
}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/uiconfiguration/ImageList.hxx b/framework/source/uiconfiguration/ImageList.hxx
index a4b46f5160d9..604624ea666b 100644
--- a/framework/source/uiconfiguration/ImageList.hxx
+++ b/framework/source/uiconfiguration/ImageList.hxx
@@ -20,7 +20,20 @@
#ifndef FRAMEWORK_SOURCE_UICONFIGURATION_IMAGELIST_HXX
#define FRAMEWORK_SOURCE_UICONFIGURATION_IMAGELIST_HXX
-struct ImplImageList;
+#include <vcl/bitmapex.hxx>
+#include <unordered_map>
+#include <vector>
+
+// Images identified by either name, or by id
+struct ImageAryData
+{
+ OUString maName;
+ sal_uInt16 mnId;
+ BitmapEx maBitmapEx;
+
+ bool IsLoadable() { return maBitmapEx.IsEmpty() && !maName.isEmpty(); }
+};
+
class ImageList
{
@@ -49,15 +62,17 @@ public:
OUString GetImageName( sal_uInt16 nPos ) const;
void GetImageNames( ::std::vector< OUString >& rNames ) const;
- bool operator==( const ImageList& rImageList ) const;
- bool operator!=( const ImageList& rImageList ) const { return !(ImageList::operator==( rImageList )); }
-
private:
- std::shared_ptr<ImplImageList> mpImplData;
+ std::vector< std::unique_ptr<ImageAryData> > maImages;
+ std::unordered_map< OUString, ImageAryData * > maNameHash;
+ OUString maPrefix;
+ Size maImageSize;
- void ImplInit( sal_uInt16 nItems, const Size &rSize );
sal_uInt16 ImplGetImageId( const OUString& rImageName ) const;
+ void ImplAddImage( const OUString &aName, sal_uInt16 nId, const BitmapEx &aBitmapEx );
+ void ImplRemoveImage( sal_uInt16 nPos );
+ void ImplLoad(ImageAryData&) const;
};
#endif // INCLUDED_VCL_IMAGE_HXX
diff --git a/framework/source/uiconfiguration/ImplImageList.cxx b/framework/source/uiconfiguration/ImplImageList.cxx
deleted file mode 100644
index 1c594f16bf89..000000000000
--- a/framework/source/uiconfiguration/ImplImageList.cxx
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <vcl/outdev.hxx>
-#include <vcl/bitmapex.hxx>
-#include <vcl/alpha.hxx>
-#include <vcl/window.hxx>
-#include <vcl/bitmapaccess.hxx>
-#include <vcl/virdev.hxx>
-#include <vcl/image.hxx>
-#include <vcl/settings.hxx>
-
-#include "image.h"
-#include <memory>
-
-ImplImageList::ImplImageList()
-{
-}
-
-ImplImageList::ImplImageList( const ImplImageList &aSrc )
- : maPrefix(aSrc.maPrefix)
- , maImageSize(aSrc.maImageSize)
-{
- maImages.reserve( aSrc.maImages.size() );
- for (auto const& elem : aSrc.maImages)
- {
- ImageAryData* pAryData = new ImageAryData(*elem);
- maImages.emplace_back( pAryData );
- if( !pAryData->maName.isEmpty() )
- maNameHash [ pAryData->maName ] = pAryData;
- }
-}
-
-ImplImageList::~ImplImageList()
-{
-}
-
-void ImplImageList::AddImage( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmapEx )
-{
- ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx );
- maImages.emplace_back( pImg );
- if( !aName.isEmpty() )
- maNameHash [ aName ] = pImg;
-}
-
-void ImplImageList::RemoveImage( sal_uInt16 nPos )
-{
- ImageAryData *pImg = maImages[ nPos ].get();
- if( !pImg->maName.isEmpty() )
- maNameHash.erase( pImg->maName );
- maImages.erase( maImages.begin() + nPos );
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/uiconfiguration/image.h b/framework/source/uiconfiguration/image.h
deleted file mode 100644
index 96c952d3dfe3..000000000000
--- a/framework/source/uiconfiguration/image.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef FRAMEWORK_SOURCE_UICONFIGURATION_IMAGE_H
-#define FRAMEWORK_SOURCE_UICONFIGURATION_IMAGE_H
-
-#include <vcl/bitmapex.hxx>
-
-#include <unordered_map>
-#include <vector>
-
-struct ImageAryData
-{
- OUString maName;
- // Images identified by either name, or by id
- sal_uInt16 mnId;
- BitmapEx maBitmapEx;
-
- ImageAryData( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmap );
- ImageAryData( const ImageAryData& rData );
- ~ImageAryData();
-
- bool IsLoadable() { return maBitmapEx.IsEmpty() && !maName.isEmpty(); }
- void Load(const OUString &rPrefix);
-
- ImageAryData& operator=( const ImageAryData& rData );
-};
-
-struct ImplImageList
-{
- typedef std::unordered_map< OUString, ImageAryData * >
- ImageAryDataNameHash;
-
- std::vector< std::unique_ptr<ImageAryData> > maImages;
- ImageAryDataNameHash maNameHash;
- OUString maPrefix;
- Size maImageSize;
-
- ImplImageList();
- ImplImageList( const ImplImageList &aSrc );
- ~ImplImageList();
-
- void AddImage( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmapEx );
- void RemoveImage( sal_uInt16 nPos );
-};
-
-#endif // INCLUDED_VCL_INC_IMAGE_H
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list