LibreOffice Module framework (master) 1
uiconfigelementwrapperbase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <properties.h>
24
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/beans/PropertyValue.hpp>
27#include <com/sun/star/ui/XUIConfiguration.hpp>
28
29#include <vcl/svapp.hxx>
31
40constexpr OUStringLiteral UIELEMENT_PROPNAME_CONFIGLISTENER = u"ConfigListener";
41constexpr OUStringLiteral UIELEMENT_PROPNAME_CONFIGSOURCE = u"ConfigurationSource";
42constexpr OUStringLiteral UIELEMENT_PROPNAME_FRAME = u"Frame";
43constexpr OUStringLiteral UIELEMENT_PROPNAME_PERSISTENT = u"Persistent";
44constexpr OUStringLiteral UIELEMENT_PROPNAME_RESOURCEURL = u"ResourceURL";
45constexpr OUStringLiteral UIELEMENT_PROPNAME_TYPE = u"Type";
46constexpr OUStringLiteral UIELEMENT_PROPNAME_XMENUBAR = u"XMenuBar";
47constexpr OUStringLiteral UIELEMENT_PROPNAME_NOCLOSE = u"NoClose";
48using namespace com::sun::star::beans;
49using namespace com::sun::star::uno;
50using namespace com::sun::star::frame;
51using namespace com::sun::star::lang;
52using namespace com::sun::star::container;
53using namespace ::com::sun::star::ui;
54
55namespace framework
56{
57
59 : ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aMutex )
60 , ::cppu::OPropertySetHelper ( *static_cast< ::cppu::OBroadcastHelper* >(this) )
61 , m_nType ( nType )
62 , m_bPersistent ( true )
63 , m_bInitialized ( false )
64 , m_bConfigListener ( false )
65 , m_bConfigListening ( false )
66 , m_bDisposed ( false )
67 , m_bNoClose ( false )
68 , m_aListenerContainer ( m_aMutex )
69{
70}
71
73{
74}
75
77{
78 Any aRet = UIConfigElementWrapperBase_BASE::queryInterface( _rType );
79 if ( !aRet.hasValue() )
80 aRet = OPropertySetHelper::queryInterface( _rType );
81 return aRet;
82}
83
85{
87 UIConfigElementWrapperBase_BASE::getTypes(),
89 );
90}
91
92// XComponent
93void SAL_CALL UIConfigElementWrapperBase::addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
94{
96}
97
98void SAL_CALL UIConfigElementWrapperBase::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
99{
101}
102
103// XEventListener
104void SAL_CALL UIConfigElementWrapperBase::disposing( const EventObject& )
105{
107 m_xConfigSource.clear();
108}
109
111{
113
114 if ( m_bInitialized )
115 return;
116
117 for ( const Any& rArg : aArguments )
118 {
119 PropertyValue aPropValue;
120 if ( rArg >>= aPropValue )
121 {
122 if ( aPropValue.Name == UIELEMENT_PROPNAME_CONFIGSOURCE )
124 else if ( aPropValue.Name == UIELEMENT_PROPNAME_FRAME )
126 else if ( aPropValue.Name == UIELEMENT_PROPNAME_PERSISTENT )
128 else if ( aPropValue.Name == UIELEMENT_PROPNAME_RESOURCEURL )
130 else if ( aPropValue.Name == UIELEMENT_PROPNAME_TYPE )
132 else if ( aPropValue.Name == UIELEMENT_PROPNAME_CONFIGLISTENER )
134 else if ( aPropValue.Name == UIELEMENT_PROPNAME_NOCLOSE )
136 }
137 }
138
139 m_bInitialized = true;
140}
141
142// XUpdatable
144{
145 // can be implemented by derived class
146}
147
148void SAL_CALL UIConfigElementWrapperBase::elementInserted( const css::ui::ConfigurationEvent& )
149{
150 // can be implemented by derived class
151}
152
153void SAL_CALL UIConfigElementWrapperBase::elementRemoved( const css::ui::ConfigurationEvent& )
154{
155 // can be implemented by derived class
156}
157
158void SAL_CALL UIConfigElementWrapperBase::elementReplaced( const css::ui::ConfigurationEvent& )
159{
160 // can be implemented by derived class
161}
162
163// XPropertySet helper
165 Any& aOldValue ,
166 sal_Int32 nHandle ,
167 const Any& aValue )
168{
169 // Initialize state with sal_False !!!
170 // (Handle can be invalid)
171 bool bReturn = false;
172
173 switch( nHandle )
174 {
177 css::uno::Any(m_bConfigListener),
178 aValue,
179 aOldValue,
180 aConvertedValue);
181 break;
182
185 css::uno::Any(m_xConfigSource),
186 aValue,
187 aOldValue,
188 aConvertedValue);
189 break;
190
192 {
195 css::uno::Any(xFrame),
196 aValue,
197 aOldValue,
198 aConvertedValue);
199 }
200 break;
201
204 css::uno::Any(m_bPersistent),
205 aValue,
206 aOldValue,
207 aConvertedValue);
208 break;
209
212 css::uno::Any(m_aResourceURL),
213 aValue,
214 aOldValue,
215 aConvertedValue);
216 break;
217
220 css::uno::Any(m_nType),
221 aValue,
222 aOldValue,
223 aConvertedValue);
224 break;
225
228 css::uno::Any(m_xMenuBar),
229 aValue,
230 aOldValue,
231 aConvertedValue);
232 break;
233
236 css::uno::Any(m_bNoClose),
237 aValue,
238 aOldValue,
239 aConvertedValue);
240 break;
241 }
242
243 // Return state of operation.
244 return bReturn;
245}
246
248 const css::uno::Any& aValue )
249{
250 switch( nHandle )
251 {
253 {
254 bool bBool( m_bConfigListener );
255 aValue >>= bBool;
256 if ( m_bConfigListener != bBool )
257 {
258 if ( m_bConfigListening )
259 {
260 if ( m_xConfigSource.is() && !bBool )
261 {
262 try
263 {
264 Reference< XUIConfiguration > xUIConfig( m_xConfigSource, UNO_QUERY );
265 if ( xUIConfig.is() )
266 {
267 xUIConfig->removeConfigurationListener( Reference< XUIConfigurationListener >(this) );
268 m_bConfigListening = false;
269 }
270 }
271 catch ( const Exception& )
272 {
273 }
274 }
275 }
276 else
277 {
278 if ( m_xConfigSource.is() && bBool )
279 {
280 try
281 {
282 Reference< XUIConfiguration > xUIConfig( m_xConfigSource, UNO_QUERY );
283 if ( xUIConfig.is() )
284 {
285 xUIConfig->addConfigurationListener( Reference< XUIConfigurationListener >(this) );
286 m_bConfigListening = true;
287 }
288 }
289 catch ( const Exception& )
290 {
291 }
292 }
293 }
294
295 m_bConfigListener = bBool;
296 }
297 }
298 break;
300 aValue >>= m_xConfigSource;
301 break;
303 {
305
306 aValue >>= xFrame;
308 break;
309 }
311 {
312 bool bBool( m_bPersistent );
313 aValue >>= bBool;
314 m_bPersistent = bBool;
315 break;
316 }
318 aValue >>= m_aResourceURL;
319 break;
321 aValue >>= m_nType;
322 break;
324 aValue >>= m_xMenuBar;
325 break;
327 {
328 bool bBool( m_bNoClose );
329 aValue >>= bBool;
330 m_bNoClose = bBool;
331 break;
332 }
333 }
334}
335
336void SAL_CALL UIConfigElementWrapperBase::getFastPropertyValue( css::uno::Any& aValue ,
337 sal_Int32 nHandle ) const
338{
339 switch( nHandle )
340 {
342 aValue <<= m_bConfigListener;
343 break;
345 aValue <<= m_xConfigSource;
346 break;
348 {
350 aValue <<= xFrame;
351 break;
352 }
354 aValue <<= m_bPersistent;
355 break;
357 aValue <<= m_aResourceURL;
358 break;
360 aValue <<= m_nType;
361 break;
363 aValue <<= m_xMenuBar;
364 break;
366 aValue <<= m_bNoClose;
367 break;
368 }
369}
370
372{
373 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
374 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
375 // "true" say: Table is sorted by name.
376 static ::cppu::OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true );
377
378 return ourInfoHelper;
379}
380
381css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL UIConfigElementWrapperBase::getPropertySetInfo()
382{
383 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
384 // (Use method "getInfoHelper()".)
385 static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
386
387 return xInfo;
388}
389
390css::uno::Sequence< css::beans::Property > UIConfigElementWrapperBase::impl_getStaticPropertyDescriptor()
391{
392 // Create property array to initialize sequence!
393 // Table of all predefined properties of this class. It's used from OPropertySetHelper-class!
394 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
395 // It's necessary for methods of OPropertySetHelper.
396 // ATTENTION:
397 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
398
399 return
400 {
401 css::beans::Property( UIELEMENT_PROPNAME_CONFIGLISTENER, UIELEMENT_PROPHANDLE_CONFIGLISTENER , cppu::UnoType<sal_Bool>::get(), css::beans::PropertyAttribute::TRANSIENT ),
402 css::beans::Property( UIELEMENT_PROPNAME_CONFIGSOURCE, UIELEMENT_PROPHANDLE_CONFIGSOURCE , cppu::UnoType<css::ui::XUIConfigurationManager>::get(), css::beans::PropertyAttribute::TRANSIENT ),
403 css::beans::Property( UIELEMENT_PROPNAME_FRAME, UIELEMENT_PROPHANDLE_FRAME , cppu::UnoType<css::frame::XFrame>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ),
404 css::beans::Property( UIELEMENT_PROPNAME_NOCLOSE, UIELEMENT_PROPHANDLE_NOCLOSE , cppu::UnoType<sal_Bool>::get(), css::beans::PropertyAttribute::TRANSIENT ),
405 css::beans::Property( UIELEMENT_PROPNAME_PERSISTENT, UIELEMENT_PROPHANDLE_PERSISTENT , cppu::UnoType<sal_Bool>::get(), css::beans::PropertyAttribute::TRANSIENT ),
406 css::beans::Property( UIELEMENT_PROPNAME_RESOURCEURL, UIELEMENT_PROPHANDLE_RESOURCEURL , cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ),
407 css::beans::Property( UIELEMENT_PROPNAME_TYPE, UIELEMENT_PROPHANDLE_TYPE , cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY ),
408 css::beans::Property( UIELEMENT_PROPNAME_XMENUBAR, UIELEMENT_PROPHANDLE_XMENUBAR , cppu::UnoType<css::awt::XMenuBar>::get(), css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY )
409 };
410}
411
413{
415
416 if ( !xSettings.is() )
417 return;
418
419 // Create a copy of the data if the container is not const
420 Reference< XIndexReplace > xReplace( xSettings, UNO_QUERY );
421 if ( xReplace.is() )
422 m_xConfigData = new ConstItemContainer( xSettings );
423 else
424 m_xConfigData = xSettings;
425
426 if ( m_xConfigSource.is() && m_bPersistent )
427 {
428 OUString aResourceURL( m_aResourceURL );
430
431 aLock.clear();
432
433 try
434 {
435 xUICfgMgr->replaceSettings( aResourceURL, m_xConfigData );
436 }
437 catch( const NoSuchElementException& )
438 {
439 }
440 }
441 else if ( !m_bPersistent )
442 {
443 // Transient menubar => Fill menubar with new data
445 }
446}
448{
449}
451{
453
454 if ( bWriteable )
456
457 return m_xConfigData;
458}
459
461{
464 return xFrame;
465}
466
468{
470 return m_aResourceURL;
471}
472
474{
476 return m_nType;
477}
478
479}
480
481/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 removeInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &r)
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
void SAL_CALL disposing()
css::uno::Sequence< css::uno::Type > getTypes()
static bool willPropertyBeChanged(const css::uno::Any &aCurrentValue, const css::uno::Any &aNewValue, css::uno::Any &aOldValue, css::uno::Any &aChangedValue)
checks if given property will be changed by this settings.
Definition: properties.h:112
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &aValue) override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &aConvertedValue, css::uno::Any &aOldValue, sal_Int32 nHandle, const css::uno::Any &aValue) override
virtual void SAL_CALL elementInserted(const css::ui::ConfigurationEvent &Event) override
css::uno::Reference< css::awt::XMenuBar > m_xMenuBar
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual OUString SAL_CALL getResourceURL() override
virtual void SAL_CALL setSettings(const css::uno::Reference< css::container::XIndexAccess > &UISettings) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL elementReplaced(const css::ui::ConfigurationEvent &Event) override
css::uno::Reference< css::container::XIndexAccess > m_xConfigData
virtual void SAL_CALL elementRemoved(const css::ui::ConfigurationEvent &Event) override
virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getSettings(sal_Bool bWriteable) override
virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override
css::uno::WeakReference< css::frame::XFrame > m_xWeakFrame
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual ::sal_Int16 SAL_CALL getType() override
static css::uno::Sequence< css::beans::Property > impl_getStaticPropertyDescriptor()
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &type) override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &aValue, sal_Int32 nHandle) const override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
css::uno::Reference< css::ui::XUIConfigurationManager > m_xConfigSource
float u
bool m_bDisposed
Sequence< PropertyValue > aArguments
@ Exception
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
Type
QPRO_FUNC_TYPE nType
sal_Int32 nHandle
Reference< XFrame > xFrame
unsigned char sal_Bool
std::mutex m_aMutex
constexpr OUStringLiteral UIELEMENT_PROPNAME_CONFIGLISTENER
constexpr OUStringLiteral UIELEMENT_PROPNAME_NOCLOSE
constexpr OUStringLiteral UIELEMENT_PROPNAME_RESOURCEURL
const int UIELEMENT_PROPHANDLE_NOCLOSE
const int UIELEMENT_PROPHANDLE_CONFIGLISTENER
constexpr OUStringLiteral UIELEMENT_PROPNAME_PERSISTENT
constexpr OUStringLiteral UIELEMENT_PROPNAME_FRAME
constexpr OUStringLiteral UIELEMENT_PROPNAME_XMENUBAR
const int UIELEMENT_PROPHANDLE_RESOURCEURL
constexpr OUStringLiteral UIELEMENT_PROPNAME_CONFIGSOURCE
const int UIELEMENT_PROPHANDLE_FRAME
constexpr OUStringLiteral UIELEMENT_PROPNAME_TYPE
const int UIELEMENT_PROPHANDLE_PERSISTENT
const int UIELEMENT_PROPHANDLE_CONFIGSOURCE
const int UIELEMENT_PROPHANDLE_TYPE
const int UIELEMENT_PROPHANDLE_XMENUBAR