Line data Source code
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 :
20 : #include <helper/uielementwrapperbase.hxx>
21 : #include <general.h>
22 : #include <properties.h>
23 : #include <threadhelp/resetableguard.hxx>
24 :
25 : #include <com/sun/star/beans/PropertyAttribute.hpp>
26 : #include <com/sun/star/beans/PropertyValue.hpp>
27 : #include <com/sun/star/beans/XPropertySet.hpp>
28 :
29 : #include <vcl/svapp.hxx>
30 : #include <rtl/logfile.hxx>
31 :
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";
39 :
40 : using namespace ::com::sun::star::uno;
41 : using namespace ::com::sun::star::beans;
42 : using namespace ::com::sun::star::frame;
43 : using ::rtl::OUString;
44 :
45 : namespace framework
46 : {
47 :
48 : //*****************************************************************************************************************
49 : // XInterface, XTypeProvider
50 : //*****************************************************************************************************************
51 77650 : DEFINE_XINTERFACE_8 ( UIElementWrapperBase ,
52 : OWeakObject ,
53 : DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ),
54 : DIRECT_INTERFACE( ::com::sun::star::ui::XUIElement ),
55 : DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet ),
56 : DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet ),
57 : DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet ),
58 : DIRECT_INTERFACE( ::com::sun::star::lang::XInitialization ),
59 : DIRECT_INTERFACE( ::com::sun::star::util::XUpdatable ),
60 : DIRECT_INTERFACE( ::com::sun::star::lang::XComponent )
61 : )
62 :
63 0 : DEFINE_XTYPEPROVIDER_8 ( UIElementWrapperBase ,
64 : ::com::sun::star::lang::XTypeProvider ,
65 : ::com::sun::star::ui::XUIElement ,
66 : ::com::sun::star::beans::XMultiPropertySet ,
67 : ::com::sun::star::beans::XFastPropertySet ,
68 : ::com::sun::star::beans::XPropertySet ,
69 : ::com::sun::star::lang::XInitialization ,
70 : ::com::sun::star::util::XUpdatable ,
71 : ::com::sun::star::lang::XComponent
72 : )
73 :
74 476 : UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType )
75 476 : : ThreadHelpBase ( &Application::GetSolarMutex() )
76 476 : , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() )
77 : , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
78 : , ::cppu::OWeakObject ( )
79 476 : , m_aListenerContainer ( m_aLock.getShareableOslMutex() )
80 : , m_nType ( nType )
81 : , m_bInitialized ( sal_False )
82 1904 : , m_bDisposed ( sal_False )
83 : {
84 476 : }
85 :
86 126 : UIElementWrapperBase::~UIElementWrapperBase()
87 : {
88 126 : }
89 :
90 0 : void SAL_CALL UIElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
91 : {
92 0 : m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
93 0 : }
94 :
95 0 : void SAL_CALL UIElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
96 : {
97 0 : m_aListenerContainer.removeInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
98 0 : }
99 :
100 236 : void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments )
101 : throw ( Exception, RuntimeException )
102 : {
103 236 : ResetableGuard aLock( m_aLock );
104 :
105 236 : if ( !m_bInitialized )
106 : {
107 944 : for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
108 : {
109 708 : PropertyValue aPropValue;
110 708 : if ( aArguments[n] >>= aPropValue )
111 : {
112 708 : if ( aPropValue.Name == "ResourceURL" )
113 236 : aPropValue.Value >>= m_aResourceURL;
114 472 : else if ( aPropValue.Name == "Frame" )
115 : {
116 236 : Reference< XFrame > xFrame;
117 236 : aPropValue.Value >>= xFrame;
118 236 : m_xWeakFrame = xFrame;
119 : }
120 : }
121 708 : }
122 :
123 236 : m_bInitialized = sal_True;
124 236 : }
125 236 : }
126 :
127 : // XUIElement
128 0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame() throw (::com::sun::star::uno::RuntimeException)
129 : {
130 0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( m_xWeakFrame );
131 0 : return xFrame;
132 : }
133 :
134 0 : ::rtl::OUString SAL_CALL UIElementWrapperBase::getResourceURL() throw (::com::sun::star::uno::RuntimeException)
135 : {
136 0 : return m_aResourceURL;
137 : }
138 :
139 0 : ::sal_Int16 SAL_CALL UIElementWrapperBase::getType() throw (::com::sun::star::uno::RuntimeException)
140 : {
141 0 : return m_nType;
142 : }
143 :
144 : // XUpdatable
145 0 : void SAL_CALL UIElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException)
146 : {
147 : // can be implemented by derived class
148 0 : }
149 :
150 : // XPropertySet helper
151 0 : sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any& /*aConvertedValue*/ ,
152 : Any& /*aOldValue*/ ,
153 : sal_Int32 /*nHandle*/ ,
154 : const Any& /*aValue*/ ) throw( com::sun::star::lang::IllegalArgumentException )
155 : {
156 : // Initialize state with sal_False !!!
157 : // (Handle can be invalid)
158 0 : return sal_False ;
159 : }
160 :
161 0 : void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 /*nHandle*/ ,
162 : const com::sun::star::uno::Any& /*aValue*/ ) throw( com::sun::star::uno::Exception )
163 : {
164 0 : }
165 :
166 0 : void SAL_CALL UIElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any& aValue ,
167 : sal_Int32 nHandle ) const
168 : {
169 0 : switch( nHandle )
170 : {
171 : case UIELEMENT_PROPHANDLE_RESOURCEURL:
172 0 : aValue <<= m_aResourceURL;
173 : break;
174 : case UIELEMENT_PROPHANDLE_TYPE:
175 0 : aValue <<= m_nType;
176 : break;
177 : case UIELEMENT_PROPHANDLE_FRAME:
178 0 : Reference< XFrame > xFrame( m_xWeakFrame );
179 0 : aValue <<= xFrame;
180 0 : break;
181 : }
182 0 : }
183 :
184 0 : ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper()
185 : {
186 : // Optimize this method !
187 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
188 : // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
189 : static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
190 :
191 0 : if( pInfoHelper == NULL )
192 : {
193 : // Ready for multithreading
194 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
195 :
196 : // Control this pointer again, another instance can be faster then these!
197 0 : if( pInfoHelper == NULL )
198 : {
199 : // Define static member to give structure of properties to baseclass "OPropertySetHelper".
200 : // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
201 : // "sal_True" say: Table is sorted by name.
202 0 : static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
203 0 : pInfoHelper = &aInfoHelper;
204 0 : }
205 : }
206 :
207 0 : return(*pInfoHelper);
208 : }
209 :
210 0 : com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException)
211 : {
212 : // Optimize this method !
213 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
214 : // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
215 : static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL;
216 :
217 0 : if( pInfo == NULL )
218 : {
219 : // Ready for multithreading
220 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
221 : // Control this pointer again, another instance can be faster then these!
222 0 : if( pInfo == NULL )
223 : {
224 : // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
225 : // (Use method "getInfoHelper()".)
226 0 : static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
227 0 : pInfo = &xInfo;
228 0 : }
229 : }
230 :
231 0 : return (*pInfo);
232 : }
233 :
234 0 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor()
235 : {
236 : // Create a property array to initialize sequence!
237 : // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
238 : // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
239 : // It's necessary for methods of OPropertySetHelper.
240 : // ATTENTION:
241 : // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
242 :
243 : const com::sun::star::beans::Property pProperties[] =
244 : {
245 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 ),
246 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 ),
247 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 )
248 0 : };
249 : // Use it to initialize sequence!
250 0 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, UIELEMENT_PROPCOUNT );
251 : // Return "PropertyDescriptor"
252 0 : return lPropertyDescriptor;
253 : }
254 :
255 : }
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|