summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2018-11-26 16:59:42 +0000
committerAndras Timar <andras.timar@collabora.com>2018-12-06 10:51:34 +0100
commitca936bb8b1728f470028e5ae0c55a808210f2b0c (patch)
treedefc6a2d3c3336488b950848304fc3bba39b3361
parent190fad517d66be7891d54d0731cecb148aff357d (diff)
Use lazy-loading stock Image to simplify framework image lists.
Project stock names through XGraphic via origin URL. Change-Id: Ib445694f7c142a163ef7e7bc0beea39b88b99e14 (cherry picked from commit 77b88eebaadebb626108172e4f2de36c60960051)
-rw-r--r--framework/source/uiconfiguration/ImageArrayData.cxx22
-rw-r--r--framework/source/uiconfiguration/ImageList.cxx37
-rw-r--r--framework/source/uiconfiguration/ImplImageList.cxx9
-rw-r--r--framework/source/uiconfiguration/image.h11
-rw-r--r--framework/source/uiconfiguration/imagemanagerimpl.cxx2
-rw-r--r--include/vcl/graph.hxx2
-rw-r--r--include/vcl/image.hxx3
-rw-r--r--sfx2/source/sidebar/Tools.cxx14
-rw-r--r--vcl/source/gdi/graph.cxx14
-rw-r--r--vcl/source/helper/commandinfoprovider.cxx35
-rw-r--r--vcl/source/image/Image.cxx30
11 files changed, 84 insertions, 95 deletions
diff --git a/framework/source/uiconfiguration/ImageArrayData.cxx b/framework/source/uiconfiguration/ImageArrayData.cxx
index 508f79105d98..076cbcefb6dd 100644
--- a/framework/source/uiconfiguration/ImageArrayData.cxx
+++ b/framework/source/uiconfiguration/ImageArrayData.cxx
@@ -38,13 +38,13 @@
ImageAryData::ImageAryData( const ImageAryData& rData ) :
maName( rData.maName ),
mnId( rData.mnId ),
- maBitmapEx( rData.maBitmapEx )
+ maImage( rData.maImage )
{
}
ImageAryData::ImageAryData( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmap )
- : maName( aName ), mnId( nId ), maBitmapEx( aBitmap )
+ sal_uInt16 nId, const Image &aImage )
+ : maName( aName ), mnId( nId ), maImage( aImage )
{
}
@@ -56,23 +56,9 @@ ImageAryData& ImageAryData::operator=( const ImageAryData& rData )
{
maName = rData.maName;
mnId = rData.mnId;
- maBitmapEx = rData.maBitmapEx;
+ maImage = rData.maImage;
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);
-
- 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 dbdb9459440f..57cbe28b10e7 100644
--- a/framework/source/uiconfiguration/ImageList.cxx
+++ b/framework/source/uiconfiguration/ImageList.cxx
@@ -44,9 +44,7 @@ ImageList::ImageList(const std::vector< OUString >& rNameVector,
mpImplData->maPrefix = rPrefix;
for( size_t i = 0; i < rNameVector.size(); ++i )
- {
- mpImplData->AddImage( rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, BitmapEx() );
- }
+ mpImplData->AddImage( rPrefix, rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, Image() );
}
void ImageList::ImplInit( sal_uInt16 nItems, const Size &rSize )
@@ -65,15 +63,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const
return BitmapEx();
aSize.Width() *= nCount;
- // Load any stragglers
- for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
- {
- ImageAryData *pData = mpImplData->maImages[ nIdx ];
- if( pData->IsLoadable() )
- pData->Load( mpImplData->maPrefix );
- }
-
- BitmapEx aTempl = mpImplData->maImages[ 0 ]->maBitmapEx;
+ BitmapEx aTempl = mpImplData->maImages[ 0 ]->maImage.GetBitmapEx();
BitmapEx aResult;
Bitmap aPixels( aSize, aTempl.GetBitmap().GetBitCount() );
if( aTempl.IsAlpha() )
@@ -87,9 +77,10 @@ BitmapEx ImageList::GetAsHorizontalStrip() const
for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
{
tools::Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ),
- mpImplData->maImageSize );
+ mpImplData->maImageSize );
ImageAryData *pData = mpImplData->maImages[ nIdx ];
- aResult.CopyPixel( aDestRect, aSrcRect, &pData->maBitmapEx);
+ BitmapEx aTmp = pData->maImage.GetBitmapEx();
+ aResult.CopyPixel( aDestRect, aSrcRect, &aTmp );
}
return aResult;
@@ -112,7 +103,7 @@ void ImageList::InsertFromHorizontalStrip( const BitmapEx &rBitmapEx,
for (sal_uInt16 nIdx = 0; nIdx < nItems; nIdx++)
{
BitmapEx aBitmap( rBitmapEx, Point( nIdx * aSize.Width(), 0 ), aSize );
- mpImplData->AddImage( rNameVector[ nIdx ], nIdx + 1, aBitmap );
+ mpImplData->AddImage( mpImplData->maPrefix, rNameVector[ nIdx ], nIdx + 1, Image( aBitmap ) );
}
}
@@ -132,8 +123,7 @@ void ImageList::AddImage( const OUString& rImageName, const Image& rImage )
if( !mpImplData )
ImplInit( 0, rImage.GetSizePixel() );
- mpImplData->AddImage( rImageName, GetImageCount() + 1,
- rImage.GetBitmapEx() );
+ mpImplData->AddImage( mpImplData->maPrefix, rImageName, GetImageCount() + 1, rImage );
}
void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage )
@@ -142,10 +132,10 @@ void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage )
if( nId )
{
- //Just replace the bitmap rather than doing RemoveImage / AddImage
- //which breaks index-based iteration.
+ // Just replace the bitmap rather than doing RemoveImage / AddImage
+ // which breaks index-based iteration.
ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
- pImg->maBitmapEx = rImage.GetBitmapEx();
+ pImg->maImage = rImage;
}
}
@@ -166,13 +156,8 @@ 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 pImg->maImage;
}
return Image();
diff --git a/framework/source/uiconfiguration/ImplImageList.cxx b/framework/source/uiconfiguration/ImplImageList.cxx
index 19bb1e8a1266..a349a865bcde 100644
--- a/framework/source/uiconfiguration/ImplImageList.cxx
+++ b/framework/source/uiconfiguration/ImplImageList.cxx
@@ -53,10 +53,13 @@ ImplImageList::~ImplImageList()
delete *aIt;
}
-void ImplImageList::AddImage( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmapEx )
+void ImplImageList::AddImage( const OUString &aPrefix, const OUString &aName,
+ sal_uInt16 nId, const Image &aImage )
{
- ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx );
+ Image aInsert = aImage;
+ if (!aInsert)
+ aInsert = Image( "private:graphicrepository/" + aPrefix + aName );
+ ImageAryData *pImg = new ImageAryData( aName, nId, aInsert );
maImages.push_back( pImg );
if( !aName.isEmpty() )
maNameHash [ aName ] = pImg;
diff --git a/framework/source/uiconfiguration/image.h b/framework/source/uiconfiguration/image.h
index 1005fc39cdf1..4e903cc9b743 100644
--- a/framework/source/uiconfiguration/image.h
+++ b/framework/source/uiconfiguration/image.h
@@ -30,16 +30,13 @@ struct ImageAryData
OUString maName;
// Images identified by either name, or by id
sal_uInt16 mnId;
- BitmapEx maBitmapEx;
+ Image maImage;
ImageAryData( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmap );
+ sal_uInt16 nId, const Image &aImage );
ImageAryData( const ImageAryData& rData );
~ImageAryData();
- bool IsLoadable() { return maBitmapEx.IsEmpty() && !maName.isEmpty(); }
- void Load(const OUString &rPrefix);
-
ImageAryData& operator=( const ImageAryData& rData );
};
@@ -57,8 +54,8 @@ struct ImplImageList
ImplImageList( const ImplImageList &aSrc );
~ImplImageList();
- void AddImage( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmapEx );
+ void AddImage( const OUString &aPrefix, const OUString &aName,
+ sal_uInt16 nId, const Image &aImage );
void RemoveImage( sal_uInt16 nPos );
};
diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx
index ded9db11ee2e..6c5a627bbe94 100644
--- a/framework/source/uiconfiguration/imagemanagerimpl.cxx
+++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx
@@ -722,7 +722,7 @@ namespace
{
css::uno::Reference< css::graphic::XGraphic > GetXGraphic(const Image &rImage)
{
- return Graphic(rImage.GetBitmapEx()).GetXGraphic();
+ return Graphic(rImage).GetXGraphic();
}
}
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index b232dc4b0990..72032931704b 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -101,6 +101,7 @@ public:
bool getSnapHorVerLines() const { return mbSnapHorVerLines; }
};
+class Image;
class VCL_DLLPUBLIC Graphic
{
private:
@@ -117,6 +118,7 @@ public:
Graphic( const Graphic& rGraphic );
Graphic( Graphic&& rGraphic );
Graphic( const Bitmap& rBmp );
+ Graphic( const Image& rImage );
Graphic( const BitmapEx& rBmpEx );
Graphic( const VectorGraphicDataPtr& rVectorGraphicDataPtr );
Graphic( const Animation& rAnimation );
diff --git a/include/vcl/image.hxx b/include/vcl/image.hxx
index 4577bd8fbed1..058a985e237d 100644
--- a/include/vcl/image.hxx
+++ b/include/vcl/image.hxx
@@ -52,7 +52,6 @@ namespace vcl
class SAL_WARN_UNUSED VCL_DLLPUBLIC Image
{
friend class ::OutputDevice;
-
public:
Image();
explicit Image( const BitmapEx& rBitmapEx );
@@ -67,6 +66,8 @@ public:
bool operator==( const Image& rImage ) const;
bool operator!=( const Image& rImage ) const { return !(Image::operator==( rImage )); }
+ SAL_DLLPRIVATE OUString GetStock() const;
+
void Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize = nullptr);
private:
diff --git a/sfx2/source/sidebar/Tools.cxx b/sfx2/source/sidebar/Tools.cxx
index e246599fd9c0..f0b0c3021b56 100644
--- a/sfx2/source/sidebar/Tools.cxx
+++ b/sfx2/source/sidebar/Tools.cxx
@@ -55,11 +55,14 @@ Image Tools::GetImage (
{
if (rsURL.getLength() > 0)
{
+ OUString sPath;
+
if (rsURL.startsWith(".uno:"))
- {
- const Image aPanelImage(vcl::CommandInfoProvider::GetImageForCommand(rsURL, rxFrame));
- return aPanelImage;
- }
+ return vcl::CommandInfoProvider::GetImageForCommand(rsURL, rxFrame);
+
+ else if (rsURL.startsWith("private:graphicrepository/", &sPath))
+ return Image(rsURL);
+
else
{
const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext());
@@ -70,8 +73,7 @@ Image Tools::GetImage (
const Reference<graphic::XGraphic> xGraphic (
xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()),
UNO_QUERY);
- if (xGraphic.is())
- return Image(xGraphic);
+ return Image(xGraphic);
}
}
return Image();
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index c0e9bb444a4b..73f623071a74 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -21,6 +21,7 @@
#include <vcl/outdev.hxx>
#include <vcl/svapp.hxx>
#include <vcl/graph.hxx>
+#include <vcl/image.hxx>
#include <vcl/metaact.hxx>
#include <impgraph.hxx>
#include <comphelper/processfactory.hxx>
@@ -32,6 +33,8 @@
#include <com/sun/star/graphic/XGraphic.hpp>
#include <cppuhelper/typeprovider.hxx>
+#include "image.h"
+
using namespace ::com::sun::star;
namespace
@@ -209,6 +212,17 @@ Graphic::Graphic(const BitmapEx& rBmpEx)
{
}
+// We use XGraphic for passing toolbar images across app UNO aps
+// and we need to be able to see and preserve 'stock' images too.
+Graphic::Graphic(const Image& rImage)
+ // FIXME: should really defer the BitmapEx load.
+ : mxImpGraphic(new ImpGraphic(rImage.GetBitmapEx()))
+{
+ OUString aStock = rImage.GetStock();
+ if (aStock.getLength())
+ mxImpGraphic->setOriginURL("private:graphicrepository/" + aStock);
+}
+
Graphic::Graphic(const VectorGraphicDataPtr& rVectorGraphicDataPtr)
: mxImpGraphic(new ImpGraphic(rVectorGraphicDataPtr))
{
diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx
index 931900ad2abe..fb0df8071c73 100644
--- a/vcl/source/helper/commandinfoprovider.cxx
+++ b/vcl/source/helper/commandinfoprovider.cxx
@@ -293,13 +293,13 @@ OUString GetRealCommandForCommand(const OUString& rCommandName,
return GetCommandProperty("TargetURL", rCommandName, rsModuleName);
}
-BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
- const Reference<frame::XFrame>& rxFrame,
- vcl::ImageType eImageType)
+Image GetImageForCommand(const OUString& rsCommandName,
+ const Reference<frame::XFrame>& rxFrame,
+ vcl::ImageType eImageType)
{
if (rsCommandName.isEmpty())
- return BitmapEx();
+ return Image();
sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT);
@@ -308,6 +308,8 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
else if (eImageType == vcl::ImageType::Size32)
nImageType |= ui::ImageType::SIZE_32;
+ Image aRet;
+
try
{
Reference<frame::XController> xController(rxFrame->getController(), UNO_SET_THROW);
@@ -321,12 +323,11 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
Sequence<OUString> aImageCmdSeq { rsCommandName };
aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
- Reference<graphic::XGraphic> xGraphic = aGraphicSeq[0];
- const Graphic aGraphic(xGraphic);
- BitmapEx aBitmap(aGraphic.GetBitmapEx());
- if (!!aBitmap)
- return aBitmap;
+ aRet = Image( aGraphicSeq[0] );
+
+ if (!!aRet)
+ return aRet;
}
}
catch (Exception&)
@@ -344,31 +345,19 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
aGraphicSeq = xModuleImageManager->getImages(nImageType, aImageCmdSeq);
- Reference<graphic::XGraphic> xGraphic(aGraphicSeq[0]);
-
- const Graphic aGraphic(xGraphic);
-
- return aGraphic.GetBitmapEx();
+ aRet = Image(aGraphicSeq[0]);
}
catch (Exception&)
{
}
- return BitmapEx();
-}
-
-Image GetImageForCommand(const OUString& rsCommandName,
- const Reference<frame::XFrame>& rxFrame,
- vcl::ImageType eImageType)
-{
- return Image(GetBitmapForCommand(rsCommandName, rxFrame, eImageType));
+ return aRet;
}
sal_Int32 GetPropertiesForCommand (
const OUString& rsCommandName,
const OUString& rsModuleName)
{
-
sal_Int32 nValue = 0;
const Sequence<beans::PropertyValue> aProperties (GetCommandProperties(rsCommandName, rsModuleName));
for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex)
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx
index 4232173f80d6..106e9e21ec4d 100644
--- a/vcl/source/image/Image.cxx
+++ b/vcl/source/image/Image.cxx
@@ -48,21 +48,24 @@ Image::Image(const BitmapEx& rBitmapEx)
Image::Image(const css::uno::Reference< css::graphic::XGraphic >& rxGraphic)
{
- const Graphic aGraphic(rxGraphic);
- ImplInit(aGraphic.GetBitmapEx());
+ if (rxGraphic.is())
+ {
+ const Graphic aGraphic(rxGraphic);
+
+ OUString aPath;
+ if (aGraphic.getOriginURL().startsWith("private:graphicrepository/", &aPath))
+ mpImplData.reset(new ImplImage(aPath));
+ else
+ ImplInit(aGraphic.GetBitmapEx());
+ }
}
Image::Image(const OUString & rFileUrl)
{
OUString aPath;
- sal_Int32 nIndex = 0;
- if (rFileUrl.getToken( 0, '/', nIndex ) == "private:graphicrepository")
- {
- OUString sPathName(rFileUrl.copy(nIndex));
- BitmapEx aBitmapEx;
- if (vcl::ImageRepository::loadImage(sPathName, aBitmapEx))
- mpImplData.reset(new ImplImage(rFileUrl.copy(nIndex)));
- }
+ if (rFileUrl.startsWith("private:graphicrepository/", &aPath))
+ mpImplData.reset(new ImplImage(aPath));
+
else
{
osl::FileBase::getSystemPathFromFileURL(rFileUrl, aPath);
@@ -79,6 +82,13 @@ void Image::ImplInit(const BitmapEx& rBitmapEx)
mpImplData.reset(new ImplImage(rBitmapEx));
}
+OUString Image::GetStock() const
+{
+ if (mpImplData)
+ return mpImplData->maStockName;
+ return OUString();
+}
+
Size Image::GetSizePixel() const
{
if (mpImplData)