Avoid potential negative array index access to cached text.
[LibreOffice.git] / framework / source / fwe / classes / rootactiontriggercontainer.cxx
blob1493f08bf429586855271b3607dfbb50aac97b83
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 // XInterface
54 Any SAL_CALL RootActionTriggerContainer::queryInterface( const Type& aType )
56 Any a = ::cppu::queryInterface(
57 aType ,
58 static_cast< XMultiServiceFactory* >(this),
59 static_cast< XServiceInfo* >(this),
60 static_cast< XTypeProvider* >(this),
61 static_cast< XNamed* >(this));
63 if( a.hasValue() )
65 return a;
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());
90 else
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 };
104 return aSeq;
107 // XIndexContainer
108 void SAL_CALL RootActionTriggerContainer::insertByIndex( sal_Int32 Index, const Any& Element )
110 SolarMutexGuard g;
112 if ( !m_bContainerCreated )
113 FillContainer();
115 PropertySetContainer::insertByIndex( Index, Element );
118 void SAL_CALL RootActionTriggerContainer::removeByIndex( sal_Int32 Index )
120 SolarMutexGuard g;
122 if ( !m_bContainerCreated )
123 FillContainer();
125 PropertySetContainer::removeByIndex( Index );
128 // XIndexReplace
129 void SAL_CALL RootActionTriggerContainer::replaceByIndex( sal_Int32 Index, const Any& Element )
131 SolarMutexGuard g;
133 if ( !m_bContainerCreated )
134 FillContainer();
136 PropertySetContainer::replaceByIndex( Index, Element );
139 // XIndexAccess
140 sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
142 SolarMutexGuard g;
144 if ( !m_bContainerCreated )
146 if ( m_xMenu )
147 return m_xMenu->getItemCount();
148 else
149 return 0;
151 else
153 return PropertySetContainer::getCount();
157 Any SAL_CALL RootActionTriggerContainer::getByIndex( sal_Int32 Index )
159 SolarMutexGuard g;
161 if ( !m_bContainerCreated )
162 FillContainer();
164 return PropertySetContainer::getByIndex( Index );
167 // XElementAccess
168 Type SAL_CALL RootActionTriggerContainer::getElementType()
170 return cppu::UnoType<XPropertySet>::get();
173 sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
175 if (m_xMenu)
176 return m_xMenu->getItemCount() > 0;
177 return false;
180 // XServiceInfo
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 };
196 // XTypeProvider
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(
221 this, m_xMenu);
223 OUString RootActionTriggerContainer::getName()
225 OUString sRet;
226 if( m_pMenuIdentifier )
227 sRet = *m_pMenuIdentifier;
228 return sRet;
231 void RootActionTriggerContainer::setName( const OUString& )
233 throw RuntimeException();
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */