fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / helper / uielementwrapperbase.cxx
blobb8780f21444013f2d4ef4f03b005c37eb36d3700
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>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <vcl/svapp.hxx>
29 #include <comphelper/sequence.hxx>
31 const int UIELEMENT_PROPHANDLE_RESOURCEURL = 1;
32 const int UIELEMENT_PROPHANDLE_TYPE = 2;
33 const int UIELEMENT_PROPHANDLE_FRAME = 3;
34 const int UIELEMENT_PROPCOUNT = 3;
35 const char UIELEMENT_PROPNAME_RESOURCEURL[] = "ResourceURL";
36 const char UIELEMENT_PROPNAME_TYPE[] = "Type";
37 const char UIELEMENT_PROPNAME_FRAME[] = "Frame";
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::frame;
43 namespace framework
46 UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType )
47 : ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aMutex )
48 , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
49 , m_aListenerContainer ( m_aMutex )
50 , m_nType ( nType )
51 , m_bInitialized ( false )
52 , m_bDisposed ( false )
56 UIElementWrapperBase::~UIElementWrapperBase()
60 Any SAL_CALL UIElementWrapperBase::queryInterface( const Type& _rType ) throw(RuntimeException, std::exception)
62 Any aRet = UIElementWrapperBase_BASE::queryInterface( _rType );
63 if ( !aRet.hasValue() )
64 aRet = OPropertySetHelper::queryInterface( _rType );
65 return aRet;
68 Sequence< Type > SAL_CALL UIElementWrapperBase::getTypes( ) throw(RuntimeException, std::exception)
70 return comphelper::concatSequences(
71 UIElementWrapperBase_BASE::getTypes(),
72 ::cppu::OPropertySetHelper::getTypes()
76 void SAL_CALL UIElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception)
78 m_aListenerContainer.addInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
81 void SAL_CALL UIElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception)
83 m_aListenerContainer.removeInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
86 void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments )
87 throw ( Exception, RuntimeException, std::exception )
89 SolarMutexGuard g;
91 if ( !m_bInitialized )
93 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
95 PropertyValue aPropValue;
96 if ( aArguments[n] >>= aPropValue )
98 if ( aPropValue.Name == "ResourceURL" )
99 aPropValue.Value >>= m_aResourceURL;
100 else if ( aPropValue.Name == "Frame" )
102 Reference< XFrame > xFrame;
103 aPropValue.Value >>= xFrame;
104 m_xWeakFrame = xFrame;
109 m_bInitialized = true;
113 // XUIElement
114 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame() throw (::com::sun::star::uno::RuntimeException, std::exception)
116 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( m_xWeakFrame );
117 return xFrame;
120 OUString SAL_CALL UIElementWrapperBase::getResourceURL() throw (::com::sun::star::uno::RuntimeException, std::exception)
122 return m_aResourceURL;
125 ::sal_Int16 SAL_CALL UIElementWrapperBase::getType() throw (::com::sun::star::uno::RuntimeException, std::exception)
127 return m_nType;
130 // XUpdatable
131 void SAL_CALL UIElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException, std::exception)
133 // can be implemented by derived class
136 // XPropertySet helper
137 sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any& /*aConvertedValue*/ ,
138 Any& /*aOldValue*/ ,
139 sal_Int32 /*nHandle*/ ,
140 const Any& /*aValue*/ ) throw( com::sun::star::lang::IllegalArgumentException )
142 // Initialize state with sal_False !!!
143 // (Handle can be invalid)
144 return sal_False;
147 void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 /*nHandle*/ ,
148 const com::sun::star::uno::Any& /*aValue*/ ) throw( com::sun::star::uno::Exception, std::exception )
152 void SAL_CALL UIElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any& aValue ,
153 sal_Int32 nHandle ) const
155 switch( nHandle )
157 case UIELEMENT_PROPHANDLE_RESOURCEURL:
158 aValue <<= m_aResourceURL;
159 break;
160 case UIELEMENT_PROPHANDLE_TYPE:
161 aValue <<= m_nType;
162 break;
163 case UIELEMENT_PROPHANDLE_FRAME:
164 Reference< XFrame > xFrame( m_xWeakFrame );
165 aValue <<= xFrame;
166 break;
170 ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper()
172 // Optimize this method !
173 // We initialize a static variable only one time. And we don't must use a mutex at every call!
174 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
175 static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
177 if( pInfoHelper == NULL )
179 // Ready for multithreading
180 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
182 // Control this pointer again, another instance can be faster then these!
183 if( pInfoHelper == NULL )
185 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
186 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
187 // "sal_True" say: Table is sorted by name.
188 static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
189 pInfoHelper = &aInfoHelper;
193 return(*pInfoHelper);
196 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException, std::exception)
198 // Optimize this method !
199 // We initialize a static variable only one time. And we don't must use a mutex at every call!
200 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
201 static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL;
203 if( pInfo == NULL )
205 // Ready for multithreading
206 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
207 // Control this pointer again, another instance can be faster then these!
208 if( pInfo == NULL )
210 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
211 // (Use method "getInfoHelper()".)
212 static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
213 pInfo = &xInfo;
217 return (*pInfo);
220 const com::sun::star::uno::Sequence< com::sun::star::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor()
222 // Create a property array to initialize sequence!
223 // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
224 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
225 // It's necessary for methods of OPropertySetHelper.
226 // ATTENTION:
227 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
229 const com::sun::star::beans::Property pProperties[] =
231 com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_FRAME), UIELEMENT_PROPHANDLE_FRAME , cppu::UnoType<XFrame>::get(), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
232 com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_RESOURCEURL), UIELEMENT_PROPHANDLE_RESOURCEURL , cppu::UnoType<sal_Int16>::get(), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
233 com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_TYPE), UIELEMENT_PROPHANDLE_TYPE , cppu::UnoType<OUString>::get(), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY )
235 // Use it to initialize sequence!
236 const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, UIELEMENT_PROPCOUNT );
237 // Return "PropertyDescriptor"
238 return lPropertyDescriptor;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */