fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwe / classes / rootactiontriggercontainer.cxx
blob18cae1562ed8eeceb2c0320d8c4875096ce528cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <classes/rootactiontriggercontainer.hxx>
21 #include <classes/actiontriggercontainer.hxx>
22 #include <classes/actiontriggerpropertyset.hxx>
23 #include <classes/actiontriggerseparatorpropertyset.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <cppuhelper/queryinterface.hxx>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <framework/actiontriggerhelper.hxx>
28 #include <osl/mutex.hxx>
29 #include <vcl/svapp.hxx>
31 using namespace cppu;
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::lang;
34 using namespace com::sun::star::container;
35 using namespace com::sun::star::beans;
37 namespace framework
40 static Sequence< sal_Int8 > impl_getStaticIdentifier()
42 static const sal_uInt8 pGUID[16] = { 0x17, 0x0F, 0xA2, 0xC9, 0xCA, 0x50, 0x4A, 0xD3, 0xA6, 0x3B, 0x39, 0x99, 0xC5, 0x96, 0x43, 0x27 };
43 static ::com::sun::star::uno::Sequence< sal_Int8 > seqID(reinterpret_cast<const sal_Int8*>(pGUID), 16);
44 return seqID;
47 RootActionTriggerContainer::RootActionTriggerContainer( const Menu* pMenu, const OUString* pMenuIdentifier ) :
48 PropertySetContainer()
49 , m_bContainerCreated( false )
50 , m_bContainerChanged( false )
51 , m_bInContainerCreation( false )
52 , m_pMenu( pMenu )
53 , m_pMenuIdentifier( pMenuIdentifier )
57 RootActionTriggerContainer::~RootActionTriggerContainer()
61 // XInterface
62 Any SAL_CALL RootActionTriggerContainer::queryInterface( const Type& aType )
63 throw ( RuntimeException, std::exception )
65 Any a = ::cppu::queryInterface(
66 aType ,
67 (static_cast< XMultiServiceFactory* >(this)),
68 (static_cast< XServiceInfo* >(this)),
69 (static_cast< XUnoTunnel* >(this)),
70 (static_cast< XTypeProvider* >(this)),
71 (static_cast< XNamed* >(this)));
73 if( a.hasValue() )
75 return a;
78 return PropertySetContainer::queryInterface( aType );
81 void SAL_CALL RootActionTriggerContainer::acquire() throw ()
83 PropertySetContainer::acquire();
86 void SAL_CALL RootActionTriggerContainer::release() throw ()
88 PropertySetContainer::release();
91 // XMultiServiceFactory
92 Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstance( const OUString& aServiceSpecifier )
93 throw ( Exception, RuntimeException, std::exception )
95 if ( aServiceSpecifier == SERVICENAME_ACTIONTRIGGER )
96 return (OWeakObject *)( new ActionTriggerPropertySet());
97 else if ( aServiceSpecifier == SERVICENAME_ACTIONTRIGGERCONTAINER )
98 return (OWeakObject *)( new ActionTriggerContainer());
99 else if ( aServiceSpecifier == SERVICENAME_ACTIONTRIGGERSEPARATOR )
100 return (OWeakObject *)( new ActionTriggerSeparatorPropertySet());
101 else
102 throw com::sun::star::uno::RuntimeException("Unknown service specifier!", (OWeakObject *)this );
105 Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstanceWithArguments( const OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ )
106 throw ( Exception, RuntimeException, std::exception )
108 return createInstance( ServiceSpecifier );
111 Sequence< OUString > SAL_CALL RootActionTriggerContainer::getAvailableServiceNames()
112 throw ( RuntimeException, std::exception )
114 Sequence< OUString > aSeq( 3 );
116 aSeq[0] = SERVICENAME_ACTIONTRIGGER;
117 aSeq[1] = SERVICENAME_ACTIONTRIGGERCONTAINER;
118 aSeq[2] = SERVICENAME_ACTIONTRIGGERSEPARATOR;
120 return aSeq;
123 // XIndexContainer
124 void SAL_CALL RootActionTriggerContainer::insertByIndex( sal_Int32 Index, const Any& Element )
125 throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
127 SolarMutexGuard g;
129 if ( !m_bContainerCreated )
130 FillContainer();
132 if ( !m_bInContainerCreation )
133 m_bContainerChanged = true;
134 PropertySetContainer::insertByIndex( Index, Element );
137 void SAL_CALL RootActionTriggerContainer::removeByIndex( sal_Int32 Index )
138 throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
140 SolarMutexGuard g;
142 if ( !m_bContainerCreated )
143 FillContainer();
145 if ( !m_bInContainerCreation )
146 m_bContainerChanged = true;
147 PropertySetContainer::removeByIndex( Index );
150 // XIndexReplace
151 void SAL_CALL RootActionTriggerContainer::replaceByIndex( sal_Int32 Index, const Any& Element )
152 throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
154 SolarMutexGuard g;
156 if ( !m_bContainerCreated )
157 FillContainer();
159 if ( !m_bInContainerCreation )
160 m_bContainerChanged = true;
161 PropertySetContainer::replaceByIndex( Index, Element );
164 // XIndexAccess
165 sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
166 throw ( RuntimeException, std::exception )
168 SolarMutexGuard g;
170 if ( !m_bContainerCreated )
172 if ( m_pMenu )
174 SolarMutexGuard aSolarMutexGuard;
175 return m_pMenu->GetItemCount();
177 else
178 return 0;
180 else
182 return PropertySetContainer::getCount();
186 Any SAL_CALL RootActionTriggerContainer::getByIndex( sal_Int32 Index )
187 throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception )
189 SolarMutexGuard g;
191 if ( !m_bContainerCreated )
192 FillContainer();
194 return PropertySetContainer::getByIndex( Index );
197 // XElementAccess
198 Type SAL_CALL RootActionTriggerContainer::getElementType()
199 throw (::com::sun::star::uno::RuntimeException, std::exception)
201 return cppu::UnoType<XPropertySet>::get();
204 sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
205 throw (::com::sun::star::uno::RuntimeException, std::exception)
207 if ( m_pMenu )
209 SolarMutexGuard aSolarMutexGuard;
210 return ( m_pMenu->GetItemCount() > 0 );
213 return sal_False;
216 // XServiceInfo
217 OUString SAL_CALL RootActionTriggerContainer::getImplementationName()
218 throw ( RuntimeException, std::exception )
220 return OUString( IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER );
223 sal_Bool SAL_CALL RootActionTriggerContainer::supportsService( const OUString& ServiceName )
224 throw ( RuntimeException, std::exception )
226 return cppu::supportsService(this, ServiceName);
229 Sequence< OUString > SAL_CALL RootActionTriggerContainer::getSupportedServiceNames()
230 throw ( RuntimeException, std::exception )
232 Sequence< OUString > seqServiceNames( 1 );
234 seqServiceNames[0] = SERVICENAME_ACTIONTRIGGERCONTAINER;
235 return seqServiceNames;
238 // XUnoTunnel
239 sal_Int64 SAL_CALL RootActionTriggerContainer::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw ( RuntimeException, std::exception )
241 if ( aIdentifier == impl_getStaticIdentifier() )
242 return reinterpret_cast< sal_Int64 >( this );
243 else
244 return 0;
247 // XTypeProvider
248 Sequence< Type > SAL_CALL RootActionTriggerContainer::getTypes() throw ( RuntimeException, std::exception )
250 // Optimize this method !
251 // We initialize a static variable only one time. And we don't must use a mutex at every call!
252 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
253 static ::cppu::OTypeCollection* pTypeCollection = NULL;
255 if ( pTypeCollection == NULL )
257 // Ready for multithreading; get global mutex for first call of this method only! see before
258 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
260 // Control these pointer again ... it can be, that another instance will be faster then these!
261 if ( pTypeCollection == NULL )
263 // Create a static typecollection ...
264 static ::cppu::OTypeCollection aTypeCollection(
265 cppu::UnoType<XMultiServiceFactory>::get(),
266 cppu::UnoType<XIndexContainer>::get(),
267 cppu::UnoType<XServiceInfo>::get(),
268 cppu::UnoType<XTypeProvider>::get(),
269 cppu::UnoType<XUnoTunnel>::get(),
270 cppu::UnoType<XNamed>::get());
272 // ... and set his address to static pointer!
273 pTypeCollection = &aTypeCollection;
277 return pTypeCollection->getTypes();
280 Sequence< sal_Int8 > SAL_CALL RootActionTriggerContainer::getImplementationId() throw ( RuntimeException, std::exception )
282 return css::uno::Sequence<sal_Int8>();
285 // private implementation helper
286 void RootActionTriggerContainer::FillContainer()
288 m_bContainerCreated = true;
289 m_bInContainerCreation = true;
290 Reference<XIndexContainer> xXIndexContainer( (OWeakObject *)this, UNO_QUERY );
291 ActionTriggerHelper::FillActionTriggerContainerFromMenu(
292 xXIndexContainer,
293 m_pMenu );
294 m_bInContainerCreation = false;
296 OUString RootActionTriggerContainer::getName() throw ( RuntimeException, std::exception )
298 OUString sRet;
299 if( m_pMenuIdentifier )
300 sRet = *m_pMenuIdentifier;
301 return sRet;
304 void RootActionTriggerContainer::setName( const OUString& ) throw ( RuntimeException, std::exception)
306 throw RuntimeException();
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */