bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / buttonnavigationhandler.cxx
blob5488d9b5428b6e5d79bdeb5d5e3f04df0710ce4e
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 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 ButtonNavigationHandler::getImplementationName_static( )
60 return OUString( "com.sun.star.comp.extensions.ButtonNavigationHandler" );
64 Sequence< OUString > ButtonNavigationHandler::getSupportedServiceNames_static( )
66 Sequence<OUString> aSupported { "com.sun.star.form.inspection.ButtonNavigationHandler" };
67 return aSupported;
71 void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee )
73 ButtonNavigationHandler_Base::inspect( _rxIntrospectee );
74 m_xSlaveHandler->inspect( _rxIntrospectee );
78 PropertyState SAL_CALL ButtonNavigationHandler::getPropertyState( const OUString& _rPropertyName )
80 ::osl::MutexGuard aGuard( m_aMutex );
81 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
82 PropertyState eState = PropertyState_DIRECT_VALUE;
83 switch ( nPropId )
85 case PROPERTY_ID_BUTTONTYPE:
87 PushButtonNavigation aHelper( m_xComponent );
88 eState = aHelper.getCurrentButtonTypeState();
90 break;
91 case PROPERTY_ID_TARGET_URL:
93 PushButtonNavigation aHelper( m_xComponent );
94 eState = aHelper.getCurrentTargetURLState();
96 break;
98 default:
99 OSL_FAIL( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
100 break;
103 return eState;
107 Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const OUString& _rPropertyName )
109 ::osl::MutexGuard aGuard( m_aMutex );
110 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
112 Any aReturn;
113 switch ( nPropId )
115 case PROPERTY_ID_BUTTONTYPE:
117 PushButtonNavigation aHelper( m_xComponent );
118 aReturn = aHelper.getCurrentButtonType();
120 break;
122 case PROPERTY_ID_TARGET_URL:
124 PushButtonNavigation aHelper( m_xComponent );
125 aReturn = aHelper.getCurrentTargetURL();
127 break;
129 default:
130 OSL_FAIL( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
131 break;
134 return aReturn;
138 void SAL_CALL ButtonNavigationHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue )
140 ::osl::MutexGuard aGuard( m_aMutex );
141 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
142 switch ( nPropId )
144 case PROPERTY_ID_BUTTONTYPE:
146 PushButtonNavigation aHelper( m_xComponent );
147 aHelper.setCurrentButtonType( _rValue );
149 break;
151 case PROPERTY_ID_TARGET_URL:
153 PushButtonNavigation aHelper( m_xComponent );
154 aHelper.setCurrentTargetURL( _rValue );
156 break;
158 default:
159 OSL_FAIL( "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
164 bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent )
166 Reference< XPropertySetInfo > xPSI;
167 if ( _rxComponent.is() )
168 xPSI = _rxComponent->getPropertySetInfo();
170 return xPSI.is()
171 && xPSI->hasPropertyByName( PROPERTY_TARGET_URL )
172 && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE );
176 Sequence< Property > ButtonNavigationHandler::doDescribeSupportedProperties() const
178 std::vector< Property > aProperties;
180 if ( isNavigationCapableButton( m_xComponent ) )
182 addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL );
183 implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::cppu::UnoType<sal_Int32>::get() );
186 if ( aProperties.empty() )
187 return Sequence< Property >();
188 return comphelper::containerToSequence(aProperties);
192 Sequence< OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( )
194 Sequence< OUString > aActuating( 2 );
195 aActuating[0] = PROPERTY_BUTTONTYPE;
196 aActuating[1] = PROPERTY_TARGET_URL;
197 return aActuating;
201 InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI )
203 ::osl::MutexGuard aGuard( m_aMutex );
204 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
206 InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled );
208 switch ( nPropId )
210 case PROPERTY_ID_TARGET_URL:
211 eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
212 break;
213 default:
214 eReturn = ButtonNavigationHandler_Base::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
215 break;
218 return eReturn;
222 void SAL_CALL ButtonNavigationHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool /*_bFirstTimeInit*/ )
224 ::osl::MutexGuard aGuard( m_aMutex );
225 PropertyId nPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
226 switch ( nPropId )
228 case PROPERTY_ID_BUTTONTYPE:
230 PushButtonNavigation aHelper( m_xComponent );
231 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() );
233 break;
235 case PROPERTY_ID_TARGET_URL:
237 PushButtonNavigation aHelper( m_xComponent );
238 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() );
240 break;
242 default:
243 OSL_FAIL( "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
248 LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory )
250 ::osl::MutexGuard aGuard( m_aMutex );
251 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
253 LineDescriptor aReturn;
255 switch ( nPropId )
257 case PROPERTY_ID_TARGET_URL:
258 aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory );
259 break;
260 default:
261 aReturn = ButtonNavigationHandler_Base::describePropertyLine( _rPropertyName, _rxControlFactory );
262 break;
265 return aReturn;
269 } // namespace pcr
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */