1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <imagemanagerimpl.hxx>
28cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
29cdf0e10cSrcweir #include <xml/imagesconfiguration.hxx>
30cdf0e10cSrcweir #include <uiconfiguration/graphicnameaccess.hxx>
31cdf0e10cSrcweir #include <services.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "properties.h"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36cdf0e10cSrcweir //	interface includes
37cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
39cdf0e10cSrcweir #include <com/sun/star/ui/ConfigurationEvent.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
41cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
42cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
43cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
44cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
45cdf0e10cSrcweir #include <com/sun/star/ui/ImageType.hpp>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //_________________________________________________________________________________________________________________
48cdf0e10cSrcweir //	other includes
49cdf0e10cSrcweir //_________________________________________________________________________________________________________________
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <vcl/svapp.hxx>
52cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
53cdf0e10cSrcweir #include <osl/mutex.hxx>
54cdf0e10cSrcweir #include <comphelper/sequence.hxx>
55cdf0e10cSrcweir #include <tools/urlobj.hxx>
56cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
57cdf0e10cSrcweir #include <vcl/pngread.hxx>
58cdf0e10cSrcweir #include <vcl/pngwrite.hxx>
59cdf0e10cSrcweir #include <rtl/logfile.hxx>
60cdf0e10cSrcweir #include "svtools/miscopt.hxx"
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //_________________________________________________________________________________________________________________
63cdf0e10cSrcweir //	namespaces
64cdf0e10cSrcweir //_________________________________________________________________________________________________________________
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using ::rtl::OUString;
67cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
68cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
69cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
70cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
71cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
72cdf0e10cSrcweir using ::com::sun::star::uno::Any;
73cdf0e10cSrcweir using ::com::sun::star::uno::makeAny;
74cdf0e10cSrcweir using ::com::sun::star::graphic::XGraphic;
75cdf0e10cSrcweir using namespace ::com::sun::star;
76cdf0e10cSrcweir using namespace ::com::sun::star::io;
77cdf0e10cSrcweir using namespace ::com::sun::star::embed;
78cdf0e10cSrcweir using namespace ::com::sun::star::lang;
79cdf0e10cSrcweir using namespace ::com::sun::star::container;
80cdf0e10cSrcweir using namespace ::com::sun::star::beans;
81cdf0e10cSrcweir using namespace ::com::sun::star::ui;
82cdf0e10cSrcweir using namespace ::cppu;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // Image sizes for our toolbars/menus
85cdf0e10cSrcweir const sal_Int32 IMAGE_SIZE_NORMAL         = 16;
86cdf0e10cSrcweir const sal_Int32 IMAGE_SIZE_LARGE          = 26;
87cdf0e10cSrcweir const sal_Int16 MAX_IMAGETYPE_VALUE       = ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST|
88cdf0e10cSrcweir                                             ::com::sun::star::ui::ImageType::SIZE_LARGE;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir static const char   IMAGE_FOLDER[]        = "images";
91cdf0e10cSrcweir static const char   BITMAPS_FOLDER[]      = "Bitmaps";
92cdf0e10cSrcweir static const char   IMAGE_EXTENSION[]     = ".png";
93cdf0e10cSrcweir 
94cdf0e10cSrcweir static const char*  IMAGELIST_XML_FILE[]  =
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     "sc_imagelist.xml",
97cdf0e10cSrcweir     "lc_imagelist.xml",
98cdf0e10cSrcweir     "sch_imagelist.xml",
99cdf0e10cSrcweir     "lch_imagelist.xml"
100cdf0e10cSrcweir };
101cdf0e10cSrcweir 
102cdf0e10cSrcweir static const char*  BITMAP_FILE_NAMES[]   =
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     "sc_userimages.png",
105cdf0e10cSrcweir     "lc_userimages.png",
106cdf0e10cSrcweir     "sch_userimages.png",
107cdf0e10cSrcweir     "lch_userimages.png"
108cdf0e10cSrcweir };
109cdf0e10cSrcweir 
110cdf0e10cSrcweir namespace framework
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     static char ModuleImageList[] = "private:resource/images/moduleimages";
113cdf0e10cSrcweir     static osl::Mutex*          pImageListWrapperMutex = 0;
114cdf0e10cSrcweir     static GlobalImageList*     pGlobalImageList = 0;
115cdf0e10cSrcweir     static const char* ImageType_Prefixes[ImageType_COUNT] =
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         "res/commandimagelist/sc_",
118cdf0e10cSrcweir         "res/commandimagelist/lc_",
119cdf0e10cSrcweir         "res/commandimagelist/sch_",
120cdf0e10cSrcweir         "res/commandimagelist/lch_"
121cdf0e10cSrcweir     };
122cdf0e10cSrcweir 
123cdf0e10cSrcweir typedef GraphicNameAccess CmdToXGraphicNameAccess;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir static osl::Mutex& getGlobalImageListMutex()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     if ( pImageListWrapperMutex == 0 )
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
130cdf0e10cSrcweir         if ( pImageListWrapperMutex == 0 )
131cdf0e10cSrcweir             pImageListWrapperMutex = new osl::Mutex;
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     return *pImageListWrapperMutex;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir static GlobalImageList* getGlobalImageList( const uno::Reference< XMultiServiceFactory >& rServiceManager )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     osl::MutexGuard guard( getGlobalImageListMutex() );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     if ( pGlobalImageList == 0 )
142cdf0e10cSrcweir         pGlobalImageList = new GlobalImageList( rServiceManager );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     return pGlobalImageList;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir static rtl::OUString getCanonicalName( const rtl::OUString& rFileName )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     bool               bRemoveSlash( true );
150cdf0e10cSrcweir     sal_Int32          nLength = rFileName.getLength();
151cdf0e10cSrcweir     const sal_Unicode* pString = rFileName.getStr();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     rtl::OUStringBuffer aBuf( nLength );
154cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < nLength; i++ )
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         const sal_Unicode c = pString[i];
157cdf0e10cSrcweir         switch ( c )
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             // map forbidden characters to escape
160cdf0e10cSrcweir             case '/' : if ( !bRemoveSlash )
161cdf0e10cSrcweir                          aBuf.appendAscii( "%2f" );
162cdf0e10cSrcweir                        break;
163cdf0e10cSrcweir             case '\\': aBuf.appendAscii( "%5c" ); bRemoveSlash = false; break;
164cdf0e10cSrcweir             case ':' : aBuf.appendAscii( "%3a" ); bRemoveSlash = false; break;
165cdf0e10cSrcweir             case '*' : aBuf.appendAscii( "%2a" ); bRemoveSlash = false; break;
166cdf0e10cSrcweir             case '?' : aBuf.appendAscii( "%3f" ); bRemoveSlash = false; break;
167cdf0e10cSrcweir             case '<' : aBuf.appendAscii( "%3c" ); bRemoveSlash = false; break;
168cdf0e10cSrcweir             case '>' : aBuf.appendAscii( "%3e" ); bRemoveSlash = false; break;
169cdf0e10cSrcweir             case '|' : aBuf.appendAscii( "%7c" ); bRemoveSlash = false; break;
170cdf0e10cSrcweir             default: aBuf.append( c ); bRemoveSlash = false;
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir     return aBuf.makeStringAndClear();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //_________________________________________________________________________________________________________________
177cdf0e10cSrcweir 
178cdf0e10cSrcweir CmdImageList::CmdImageList( const uno::Reference< XMultiServiceFactory >& rServiceManager, const rtl::OUString& aModuleIdentifier ) :
179cdf0e10cSrcweir     m_bVectorInit( sal_False ),
180cdf0e10cSrcweir     m_aModuleIdentifier( aModuleIdentifier ),
181cdf0e10cSrcweir     m_xServiceManager( rServiceManager ),
182cdf0e10cSrcweir     m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
185cdf0e10cSrcweir         m_pImageList[n] = 0;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir CmdImageList::~CmdImageList()
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
191cdf0e10cSrcweir         delete m_pImageList[n];
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir void CmdImageList::impl_fillCommandToImageNameMap()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "framework: CmdImageList::impl_fillCommandToImageNameMap" );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     if ( !m_bVectorInit )
199cdf0e10cSrcweir     {
200cdf0e10cSrcweir         const rtl::OUString aCommandImageList( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST ));
201cdf0e10cSrcweir         Sequence< OUString > aCmdImageSeq;
202cdf0e10cSrcweir         uno::Reference< XNameAccess > xCmdDesc( m_xServiceManager->createInstance(
203cdf0e10cSrcweir                                                 SERVICENAME_UICOMMANDDESCRIPTION ),
204cdf0e10cSrcweir                                             UNO_QUERY );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         if ( m_aModuleIdentifier.getLength() > 0 )
207cdf0e10cSrcweir         {
208cdf0e10cSrcweir             // If we have a module identifier - use to retrieve the command image name list from it.
209cdf0e10cSrcweir             // Otherwise we will use the global command image list
210cdf0e10cSrcweir             try
211cdf0e10cSrcweir             {
212cdf0e10cSrcweir                 xCmdDesc->getByName( m_aModuleIdentifier ) >>= xCmdDesc;
213cdf0e10cSrcweir                 if ( xCmdDesc.is() )
214cdf0e10cSrcweir                     xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
215cdf0e10cSrcweir             }
216cdf0e10cSrcweir             catch ( NoSuchElementException& )
217cdf0e10cSrcweir             {
218cdf0e10cSrcweir                 // Module unknown we will work with an empty command image list!
219cdf0e10cSrcweir                 return;
220cdf0e10cSrcweir             }
221cdf0e10cSrcweir         }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         if ( xCmdDesc.is() )
224cdf0e10cSrcweir         {
225cdf0e10cSrcweir             try
226cdf0e10cSrcweir             {
227cdf0e10cSrcweir                 xCmdDesc->getByName( aCommandImageList ) >>= aCmdImageSeq;
228cdf0e10cSrcweir             }
229cdf0e10cSrcweir             catch ( NoSuchElementException& )
230cdf0e10cSrcweir             {
231cdf0e10cSrcweir             }
232cdf0e10cSrcweir             catch ( WrappedTargetException& )
233cdf0e10cSrcweir             {
234cdf0e10cSrcweir             }
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         // We have to map commands which uses special characters like '/',':','?','\','<'.'>','|'
238cdf0e10cSrcweir         String aExt = String::CreateFromAscii( IMAGE_EXTENSION );
239cdf0e10cSrcweir         m_aImageCommandNameVector.resize(aCmdImageSeq.getLength() );
240cdf0e10cSrcweir         m_aImageNameVector.resize( aCmdImageSeq.getLength() );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         ::std::copy( aCmdImageSeq.getConstArray(),
243cdf0e10cSrcweir                      aCmdImageSeq.getConstArray()+aCmdImageSeq.getLength(),
244cdf0e10cSrcweir                      m_aImageCommandNameVector.begin() );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         // Create a image name vector that must be provided to the vcl imagelist. We also need
247cdf0e10cSrcweir         // a command to image name map to speed up access time for image retrieval.
248cdf0e10cSrcweir         OUString aUNOString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
249cdf0e10cSrcweir         String   aEmptyString;
250cdf0e10cSrcweir         const sal_uInt32 nCount = m_aImageCommandNameVector.size();
251cdf0e10cSrcweir 		for ( sal_uInt32 i = 0; i < nCount; i++ )
252cdf0e10cSrcweir         {
253cdf0e10cSrcweir             OUString aCommandName( m_aImageCommandNameVector[i] );
254cdf0e10cSrcweir             String   aImageName;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir             if ( aCommandName.indexOf( aUNOString ) != 0 )
257cdf0e10cSrcweir             {
258cdf0e10cSrcweir                 INetURLObject aUrlObject( aCommandName, INetURLObject::ENCODE_ALL );
259cdf0e10cSrcweir                 aImageName = aUrlObject.GetURLPath();
260cdf0e10cSrcweir                 aImageName = getCanonicalName( aImageName ); // convert to valid filename
261cdf0e10cSrcweir             }
262cdf0e10cSrcweir             else
263cdf0e10cSrcweir             {
264cdf0e10cSrcweir                 // just remove the schema
265cdf0e10cSrcweir                 if ( aCommandName.getLength() > 5 )
266cdf0e10cSrcweir                     aImageName = aCommandName.copy( 5 );
267cdf0e10cSrcweir                 else
268cdf0e10cSrcweir                     aImageName = aEmptyString;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir                 // Search for query part.
271cdf0e10cSrcweir                 sal_Int32 nIndex = aImageName.Search( '?' );
272cdf0e10cSrcweir                 if ( nIndex != STRING_NOTFOUND )
273cdf0e10cSrcweir                     aImageName = getCanonicalName( aImageName ); // convert to valid filename
274cdf0e10cSrcweir             }
275cdf0e10cSrcweir             // Image names are not case-dependent. Always use lower case characters to
276cdf0e10cSrcweir             // reflect this.
277cdf0e10cSrcweir             aImageName += aExt;
278cdf0e10cSrcweir             aImageName.ToLowerAscii();
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             m_aImageNameVector[i] = aImageName;
281cdf0e10cSrcweir             m_aCommandToImageNameMap.insert( CommandToImageNameMap::value_type( aCommandName, aImageName ));
282cdf0e10cSrcweir         }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir         m_bVectorInit = sal_True;
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir ImageList* CmdImageList::impl_getImageList( sal_Int16 nImageType )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir     SvtMiscOptions aMiscOptions;
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     sal_Int16 nSymbolsStyle = aMiscOptions.GetCurrentSymbolsStyle();
293cdf0e10cSrcweir     if ( nSymbolsStyle != m_nSymbolsStyle )
294cdf0e10cSrcweir     {
295cdf0e10cSrcweir         m_nSymbolsStyle = nSymbolsStyle;
296cdf0e10cSrcweir         for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
297cdf0e10cSrcweir             delete m_pImageList[n], m_pImageList[n] = NULL;
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     if ( !m_pImageList[nImageType] )
301cdf0e10cSrcweir     {
302cdf0e10cSrcweir         m_pImageList[nImageType] = new ImageList( m_aImageNameVector,
303cdf0e10cSrcweir                                                   OUString::createFromAscii( ImageType_Prefixes[nImageType] ) );
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     return m_pImageList[nImageType];
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir std::vector< ::rtl::OUString >& CmdImageList::impl_getImageNameVector()
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     return m_aImageNameVector;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir std::vector< rtl::OUString >& CmdImageList::impl_getImageCommandNameVector()
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     return m_aImageCommandNameVector;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir Image CmdImageList::getImageFromCommandURL( sal_Int16 nImageType, const rtl::OUString& rCommandURL )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     impl_fillCommandToImageNameMap();
322cdf0e10cSrcweir     CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
323cdf0e10cSrcweir     if ( pIter != m_aCommandToImageNameMap.end() )
324cdf0e10cSrcweir     {
325cdf0e10cSrcweir         ImageList* pImageList = impl_getImageList( nImageType );
326cdf0e10cSrcweir         return pImageList->GetImage( pIter->second );
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     return Image();
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir bool CmdImageList::hasImage( sal_Int16 /*nImageType*/, const rtl::OUString& rCommandURL )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir     impl_fillCommandToImageNameMap();
335cdf0e10cSrcweir     CommandToImageNameMap::const_iterator pIter = m_aCommandToImageNameMap.find( rCommandURL );
336cdf0e10cSrcweir     if ( pIter != m_aCommandToImageNameMap.end() )
337cdf0e10cSrcweir         return true;
338cdf0e10cSrcweir     else
339cdf0e10cSrcweir         return false;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir ::std::vector< rtl::OUString >& CmdImageList::getImageNames()
343cdf0e10cSrcweir {
344cdf0e10cSrcweir     return impl_getImageNameVector();
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir ::std::vector< rtl::OUString >& CmdImageList::getImageCommandNames()
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     return impl_getImageCommandNameVector();
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir //_________________________________________________________________________________________________________________
353cdf0e10cSrcweir 
354cdf0e10cSrcweir GlobalImageList::GlobalImageList( const uno::Reference< XMultiServiceFactory >& rServiceManager ) :
355cdf0e10cSrcweir     CmdImageList( rServiceManager, rtl::OUString() ),
356cdf0e10cSrcweir     m_nRefCount( 0 )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir GlobalImageList::~GlobalImageList()
361cdf0e10cSrcweir {
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir Image GlobalImageList::getImageFromCommandURL( sal_Int16 nImageType, const rtl::OUString& rCommandURL )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     osl::MutexGuard guard( getGlobalImageListMutex() );
367cdf0e10cSrcweir     return CmdImageList::getImageFromCommandURL( nImageType, rCommandURL );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir bool GlobalImageList::hasImage( sal_Int16 nImageType, const rtl::OUString& rCommandURL )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     osl::MutexGuard guard( getGlobalImageListMutex() );
373cdf0e10cSrcweir     return CmdImageList::hasImage( nImageType, rCommandURL );
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir ::std::vector< rtl::OUString >& GlobalImageList::getImageNames()
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     osl::MutexGuard guard( getGlobalImageListMutex() );
379cdf0e10cSrcweir     return impl_getImageNameVector();
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir ::std::vector< rtl::OUString >& GlobalImageList::getImageCommandNames()
383cdf0e10cSrcweir {
384cdf0e10cSrcweir     osl::MutexGuard guard( getGlobalImageListMutex() );
385cdf0e10cSrcweir     return impl_getImageCommandNameVector();
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir oslInterlockedCount GlobalImageList::acquire()
389cdf0e10cSrcweir {
390cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_nRefCount );
391cdf0e10cSrcweir     return m_nRefCount;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir oslInterlockedCount GlobalImageList::release()
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     osl::MutexGuard guard( getGlobalImageListMutex() );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     if ( !osl_decrementInterlockedCount( &m_nRefCount ))
399cdf0e10cSrcweir     {
400cdf0e10cSrcweir         oslInterlockedCount nCount( m_nRefCount );
401cdf0e10cSrcweir         // remove global pointer as we destroy the object now
402cdf0e10cSrcweir         pGlobalImageList = 0;
403cdf0e10cSrcweir 		delete this;
404cdf0e10cSrcweir         return nCount;
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     return m_nRefCount;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir static sal_Bool implts_checkAndScaleGraphic( uno::Reference< XGraphic >& rOutGraphic, const uno::Reference< XGraphic >& rInGraphic, sal_Int16 nImageType )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir     static Size   aNormSize( IMAGE_SIZE_NORMAL, IMAGE_SIZE_NORMAL );
413cdf0e10cSrcweir     static Size   aLargeSize( IMAGE_SIZE_LARGE, IMAGE_SIZE_LARGE );
414cdf0e10cSrcweir 
415cdf0e10cSrcweir     if ( !rInGraphic.is() )
416cdf0e10cSrcweir     {
417cdf0e10cSrcweir         rOutGraphic = Image().GetXGraphic();
418cdf0e10cSrcweir         return sal_False;
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     // Check size and scale it
422cdf0e10cSrcweir     Image  aImage( rInGraphic );
423cdf0e10cSrcweir     Size   aSize = aImage.GetSizePixel();
424cdf0e10cSrcweir     bool   bMustScale( false );
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     if (( nImageType == ImageType_Color_Large ) ||
427cdf0e10cSrcweir         ( nImageType == ImageType_HC_Large ))
428cdf0e10cSrcweir         bMustScale = ( aSize != aLargeSize );
429cdf0e10cSrcweir     else
430cdf0e10cSrcweir         bMustScale = ( aSize != aNormSize );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     if ( bMustScale )
433cdf0e10cSrcweir     {
434cdf0e10cSrcweir         BitmapEx aBitmap = aImage.GetBitmapEx();
435cdf0e10cSrcweir         aBitmap.Scale( aNormSize );
436cdf0e10cSrcweir         aImage = Image( aBitmap );
437cdf0e10cSrcweir         rOutGraphic = aImage.GetXGraphic();
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir     else
440cdf0e10cSrcweir         rOutGraphic = rInGraphic;
441cdf0e10cSrcweir     return sal_True;
442cdf0e10cSrcweir }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir static sal_Int16 implts_convertImageTypeToIndex( sal_Int16 nImageType )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir     sal_Int16 nIndex( 0 );
447cdf0e10cSrcweir     if ( nImageType & ::com::sun::star::ui::ImageType::SIZE_LARGE )
448cdf0e10cSrcweir         nIndex += 1;
449cdf0e10cSrcweir     if ( nImageType & ::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST )
450cdf0e10cSrcweir         nIndex += 2;
451cdf0e10cSrcweir     return nIndex;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir ImageList* ImageManagerImpl::implts_getUserImageList( ImageType nImageType )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
457cdf0e10cSrcweir     if ( !m_pUserImageList[nImageType] )
458cdf0e10cSrcweir         implts_loadUserImages( nImageType, m_xUserImageStorage, m_xUserBitmapsStorage );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     return m_pUserImageList[nImageType];
461cdf0e10cSrcweir }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir void ImageManagerImpl::implts_initialize()
464cdf0e10cSrcweir {
465cdf0e10cSrcweir     // Initialize the top-level structures with the storage data
466cdf0e10cSrcweir     if ( m_xUserConfigStorage.is() )
467cdf0e10cSrcweir     {
468cdf0e10cSrcweir         long nModes = m_bReadOnly ? ElementModes::READ : ElementModes::READWRITE;
469cdf0e10cSrcweir 
470cdf0e10cSrcweir         try
471cdf0e10cSrcweir         {
472cdf0e10cSrcweir             m_xUserImageStorage = m_xUserConfigStorage->openStorageElement( OUString::createFromAscii( IMAGE_FOLDER ),
473cdf0e10cSrcweir                                                                             nModes );
474cdf0e10cSrcweir             if ( m_xUserImageStorage.is() )
475cdf0e10cSrcweir             {
476cdf0e10cSrcweir                 m_xUserBitmapsStorage = m_xUserImageStorage->openStorageElement( OUString::createFromAscii( BITMAPS_FOLDER ),
477cdf0e10cSrcweir                                                                                  nModes );
478cdf0e10cSrcweir             }
479cdf0e10cSrcweir         }
480cdf0e10cSrcweir         catch ( com::sun::star::container::NoSuchElementException& )
481cdf0e10cSrcweir         {
482cdf0e10cSrcweir         }
483cdf0e10cSrcweir         catch ( ::com::sun::star::embed::InvalidStorageException& )
484cdf0e10cSrcweir         {
485cdf0e10cSrcweir         }
486cdf0e10cSrcweir         catch ( ::com::sun::star::lang::IllegalArgumentException& )
487cdf0e10cSrcweir         {
488cdf0e10cSrcweir         }
489cdf0e10cSrcweir         catch ( ::com::sun::star::io::IOException& )
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir         catch ( ::com::sun::star::embed::StorageWrappedTargetException& )
493cdf0e10cSrcweir         {
494cdf0e10cSrcweir         }
495cdf0e10cSrcweir     }
496cdf0e10cSrcweir }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir sal_Bool ImageManagerImpl::implts_loadUserImages(
499cdf0e10cSrcweir     ImageType nImageType,
500cdf0e10cSrcweir     const uno::Reference< XStorage >& xUserImageStorage,
501cdf0e10cSrcweir     const uno::Reference< XStorage >& xUserBitmapsStorage )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     if ( xUserImageStorage.is() && xUserBitmapsStorage.is() )
506cdf0e10cSrcweir     {
507cdf0e10cSrcweir         try
508cdf0e10cSrcweir         {
509cdf0e10cSrcweir             uno::Reference< XStream > xStream = xUserImageStorage->openStreamElement( rtl::OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ),
510cdf0e10cSrcweir                                                                                       ElementModes::READ );
511cdf0e10cSrcweir             uno::Reference< XInputStream > xInputStream = xStream->getInputStream();
512cdf0e10cSrcweir 
513cdf0e10cSrcweir             ImageListsDescriptor aUserImageListInfo;
514cdf0e10cSrcweir             ImagesConfiguration::LoadImages( m_xServiceManager,
515cdf0e10cSrcweir                                              xInputStream,
516cdf0e10cSrcweir                                              aUserImageListInfo );
517cdf0e10cSrcweir             if (( aUserImageListInfo.pImageList != 0 ) &&
518cdf0e10cSrcweir                 ( aUserImageListInfo.pImageList->Count() > 0 ))
519cdf0e10cSrcweir             {
520cdf0e10cSrcweir                 ImageListItemDescriptor* pList = aUserImageListInfo.pImageList->GetObject(0);
521cdf0e10cSrcweir                 sal_Int32 nCount = pList->pImageItemList->Count();
522cdf0e10cSrcweir                 std::vector< OUString > aUserImagesVector;
523cdf0e10cSrcweir                 aUserImagesVector.reserve(nCount);
524cdf0e10cSrcweir                 for ( sal_uInt16 i=0; i < nCount; i++ )
525cdf0e10cSrcweir                 {
526cdf0e10cSrcweir                     const ImageItemDescriptor* pItem = pList->pImageItemList->GetObject(i);
527cdf0e10cSrcweir                     aUserImagesVector.push_back( pItem->aCommandURL );
528cdf0e10cSrcweir                 }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir                 uno::Reference< XStream > xBitmapStream = xUserBitmapsStorage->openStreamElement(
531cdf0e10cSrcweir                                                         rtl::OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ),
532cdf0e10cSrcweir                                                         ElementModes::READ );
533cdf0e10cSrcweir 
534cdf0e10cSrcweir                 if ( xBitmapStream.is() )
535cdf0e10cSrcweir                 {
536cdf0e10cSrcweir                     SvStream* pSvStream( 0 );
537cdf0e10cSrcweir 		            BitmapEx aUserBitmap;
538cdf0e10cSrcweir 		            {
539cdf0e10cSrcweir 		                pSvStream = utl::UcbStreamHelper::CreateStream( xBitmapStream );
540cdf0e10cSrcweir 		                vcl::PNGReader aPngReader( *pSvStream );
541cdf0e10cSrcweir 		                aUserBitmap = aPngReader.Read();
542cdf0e10cSrcweir 		            }
543cdf0e10cSrcweir                     delete pSvStream;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir                     // Delete old image list and create a new one from the read bitmap
546cdf0e10cSrcweir                     delete m_pUserImageList[nImageType];
547cdf0e10cSrcweir                     m_pUserImageList[nImageType] = new ImageList();
548cdf0e10cSrcweir 					m_pUserImageList[nImageType]->InsertFromHorizontalStrip
549cdf0e10cSrcweir 						( aUserBitmap, aUserImagesVector );
550cdf0e10cSrcweir                     return sal_True;
551cdf0e10cSrcweir                 }
552cdf0e10cSrcweir             }
553cdf0e10cSrcweir         }
554cdf0e10cSrcweir         catch ( com::sun::star::container::NoSuchElementException& )
555cdf0e10cSrcweir         {
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir         catch ( ::com::sun::star::embed::InvalidStorageException& )
558cdf0e10cSrcweir         {
559cdf0e10cSrcweir         }
560cdf0e10cSrcweir         catch ( ::com::sun::star::lang::IllegalArgumentException& )
561cdf0e10cSrcweir         {
562cdf0e10cSrcweir         }
563cdf0e10cSrcweir         catch ( ::com::sun::star::io::IOException& )
564cdf0e10cSrcweir         {
565cdf0e10cSrcweir         }
566cdf0e10cSrcweir         catch ( ::com::sun::star::embed::StorageWrappedTargetException& )
567cdf0e10cSrcweir         {
568cdf0e10cSrcweir         }
569cdf0e10cSrcweir     }
570cdf0e10cSrcweir 
571cdf0e10cSrcweir     // Destroy old image list - create a new empty one
572cdf0e10cSrcweir     delete m_pUserImageList[nImageType];
573cdf0e10cSrcweir     m_pUserImageList[nImageType] = new ImageList;
574cdf0e10cSrcweir 
575cdf0e10cSrcweir     return sal_True;
576cdf0e10cSrcweir }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir sal_Bool ImageManagerImpl::implts_storeUserImages(
579cdf0e10cSrcweir     ImageType nImageType,
580cdf0e10cSrcweir     const uno::Reference< XStorage >& xUserImageStorage,
581cdf0e10cSrcweir     const uno::Reference< XStorage >& xUserBitmapsStorage )
582cdf0e10cSrcweir {
583cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     if ( m_bModified )
586cdf0e10cSrcweir     {
587cdf0e10cSrcweir         ImageList* pImageList = implts_getUserImageList( nImageType );
588cdf0e10cSrcweir         if ( pImageList->GetImageCount() > 0 )
589cdf0e10cSrcweir         {
590cdf0e10cSrcweir             ImageListsDescriptor aUserImageListInfo;
591cdf0e10cSrcweir             aUserImageListInfo.pImageList = new ImageListDescriptor;
592cdf0e10cSrcweir 
593cdf0e10cSrcweir             ImageListItemDescriptor* pList = new ImageListItemDescriptor;
594cdf0e10cSrcweir             aUserImageListInfo.pImageList->Insert( pList, 0 );
595cdf0e10cSrcweir 
596cdf0e10cSrcweir             pList->pImageItemList = new ImageItemListDescriptor;
597cdf0e10cSrcweir             for ( sal_uInt16 i=0; i < pImageList->GetImageCount(); i++ )
598cdf0e10cSrcweir             {
599cdf0e10cSrcweir                 ImageItemDescriptor* pItem = new ::framework::ImageItemDescriptor;
600cdf0e10cSrcweir 
601cdf0e10cSrcweir                 pItem->nIndex = i;
602cdf0e10cSrcweir                 pItem->aCommandURL = pImageList->GetImageName( i );
603cdf0e10cSrcweir                 pList->pImageItemList->Insert( pItem, pList->pImageItemList->Count() );
604cdf0e10cSrcweir             }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir             pList->aURL = String::CreateFromAscii("Bitmaps/");
607cdf0e10cSrcweir             pList->aURL += String::CreateFromAscii( BITMAP_FILE_NAMES[nImageType] );
608cdf0e10cSrcweir 
609cdf0e10cSrcweir             uno::Reference< XTransactedObject > xTransaction;
610cdf0e10cSrcweir             uno::Reference< XOutputStream >     xOutputStream;
611cdf0e10cSrcweir             uno::Reference< XStream > xStream = xUserImageStorage->openStreamElement( rtl::OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ),
612cdf0e10cSrcweir                                                                                       ElementModes::WRITE|ElementModes::TRUNCATE );
613cdf0e10cSrcweir             if ( xStream.is() )
614cdf0e10cSrcweir             {
615cdf0e10cSrcweir                 uno::Reference< XStream > xBitmapStream =
616cdf0e10cSrcweir                     xUserBitmapsStorage->openStreamElement( rtl::OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ),
617cdf0e10cSrcweir                                                             ElementModes::WRITE|ElementModes::TRUNCATE );
618cdf0e10cSrcweir                 if ( xBitmapStream.is() )
619cdf0e10cSrcweir                 {
620cdf0e10cSrcweir                     SvStream* pSvStream = utl::UcbStreamHelper::CreateStream( xBitmapStream );
621cdf0e10cSrcweir                     {
622cdf0e10cSrcweir                         vcl::PNGWriter aPngWriter( pImageList->GetAsHorizontalStrip() );
623cdf0e10cSrcweir                         aPngWriter.Write( *pSvStream );
624cdf0e10cSrcweir                     }
625cdf0e10cSrcweir                     delete pSvStream;
626cdf0e10cSrcweir 
627cdf0e10cSrcweir                     // Commit user bitmaps storage
628cdf0e10cSrcweir                     xTransaction = uno::Reference< XTransactedObject >( xUserBitmapsStorage, UNO_QUERY );
629cdf0e10cSrcweir 					if ( xTransaction.is() )
630cdf0e10cSrcweir                     	xTransaction->commit();
631cdf0e10cSrcweir                 }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir                 xOutputStream = xStream->getOutputStream();
634cdf0e10cSrcweir                 if ( xOutputStream.is() )
635cdf0e10cSrcweir                     ImagesConfiguration::StoreImages( m_xServiceManager, xOutputStream, aUserImageListInfo );
636cdf0e10cSrcweir 
637cdf0e10cSrcweir                 // Commit user image storage
638cdf0e10cSrcweir                 xTransaction = uno::Reference< XTransactedObject >( xUserImageStorage, UNO_QUERY );
639cdf0e10cSrcweir 				if ( xTransaction.is() )
640cdf0e10cSrcweir                 	xTransaction->commit();
641cdf0e10cSrcweir             }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir             return sal_True;
644cdf0e10cSrcweir         }
645cdf0e10cSrcweir         else
646cdf0e10cSrcweir         {
647cdf0e10cSrcweir             // Remove the streams from the storage, if we have no data. We have to catch
648cdf0e10cSrcweir             // the NoSuchElementException as it can be possible that there is no stream at all!
649cdf0e10cSrcweir             try
650cdf0e10cSrcweir             {
651cdf0e10cSrcweir                 xUserImageStorage->removeElement( rtl::OUString::createFromAscii( IMAGELIST_XML_FILE[nImageType] ));
652cdf0e10cSrcweir             }
653cdf0e10cSrcweir             catch ( ::com::sun::star::container::NoSuchElementException& )
654cdf0e10cSrcweir             {
655cdf0e10cSrcweir             }
656cdf0e10cSrcweir 
657cdf0e10cSrcweir             try
658cdf0e10cSrcweir             {
659cdf0e10cSrcweir                 xUserBitmapsStorage->removeElement( rtl::OUString::createFromAscii( BITMAP_FILE_NAMES[nImageType] ));
660cdf0e10cSrcweir             }
661cdf0e10cSrcweir             catch ( ::com::sun::star::container::NoSuchElementException& )
662cdf0e10cSrcweir             {
663cdf0e10cSrcweir             }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir             uno::Reference< XTransactedObject > xTransaction;
666cdf0e10cSrcweir 
667cdf0e10cSrcweir             // Commit user image storage
668cdf0e10cSrcweir             xTransaction = uno::Reference< XTransactedObject >( xUserImageStorage, UNO_QUERY );
669cdf0e10cSrcweir 			if ( xTransaction.is() )
670cdf0e10cSrcweir                 xTransaction->commit();
671cdf0e10cSrcweir 
672cdf0e10cSrcweir             // Commit user bitmaps storage
673cdf0e10cSrcweir             xTransaction = uno::Reference< XTransactedObject >( xUserBitmapsStorage, UNO_QUERY );
674cdf0e10cSrcweir 			if ( xTransaction.is() )
675cdf0e10cSrcweir                 xTransaction->commit();
676cdf0e10cSrcweir 
677cdf0e10cSrcweir             return sal_True;
678cdf0e10cSrcweir         }
679cdf0e10cSrcweir     }
680cdf0e10cSrcweir 
681cdf0e10cSrcweir     return sal_False;
682cdf0e10cSrcweir }
683cdf0e10cSrcweir const rtl::Reference< GlobalImageList >& ImageManagerImpl::implts_getGlobalImageList()
684cdf0e10cSrcweir {
685cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
686cdf0e10cSrcweir 
687cdf0e10cSrcweir     if ( !m_pGlobalImageList.is() )
688cdf0e10cSrcweir         m_pGlobalImageList = getGlobalImageList( m_xServiceManager );
689cdf0e10cSrcweir     return m_pGlobalImageList;
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir CmdImageList* ImageManagerImpl::implts_getDefaultImageList()
693cdf0e10cSrcweir {
694cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     if ( !m_pDefaultImageList )
697cdf0e10cSrcweir         m_pDefaultImageList = new CmdImageList( m_xServiceManager, m_aModuleIdentifier );
698cdf0e10cSrcweir 
699cdf0e10cSrcweir     return m_pDefaultImageList;
700cdf0e10cSrcweir }
701cdf0e10cSrcweir 
702cdf0e10cSrcweir ImageManagerImpl::ImageManagerImpl( const uno::Reference< XMultiServiceFactory >& xServiceManager,const uno::Reference< XInterface >& _xOwner,bool _bUseGlobal ) :
703cdf0e10cSrcweir     ThreadHelpBase( &Application::GetSolarMutex() )
704cdf0e10cSrcweir     , m_xServiceManager( xServiceManager )
705cdf0e10cSrcweir     , m_xOwner(_xOwner)
706cdf0e10cSrcweir     , m_pDefaultImageList( 0 )
707cdf0e10cSrcweir     , m_aXMLPostfix( RTL_CONSTASCII_USTRINGPARAM( ".xml" ))
708cdf0e10cSrcweir     , m_aResourceString( RTL_CONSTASCII_USTRINGPARAM( ModuleImageList ))
709cdf0e10cSrcweir     , m_aListenerContainer( m_aLock.getShareableOslMutex() )
710cdf0e10cSrcweir     , m_bUseGlobal(_bUseGlobal)
711cdf0e10cSrcweir     , m_bReadOnly( true )
712cdf0e10cSrcweir     , m_bInitialized( false )
713cdf0e10cSrcweir     , m_bModified( false )
714cdf0e10cSrcweir     , m_bConfigRead( false )
715cdf0e10cSrcweir     , m_bDisposed( false )
716cdf0e10cSrcweir {
717cdf0e10cSrcweir     for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
718cdf0e10cSrcweir     {
719cdf0e10cSrcweir         m_pUserImageList[n] = 0;
720cdf0e10cSrcweir         m_bUserImageListModified[n] = false;
721cdf0e10cSrcweir     }
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir ImageManagerImpl::~ImageManagerImpl()
725cdf0e10cSrcweir {
726cdf0e10cSrcweir     clear();
727cdf0e10cSrcweir }
728cdf0e10cSrcweir 
729cdf0e10cSrcweir void ImageManagerImpl::dispose()
730cdf0e10cSrcweir {
731cdf0e10cSrcweir     css::lang::EventObject aEvent( m_xOwner );
732cdf0e10cSrcweir     m_aListenerContainer.disposeAndClear( aEvent );
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 	{
735cdf0e10cSrcweir 	    ResetableGuard aGuard( m_aLock );
736cdf0e10cSrcweir         m_xUserConfigStorage.clear();
737cdf0e10cSrcweir         m_xUserImageStorage.clear();
738cdf0e10cSrcweir         m_xUserRootCommit.clear();
739cdf0e10cSrcweir         m_bConfigRead = false;
740cdf0e10cSrcweir         m_bModified = false;
741cdf0e10cSrcweir         m_bDisposed = true;
742cdf0e10cSrcweir 
743cdf0e10cSrcweir         // delete user and default image list on dispose
744cdf0e10cSrcweir         for ( sal_Int32 n=0; n < ImageType_COUNT; n++ )
745cdf0e10cSrcweir         {
746cdf0e10cSrcweir             delete m_pUserImageList[n];
747cdf0e10cSrcweir             m_pUserImageList[n] = 0;
748cdf0e10cSrcweir         }
749cdf0e10cSrcweir         delete m_pDefaultImageList;
750cdf0e10cSrcweir         m_pDefaultImageList = 0;
751cdf0e10cSrcweir     }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir }
754cdf0e10cSrcweir void ImageManagerImpl::addEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
755cdf0e10cSrcweir {
756cdf0e10cSrcweir     {
757cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 	    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
760cdf0e10cSrcweir         if ( m_bDisposed )
761cdf0e10cSrcweir             throw DisposedException();
762cdf0e10cSrcweir     }
763cdf0e10cSrcweir 
764cdf0e10cSrcweir     m_aListenerContainer.addInterface( ::getCppuType( ( const uno::Reference< XEventListener >* ) NULL ), xListener );
765cdf0e10cSrcweir }
766cdf0e10cSrcweir 
767cdf0e10cSrcweir void ImageManagerImpl::removeEventListener( const uno::Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
768cdf0e10cSrcweir {
769cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
770cdf0e10cSrcweir     m_aListenerContainer.removeInterface( ::getCppuType( ( const uno::Reference< XEventListener >* ) NULL ), xListener );
771cdf0e10cSrcweir }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir // XInitialization
774cdf0e10cSrcweir void ImageManagerImpl::initialize( const Sequence< Any >& aArguments )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
777cdf0e10cSrcweir 
778cdf0e10cSrcweir     if ( !m_bInitialized )
779cdf0e10cSrcweir     {
780cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
781cdf0e10cSrcweir         {
782cdf0e10cSrcweir             PropertyValue aPropValue;
783cdf0e10cSrcweir             if ( aArguments[n] >>= aPropValue )
784cdf0e10cSrcweir             {
785cdf0e10cSrcweir                 if ( aPropValue.Name.equalsAscii( "UserConfigStorage" ))
786cdf0e10cSrcweir                 {
787cdf0e10cSrcweir                     aPropValue.Value >>= m_xUserConfigStorage;
788cdf0e10cSrcweir                 }
789cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAscii( "ModuleIdentifier" ))
790cdf0e10cSrcweir                 {
791cdf0e10cSrcweir                     aPropValue.Value >>= m_aModuleIdentifier;
792cdf0e10cSrcweir                 }
793cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAscii( "UserRootCommit" ))
794cdf0e10cSrcweir                 {
795cdf0e10cSrcweir                     aPropValue.Value >>= m_xUserRootCommit;
796cdf0e10cSrcweir                 }
797cdf0e10cSrcweir             }
798cdf0e10cSrcweir         }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir         if ( m_xUserConfigStorage.is() )
801cdf0e10cSrcweir         {
802cdf0e10cSrcweir             uno::Reference< XPropertySet > xPropSet( m_xUserConfigStorage, UNO_QUERY );
803cdf0e10cSrcweir             if ( xPropSet.is() )
804cdf0e10cSrcweir             {
805cdf0e10cSrcweir                 long nOpenMode = 0;
806cdf0e10cSrcweir                 if ( xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ))) >>= nOpenMode )
807cdf0e10cSrcweir                     m_bReadOnly = !( nOpenMode & ElementModes::WRITE );
808cdf0e10cSrcweir             }
809cdf0e10cSrcweir         }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir         implts_initialize();
812cdf0e10cSrcweir 
813cdf0e10cSrcweir         m_bInitialized = true;
814cdf0e10cSrcweir     }
815cdf0e10cSrcweir }
816cdf0e10cSrcweir 
817cdf0e10cSrcweir // XImageManagerImpl
818cdf0e10cSrcweir void ImageManagerImpl::reset()
819cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
820cdf0e10cSrcweir {
821cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
822cdf0e10cSrcweir 
823cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
824cdf0e10cSrcweir     if ( m_bDisposed )
825cdf0e10cSrcweir         throw DisposedException();
826cdf0e10cSrcweir 
827cdf0e10cSrcweir     std::vector< OUString > aUserImageNames;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
830cdf0e10cSrcweir     {
831cdf0e10cSrcweir         aUserImageNames.clear();
832cdf0e10cSrcweir         ImageList* pImageList = implts_getUserImageList( ImageType(i));
833cdf0e10cSrcweir         pImageList->GetImageNames( aUserImageNames );
834cdf0e10cSrcweir 
835cdf0e10cSrcweir         Sequence< rtl::OUString > aRemoveList( aUserImageNames.size() );
836cdf0e10cSrcweir         const sal_uInt32 nCount = aUserImageNames.size();
837cdf0e10cSrcweir 		for ( sal_uInt32 j = 0; j < nCount; j++ )
838cdf0e10cSrcweir             aRemoveList[j] = aUserImageNames[j];
839cdf0e10cSrcweir 
840cdf0e10cSrcweir         // Remove images
841cdf0e10cSrcweir         removeImages( sal_Int16( i ), aRemoveList );
842cdf0e10cSrcweir         m_bUserImageListModified[i] = true;
843cdf0e10cSrcweir     }
844cdf0e10cSrcweir 
845cdf0e10cSrcweir     m_bModified = sal_True;
846cdf0e10cSrcweir }
847cdf0e10cSrcweir 
848cdf0e10cSrcweir Sequence< ::rtl::OUString > ImageManagerImpl::getAllImageNames( ::sal_Int16 nImageType )
849cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
850cdf0e10cSrcweir {
851cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
852cdf0e10cSrcweir 
853cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
854cdf0e10cSrcweir     if ( m_bDisposed )
855cdf0e10cSrcweir         throw DisposedException();
856cdf0e10cSrcweir 
857cdf0e10cSrcweir     ImageNameMap aImageCmdNameMap;
858cdf0e10cSrcweir 
859cdf0e10cSrcweir     sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
860cdf0e10cSrcweir 
861cdf0e10cSrcweir     sal_uInt32 i( 0 );
862cdf0e10cSrcweir     if ( m_bUseGlobal )
863cdf0e10cSrcweir     {
864cdf0e10cSrcweir         rtl::Reference< GlobalImageList > rGlobalImageList = implts_getGlobalImageList();
865cdf0e10cSrcweir 
866cdf0e10cSrcweir         const std::vector< OUString >& rGlobalImageNameVector = rGlobalImageList->getImageCommandNames();
867cdf0e10cSrcweir         const sal_uInt32 nGlobalCount = rGlobalImageNameVector.size();
868cdf0e10cSrcweir         for ( i = 0; i < nGlobalCount; i++ )
869cdf0e10cSrcweir             aImageCmdNameMap.insert( ImageNameMap::value_type( rGlobalImageNameVector[i], sal_True ));
870cdf0e10cSrcweir 
871cdf0e10cSrcweir         const std::vector< OUString >& rModuleImageNameVector = implts_getDefaultImageList()->getImageCommandNames();
872cdf0e10cSrcweir         const sal_uInt32 nModuleCount = rModuleImageNameVector.size();
873cdf0e10cSrcweir         for ( i = 0; i < nModuleCount; i++ )
874cdf0e10cSrcweir             aImageCmdNameMap.insert( ImageNameMap::value_type( rModuleImageNameVector[i], sal_True ));
875cdf0e10cSrcweir     }
876cdf0e10cSrcweir 
877cdf0e10cSrcweir     ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
878cdf0e10cSrcweir     std::vector< OUString > rUserImageNames;
879cdf0e10cSrcweir     pImageList->GetImageNames( rUserImageNames );
880cdf0e10cSrcweir     const sal_uInt32 nUserCount = rUserImageNames.size();
881cdf0e10cSrcweir     for ( i = 0; i < nUserCount; i++ )
882cdf0e10cSrcweir         aImageCmdNameMap.insert( ImageNameMap::value_type( rUserImageNames[i], sal_True ));
883cdf0e10cSrcweir 
884cdf0e10cSrcweir     Sequence< OUString > aImageNameSeq( aImageCmdNameMap.size() );
885cdf0e10cSrcweir     ImageNameMap::const_iterator pIter;
886cdf0e10cSrcweir     i = 0;
887cdf0e10cSrcweir     for ( pIter = aImageCmdNameMap.begin(); pIter != aImageCmdNameMap.end(); pIter++ )
888cdf0e10cSrcweir         aImageNameSeq[i++] = pIter->first;
889cdf0e10cSrcweir 
890cdf0e10cSrcweir     return aImageNameSeq;
891cdf0e10cSrcweir }
892cdf0e10cSrcweir 
893cdf0e10cSrcweir ::sal_Bool ImageManagerImpl::hasImage( ::sal_Int16 nImageType, const ::rtl::OUString& aCommandURL )
894cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
895cdf0e10cSrcweir {
896cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
897cdf0e10cSrcweir 
898cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
899cdf0e10cSrcweir     if ( m_bDisposed )
900cdf0e10cSrcweir         throw DisposedException();
901cdf0e10cSrcweir 
902cdf0e10cSrcweir     if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
903cdf0e10cSrcweir         throw IllegalArgumentException();
904cdf0e10cSrcweir 
905cdf0e10cSrcweir     sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
906cdf0e10cSrcweir     if ( m_bUseGlobal && implts_getGlobalImageList()->hasImage( nIndex, aCommandURL ))
907cdf0e10cSrcweir         return sal_True;
908cdf0e10cSrcweir     else
909cdf0e10cSrcweir     {
910cdf0e10cSrcweir         if ( m_bUseGlobal && implts_getDefaultImageList()->hasImage( nIndex, aCommandURL ))
911cdf0e10cSrcweir             return sal_True;
912cdf0e10cSrcweir         else
913cdf0e10cSrcweir         {
914cdf0e10cSrcweir             // User layer
915cdf0e10cSrcweir             ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
916cdf0e10cSrcweir             if ( pImageList )
917cdf0e10cSrcweir                 return ( pImageList->GetImagePos( aCommandURL ) != IMAGELIST_IMAGE_NOTFOUND );
918cdf0e10cSrcweir         }
919cdf0e10cSrcweir     }
920cdf0e10cSrcweir 
921cdf0e10cSrcweir     return sal_False;
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir Sequence< uno::Reference< XGraphic > > ImageManagerImpl::getImages(
925cdf0e10cSrcweir     ::sal_Int16 nImageType,
926cdf0e10cSrcweir     const Sequence< ::rtl::OUString >& aCommandURLSequence )
927cdf0e10cSrcweir throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
928cdf0e10cSrcweir {
929cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
930cdf0e10cSrcweir 
931cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
932cdf0e10cSrcweir     if ( m_bDisposed )
933cdf0e10cSrcweir         throw DisposedException();
934cdf0e10cSrcweir 
935cdf0e10cSrcweir     if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
936cdf0e10cSrcweir         throw IllegalArgumentException();
937cdf0e10cSrcweir 
938cdf0e10cSrcweir     Sequence< uno::Reference< XGraphic > > aGraphSeq( aCommandURLSequence.getLength() );
939cdf0e10cSrcweir 
940cdf0e10cSrcweir     const rtl::OUString* aStrArray = aCommandURLSequence.getConstArray();
941cdf0e10cSrcweir 
942cdf0e10cSrcweir     sal_Int16                         nIndex            = implts_convertImageTypeToIndex( nImageType );
943cdf0e10cSrcweir     rtl::Reference< GlobalImageList > rGlobalImageList;
944cdf0e10cSrcweir     CmdImageList*                     pDefaultImageList = NULL;
945cdf0e10cSrcweir     if ( m_bUseGlobal )
946cdf0e10cSrcweir     {
947cdf0e10cSrcweir         rGlobalImageList  = implts_getGlobalImageList();
948cdf0e10cSrcweir         pDefaultImageList = implts_getDefaultImageList();
949cdf0e10cSrcweir     }
950cdf0e10cSrcweir     ImageList*                        pUserImageList    = implts_getUserImageList( ImageType( nIndex ));
951cdf0e10cSrcweir 
952cdf0e10cSrcweir     // We have to search our image list in the following order:
953cdf0e10cSrcweir     // 1. user image list (read/write)
954cdf0e10cSrcweir     // 2. module image list (read)
955cdf0e10cSrcweir     // 3. global image list (read)
956cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < aCommandURLSequence.getLength(); n++ )
957cdf0e10cSrcweir     {
958cdf0e10cSrcweir         Image aImage = pUserImageList->GetImage( aStrArray[n] );
959cdf0e10cSrcweir         if ( !aImage && m_bUseGlobal )
960cdf0e10cSrcweir         {
961cdf0e10cSrcweir             aImage = pDefaultImageList->getImageFromCommandURL( nIndex, aStrArray[n] );
962cdf0e10cSrcweir             if ( !aImage )
963cdf0e10cSrcweir                 aImage = rGlobalImageList->getImageFromCommandURL( nIndex, aStrArray[n] );
964cdf0e10cSrcweir         }
965cdf0e10cSrcweir 
966cdf0e10cSrcweir         aGraphSeq[n] = aImage.GetXGraphic();
967cdf0e10cSrcweir     }
968cdf0e10cSrcweir 
969cdf0e10cSrcweir     return aGraphSeq;
970cdf0e10cSrcweir }
971cdf0e10cSrcweir 
972cdf0e10cSrcweir void ImageManagerImpl::replaceImages(
973cdf0e10cSrcweir     ::sal_Int16 nImageType,
974cdf0e10cSrcweir     const Sequence< ::rtl::OUString >& aCommandURLSequence,
975cdf0e10cSrcweir     const Sequence< uno::Reference< XGraphic > >& aGraphicsSequence )
976cdf0e10cSrcweir throw ( ::com::sun::star::lang::IllegalArgumentException,
977cdf0e10cSrcweir         ::com::sun::star::lang::IllegalAccessException,
978cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException)
979cdf0e10cSrcweir {
980cdf0e10cSrcweir     CmdToXGraphicNameAccess* pInsertedImages( 0 );
981cdf0e10cSrcweir     CmdToXGraphicNameAccess* pReplacedImages( 0 );
982cdf0e10cSrcweir 
983cdf0e10cSrcweir     {
984cdf0e10cSrcweir         ResetableGuard aLock( m_aLock );
985cdf0e10cSrcweir 
986cdf0e10cSrcweir         /* SAFE AREA ----------------------------------------------------------------------------------------------- */
987cdf0e10cSrcweir         if ( m_bDisposed )
988cdf0e10cSrcweir             throw DisposedException();
989cdf0e10cSrcweir 
990cdf0e10cSrcweir         if (( aCommandURLSequence.getLength() != aGraphicsSequence.getLength() ) ||
991cdf0e10cSrcweir             (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE )))
992cdf0e10cSrcweir             throw IllegalArgumentException();
993cdf0e10cSrcweir 
994cdf0e10cSrcweir         if ( m_bReadOnly )
995cdf0e10cSrcweir             throw IllegalAccessException();
996cdf0e10cSrcweir 
997cdf0e10cSrcweir         sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
998cdf0e10cSrcweir         ImageList* pImageList = implts_getUserImageList( ImageType( nIndex ));
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir         uno::Reference< XGraphic > xGraphic;
1001cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < aCommandURLSequence.getLength(); i++ )
1002cdf0e10cSrcweir         {
1003cdf0e10cSrcweir             // Check size and scale. If we don't have any graphics ignore it
1004cdf0e10cSrcweir             if ( !implts_checkAndScaleGraphic( xGraphic, aGraphicsSequence[i], nIndex ))
1005cdf0e10cSrcweir                 continue;
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir             sal_uInt16 nPos = pImageList->GetImagePos( aCommandURLSequence[i] );
1008cdf0e10cSrcweir             if ( nPos == IMAGELIST_IMAGE_NOTFOUND )
1009cdf0e10cSrcweir             {
1010cdf0e10cSrcweir                 pImageList->AddImage( aCommandURLSequence[i], xGraphic );
1011cdf0e10cSrcweir                 if ( !pInsertedImages )
1012cdf0e10cSrcweir                     pInsertedImages = new CmdToXGraphicNameAccess();
1013cdf0e10cSrcweir                 pInsertedImages->addElement( aCommandURLSequence[i], xGraphic );
1014cdf0e10cSrcweir             }
1015cdf0e10cSrcweir             else
1016cdf0e10cSrcweir             {
1017cdf0e10cSrcweir                 pImageList->ReplaceImage( aCommandURLSequence[i], xGraphic );
1018cdf0e10cSrcweir                 if ( !pReplacedImages )
1019cdf0e10cSrcweir                     pReplacedImages = new CmdToXGraphicNameAccess();
1020cdf0e10cSrcweir                 pReplacedImages->addElement( aCommandURLSequence[i], xGraphic );
1021cdf0e10cSrcweir             }
1022cdf0e10cSrcweir         }
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir         if (( pInsertedImages != 0 ) || (  pReplacedImages != 0 ))
1025cdf0e10cSrcweir         {
1026cdf0e10cSrcweir             m_bModified = sal_True;
1027cdf0e10cSrcweir             m_bUserImageListModified[nIndex] = true;
1028cdf0e10cSrcweir         }
1029cdf0e10cSrcweir     }
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir     // Notify listeners
1032cdf0e10cSrcweir     if ( pInsertedImages != 0 )
1033cdf0e10cSrcweir     {
1034cdf0e10cSrcweir         ConfigurationEvent aInsertEvent;
1035cdf0e10cSrcweir         aInsertEvent.aInfo           <<= nImageType;
1036cdf0e10cSrcweir         aInsertEvent.Accessor        <<= m_xOwner;
1037cdf0e10cSrcweir         aInsertEvent.Source          = m_xOwner;
1038cdf0e10cSrcweir         aInsertEvent.ResourceURL     = m_aResourceString;
1039cdf0e10cSrcweir         aInsertEvent.Element         = uno::makeAny( uno::Reference< XNameAccess >(
1040cdf0e10cSrcweir                                         static_cast< OWeakObject *>( pInsertedImages ), UNO_QUERY ));
1041cdf0e10cSrcweir         implts_notifyContainerListener( aInsertEvent, NotifyOp_Insert );
1042cdf0e10cSrcweir     }
1043cdf0e10cSrcweir     if ( pReplacedImages != 0 )
1044cdf0e10cSrcweir     {
1045cdf0e10cSrcweir         ConfigurationEvent aReplaceEvent;
1046cdf0e10cSrcweir         aReplaceEvent.aInfo           <<= nImageType;
1047cdf0e10cSrcweir         aReplaceEvent.Accessor        <<= m_xOwner;
1048cdf0e10cSrcweir         aReplaceEvent.Source          = m_xOwner;
1049cdf0e10cSrcweir         aReplaceEvent.ResourceURL     = m_aResourceString;
1050cdf0e10cSrcweir         aReplaceEvent.ReplacedElement = Any();
1051cdf0e10cSrcweir         aReplaceEvent.Element         = uno::makeAny( uno::Reference< XNameAccess >(
1052cdf0e10cSrcweir                                             static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1053cdf0e10cSrcweir         implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1054cdf0e10cSrcweir     }
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir void ImageManagerImpl::removeImages( ::sal_Int16 nImageType, const Sequence< ::rtl::OUString >& aCommandURLSequence )
1058cdf0e10cSrcweir throw ( ::com::sun::star::lang::IllegalArgumentException,
1059cdf0e10cSrcweir         ::com::sun::star::lang::IllegalAccessException,
1060cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException)
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir     CmdToXGraphicNameAccess* pRemovedImages( 0 );
1063cdf0e10cSrcweir     CmdToXGraphicNameAccess* pReplacedImages( 0 );
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir     {
1066cdf0e10cSrcweir         ResetableGuard aLock( m_aLock );
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir         /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1069cdf0e10cSrcweir         if ( m_bDisposed )
1070cdf0e10cSrcweir             throw DisposedException();
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir         if (( nImageType < 0 ) || ( nImageType > MAX_IMAGETYPE_VALUE ))
1073cdf0e10cSrcweir             throw IllegalArgumentException();
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir         if ( m_bReadOnly )
1076cdf0e10cSrcweir             throw IllegalAccessException();
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir         sal_Int16 nIndex = implts_convertImageTypeToIndex( nImageType );
1079cdf0e10cSrcweir         rtl::Reference< GlobalImageList > rGlobalImageList;
1080cdf0e10cSrcweir         CmdImageList*                     pDefaultImageList = NULL;
1081cdf0e10cSrcweir         if ( m_bUseGlobal )
1082cdf0e10cSrcweir         {
1083cdf0e10cSrcweir             rGlobalImageList  = implts_getGlobalImageList();
1084cdf0e10cSrcweir             pDefaultImageList = implts_getDefaultImageList();
1085cdf0e10cSrcweir         }
1086cdf0e10cSrcweir         ImageList*                        pImageList        = implts_getUserImageList( ImageType( nIndex ));
1087cdf0e10cSrcweir         uno::Reference< XGraphic >        xEmptyGraphic( Image().GetXGraphic() );
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < aCommandURLSequence.getLength(); i++ )
1090cdf0e10cSrcweir         {
1091cdf0e10cSrcweir             sal_uInt16 nPos = pImageList->GetImagePos( aCommandURLSequence[i] );
1092cdf0e10cSrcweir             if ( nPos != IMAGELIST_IMAGE_NOTFOUND )
1093cdf0e10cSrcweir             {
1094cdf0e10cSrcweir                 Image aImage = pImageList->GetImage( nPos );
1095cdf0e10cSrcweir                 sal_uInt16 nId   = pImageList->GetImageId( nPos );
1096cdf0e10cSrcweir                 pImageList->RemoveImage( nId );
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir                 if ( m_bUseGlobal )
1099cdf0e10cSrcweir                 {
1100cdf0e10cSrcweir                     // Check, if we have a image in our module/global image list. If we find one =>
1101cdf0e10cSrcweir                     // this is a replace instead of a remove operation!
1102cdf0e10cSrcweir                     Image aNewImage = pDefaultImageList->getImageFromCommandURL( nIndex, aCommandURLSequence[i] );
1103cdf0e10cSrcweir                     if ( !aNewImage )
1104cdf0e10cSrcweir                         aNewImage = rGlobalImageList->getImageFromCommandURL( nIndex, aCommandURLSequence[i] );
1105cdf0e10cSrcweir                     if ( !aNewImage )
1106cdf0e10cSrcweir                     {
1107cdf0e10cSrcweir                         if ( !pRemovedImages )
1108cdf0e10cSrcweir                             pRemovedImages = new CmdToXGraphicNameAccess();
1109cdf0e10cSrcweir                         pRemovedImages->addElement( aCommandURLSequence[i], xEmptyGraphic );
1110cdf0e10cSrcweir                     }
1111cdf0e10cSrcweir                     else
1112cdf0e10cSrcweir                     {
1113cdf0e10cSrcweir                         if ( !pReplacedImages )
1114cdf0e10cSrcweir                             pReplacedImages = new CmdToXGraphicNameAccess();
1115cdf0e10cSrcweir                         pReplacedImages->addElement( aCommandURLSequence[i], aNewImage.GetXGraphic() );
1116cdf0e10cSrcweir                     }
1117cdf0e10cSrcweir                 } // if ( m_bUseGlobal )
1118cdf0e10cSrcweir                 else
1119cdf0e10cSrcweir                 {
1120cdf0e10cSrcweir                     if ( !pRemovedImages )
1121cdf0e10cSrcweir                         pRemovedImages = new CmdToXGraphicNameAccess();
1122cdf0e10cSrcweir                     pRemovedImages->addElement( aCommandURLSequence[i], xEmptyGraphic );
1123cdf0e10cSrcweir                 }
1124cdf0e10cSrcweir             }
1125cdf0e10cSrcweir         }
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir         if (( pReplacedImages != 0 ) || ( pRemovedImages != 0 ))
1128cdf0e10cSrcweir         {
1129cdf0e10cSrcweir             m_bModified = sal_True;
1130cdf0e10cSrcweir             m_bUserImageListModified[nIndex] = true;
1131cdf0e10cSrcweir         }
1132cdf0e10cSrcweir     }
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir     // Notify listeners
1135cdf0e10cSrcweir     if ( pRemovedImages != 0 )
1136cdf0e10cSrcweir     {
1137cdf0e10cSrcweir         ConfigurationEvent aRemoveEvent;
1138cdf0e10cSrcweir         aRemoveEvent.aInfo           = uno::makeAny( nImageType );
1139cdf0e10cSrcweir         aRemoveEvent.Accessor        = uno::makeAny( m_xOwner );
1140cdf0e10cSrcweir         aRemoveEvent.Source          = m_xOwner;
1141cdf0e10cSrcweir         aRemoveEvent.ResourceURL     = m_aResourceString;
1142cdf0e10cSrcweir         aRemoveEvent.Element         = uno::makeAny( uno::Reference< XNameAccess >(
1143cdf0e10cSrcweir                                             static_cast< OWeakObject *>( pRemovedImages ), UNO_QUERY ));
1144cdf0e10cSrcweir         implts_notifyContainerListener( aRemoveEvent, NotifyOp_Remove );
1145cdf0e10cSrcweir     }
1146cdf0e10cSrcweir     if ( pReplacedImages != 0 )
1147cdf0e10cSrcweir     {
1148cdf0e10cSrcweir         ConfigurationEvent aReplaceEvent;
1149cdf0e10cSrcweir         aReplaceEvent.aInfo           = uno::makeAny( nImageType );
1150cdf0e10cSrcweir         aReplaceEvent.Accessor        = uno::makeAny( m_xOwner );
1151cdf0e10cSrcweir         aReplaceEvent.Source          = m_xOwner;
1152cdf0e10cSrcweir         aReplaceEvent.ResourceURL     = m_aResourceString;
1153cdf0e10cSrcweir         aReplaceEvent.ReplacedElement = Any();
1154cdf0e10cSrcweir         aReplaceEvent.Element         = uno::makeAny( uno::Reference< XNameAccess >(
1155cdf0e10cSrcweir                                             static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1156cdf0e10cSrcweir         implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1157cdf0e10cSrcweir     }
1158cdf0e10cSrcweir }
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir void ImageManagerImpl::insertImages( ::sal_Int16 nImageType, const Sequence< ::rtl::OUString >& aCommandURLSequence, const Sequence< uno::Reference< XGraphic > >& aGraphicSequence )
1161cdf0e10cSrcweir throw ( ::com::sun::star::container::ElementExistException,
1162cdf0e10cSrcweir         ::com::sun::star::lang::IllegalArgumentException,
1163cdf0e10cSrcweir         ::com::sun::star::lang::IllegalAccessException,
1164cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException)
1165cdf0e10cSrcweir {
1166cdf0e10cSrcweir     replaceImages(nImageType,aCommandURLSequence,aGraphicSequence);
1167cdf0e10cSrcweir }
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir // XUIConfigurationPersistence
1171cdf0e10cSrcweir void ImageManagerImpl::reload()
1172cdf0e10cSrcweir throw ( ::com::sun::star::uno::Exception,
1173cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException )
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir     if ( m_bDisposed )
1178cdf0e10cSrcweir         throw DisposedException();
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir     CommandMap                   aOldUserCmdImageSet;
1181cdf0e10cSrcweir     std::vector< rtl::OUString > aNewUserCmdImageSet;
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir     if ( m_bModified )
1184cdf0e10cSrcweir     {
1185cdf0e10cSrcweir         for ( sal_Int16 i = 0; i < sal_Int16( ImageType_COUNT ); i++ )
1186cdf0e10cSrcweir         {
1187cdf0e10cSrcweir             if ( !m_bDisposed && m_bUserImageListModified[i] )
1188cdf0e10cSrcweir             {
1189cdf0e10cSrcweir                 std::vector< rtl::OUString > aOldUserCmdImageVector;
1190cdf0e10cSrcweir                 ImageList* pImageList = implts_getUserImageList( (ImageType)i );
1191cdf0e10cSrcweir                 pImageList->GetImageNames( aOldUserCmdImageVector );
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir                 // Fill hash map to speed up search afterwards
1194cdf0e10cSrcweir                 sal_uInt32 j( 0 );
1195cdf0e10cSrcweir                 const sal_uInt32 nOldCount = aOldUserCmdImageVector.size();
1196cdf0e10cSrcweir 				for ( j = 0; j < nOldCount; j++ )
1197cdf0e10cSrcweir                     aOldUserCmdImageSet.insert( CommandMap::value_type( aOldUserCmdImageVector[j], false ));
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir                 // Attention: This can make the old image list pointer invalid!
1200cdf0e10cSrcweir                 implts_loadUserImages( (ImageType)i, m_xUserImageStorage, m_xUserBitmapsStorage );
1201cdf0e10cSrcweir                 pImageList = implts_getUserImageList( (ImageType)i );
1202cdf0e10cSrcweir                 pImageList->GetImageNames( aNewUserCmdImageSet );
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir                 CmdToXGraphicNameAccess* pInsertedImages( 0 );
1205cdf0e10cSrcweir                 CmdToXGraphicNameAccess* pReplacedImages( 0 );
1206cdf0e10cSrcweir                 CmdToXGraphicNameAccess* pRemovedImages( 0 );
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir                 const sal_uInt32 nNewCount = aNewUserCmdImageSet.size();
1209cdf0e10cSrcweir 				for ( j = 0; j < nNewCount; j++ )
1210cdf0e10cSrcweir                 {
1211cdf0e10cSrcweir                     CommandMap::iterator pIter = aOldUserCmdImageSet.find( aNewUserCmdImageSet[j] );
1212cdf0e10cSrcweir                     if ( pIter != aOldUserCmdImageSet.end() )
1213cdf0e10cSrcweir                     {
1214cdf0e10cSrcweir                         pIter->second = true; // mark entry as replaced
1215cdf0e10cSrcweir                         if ( !pReplacedImages )
1216cdf0e10cSrcweir                             pReplacedImages = new CmdToXGraphicNameAccess();
1217cdf0e10cSrcweir                         pReplacedImages->addElement( aNewUserCmdImageSet[j],
1218cdf0e10cSrcweir                                                      pImageList->GetImage( aNewUserCmdImageSet[j] ).GetXGraphic() );
1219cdf0e10cSrcweir                     }
1220cdf0e10cSrcweir                     else
1221cdf0e10cSrcweir                     {
1222cdf0e10cSrcweir                         if ( !pInsertedImages )
1223cdf0e10cSrcweir                             pInsertedImages = new CmdToXGraphicNameAccess();
1224cdf0e10cSrcweir                         pInsertedImages->addElement( aNewUserCmdImageSet[j],
1225cdf0e10cSrcweir                                                      pImageList->GetImage( aNewUserCmdImageSet[j] ).GetXGraphic() );
1226cdf0e10cSrcweir                     }
1227cdf0e10cSrcweir                 }
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir                 // Search map for unmarked entries => they have been removed from the user list
1230cdf0e10cSrcweir                 // through this reload operation.
1231cdf0e10cSrcweir                 // We have to search the module and global image list!
1232cdf0e10cSrcweir                 rtl::Reference< GlobalImageList > rGlobalImageList;
1233cdf0e10cSrcweir                 CmdImageList*                     pDefaultImageList = NULL;
1234cdf0e10cSrcweir                 if ( m_bUseGlobal )
1235cdf0e10cSrcweir                 {
1236cdf0e10cSrcweir                     rGlobalImageList  = implts_getGlobalImageList();
1237cdf0e10cSrcweir                     pDefaultImageList = implts_getDefaultImageList();
1238cdf0e10cSrcweir                 }
1239cdf0e10cSrcweir                 uno::Reference< XGraphic >        xEmptyGraphic( Image().GetXGraphic() );
1240cdf0e10cSrcweir                 CommandMap::const_iterator        pIter = aOldUserCmdImageSet.begin();
1241cdf0e10cSrcweir                 while ( pIter != aOldUserCmdImageSet.end() )
1242cdf0e10cSrcweir                 {
1243cdf0e10cSrcweir                     if ( !pIter->second )
1244cdf0e10cSrcweir                     {
1245cdf0e10cSrcweir                         if ( m_bUseGlobal )
1246cdf0e10cSrcweir                         {
1247cdf0e10cSrcweir                             Image aImage = pDefaultImageList->getImageFromCommandURL( i, pIter->first );
1248cdf0e10cSrcweir                             if ( !aImage )
1249cdf0e10cSrcweir                                 aImage = rGlobalImageList->getImageFromCommandURL( i, pIter->first );
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir                             if ( !aImage )
1252cdf0e10cSrcweir                             {
1253cdf0e10cSrcweir                                 // No image in the module/global image list => remove user image
1254cdf0e10cSrcweir                                 if ( !pRemovedImages )
1255cdf0e10cSrcweir                                     pRemovedImages = new CmdToXGraphicNameAccess();
1256cdf0e10cSrcweir                                 pRemovedImages->addElement( pIter->first, xEmptyGraphic );
1257cdf0e10cSrcweir                             }
1258cdf0e10cSrcweir                             else
1259cdf0e10cSrcweir                             {
1260cdf0e10cSrcweir                                 // Image has been found in the module/global image list => replace user image
1261cdf0e10cSrcweir                                 if ( !pReplacedImages )
1262cdf0e10cSrcweir                                     pReplacedImages = new CmdToXGraphicNameAccess();
1263cdf0e10cSrcweir                                 pReplacedImages->addElement( pIter->first, aImage.GetXGraphic() );
1264cdf0e10cSrcweir                             }
1265cdf0e10cSrcweir                         } // if ( m_bUseGlobal )
1266cdf0e10cSrcweir                         else
1267cdf0e10cSrcweir                         {
1268cdf0e10cSrcweir                             // No image in the user image list => remove user image
1269cdf0e10cSrcweir                             if ( !pRemovedImages )
1270cdf0e10cSrcweir                                 pRemovedImages = new CmdToXGraphicNameAccess();
1271cdf0e10cSrcweir                             pRemovedImages->addElement( pIter->first, xEmptyGraphic );
1272cdf0e10cSrcweir                         }
1273cdf0e10cSrcweir                     }
1274cdf0e10cSrcweir                     ++pIter;
1275cdf0e10cSrcweir                 }
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir                 aGuard.unlock();
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir                 // Now notify our listeners. Unlock mutex to prevent deadlocks
1280cdf0e10cSrcweir                 if ( pInsertedImages != 0 )
1281cdf0e10cSrcweir                 {
1282cdf0e10cSrcweir                     ConfigurationEvent aInsertEvent;
1283cdf0e10cSrcweir                     aInsertEvent.aInfo           = uno::makeAny( i );
1284cdf0e10cSrcweir                     aInsertEvent.Accessor        = uno::makeAny( m_xOwner );
1285cdf0e10cSrcweir                     aInsertEvent.Source          = m_xOwner;
1286cdf0e10cSrcweir                     aInsertEvent.ResourceURL     = m_aResourceString;
1287cdf0e10cSrcweir                     aInsertEvent.Element         = uno::makeAny( uno::Reference< XNameAccess >(
1288cdf0e10cSrcweir                                                     static_cast< OWeakObject *>( pInsertedImages ), UNO_QUERY ));
1289cdf0e10cSrcweir                     implts_notifyContainerListener( aInsertEvent, NotifyOp_Insert );
1290cdf0e10cSrcweir                 }
1291cdf0e10cSrcweir                 if ( pReplacedImages != 0 )
1292cdf0e10cSrcweir                 {
1293cdf0e10cSrcweir                     ConfigurationEvent aReplaceEvent;
1294cdf0e10cSrcweir                     aReplaceEvent.aInfo           = uno::makeAny( i );
1295cdf0e10cSrcweir                     aReplaceEvent.Accessor        = uno::makeAny( m_xOwner );
1296cdf0e10cSrcweir                     aReplaceEvent.Source          = m_xOwner;
1297cdf0e10cSrcweir                     aReplaceEvent.ResourceURL     = m_aResourceString;
1298cdf0e10cSrcweir                     aReplaceEvent.ReplacedElement = Any();
1299cdf0e10cSrcweir                     aReplaceEvent.Element         = uno::makeAny( uno::Reference< XNameAccess >(
1300cdf0e10cSrcweir                                                     static_cast< OWeakObject *>( pReplacedImages ), UNO_QUERY ));
1301cdf0e10cSrcweir                     implts_notifyContainerListener( aReplaceEvent, NotifyOp_Replace );
1302cdf0e10cSrcweir                 }
1303cdf0e10cSrcweir                 if ( pRemovedImages != 0 )
1304cdf0e10cSrcweir                 {
1305cdf0e10cSrcweir                     ConfigurationEvent aRemoveEvent;
1306cdf0e10cSrcweir                     aRemoveEvent.aInfo           = uno::makeAny( i );
1307cdf0e10cSrcweir                     aRemoveEvent.Accessor        = uno::makeAny( m_xOwner );
1308cdf0e10cSrcweir                     aRemoveEvent.Source          = m_xOwner;
1309cdf0e10cSrcweir                     aRemoveEvent.ResourceURL     = m_aResourceString;
1310cdf0e10cSrcweir                     aRemoveEvent.Element         = uno::makeAny( uno::Reference< XNameAccess >(
1311cdf0e10cSrcweir                                                         static_cast< OWeakObject *>( pRemovedImages ), UNO_QUERY ));
1312cdf0e10cSrcweir                     implts_notifyContainerListener( aRemoveEvent, NotifyOp_Remove );
1313cdf0e10cSrcweir                 }
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir                 aGuard.lock();
1316cdf0e10cSrcweir             }
1317cdf0e10cSrcweir         }
1318cdf0e10cSrcweir     }
1319cdf0e10cSrcweir }
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir void ImageManagerImpl::store()
1322cdf0e10cSrcweir throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1323cdf0e10cSrcweir {
1324cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir     if ( m_bDisposed )
1327cdf0e10cSrcweir         throw DisposedException();
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir     if ( m_bModified )
1330cdf0e10cSrcweir     {
1331cdf0e10cSrcweir         sal_Bool bWritten( sal_False );
1332cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
1333cdf0e10cSrcweir         {
1334cdf0e10cSrcweir             sal_Bool bSuccess = implts_storeUserImages( ImageType(i), m_xUserImageStorage, m_xUserBitmapsStorage );
1335cdf0e10cSrcweir             if ( bSuccess )
1336cdf0e10cSrcweir                 bWritten = sal_True;
1337cdf0e10cSrcweir             m_bUserImageListModified[i] = false;
1338cdf0e10cSrcweir         }
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir         if ( bWritten &&
1341cdf0e10cSrcweir              m_xUserConfigStorage.is() )
1342cdf0e10cSrcweir         {
1343cdf0e10cSrcweir             uno::Reference< XTransactedObject > xUserConfigStorageCommit( m_xUserConfigStorage, UNO_QUERY );
1344cdf0e10cSrcweir 			if ( xUserConfigStorageCommit.is() )
1345cdf0e10cSrcweir             	xUserConfigStorageCommit->commit();
1346cdf0e10cSrcweir             if ( m_xUserRootCommit.is() )
1347cdf0e10cSrcweir                 m_xUserRootCommit->commit();
1348cdf0e10cSrcweir         }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir         m_bModified = sal_False;
1351cdf0e10cSrcweir     }
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir void ImageManagerImpl::storeToStorage( const uno::Reference< XStorage >& Storage )
1355cdf0e10cSrcweir throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1356cdf0e10cSrcweir {
1357cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir     if ( m_bDisposed )
1360cdf0e10cSrcweir         throw DisposedException();
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir     if ( m_bModified && Storage.is() )
1363cdf0e10cSrcweir     {
1364cdf0e10cSrcweir         long nModes = ElementModes::READWRITE;
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir         uno::Reference< XStorage > xUserImageStorage = Storage->openStorageElement( OUString::createFromAscii( IMAGE_FOLDER ),
1367cdf0e10cSrcweir                                                                                     nModes );
1368cdf0e10cSrcweir         if ( xUserImageStorage.is() )
1369cdf0e10cSrcweir         {
1370cdf0e10cSrcweir             uno::Reference< XStorage > xUserBitmapsStorage = xUserImageStorage->openStorageElement( OUString::createFromAscii( BITMAPS_FOLDER ),
1371cdf0e10cSrcweir                                                                                                     nModes );
1372cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < ImageType_COUNT; i++ )
1373cdf0e10cSrcweir             {
1374cdf0e10cSrcweir                 implts_getUserImageList( (ImageType)i );
1375cdf0e10cSrcweir                 implts_storeUserImages( (ImageType)i, xUserImageStorage, xUserBitmapsStorage );
1376cdf0e10cSrcweir             }
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir             uno::Reference< XTransactedObject > xTransaction( Storage, UNO_QUERY );
1379cdf0e10cSrcweir 			if ( xTransaction.is() )
1380cdf0e10cSrcweir             	xTransaction->commit();
1381cdf0e10cSrcweir         }
1382cdf0e10cSrcweir     }
1383cdf0e10cSrcweir }
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir sal_Bool ImageManagerImpl::isModified()
1386cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
1387cdf0e10cSrcweir {
1388cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1389cdf0e10cSrcweir     return m_bModified;
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir sal_Bool ImageManagerImpl::isReadOnly() throw (::com::sun::star::uno::RuntimeException)
1393cdf0e10cSrcweir {
1394cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1395cdf0e10cSrcweir     return m_bReadOnly;
1396cdf0e10cSrcweir }
1397cdf0e10cSrcweir // XUIConfiguration
1398cdf0e10cSrcweir void ImageManagerImpl::addConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
1399cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
1400cdf0e10cSrcweir {
1401cdf0e10cSrcweir     {
1402cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir         /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1405cdf0e10cSrcweir         if ( m_bDisposed )
1406cdf0e10cSrcweir             throw DisposedException();
1407cdf0e10cSrcweir     }
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir     m_aListenerContainer.addInterface( ::getCppuType( ( const uno::Reference< XUIConfigurationListener >* ) NULL ), xListener );
1410cdf0e10cSrcweir }
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir void ImageManagerImpl::removeConfigurationListener( const uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener )
1413cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
1414cdf0e10cSrcweir {
1415cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1416cdf0e10cSrcweir     m_aListenerContainer.removeInterface( ::getCppuType( ( const uno::Reference< XUIConfigurationListener >* ) NULL ), xListener );
1417cdf0e10cSrcweir }
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir 
1420cdf0e10cSrcweir void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& aEvent, NotifyOp eOp )
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
1423cdf0e10cSrcweir                                         ::getCppuType( ( const css::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >*) NULL ) );
1424cdf0e10cSrcweir     if ( pContainer != NULL )
1425cdf0e10cSrcweir 	{
1426cdf0e10cSrcweir         ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
1427cdf0e10cSrcweir         while ( pIterator.hasMoreElements() )
1428cdf0e10cSrcweir         {
1429cdf0e10cSrcweir             try
1430cdf0e10cSrcweir             {
1431cdf0e10cSrcweir                 switch ( eOp )
1432cdf0e10cSrcweir                 {
1433cdf0e10cSrcweir                     case NotifyOp_Replace:
1434cdf0e10cSrcweir                         ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementReplaced( aEvent );
1435cdf0e10cSrcweir                         break;
1436cdf0e10cSrcweir                     case NotifyOp_Insert:
1437cdf0e10cSrcweir                         ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementInserted( aEvent );
1438cdf0e10cSrcweir                         break;
1439cdf0e10cSrcweir                     case NotifyOp_Remove:
1440cdf0e10cSrcweir                         ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementRemoved( aEvent );
1441cdf0e10cSrcweir                         break;
1442cdf0e10cSrcweir                 }
1443cdf0e10cSrcweir             }
1444cdf0e10cSrcweir             catch( css::uno::RuntimeException& )
1445cdf0e10cSrcweir             {
1446cdf0e10cSrcweir                 pIterator.remove();
1447cdf0e10cSrcweir             }
1448cdf0e10cSrcweir         }
1449cdf0e10cSrcweir 	}
1450cdf0e10cSrcweir }
1451cdf0e10cSrcweir void ImageManagerImpl::clear()
1452cdf0e10cSrcweir {
1453cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1454cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < ImageType_COUNT; n++ )
1455cdf0e10cSrcweir     {
1456cdf0e10cSrcweir         delete m_pUserImageList[n];
1457cdf0e10cSrcweir         m_pUserImageList[n] = 0;
1458cdf0e10cSrcweir     }
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir } // namespace framework
1461