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()
53 // XMultiServiceFactory
54 Reference
< XInterface
> SAL_CALL
RootActionTriggerContainer::createInstance( const OUString
& aServiceSpecifier
)
56 if ( aServiceSpecifier
== SERVICENAME_ACTIONTRIGGER
)
57 return static_cast<OWeakObject
*>( new ActionTriggerPropertySet());
58 else if ( aServiceSpecifier
== SERVICENAME_ACTIONTRIGGERCONTAINER
)
59 return static_cast<OWeakObject
*>( new ActionTriggerContainer());
60 else if ( aServiceSpecifier
== SERVICENAME_ACTIONTRIGGERSEPARATOR
)
61 return static_cast<OWeakObject
*>( new ActionTriggerSeparatorPropertySet());
63 throw css::uno::RuntimeException(u
"Unknown service specifier!"_ustr
, static_cast<OWeakObject
*>(this) );
66 Reference
< XInterface
> SAL_CALL
RootActionTriggerContainer::createInstanceWithArguments( const OUString
& ServiceSpecifier
, const Sequence
< Any
>& /*Arguments*/ )
68 return createInstance( ServiceSpecifier
);
71 Sequence
< OUString
> SAL_CALL
RootActionTriggerContainer::getAvailableServiceNames()
73 Sequence
< OUString
> aSeq
{ SERVICENAME_ACTIONTRIGGER
,
74 SERVICENAME_ACTIONTRIGGERCONTAINER
,
75 SERVICENAME_ACTIONTRIGGERSEPARATOR
};
80 void SAL_CALL
RootActionTriggerContainer::insertByIndex( sal_Int32 Index
, const Any
& Element
)
84 if ( !m_bContainerCreated
)
87 PropertySetContainer::insertByIndex( Index
, Element
);
90 void SAL_CALL
RootActionTriggerContainer::removeByIndex( sal_Int32 Index
)
94 if ( !m_bContainerCreated
)
97 PropertySetContainer::removeByIndex( Index
);
101 void SAL_CALL
RootActionTriggerContainer::replaceByIndex( sal_Int32 Index
, const Any
& Element
)
105 if ( !m_bContainerCreated
)
108 PropertySetContainer::replaceByIndex( Index
, Element
);
112 sal_Int32 SAL_CALL
RootActionTriggerContainer::getCount()
116 if ( !m_bContainerCreated
)
119 return m_xMenu
->getItemCount();
125 return PropertySetContainer::getCount();
129 Any SAL_CALL
RootActionTriggerContainer::getByIndex( sal_Int32 Index
)
133 if ( !m_bContainerCreated
)
136 return PropertySetContainer::getByIndex( Index
);
140 Type SAL_CALL
RootActionTriggerContainer::getElementType()
142 return cppu::UnoType
<XPropertySet
>::get();
145 sal_Bool SAL_CALL
RootActionTriggerContainer::hasElements()
148 return m_xMenu
->getItemCount() > 0;
153 OUString SAL_CALL
RootActionTriggerContainer::getImplementationName()
155 return IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER
;
158 sal_Bool SAL_CALL
RootActionTriggerContainer::supportsService( const OUString
& ServiceName
)
160 return cppu::supportsService(this, ServiceName
);
163 Sequence
< OUString
> SAL_CALL
RootActionTriggerContainer::getSupportedServiceNames()
165 return { SERVICENAME_ACTIONTRIGGERCONTAINER
};
168 // private implementation helper
169 void RootActionTriggerContainer::FillContainer()
171 m_bContainerCreated
= true;
172 ActionTriggerHelper::FillActionTriggerContainerFromMenu(
175 OUString
RootActionTriggerContainer::getName()
178 if( m_pMenuIdentifier
)
179 sRet
= *m_pMenuIdentifier
;
183 void RootActionTriggerContainer::setName( const OUString
& )
185 throw RuntimeException();
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */