Update git submodules
[LibreOffice.git] / framework / source / fwe / classes / rootactiontriggercontainer.cxx
blobdff698066dbe807cce497017d08eb2dc2bae7255
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 <comphelper/servicehelper.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <cppuhelper/queryinterface.hxx>
27 #include <cppuhelper/typeprovider.hxx>
28 #include <framework/actiontriggerhelper.hxx>
29 #include <utility>
30 #include <vcl/svapp.hxx>
32 using namespace cppu;
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;
38 namespace framework
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());
62 else
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 };
76 return aSeq;
79 // XIndexContainer
80 void SAL_CALL RootActionTriggerContainer::insertByIndex( sal_Int32 Index, const Any& Element )
82 SolarMutexGuard g;
84 if ( !m_bContainerCreated )
85 FillContainer();
87 PropertySetContainer::insertByIndex( Index, Element );
90 void SAL_CALL RootActionTriggerContainer::removeByIndex( sal_Int32 Index )
92 SolarMutexGuard g;
94 if ( !m_bContainerCreated )
95 FillContainer();
97 PropertySetContainer::removeByIndex( Index );
100 // XIndexReplace
101 void SAL_CALL RootActionTriggerContainer::replaceByIndex( sal_Int32 Index, const Any& Element )
103 SolarMutexGuard g;
105 if ( !m_bContainerCreated )
106 FillContainer();
108 PropertySetContainer::replaceByIndex( Index, Element );
111 // XIndexAccess
112 sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
114 SolarMutexGuard g;
116 if ( !m_bContainerCreated )
118 if ( m_xMenu )
119 return m_xMenu->getItemCount();
120 else
121 return 0;
123 else
125 return PropertySetContainer::getCount();
129 Any SAL_CALL RootActionTriggerContainer::getByIndex( sal_Int32 Index )
131 SolarMutexGuard g;
133 if ( !m_bContainerCreated )
134 FillContainer();
136 return PropertySetContainer::getByIndex( Index );
139 // XElementAccess
140 Type SAL_CALL RootActionTriggerContainer::getElementType()
142 return cppu::UnoType<XPropertySet>::get();
145 sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
147 if (m_xMenu)
148 return m_xMenu->getItemCount() > 0;
149 return false;
152 // XServiceInfo
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(
173 this, m_xMenu);
175 OUString RootActionTriggerContainer::getName()
177 OUString sRet;
178 if( m_pMenuIdentifier )
179 sRet = *m_pMenuIdentifier;
180 return sRet;
183 void RootActionTriggerContainer::setName( const OUString& )
185 throw RuntimeException();
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */