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 <helper/uiconfigelementwrapperbase.hxx>
22 #include <properties.h>
23 #include <uielement/constitemcontainer.hxx>
24 #include <uielement/rootitemcontainer.hxx>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/ui/XUIConfiguration.hpp>
31 #include <vcl/svapp.hxx>
32 #include <comphelper/sequence.hxx>
34 const int UIELEMENT_PROPHANDLE_CONFIGSOURCE
= 1;
35 const int UIELEMENT_PROPHANDLE_FRAME
= 2;
36 const int UIELEMENT_PROPHANDLE_PERSISTENT
= 3;
37 const int UIELEMENT_PROPHANDLE_RESOURCEURL
= 4;
38 const int UIELEMENT_PROPHANDLE_TYPE
= 5;
39 const int UIELEMENT_PROPHANDLE_XMENUBAR
= 6;
40 const int UIELEMENT_PROPHANDLE_CONFIGLISTENER
= 7;
41 const int UIELEMENT_PROPHANDLE_NOCLOSE
= 8;
42 const char UIELEMENT_PROPNAME_CONFIGLISTENER
[] = "ConfigListener";
43 const char UIELEMENT_PROPNAME_CONFIGSOURCE
[] = "ConfigurationSource";
44 const char UIELEMENT_PROPNAME_FRAME
[] = "Frame";
45 const char UIELEMENT_PROPNAME_PERSISTENT
[] = "Persistent";
46 const char UIELEMENT_PROPNAME_RESOURCEURL
[] = "ResourceURL";
47 const char UIELEMENT_PROPNAME_TYPE
[] = "Type";
48 const char UIELEMENT_PROPNAME_XMENUBAR
[] = "XMenuBar";
49 const char UIELEMENT_PROPNAME_NOCLOSE
[] = "NoClose";
50 using namespace com::sun::star::beans
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::frame
;
53 using namespace com::sun::star::lang
;
54 using namespace com::sun::star::container
;
55 using namespace ::com::sun::star::ui
;
60 UIConfigElementWrapperBase::UIConfigElementWrapperBase( sal_Int16 nType
)
61 : ::cppu::OBroadcastHelperVar
< ::cppu::OMultiTypeInterfaceContainerHelper
, ::cppu::OMultiTypeInterfaceContainerHelper::keyType
>( m_aMutex
)
62 , ::cppu::OPropertySetHelper ( *static_cast< ::cppu::OBroadcastHelper
* >(this) )
64 , m_bPersistent ( true )
65 , m_bInitialized ( false )
66 , m_bConfigListener ( false )
67 , m_bConfigListening ( false )
68 , m_bDisposed ( false )
69 , m_bNoClose ( false )
70 , m_aListenerContainer ( m_aMutex
)
74 UIConfigElementWrapperBase::~UIConfigElementWrapperBase()
78 Any SAL_CALL
UIConfigElementWrapperBase::queryInterface( const Type
& _rType
)
80 Any aRet
= UIConfigElementWrapperBase_BASE::queryInterface( _rType
);
81 if ( !aRet
.hasValue() )
82 aRet
= OPropertySetHelper::queryInterface( _rType
);
86 Sequence
< Type
> SAL_CALL
UIConfigElementWrapperBase::getTypes( )
88 return comphelper::concatSequences(
89 UIConfigElementWrapperBase_BASE::getTypes(),
90 ::cppu::OPropertySetHelper::getTypes()
95 void SAL_CALL
UIConfigElementWrapperBase::addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
)
97 m_aListenerContainer
.addInterface( cppu::UnoType
<css::lang::XEventListener
>::get(), xListener
);
100 void SAL_CALL
UIConfigElementWrapperBase::removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
)
102 m_aListenerContainer
.removeInterface( cppu::UnoType
<css::lang::XEventListener
>::get(), aListener
);
106 void SAL_CALL
UIConfigElementWrapperBase::disposing( const EventObject
& )
109 m_xConfigSource
.clear();
112 void SAL_CALL
UIConfigElementWrapperBase::initialize( const Sequence
< Any
>& aArguments
)
116 if ( !m_bInitialized
)
118 for ( sal_Int32 n
= 0; n
< aArguments
.getLength(); n
++ )
120 PropertyValue aPropValue
;
121 if ( aArguments
[n
] >>= aPropValue
)
123 if ( aPropValue
.Name
== UIELEMENT_PROPNAME_CONFIGSOURCE
)
124 setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_CONFIGSOURCE
, aPropValue
.Value
);
125 else if ( aPropValue
.Name
== UIELEMENT_PROPNAME_FRAME
)
126 setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_FRAME
, aPropValue
.Value
);
127 else if ( aPropValue
.Name
== UIELEMENT_PROPNAME_PERSISTENT
)
128 setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_PERSISTENT
, aPropValue
.Value
);
129 else if ( aPropValue
.Name
== UIELEMENT_PROPNAME_RESOURCEURL
)
130 setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_RESOURCEURL
, aPropValue
.Value
);
131 else if ( aPropValue
.Name
== UIELEMENT_PROPNAME_TYPE
)
132 setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_TYPE
, aPropValue
.Value
);
133 else if ( aPropValue
.Name
== UIELEMENT_PROPNAME_CONFIGLISTENER
)
134 setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_CONFIGLISTENER
, aPropValue
.Value
);
135 else if ( aPropValue
.Name
== UIELEMENT_PROPNAME_NOCLOSE
)
136 setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_NOCLOSE
, aPropValue
.Value
);
140 m_bInitialized
= true;
145 void SAL_CALL
UIConfigElementWrapperBase::update()
147 // can be implemented by derived class
150 void SAL_CALL
UIConfigElementWrapperBase::elementInserted( const css::ui::ConfigurationEvent
& )
152 // can be implemented by derived class
155 void SAL_CALL
UIConfigElementWrapperBase::elementRemoved( const css::ui::ConfigurationEvent
& )
157 // can be implemented by derived class
160 void SAL_CALL
UIConfigElementWrapperBase::elementReplaced( const css::ui::ConfigurationEvent
& )
162 // can be implemented by derived class
165 // XPropertySet helper
166 sal_Bool SAL_CALL
UIConfigElementWrapperBase::convertFastPropertyValue( Any
& aConvertedValue
,
171 // Initialize state with sal_False !!!
172 // (Handle can be invalid)
173 bool bReturn
= false;
177 case UIELEMENT_PROPHANDLE_CONFIGLISTENER
:
178 bReturn
= PropHelper::willPropertyBeChanged(
179 css::uno::makeAny(m_bConfigListener
),
185 case UIELEMENT_PROPHANDLE_CONFIGSOURCE
:
186 bReturn
= PropHelper::willPropertyBeChanged(
187 css::uno::makeAny(m_xConfigSource
),
193 case UIELEMENT_PROPHANDLE_FRAME
:
195 Reference
< XFrame
> xFrame( m_xWeakFrame
);
196 bReturn
= PropHelper::willPropertyBeChanged(
197 css::uno::makeAny(xFrame
),
204 case UIELEMENT_PROPHANDLE_PERSISTENT
:
205 bReturn
= PropHelper::willPropertyBeChanged(
206 css::uno::makeAny(m_bPersistent
),
212 case UIELEMENT_PROPHANDLE_RESOURCEURL
:
213 bReturn
= PropHelper::willPropertyBeChanged(
214 css::uno::makeAny(m_aResourceURL
),
220 case UIELEMENT_PROPHANDLE_TYPE
:
221 bReturn
= PropHelper::willPropertyBeChanged(
222 css::uno::makeAny(m_nType
),
228 case UIELEMENT_PROPHANDLE_XMENUBAR
:
229 bReturn
= PropHelper::willPropertyBeChanged(
230 css::uno::makeAny(m_xMenuBar
),
236 case UIELEMENT_PROPHANDLE_NOCLOSE
:
237 bReturn
= PropHelper::willPropertyBeChanged(
238 css::uno::makeAny(m_bNoClose
),
245 // Return state of operation.
249 void SAL_CALL
UIConfigElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
,
250 const css::uno::Any
& aValue
)
254 case UIELEMENT_PROPHANDLE_CONFIGLISTENER
:
256 bool bBool( m_bConfigListener
);
258 if ( m_bConfigListener
!= bBool
)
260 if ( m_bConfigListening
)
262 if ( m_xConfigSource
.is() && !bBool
)
266 Reference
< XUIConfiguration
> xUIConfig( m_xConfigSource
, UNO_QUERY
);
267 if ( xUIConfig
.is() )
269 xUIConfig
->removeConfigurationListener( Reference
< XUIConfigurationListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
));
270 m_bConfigListening
= false;
273 catch ( const Exception
& )
280 if ( m_xConfigSource
.is() && bBool
)
284 Reference
< XUIConfiguration
> xUIConfig( m_xConfigSource
, UNO_QUERY
);
285 if ( xUIConfig
.is() )
287 xUIConfig
->addConfigurationListener( Reference
< XUIConfigurationListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
));
288 m_bConfigListening
= true;
291 catch ( const Exception
& )
297 m_bConfigListener
= bBool
;
301 case UIELEMENT_PROPHANDLE_CONFIGSOURCE
:
302 aValue
>>= m_xConfigSource
;
304 case UIELEMENT_PROPHANDLE_FRAME
:
306 Reference
< XFrame
> xFrame
;
309 m_xWeakFrame
= xFrame
;
312 case UIELEMENT_PROPHANDLE_PERSISTENT
:
314 bool bBool( m_bPersistent
);
316 m_bPersistent
= bBool
;
319 case UIELEMENT_PROPHANDLE_RESOURCEURL
:
320 aValue
>>= m_aResourceURL
;
322 case UIELEMENT_PROPHANDLE_TYPE
:
325 case UIELEMENT_PROPHANDLE_XMENUBAR
:
326 aValue
>>= m_xMenuBar
;
328 case UIELEMENT_PROPHANDLE_NOCLOSE
:
330 bool bBool( m_bNoClose
);
338 void SAL_CALL
UIConfigElementWrapperBase::getFastPropertyValue( css::uno::Any
& aValue
,
339 sal_Int32 nHandle
) const
343 case UIELEMENT_PROPHANDLE_CONFIGLISTENER
:
344 aValue
<<= m_bConfigListener
;
346 case UIELEMENT_PROPHANDLE_CONFIGSOURCE
:
347 aValue
<<= m_xConfigSource
;
349 case UIELEMENT_PROPHANDLE_FRAME
:
351 Reference
< XFrame
> xFrame( m_xWeakFrame
);
355 case UIELEMENT_PROPHANDLE_PERSISTENT
:
356 aValue
<<= m_bPersistent
;
358 case UIELEMENT_PROPHANDLE_RESOURCEURL
:
359 aValue
<<= m_aResourceURL
;
361 case UIELEMENT_PROPHANDLE_TYPE
:
364 case UIELEMENT_PROPHANDLE_XMENUBAR
:
365 aValue
<<= m_xMenuBar
;
367 case UIELEMENT_PROPHANDLE_NOCLOSE
:
368 aValue
<<= m_bNoClose
;
373 ::cppu::IPropertyArrayHelper
& SAL_CALL
UIConfigElementWrapperBase::getInfoHelper()
375 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
376 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
377 // "true" say: Table is sorted by name.
378 static ::cppu::OPropertyArrayHelper
ourInfoHelper( impl_getStaticPropertyDescriptor(), true );
380 return ourInfoHelper
;
383 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
UIConfigElementWrapperBase::getPropertySetInfo()
385 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
386 // (Use method "getInfoHelper()".)
387 static css::uno::Reference
< css::beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
392 css::uno::Sequence
< css::beans::Property
> UIConfigElementWrapperBase::impl_getStaticPropertyDescriptor()
394 // Create property array to initialize sequence!
395 // Table of all predefined properties of this class. It's used from OPropertySetHelper-class!
396 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
397 // It's necessary for methods of OPropertySetHelper.
399 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
403 css::beans::Property( UIELEMENT_PROPNAME_CONFIGLISTENER
, UIELEMENT_PROPHANDLE_CONFIGLISTENER
, cppu::UnoType
<sal_Bool
>::get(), css::beans::PropertyAttribute::TRANSIENT
),
404 css::beans::Property( UIELEMENT_PROPNAME_CONFIGSOURCE
, UIELEMENT_PROPHANDLE_CONFIGSOURCE
, cppu::UnoType
<css::ui::XUIConfigurationManager
>::get(), css::beans::PropertyAttribute::TRANSIENT
),
405 css::beans::Property( UIELEMENT_PROPNAME_FRAME
, UIELEMENT_PROPHANDLE_FRAME
, cppu::UnoType
<css::frame::XFrame
>::get(), css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
),
406 css::beans::Property( UIELEMENT_PROPNAME_NOCLOSE
, UIELEMENT_PROPHANDLE_NOCLOSE
, cppu::UnoType
<sal_Bool
>::get(), css::beans::PropertyAttribute::TRANSIENT
),
407 css::beans::Property( UIELEMENT_PROPNAME_PERSISTENT
, UIELEMENT_PROPHANDLE_PERSISTENT
, cppu::UnoType
<sal_Bool
>::get(), css::beans::PropertyAttribute::TRANSIENT
),
408 css::beans::Property( UIELEMENT_PROPNAME_RESOURCEURL
, UIELEMENT_PROPHANDLE_RESOURCEURL
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
),
409 css::beans::Property( UIELEMENT_PROPNAME_TYPE
, UIELEMENT_PROPHANDLE_TYPE
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
),
410 css::beans::Property( UIELEMENT_PROPNAME_XMENUBAR
, UIELEMENT_PROPHANDLE_XMENUBAR
, cppu::UnoType
<css::awt::XMenuBar
>::get(), css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
)
414 void SAL_CALL
UIConfigElementWrapperBase::setSettings( const Reference
< XIndexAccess
>& xSettings
)
416 SolarMutexClearableGuard aLock
;
418 if ( xSettings
.is() )
420 // Create a copy of the data if the container is not const
421 Reference
< XIndexReplace
> xReplace( xSettings
, UNO_QUERY
);
423 m_xConfigData
.set( static_cast< OWeakObject
* >( new ConstItemContainer( xSettings
) ), UNO_QUERY
);
425 m_xConfigData
= xSettings
;
427 if ( m_xConfigSource
.is() && m_bPersistent
)
429 OUString
aResourceURL( m_aResourceURL
);
430 Reference
< XUIConfigurationManager
> xUICfgMgr( m_xConfigSource
);
436 xUICfgMgr
->replaceSettings( aResourceURL
, m_xConfigData
);
438 catch( const NoSuchElementException
& )
442 else if ( !m_bPersistent
)
444 // Transient menubar => Fill menubar with new data
449 void UIConfigElementWrapperBase::impl_fillNewData()
452 Reference
< XIndexAccess
> SAL_CALL
UIConfigElementWrapperBase::getSettings( sal_Bool bWriteable
)
457 return Reference
< XIndexAccess
>( static_cast< OWeakObject
* >( new RootItemContainer( m_xConfigData
) ), UNO_QUERY
);
459 return m_xConfigData
;
462 Reference
< XFrame
> SAL_CALL
UIConfigElementWrapperBase::getFrame()
465 Reference
< XFrame
> xFrame( m_xWeakFrame
);
469 OUString SAL_CALL
UIConfigElementWrapperBase::getResourceURL()
472 return m_aResourceURL
;
475 ::sal_Int16 SAL_CALL
UIConfigElementWrapperBase::getType()
483 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */