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 $
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>
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
;
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) ;
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
)
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
)
88 ResetableGuard
aGuard( m_aLock
);
90 Menu
* pNewMenu
= new PopupMenu
;
92 ActionTriggerHelper::CreateMenuFromActionTriggerContainer( pNewMenu
, this );
94 m_bContainerChanged
= sal_False
;
102 Any SAL_CALL
RootActionTriggerContainer::queryInterface( const Type
& aType
)
103 throw ( RuntimeException
)
105 Any a
= ::cppu::queryInterface(
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 ));
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
));
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
));
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
)
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
)
186 if ( !m_bInContainerCreation
)
187 m_bContainerChanged
= sal_True
;
188 PropertySetContainer::removeByIndex( Index
);
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
)
201 if ( !m_bInContainerCreation
)
202 m_bContainerChanged
= sal_True
;
203 PropertySetContainer::replaceByIndex( Index
, Element
);
208 sal_Int32 SAL_CALL
RootActionTriggerContainer::getCount()
209 throw ( RuntimeException
)
211 ResetableGuard
aGuard( m_aLock
);
213 if ( !m_bContainerCreated
)
217 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
218 return m_pMenu
->GetItemCount();
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
)
237 return PropertySetContainer::getByIndex( Index
);
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
)
253 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
254 return ( m_pMenu
->GetItemCount() > 0 );
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
))
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
;
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 );
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
;
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!
348 // Create a new static ID ...
349 static ::cppu::OImplementationId
aID( sal_False
) ;
350 // ... and set his address to static pointer!
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(
367 m_bInContainerCreation
= sal_False
;
369 ::rtl::OUString
RootActionTriggerContainer::getName() throw ( RuntimeException
)
371 ::rtl::OUString sRet
;
372 if( m_pMenuIdentifier
)
373 sRet
= *m_pMenuIdentifier
;
377 void RootActionTriggerContainer::setName( const ::rtl::OUString
& ) throw ( RuntimeException
)
379 throw RuntimeException();