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