[Libreoffice-commits] core.git: 2 commits - framework/source include/vcl vcl/Library_vcl.mk vcl/source
Tomaž Vajngerl
tomaz.vajngerl at collabora.com
Thu Nov 19 04:05:07 PST 2015
framework/source/uiconfiguration/imagemanagerimpl.cxx | 175 ----
framework/source/uiconfiguration/imagemanagerimpl.hxx | 29
include/vcl/CommandImageResolver.hxx | 64 +
vcl/Library_vcl.mk | 14
vcl/source/bitmap/CommandImageResolver.cxx | 161 ++++
vcl/source/gdi/image.cxx | 697 ------------------
vcl/source/gdi/imagerepository.cxx | 43 -
vcl/source/gdi/impimage.cxx | 393 ----------
vcl/source/gdi/impimagetree.cxx | 439 -----------
vcl/source/image/Image.cxx | 277 +++++++
vcl/source/image/ImageArrayData.cxx | 58 +
vcl/source/image/ImageList.cxx | 462 +++++++++++
vcl/source/image/ImageRepository.cxx | 43 +
vcl/source/image/ImplImage.cxx | 53 +
vcl/source/image/ImplImageBmp.cxx | 287 +++++++
vcl/source/image/ImplImageData.cxx | 48 +
vcl/source/image/ImplImageList.cxx | 75 +
vcl/source/image/ImplImageTree.cxx | 439 +++++++++++
18 files changed, 2019 insertions(+), 1738 deletions(-)
New commits:
commit 25d60232ff5d882017ffb88453f16fd6cef5534c
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Thu Nov 19 12:57:52 2015 +0100
vcl: move and split up "Image" related sources to "image" folder
This commit moves all sources related to Image class into its own
"vcl/source/image" folder. Sources containing more classes were
split up into its own source file.
Change-Id: Ie6edcdb0a7caf936bccdc210c31f78bb15667945
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index ef21b30..e828258 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -283,14 +283,10 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/gdi/graph \
vcl/source/gdi/graphictools \
vcl/source/gdi/hatch \
- vcl/source/gdi/image \
- vcl/source/gdi/imagerepository \
vcl/source/gdi/impanmvw \
vcl/source/gdi/impbmp \
vcl/source/gdi/impfont \
vcl/source/gdi/impgraph \
- vcl/source/gdi/impimage \
- vcl/source/gdi/impimagetree \
vcl/source/gdi/impvect \
vcl/source/gdi/jobset \
vcl/source/gdi/lineinfo \
@@ -329,6 +325,15 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/BitmapTools \
vcl/source/bitmap/checksum \
vcl/source/bitmap/CommandImageResolver \
+ vcl/source/image/Image \
+ vcl/source/image/ImageArrayData \
+ vcl/source/image/ImageList \
+ vcl/source/image/ImageRepository \
+ vcl/source/image/ImplImage \
+ vcl/source/image/ImplImageBmp \
+ vcl/source/image/ImplImageData \
+ vcl/source/image/ImplImageList \
+ vcl/source/image/ImplImageTree \
vcl/source/helper/canvasbitmap \
vcl/source/helper/canvastools \
vcl/source/helper/commandinfoprovider \
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx
new file mode 100644
index 0000000..cc1f467
--- /dev/null
+++ b/vcl/source/image/Image.cxx
@@ -0,0 +1,277 @@
+/* -*- 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 <osl/file.hxx>
+#include <tools/debug.hxx>
+#include <tools/stream.hxx>
+#include <tools/rc.h>
+#include <tools/rc.hxx>
+#include <tools/resmgr.hxx>
+#include <vcl/settings.hxx>
+#include <vcl/outdev.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/image.hxx>
+#include <vcl/imagerepository.hxx>
+#include <vcl/implimagetree.hxx>
+#include <image.h>
+
+#if OSL_DEBUG_LEVEL > 0
+#include <rtl/strbuf.hxx>
+#endif
+
+using namespace ::com::sun::star;
+
+Image::Image() :
+ mpImplData( nullptr )
+{
+}
+
+Image::Image( const ResId& rResId ) :
+ mpImplData( nullptr )
+{
+
+ rResId.SetRT( RSC_IMAGE );
+
+ ResMgr* pResMgr = rResId.GetResMgr();
+ if( pResMgr && pResMgr->GetResource( rResId ) )
+ {
+ pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
+
+ BitmapEx aBmpEx;
+ sal_uLong nObjMask = pResMgr->ReadLong();
+
+ if( nObjMask & RSC_IMAGE_IMAGEBITMAP )
+ {
+ aBmpEx = BitmapEx( ResId( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()), *pResMgr ) );
+ pResMgr->Increment( ResMgr::GetObjSize( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()) ) );
+ }
+
+ if( nObjMask & RSC_IMAGE_MASKBITMAP )
+ {
+ if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE )
+ {
+ const Bitmap aMaskBitmap( ResId( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()), *pResMgr ) );
+ aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskBitmap );
+ }
+
+ pResMgr->Increment( ResMgr::GetObjSize( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()) ) );
+ }
+
+ if( nObjMask & RSC_IMAGE_MASKCOLOR )
+ {
+ if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE )
+ {
+ const Color aMaskColor( ResId( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()), *pResMgr ) );
+ aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskColor );
+ }
+
+ pResMgr->Increment( ResMgr::GetObjSize( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()) ) );
+ }
+ if( ! aBmpEx.IsEmpty() )
+ ImplInit( aBmpEx );
+ }
+}
+
+Image::Image( const Image& rImage ) :
+ mpImplData( rImage.mpImplData )
+{
+
+ if( mpImplData )
+ ++mpImplData->mnRefCount;
+}
+
+Image::Image( const BitmapEx& rBitmapEx ) :
+ mpImplData( nullptr )
+{
+
+ ImplInit( rBitmapEx );
+}
+
+Image::Image( const Bitmap& rBitmap ) :
+ mpImplData( nullptr )
+{
+
+ ImplInit( rBitmap );
+}
+
+Image::Image( const Bitmap& rBitmap, const Bitmap& rMaskBitmap ) :
+ mpImplData( nullptr )
+{
+
+ const BitmapEx aBmpEx( rBitmap, rMaskBitmap );
+
+ ImplInit( aBmpEx );
+}
+
+Image::Image( const Bitmap& rBitmap, const Color& rColor ) :
+ mpImplData( nullptr )
+{
+
+ const BitmapEx aBmpEx( rBitmap, rColor );
+
+ ImplInit( aBmpEx );
+}
+
+Image::Image( const uno::Reference< graphic::XGraphic >& rxGraphic ) :
+ mpImplData( nullptr )
+{
+
+ const Graphic aGraphic( rxGraphic );
+ ImplInit( aGraphic.GetBitmapEx() );
+}
+
+Image::Image( const OUString &rFileUrl ) :
+ mpImplData( nullptr )
+{
+ OUString aTmp;
+ osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
+ Graphic aGraphic;
+ const OUString aFilterName( IMP_PNG );
+ if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
+ {
+ ImplInit( aGraphic.GetBitmapEx() );
+ }
+}
+
+Image::~Image()
+{
+
+ if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
+ delete mpImplData;
+}
+
+void Image::ImplInit( const BitmapEx& rBmpEx )
+{
+ if( !rBmpEx.IsEmpty() )
+ {
+ mpImplData = new ImplImage;
+
+ if( rBmpEx.GetTransparentType() == TRANSPARENT_NONE )
+ {
+ mpImplData->meType = IMAGETYPE_BITMAP;
+ mpImplData->mpData = new Bitmap( rBmpEx.GetBitmap() );
+ }
+ else
+ {
+ mpImplData->meType = IMAGETYPE_IMAGE;
+ mpImplData->mpData = new ImplImageData( rBmpEx );
+ }
+ }
+}
+
+Size Image::GetSizePixel() const
+{
+
+ Size aRet;
+
+ if( mpImplData )
+ {
+ switch( mpImplData->meType )
+ {
+ case IMAGETYPE_BITMAP:
+ aRet = static_cast< Bitmap* >( mpImplData->mpData )->GetSizePixel();
+ break;
+
+ case IMAGETYPE_IMAGE:
+ aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx.GetSizePixel();
+ break;
+ }
+ }
+
+ return aRet;
+}
+
+BitmapEx Image::GetBitmapEx() const
+{
+
+ BitmapEx aRet;
+
+ if( mpImplData )
+ {
+ switch( mpImplData->meType )
+ {
+ case IMAGETYPE_BITMAP:
+ aRet = *static_cast< Bitmap* >( mpImplData->mpData );
+ break;
+
+ case IMAGETYPE_IMAGE:
+ aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx;
+ break;
+ }
+ }
+
+ return aRet;
+}
+
+uno::Reference< graphic::XGraphic > Image::GetXGraphic() const
+{
+ const Graphic aGraphic( GetBitmapEx() );
+
+ return aGraphic.GetXGraphic();
+}
+
+Image& Image::operator=( const Image& rImage )
+{
+
+ if( rImage.mpImplData )
+ ++rImage.mpImplData->mnRefCount;
+
+ if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
+ delete mpImplData;
+
+ mpImplData = rImage.mpImplData;
+
+ return *this;
+}
+
+bool Image::operator==( const Image& rImage ) const
+{
+
+ bool bRet = false;
+
+ if( rImage.mpImplData == mpImplData )
+ bRet = true;
+ else if( !rImage.mpImplData || !mpImplData )
+ bRet = false;
+ else if( rImage.mpImplData->mpData == mpImplData->mpData )
+ bRet = true;
+ else if( rImage.mpImplData->meType == mpImplData->meType )
+ {
+ switch( mpImplData->meType )
+ {
+ case IMAGETYPE_BITMAP:
+ bRet = ( *static_cast< Bitmap* >( rImage.mpImplData->mpData ) == *static_cast< Bitmap* >( mpImplData->mpData ) );
+ break;
+
+ case IMAGETYPE_IMAGE:
+ bRet = static_cast< ImplImageData* >( rImage.mpImplData->mpData )->IsEqual( *static_cast< ImplImageData* >( mpImplData->mpData ) );
+ break;
+
+ default:
+ bRet = false;
+ break;
+ }
+ }
+
+ return bRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/image/ImageArrayData.cxx b/vcl/source/image/ImageArrayData.cxx
new file mode 100644
index 0000000..d7b3bbb
--- /dev/null
+++ b/vcl/source/image/ImageArrayData.cxx
@@ -0,0 +1,58 @@
+/* -*- 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/bmpacc.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/image.hxx>
+#include <vcl/settings.hxx>
+
+#include <image.h>
+#include <memory>
+
+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;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/image.cxx b/vcl/source/image/ImageList.cxx
similarity index 69%
rename from vcl/source/gdi/image.cxx
rename to vcl/source/image/ImageList.cxx
index 811fca5..6c2dff9 100644
--- a/vcl/source/gdi/image.cxx
+++ b/vcl/source/image/ImageList.cxx
@@ -39,241 +39,6 @@
using namespace ::com::sun::star;
-Image::Image() :
- mpImplData( nullptr )
-{
-}
-
-Image::Image( const ResId& rResId ) :
- mpImplData( nullptr )
-{
-
- rResId.SetRT( RSC_IMAGE );
-
- ResMgr* pResMgr = rResId.GetResMgr();
- if( pResMgr && pResMgr->GetResource( rResId ) )
- {
- pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
-
- BitmapEx aBmpEx;
- sal_uLong nObjMask = pResMgr->ReadLong();
-
- if( nObjMask & RSC_IMAGE_IMAGEBITMAP )
- {
- aBmpEx = BitmapEx( ResId( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()), *pResMgr ) );
- pResMgr->Increment( ResMgr::GetObjSize( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()) ) );
- }
-
- if( nObjMask & RSC_IMAGE_MASKBITMAP )
- {
- if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE )
- {
- const Bitmap aMaskBitmap( ResId( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()), *pResMgr ) );
- aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskBitmap );
- }
-
- pResMgr->Increment( ResMgr::GetObjSize( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()) ) );
- }
-
- if( nObjMask & RSC_IMAGE_MASKCOLOR )
- {
- if( !aBmpEx.IsEmpty() && aBmpEx.GetTransparentType() == TRANSPARENT_NONE )
- {
- const Color aMaskColor( ResId( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()), *pResMgr ) );
- aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMaskColor );
- }
-
- pResMgr->Increment( ResMgr::GetObjSize( static_cast<RSHEADER_TYPE*>(pResMgr->GetClass()) ) );
- }
- if( ! aBmpEx.IsEmpty() )
- ImplInit( aBmpEx );
- }
-}
-
-Image::Image( const Image& rImage ) :
- mpImplData( rImage.mpImplData )
-{
-
- if( mpImplData )
- ++mpImplData->mnRefCount;
-}
-
-Image::Image( const BitmapEx& rBitmapEx ) :
- mpImplData( nullptr )
-{
-
- ImplInit( rBitmapEx );
-}
-
-Image::Image( const Bitmap& rBitmap ) :
- mpImplData( nullptr )
-{
-
- ImplInit( rBitmap );
-}
-
-Image::Image( const Bitmap& rBitmap, const Bitmap& rMaskBitmap ) :
- mpImplData( nullptr )
-{
-
- const BitmapEx aBmpEx( rBitmap, rMaskBitmap );
-
- ImplInit( aBmpEx );
-}
-
-Image::Image( const Bitmap& rBitmap, const Color& rColor ) :
- mpImplData( nullptr )
-{
-
- const BitmapEx aBmpEx( rBitmap, rColor );
-
- ImplInit( aBmpEx );
-}
-
-Image::Image( const uno::Reference< graphic::XGraphic >& rxGraphic ) :
- mpImplData( nullptr )
-{
-
- const Graphic aGraphic( rxGraphic );
- ImplInit( aGraphic.GetBitmapEx() );
-}
-
-Image::Image( const OUString &rFileUrl ) :
- mpImplData( nullptr )
-{
- OUString aTmp;
- osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
- Graphic aGraphic;
- const OUString aFilterName( IMP_PNG );
- if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
- {
- ImplInit( aGraphic.GetBitmapEx() );
- }
-}
-
-Image::~Image()
-{
-
- if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
- delete mpImplData;
-}
-
-void Image::ImplInit( const BitmapEx& rBmpEx )
-{
- if( !rBmpEx.IsEmpty() )
- {
- mpImplData = new ImplImage;
-
- if( rBmpEx.GetTransparentType() == TRANSPARENT_NONE )
- {
- mpImplData->meType = IMAGETYPE_BITMAP;
- mpImplData->mpData = new Bitmap( rBmpEx.GetBitmap() );
- }
- else
- {
- mpImplData->meType = IMAGETYPE_IMAGE;
- mpImplData->mpData = new ImplImageData( rBmpEx );
- }
- }
-}
-
-Size Image::GetSizePixel() const
-{
-
- Size aRet;
-
- if( mpImplData )
- {
- switch( mpImplData->meType )
- {
- case IMAGETYPE_BITMAP:
- aRet = static_cast< Bitmap* >( mpImplData->mpData )->GetSizePixel();
- break;
-
- case IMAGETYPE_IMAGE:
- aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx.GetSizePixel();
- break;
- }
- }
-
- return aRet;
-}
-
-BitmapEx Image::GetBitmapEx() const
-{
-
- BitmapEx aRet;
-
- if( mpImplData )
- {
- switch( mpImplData->meType )
- {
- case IMAGETYPE_BITMAP:
- aRet = *static_cast< Bitmap* >( mpImplData->mpData );
- break;
-
- case IMAGETYPE_IMAGE:
- aRet = static_cast< ImplImageData* >( mpImplData->mpData )->maBmpEx;
- break;
- }
- }
-
- return aRet;
-}
-
-uno::Reference< graphic::XGraphic > Image::GetXGraphic() const
-{
- const Graphic aGraphic( GetBitmapEx() );
-
- return aGraphic.GetXGraphic();
-}
-
-Image& Image::operator=( const Image& rImage )
-{
-
- if( rImage.mpImplData )
- ++rImage.mpImplData->mnRefCount;
-
- if( mpImplData && ( 0 == --mpImplData->mnRefCount ) )
- delete mpImplData;
-
- mpImplData = rImage.mpImplData;
-
- return *this;
-}
-
-bool Image::operator==( const Image& rImage ) const
-{
-
- bool bRet = false;
-
- if( rImage.mpImplData == mpImplData )
- bRet = true;
- else if( !rImage.mpImplData || !mpImplData )
- bRet = false;
- else if( rImage.mpImplData->mpData == mpImplData->mpData )
- bRet = true;
- else if( rImage.mpImplData->meType == mpImplData->meType )
- {
- switch( mpImplData->meType )
- {
- case IMAGETYPE_BITMAP:
- bRet = ( *static_cast< Bitmap* >( rImage.mpImplData->mpData ) == *static_cast< Bitmap* >( mpImplData->mpData ) );
- break;
-
- case IMAGETYPE_IMAGE:
- bRet = static_cast< ImplImageData* >( rImage.mpImplData->mpData )->IsEqual( *static_cast< ImplImageData* >( mpImplData->mpData ) );
- break;
-
- default:
- bRet = false;
- break;
- }
- }
-
- return bRet;
-}
-
ImageList::ImageList( sal_uInt16 nInit, sal_uInt16 nGrow ) :
mpImplData( nullptr ),
mnInitSize( nInit ),
diff --git a/vcl/source/gdi/imagerepository.cxx b/vcl/source/image/ImageRepository.cxx
similarity index 100%
rename from vcl/source/gdi/imagerepository.cxx
rename to vcl/source/image/ImageRepository.cxx
diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx
new file mode 100644
index 0000000..9272cf0
--- /dev/null
+++ b/vcl/source/image/ImplImage.cxx
@@ -0,0 +1,53 @@
+/* -*- 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/bmpacc.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/image.hxx>
+#include <vcl/settings.hxx>
+
+#include <image.h>
+#include <memory>
+
+ImplImage::ImplImage()
+ : mnRefCount(1)
+ , mpData(nullptr)
+ , meType(IMAGETYPE_BITMAP)
+{
+}
+
+ImplImage::~ImplImage()
+{
+ switch( meType )
+ {
+ case IMAGETYPE_BITMAP:
+ delete static_cast< Bitmap* >( mpData );
+ break;
+
+ case IMAGETYPE_IMAGE:
+ delete static_cast< ImplImageData* >( mpData );
+ break;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/impimage.cxx b/vcl/source/image/ImplImageBmp.cxx
similarity index 81%
rename from vcl/source/gdi/impimage.cxx
rename to vcl/source/image/ImplImageBmp.cxx
index 813f05e..cb83cc3 100644
--- a/vcl/source/gdi/impimage.cxx
+++ b/vcl/source/image/ImplImageBmp.cxx
@@ -32,112 +32,6 @@
#define IMPSYSIMAGEITEM_MASK ( 0x01 )
#define IMPSYSIMAGEITEM_ALPHA ( 0x02 )
-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;
-}
-
-ImplImageList::ImplImageList()
- : mnRefCount(1)
-{
-}
-
-ImplImageList::ImplImageList( const ImplImageList &aSrc )
- : maPrefix(aSrc.maPrefix)
- , maImageSize(aSrc.maImageSize)
- , mnRefCount(1)
-{
- maImages.reserve( aSrc.maImages.size() );
- for ( ImageAryDataVec::const_iterator aIt = aSrc.maImages.begin(), aEnd = aSrc.maImages.end(); aIt != aEnd; ++aIt )
- {
- ImageAryData* pAryData = new ImageAryData( **aIt );
- maImages.push_back( pAryData );
- if( !pAryData->maName.isEmpty() )
- maNameHash [ pAryData->maName ] = pAryData;
- }
-}
-
-ImplImageList::~ImplImageList()
-{
- for ( ImageAryDataVec::iterator aIt = maImages.begin(), aEnd = maImages.end(); aIt != aEnd; ++aIt )
- delete *aIt;
-}
-
-void ImplImageList::AddImage( const OUString &aName,
- sal_uInt16 nId, const BitmapEx &aBitmapEx )
-{
- ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx );
- maImages.push_back( pImg );
- if( !aName.isEmpty() )
- maNameHash [ aName ] = pImg;
-}
-
-void ImplImageList::RemoveImage( sal_uInt16 nPos )
-{
- ImageAryData *pImg = maImages[ nPos ];
- if( !pImg->maName.isEmpty() )
- maNameHash.erase( pImg->maName );
- maImages.erase( maImages.begin() + nPos );
-}
-
-ImplImageData::ImplImageData( const BitmapEx& rBmpEx ) :
- mpImageBitmap( nullptr ),
- maBmpEx( rBmpEx )
-{
-}
-
-ImplImageData::~ImplImageData()
-{
- delete mpImageBitmap;
-}
-
-bool ImplImageData::IsEqual( const ImplImageData& rData )
-{
- return( maBmpEx == rData.maBmpEx );
-}
-
-ImplImage::ImplImage()
- : mnRefCount(1)
- , mpData(nullptr)
- , meType(IMAGETYPE_BITMAP)
-{
-}
-
-ImplImage::~ImplImage()
-{
- switch( meType )
- {
- case IMAGETYPE_BITMAP:
- delete static_cast< Bitmap* >( mpData );
- break;
-
- case IMAGETYPE_IMAGE:
- delete static_cast< ImplImageData* >( mpData );
- break;
- }
-}
-
ImplImageBmp::ImplImageBmp()
: maBitmapChecksum(0)
, mpDisplayBmp(nullptr)
diff --git a/vcl/source/image/ImplImageData.cxx b/vcl/source/image/ImplImageData.cxx
new file mode 100644
index 0000000..6fc0747
--- /dev/null
+++ b/vcl/source/image/ImplImageData.cxx
@@ -0,0 +1,48 @@
+/* -*- 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/bmpacc.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/image.hxx>
+#include <vcl/settings.hxx>
+
+#include <image.h>
+#include <memory>
+
+ImplImageData::ImplImageData( const BitmapEx& rBmpEx ) :
+ mpImageBitmap( nullptr ),
+ maBmpEx( rBmpEx )
+{
+}
+
+ImplImageData::~ImplImageData()
+{
+ delete mpImageBitmap;
+}
+
+bool ImplImageData::IsEqual( const ImplImageData& rData )
+{
+ return( maBmpEx == rData.maBmpEx );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/image/ImplImageList.cxx b/vcl/source/image/ImplImageList.cxx
new file mode 100644
index 0000000..bc137fc
--- /dev/null
+++ b/vcl/source/image/ImplImageList.cxx
@@ -0,0 +1,75 @@
+/* -*- 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/bmpacc.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/image.hxx>
+#include <vcl/settings.hxx>
+
+#include <image.h>
+#include <memory>
+
+ImplImageList::ImplImageList()
+ : mnRefCount(1)
+{
+}
+
+ImplImageList::ImplImageList( const ImplImageList &aSrc )
+ : maPrefix(aSrc.maPrefix)
+ , maImageSize(aSrc.maImageSize)
+ , mnRefCount(1)
+{
+ maImages.reserve( aSrc.maImages.size() );
+ for ( ImageAryDataVec::const_iterator aIt = aSrc.maImages.begin(), aEnd = aSrc.maImages.end(); aIt != aEnd; ++aIt )
+ {
+ ImageAryData* pAryData = new ImageAryData( **aIt );
+ maImages.push_back( pAryData );
+ if( !pAryData->maName.isEmpty() )
+ maNameHash [ pAryData->maName ] = pAryData;
+ }
+}
+
+ImplImageList::~ImplImageList()
+{
+ for ( ImageAryDataVec::iterator aIt = maImages.begin(), aEnd = maImages.end(); aIt != aEnd; ++aIt )
+ delete *aIt;
+}
+
+void ImplImageList::AddImage( const OUString &aName,
+ sal_uInt16 nId, const BitmapEx &aBitmapEx )
+{
+ ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx );
+ maImages.push_back( pImg );
+ if( !aName.isEmpty() )
+ maNameHash [ aName ] = pImg;
+}
+
+void ImplImageList::RemoveImage( sal_uInt16 nPos )
+{
+ ImageAryData *pImg = maImages[ nPos ];
+ if( !pImg->maName.isEmpty() )
+ maNameHash.erase( pImg->maName );
+ maImages.erase( maImages.begin() + nPos );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/image/ImplImageTree.cxx
similarity index 100%
rename from vcl/source/gdi/impimagetree.cxx
rename to vcl/source/image/ImplImageTree.cxx
commit 6480b4d11a0cf2dd489d30b6290aa6d831704a45
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Wed Nov 18 18:42:40 2015 +0100
move translating a command name to image name out of framework
This is the first step to decouple resolving of command names to
image (icon) names. This is necessary to make allow additional
processing of images before the image is passed on and better
decision which image source to take.
Change-Id: I129dc6a1ae812aaaca32696ef2a2749d5fa86a54
diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx
index e62a7a7..5b5c0f5 100644
--- a/framework/source/uiconfiguration/imagemanagerimpl.cxx
+++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx
@@ -87,12 +87,8 @@ static const char* BITMAP_FILE_NAMES[] =
namespace framework
{
- static GlobalImageList* pGlobalImageList = nullptr;
- static const char* ImageType_Prefixes[ImageType_COUNT] =
- {
- "cmd/sc_",
- "cmd/lc_"
- };
+
+static GlobalImageList* pGlobalImageList = nullptr;
typedef GraphicNameAccess CmdToXGraphicNameAccess;
@@ -117,190 +113,79 @@ static GlobalImageList* getGlobalImageList( const uno::Reference< uno::XComponen
return pGlobalImageList;
}
-static OUString getCanonicalName( const OUString& rFileName )
-{
- bool bRemoveSlash( true );
- sal_Int32 nLength = rFileName.getLength();
- const sal_Unicode* pString = rFileName.getStr();
-
- OUStringBuffer aBuf( nLength );
- for ( sal_Int32 i = 0; i < nLength; i++ )
- {
- const sal_Unicode c = pString[i];
- switch ( c )
- {
- // map forbidden characters to escape
- case '/' : if ( !bRemoveSlash )
- aBuf.append( "%2f" );
- break;
- case '\\': aBuf.append( "%5c" ); bRemoveSlash = false; break;
- case ':' : aBuf.append( "%3a" ); bRemoveSlash = false; break;
- case '*' : aBuf.append( "%2a" ); bRemoveSlash = false; break;
- case '?' : aBuf.append( "%3f" ); bRemoveSlash = false; break;
- case '<' : aBuf.append( "%3c" ); bRemoveSlash = false; break;
- case '>' : aBuf.append( "%3e" ); bRemoveSlash = false; break;
- case '|' : aBuf.append( "%7c" ); bRemoveSlash = false; break;
- default: aBuf.append( c ); bRemoveSlash = false;
- }
- }
- return aBuf.makeStringAndClear();
-}
-
CmdImageList::CmdImageList( const uno::Reference< uno::XComponentContext >& rxContext, const OUString& aModuleIdentifier ) :
- m_bVectorInit( false ),
+ m_bInitialized(false),
m_aModuleIdentifier( aModuleIdentifier ),
- m_xContext( rxContext ),
- m_sIconTheme( SvtMiscOptions().GetIconTheme() )
+ m_xContext( rxContext )
{
- for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
- m_pImageList[n] = nullptr;
}
CmdImageList::~CmdImageList()
{
- for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
- delete m_pImageList[n];
}
-void CmdImageList::impl_fillCommandToImageNameMap()
+void CmdImageList::initialize()
{
- SAL_INFO( "fwk", "framework: CmdImageList::impl_fillCommandToImageNameMap" );
-
- if ( !m_bVectorInit )
+ if (!m_bInitialized)
{
- const OUString aCommandImageList( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST );
- Sequence< OUString > aCmdImageSeq;
- uno::Reference< XNameAccess > xCmdDesc = frame::theUICommandDescription::get( m_xContext );
+ const OUString aCommandImageList(UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST);
+
+ Sequence<OUString> aCommandImageSeq;
+ uno::Reference<XNameAccess> xCommandDesc = frame::theUICommandDescription::get(m_xContext);
- if ( !m_aModuleIdentifier.isEmpty() )
+ if (!m_aModuleIdentifier.isEmpty())
{
// If we have a module identifier - use to retrieve the command image name list from it.
// Otherwise we will use the global command image list
try
{
- xCmdDesc->getByName( m_aModuleIdentifier ) >>= xCmdDesc;
- if ( xCmdDesc.is() )
- xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
+ xCommandDesc->getByName(m_aModuleIdentifier) >>= xCommandDesc;
+ if (xCommandDesc.is())
+ xCommandDesc->getByName(aCommandImageList) >>= aCommandImageSeq;
}
- catch ( const NoSuchElementException& )
+ catch (const NoSuchElementException&)
{
// Module unknown we will work with an empty command image list!
return;
}
}
- if ( xCmdDesc.is() )
+ if (xCommandDesc.is())
{
try
{
- xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
+ xCommandDesc->getByName(aCommandImageList) >>= aCommandImageSeq;
}
- catch ( const NoSuchElementException& )
+ catch (const NoSuchElementException&)
{
}
- catch ( const WrappedTargetException& )
+ catch (const WrappedTargetException&)
{
}
}
- // We have to map commands which uses special characters like '/',':','?','\','<'.'>','|'
- OUString aExt = ".png";
- m_aImageCommandNameVector.resize(aCmdImageSeq.getLength() );
- m_aImageNameVector.resize( aCmdImageSeq.getLength() );
-
- ::std::copy( aCmdImageSeq.begin(), aCmdImageSeq.end(),
- m_aImageCommandNameVector.begin() );
-
- // Create a image name vector that must be provided to the vcl imagelist. We also need
- // a command to image name map to speed up access time for image retrieval.
- OUString aUNOString( ".uno:" );
- OUString aEmptyString;
- const sal_uInt32 nCount = m_aImageCommandNameVector.size();
- for ( sal_uInt32 i = 0; i < nCount; i++ )
- {
- OUString aCommandName( m_aImageCommandNameVector[i] );
- OUString aImageName;
-
- if ( aCommandName.indexOf( aUNOString ) != 0 )
- {
- INetURLObject aUrlObject( aCommandName, INetURLObject::ENCODE_ALL );
- aImageName = aUrlObject.GetURLPath();
- aImageName = getCanonicalName( aImageName ); // convert to valid filename
- }
- else
- {
- // just remove the schema
- if ( aCommandName.getLength() > 5 )
- aImageName = aCommandName.copy( 5 );
- else
- aImageName = aEmptyString;
+ m_aResolver.registerCommands(aCommandImageSeq);
- // Search for query part.
- if ( aImageName.indexOf('?') != -1 )
- aImageName = getCanonicalName( aImageName ); // convert to valid filename
- }
- // Image names are not case-dependent. Always use lower case characters to
- // reflect this.
- aImageName += aExt;
- aImageName = aImageName.toAsciiLowerCase();
-
- m_aImageNameVector[i] = aImageName;
- m_aCommandToImageNameMap.insert( CommandToImageNameMap::value_type( aCommandName, aImageName ));
- }
-
- m_bVectorInit = true;
- }
-}
-
-ImageList* CmdImageList::impl_getImageList( sal_Int16 nImageType )
-{
- SvtMiscOptions aMiscOptions;
-
- const OUString& rIconTheme = aMiscOptions.GetIconTheme();
- if ( rIconTheme != m_sIconTheme )
- {
- m_sIconTheme = rIconTheme;
- for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
- delete m_pImageList[n], m_pImageList[n] = nullptr;
- }
-
- if ( !m_pImageList[nImageType] )
- {
- m_pImageList[nImageType] = new ImageList( m_aImageNameVector,
- OUString::createFromAscii( ImageType_Prefixes[nImageType] ) );
+ m_bInitialized = true;
}
-
- return m_pImageList[nImageType];
}
-
-Image CmdImageList::getImageFromCommandURL( sal_Int16 nImageType, const OUString& rCommandURL )
+Image CmdImageList::getImageFromCommandURL(sal_Int16 nImageType, const OUString& rCommandURL)
{
- impl_fillCommandToImageNameMap();
- CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
- if ( pIter != m_aCommandToImageNameMap.end() )
- {
- ImageList* pImageList = impl_getImageList( nImageType );
- return pImageList->GetImage( pIter->second );
- }
-
- return Image();
+ initialize();
+ return m_aResolver.getImageFromCommandURL(nImageType, rCommandURL);
}
-bool CmdImageList::hasImage( sal_Int16 /*nImageType*/, const OUString& rCommandURL )
+bool CmdImageList::hasImage(sal_Int16 /*nImageType*/, const OUString& rCommandURL)
{
- impl_fillCommandToImageNameMap();
- CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
- if ( pIter != m_aCommandToImageNameMap.end() )
- return true;
- else
- return false;
+ initialize();
+ return m_aResolver.hasImage(rCommandURL);
}
-::std::vector< OUString >& CmdImageList::getImageCommandNames()
+std::vector<OUString>& CmdImageList::getImageCommandNames()
{
- return impl_getImageCommandNameVector();
+ return m_aResolver.getCommandNames();
}
GlobalImageList::GlobalImageList( const uno::Reference< uno::XComponentContext >& rxContext ) :
@@ -330,7 +215,7 @@ bool GlobalImageList::hasImage( sal_Int16 nImageType, const OUString& rCommandUR
::std::vector< OUString >& GlobalImageList::getImageCommandNames()
{
osl::MutexGuard guard( getGlobalImageListMutex() );
- return impl_getImageCommandNameVector();
+ return CmdImageList::getImageCommandNames();
}
static bool implts_checkAndScaleGraphic( uno::Reference< XGraphic >& rOutGraphic, const uno::Reference< XGraphic >& rInGraphic, sal_Int16 nImageType )
diff --git a/framework/source/uiconfiguration/imagemanagerimpl.hxx b/framework/source/uiconfiguration/imagemanagerimpl.hxx
index 0ac09cc..f9c36ea 100644
--- a/framework/source/uiconfiguration/imagemanagerimpl.hxx
+++ b/framework/source/uiconfiguration/imagemanagerimpl.hxx
@@ -41,7 +41,6 @@
#include <cppuhelper/interfacecontainer.hxx>
#include <rtl/ustring.hxx>
-#include <vcl/image.hxx>
#include <rtl/ref.hxx>
#include <salhelper/simplereferenceobject.hxx>
@@ -49,33 +48,29 @@
#include <unordered_map>
#include <vector>
+#include <vcl/CommandImageResolver.hxx>
+
namespace framework
{
class CmdImageList
{
public:
- CmdImageList( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
- const OUString& aModuleIdentifier );
+ CmdImageList(const css::uno::Reference< css::uno::XComponentContext >& rxContext, const OUString& aModuleIdentifier);
virtual ~CmdImageList();
- virtual Image getImageFromCommandURL( sal_Int16 nImageType, const OUString& rCommandURL );
- virtual bool hasImage( sal_Int16 nImageType, const OUString& rCommandURL );
- virtual ::std::vector< OUString >& getImageCommandNames();
+ virtual Image getImageFromCommandURL(sal_Int16 nImageType, const OUString& rCommandURL);
+ virtual bool hasImage(sal_Int16 nImageType, const OUString& rCommandURL);
+ virtual std::vector<OUString>& getImageCommandNames();
protected:
- void impl_fillCommandToImageNameMap();
- ImageList* impl_getImageList( sal_Int16 nImageType );
- std::vector< OUString >& impl_getImageCommandNameVector() { return m_aImageCommandNameVector;}
+ void initialize();
private:
- bool m_bVectorInit;
- OUString m_aModuleIdentifier;
- ImageList* m_pImageList[ImageType_COUNT];
- CommandToImageNameMap m_aCommandToImageNameMap;
- css::uno::Reference< css::uno::XComponentContext > m_xContext;
- ::std::vector< OUString > m_aImageNameVector;
- ::std::vector< OUString > m_aImageCommandNameVector;
- OUString m_sIconTheme;
+ bool m_bInitialized;
+ vcl::CommandImageResolver m_aResolver;
+
+ OUString m_aModuleIdentifier;
+ css::uno::Reference<css::uno::XComponentContext> m_xContext;
};
class GlobalImageList : public CmdImageList, public salhelper::SimpleReferenceObject
diff --git a/include/vcl/CommandImageResolver.hxx b/include/vcl/CommandImageResolver.hxx
new file mode 100644
index 0000000..ad09df1
--- /dev/null
+++ b/include/vcl/CommandImageResolver.hxx
@@ -0,0 +1,64 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_VCL_COMMANDICONRESOLVER_HXX
+#define INCLUDED_VCL_COMMANDICONRESOLVER_HXX
+
+#include <vcl/dllapi.h>
+#include <vcl/image.hxx>
+
+#include <com/sun/star/uno/Sequence.hxx>
+
+#include <unordered_map>
+#include <vector>
+
+namespace vcl
+{
+
+enum ImageType
+{
+ ImageType_Color = 0,
+ ImageType_Color_Large,
+ ImageType_COUNT
+};
+
+class VCL_DLLPUBLIC CommandImageResolver
+{
+private:
+ typedef std::unordered_map<OUString, OUString, OUStringHash, std::equal_to<OUString>> CommandToImageNameMap;
+
+ CommandToImageNameMap m_aCommandToImageNameMap;
+ std::vector<OUString> m_aImageCommandNameVector;
+ std::vector<OUString> m_aImageNameVector;
+
+ ImageList* m_pImageList[ImageType_COUNT];
+ OUString m_sIconTheme;
+
+ ImageList* getImageList(sal_Int16 nImageType);
+
+public:
+ CommandImageResolver();
+ virtual ~CommandImageResolver();
+
+ bool registerCommands(css::uno::Sequence<OUString>& aCommandSequence);
+ Image getImageFromCommandURL(sal_Int16 nImageType, const OUString& rCommandURL);
+
+ std::vector<OUString>& getCommandNames()
+ {
+ return m_aImageCommandNameVector;
+ }
+
+ bool hasImage(const OUString& rCommandURL);
+};
+
+} // end namespace vcl
+
+#endif // INCLUDED_VCL_COMMANDICONRESOLVER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 0da204a..ef21b30 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -328,6 +328,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/BitmapProcessor \
vcl/source/bitmap/BitmapTools \
vcl/source/bitmap/checksum \
+ vcl/source/bitmap/CommandImageResolver \
vcl/source/helper/canvasbitmap \
vcl/source/helper/canvastools \
vcl/source/helper/commandinfoprovider \
diff --git a/vcl/source/bitmap/CommandImageResolver.cxx b/vcl/source/bitmap/CommandImageResolver.cxx
new file mode 100644
index 0000000..5c636d7
--- /dev/null
+++ b/vcl/source/bitmap/CommandImageResolver.cxx
@@ -0,0 +1,161 @@
+/* -*- 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/.
+ */
+
+#include <vcl/CommandImageResolver.hxx>
+
+#include <rtl/ustrbuf.hxx>
+#include <tools/urlobj.hxx>
+#include <svtools/miscopt.hxx>
+#include <officecfg/Office/Common.hxx>
+
+using css::uno::Sequence;
+
+namespace vcl
+{
+
+namespace
+{
+
+const char* ImageType_Prefixes[ImageType_COUNT] =
+{
+ "cmd/sc_",
+ "cmd/lc_"
+};
+
+OUString lclConvertToCanonicalName(const OUString& rFileName)
+{
+ bool bRemoveSlash(true);
+ sal_Int32 nLength = rFileName.getLength();
+ const sal_Unicode* pString = rFileName.getStr();
+
+ OUStringBuffer aBuffer(nLength);
+
+ for (sal_Int32 i = 0; i < nLength; i++)
+ {
+ const sal_Unicode cCurrentChar = pString[i];
+ switch (cCurrentChar)
+ {
+ // map forbidden characters to escape
+ case '/':
+ if (!bRemoveSlash)
+ aBuffer.append("%2f");
+ break;
+ case '\\': aBuffer.append("%5c"); bRemoveSlash = false; break;
+ case ':': aBuffer.append("%3a"); bRemoveSlash = false; break;
+ case '*': aBuffer.append("%2a"); bRemoveSlash = false; break;
+ case '?': aBuffer.append("%3f"); bRemoveSlash = false; break;
+ case '<': aBuffer.append("%3c"); bRemoveSlash = false; break;
+ case '>': aBuffer.append("%3e"); bRemoveSlash = false; break;
+ case '|': aBuffer.append("%7c"); bRemoveSlash = false; break;
+ default:
+ aBuffer.append(cCurrentChar); bRemoveSlash = false; break;
+ }
+ }
+ return aBuffer.makeStringAndClear();
+}
+
+} // end anonymouse namespace
+
+CommandImageResolver::CommandImageResolver()
+{
+ for (sal_Int32 n = 0; n < ImageType_COUNT; n++)
+ m_pImageList[n] = nullptr;
+}
+
+CommandImageResolver::~CommandImageResolver()
+{
+ for (sal_Int32 n = 0; n < ImageType_COUNT; n++)
+ delete m_pImageList[n];
+}
+
+bool CommandImageResolver::registerCommands(Sequence<OUString>& aCommandSequence)
+{
+ sal_Int32 nSequenceSize = aCommandSequence.getLength();
+
+ m_aImageCommandNameVector.resize(nSequenceSize);
+ m_aImageNameVector.resize(nSequenceSize);
+
+ for (sal_Int32 i = 0; i < nSequenceSize; ++i)
+ {
+ OUString aCommandName(aCommandSequence[i]);
+ OUString aImageName;
+
+ m_aImageCommandNameVector[i] = aCommandName;
+
+ if (aCommandName.indexOf(".uno:") != 0)
+ {
+ INetURLObject aUrlObject(aCommandName, INetURLObject::ENCODE_ALL);
+ aImageName = aUrlObject.GetURLPath();
+ aImageName = lclConvertToCanonicalName(aImageName);
+ }
+ else
+ {
+ // just remove the schema
+ if (aCommandName.getLength() > 5)
+ aImageName = aCommandName.copy(5);
+
+ // Search for query part.
+ if (aImageName.indexOf('?') != -1)
+ aImageName = lclConvertToCanonicalName(aImageName);
+ }
+
+ // Image names are not case-dependent. Always use lower case characters to
+ // reflect this.
+ aImageName = aImageName.toAsciiLowerCase();
+ aImageName += ".png";
+
+ m_aImageNameVector[i] = aImageName;
+ m_aCommandToImageNameMap[aCommandName] = aImageName;
+ }
+ return true;
+}
+
+bool CommandImageResolver::hasImage(const OUString& rCommandURL)
+{
+ CommandToImageNameMap::const_iterator pIterator = m_aCommandToImageNameMap.find(rCommandURL);
+ return pIterator != m_aCommandToImageNameMap.end();
+}
+
+ImageList* CommandImageResolver::getImageList(sal_Int16 nImageType)
+{
+ const OUString& rIconTheme = officecfg::Office::Common::Misc::SymbolStyle::get();
+
+ if (rIconTheme != m_sIconTheme)
+ {
+ m_sIconTheme = rIconTheme;
+ for (sal_Int32 n = 0; n < ImageType_COUNT; ++n)
+ {
+ delete m_pImageList[n];
+ m_pImageList[n] = nullptr;
+ }
+ }
+
+ if (!m_pImageList[nImageType])
+ {
+ OUString sIconPath = OUString::createFromAscii(ImageType_Prefixes[nImageType]);
+ m_pImageList[nImageType] = new ImageList(m_aImageNameVector, sIconPath);
+ }
+
+ return m_pImageList[nImageType];
+}
+
+Image CommandImageResolver::getImageFromCommandURL(sal_Int16 nImageType, const OUString& rCommandURL)
+{
+ CommandToImageNameMap::const_iterator pIterator = m_aCommandToImageNameMap.find(rCommandURL);
+ if (pIterator != m_aCommandToImageNameMap.end())
+ {
+ ImageList* pImageList = getImageList(nImageType);
+ return pImageList->GetImage(pIterator->second);
+ }
+ return Image();
+}
+
+} // end namespace vcl
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list