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