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