update dev300-m58
[ooovba.git] / framework / source / uiconfiguration / windowstateconfiguration.cxx
blobc97caecc01bfa9c600f302dfcd74e75024c51cbc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: windowstateconfiguration.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
37 #include "uiconfiguration/windowstateconfiguration.hxx"
38 #include <threadhelp/resetableguard.hxx>
39 #include "services.h"
41 //_________________________________________________________________________________________________________________
42 // interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/beans/PropertyValue.hpp>
45 #include <com/sun/star/beans/XPropertySet.hpp>
46 #include <com/sun/star/container/XNameAccess.hpp>
47 #include <com/sun/star/container/XNameContainer.hpp>
48 #include <com/sun/star/container/XContainer.hpp>
49 #include <com/sun/star/awt/Point.hpp>
50 #include <com/sun/star/awt/Size.hpp>
51 #include <com/sun/star/ui/DockingArea.hpp>
52 #include <com/sun/star/util/XChangesBatch.hpp>
54 //_________________________________________________________________________________________________________________
55 // includes of other projects
56 //_________________________________________________________________________________________________________________
57 #include <rtl/ustrbuf.hxx>
58 #include <cppuhelper/weak.hxx>
59 #include <tools/debug.hxx>
61 //_________________________________________________________________________________________________________________
62 // Defines
63 //_________________________________________________________________________________________________________________
66 using namespace com::sun::star::uno;
67 using namespace com::sun::star::lang;
68 using namespace com::sun::star::beans;
69 using namespace com::sun::star::util;
70 using namespace com::sun::star::container;
71 using namespace ::com::sun::star::frame;
72 using namespace ::com::sun::star::ui;
74 //_________________________________________________________________________________________________________________
75 // Namespace
76 //_________________________________________________________________________________________________________________
79 static const char CONFIGURATION_ROOT_ACCESS[] = "/org.openoffice.Office.UI.";
80 static const char CONFIGURATION_WINDOWSTATE_ACCESS[] = "/UIElements/States";
82 static const char CONFIGURATION_PROPERTY_LOCKED[] = WINDOWSTATE_PROPERTY_LOCKED;
83 static const char CONFIGURATION_PROPERTY_DOCKED[] = WINDOWSTATE_PROPERTY_DOCKED;
84 static const char CONFIGURATION_PROPERTY_VISIBLE[] = WINDOWSTATE_PROPERTY_VISIBLE;
85 static const char CONFIGURATION_PROPERTY_DOCKINGAREA[] = WINDOWSTATE_PROPERTY_DOCKINGAREA;
86 static const char CONFIGURATION_PROPERTY_DOCKPOS[] = WINDOWSTATE_PROPERTY_DOCKPOS;
87 static const char CONFIGURATION_PROPERTY_DOCKSIZE[] = WINDOWSTATE_PROPERTY_DOCKSIZE;
88 static const char CONFIGURATION_PROPERTY_POS[] = WINDOWSTATE_PROPERTY_POS;
89 static const char CONFIGURATION_PROPERTY_SIZE[] = WINDOWSTATE_PROPERTY_SIZE;
90 static const char CONFIGURATION_PROPERTY_UINAME[] = WINDOWSTATE_PROPERTY_UINAME;
91 static const char CONFIGURATION_PROPERTY_INTERNALSTATE[] = WINDOWSTATE_PROPERTY_INTERNALSTATE;
92 static const char CONFIGURATION_PROPERTY_STYLE[] = WINDOWSTATE_PROPERTY_STYLE;
93 static const char CONFIGURATION_PROPERTY_CONTEXT[] = WINDOWSTATE_PROPERTY_CONTEXT;
94 static const char CONFIGURATION_PROPERTY_HIDEFROMMENU[] = WINDOWSTATE_PROPERTY_HIDEFROMENU;
95 static const char CONFIGURATION_PROPERTY_NOCLOSE[] = WINDOWSTATE_PROPERTY_NOCLOSE;
96 static const char CONFIGURATION_PROPERTY_SOFTCLOSE[] = WINDOWSTATE_PROPERTY_SOFTCLOSE;
97 static const char CONFIGURATION_PROPERTY_CONTEXTACTIVE[] = WINDOWSTATE_PROPERTY_CONTEXTACTIVE;
99 // Zero based indexes, order must be the same as WindowStateMask && CONFIGURATION_PROPERTIES!
100 static const sal_Int16 PROPERTY_LOCKED = 0;
101 static const sal_Int16 PROPERTY_DOCKED = 1;
102 static const sal_Int16 PROPERTY_VISIBLE = 2;
103 static const sal_Int16 PROPERTY_CONTEXT = 3;
104 static const sal_Int16 PROPERTY_HIDEFROMMENU = 4;
105 static const sal_Int16 PROPERTY_NOCLOSE = 5;
106 static const sal_Int16 PROPERTY_SOFTCLOSE = 6;
107 static const sal_Int16 PROPERTY_CONTEXTACTIVE = 7;
108 static const sal_Int16 PROPERTY_DOCKINGAREA = 8;
109 static const sal_Int16 PROPERTY_POS = 9;
110 static const sal_Int16 PROPERTY_SIZE = 10;
111 static const sal_Int16 PROPERTY_UINAME = 11;
112 static const sal_Int16 PROPERTY_INTERNALSTATE = 12;
113 static const sal_Int16 PROPERTY_STYLE = 13;
114 static const sal_Int16 PROPERTY_DOCKPOS = 14;
115 static const sal_Int16 PROPERTY_DOCKSIZE = 15;
117 // Order must be the same as WindowStateMask!!
118 static const char* CONFIGURATION_PROPERTIES[] =
120 CONFIGURATION_PROPERTY_LOCKED,
121 CONFIGURATION_PROPERTY_DOCKED,
122 CONFIGURATION_PROPERTY_VISIBLE,
123 CONFIGURATION_PROPERTY_CONTEXT,
124 CONFIGURATION_PROPERTY_HIDEFROMMENU,
125 CONFIGURATION_PROPERTY_NOCLOSE,
126 CONFIGURATION_PROPERTY_SOFTCLOSE,
127 CONFIGURATION_PROPERTY_CONTEXTACTIVE,
128 CONFIGURATION_PROPERTY_DOCKINGAREA,
129 CONFIGURATION_PROPERTY_POS,
130 CONFIGURATION_PROPERTY_SIZE,
131 CONFIGURATION_PROPERTY_UINAME,
132 CONFIGURATION_PROPERTY_INTERNALSTATE,
133 CONFIGURATION_PROPERTY_STYLE,
134 CONFIGURATION_PROPERTY_DOCKPOS,
135 CONFIGURATION_PROPERTY_DOCKSIZE,
139 namespace framework
142 //*****************************************************************************************************************
143 // Configuration access class for WindowState supplier implementation
144 //*****************************************************************************************************************
146 class ConfigurationAccess_WindowState : // interfaces
147 public XTypeProvider ,
148 public XNameContainer ,
149 public XContainerListener ,
150 // baseclasses
151 // Order is neccessary for right initialization!
152 private ThreadHelpBase ,
153 public ::cppu::OWeakObject
155 public:
156 ConfigurationAccess_WindowState( const ::rtl::OUString& aWindowStateConfigFile, const Reference< XMultiServiceFactory >& rServiceManager );
157 virtual ~ConfigurationAccess_WindowState();
159 // XInterface, XTypeProvider
160 FWK_DECLARE_XINTERFACE
161 FWK_DECLARE_XTYPEPROVIDER
163 // XNameAccess
164 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
165 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
167 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
168 throw (::com::sun::star::uno::RuntimeException);
170 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
171 throw (::com::sun::star::uno::RuntimeException);
173 // XNameContainer
174 virtual void SAL_CALL removeByName( const ::rtl::OUString& sName )
175 throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException );
177 virtual void SAL_CALL insertByName( const ::rtl::OUString& sName, const css::uno::Any& aPropertySet )
178 throw(css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, css::uno::RuntimeException );
180 // XNameReplace
181 virtual void SAL_CALL replaceByName( const ::rtl::OUString& sName, const css::uno::Any& aPropertySet )
182 throw(css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException );
184 // XElementAccess
185 virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
186 throw (::com::sun::star::uno::RuntimeException);
188 virtual sal_Bool SAL_CALL hasElements()
189 throw (::com::sun::star::uno::RuntimeException);
191 // container.XContainerListener
192 virtual void SAL_CALL elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException);
193 virtual void SAL_CALL elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException);
194 virtual void SAL_CALL elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException);
196 // lang.XEventListener
197 virtual void SAL_CALL disposing( const EventObject& aEvent ) throw(RuntimeException);
199 protected:
200 enum WindowStateMask
202 WINDOWSTATE_MASK_LOCKED = 1,
203 WINDOWSTATE_MASK_DOCKED = 2,
204 WINDOWSTATE_MASK_VISIBLE = 4,
205 WINDOWSTATE_MASK_CONTEXT = 8,
206 WINDOWSTATE_MASK_HIDEFROMMENU = 16,
207 WINDOWSTATE_MASK_NOCLOSE = 32,
208 WINDOWSTATE_MASK_SOFTCLOSE = 64,
209 WINDOWSTATE_MASK_CONTEXTACTIVE = 128,
210 WINDOWSTATE_MASK_DOCKINGAREA = 256,
211 WINDOWSTATE_MASK_POS = 512,
212 WINDOWSTATE_MASK_SIZE = 1024,
213 WINDOWSTATE_MASK_UINAME = 2048,
214 WINDOWSTATE_MASK_INTERNALSTATE = 4096,
215 WINDOWSTATE_MASK_STYLE = 8192,
216 WINDOWSTATE_MASK_DOCKPOS = 16384,
217 WINDOWSTATE_MASK_DOCKSIZE = 32768
220 // Cache structure. Valid values are described by tje eMask member. All other values should not be
221 // provided to outside code!
222 struct WindowStateInfo
224 WindowStateInfo() : aDockingArea( ::com::sun::star::ui::DockingArea_DOCKINGAREA_TOP ),
225 aDockPos( 0, 0 ),
226 aPos( 0, 0 ),
227 aSize( 0, 0 ),
228 nInternalState( 0 ),
229 nStyle( 0 ),
230 nMask( 0 ) {}
232 bool bLocked : 1,
233 bDocked : 1,
234 bVisible : 1,
235 bContext : 1,
236 bHideFromMenu : 1,
237 bNoClose : 1,
238 bSoftClose : 1,
239 bContextActive : 1;
240 ::com::sun::star::ui::DockingArea aDockingArea;
241 com::sun::star::awt::Point aDockPos;
242 com::sun::star::awt::Size aDockSize;
243 com::sun::star::awt::Point aPos;
244 com::sun::star::awt::Size aSize;
245 rtl::OUString aUIName;
246 sal_uInt32 nInternalState;
247 sal_uInt16 nStyle;
248 sal_uInt32 nMask; // see WindowStateMask
251 void impl_putPropertiesFromStruct( const WindowStateInfo& rWinStateInfo, Reference< XPropertySet >& xPropSet );
252 Any impl_insertCacheAndReturnSequence( const rtl::OUString& rResourceURL, Reference< XNameAccess >& rNameAccess );
253 WindowStateInfo& impl_insertCacheAndReturnWinState( const rtl::OUString& rResourceURL, Reference< XNameAccess >& rNameAccess );
254 Any impl_getSequenceFromStruct( const WindowStateInfo& rWinStateInfo );
255 void impl_fillStructFromSequence( WindowStateInfo& rWinStateInfo, const Sequence< PropertyValue >& rSeq );
256 Any impl_getWindowStateFromResourceURL( const rtl::OUString& rResourceURL );
257 sal_Bool impl_initializeConfigAccess();
259 private:
260 typedef ::std::hash_map< ::rtl::OUString,
261 WindowStateInfo,
262 OUStringHashCode,
263 ::std::equal_to< ::rtl::OUString > > ResourceURLToInfoCache;
265 rtl::OUString m_aConfigWindowAccess;
266 Reference< XMultiServiceFactory > m_xServiceManager;
267 Reference< XMultiServiceFactory > m_xConfigProvider;
268 Reference< XNameAccess > m_xConfigAccess;
269 ResourceURLToInfoCache m_aResourceURLToInfoCache;
270 sal_Bool m_bConfigAccessInitialized : 1,
271 m_bModified : 1;
272 std::vector< ::rtl::OUString > m_aPropArray;
275 //*****************************************************************************************************************
276 // XInterface, XTypeProvider
277 //*****************************************************************************************************************
278 DEFINE_XINTERFACE_7 ( ConfigurationAccess_WindowState ,
279 OWeakObject ,
280 DIRECT_INTERFACE ( css::container::XNameContainer ),
281 DIRECT_INTERFACE ( css::container::XContainerListener ),
282 DIRECT_INTERFACE ( css::lang::XTypeProvider ),
283 DERIVED_INTERFACE( css::container::XElementAccess, css::container::XNameAccess ),
284 DERIVED_INTERFACE( css::container::XNameAccess, css::container::XNameReplace ),
285 DERIVED_INTERFACE( css::container::XNameReplace, css::container::XNameContainer ),
286 DERIVED_INTERFACE( css::lang::XEventListener, XContainerListener )
289 DEFINE_XTYPEPROVIDER_7 ( ConfigurationAccess_WindowState ,
290 css::container::XNameContainer ,
291 css::container::XNameReplace ,
292 css::container::XNameAccess ,
293 css::container::XElementAccess ,
294 css::container::XContainerListener ,
295 css::lang::XEventListener ,
296 css::lang::XTypeProvider
299 ConfigurationAccess_WindowState::ConfigurationAccess_WindowState( const rtl::OUString& aModuleName, const Reference< XMultiServiceFactory >& rServiceManager ) :
300 ThreadHelpBase(),
301 m_aConfigWindowAccess( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_ROOT_ACCESS )),
302 m_xServiceManager( rServiceManager ),
303 m_bConfigAccessInitialized( sal_False ),
304 m_bModified( sal_False )
306 // Create configuration hierachical access name
307 m_aConfigWindowAccess += aModuleName;
308 m_aConfigWindowAccess += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_WINDOWSTATE_ACCESS ));
309 m_xConfigProvider = Reference< XMultiServiceFactory >( rServiceManager->createInstance( SERVICENAME_CFGPROVIDER ), UNO_QUERY );
311 // Initialize access array with property names.
312 sal_Int32 n = 0;
313 while ( CONFIGURATION_PROPERTIES[n] )
315 m_aPropArray.push_back( ::rtl::OUString::createFromAscii( CONFIGURATION_PROPERTIES[n] ));
316 ++n;
320 ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState()
322 // SAFE
323 ResetableGuard aLock( m_aLock );
324 Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
325 if ( xContainer.is() )
326 xContainer->removeContainerListener( this );
329 // XNameAccess
330 Any SAL_CALL ConfigurationAccess_WindowState::getByName( const ::rtl::OUString& rResourceURL )
331 throw ( NoSuchElementException, WrappedTargetException, RuntimeException)
333 // SAFE
334 ResetableGuard aLock( m_aLock );
336 ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
337 if ( pIter != m_aResourceURLToInfoCache.end() )
338 return impl_getSequenceFromStruct( pIter->second );
339 else
341 Any a( impl_getWindowStateFromResourceURL( rResourceURL ) );
342 if ( a == Any() )
343 throw NoSuchElementException();
344 else
345 return a;
349 Sequence< ::rtl::OUString > SAL_CALL ConfigurationAccess_WindowState::getElementNames()
350 throw ( RuntimeException )
352 // SAFE
353 ResetableGuard aLock( m_aLock );
355 if ( !m_bConfigAccessInitialized )
357 impl_initializeConfigAccess();
358 m_bConfigAccessInitialized = sal_True;
361 if ( m_xConfigAccess.is() )
362 return m_xConfigAccess->getElementNames();
363 else
364 return Sequence< ::rtl::OUString > ();
367 sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasByName( const ::rtl::OUString& rResourceURL )
368 throw (::com::sun::star::uno::RuntimeException)
372 getByName( rResourceURL );
374 catch ( NoSuchElementException& )
376 return sal_False;
379 return sal_True;
382 // XElementAccess
383 Type SAL_CALL ConfigurationAccess_WindowState::getElementType()
384 throw ( RuntimeException )
386 return( ::getCppuType( (const Sequence< PropertyValue >*)NULL ) );
389 sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasElements()
390 throw ( RuntimeException )
392 // SAFE
393 ResetableGuard aLock( m_aLock );
395 if ( !m_bConfigAccessInitialized )
397 impl_initializeConfigAccess();
398 m_bConfigAccessInitialized = sal_True;
401 if ( m_xConfigAccess.is() )
402 return m_xConfigAccess->hasElements();
403 else
404 return sal_False;
407 // XNameContainer
408 void SAL_CALL ConfigurationAccess_WindowState::removeByName( const ::rtl::OUString& rResourceURL )
409 throw( NoSuchElementException, WrappedTargetException, RuntimeException )
411 // SAFE
412 ResetableGuard aLock( m_aLock );
414 ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
415 if ( pIter != m_aResourceURLToInfoCache.end() )
416 m_aResourceURLToInfoCache.erase( pIter );
418 if ( !m_bConfigAccessInitialized )
420 impl_initializeConfigAccess();
421 m_bConfigAccessInitialized = sal_True;
426 // Remove must be write-through => remove element from configuration
427 Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
428 if ( xNameContainer.is() )
430 aLock.unlock();
432 xNameContainer->removeByName( rResourceURL );
433 Reference< XChangesBatch > xFlush( m_xConfigAccess, UNO_QUERY );
434 if ( xFlush.is() )
435 xFlush->commitChanges();
438 catch ( com::sun::star::lang::WrappedTargetException& )
443 void SAL_CALL ConfigurationAccess_WindowState::insertByName( const ::rtl::OUString& rResourceURL, const css::uno::Any& aPropertySet )
444 throw( IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException )
446 // SAFE
447 ResetableGuard aLock( m_aLock );
449 Sequence< PropertyValue > aPropSet;
450 if ( aPropertySet >>= aPropSet )
452 ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
453 if ( pIter != m_aResourceURLToInfoCache.end() )
454 throw ElementExistException();
455 else
457 if ( !m_bConfigAccessInitialized )
459 impl_initializeConfigAccess();
460 m_bConfigAccessInitialized = sal_True;
463 // Try to ask our configuration access
464 if ( m_xConfigAccess.is() )
466 if ( m_xConfigAccess->hasByName( rResourceURL ) )
467 throw ElementExistException();
468 else
470 WindowStateInfo aWinStateInfo;
471 impl_fillStructFromSequence( aWinStateInfo, aPropSet );
472 m_aResourceURLToInfoCache.insert( ResourceURLToInfoCache::value_type( rResourceURL, aWinStateInfo ));
474 // insert must be write-through => insert element into configuration
475 Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
476 if ( xNameContainer.is() )
478 Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY );
479 aLock.unlock();
483 Reference< XPropertySet > xPropSet( xFactory->createInstance(), UNO_QUERY );
484 if ( xPropSet.is() )
486 Any a;
487 impl_putPropertiesFromStruct( aWinStateInfo, xPropSet );
488 a <<= xPropSet;
489 xNameContainer->insertByName( rResourceURL, a );
490 Reference< XChangesBatch > xFlush( xFactory, UNO_QUERY );
491 if ( xFlush.is() )
492 xFlush->commitChanges();
495 catch ( Exception& )
503 else
504 throw IllegalArgumentException();
507 // XNameReplace
508 void SAL_CALL ConfigurationAccess_WindowState::replaceByName( const ::rtl::OUString& rResourceURL, const css::uno::Any& aPropertySet )
509 throw( IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException )
511 // SAFE
512 ResetableGuard aLock( m_aLock );
514 Sequence< PropertyValue > aPropSet;
515 if ( aPropertySet >>= aPropSet )
517 ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL );
518 if ( pIter != m_aResourceURLToInfoCache.end() )
520 WindowStateInfo& rWinStateInfo = pIter->second;
521 impl_fillStructFromSequence( rWinStateInfo, aPropSet );
522 m_bModified = sal_True;
524 else
526 if ( !m_bConfigAccessInitialized )
528 impl_initializeConfigAccess();
529 m_bConfigAccessInitialized = sal_True;
532 // Try to ask our configuration access
533 Reference< XNameAccess > xNameAccess;
534 Any a( m_xConfigAccess->getByName( rResourceURL ));
536 if ( a >>= xNameAccess )
538 WindowStateInfo& rWinStateInfo( impl_insertCacheAndReturnWinState( rResourceURL, xNameAccess ));
539 impl_fillStructFromSequence( rWinStateInfo, aPropSet );
540 m_bModified = sal_True;
541 pIter = m_aResourceURLToInfoCache.find( rResourceURL );
543 else
544 throw NoSuchElementException();
547 if ( m_bModified && pIter != m_aResourceURLToInfoCache.end() )
549 Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY );
550 if ( xNameContainer.is() )
552 WindowStateInfo aWinStateInfo( pIter->second );
553 ::rtl::OUString aResourceURL( pIter->first );
554 m_bModified = sal_False;
555 aLock.unlock();
559 Reference< XPropertySet > xPropSet;
560 if ( xNameContainer->getByName( aResourceURL ) >>= xPropSet )
562 impl_putPropertiesFromStruct( aWinStateInfo, xPropSet );
564 Reference< XChangesBatch > xFlush( m_xConfigAccess, UNO_QUERY );
565 if ( xFlush.is() )
566 xFlush->commitChanges();
569 catch ( Exception& )
575 else
576 throw IllegalArgumentException();
579 // container.XContainerListener
580 void SAL_CALL ConfigurationAccess_WindowState::elementInserted( const ContainerEvent& ) throw(RuntimeException)
582 // do nothing - next time someone wants to retrieve this node we will find it in the configuration
585 void SAL_CALL ConfigurationAccess_WindowState::elementRemoved ( const ContainerEvent& ) throw(RuntimeException)
590 void SAL_CALL ConfigurationAccess_WindowState::elementReplaced( const ContainerEvent& ) throw(RuntimeException)
595 // lang.XEventListener
596 void SAL_CALL ConfigurationAccess_WindowState::disposing( const EventObject& aEvent ) throw(RuntimeException)
598 // SAFE
599 // remove our reference to the config access
600 ResetableGuard aLock( m_aLock );
602 Reference< XInterface > xIfac1( aEvent.Source, UNO_QUERY );
603 Reference< XInterface > xIfac2( m_xConfigAccess, UNO_QUERY );
604 if ( xIfac1 == xIfac2 )
605 m_xConfigAccess.clear();
608 // private helper methods
609 Any ConfigurationAccess_WindowState::impl_getSequenceFromStruct( const WindowStateInfo& rWinStateInfo )
611 sal_Int32 i( 0 );
612 sal_Int32 nCount( m_aPropArray.size() );
613 Sequence< PropertyValue > aPropSeq;
615 for ( i = 0; i < nCount; i++ )
617 if ( rWinStateInfo.nMask & ( 1 << i ))
619 // put value into the return sequence
620 sal_Int32 nIndex( aPropSeq.getLength());
621 aPropSeq.realloc( nIndex+1 );
622 aPropSeq[nIndex].Name = m_aPropArray[i];
624 switch ( i )
626 case PROPERTY_LOCKED:
627 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bLocked ); break;
628 case PROPERTY_DOCKED:
629 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bDocked ); break;
630 case PROPERTY_VISIBLE:
631 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bVisible ); break;
632 case PROPERTY_CONTEXT:
633 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bContext ); break;
634 case PROPERTY_HIDEFROMMENU:
635 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bHideFromMenu ); break;
636 case PROPERTY_NOCLOSE:
637 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bNoClose ); break;
638 case PROPERTY_SOFTCLOSE:
639 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bSoftClose ); break;
640 case PROPERTY_CONTEXTACTIVE:
641 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.bContextActive ); break;
642 case PROPERTY_DOCKINGAREA:
643 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aDockingArea ); break;
644 case PROPERTY_POS:
645 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aPos ); break;
646 case PROPERTY_SIZE:
647 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aSize ); break;
648 case PROPERTY_UINAME:
649 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aUIName ); break;
650 case PROPERTY_INTERNALSTATE:
651 aPropSeq[nIndex].Value = makeAny( sal_Int32( rWinStateInfo.nInternalState )); break;
652 case PROPERTY_STYLE:
653 aPropSeq[nIndex].Value = makeAny( sal_Int16( rWinStateInfo.nStyle )); break;
654 case PROPERTY_DOCKPOS:
655 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aDockPos ); break;
656 case PROPERTY_DOCKSIZE:
657 aPropSeq[nIndex].Value = makeAny( rWinStateInfo.aDockSize ); break;
658 default:
659 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
664 return makeAny( aPropSeq );
667 Any ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const rtl::OUString& rResourceURL, Reference< XNameAccess >& xNameAccess )
669 sal_Int32 nMask( 0 );
670 sal_Int32 nCount( m_aPropArray.size() );
671 sal_Int32 i( 0 );
672 sal_Int32 nIndex( 0 );
673 Sequence< PropertyValue > aPropSeq;
674 WindowStateInfo aWindowStateInfo;
676 for ( i = 0; i < nCount; i++ )
680 bool bAddToSeq( false );
681 Any a( xNameAccess->getByName( m_aPropArray[i] ) );
682 switch ( i )
684 case PROPERTY_LOCKED:
685 case PROPERTY_DOCKED:
686 case PROPERTY_VISIBLE:
687 case PROPERTY_CONTEXT:
688 case PROPERTY_HIDEFROMMENU:
689 case PROPERTY_NOCLOSE:
690 case PROPERTY_SOFTCLOSE:
691 case PROPERTY_CONTEXTACTIVE:
693 sal_Bool bValue = sal_Bool();
694 if ( a >>= bValue )
696 sal_Int32 nValue( 1 << i );
697 nMask |= nValue;
698 bAddToSeq = true;
699 switch ( i )
701 case PROPERTY_LOCKED:
702 aWindowStateInfo.bLocked = bValue; break;
703 case PROPERTY_DOCKED:
704 aWindowStateInfo.bDocked = bValue; break;
705 case PROPERTY_VISIBLE:
706 aWindowStateInfo.bVisible = bValue; break;
707 case PROPERTY_CONTEXT:
708 aWindowStateInfo.bContext = bValue; break;
709 case PROPERTY_HIDEFROMMENU:
710 aWindowStateInfo.bHideFromMenu = bValue; break;
711 case PROPERTY_NOCLOSE:
712 aWindowStateInfo.bNoClose = bValue; break;
713 case PROPERTY_SOFTCLOSE:
714 aWindowStateInfo.bSoftClose = bValue; break;
715 case PROPERTY_CONTEXTACTIVE:
716 aWindowStateInfo.bContextActive = bValue; break;
720 break;
722 case PROPERTY_DOCKINGAREA:
724 sal_Int32 nDockingArea = 0;
725 if ( a >>= nDockingArea )
727 if (( nDockingArea >= 0 ) &&
728 ( nDockingArea <= sal_Int32( DockingArea_DOCKINGAREA_RIGHT )))
730 aWindowStateInfo.aDockingArea = (DockingArea)nDockingArea;
731 nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
732 a = makeAny( aWindowStateInfo.aDockingArea );
733 bAddToSeq = true;
737 break;
739 case PROPERTY_POS:
740 case PROPERTY_DOCKPOS:
742 ::rtl::OUString aString;
743 if ( a >>= aString )
745 sal_Int32 nToken( 0 );
746 ::rtl::OUString aXStr = aString.getToken( 0, ',', nToken );
747 if ( nToken > 0 )
749 com::sun::star::awt::Point aPos;
750 aPos.X = aXStr.toInt32();
751 aPos.Y = aString.getToken( 0, ',', nToken ).toInt32();
753 if ( i == PROPERTY_POS )
755 aWindowStateInfo.aPos = aPos;
756 nMask |= WINDOWSTATE_MASK_POS;
758 else
760 aWindowStateInfo.aDockPos = aPos;
761 nMask |= WINDOWSTATE_MASK_DOCKPOS;
764 a <<= aPos;
765 bAddToSeq = true;
769 break;
771 case PROPERTY_SIZE:
772 case PROPERTY_DOCKSIZE:
774 ::rtl::OUString aString;
775 if ( a >>= aString )
777 sal_Int32 nToken( 0 );
778 ::rtl::OUString aStr = aString.getToken( 0, ',', nToken );
779 if ( nToken > 0 )
781 com::sun::star::awt::Size aSize;
782 aSize.Width = aStr.toInt32();
783 aSize.Height = aString.getToken( 0, ',', nToken ).toInt32();
784 if ( i == PROPERTY_SIZE )
786 aWindowStateInfo.aSize = aSize;
787 nMask |= WINDOWSTATE_MASK_SIZE;
789 else
791 aWindowStateInfo.aDockSize = aSize;
792 nMask |= WINDOWSTATE_MASK_DOCKSIZE;
795 a <<= aSize;
796 bAddToSeq = true;
800 break;
802 case PROPERTY_UINAME:
804 ::rtl::OUString aValue;
805 if ( a >>= aValue )
807 nMask |= WINDOWSTATE_MASK_UINAME;
808 aWindowStateInfo.aUIName = aValue;
809 bAddToSeq = true;
812 break;
814 case PROPERTY_INTERNALSTATE:
816 sal_uInt32 nValue = 0;
817 if ( a >>= nValue )
819 nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
820 aWindowStateInfo.nInternalState = nValue;
821 bAddToSeq = true;
824 break;
826 case PROPERTY_STYLE:
828 sal_Int32 nValue = 0;
829 if ( a >>= nValue )
831 nMask |= WINDOWSTATE_MASK_STYLE;
832 aWindowStateInfo.nStyle = sal_uInt16( nValue );
833 bAddToSeq = true;
836 break;
838 default:
839 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
842 if ( bAddToSeq )
844 // put value into the return sequence
845 nIndex = aPropSeq.getLength();
846 aPropSeq.realloc( nIndex+1 );
847 aPropSeq[nIndex].Name = m_aPropArray[i];
848 aPropSeq[nIndex].Value = a;
851 catch( com::sun::star::container::NoSuchElementException& )
854 catch ( com::sun::star::lang::WrappedTargetException& )
859 aWindowStateInfo.nMask = nMask;
860 m_aResourceURLToInfoCache.insert( ResourceURLToInfoCache::value_type( rResourceURL, aWindowStateInfo ));
861 return makeAny( aPropSeq );
864 ConfigurationAccess_WindowState::WindowStateInfo& ConfigurationAccess_WindowState::impl_insertCacheAndReturnWinState( const rtl::OUString& rResourceURL, Reference< XNameAccess >& rNameAccess )
866 sal_Int32 nMask( 0 );
867 sal_Int32 nCount( m_aPropArray.size() );
868 sal_Int32 i( 0 );
869 Sequence< PropertyValue > aPropSeq;
870 WindowStateInfo aWindowStateInfo;
872 for ( i = 0; i < nCount; i++ )
876 Any a( rNameAccess->getByName( m_aPropArray[i] ) );
877 switch ( i )
879 case PROPERTY_LOCKED:
880 case PROPERTY_DOCKED:
881 case PROPERTY_VISIBLE:
882 case PROPERTY_CONTEXT:
883 case PROPERTY_HIDEFROMMENU:
884 case PROPERTY_NOCLOSE:
885 case PROPERTY_SOFTCLOSE:
886 case PROPERTY_CONTEXTACTIVE:
888 sal_Bool bValue = sal_Bool();
889 if ( a >>= bValue )
891 sal_Int32 nValue( 1 << i );
892 nMask |= nValue;
893 switch ( i )
895 case PROPERTY_LOCKED:
896 aWindowStateInfo.bLocked = bValue; break;
897 case PROPERTY_DOCKED:
898 aWindowStateInfo.bDocked = bValue; break;
899 case PROPERTY_VISIBLE:
900 aWindowStateInfo.bVisible = bValue; break;
901 case PROPERTY_CONTEXT:
902 aWindowStateInfo.bContext = bValue; break;
903 case PROPERTY_HIDEFROMMENU:
904 aWindowStateInfo.bHideFromMenu = bValue; break;
905 case PROPERTY_NOCLOSE:
906 aWindowStateInfo.bNoClose = bValue; break;
907 case PROPERTY_SOFTCLOSE:
908 aWindowStateInfo.bNoClose = bValue; break;
909 case PROPERTY_CONTEXTACTIVE:
910 aWindowStateInfo.bContextActive = bValue; break;
911 default:
912 DBG_ASSERT( sal_False, "Unknown boolean property in WindowState found!" );
916 break;
918 case PROPERTY_DOCKINGAREA:
920 sal_Int32 nDockingArea = 0;
921 if ( a >>= nDockingArea )
923 if (( nDockingArea >= 0 ) &&
924 ( nDockingArea <= sal_Int32( DockingArea_DOCKINGAREA_RIGHT )))
926 aWindowStateInfo.aDockingArea = (DockingArea)nDockingArea;
927 nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
931 break;
933 case PROPERTY_POS:
934 case PROPERTY_DOCKPOS:
936 ::rtl::OUString aString;
937 if ( a >>= aString )
939 sal_Int32 nToken( 0 );
940 ::rtl::OUString aXStr = aString.getToken( 0, ',', nToken );
941 if ( nToken > 0 )
943 com::sun::star::awt::Point aPos;
944 aPos.X = aXStr.toInt32();
945 aPos.Y = aString.getToken( 0, ',', nToken ).toInt32();
947 if ( i == PROPERTY_POS )
949 aWindowStateInfo.aPos = aPos;
950 nMask |= WINDOWSTATE_MASK_POS;
952 else
954 aWindowStateInfo.aDockPos = aPos;
955 nMask |= WINDOWSTATE_MASK_DOCKPOS;
960 break;
962 case PROPERTY_SIZE:
963 case PROPERTY_DOCKSIZE:
965 ::rtl::OUString aString;
966 if ( a >>= aString )
968 sal_Int32 nToken( 0 );
969 ::rtl::OUString aStr = aString.getToken( 0, ',', nToken );
970 if ( nToken > 0 )
972 com::sun::star::awt::Size aSize;
973 aSize.Width = aStr.toInt32();
974 aSize.Height = aString.getToken( 0, ',', nToken ).toInt32();
975 if ( i == PROPERTY_SIZE )
977 aWindowStateInfo.aSize = aSize;
978 nMask |= WINDOWSTATE_MASK_SIZE;
980 else
982 aWindowStateInfo.aDockSize = aSize;
983 nMask |= WINDOWSTATE_MASK_DOCKSIZE;
988 break;
990 case PROPERTY_UINAME:
992 ::rtl::OUString aValue;
993 if ( a >>= aValue )
995 nMask |= WINDOWSTATE_MASK_UINAME;
996 aWindowStateInfo.aUIName = aValue;
999 break;
1001 case PROPERTY_INTERNALSTATE:
1003 sal_Int32 nValue = 0;
1004 if ( a >>= nValue )
1006 nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
1007 aWindowStateInfo.nInternalState = sal_uInt32( nValue );
1010 break;
1012 case PROPERTY_STYLE:
1014 sal_Int32 nValue = 0;
1015 if ( a >>= nValue )
1017 nMask |= WINDOWSTATE_MASK_STYLE;
1018 aWindowStateInfo.nStyle = sal_uInt16( nValue );
1022 default:
1023 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1026 catch( com::sun::star::container::NoSuchElementException& )
1029 catch ( com::sun::star::lang::WrappedTargetException& )
1034 aWindowStateInfo.nMask = nMask;
1035 ResourceURLToInfoCache::iterator pIter = (m_aResourceURLToInfoCache.insert( ResourceURLToInfoCache::value_type( rResourceURL, aWindowStateInfo ))).first;
1036 return pIter->second;
1039 Any ConfigurationAccess_WindowState::impl_getWindowStateFromResourceURL( const rtl::OUString& rResourceURL )
1041 if ( !m_bConfigAccessInitialized )
1043 impl_initializeConfigAccess();
1044 m_bConfigAccessInitialized = sal_True;
1049 // Try to ask our configuration access
1050 if ( m_xConfigAccess.is() )
1052 Reference< XNameAccess > xNameAccess;
1053 Any a( m_xConfigAccess->getByName( rResourceURL ));
1055 if ( a >>= xNameAccess )
1056 return impl_insertCacheAndReturnSequence( rResourceURL, xNameAccess );
1059 catch( com::sun::star::container::NoSuchElementException& )
1062 catch ( com::sun::star::lang::WrappedTargetException& )
1066 return Any();
1069 void ConfigurationAccess_WindowState::impl_fillStructFromSequence( WindowStateInfo& rWinStateInfo, const Sequence< PropertyValue >& rSeq )
1071 sal_Int32 nCompareCount( m_aPropArray.size() );
1072 sal_Int32 nCount( rSeq.getLength() );
1073 sal_Int32 i( 0 );
1075 for ( i = 0; i < nCount; i++ )
1077 for ( sal_Int32 j = 0; j < nCompareCount; j++ )
1079 if ( rSeq[i].Name.equals( m_aPropArray[j] ))
1081 switch ( j )
1083 case PROPERTY_LOCKED:
1084 case PROPERTY_DOCKED:
1085 case PROPERTY_VISIBLE:
1086 case PROPERTY_CONTEXT:
1087 case PROPERTY_HIDEFROMMENU:
1088 case PROPERTY_NOCLOSE:
1089 case PROPERTY_SOFTCLOSE:
1090 case PROPERTY_CONTEXTACTIVE:
1092 sal_Bool bValue = sal_Bool();
1093 if ( rSeq[i].Value >>= bValue )
1095 sal_Int32 nValue( 1 << j );
1096 rWinStateInfo.nMask |= nValue;
1097 switch ( j )
1099 case PROPERTY_LOCKED:
1100 rWinStateInfo.bLocked = bValue;
1101 break;
1102 case PROPERTY_DOCKED:
1103 rWinStateInfo.bDocked = bValue;
1104 break;
1105 case PROPERTY_VISIBLE:
1106 rWinStateInfo.bVisible = bValue;
1107 break;
1108 case PROPERTY_CONTEXT:
1109 rWinStateInfo.bContext = bValue;
1110 break;
1111 case PROPERTY_HIDEFROMMENU:
1112 rWinStateInfo.bHideFromMenu = bValue;
1113 break;
1114 case PROPERTY_NOCLOSE:
1115 rWinStateInfo.bNoClose = bValue;
1116 break;
1117 case PROPERTY_SOFTCLOSE:
1118 rWinStateInfo.bSoftClose = bValue;
1119 break;
1120 case PROPERTY_CONTEXTACTIVE:
1121 rWinStateInfo.bContextActive = bValue;
1122 break;
1123 default:
1124 DBG_ASSERT( sal_False, "Unknown boolean property in WindowState found!" );
1128 break;
1130 case PROPERTY_DOCKINGAREA:
1132 ::com::sun::star::ui::DockingArea eDockingArea;
1133 if ( rSeq[i].Value >>= eDockingArea )
1135 rWinStateInfo.aDockingArea = eDockingArea;
1136 rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKINGAREA;
1139 break;
1141 case PROPERTY_POS:
1142 case PROPERTY_DOCKPOS:
1144 com::sun::star::awt::Point aPoint;
1145 if ( rSeq[i].Value >>= aPoint )
1147 if ( j == PROPERTY_POS )
1149 rWinStateInfo.aPos = aPoint;
1150 rWinStateInfo.nMask |= WINDOWSTATE_MASK_POS;
1152 else
1154 rWinStateInfo.aDockPos = aPoint;
1155 rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKPOS;
1159 break;
1161 case PROPERTY_SIZE:
1162 case PROPERTY_DOCKSIZE:
1164 com::sun::star::awt::Size aSize;
1165 if ( rSeq[i].Value >>= aSize )
1167 if ( j == PROPERTY_SIZE )
1169 rWinStateInfo.aSize = aSize;
1170 rWinStateInfo.nMask |= WINDOWSTATE_MASK_SIZE;
1172 else
1174 rWinStateInfo.aDockSize = aSize;
1175 rWinStateInfo.nMask |= WINDOWSTATE_MASK_DOCKSIZE;
1179 break;
1181 case PROPERTY_UINAME:
1183 ::rtl::OUString aValue;
1184 if ( rSeq[i].Value >>= aValue )
1186 rWinStateInfo.aUIName = aValue;
1187 rWinStateInfo.nMask |= WINDOWSTATE_MASK_UINAME;
1190 break;
1192 case PROPERTY_INTERNALSTATE:
1194 sal_Int32 nValue = 0;
1195 if ( rSeq[i].Value >>= nValue )
1197 rWinStateInfo.nInternalState = sal_uInt32( nValue );
1198 rWinStateInfo.nMask |= WINDOWSTATE_MASK_INTERNALSTATE;
1201 break;
1203 case PROPERTY_STYLE:
1205 sal_Int32 nValue = 0;
1206 if ( rSeq[i].Value >>= nValue )
1208 rWinStateInfo.nStyle = sal_uInt16( nValue );
1209 rWinStateInfo.nMask |= WINDOWSTATE_MASK_STYLE;
1212 break;
1214 default:
1215 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1218 break;
1224 void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const WindowStateInfo& rWinStateInfo, Reference< XPropertySet >& xPropSet )
1226 sal_Int32 i( 0 );
1227 sal_Int32 nCount( m_aPropArray.size() );
1228 Sequence< PropertyValue > aPropSeq;
1229 ::rtl::OUString aDelim( ::rtl::OUString::createFromAscii( "," ));
1231 for ( i = 0; i < nCount; i++ )
1233 if ( rWinStateInfo.nMask & ( 1 << i ))
1237 // put values into the property set
1238 switch ( i )
1240 case PROPERTY_LOCKED:
1241 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bLocked )) ); break;
1242 case PROPERTY_DOCKED:
1243 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bDocked )) ); break;
1244 case PROPERTY_VISIBLE:
1245 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bVisible )) ); break;
1246 case PROPERTY_CONTEXT:
1247 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bContext )) ); break;
1248 case PROPERTY_HIDEFROMMENU:
1249 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bHideFromMenu )) ); break;
1250 case PROPERTY_NOCLOSE:
1251 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bNoClose )) ); break;
1252 case PROPERTY_SOFTCLOSE:
1253 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bSoftClose )) ); break;
1254 case PROPERTY_CONTEXTACTIVE:
1255 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Bool( rWinStateInfo.bContextActive )) ); break;
1256 case PROPERTY_DOCKINGAREA:
1257 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int16( rWinStateInfo.aDockingArea ) ) ); break;
1258 case PROPERTY_POS:
1259 case PROPERTY_DOCKPOS:
1261 ::rtl::OUString aPosStr;
1262 if ( i == PROPERTY_POS )
1263 aPosStr = ::rtl::OUString::valueOf( rWinStateInfo.aPos.X );
1264 else
1265 aPosStr = ::rtl::OUString::valueOf( rWinStateInfo.aDockPos.X );
1266 aPosStr += aDelim;
1267 if ( i == PROPERTY_POS )
1268 aPosStr += ::rtl::OUString::valueOf( rWinStateInfo.aPos.Y );
1269 else
1270 aPosStr += ::rtl::OUString::valueOf( rWinStateInfo.aDockPos.Y );
1271 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( aPosStr ) );
1272 break;
1274 case PROPERTY_SIZE:
1275 case PROPERTY_DOCKSIZE:
1277 ::rtl::OUString aSizeStr;
1278 if ( i == PROPERTY_SIZE )
1279 aSizeStr = ( ::rtl::OUString::valueOf( rWinStateInfo.aSize.Width ));
1280 else
1281 aSizeStr = ( ::rtl::OUString::valueOf( rWinStateInfo.aDockSize.Width ));
1282 aSizeStr += aDelim;
1283 if ( i == PROPERTY_SIZE )
1284 aSizeStr += ::rtl::OUString::valueOf( rWinStateInfo.aSize.Height );
1285 else
1286 aSizeStr += ::rtl::OUString::valueOf( rWinStateInfo.aDockSize.Height );
1287 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( aSizeStr ) );
1288 break;
1290 case PROPERTY_UINAME:
1291 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.aUIName ) ); break;
1292 case PROPERTY_INTERNALSTATE:
1293 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int32( rWinStateInfo.nInternalState )) ); break;
1294 case PROPERTY_STYLE:
1295 xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int32( rWinStateInfo.nStyle )) ); break;
1296 default:
1297 DBG_ASSERT( sal_False, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1300 catch( Exception& )
1307 sal_Bool ConfigurationAccess_WindowState::impl_initializeConfigAccess()
1309 Sequence< Any > aArgs( 2 );
1310 PropertyValue aPropValue;
1314 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
1315 aPropValue.Value <<= m_aConfigWindowAccess;
1316 aArgs[0] <<= aPropValue;
1317 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ));
1318 aPropValue.Value <<= sal_True;
1319 aArgs[1] <<= aPropValue;
1321 m_xConfigAccess = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(
1322 SERVICENAME_CFGUPDATEACCESS, aArgs ),
1323 UNO_QUERY );
1324 if ( m_xConfigAccess.is() )
1326 // Add as container listener
1327 Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
1328 if ( xContainer.is() )
1329 xContainer->addContainerListener( this );
1332 return sal_True;
1334 catch ( WrappedTargetException& )
1337 catch ( Exception& )
1341 return sal_False;
1345 //*****************************************************************************************************************
1346 // XInterface, XTypeProvider, XServiceInfo
1347 //*****************************************************************************************************************
1348 DEFINE_XINTERFACE_4 ( WindowStateConfiguration ,
1349 OWeakObject ,
1350 DIRECT_INTERFACE( css::lang::XTypeProvider ),
1351 DIRECT_INTERFACE( css::lang::XServiceInfo ),
1352 DIRECT_INTERFACE( css::container::XNameAccess ),
1353 DERIVED_INTERFACE( css::container::XElementAccess, css::container::XNameAccess )
1356 DEFINE_XTYPEPROVIDER_4 ( WindowStateConfiguration ,
1357 css::lang::XTypeProvider ,
1358 css::lang::XServiceInfo ,
1359 css::container::XNameAccess ,
1360 css::container::XElementAccess
1363 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( WindowStateConfiguration ,
1364 ::cppu::OWeakObject ,
1365 SERVICENAME_WINDOWSTATECONFIGURATION ,
1366 IMPLEMENTATIONNAME_WINDOWSTATECONFIGURATION
1369 DEFINE_INIT_SERVICE ( WindowStateConfiguration, {} )
1371 WindowStateConfiguration::WindowStateConfiguration( const Reference< XMultiServiceFactory >& xServiceManager ) :
1372 ThreadHelpBase(),
1373 m_xServiceManager( xServiceManager )
1375 m_xModuleManager = Reference< XModuleManager >( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ),
1376 UNO_QUERY );
1377 Reference< XNameAccess > xEmptyNameAccess;
1378 Reference< XNameAccess > xNameAccess( m_xModuleManager, UNO_QUERY_THROW );
1379 Sequence< rtl::OUString > aElementNames = xNameAccess->getElementNames();
1380 Sequence< PropertyValue > aSeq;
1381 ::rtl::OUString aModuleIdentifier;
1383 for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
1385 aModuleIdentifier = aElementNames[i];
1386 if ( xNameAccess->getByName( aModuleIdentifier ) >>= aSeq )
1388 ::rtl::OUString aWindowStateFileStr;
1389 for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
1391 if ( aSeq[y].Name.equalsAscii("ooSetupFactoryWindowStateConfigRef") )
1393 aSeq[y].Value >>= aWindowStateFileStr;
1394 break;
1398 if ( aWindowStateFileStr.getLength() > 0 )
1400 // Create first mapping ModuleIdentifier ==> Window state configuration file
1401 m_aModuleToFileHashMap.insert( ModuleToWindowStateFileMap::value_type( aModuleIdentifier, aWindowStateFileStr ));
1403 // Create second mapping Command File ==> Window state configuration instance
1404 ModuleToWindowStateConfigHashMap::iterator pIter = m_aModuleToWindowStateHashMap.find( aWindowStateFileStr );
1405 if ( pIter == m_aModuleToWindowStateHashMap.end() )
1406 m_aModuleToWindowStateHashMap.insert( ModuleToWindowStateConfigHashMap::value_type( aWindowStateFileStr, xEmptyNameAccess ));
1412 WindowStateConfiguration::~WindowStateConfiguration()
1414 ResetableGuard aLock( m_aLock );
1415 m_aModuleToFileHashMap.clear();
1416 m_aModuleToWindowStateHashMap.clear();
1419 Any SAL_CALL WindowStateConfiguration::getByName( const ::rtl::OUString& aModuleIdentifier )
1420 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1422 ResetableGuard aLock( m_aLock );
1424 ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aModuleIdentifier );
1425 if ( pIter != m_aModuleToFileHashMap.end() )
1427 Any a;
1428 ::rtl::OUString aWindowStateConfigFile( pIter->second );
1430 ModuleToWindowStateConfigHashMap::iterator pModuleIter = m_aModuleToWindowStateHashMap.find( aWindowStateConfigFile );
1431 if ( pModuleIter != m_aModuleToWindowStateHashMap.end() )
1433 if ( pModuleIter->second.is() )
1434 a = makeAny( pModuleIter->second );
1435 else
1437 Reference< XNameAccess > xResourceURLWindowState;
1438 ConfigurationAccess_WindowState* pModuleWindowState = new ConfigurationAccess_WindowState( aWindowStateConfigFile, m_xServiceManager );
1439 xResourceURLWindowState = Reference< XNameAccess >( static_cast< cppu::OWeakObject* >( pModuleWindowState ),UNO_QUERY );
1440 pModuleIter->second = xResourceURLWindowState;
1441 a <<= xResourceURLWindowState;
1444 return a;
1448 throw NoSuchElementException();
1451 Sequence< ::rtl::OUString > SAL_CALL WindowStateConfiguration::getElementNames()
1452 throw (::com::sun::star::uno::RuntimeException)
1454 ResetableGuard aLock( m_aLock );
1456 Sequence< rtl::OUString > aSeq( m_aModuleToFileHashMap.size() );
1458 sal_Int32 n = 0;
1459 ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.begin();
1460 while ( pIter != m_aModuleToFileHashMap.end() )
1462 aSeq[n] = pIter->first;
1463 ++pIter;
1466 return aSeq;
1469 sal_Bool SAL_CALL WindowStateConfiguration::hasByName( const ::rtl::OUString& aName )
1470 throw (::com::sun::star::uno::RuntimeException)
1472 ResetableGuard aLock( m_aLock );
1474 ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aName );
1475 return ( pIter != m_aModuleToFileHashMap.end() );
1478 // XElementAccess
1479 Type SAL_CALL WindowStateConfiguration::getElementType()
1480 throw (::com::sun::star::uno::RuntimeException)
1482 return( ::getCppuType( (const Reference< XNameAccess >*)NULL ) );
1485 sal_Bool SAL_CALL WindowStateConfiguration::hasElements()
1486 throw (::com::sun::star::uno::RuntimeException)
1488 // We always have at least one module. So it is valid to return true!
1489 return sal_True;
1492 } // namespace framework