Update ooo320-m1
[ooovba.git] / framework / source / classes / rootactiontriggercontainer.cxx
blob7e18782300274b74243cbe34a39d9ec30e6ddf91
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rootactiontriggercontainer.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include <classes/rootactiontriggercontainer.hxx>
35 #include <classes/actiontriggercontainer.hxx>
36 #include <classes/actiontriggerpropertyset.hxx>
37 #include <classes/actiontriggerseparatorpropertyset.hxx>
38 #include <helper/actiontriggerhelper.hxx>
39 #include <threadhelp/resetableguard.hxx>
40 #include <osl/mutex.hxx>
41 #include <vcl/svapp.hxx>
42 #include <cppuhelper/typeprovider.hxx>
45 using namespace cppu;
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::lang;
48 using namespace com::sun::star::container;
49 using namespace com::sun::star::beans;
52 namespace framework
55 static Sequence< sal_Int8 > impl_getStaticIdentifier()
57 static sal_uInt8 pGUID[16] = { 0x17, 0x0F, 0xA2, 0xC9, 0xCA, 0x50, 0x4A, 0xD3, 0xA6, 0x3B, 0x39, 0x99, 0xC5, 0x96, 0x43, 0x27 };
58 static ::com::sun::star::uno::Sequence< sal_Int8 > seqID((sal_Int8*)pGUID,16) ;
59 return seqID ;
63 RootActionTriggerContainer::RootActionTriggerContainer( const Menu* pMenu, const ::rtl::OUString* pMenuIdentifier, const Reference< XMultiServiceFactory >& rServiceManager ) :
64 PropertySetContainer( rServiceManager )
65 , m_bContainerCreated( sal_False )
66 , m_bContainerChanged( sal_False )
67 , m_bInContainerCreation( sal_False )
68 , m_pMenu( pMenu )
69 , m_pMenuIdentifier( pMenuIdentifier )
73 RootActionTriggerContainer::~RootActionTriggerContainer()
77 Sequence< sal_Int8 > RootActionTriggerContainer::GetUnoTunnelId() const
79 return impl_getStaticIdentifier();
82 const Menu* RootActionTriggerContainer::GetMenu()
84 if ( !m_bContainerChanged )
85 return m_pMenu;
86 else
88 ResetableGuard aGuard( m_aLock );
90 Menu* pNewMenu = new PopupMenu;
92 ActionTriggerHelper::CreateMenuFromActionTriggerContainer( pNewMenu, this );
93 m_pMenu = pNewMenu;
94 m_bContainerChanged = sal_False;
96 return m_pMenu;
101 // XInterface
102 Any SAL_CALL RootActionTriggerContainer::queryInterface( const Type& aType )
103 throw ( RuntimeException )
105 Any a = ::cppu::queryInterface(
106 aType ,
107 SAL_STATIC_CAST( XMultiServiceFactory* , this ),
108 SAL_STATIC_CAST( XServiceInfo* , this ),
109 SAL_STATIC_CAST( XUnoTunnel* , this ),
110 SAL_STATIC_CAST( XTypeProvider* , this ),
111 SAL_STATIC_CAST( XNamed* , this ));
113 if( a.hasValue() )
115 return a;
118 return PropertySetContainer::queryInterface( aType );
121 void SAL_CALL RootActionTriggerContainer::acquire() throw ()
123 PropertySetContainer::acquire();
126 void SAL_CALL RootActionTriggerContainer::release() throw ()
128 PropertySetContainer::release();
131 // XMultiServiceFactory
132 Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstance( const ::rtl::OUString& aServiceSpecifier )
133 throw ( Exception, RuntimeException )
135 if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
136 return (OWeakObject *)( new ActionTriggerPropertySet( m_xServiceManager ));
137 else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
138 return (OWeakObject *)( new ActionTriggerContainer( m_xServiceManager ));
139 else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR ))
140 return (OWeakObject *)( new ActionTriggerSeparatorPropertySet( m_xServiceManager ));
141 else
142 throw com::sun::star::uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown service specifier!" )), (OWeakObject *)this );
145 Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ )
146 throw ( Exception, RuntimeException )
148 return createInstance( ServiceSpecifier );
151 Sequence< ::rtl::OUString > SAL_CALL RootActionTriggerContainer::getAvailableServiceNames()
152 throw ( RuntimeException )
154 Sequence< ::rtl::OUString > aSeq( 3 );
156 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
157 aSeq[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
158 aSeq[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR ));
160 return aSeq;
164 // XIndexContainer
165 void SAL_CALL RootActionTriggerContainer::insertByIndex( sal_Int32 Index, const Any& Element )
166 throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
168 ResetableGuard aGuard( m_aLock );
170 if ( !m_bContainerCreated )
171 FillContainer();
173 if ( !m_bInContainerCreation )
174 m_bContainerChanged = sal_True;
175 PropertySetContainer::insertByIndex( Index, Element );
178 void SAL_CALL RootActionTriggerContainer::removeByIndex( sal_Int32 Index )
179 throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
181 ResetableGuard aGuard( m_aLock );
183 if ( !m_bContainerCreated )
184 FillContainer();
186 if ( !m_bInContainerCreation )
187 m_bContainerChanged = sal_True;
188 PropertySetContainer::removeByIndex( Index );
192 // XIndexReplace
193 void SAL_CALL RootActionTriggerContainer::replaceByIndex( sal_Int32 Index, const Any& Element )
194 throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
196 ResetableGuard aGuard( m_aLock );
198 if ( !m_bContainerCreated )
199 FillContainer();
201 if ( !m_bInContainerCreation )
202 m_bContainerChanged = sal_True;
203 PropertySetContainer::replaceByIndex( Index, Element );
207 // XIndexAccess
208 sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
209 throw ( RuntimeException )
211 ResetableGuard aGuard( m_aLock );
213 if ( !m_bContainerCreated )
215 if ( m_pMenu )
217 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
218 return m_pMenu->GetItemCount();
220 else
221 return 0;
223 else
225 return PropertySetContainer::getCount();
229 Any SAL_CALL RootActionTriggerContainer::getByIndex( sal_Int32 Index )
230 throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
232 ResetableGuard aGuard( m_aLock );
234 if ( !m_bContainerCreated )
235 FillContainer();
237 return PropertySetContainer::getByIndex( Index );
241 // XElementAccess
242 Type SAL_CALL RootActionTriggerContainer::getElementType()
243 throw (::com::sun::star::uno::RuntimeException)
245 return ::getCppuType(( Reference< XPropertySet >*)0);
248 sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
249 throw (::com::sun::star::uno::RuntimeException)
251 if ( m_pMenu )
253 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
254 return ( m_pMenu->GetItemCount() > 0 );
257 return sal_False;
261 // XServiceInfo
262 ::rtl::OUString SAL_CALL RootActionTriggerContainer::getImplementationName()
263 throw ( RuntimeException )
265 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER ));
268 sal_Bool SAL_CALL RootActionTriggerContainer::supportsService( const ::rtl::OUString& ServiceName )
269 throw ( RuntimeException )
271 if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
272 return sal_True;
274 return sal_False;
277 Sequence< ::rtl::OUString > SAL_CALL RootActionTriggerContainer::getSupportedServiceNames()
278 throw ( RuntimeException )
280 Sequence< ::rtl::OUString > seqServiceNames( 1 );
282 seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
283 return seqServiceNames;
286 // XUnoTunnel
287 sal_Int64 SAL_CALL RootActionTriggerContainer::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw ( RuntimeException )
289 if ( aIdentifier == impl_getStaticIdentifier() )
290 return reinterpret_cast< sal_Int64 >( this );
291 else
292 return 0;
295 // XTypeProvider
296 Sequence< Type > SAL_CALL RootActionTriggerContainer::getTypes() throw ( RuntimeException )
298 // Optimize this method !
299 // We initialize a static variable only one time. And we don't must use a mutex at every call!
300 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
301 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
303 if ( pTypeCollection == NULL )
305 // Ready for multithreading; get global mutex for first call of this method only! see before
306 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
308 // Control these pointer again ... it can be, that another instance will be faster then these!
309 if ( pTypeCollection == NULL )
311 // Create a static typecollection ...
312 static ::cppu::OTypeCollection aTypeCollection(
313 ::getCppuType(( const Reference< XMultiServiceFactory >*)NULL ) ,
314 ::getCppuType(( const Reference< XIndexContainer >*)NULL ) ,
315 ::getCppuType(( const Reference< XIndexAccess >*)NULL ) ,
316 ::getCppuType(( const Reference< XIndexReplace >*)NULL ) ,
317 ::getCppuType(( const Reference< XServiceInfo >*)NULL ) ,
318 ::getCppuType(( const Reference< XTypeProvider >*)NULL ) ,
319 ::getCppuType(( const Reference< XUnoTunnel >*)NULL ) ,
320 ::getCppuType(( const Reference< XNamed >*)NULL )) ;
322 // ... and set his address to static pointer!
323 pTypeCollection = &aTypeCollection ;
327 return pTypeCollection->getTypes() ;
330 Sequence< sal_Int8 > SAL_CALL RootActionTriggerContainer::getImplementationId() throw ( RuntimeException )
332 // Create one Id for all instances of this class.
333 // Use ethernet address to do this! (sal_True)
335 // Optimize this method
336 // We initialize a static variable only one time. And we don't must use a mutex at every call!
337 // For the first call; pID is NULL - for the second call pID is different from NULL!
338 static ::cppu::OImplementationId* pID = NULL ;
340 if ( pID == NULL )
342 // Ready for multithreading; get global mutex for first call of this method only! see before
343 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
345 // Control these pointer again ... it can be, that another instance will be faster then these!
346 if ( pID == NULL )
348 // Create a new static ID ...
349 static ::cppu::OImplementationId aID( sal_False ) ;
350 // ... and set his address to static pointer!
351 pID = &aID ;
355 return pID->getImplementationId() ;
358 // private implementation helper
359 void RootActionTriggerContainer::FillContainer()
361 m_bContainerCreated = sal_True;
362 m_bInContainerCreation = sal_True;
363 Reference<XIndexContainer> xXIndexContainer( (OWeakObject *)this, UNO_QUERY );
364 ActionTriggerHelper::FillActionTriggerContainerFromMenu(
365 xXIndexContainer,
366 m_pMenu );
367 m_bInContainerCreation = sal_False;
369 ::rtl::OUString RootActionTriggerContainer::getName() throw ( RuntimeException )
371 ::rtl::OUString sRet;
372 if( m_pMenuIdentifier )
373 sRet = *m_pMenuIdentifier;
374 return sRet;
377 void RootActionTriggerContainer::setName( const ::rtl::OUString& ) throw ( RuntimeException)
379 throw RuntimeException();