bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / propctrlr / buttonnavigationhandler.cxx
blob20f1a6b0e5afc43d5d7faee727ebfb3c3c77ab70
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 "pcrservices.hxx"
24 #include "pushbuttonnavigation.hxx"
26 #include <com/sun/star/form/inspection/FormComponentPropertyHandler.hpp>
28 extern "C" void SAL_CALL createRegistryInfo_ButtonNavigationHandler()
30 ::pcr::ButtonNavigationHandler::registerImplementation();
34 namespace pcr
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::script;
42 using namespace ::com::sun::star::frame;
43 using namespace ::com::sun::star::inspection;
45 ButtonNavigationHandler::ButtonNavigationHandler( const Reference< XComponentContext >& _rxContext )
46 :ButtonNavigationHandler_Base( _rxContext )
49 m_xSlaveHandler = css::form::inspection::FormComponentPropertyHandler::create( m_xContext );
53 ButtonNavigationHandler::~ButtonNavigationHandler( )
58 OUString SAL_CALL ButtonNavigationHandler::getImplementationName_static( ) throw (RuntimeException)
60 return OUString( "com.sun.star.comp.extensions.ButtonNavigationHandler" );
64 Sequence< OUString > SAL_CALL ButtonNavigationHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
66 Sequence< OUString > aSupported( 1 );
67 aSupported[0] = "com.sun.star.form.inspection.ButtonNavigationHandler";
68 return aSupported;
72 void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException, std::exception)
74 ButtonNavigationHandler_Base::inspect( _rxIntrospectee );
75 m_xSlaveHandler->inspect( _rxIntrospectee );
79 PropertyState SAL_CALL ButtonNavigationHandler::getPropertyState( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
81 ::osl::MutexGuard aGuard( m_aMutex );
82 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
83 PropertyState eState = PropertyState_DIRECT_VALUE;
84 switch ( nPropId )
86 case PROPERTY_ID_BUTTONTYPE:
88 PushButtonNavigation aHelper( m_xComponent );
89 eState = aHelper.getCurrentButtonTypeState();
91 break;
92 case PROPERTY_ID_TARGET_URL:
94 PushButtonNavigation aHelper( m_xComponent );
95 eState = aHelper.getCurrentTargetURLState();
97 break;
99 default:
100 OSL_FAIL( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
101 break;
104 return eState;
108 Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
110 ::osl::MutexGuard aGuard( m_aMutex );
111 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
113 Any aReturn;
114 switch ( nPropId )
116 case PROPERTY_ID_BUTTONTYPE:
118 PushButtonNavigation aHelper( m_xComponent );
119 aReturn = aHelper.getCurrentButtonType();
121 break;
123 case PROPERTY_ID_TARGET_URL:
125 PushButtonNavigation aHelper( m_xComponent );
126 aReturn = aHelper.getCurrentTargetURL();
128 break;
130 default:
131 OSL_FAIL( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
132 break;
135 return aReturn;
139 void SAL_CALL ButtonNavigationHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
141 ::osl::MutexGuard aGuard( m_aMutex );
142 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
143 switch ( nPropId )
145 case PROPERTY_ID_BUTTONTYPE:
147 PushButtonNavigation aHelper( m_xComponent );
148 aHelper.setCurrentButtonType( _rValue );
150 break;
152 case PROPERTY_ID_TARGET_URL:
154 PushButtonNavigation aHelper( m_xComponent );
155 aHelper.setCurrentTargetURL( _rValue );
157 break;
159 default:
160 OSL_FAIL( "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
165 bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent )
167 Reference< XPropertySetInfo > xPSI;
168 if ( _rxComponent.is() )
169 xPSI = _rxComponent->getPropertySetInfo();
171 return xPSI.is()
172 && xPSI->hasPropertyByName( PROPERTY_TARGET_URL )
173 && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE );
177 Sequence< Property > SAL_CALL ButtonNavigationHandler::doDescribeSupportedProperties() const
179 ::std::vector< Property > aProperties;
181 if ( isNavigationCapableButton( m_xComponent ) )
183 addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL );
184 implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::cppu::UnoType<sal_Int32>::get() );
187 if ( aProperties.empty() )
188 return Sequence< Property >();
189 return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
193 Sequence< OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( ) throw (RuntimeException, std::exception)
195 Sequence< OUString > aActuating( 2 );
196 aActuating[0] = PROPERTY_BUTTONTYPE;
197 aActuating[1] = PROPERTY_TARGET_URL;
198 return aActuating;
202 InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
204 ::osl::MutexGuard aGuard( m_aMutex );
205 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
207 InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled );
209 switch ( nPropId )
211 case PROPERTY_ID_TARGET_URL:
212 eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
213 break;
214 default:
215 eReturn = ButtonNavigationHandler_Base::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
216 break;
219 return eReturn;
223 void SAL_CALL ButtonNavigationHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException, std::exception)
225 ::osl::MutexGuard aGuard( m_aMutex );
226 PropertyId nPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
227 switch ( nPropId )
229 case PROPERTY_ID_BUTTONTYPE:
231 PushButtonNavigation aHelper( m_xComponent );
232 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() );
234 break;
236 case PROPERTY_ID_TARGET_URL:
238 PushButtonNavigation aHelper( m_xComponent );
239 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() );
241 break;
243 default:
244 OSL_FAIL( "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
249 LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory ) throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
251 ::osl::MutexGuard aGuard( m_aMutex );
252 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
254 LineDescriptor aReturn;
256 switch ( nPropId )
258 case PROPERTY_ID_TARGET_URL:
259 aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory );
260 break;
261 default:
262 aReturn = ButtonNavigationHandler_Base::describePropertyLine( _rPropertyName, _rxControlFactory );
263 break;
266 return aReturn;
270 } // namespace pcr
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */