Kaydet (Commit) ca936bb8 authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Andras Timar

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)
üst 190fad51
...@@ -38,13 +38,13 @@ ...@@ -38,13 +38,13 @@
ImageAryData::ImageAryData( const ImageAryData& rData ) : ImageAryData::ImageAryData( const ImageAryData& rData ) :
maName( rData.maName ), maName( rData.maName ),
mnId( rData.mnId ), mnId( rData.mnId ),
maBitmapEx( rData.maBitmapEx ) maImage( rData.maImage )
{ {
} }
ImageAryData::ImageAryData( const OUString &aName, ImageAryData::ImageAryData( const OUString &aName,
sal_uInt16 nId, const BitmapEx &aBitmap ) sal_uInt16 nId, const Image &aImage )
: maName( aName ), mnId( nId ), maBitmapEx( aBitmap ) : maName( aName ), mnId( nId ), maImage( aImage )
{ {
} }
...@@ -56,23 +56,9 @@ ImageAryData& ImageAryData::operator=( const ImageAryData& rData ) ...@@ -56,23 +56,9 @@ ImageAryData& ImageAryData::operator=( const ImageAryData& rData )
{ {
maName = rData.maName; maName = rData.maName;
mnId = rData.mnId; mnId = rData.mnId;
maBitmapEx = rData.maBitmapEx; maImage = rData.maImage;
return *this; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -44,9 +44,7 @@ ImageList::ImageList(const std::vector< OUString >& rNameVector, ...@@ -44,9 +44,7 @@ ImageList::ImageList(const std::vector< OUString >& rNameVector,
mpImplData->maPrefix = rPrefix; mpImplData->maPrefix = rPrefix;
for( size_t i = 0; i < rNameVector.size(); ++i ) for( size_t i = 0; i < rNameVector.size(); ++i )
{ mpImplData->AddImage( rPrefix, rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, Image() );
mpImplData->AddImage( rNameVector[ i ], static_cast< sal_uInt16 >( i ) + 1, BitmapEx() );
}
} }
void ImageList::ImplInit( sal_uInt16 nItems, const Size &rSize ) void ImageList::ImplInit( sal_uInt16 nItems, const Size &rSize )
...@@ -65,15 +63,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const ...@@ -65,15 +63,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const
return BitmapEx(); return BitmapEx();
aSize.Width() *= nCount; aSize.Width() *= nCount;
// Load any stragglers BitmapEx aTempl = mpImplData->maImages[ 0 ]->maImage.GetBitmapEx();
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 aResult; BitmapEx aResult;
Bitmap aPixels( aSize, aTempl.GetBitmap().GetBitCount() ); Bitmap aPixels( aSize, aTempl.GetBitmap().GetBitCount() );
if( aTempl.IsAlpha() ) if( aTempl.IsAlpha() )
...@@ -87,9 +77,10 @@ BitmapEx ImageList::GetAsHorizontalStrip() const ...@@ -87,9 +77,10 @@ BitmapEx ImageList::GetAsHorizontalStrip() const
for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++) for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
{ {
tools::Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ), tools::Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ),
mpImplData->maImageSize ); mpImplData->maImageSize );
ImageAryData *pData = mpImplData->maImages[ nIdx ]; ImageAryData *pData = mpImplData->maImages[ nIdx ];
aResult.CopyPixel( aDestRect, aSrcRect, &pData->maBitmapEx); BitmapEx aTmp = pData->maImage.GetBitmapEx();
aResult.CopyPixel( aDestRect, aSrcRect, &aTmp );
} }
return aResult; return aResult;
...@@ -112,7 +103,7 @@ void ImageList::InsertFromHorizontalStrip( const BitmapEx &rBitmapEx, ...@@ -112,7 +103,7 @@ void ImageList::InsertFromHorizontalStrip( const BitmapEx &rBitmapEx,
for (sal_uInt16 nIdx = 0; nIdx < nItems; nIdx++) for (sal_uInt16 nIdx = 0; nIdx < nItems; nIdx++)
{ {
BitmapEx aBitmap( rBitmapEx, Point( nIdx * aSize.Width(), 0 ), aSize ); 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 ) ...@@ -132,8 +123,7 @@ void ImageList::AddImage( const OUString& rImageName, const Image& rImage )
if( !mpImplData ) if( !mpImplData )
ImplInit( 0, rImage.GetSizePixel() ); ImplInit( 0, rImage.GetSizePixel() );
mpImplData->AddImage( rImageName, GetImageCount() + 1, mpImplData->AddImage( mpImplData->maPrefix, rImageName, GetImageCount() + 1, rImage );
rImage.GetBitmapEx() );
} }
void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage ) void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage )
...@@ -142,10 +132,10 @@ void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage ) ...@@ -142,10 +132,10 @@ void ImageList::ReplaceImage( const OUString& rImageName, const Image& rImage )
if( nId ) if( nId )
{ {
//Just replace the bitmap rather than doing RemoveImage / AddImage // Just replace the bitmap rather than doing RemoveImage / AddImage
//which breaks index-based iteration. // which breaks index-based iteration.
ImageAryData *pImg = mpImplData->maNameHash[ rImageName ]; ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
pImg->maBitmapEx = rImage.GetBitmapEx(); pImg->maImage = rImage;
} }
} }
...@@ -166,13 +156,8 @@ Image ImageList::GetImage( const OUString& rImageName ) const ...@@ -166,13 +156,8 @@ Image ImageList::GetImage( const OUString& rImageName ) const
if( mpImplData ) if( mpImplData )
{ {
ImageAryData *pImg = mpImplData->maNameHash[ rImageName ]; ImageAryData *pImg = mpImplData->maNameHash[ rImageName ];
if( pImg ) if( pImg )
{ return pImg->maImage;
if( pImg->IsLoadable() )
pImg->Load( mpImplData->maPrefix );
return Image( pImg->maBitmapEx );
}
} }
return Image(); return Image();
......
...@@ -53,10 +53,13 @@ ImplImageList::~ImplImageList() ...@@ -53,10 +53,13 @@ ImplImageList::~ImplImageList()
delete *aIt; delete *aIt;
} }
void ImplImageList::AddImage( const OUString &aName, void ImplImageList::AddImage( const OUString &aPrefix, const OUString &aName,
sal_uInt16 nId, const BitmapEx &aBitmapEx ) 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 ); maImages.push_back( pImg );
if( !aName.isEmpty() ) if( !aName.isEmpty() )
maNameHash [ aName ] = pImg; maNameHash [ aName ] = pImg;
......
...@@ -30,16 +30,13 @@ struct ImageAryData ...@@ -30,16 +30,13 @@ struct ImageAryData
OUString maName; OUString maName;
// Images identified by either name, or by id // Images identified by either name, or by id
sal_uInt16 mnId; sal_uInt16 mnId;
BitmapEx maBitmapEx; Image maImage;
ImageAryData( const OUString &aName, ImageAryData( const OUString &aName,
sal_uInt16 nId, const BitmapEx &aBitmap ); sal_uInt16 nId, const Image &aImage );
ImageAryData( const ImageAryData& rData ); ImageAryData( const ImageAryData& rData );
~ImageAryData(); ~ImageAryData();
bool IsLoadable() { return maBitmapEx.IsEmpty() && !maName.isEmpty(); }
void Load(const OUString &rPrefix);
ImageAryData& operator=( const ImageAryData& rData ); ImageAryData& operator=( const ImageAryData& rData );
}; };
...@@ -57,8 +54,8 @@ struct ImplImageList ...@@ -57,8 +54,8 @@ struct ImplImageList
ImplImageList( const ImplImageList &aSrc ); ImplImageList( const ImplImageList &aSrc );
~ImplImageList(); ~ImplImageList();
void AddImage( const OUString &aName, void AddImage( const OUString &aPrefix, const OUString &aName,
sal_uInt16 nId, const BitmapEx &aBitmapEx ); sal_uInt16 nId, const Image &aImage );
void RemoveImage( sal_uInt16 nPos ); void RemoveImage( sal_uInt16 nPos );
}; };
......
...@@ -722,7 +722,7 @@ namespace ...@@ -722,7 +722,7 @@ namespace
{ {
css::uno::Reference< css::graphic::XGraphic > GetXGraphic(const Image &rImage) css::uno::Reference< css::graphic::XGraphic > GetXGraphic(const Image &rImage)
{ {
return Graphic(rImage.GetBitmapEx()).GetXGraphic(); return Graphic(rImage).GetXGraphic();
} }
} }
......
...@@ -101,6 +101,7 @@ public: ...@@ -101,6 +101,7 @@ public:
bool getSnapHorVerLines() const { return mbSnapHorVerLines; } bool getSnapHorVerLines() const { return mbSnapHorVerLines; }
}; };
class Image;
class VCL_DLLPUBLIC Graphic class VCL_DLLPUBLIC Graphic
{ {
private: private:
...@@ -117,6 +118,7 @@ public: ...@@ -117,6 +118,7 @@ public:
Graphic( const Graphic& rGraphic ); Graphic( const Graphic& rGraphic );
Graphic( Graphic&& rGraphic ); Graphic( Graphic&& rGraphic );
Graphic( const Bitmap& rBmp ); Graphic( const Bitmap& rBmp );
Graphic( const Image& rImage );
Graphic( const BitmapEx& rBmpEx ); Graphic( const BitmapEx& rBmpEx );
Graphic( const VectorGraphicDataPtr& rVectorGraphicDataPtr ); Graphic( const VectorGraphicDataPtr& rVectorGraphicDataPtr );
Graphic( const Animation& rAnimation ); Graphic( const Animation& rAnimation );
......
...@@ -52,7 +52,6 @@ namespace vcl ...@@ -52,7 +52,6 @@ namespace vcl
class SAL_WARN_UNUSED VCL_DLLPUBLIC Image class SAL_WARN_UNUSED VCL_DLLPUBLIC Image
{ {
friend class ::OutputDevice; friend class ::OutputDevice;
public: public:
Image(); Image();
explicit Image( const BitmapEx& rBitmapEx ); explicit Image( const BitmapEx& rBitmapEx );
...@@ -67,6 +66,8 @@ public: ...@@ -67,6 +66,8 @@ public:
bool operator==( const Image& rImage ) const; bool operator==( const Image& rImage ) const;
bool operator!=( const Image& rImage ) const { return !(Image::operator==( rImage )); } 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); void Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize = nullptr);
private: private:
......
...@@ -55,11 +55,14 @@ Image Tools::GetImage ( ...@@ -55,11 +55,14 @@ Image Tools::GetImage (
{ {
if (rsURL.getLength() > 0) if (rsURL.getLength() > 0)
{ {
OUString sPath;
if (rsURL.startsWith(".uno:")) if (rsURL.startsWith(".uno:"))
{ return vcl::CommandInfoProvider::GetImageForCommand(rsURL, rxFrame);
const Image aPanelImage(vcl::CommandInfoProvider::GetImageForCommand(rsURL, rxFrame));
return aPanelImage; else if (rsURL.startsWith("private:graphicrepository/", &sPath))
} return Image(rsURL);
else else
{ {
const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext()); const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext());
...@@ -70,8 +73,7 @@ Image Tools::GetImage ( ...@@ -70,8 +73,7 @@ Image Tools::GetImage (
const Reference<graphic::XGraphic> xGraphic ( const Reference<graphic::XGraphic> xGraphic (
xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()), xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()),
UNO_QUERY); UNO_QUERY);
if (xGraphic.is()) return Image(xGraphic);
return Image(xGraphic);
} }
} }
return Image(); return Image();
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <vcl/outdev.hxx> #include <vcl/outdev.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/graph.hxx> #include <vcl/graph.hxx>
#include <vcl/image.hxx>
#include <vcl/metaact.hxx> #include <vcl/metaact.hxx>
#include <impgraph.hxx> #include <impgraph.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
...@@ -32,6 +33,8 @@ ...@@ -32,6 +33,8 @@
#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/graphic/XGraphic.hpp>
#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/typeprovider.hxx>
#include "image.h"
using namespace ::com::sun::star; using namespace ::com::sun::star;
namespace namespace
...@@ -209,6 +212,17 @@ Graphic::Graphic(const BitmapEx& rBmpEx) ...@@ -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) Graphic::Graphic(const VectorGraphicDataPtr& rVectorGraphicDataPtr)
: mxImpGraphic(new ImpGraphic(rVectorGraphicDataPtr)) : mxImpGraphic(new ImpGraphic(rVectorGraphicDataPtr))
{ {
......
...@@ -293,13 +293,13 @@ OUString GetRealCommandForCommand(const OUString& rCommandName, ...@@ -293,13 +293,13 @@ OUString GetRealCommandForCommand(const OUString& rCommandName,
return GetCommandProperty("TargetURL", rCommandName, rsModuleName); return GetCommandProperty("TargetURL", rCommandName, rsModuleName);
} }
BitmapEx GetBitmapForCommand(const OUString& rsCommandName, Image GetImageForCommand(const OUString& rsCommandName,
const Reference<frame::XFrame>& rxFrame, const Reference<frame::XFrame>& rxFrame,
vcl::ImageType eImageType) vcl::ImageType eImageType)
{ {
if (rsCommandName.isEmpty()) if (rsCommandName.isEmpty())
return BitmapEx(); return Image();
sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT); sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT);
...@@ -308,6 +308,8 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName, ...@@ -308,6 +308,8 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
else if (eImageType == vcl::ImageType::Size32) else if (eImageType == vcl::ImageType::Size32)
nImageType |= ui::ImageType::SIZE_32; nImageType |= ui::ImageType::SIZE_32;
Image aRet;
try try
{ {
Reference<frame::XController> xController(rxFrame->getController(), UNO_SET_THROW); Reference<frame::XController> xController(rxFrame->getController(), UNO_SET_THROW);
...@@ -321,12 +323,11 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName, ...@@ -321,12 +323,11 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
Sequence<OUString> aImageCmdSeq { rsCommandName }; Sequence<OUString> aImageCmdSeq { rsCommandName };
aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq ); aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
Reference<graphic::XGraphic> xGraphic = aGraphicSeq[0];
const Graphic aGraphic(xGraphic);
BitmapEx aBitmap(aGraphic.GetBitmapEx());
if (!!aBitmap) aRet = Image( aGraphicSeq[0] );
return aBitmap;
if (!!aRet)
return aRet;
} }
} }
catch (Exception&) catch (Exception&)
...@@ -344,31 +345,19 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName, ...@@ -344,31 +345,19 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
aGraphicSeq = xModuleImageManager->getImages(nImageType, aImageCmdSeq); aGraphicSeq = xModuleImageManager->getImages(nImageType, aImageCmdSeq);
Reference<graphic::XGraphic> xGraphic(aGraphicSeq[0]); aRet = Image(aGraphicSeq[0]);
const Graphic aGraphic(xGraphic);
return aGraphic.GetBitmapEx();
} }
catch (Exception&) catch (Exception&)
{ {
} }
return BitmapEx(); return aRet;
}
Image GetImageForCommand(const OUString& rsCommandName,
const Reference<frame::XFrame>& rxFrame,
vcl::ImageType eImageType)
{
return Image(GetBitmapForCommand(rsCommandName, rxFrame, eImageType));
} }
sal_Int32 GetPropertiesForCommand ( sal_Int32 GetPropertiesForCommand (
const OUString& rsCommandName, const OUString& rsCommandName,
const OUString& rsModuleName) const OUString& rsModuleName)
{ {
sal_Int32 nValue = 0; sal_Int32 nValue = 0;
const Sequence<beans::PropertyValue> aProperties (GetCommandProperties(rsCommandName, rsModuleName)); const Sequence<beans::PropertyValue> aProperties (GetCommandProperties(rsCommandName, rsModuleName));
for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex) for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex)
......
...@@ -48,21 +48,24 @@ Image::Image(const BitmapEx& rBitmapEx) ...@@ -48,21 +48,24 @@ Image::Image(const BitmapEx& rBitmapEx)
Image::Image(const css::uno::Reference< css::graphic::XGraphic >& rxGraphic) Image::Image(const css::uno::Reference< css::graphic::XGraphic >& rxGraphic)
{ {
const Graphic aGraphic(rxGraphic); if (rxGraphic.is())
ImplInit(aGraphic.GetBitmapEx()); {
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) Image::Image(const OUString & rFileUrl)
{ {
OUString aPath; OUString aPath;
sal_Int32 nIndex = 0; if (rFileUrl.startsWith("private:graphicrepository/", &aPath))
if (rFileUrl.getToken( 0, '/', nIndex ) == "private:graphicrepository") mpImplData.reset(new ImplImage(aPath));
{
OUString sPathName(rFileUrl.copy(nIndex));
BitmapEx aBitmapEx;
if (vcl::ImageRepository::loadImage(sPathName, aBitmapEx))
mpImplData.reset(new ImplImage(rFileUrl.copy(nIndex)));
}
else else
{ {
osl::FileBase::getSystemPathFromFileURL(rFileUrl, aPath); osl::FileBase::getSystemPathFromFileURL(rFileUrl, aPath);
...@@ -79,6 +82,13 @@ void Image::ImplInit(const BitmapEx& rBitmapEx) ...@@ -79,6 +82,13 @@ void Image::ImplInit(const BitmapEx& rBitmapEx)
mpImplData.reset(new ImplImage(rBitmapEx)); mpImplData.reset(new ImplImage(rBitmapEx));
} }
OUString Image::GetStock() const
{
if (mpImplData)
return mpImplData->maStockName;
return OUString();
}
Size Image::GetSizePixel() const Size Image::GetSizePixel() const
{ {
if (mpImplData) if (mpImplData)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment