1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ImageManagerImpl.cxx,v $
10 * $Revision: 1.16.82.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <imagemanagerimpl.hxx>
34 #include <threadhelp/resetableguard.hxx>
35 #include <xml/imagesconfiguration.hxx>
36 #include <uiconfiguration/graphicnameaccess.hxx>
39 #include "properties.h"
41 //_________________________________________________________________________________________________________________
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/ui/UIElementType.hpp>
45 #include <com/sun/star/ui/ConfigurationEvent.hpp>
46 #include <com/sun/star/lang/DisposedException.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #include <com/sun/star/embed/ElementModes.hpp>
50 #include <com/sun/star/io/XStream.hpp>
51 #include <com/sun/star/ui/ImageType.hpp>
53 //_________________________________________________________________________________________________________________
55 //_________________________________________________________________________________________________________________
57 #include <vcl/svapp.hxx>
58 #include <rtl/ustrbuf.hxx>
59 #include <osl/mutex.hxx>
60 #include <comphelper/sequence.hxx>
61 #include <tools/urlobj.hxx>
62 #include <unotools/ucbstreamhelper.hxx>
63 #include <vcl/pngread.hxx>
64 #include <vcl/pngwrite.hxx>
65 #include <rtl/logfile.hxx>
66 #include "svtools/miscopt.hxx"
68 //_________________________________________________________________________________________________________________
70 //_________________________________________________________________________________________________________________
72 using ::rtl::OUString
;
73 using ::com::sun::star::uno::Sequence
;
74 using ::com::sun::star::uno::XInterface
;
75 using ::com::sun::star::uno::Exception
;
76 using ::com::sun::star::uno::RuntimeException
;
77 using ::com::sun::star::uno::UNO_QUERY
;
78 using ::com::sun::star::uno::Any
;
79 using ::com::sun::star::uno::makeAny
;
80 using ::com::sun::star::graphic::XGraphic
;
81 using namespace ::com::sun::star
;
82 using namespace ::com::sun::star::io
;
83 using namespace ::com::sun::star::embed
;
84 using namespace ::com::sun::star::lang
;
85 using namespace ::com::sun::star::container
;
86 using namespace ::com::sun::star::beans
;
87 using namespace ::com::sun::star::ui
;
88 using namespace ::cppu
;
90 // Image sizes for our toolbars/menus
91 const sal_Int32 IMAGE_SIZE_NORMAL
= 16;
92 const sal_Int32 IMAGE_SIZE_LARGE
= 26;
93 const sal_Int16 MAX_IMAGETYPE_VALUE
= ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST
|
94 ::com::sun::star::ui::ImageType::SIZE_LARGE
;
96 static const char IMAGE_FOLDER
[] = "images";
97 static const char BITMAPS_FOLDER
[] = "Bitmaps";
98 static const char IMAGE_EXTENSION
[] = ".png";
100 static const char* IMAGELIST_XML_FILE
[] =
108 static const char* BITMAP_FILE_NAMES
[] =
112 "sch_userimages.png",
118 static char ModuleImageList
[] = "private:resource/images/moduleimages";
119 static osl::Mutex
* pImageListWrapperMutex
= 0;
120 static GlobalImageList
* pGlobalImageList
= 0;
121 static const char* ImageType_Prefixes
[ImageType_COUNT
] =
123 "res/commandimagelist/sc_",
124 "res/commandimagelist/lc_",
125 "res/commandimagelist/sch_",
126 "res/commandimagelist/lch_"
129 typedef GraphicNameAccess CmdToXGraphicNameAccess
;
131 static osl::Mutex
& getGlobalImageListMutex()
133 if ( pImageListWrapperMutex
== 0 )
135 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
136 if ( pImageListWrapperMutex
== 0 )
137 pImageListWrapperMutex
= new osl::Mutex
;
140 return *pImageListWrapperMutex
;
143 static GlobalImageList
* getGlobalImageList( const uno::Reference
< XMultiServiceFactory
>& rServiceManager
)
145 osl::MutexGuard
guard( getGlobalImageListMutex() );
147 if ( pGlobalImageList
== 0 )
148 pGlobalImageList
= new GlobalImageList( rServiceManager
);
150 return pGlobalImageList
;
153 static rtl::OUString
getCanonicalName( const rtl::OUString
& rFileName
)
155 bool bRemoveSlash( true );
156 sal_Int32 nLength
= rFileName
.getLength();
157 const sal_Unicode
* pString
= rFileName
.getStr();
159 rtl::OUStringBuffer
aBuf( nLength
);
160 for ( sal_Int32 i
= 0; i
< nLength
; i
++ )
162 const sal_Unicode c
= pString
[i
];
165 // map forbidden characters to escape
166 case '/' : if ( !bRemoveSlash
)
167 aBuf
.appendAscii( "%2f" );
169 case '\\': aBuf
.appendAscii( "%5c" ); bRemoveSlash
= false; break;
170 case ':' : aBuf
.appendAscii( "%3a" ); bRemoveSlash
= false; break;
171 case '*' : aBuf
.appendAscii( "%2a" ); bRemoveSlash
= false; break;
172 case '?' : aBuf
.appendAscii( "%3f" ); bRemoveSlash
= false; break;
173 case '<' : aBuf
.appendAscii( "%3c" ); bRemoveSlash
= false; break;
174 case '>' : aBuf
.appendAscii( "%3e" ); bRemoveSlash
= false; break;
175 case '|' : aBuf
.appendAscii( "%7c" ); bRemoveSlash
= false; break;
176 default: aBuf
.append( c
); bRemoveSlash
= false;
179 return aBuf
.makeStringAndClear();
182 //_________________________________________________________________________________________________________________
184 CmdImageList::CmdImageList( const uno::Reference
< XMultiServiceFactory
>& rServiceManager
, const rtl::OUString
& aModuleIdentifier
) :
185 m_bVectorInit( sal_False
),
186 m_aModuleIdentifier( aModuleIdentifier
),
187 m_xServiceManager( rServiceManager
),
188 m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
190 for ( sal_Int32 n
=0; n
< ImageType_COUNT
; n
++ )
194 CmdImageList::~CmdImageList()
196 for ( sal_Int32 n
=0; n
< ImageType_COUNT
; n
++ )
197 delete m_pImageList
[n
];
200 void CmdImageList::impl_fillCommandToImageNameMap()
202 RTL_LOGFILE_CONTEXT( aLog
, "framework: CmdImageList::impl_fillCommandToImageNameMap" );
204 if ( !m_bVectorInit
)
206 const rtl::OUString
aCommandImageList( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST
));
207 Sequence
< OUString
> aCmdImageSeq
;
208 uno::Reference
< XNameAccess
> xCmdDesc( m_xServiceManager
->createInstance(
209 SERVICENAME_UICOMMANDDESCRIPTION
),
212 if ( m_aModuleIdentifier
.getLength() > 0 )
214 // If we have a module identifier - use to retrieve the command image name list from it.
215 // Otherwise we will use the global command image list
218 xCmdDesc
->getByName( m_aModuleIdentifier
) >>= xCmdDesc
;
220 xCmdDesc
->getByName( aCommandImageList
) >>= aCmdImageSeq
;
222 catch ( NoSuchElementException
& )
224 // Module unknown we will work with an empty command image list!
233 xCmdDesc
->getByName( aCommandImageList
) >>= aCmdImageSeq
;
235 catch ( NoSuchElementException
& )
238 catch ( WrappedTargetException
& )
243 // We have to map commands which uses special characters like '/',':','?','\','<'.'>','|'
244 String aExt
= String::CreateFromAscii( IMAGE_EXTENSION
);
245 m_aImageCommandNameVector
.resize(aCmdImageSeq
.getLength() );
246 m_aImageNameVector
.resize( aCmdImageSeq
.getLength() );
248 ::std::copy( aCmdImageSeq
.getConstArray(),
249 aCmdImageSeq
.getConstArray()+aCmdImageSeq
.getLength(),
250 m_aImageCommandNameVector
.begin() );
252 // Create a image name vector that must be provided to the vcl imagelist. We also need
253 // a command to image name map to speed up access time for image retrieval.
254 OUString
aUNOString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
256 const sal_uInt32 nCount
= m_aImageCommandNameVector
.size();
257 for ( sal_uInt32 i
= 0; i
< nCount
; i
++ )
259 OUString
aCommandName( m_aImageCommandNameVector
[i
] );
262 if ( aCommandName
.indexOf( aUNOString
) != 0 )
264 INetURLObject
aUrlObject( aCommandName
, INetURLObject::ENCODE_ALL
);
265 aImageName
= aUrlObject
.GetURLPath();
266 aImageName
= getCanonicalName( aImageName
); // convert to valid filename
270 // just remove the schema
271 if ( aCommandName
.getLength() > 5 )
272 aImageName
= aCommandName
.copy( 5 );
274 aImageName
= aEmptyString
;
276 // Search for query part.
277 sal_Int32 nIndex
= aImageName
.Search( '?' );
278 if ( nIndex
!= STRING_NOTFOUND
)
279 aImageName
= getCanonicalName( aImageName
); // convert to valid filename
281 // Image names are not case-dependent. Always use lower case characters to
284 aImageName
.ToLowerAscii();
286 m_aImageNameVector
[i
] = aImageName
;
287 m_aCommandToImageNameMap
.insert( CommandToImageNameMap::value_type( aCommandName
, aImageName
));
290 m_bVectorInit
= sal_True
;
294 ImageList
* CmdImageList::impl_getImageList( sal_Int16 nImageType
)
296 SvtMiscOptions aMiscOptions
;
298 sal_Int16 nSymbolsStyle
= aMiscOptions
.GetCurrentSymbolsStyle();
299 if ( nSymbolsStyle
!= m_nSymbolsStyle
)
301 m_nSymbolsStyle
= nSymbolsStyle
;
302 for ( sal_Int32 n
=0; n
< ImageType_COUNT
; n
++ )
303 delete m_pImageList
[n
], m_pImageList
[n
] = NULL
;
306 if ( !m_pImageList
[nImageType
] )
308 m_pImageList
[nImageType
] = new ImageList( m_aImageNameVector
,
309 OUString::createFromAscii( ImageType_Prefixes
[nImageType
] ) );
312 return m_pImageList
[nImageType
];
315 std::vector
< ::rtl::OUString
>& CmdImageList::impl_getImageNameVector()
317 return m_aImageNameVector
;
320 std::vector
< rtl::OUString
>& CmdImageList::impl_getImageCommandNameVector()
322 return m_aImageCommandNameVector
;
325 Image
CmdImageList::getImageFromCommandURL( sal_Int16 nImageType
, const rtl::OUString
& rCommandURL
)
327 impl_fillCommandToImageNameMap();
328 CommandToImageNameMap::const_iterator pIter
= m_aCommandToImageNameMap
.find( rCommandURL
);
329 if ( pIter
!= m_aCommandToImageNameMap
.end() )
331 ImageList
* pImageList
= impl_getImageList( nImageType
);
332 return pImageList
->GetImage( pIter
->second
);
338 bool CmdImageList::hasImage( sal_Int16
/*nImageType*/, const rtl::OUString
& rCommandURL
)
340 impl_fillCommandToImageNameMap();
341 CommandToImageNameMap::const_iterator pIter
= m_aCommandToImageNameMap
.find( rCommandURL
);
342 if ( pIter
!= m_aCommandToImageNameMap
.end() )
348 ::std::vector
< rtl::OUString
>& CmdImageList::getImageNames()
350 return impl_getImageNameVector();
353 ::std::vector
< rtl::OUString
>& CmdImageList::getImageCommandNames()
355 return impl_getImageCommandNameVector();
358 //_________________________________________________________________________________________________________________
360 GlobalImageList::GlobalImageList( const uno::Reference
< XMultiServiceFactory
>& rServiceManager
) :
361 CmdImageList( rServiceManager
, rtl::OUString() ),
366 GlobalImageList::~GlobalImageList()
370 Image
GlobalImageList::getImageFromCommandURL( sal_Int16 nImageType
, const rtl::OUString
& rCommandURL
)
372 osl::MutexGuard
guard( getGlobalImageListMutex() );
373 return CmdImageList::getImageFromCommandURL( nImageType
, rCommandURL
);
376 bool GlobalImageList::hasImage( sal_Int16 nImageType
, const rtl::OUString
& rCommandURL
)
378 osl::MutexGuard
guard( getGlobalImageListMutex() );
379 return CmdImageList::hasImage( nImageType
, rCommandURL
);
382 ::std::vector
< rtl::OUString
>& GlobalImageList::getImageNames()
384 osl::MutexGuard
guard( getGlobalImageListMutex() );
385 return impl_getImageNameVector();
388 ::std::vector
< rtl::OUString
>& GlobalImageList::getImageCommandNames()
390 osl::MutexGuard
guard( getGlobalImageListMutex() );
391 return impl_getImageCommandNameVector();
394 oslInterlockedCount
GlobalImageList::acquire()
396 osl_incrementInterlockedCount( &m_nRefCount
);
400 oslInterlockedCount
GlobalImageList::release()
402 osl::MutexGuard
guard( getGlobalImageListMutex() );
404 if ( !osl_decrementInterlockedCount( &m_nRefCount
))
406 oslInterlockedCount
nCount( m_nRefCount
);
407 // remove global pointer as we destroy the object now
408 pGlobalImageList
= 0;
416 static sal_Bool
implts_checkAndScaleGraphic( uno::Reference
< XGraphic
>& rOutGraphic
, const uno::Reference
< XGraphic
>& rInGraphic
, sal_Int16 nImageType
)
418 static Size
aNormSize( IMAGE_SIZE_NORMAL
, IMAGE_SIZE_NORMAL
);
419 static Size
aLargeSize( IMAGE_SIZE_LARGE
, IMAGE_SIZE_LARGE
);
421 if ( !rInGraphic
.is() )
423 rOutGraphic
= Image().GetXGraphic();
427 // Check size and scale it
428 Image
aImage( rInGraphic
);
429 Size aSize
= aImage
.GetSizePixel();
430 bool bMustScale( false );
432 if (( nImageType
== ImageType_Color_Large
) ||
433 ( nImageType
== ImageType_HC_Large
))
434 bMustScale
= ( aSize
!= aLargeSize
);
436 bMustScale
= ( aSize
!= aNormSize
);
440 BitmapEx aBitmap
= aImage
.GetBitmapEx();
441 aBitmap
.Scale( aNormSize
);
442 aImage
= Image( aBitmap
);
443 rOutGraphic
= aImage
.GetXGraphic();
446 rOutGraphic
= rInGraphic
;
450 static sal_Int16
implts_convertImageTypeToIndex( sal_Int16 nImageType
)
452 sal_Int16
nIndex( 0 );
453 if ( nImageType
& ::com::sun::star::ui::ImageType::SIZE_LARGE
)
455 if ( nImageType
& ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST
)
460 ImageList
* ImageManagerImpl::implts_getUserImageList( ImageType nImageType
)
462 ResetableGuard
aGuard( m_aLock
);
463 if ( !m_pUserImageList
[nImageType
] )
464 implts_loadUserImages( nImageType
, m_xUserImageStorage
, m_xUserBitmapsStorage
);
466 return m_pUserImageList
[nImageType
];
469 void ImageManagerImpl::implts_initialize()
471 // Initialize the top-level structures with the storage data
472 if ( m_xUserConfigStorage
.is() )
474 long nModes
= m_bReadOnly
? ElementModes::READ
: ElementModes::READWRITE
;
478 m_xUserImageStorage
= m_xUserConfigStorage
->openStorageElement( OUString::createFromAscii( IMAGE_FOLDER
),
480 if ( m_xUserImageStorage
.is() )
482 m_xUserBitmapsStorage
= m_xUserImageStorage
->openStorageElement( OUString::createFromAscii( BITMAPS_FOLDER
),
486 catch ( com::sun::star::container::NoSuchElementException
& )
489 catch ( ::com::sun::star::embed::InvalidStorageException
& )
492 catch ( ::com::sun::star::lang::IllegalArgumentException
& )
495 catch ( ::com::sun::star::io::IOException
& )
498 catch ( ::com::sun::star::embed::StorageWrappedTargetException
& )
504 sal_Bool
ImageManagerImpl::implts_loadUserImages(
505 ImageType nImageType
,
506 const uno::Reference
< XStorage
>& xUserImageStorage
,
507 const uno::Reference
< XStorage
>& xUserBitmapsStorage
)
509 ResetableGuard
aGuard( m_aLock
);
511 if ( xUserImageStorage
.is() && xUserBitmapsStorage
.is() )
515 uno::Reference
< XStream
> xStream
= xUserImageStorage
->openStreamElement( rtl::OUString::createFromAscii( IMAGELIST_XML_FILE
[nImageType
] ),
516 ElementModes::READ
);
517 uno::Reference
< XInputStream
> xInputStream
= xStream
->getInputStream();
519 ImageListsDescriptor aUserImageListInfo
;
520 ImagesConfiguration::LoadImages( m_xServiceManager
,
522 aUserImageListInfo
);
523 if (( aUserImageListInfo
.pImageList
!= 0 ) &&
524 ( aUserImageListInfo
.pImageList
->Count() > 0 ))
526 ImageListItemDescriptor
* pList
= aUserImageListInfo
.pImageList
->GetObject(0);
527 sal_Int32 nCount
= pList
->pImageItemList
->Count();
528 std::vector
< OUString
> aUserImagesVector
;
529 aUserImagesVector
.reserve(nCount
);
530 for ( USHORT i
=0; i
< nCount
; i
++ )
532 const ImageItemDescriptor
* pItem
= pList
->pImageItemList
->GetObject(i
);
533 aUserImagesVector
.push_back( pItem
->aCommandURL
);
536 uno::Reference
< XStream
> xBitmapStream
= xUserBitmapsStorage
->openStreamElement(
537 rtl::OUString::createFromAscii( BITMAP_FILE_NAMES
[nImageType
] ),
538 ElementModes::READ
);
540 if ( xBitmapStream
.is() )
542 SvStream
* pSvStream( 0 );
543 BitmapEx aUserBitmap
;
545 pSvStream
= utl::UcbStreamHelper::CreateStream( xBitmapStream
);
546 vcl::PNGReader
aPngReader( *pSvStream
);
547 aUserBitmap
= aPngReader
.Read();
551 // Delete old image list and create a new one from the read bitmap
552 delete m_pUserImageList
[nImageType
];
553 m_pUserImageList
[nImageType
] = new ImageList();
554 m_pUserImageList
[nImageType
]->InsertFromHorizontalStrip
555 ( aUserBitmap
, aUserImagesVector
);
560 catch ( com::sun::star::container::NoSuchElementException
& )
563 catch ( ::com::sun::star::embed::InvalidStorageException
& )
566 catch ( ::com::sun::star::lang::IllegalArgumentException
& )
569 catch ( ::com::sun::star::io::IOException
& )
572 catch ( ::com::sun::star::embed::StorageWrappedTargetException
& )
577 // Destroy old image list - create a new empty one
578 delete m_pUserImageList
[nImageType
];
579 m_pUserImageList
[nImageType
] = new ImageList
;
584 sal_Bool
ImageManagerImpl::implts_storeUserImages(
585 ImageType nImageType
,
586 const uno::Reference
< XStorage
>& xUserImageStorage
,
587 const uno::Reference
< XStorage
>& xUserBitmapsStorage
)
589 ResetableGuard
aGuard( m_aLock
);
593 ImageList
* pImageList
= implts_getUserImageList( nImageType
);
594 if ( pImageList
->GetImageCount() > 0 )
596 ImageListsDescriptor aUserImageListInfo
;
597 aUserImageListInfo
.pImageList
= new ImageListDescriptor
;
599 ImageListItemDescriptor
* pList
= new ImageListItemDescriptor
;
600 aUserImageListInfo
.pImageList
->Insert( pList
, 0 );
602 pList
->pImageItemList
= new ImageItemListDescriptor
;
603 for ( USHORT i
=0; i
< pImageList
->GetImageCount(); i
++ )
605 ImageItemDescriptor
* pItem
= new ::framework::ImageItemDescriptor
;
608 pItem
->aCommandURL
= pImageList
->GetImageName( i
);
609 pList
->pImageItemList
->Insert( pItem
, pList
->pImageItemList
->Count() );
612 pList
->aURL
= String::CreateFromAscii("Bitmaps/");
613 pList
->aURL
+= String::CreateFromAscii( BITMAP_FILE_NAMES
[nImageType
] );
615 uno::Reference
< XTransactedObject
> xTransaction
;
616 uno::Reference
< XOutputStream
> xOutputStream
;
617 uno::Reference
< XStream
> xStream
= xUserImageStorage
->openStreamElement( rtl::OUString::createFromAscii( IMAGELIST_XML_FILE
[nImageType
] ),
618 ElementModes::WRITE
|ElementModes::TRUNCATE
);
621 uno::Reference
< XStream
> xBitmapStream
=
622 xUserBitmapsStorage
->openStreamElement( rtl::OUString::createFromAscii( BITMAP_FILE_NAMES
[nImageType
] ),
623 ElementModes::WRITE
|ElementModes::TRUNCATE
);
624 if ( xBitmapStream
.is() )
626 SvStream
* pSvStream
= utl::UcbStreamHelper::CreateStream( xBitmapStream
);
628 vcl::PNGWriter
aPngWriter( pImageList
->GetAsHorizontalStrip() );
629 aPngWriter
.Write( *pSvStream
);
633 // Commit user bitmaps storage
634 xTransaction
= uno::Reference
< XTransactedObject
>( xUserBitmapsStorage
, UNO_QUERY
);
635 if ( xTransaction
.is() )
636 xTransaction
->commit();
639 xOutputStream
= xStream
->getOutputStream();
640 if ( xOutputStream
.is() )
641 ImagesConfiguration::StoreImages( m_xServiceManager
, xOutputStream
, aUserImageListInfo
);
643 // Commit user image storage
644 xTransaction
= uno::Reference
< XTransactedObject
>( xUserImageStorage
, UNO_QUERY
);
645 if ( xTransaction
.is() )
646 xTransaction
->commit();
653 // Remove the streams from the storage, if we have no data. We have to catch
654 // the NoSuchElementException as it can be possible that there is no stream at all!
657 xUserImageStorage
->removeElement( rtl::OUString::createFromAscii( IMAGELIST_XML_FILE
[nImageType
] ));
659 catch ( ::com::sun::star::container::NoSuchElementException
& )
665 xUserBitmapsStorage
->removeElement( rtl::OUString::createFromAscii( BITMAP_FILE_NAMES
[nImageType
] ));
667 catch ( ::com::sun::star::container::NoSuchElementException
& )
671 uno::Reference
< XTransactedObject
> xTransaction
;
673 // Commit user image storage
674 xTransaction
= uno::Reference
< XTransactedObject
>( xUserImageStorage
, UNO_QUERY
);
675 if ( xTransaction
.is() )
676 xTransaction
->commit();
678 // Commit user bitmaps storage
679 xTransaction
= uno::Reference
< XTransactedObject
>( xUserBitmapsStorage
, UNO_QUERY
);
680 if ( xTransaction
.is() )
681 xTransaction
->commit();
689 const rtl::Reference
< GlobalImageList
>& ImageManagerImpl::implts_getGlobalImageList()
691 ResetableGuard
aGuard( m_aLock
);
693 if ( !m_pGlobalImageList
.is() )
694 m_pGlobalImageList
= getGlobalImageList( m_xServiceManager
);
695 return m_pGlobalImageList
;
698 CmdImageList
* ImageManagerImpl::implts_getDefaultImageList()
700 ResetableGuard
aGuard( m_aLock
);
702 if ( !m_pDefaultImageList
)
703 m_pDefaultImageList
= new CmdImageList( m_xServiceManager
, m_aModuleIdentifier
);
705 return m_pDefaultImageList
;
708 ImageManagerImpl::ImageManagerImpl( const uno::Reference
< XMultiServiceFactory
>& xServiceManager
,const uno::Reference
< XInterface
>& _xOwner
,bool _bUseGlobal
) :
709 ThreadHelpBase( &Application::GetSolarMutex() )
710 , m_xServiceManager( xServiceManager
)
712 , m_pDefaultImageList( 0 )
713 , m_aXMLPostfix( RTL_CONSTASCII_USTRINGPARAM( ".xml" ))
714 , m_aResourceString( RTL_CONSTASCII_USTRINGPARAM( ModuleImageList
))
715 , m_aListenerContainer( m_aLock
.getShareableOslMutex() )
716 , m_bUseGlobal(_bUseGlobal
)
717 , m_bReadOnly( true )
718 , m_bInitialized( false )
719 , m_bModified( false )
720 , m_bConfigRead( false )
721 , m_bDisposed( false )
723 for ( sal_Int32 n
=0; n
< ImageType_COUNT
; n
++ )
725 m_pUserImageList
[n
] = 0;
726 m_bUserImageListModified
[n
] = false;
730 ImageManagerImpl::~ImageManagerImpl()
735 void ImageManagerImpl::dispose()
737 css::lang::EventObject
aEvent( m_xOwner
);
738 m_aListenerContainer
.disposeAndClear( aEvent
);
741 ResetableGuard
aGuard( m_aLock
);
742 m_xUserConfigStorage
.clear();
743 m_xUserImageStorage
.clear();
744 m_xUserRootCommit
.clear();
745 m_bConfigRead
= false;
749 // delete user and default image list on dispose
750 for ( sal_Int32 n
=0; n
< ImageType_COUNT
; n
++ )
752 delete m_pUserImageList
[n
];
753 m_pUserImageList
[n
] = 0;
755 delete m_pDefaultImageList
;
756 m_pDefaultImageList
= 0;
760 void ImageManagerImpl::addEventListener( const uno::Reference
< XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
)
763 ResetableGuard
aGuard( m_aLock
);
765 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
767 throw DisposedException();
770 m_aListenerContainer
.addInterface( ::getCppuType( ( const uno::Reference
< XEventListener
>* ) NULL
), xListener
);
773 void ImageManagerImpl::removeEventListener( const uno::Reference
< XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
)
775 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
776 m_aListenerContainer
.removeInterface( ::getCppuType( ( const uno::Reference
< XEventListener
>* ) NULL
), xListener
);
780 void ImageManagerImpl::initialize( const Sequence
< Any
>& aArguments
)
782 ResetableGuard
aLock( m_aLock
);
784 if ( !m_bInitialized
)
786 for ( sal_Int32 n
= 0; n
< aArguments
.getLength(); n
++ )
788 PropertyValue aPropValue
;
789 if ( aArguments
[n
] >>= aPropValue
)
791 if ( aPropValue
.Name
.equalsAscii( "UserConfigStorage" ))
793 aPropValue
.Value
>>= m_xUserConfigStorage
;
795 else if ( aPropValue
.Name
.equalsAscii( "ModuleIdentifier" ))
797 aPropValue
.Value
>>= m_aModuleIdentifier
;
799 else if ( aPropValue
.Name
.equalsAscii( "UserRootCommit" ))
801 aPropValue
.Value
>>= m_xUserRootCommit
;
806 if ( m_xUserConfigStorage
.is() )
808 uno::Reference
< XPropertySet
> xPropSet( m_xUserConfigStorage
, UNO_QUERY
);
812 if ( xPropSet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ))) >>= nOpenMode
)
813 m_bReadOnly
= !( nOpenMode
& ElementModes::WRITE
);
819 m_bInitialized
= true;
824 void ImageManagerImpl::reset()
825 throw (::com::sun::star::uno::RuntimeException
)
827 ResetableGuard
aLock( m_aLock
);
829 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
831 throw DisposedException();
833 std::vector
< OUString
> aUserImageNames
;
835 for ( sal_Int32 i
= 0; i
< ImageType_COUNT
; i
++ )
837 aUserImageNames
.clear();
838 ImageList
* pImageList
= implts_getUserImageList( ImageType(i
));
839 pImageList
->GetImageNames( aUserImageNames
);
841 Sequence
< rtl::OUString
> aRemoveList( aUserImageNames
.size() );
842 const sal_uInt32 nCount
= aUserImageNames
.size();
843 for ( sal_uInt32 j
= 0; j
< nCount
; j
++ )
844 aRemoveList
[j
] = aUserImageNames
[j
];
847 removeImages( sal_Int16( i
), aRemoveList
);
848 m_bUserImageListModified
[i
] = true;
851 m_bModified
= sal_True
;
854 Sequence
< ::rtl::OUString
> ImageManagerImpl::getAllImageNames( ::sal_Int16 nImageType
)
855 throw (::com::sun::star::uno::RuntimeException
)
857 ResetableGuard
aLock( m_aLock
);
859 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
861 throw DisposedException();
863 ImageNameMap aImageCmdNameMap
;
865 sal_Int16 nIndex
= implts_convertImageTypeToIndex( nImageType
);
870 rtl::Reference
< GlobalImageList
> rGlobalImageList
= implts_getGlobalImageList();
872 const std::vector
< OUString
>& rGlobalImageNameVector
= rGlobalImageList
->getImageCommandNames();
873 const sal_uInt32 nGlobalCount
= rGlobalImageNameVector
.size();
874 for ( i
= 0; i
< nGlobalCount
; i
++ )
875 aImageCmdNameMap
.insert( ImageNameMap::value_type( rGlobalImageNameVector
[i
], sal_True
));
877 const std::vector
< OUString
>& rModuleImageNameVector
= implts_getDefaultImageList()->getImageCommandNames();
878 const sal_uInt32 nModuleCount
= rModuleImageNameVector
.size();
879 for ( i
= 0; i
< nModuleCount
; i
++ )
880 aImageCmdNameMap
.insert( ImageNameMap::value_type( rModuleImageNameVector
[i
], sal_True
));
883 ImageList
* pImageList
= implts_getUserImageList( ImageType( nIndex
));
884 std::vector
< OUString
> rUserImageNames
;
885 pImageList
->GetImageNames( rUserImageNames
);
886 const sal_uInt32 nUserCount
= rUserImageNames
.size();
887 for ( i
= 0; i
< nUserCount
; i
++ )
888 aImageCmdNameMap
.insert( ImageNameMap::value_type( rUserImageNames
[i
], sal_True
));
890 Sequence
< OUString
> aImageNameSeq( aImageCmdNameMap
.size() );
891 ImageNameMap::const_iterator pIter
;
893 for ( pIter
= aImageCmdNameMap
.begin(); pIter
!= aImageCmdNameMap
.end(); pIter
++ )
894 aImageNameSeq
[i
++] = pIter
->first
;
896 return aImageNameSeq
;
899 ::sal_Bool
ImageManagerImpl::hasImage( ::sal_Int16 nImageType
, const ::rtl::OUString
& aCommandURL
)
900 throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
902 ResetableGuard
aLock( m_aLock
);
904 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
906 throw DisposedException();
908 if (( nImageType
< 0 ) || ( nImageType
> MAX_IMAGETYPE_VALUE
))
909 throw IllegalArgumentException();
911 sal_Int16 nIndex
= implts_convertImageTypeToIndex( nImageType
);
912 if ( m_bUseGlobal
&& implts_getGlobalImageList()->hasImage( nIndex
, aCommandURL
))
916 if ( m_bUseGlobal
&& implts_getDefaultImageList()->hasImage( nIndex
, aCommandURL
))
921 ImageList
* pImageList
= implts_getUserImageList( ImageType( nIndex
));
923 return ( pImageList
->GetImagePos( aCommandURL
) != IMAGELIST_IMAGE_NOTFOUND
);
930 Sequence
< uno::Reference
< XGraphic
> > ImageManagerImpl::getImages(
931 ::sal_Int16 nImageType
,
932 const Sequence
< ::rtl::OUString
>& aCommandURLSequence
)
933 throw ( ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
935 ResetableGuard
aLock( m_aLock
);
937 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
939 throw DisposedException();
941 if (( nImageType
< 0 ) || ( nImageType
> MAX_IMAGETYPE_VALUE
))
942 throw IllegalArgumentException();
944 Sequence
< uno::Reference
< XGraphic
> > aGraphSeq( aCommandURLSequence
.getLength() );
946 const rtl::OUString
* aStrArray
= aCommandURLSequence
.getConstArray();
948 sal_Int16 nIndex
= implts_convertImageTypeToIndex( nImageType
);
949 rtl::Reference
< GlobalImageList
> rGlobalImageList
;
950 CmdImageList
* pDefaultImageList
= NULL
;
953 rGlobalImageList
= implts_getGlobalImageList();
954 pDefaultImageList
= implts_getDefaultImageList();
956 ImageList
* pUserImageList
= implts_getUserImageList( ImageType( nIndex
));
958 // We have to search our image list in the following order:
959 // 1. user image list (read/write)
960 // 2. module image list (read)
961 // 3. global image list (read)
962 for ( sal_Int32 n
= 0; n
< aCommandURLSequence
.getLength(); n
++ )
964 Image aImage
= pUserImageList
->GetImage( aStrArray
[n
] );
965 if ( !aImage
&& m_bUseGlobal
)
967 aImage
= pDefaultImageList
->getImageFromCommandURL( nIndex
, aStrArray
[n
] );
969 aImage
= rGlobalImageList
->getImageFromCommandURL( nIndex
, aStrArray
[n
] );
972 aGraphSeq
[n
] = aImage
.GetXGraphic();
978 void ImageManagerImpl::replaceImages(
979 ::sal_Int16 nImageType
,
980 const Sequence
< ::rtl::OUString
>& aCommandURLSequence
,
981 const Sequence
< uno::Reference
< XGraphic
> >& aGraphicsSequence
)
982 throw ( ::com::sun::star::lang::IllegalArgumentException
,
983 ::com::sun::star::lang::IllegalAccessException
,
984 ::com::sun::star::uno::RuntimeException
)
986 CmdToXGraphicNameAccess
* pInsertedImages( 0 );
987 CmdToXGraphicNameAccess
* pReplacedImages( 0 );
990 ResetableGuard
aLock( m_aLock
);
992 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
994 throw DisposedException();
996 if (( aCommandURLSequence
.getLength() != aGraphicsSequence
.getLength() ) ||
997 (( nImageType
< 0 ) || ( nImageType
> MAX_IMAGETYPE_VALUE
)))
998 throw IllegalArgumentException();
1001 throw IllegalAccessException();
1003 sal_Int16 nIndex
= implts_convertImageTypeToIndex( nImageType
);
1004 ImageList
* pImageList
= implts_getUserImageList( ImageType( nIndex
));
1006 uno::Reference
< XGraphic
> xGraphic
;
1007 for ( sal_Int32 i
= 0; i
< aCommandURLSequence
.getLength(); i
++ )
1009 // Check size and scale. If we don't have any graphics ignore it
1010 if ( !implts_checkAndScaleGraphic( xGraphic
, aGraphicsSequence
[i
], nIndex
))
1013 USHORT nPos
= pImageList
->GetImagePos( aCommandURLSequence
[i
] );
1014 if ( nPos
== IMAGELIST_IMAGE_NOTFOUND
)
1016 pImageList
->AddImage( aCommandURLSequence
[i
], xGraphic
);
1017 if ( !pInsertedImages
)
1018 pInsertedImages
= new CmdToXGraphicNameAccess();
1019 pInsertedImages
->addElement( aCommandURLSequence
[i
], xGraphic
);
1023 pImageList
->ReplaceImage( aCommandURLSequence
[i
], xGraphic
);
1024 if ( !pReplacedImages
)
1025 pReplacedImages
= new CmdToXGraphicNameAccess();
1026 pReplacedImages
->addElement( aCommandURLSequence
[i
], xGraphic
);
1030 if (( pInsertedImages
!= 0 ) || ( pReplacedImages
!= 0 ))
1032 m_bModified
= sal_True
;
1033 m_bUserImageListModified
[nIndex
] = true;
1038 if ( pInsertedImages
!= 0 )
1040 ConfigurationEvent aInsertEvent
;
1041 aInsertEvent
.aInfo
<<= nImageType
;
1042 aInsertEvent
.Accessor
<<= m_xOwner
;
1043 aInsertEvent
.Source
= m_xOwner
;
1044 aInsertEvent
.ResourceURL
= m_aResourceString
;
1045 aInsertEvent
.Element
= uno::makeAny( uno::Reference
< XNameAccess
>(
1046 static_cast< OWeakObject
*>( pInsertedImages
), UNO_QUERY
));
1047 implts_notifyContainerListener( aInsertEvent
, NotifyOp_Insert
);
1049 if ( pReplacedImages
!= 0 )
1051 ConfigurationEvent aReplaceEvent
;
1052 aReplaceEvent
.aInfo
<<= nImageType
;
1053 aReplaceEvent
.Accessor
<<= m_xOwner
;
1054 aReplaceEvent
.Source
= m_xOwner
;
1055 aReplaceEvent
.ResourceURL
= m_aResourceString
;
1056 aReplaceEvent
.ReplacedElement
= Any();
1057 aReplaceEvent
.Element
= uno::makeAny( uno::Reference
< XNameAccess
>(
1058 static_cast< OWeakObject
*>( pReplacedImages
), UNO_QUERY
));
1059 implts_notifyContainerListener( aReplaceEvent
, NotifyOp_Replace
);
1063 void ImageManagerImpl::removeImages( ::sal_Int16 nImageType
, const Sequence
< ::rtl::OUString
>& aCommandURLSequence
)
1064 throw ( ::com::sun::star::lang::IllegalArgumentException
,
1065 ::com::sun::star::lang::IllegalAccessException
,
1066 ::com::sun::star::uno::RuntimeException
)
1068 CmdToXGraphicNameAccess
* pRemovedImages( 0 );
1069 CmdToXGraphicNameAccess
* pReplacedImages( 0 );
1072 ResetableGuard
aLock( m_aLock
);
1074 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1076 throw DisposedException();
1078 if (( nImageType
< 0 ) || ( nImageType
> MAX_IMAGETYPE_VALUE
))
1079 throw IllegalArgumentException();
1082 throw IllegalAccessException();
1084 sal_Int16 nIndex
= implts_convertImageTypeToIndex( nImageType
);
1085 rtl::Reference
< GlobalImageList
> rGlobalImageList
;
1086 CmdImageList
* pDefaultImageList
= NULL
;
1089 rGlobalImageList
= implts_getGlobalImageList();
1090 pDefaultImageList
= implts_getDefaultImageList();
1092 ImageList
* pImageList
= implts_getUserImageList( ImageType( nIndex
));
1093 uno::Reference
< XGraphic
> xEmptyGraphic( Image().GetXGraphic() );
1095 for ( sal_Int32 i
= 0; i
< aCommandURLSequence
.getLength(); i
++ )
1097 USHORT nPos
= pImageList
->GetImagePos( aCommandURLSequence
[i
] );
1098 if ( nPos
!= IMAGELIST_IMAGE_NOTFOUND
)
1100 Image aImage
= pImageList
->GetImage( nPos
);
1101 USHORT nId
= pImageList
->GetImageId( nPos
);
1102 pImageList
->RemoveImage( nId
);
1106 // Check, if we have a image in our module/global image list. If we find one =>
1107 // this is a replace instead of a remove operation!
1108 Image aNewImage
= pDefaultImageList
->getImageFromCommandURL( nIndex
, aCommandURLSequence
[i
] );
1110 aNewImage
= rGlobalImageList
->getImageFromCommandURL( nIndex
, aCommandURLSequence
[i
] );
1113 if ( !pRemovedImages
)
1114 pRemovedImages
= new CmdToXGraphicNameAccess();
1115 pRemovedImages
->addElement( aCommandURLSequence
[i
], xEmptyGraphic
);
1119 if ( !pReplacedImages
)
1120 pReplacedImages
= new CmdToXGraphicNameAccess();
1121 pReplacedImages
->addElement( aCommandURLSequence
[i
], aNewImage
.GetXGraphic() );
1123 } // if ( m_bUseGlobal )
1126 if ( !pRemovedImages
)
1127 pRemovedImages
= new CmdToXGraphicNameAccess();
1128 pRemovedImages
->addElement( aCommandURLSequence
[i
], xEmptyGraphic
);
1133 if (( pReplacedImages
!= 0 ) || ( pRemovedImages
!= 0 ))
1135 m_bModified
= sal_True
;
1136 m_bUserImageListModified
[nIndex
] = true;
1141 if ( pRemovedImages
!= 0 )
1143 ConfigurationEvent aRemoveEvent
;
1144 aRemoveEvent
.aInfo
= uno::makeAny( nImageType
);
1145 aRemoveEvent
.Accessor
= uno::makeAny( m_xOwner
);
1146 aRemoveEvent
.Source
= m_xOwner
;
1147 aRemoveEvent
.ResourceURL
= m_aResourceString
;
1148 aRemoveEvent
.Element
= uno::makeAny( uno::Reference
< XNameAccess
>(
1149 static_cast< OWeakObject
*>( pRemovedImages
), UNO_QUERY
));
1150 implts_notifyContainerListener( aRemoveEvent
, NotifyOp_Remove
);
1152 if ( pReplacedImages
!= 0 )
1154 ConfigurationEvent aReplaceEvent
;
1155 aReplaceEvent
.aInfo
= uno::makeAny( nImageType
);
1156 aReplaceEvent
.Accessor
= uno::makeAny( m_xOwner
);
1157 aReplaceEvent
.Source
= m_xOwner
;
1158 aReplaceEvent
.ResourceURL
= m_aResourceString
;
1159 aReplaceEvent
.ReplacedElement
= Any();
1160 aReplaceEvent
.Element
= uno::makeAny( uno::Reference
< XNameAccess
>(
1161 static_cast< OWeakObject
*>( pReplacedImages
), UNO_QUERY
));
1162 implts_notifyContainerListener( aReplaceEvent
, NotifyOp_Replace
);
1166 void ImageManagerImpl::insertImages( ::sal_Int16 nImageType
, const Sequence
< ::rtl::OUString
>& aCommandURLSequence
, const Sequence
< uno::Reference
< XGraphic
> >& aGraphicSequence
)
1167 throw ( ::com::sun::star::container::ElementExistException
,
1168 ::com::sun::star::lang::IllegalArgumentException
,
1169 ::com::sun::star::lang::IllegalAccessException
,
1170 ::com::sun::star::uno::RuntimeException
)
1172 replaceImages(nImageType
,aCommandURLSequence
,aGraphicSequence
);
1176 // XUIConfigurationPersistence
1177 void ImageManagerImpl::reload()
1178 throw ( ::com::sun::star::uno::Exception
,
1179 ::com::sun::star::uno::RuntimeException
)
1181 ResetableGuard
aGuard( m_aLock
);
1184 throw DisposedException();
1186 CommandMap aOldUserCmdImageSet
;
1187 std::vector
< rtl::OUString
> aNewUserCmdImageSet
;
1191 for ( sal_Int16 i
= 0; i
< sal_Int16( ImageType_COUNT
); i
++ )
1193 if ( !m_bDisposed
&& m_bUserImageListModified
[i
] )
1195 std::vector
< rtl::OUString
> aOldUserCmdImageVector
;
1196 ImageList
* pImageList
= implts_getUserImageList( (ImageType
)i
);
1197 pImageList
->GetImageNames( aOldUserCmdImageVector
);
1199 // Fill hash map to speed up search afterwards
1201 const sal_uInt32 nOldCount
= aOldUserCmdImageVector
.size();
1202 for ( j
= 0; j
< nOldCount
; j
++ )
1203 aOldUserCmdImageSet
.insert( CommandMap::value_type( aOldUserCmdImageVector
[j
], false ));
1205 // Attention: This can make the old image list pointer invalid!
1206 implts_loadUserImages( (ImageType
)i
, m_xUserImageStorage
, m_xUserBitmapsStorage
);
1207 pImageList
= implts_getUserImageList( (ImageType
)i
);
1208 pImageList
->GetImageNames( aNewUserCmdImageSet
);
1210 CmdToXGraphicNameAccess
* pInsertedImages( 0 );
1211 CmdToXGraphicNameAccess
* pReplacedImages( 0 );
1212 CmdToXGraphicNameAccess
* pRemovedImages( 0 );
1214 const sal_uInt32 nNewCount
= aNewUserCmdImageSet
.size();
1215 for ( j
= 0; j
< nNewCount
; j
++ )
1217 CommandMap::iterator pIter
= aOldUserCmdImageSet
.find( aNewUserCmdImageSet
[j
] );
1218 if ( pIter
!= aOldUserCmdImageSet
.end() )
1220 pIter
->second
= true; // mark entry as replaced
1221 if ( !pReplacedImages
)
1222 pReplacedImages
= new CmdToXGraphicNameAccess();
1223 pReplacedImages
->addElement( aNewUserCmdImageSet
[j
],
1224 pImageList
->GetImage( aNewUserCmdImageSet
[j
] ).GetXGraphic() );
1228 if ( !pInsertedImages
)
1229 pInsertedImages
= new CmdToXGraphicNameAccess();
1230 pInsertedImages
->addElement( aNewUserCmdImageSet
[j
],
1231 pImageList
->GetImage( aNewUserCmdImageSet
[j
] ).GetXGraphic() );
1235 // Search map for unmarked entries => they have been removed from the user list
1236 // through this reload operation.
1237 // We have to search the module and global image list!
1238 rtl::Reference
< GlobalImageList
> rGlobalImageList
;
1239 CmdImageList
* pDefaultImageList
= NULL
;
1242 rGlobalImageList
= implts_getGlobalImageList();
1243 pDefaultImageList
= implts_getDefaultImageList();
1245 uno::Reference
< XGraphic
> xEmptyGraphic( Image().GetXGraphic() );
1246 CommandMap::const_iterator pIter
= aOldUserCmdImageSet
.begin();
1247 while ( pIter
!= aOldUserCmdImageSet
.end() )
1249 if ( !pIter
->second
)
1253 Image aImage
= pDefaultImageList
->getImageFromCommandURL( i
, pIter
->first
);
1255 aImage
= rGlobalImageList
->getImageFromCommandURL( i
, pIter
->first
);
1259 // No image in the module/global image list => remove user image
1260 if ( !pRemovedImages
)
1261 pRemovedImages
= new CmdToXGraphicNameAccess();
1262 pRemovedImages
->addElement( pIter
->first
, xEmptyGraphic
);
1266 // Image has been found in the module/global image list => replace user image
1267 if ( !pReplacedImages
)
1268 pReplacedImages
= new CmdToXGraphicNameAccess();
1269 pReplacedImages
->addElement( pIter
->first
, aImage
.GetXGraphic() );
1271 } // if ( m_bUseGlobal )
1274 // No image in the user image list => remove user image
1275 if ( !pRemovedImages
)
1276 pRemovedImages
= new CmdToXGraphicNameAccess();
1277 pRemovedImages
->addElement( pIter
->first
, xEmptyGraphic
);
1285 // Now notify our listeners. Unlock mutex to prevent deadlocks
1286 if ( pInsertedImages
!= 0 )
1288 ConfigurationEvent aInsertEvent
;
1289 aInsertEvent
.aInfo
= uno::makeAny( i
);
1290 aInsertEvent
.Accessor
= uno::makeAny( m_xOwner
);
1291 aInsertEvent
.Source
= m_xOwner
;
1292 aInsertEvent
.ResourceURL
= m_aResourceString
;
1293 aInsertEvent
.Element
= uno::makeAny( uno::Reference
< XNameAccess
>(
1294 static_cast< OWeakObject
*>( pInsertedImages
), UNO_QUERY
));
1295 implts_notifyContainerListener( aInsertEvent
, NotifyOp_Insert
);
1297 if ( pReplacedImages
!= 0 )
1299 ConfigurationEvent aReplaceEvent
;
1300 aReplaceEvent
.aInfo
= uno::makeAny( i
);
1301 aReplaceEvent
.Accessor
= uno::makeAny( m_xOwner
);
1302 aReplaceEvent
.Source
= m_xOwner
;
1303 aReplaceEvent
.ResourceURL
= m_aResourceString
;
1304 aReplaceEvent
.ReplacedElement
= Any();
1305 aReplaceEvent
.Element
= uno::makeAny( uno::Reference
< XNameAccess
>(
1306 static_cast< OWeakObject
*>( pReplacedImages
), UNO_QUERY
));
1307 implts_notifyContainerListener( aReplaceEvent
, NotifyOp_Replace
);
1309 if ( pRemovedImages
!= 0 )
1311 ConfigurationEvent aRemoveEvent
;
1312 aRemoveEvent
.aInfo
= uno::makeAny( i
);
1313 aRemoveEvent
.Accessor
= uno::makeAny( m_xOwner
);
1314 aRemoveEvent
.Source
= m_xOwner
;
1315 aRemoveEvent
.ResourceURL
= m_aResourceString
;
1316 aRemoveEvent
.Element
= uno::makeAny( uno::Reference
< XNameAccess
>(
1317 static_cast< OWeakObject
*>( pRemovedImages
), UNO_QUERY
));
1318 implts_notifyContainerListener( aRemoveEvent
, NotifyOp_Remove
);
1327 void ImageManagerImpl::store()
1328 throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
)
1330 ResetableGuard
aGuard( m_aLock
);
1333 throw DisposedException();
1337 sal_Bool
bWritten( sal_False
);
1338 for ( sal_Int32 i
= 0; i
< ImageType_COUNT
; i
++ )
1340 sal_Bool bSuccess
= implts_storeUserImages( ImageType(i
), m_xUserImageStorage
, m_xUserBitmapsStorage
);
1342 bWritten
= sal_True
;
1343 m_bUserImageListModified
[i
] = false;
1347 m_xUserConfigStorage
.is() )
1349 uno::Reference
< XTransactedObject
> xUserConfigStorageCommit( m_xUserConfigStorage
, UNO_QUERY
);
1350 if ( xUserConfigStorageCommit
.is() )
1351 xUserConfigStorageCommit
->commit();
1352 if ( m_xUserRootCommit
.is() )
1353 m_xUserRootCommit
->commit();
1356 m_bModified
= sal_False
;
1360 void ImageManagerImpl::storeToStorage( const uno::Reference
< XStorage
>& Storage
)
1361 throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
)
1363 ResetableGuard
aGuard( m_aLock
);
1366 throw DisposedException();
1368 if ( m_bModified
&& Storage
.is() )
1370 long nModes
= ElementModes::READWRITE
;
1372 uno::Reference
< XStorage
> xUserImageStorage
= Storage
->openStorageElement( OUString::createFromAscii( IMAGE_FOLDER
),
1374 if ( xUserImageStorage
.is() )
1376 uno::Reference
< XStorage
> xUserBitmapsStorage
= xUserImageStorage
->openStorageElement( OUString::createFromAscii( BITMAPS_FOLDER
),
1378 for ( sal_Int32 i
= 0; i
< ImageType_COUNT
; i
++ )
1380 implts_getUserImageList( (ImageType
)i
);
1381 implts_storeUserImages( (ImageType
)i
, xUserImageStorage
, xUserBitmapsStorage
);
1384 uno::Reference
< XTransactedObject
> xTransaction( Storage
, UNO_QUERY
);
1385 if ( xTransaction
.is() )
1386 xTransaction
->commit();
1391 sal_Bool
ImageManagerImpl::isModified()
1392 throw (::com::sun::star::uno::RuntimeException
)
1394 ResetableGuard
aGuard( m_aLock
);
1398 sal_Bool
ImageManagerImpl::isReadOnly() throw (::com::sun::star::uno::RuntimeException
)
1400 ResetableGuard
aGuard( m_aLock
);
1404 void ImageManagerImpl::addConfigurationListener( const uno::Reference
< ::com::sun::star::ui::XUIConfigurationListener
>& xListener
)
1405 throw (::com::sun::star::uno::RuntimeException
)
1408 ResetableGuard
aGuard( m_aLock
);
1410 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1412 throw DisposedException();
1415 m_aListenerContainer
.addInterface( ::getCppuType( ( const uno::Reference
< XUIConfigurationListener
>* ) NULL
), xListener
);
1418 void ImageManagerImpl::removeConfigurationListener( const uno::Reference
< ::com::sun::star::ui::XUIConfigurationListener
>& xListener
)
1419 throw (::com::sun::star::uno::RuntimeException
)
1421 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1422 m_aListenerContainer
.removeInterface( ::getCppuType( ( const uno::Reference
< XUIConfigurationListener
>* ) NULL
), xListener
);
1426 void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent
& aEvent
, NotifyOp eOp
)
1428 ::cppu::OInterfaceContainerHelper
* pContainer
= m_aListenerContainer
.getContainer(
1429 ::getCppuType( ( const css::uno::Reference
< ::com::sun::star::ui::XUIConfigurationListener
>*) NULL
) );
1430 if ( pContainer
!= NULL
)
1432 ::cppu::OInterfaceIteratorHelper
pIterator( *pContainer
);
1433 while ( pIterator
.hasMoreElements() )
1439 case NotifyOp_Replace
:
1440 ((::com::sun::star::ui::XUIConfigurationListener
*)pIterator
.next())->elementReplaced( aEvent
);
1442 case NotifyOp_Insert
:
1443 ((::com::sun::star::ui::XUIConfigurationListener
*)pIterator
.next())->elementInserted( aEvent
);
1445 case NotifyOp_Remove
:
1446 ((::com::sun::star::ui::XUIConfigurationListener
*)pIterator
.next())->elementRemoved( aEvent
);
1450 catch( css::uno::RuntimeException
& )
1457 void ImageManagerImpl::clear()
1459 ResetableGuard
aGuard( m_aLock
);
1460 for ( sal_Int32 n
= 0; n
< ImageType_COUNT
; n
++ )
1462 delete m_pUserImageList
[n
];
1463 m_pUserImageList
[n
] = 0;
1466 } // namespace framework