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/queryinterface.hxx>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <framework/actiontriggerhelper.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 
impl_getStaticIdentifier()39 static Sequence< sal_Int8 > const & 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     static css::uno::Sequence< sal_Int8 > seqID(reinterpret_cast<const sal_Int8*>(pGUID), 16);
43     return seqID;
44 }
45 
RootActionTriggerContainer(const Menu * pMenu,const OUString * pMenuIdentifier)46 RootActionTriggerContainer::RootActionTriggerContainer( const Menu* pMenu, const OUString* pMenuIdentifier ) :
47     PropertySetContainer()
48     ,   m_bContainerCreated( false )
49     ,   m_pMenu( pMenu )
50     ,   m_pMenuIdentifier( pMenuIdentifier )
51 {
52 }
53 
~RootActionTriggerContainer()54 RootActionTriggerContainer::~RootActionTriggerContainer()
55 {
56 }
57 
58 // XInterface
queryInterface(const Type & aType)59 Any SAL_CALL RootActionTriggerContainer::queryInterface( const Type& aType )
60 {
61     Any a = ::cppu::queryInterface(
62                 aType ,
63                 static_cast< XMultiServiceFactory*   >(this),
64                 static_cast< XServiceInfo*           >(this),
65                 static_cast< XUnoTunnel*             >(this),
66                 static_cast< XTypeProvider*          >(this),
67                 static_cast< XNamed*                 >(this));
68 
69     if( a.hasValue() )
70     {
71         return a;
72     }
73 
74     return PropertySetContainer::queryInterface( aType );
75 }
76 
acquire()77 void SAL_CALL RootActionTriggerContainer::acquire() throw ()
78 {
79     PropertySetContainer::acquire();
80 }
81 
release()82 void SAL_CALL RootActionTriggerContainer::release() throw ()
83 {
84     PropertySetContainer::release();
85 }
86 
87 // XMultiServiceFactory
createInstance(const OUString & aServiceSpecifier)88 Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstance( const OUString& aServiceSpecifier )
89 {
90     if ( aServiceSpecifier == SERVICENAME_ACTIONTRIGGER )
91         return static_cast<OWeakObject *>( new ActionTriggerPropertySet());
92     else if ( aServiceSpecifier == SERVICENAME_ACTIONTRIGGERCONTAINER )
93         return static_cast<OWeakObject *>( new ActionTriggerContainer());
94     else if ( aServiceSpecifier == SERVICENAME_ACTIONTRIGGERSEPARATOR )
95         return static_cast<OWeakObject *>( new ActionTriggerSeparatorPropertySet());
96     else
97         throw css::uno::RuntimeException("Unknown service specifier!", static_cast<OWeakObject *>(this) );
98 }
99 
createInstanceWithArguments(const OUString & ServiceSpecifier,const Sequence<Any> &)100 Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstanceWithArguments( const OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ )
101 {
102     return createInstance( ServiceSpecifier );
103 }
104 
getAvailableServiceNames()105 Sequence< OUString > SAL_CALL RootActionTriggerContainer::getAvailableServiceNames()
106 {
107     Sequence< OUString > aSeq( 3 );
108 
109     aSeq[0] = SERVICENAME_ACTIONTRIGGER;
110     aSeq[1] = SERVICENAME_ACTIONTRIGGERCONTAINER;
111     aSeq[2] = SERVICENAME_ACTIONTRIGGERSEPARATOR;
112 
113     return aSeq;
114 }
115 
116 // XIndexContainer
insertByIndex(sal_Int32 Index,const Any & Element)117 void SAL_CALL RootActionTriggerContainer::insertByIndex( sal_Int32 Index, const Any& Element )
118 {
119     SolarMutexGuard g;
120 
121     if ( !m_bContainerCreated )
122         FillContainer();
123 
124     PropertySetContainer::insertByIndex( Index, Element );
125 }
126 
removeByIndex(sal_Int32 Index)127 void SAL_CALL RootActionTriggerContainer::removeByIndex( sal_Int32 Index )
128 {
129     SolarMutexGuard g;
130 
131     if ( !m_bContainerCreated )
132         FillContainer();
133 
134     PropertySetContainer::removeByIndex( Index );
135 }
136 
137 // XIndexReplace
replaceByIndex(sal_Int32 Index,const Any & Element)138 void SAL_CALL RootActionTriggerContainer::replaceByIndex( sal_Int32 Index, const Any& Element )
139 {
140     SolarMutexGuard g;
141 
142     if ( !m_bContainerCreated )
143         FillContainer();
144 
145     PropertySetContainer::replaceByIndex( Index, Element );
146 }
147 
148 // XIndexAccess
getCount()149 sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
150 {
151     SolarMutexGuard g;
152 
153     if ( !m_bContainerCreated )
154     {
155         if ( m_pMenu )
156         {
157             SolarMutexGuard aSolarMutexGuard;
158             return m_pMenu->GetItemCount();
159         }
160         else
161             return 0;
162     }
163     else
164     {
165         return PropertySetContainer::getCount();
166     }
167 }
168 
getByIndex(sal_Int32 Index)169 Any SAL_CALL RootActionTriggerContainer::getByIndex( sal_Int32 Index )
170 {
171     SolarMutexGuard g;
172 
173     if ( !m_bContainerCreated )
174         FillContainer();
175 
176     return PropertySetContainer::getByIndex( Index );
177 }
178 
179 // XElementAccess
getElementType()180 Type SAL_CALL RootActionTriggerContainer::getElementType()
181 {
182     return cppu::UnoType<XPropertySet>::get();
183 }
184 
hasElements()185 sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
186 {
187     if ( m_pMenu )
188     {
189         SolarMutexGuard aSolarMutexGuard;
190         return ( m_pMenu->GetItemCount() > 0 );
191     }
192 
193     return false;
194 }
195 
196 // XServiceInfo
getImplementationName()197 OUString SAL_CALL RootActionTriggerContainer::getImplementationName()
198 {
199     return IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER;
200 }
201 
supportsService(const OUString & ServiceName)202 sal_Bool SAL_CALL RootActionTriggerContainer::supportsService( const OUString& ServiceName )
203 {
204     return cppu::supportsService(this, ServiceName);
205 }
206 
getSupportedServiceNames()207 Sequence< OUString > SAL_CALL RootActionTriggerContainer::getSupportedServiceNames()
208 {
209     Sequence< OUString > seqServiceNames { SERVICENAME_ACTIONTRIGGERCONTAINER };
210     return seqServiceNames;
211 }
212 
213 // XUnoTunnel
getSomething(const Sequence<sal_Int8> & aIdentifier)214 sal_Int64 SAL_CALL RootActionTriggerContainer::getSomething( const Sequence< sal_Int8 >& aIdentifier )
215 {
216     if ( aIdentifier == impl_getStaticIdentifier() )
217         return reinterpret_cast< sal_Int64 >( this );
218     else
219         return 0;
220 }
221 
222 // XTypeProvider
getTypes()223 Sequence< Type > SAL_CALL RootActionTriggerContainer::getTypes()
224 {
225     // Create a static typecollection ...
226     static ::cppu::OTypeCollection ourTypeCollection(
227                         cppu::UnoType<XMultiServiceFactory>::get(),
228                         cppu::UnoType<XIndexContainer>::get(),
229                         cppu::UnoType<XServiceInfo>::get(),
230                         cppu::UnoType<XTypeProvider>::get(),
231                         cppu::UnoType<XUnoTunnel>::get(),
232                         cppu::UnoType<XNamed>::get());
233 
234     return ourTypeCollection.getTypes();
235 }
236 
getImplementationId()237 Sequence< sal_Int8 > SAL_CALL RootActionTriggerContainer::getImplementationId()
238 {
239     return css::uno::Sequence<sal_Int8>();
240 }
241 
242 // private implementation helper
FillContainer()243 void RootActionTriggerContainer::FillContainer()
244 {
245     m_bContainerCreated = true;
246     ActionTriggerHelper::FillActionTriggerContainerFromMenu(
247         this,
248         m_pMenu );
249 }
getName()250 OUString RootActionTriggerContainer::getName()
251 {
252     OUString sRet;
253     if( m_pMenuIdentifier )
254         sRet = *m_pMenuIdentifier;
255     return sRet;
256 }
257 
setName(const OUString &)258 void RootActionTriggerContainer::setName( const OUString& )
259 {
260     throw RuntimeException();
261 }
262 }
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
265