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 : :
30 : : #include <classes/rootactiontriggercontainer.hxx>
31 : : #include <classes/actiontriggercontainer.hxx>
32 : : #include <classes/actiontriggerpropertyset.hxx>
33 : : #include <classes/actiontriggerseparatorpropertyset.hxx>
34 : : #include <framework/actiontriggerhelper.hxx>
35 : : #include <threadhelp/resetableguard.hxx>
36 : : #include <osl/mutex.hxx>
37 : : #include <vcl/svapp.hxx>
38 : : #include <cppuhelper/typeprovider.hxx>
39 : :
40 : :
41 : : using namespace cppu;
42 : : using namespace com::sun::star::uno;
43 : : using namespace com::sun::star::lang;
44 : : using namespace com::sun::star::container;
45 : : using namespace com::sun::star::beans;
46 : :
47 : :
48 : : namespace framework
49 : : {
50 : :
51 : 0 : static Sequence< sal_Int8 > impl_getStaticIdentifier()
52 : : {
53 : : static sal_uInt8 pGUID[16] = { 0x17, 0x0F, 0xA2, 0xC9, 0xCA, 0x50, 0x4A, 0xD3, 0xA6, 0x3B, 0x39, 0x99, 0xC5, 0x96, 0x43, 0x27 };
54 [ # # ][ # # ]: 0 : static ::com::sun::star::uno::Sequence< sal_Int8 > seqID((sal_Int8*)pGUID,16) ;
[ # # ][ # # ]
55 : 0 : return seqID ;
56 : : }
57 : :
58 : :
59 : 0 : RootActionTriggerContainer::RootActionTriggerContainer( const Menu* pMenu, const ::rtl::OUString* pMenuIdentifier, const Reference< XMultiServiceFactory >& rServiceManager ) :
60 : : PropertySetContainer( rServiceManager )
61 : : , m_bContainerCreated( sal_False )
62 : : , m_bContainerChanged( sal_False )
63 : : , m_bInContainerCreation( sal_False )
64 : : , m_pMenu( pMenu )
65 : 0 : , m_pMenuIdentifier( pMenuIdentifier )
66 : : {
67 : 0 : }
68 : :
69 : 0 : RootActionTriggerContainer::~RootActionTriggerContainer()
70 : : {
71 [ # # ]: 0 : }
72 : :
73 : : // XInterface
74 : 0 : Any SAL_CALL RootActionTriggerContainer::queryInterface( const Type& aType )
75 : : throw ( RuntimeException )
76 : : {
77 : : Any a = ::cppu::queryInterface(
78 : : aType ,
79 : : (static_cast< XMultiServiceFactory* >(this)),
80 : : (static_cast< XServiceInfo* >(this)),
81 : : (static_cast< XUnoTunnel* >(this)),
82 : : (static_cast< XTypeProvider* >(this)),
83 [ # # ]: 0 : (static_cast< XNamed* >(this)));
84 : :
85 [ # # ]: 0 : if( a.hasValue() )
86 : : {
87 : 0 : return a;
88 : : }
89 : :
90 [ # # ]: 0 : return PropertySetContainer::queryInterface( aType );
91 : : }
92 : :
93 : 0 : void SAL_CALL RootActionTriggerContainer::acquire() throw ()
94 : : {
95 : 0 : PropertySetContainer::acquire();
96 : 0 : }
97 : :
98 : 0 : void SAL_CALL RootActionTriggerContainer::release() throw ()
99 : : {
100 : 0 : PropertySetContainer::release();
101 : 0 : }
102 : :
103 : : // XMultiServiceFactory
104 : 0 : Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstance( const ::rtl::OUString& aServiceSpecifier )
105 : : throw ( Exception, RuntimeException )
106 : : {
107 [ # # ]: 0 : if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
108 [ # # ][ # # ]: 0 : return (OWeakObject *)( new ActionTriggerPropertySet( m_xServiceManager ));
109 [ # # ]: 0 : else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
110 [ # # ][ # # ]: 0 : return (OWeakObject *)( new ActionTriggerContainer( m_xServiceManager ));
111 [ # # ]: 0 : else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR ))
112 [ # # ][ # # ]: 0 : return (OWeakObject *)( new ActionTriggerSeparatorPropertySet( m_xServiceManager ));
113 : : else
114 [ # # ][ # # ]: 0 : throw com::sun::star::uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown service specifier!" )), (OWeakObject *)this );
[ # # ]
115 : : }
116 : :
117 : 0 : Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ )
118 : : throw ( Exception, RuntimeException )
119 : : {
120 : 0 : return createInstance( ServiceSpecifier );
121 : : }
122 : :
123 : 0 : Sequence< ::rtl::OUString > SAL_CALL RootActionTriggerContainer::getAvailableServiceNames()
124 : : throw ( RuntimeException )
125 : : {
126 : 0 : Sequence< ::rtl::OUString > aSeq( 3 );
127 : :
128 [ # # ][ # # ]: 0 : aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
129 [ # # ][ # # ]: 0 : aSeq[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
130 [ # # ][ # # ]: 0 : aSeq[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR ));
131 : :
132 : 0 : return aSeq;
133 : : }
134 : :
135 : :
136 : : // XIndexContainer
137 : 0 : void SAL_CALL RootActionTriggerContainer::insertByIndex( sal_Int32 Index, const Any& Element )
138 : : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
139 : : {
140 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
141 : :
142 [ # # ]: 0 : if ( !m_bContainerCreated )
143 [ # # ]: 0 : FillContainer();
144 : :
145 [ # # ]: 0 : if ( !m_bInContainerCreation )
146 : 0 : m_bContainerChanged = sal_True;
147 [ # # ][ # # ]: 0 : PropertySetContainer::insertByIndex( Index, Element );
148 : 0 : }
149 : :
150 : 0 : void SAL_CALL RootActionTriggerContainer::removeByIndex( sal_Int32 Index )
151 : : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
152 : : {
153 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
154 : :
155 [ # # ]: 0 : if ( !m_bContainerCreated )
156 [ # # ]: 0 : FillContainer();
157 : :
158 [ # # ]: 0 : if ( !m_bInContainerCreation )
159 : 0 : m_bContainerChanged = sal_True;
160 [ # # ][ # # ]: 0 : PropertySetContainer::removeByIndex( Index );
161 : 0 : }
162 : :
163 : :
164 : : // XIndexReplace
165 : 0 : void SAL_CALL RootActionTriggerContainer::replaceByIndex( sal_Int32 Index, const Any& Element )
166 : : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
167 : : {
168 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
169 : :
170 [ # # ]: 0 : if ( !m_bContainerCreated )
171 [ # # ]: 0 : FillContainer();
172 : :
173 [ # # ]: 0 : if ( !m_bInContainerCreation )
174 : 0 : m_bContainerChanged = sal_True;
175 [ # # ][ # # ]: 0 : PropertySetContainer::replaceByIndex( Index, Element );
176 : 0 : }
177 : :
178 : :
179 : : // XIndexAccess
180 : 0 : sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
181 : : throw ( RuntimeException )
182 : : {
183 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
184 : :
185 [ # # ]: 0 : if ( !m_bContainerCreated )
186 : : {
187 [ # # ]: 0 : if ( m_pMenu )
188 : : {
189 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
190 [ # # ][ # # ]: 0 : return m_pMenu->GetItemCount();
191 : : }
192 : : else
193 : 0 : return 0;
194 : : }
195 : : else
196 : : {
197 [ # # ]: 0 : return PropertySetContainer::getCount();
198 [ # # ]: 0 : }
199 : : }
200 : :
201 : 0 : Any SAL_CALL RootActionTriggerContainer::getByIndex( sal_Int32 Index )
202 : : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
203 : : {
204 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
205 : :
206 [ # # ]: 0 : if ( !m_bContainerCreated )
207 [ # # ]: 0 : FillContainer();
208 : :
209 [ # # ][ # # ]: 0 : return PropertySetContainer::getByIndex( Index );
210 : : }
211 : :
212 : :
213 : : // XElementAccess
214 : 0 : Type SAL_CALL RootActionTriggerContainer::getElementType()
215 : : throw (::com::sun::star::uno::RuntimeException)
216 : : {
217 : 0 : return ::getCppuType(( Reference< XPropertySet >*)0);
218 : : }
219 : :
220 : 0 : sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
221 : : throw (::com::sun::star::uno::RuntimeException)
222 : : {
223 [ # # ]: 0 : if ( m_pMenu )
224 : : {
225 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
226 [ # # ][ # # ]: 0 : return ( m_pMenu->GetItemCount() > 0 );
227 : : }
228 : :
229 : 0 : return sal_False;
230 : : }
231 : :
232 : :
233 : : // XServiceInfo
234 : 0 : ::rtl::OUString SAL_CALL RootActionTriggerContainer::getImplementationName()
235 : : throw ( RuntimeException )
236 : : {
237 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER ));
238 : : }
239 : :
240 : 0 : sal_Bool SAL_CALL RootActionTriggerContainer::supportsService( const ::rtl::OUString& ServiceName )
241 : : throw ( RuntimeException )
242 : : {
243 [ # # ]: 0 : if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
244 : 0 : return sal_True;
245 : :
246 : 0 : return sal_False;
247 : : }
248 : :
249 : 0 : Sequence< ::rtl::OUString > SAL_CALL RootActionTriggerContainer::getSupportedServiceNames()
250 : : throw ( RuntimeException )
251 : : {
252 : 0 : Sequence< ::rtl::OUString > seqServiceNames( 1 );
253 : :
254 [ # # ][ # # ]: 0 : seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
255 : 0 : return seqServiceNames;
256 : : }
257 : :
258 : : // XUnoTunnel
259 : 0 : sal_Int64 SAL_CALL RootActionTriggerContainer::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw ( RuntimeException )
260 : : {
261 [ # # ][ # # ]: 0 : if ( aIdentifier == impl_getStaticIdentifier() )
262 : 0 : return reinterpret_cast< sal_Int64 >( this );
263 : : else
264 : 0 : return 0;
265 : : }
266 : :
267 : : // XTypeProvider
268 : 0 : Sequence< Type > SAL_CALL RootActionTriggerContainer::getTypes() throw ( RuntimeException )
269 : : {
270 : : // Optimize this method !
271 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
272 : : // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
273 : : static ::cppu::OTypeCollection* pTypeCollection = NULL ;
274 : :
275 [ # # ]: 0 : if ( pTypeCollection == NULL )
276 : : {
277 : : // Ready for multithreading; get global mutex for first call of this method only! see before
278 [ # # ][ # # ]: 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
279 : :
280 : : // Control these pointer again ... it can be, that another instance will be faster then these!
281 [ # # ]: 0 : if ( pTypeCollection == NULL )
282 : : {
283 : : // Create a static typecollection ...
284 : : static ::cppu::OTypeCollection aTypeCollection(
285 [ # # ]: 0 : ::getCppuType(( const Reference< XMultiServiceFactory >*)NULL ) ,
286 [ # # ]: 0 : ::getCppuType(( const Reference< XIndexContainer >*)NULL ) ,
287 [ # # ]: 0 : ::getCppuType(( const Reference< XIndexAccess >*)NULL ) ,
288 [ # # ]: 0 : ::getCppuType(( const Reference< XIndexReplace >*)NULL ) ,
289 [ # # ]: 0 : ::getCppuType(( const Reference< XServiceInfo >*)NULL ) ,
290 [ # # ]: 0 : ::getCppuType(( const Reference< XTypeProvider >*)NULL ) ,
291 [ # # ]: 0 : ::getCppuType(( const Reference< XUnoTunnel >*)NULL ) ,
292 [ # # ][ # # ]: 0 : ::getCppuType(( const Reference< XNamed >*)NULL )) ;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
293 : :
294 : : // ... and set his address to static pointer!
295 : 0 : pTypeCollection = &aTypeCollection ;
296 [ # # ]: 0 : }
297 : : }
298 : :
299 : 0 : return pTypeCollection->getTypes() ;
300 : : }
301 : :
302 : 0 : Sequence< sal_Int8 > SAL_CALL RootActionTriggerContainer::getImplementationId() throw ( RuntimeException )
303 : : {
304 : : // Create one Id for all instances of this class.
305 : : // Use ethernet address to do this! (sal_True)
306 : :
307 : : // Optimize this method
308 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
309 : : // For the first call; pID is NULL - for the second call pID is different from NULL!
310 : : static ::cppu::OImplementationId* pID = NULL ;
311 : :
312 [ # # ]: 0 : if ( pID == NULL )
313 : : {
314 : : // Ready for multithreading; get global mutex for first call of this method only! see before
315 [ # # ][ # # ]: 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
316 : :
317 : : // Control these pointer again ... it can be, that another instance will be faster then these!
318 [ # # ]: 0 : if ( pID == NULL )
319 : : {
320 : : // Create a new static ID ...
321 [ # # ][ # # ]: 0 : static ::cppu::OImplementationId aID( sal_False ) ;
322 : : // ... and set his address to static pointer!
323 : 0 : pID = &aID ;
324 [ # # ]: 0 : }
325 : : }
326 : :
327 : 0 : return pID->getImplementationId() ;
328 : : }
329 : :
330 : : // private implementation helper
331 : 0 : void RootActionTriggerContainer::FillContainer()
332 : : {
333 : 0 : m_bContainerCreated = sal_True;
334 : 0 : m_bInContainerCreation = sal_True;
335 [ # # ]: 0 : Reference<XIndexContainer> xXIndexContainer( (OWeakObject *)this, UNO_QUERY );
336 : : ActionTriggerHelper::FillActionTriggerContainerFromMenu(
337 : : xXIndexContainer,
338 [ # # ]: 0 : m_pMenu );
339 : 0 : m_bInContainerCreation = sal_False;
340 : 0 : }
341 : 0 : ::rtl::OUString RootActionTriggerContainer::getName() throw ( RuntimeException )
342 : : {
343 : 0 : ::rtl::OUString sRet;
344 [ # # ]: 0 : if( m_pMenuIdentifier )
345 : 0 : sRet = *m_pMenuIdentifier;
346 : 0 : return sRet;
347 : : }
348 : :
349 : 0 : void RootActionTriggerContainer::setName( const ::rtl::OUString& ) throw ( RuntimeException)
350 : : {
351 [ # # ]: 0 : throw RuntimeException();
352 : : }
353 : : }
354 : :
355 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|