fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uiconfiguration / imagemanagerimpl.cxx
blob0238ff01ed4c34c969b827b88fbad351c61ca308
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "imagemanagerimpl.hxx"
21 #include <xml/imagesconfiguration.hxx>
22 #include <uiconfiguration/graphicnameaccess.hxx>
23 #include <services.h>
25 #include "properties.h"
27 #include <com/sun/star/frame/theUICommandDescription.hpp>
28 #include <com/sun/star/ui/UIElementType.hpp>
29 #include <com/sun/star/ui/ConfigurationEvent.hpp>
30 #include <com/sun/star/lang/DisposedException.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/embed/ElementModes.hpp>
34 #include <com/sun/star/io/XStream.hpp>
35 #include <com/sun/star/ui/ImageType.hpp>
37 #include <vcl/svapp.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <osl/mutex.hxx>
40 #include <comphelper/sequence.hxx>
41 #include <tools/urlobj.hxx>
42 #include <unotools/ucbstreamhelper.hxx>
43 #include <vcl/pngread.hxx>
44 #include <vcl/pngwrite.hxx>
45 #include <rtl/instance.hxx>
46 #include <svtools/miscopt.hxx>
47 #include <boost/scoped_ptr.hpp>
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::uno::XInterface;
51 using ::com::sun::star::uno::Exception;
52 using ::com::sun::star::uno::RuntimeException;
53 using ::com::sun::star::uno::UNO_QUERY;
54 using ::com::sun::star::uno::Any;
55 using ::com::sun::star::uno::makeAny;
56 using ::com::sun::star::graphic::XGraphic;
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::io;
59 using namespace ::com::sun::star::embed;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::beans;
63 using namespace ::com::sun::star::ui;
64 using namespace ::cppu;
66 // Image sizes for our toolbars/menus
67 const sal_Int32 IMAGE_SIZE_NORMAL = 16;
68 const sal_Int32 IMAGE_SIZE_LARGE = 26;
69 const sal_Int16 MAX_IMAGETYPE_VALUE = ::com::sun::star::ui::ImageType::SIZE_LARGE;
71 static const char IMAGE_FOLDER[] = "images";
72 static const char BITMAPS_FOLDER[] = "Bitmaps";
74 static const char ModuleImageList[] = "private:resource/images/moduleimages";
76 static const char* IMAGELIST_XML_FILE[] =
78 "sc_imagelist.xml",
79 "lc_imagelist.xml"
82 static const char* BITMAP_FILE_NAMES[] =
84 "sc_userimages.png",
85 "lc_userimages.png"
88 namespace framework
90 static GlobalImageList* pGlobalImageList = 0;
91 static const char* ImageType_Prefixes[ImageType_COUNT] =
93 "cmd/sc_",
94 "cmd/lc_"
97 typedef GraphicNameAccess CmdToXGraphicNameAccess;
99 namespace
101 class theGlobalImageListMutex
102 : public rtl::Static<osl::Mutex, theGlobalImageListMutex> {};
105 static osl::Mutex& getGlobalImageListMutex()
107 return theGlobalImageListMutex::get();
110 static GlobalImageList* getGlobalImageList( const uno::Reference< uno::XComponentContext >& rxContext )
112 osl::MutexGuard guard( getGlobalImageListMutex() );
114 if ( pGlobalImageList == 0 )
115 pGlobalImageList = new GlobalImageList( rxContext );
117 return pGlobalImageList;
120 static OUString getCanonicalName( const OUString& rFileName )
122 bool bRemoveSlash( true );
123 sal_Int32 nLength = rFileName.getLength();
124 const sal_Unicode* pString = rFileName.getStr();
126 OUStringBuffer aBuf( nLength );
127 for ( sal_Int32 i = 0; i < nLength; i++ )
129 const sal_Unicode c = pString[i];
130 switch ( c )
132 // map forbidden characters to escape
133 case '/' : if ( !bRemoveSlash )
134 aBuf.appendAscii( "%2f" );
135 break;
136 case '\\': aBuf.appendAscii( "%5c" ); bRemoveSlash = false; break;
137 case ':' : aBuf.appendAscii( "%3a" ); bRemoveSlash = false; break;
138 case '*' : aBuf.appendAscii( "%2a" ); bRemoveSlash = false; break;
139 case '?' : aBuf.appendAscii( "%3f" ); bRemoveSlash = false; break;
140 case '<' : aBuf.appendAscii( "%3c" ); bRemoveSlash = false; break;
141 case '>' : aBuf.appendAscii( "%3e" ); bRemoveSlash = false; break;
142 case '|' : aBuf.appendAscii( "%7c" ); bRemoveSlash = false; break;
143 default: aBuf.append( c ); bRemoveSlash = false;
146 return aBuf.makeStringAndClear();
149 CmdImageList::CmdImageList( const uno::Reference< uno::XComponentContext >& rxContext, const OUString& aModuleIdentifier ) :
150 m_bVectorInit( false ),
151 m_aModuleIdentifier( aModuleIdentifier ),
152 m_xContext( rxContext ),
153 m_sIconTheme( SvtMiscOptions().GetIconTheme() )
155 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
156 m_pImageList[n] = 0;
159 CmdImageList::~CmdImageList()
161 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
162 delete m_pImageList[n];
165 void CmdImageList::impl_fillCommandToImageNameMap()
167 SAL_INFO( "fwk", "framework: CmdImageList::impl_fillCommandToImageNameMap" );
169 if ( !m_bVectorInit )
171 const OUString aCommandImageList( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST );
172 Sequence< OUString > aCmdImageSeq;
173 uno::Reference< XNameAccess > xCmdDesc = frame::theUICommandDescription::get( m_xContext );
175 if ( !m_aModuleIdentifier.isEmpty() )
177 // If we have a module identifier - use to retrieve the command image name list from it.
178 // Otherwise we will use the global command image list
181 xCmdDesc->getByName( m_aModuleIdentifier ) >>= xCmdDesc;
182 if ( xCmdDesc.is() )
183 xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
185 catch ( const NoSuchElementException& )
187 // Module unknown we will work with an empty command image list!
188 return;
192 if ( xCmdDesc.is() )
196 xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
198 catch ( const NoSuchElementException& )
201 catch ( const WrappedTargetException& )
206 // We have to map commands which uses special characters like '/',':','?','\','<'.'>','|'
207 OUString aExt = ".png";
208 m_aImageCommandNameVector.resize(aCmdImageSeq.getLength() );
209 m_aImageNameVector.resize( aCmdImageSeq.getLength() );
211 ::std::copy( aCmdImageSeq.getConstArray(),
212 aCmdImageSeq.getConstArray()+aCmdImageSeq.getLength(),
213 m_aImageCommandNameVector.begin() );
215 // Create a image name vector that must be provided to the vcl imagelist. We also need
216 // a command to image name map to speed up access time for image retrieval.
217 OUString aUNOString( ".uno:" );
218 OUString aEmptyString;
219 const sal_uInt32 nCount = m_aImageCommandNameVector.size();
220 for ( sal_uInt32 i = 0; i < nCount; i++ )
222 OUString aCommandName( m_aImageCommandNameVector[i] );
223 OUString aImageName;
225 if ( aCommandName.indexOf( aUNOString ) != 0 )
227 INetURLObject aUrlObject( aCommandName, INetURLObject::ENCODE_ALL );
228 aImageName = aUrlObject.GetURLPath();
229 aImageName = getCanonicalName( aImageName ); // convert to valid filename
231 else
233 // just remove the schema
234 if ( aCommandName.getLength() > 5 )
235 aImageName = aCommandName.copy( 5 );
236 else
237 aImageName = aEmptyString;
239 // Search for query part.
240 if ( aImageName.indexOf('?') != -1 )
241 aImageName = getCanonicalName( aImageName ); // convert to valid filename
243 // Image names are not case-dependent. Always use lower case characters to
244 // reflect this.
245 aImageName += aExt;
246 aImageName = aImageName.toAsciiLowerCase();
248 m_aImageNameVector[i] = aImageName;
249 m_aCommandToImageNameMap.insert( CommandToImageNameMap::value_type( aCommandName, aImageName ));
252 m_bVectorInit = true;
256 ImageList* CmdImageList::impl_getImageList( sal_Int16 nImageType )
258 SvtMiscOptions aMiscOptions;
260 const OUString& rIconTheme = aMiscOptions.GetIconTheme();
261 if ( rIconTheme != m_sIconTheme )
263 m_sIconTheme = rIconTheme;
264 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
265 delete m_pImageList[n], m_pImageList[n] = NULL;
268 if ( !m_pImageList[nImageType] )
270 m_pImageList[nImageType] = new ImageList( m_aImageNameVector,
271 OUString::createFromAscii( ImageType_Prefixes[nImageType] ) );
274 return m_pImageList[nImageType];
279 Image CmdImageList::getImageFromCommandURL( sal_Int16 nImageType, const OUString& rCommandURL )
281 impl_fillCommandToImageNameMap();
282 CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
283 if ( pIter != m_aCommandToImageNameMap.end() )
285 ImageList* pImageList = impl_getImageList( nImageType );
286 return pImageList->GetImage( pIter->second );
289 return Image();
292 bool CmdImageList::hasImage( sal_Int16 /*nImageType*/, const OUString& rCommandURL )
294 impl_fillCommandToImageNameMap();
295 CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
296 if ( pIter != m_aCommandToImageNameMap.end() )
297 return true;
298 else
299 return false;
302 ::std::vector< OUString >& CmdImageList::getImageNames()
304 return impl_getImageNameVector();
307 ::std::vector< OUString >& CmdImageList::getImageCommandNames()
309 return impl_getImageCommandNameVector();
312 GlobalImageList::GlobalImageList( const uno::Reference< uno::XComponentContext >& rxContext ) :
313 CmdImageList( rxContext, OUString() )
317 GlobalImageList::~GlobalImageList()
319 osl::MutexGuard guard( getGlobalImageListMutex() );
320 // remove global pointer as we destroy the object now
321 pGlobalImageList = 0;
324 Image GlobalImageList::getImageFromCommandURL( sal_Int16 nImageType, const OUString& rCommandURL )
326 osl::MutexGuard guard( getGlobalImageListMutex() );
327 return CmdImageList::getImageFromCommandURL( nImageType, rCommandURL );
330 bool GlobalImageList::hasImage( sal_Int16 nImageType, const OUString& rCommandURL )
332 osl::MutexGuard guard( getGlobalImageListMutex() );
333 return CmdImageList::hasImage( nImageType, rCommandURL );
336 ::std::vector< OUString >& GlobalImageList::getImageNames()
338 osl::MutexGuard guard( getGlobalImageListMutex() );
339 return impl_getImageNameVector();
342 ::std::vector< OUString >& GlobalImageList::getImageCommandNames()
344 osl::MutexGuard guard( getGlobalImageListMutex() );
345 return impl_getImageCommandNameVector();
348 static bool implts_checkAndScaleGraphic( uno::Reference< XGraphic >& rOutGraphic, const uno::Reference< XGraphic >& rInGraphic, sal_Int16 nImageType )
350 static Size aNormSize( IMAGE_SIZE_NORMAL, IMAGE_SIZE_NORMAL );
351 static Size aLargeSize( IMAGE_SIZE_LARGE, IMAGE_SIZE_LARGE );
353 if ( !rInGraphic.is() )
355 rOutGraphic = Image().GetXGraphic();
356 return false;
359 // Check size and scale it
360 Image aImage( rInGraphic );
361 Size aSize = aImage.GetSizePixel();
362 bool bMustScale( false );
364 if ( nImageType == ImageType_Color_Large )
365 bMustScale = ( aSize != aLargeSize );
366 else
367 bMustScale = ( aSize != aNormSize );
369 if ( bMustScale )
371 BitmapEx aBitmap = aImage.GetBitmapEx();
372 aBitmap.Scale( aNormSize );
373 aImage = Image( aBitmap );
374 rOutGraphic = aImage.GetXGraphic();
376 else
377 rOutGraphic = rInGraphic;
378 return true;
381 static sal_Int16 implts_convertImageTypeToIndex( sal_Int16 nImageType )
383 sal_Int16 nIndex( 0 );
384 if ( nImageType & ::com::sun::star::ui::ImageType::SIZE_LARGE )
385 nIndex += 1;
386 return nIndex;
389 ImageList* ImageManagerImpl::implts_getUserImageList( ImageType nImageType )
391 SolarMutexGuard g;
392 if ( !m_pUserImageList[nImageType] )
393 implts_loadUserImages( nImageType, m_xUserImageStorage, m_xUserBitmapsStorage );
395 return m_pUserImageList[nImageType];
398 void ImageManagerImpl::implts_initialize()
400 // Initialize the top-level structures with the storage data
401 if ( m_xUserConfigStorage.is() )
403 long nModes = m_bReadOnly ? ElementModes::READ : ElementModes::READWRITE;
407 m_xUserImageStorage = m_xUserConfigStorage->openStorageElement( OUString(IMAGE_FOLDER ),
408 nModes );
409 if ( m_xUserImageStorage.is() )
411 m_xUserBitmapsStorage = m_xUserImageStorage->openStorageElement( OUString(BITMAPS_FOLDER ),
412 nModes );
415 catch ( const ::com::sun::star::container::NoSuchElementException& )
418 catch ( const ::com::sun::star::embed::InvalidStorageException& )
421 catch ( const ::com::sun::star::lang::IllegalArgumentException& )
424 catch ( const ::com::sun::star::io::IOException& )
427 catch ( const ::com::sun::star::embed::StorageWrappedTargetException& )
433 bool ImageManagerImpl::implts_loadUserImages(
434 ImageType nImageType,
435 const uno::Reference< XStorage >& xUserImageStorage,
436 const uno::Reference< XStorage >& xUserBitmapsStorage )
438 SolarMutexGuard g;
440 if ( xUserImageStorage.is() && xUserBitmapsStorage.is() )
444 uno::Reference< XStream > xStream = xUserImageStorage->openStreamElement( OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ),
445 ElementModes::READ );
446 uno::Reference< XInputStream > xInputStream = xStream->getInputStream();
448 ImageListsDescriptor aUserImageListInfo;
449 ImagesConfiguration::LoadImages( m_xContext,
450 xInputStream,
451 aUserImageListInfo );
452 if (( aUserImageListInfo.pImageList != 0 ) &&
453 ( !aUserImageListInfo.pImageList->empty() ))
455 ImageListItemDescriptor* pList = &aUserImageListInfo.pImageList->front();
456 sal_Int32 nCount = pList->pImageItemList->size();
457 std::vector< OUString > aUserImagesVector;
458 aUserImagesVector.reserve(nCount);
459 for ( sal_uInt16 i=0; i < nCount; i++ )
461 const ImageItemDescriptor* pItem = &(*pList->pImageItemList)[i];
462 aUserImagesVector.push_back( pItem->aCommandURL );
465 uno::Reference< XStream > xBitmapStream = xUserBitmapsStorage->openStreamElement(
466 OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ),
467 ElementModes::READ );
469 if ( xBitmapStream.is() )
471 BitmapEx aUserBitmap;
473 boost::scoped_ptr<SvStream> pSvStream(utl::UcbStreamHelper::CreateStream( xBitmapStream ));
474 vcl::PNGReader aPngReader( *pSvStream );
475 aUserBitmap = aPngReader.Read();
478 // Delete old image list and create a new one from the read bitmap
479 delete m_pUserImageList[nImageType];
480 m_pUserImageList[nImageType] = new ImageList();
481 m_pUserImageList[nImageType]->InsertFromHorizontalStrip
482 ( aUserBitmap, aUserImagesVector );
483 return true;
487 catch ( const ::com::sun::star::container::NoSuchElementException& )
490 catch ( const ::com::sun::star::embed::InvalidStorageException& )
493 catch ( const ::com::sun::star::lang::IllegalArgumentException& )
496 catch ( const ::com::sun::star::io::IOException& )
499 catch ( const ::com::sun::star::embed::StorageWrappedTargetException& )
504 // Destroy old image list - create a new empty one
505 delete m_pUserImageList[nImageType];
506 m_pUserImageList[nImageType] = new ImageList;
508 return true;
511 bool ImageManagerImpl::implts_storeUserImages(
512 ImageType nImageType,
513 const uno::Reference< XStorage >& xUserImageStorage,
514 const uno::Reference< XStorage >& xUserBitmapsStorage )
516 SolarMutexGuard g;
518 if ( m_bModified )
520 ImageList* pImageList = implts_getUserImageList( nImageType );
521 if ( pImageList->GetImageCount() > 0 )
523 ImageListsDescriptor aUserImageListInfo;
524 aUserImageListInfo.pImageList = new ImageListDescriptor;
526 ImageListItemDescriptor* pList = new ImageListItemDescriptor;
527 aUserImageListInfo.pImageList->push_back( pList );
529 pList->pImageItemList = new ImageItemListDescriptor;
530 for ( sal_uInt16 i=0; i < pImageList->GetImageCount(); i++ )
532 ImageItemDescriptor* pItem = new ::framework::ImageItemDescriptor;
534 pItem->nIndex = i;
535 pItem->aCommandURL = pImageList->GetImageName( i );
536 pList->pImageItemList->push_back( pItem );
539 pList->aURL = "Bitmaps/" + OUString::createFromAscii(BITMAP_FILE_NAMES[nImageType]);
541 uno::Reference< XTransactedObject > xTransaction;
542 uno::Reference< XOutputStream > xOutputStream;
543 uno::Reference< XStream > xStream = xUserImageStorage->openStreamElement( OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ),
544 ElementModes::WRITE|ElementModes::TRUNCATE );
545 if ( xStream.is() )
547 uno::Reference< XStream > xBitmapStream =
548 xUserBitmapsStorage->openStreamElement( OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ),
549 ElementModes::WRITE|ElementModes::TRUNCATE );
550 if ( xBitmapStream.is() )
553 boost::scoped_ptr<SvStream> pSvStream(utl::UcbStreamHelper::CreateStream( xBitmapStream ));
554 vcl::PNGWriter aPngWriter( pImageList->GetAsHorizontalStrip() );
555 aPngWriter.Write( *pSvStream );
558 // Commit user bitmaps storage
559 xTransaction = uno::Reference< XTransactedObject >( xUserBitmapsStorage, UNO_QUERY );
560 if ( xTransaction.is() )
561 xTransaction->commit();
564 xOutputStream = xStream->getOutputStream();
565 if ( xOutputStream.is() )
566 ImagesConfiguration::StoreImages( m_xContext, xOutputStream, aUserImageListInfo );
568 // Commit user image storage
569 xTransaction = uno::Reference< XTransactedObject >( xUserImageStorage, UNO_QUERY );
570 if ( xTransaction.is() )
571 xTransaction->commit();
574 return true;
576 else
578 // Remove the streams from the storage, if we have no data. We have to catch
579 // the NoSuchElementException as it can be possible that there is no stream at all!
582 xUserImageStorage->removeElement( OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ));
584 catch ( const ::com::sun::star::container::NoSuchElementException& )
590 xUserBitmapsStorage->removeElement( OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ));
592 catch ( const ::com::sun::star::container::NoSuchElementException& )
596 uno::Reference< XTransactedObject > xTransaction;
598 // Commit user image storage
599 xTransaction = uno::Reference< XTransactedObject >( xUserImageStorage, UNO_QUERY );
600 if ( xTransaction.is() )
601 xTransaction->commit();
603 // Commit user bitmaps storage
604 xTransaction = uno::Reference< XTransactedObject >( xUserBitmapsStorage, UNO_QUERY );
605 if ( xTransaction.is() )
606 xTransaction->commit();
608 return true;
612 return false;
615 const rtl::Reference< GlobalImageList >& ImageManagerImpl::implts_getGlobalImageList()
617 SolarMutexGuard g;
619 if ( !m_pGlobalImageList.is() )
620 m_pGlobalImageList = getGlobalImageList( m_xContext );
621 return m_pGlobalImageList;
624 CmdImageList* ImageManagerImpl::implts_getDefaultImageList()
626 SolarMutexGuard g;
628 if ( !m_pDefaultImageList )
629 m_pDefaultImageList = new CmdImageList( m_xContext, m_aModuleIdentifier );
631 return m_pDefaultImageList;
634 ImageManagerImpl::ImageManagerImpl( const uno::Reference< uno::XComponentContext >& rxContext,::cppu::OWeakObject* pOwner,bool _bUseGlobal ) :
635 m_xContext( rxContext )
636 , m_pOwner(pOwner)
637 , m_pDefaultImageList( 0 )
638 , m_aXMLPostfix( ".xml" )
639 , m_aResourceString( ModuleImageList )
640 , m_aListenerContainer( m_mutex )
641 , m_bUseGlobal(_bUseGlobal)
642 , m_bReadOnly( true )
643 , m_bInitialized( false )
644 , m_bModified( false )
645 , m_bConfigRead( false )
646 , m_bDisposed( false )
648 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
650 m_pUserImageList[n] = 0;
651 m_bUserImageListModified[n] = false;
655 ImageManagerImpl::~ImageManagerImpl()
657 clear();
660 void ImageManagerImpl::dispose()
662 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
663 css::lang::EventObject aEvent( xOwner );
664 m_aListenerContainer.disposeAndClear( aEvent );
667 SolarMutexGuard g;
668 m_xUserConfigStorage.clear();
669 m_xUserImageStorage.clear();
670 m_xUserRootCommit.clear();
671 m_bConfigRead = false;
672 m_bModified = false;
673 m_bDisposed = true;
675 // delete user and default image list on dispose
676 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
678 delete m_pUserImageList[n];
679 m_pUserImageList[n] = 0;
681 delete m_pDefaultImageList;
682 m_pDefaultImageList = 0;
686 void ImageManagerImpl::addEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
689 SolarMutexGuard g;
691 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
692 if ( m_bDisposed )
693 throw DisposedException();
696 m_aListenerContainer.addInterface( cppu::UnoType<XEventListener>::get(), xListener );
699 void ImageManagerImpl::removeEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
701 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
702 m_aListenerContainer.removeInterface( cppu::UnoType<XEventListener>::get(), xListener );
705 // XInitialization
706 void ImageManagerImpl::initialize( const Sequence< Any >& aArguments )
708 SolarMutexGuard g;
710 if ( !m_bInitialized )
712 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
714 PropertyValue aPropValue;
715 if ( aArguments[n] >>= aPropValue )
717 if ( aPropValue.Name == "UserConfigStorage" )
719 aPropValue.Value >>= m_xUserConfigStorage;
721 else if ( aPropValue.Name == "ModuleIdentifier" )
723 aPropValue.Value >>= m_aModuleIdentifier;
725 else if ( aPropValue.Name == "UserRootCommit" )
727 aPropValue.Value >>= m_xUserRootCommit;
732 if ( m_xUserConfigStorage.is() )
734 uno::Reference< XPropertySet > xPropSet( m_xUserConfigStorage, UNO_QUERY );
735 if ( xPropSet.is() )
737 long nOpenMode = 0;
738 if ( xPropSet->getPropertyValue("OpenMode") >>= nOpenMode )
739 m_bReadOnly = !( nOpenMode & ElementModes::WRITE );
743 implts_initialize();
745 m_bInitialized = true;
749 // XImageManagerImpl
750 void ImageManagerImpl::reset()
751 throw (::com::sun::star::uno::RuntimeException, lang::IllegalAccessException)
753 SolarMutexGuard g;
755 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
756 if ( m_bDisposed )
757 throw DisposedException();
759 std::vector< OUString > aUserImageNames;
761 for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
763 aUserImageNames.clear();
764 ImageList* pImageList = implts_getUserImageList( ImageType(i));
765 pImageList->GetImageNames( aUserImageNames );
767 Sequence< OUString > aRemoveList( aUserImageNames.size() );
768 const sal_uInt32 nCount = aUserImageNames.size();
769 for ( sal_uInt32 j = 0; j < nCount; j++ )
770 aRemoveList[j] = aUserImageNames[j];
772 // Remove images
773 removeImages( sal_Int16( i ), aRemoveList );
774 m_bUserImageListModified[i] = true;
777 m_bModified = true;
780 Sequence< OUString > ImageManagerImpl::getAllImageNames( ::sal_Int16 nImageType )
781 throw (::com::sun::star::uno::RuntimeException)
783 SolarMutexGuard g;
785 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
786 if ( m_bDisposed )
787 throw DisposedException();
789 ImageNameMap aImageCmdNameMap;
791 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
793 sal_uInt32 i( 0 );
794 if ( m_bUseGlobal )
796 rtl::Reference< GlobalImageList > rGlobalImageList = implts_getGlobalImageList();
798 const std::vector< OUString >& rGlobalImageNameVector = rGlobalImageList->getImageCommandNames();
799 const sal_uInt32 nGlobalCount = rGlobalImageNameVector.size();
800 for ( i = 0; i < nGlobalCount; i++ )
801 aImageCmdNameMap.insert( ImageNameMap::value_type( rGlobalImageNameVector[i], sal_True ));
803 const std::vector< OUString >& rModuleImageNameVector = implts_getDefaultImageList()->getImageCommandNames();
804 const sal_uInt32 nModuleCount = rModuleImageNameVector.size();
805 for ( i = 0; i < nModuleCount; i++ )
806 aImageCmdNameMap.insert( ImageNameMap::value_type( rModuleImageNameVector[i], sal_True ));
809 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
810 std::vector< OUString > rUserImageNames;
811 pImageList->GetImageNames( rUserImageNames );
812 const sal_uInt32 nUserCount = rUserImageNames.size();
813 for ( i = 0; i < nUserCount; i++ )
814 aImageCmdNameMap.insert( ImageNameMap::value_type( rUserImageNames[i], sal_True ));
816 Sequence< OUString > aImageNameSeq( aImageCmdNameMap.size() );
817 ImageNameMap::const_iterator pIter;
818 i = 0;
819 for ( pIter = aImageCmdNameMap.begin(); pIter != aImageCmdNameMap.end(); ++pIter )
820 aImageNameSeq[i++] = pIter->first;
822 return aImageNameSeq;
825 bool ImageManagerImpl::hasImage( ::sal_Int16 nImageType, const OUString& aCommandURL )
826 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
828 SolarMutexGuard g;
830 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
831 if ( m_bDisposed )
832 throw DisposedException();
834 if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
835 throw IllegalArgumentException();
837 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
838 if ( m_bUseGlobal && implts_getGlobalImageList()->hasImage( nIndex, aCommandURL ))
839 return true;
840 else
842 if ( m_bUseGlobal && implts_getDefaultImageList()->hasImage( nIndex, aCommandURL ))
843 return true;
844 else
846 // User layer
847 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
848 if ( pImageList )
849 return ( pImageList->GetImagePos( aCommandURL ) != IMAGELIST_IMAGE_NOTFOUND );
853 return false;
856 Sequence< uno::Reference< XGraphic > > ImageManagerImpl::getImages(
857 ::sal_Int16 nImageType,
858 const Sequence< OUString >& aCommandURLSequence )
859 throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
861 SolarMutexGuard g;
863 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
864 if ( m_bDisposed )
865 throw DisposedException();
867 if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
868 throw IllegalArgumentException();
870 Sequence< uno::Reference< XGraphic > > aGraphSeq( aCommandURLSequence.getLength() );
872 const OUString* aStrArray = aCommandURLSequence.getConstArray();
874 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
875 rtl::Reference< GlobalImageList > rGlobalImageList;
876 CmdImageList* pDefaultImageList = NULL;
877 if ( m_bUseGlobal )
879 rGlobalImageList = implts_getGlobalImageList();
880 pDefaultImageList = implts_getDefaultImageList();
882 ImageList* pUserImageList = implts_getUserImageList( ImageType( nIndex ));
884 // We have to search our image list in the following order:
885 // 1. user image list (read/write)
886 // 2. module image list (read)
887 // 3. global image list (read)
888 for ( sal_Int32 n = 0; n < aCommandURLSequence.getLength(); n++ )
890 Image aImage = pUserImageList->GetImage( aStrArray[n] );
891 if ( !aImage && m_bUseGlobal )
893 aImage = pDefaultImageList->getImageFromCommandURL( nIndex, aStrArray[n] );
894 if ( !aImage )
895 aImage = rGlobalImageList->getImageFromCommandURL( nIndex, aStrArray[n] );
898 aGraphSeq[n] = aImage.GetXGraphic();
901 return aGraphSeq;
904 void ImageManagerImpl::replaceImages(
905 ::sal_Int16 nImageType,
906 const Sequence< OUString >& aCommandURLSequence,
907 const Sequence< uno::Reference< XGraphic > >& aGraphicsSequence )
908 throw (css::lang::IllegalArgumentException,
909 css::lang::IllegalAccessException,
910 css::uno::RuntimeException,
911 std::exception)
913 CmdToXGraphicNameAccess* pInsertedImages( 0 );
914 CmdToXGraphicNameAccess* pReplacedImages( 0 );
917 SolarMutexGuard g;
919 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
920 if ( m_bDisposed )
921 throw DisposedException();
923 if (( aCommandURLSequence.getLength() != aGraphicsSequence.getLength() ) ||
924 (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE )))
925 throw IllegalArgumentException();
927 if ( m_bReadOnly )
928 throw IllegalAccessException();
930 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
931 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
933 uno::Reference< XGraphic > xGraphic;
934 for ( sal_Int32 i = 0; i < aCommandURLSequence.getLength(); i++ )
936 // Check size and scale. If we don't have any graphics ignore it
937 if ( !implts_checkAndScaleGraphic( xGraphic, aGraphicsSequence[i], nIndex ))
938 continue;
940 sal_uInt16 nPos = pImageList->GetImagePos( aCommandURLSequence[i] );
941 if ( nPos == IMAGELIST_IMAGE_NOTFOUND )
943 pImageList->AddImage(aCommandURLSequence[i], Image(xGraphic));
944 if ( !pInsertedImages )
945 pInsertedImages = new CmdToXGraphicNameAccess();
946 pInsertedImages->addElement( aCommandURLSequence[i], xGraphic );
948 else
950 pImageList->ReplaceImage(aCommandURLSequence[i], Image(xGraphic));
951 if ( !pReplacedImages )
952 pReplacedImages = new CmdToXGraphicNameAccess();
953 pReplacedImages->addElement( aCommandURLSequence[i], xGraphic );
957 if (( pInsertedImages != 0 ) || ( pReplacedImages != 0 ))
959 m_bModified = true;
960 m_bUserImageListModified[nIndex] = true;
964 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
965 // Notify listeners
966 if ( pInsertedImages != 0 )
968 ConfigurationEvent aInsertEvent;
969 aInsertEvent.aInfo <<= nImageType;
970 aInsertEvent.Accessor <<= xOwner;
971 aInsertEvent.Source = xOwner;
972 aInsertEvent.ResourceURL = m_aResourceString;
973 aInsertEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
974 static_cast< OWeakObject *>( pInsertedImages ), UNO_QUERY ));
975 implts_notifyContainerListener( aInsertEvent, NotifyOp_Insert );
977 if ( pReplacedImages != 0 )
979 ConfigurationEvent aReplaceEvent;
980 aReplaceEvent.aInfo <<= nImageType;
981 aReplaceEvent.Accessor <<= xOwner;
982 aReplaceEvent.Source = xOwner;
983 aReplaceEvent.ResourceURL = m_aResourceString;
984 aReplaceEvent.ReplacedElement = Any();
985 aReplaceEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
986 static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
987 implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
991 void ImageManagerImpl::removeImages( ::sal_Int16 nImageType, const Sequence< OUString >& aCommandURLSequence )
992 throw ( ::com::sun::star::lang::IllegalArgumentException,
993 ::com::sun::star::lang::IllegalAccessException,
994 ::com::sun::star::uno::RuntimeException)
996 CmdToXGraphicNameAccess* pRemovedImages( 0 );
997 CmdToXGraphicNameAccess* pReplacedImages( 0 );
1000 SolarMutexGuard g;
1002 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1003 if ( m_bDisposed )
1004 throw DisposedException();
1006 if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
1007 throw IllegalArgumentException();
1009 if ( m_bReadOnly )
1010 throw IllegalAccessException();
1012 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
1013 rtl::Reference< GlobalImageList > rGlobalImageList;
1014 CmdImageList* pDefaultImageList = NULL;
1015 if ( m_bUseGlobal )
1017 rGlobalImageList = implts_getGlobalImageList();
1018 pDefaultImageList = implts_getDefaultImageList();
1020 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
1021 uno::Reference< XGraphic > xEmptyGraphic( Image().GetXGraphic() );
1023 for ( sal_Int32 i = 0; i < aCommandURLSequence.getLength(); i++ )
1025 sal_uInt16 nPos = pImageList->GetImagePos( aCommandURLSequence[i] );
1026 if ( nPos != IMAGELIST_IMAGE_NOTFOUND )
1028 Image aImage = pImageList->GetImage( nPos );
1029 sal_uInt16 nId = pImageList->GetImageId( nPos );
1030 pImageList->RemoveImage( nId );
1032 if ( m_bUseGlobal )
1034 // Check, if we have a image in our module/global image list. If we find one =>
1035 // this is a replace instead of a remove operation!
1036 Image aNewImage = pDefaultImageList->getImageFromCommandURL( nIndex, aCommandURLSequence[i] );
1037 if ( !aNewImage )
1038 aNewImage = rGlobalImageList->getImageFromCommandURL( nIndex, aCommandURLSequence[i] );
1039 if ( !aNewImage )
1041 if ( !pRemovedImages )
1042 pRemovedImages = new CmdToXGraphicNameAccess();
1043 pRemovedImages->addElement( aCommandURLSequence[i], xEmptyGraphic );
1045 else
1047 if ( !pReplacedImages )
1048 pReplacedImages = new CmdToXGraphicNameAccess();
1049 pReplacedImages->addElement( aCommandURLSequence[i], aNewImage.GetXGraphic() );
1051 } // if ( m_bUseGlobal )
1052 else
1054 if ( !pRemovedImages )
1055 pRemovedImages = new CmdToXGraphicNameAccess();
1056 pRemovedImages->addElement( aCommandURLSequence[i], xEmptyGraphic );
1061 if (( pReplacedImages != 0 ) || ( pRemovedImages != 0 ))
1063 m_bModified = true;
1064 m_bUserImageListModified[nIndex] = true;
1068 // Notify listeners
1069 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
1070 if ( pRemovedImages != 0 )
1072 ConfigurationEvent aRemoveEvent;
1073 aRemoveEvent.aInfo = uno::makeAny( nImageType );
1074 aRemoveEvent.Accessor = uno::makeAny( xOwner );
1075 aRemoveEvent.Source = xOwner;
1076 aRemoveEvent.ResourceURL = m_aResourceString;
1077 aRemoveEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1078 static_cast< OWeakObject *>( pRemovedImages ), UNO_QUERY ));
1079 implts_notifyContainerListener( aRemoveEvent, NotifyOp_Remove );
1081 if ( pReplacedImages != 0 )
1083 ConfigurationEvent aReplaceEvent;
1084 aReplaceEvent.aInfo = uno::makeAny( nImageType );
1085 aReplaceEvent.Accessor = uno::makeAny( xOwner );
1086 aReplaceEvent.Source = xOwner;
1087 aReplaceEvent.ResourceURL = m_aResourceString;
1088 aReplaceEvent.ReplacedElement = Any();
1089 aReplaceEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1090 static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1091 implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1095 void ImageManagerImpl::insertImages( ::sal_Int16 nImageType, const Sequence< OUString >& aCommandURLSequence, const Sequence< uno::Reference< XGraphic > >& aGraphicSequence )
1096 throw ( ::com::sun::star::container::ElementExistException,
1097 ::com::sun::star::lang::IllegalArgumentException,
1098 ::com::sun::star::lang::IllegalAccessException,
1099 ::com::sun::star::uno::RuntimeException)
1101 replaceImages(nImageType,aCommandURLSequence,aGraphicSequence);
1104 // XUIConfigurationPersistence
1105 void ImageManagerImpl::reload()
1106 throw (css::uno::Exception,
1107 css::uno::RuntimeException,
1108 std::exception)
1110 SolarMutexClearableGuard aGuard;
1112 if ( m_bDisposed )
1113 throw DisposedException();
1115 CommandMap aOldUserCmdImageSet;
1116 std::vector< OUString > aNewUserCmdImageSet;
1118 if ( m_bModified )
1120 for ( sal_Int16 i = 0; i < sal_Int16( ImageType_COUNT ); i++ )
1122 if ( !m_bDisposed && m_bUserImageListModified[i] )
1124 std::vector< OUString > aOldUserCmdImageVector;
1125 ImageList* pImageList = implts_getUserImageList( (ImageType)i );
1126 pImageList->GetImageNames( aOldUserCmdImageVector );
1128 // Fill hash map to speed up search afterwards
1129 sal_uInt32 j( 0 );
1130 const sal_uInt32 nOldCount = aOldUserCmdImageVector.size();
1131 for ( j = 0; j < nOldCount; j++ )
1132 aOldUserCmdImageSet.insert( CommandMap::value_type( aOldUserCmdImageVector[j], false ));
1134 // Attention: This can make the old image list pointer invalid!
1135 implts_loadUserImages( (ImageType)i, m_xUserImageStorage, m_xUserBitmapsStorage );
1136 pImageList = implts_getUserImageList( (ImageType)i );
1137 pImageList->GetImageNames( aNewUserCmdImageSet );
1139 CmdToXGraphicNameAccess* pInsertedImages( 0 );
1140 CmdToXGraphicNameAccess* pReplacedImages( 0 );
1141 CmdToXGraphicNameAccess* pRemovedImages( 0 );
1143 const sal_uInt32 nNewCount = aNewUserCmdImageSet.size();
1144 for ( j = 0; j < nNewCount; j++ )
1146 CommandMap::iterator pIter = aOldUserCmdImageSet.find( aNewUserCmdImageSet[j] );
1147 if ( pIter != aOldUserCmdImageSet.end() )
1149 pIter->second = true; // mark entry as replaced
1150 if ( !pReplacedImages )
1151 pReplacedImages = new CmdToXGraphicNameAccess();
1152 pReplacedImages->addElement( aNewUserCmdImageSet[j],
1153 pImageList->GetImage( aNewUserCmdImageSet[j] ).GetXGraphic() );
1155 else
1157 if ( !pInsertedImages )
1158 pInsertedImages = new CmdToXGraphicNameAccess();
1159 pInsertedImages->addElement( aNewUserCmdImageSet[j],
1160 pImageList->GetImage( aNewUserCmdImageSet[j] ).GetXGraphic() );
1164 // Search map for unmarked entries => they have been removed from the user list
1165 // through this reload operation.
1166 // We have to search the module and global image list!
1167 rtl::Reference< GlobalImageList > rGlobalImageList;
1168 CmdImageList* pDefaultImageList = NULL;
1169 if ( m_bUseGlobal )
1171 rGlobalImageList = implts_getGlobalImageList();
1172 pDefaultImageList = implts_getDefaultImageList();
1174 uno::Reference< XGraphic > xEmptyGraphic( Image().GetXGraphic() );
1175 CommandMap::const_iterator pIter = aOldUserCmdImageSet.begin();
1176 while ( pIter != aOldUserCmdImageSet.end() )
1178 if ( !pIter->second )
1180 if ( m_bUseGlobal )
1182 Image aImage = pDefaultImageList->getImageFromCommandURL( i, pIter->first );
1183 if ( !aImage )
1184 aImage = rGlobalImageList->getImageFromCommandURL( i, pIter->first );
1186 if ( !aImage )
1188 // No image in the module/global image list => remove user image
1189 if ( !pRemovedImages )
1190 pRemovedImages = new CmdToXGraphicNameAccess();
1191 pRemovedImages->addElement( pIter->first, xEmptyGraphic );
1193 else
1195 // Image has been found in the module/global image list => replace user image
1196 if ( !pReplacedImages )
1197 pReplacedImages = new CmdToXGraphicNameAccess();
1198 pReplacedImages->addElement( pIter->first, aImage.GetXGraphic() );
1200 } // if ( m_bUseGlobal )
1201 else
1203 // No image in the user image list => remove user image
1204 if ( !pRemovedImages )
1205 pRemovedImages = new CmdToXGraphicNameAccess();
1206 pRemovedImages->addElement( pIter->first, xEmptyGraphic );
1209 ++pIter;
1212 aGuard.clear();
1214 // Now notify our listeners. Unlock mutex to prevent deadlocks
1215 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
1216 if ( pInsertedImages != 0 )
1218 ConfigurationEvent aInsertEvent;
1219 aInsertEvent.aInfo = uno::makeAny( i );
1220 aInsertEvent.Accessor = uno::makeAny( xOwner );
1221 aInsertEvent.Source = xOwner;
1222 aInsertEvent.ResourceURL = m_aResourceString;
1223 aInsertEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1224 static_cast< OWeakObject *>( pInsertedImages ), UNO_QUERY ));
1225 implts_notifyContainerListener( aInsertEvent, NotifyOp_Insert );
1227 if ( pReplacedImages != 0 )
1229 ConfigurationEvent aReplaceEvent;
1230 aReplaceEvent.aInfo = uno::makeAny( i );
1231 aReplaceEvent.Accessor = uno::makeAny( xOwner );
1232 aReplaceEvent.Source = xOwner;
1233 aReplaceEvent.ResourceURL = m_aResourceString;
1234 aReplaceEvent.ReplacedElement = Any();
1235 aReplaceEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1236 static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1237 implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1239 if ( pRemovedImages != 0 )
1241 ConfigurationEvent aRemoveEvent;
1242 aRemoveEvent.aInfo = uno::makeAny( i );
1243 aRemoveEvent.Accessor = uno::makeAny( xOwner );
1244 aRemoveEvent.Source = xOwner;
1245 aRemoveEvent.ResourceURL = m_aResourceString;
1246 aRemoveEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1247 static_cast< OWeakObject *>( pRemovedImages ), UNO_QUERY ));
1248 implts_notifyContainerListener( aRemoveEvent, NotifyOp_Remove );
1251 aGuard.clear();
1257 void ImageManagerImpl::store()
1258 throw (::com::sun::star::uno::Exception,
1259 ::com::sun::star::uno::RuntimeException,
1260 std::exception)
1262 SolarMutexGuard g;
1264 if ( m_bDisposed )
1265 throw DisposedException();
1267 if ( m_bModified )
1269 bool bWritten( false );
1270 for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
1272 bool bSuccess = implts_storeUserImages( ImageType(i), m_xUserImageStorage, m_xUserBitmapsStorage );
1273 if ( bSuccess )
1274 bWritten = true;
1275 m_bUserImageListModified[i] = false;
1278 if ( bWritten &&
1279 m_xUserConfigStorage.is() )
1281 uno::Reference< XTransactedObject > xUserConfigStorageCommit( m_xUserConfigStorage, UNO_QUERY );
1282 if ( xUserConfigStorageCommit.is() )
1283 xUserConfigStorageCommit->commit();
1284 if ( m_xUserRootCommit.is() )
1285 m_xUserRootCommit->commit();
1288 m_bModified = false;
1292 void ImageManagerImpl::storeToStorage( const uno::Reference< XStorage >& Storage )
1293 throw (::com::sun::star::uno::Exception,
1294 ::com::sun::star::uno::RuntimeException,
1295 std::exception)
1297 SolarMutexGuard g;
1299 if ( m_bDisposed )
1300 throw DisposedException();
1302 if ( m_bModified && Storage.is() )
1304 long nModes = ElementModes::READWRITE;
1306 uno::Reference< XStorage > xUserImageStorage = Storage->openStorageElement( OUString(IMAGE_FOLDER ),
1307 nModes );
1308 if ( xUserImageStorage.is() )
1310 uno::Reference< XStorage > xUserBitmapsStorage = xUserImageStorage->openStorageElement( OUString(BITMAPS_FOLDER ),
1311 nModes );
1312 for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
1314 implts_getUserImageList( (ImageType)i );
1315 implts_storeUserImages( (ImageType)i, xUserImageStorage, xUserBitmapsStorage );
1318 uno::Reference< XTransactedObject > xTransaction( Storage, UNO_QUERY );
1319 if ( xTransaction.is() )
1320 xTransaction->commit();
1325 bool ImageManagerImpl::isModified()
1326 throw (::com::sun::star::uno::RuntimeException)
1328 SolarMutexGuard g;
1329 return m_bModified;
1332 bool ImageManagerImpl::isReadOnly() throw (::com::sun::star::uno::RuntimeException)
1334 SolarMutexGuard g;
1335 return m_bReadOnly;
1337 // XUIConfiguration
1338 void ImageManagerImpl::addConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
1339 throw (::com::sun::star::uno::RuntimeException)
1342 SolarMutexGuard g;
1344 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1345 if ( m_bDisposed )
1346 throw DisposedException();
1349 m_aListenerContainer.addInterface( cppu::UnoType<XUIConfigurationListener>::get(), xListener );
1352 void ImageManagerImpl::removeConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
1353 throw (::com::sun::star::uno::RuntimeException)
1355 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1356 m_aListenerContainer.removeInterface( cppu::UnoType<XUIConfigurationListener>::get(), xListener );
1359 void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& aEvent, NotifyOp eOp )
1361 ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
1362 cppu::UnoType<com::sun::star::ui::XUIConfigurationListener>::get());
1363 if ( pContainer != NULL )
1365 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
1366 while ( pIterator.hasMoreElements() )
1370 switch ( eOp )
1372 case NotifyOp_Replace:
1373 static_cast< ::com::sun::star::ui::XUIConfigurationListener*>(pIterator.next())->elementReplaced( aEvent );
1374 break;
1375 case NotifyOp_Insert:
1376 static_cast< ::com::sun::star::ui::XUIConfigurationListener*>(pIterator.next())->elementInserted( aEvent );
1377 break;
1378 case NotifyOp_Remove:
1379 static_cast< ::com::sun::star::ui::XUIConfigurationListener*>(pIterator.next())->elementRemoved( aEvent );
1380 break;
1383 catch( const css::uno::RuntimeException& )
1385 pIterator.remove();
1390 void ImageManagerImpl::clear()
1392 SolarMutexGuard g;
1394 for ( sal_Int32 n = 0; n < ImageType_COUNT; n++ )
1396 delete m_pUserImageList[n];
1397 m_pUserImageList[n] = 0;
1400 } // namespace framework
1402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */