bump product version to 4.1.6.2
[LibreOffice.git] / framework / source / helper / uielementwrapperbase.cxx
blob071448d37e7f4bfbef55d63b3f392e2bc19c7305
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/uielementwrapperbase.hxx>
21 #include <general.h>
22 #include <properties.h>
23 #include <threadhelp/resetableguard.hxx>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <vcl/svapp.hxx>
30 #include <rtl/logfile.hxx>
32 const int UIELEMENT_PROPHANDLE_RESOURCEURL = 1;
33 const int UIELEMENT_PROPHANDLE_TYPE = 2;
34 const int UIELEMENT_PROPHANDLE_FRAME = 3;
35 const int UIELEMENT_PROPCOUNT = 3;
36 const char UIELEMENT_PROPNAME_RESOURCEURL[] = "ResourceURL";
37 const char UIELEMENT_PROPNAME_TYPE[] = "Type";
38 const char UIELEMENT_PROPNAME_FRAME[] = "Frame";
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::frame;
44 namespace framework
47 //*****************************************************************************************************************
48 // XInterface, XTypeProvider
49 //*****************************************************************************************************************
50 DEFINE_XINTERFACE_8 ( UIElementWrapperBase ,
51 OWeakObject ,
52 DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ),
53 DIRECT_INTERFACE( ::com::sun::star::ui::XUIElement ),
54 DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet ),
55 DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet ),
56 DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet ),
57 DIRECT_INTERFACE( ::com::sun::star::lang::XInitialization ),
58 DIRECT_INTERFACE( ::com::sun::star::util::XUpdatable ),
59 DIRECT_INTERFACE( ::com::sun::star::lang::XComponent )
62 DEFINE_XTYPEPROVIDER_8 ( UIElementWrapperBase ,
63 ::com::sun::star::lang::XTypeProvider ,
64 ::com::sun::star::ui::XUIElement ,
65 ::com::sun::star::beans::XMultiPropertySet ,
66 ::com::sun::star::beans::XFastPropertySet ,
67 ::com::sun::star::beans::XPropertySet ,
68 ::com::sun::star::lang::XInitialization ,
69 ::com::sun::star::util::XUpdatable ,
70 ::com::sun::star::lang::XComponent
73 UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType )
74 : ThreadHelpBase ( &Application::GetSolarMutex() )
75 , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() )
76 , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
77 , ::cppu::OWeakObject ( )
78 , m_aListenerContainer ( m_aLock.getShareableOslMutex() )
79 , m_nType ( nType )
80 , m_bInitialized ( sal_False )
81 , m_bDisposed ( sal_False )
85 UIElementWrapperBase::~UIElementWrapperBase()
89 void SAL_CALL UIElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
91 m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
94 void SAL_CALL UIElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
96 m_aListenerContainer.removeInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
99 void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments )
100 throw ( Exception, RuntimeException )
102 ResetableGuard aLock( m_aLock );
104 if ( !m_bInitialized )
106 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
108 PropertyValue aPropValue;
109 if ( aArguments[n] >>= aPropValue )
111 if ( aPropValue.Name == "ResourceURL" )
112 aPropValue.Value >>= m_aResourceURL;
113 else if ( aPropValue.Name == "Frame" )
115 Reference< XFrame > xFrame;
116 aPropValue.Value >>= xFrame;
117 m_xWeakFrame = xFrame;
122 m_bInitialized = sal_True;
126 // XUIElement
127 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame() throw (::com::sun::star::uno::RuntimeException)
129 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( m_xWeakFrame );
130 return xFrame;
133 OUString SAL_CALL UIElementWrapperBase::getResourceURL() throw (::com::sun::star::uno::RuntimeException)
135 return m_aResourceURL;
138 ::sal_Int16 SAL_CALL UIElementWrapperBase::getType() throw (::com::sun::star::uno::RuntimeException)
140 return m_nType;
143 // XUpdatable
144 void SAL_CALL UIElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException)
146 // can be implemented by derived class
149 // XPropertySet helper
150 sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any& /*aConvertedValue*/ ,
151 Any& /*aOldValue*/ ,
152 sal_Int32 /*nHandle*/ ,
153 const Any& /*aValue*/ ) throw( com::sun::star::lang::IllegalArgumentException )
155 // Initialize state with sal_False !!!
156 // (Handle can be invalid)
157 return sal_False ;
160 void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 /*nHandle*/ ,
161 const com::sun::star::uno::Any& /*aValue*/ ) throw( com::sun::star::uno::Exception )
165 void SAL_CALL UIElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any& aValue ,
166 sal_Int32 nHandle ) const
168 switch( nHandle )
170 case UIELEMENT_PROPHANDLE_RESOURCEURL:
171 aValue <<= m_aResourceURL;
172 break;
173 case UIELEMENT_PROPHANDLE_TYPE:
174 aValue <<= m_nType;
175 break;
176 case UIELEMENT_PROPHANDLE_FRAME:
177 Reference< XFrame > xFrame( m_xWeakFrame );
178 aValue <<= xFrame;
179 break;
183 ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper()
185 // Optimize this method !
186 // We initialize a static variable only one time. And we don't must use a mutex at every call!
187 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
188 static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
190 if( pInfoHelper == NULL )
192 // Ready for multithreading
193 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
195 // Control this pointer again, another instance can be faster then these!
196 if( pInfoHelper == NULL )
198 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
199 // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
200 // "sal_True" say: Table is sorted by name.
201 static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
202 pInfoHelper = &aInfoHelper;
206 return(*pInfoHelper);
209 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException)
211 // Optimize this method !
212 // We initialize a static variable only one time. And we don't must use a mutex at every call!
213 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
214 static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL;
216 if( pInfo == NULL )
218 // Ready for multithreading
219 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
220 // Control this pointer again, another instance can be faster then these!
221 if( pInfo == NULL )
223 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
224 // (Use method "getInfoHelper()".)
225 static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
226 pInfo = &xInfo;
230 return (*pInfo);
233 const com::sun::star::uno::Sequence< com::sun::star::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor()
235 // Create a property array to initialize sequence!
236 // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
237 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
238 // It's necessary for methods of OPropertySetHelper.
239 // ATTENTION:
240 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
242 const com::sun::star::beans::Property pProperties[] =
244 com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_FRAME), UIELEMENT_PROPHANDLE_FRAME , ::getCppuType((Reference< XFrame >*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
245 com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_RESOURCEURL), UIELEMENT_PROPHANDLE_RESOURCEURL , ::getCppuType((sal_Int16*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
246 com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_TYPE), UIELEMENT_PROPHANDLE_TYPE , ::getCppuType((const OUString*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY )
248 // Use it to initialize sequence!
249 const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, UIELEMENT_PROPCOUNT );
250 // Return "PropertyDescriptor"
251 return lPropertyDescriptor;
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */