1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "uiconfiguration/windowstateconfiguration.hxx"
21 #include <threadhelp/resetableguard.hxx>
24 #include "helper/mischelper.hxx"
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/configuration/theDefaultProvider.hpp>
29 #include <com/sun/star/container/XNameAccess.hpp>
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include <com/sun/star/container/XContainer.hpp>
32 #include <com/sun/star/frame/ModuleManager.hpp>
33 #include <com/sun/star/awt/Point.hpp>
34 #include <com/sun/star/awt/Size.hpp>
35 #include <com/sun/star/ui/DockingArea.hpp>
36 #include <com/sun/star/util/XChangesBatch.hpp>
38 #include <rtl/ustrbuf.hxx>
39 #include <cppuhelper/weak.hxx>
40 #include <tools/debug.hxx>
42 //_________________________________________________________________________________________________________________
44 //_________________________________________________________________________________________________________________
46 using namespace com::sun::star::uno
;
47 using namespace com::sun::star::lang
;
48 using namespace com::sun::star::beans
;
49 using namespace com::sun::star::util
;
50 using namespace com::sun::star::configuration
;
51 using namespace com::sun::star::container
;
52 using namespace ::com::sun::star::frame
;
53 using namespace ::com::sun::star::ui
;
55 //_________________________________________________________________________________________________________________
57 //_________________________________________________________________________________________________________________
59 static const char CONFIGURATION_ROOT_ACCESS
[] = "/org.openoffice.Office.UI.";
60 static const char CONFIGURATION_WINDOWSTATE_ACCESS
[] = "/UIElements/States";
62 static const char CONFIGURATION_PROPERTY_LOCKED
[] = WINDOWSTATE_PROPERTY_LOCKED
;
63 static const char CONFIGURATION_PROPERTY_DOCKED
[] = WINDOWSTATE_PROPERTY_DOCKED
;
64 static const char CONFIGURATION_PROPERTY_VISIBLE
[] = WINDOWSTATE_PROPERTY_VISIBLE
;
65 static const char CONFIGURATION_PROPERTY_DOCKINGAREA
[] = WINDOWSTATE_PROPERTY_DOCKINGAREA
;
66 static const char CONFIGURATION_PROPERTY_DOCKPOS
[] = WINDOWSTATE_PROPERTY_DOCKPOS
;
67 static const char CONFIGURATION_PROPERTY_DOCKSIZE
[] = WINDOWSTATE_PROPERTY_DOCKSIZE
;
68 static const char CONFIGURATION_PROPERTY_POS
[] = WINDOWSTATE_PROPERTY_POS
;
69 static const char CONFIGURATION_PROPERTY_SIZE
[] = WINDOWSTATE_PROPERTY_SIZE
;
70 static const char CONFIGURATION_PROPERTY_UINAME
[] = WINDOWSTATE_PROPERTY_UINAME
;
71 static const char CONFIGURATION_PROPERTY_INTERNALSTATE
[] = WINDOWSTATE_PROPERTY_INTERNALSTATE
;
72 static const char CONFIGURATION_PROPERTY_STYLE
[] = WINDOWSTATE_PROPERTY_STYLE
;
73 static const char CONFIGURATION_PROPERTY_CONTEXT
[] = WINDOWSTATE_PROPERTY_CONTEXT
;
74 static const char CONFIGURATION_PROPERTY_HIDEFROMMENU
[] = WINDOWSTATE_PROPERTY_HIDEFROMENU
;
75 static const char CONFIGURATION_PROPERTY_NOCLOSE
[] = WINDOWSTATE_PROPERTY_NOCLOSE
;
76 static const char CONFIGURATION_PROPERTY_SOFTCLOSE
[] = WINDOWSTATE_PROPERTY_SOFTCLOSE
;
77 static const char CONFIGURATION_PROPERTY_CONTEXTACTIVE
[] = WINDOWSTATE_PROPERTY_CONTEXTACTIVE
;
79 // Zero based indexes, order must be the same as WindowStateMask && CONFIGURATION_PROPERTIES!
80 static const sal_Int16 PROPERTY_LOCKED
= 0;
81 static const sal_Int16 PROPERTY_DOCKED
= 1;
82 static const sal_Int16 PROPERTY_VISIBLE
= 2;
83 static const sal_Int16 PROPERTY_CONTEXT
= 3;
84 static const sal_Int16 PROPERTY_HIDEFROMMENU
= 4;
85 static const sal_Int16 PROPERTY_NOCLOSE
= 5;
86 static const sal_Int16 PROPERTY_SOFTCLOSE
= 6;
87 static const sal_Int16 PROPERTY_CONTEXTACTIVE
= 7;
88 static const sal_Int16 PROPERTY_DOCKINGAREA
= 8;
89 static const sal_Int16 PROPERTY_POS
= 9;
90 static const sal_Int16 PROPERTY_SIZE
= 10;
91 static const sal_Int16 PROPERTY_UINAME
= 11;
92 static const sal_Int16 PROPERTY_INTERNALSTATE
= 12;
93 static const sal_Int16 PROPERTY_STYLE
= 13;
94 static const sal_Int16 PROPERTY_DOCKPOS
= 14;
95 static const sal_Int16 PROPERTY_DOCKSIZE
= 15;
97 // Order must be the same as WindowStateMask!!
98 static const char* CONFIGURATION_PROPERTIES
[] =
100 CONFIGURATION_PROPERTY_LOCKED
,
101 CONFIGURATION_PROPERTY_DOCKED
,
102 CONFIGURATION_PROPERTY_VISIBLE
,
103 CONFIGURATION_PROPERTY_CONTEXT
,
104 CONFIGURATION_PROPERTY_HIDEFROMMENU
,
105 CONFIGURATION_PROPERTY_NOCLOSE
,
106 CONFIGURATION_PROPERTY_SOFTCLOSE
,
107 CONFIGURATION_PROPERTY_CONTEXTACTIVE
,
108 CONFIGURATION_PROPERTY_DOCKINGAREA
,
109 CONFIGURATION_PROPERTY_POS
,
110 CONFIGURATION_PROPERTY_SIZE
,
111 CONFIGURATION_PROPERTY_UINAME
,
112 CONFIGURATION_PROPERTY_INTERNALSTATE
,
113 CONFIGURATION_PROPERTY_STYLE
,
114 CONFIGURATION_PROPERTY_DOCKPOS
,
115 CONFIGURATION_PROPERTY_DOCKSIZE
,
122 //*****************************************************************************************************************
123 // Configuration access class for WindowState supplier implementation
124 //*****************************************************************************************************************
126 class ConfigurationAccess_WindowState
: // interfaces
127 public XTypeProvider
,
128 public XNameContainer
,
129 public XContainerListener
,
131 // Order is necessary for right initialization!
132 private ThreadHelpBase
,
133 public ::cppu::OWeakObject
136 ConfigurationAccess_WindowState( const OUString
& aWindowStateConfigFile
, const Reference
< XComponentContext
>& rxContext
);
137 virtual ~ConfigurationAccess_WindowState();
139 // XInterface, XTypeProvider
140 FWK_DECLARE_XINTERFACE
141 FWK_DECLARE_XTYPEPROVIDER
144 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const OUString
& aName
)
145 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
147 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getElementNames()
148 throw (::com::sun::star::uno::RuntimeException
);
150 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
)
151 throw (::com::sun::star::uno::RuntimeException
);
154 virtual void SAL_CALL
removeByName( const OUString
& sName
)
155 throw(css::container::NoSuchElementException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
);
157 virtual void SAL_CALL
insertByName( const OUString
& sName
, const css::uno::Any
& aPropertySet
)
158 throw(css::lang::IllegalArgumentException
, css::container::ElementExistException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
);
161 virtual void SAL_CALL
replaceByName( const OUString
& sName
, const css::uno::Any
& aPropertySet
)
162 throw(css::lang::IllegalArgumentException
, css::container::NoSuchElementException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
);
165 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType()
166 throw (::com::sun::star::uno::RuntimeException
);
168 virtual sal_Bool SAL_CALL
hasElements()
169 throw (::com::sun::star::uno::RuntimeException
);
171 // container.XContainerListener
172 virtual void SAL_CALL
elementInserted( const ContainerEvent
& aEvent
) throw(RuntimeException
);
173 virtual void SAL_CALL
elementRemoved ( const ContainerEvent
& aEvent
) throw(RuntimeException
);
174 virtual void SAL_CALL
elementReplaced( const ContainerEvent
& aEvent
) throw(RuntimeException
);
176 // lang.XEventListener
177 virtual void SAL_CALL
disposing( const EventObject
& aEvent
) throw(RuntimeException
);
182 WINDOWSTATE_MASK_LOCKED
= 1,
183 WINDOWSTATE_MASK_DOCKED
= 2,
184 WINDOWSTATE_MASK_VISIBLE
= 4,
185 WINDOWSTATE_MASK_CONTEXT
= 8,
186 WINDOWSTATE_MASK_HIDEFROMMENU
= 16,
187 WINDOWSTATE_MASK_NOCLOSE
= 32,
188 WINDOWSTATE_MASK_SOFTCLOSE
= 64,
189 WINDOWSTATE_MASK_CONTEXTACTIVE
= 128,
190 WINDOWSTATE_MASK_DOCKINGAREA
= 256,
191 WINDOWSTATE_MASK_POS
= 512,
192 WINDOWSTATE_MASK_SIZE
= 1024,
193 WINDOWSTATE_MASK_UINAME
= 2048,
194 WINDOWSTATE_MASK_INTERNALSTATE
= 4096,
195 WINDOWSTATE_MASK_STYLE
= 8192,
196 WINDOWSTATE_MASK_DOCKPOS
= 16384,
197 WINDOWSTATE_MASK_DOCKSIZE
= 32768
200 // Cache structure. Valid values are described by the eMask member. All other values should not be
201 // provided to outside code!
202 struct WindowStateInfo
204 WindowStateInfo() : aDockingArea( ::com::sun::star::ui::DockingArea_DOCKINGAREA_TOP
),
220 ::com::sun::star::ui::DockingArea aDockingArea
;
221 com::sun::star::awt::Point aDockPos
;
222 com::sun::star::awt::Size aDockSize
;
223 com::sun::star::awt::Point aPos
;
224 com::sun::star::awt::Size aSize
;
226 sal_uInt32 nInternalState
;
228 sal_uInt32 nMask
; // see WindowStateMask
231 void impl_putPropertiesFromStruct( const WindowStateInfo
& rWinStateInfo
, Reference
< XPropertySet
>& xPropSet
);
232 Any
impl_insertCacheAndReturnSequence( const OUString
& rResourceURL
, Reference
< XNameAccess
>& rNameAccess
);
233 WindowStateInfo
& impl_insertCacheAndReturnWinState( const OUString
& rResourceURL
, Reference
< XNameAccess
>& rNameAccess
);
234 Any
impl_getSequenceFromStruct( const WindowStateInfo
& rWinStateInfo
);
235 void impl_fillStructFromSequence( WindowStateInfo
& rWinStateInfo
, const Sequence
< PropertyValue
>& rSeq
);
236 Any
impl_getWindowStateFromResourceURL( const OUString
& rResourceURL
);
237 sal_Bool
impl_initializeConfigAccess();
240 typedef ::boost::unordered_map
< OUString
,
243 ::std::equal_to
< OUString
> > ResourceURLToInfoCache
;
245 OUString m_aConfigWindowAccess
;
246 Reference
< XMultiServiceFactory
> m_xConfigProvider
;
247 Reference
< XNameAccess
> m_xConfigAccess
;
248 Reference
< XContainerListener
> m_xConfigListener
;
249 ResourceURLToInfoCache m_aResourceURLToInfoCache
;
250 sal_Bool m_bConfigAccessInitialized
: 1,
252 std::vector
< OUString
> m_aPropArray
;
255 //*****************************************************************************************************************
256 // XInterface, XTypeProvider
257 //*****************************************************************************************************************
258 DEFINE_XINTERFACE_7 ( ConfigurationAccess_WindowState
,
260 DIRECT_INTERFACE ( css::container::XNameContainer
),
261 DIRECT_INTERFACE ( css::container::XContainerListener
),
262 DIRECT_INTERFACE ( css::lang::XTypeProvider
),
263 DERIVED_INTERFACE( css::container::XElementAccess
, css::container::XNameAccess
),
264 DERIVED_INTERFACE( css::container::XNameAccess
, css::container::XNameReplace
),
265 DERIVED_INTERFACE( css::container::XNameReplace
, css::container::XNameContainer
),
266 DERIVED_INTERFACE( css::lang::XEventListener
, XContainerListener
)
269 DEFINE_XTYPEPROVIDER_7 ( ConfigurationAccess_WindowState
,
270 css::container::XNameContainer
,
271 css::container::XNameReplace
,
272 css::container::XNameAccess
,
273 css::container::XElementAccess
,
274 css::container::XContainerListener
,
275 css::lang::XEventListener
,
276 css::lang::XTypeProvider
279 ConfigurationAccess_WindowState::ConfigurationAccess_WindowState( const OUString
& aModuleName
, const Reference
< XComponentContext
>& rxContext
) :
281 m_aConfigWindowAccess( CONFIGURATION_ROOT_ACCESS
),
282 m_bConfigAccessInitialized( sal_False
),
283 m_bModified( sal_False
)
285 // Create configuration hierachical access name
286 m_aConfigWindowAccess
+= aModuleName
;
287 m_aConfigWindowAccess
+= OUString( CONFIGURATION_WINDOWSTATE_ACCESS
);
288 m_xConfigProvider
= theDefaultProvider::get( rxContext
);
290 // Initialize access array with property names.
292 while ( CONFIGURATION_PROPERTIES
[n
] )
294 m_aPropArray
.push_back( OUString::createFromAscii( CONFIGURATION_PROPERTIES
[n
] ));
299 ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState()
302 ResetableGuard
aLock( m_aLock
);
303 Reference
< XContainer
> xContainer( m_xConfigAccess
, UNO_QUERY
);
304 if ( xContainer
.is() )
305 xContainer
->removeContainerListener(m_xConfigListener
);
309 Any SAL_CALL
ConfigurationAccess_WindowState::getByName( const OUString
& rResourceURL
)
310 throw ( NoSuchElementException
, WrappedTargetException
, RuntimeException
)
313 ResetableGuard
aLock( m_aLock
);
315 ResourceURLToInfoCache::const_iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
316 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
317 return impl_getSequenceFromStruct( pIter
->second
);
320 Any
a( impl_getWindowStateFromResourceURL( rResourceURL
) );
322 throw NoSuchElementException();
328 Sequence
< OUString
> SAL_CALL
ConfigurationAccess_WindowState::getElementNames()
329 throw ( RuntimeException
)
332 ResetableGuard
aLock( m_aLock
);
334 if ( !m_bConfigAccessInitialized
)
336 impl_initializeConfigAccess();
337 m_bConfigAccessInitialized
= sal_True
;
340 if ( m_xConfigAccess
.is() )
341 return m_xConfigAccess
->getElementNames();
343 return Sequence
< OUString
> ();
346 sal_Bool SAL_CALL
ConfigurationAccess_WindowState::hasByName( const OUString
& rResourceURL
)
347 throw (::com::sun::star::uno::RuntimeException
)
350 ResetableGuard
aLock( m_aLock
);
352 ResourceURLToInfoCache::const_iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
353 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
357 Any
a( impl_getWindowStateFromResourceURL( rResourceURL
) );
366 Type SAL_CALL
ConfigurationAccess_WindowState::getElementType()
367 throw ( RuntimeException
)
369 return( ::getCppuType( (const Sequence
< PropertyValue
>*)NULL
) );
372 sal_Bool SAL_CALL
ConfigurationAccess_WindowState::hasElements()
373 throw ( RuntimeException
)
376 ResetableGuard
aLock( m_aLock
);
378 if ( !m_bConfigAccessInitialized
)
380 impl_initializeConfigAccess();
381 m_bConfigAccessInitialized
= sal_True
;
384 if ( m_xConfigAccess
.is() )
385 return m_xConfigAccess
->hasElements();
391 void SAL_CALL
ConfigurationAccess_WindowState::removeByName( const OUString
& rResourceURL
)
392 throw( NoSuchElementException
, WrappedTargetException
, RuntimeException
)
395 ResetableGuard
aLock( m_aLock
);
397 ResourceURLToInfoCache::iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
398 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
399 m_aResourceURLToInfoCache
.erase( pIter
);
401 if ( !m_bConfigAccessInitialized
)
403 impl_initializeConfigAccess();
404 m_bConfigAccessInitialized
= sal_True
;
409 // Remove must be write-through => remove element from configuration
410 Reference
< XNameContainer
> xNameContainer( m_xConfigAccess
, UNO_QUERY
);
411 if ( xNameContainer
.is() )
415 xNameContainer
->removeByName( rResourceURL
);
416 Reference
< XChangesBatch
> xFlush( m_xConfigAccess
, UNO_QUERY
);
418 xFlush
->commitChanges();
421 catch ( const com::sun::star::lang::WrappedTargetException
& )
426 void SAL_CALL
ConfigurationAccess_WindowState::insertByName( const OUString
& rResourceURL
, const css::uno::Any
& aPropertySet
)
427 throw( IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
)
430 ResetableGuard
aLock( m_aLock
);
432 Sequence
< PropertyValue
> aPropSet
;
433 if ( aPropertySet
>>= aPropSet
)
435 ResourceURLToInfoCache::const_iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
436 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
437 throw ElementExistException();
440 if ( !m_bConfigAccessInitialized
)
442 impl_initializeConfigAccess();
443 m_bConfigAccessInitialized
= sal_True
;
446 // Try to ask our configuration access
447 if ( m_xConfigAccess
.is() )
449 if ( m_xConfigAccess
->hasByName( rResourceURL
) )
450 throw ElementExistException();
453 WindowStateInfo aWinStateInfo
;
454 impl_fillStructFromSequence( aWinStateInfo
, aPropSet
);
455 m_aResourceURLToInfoCache
.insert( ResourceURLToInfoCache::value_type( rResourceURL
, aWinStateInfo
));
457 // insert must be write-through => insert element into configuration
458 Reference
< XNameContainer
> xNameContainer( m_xConfigAccess
, UNO_QUERY
);
459 if ( xNameContainer
.is() )
461 Reference
< XSingleServiceFactory
> xFactory( m_xConfigAccess
, UNO_QUERY
);
466 Reference
< XPropertySet
> xPropSet( xFactory
->createInstance(), UNO_QUERY
);
470 impl_putPropertiesFromStruct( aWinStateInfo
, xPropSet
);
472 xNameContainer
->insertByName( rResourceURL
, a
);
473 Reference
< XChangesBatch
> xFlush( xFactory
, UNO_QUERY
);
475 xFlush
->commitChanges();
478 catch ( const Exception
& )
487 throw IllegalArgumentException();
491 void SAL_CALL
ConfigurationAccess_WindowState::replaceByName( const OUString
& rResourceURL
, const css::uno::Any
& aPropertySet
)
492 throw( IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
)
495 ResetableGuard
aLock( m_aLock
);
497 Sequence
< PropertyValue
> aPropSet
;
498 if ( aPropertySet
>>= aPropSet
)
500 ResourceURLToInfoCache::iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
501 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
503 WindowStateInfo
& rWinStateInfo
= pIter
->second
;
504 impl_fillStructFromSequence( rWinStateInfo
, aPropSet
);
505 m_bModified
= sal_True
;
509 if ( !m_bConfigAccessInitialized
)
511 impl_initializeConfigAccess();
512 m_bConfigAccessInitialized
= sal_True
;
515 // Try to ask our configuration access
516 Reference
< XNameAccess
> xNameAccess
;
517 Any
a( m_xConfigAccess
->getByName( rResourceURL
));
519 if ( a
>>= xNameAccess
)
521 WindowStateInfo
& rWinStateInfo( impl_insertCacheAndReturnWinState( rResourceURL
, xNameAccess
));
522 impl_fillStructFromSequence( rWinStateInfo
, aPropSet
);
523 m_bModified
= sal_True
;
524 pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
527 throw NoSuchElementException();
530 if ( m_bModified
&& pIter
!= m_aResourceURLToInfoCache
.end() )
532 Reference
< XNameContainer
> xNameContainer( m_xConfigAccess
, UNO_QUERY
);
533 if ( xNameContainer
.is() )
535 WindowStateInfo
aWinStateInfo( pIter
->second
);
536 OUString
aResourceURL( pIter
->first
);
537 m_bModified
= sal_False
;
542 Reference
< XPropertySet
> xPropSet
;
543 if ( xNameContainer
->getByName( aResourceURL
) >>= xPropSet
)
545 impl_putPropertiesFromStruct( aWinStateInfo
, xPropSet
);
547 Reference
< XChangesBatch
> xFlush( m_xConfigAccess
, UNO_QUERY
);
549 xFlush
->commitChanges();
552 catch ( const Exception
& )
559 throw IllegalArgumentException();
562 // container.XContainerListener
563 void SAL_CALL
ConfigurationAccess_WindowState::elementInserted( const ContainerEvent
& ) throw(RuntimeException
)
565 // do nothing - next time someone wants to retrieve this node we will find it in the configuration
568 void SAL_CALL
ConfigurationAccess_WindowState::elementRemoved ( const ContainerEvent
& ) throw(RuntimeException
)
572 void SAL_CALL
ConfigurationAccess_WindowState::elementReplaced( const ContainerEvent
& ) throw(RuntimeException
)
576 // lang.XEventListener
577 void SAL_CALL
ConfigurationAccess_WindowState::disposing( const EventObject
& aEvent
) throw(RuntimeException
)
580 // remove our reference to the config access
581 ResetableGuard
aLock( m_aLock
);
583 Reference
< XInterface
> xIfac1( aEvent
.Source
, UNO_QUERY
);
584 Reference
< XInterface
> xIfac2( m_xConfigAccess
, UNO_QUERY
);
585 if ( xIfac1
== xIfac2
)
586 m_xConfigAccess
.clear();
589 // private helper methods
590 Any
ConfigurationAccess_WindowState::impl_getSequenceFromStruct( const WindowStateInfo
& rWinStateInfo
)
593 sal_Int32
nCount( m_aPropArray
.size() );
594 Sequence
< PropertyValue
> aPropSeq
;
596 for ( i
= 0; i
< nCount
; i
++ )
598 if ( rWinStateInfo
.nMask
& ( 1 << i
))
600 // put value into the return sequence
601 sal_Int32
nIndex( aPropSeq
.getLength());
602 aPropSeq
.realloc( nIndex
+1 );
603 aPropSeq
[nIndex
].Name
= m_aPropArray
[i
];
607 case PROPERTY_LOCKED
:
608 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bLocked
); break;
609 case PROPERTY_DOCKED
:
610 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bDocked
); break;
611 case PROPERTY_VISIBLE
:
612 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bVisible
); break;
613 case PROPERTY_CONTEXT
:
614 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bContext
); break;
615 case PROPERTY_HIDEFROMMENU
:
616 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bHideFromMenu
); break;
617 case PROPERTY_NOCLOSE
:
618 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bNoClose
); break;
619 case PROPERTY_SOFTCLOSE
:
620 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bSoftClose
); break;
621 case PROPERTY_CONTEXTACTIVE
:
622 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bContextActive
); break;
623 case PROPERTY_DOCKINGAREA
:
624 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aDockingArea
); break;
626 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aPos
); break;
628 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aSize
); break;
629 case PROPERTY_UINAME
:
630 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aUIName
); break;
631 case PROPERTY_INTERNALSTATE
:
632 aPropSeq
[nIndex
].Value
= makeAny( sal_Int32( rWinStateInfo
.nInternalState
)); break;
634 aPropSeq
[nIndex
].Value
= makeAny( sal_Int16( rWinStateInfo
.nStyle
)); break;
635 case PROPERTY_DOCKPOS
:
636 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aDockPos
); break;
637 case PROPERTY_DOCKSIZE
:
638 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aDockSize
); break;
640 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
645 return makeAny( aPropSeq
);
648 Any
ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const OUString
& rResourceURL
, Reference
< XNameAccess
>& xNameAccess
)
650 sal_Int32
nMask( 0 );
651 sal_Int32
nCount( m_aPropArray
.size() );
653 sal_Int32
nIndex( 0 );
654 Sequence
< PropertyValue
> aPropSeq
;
655 WindowStateInfo aWindowStateInfo
;
657 for ( i
= 0; i
< nCount
; i
++ )
661 bool bAddToSeq( false );
662 Any
a( xNameAccess
->getByName( m_aPropArray
[i
] ) );
665 case PROPERTY_LOCKED
:
666 case PROPERTY_DOCKED
:
667 case PROPERTY_VISIBLE
:
668 case PROPERTY_CONTEXT
:
669 case PROPERTY_HIDEFROMMENU
:
670 case PROPERTY_NOCLOSE
:
671 case PROPERTY_SOFTCLOSE
:
672 case PROPERTY_CONTEXTACTIVE
:
674 sal_Bool bValue
= sal_Bool();
677 sal_Int32
nValue( 1 << i
);
682 case PROPERTY_LOCKED
:
683 aWindowStateInfo
.bLocked
= bValue
; break;
684 case PROPERTY_DOCKED
:
685 aWindowStateInfo
.bDocked
= bValue
; break;
686 case PROPERTY_VISIBLE
:
687 aWindowStateInfo
.bVisible
= bValue
; break;
688 case PROPERTY_CONTEXT
:
689 aWindowStateInfo
.bContext
= bValue
; break;
690 case PROPERTY_HIDEFROMMENU
:
691 aWindowStateInfo
.bHideFromMenu
= bValue
; break;
692 case PROPERTY_NOCLOSE
:
693 aWindowStateInfo
.bNoClose
= bValue
; break;
694 case PROPERTY_SOFTCLOSE
:
695 aWindowStateInfo
.bSoftClose
= bValue
; break;
696 case PROPERTY_CONTEXTACTIVE
:
697 aWindowStateInfo
.bContextActive
= bValue
; break;
703 case PROPERTY_DOCKINGAREA
:
705 sal_Int32 nDockingArea
= 0;
706 if ( a
>>= nDockingArea
)
708 if (( nDockingArea
>= 0 ) &&
709 ( nDockingArea
<= sal_Int32( DockingArea_DOCKINGAREA_RIGHT
)))
711 aWindowStateInfo
.aDockingArea
= (DockingArea
)nDockingArea
;
712 nMask
|= WINDOWSTATE_MASK_DOCKINGAREA
;
713 a
= makeAny( aWindowStateInfo
.aDockingArea
);
721 case PROPERTY_DOCKPOS
:
726 sal_Int32
nToken( 0 );
727 OUString aXStr
= aString
.getToken( 0, ',', nToken
);
730 com::sun::star::awt::Point aPos
;
731 aPos
.X
= aXStr
.toInt32();
732 aPos
.Y
= aString
.getToken( 0, ',', nToken
).toInt32();
734 if ( i
== PROPERTY_POS
)
736 aWindowStateInfo
.aPos
= aPos
;
737 nMask
|= WINDOWSTATE_MASK_POS
;
741 aWindowStateInfo
.aDockPos
= aPos
;
742 nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
753 case PROPERTY_DOCKSIZE
:
758 sal_Int32
nToken( 0 );
759 OUString aStr
= aString
.getToken( 0, ',', nToken
);
762 com::sun::star::awt::Size aSize
;
763 aSize
.Width
= aStr
.toInt32();
764 aSize
.Height
= aString
.getToken( 0, ',', nToken
).toInt32();
765 if ( i
== PROPERTY_SIZE
)
767 aWindowStateInfo
.aSize
= aSize
;
768 nMask
|= WINDOWSTATE_MASK_SIZE
;
772 aWindowStateInfo
.aDockSize
= aSize
;
773 nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
783 case PROPERTY_UINAME
:
788 nMask
|= WINDOWSTATE_MASK_UINAME
;
789 aWindowStateInfo
.aUIName
= aValue
;
795 case PROPERTY_INTERNALSTATE
:
797 sal_uInt32 nValue
= 0;
800 nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
801 aWindowStateInfo
.nInternalState
= nValue
;
809 sal_Int32 nValue
= 0;
812 nMask
|= WINDOWSTATE_MASK_STYLE
;
813 aWindowStateInfo
.nStyle
= sal_uInt16( nValue
);
820 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
825 // put value into the return sequence
826 nIndex
= aPropSeq
.getLength();
827 aPropSeq
.realloc( nIndex
+1 );
828 aPropSeq
[nIndex
].Name
= m_aPropArray
[i
];
829 aPropSeq
[nIndex
].Value
= a
;
832 catch( const com::sun::star::container::NoSuchElementException
& )
835 catch ( const com::sun::star::lang::WrappedTargetException
& )
840 aWindowStateInfo
.nMask
= nMask
;
841 m_aResourceURLToInfoCache
.insert( ResourceURLToInfoCache::value_type( rResourceURL
, aWindowStateInfo
));
842 return makeAny( aPropSeq
);
845 ConfigurationAccess_WindowState::WindowStateInfo
& ConfigurationAccess_WindowState::impl_insertCacheAndReturnWinState( const OUString
& rResourceURL
, Reference
< XNameAccess
>& rNameAccess
)
847 sal_Int32
nMask( 0 );
848 sal_Int32
nCount( m_aPropArray
.size() );
850 Sequence
< PropertyValue
> aPropSeq
;
851 WindowStateInfo aWindowStateInfo
;
853 for ( i
= 0; i
< nCount
; i
++ )
857 Any
a( rNameAccess
->getByName( m_aPropArray
[i
] ) );
860 case PROPERTY_LOCKED
:
861 case PROPERTY_DOCKED
:
862 case PROPERTY_VISIBLE
:
863 case PROPERTY_CONTEXT
:
864 case PROPERTY_HIDEFROMMENU
:
865 case PROPERTY_NOCLOSE
:
866 case PROPERTY_SOFTCLOSE
:
867 case PROPERTY_CONTEXTACTIVE
:
869 sal_Bool bValue
= sal_Bool();
872 sal_Int32
nValue( 1 << i
);
876 case PROPERTY_LOCKED
:
877 aWindowStateInfo
.bLocked
= bValue
; break;
878 case PROPERTY_DOCKED
:
879 aWindowStateInfo
.bDocked
= bValue
; break;
880 case PROPERTY_VISIBLE
:
881 aWindowStateInfo
.bVisible
= bValue
; break;
882 case PROPERTY_CONTEXT
:
883 aWindowStateInfo
.bContext
= bValue
; break;
884 case PROPERTY_HIDEFROMMENU
:
885 aWindowStateInfo
.bHideFromMenu
= bValue
; break;
886 case PROPERTY_NOCLOSE
:
887 aWindowStateInfo
.bNoClose
= bValue
; break;
888 case PROPERTY_SOFTCLOSE
:
889 aWindowStateInfo
.bNoClose
= bValue
; break;
890 case PROPERTY_CONTEXTACTIVE
:
891 aWindowStateInfo
.bContextActive
= bValue
; break;
893 DBG_ASSERT( sal_False
, "Unknown boolean property in WindowState found!" );
899 case PROPERTY_DOCKINGAREA
:
901 sal_Int32 nDockingArea
= 0;
902 if ( a
>>= nDockingArea
)
904 if (( nDockingArea
>= 0 ) &&
905 ( nDockingArea
<= sal_Int32( DockingArea_DOCKINGAREA_RIGHT
)))
907 aWindowStateInfo
.aDockingArea
= (DockingArea
)nDockingArea
;
908 nMask
|= WINDOWSTATE_MASK_DOCKINGAREA
;
915 case PROPERTY_DOCKPOS
:
920 sal_Int32
nToken( 0 );
921 OUString aXStr
= aString
.getToken( 0, ',', nToken
);
924 com::sun::star::awt::Point aPos
;
925 aPos
.X
= aXStr
.toInt32();
926 aPos
.Y
= aString
.getToken( 0, ',', nToken
).toInt32();
928 if ( i
== PROPERTY_POS
)
930 aWindowStateInfo
.aPos
= aPos
;
931 nMask
|= WINDOWSTATE_MASK_POS
;
935 aWindowStateInfo
.aDockPos
= aPos
;
936 nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
944 case PROPERTY_DOCKSIZE
:
949 sal_Int32
nToken( 0 );
950 OUString aStr
= aString
.getToken( 0, ',', nToken
);
953 com::sun::star::awt::Size aSize
;
954 aSize
.Width
= aStr
.toInt32();
955 aSize
.Height
= aString
.getToken( 0, ',', nToken
).toInt32();
956 if ( i
== PROPERTY_SIZE
)
958 aWindowStateInfo
.aSize
= aSize
;
959 nMask
|= WINDOWSTATE_MASK_SIZE
;
963 aWindowStateInfo
.aDockSize
= aSize
;
964 nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
971 case PROPERTY_UINAME
:
976 nMask
|= WINDOWSTATE_MASK_UINAME
;
977 aWindowStateInfo
.aUIName
= aValue
;
982 case PROPERTY_INTERNALSTATE
:
984 sal_Int32 nValue
= 0;
987 nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
988 aWindowStateInfo
.nInternalState
= sal_uInt32( nValue
);
995 sal_Int32 nValue
= 0;
998 nMask
|= WINDOWSTATE_MASK_STYLE
;
999 aWindowStateInfo
.nStyle
= sal_uInt16( nValue
);
1004 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1007 catch( const com::sun::star::container::NoSuchElementException
& )
1010 catch ( const com::sun::star::lang::WrappedTargetException
& )
1015 aWindowStateInfo
.nMask
= nMask
;
1016 ResourceURLToInfoCache::iterator pIter
= (m_aResourceURLToInfoCache
.insert( ResourceURLToInfoCache::value_type( rResourceURL
, aWindowStateInfo
))).first
;
1017 return pIter
->second
;
1020 Any
ConfigurationAccess_WindowState::impl_getWindowStateFromResourceURL( const OUString
& rResourceURL
)
1022 if ( !m_bConfigAccessInitialized
)
1024 impl_initializeConfigAccess();
1025 m_bConfigAccessInitialized
= sal_True
;
1030 // Try to ask our configuration access
1031 if ( m_xConfigAccess
.is() && m_xConfigAccess
->hasByName( rResourceURL
) )
1034 Reference
< XNameAccess
> xNameAccess( m_xConfigAccess
->getByName( rResourceURL
), UNO_QUERY
);
1035 if ( xNameAccess
.is() )
1036 return impl_insertCacheAndReturnSequence( rResourceURL
, xNameAccess
);
1039 catch( const com::sun::star::container::NoSuchElementException
& )
1042 catch ( const com::sun::star::lang::WrappedTargetException
& )
1049 void ConfigurationAccess_WindowState::impl_fillStructFromSequence( WindowStateInfo
& rWinStateInfo
, const Sequence
< PropertyValue
>& rSeq
)
1051 sal_Int32
nCompareCount( m_aPropArray
.size() );
1052 sal_Int32
nCount( rSeq
.getLength() );
1055 for ( i
= 0; i
< nCount
; i
++ )
1057 for ( sal_Int32 j
= 0; j
< nCompareCount
; j
++ )
1059 if ( rSeq
[i
].Name
.equals( m_aPropArray
[j
] ))
1063 case PROPERTY_LOCKED
:
1064 case PROPERTY_DOCKED
:
1065 case PROPERTY_VISIBLE
:
1066 case PROPERTY_CONTEXT
:
1067 case PROPERTY_HIDEFROMMENU
:
1068 case PROPERTY_NOCLOSE
:
1069 case PROPERTY_SOFTCLOSE
:
1070 case PROPERTY_CONTEXTACTIVE
:
1072 sal_Bool bValue
= sal_Bool();
1073 if ( rSeq
[i
].Value
>>= bValue
)
1075 sal_Int32
nValue( 1 << j
);
1076 rWinStateInfo
.nMask
|= nValue
;
1079 case PROPERTY_LOCKED
:
1080 rWinStateInfo
.bLocked
= bValue
;
1082 case PROPERTY_DOCKED
:
1083 rWinStateInfo
.bDocked
= bValue
;
1085 case PROPERTY_VISIBLE
:
1086 rWinStateInfo
.bVisible
= bValue
;
1088 case PROPERTY_CONTEXT
:
1089 rWinStateInfo
.bContext
= bValue
;
1091 case PROPERTY_HIDEFROMMENU
:
1092 rWinStateInfo
.bHideFromMenu
= bValue
;
1094 case PROPERTY_NOCLOSE
:
1095 rWinStateInfo
.bNoClose
= bValue
;
1097 case PROPERTY_SOFTCLOSE
:
1098 rWinStateInfo
.bSoftClose
= bValue
;
1100 case PROPERTY_CONTEXTACTIVE
:
1101 rWinStateInfo
.bContextActive
= bValue
;
1104 DBG_ASSERT( sal_False
, "Unknown boolean property in WindowState found!" );
1110 case PROPERTY_DOCKINGAREA
:
1112 ::com::sun::star::ui::DockingArea eDockingArea
;
1113 if ( rSeq
[i
].Value
>>= eDockingArea
)
1115 rWinStateInfo
.aDockingArea
= eDockingArea
;
1116 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKINGAREA
;
1122 case PROPERTY_DOCKPOS
:
1124 com::sun::star::awt::Point aPoint
;
1125 if ( rSeq
[i
].Value
>>= aPoint
)
1127 if ( j
== PROPERTY_POS
)
1129 rWinStateInfo
.aPos
= aPoint
;
1130 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_POS
;
1134 rWinStateInfo
.aDockPos
= aPoint
;
1135 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
1142 case PROPERTY_DOCKSIZE
:
1144 com::sun::star::awt::Size aSize
;
1145 if ( rSeq
[i
].Value
>>= aSize
)
1147 if ( j
== PROPERTY_SIZE
)
1149 rWinStateInfo
.aSize
= aSize
;
1150 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_SIZE
;
1154 rWinStateInfo
.aDockSize
= aSize
;
1155 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
1161 case PROPERTY_UINAME
:
1164 if ( rSeq
[i
].Value
>>= aValue
)
1166 rWinStateInfo
.aUIName
= aValue
;
1167 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_UINAME
;
1172 case PROPERTY_INTERNALSTATE
:
1174 sal_Int32 nValue
= 0;
1175 if ( rSeq
[i
].Value
>>= nValue
)
1177 rWinStateInfo
.nInternalState
= sal_uInt32( nValue
);
1178 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
1183 case PROPERTY_STYLE
:
1185 sal_Int32 nValue
= 0;
1186 if ( rSeq
[i
].Value
>>= nValue
)
1188 rWinStateInfo
.nStyle
= sal_uInt16( nValue
);
1189 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_STYLE
;
1195 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1204 void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const WindowStateInfo
& rWinStateInfo
, Reference
< XPropertySet
>& xPropSet
)
1207 sal_Int32
nCount( m_aPropArray
.size() );
1208 Sequence
< PropertyValue
> aPropSeq
;
1209 OUString
aDelim( "," );
1211 for ( i
= 0; i
< nCount
; i
++ )
1213 if ( rWinStateInfo
.nMask
& ( 1 << i
))
1217 // put values into the property set
1220 case PROPERTY_LOCKED
:
1221 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bLocked
)) ); break;
1222 case PROPERTY_DOCKED
:
1223 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bDocked
)) ); break;
1224 case PROPERTY_VISIBLE
:
1225 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bVisible
)) ); break;
1226 case PROPERTY_CONTEXT
:
1227 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bContext
)) ); break;
1228 case PROPERTY_HIDEFROMMENU
:
1229 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bHideFromMenu
)) ); break;
1230 case PROPERTY_NOCLOSE
:
1231 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bNoClose
)) ); break;
1232 case PROPERTY_SOFTCLOSE
:
1233 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bSoftClose
)) ); break;
1234 case PROPERTY_CONTEXTACTIVE
:
1235 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Bool( rWinStateInfo
.bContextActive
)) ); break;
1236 case PROPERTY_DOCKINGAREA
:
1237 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Int16( rWinStateInfo
.aDockingArea
) ) ); break;
1239 case PROPERTY_DOCKPOS
:
1242 if ( i
== PROPERTY_POS
)
1243 aPosStr
= OUString::valueOf( rWinStateInfo
.aPos
.X
);
1245 aPosStr
= OUString::valueOf( rWinStateInfo
.aDockPos
.X
);
1247 if ( i
== PROPERTY_POS
)
1248 aPosStr
+= OUString::valueOf( rWinStateInfo
.aPos
.Y
);
1250 aPosStr
+= OUString::valueOf( rWinStateInfo
.aDockPos
.Y
);
1251 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( aPosStr
) );
1255 case PROPERTY_DOCKSIZE
:
1258 if ( i
== PROPERTY_SIZE
)
1259 aSizeStr
= ( OUString::valueOf( rWinStateInfo
.aSize
.Width
));
1261 aSizeStr
= ( OUString::valueOf( rWinStateInfo
.aDockSize
.Width
));
1263 if ( i
== PROPERTY_SIZE
)
1264 aSizeStr
+= OUString::valueOf( rWinStateInfo
.aSize
.Height
);
1266 aSizeStr
+= OUString::valueOf( rWinStateInfo
.aDockSize
.Height
);
1267 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( aSizeStr
) );
1270 case PROPERTY_UINAME
:
1271 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.aUIName
) ); break;
1272 case PROPERTY_INTERNALSTATE
:
1273 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Int32( rWinStateInfo
.nInternalState
)) ); break;
1274 case PROPERTY_STYLE
:
1275 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Int32( rWinStateInfo
.nStyle
)) ); break;
1277 DBG_ASSERT( sal_False
, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1280 catch( const Exception
& )
1287 sal_Bool
ConfigurationAccess_WindowState::impl_initializeConfigAccess()
1289 Sequence
< Any
> aArgs( 2 );
1290 PropertyValue aPropValue
;
1294 aPropValue
.Name
= OUString( "nodepath" );
1295 aPropValue
.Value
<<= m_aConfigWindowAccess
;
1296 aArgs
[0] <<= aPropValue
;
1297 aPropValue
.Name
= OUString( "lazywrite" );
1298 aPropValue
.Value
<<= sal_True
;
1299 aArgs
[1] <<= aPropValue
;
1301 m_xConfigAccess
= Reference
< XNameAccess
>( m_xConfigProvider
->createInstanceWithArguments(
1302 SERVICENAME_CFGUPDATEACCESS
, aArgs
),
1304 if ( m_xConfigAccess
.is() )
1306 // Add as container listener
1307 Reference
< XContainer
> xContainer( m_xConfigAccess
, UNO_QUERY
);
1308 if ( xContainer
.is() )
1310 m_xConfigListener
= new WeakContainerListener(this);
1311 xContainer
->addContainerListener(m_xConfigListener
);
1317 catch ( const WrappedTargetException
& )
1320 catch ( const Exception
& )
1328 //*****************************************************************************************************************
1329 // XInterface, XTypeProvider, XServiceInfo
1330 //*****************************************************************************************************************
1331 DEFINE_XINTERFACE_4 ( WindowStateConfiguration
,
1333 DIRECT_INTERFACE( css::lang::XTypeProvider
),
1334 DIRECT_INTERFACE( css::lang::XServiceInfo
),
1335 DIRECT_INTERFACE( css::container::XNameAccess
),
1336 DERIVED_INTERFACE( css::container::XElementAccess
, css::container::XNameAccess
)
1339 DEFINE_XTYPEPROVIDER_4 ( WindowStateConfiguration
,
1340 css::lang::XTypeProvider
,
1341 css::lang::XServiceInfo
,
1342 css::container::XNameAccess
,
1343 css::container::XElementAccess
1346 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE_2( WindowStateConfiguration
,
1347 ::cppu::OWeakObject
,
1348 DECLARE_ASCII("com.sun.star.ui.WindowStateConfiguration"),
1349 IMPLEMENTATIONNAME_WINDOWSTATECONFIGURATION
1352 DEFINE_INIT_SERVICE ( WindowStateConfiguration
, {} )
1354 WindowStateConfiguration::WindowStateConfiguration( const Reference
< XComponentContext
>& rxContext
) :
1356 m_xContext( rxContext
)
1358 m_xModuleManager
= ModuleManager::create( m_xContext
);
1359 Reference
< XNameAccess
> xEmptyNameAccess
;
1360 Sequence
< OUString
> aElementNames
;
1363 aElementNames
= m_xModuleManager
->getElementNames();
1365 catch (const ::com::sun::star::uno::RuntimeException
&)
1368 Sequence
< PropertyValue
> aSeq
;
1369 OUString aModuleIdentifier
;
1371 for ( sal_Int32 i
= 0; i
< aElementNames
.getLength(); i
++ )
1373 aModuleIdentifier
= aElementNames
[i
];
1374 if ( m_xModuleManager
->getByName( aModuleIdentifier
) >>= aSeq
)
1376 OUString aWindowStateFileStr
;
1377 for ( sal_Int32 y
= 0; y
< aSeq
.getLength(); y
++ )
1379 if ( aSeq
[y
].Name
== "ooSetupFactoryWindowStateConfigRef" )
1381 aSeq
[y
].Value
>>= aWindowStateFileStr
;
1386 if ( !aWindowStateFileStr
.isEmpty() )
1388 // Create first mapping ModuleIdentifier ==> Window state configuration file
1389 m_aModuleToFileHashMap
.insert( ModuleToWindowStateFileMap::value_type( aModuleIdentifier
, aWindowStateFileStr
));
1391 // Create second mapping Command File ==> Window state configuration instance
1392 ModuleToWindowStateConfigHashMap::iterator pIter
= m_aModuleToWindowStateHashMap
.find( aWindowStateFileStr
);
1393 if ( pIter
== m_aModuleToWindowStateHashMap
.end() )
1394 m_aModuleToWindowStateHashMap
.insert( ModuleToWindowStateConfigHashMap::value_type( aWindowStateFileStr
, xEmptyNameAccess
));
1400 WindowStateConfiguration::~WindowStateConfiguration()
1402 ResetableGuard
aLock( m_aLock
);
1403 m_aModuleToFileHashMap
.clear();
1404 m_aModuleToWindowStateHashMap
.clear();
1407 Any SAL_CALL
WindowStateConfiguration::getByName( const OUString
& aModuleIdentifier
)
1408 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
)
1410 ResetableGuard
aLock( m_aLock
);
1412 ModuleToWindowStateFileMap::const_iterator pIter
= m_aModuleToFileHashMap
.find( aModuleIdentifier
);
1413 if ( pIter
!= m_aModuleToFileHashMap
.end() )
1416 OUString
aWindowStateConfigFile( pIter
->second
);
1418 ModuleToWindowStateConfigHashMap::iterator pModuleIter
= m_aModuleToWindowStateHashMap
.find( aWindowStateConfigFile
);
1419 if ( pModuleIter
!= m_aModuleToWindowStateHashMap
.end() )
1421 if ( pModuleIter
->second
.is() )
1422 a
= makeAny( pModuleIter
->second
);
1425 Reference
< XNameAccess
> xResourceURLWindowState
;
1426 ConfigurationAccess_WindowState
* pModuleWindowState
= new ConfigurationAccess_WindowState( aWindowStateConfigFile
, m_xContext
);
1427 xResourceURLWindowState
= Reference
< XNameAccess
>( static_cast< cppu::OWeakObject
* >( pModuleWindowState
),UNO_QUERY
);
1428 pModuleIter
->second
= xResourceURLWindowState
;
1429 a
<<= xResourceURLWindowState
;
1436 throw NoSuchElementException();
1439 Sequence
< OUString
> SAL_CALL
WindowStateConfiguration::getElementNames()
1440 throw (::com::sun::star::uno::RuntimeException
)
1442 ResetableGuard
aLock( m_aLock
);
1444 Sequence
< OUString
> aSeq( m_aModuleToFileHashMap
.size() );
1447 ModuleToWindowStateFileMap::const_iterator pIter
= m_aModuleToFileHashMap
.begin();
1448 while ( pIter
!= m_aModuleToFileHashMap
.end() )
1450 aSeq
[n
] = pIter
->first
;
1457 sal_Bool SAL_CALL
WindowStateConfiguration::hasByName( const OUString
& aName
)
1458 throw (::com::sun::star::uno::RuntimeException
)
1460 ResetableGuard
aLock( m_aLock
);
1462 ModuleToWindowStateFileMap::const_iterator pIter
= m_aModuleToFileHashMap
.find( aName
);
1463 return ( pIter
!= m_aModuleToFileHashMap
.end() );
1467 Type SAL_CALL
WindowStateConfiguration::getElementType()
1468 throw (::com::sun::star::uno::RuntimeException
)
1470 return( ::getCppuType( (const Reference
< XNameAccess
>*)NULL
) );
1473 sal_Bool SAL_CALL
WindowStateConfiguration::hasElements()
1474 throw (::com::sun::star::uno::RuntimeException
)
1476 // We always have at least one module. So it is valid to return true!
1480 } // namespace framework
1482 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */