merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / uiconfiguration / windowstateconfiguration.cxx
blob4ac316b73ab019b0feb22557adc4bd06b2011dbf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 //_________________________________________________________________________________________________________________
32 // my own includes
33 //_________________________________________________________________________________________________________________
34 #include "uiconfiguration/windowstateconfiguration.hxx"
35 #include <threadhelp/resetableguard.hxx>
36 #include "services.h"
38 //_________________________________________________________________________________________________________________
39 // interface includes
40 //_________________________________________________________________________________________________________________
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/container/XNameContainer.hpp>
45 #include <com/sun/star/container/XContainer.hpp>
46 #include <com/sun/star/awt/Point.hpp>
47 #include <com/sun/star/awt/Size.hpp>
48 #include <com/sun/star/ui/DockingArea.hpp>
49 #include <com/sun/star/util/XChangesBatch.hpp>
51 //_________________________________________________________________________________________________________________
52 // includes of other projects
53 //_________________________________________________________________________________________________________________
54 #include <rtl/ustrbuf.hxx>
55 #include <cppuhelper/weak.hxx>
56 #include <tools/debug.hxx>
58 //_________________________________________________________________________________________________________________
59 // Defines
60 //_________________________________________________________________________________________________________________
63 using namespace com::sun::star::uno;
64 using namespace com::sun::star::lang;
65 using namespace com::sun::star::beans;
66 using namespace com::sun::star::util;
67 using namespace com::sun::star::container;
68 using namespace ::com::sun::star::frame;
69 using namespace ::com::sun::star::ui;
71 //_________________________________________________________________________________________________________________
72 // Namespace
73 //_________________________________________________________________________________________________________________
76 static const char CONFIGURATION_ROOT_ACCESS[] = "/org.openoffice.Office.UI.";
77 static const char CONFIGURATION_WINDOWSTATE_ACCESS[] = "/UIElements/States";
79 static const char CONFIGURATION_PROPERTY_LOCKED[] = WINDOWSTATE_PROPERTY_LOCKED;
80 static const char CONFIGURATION_PROPERTY_DOCKED[] = WINDOWSTATE_PROPERTY_DOCKED;
81 static const char CONFIGURATION_PROPERTY_VISIBLE[] = WINDOWSTATE_PROPERTY_VISIBLE;
82 static const char CONFIGURATION_PROPERTY_DOCKINGAREA[] = WINDOWSTATE_PROPERTY_DOCKINGAREA;
83 static const char CONFIGURATION_PROPERTY_DOCKPOS[] = WINDOWSTATE_PROPERTY_DOCKPOS;
84 static const char CONFIGURATION_PROPERTY_DOCKSIZE[] = WINDOWSTATE_PROPERTY_DOCKSIZE;
85 static const char CONFIGURATION_PROPERTY_POS[] = WINDOWSTATE_PROPERTY_POS;
86 static const char CONFIGURATION_PROPERTY_SIZE[] = WINDOWSTATE_PROPERTY_SIZE;
87 static const char CONFIGURATION_PROPERTY_UINAME[] = WINDOWSTATE_PROPERTY_UINAME;
88 static const char CONFIGURATION_PROPERTY_INTERNALSTATE[] = WINDOWSTATE_PROPERTY_INTERNALSTATE;
89 static const char CONFIGURATION_PROPERTY_STYLE[] = WINDOWSTATE_PROPERTY_STYLE;
90 static const char CONFIGURATION_PROPERTY_CONTEXT[] = WINDOWSTATE_PROPERTY_CONTEXT;
91 static const char CONFIGURATION_PROPERTY_HIDEFROMMENU[] = WINDOWSTATE_PROPERTY_HIDEFROMENU;
92 static const char CONFIGURATION_PROPERTY_NOCLOSE[] = WINDOWSTATE_PROPERTY_NOCLOSE;
93 static const char CONFIGURATION_PROPERTY_SOFTCLOSE[] = WINDOWSTATE_PROPERTY_SOFTCLOSE;
94 static const char CONFIGURATION_PROPERTY_CONTEXTACTIVE[] = WINDOWSTATE_PROPERTY_CONTEXTACTIVE;
96 // Zero based indexes, order must be the same as WindowStateMask && CONFIGURATION_PROPERTIES!
97 static const sal_Int16 PROPERTY_LOCKED = 0;
98 static const sal_Int16 PROPERTY_DOCKED = 1;
99 static const sal_Int16 PROPERTY_VISIBLE = 2;
100 static const sal_Int16 PROPERTY_CONTEXT = 3;
101 static const sal_Int16 PROPERTY_HIDEFROMMENU = 4;
102 static const sal_Int16 PROPERTY_NOCLOSE = 5;
103 static const sal_Int16 PROPERTY_SOFTCLOSE = 6;
104 static const sal_Int16 PROPERTY_CONTEXTACTIVE = 7;
105 static const sal_Int16 PROPERTY_DOCKINGAREA = 8;
106 static const sal_Int16 PROPERTY_POS = 9;
107 static const sal_Int16 PROPERTY_SIZE = 10;
108 static const sal_Int16 PROPERTY_UINAME = 11;
109 static const sal_Int16 PROPERTY_INTERNALSTATE = 12;
110 static const sal_Int16 PROPERTY_STYLE = 13;
111 static const sal_Int16 PROPERTY_DOCKPOS = 14;
112 static const sal_Int16 PROPERTY_DOCKSIZE = 15;
114 // Order must be the same as WindowStateMask!!
115 static const char* CONFIGURATION_PROPERTIES[] =
117 CONFIGURATION_PROPERTY_LOCKED,
118 CONFIGURATION_PROPERTY_DOCKED,
119 CONFIGURATION_PROPERTY_VISIBLE,
120 CONFIGURATION_PROPERTY_CONTEXT,
121 CONFIGURATION_PROPERTY_HIDEFROMMENU,
122 CONFIGURATION_PROPERTY_NOCLOSE,
123 CONFIGURATION_PROPERTY_SOFTCLOSE,
124 CONFIGURATION_PROPERTY_CONTEXTACTIVE,
125 CONFIGURATION_PROPERTY_DOCKINGAREA,
126 CONFIGURATION_PROPERTY_POS,
127 CONFIGURATION_PROPERTY_SIZE,
128 CONFIGURATION_PROPERTY_UINAME,
129 CONFIGURATION_PROPERTY_INTERNALSTATE,
130 CONFIGURATION_PROPERTY_STYLE,
131 CONFIGURATION_PROPERTY_DOCKPOS,
132 CONFIGURATION_PROPERTY_DOCKSIZE,
136 namespace framework
139 //*****************************************************************************************************************
140 // Configuration access class for WindowState supplier implementation
141 //*****************************************************************************************************************
143 class ConfigurationAccess_WindowState : // interfaces
144 public XTypeProvider ,
145 public XNameContainer ,
146 public XContainerListener ,
147 // baseclasses
148 // Order is neccessary for right initialization!
149 private ThreadHelpBase ,
150 public ::cppu::OWeakObject
152 public:
153 ConfigurationAccess_WindowState( const ::rtl::OUString& aWindowStateConfigFile, const Reference< XMultiServiceFactory >& rServiceManager );
154 virtual ~ConfigurationAccess_WindowState();
156 // XInterface, XTypeProvider
157 FWK_DECLARE_XINTERFACE
158 FWK_DECLARE_XTYPEPROVIDER
160 // XNameAccess
161 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
162 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
164 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
165 throw (::com::sun::star::uno::RuntimeException);
167 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
168 throw (::com::sun::star::uno::RuntimeException);
170 // XNameContainer
171 virtual void SAL_CALL removeByName( const ::rtl::OUString& sName )
172 throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException );
174 virtual void SAL_CALL insertByName( const ::rtl::OUString& sName, const css::uno::Any& aPropertySet )
175 throw(css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, css::uno::RuntimeException );
177 // XNameReplace
178 virtual void SAL_CALL replaceByName( const ::rtl::OUString& sName, const css::uno::Any& aPropertySet )
179 throw(css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException );
181 // XElementAccess
182 virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
183 throw (::com::sun::star::uno::RuntimeException);
185 virtual sal_Bool SAL_CALL hasElements()
186 throw (::com::sun::star::uno::RuntimeException);
188 // container.XContainerListener
189 virtual void SAL_CALL elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException);
190 virtual void SAL_CALL elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException);
191 virtual void SAL_CALL elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException);
193 // lang.XEventListener
194 virtual void SAL_CALL disposing( const EventObject& aEvent ) throw(RuntimeException);
196 protected:
197 enum WindowStateMask
199 WINDOWSTATE_MASK_LOCKED = 1,
200 WINDOWSTATE_MASK_DOCKED = 2,
201 WINDOWSTATE_MASK_VISIBLE = 4,
202 WINDOWSTATE_MASK_CONTEXT = 8,
203 WINDOWSTATE_MASK_HIDEFROMMENU = 16,
204 WINDOWSTATE_MASK_NOCLOSE = 32,
205 WINDOWSTATE_MASK_SOFTCLOSE = 64,
206 WINDOWSTATE_MASK_CONTEXTACTIVE = 128,
207 WINDOWSTATE_MASK_DOCKINGAREA = 256,
208 WINDOWSTATE_MASK_POS = 512,
209 WINDOWSTATE_MASK_SIZE = 1024,
210 WINDOWSTATE_MASK_UINAME = 2048,
211 WINDOWSTATE_MASK_INTERNALSTATE = 4096,
212 WINDOWSTATE_MASK_STYLE = 8192,
213 WINDOWSTATE_MASK_DOCKPOS = 16384,
214 WINDOWSTATE_MASK_DOCKSIZE = 32768
217 // Cache structure. Valid values are described by tje eMask member. All other values should not be
218 // provided to outside code!
219 struct WindowStateInfo
221 WindowStateInfo() : aDockingArea( ::com::sun::star::ui::DockingArea_DOCKINGAREA_TOP ),
222 aDockPos( 0, 0 ),
223 aPos( 0, 0 ),
224 aSize( 0, 0 ),
225 nInternalState( 0 ),
226 nStyle( 0 ),
227 nMask( 0 ) {}
229 bool bLocked : 1,
230 bDocked : 1,
231 bVisible : 1,
232 bContext : 1,
233 bHideFromMenu : 1,
234 bNoClose : 1,
235 bSoftClose : 1,
236 bContextActive : 1;
237 ::com::sun::star::ui::DockingArea aDockingArea;
238 com::sun::star::awt::Point aDockPos;
239 com::sun::star::awt::Size aDockSize;
240 com::sun::star::awt::Point aPos;
241 com::sun::star::awt::Size aSize;
242 rtl::OUString aUIName;
243 sal_uInt32 nInternalState;
244 sal_uInt16 nStyle;
245 sal_uInt32 nMask; // see WindowStateMask
248 void impl_putPropertiesFromStruct( const WindowStateInfo& rWinStateInfo, Reference< XPropertySet >& xPropSet );
249 Any impl_insertCacheAndReturnSequence( const rtl::OUString& rResourceURL, Reference< XNameAccess >& rNameAccess );
250 WindowStateInfo& impl_insertCacheAndReturnWinState( const rtl::OUString& rResourceURL, Reference< XNameAccess >& rNameAccess );
251 Any impl_getSequenceFromStruct( const WindowStateInfo& rWinStateInfo );
252 void impl_fillStructFromSequence( WindowStateInfo& rWinStateInfo, const Sequence< PropertyValue >& rSeq );
253 Any impl_getWindowStateFromResourceURL( const rtl::OUString& rResourceURL );
254 sal_Bool impl_initializeConfigAccess();
256 private:
257 typedef ::std::hash_map< ::rtl::OUString,
258 WindowStateInfo,
259 OUStringHashCode,
260 ::std::equal_to< ::rtl::OUString > > ResourceURLToInfoCache;
262 rtl::OUString m_aConfigWindowAccess;
263 Reference< XMultiServiceFactory > m_xServiceManager;
264 Reference< XMultiServiceFactory > m_xConfigProvider;
265 Reference< XNameAccess > m_xConfigAccess;
266 ResourceURLToInfoCache m_aResourceURLToInfoCache;
267 sal_Bool m_bConfigAccessInitialized : 1,
268 m_bModified : 1;
269 std::vector< ::rtl::OUString > m_aPropArray;
272 //*****************************************************************************************************************
273 // XInterface, XTypeProvider
274 //*****************************************************************************************************************
275 DEFINE_XINTERFACE_7 ( ConfigurationAccess_WindowState ,
276 OWeakObject ,
277 DIRECT_INTERFACE ( css::container::XNameContainer ),
278 DIRECT_INTERFACE ( css::container::XContainerListener ),
279 DIRECT_INTERFACE ( css::lang::XTypeProvider ),
280 DERIVED_INTERFACE( css::container::XElementAccess, css::container::XNameAccess ),
281 DERIVED_INTERFACE( css::container::XNameAccess, css::container::XNameReplace ),
282 DERIVED_INTERFACE( css::container::XNameReplace, css::container::XNameContainer ),
283 DERIVED_INTERFACE( css::lang::XEventListener, XContainerListener )
286 DEFINE_XTYPEPROVIDER_7 ( ConfigurationAccess_WindowState ,
287 css::container::XNameContainer ,
288 css::container::XNameReplace ,
289 css::container::XNameAccess ,
290 css::container::XElementAccess ,
291 css::container::XContainerListener ,
292 css::lang::XEventListener ,
293 css::lang::XTypeProvider
296 ConfigurationAccess_WindowState::ConfigurationAccess_WindowState( const rtl::OUString& aModuleName, const Reference< XMultiServiceFactory >& rServiceManager ) :
297 ThreadHelpBase(),
298 m_aConfigWindowAccess( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_ROOT_ACCESS )),
299 m_xServiceManager( rServiceManager ),
300 m_bConfigAccessInitialized( sal_False ),
301 m_bModified( sal_False )
303 // Create configuration hierachical access name
304 m_aConfigWindowAccess += aModuleName;
305 m_aConfigWindowAccess += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_WINDOWSTATE_ACCESS ));
306 m_xConfigProvider = Reference< XMultiServiceFactory >( rServiceManager->createInstance( SERVICENAME_CFGPROVIDER ), UNO_QUERY );
308 // Initialize access array with property names.
309 sal_Int32 n = 0;
310 while ( CONFIGURATION_PROPERTIES[n] )
312 m_aPropArray.push_back( ::rtl::OUString::createFromAscii( CONFIGURATION_PROPERTIES[n] ));
313 ++n;
317 ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState()
319 // SAFE
320 ResetableGuard aLock( m_aLock );
321 Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
322 if ( xContainer.is() )
323 xContainer->removeContainerListener( this );
326 // XNameAccess
327 Any SAL_CALL ConfigurationAccess_WindowState::getByName( const ::rtl::OUString& rResourceURL )
328 throw ( NoSuchElementException, WrappedTargetException, RuntimeException)
330 // SAFE
331 ResetableGuard aLock( m_aLock );
333 ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
334 if ( pIter != m_aResourceURLToInfoCache.end() )
335 return impl_getSequenceFromStruct( pIter->second );
336 else
338 Any a( impl_getWindowStateFromResourceURL( rResourceURL ) );
339 if ( a == Any() )
340 throw NoSuchElementException();
341 else
342 return a;
346 Sequence< ::rtl::OUString > SAL_CALL ConfigurationAccess_WindowState::getElementNames()
347 throw ( RuntimeException )
349 // SAFE
350 ResetableGuard aLock( m_aLock );
352 if ( !m_bConfigAccessInitialized )
354 impl_initializeConfigAccess();
355 m_bConfigAccessInitialized = sal_True;
358 if ( m_xConfigAccess.is() )
359 return m_xConfigAccess->getElementNames();
360 else
361 return Sequence< ::rtl::OUString > ();
364 sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasByName( const ::rtl::OUString& rResourceURL )
365 throw (::com::sun::star::uno::RuntimeException)
369 getByName( rResourceURL );
371 catch ( NoSuchElementException& )
373 return sal_False;
376 return sal_True;
379 // XElementAccess
380 Type SAL_CALL ConfigurationAccess_WindowState::getElementType()
381 throw ( RuntimeException )
383 return( ::getCppuType( (const Sequence< PropertyValue >*)NULL ) );
386 sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasElements()
387 throw ( RuntimeException )
389 // SAFE
390 ResetableGuard aLock( m_aLock );
392 if ( !m_bConfigAccessInitialized )
394 impl_initializeConfigAccess();
395 m_bConfigAccessInitialized = sal_True;
398 if ( m_xConfigAccess.is() )
399 return m_xConfigAccess->hasElements();
400 else
401 return sal_False;
404 // XNameContainer
405 void SAL_CALL ConfigurationAccess_WindowState::removeByName( const ::rtl::OUString& rResourceURL )
406 throw( NoSuchElementException, WrappedTargetException, RuntimeException )
408 // SAFE
409 ResetableGuard aLock( m_aLock );
411 ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
412 if ( pIter != m_aResourceURLToInfoCache.end() )
413 m_aResourceURLToInfoCache.erase( pIter );
415 if ( !m_bConfigAccessInitialized )
417 impl_initializeConfigAccess();
418 m_bConfigAccessInitialized = sal_True;
423 // Remove must be write-through => remove element from configuration
424 Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
425 if ( xNameContainer.is() )
427 aLock.unlock();
429 xNameContainer->removeByName( rResourceURL );
430 Reference< XChangesBatch > xFlush( m_xConfigAccess, UNO_QUERY );
431 if ( xFlush.is() )
432 xFlush->commitChanges();
435 catch ( com::sun::star::lang::WrappedTargetException& )
440 void SAL_CALL ConfigurationAccess_WindowState::insertByName( const ::rtl::OUString& rResourceURL, const css::uno::Any& aPropertySet )
441 throw( IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException )
443 // SAFE
444 ResetableGuard aLock( m_aLock );
446 Sequence< PropertyValue > aPropSet;
447 if ( aPropertySet >>= aPropSet )
449 ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
450 if ( pIter != m_aResourceURLToInfoCache.end() )
451 throw ElementExistException();
452 else
454 if ( !m_bConfigAccessInitialized )
456 impl_initializeConfigAccess();
457 m_bConfigAccessInitialized = sal_True;
460 // Try to ask our configuration access
461 if ( m_xConfigAccess.is() )
463 if ( m_xConfigAccess->hasByName( rResourceURL ) )
464 throw ElementExistException();
465 else
467 WindowStateInfo aWinStateInfo;
468 impl_fillStructFromSequence( aWinStateInfo, aPropSet );
469 m_aResourceURLToInfoCache.insert( ResourceURLToInfoCache::value_type( rResourceURL, aWinStateInfo ));
471 // insert must be write-through => insert element into configuration
472 Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
473 if ( xNameContainer.is() )
475 Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY );
476 aLock.unlock();
480 Reference< XPropertySet > xPropSet( xFactory->createInstance(), UNO_QUERY );
481 if ( xPropSet.is() )
483 Any a;
484 impl_putPropertiesFromStruct( aWinStateInfo, xPropSet );
485 a <<= xPropSet;
486 xNameContainer->insertByName( rResourceURL, a );
487 Reference< XChangesBatch > xFlush( xFactory, UNO_QUERY );
488 if ( xFlush.is() )
489 xFlush->commitChanges();
492 catch ( Exception& )
500 else
501 throw IllegalArgumentException();
504 // XNameReplace
505 void SAL_CALL ConfigurationAccess_WindowState::replaceByName( const ::rtl::OUString& rResourceURL, const css::uno::Any& aPropertySet )
506 throw( IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException )
508 // SAFE
509 ResetableGuard aLock( m_aLock );
511 Sequence< PropertyValue > aPropSet;
512 if ( aPropertySet >>= aPropSet )
514 ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
515 if ( pIter != m_aResourceURLToInfoCache.end() )
517 WindowStateInfo& rWinStateInfo = pIter->second;
518 impl_fillStructFromSequence( rWinStateInfo, aPropSet );
519 m_bModified = sal_True;
521 else
523 if ( !m_bConfigAccessInitialized )
525 impl_initializeConfigAccess();
526 m_bConfigAccessInitialized = sal_True;
529 // Try to ask our configuration access
530 Reference< XNameAccess > xNameAccess;
531 Any a( m_xConfigAccess->getByName( rResourceURL ));
533 if ( a >>= xNameAccess )
535 WindowStateInfo& rWinStateInfo( impl_insertCacheAndReturnWinState( rResourceURL, xNameAccess ));
536 impl_fillStructFromSequence( rWinStateInfo, aPropSet );
537 m_bModified = sal_True;
538 pIter = m_aResourceURLToInfoCache.find( rResourceURL );
540 else
541 throw NoSuchElementException();
544 if ( m_bModified && pIter != m_aResourceURLToInfoCache.end() )
546 Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
547 if ( xNameContainer.is() )
549 WindowStateInfo aWinStateInfo( pIter->second );
550 ::rtl::OUString aResourceURL( pIter->first );
551 m_bModified = sal_False;
552 aLock.unlock();
556 Reference< XPropertySet > xPropSet;
557 if ( xNameContainer->getByName( aResourceURL ) >>= xPropSet )
559 impl_putPropertiesFromStruct( aWinStateInfo, xPropSet );
561 Reference< XChangesBatch > xFlush( m_xConfigAccess, UNO_QUERY );
562 if ( xFlush.is() )
563 xFlush->commitChanges();
566 catch ( Exception& )
572 else
573 throw IllegalArgumentException();
576 // container.XContainerListener
577 void SAL_CALL ConfigurationAccess_WindowState::elementInserted( const ContainerEvent& ) throw(RuntimeException)
579 // do nothing - next time someone wants to retrieve this node we will find it in the configuration
582 void SAL_CALL ConfigurationAccess_WindowState::elementRemoved ( const ContainerEvent& ) throw(RuntimeException)
587 void SAL_CALL ConfigurationAccess_WindowState::elementReplaced( const ContainerEvent& ) throw(RuntimeException)
592 // lang.XEventListener
593 void SAL_CALL ConfigurationAccess_WindowState::disposing( const EventObject& aEvent ) throw(RuntimeException)
595 // SAFE
596 // remove our reference to the config access
597 ResetableGuard aLock( m_aLock );
599 Reference< XInterface > xIfac1( aEvent.Source, UNO_QUERY );
600 Reference< XInterface > xIfac2( m_xConfigAccess, UNO_QUERY );
601 if ( xIfac1 == xIfac2 )
602 m_xConfigAccess.clear();
605 // private helper methods
606 Any ConfigurationAccess_WindowState::impl_getSequenceFromStruct( const WindowStateInfo& rWinStateInfo )
608 sal_Int32 i( 0 );
609 sal_Int32 nCount( m_aPropArray.size() );
610 Sequence< PropertyValue > aPropSeq;
612 for ( i = 0; i < nCount; i++ )
614 if ( rWinStateInfo.nMask & ( 1 << i ))
616 // put value into the return sequence
617 sal_Int32 nIndex( aPropSeq.getLength());
618 aPropSeq.realloc( nIndex+1 );
619 aPropSeq[nIndex].Name = m_aPropArray[i];
621 switch ( i )
623 case PROPERTY_LOCKED:
624 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bLocked ); break;
625 case PROPERTY_DOCKED:
626 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bDocked ); break;
627 case PROPERTY_VISIBLE:
628 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bVisible ); break;
629 case PROPERTY_CONTEXT:
630 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bContext ); break;
631 case PROPERTY_HIDEFROMMENU:
632 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bHideFromMenu ); break;
633 case PROPERTY_NOCLOSE:
634 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bNoClose ); break;
635 case PROPERTY_SOFTCLOSE:
636 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bSoftClose ); break;
637 case PROPERTY_CONTEXTACTIVE:
638 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bContextActive ); break;
639 case PROPERTY_DOCKINGAREA:
640 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aDockingArea ); break;
641 case PROPERTY_POS:
642 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aPos ); break;
643 case PROPERTY_SIZE:
644 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aSize ); break;
645 case PROPERTY_UINAME:
646 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aUIName ); break;
647 case PROPERTY_INTERNALSTATE:
648 aPropSeq[nIndex].Value = makeAny( sal_Int32( rWinStateInfo.nInternalState )); break;
649 case PROPERTY_STYLE:
650 aPropSeq[nIndex].Value = makeAny( sal_Int16( rWinStateInfo.nStyle )); break;
651 case PROPERTY_DOCKPOS:
652 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aDockPos ); break;
653 case PROPERTY_DOCKSIZE:
654 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aDockSize ); break;
655 default:
656 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
661 return makeAny( aPropSeq );
664 Any ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const rtl::OUString& rResourceURL, Reference< XNameAccess >& xNameAccess )
666 sal_Int32 nMask( 0 );
667 sal_Int32 nCount( m_aPropArray.size() );
668 sal_Int32 i( 0 );
669 sal_Int32 nIndex( 0 );
670 Sequence< PropertyValue > aPropSeq;
671 WindowStateInfo aWindowStateInfo;
673 for ( i = 0; i < nCount; i++ )
677 bool bAddToSeq( false );
678 Any a( xNameAccess->getByName( m_aPropArray[i] ) );
679 switch ( i )
681 case PROPERTY_LOCKED:
682 case PROPERTY_DOCKED:
683 case PROPERTY_VISIBLE:
684 case PROPERTY_CONTEXT:
685 case PROPERTY_HIDEFROMMENU:
686 case PROPERTY_NOCLOSE:
687 case PROPERTY_SOFTCLOSE:
688 case PROPERTY_CONTEXTACTIVE:
690 sal_Bool bValue = sal_Bool();
691 if ( a >>= bValue )
693 sal_Int32 nValue( 1 << i );
694 nMask |= nValue;
695 bAddToSeq = true;
696 switch ( i )
698 case PROPERTY_LOCKED:
699 aWindowStateInfo.bLocked = bValue; break;
700 case PROPERTY_DOCKED:
701 aWindowStateInfo.bDocked = bValue; break;
702 case PROPERTY_VISIBLE:
703 aWindowStateInfo.bVisible = bValue; break;
704 case PROPERTY_CONTEXT:
705 aWindowStateInfo.bContext = bValue; break;
706 case PROPERTY_HIDEFROMMENU:
707 aWindowStateInfo.bHideFromMenu = bValue; break;
708 case PROPERTY_NOCLOSE:
709 aWindowStateInfo.bNoClose = bValue; break;
710 case PROPERTY_SOFTCLOSE:
711 aWindowStateInfo.bSoftClose = bValue; break;
712 case PROPERTY_CONTEXTACTIVE:
713 aWindowStateInfo.bContextActive = bValue; break;
717 break;
719 case PROPERTY_DOCKINGAREA:
721 sal_Int32 nDockingArea = 0;
722 if ( a >>= nDockingArea )
724 if (( nDockingArea >= 0 ) &&
725 ( nDockingArea <= sal_Int32( DockingArea_DOCKINGAREA_RIGHT )))
727 aWindowStateInfo.aDockingArea = (DockingArea)nDockingArea;
728 nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
729 a = makeAny( aWindowStateInfo.aDockingArea );
730 bAddToSeq = true;
734 break;
736 case PROPERTY_POS:
737 case PROPERTY_DOCKPOS:
739 ::rtl::OUString aString;
740 if ( a >>= aString )
742 sal_Int32 nToken( 0 );
743 ::rtl::OUString aXStr = aString.getToken( 0, ',', nToken );
744 if ( nToken > 0 )
746 com::sun::star::awt::Point aPos;
747 aPos.X = aXStr.toInt32();
748 aPos.Y = aString.getToken( 0, ',', nToken ).toInt32();
750 if ( i == PROPERTY_POS )
752 aWindowStateInfo.aPos = aPos;
753 nMask |= WINDOWSTATE_MASK_POS;
755 else
757 aWindowStateInfo.aDockPos = aPos;
758 nMask |= WINDOWSTATE_MASK_DOCKPOS;
761 a <<= aPos;
762 bAddToSeq = true;
766 break;
768 case PROPERTY_SIZE:
769 case PROPERTY_DOCKSIZE:
771 ::rtl::OUString aString;
772 if ( a >>= aString )
774 sal_Int32 nToken( 0 );
775 ::rtl::OUString aStr = aString.getToken( 0, ',', nToken );
776 if ( nToken > 0 )
778 com::sun::star::awt::Size aSize;
779 aSize.Width = aStr.toInt32();
780 aSize.Height = aString.getToken( 0, ',', nToken ).toInt32();
781 if ( i == PROPERTY_SIZE )
783 aWindowStateInfo.aSize = aSize;
784 nMask |= WINDOWSTATE_MASK_SIZE;
786 else
788 aWindowStateInfo.aDockSize = aSize;
789 nMask |= WINDOWSTATE_MASK_DOCKSIZE;
792 a <<= aSize;
793 bAddToSeq = true;
797 break;
799 case PROPERTY_UINAME:
801 ::rtl::OUString aValue;
802 if ( a >>= aValue )
804 nMask |= WINDOWSTATE_MASK_UINAME;
805 aWindowStateInfo.aUIName = aValue;
806 bAddToSeq = true;
809 break;
811 case PROPERTY_INTERNALSTATE:
813 sal_uInt32 nValue = 0;
814 if ( a >>= nValue )
816 nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
817 aWindowStateInfo.nInternalState = nValue;
818 bAddToSeq = true;
821 break;
823 case PROPERTY_STYLE:
825 sal_Int32 nValue = 0;
826 if ( a >>= nValue )
828 nMask |= WINDOWSTATE_MASK_STYLE;
829 aWindowStateInfo.nStyle = sal_uInt16( nValue );
830 bAddToSeq = true;
833 break;
835 default:
836 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
839 if ( bAddToSeq )
841 // put value into the return sequence
842 nIndex = aPropSeq.getLength();
843 aPropSeq.realloc( nIndex+1 );
844 aPropSeq[nIndex].Name = m_aPropArray[i];
845 aPropSeq[nIndex].Value = a;
848 catch( com::sun::star::container::NoSuchElementException& )
851 catch ( com::sun::star::lang::WrappedTargetException& )
856 aWindowStateInfo.nMask = nMask;
857 m_aResourceURLToInfoCache.insert( ResourceURLToInfoCache::value_type( rResourceURL, aWindowStateInfo ));
858 return makeAny( aPropSeq );
861 ConfigurationAccess_WindowState::WindowStateInfo& ConfigurationAccess_WindowState::impl_insertCacheAndReturnWinState( const rtl::OUString& rResourceURL, Reference< XNameAccess >& rNameAccess )
863 sal_Int32 nMask( 0 );
864 sal_Int32 nCount( m_aPropArray.size() );
865 sal_Int32 i( 0 );
866 Sequence< PropertyValue > aPropSeq;
867 WindowStateInfo aWindowStateInfo;
869 for ( i = 0; i < nCount; i++ )
873 Any a( rNameAccess->getByName( m_aPropArray[i] ) );
874 switch ( i )
876 case PROPERTY_LOCKED:
877 case PROPERTY_DOCKED:
878 case PROPERTY_VISIBLE:
879 case PROPERTY_CONTEXT:
880 case PROPERTY_HIDEFROMMENU:
881 case PROPERTY_NOCLOSE:
882 case PROPERTY_SOFTCLOSE:
883 case PROPERTY_CONTEXTACTIVE:
885 sal_Bool bValue = sal_Bool();
886 if ( a >>= bValue )
888 sal_Int32 nValue( 1 << i );
889 nMask |= nValue;
890 switch ( i )
892 case PROPERTY_LOCKED:
893 aWindowStateInfo.bLocked = bValue; break;
894 case PROPERTY_DOCKED:
895 aWindowStateInfo.bDocked = bValue; break;
896 case PROPERTY_VISIBLE:
897 aWindowStateInfo.bVisible = bValue; break;
898 case PROPERTY_CONTEXT:
899 aWindowStateInfo.bContext = bValue; break;
900 case PROPERTY_HIDEFROMMENU:
901 aWindowStateInfo.bHideFromMenu = bValue; break;
902 case PROPERTY_NOCLOSE:
903 aWindowStateInfo.bNoClose = bValue; break;
904 case PROPERTY_SOFTCLOSE:
905 aWindowStateInfo.bNoClose = bValue; break;
906 case PROPERTY_CONTEXTACTIVE:
907 aWindowStateInfo.bContextActive = bValue; break;
908 default:
909 DBG_ASSERT( sal_False, "Unknown boolean property in WindowState found!" );
913 break;
915 case PROPERTY_DOCKINGAREA:
917 sal_Int32 nDockingArea = 0;
918 if ( a >>= nDockingArea )
920 if (( nDockingArea >= 0 ) &&
921 ( nDockingArea <= sal_Int32( DockingArea_DOCKINGAREA_RIGHT )))
923 aWindowStateInfo.aDockingArea = (DockingArea)nDockingArea;
924 nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
928 break;
930 case PROPERTY_POS:
931 case PROPERTY_DOCKPOS:
933 ::rtl::OUString aString;
934 if ( a >>= aString )
936 sal_Int32 nToken( 0 );
937 ::rtl::OUString aXStr = aString.getToken( 0, ',', nToken );
938 if ( nToken > 0 )
940 com::sun::star::awt::Point aPos;
941 aPos.X = aXStr.toInt32();
942 aPos.Y = aString.getToken( 0, ',', nToken ).toInt32();
944 if ( i == PROPERTY_POS )
946 aWindowStateInfo.aPos = aPos;
947 nMask |= WINDOWSTATE_MASK_POS;
949 else
951 aWindowStateInfo.aDockPos = aPos;
952 nMask |= WINDOWSTATE_MASK_DOCKPOS;
957 break;
959 case PROPERTY_SIZE:
960 case PROPERTY_DOCKSIZE:
962 ::rtl::OUString aString;
963 if ( a >>= aString )
965 sal_Int32 nToken( 0 );
966 ::rtl::OUString aStr = aString.getToken( 0, ',', nToken );
967 if ( nToken > 0 )
969 com::sun::star::awt::Size aSize;
970 aSize.Width = aStr.toInt32();
971 aSize.Height = aString.getToken( 0, ',', nToken ).toInt32();
972 if ( i == PROPERTY_SIZE )
974 aWindowStateInfo.aSize = aSize;
975 nMask |= WINDOWSTATE_MASK_SIZE;
977 else
979 aWindowStateInfo.aDockSize = aSize;
980 nMask |= WINDOWSTATE_MASK_DOCKSIZE;
985 break;
987 case PROPERTY_UINAME:
989 ::rtl::OUString aValue;
990 if ( a >>= aValue )
992 nMask |= WINDOWSTATE_MASK_UINAME;
993 aWindowStateInfo.aUIName = aValue;
996 break;
998 case PROPERTY_INTERNALSTATE:
1000 sal_Int32 nValue = 0;
1001 if ( a >>= nValue )
1003 nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
1004 aWindowStateInfo.nInternalState = sal_uInt32( nValue );
1007 break;
1009 case PROPERTY_STYLE:
1011 sal_Int32 nValue = 0;
1012 if ( a >>= nValue )
1014 nMask |= WINDOWSTATE_MASK_STYLE;
1015 aWindowStateInfo.nStyle = sal_uInt16( nValue );
1019 default:
1020 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1023 catch( com::sun::star::container::NoSuchElementException& )
1026 catch ( com::sun::star::lang::WrappedTargetException& )
1031 aWindowStateInfo.nMask = nMask;
1032 ResourceURLToInfoCache::iterator pIter = (m_aResourceURLToInfoCache.insert( ResourceURLToInfoCache::value_type( rResourceURL, aWindowStateInfo ))).first;
1033 return pIter->second;
1036 Any ConfigurationAccess_WindowState::impl_getWindowStateFromResourceURL( const rtl::OUString& rResourceURL )
1038 if ( !m_bConfigAccessInitialized )
1040 impl_initializeConfigAccess();
1041 m_bConfigAccessInitialized = sal_True;
1046 // Try to ask our configuration access
1047 if ( m_xConfigAccess.is() )
1049 Reference< XNameAccess > xNameAccess;
1050 Any a( m_xConfigAccess->getByName( rResourceURL ));
1052 if ( a >>= xNameAccess )
1053 return impl_insertCacheAndReturnSequence( rResourceURL, xNameAccess );
1056 catch( com::sun::star::container::NoSuchElementException& )
1059 catch ( com::sun::star::lang::WrappedTargetException& )
1063 return Any();
1066 void ConfigurationAccess_WindowState::impl_fillStructFromSequence( WindowStateInfo& rWinStateInfo, const Sequence< PropertyValue >& rSeq )
1068 sal_Int32 nCompareCount( m_aPropArray.size() );
1069 sal_Int32 nCount( rSeq.getLength() );
1070 sal_Int32 i( 0 );
1072 for ( i = 0; i < nCount; i++ )
1074 for ( sal_Int32 j = 0; j < nCompareCount; j++ )
1076 if ( rSeq[i].Name.equals( m_aPropArray[j] ))
1078 switch ( j )
1080 case PROPERTY_LOCKED:
1081 case PROPERTY_DOCKED:
1082 case PROPERTY_VISIBLE:
1083 case PROPERTY_CONTEXT:
1084 case PROPERTY_HIDEFROMMENU:
1085 case PROPERTY_NOCLOSE:
1086 case PROPERTY_SOFTCLOSE:
1087 case PROPERTY_CONTEXTACTIVE:
1089 sal_Bool bValue = sal_Bool();
1090 if ( rSeq[i].Value >>= bValue )
1092 sal_Int32 nValue( 1 << j );
1093 rWinStateInfo.nMask |= nValue;
1094 switch ( j )
1096 case PROPERTY_LOCKED:
1097 rWinStateInfo.bLocked = bValue;
1098 break;
1099 case PROPERTY_DOCKED:
1100 rWinStateInfo.bDocked = bValue;
1101 break;
1102 case PROPERTY_VISIBLE:
1103 rWinStateInfo.bVisible = bValue;
1104 break;
1105 case PROPERTY_CONTEXT:
1106 rWinStateInfo.bContext = bValue;
1107 break;
1108 case PROPERTY_HIDEFROMMENU:
1109 rWinStateInfo.bHideFromMenu = bValue;
1110 break;
1111 case PROPERTY_NOCLOSE:
1112 rWinStateInfo.bNoClose = bValue;
1113 break;
1114 case PROPERTY_SOFTCLOSE:
1115 rWinStateInfo.bSoftClose = bValue;
1116 break;
1117 case PROPERTY_CONTEXTACTIVE:
1118 rWinStateInfo.bContextActive = bValue;
1119 break;
1120 default:
1121 DBG_ASSERT( sal_False, "Unknown boolean property in WindowState found!" );
1125 break;
1127 case PROPERTY_DOCKINGAREA:
1129 ::com::sun::star::ui::DockingArea eDockingArea;
1130 if ( rSeq[i].Value >>= eDockingArea )
1132 rWinStateInfo.aDockingArea = eDockingArea;
1133 rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
1136 break;
1138 case PROPERTY_POS:
1139 case PROPERTY_DOCKPOS:
1141 com::sun::star::awt::Point aPoint;
1142 if ( rSeq[i].Value >>= aPoint )
1144 if ( j == PROPERTY_POS )
1146 rWinStateInfo.aPos = aPoint;
1147 rWinStateInfo.nMask |= WINDOWSTATE_MASK_POS;
1149 else
1151 rWinStateInfo.aDockPos = aPoint;
1152 rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKPOS;
1156 break;
1158 case PROPERTY_SIZE:
1159 case PROPERTY_DOCKSIZE:
1161 com::sun::star::awt::Size aSize;
1162 if ( rSeq[i].Value >>= aSize )
1164 if ( j == PROPERTY_SIZE )
1166 rWinStateInfo.aSize = aSize;
1167 rWinStateInfo.nMask |= WINDOWSTATE_MASK_SIZE;
1169 else
1171 rWinStateInfo.aDockSize = aSize;
1172 rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKSIZE;
1176 break;
1178 case PROPERTY_UINAME:
1180 ::rtl::OUString aValue;
1181 if ( rSeq[i].Value >>= aValue )
1183 rWinStateInfo.aUIName = aValue;
1184 rWinStateInfo.nMask |= WINDOWSTATE_MASK_UINAME;
1187 break;
1189 case PROPERTY_INTERNALSTATE:
1191 sal_Int32 nValue = 0;
1192 if ( rSeq[i].Value >>= nValue )
1194 rWinStateInfo.nInternalState = sal_uInt32( nValue );
1195 rWinStateInfo.nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
1198 break;
1200 case PROPERTY_STYLE:
1202 sal_Int32 nValue = 0;
1203 if ( rSeq[i].Value >>= nValue )
1205 rWinStateInfo.nStyle = sal_uInt16( nValue );
1206 rWinStateInfo.nMask |= WINDOWSTATE_MASK_STYLE;
1209 break;
1211 default:
1212 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1215 break;
1221 void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const WindowStateInfo& rWinStateInfo, Reference< XPropertySet >& xPropSet )
1223 sal_Int32 i( 0 );
1224 sal_Int32 nCount( m_aPropArray.size() );
1225 Sequence< PropertyValue > aPropSeq;
1226 ::rtl::OUString aDelim( ::rtl::OUString::createFromAscii( "," ));
1228 for ( i = 0; i < nCount; i++ )
1230 if ( rWinStateInfo.nMask & ( 1 << i ))
1234 // put values into the property set
1235 switch ( i )
1237 case PROPERTY_LOCKED:
1238 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bLocked )) ); break;
1239 case PROPERTY_DOCKED:
1240 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bDocked )) ); break;
1241 case PROPERTY_VISIBLE:
1242 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bVisible )) ); break;
1243 case PROPERTY_CONTEXT:
1244 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bContext )) ); break;
1245 case PROPERTY_HIDEFROMMENU:
1246 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bHideFromMenu )) ); break;
1247 case PROPERTY_NOCLOSE:
1248 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bNoClose )) ); break;
1249 case PROPERTY_SOFTCLOSE:
1250 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bSoftClose )) ); break;
1251 case PROPERTY_CONTEXTACTIVE:
1252 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bContextActive )) ); break;
1253 case PROPERTY_DOCKINGAREA:
1254 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int16( rWinStateInfo.aDockingArea ) ) ); break;
1255 case PROPERTY_POS:
1256 case PROPERTY_DOCKPOS:
1258 ::rtl::OUString aPosStr;
1259 if ( i == PROPERTY_POS )
1260 aPosStr = ::rtl::OUString::valueOf( rWinStateInfo.aPos.X );
1261 else
1262 aPosStr = ::rtl::OUString::valueOf( rWinStateInfo.aDockPos.X );
1263 aPosStr += aDelim;
1264 if ( i == PROPERTY_POS )
1265 aPosStr += ::rtl::OUString::valueOf( rWinStateInfo.aPos.Y );
1266 else
1267 aPosStr += ::rtl::OUString::valueOf( rWinStateInfo.aDockPos.Y );
1268 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( aPosStr ) );
1269 break;
1271 case PROPERTY_SIZE:
1272 case PROPERTY_DOCKSIZE:
1274 ::rtl::OUString aSizeStr;
1275 if ( i == PROPERTY_SIZE )
1276 aSizeStr = ( ::rtl::OUString::valueOf( rWinStateInfo.aSize.Width ));
1277 else
1278 aSizeStr = ( ::rtl::OUString::valueOf( rWinStateInfo.aDockSize.Width ));
1279 aSizeStr += aDelim;
1280 if ( i == PROPERTY_SIZE )
1281 aSizeStr += ::rtl::OUString::valueOf( rWinStateInfo.aSize.Height );
1282 else
1283 aSizeStr += ::rtl::OUString::valueOf( rWinStateInfo.aDockSize.Height );
1284 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( aSizeStr ) );
1285 break;
1287 case PROPERTY_UINAME:
1288 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.aUIName ) ); break;
1289 case PROPERTY_INTERNALSTATE:
1290 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int32( rWinStateInfo.nInternalState )) ); break;
1291 case PROPERTY_STYLE:
1292 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int32( rWinStateInfo.nStyle )) ); break;
1293 default:
1294 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1297 catch( Exception& )
1304 sal_Bool ConfigurationAccess_WindowState::impl_initializeConfigAccess()
1306 Sequence< Any > aArgs( 2 );
1307 PropertyValue aPropValue;
1311 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
1312 aPropValue.Value <<= m_aConfigWindowAccess;
1313 aArgs[0] <<= aPropValue;
1314 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ));
1315 aPropValue.Value <<= sal_True;
1316 aArgs[1] <<= aPropValue;
1318 m_xConfigAccess = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(
1319 SERVICENAME_CFGUPDATEACCESS, aArgs ),
1320 UNO_QUERY );
1321 if ( m_xConfigAccess.is() )
1323 // Add as container listener
1324 Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
1325 if ( xContainer.is() )
1326 xContainer->addContainerListener( this );
1329 return sal_True;
1331 catch ( WrappedTargetException& )
1334 catch ( Exception& )
1338 return sal_False;
1342 //*****************************************************************************************************************
1343 // XInterface, XTypeProvider, XServiceInfo
1344 //*****************************************************************************************************************
1345 DEFINE_XINTERFACE_4 ( WindowStateConfiguration ,
1346 OWeakObject ,
1347 DIRECT_INTERFACE( css::lang::XTypeProvider ),
1348 DIRECT_INTERFACE( css::lang::XServiceInfo ),
1349 DIRECT_INTERFACE( css::container::XNameAccess ),
1350 DERIVED_INTERFACE( css::container::XElementAccess, css::container::XNameAccess )
1353 DEFINE_XTYPEPROVIDER_4 ( WindowStateConfiguration ,
1354 css::lang::XTypeProvider ,
1355 css::lang::XServiceInfo ,
1356 css::container::XNameAccess ,
1357 css::container::XElementAccess
1360 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( WindowStateConfiguration ,
1361 ::cppu::OWeakObject ,
1362 SERVICENAME_WINDOWSTATECONFIGURATION ,
1363 IMPLEMENTATIONNAME_WINDOWSTATECONFIGURATION
1366 DEFINE_INIT_SERVICE ( WindowStateConfiguration, {} )
1368 WindowStateConfiguration::WindowStateConfiguration( const Reference< XMultiServiceFactory >& xServiceManager ) :
1369 ThreadHelpBase(),
1370 m_xServiceManager( xServiceManager )
1372 m_xModuleManager = Reference< XModuleManager >( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ),
1373 UNO_QUERY );
1374 Reference< XNameAccess > xEmptyNameAccess;
1375 Reference< XNameAccess > xNameAccess( m_xModuleManager, UNO_QUERY_THROW );
1376 Sequence< rtl::OUString > aElementNames = xNameAccess->getElementNames();
1377 Sequence< PropertyValue > aSeq;
1378 ::rtl::OUString aModuleIdentifier;
1380 for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
1382 aModuleIdentifier = aElementNames[i];
1383 if ( xNameAccess->getByName( aModuleIdentifier ) >>= aSeq )
1385 ::rtl::OUString aWindowStateFileStr;
1386 for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
1388 if ( aSeq[y].Name.equalsAscii("ooSetupFactoryWindowStateConfigRef") )
1390 aSeq[y].Value >>= aWindowStateFileStr;
1391 break;
1395 if ( aWindowStateFileStr.getLength() > 0 )
1397 // Create first mapping ModuleIdentifier ==> Window state configuration file
1398 m_aModuleToFileHashMap.insert( ModuleToWindowStateFileMap::value_type( aModuleIdentifier, aWindowStateFileStr ));
1400 // Create second mapping Command File ==> Window state configuration instance
1401 ModuleToWindowStateConfigHashMap::iterator pIter = m_aModuleToWindowStateHashMap.find( aWindowStateFileStr );
1402 if ( pIter == m_aModuleToWindowStateHashMap.end() )
1403 m_aModuleToWindowStateHashMap.insert( ModuleToWindowStateConfigHashMap::value_type( aWindowStateFileStr, xEmptyNameAccess ));
1409 WindowStateConfiguration::~WindowStateConfiguration()
1411 ResetableGuard aLock( m_aLock );
1412 m_aModuleToFileHashMap.clear();
1413 m_aModuleToWindowStateHashMap.clear();
1416 Any SAL_CALL WindowStateConfiguration::getByName( const ::rtl::OUString& aModuleIdentifier )
1417 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1419 ResetableGuard aLock( m_aLock );
1421 ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aModuleIdentifier );
1422 if ( pIter != m_aModuleToFileHashMap.end() )
1424 Any a;
1425 ::rtl::OUString aWindowStateConfigFile( pIter->second );
1427 ModuleToWindowStateConfigHashMap::iterator pModuleIter = m_aModuleToWindowStateHashMap.find( aWindowStateConfigFile );
1428 if ( pModuleIter != m_aModuleToWindowStateHashMap.end() )
1430 if ( pModuleIter->second.is() )
1431 a = makeAny( pModuleIter->second );
1432 else
1434 Reference< XNameAccess > xResourceURLWindowState;
1435 ConfigurationAccess_WindowState* pModuleWindowState = new ConfigurationAccess_WindowState( aWindowStateConfigFile, m_xServiceManager );
1436 xResourceURLWindowState = Reference< XNameAccess >( static_cast< cppu::OWeakObject* >( pModuleWindowState ),UNO_QUERY );
1437 pModuleIter->second = xResourceURLWindowState;
1438 a <<= xResourceURLWindowState;
1441 return a;
1445 throw NoSuchElementException();
1448 Sequence< ::rtl::OUString > SAL_CALL WindowStateConfiguration::getElementNames()
1449 throw (::com::sun::star::uno::RuntimeException)
1451 ResetableGuard aLock( m_aLock );
1453 Sequence< rtl::OUString > aSeq( m_aModuleToFileHashMap.size() );
1455 sal_Int32 n = 0;
1456 ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.begin();
1457 while ( pIter != m_aModuleToFileHashMap.end() )
1459 aSeq[n] = pIter->first;
1460 ++pIter;
1463 return aSeq;
1466 sal_Bool SAL_CALL WindowStateConfiguration::hasByName( const ::rtl::OUString& aName )
1467 throw (::com::sun::star::uno::RuntimeException)
1469 ResetableGuard aLock( m_aLock );
1471 ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aName );
1472 return ( pIter != m_aModuleToFileHashMap.end() );
1475 // XElementAccess
1476 Type SAL_CALL WindowStateConfiguration::getElementType()
1477 throw (::com::sun::star::uno::RuntimeException)
1479 return( ::getCppuType( (const Reference< XNameAccess >*)NULL ) );
1482 sal_Bool SAL_CALL WindowStateConfiguration::hasElements()
1483 throw (::com::sun::star::uno::RuntimeException)
1485 // We always have at least one module. So it is valid to return true!
1486 return sal_True;
1489 } // namespace framework