update credits
[LibreOffice.git] / framework / source / uiconfiguration / imagemanagerimpl.cxx
blobfacc0e47345a9e367f2b6d64e97edb48c2261871
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 .
21 #include <imagemanagerimpl.hxx>
22 #include <threadhelp/resetableguard.hxx>
23 #include <xml/imagesconfiguration.hxx>
24 #include <uiconfiguration/graphicnameaccess.hxx>
25 #include <services.h>
27 #include "properties.h"
29 #include <com/sun/star/frame/UICommandDescription.hpp>
30 #include <com/sun/star/ui/UIElementType.hpp>
31 #include <com/sun/star/ui/ConfigurationEvent.hpp>
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <com/sun/star/embed/ElementModes.hpp>
36 #include <com/sun/star/io/XStream.hpp>
37 #include <com/sun/star/ui/ImageType.hpp>
39 #include <vcl/svapp.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include <osl/mutex.hxx>
42 #include <comphelper/componentcontext.hxx>
43 #include <comphelper/sequence.hxx>
44 #include <tools/urlobj.hxx>
45 #include <unotools/ucbstreamhelper.hxx>
46 #include <vcl/pngread.hxx>
47 #include <vcl/pngwrite.hxx>
48 #include <rtl/logfile.hxx>
49 #include <rtl/instance.hxx>
50 #include <svtools/miscopt.hxx>
52 using ::com::sun::star::uno::Sequence;
53 using ::com::sun::star::uno::XInterface;
54 using ::com::sun::star::uno::Exception;
55 using ::com::sun::star::uno::RuntimeException;
56 using ::com::sun::star::uno::UNO_QUERY;
57 using ::com::sun::star::uno::Any;
58 using ::com::sun::star::uno::makeAny;
59 using ::com::sun::star::graphic::XGraphic;
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::io;
62 using namespace ::com::sun::star::embed;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::container;
65 using namespace ::com::sun::star::beans;
66 using namespace ::com::sun::star::ui;
67 using namespace ::cppu;
69 // Image sizes for our toolbars/menus
70 const sal_Int32 IMAGE_SIZE_NORMAL = 16;
71 const sal_Int32 IMAGE_SIZE_LARGE = 26;
72 const sal_Int16 MAX_IMAGETYPE_VALUE = ::com::sun::star::ui::ImageType::SIZE_LARGE;
74 static const char IMAGE_FOLDER[] = "images";
75 static const char BITMAPS_FOLDER[] = "Bitmaps";
77 static const char ModuleImageList[] = "private:resource/images/moduleimages";
79 static const char* IMAGELIST_XML_FILE[] =
81 "sc_imagelist.xml",
82 "lc_imagelist.xml"
85 static const char* BITMAP_FILE_NAMES[] =
87 "sc_userimages.png",
88 "lc_userimages.png"
91 namespace framework
93 static GlobalImageList* pGlobalImageList = 0;
94 static const char* ImageType_Prefixes[ImageType_COUNT] =
96 "cmd/sc_",
97 "cmd/lc_"
100 typedef GraphicNameAccess CmdToXGraphicNameAccess;
102 namespace
104 class theGlobalImageListMutex
105 : public rtl::Static<osl::Mutex, theGlobalImageListMutex> {};
108 static osl::Mutex& getGlobalImageListMutex()
110 return theGlobalImageListMutex::get();
113 static GlobalImageList* getGlobalImageList( const uno::Reference< uno::XComponentContext >& rxContext )
115 osl::MutexGuard guard( getGlobalImageListMutex() );
117 if ( pGlobalImageList == 0 )
118 pGlobalImageList = new GlobalImageList( rxContext );
120 return pGlobalImageList;
123 static OUString getCanonicalName( const OUString& rFileName )
125 bool bRemoveSlash( true );
126 sal_Int32 nLength = rFileName.getLength();
127 const sal_Unicode* pString = rFileName.getStr();
129 OUStringBuffer aBuf( nLength );
130 for ( sal_Int32 i = 0; i < nLength; i++ )
132 const sal_Unicode c = pString[i];
133 switch ( c )
135 // map forbidden characters to escape
136 case '/' : if ( !bRemoveSlash )
137 aBuf.appendAscii( "%2f" );
138 break;
139 case '\\': aBuf.appendAscii( "%5c" ); bRemoveSlash = false; break;
140 case ':' : aBuf.appendAscii( "%3a" ); bRemoveSlash = false; break;
141 case '*' : aBuf.appendAscii( "%2a" ); bRemoveSlash = false; break;
142 case '?' : aBuf.appendAscii( "%3f" ); bRemoveSlash = false; break;
143 case '<' : aBuf.appendAscii( "%3c" ); bRemoveSlash = false; break;
144 case '>' : aBuf.appendAscii( "%3e" ); bRemoveSlash = false; break;
145 case '|' : aBuf.appendAscii( "%7c" ); bRemoveSlash = false; break;
146 default: aBuf.append( c ); bRemoveSlash = false;
149 return aBuf.makeStringAndClear();
152 //_________________________________________________________________________________________________________________
154 CmdImageList::CmdImageList( const uno::Reference< uno::XComponentContext >& rxContext, const OUString& aModuleIdentifier ) :
155 m_bVectorInit( sal_False ),
156 m_aModuleIdentifier( aModuleIdentifier ),
157 m_xContext( rxContext ),
158 m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
160 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
161 m_pImageList[n] = 0;
164 CmdImageList::~CmdImageList()
166 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
167 delete m_pImageList[n];
170 void CmdImageList::impl_fillCommandToImageNameMap()
172 RTL_LOGFILE_CONTEXT( aLog, "framework: CmdImageList::impl_fillCommandToImageNameMap" );
174 if ( !m_bVectorInit )
176 const OUString aCommandImageList( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST );
177 Sequence< OUString > aCmdImageSeq;
178 uno::Reference< XNameAccess > xCmdDesc = frame::UICommandDescription::create( m_xContext );
180 if ( !m_aModuleIdentifier.isEmpty() )
182 // If we have a module identifier - use to retrieve the command image name list from it.
183 // Otherwise we will use the global command image list
186 xCmdDesc->getByName( m_aModuleIdentifier ) >>= xCmdDesc;
187 if ( xCmdDesc.is() )
188 xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
190 catch ( const NoSuchElementException& )
192 // Module unknown we will work with an empty command image list!
193 return;
197 if ( xCmdDesc.is() )
201 xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
203 catch ( const NoSuchElementException& )
206 catch ( const WrappedTargetException& )
211 // We have to map commands which uses special characters like '/',':','?','\','<'.'>','|'
212 String aExt = OUString(".png");
213 m_aImageCommandNameVector.resize(aCmdImageSeq.getLength() );
214 m_aImageNameVector.resize( aCmdImageSeq.getLength() );
216 ::std::copy( aCmdImageSeq.getConstArray(),
217 aCmdImageSeq.getConstArray()+aCmdImageSeq.getLength(),
218 m_aImageCommandNameVector.begin() );
220 // Create a image name vector that must be provided to the vcl imagelist. We also need
221 // a command to image name map to speed up access time for image retrieval.
222 OUString aUNOString( ".uno:" );
223 String aEmptyString;
224 const sal_uInt32 nCount = m_aImageCommandNameVector.size();
225 for ( sal_uInt32 i = 0; i < nCount; i++ )
227 OUString aCommandName( m_aImageCommandNameVector[i] );
228 String aImageName;
230 if ( aCommandName.indexOf( aUNOString ) != 0 )
232 INetURLObject aUrlObject( aCommandName, INetURLObject::ENCODE_ALL );
233 aImageName = aUrlObject.GetURLPath();
234 aImageName = getCanonicalName( aImageName ); // convert to valid filename
236 else
238 // just remove the schema
239 if ( aCommandName.getLength() > 5 )
240 aImageName = aCommandName.copy( 5 );
241 else
242 aImageName = aEmptyString;
244 // Search for query part.
245 sal_Int32 nIndex = aImageName.Search( '?' );
246 if ( nIndex != STRING_NOTFOUND )
247 aImageName = getCanonicalName( aImageName ); // convert to valid filename
249 // Image names are not case-dependent. Always use lower case characters to
250 // reflect this.
251 aImageName += aExt;
252 aImageName.ToLowerAscii();
254 m_aImageNameVector[i] = aImageName;
255 m_aCommandToImageNameMap.insert( CommandToImageNameMap::value_type( aCommandName, aImageName ));
258 m_bVectorInit = sal_True;
262 ImageList* CmdImageList::impl_getImageList( sal_Int16 nImageType )
264 SvtMiscOptions aMiscOptions;
266 sal_Int16 nSymbolsStyle = aMiscOptions.GetCurrentSymbolsStyle();
267 if ( nSymbolsStyle != m_nSymbolsStyle )
269 m_nSymbolsStyle = nSymbolsStyle;
270 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
271 delete m_pImageList[n], m_pImageList[n] = NULL;
274 if ( !m_pImageList[nImageType] )
276 m_pImageList[nImageType] = new ImageList( m_aImageNameVector,
277 OUString::createFromAscii( ImageType_Prefixes[nImageType] ) );
280 return m_pImageList[nImageType];
283 std::vector< OUString >& CmdImageList::impl_getImageNameVector()
285 return m_aImageNameVector;
288 std::vector< OUString >& CmdImageList::impl_getImageCommandNameVector()
290 return m_aImageCommandNameVector;
293 Image CmdImageList::getImageFromCommandURL( sal_Int16 nImageType, const OUString& rCommandURL )
295 impl_fillCommandToImageNameMap();
296 CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
297 if ( pIter != m_aCommandToImageNameMap.end() )
299 ImageList* pImageList = impl_getImageList( nImageType );
300 return pImageList->GetImage( pIter->second );
303 return Image();
306 bool CmdImageList::hasImage( sal_Int16 /*nImageType*/, const OUString& rCommandURL )
308 impl_fillCommandToImageNameMap();
309 CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
310 if ( pIter != m_aCommandToImageNameMap.end() )
311 return true;
312 else
313 return false;
316 ::std::vector< OUString >& CmdImageList::getImageNames()
318 return impl_getImageNameVector();
321 ::std::vector< OUString >& CmdImageList::getImageCommandNames()
323 return impl_getImageCommandNameVector();
326 //_________________________________________________________________________________________________________________
328 GlobalImageList::GlobalImageList( const uno::Reference< uno::XComponentContext >& rxContext ) :
329 CmdImageList( rxContext, OUString() ),
330 m_nRefCount( 0 )
334 GlobalImageList::~GlobalImageList()
338 Image GlobalImageList::getImageFromCommandURL( sal_Int16 nImageType, const OUString& rCommandURL )
340 osl::MutexGuard guard( getGlobalImageListMutex() );
341 return CmdImageList::getImageFromCommandURL( nImageType, rCommandURL );
344 bool GlobalImageList::hasImage( sal_Int16 nImageType, const OUString& rCommandURL )
346 osl::MutexGuard guard( getGlobalImageListMutex() );
347 return CmdImageList::hasImage( nImageType, rCommandURL );
350 ::std::vector< OUString >& GlobalImageList::getImageNames()
352 osl::MutexGuard guard( getGlobalImageListMutex() );
353 return impl_getImageNameVector();
356 ::std::vector< OUString >& GlobalImageList::getImageCommandNames()
358 osl::MutexGuard guard( getGlobalImageListMutex() );
359 return impl_getImageCommandNameVector();
362 oslInterlockedCount GlobalImageList::acquire()
364 osl_atomic_increment( &m_nRefCount );
365 return m_nRefCount;
368 oslInterlockedCount GlobalImageList::release()
370 osl::MutexGuard guard( getGlobalImageListMutex() );
372 if ( !osl_atomic_decrement( &m_nRefCount ))
374 oslInterlockedCount nCount( m_nRefCount );
375 // remove global pointer as we destroy the object now
376 pGlobalImageList = 0;
377 delete this;
378 return nCount;
381 return m_nRefCount;
384 static sal_Bool implts_checkAndScaleGraphic( uno::Reference< XGraphic >& rOutGraphic, const uno::Reference< XGraphic >& rInGraphic, sal_Int16 nImageType )
386 static Size aNormSize( IMAGE_SIZE_NORMAL, IMAGE_SIZE_NORMAL );
387 static Size aLargeSize( IMAGE_SIZE_LARGE, IMAGE_SIZE_LARGE );
389 if ( !rInGraphic.is() )
391 rOutGraphic = Image().GetXGraphic();
392 return sal_False;
395 // Check size and scale it
396 Image aImage( rInGraphic );
397 Size aSize = aImage.GetSizePixel();
398 bool bMustScale( false );
400 if ( nImageType == ImageType_Color_Large )
401 bMustScale = ( aSize != aLargeSize );
402 else
403 bMustScale = ( aSize != aNormSize );
405 if ( bMustScale )
407 BitmapEx aBitmap = aImage.GetBitmapEx();
408 aBitmap.Scale( aNormSize );
409 aImage = Image( aBitmap );
410 rOutGraphic = aImage.GetXGraphic();
412 else
413 rOutGraphic = rInGraphic;
414 return sal_True;
417 static sal_Int16 implts_convertImageTypeToIndex( sal_Int16 nImageType )
419 sal_Int16 nIndex( 0 );
420 if ( nImageType & ::com::sun::star::ui::ImageType::SIZE_LARGE )
421 nIndex += 1;
422 return nIndex;
425 ImageList* ImageManagerImpl::implts_getUserImageList( ImageType nImageType )
427 ResetableGuard aGuard( m_aLock );
428 if ( !m_pUserImageList[nImageType] )
429 implts_loadUserImages( nImageType, m_xUserImageStorage, m_xUserBitmapsStorage );
431 return m_pUserImageList[nImageType];
434 void ImageManagerImpl::implts_initialize()
436 // Initialize the top-level structures with the storage data
437 if ( m_xUserConfigStorage.is() )
439 long nModes = m_bReadOnly ? ElementModes::READ : ElementModes::READWRITE;
443 m_xUserImageStorage = m_xUserConfigStorage->openStorageElement( OUString(IMAGE_FOLDER ),
444 nModes );
445 if ( m_xUserImageStorage.is() )
447 m_xUserBitmapsStorage = m_xUserImageStorage->openStorageElement( OUString(BITMAPS_FOLDER ),
448 nModes );
451 catch ( const ::com::sun::star::container::NoSuchElementException& )
454 catch ( const ::com::sun::star::embed::InvalidStorageException& )
457 catch ( const ::com::sun::star::lang::IllegalArgumentException& )
460 catch ( const ::com::sun::star::io::IOException& )
463 catch ( const ::com::sun::star::embed::StorageWrappedTargetException& )
469 sal_Bool ImageManagerImpl::implts_loadUserImages(
470 ImageType nImageType,
471 const uno::Reference< XStorage >& xUserImageStorage,
472 const uno::Reference< XStorage >& xUserBitmapsStorage )
474 ResetableGuard aGuard( m_aLock );
476 if ( xUserImageStorage.is() && xUserBitmapsStorage.is() )
480 uno::Reference< XStream > xStream = xUserImageStorage->openStreamElement( OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ),
481 ElementModes::READ );
482 uno::Reference< XInputStream > xInputStream = xStream->getInputStream();
484 ImageListsDescriptor aUserImageListInfo;
485 ImagesConfiguration::LoadImages( m_xContext,
486 xInputStream,
487 aUserImageListInfo );
488 if (( aUserImageListInfo.pImageList != 0 ) &&
489 ( !aUserImageListInfo.pImageList->empty() ))
491 ImageListItemDescriptor* pList = &aUserImageListInfo.pImageList->front();
492 sal_Int32 nCount = pList->pImageItemList->size();
493 std::vector< OUString > aUserImagesVector;
494 aUserImagesVector.reserve(nCount);
495 for ( sal_uInt16 i=0; i < nCount; i++ )
497 const ImageItemDescriptor* pItem = &(*pList->pImageItemList)[i];
498 aUserImagesVector.push_back( pItem->aCommandURL );
501 uno::Reference< XStream > xBitmapStream = xUserBitmapsStorage->openStreamElement(
502 OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ),
503 ElementModes::READ );
505 if ( xBitmapStream.is() )
507 SvStream* pSvStream( 0 );
508 BitmapEx aUserBitmap;
510 pSvStream = utl::UcbStreamHelper::CreateStream( xBitmapStream );
511 vcl::PNGReader aPngReader( *pSvStream );
512 aUserBitmap = aPngReader.Read();
514 delete pSvStream;
516 // Delete old image list and create a new one from the read bitmap
517 delete m_pUserImageList[nImageType];
518 m_pUserImageList[nImageType] = new ImageList();
519 m_pUserImageList[nImageType]->InsertFromHorizontalStrip
520 ( aUserBitmap, aUserImagesVector );
521 return sal_True;
525 catch ( const ::com::sun::star::container::NoSuchElementException& )
528 catch ( const ::com::sun::star::embed::InvalidStorageException& )
531 catch ( const ::com::sun::star::lang::IllegalArgumentException& )
534 catch ( const ::com::sun::star::io::IOException& )
537 catch ( const ::com::sun::star::embed::StorageWrappedTargetException& )
542 // Destroy old image list - create a new empty one
543 delete m_pUserImageList[nImageType];
544 m_pUserImageList[nImageType] = new ImageList;
546 return sal_True;
549 sal_Bool ImageManagerImpl::implts_storeUserImages(
550 ImageType nImageType,
551 const uno::Reference< XStorage >& xUserImageStorage,
552 const uno::Reference< XStorage >& xUserBitmapsStorage )
554 ResetableGuard aGuard( m_aLock );
556 if ( m_bModified )
558 ImageList* pImageList = implts_getUserImageList( nImageType );
559 if ( pImageList->GetImageCount() > 0 )
561 ImageListsDescriptor aUserImageListInfo;
562 aUserImageListInfo.pImageList = new ImageListDescriptor;
564 ImageListItemDescriptor* pList = new ImageListItemDescriptor;
565 aUserImageListInfo.pImageList->push_back( pList );
567 pList->pImageItemList = new ImageItemListDescriptor;
568 for ( sal_uInt16 i=0; i < pImageList->GetImageCount(); i++ )
570 ImageItemDescriptor* pItem = new ::framework::ImageItemDescriptor;
572 pItem->nIndex = i;
573 pItem->aCommandURL = pImageList->GetImageName( i );
574 pList->pImageItemList->push_back( pItem );
577 pList->aURL = OUString("Bitmaps/");
578 pList->aURL += OUString::createFromAscii(BITMAP_FILE_NAMES[nImageType]);
580 uno::Reference< XTransactedObject > xTransaction;
581 uno::Reference< XOutputStream > xOutputStream;
582 uno::Reference< XStream > xStream = xUserImageStorage->openStreamElement( OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ),
583 ElementModes::WRITE|ElementModes::TRUNCATE );
584 if ( xStream.is() )
586 uno::Reference< XStream > xBitmapStream =
587 xUserBitmapsStorage->openStreamElement( OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ),
588 ElementModes::WRITE|ElementModes::TRUNCATE );
589 if ( xBitmapStream.is() )
591 SvStream* pSvStream = utl::UcbStreamHelper::CreateStream( xBitmapStream );
593 vcl::PNGWriter aPngWriter( pImageList->GetAsHorizontalStrip() );
594 aPngWriter.Write( *pSvStream );
596 delete pSvStream;
598 // Commit user bitmaps storage
599 xTransaction = uno::Reference< XTransactedObject >( xUserBitmapsStorage, UNO_QUERY );
600 if ( xTransaction.is() )
601 xTransaction->commit();
604 xOutputStream = xStream->getOutputStream();
605 if ( xOutputStream.is() )
606 ImagesConfiguration::StoreImages( m_xContext, xOutputStream, aUserImageListInfo );
608 // Commit user image storage
609 xTransaction = uno::Reference< XTransactedObject >( xUserImageStorage, UNO_QUERY );
610 if ( xTransaction.is() )
611 xTransaction->commit();
614 return sal_True;
616 else
618 // Remove the streams from the storage, if we have no data. We have to catch
619 // the NoSuchElementException as it can be possible that there is no stream at all!
622 xUserImageStorage->removeElement( OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ));
624 catch ( const ::com::sun::star::container::NoSuchElementException& )
630 xUserBitmapsStorage->removeElement( OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ));
632 catch ( const ::com::sun::star::container::NoSuchElementException& )
636 uno::Reference< XTransactedObject > xTransaction;
638 // Commit user image storage
639 xTransaction = uno::Reference< XTransactedObject >( xUserImageStorage, UNO_QUERY );
640 if ( xTransaction.is() )
641 xTransaction->commit();
643 // Commit user bitmaps storage
644 xTransaction = uno::Reference< XTransactedObject >( xUserBitmapsStorage, UNO_QUERY );
645 if ( xTransaction.is() )
646 xTransaction->commit();
648 return sal_True;
652 return sal_False;
654 const rtl::Reference< GlobalImageList >& ImageManagerImpl::implts_getGlobalImageList()
656 ResetableGuard aGuard( m_aLock );
658 if ( !m_pGlobalImageList.is() )
659 m_pGlobalImageList = getGlobalImageList( m_xContext );
660 return m_pGlobalImageList;
663 CmdImageList* ImageManagerImpl::implts_getDefaultImageList()
665 ResetableGuard aGuard( m_aLock );
667 if ( !m_pDefaultImageList )
668 m_pDefaultImageList = new CmdImageList( m_xContext, m_aModuleIdentifier );
670 return m_pDefaultImageList;
673 ImageManagerImpl::ImageManagerImpl( const uno::Reference< uno::XComponentContext >& rxContext,::cppu::OWeakObject* pOwner,bool _bUseGlobal ) :
674 ThreadHelpBase( &Application::GetSolarMutex() )
675 , m_xContext( rxContext )
676 , m_pOwner(pOwner)
677 , m_pDefaultImageList( 0 )
678 , m_aXMLPostfix( ".xml" )
679 , m_aResourceString( ModuleImageList )
680 , m_aListenerContainer( m_aLock.getShareableOslMutex() )
681 , m_bUseGlobal(_bUseGlobal)
682 , m_bReadOnly( true )
683 , m_bInitialized( false )
684 , m_bModified( false )
685 , m_bConfigRead( false )
686 , m_bDisposed( false )
688 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
690 m_pUserImageList[n] = 0;
691 m_bUserImageListModified[n] = false;
695 ImageManagerImpl::~ImageManagerImpl()
697 clear();
700 void ImageManagerImpl::dispose()
702 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
703 css::lang::EventObject aEvent( xOwner );
704 m_aListenerContainer.disposeAndClear( aEvent );
707 ResetableGuard aGuard( m_aLock );
708 m_xUserConfigStorage.clear();
709 m_xUserImageStorage.clear();
710 m_xUserRootCommit.clear();
711 m_bConfigRead = false;
712 m_bModified = false;
713 m_bDisposed = true;
715 // delete user and default image list on dispose
716 for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
718 delete m_pUserImageList[n];
719 m_pUserImageList[n] = 0;
721 delete m_pDefaultImageList;
722 m_pDefaultImageList = 0;
726 void ImageManagerImpl::addEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
729 ResetableGuard aGuard( m_aLock );
731 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
732 if ( m_bDisposed )
733 throw DisposedException();
736 m_aListenerContainer.addInterface( ::getCppuType( ( const uno::Reference< XEventListener >* ) NULL ), xListener );
739 void ImageManagerImpl::removeEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
741 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
742 m_aListenerContainer.removeInterface( ::getCppuType( ( const uno::Reference< XEventListener >* ) NULL ), xListener );
745 // XInitialization
746 void ImageManagerImpl::initialize( const Sequence< Any >& aArguments )
748 ResetableGuard aLock( m_aLock );
750 if ( !m_bInitialized )
752 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
754 PropertyValue aPropValue;
755 if ( aArguments[n] >>= aPropValue )
757 if ( aPropValue.Name == "UserConfigStorage" )
759 aPropValue.Value >>= m_xUserConfigStorage;
761 else if ( aPropValue.Name == "ModuleIdentifier" )
763 aPropValue.Value >>= m_aModuleIdentifier;
765 else if ( aPropValue.Name == "UserRootCommit" )
767 aPropValue.Value >>= m_xUserRootCommit;
772 if ( m_xUserConfigStorage.is() )
774 uno::Reference< XPropertySet > xPropSet( m_xUserConfigStorage, UNO_QUERY );
775 if ( xPropSet.is() )
777 long nOpenMode = 0;
778 if ( xPropSet->getPropertyValue( OUString( "OpenMode" )) >>= nOpenMode )
779 m_bReadOnly = !( nOpenMode & ElementModes::WRITE );
783 implts_initialize();
785 m_bInitialized = true;
789 // XImageManagerImpl
790 void ImageManagerImpl::reset()
791 throw (::com::sun::star::uno::RuntimeException)
793 ResetableGuard aLock( m_aLock );
795 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
796 if ( m_bDisposed )
797 throw DisposedException();
799 std::vector< OUString > aUserImageNames;
801 for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
803 aUserImageNames.clear();
804 ImageList* pImageList = implts_getUserImageList( ImageType(i));
805 pImageList->GetImageNames( aUserImageNames );
807 Sequence< OUString > aRemoveList( aUserImageNames.size() );
808 const sal_uInt32 nCount = aUserImageNames.size();
809 for ( sal_uInt32 j = 0; j < nCount; j++ )
810 aRemoveList[j] = aUserImageNames[j];
812 // Remove images
813 removeImages( sal_Int16( i ), aRemoveList );
814 m_bUserImageListModified[i] = true;
817 m_bModified = sal_True;
820 Sequence< OUString > ImageManagerImpl::getAllImageNames( ::sal_Int16 nImageType )
821 throw (::com::sun::star::uno::RuntimeException)
823 ResetableGuard aLock( m_aLock );
825 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
826 if ( m_bDisposed )
827 throw DisposedException();
829 ImageNameMap aImageCmdNameMap;
831 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
833 sal_uInt32 i( 0 );
834 if ( m_bUseGlobal )
836 rtl::Reference< GlobalImageList > rGlobalImageList = implts_getGlobalImageList();
838 const std::vector< OUString >& rGlobalImageNameVector = rGlobalImageList->getImageCommandNames();
839 const sal_uInt32 nGlobalCount = rGlobalImageNameVector.size();
840 for ( i = 0; i < nGlobalCount; i++ )
841 aImageCmdNameMap.insert( ImageNameMap::value_type( rGlobalImageNameVector[i], sal_True ));
843 const std::vector< OUString >& rModuleImageNameVector = implts_getDefaultImageList()->getImageCommandNames();
844 const sal_uInt32 nModuleCount = rModuleImageNameVector.size();
845 for ( i = 0; i < nModuleCount; i++ )
846 aImageCmdNameMap.insert( ImageNameMap::value_type( rModuleImageNameVector[i], sal_True ));
849 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
850 std::vector< OUString > rUserImageNames;
851 pImageList->GetImageNames( rUserImageNames );
852 const sal_uInt32 nUserCount = rUserImageNames.size();
853 for ( i = 0; i < nUserCount; i++ )
854 aImageCmdNameMap.insert( ImageNameMap::value_type( rUserImageNames[i], sal_True ));
856 Sequence< OUString > aImageNameSeq( aImageCmdNameMap.size() );
857 ImageNameMap::const_iterator pIter;
858 i = 0;
859 for ( pIter = aImageCmdNameMap.begin(); pIter != aImageCmdNameMap.end(); ++pIter )
860 aImageNameSeq[i++] = pIter->first;
862 return aImageNameSeq;
865 ::sal_Bool ImageManagerImpl::hasImage( ::sal_Int16 nImageType, const OUString& aCommandURL )
866 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
868 ResetableGuard aLock( m_aLock );
870 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
871 if ( m_bDisposed )
872 throw DisposedException();
874 if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
875 throw IllegalArgumentException();
877 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
878 if ( m_bUseGlobal && implts_getGlobalImageList()->hasImage( nIndex, aCommandURL ))
879 return sal_True;
880 else
882 if ( m_bUseGlobal && implts_getDefaultImageList()->hasImage( nIndex, aCommandURL ))
883 return sal_True;
884 else
886 // User layer
887 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
888 if ( pImageList )
889 return ( pImageList->GetImagePos( aCommandURL ) != IMAGELIST_IMAGE_NOTFOUND );
893 return sal_False;
896 Sequence< uno::Reference< XGraphic > > ImageManagerImpl::getImages(
897 ::sal_Int16 nImageType,
898 const Sequence< OUString >& aCommandURLSequence )
899 throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
901 ResetableGuard aLock( m_aLock );
903 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
904 if ( m_bDisposed )
905 throw DisposedException();
907 if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
908 throw IllegalArgumentException();
910 Sequence< uno::Reference< XGraphic > > aGraphSeq( aCommandURLSequence.getLength() );
912 const OUString* aStrArray = aCommandURLSequence.getConstArray();
914 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
915 rtl::Reference< GlobalImageList > rGlobalImageList;
916 CmdImageList* pDefaultImageList = NULL;
917 if ( m_bUseGlobal )
919 rGlobalImageList = implts_getGlobalImageList();
920 pDefaultImageList = implts_getDefaultImageList();
922 ImageList* pUserImageList = implts_getUserImageList( ImageType( nIndex ));
924 // We have to search our image list in the following order:
925 // 1. user image list (read/write)
926 // 2. module image list (read)
927 // 3. global image list (read)
928 for ( sal_Int32 n = 0; n < aCommandURLSequence.getLength(); n++ )
930 Image aImage = pUserImageList->GetImage( aStrArray[n] );
931 if ( !aImage && m_bUseGlobal )
933 aImage = pDefaultImageList->getImageFromCommandURL( nIndex, aStrArray[n] );
934 if ( !aImage )
935 aImage = rGlobalImageList->getImageFromCommandURL( nIndex, aStrArray[n] );
938 aGraphSeq[n] = aImage.GetXGraphic();
941 return aGraphSeq;
944 void ImageManagerImpl::replaceImages(
945 ::sal_Int16 nImageType,
946 const Sequence< OUString >& aCommandURLSequence,
947 const Sequence< uno::Reference< XGraphic > >& aGraphicsSequence )
948 throw ( ::com::sun::star::lang::IllegalArgumentException,
949 ::com::sun::star::lang::IllegalAccessException,
950 ::com::sun::star::uno::RuntimeException)
952 CmdToXGraphicNameAccess* pInsertedImages( 0 );
953 CmdToXGraphicNameAccess* pReplacedImages( 0 );
956 ResetableGuard aLock( m_aLock );
958 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
959 if ( m_bDisposed )
960 throw DisposedException();
962 if (( aCommandURLSequence.getLength() != aGraphicsSequence.getLength() ) ||
963 (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE )))
964 throw IllegalArgumentException();
966 if ( m_bReadOnly )
967 throw IllegalAccessException();
969 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
970 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
972 uno::Reference< XGraphic > xGraphic;
973 for ( sal_Int32 i = 0; i < aCommandURLSequence.getLength(); i++ )
975 // Check size and scale. If we don't have any graphics ignore it
976 if ( !implts_checkAndScaleGraphic( xGraphic, aGraphicsSequence[i], nIndex ))
977 continue;
979 sal_uInt16 nPos = pImageList->GetImagePos( aCommandURLSequence[i] );
980 if ( nPos == IMAGELIST_IMAGE_NOTFOUND )
982 pImageList->AddImage( aCommandURLSequence[i], xGraphic );
983 if ( !pInsertedImages )
984 pInsertedImages = new CmdToXGraphicNameAccess();
985 pInsertedImages->addElement( aCommandURLSequence[i], xGraphic );
987 else
989 pImageList->ReplaceImage( aCommandURLSequence[i], xGraphic );
990 if ( !pReplacedImages )
991 pReplacedImages = new CmdToXGraphicNameAccess();
992 pReplacedImages->addElement( aCommandURLSequence[i], xGraphic );
996 if (( pInsertedImages != 0 ) || ( pReplacedImages != 0 ))
998 m_bModified = sal_True;
999 m_bUserImageListModified[nIndex] = true;
1003 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
1004 // Notify listeners
1005 if ( pInsertedImages != 0 )
1007 ConfigurationEvent aInsertEvent;
1008 aInsertEvent.aInfo <<= nImageType;
1009 aInsertEvent.Accessor <<= xOwner;
1010 aInsertEvent.Source = xOwner;
1011 aInsertEvent.ResourceURL = m_aResourceString;
1012 aInsertEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1013 static_cast< OWeakObject *>( pInsertedImages ), UNO_QUERY ));
1014 implts_notifyContainerListener( aInsertEvent, NotifyOp_Insert );
1016 if ( pReplacedImages != 0 )
1018 ConfigurationEvent aReplaceEvent;
1019 aReplaceEvent.aInfo <<= nImageType;
1020 aReplaceEvent.Accessor <<= xOwner;
1021 aReplaceEvent.Source = xOwner;
1022 aReplaceEvent.ResourceURL = m_aResourceString;
1023 aReplaceEvent.ReplacedElement = Any();
1024 aReplaceEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1025 static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1026 implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1030 void ImageManagerImpl::removeImages( ::sal_Int16 nImageType, const Sequence< OUString >& aCommandURLSequence )
1031 throw ( ::com::sun::star::lang::IllegalArgumentException,
1032 ::com::sun::star::lang::IllegalAccessException,
1033 ::com::sun::star::uno::RuntimeException)
1035 CmdToXGraphicNameAccess* pRemovedImages( 0 );
1036 CmdToXGraphicNameAccess* pReplacedImages( 0 );
1039 ResetableGuard aLock( m_aLock );
1041 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1042 if ( m_bDisposed )
1043 throw DisposedException();
1045 if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
1046 throw IllegalArgumentException();
1048 if ( m_bReadOnly )
1049 throw IllegalAccessException();
1051 sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
1052 rtl::Reference< GlobalImageList > rGlobalImageList;
1053 CmdImageList* pDefaultImageList = NULL;
1054 if ( m_bUseGlobal )
1056 rGlobalImageList = implts_getGlobalImageList();
1057 pDefaultImageList = implts_getDefaultImageList();
1059 ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
1060 uno::Reference< XGraphic > xEmptyGraphic( Image().GetXGraphic() );
1062 for ( sal_Int32 i = 0; i < aCommandURLSequence.getLength(); i++ )
1064 sal_uInt16 nPos = pImageList->GetImagePos( aCommandURLSequence[i] );
1065 if ( nPos != IMAGELIST_IMAGE_NOTFOUND )
1067 Image aImage = pImageList->GetImage( nPos );
1068 sal_uInt16 nId = pImageList->GetImageId( nPos );
1069 pImageList->RemoveImage( nId );
1071 if ( m_bUseGlobal )
1073 // Check, if we have a image in our module/global image list. If we find one =>
1074 // this is a replace instead of a remove operation!
1075 Image aNewImage = pDefaultImageList->getImageFromCommandURL( nIndex, aCommandURLSequence[i] );
1076 if ( !aNewImage )
1077 aNewImage = rGlobalImageList->getImageFromCommandURL( nIndex, aCommandURLSequence[i] );
1078 if ( !aNewImage )
1080 if ( !pRemovedImages )
1081 pRemovedImages = new CmdToXGraphicNameAccess();
1082 pRemovedImages->addElement( aCommandURLSequence[i], xEmptyGraphic );
1084 else
1086 if ( !pReplacedImages )
1087 pReplacedImages = new CmdToXGraphicNameAccess();
1088 pReplacedImages->addElement( aCommandURLSequence[i], aNewImage.GetXGraphic() );
1090 } // if ( m_bUseGlobal )
1091 else
1093 if ( !pRemovedImages )
1094 pRemovedImages = new CmdToXGraphicNameAccess();
1095 pRemovedImages->addElement( aCommandURLSequence[i], xEmptyGraphic );
1100 if (( pReplacedImages != 0 ) || ( pRemovedImages != 0 ))
1102 m_bModified = sal_True;
1103 m_bUserImageListModified[nIndex] = true;
1107 // Notify listeners
1108 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
1109 if ( pRemovedImages != 0 )
1111 ConfigurationEvent aRemoveEvent;
1112 aRemoveEvent.aInfo = uno::makeAny( nImageType );
1113 aRemoveEvent.Accessor = uno::makeAny( xOwner );
1114 aRemoveEvent.Source = xOwner;
1115 aRemoveEvent.ResourceURL = m_aResourceString;
1116 aRemoveEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1117 static_cast< OWeakObject *>( pRemovedImages ), UNO_QUERY ));
1118 implts_notifyContainerListener( aRemoveEvent, NotifyOp_Remove );
1120 if ( pReplacedImages != 0 )
1122 ConfigurationEvent aReplaceEvent;
1123 aReplaceEvent.aInfo = uno::makeAny( nImageType );
1124 aReplaceEvent.Accessor = uno::makeAny( xOwner );
1125 aReplaceEvent.Source = xOwner;
1126 aReplaceEvent.ResourceURL = m_aResourceString;
1127 aReplaceEvent.ReplacedElement = Any();
1128 aReplaceEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1129 static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1130 implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1134 void ImageManagerImpl::insertImages( ::sal_Int16 nImageType, const Sequence< OUString >& aCommandURLSequence, const Sequence< uno::Reference< XGraphic > >& aGraphicSequence )
1135 throw ( ::com::sun::star::container::ElementExistException,
1136 ::com::sun::star::lang::IllegalArgumentException,
1137 ::com::sun::star::lang::IllegalAccessException,
1138 ::com::sun::star::uno::RuntimeException)
1140 replaceImages(nImageType,aCommandURLSequence,aGraphicSequence);
1144 // XUIConfigurationPersistence
1145 void ImageManagerImpl::reload()
1146 throw ( ::com::sun::star::uno::Exception,
1147 ::com::sun::star::uno::RuntimeException )
1149 ResetableGuard aGuard( m_aLock );
1151 if ( m_bDisposed )
1152 throw DisposedException();
1154 CommandMap aOldUserCmdImageSet;
1155 std::vector< OUString > aNewUserCmdImageSet;
1157 if ( m_bModified )
1159 for ( sal_Int16 i = 0; i < sal_Int16( ImageType_COUNT ); i++ )
1161 if ( !m_bDisposed && m_bUserImageListModified[i] )
1163 std::vector< OUString > aOldUserCmdImageVector;
1164 ImageList* pImageList = implts_getUserImageList( (ImageType)i );
1165 pImageList->GetImageNames( aOldUserCmdImageVector );
1167 // Fill hash map to speed up search afterwards
1168 sal_uInt32 j( 0 );
1169 const sal_uInt32 nOldCount = aOldUserCmdImageVector.size();
1170 for ( j = 0; j < nOldCount; j++ )
1171 aOldUserCmdImageSet.insert( CommandMap::value_type( aOldUserCmdImageVector[j], false ));
1173 // Attention: This can make the old image list pointer invalid!
1174 implts_loadUserImages( (ImageType)i, m_xUserImageStorage, m_xUserBitmapsStorage );
1175 pImageList = implts_getUserImageList( (ImageType)i );
1176 pImageList->GetImageNames( aNewUserCmdImageSet );
1178 CmdToXGraphicNameAccess* pInsertedImages( 0 );
1179 CmdToXGraphicNameAccess* pReplacedImages( 0 );
1180 CmdToXGraphicNameAccess* pRemovedImages( 0 );
1182 const sal_uInt32 nNewCount = aNewUserCmdImageSet.size();
1183 for ( j = 0; j < nNewCount; j++ )
1185 CommandMap::iterator pIter = aOldUserCmdImageSet.find( aNewUserCmdImageSet[j] );
1186 if ( pIter != aOldUserCmdImageSet.end() )
1188 pIter->second = true; // mark entry as replaced
1189 if ( !pReplacedImages )
1190 pReplacedImages = new CmdToXGraphicNameAccess();
1191 pReplacedImages->addElement( aNewUserCmdImageSet[j],
1192 pImageList->GetImage( aNewUserCmdImageSet[j] ).GetXGraphic() );
1194 else
1196 if ( !pInsertedImages )
1197 pInsertedImages = new CmdToXGraphicNameAccess();
1198 pInsertedImages->addElement( aNewUserCmdImageSet[j],
1199 pImageList->GetImage( aNewUserCmdImageSet[j] ).GetXGraphic() );
1203 // Search map for unmarked entries => they have been removed from the user list
1204 // through this reload operation.
1205 // We have to search the module and global image list!
1206 rtl::Reference< GlobalImageList > rGlobalImageList;
1207 CmdImageList* pDefaultImageList = NULL;
1208 if ( m_bUseGlobal )
1210 rGlobalImageList = implts_getGlobalImageList();
1211 pDefaultImageList = implts_getDefaultImageList();
1213 uno::Reference< XGraphic > xEmptyGraphic( Image().GetXGraphic() );
1214 CommandMap::const_iterator pIter = aOldUserCmdImageSet.begin();
1215 while ( pIter != aOldUserCmdImageSet.end() )
1217 if ( !pIter->second )
1219 if ( m_bUseGlobal )
1221 Image aImage = pDefaultImageList->getImageFromCommandURL( i, pIter->first );
1222 if ( !aImage )
1223 aImage = rGlobalImageList->getImageFromCommandURL( i, pIter->first );
1225 if ( !aImage )
1227 // No image in the module/global image list => remove user image
1228 if ( !pRemovedImages )
1229 pRemovedImages = new CmdToXGraphicNameAccess();
1230 pRemovedImages->addElement( pIter->first, xEmptyGraphic );
1232 else
1234 // Image has been found in the module/global image list => replace user image
1235 if ( !pReplacedImages )
1236 pReplacedImages = new CmdToXGraphicNameAccess();
1237 pReplacedImages->addElement( pIter->first, aImage.GetXGraphic() );
1239 } // if ( m_bUseGlobal )
1240 else
1242 // No image in the user image list => remove user image
1243 if ( !pRemovedImages )
1244 pRemovedImages = new CmdToXGraphicNameAccess();
1245 pRemovedImages->addElement( pIter->first, xEmptyGraphic );
1248 ++pIter;
1251 aGuard.unlock();
1253 // Now notify our listeners. Unlock mutex to prevent deadlocks
1254 uno::Reference< uno::XInterface > xOwner(static_cast< OWeakObject* >(m_pOwner));
1255 if ( pInsertedImages != 0 )
1257 ConfigurationEvent aInsertEvent;
1258 aInsertEvent.aInfo = uno::makeAny( i );
1259 aInsertEvent.Accessor = uno::makeAny( xOwner );
1260 aInsertEvent.Source = xOwner;
1261 aInsertEvent.ResourceURL = m_aResourceString;
1262 aInsertEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1263 static_cast< OWeakObject *>( pInsertedImages ), UNO_QUERY ));
1264 implts_notifyContainerListener( aInsertEvent, NotifyOp_Insert );
1266 if ( pReplacedImages != 0 )
1268 ConfigurationEvent aReplaceEvent;
1269 aReplaceEvent.aInfo = uno::makeAny( i );
1270 aReplaceEvent.Accessor = uno::makeAny( xOwner );
1271 aReplaceEvent.Source = xOwner;
1272 aReplaceEvent.ResourceURL = m_aResourceString;
1273 aReplaceEvent.ReplacedElement = Any();
1274 aReplaceEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1275 static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1276 implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1278 if ( pRemovedImages != 0 )
1280 ConfigurationEvent aRemoveEvent;
1281 aRemoveEvent.aInfo = uno::makeAny( i );
1282 aRemoveEvent.Accessor = uno::makeAny( xOwner );
1283 aRemoveEvent.Source = xOwner;
1284 aRemoveEvent.ResourceURL = m_aResourceString;
1285 aRemoveEvent.Element = uno::makeAny( uno::Reference< XNameAccess >(
1286 static_cast< OWeakObject *>( pRemovedImages ), UNO_QUERY ));
1287 implts_notifyContainerListener( aRemoveEvent, NotifyOp_Remove );
1290 aGuard.lock();
1296 void ImageManagerImpl::store()
1297 throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1299 ResetableGuard aGuard( m_aLock );
1301 if ( m_bDisposed )
1302 throw DisposedException();
1304 if ( m_bModified )
1306 sal_Bool bWritten( sal_False );
1307 for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
1309 sal_Bool bSuccess = implts_storeUserImages( ImageType(i), m_xUserImageStorage, m_xUserBitmapsStorage );
1310 if ( bSuccess )
1311 bWritten = sal_True;
1312 m_bUserImageListModified[i] = false;
1315 if ( bWritten &&
1316 m_xUserConfigStorage.is() )
1318 uno::Reference< XTransactedObject > xUserConfigStorageCommit( m_xUserConfigStorage, UNO_QUERY );
1319 if ( xUserConfigStorageCommit.is() )
1320 xUserConfigStorageCommit->commit();
1321 if ( m_xUserRootCommit.is() )
1322 m_xUserRootCommit->commit();
1325 m_bModified = sal_False;
1329 void ImageManagerImpl::storeToStorage( const uno::Reference< XStorage >& Storage )
1330 throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1332 ResetableGuard aGuard( m_aLock );
1334 if ( m_bDisposed )
1335 throw DisposedException();
1337 if ( m_bModified && Storage.is() )
1339 long nModes = ElementModes::READWRITE;
1341 uno::Reference< XStorage > xUserImageStorage = Storage->openStorageElement( OUString(IMAGE_FOLDER ),
1342 nModes );
1343 if ( xUserImageStorage.is() )
1345 uno::Reference< XStorage > xUserBitmapsStorage = xUserImageStorage->openStorageElement( OUString(BITMAPS_FOLDER ),
1346 nModes );
1347 for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
1349 implts_getUserImageList( (ImageType)i );
1350 implts_storeUserImages( (ImageType)i, xUserImageStorage, xUserBitmapsStorage );
1353 uno::Reference< XTransactedObject > xTransaction( Storage, UNO_QUERY );
1354 if ( xTransaction.is() )
1355 xTransaction->commit();
1360 sal_Bool ImageManagerImpl::isModified()
1361 throw (::com::sun::star::uno::RuntimeException)
1363 ResetableGuard aGuard( m_aLock );
1364 return m_bModified;
1367 sal_Bool ImageManagerImpl::isReadOnly() throw (::com::sun::star::uno::RuntimeException)
1369 ResetableGuard aGuard( m_aLock );
1370 return m_bReadOnly;
1372 // XUIConfiguration
1373 void ImageManagerImpl::addConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
1374 throw (::com::sun::star::uno::RuntimeException)
1377 ResetableGuard aGuard( m_aLock );
1379 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1380 if ( m_bDisposed )
1381 throw DisposedException();
1384 m_aListenerContainer.addInterface( ::getCppuType( ( const uno::Reference< XUIConfigurationListener >* ) NULL ), xListener );
1387 void ImageManagerImpl::removeConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
1388 throw (::com::sun::star::uno::RuntimeException)
1390 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1391 m_aListenerContainer.removeInterface( ::getCppuType( ( const uno::Reference< XUIConfigurationListener >* ) NULL ), xListener );
1395 void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& aEvent, NotifyOp eOp )
1397 ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
1398 ::getCppuType( ( const css::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >*) NULL ) );
1399 if ( pContainer != NULL )
1401 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
1402 while ( pIterator.hasMoreElements() )
1406 switch ( eOp )
1408 case NotifyOp_Replace:
1409 ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementReplaced( aEvent );
1410 break;
1411 case NotifyOp_Insert:
1412 ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementInserted( aEvent );
1413 break;
1414 case NotifyOp_Remove:
1415 ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementRemoved( aEvent );
1416 break;
1419 catch( const css::uno::RuntimeException& )
1421 pIterator.remove();
1426 void ImageManagerImpl::clear()
1428 ResetableGuard aGuard( m_aLock );
1430 for ( sal_Int32 n = 0; n < ImageType_COUNT; n++ )
1432 delete m_pUserImageList[n];
1433 m_pUserImageList[n] = 0;
1436 } // namespace framework
1438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */