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 .
20 #include <classes/rootactiontriggercontainer.hxx>
21 #include <classes/actiontriggercontainer.hxx>
22 #include <classes/actiontriggerpropertyset.hxx>
23 #include <classes/actiontriggerseparatorpropertyset.hxx>
24 #include <comphelper/servicehelper.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <cppuhelper/queryinterface.hxx>
27 #include <cppuhelper/typeprovider.hxx>
28 #include <framework/actiontriggerhelper.hxx>
30 #include <vcl/svapp.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
;
41 RootActionTriggerContainer::RootActionTriggerContainer(css::uno::Reference
<css::awt::XPopupMenu
> xMenu
,
42 const OUString
* pMenuIdentifier
)
43 : m_bContainerCreated(false)
44 , m_xMenu(std::move(xMenu
))
45 , m_pMenuIdentifier(pMenuIdentifier
)
49 RootActionTriggerContainer::~RootActionTriggerContainer()
54 Any SAL_CALL
RootActionTriggerContainer::queryInterface( const Type
& aType
)
56 Any a
= ::cppu::queryInterface(
58 static_cast< XMultiServiceFactory
* >(this),
59 static_cast< XServiceInfo
* >(this),
60 static_cast< XTypeProvider
* >(this),
61 static_cast< XNamed
* >(this));
68 return PropertySetContainer::queryInterface( aType
);
71 void SAL_CALL
RootActionTriggerContainer::acquire() noexcept
73 PropertySetContainer::acquire();
76 void SAL_CALL
RootActionTriggerContainer::release() noexcept
78 PropertySetContainer::release();
81 // XMultiServiceFactory
82 Reference
< XInterface
> SAL_CALL
RootActionTriggerContainer::createInstance( const OUString
& aServiceSpecifier
)
84 if ( aServiceSpecifier
== SERVICENAME_ACTIONTRIGGER
)
85 return static_cast<OWeakObject
*>( new ActionTriggerPropertySet());
86 else if ( aServiceSpecifier
== SERVICENAME_ACTIONTRIGGERCONTAINER
)
87 return static_cast<OWeakObject
*>( new ActionTriggerContainer());
88 else if ( aServiceSpecifier
== SERVICENAME_ACTIONTRIGGERSEPARATOR
)
89 return static_cast<OWeakObject
*>( new ActionTriggerSeparatorPropertySet());
91 throw css::uno::RuntimeException("Unknown service specifier!", static_cast<OWeakObject
*>(this) );
94 Reference
< XInterface
> SAL_CALL
RootActionTriggerContainer::createInstanceWithArguments( const OUString
& ServiceSpecifier
, const Sequence
< Any
>& /*Arguments*/ )
96 return createInstance( ServiceSpecifier
);
99 Sequence
< OUString
> SAL_CALL
RootActionTriggerContainer::getAvailableServiceNames()
101 Sequence
< OUString
> aSeq
{ SERVICENAME_ACTIONTRIGGER
,
102 SERVICENAME_ACTIONTRIGGERCONTAINER
,
103 SERVICENAME_ACTIONTRIGGERSEPARATOR
};
108 void SAL_CALL
RootActionTriggerContainer::insertByIndex( sal_Int32 Index
, const Any
& Element
)
112 if ( !m_bContainerCreated
)
115 PropertySetContainer::insertByIndex( Index
, Element
);
118 void SAL_CALL
RootActionTriggerContainer::removeByIndex( sal_Int32 Index
)
122 if ( !m_bContainerCreated
)
125 PropertySetContainer::removeByIndex( Index
);
129 void SAL_CALL
RootActionTriggerContainer::replaceByIndex( sal_Int32 Index
, const Any
& Element
)
133 if ( !m_bContainerCreated
)
136 PropertySetContainer::replaceByIndex( Index
, Element
);
140 sal_Int32 SAL_CALL
RootActionTriggerContainer::getCount()
144 if ( !m_bContainerCreated
)
147 return m_xMenu
->getItemCount();
153 return PropertySetContainer::getCount();
157 Any SAL_CALL
RootActionTriggerContainer::getByIndex( sal_Int32 Index
)
161 if ( !m_bContainerCreated
)
164 return PropertySetContainer::getByIndex( Index
);
168 Type SAL_CALL
RootActionTriggerContainer::getElementType()
170 return cppu::UnoType
<XPropertySet
>::get();
173 sal_Bool SAL_CALL
RootActionTriggerContainer::hasElements()
176 return m_xMenu
->getItemCount() > 0;
181 OUString SAL_CALL
RootActionTriggerContainer::getImplementationName()
183 return IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER
;
186 sal_Bool SAL_CALL
RootActionTriggerContainer::supportsService( const OUString
& ServiceName
)
188 return cppu::supportsService(this, ServiceName
);
191 Sequence
< OUString
> SAL_CALL
RootActionTriggerContainer::getSupportedServiceNames()
193 return { SERVICENAME_ACTIONTRIGGERCONTAINER
};
197 Sequence
< Type
> SAL_CALL
RootActionTriggerContainer::getTypes()
199 // Create a static typecollection ...
200 static ::cppu::OTypeCollection
ourTypeCollection(
201 cppu::UnoType
<XMultiServiceFactory
>::get(),
202 cppu::UnoType
<XIndexContainer
>::get(),
203 cppu::UnoType
<XServiceInfo
>::get(),
204 cppu::UnoType
<XTypeProvider
>::get(),
205 cppu::UnoType
<XUnoTunnel
>::get(),
206 cppu::UnoType
<XNamed
>::get());
208 return ourTypeCollection
.getTypes();
211 Sequence
< sal_Int8
> SAL_CALL
RootActionTriggerContainer::getImplementationId()
213 return css::uno::Sequence
<sal_Int8
>();
216 // private implementation helper
217 void RootActionTriggerContainer::FillContainer()
219 m_bContainerCreated
= true;
220 ActionTriggerHelper::FillActionTriggerContainerFromMenu(
223 OUString
RootActionTriggerContainer::getName()
226 if( m_pMenuIdentifier
)
227 sRet
= *m_pMenuIdentifier
;
231 void RootActionTriggerContainer::setName( const OUString
& )
233 throw RuntimeException();
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */