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 //_________________________________________________________________________________________________________________
33 //_________________________________________________________________________________________________________________
34 #include "uiconfiguration/windowstateconfiguration.hxx"
35 #include <threadhelp/resetableguard.hxx>
38 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
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
,
139 //*****************************************************************************************************************
140 // Configuration access class for WindowState supplier implementation
141 //*****************************************************************************************************************
143 class ConfigurationAccess_WindowState
: // interfaces
144 public XTypeProvider
,
145 public XNameContainer
,
146 public XContainerListener
,
148 // Order is neccessary for right initialization!
149 private ThreadHelpBase
,
150 public ::cppu::OWeakObject
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
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
);
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
);
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
);
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
);
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
),
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
;
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();
257 typedef ::std::hash_map
< ::rtl::OUString
,
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,
269 std::vector
< ::rtl::OUString
> m_aPropArray
;
272 //*****************************************************************************************************************
273 // XInterface, XTypeProvider
274 //*****************************************************************************************************************
275 DEFINE_XINTERFACE_7 ( ConfigurationAccess_WindowState
,
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
) :
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.
310 while ( CONFIGURATION_PROPERTIES
[n
] )
312 m_aPropArray
.push_back( ::rtl::OUString::createFromAscii( CONFIGURATION_PROPERTIES
[n
] ));
317 ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState()
320 ResetableGuard
aLock( m_aLock
);
321 Reference
< XContainer
> xContainer( m_xConfigAccess
, UNO_QUERY
);
322 if ( xContainer
.is() )
323 xContainer
->removeContainerListener( this );
327 Any SAL_CALL
ConfigurationAccess_WindowState::getByName( const ::rtl::OUString
& rResourceURL
)
328 throw ( NoSuchElementException
, WrappedTargetException
, RuntimeException
)
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
);
338 Any
a( impl_getWindowStateFromResourceURL( rResourceURL
) );
340 throw NoSuchElementException();
346 Sequence
< ::rtl::OUString
> SAL_CALL
ConfigurationAccess_WindowState::getElementNames()
347 throw ( RuntimeException
)
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();
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
& )
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
)
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();
405 void SAL_CALL
ConfigurationAccess_WindowState::removeByName( const ::rtl::OUString
& rResourceURL
)
406 throw( NoSuchElementException
, WrappedTargetException
, RuntimeException
)
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() )
429 xNameContainer
->removeByName( rResourceURL
);
430 Reference
< XChangesBatch
> xFlush( m_xConfigAccess
, UNO_QUERY
);
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
)
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();
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();
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
);
480 Reference
< XPropertySet
> xPropSet( xFactory
->createInstance(), UNO_QUERY
);
484 impl_putPropertiesFromStruct( aWinStateInfo
, xPropSet
);
486 xNameContainer
->insertByName( rResourceURL
, a
);
487 Reference
< XChangesBatch
> xFlush( xFactory
, UNO_QUERY
);
489 xFlush
->commitChanges();
501 throw IllegalArgumentException();
505 void SAL_CALL
ConfigurationAccess_WindowState::replaceByName( const ::rtl::OUString
& rResourceURL
, const css::uno::Any
& aPropertySet
)
506 throw( IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
)
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
;
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
);
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
;
556 Reference
< XPropertySet
> xPropSet
;
557 if ( xNameContainer
->getByName( aResourceURL
) >>= xPropSet
)
559 impl_putPropertiesFromStruct( aWinStateInfo
, xPropSet
);
561 Reference
< XChangesBatch
> xFlush( m_xConfigAccess
, UNO_QUERY
);
563 xFlush
->commitChanges();
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
)
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
)
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
];
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;
642 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aPos
); break;
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;
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;
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() );
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
] ) );
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();
693 sal_Int32
nValue( 1 << 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;
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
);
737 case PROPERTY_DOCKPOS
:
739 ::rtl::OUString aString
;
742 sal_Int32
nToken( 0 );
743 ::rtl::OUString aXStr
= aString
.getToken( 0, ',', nToken
);
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
;
757 aWindowStateInfo
.aDockPos
= aPos
;
758 nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
769 case PROPERTY_DOCKSIZE
:
771 ::rtl::OUString aString
;
774 sal_Int32
nToken( 0 );
775 ::rtl::OUString aStr
= aString
.getToken( 0, ',', nToken
);
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
;
788 aWindowStateInfo
.aDockSize
= aSize
;
789 nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
799 case PROPERTY_UINAME
:
801 ::rtl::OUString aValue
;
804 nMask
|= WINDOWSTATE_MASK_UINAME
;
805 aWindowStateInfo
.aUIName
= aValue
;
811 case PROPERTY_INTERNALSTATE
:
813 sal_uInt32 nValue
= 0;
816 nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
817 aWindowStateInfo
.nInternalState
= nValue
;
825 sal_Int32 nValue
= 0;
828 nMask
|= WINDOWSTATE_MASK_STYLE
;
829 aWindowStateInfo
.nStyle
= sal_uInt16( nValue
);
836 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
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() );
866 Sequence
< PropertyValue
> aPropSeq
;
867 WindowStateInfo aWindowStateInfo
;
869 for ( i
= 0; i
< nCount
; i
++ )
873 Any
a( rNameAccess
->getByName( m_aPropArray
[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();
888 sal_Int32
nValue( 1 << 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;
909 DBG_ASSERT( sal_False
, "Unknown boolean property in WindowState found!" );
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
;
931 case PROPERTY_DOCKPOS
:
933 ::rtl::OUString aString
;
936 sal_Int32
nToken( 0 );
937 ::rtl::OUString aXStr
= aString
.getToken( 0, ',', nToken
);
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
;
951 aWindowStateInfo
.aDockPos
= aPos
;
952 nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
960 case PROPERTY_DOCKSIZE
:
962 ::rtl::OUString aString
;
965 sal_Int32
nToken( 0 );
966 ::rtl::OUString aStr
= aString
.getToken( 0, ',', nToken
);
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
;
979 aWindowStateInfo
.aDockSize
= aSize
;
980 nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
987 case PROPERTY_UINAME
:
989 ::rtl::OUString aValue
;
992 nMask
|= WINDOWSTATE_MASK_UINAME
;
993 aWindowStateInfo
.aUIName
= aValue
;
998 case PROPERTY_INTERNALSTATE
:
1000 sal_Int32 nValue
= 0;
1003 nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
1004 aWindowStateInfo
.nInternalState
= sal_uInt32( nValue
);
1009 case PROPERTY_STYLE
:
1011 sal_Int32 nValue
= 0;
1014 nMask
|= WINDOWSTATE_MASK_STYLE
;
1015 aWindowStateInfo
.nStyle
= sal_uInt16( nValue
);
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
& )
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() );
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
] ))
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
;
1096 case PROPERTY_LOCKED
:
1097 rWinStateInfo
.bLocked
= bValue
;
1099 case PROPERTY_DOCKED
:
1100 rWinStateInfo
.bDocked
= bValue
;
1102 case PROPERTY_VISIBLE
:
1103 rWinStateInfo
.bVisible
= bValue
;
1105 case PROPERTY_CONTEXT
:
1106 rWinStateInfo
.bContext
= bValue
;
1108 case PROPERTY_HIDEFROMMENU
:
1109 rWinStateInfo
.bHideFromMenu
= bValue
;
1111 case PROPERTY_NOCLOSE
:
1112 rWinStateInfo
.bNoClose
= bValue
;
1114 case PROPERTY_SOFTCLOSE
:
1115 rWinStateInfo
.bSoftClose
= bValue
;
1117 case PROPERTY_CONTEXTACTIVE
:
1118 rWinStateInfo
.bContextActive
= bValue
;
1121 DBG_ASSERT( sal_False
, "Unknown boolean property in WindowState found!" );
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
;
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
;
1151 rWinStateInfo
.aDockPos
= aPoint
;
1152 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
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
;
1171 rWinStateInfo
.aDockSize
= aSize
;
1172 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
1178 case PROPERTY_UINAME
:
1180 ::rtl::OUString aValue
;
1181 if ( rSeq
[i
].Value
>>= aValue
)
1183 rWinStateInfo
.aUIName
= aValue
;
1184 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_UINAME
;
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
;
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
;
1212 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1221 void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const WindowStateInfo
& rWinStateInfo
, Reference
< XPropertySet
>& xPropSet
)
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
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;
1256 case PROPERTY_DOCKPOS
:
1258 ::rtl::OUString aPosStr
;
1259 if ( i
== PROPERTY_POS
)
1260 aPosStr
= ::rtl::OUString::valueOf( rWinStateInfo
.aPos
.X
);
1262 aPosStr
= ::rtl::OUString::valueOf( rWinStateInfo
.aDockPos
.X
);
1264 if ( i
== PROPERTY_POS
)
1265 aPosStr
+= ::rtl::OUString::valueOf( rWinStateInfo
.aPos
.Y
);
1267 aPosStr
+= ::rtl::OUString::valueOf( rWinStateInfo
.aDockPos
.Y
);
1268 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( aPosStr
) );
1272 case PROPERTY_DOCKSIZE
:
1274 ::rtl::OUString aSizeStr
;
1275 if ( i
== PROPERTY_SIZE
)
1276 aSizeStr
= ( ::rtl::OUString::valueOf( rWinStateInfo
.aSize
.Width
));
1278 aSizeStr
= ( ::rtl::OUString::valueOf( rWinStateInfo
.aDockSize
.Width
));
1280 if ( i
== PROPERTY_SIZE
)
1281 aSizeStr
+= ::rtl::OUString::valueOf( rWinStateInfo
.aSize
.Height
);
1283 aSizeStr
+= ::rtl::OUString::valueOf( rWinStateInfo
.aDockSize
.Height
);
1284 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( aSizeStr
) );
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;
1294 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
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
),
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 );
1331 catch ( WrappedTargetException
& )
1334 catch ( Exception
& )
1342 //*****************************************************************************************************************
1343 // XInterface, XTypeProvider, XServiceInfo
1344 //*****************************************************************************************************************
1345 DEFINE_XINTERFACE_4 ( WindowStateConfiguration
,
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
) :
1370 m_xServiceManager( xServiceManager
)
1372 m_xModuleManager
= Reference
< XModuleManager
>( m_xServiceManager
->createInstance( SERVICENAME_MODULEMANAGER
),
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
;
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() )
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
);
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
;
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() );
1456 ModuleToWindowStateFileMap::const_iterator pIter
= m_aModuleToFileHashMap
.begin();
1457 while ( pIter
!= m_aModuleToFileHashMap
.end() )
1459 aSeq
[n
] = pIter
->first
;
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() );
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!
1489 } // namespace framework