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/windowstateproperties.hxx>
21 #include <helper/mischelper.hxx>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/configuration/theDefaultProvider.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/container/XContainer.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 #include <com/sun/star/frame/ModuleManager.hpp>
32 #include <com/sun/star/frame/XModuleManager2.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>
37 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <cppuhelper/basemutex.hxx>
40 #include <cppuhelper/compbase2.hxx>
41 #include <cppuhelper/implbase2.hxx>
42 #include <cppuhelper/supportsservice.hxx>
43 #include <tools/debug.hxx>
45 #include <unordered_map>
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::lang
;
50 using namespace com::sun::star::beans
;
51 using namespace com::sun::star::util
;
52 using namespace com::sun::star::configuration
;
53 using namespace com::sun::star::container
;
54 using namespace ::com::sun::star::frame
;
55 using namespace ::com::sun::star::ui
;
56 using namespace framework
;
58 #undef WINDOWSTATE_MASK_POS
62 // Zero based indexes, order must be the same as WindowStateMask && CONFIGURATION_PROPERTIES!
63 static const sal_Int16 PROPERTY_LOCKED
= 0;
64 static const sal_Int16 PROPERTY_DOCKED
= 1;
65 static const sal_Int16 PROPERTY_VISIBLE
= 2;
66 static const sal_Int16 PROPERTY_CONTEXT
= 3;
67 static const sal_Int16 PROPERTY_HIDEFROMMENU
= 4;
68 static const sal_Int16 PROPERTY_NOCLOSE
= 5;
69 static const sal_Int16 PROPERTY_SOFTCLOSE
= 6;
70 static const sal_Int16 PROPERTY_CONTEXTACTIVE
= 7;
71 static const sal_Int16 PROPERTY_DOCKINGAREA
= 8;
72 static const sal_Int16 PROPERTY_POS
= 9;
73 static const sal_Int16 PROPERTY_SIZE
= 10;
74 static const sal_Int16 PROPERTY_UINAME
= 11;
75 static const sal_Int16 PROPERTY_INTERNALSTATE
= 12;
76 static const sal_Int16 PROPERTY_STYLE
= 13;
77 static const sal_Int16 PROPERTY_DOCKPOS
= 14;
78 static const sal_Int16 PROPERTY_DOCKSIZE
= 15;
80 // Order must be the same as WindowStateMask!!
81 static const char* CONFIGURATION_PROPERTIES
[] =
83 WINDOWSTATE_PROPERTY_LOCKED
,
84 WINDOWSTATE_PROPERTY_DOCKED
,
85 WINDOWSTATE_PROPERTY_VISIBLE
,
86 WINDOWSTATE_PROPERTY_CONTEXT
,
87 WINDOWSTATE_PROPERTY_HIDEFROMENU
,
88 WINDOWSTATE_PROPERTY_NOCLOSE
,
89 WINDOWSTATE_PROPERTY_SOFTCLOSE
,
90 WINDOWSTATE_PROPERTY_CONTEXTACTIVE
,
91 WINDOWSTATE_PROPERTY_DOCKINGAREA
,
92 WINDOWSTATE_PROPERTY_POS
,
93 WINDOWSTATE_PROPERTY_SIZE
,
94 WINDOWSTATE_PROPERTY_UINAME
,
95 WINDOWSTATE_PROPERTY_INTERNALSTATE
,
96 WINDOWSTATE_PROPERTY_STYLE
,
97 WINDOWSTATE_PROPERTY_DOCKPOS
,
98 WINDOWSTATE_PROPERTY_DOCKSIZE
,
102 // Configuration access class for WindowState supplier implementation
104 class ConfigurationAccess_WindowState
: public ::cppu::WeakImplHelper2
< XNameContainer
, XContainerListener
>
107 ConfigurationAccess_WindowState( const OUString
& aWindowStateConfigFile
, const Reference
< XComponentContext
>& rxContext
);
108 virtual ~ConfigurationAccess_WindowState();
111 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const OUString
& aName
)
112 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getElementNames()
115 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
117 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
)
118 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
121 virtual void SAL_CALL
removeByName( const OUString
& sName
)
122 throw(css::container::NoSuchElementException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
124 virtual void SAL_CALL
insertByName( const OUString
& sName
, const css::uno::Any
& aPropertySet
)
125 throw(css::lang::IllegalArgumentException
, css::container::ElementExistException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
128 virtual void SAL_CALL
replaceByName( const OUString
& sName
, const css::uno::Any
& aPropertySet
)
129 throw(css::lang::IllegalArgumentException
, css::container::NoSuchElementException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
132 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType()
133 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
135 virtual sal_Bool SAL_CALL
hasElements()
136 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
138 // container.XContainerListener
139 virtual void SAL_CALL
elementInserted( const ContainerEvent
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
140 virtual void SAL_CALL
elementRemoved ( const ContainerEvent
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
141 virtual void SAL_CALL
elementReplaced( const ContainerEvent
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
143 // lang.XEventListener
144 virtual void SAL_CALL
disposing( const EventObject
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
149 WINDOWSTATE_MASK_LOCKED
= 1,
150 WINDOWSTATE_MASK_DOCKED
= 2,
151 WINDOWSTATE_MASK_VISIBLE
= 4,
152 WINDOWSTATE_MASK_CONTEXT
= 8,
153 WINDOWSTATE_MASK_HIDEFROMMENU
= 16,
154 WINDOWSTATE_MASK_NOCLOSE
= 32,
155 WINDOWSTATE_MASK_SOFTCLOSE
= 64,
156 WINDOWSTATE_MASK_CONTEXTACTIVE
= 128,
157 WINDOWSTATE_MASK_DOCKINGAREA
= 256,
158 WINDOWSTATE_MASK_POS
= 512,
159 WINDOWSTATE_MASK_SIZE
= 1024,
160 WINDOWSTATE_MASK_UINAME
= 2048,
161 WINDOWSTATE_MASK_INTERNALSTATE
= 4096,
162 WINDOWSTATE_MASK_STYLE
= 8192,
163 WINDOWSTATE_MASK_DOCKPOS
= 16384,
164 WINDOWSTATE_MASK_DOCKSIZE
= 32768
167 // Cache structure. Valid values are described by the eMask member. All other values should not be
168 // provided to outside code!
169 struct WindowStateInfo
176 , bHideFromMenu(false)
179 , bContextActive(false)
180 , aDockingArea(::com::sun::star::ui::DockingArea_DOCKINGAREA_TOP
)
198 ::com::sun::star::ui::DockingArea aDockingArea
;
199 com::sun::star::awt::Point aDockPos
;
200 com::sun::star::awt::Size aDockSize
;
201 com::sun::star::awt::Point aPos
;
202 com::sun::star::awt::Size aSize
;
204 sal_uInt32 nInternalState
;
206 sal_uInt32 nMask
; // see WindowStateMask
209 void impl_putPropertiesFromStruct( const WindowStateInfo
& rWinStateInfo
, Reference
< XPropertySet
>& xPropSet
);
210 Any
impl_insertCacheAndReturnSequence( const OUString
& rResourceURL
, Reference
< XNameAccess
>& rNameAccess
);
211 WindowStateInfo
& impl_insertCacheAndReturnWinState( const OUString
& rResourceURL
, Reference
< XNameAccess
>& rNameAccess
);
212 Any
impl_getSequenceFromStruct( const WindowStateInfo
& rWinStateInfo
);
213 void impl_fillStructFromSequence( WindowStateInfo
& rWinStateInfo
, const Sequence
< PropertyValue
>& rSeq
);
214 Any
impl_getWindowStateFromResourceURL( const OUString
& rResourceURL
);
215 bool impl_initializeConfigAccess();
218 typedef std::unordered_map
< OUString
,
221 std::equal_to
< OUString
> > ResourceURLToInfoCache
;
224 OUString m_aConfigWindowAccess
;
225 Reference
< XMultiServiceFactory
> m_xConfigProvider
;
226 Reference
< XNameAccess
> m_xConfigAccess
;
227 Reference
< XContainerListener
> m_xConfigListener
;
228 ResourceURLToInfoCache m_aResourceURLToInfoCache
;
229 bool m_bConfigAccessInitialized
: 1,
231 std::vector
< OUString
> m_aPropArray
;
234 ConfigurationAccess_WindowState::ConfigurationAccess_WindowState( const OUString
& aModuleName
, const Reference
< XComponentContext
>& rxContext
) :
235 m_aConfigWindowAccess( "/org.openoffice.Office.UI." ),
236 m_bConfigAccessInitialized( false ),
239 // Create configuration hierarchical access name
240 m_aConfigWindowAccess
+= aModuleName
;
241 m_aConfigWindowAccess
+= "/UIElements/States";
242 m_xConfigProvider
= theDefaultProvider::get( rxContext
);
244 // Initialize access array with property names.
246 while ( CONFIGURATION_PROPERTIES
[n
] )
248 m_aPropArray
.push_back( OUString::createFromAscii( CONFIGURATION_PROPERTIES
[n
] ));
253 ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState()
256 osl::MutexGuard
g(m_aMutex
);
257 Reference
< XContainer
> xContainer( m_xConfigAccess
, UNO_QUERY
);
258 if ( xContainer
.is() )
259 xContainer
->removeContainerListener(m_xConfigListener
);
263 Any SAL_CALL
ConfigurationAccess_WindowState::getByName( const OUString
& rResourceURL
)
264 throw ( NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
267 osl::MutexGuard
g(m_aMutex
);
269 ResourceURLToInfoCache::const_iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
270 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
271 return impl_getSequenceFromStruct( pIter
->second
);
274 Any
a( impl_getWindowStateFromResourceURL( rResourceURL
) );
276 throw NoSuchElementException();
282 Sequence
< OUString
> SAL_CALL
ConfigurationAccess_WindowState::getElementNames()
283 throw ( RuntimeException
, std::exception
)
286 osl::MutexGuard
g(m_aMutex
);
288 if ( !m_bConfigAccessInitialized
)
290 impl_initializeConfigAccess();
291 m_bConfigAccessInitialized
= true;
294 if ( m_xConfigAccess
.is() )
295 return m_xConfigAccess
->getElementNames();
297 return Sequence
< OUString
> ();
300 sal_Bool SAL_CALL
ConfigurationAccess_WindowState::hasByName( const OUString
& rResourceURL
)
301 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
304 osl::MutexGuard
g(m_aMutex
);
306 ResourceURLToInfoCache::const_iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
307 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
311 Any
a( impl_getWindowStateFromResourceURL( rResourceURL
) );
320 Type SAL_CALL
ConfigurationAccess_WindowState::getElementType()
321 throw ( RuntimeException
, std::exception
)
323 return( cppu::UnoType
<Sequence
< PropertyValue
>>::get() );
326 sal_Bool SAL_CALL
ConfigurationAccess_WindowState::hasElements()
327 throw ( RuntimeException
, std::exception
)
330 osl::MutexGuard
g(m_aMutex
);
332 if ( !m_bConfigAccessInitialized
)
334 impl_initializeConfigAccess();
335 m_bConfigAccessInitialized
= true;
338 if ( m_xConfigAccess
.is() )
339 return m_xConfigAccess
->hasElements();
345 void SAL_CALL
ConfigurationAccess_WindowState::removeByName( const OUString
& rResourceURL
)
346 throw( NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
349 osl::ResettableMutexGuard
g(m_aMutex
);
351 ResourceURLToInfoCache::iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
352 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
353 m_aResourceURLToInfoCache
.erase( pIter
);
355 if ( !m_bConfigAccessInitialized
)
357 impl_initializeConfigAccess();
358 m_bConfigAccessInitialized
= true;
363 // Remove must be write-through => remove element from configuration
364 Reference
< XNameContainer
> xNameContainer( m_xConfigAccess
, UNO_QUERY
);
365 if ( xNameContainer
.is() )
369 xNameContainer
->removeByName( rResourceURL
);
370 Reference
< XChangesBatch
> xFlush( m_xConfigAccess
, UNO_QUERY
);
372 xFlush
->commitChanges();
375 catch ( const com::sun::star::lang::WrappedTargetException
& )
380 void SAL_CALL
ConfigurationAccess_WindowState::insertByName( const OUString
& rResourceURL
, const css::uno::Any
& aPropertySet
)
381 throw( IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
, std::exception
)
384 osl::ResettableMutexGuard
g(m_aMutex
);
386 Sequence
< PropertyValue
> aPropSet
;
387 if ( aPropertySet
>>= aPropSet
)
389 ResourceURLToInfoCache::const_iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
390 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
391 throw ElementExistException();
394 if ( !m_bConfigAccessInitialized
)
396 impl_initializeConfigAccess();
397 m_bConfigAccessInitialized
= true;
400 // Try to ask our configuration access
401 if ( m_xConfigAccess
.is() )
403 if ( m_xConfigAccess
->hasByName( rResourceURL
) )
404 throw ElementExistException();
407 WindowStateInfo aWinStateInfo
;
408 impl_fillStructFromSequence( aWinStateInfo
, aPropSet
);
409 m_aResourceURLToInfoCache
.insert( ResourceURLToInfoCache::value_type( rResourceURL
, aWinStateInfo
));
411 // insert must be write-through => insert element into configuration
412 Reference
< XNameContainer
> xNameContainer( m_xConfigAccess
, UNO_QUERY
);
413 if ( xNameContainer
.is() )
415 Reference
< XSingleServiceFactory
> xFactory( m_xConfigAccess
, UNO_QUERY
);
420 Reference
< XPropertySet
> xPropSet( xFactory
->createInstance(), UNO_QUERY
);
424 impl_putPropertiesFromStruct( aWinStateInfo
, xPropSet
);
426 xNameContainer
->insertByName( rResourceURL
, a
);
427 Reference
< XChangesBatch
> xFlush( xFactory
, UNO_QUERY
);
429 xFlush
->commitChanges();
432 catch ( const Exception
& )
441 throw IllegalArgumentException();
445 void SAL_CALL
ConfigurationAccess_WindowState::replaceByName( const OUString
& rResourceURL
, const css::uno::Any
& aPropertySet
)
446 throw( IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
449 osl::ResettableMutexGuard
g(m_aMutex
);
451 Sequence
< PropertyValue
> aPropSet
;
452 if ( aPropertySet
>>= aPropSet
)
454 ResourceURLToInfoCache::iterator pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
455 if ( pIter
!= m_aResourceURLToInfoCache
.end() )
457 WindowStateInfo
& rWinStateInfo
= pIter
->second
;
458 impl_fillStructFromSequence( rWinStateInfo
, aPropSet
);
463 if ( !m_bConfigAccessInitialized
)
465 impl_initializeConfigAccess();
466 m_bConfigAccessInitialized
= true;
469 // Try to ask our configuration access
470 Reference
< XNameAccess
> xNameAccess
;
471 Any
a( m_xConfigAccess
->getByName( rResourceURL
));
473 if ( a
>>= xNameAccess
)
475 WindowStateInfo
& rWinStateInfo( impl_insertCacheAndReturnWinState( rResourceURL
, xNameAccess
));
476 impl_fillStructFromSequence( rWinStateInfo
, aPropSet
);
478 pIter
= m_aResourceURLToInfoCache
.find( rResourceURL
);
481 throw NoSuchElementException();
484 if ( m_bModified
&& pIter
!= m_aResourceURLToInfoCache
.end() )
486 Reference
< XNameContainer
> xNameContainer( m_xConfigAccess
, UNO_QUERY
);
487 if ( xNameContainer
.is() )
489 WindowStateInfo
aWinStateInfo( pIter
->second
);
490 OUString
aResourceURL( pIter
->first
);
496 Reference
< XPropertySet
> xPropSet
;
497 if ( xNameContainer
->getByName( aResourceURL
) >>= xPropSet
)
499 impl_putPropertiesFromStruct( aWinStateInfo
, xPropSet
);
501 Reference
< XChangesBatch
> xFlush( m_xConfigAccess
, UNO_QUERY
);
503 xFlush
->commitChanges();
506 catch ( const Exception
& )
513 throw IllegalArgumentException();
516 // container.XContainerListener
517 void SAL_CALL
ConfigurationAccess_WindowState::elementInserted( const ContainerEvent
& ) throw(RuntimeException
, std::exception
)
519 // do nothing - next time someone wants to retrieve this node we will find it in the configuration
522 void SAL_CALL
ConfigurationAccess_WindowState::elementRemoved ( const ContainerEvent
& ) throw(RuntimeException
, std::exception
)
526 void SAL_CALL
ConfigurationAccess_WindowState::elementReplaced( const ContainerEvent
& ) throw(RuntimeException
, std::exception
)
530 // lang.XEventListener
531 void SAL_CALL
ConfigurationAccess_WindowState::disposing( const EventObject
& aEvent
) throw(RuntimeException
, std::exception
)
534 // remove our reference to the config access
535 osl::MutexGuard
g(m_aMutex
);
537 Reference
< XInterface
> xIfac1( aEvent
.Source
, UNO_QUERY
);
538 Reference
< XInterface
> xIfac2( m_xConfigAccess
, UNO_QUERY
);
539 if ( xIfac1
== xIfac2
)
540 m_xConfigAccess
.clear();
543 // private helper methods
544 Any
ConfigurationAccess_WindowState::impl_getSequenceFromStruct( const WindowStateInfo
& rWinStateInfo
)
547 sal_Int32
nCount( m_aPropArray
.size() );
548 Sequence
< PropertyValue
> aPropSeq
;
550 for ( i
= 0; i
< nCount
; i
++ )
552 if ( rWinStateInfo
.nMask
& ( 1 << i
))
554 // put value into the return sequence
555 sal_Int32
nIndex( aPropSeq
.getLength());
556 aPropSeq
.realloc( nIndex
+1 );
557 aPropSeq
[nIndex
].Name
= m_aPropArray
[i
];
561 case PROPERTY_LOCKED
:
562 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bLocked
); break;
563 case PROPERTY_DOCKED
:
564 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bDocked
); break;
565 case PROPERTY_VISIBLE
:
566 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bVisible
); break;
567 case PROPERTY_CONTEXT
:
568 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bContext
); break;
569 case PROPERTY_HIDEFROMMENU
:
570 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bHideFromMenu
); break;
571 case PROPERTY_NOCLOSE
:
572 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bNoClose
); break;
573 case PROPERTY_SOFTCLOSE
:
574 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bSoftClose
); break;
575 case PROPERTY_CONTEXTACTIVE
:
576 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.bContextActive
); break;
577 case PROPERTY_DOCKINGAREA
:
578 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aDockingArea
); break;
580 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aPos
); break;
582 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aSize
); break;
583 case PROPERTY_UINAME
:
584 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aUIName
); break;
585 case PROPERTY_INTERNALSTATE
:
586 aPropSeq
[nIndex
].Value
= makeAny( sal_Int32( rWinStateInfo
.nInternalState
)); break;
588 aPropSeq
[nIndex
].Value
= makeAny( sal_Int16( rWinStateInfo
.nStyle
)); break;
589 case PROPERTY_DOCKPOS
:
590 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aDockPos
); break;
591 case PROPERTY_DOCKSIZE
:
592 aPropSeq
[nIndex
].Value
= makeAny( rWinStateInfo
.aDockSize
); break;
594 DBG_ASSERT( false, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
599 return makeAny( aPropSeq
);
602 Any
ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const OUString
& rResourceURL
, Reference
< XNameAccess
>& xNameAccess
)
604 sal_Int32
nMask( 0 );
605 sal_Int32
nCount( m_aPropArray
.size() );
607 sal_Int32
nIndex( 0 );
608 Sequence
< PropertyValue
> aPropSeq
;
609 WindowStateInfo aWindowStateInfo
;
611 for ( i
= 0; i
< nCount
; i
++ )
615 bool bAddToSeq( false );
616 Any
a( xNameAccess
->getByName( m_aPropArray
[i
] ) );
619 case PROPERTY_LOCKED
:
620 case PROPERTY_DOCKED
:
621 case PROPERTY_VISIBLE
:
622 case PROPERTY_CONTEXT
:
623 case PROPERTY_HIDEFROMMENU
:
624 case PROPERTY_NOCLOSE
:
625 case PROPERTY_SOFTCLOSE
:
626 case PROPERTY_CONTEXTACTIVE
:
631 sal_Int32
nValue( 1 << i
);
636 case PROPERTY_LOCKED
:
637 aWindowStateInfo
.bLocked
= bValue
; break;
638 case PROPERTY_DOCKED
:
639 aWindowStateInfo
.bDocked
= bValue
; break;
640 case PROPERTY_VISIBLE
:
641 aWindowStateInfo
.bVisible
= bValue
; break;
642 case PROPERTY_CONTEXT
:
643 aWindowStateInfo
.bContext
= bValue
; break;
644 case PROPERTY_HIDEFROMMENU
:
645 aWindowStateInfo
.bHideFromMenu
= bValue
; break;
646 case PROPERTY_NOCLOSE
:
647 aWindowStateInfo
.bNoClose
= bValue
; break;
648 case PROPERTY_SOFTCLOSE
:
649 aWindowStateInfo
.bSoftClose
= bValue
; break;
650 case PROPERTY_CONTEXTACTIVE
:
651 aWindowStateInfo
.bContextActive
= bValue
; break;
657 case PROPERTY_DOCKINGAREA
:
659 sal_Int32 nDockingArea
= 0;
660 if ( a
>>= nDockingArea
)
662 if (( nDockingArea
>= 0 ) &&
663 ( nDockingArea
<= sal_Int32( DockingArea_DOCKINGAREA_RIGHT
)))
665 aWindowStateInfo
.aDockingArea
= (DockingArea
)nDockingArea
;
666 nMask
|= WINDOWSTATE_MASK_DOCKINGAREA
;
667 a
= makeAny( aWindowStateInfo
.aDockingArea
);
675 case PROPERTY_DOCKPOS
:
680 sal_Int32
nToken( 0 );
681 OUString aXStr
= aString
.getToken( 0, ',', nToken
);
684 com::sun::star::awt::Point aPos
;
685 aPos
.X
= aXStr
.toInt32();
686 aPos
.Y
= aString
.getToken( 0, ',', nToken
).toInt32();
688 if ( i
== PROPERTY_POS
)
690 aWindowStateInfo
.aPos
= aPos
;
691 nMask
|= WINDOWSTATE_MASK_POS
;
695 aWindowStateInfo
.aDockPos
= aPos
;
696 nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
707 case PROPERTY_DOCKSIZE
:
712 sal_Int32
nToken( 0 );
713 OUString aStr
= aString
.getToken( 0, ',', nToken
);
716 com::sun::star::awt::Size aSize
;
717 aSize
.Width
= aStr
.toInt32();
718 aSize
.Height
= aString
.getToken( 0, ',', nToken
).toInt32();
719 if ( i
== PROPERTY_SIZE
)
721 aWindowStateInfo
.aSize
= aSize
;
722 nMask
|= WINDOWSTATE_MASK_SIZE
;
726 aWindowStateInfo
.aDockSize
= aSize
;
727 nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
737 case PROPERTY_UINAME
:
742 nMask
|= WINDOWSTATE_MASK_UINAME
;
743 aWindowStateInfo
.aUIName
= aValue
;
749 case PROPERTY_INTERNALSTATE
:
751 sal_uInt32 nValue
= 0;
754 nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
755 aWindowStateInfo
.nInternalState
= nValue
;
763 sal_Int32 nValue
= 0;
766 nMask
|= WINDOWSTATE_MASK_STYLE
;
767 aWindowStateInfo
.nStyle
= sal_uInt16( nValue
);
774 DBG_ASSERT( false, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
779 // put value into the return sequence
780 nIndex
= aPropSeq
.getLength();
781 aPropSeq
.realloc( nIndex
+1 );
782 aPropSeq
[nIndex
].Name
= m_aPropArray
[i
];
783 aPropSeq
[nIndex
].Value
= a
;
786 catch( const com::sun::star::container::NoSuchElementException
& )
789 catch ( const com::sun::star::lang::WrappedTargetException
& )
794 aWindowStateInfo
.nMask
= nMask
;
795 m_aResourceURLToInfoCache
.insert( ResourceURLToInfoCache::value_type( rResourceURL
, aWindowStateInfo
));
796 return makeAny( aPropSeq
);
799 ConfigurationAccess_WindowState::WindowStateInfo
& ConfigurationAccess_WindowState::impl_insertCacheAndReturnWinState( const OUString
& rResourceURL
, Reference
< XNameAccess
>& rNameAccess
)
801 sal_Int32
nMask( 0 );
802 sal_Int32
nCount( m_aPropArray
.size() );
804 WindowStateInfo aWindowStateInfo
;
806 for ( i
= 0; i
< nCount
; i
++ )
810 Any
a( rNameAccess
->getByName( m_aPropArray
[i
] ) );
813 case PROPERTY_LOCKED
:
814 case PROPERTY_DOCKED
:
815 case PROPERTY_VISIBLE
:
816 case PROPERTY_CONTEXT
:
817 case PROPERTY_HIDEFROMMENU
:
818 case PROPERTY_NOCLOSE
:
819 case PROPERTY_SOFTCLOSE
:
820 case PROPERTY_CONTEXTACTIVE
:
825 sal_Int32
nValue( 1 << i
);
829 case PROPERTY_LOCKED
:
830 aWindowStateInfo
.bLocked
= bValue
; break;
831 case PROPERTY_DOCKED
:
832 aWindowStateInfo
.bDocked
= bValue
; break;
833 case PROPERTY_VISIBLE
:
834 aWindowStateInfo
.bVisible
= bValue
; break;
835 case PROPERTY_CONTEXT
:
836 aWindowStateInfo
.bContext
= bValue
; break;
837 case PROPERTY_HIDEFROMMENU
:
838 aWindowStateInfo
.bHideFromMenu
= bValue
; break;
839 case PROPERTY_NOCLOSE
:
840 aWindowStateInfo
.bNoClose
= bValue
; break;
841 case PROPERTY_SOFTCLOSE
:
842 aWindowStateInfo
.bNoClose
= bValue
; break;
843 case PROPERTY_CONTEXTACTIVE
:
844 aWindowStateInfo
.bContextActive
= bValue
; break;
846 DBG_ASSERT( false, "Unknown boolean property in WindowState found!" );
852 case PROPERTY_DOCKINGAREA
:
854 sal_Int32 nDockingArea
= 0;
855 if ( a
>>= nDockingArea
)
857 if (( nDockingArea
>= 0 ) &&
858 ( nDockingArea
<= sal_Int32( DockingArea_DOCKINGAREA_RIGHT
)))
860 aWindowStateInfo
.aDockingArea
= (DockingArea
)nDockingArea
;
861 nMask
|= WINDOWSTATE_MASK_DOCKINGAREA
;
868 case PROPERTY_DOCKPOS
:
873 sal_Int32
nToken( 0 );
874 OUString aXStr
= aString
.getToken( 0, ',', nToken
);
877 com::sun::star::awt::Point aPos
;
878 aPos
.X
= aXStr
.toInt32();
879 aPos
.Y
= aString
.getToken( 0, ',', nToken
).toInt32();
881 if ( i
== PROPERTY_POS
)
883 aWindowStateInfo
.aPos
= aPos
;
884 nMask
|= WINDOWSTATE_MASK_POS
;
888 aWindowStateInfo
.aDockPos
= aPos
;
889 nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
897 case PROPERTY_DOCKSIZE
:
902 sal_Int32
nToken( 0 );
903 OUString aStr
= aString
.getToken( 0, ',', nToken
);
906 com::sun::star::awt::Size aSize
;
907 aSize
.Width
= aStr
.toInt32();
908 aSize
.Height
= aString
.getToken( 0, ',', nToken
).toInt32();
909 if ( i
== PROPERTY_SIZE
)
911 aWindowStateInfo
.aSize
= aSize
;
912 nMask
|= WINDOWSTATE_MASK_SIZE
;
916 aWindowStateInfo
.aDockSize
= aSize
;
917 nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
924 case PROPERTY_UINAME
:
929 nMask
|= WINDOWSTATE_MASK_UINAME
;
930 aWindowStateInfo
.aUIName
= aValue
;
935 case PROPERTY_INTERNALSTATE
:
937 sal_Int32 nValue
= 0;
940 nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
941 aWindowStateInfo
.nInternalState
= sal_uInt32( nValue
);
948 sal_Int32 nValue
= 0;
951 nMask
|= WINDOWSTATE_MASK_STYLE
;
952 aWindowStateInfo
.nStyle
= sal_uInt16( nValue
);
958 DBG_ASSERT( false, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
961 catch( const com::sun::star::container::NoSuchElementException
& )
964 catch ( const com::sun::star::lang::WrappedTargetException
& )
969 aWindowStateInfo
.nMask
= nMask
;
970 ResourceURLToInfoCache::iterator pIter
= (m_aResourceURLToInfoCache
.insert( ResourceURLToInfoCache::value_type( rResourceURL
, aWindowStateInfo
))).first
;
971 return pIter
->second
;
974 Any
ConfigurationAccess_WindowState::impl_getWindowStateFromResourceURL( const OUString
& rResourceURL
)
976 if ( !m_bConfigAccessInitialized
)
978 impl_initializeConfigAccess();
979 m_bConfigAccessInitialized
= true;
984 // Try to ask our configuration access
985 if ( m_xConfigAccess
.is() && m_xConfigAccess
->hasByName( rResourceURL
) )
988 Reference
< XNameAccess
> xNameAccess( m_xConfigAccess
->getByName( rResourceURL
), UNO_QUERY
);
989 if ( xNameAccess
.is() )
990 return impl_insertCacheAndReturnSequence( rResourceURL
, xNameAccess
);
993 catch( const com::sun::star::container::NoSuchElementException
& )
996 catch ( const com::sun::star::lang::WrappedTargetException
& )
1003 void ConfigurationAccess_WindowState::impl_fillStructFromSequence( WindowStateInfo
& rWinStateInfo
, const Sequence
< PropertyValue
>& rSeq
)
1005 sal_Int32
nCompareCount( m_aPropArray
.size() );
1006 sal_Int32
nCount( rSeq
.getLength() );
1009 for ( i
= 0; i
< nCount
; i
++ )
1011 for ( sal_Int32 j
= 0; j
< nCompareCount
; j
++ )
1013 if ( rSeq
[i
].Name
.equals( m_aPropArray
[j
] ))
1017 case PROPERTY_LOCKED
:
1018 case PROPERTY_DOCKED
:
1019 case PROPERTY_VISIBLE
:
1020 case PROPERTY_CONTEXT
:
1021 case PROPERTY_HIDEFROMMENU
:
1022 case PROPERTY_NOCLOSE
:
1023 case PROPERTY_SOFTCLOSE
:
1024 case PROPERTY_CONTEXTACTIVE
:
1027 if ( rSeq
[i
].Value
>>= bValue
)
1029 sal_Int32
nValue( 1 << j
);
1030 rWinStateInfo
.nMask
|= nValue
;
1033 case PROPERTY_LOCKED
:
1034 rWinStateInfo
.bLocked
= bValue
;
1036 case PROPERTY_DOCKED
:
1037 rWinStateInfo
.bDocked
= bValue
;
1039 case PROPERTY_VISIBLE
:
1040 rWinStateInfo
.bVisible
= bValue
;
1042 case PROPERTY_CONTEXT
:
1043 rWinStateInfo
.bContext
= bValue
;
1045 case PROPERTY_HIDEFROMMENU
:
1046 rWinStateInfo
.bHideFromMenu
= bValue
;
1048 case PROPERTY_NOCLOSE
:
1049 rWinStateInfo
.bNoClose
= bValue
;
1051 case PROPERTY_SOFTCLOSE
:
1052 rWinStateInfo
.bSoftClose
= bValue
;
1054 case PROPERTY_CONTEXTACTIVE
:
1055 rWinStateInfo
.bContextActive
= bValue
;
1062 case PROPERTY_DOCKINGAREA
:
1064 ::com::sun::star::ui::DockingArea eDockingArea
;
1065 if ( rSeq
[i
].Value
>>= eDockingArea
)
1067 rWinStateInfo
.aDockingArea
= eDockingArea
;
1068 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKINGAREA
;
1074 case PROPERTY_DOCKPOS
:
1076 com::sun::star::awt::Point aPoint
;
1077 if ( rSeq
[i
].Value
>>= aPoint
)
1079 if ( j
== PROPERTY_POS
)
1081 rWinStateInfo
.aPos
= aPoint
;
1082 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_POS
;
1086 rWinStateInfo
.aDockPos
= aPoint
;
1087 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKPOS
;
1094 case PROPERTY_DOCKSIZE
:
1096 com::sun::star::awt::Size aSize
;
1097 if ( rSeq
[i
].Value
>>= aSize
)
1099 if ( j
== PROPERTY_SIZE
)
1101 rWinStateInfo
.aSize
= aSize
;
1102 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_SIZE
;
1106 rWinStateInfo
.aDockSize
= aSize
;
1107 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_DOCKSIZE
;
1113 case PROPERTY_UINAME
:
1116 if ( rSeq
[i
].Value
>>= aValue
)
1118 rWinStateInfo
.aUIName
= aValue
;
1119 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_UINAME
;
1124 case PROPERTY_INTERNALSTATE
:
1126 sal_Int32 nValue
= 0;
1127 if ( rSeq
[i
].Value
>>= nValue
)
1129 rWinStateInfo
.nInternalState
= sal_uInt32( nValue
);
1130 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_INTERNALSTATE
;
1135 case PROPERTY_STYLE
:
1137 sal_Int32 nValue
= 0;
1138 if ( rSeq
[i
].Value
>>= nValue
)
1140 rWinStateInfo
.nStyle
= sal_uInt16( nValue
);
1141 rWinStateInfo
.nMask
|= WINDOWSTATE_MASK_STYLE
;
1147 DBG_ASSERT( false, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1156 void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const WindowStateInfo
& rWinStateInfo
, Reference
< XPropertySet
>& xPropSet
)
1159 sal_Int32
nCount( m_aPropArray
.size() );
1160 OUString
aDelim( "," );
1162 for ( i
= 0; i
< nCount
; i
++ )
1164 if ( rWinStateInfo
.nMask
& ( 1 << i
))
1168 // put values into the property set
1171 case PROPERTY_LOCKED
:
1172 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bLocked
) ); break;
1173 case PROPERTY_DOCKED
:
1174 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bDocked
) ); break;
1175 case PROPERTY_VISIBLE
:
1176 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bVisible
) ); break;
1177 case PROPERTY_CONTEXT
:
1178 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bContext
) ); break;
1179 case PROPERTY_HIDEFROMMENU
:
1180 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bHideFromMenu
) ); break;
1181 case PROPERTY_NOCLOSE
:
1182 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bNoClose
) ); break;
1183 case PROPERTY_SOFTCLOSE
:
1184 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bSoftClose
) ); break;
1185 case PROPERTY_CONTEXTACTIVE
:
1186 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.bContextActive
) ); break;
1187 case PROPERTY_DOCKINGAREA
:
1188 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Int16( rWinStateInfo
.aDockingArea
) ) ); break;
1190 case PROPERTY_DOCKPOS
:
1193 if ( i
== PROPERTY_POS
)
1194 aPosStr
= OUString::number( rWinStateInfo
.aPos
.X
);
1196 aPosStr
= OUString::number( rWinStateInfo
.aDockPos
.X
);
1198 if ( i
== PROPERTY_POS
)
1199 aPosStr
+= OUString::number( rWinStateInfo
.aPos
.Y
);
1201 aPosStr
+= OUString::number( rWinStateInfo
.aDockPos
.Y
);
1202 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( aPosStr
) );
1206 case PROPERTY_DOCKSIZE
:
1209 if ( i
== PROPERTY_SIZE
)
1210 aSizeStr
= ( OUString::number( rWinStateInfo
.aSize
.Width
));
1212 aSizeStr
= ( OUString::number( rWinStateInfo
.aDockSize
.Width
));
1214 if ( i
== PROPERTY_SIZE
)
1215 aSizeStr
+= OUString::number( rWinStateInfo
.aSize
.Height
);
1217 aSizeStr
+= OUString::number( rWinStateInfo
.aDockSize
.Height
);
1218 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( aSizeStr
) );
1221 case PROPERTY_UINAME
:
1222 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( rWinStateInfo
.aUIName
) ); break;
1223 case PROPERTY_INTERNALSTATE
:
1224 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Int32( rWinStateInfo
.nInternalState
)) ); break;
1225 case PROPERTY_STYLE
:
1226 xPropSet
->setPropertyValue( m_aPropArray
[i
], makeAny( sal_Int32( rWinStateInfo
.nStyle
)) ); break;
1228 DBG_ASSERT( false, "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" );
1231 catch( const Exception
& )
1238 bool ConfigurationAccess_WindowState::impl_initializeConfigAccess()
1240 Sequence
< Any
> aArgs( 2 );
1241 PropertyValue aPropValue
;
1245 aPropValue
.Name
= "nodepath";
1246 aPropValue
.Value
<<= m_aConfigWindowAccess
;
1247 aArgs
[0] <<= aPropValue
;
1248 aPropValue
.Name
= "lazywrite";
1249 aPropValue
.Value
<<= sal_True
;
1250 aArgs
[1] <<= aPropValue
;
1252 m_xConfigAccess
= Reference
< XNameAccess
>( m_xConfigProvider
->createInstanceWithArguments(
1253 "com.sun.star.configuration.ConfigurationUpdateAccess", aArgs
), UNO_QUERY
);
1254 if ( m_xConfigAccess
.is() )
1256 // Add as container listener
1257 Reference
< XContainer
> xContainer( m_xConfigAccess
, UNO_QUERY
);
1258 if ( xContainer
.is() )
1260 m_xConfigListener
= new WeakContainerListener(this);
1261 xContainer
->addContainerListener(m_xConfigListener
);
1267 catch ( const WrappedTargetException
& )
1270 catch ( const Exception
& )
1277 typedef ::cppu::WeakComponentImplHelper2
< css::container::XNameAccess
,
1278 css::lang::XServiceInfo
> WindowStateConfiguration_BASE
;
1280 class WindowStateConfiguration
: private cppu::BaseMutex
,
1281 public WindowStateConfiguration_BASE
1284 WindowStateConfiguration( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
1285 virtual ~WindowStateConfiguration();
1287 virtual OUString SAL_CALL
getImplementationName()
1288 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1290 return OUString("com.sun.star.comp.framework.WindowStateConfiguration");
1293 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
)
1294 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1296 return cppu::supportsService(this, ServiceName
);
1299 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames()
1300 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
1302 css::uno::Sequence
< OUString
> aSeq(1);
1303 aSeq
[0] = "com.sun.star.ui.WindowStateConfiguration";
1308 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
)
1309 throw ( css::container::NoSuchElementException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
1311 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames()
1312 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
1314 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
)
1315 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
1318 virtual css::uno::Type SAL_CALL
getElementType()
1319 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
1320 virtual sal_Bool SAL_CALL
hasElements()
1321 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
1323 typedef std::unordered_map
< OUString
,
1326 std::equal_to
< OUString
> > ModuleToWindowStateFileMap
;
1328 typedef std::unordered_map
< OUString
,
1329 css::uno::Reference
< css::container::XNameAccess
>,
1331 std::equal_to
< OUString
> > ModuleToWindowStateConfigHashMap
;
1334 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
1335 ModuleToWindowStateFileMap m_aModuleToFileHashMap
;
1336 ModuleToWindowStateConfigHashMap m_aModuleToWindowStateHashMap
;
1339 WindowStateConfiguration::WindowStateConfiguration( const Reference
< XComponentContext
>& rxContext
) :
1340 WindowStateConfiguration_BASE(m_aMutex
),
1341 m_xContext( rxContext
)
1343 css::uno::Reference
< css::frame::XModuleManager2
> xModuleManager
=
1344 ModuleManager::create( m_xContext
);
1345 Reference
< XNameAccess
> xEmptyNameAccess
;
1346 Sequence
< OUString
> aElementNames
;
1349 aElementNames
= xModuleManager
->getElementNames();
1351 catch (const ::com::sun::star::uno::RuntimeException
&)
1354 Sequence
< PropertyValue
> aSeq
;
1355 OUString aModuleIdentifier
;
1357 for ( sal_Int32 i
= 0; i
< aElementNames
.getLength(); i
++ )
1359 aModuleIdentifier
= aElementNames
[i
];
1360 if ( xModuleManager
->getByName( aModuleIdentifier
) >>= aSeq
)
1362 OUString aWindowStateFileStr
;
1363 for ( sal_Int32 y
= 0; y
< aSeq
.getLength(); y
++ )
1365 if ( aSeq
[y
].Name
== "ooSetupFactoryWindowStateConfigRef" )
1367 aSeq
[y
].Value
>>= aWindowStateFileStr
;
1372 if ( !aWindowStateFileStr
.isEmpty() )
1374 // Create first mapping ModuleIdentifier ==> Window state configuration file
1375 m_aModuleToFileHashMap
.insert( ModuleToWindowStateFileMap::value_type( aModuleIdentifier
, aWindowStateFileStr
));
1377 // Create second mapping Command File ==> Window state configuration instance
1378 ModuleToWindowStateConfigHashMap::iterator pIter
= m_aModuleToWindowStateHashMap
.find( aWindowStateFileStr
);
1379 if ( pIter
== m_aModuleToWindowStateHashMap
.end() )
1380 m_aModuleToWindowStateHashMap
.insert( ModuleToWindowStateConfigHashMap::value_type( aWindowStateFileStr
, xEmptyNameAccess
));
1386 WindowStateConfiguration::~WindowStateConfiguration()
1388 osl::MutexGuard
g(cppu::WeakComponentImplHelperBase::rBHelper
.rMutex
);
1389 m_aModuleToFileHashMap
.clear();
1390 m_aModuleToWindowStateHashMap
.clear();
1393 Any SAL_CALL
WindowStateConfiguration::getByName( const OUString
& aModuleIdentifier
)
1394 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
1396 osl::MutexGuard
g(cppu::WeakComponentImplHelperBase::rBHelper
.rMutex
);
1398 ModuleToWindowStateFileMap::const_iterator pIter
= m_aModuleToFileHashMap
.find( aModuleIdentifier
);
1399 if ( pIter
!= m_aModuleToFileHashMap
.end() )
1402 OUString
aWindowStateConfigFile( pIter
->second
);
1404 ModuleToWindowStateConfigHashMap::iterator pModuleIter
= m_aModuleToWindowStateHashMap
.find( aWindowStateConfigFile
);
1405 if ( pModuleIter
!= m_aModuleToWindowStateHashMap
.end() )
1407 if ( pModuleIter
->second
.is() )
1408 a
= makeAny( pModuleIter
->second
);
1411 Reference
< XNameAccess
> xResourceURLWindowState
;
1412 ConfigurationAccess_WindowState
* pModuleWindowState
= new ConfigurationAccess_WindowState( aWindowStateConfigFile
, m_xContext
);
1413 xResourceURLWindowState
= Reference
< XNameAccess
>( static_cast< cppu::OWeakObject
* >( pModuleWindowState
),UNO_QUERY
);
1414 pModuleIter
->second
= xResourceURLWindowState
;
1415 a
<<= xResourceURLWindowState
;
1422 throw NoSuchElementException();
1425 Sequence
< OUString
> SAL_CALL
WindowStateConfiguration::getElementNames()
1426 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1428 osl::MutexGuard
g(cppu::WeakComponentImplHelperBase::rBHelper
.rMutex
);
1430 Sequence
< OUString
> aSeq( m_aModuleToFileHashMap
.size() );
1433 ModuleToWindowStateFileMap::const_iterator pIter
= m_aModuleToFileHashMap
.begin();
1434 while ( pIter
!= m_aModuleToFileHashMap
.end() )
1436 aSeq
[n
] = pIter
->first
;
1443 sal_Bool SAL_CALL
WindowStateConfiguration::hasByName( const OUString
& aName
)
1444 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1446 osl::MutexGuard
g(cppu::WeakComponentImplHelperBase::rBHelper
.rMutex
);
1448 ModuleToWindowStateFileMap::const_iterator pIter
= m_aModuleToFileHashMap
.find( aName
);
1449 return ( pIter
!= m_aModuleToFileHashMap
.end() );
1453 Type SAL_CALL
WindowStateConfiguration::getElementType()
1454 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1456 return( cppu::UnoType
<XNameAccess
>::get());
1459 sal_Bool SAL_CALL
WindowStateConfiguration::hasElements()
1460 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
1462 // We always have at least one module. So it is valid to return true!
1468 css::uno::Reference
<css::uno::XComponentContext
> const & context
):
1469 instance(static_cast<cppu::OWeakObject
*>(
1470 new WindowStateConfiguration(context
)))
1474 css::uno::Reference
<css::uno::XInterface
> instance
;
1478 public rtl::StaticWithArg
<
1479 Instance
, css::uno::Reference
<css::uno::XComponentContext
>, Singleton
>
1484 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
1485 com_sun_star_comp_framework_WindowStateConfiguration_get_implementation(
1486 css::uno::XComponentContext
*context
,
1487 css::uno::Sequence
<css::uno::Any
> const &)
1489 return cppu::acquire(static_cast<cppu::OWeakObject
*>(
1490 Singleton::get(context
).instance
.get()));
1493 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */