1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <classes/rootactiontriggercontainer.hxx>
22 #include <classes/actiontriggercontainer.hxx>
23 #include <classes/actiontriggerpropertyset.hxx>
24 #include <classes/actiontriggerseparatorpropertyset.hxx>
25 #include <framework/actiontriggerhelper.hxx>
26 #include <threadhelp/resetableguard.hxx>
27 #include <osl/mutex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <cppuhelper/typeprovider.hxx>
33 using namespace com::sun::star::uno
;
34 using namespace com::sun::star::lang
;
35 using namespace com::sun::star::container
;
36 using namespace com::sun::star::beans
;
42 static Sequence
< sal_Int8
> impl_getStaticIdentifier()
44 static sal_uInt8 pGUID
[16] = { 0x17, 0x0F, 0xA2, 0xC9, 0xCA, 0x50, 0x4A, 0xD3, 0xA6, 0x3B, 0x39, 0x99, 0xC5, 0x96, 0x43, 0x27 };
45 static ::com::sun::star::uno::Sequence
< sal_Int8
> seqID((sal_Int8
*)pGUID
,16) ;
50 RootActionTriggerContainer::RootActionTriggerContainer( const Menu
* pMenu
, const OUString
* pMenuIdentifier
) :
51 PropertySetContainer()
52 , m_bContainerCreated( sal_False
)
53 , m_bContainerChanged( sal_False
)
54 , m_bInContainerCreation( sal_False
)
56 , m_pMenuIdentifier( pMenuIdentifier
)
60 RootActionTriggerContainer::~RootActionTriggerContainer()
65 Any SAL_CALL
RootActionTriggerContainer::queryInterface( const Type
& aType
)
66 throw ( RuntimeException
)
68 Any a
= ::cppu::queryInterface(
70 (static_cast< XMultiServiceFactory
* >(this)),
71 (static_cast< XServiceInfo
* >(this)),
72 (static_cast< XUnoTunnel
* >(this)),
73 (static_cast< XTypeProvider
* >(this)),
74 (static_cast< XNamed
* >(this)));
81 return PropertySetContainer::queryInterface( aType
);
84 void SAL_CALL
RootActionTriggerContainer::acquire() throw ()
86 PropertySetContainer::acquire();
89 void SAL_CALL
RootActionTriggerContainer::release() throw ()
91 PropertySetContainer::release();
94 // XMultiServiceFactory
95 Reference
< XInterface
> SAL_CALL
RootActionTriggerContainer::createInstance( const OUString
& aServiceSpecifier
)
96 throw ( Exception
, RuntimeException
)
98 if ( aServiceSpecifier
.equalsAscii( SERVICENAME_ACTIONTRIGGER
))
99 return (OWeakObject
*)( new ActionTriggerPropertySet());
100 else if ( aServiceSpecifier
.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER
))
101 return (OWeakObject
*)( new ActionTriggerContainer());
102 else if ( aServiceSpecifier
.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR
))
103 return (OWeakObject
*)( new ActionTriggerSeparatorPropertySet());
105 throw com::sun::star::uno::RuntimeException( OUString( "Unknown service specifier!" ), (OWeakObject
*)this );
108 Reference
< XInterface
> SAL_CALL
RootActionTriggerContainer::createInstanceWithArguments( const OUString
& ServiceSpecifier
, const Sequence
< Any
>& /*Arguments*/ )
109 throw ( Exception
, RuntimeException
)
111 return createInstance( ServiceSpecifier
);
114 Sequence
< OUString
> SAL_CALL
RootActionTriggerContainer::getAvailableServiceNames()
115 throw ( RuntimeException
)
117 Sequence
< OUString
> aSeq( 3 );
119 aSeq
[0] = OUString( SERVICENAME_ACTIONTRIGGER
);
120 aSeq
[1] = OUString( SERVICENAME_ACTIONTRIGGERCONTAINER
);
121 aSeq
[2] = OUString( SERVICENAME_ACTIONTRIGGERSEPARATOR
);
128 void SAL_CALL
RootActionTriggerContainer::insertByIndex( sal_Int32 Index
, const Any
& Element
)
129 throw ( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
131 ResetableGuard
aGuard( m_aLock
);
133 if ( !m_bContainerCreated
)
136 if ( !m_bInContainerCreation
)
137 m_bContainerChanged
= sal_True
;
138 PropertySetContainer::insertByIndex( Index
, Element
);
141 void SAL_CALL
RootActionTriggerContainer::removeByIndex( sal_Int32 Index
)
142 throw ( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
144 ResetableGuard
aGuard( m_aLock
);
146 if ( !m_bContainerCreated
)
149 if ( !m_bInContainerCreation
)
150 m_bContainerChanged
= sal_True
;
151 PropertySetContainer::removeByIndex( Index
);
156 void SAL_CALL
RootActionTriggerContainer::replaceByIndex( sal_Int32 Index
, const Any
& Element
)
157 throw ( IllegalArgumentException
, IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
159 ResetableGuard
aGuard( m_aLock
);
161 if ( !m_bContainerCreated
)
164 if ( !m_bInContainerCreation
)
165 m_bContainerChanged
= sal_True
;
166 PropertySetContainer::replaceByIndex( Index
, Element
);
171 sal_Int32 SAL_CALL
RootActionTriggerContainer::getCount()
172 throw ( RuntimeException
)
174 ResetableGuard
aGuard( m_aLock
);
176 if ( !m_bContainerCreated
)
180 SolarMutexGuard aSolarMutexGuard
;
181 return m_pMenu
->GetItemCount();
188 return PropertySetContainer::getCount();
192 Any SAL_CALL
RootActionTriggerContainer::getByIndex( sal_Int32 Index
)
193 throw ( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
195 ResetableGuard
aGuard( m_aLock
);
197 if ( !m_bContainerCreated
)
200 return PropertySetContainer::getByIndex( Index
);
205 Type SAL_CALL
RootActionTriggerContainer::getElementType()
206 throw (::com::sun::star::uno::RuntimeException
)
208 return ::getCppuType(( Reference
< XPropertySet
>*)0);
211 sal_Bool SAL_CALL
RootActionTriggerContainer::hasElements()
212 throw (::com::sun::star::uno::RuntimeException
)
216 SolarMutexGuard aSolarMutexGuard
;
217 return ( m_pMenu
->GetItemCount() > 0 );
225 OUString SAL_CALL
RootActionTriggerContainer::getImplementationName()
226 throw ( RuntimeException
)
228 return OUString( IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER
);
231 sal_Bool SAL_CALL
RootActionTriggerContainer::supportsService( const OUString
& ServiceName
)
232 throw ( RuntimeException
)
234 if ( ServiceName
.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER
))
240 Sequence
< OUString
> SAL_CALL
RootActionTriggerContainer::getSupportedServiceNames()
241 throw ( RuntimeException
)
243 Sequence
< OUString
> seqServiceNames( 1 );
245 seqServiceNames
[0] = OUString( SERVICENAME_ACTIONTRIGGERCONTAINER
);
246 return seqServiceNames
;
250 sal_Int64 SAL_CALL
RootActionTriggerContainer::getSomething( const Sequence
< sal_Int8
>& aIdentifier
) throw ( RuntimeException
)
252 if ( aIdentifier
== impl_getStaticIdentifier() )
253 return reinterpret_cast< sal_Int64
>( this );
259 Sequence
< Type
> SAL_CALL
RootActionTriggerContainer::getTypes() throw ( RuntimeException
)
261 // Optimize this method !
262 // We initialize a static variable only one time. And we don't must use a mutex at every call!
263 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
264 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
266 if ( pTypeCollection
== NULL
)
268 // Ready for multithreading; get global mutex for first call of this method only! see before
269 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
271 // Control these pointer again ... it can be, that another instance will be faster then these!
272 if ( pTypeCollection
== NULL
)
274 // Create a static typecollection ...
275 static ::cppu::OTypeCollection
aTypeCollection(
276 ::getCppuType(( const Reference
< XMultiServiceFactory
>*)NULL
) ,
277 ::getCppuType(( const Reference
< XIndexContainer
>*)NULL
) ,
278 ::getCppuType(( const Reference
< XServiceInfo
>*)NULL
) ,
279 ::getCppuType(( const Reference
< XTypeProvider
>*)NULL
) ,
280 ::getCppuType(( const Reference
< XUnoTunnel
>*)NULL
) ,
281 ::getCppuType(( const Reference
< XNamed
>*)NULL
)) ;
283 // ... and set his address to static pointer!
284 pTypeCollection
= &aTypeCollection
;
288 return pTypeCollection
->getTypes() ;
291 Sequence
< sal_Int8
> SAL_CALL
RootActionTriggerContainer::getImplementationId() throw ( RuntimeException
)
293 // Create one Id for all instances of this class.
294 // Use ethernet address to do this! (sal_True)
296 // Optimize this method
297 // We initialize a static variable only one time. And we don't must use a mutex at every call!
298 // For the first call; pID is NULL - for the second call pID is different from NULL!
299 static ::cppu::OImplementationId
* pID
= NULL
;
303 // Ready for multithreading; get global mutex for first call of this method only! see before
304 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
306 // Control these pointer again ... it can be, that another instance will be faster then these!
309 // Create a new static ID ...
310 static ::cppu::OImplementationId
aID( sal_False
) ;
311 // ... and set his address to static pointer!
316 return pID
->getImplementationId() ;
319 // private implementation helper
320 void RootActionTriggerContainer::FillContainer()
322 m_bContainerCreated
= sal_True
;
323 m_bInContainerCreation
= sal_True
;
324 Reference
<XIndexContainer
> xXIndexContainer( (OWeakObject
*)this, UNO_QUERY
);
325 ActionTriggerHelper::FillActionTriggerContainerFromMenu(
328 m_bInContainerCreation
= sal_False
;
330 OUString
RootActionTriggerContainer::getName() throw ( RuntimeException
)
333 if( m_pMenuIdentifier
)
334 sRet
= *m_pMenuIdentifier
;
338 void RootActionTriggerContainer::setName( const OUString
& ) throw ( RuntimeException
)
340 throw RuntimeException();
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */