Avoid potential negative array index access to cached text.
[LibreOffice.git] / extensions / source / propctrlr / buttonnavigationhandler.cxx
blob618d9db46b869d26925e6aa885cb3b7cd18c314b
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 "buttonnavigationhandler.hxx"
21 #include "formstrings.hxx"
22 #include "formmetadata.hxx"
23 #include "pushbuttonnavigation.hxx"
25 #include <com/sun/star/form/inspection/FormComponentPropertyHandler.hpp>
27 namespace pcr
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::script;
35 using namespace ::com::sun::star::frame;
36 using namespace ::com::sun::star::inspection;
38 ButtonNavigationHandler::ButtonNavigationHandler( const Reference< XComponentContext >& _rxContext )
39 :PropertyHandlerComponent( _rxContext )
42 m_xSlaveHandler = css::form::inspection::FormComponentPropertyHandler::create( m_xContext );
46 ButtonNavigationHandler::~ButtonNavigationHandler( )
51 OUString ButtonNavigationHandler::getImplementationName( )
53 return "com.sun.star.comp.extensions.ButtonNavigationHandler";
57 Sequence< OUString > ButtonNavigationHandler::getSupportedServiceNames( )
59 return { "com.sun.star.form.inspection.ButtonNavigationHandler" };
63 void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee )
65 PropertyHandlerComponent::inspect( _rxIntrospectee );
66 m_xSlaveHandler->inspect( _rxIntrospectee );
70 PropertyState SAL_CALL ButtonNavigationHandler::getPropertyState( const OUString& _rPropertyName )
72 ::osl::MutexGuard aGuard( m_aMutex );
73 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
74 PropertyState eState = PropertyState_DIRECT_VALUE;
75 switch ( nPropId )
77 case PROPERTY_ID_BUTTONTYPE:
79 PushButtonNavigation aHelper( m_xComponent );
80 eState = aHelper.getCurrentButtonTypeState();
82 break;
83 case PROPERTY_ID_TARGET_URL:
85 PushButtonNavigation aHelper( m_xComponent );
86 eState = aHelper.getCurrentTargetURLState();
88 break;
90 default:
91 OSL_FAIL( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
92 break;
95 return eState;
99 Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const OUString& _rPropertyName )
101 ::osl::MutexGuard aGuard( m_aMutex );
102 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
104 Any aReturn;
105 switch ( nPropId )
107 case PROPERTY_ID_BUTTONTYPE:
109 PushButtonNavigation aHelper( m_xComponent );
110 aReturn = aHelper.getCurrentButtonType();
112 break;
114 case PROPERTY_ID_TARGET_URL:
116 PushButtonNavigation aHelper( m_xComponent );
117 aReturn = aHelper.getCurrentTargetURL();
119 break;
121 default:
122 OSL_FAIL( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
123 break;
126 return aReturn;
130 void SAL_CALL ButtonNavigationHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue )
132 ::osl::MutexGuard aGuard( m_aMutex );
133 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
134 switch ( nPropId )
136 case PROPERTY_ID_BUTTONTYPE:
138 PushButtonNavigation aHelper( m_xComponent );
139 aHelper.setCurrentButtonType( _rValue );
141 break;
143 case PROPERTY_ID_TARGET_URL:
145 PushButtonNavigation aHelper( m_xComponent );
146 aHelper.setCurrentTargetURL( _rValue );
148 break;
150 default:
151 OSL_FAIL( "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
156 bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent )
158 Reference< XPropertySetInfo > xPSI;
159 if ( _rxComponent.is() )
160 xPSI = _rxComponent->getPropertySetInfo();
162 return xPSI.is()
163 && xPSI->hasPropertyByName( PROPERTY_TARGET_URL )
164 && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE );
168 Sequence< Property > ButtonNavigationHandler::doDescribeSupportedProperties() const
170 std::vector< Property > aProperties;
172 if ( isNavigationCapableButton( m_xComponent ) )
174 addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL );
175 implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::cppu::UnoType<sal_Int32>::get() );
178 if ( aProperties.empty() )
179 return Sequence< Property >();
180 return comphelper::containerToSequence(aProperties);
184 Sequence< OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( )
186 Sequence< OUString > aActuating{ PROPERTY_BUTTONTYPE, PROPERTY_TARGET_URL };
187 return aActuating;
191 InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI )
193 ::osl::MutexGuard aGuard( m_aMutex );
194 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
196 InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled );
198 switch ( nPropId )
200 case PROPERTY_ID_TARGET_URL:
201 eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
202 break;
203 default:
204 eReturn = PropertyHandlerComponent::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
205 break;
208 return eReturn;
212 void SAL_CALL ButtonNavigationHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool /*_bFirstTimeInit*/ )
214 ::osl::MutexGuard aGuard( m_aMutex );
215 PropertyId nPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
216 switch ( nPropId )
218 case PROPERTY_ID_BUTTONTYPE:
220 PushButtonNavigation aHelper( m_xComponent );
221 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() );
223 break;
225 case PROPERTY_ID_TARGET_URL:
227 PushButtonNavigation aHelper( m_xComponent );
228 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() );
230 break;
232 default:
233 OSL_FAIL( "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
238 LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory )
240 ::osl::MutexGuard aGuard( m_aMutex );
241 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
243 LineDescriptor aReturn;
245 switch ( nPropId )
247 case PROPERTY_ID_TARGET_URL:
248 aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory );
249 break;
250 default:
251 aReturn = PropertyHandlerComponent::describePropertyLine( _rPropertyName, _rxControlFactory );
252 break;
255 return aReturn;
259 } // namespace pcr
261 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
262 extensions_propctrlr_ButtonNavigationHandler_get_implementation(
263 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
265 return cppu::acquire(new pcr::ButtonNavigationHandler(context));
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */