Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <helper/uielementwrapperbase.hxx>
30 : : #include <general.h>
31 : : #include <properties.h>
32 : : #include <threadhelp/resetableguard.hxx>
33 : :
34 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
35 : : #include <com/sun/star/beans/PropertyValue.hpp>
36 : : #include <com/sun/star/beans/XPropertySet.hpp>
37 : :
38 : : #include <vcl/svapp.hxx>
39 : : #include <rtl/logfile.hxx>
40 : :
41 : : const int UIELEMENT_PROPHANDLE_RESOURCEURL = 1;
42 : : const int UIELEMENT_PROPHANDLE_TYPE = 2;
43 : : const int UIELEMENT_PROPHANDLE_FRAME = 3;
44 : : const int UIELEMENT_PROPCOUNT = 3;
45 : : const char UIELEMENT_PROPNAME_RESOURCEURL[] = "ResourceURL";
46 : : const char UIELEMENT_PROPNAME_TYPE[] = "Type";
47 : : const char UIELEMENT_PROPNAME_FRAME[] = "Frame";
48 : :
49 : : using namespace ::com::sun::star::uno;
50 : : using namespace ::com::sun::star::beans;
51 : : using namespace ::com::sun::star::frame;
52 : : using ::rtl::OUString;
53 : :
54 : : namespace framework
55 : : {
56 : :
57 : : //*****************************************************************************************************************
58 : : // XInterface, XTypeProvider
59 : : //*****************************************************************************************************************
60 [ + + ][ + - ]: 279297 : DEFINE_XINTERFACE_8 ( UIElementWrapperBase ,
61 : : OWeakObject ,
62 : : DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ),
63 : : DIRECT_INTERFACE( ::com::sun::star::ui::XUIElement ),
64 : : DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet ),
65 : : DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet ),
66 : : DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet ),
67 : : DIRECT_INTERFACE( ::com::sun::star::lang::XInitialization ),
68 : : DIRECT_INTERFACE( ::com::sun::star::util::XUpdatable ),
69 : : DIRECT_INTERFACE( ::com::sun::star::lang::XComponent )
70 : : )
71 : :
72 [ # # ][ # # ]: 0 : DEFINE_XTYPEPROVIDER_8 ( UIElementWrapperBase ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
73 : : ::com::sun::star::lang::XTypeProvider ,
74 : : ::com::sun::star::ui::XUIElement ,
75 : : ::com::sun::star::beans::XMultiPropertySet ,
76 : : ::com::sun::star::beans::XFastPropertySet ,
77 : : ::com::sun::star::beans::XPropertySet ,
78 : : ::com::sun::star::lang::XInitialization ,
79 : : ::com::sun::star::util::XUpdatable ,
80 : : ::com::sun::star::lang::XComponent
81 : : )
82 : :
83 : 1747 : UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType )
84 [ + - ]: 1747 : : ThreadHelpBase ( &Application::GetSolarMutex() )
85 [ + - ]: 1747 : , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() )
86 : : , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
87 : : , ::cppu::OWeakObject ( )
88 [ + - ]: 1747 : , m_aListenerContainer ( m_aLock.getShareableOslMutex() )
89 : : , m_nType ( nType )
90 : : , m_bInitialized ( sal_False )
91 [ + - ][ + - ]: 6988 : , m_bDisposed ( sal_False )
[ + - ][ + - ]
[ + - ]
92 : : {
93 : 1747 : }
94 : :
95 [ + - ][ + - ]: 1656 : UIElementWrapperBase::~UIElementWrapperBase()
[ + - ][ + - ]
[ + - ][ + - ]
96 : : {
97 [ - + ]: 1656 : }
98 : :
99 : 0 : void SAL_CALL UIElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
100 : : {
101 : 0 : m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
102 : 0 : }
103 : :
104 : 0 : void SAL_CALL UIElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
105 : : {
106 : 0 : m_aListenerContainer.removeInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
107 : 0 : }
108 : :
109 : 0 : void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments )
110 : : throw ( Exception, RuntimeException )
111 : : {
112 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
113 : :
114 [ # # ]: 0 : if ( !m_bInitialized )
115 : : {
116 [ # # ]: 0 : for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
117 : : {
118 : 0 : PropertyValue aPropValue;
119 [ # # ][ # # ]: 0 : if ( aArguments[n] >>= aPropValue )
120 : : {
121 [ # # ]: 0 : if ( aPropValue.Name == "ResourceURL" )
122 : 0 : aPropValue.Value >>= m_aResourceURL;
123 [ # # ]: 0 : else if ( aPropValue.Name == "Frame" )
124 : : {
125 : 0 : Reference< XFrame > xFrame;
126 [ # # ]: 0 : aPropValue.Value >>= xFrame;
127 [ # # ]: 0 : m_xWeakFrame = xFrame;
128 : : }
129 : : }
130 : 0 : }
131 : :
132 : 0 : m_bInitialized = sal_True;
133 [ # # ]: 0 : }
134 : 0 : }
135 : :
136 : : // XUIElement
137 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame() throw (::com::sun::star::uno::RuntimeException)
138 : : {
139 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( m_xWeakFrame );
140 : 0 : return xFrame;
141 : : }
142 : :
143 : 0 : ::rtl::OUString SAL_CALL UIElementWrapperBase::getResourceURL() throw (::com::sun::star::uno::RuntimeException)
144 : : {
145 : 0 : return m_aResourceURL;
146 : : }
147 : :
148 : 0 : ::sal_Int16 SAL_CALL UIElementWrapperBase::getType() throw (::com::sun::star::uno::RuntimeException)
149 : : {
150 : 0 : return m_nType;
151 : : }
152 : :
153 : : // XUpdatable
154 : 0 : void SAL_CALL UIElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException)
155 : : {
156 : : // can be implemented by derived class
157 : 0 : }
158 : :
159 : : // XPropertySet helper
160 : 0 : sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any& /*aConvertedValue*/ ,
161 : : Any& /*aOldValue*/ ,
162 : : sal_Int32 /*nHandle*/ ,
163 : : const Any& /*aValue*/ ) throw( com::sun::star::lang::IllegalArgumentException )
164 : : {
165 : : // Initialize state with sal_False !!!
166 : : // (Handle can be invalid)
167 : 0 : return sal_False ;
168 : : }
169 : :
170 : 0 : void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 /*nHandle*/ ,
171 : : const com::sun::star::uno::Any& /*aValue*/ ) throw( com::sun::star::uno::Exception )
172 : : {
173 : 0 : }
174 : :
175 : 0 : void SAL_CALL UIElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any& aValue ,
176 : : sal_Int32 nHandle ) const
177 : : {
178 [ # # # # ]: 0 : switch( nHandle )
179 : : {
180 : : case UIELEMENT_PROPHANDLE_RESOURCEURL:
181 [ # # ]: 0 : aValue <<= m_aResourceURL;
182 : : break;
183 : : case UIELEMENT_PROPHANDLE_TYPE:
184 [ # # ]: 0 : aValue <<= m_nType;
185 : : break;
186 : : case UIELEMENT_PROPHANDLE_FRAME:
187 [ # # ]: 0 : Reference< XFrame > xFrame( m_xWeakFrame );
188 [ # # ]: 0 : aValue <<= xFrame;
189 : 0 : break;
190 : : }
191 : 0 : }
192 : :
193 : 0 : ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper()
194 : : {
195 : : // Optimize this method !
196 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
197 : : // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
198 : : static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
199 : :
200 [ # # ]: 0 : if( pInfoHelper == NULL )
201 : : {
202 : : // Ready for multithreading
203 [ # # ][ # # ]: 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
204 : :
205 : : // Control this pointer again, another instance can be faster then these!
206 [ # # ]: 0 : if( pInfoHelper == NULL )
207 : : {
208 : : // Define static member to give structure of properties to baseclass "OPropertySetHelper".
209 : : // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
210 : : // "sal_True" say: Table is sorted by name.
211 [ # # ][ # # ]: 0 : static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
[ # # ][ # # ]
[ # # ][ # # ]
212 : 0 : pInfoHelper = &aInfoHelper;
213 [ # # ]: 0 : }
214 : : }
215 : :
216 : 0 : return(*pInfoHelper);
217 : : }
218 : :
219 : 0 : com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException)
220 : : {
221 : : // Optimize this method !
222 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
223 : : // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
224 : : static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL;
225 : :
226 [ # # ]: 0 : if( pInfo == NULL )
227 : : {
228 : : // Ready for multithreading
229 [ # # ][ # # ]: 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
230 : : // Control this pointer again, another instance can be faster then these!
231 [ # # ]: 0 : if( pInfo == NULL )
232 : : {
233 : : // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
234 : : // (Use method "getInfoHelper()".)
235 [ # # ][ # # ]: 0 : static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
[ # # ][ # # ]
[ # # ]
236 : 0 : pInfo = &xInfo;
237 [ # # ]: 0 : }
238 : : }
239 : :
240 : 0 : return (*pInfo);
241 : : }
242 : :
243 : 0 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor()
244 : : {
245 : : // Create a property array to initialize sequence!
246 : : // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
247 : : // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
248 : : // It's necessary for methods of OPropertySetHelper.
249 : : // ATTENTION:
250 : : // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
251 : :
252 : : const com::sun::star::beans::Property pProperties[] =
253 : : {
254 [ # # ]: 0 : com::sun::star::beans::Property( rtl::OUString(UIELEMENT_PROPNAME_FRAME), UIELEMENT_PROPHANDLE_FRAME , ::getCppuType((Reference< XFrame >*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
255 [ # # ]: 0 : com::sun::star::beans::Property( rtl::OUString(UIELEMENT_PROPNAME_RESOURCEURL), UIELEMENT_PROPHANDLE_RESOURCEURL , ::getCppuType((sal_Int16*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
256 [ # # ]: 0 : com::sun::star::beans::Property( rtl::OUString(UIELEMENT_PROPNAME_TYPE), UIELEMENT_PROPHANDLE_TYPE , ::getCppuType((const ::rtl::OUString*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY )
257 [ # # # # ]: 0 : };
258 : : // Use it to initialize sequence!
259 [ # # ]: 0 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, UIELEMENT_PROPCOUNT );
260 : : // Return "PropertyDescriptor"
261 [ # # ][ # # ]: 0 : return lPropertyDescriptor;
262 : : }
263 : :
264 : : }
265 : :
266 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|