xref: /AOO41X/main/framework/source/fwe/classes/actiontriggerseparatorpropertyset.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 
27 #include <classes/actiontriggerseparatorpropertyset.hxx>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <cppuhelper/proptypehlp.hxx>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <vcl/svapp.hxx>
32 
33 
34 using namespace cppu;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::beans;
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::awt;
39 
40 // Handles for properties
41 // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
42 // We use an enum to define these handles, to use all numbers from 0 to nn and
43 // if you add someone, you don't must control this!
44 // But don't forget to change values of follow defines, if you do something with this enum!
45 enum EPROPERTIES
46 {
47     HANDLE_TYPE,
48     PROPERTYCOUNT
49 };
50 
51 namespace framework
52 {
53 
54 ActionTriggerSeparatorPropertySet::ActionTriggerSeparatorPropertySet( const Reference< XMultiServiceFactory >& /*ServiceManager*/ )
55         :   ThreadHelpBase          ( &Application::GetSolarMutex()                     )
56         ,   OBroadcastHelper        ( m_aLock.getShareableOslMutex()                    )
57         ,   OPropertySetHelper      ( *SAL_STATIC_CAST( OBroadcastHelper *, this )      )
58         ,   OWeakObject             (                                                   )
59         ,   m_nSeparatorType( 0 )
60 {
61 }
62 
63 ActionTriggerSeparatorPropertySet::~ActionTriggerSeparatorPropertySet()
64 {
65 }
66 
67 // XInterface
68 Any SAL_CALL ActionTriggerSeparatorPropertySet::queryInterface( const Type& aType )
69 throw ( RuntimeException )
70 {
71     Any a = ::cppu::queryInterface(
72                 aType ,
73                 SAL_STATIC_CAST( XServiceInfo*, this ));
74 
75     if( a.hasValue() )
76         return a;
77     else
78     {
79         a = OPropertySetHelper::queryInterface( aType );
80 
81         if( a.hasValue() )
82             return a;
83     }
84 
85     return OWeakObject::queryInterface( aType );
86 }
87 
88 void ActionTriggerSeparatorPropertySet::acquire() throw()
89 {
90     OWeakObject::acquire();
91 }
92 
93 void ActionTriggerSeparatorPropertySet::release() throw()
94 {
95     OWeakObject::release();
96 }
97 
98 // XServiceInfo
99 ::rtl::OUString SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationName()
100 throw ( RuntimeException )
101 {
102     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGERSEPARATOR ));
103 }
104 
105 sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::supportsService( const ::rtl::OUString& ServiceName )
106 throw ( RuntimeException )
107 {
108     if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR ))
109         return sal_True;
110 
111     return sal_False;
112 }
113 
114 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerSeparatorPropertySet::getSupportedServiceNames()
115 throw ( RuntimeException )
116 {
117     Sequence< ::rtl::OUString > seqServiceNames( 1 );
118     seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR ));
119     return seqServiceNames;
120 }
121 
122 // XTypeProvider
123 Sequence< Type > SAL_CALL ActionTriggerSeparatorPropertySet::getTypes() throw ( RuntimeException )
124 {
125     // Optimize this method !
126     // We initialize a static variable only one time. And we don't must use a mutex at every call!
127     // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
128     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
129 
130     if ( pTypeCollection == NULL )
131     {
132         // Ready for multithreading; get global mutex for first call of this method only! see before
133         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
134 
135         // Control these pointer again ... it can be, that another instance will be faster then these!
136         if ( pTypeCollection == NULL )
137         {
138             // Create a static typecollection ...
139             static ::cppu::OTypeCollection aTypeCollection(
140                         ::getCppuType(( const Reference< XPropertySet           >*)NULL ) ,
141                         ::getCppuType(( const Reference< XFastPropertySet       >*)NULL ) ,
142                         ::getCppuType(( const Reference< XMultiPropertySet      >*)NULL ) ,
143                         ::getCppuType(( const Reference< XServiceInfo           >*)NULL ) ,
144                         ::getCppuType(( const Reference< XTypeProvider          >*)NULL ) ) ;
145 
146             // ... and set his address to static pointer!
147             pTypeCollection = &aTypeCollection ;
148         }
149     }
150 
151     return pTypeCollection->getTypes() ;
152 }
153 
154 Sequence< sal_Int8 > SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationId() throw ( RuntimeException )
155 {
156     // Create one Id for all instances of this class.
157     // Use ethernet address to do this! (sal_True)
158 
159     // Optimize this method
160     // We initialize a static variable only one time. And we don't must use a mutex at every call!
161     // For the first call; pID is NULL - for the second call pID is different from NULL!
162     static ::cppu::OImplementationId* pID = NULL ;
163 
164     if ( pID == NULL )
165     {
166         // Ready for multithreading; get global mutex for first call of this method only! see before
167         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
168 
169         // Control these pointer again ... it can be, that another instance will be faster then these!
170         if ( pID == NULL )
171         {
172             // Create a new static ID ...
173             static ::cppu::OImplementationId aID( sal_False ) ;
174             // ... and set his address to static pointer!
175             pID = &aID ;
176         }
177     }
178 
179     return pID->getImplementationId() ;
180 }
181 
182 //---------------------------------------------------------------------------------------------------------
183 //  OPropertySetHelper implementation
184 //---------------------------------------------------------------------------------------------------------
185 
186 sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::convertFastPropertyValue(
187     Any&        aConvertedValue,
188     Any&        aOldValue,
189     sal_Int32   nHandle,
190     const Any&  aValue  )
191 throw( IllegalArgumentException )
192 {
193     //  Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
194     //  Return sal_True, if changed - else return sal_False.
195     //  Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
196     //  Initialize return value with sal_False !!!
197     //  (Handle can be invalid)
198     sal_Bool bReturn = sal_False;
199 
200     switch( nHandle )
201     {
202         case HANDLE_TYPE:
203             bReturn = impl_tryToChangeProperty( m_nSeparatorType, aValue, aOldValue, aConvertedValue );
204             break;
205     }
206 
207     // Return state of operation.
208     return bReturn;
209 }
210 
211 
212 void SAL_CALL ActionTriggerSeparatorPropertySet::setFastPropertyValue_NoBroadcast(
213     sal_Int32 nHandle, const Any& aValue )
214 throw( Exception )
215 {
216     ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
217 
218     // Search for right handle ... and try to set property value.
219     switch( nHandle )
220     {
221         case HANDLE_TYPE:
222             aValue >>= m_nSeparatorType;
223             break;
224     }
225 }
226 
227 void SAL_CALL ActionTriggerSeparatorPropertySet::getFastPropertyValue(
228     Any& aValue, sal_Int32 nHandle ) const
229 {
230     ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
231 
232     // Search for right handle ... and try to get property value.
233     switch( nHandle )
234     {
235         case HANDLE_TYPE:
236             aValue <<= m_nSeparatorType;
237             break;
238     }
239 }
240 
241 ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerSeparatorPropertySet::getInfoHelper()
242 {
243     // Optimize this method !
244     // We initialize a static variable only one time. And we don't must use a mutex at every call!
245     // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
246     static OPropertyArrayHelper* pInfoHelper = NULL;
247 
248     if( pInfoHelper == NULL )
249     {
250         // Ready for multithreading
251         ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
252         // Control this pointer again, another instance can be faster then these!
253         if( pInfoHelper == NULL )
254         {
255             // Define static member to give structure of properties to baseclass "OPropertySetHelper".
256             // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
257             // "sal_True" say: Table is sorted by name.
258             static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
259             pInfoHelper = &aInfoHelper;
260         }
261     }
262 
263     return (*pInfoHelper);
264 }
265 
266 Reference< XPropertySetInfo > SAL_CALL ActionTriggerSeparatorPropertySet::getPropertySetInfo()
267 throw ( RuntimeException )
268 {
269     // Optimize this method !
270     // We initialize a static variable only one time. And we don't must use a mutex at every call!
271     // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
272     static Reference< XPropertySetInfo >* pInfo = NULL ;
273 
274     if( pInfo == NULL )
275     {
276         // Ready for multithreading
277         ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
278         // Control this pointer again, another instance can be faster then these!
279         if( pInfo == NULL )
280         {
281             // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
282             // (Use method "getInfoHelper()".)
283             static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
284             pInfo = &xInfo;
285         }
286     }
287 
288     return (*pInfo);
289 }
290 
291 const Sequence< Property > ActionTriggerSeparatorPropertySet::impl_getStaticPropertyDescriptor()
292 {
293     static const Property pActionTriggerPropertys[] =
294     {
295         Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SeparatorType" )), HANDLE_TYPE, ::getCppuType((sal_Int16*)0), PropertyAttribute::TRANSIENT )
296     };
297 
298     // Use it to initialize sequence!
299     static const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT );
300 
301     // Return static "PropertyDescriptor"
302     return seqActionTriggerPropertyDescriptor ;
303 }
304 
305 
306 //******************************************************************************************************************************
307 //  private method
308 //******************************************************************************************************************************
309 sal_Bool ActionTriggerSeparatorPropertySet::impl_tryToChangeProperty(
310     sal_Int16           aCurrentValue   ,
311     const   Any&        aNewValue       ,
312     Any&                aOldValue       ,
313     Any&                aConvertedValue )
314 throw( IllegalArgumentException )
315 {
316     // Set default return value if method failed.
317     sal_Bool bReturn = sal_False;
318     // Get new value from any.
319     // IllegalArgumentException() can be thrown!
320     sal_Int16 aValue = 0;
321     convertPropertyValue( aValue, aNewValue );
322 
323     // If value change ...
324     if( aValue != aCurrentValue )
325     {
326         // ... set information of change.
327         aOldValue       <<= aCurrentValue   ;
328         aConvertedValue <<= aValue          ;
329         // Return OK - "value will be change ..."
330         bReturn = sal_True;
331     }
332     else
333     {
334         // ... clear information of return parameter!
335         aOldValue.clear         () ;
336         aConvertedValue.clear   () ;
337         // Return NOTHING - "value will not be change ..."
338         bReturn = sal_False;
339     }
340 
341     return bReturn;
342 }
343 
344 }
345 
346