28#include <com/sun/star/frame/theUICommandDescription.hpp>
29#include <com/sun/star/ui/ConfigurationEvent.hpp>
30#include <com/sun/star/lang/DisposedException.hpp>
31#include <com/sun/star/lang/IllegalAccessException.hpp>
32#include <com/sun/star/beans/XPropertySet.hpp>
33#include <com/sun/star/beans/PropertyValue.hpp>
34#include <com/sun/star/embed/ElementModes.hpp>
35#include <com/sun/star/embed/InvalidStorageException.hpp>
36#include <com/sun/star/embed/StorageWrappedTargetException.hpp>
37#include <com/sun/star/io/IOException.hpp>
38#include <com/sun/star/io/XStream.hpp>
39#include <com/sun/star/ui/ImageType.hpp>
48#include <unordered_set>
50using ::com::sun::star::uno::Sequence;
51using ::com::sun::star::uno::XInterface;
52using ::com::sun::star::uno::RuntimeException;
53using ::com::sun::star::uno::UNO_QUERY;
54using ::com::sun::star::uno::Any;
55using ::com::sun::star::graphic::XGraphic;
63using namespace ::
cppu;
91 static std::mutex
mutex;
106 m_bInitialized(false),
107 m_aModuleIdentifier(
std::move( aModuleIdentifier )),
123 Sequence<OUString> aCommandImageSeq;
124 uno::Reference<XNameAccess> xCommandDesc = frame::theUICommandDescription::get(
m_xContext);
133 if (xCommandDesc.is())
134 xCommandDesc->getByName(aCommandImageList) >>= aCommandImageSeq;
136 catch (
const NoSuchElementException&)
143 if (xCommandDesc.is())
147 xCommandDesc->getByName(aCommandImageList) >>= aCommandImageSeq;
149 catch (
const NoSuchElementException&)
152 catch (
const WrappedTargetException&)
212 if ( !rInGraphic.is() )
214 rOutGraphic = uno::Reference<graphic::XGraphic>();
228 aBitmap.
Scale(BITMAP_SIZE[nImageType]);
233 rOutGraphic = rInGraphic;
240 if (nImageType & css::ui::ImageType::SIZE_LARGE)
242 else if (nImageType & css::ui::ImageType::SIZE_32)
275 catch (
const css::container::NoSuchElementException& )
278 catch (
const css::embed::InvalidStorageException& )
281 catch (
const css::lang::IllegalArgumentException& )
284 catch (
const css::io::IOException& )
287 catch (
const css::embed::StorageWrappedTargetException& )
294 const uno::Reference< XStorage >& xUserImageStorage,
295 const uno::Reference< XStorage >& xUserBitmapsStorage )
299 if ( xUserImageStorage.is() && xUserBitmapsStorage.is() )
303 uno::Reference< XStream >
xStream = xUserImageStorage->openStreamElement( OUString::createFromAscii(
IMAGELIST_XML_FILE[nImageType] ),
304 ElementModes::READ );
305 uno::Reference< XInputStream > xInputStream =
xStream->getInputStream();
310 aUserImageListInfo );
311 if ( !aUserImageListInfo.empty() )
313 sal_Int32
nCount = aUserImageListInfo.size();
314 std::vector< OUString > aUserImagesVector;
315 aUserImagesVector.reserve(
nCount);
322 uno::Reference< XStream > xBitmapStream = xUserBitmapsStorage->openStreamElement(
324 ElementModes::READ );
326 if ( xBitmapStream.is() )
332 aUserBitmap = aPngReader.
read();
338 ( aUserBitmap, aUserImagesVector );
343 catch (
const css::container::NoSuchElementException& )
346 catch (
const css::embed::InvalidStorageException& )
349 catch (
const css::lang::IllegalArgumentException& )
352 catch (
const css::io::IOException& )
355 catch (
const css::embed::StorageWrappedTargetException& )
366 const uno::Reference< XStorage >& xUserImageStorage,
367 const uno::Reference< XStorage >& xUserBitmapsStorage )
383 aUserImageListInfo.push_back( aItem );
386 uno::Reference< XTransactedObject > xTransaction;
387 uno::Reference< XOutputStream > xOutputStream;
388 uno::Reference< XStream >
xStream = xUserImageStorage->openStreamElement( OUString::createFromAscii(
IMAGELIST_XML_FILE[nImageType] ),
389 ElementModes::WRITE|ElementModes::TRUNCATE );
392 uno::Reference< XStream > xBitmapStream =
393 xUserBitmapsStorage->openStreamElement( OUString::createFromAscii(
BITMAP_FILE_NAMES[nImageType] ),
394 ElementModes::WRITE|ElementModes::TRUNCATE );
395 if ( xBitmapStream.is() )
401 aPngWriter.
write( rBitmap );
405 xTransaction.set( xUserBitmapsStorage, UNO_QUERY );
406 if ( xTransaction.is() )
407 xTransaction->commit();
410 xOutputStream =
xStream->getOutputStream();
411 if ( xOutputStream.is() )
415 xTransaction.set( xUserImageStorage, UNO_QUERY );
416 if ( xTransaction.is() )
417 xTransaction->commit();
428 xUserImageStorage->removeElement( OUString::createFromAscii(
IMAGELIST_XML_FILE[nImageType] ));
430 catch (
const css::container::NoSuchElementException& )
436 xUserBitmapsStorage->removeElement( OUString::createFromAscii(
BITMAP_FILE_NAMES[nImageType] ));
438 catch (
const css::container::NoSuchElementException& )
442 uno::Reference< XTransactedObject > xTransaction;
445 xTransaction.set( xUserImageStorage, UNO_QUERY );
446 if ( xTransaction.is() )
447 xTransaction->commit();
450 xTransaction.set( xUserBitmapsStorage, UNO_QUERY );
451 if ( xTransaction.is() )
452 xTransaction->commit();
482 , m_aResourceString(
"private:resource/images/moduleimages" )
483 , m_bUseGlobal(_bUseGlobal)
485 , m_bInitialized( false )
486 , m_bModified( false )
503 uno::Reference< uno::XInterface > xOwner(
m_pOwner);
504 css::lang::EventObject
aEvent( xOwner );
506 std::unique_lock aGuard(
m_mutex);
510 std::unique_lock aGuard(
m_mutex);
538 throw DisposedException();
541 std::unique_lock aGuard(
m_mutex);
548 std::unique_lock aGuard(
m_mutex);
562 PropertyValue aPropValue;
563 if ( rArg >>= aPropValue )
565 if ( aPropValue.Name ==
"UserConfigStorage" )
569 else if ( aPropValue.Name ==
"ModuleIdentifier" )
573 else if ( aPropValue.Name ==
"UserRootCommit" )
586 if ( xPropSet->getPropertyValue(
"OpenMode") >>= nOpenMode )
587 m_bReadOnly = !( nOpenMode & ElementModes::WRITE );
603 throw DisposedException();
605 std::vector< OUString > aUserImageNames;
609 aUserImageNames.clear();
629 throw DisposedException();
631 std::unordered_set< OUString > aImageCmdNames;
640 const std::vector< OUString >& rGlobalImageNameVector = rGlobalImageList->getImageCommandNames();
641 const sal_uInt32 nGlobalCount = rGlobalImageNameVector.size();
642 for (
i = 0;
i < nGlobalCount;
i++ )
643 aImageCmdNames.insert( rGlobalImageNameVector[
i] );
646 const sal_uInt32 nModuleCount = rModuleImageNameVector.size();
647 for (
i = 0;
i < nModuleCount;
i++ )
648 aImageCmdNames.insert( rModuleImageNameVector[
i] );
652 std::vector< OUString > rUserImageNames;
654 const sal_uInt32 nUserCount = rUserImageNames.size();
655 for (
i = 0;
i < nUserCount;
i++ )
656 aImageCmdNames.insert( rUserImageNames[
i] );
667 throw DisposedException();
670 throw IllegalArgumentException();
693 css::uno::Reference< css::graphic::XGraphic > GetXGraphic(
const Image &rImage)
700 ::sal_Int16 nImageType,
701 const Sequence< OUString >& aCommandURLSequence )
707 throw DisposedException();
710 throw IllegalArgumentException();
712 Sequence< uno::Reference< XGraphic > > aGraphSeq( aCommandURLSequence.getLength() );
728 auto aGraphSeqRange = asNonConstRange(aGraphSeq);
730 for (
const OUString& rURL : aCommandURLSequence )
737 aImage = rGlobalImageList->getImageFromCommandURL(
nIndex, rURL );
740 aGraphSeqRange[
n++] = GetXGraphic(aImage);
747 ::sal_Int16 nImageType,
748 const Sequence< OUString >& aCommandURLSequence,
749 const Sequence< uno::Reference< XGraphic > >& aGraphicsSequence )
759 throw DisposedException();
761 if (( aCommandURLSequence.getLength() != aGraphicsSequence.getLength() ) ||
763 throw IllegalArgumentException();
766 throw IllegalAccessException();
771 uno::Reference< XGraphic > xGraphic;
772 for ( sal_Int32
i = 0;
i < aCommandURLSequence.getLength();
i++ )
782 if ( !pInsertedImages )
784 pInsertedImages->addElement( aCommandURLSequence[
i], xGraphic );
789 if ( !pReplacedImages )
791 pReplacedImages->addElement( aCommandURLSequence[
i], xGraphic );
795 if (( pInsertedImages !=
nullptr ) || ( pReplacedImages !=
nullptr ))
802 uno::Reference< uno::XInterface > xOwner(
m_pOwner);
804 if ( pInsertedImages !=
nullptr )
806 ConfigurationEvent aInsertEvent;
807 aInsertEvent.aInfo <<= nImageType;
808 aInsertEvent.Accessor <<= xOwner;
809 aInsertEvent.Source = xOwner;
811 aInsertEvent.Element <<= uno::Reference< XNameAccess >(pInsertedImages);
814 if ( pReplacedImages !=
nullptr )
816 ConfigurationEvent aReplaceEvent;
817 aReplaceEvent.aInfo <<= nImageType;
818 aReplaceEvent.Accessor <<= xOwner;
819 aReplaceEvent.Source = xOwner;
821 aReplaceEvent.ReplacedElement =
Any();
822 aReplaceEvent.Element <<= uno::Reference< XNameAccess >(pReplacedImages);
837 throw DisposedException();
840 throw IllegalArgumentException();
843 throw IllegalAccessException();
854 uno::Reference<XGraphic> xEmptyGraphic;
856 for (
const OUString& rURL : aCommandURLSequence )
870 aNewImage = rGlobalImageList->getImageFromCommandURL(
nIndex, rURL );
873 if ( !pRemovedImages )
875 pRemovedImages->addElement( rURL, xEmptyGraphic );
879 if ( !pReplacedImages )
881 pReplacedImages->addElement(rURL, GetXGraphic(aNewImage));
886 if ( !pRemovedImages )
888 pRemovedImages->addElement( rURL, xEmptyGraphic );
893 if (( pReplacedImages !=
nullptr ) || ( pRemovedImages !=
nullptr ))
901 uno::Reference< uno::XInterface > xOwner(
m_pOwner);
902 if ( pRemovedImages !=
nullptr )
904 ConfigurationEvent aRemoveEvent;
905 aRemoveEvent.aInfo <<= nImageType;
906 aRemoveEvent.Accessor <<= xOwner;
907 aRemoveEvent.Source = xOwner;
909 aRemoveEvent.Element <<= uno::Reference< XNameAccess >(pRemovedImages);
912 if ( pReplacedImages !=
nullptr )
914 ConfigurationEvent aReplaceEvent;
915 aReplaceEvent.aInfo <<= nImageType;
916 aReplaceEvent.Accessor <<= xOwner;
917 aReplaceEvent.Source = xOwner;
919 aReplaceEvent.ReplacedElement =
Any();
920 aReplaceEvent.Element <<= uno::Reference< XNameAccess >(pReplacedImages);
925void ImageManagerImpl::insertImages( ::sal_Int16 nImageType,
const Sequence< OUString >& aCommandURLSequence,
const Sequence< uno::Reference< XGraphic > >& aGraphicSequence )
927 replaceImages(nImageType,aCommandURLSequence,aGraphicSequence);
936 throw DisposedException();
939 std::vector< OUString > aNewUserCmdImageSet;
948 std::vector< OUString > aOldUserCmdImageVector;
954 const sal_uInt32 nOldCount = aOldUserCmdImageVector.size();
955 for ( j = 0; j < nOldCount; j++ )
956 aOldUserCmdImageSet.emplace( aOldUserCmdImageVector[j],
false );
967 for (
auto const& newUserCmdImage : aNewUserCmdImageSet)
969 CommandMap::iterator pIter = aOldUserCmdImageSet.find(newUserCmdImage);
970 if ( pIter != aOldUserCmdImageSet.end() )
972 pIter->second =
true;
973 if ( !pReplacedImages )
975 pReplacedImages->addElement( newUserCmdImage,
976 GetXGraphic(pImageList->
GetImage(newUserCmdImage)) );
980 if ( !pInsertedImages )
982 pInsertedImages->addElement( newUserCmdImage,
983 GetXGraphic(pImageList->
GetImage(newUserCmdImage)) );
997 uno::Reference<XGraphic> xEmptyGraphic;
998 for (
auto const& oldUserCmdImage : aOldUserCmdImageSet)
1000 if ( !oldUserCmdImage.second )
1006 aImage = rGlobalImageList->getImageFromCommandURL(
i, oldUserCmdImage.first );
1011 if ( !pRemovedImages )
1013 pRemovedImages->addElement( oldUserCmdImage.first, xEmptyGraphic );
1018 if ( !pReplacedImages )
1020 pReplacedImages->addElement(oldUserCmdImage.first, GetXGraphic(aImage));
1026 if ( !pRemovedImages )
1028 pRemovedImages->addElement( oldUserCmdImage.first, xEmptyGraphic );
1036 uno::Reference< uno::XInterface > xOwner(
m_pOwner);
1037 if ( pInsertedImages !=
nullptr )
1039 ConfigurationEvent aInsertEvent;
1040 aInsertEvent.aInfo <<=
static_cast<sal_uInt16
>(
i);
1041 aInsertEvent.Accessor <<= xOwner;
1042 aInsertEvent.Source = xOwner;
1044 aInsertEvent.Element <<= uno::Reference< XNameAccess >( pInsertedImages );
1047 if ( pReplacedImages !=
nullptr )
1049 ConfigurationEvent aReplaceEvent;
1050 aReplaceEvent.aInfo <<=
static_cast<sal_uInt16
>(
i);
1051 aReplaceEvent.Accessor <<= xOwner;
1052 aReplaceEvent.Source = xOwner;
1054 aReplaceEvent.ReplacedElement =
Any();
1055 aReplaceEvent.Element <<= uno::Reference< XNameAccess >( pReplacedImages );
1058 if ( pRemovedImages !=
nullptr )
1060 ConfigurationEvent aRemoveEvent;
1061 aRemoveEvent.aInfo <<=
static_cast<sal_uInt16
>(
i);
1062 aRemoveEvent.Accessor <<= xOwner;
1063 aRemoveEvent.Source = xOwner;
1065 aRemoveEvent.Element <<= uno::Reference< XNameAccess >( pRemovedImages );
1079 throw DisposedException();
1084 bool bWritten(
false );
1096 uno::Reference< XTransactedObject > xUserConfigStorageCommit(
m_xUserConfigStorage, UNO_QUERY );
1097 if ( xUserConfigStorageCommit.is() )
1098 xUserConfigStorageCommit->commit();
1111 throw DisposedException();
1120 if ( !xUserImageStorage.is() )
1123 uno::Reference< XStorage > xUserBitmapsStorage = xUserImageStorage->openStorageElement(
BITMAPS_FOLDER,
1131 uno::Reference< XTransactedObject > xTransaction(
Storage, UNO_QUERY );
1132 if ( xTransaction.is() )
1133 xTransaction->commit();
1155 throw DisposedException();
1158 std::unique_lock aGuard(
m_mutex);
1165 std::unique_lock aGuard(
m_mutex);
1171 std::unique_lock aGuard(
m_mutex);
1191 catch(
const css::uno::RuntimeException& )
1194 pIterator.
remove(aGuard);
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
void AddImage(const OUString &rImageName, const Image &rImage)
void ReplaceImage(const OUString &rImageName, const Image &rImage)
sal_uInt16 GetImagePos(std::u16string_view rImageName) const
Image GetImage(const OUString &rImageName) const
sal_uInt16 GetImageId(sal_uInt16 nPos) const
const OUString & GetImageName(sal_uInt16 nPos) const
BitmapEx GetAsHorizontalStrip() const
void GetImageNames(::std::vector< OUString > &rNames) const
void RemoveImage(sal_uInt16 nId)
sal_uInt16 GetImageCount() const
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
bool hasMoreElements() const
css::uno::Reference< ListenerT > const & next()
void remove(::std::unique_lock<::std::mutex > &rGuard)
css::uno::Reference< css::uno::XComponentContext > m_xContext
CmdImageList(css::uno::Reference< css::uno::XComponentContext > xContext, OUString aModuleIdentifier)
virtual std::vector< OUString > & getImageCommandNames()
vcl::CommandImageResolver m_aResolver
OUString m_aModuleIdentifier
virtual Image getImageFromCommandURL(vcl::ImageType nImageType, const OUString &rCommandURL)
virtual bool hasImage(vcl::ImageType nImageType, const OUString &rCommandURL)
virtual ::std::vector< OUString > & getImageCommandNames() override
virtual ~GlobalImageList() override
GlobalImageList(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual Image getImageFromCommandURL(vcl::ImageType nImageType, const OUString &rCommandURL) override
virtual bool hasImage(vcl::ImageType nImageType, const OUString &rCommandURL) override
OUString m_aResourceString
css::uno::Sequence< OUString > getAllImageNames(::sal_Int16 nImageType)
void implts_notifyContainerListener(const css::ui::ConfigurationEvent &aEvent, NotifyOp eOp)
o3tl::enumarray< vcl::ImageType, std::unique_ptr< ImageList > > m_pUserImageList
ImageManagerImpl(css::uno::Reference< css::uno::XComponentContext > xContext,::cppu::OWeakObject *pOwner, bool _bUseGlobal)
::cppu::OWeakObject * m_pOwner
css::uno::Reference< css::embed::XStorage > m_xUserConfigStorage
CmdImageList * implts_getDefaultImageList()
void storeToStorage(const css::uno::Reference< css::embed::XStorage > &Storage)
o3tl::enumarray< vcl::ImageType, bool > m_bUserImageListModified
std::unique_ptr< CmdImageList > m_pDefaultImageList
void insertImages(::sal_Int16 nImageType, const css::uno::Sequence< OUString > &aCommandURLSequence, const css::uno::Sequence< css::uno::Reference< css::graphic::XGraphic > > &aGraphicSequence)
rtl::Reference< GlobalImageList > m_pGlobalImageList
bool hasImage(::sal_Int16 nImageType, const OUString &aCommandURL)
const rtl::Reference< GlobalImageList > & implts_getGlobalImageList()
css::uno::Sequence< css::uno::Reference< css::graphic::XGraphic > > getImages(::sal_Int16 nImageType, const css::uno::Sequence< OUString > &aCommandURLSequence)
comphelper::OInterfaceContainerHelper4< css::ui::XUIConfigurationListener > m_aConfigListeners
css::uno::Reference< css::embed::XStorage > m_xUserBitmapsStorage
css::uno::Reference< css::embed::XStorage > m_xUserImageStorage
OUString m_aModuleIdentifier
void addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener)
void initialize(const css::uno::Sequence< css::uno::Any > &aArguments)
void removeImages(::sal_Int16 nImageType, const css::uno::Sequence< OUString > &aResourceURLSequence)
void replaceImages(::sal_Int16 nImageType, const css::uno::Sequence< OUString > &aCommandURLSequence, const css::uno::Sequence< css::uno::Reference< css::graphic::XGraphic > > &aGraphicsSequence)
css::uno::Reference< css::embed::XTransactedObject > m_xUserRootCommit
void removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener > &Listener)
bool implts_storeUserImages(vcl::ImageType nImageType, const css::uno::Reference< css::embed::XStorage > &xUserImageStorage, const css::uno::Reference< css::embed::XStorage > &xUserBitmapsStorage)
ImageList * implts_getUserImageList(vcl::ImageType nImageType)
void implts_loadUserImages(vcl::ImageType nImageType, const css::uno::Reference< css::embed::XStorage > &xUserImageStorage, const css::uno::Reference< css::embed::XStorage > &xUserBitmapsStorage)
void removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener)
comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aEventListeners
void addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener > &Listener)
css::uno::Reference< css::uno::XComponentContext > m_xContext
static bool LoadImages(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::io::XInputStream > &rInputStream, ImageItemDescriptorList &rItems)
static bool StoreImages(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::io::XOutputStream > &rOutputStream, const ImageItemDescriptorList &rItems)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
bool hasImage(const OUString &rCommandURL)
Image getImageFromCommandURL(ImageType nImageType, const OUString &rCommandURL)
std::vector< OUString > & getCommandNames()
void registerCommands(const css::uno::Sequence< OUString > &aCommandSequence)
bool read(BitmapEx &rBitmap)
bool write(const BitmapEx &rBitmap)
css::uno::Reference< css::uno::XComponentContext > m_xContext
#define IMAGELIST_IMAGE_NOTFOUND
constexpr OUStringLiteral BITMAPS_FOLDER
const o3tl::enumarray< vcl::ImageType, const char * > BITMAP_FILE_NAMES
const o3tl::enumarray< vcl::ImageType, const char * > IMAGELIST_XML_FILE
constexpr OUStringLiteral IMAGE_FOLDER
const sal_Int16 MAX_IMAGETYPE_VALUE
Sequence< PropertyValue > aArguments
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
std::unordered_map< OUString, bool > CommandMap
constexpr OUStringLiteral UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST
properties for "UICommandDescription" class
std::vector< ImageItemDescriptor > ImageItemDescriptorList
static bool implts_checkAndScaleGraphic(uno::Reference< XGraphic > &rOutGraphic, const uno::Reference< XGraphic > &rInGraphic, vcl::ImageType nImageType)
static GlobalImageList * getGlobalImageList(const uno::Reference< uno::XComponentContext > &rxContext)
static std::mutex & getGlobalImageListMutex()
static GlobalImageList * pGlobalImageList
static vcl::ImageType implts_convertImageTypeToIndex(sal_Int16 nImageType)
ContentProvider * m_pOwner