bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / propctrlr / buttonnavigationhandler.cxx
blobd4b25c2f84ec9768dc771f4ff3e31a4708f6b8b8
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 <tools/debug.hxx>
27 //------------------------------------------------------------------------
28 extern "C" void SAL_CALL createRegistryInfo_ButtonNavigationHandler()
30 ::pcr::ButtonNavigationHandler::registerImplementation();
33 //........................................................................
34 namespace pcr
36 //........................................................................
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 //====================================================================
46 //= ButtonNavigationHandler
47 //====================================================================
48 DBG_NAME( ButtonNavigationHandler )
49 //--------------------------------------------------------------------
50 ButtonNavigationHandler::ButtonNavigationHandler( const Reference< XComponentContext >& _rxContext )
51 :ButtonNavigationHandler_Base( _rxContext )
53 DBG_CTOR( ButtonNavigationHandler, NULL );
55 m_aContext.createComponent(
56 OUString( "com.sun.star.form.inspection.FormComponentPropertyHandler" ),
57 m_xSlaveHandler );
58 if ( !m_xSlaveHandler.is() )
59 throw RuntimeException();
62 //--------------------------------------------------------------------
63 ButtonNavigationHandler::~ButtonNavigationHandler( )
65 DBG_DTOR( ButtonNavigationHandler, NULL );
68 //--------------------------------------------------------------------
69 OUString SAL_CALL ButtonNavigationHandler::getImplementationName_static( ) throw (RuntimeException)
71 return OUString( "com.sun.star.comp.extensions.ButtonNavigationHandler" );
74 //--------------------------------------------------------------------
75 Sequence< OUString > SAL_CALL ButtonNavigationHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
77 Sequence< OUString > aSupported( 1 );
78 aSupported[0] = OUString( "com.sun.star.form.inspection.ButtonNavigationHandler" );
79 return aSupported;
82 //--------------------------------------------------------------------
83 void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException)
85 ButtonNavigationHandler_Base::inspect( _rxIntrospectee );
86 m_xSlaveHandler->inspect( _rxIntrospectee );
89 //--------------------------------------------------------------------
90 PropertyState SAL_CALL ButtonNavigationHandler::getPropertyState( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
92 ::osl::MutexGuard aGuard( m_aMutex );
93 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
94 PropertyState eState = PropertyState_DIRECT_VALUE;
95 switch ( nPropId )
97 case PROPERTY_ID_BUTTONTYPE:
99 PushButtonNavigation aHelper( m_xComponent );
100 eState = aHelper.getCurrentButtonTypeState();
102 break;
103 case PROPERTY_ID_TARGET_URL:
105 PushButtonNavigation aHelper( m_xComponent );
106 eState = aHelper.getCurrentTargetURLState();
108 break;
110 default:
111 OSL_FAIL( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
112 break;
115 return eState;
118 //--------------------------------------------------------------------
119 Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
121 ::osl::MutexGuard aGuard( m_aMutex );
122 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
124 Any aReturn;
125 switch ( nPropId )
127 case PROPERTY_ID_BUTTONTYPE:
129 PushButtonNavigation aHelper( m_xComponent );
130 aReturn = aHelper.getCurrentButtonType();
132 break;
134 case PROPERTY_ID_TARGET_URL:
136 PushButtonNavigation aHelper( m_xComponent );
137 aReturn = aHelper.getCurrentTargetURL();
139 break;
141 default:
142 OSL_FAIL( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
143 break;
146 return aReturn;
149 //--------------------------------------------------------------------
150 void SAL_CALL ButtonNavigationHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
152 ::osl::MutexGuard aGuard( m_aMutex );
153 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
154 switch ( nPropId )
156 case PROPERTY_ID_BUTTONTYPE:
158 PushButtonNavigation aHelper( m_xComponent );
159 aHelper.setCurrentButtonType( _rValue );
161 break;
163 case PROPERTY_ID_TARGET_URL:
165 PushButtonNavigation aHelper( m_xComponent );
166 aHelper.setCurrentTargetURL( _rValue );
168 break;
170 default:
171 OSL_FAIL( "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
175 //--------------------------------------------------------------------
176 bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent )
178 Reference< XPropertySetInfo > xPSI;
179 if ( _rxComponent.is() )
180 xPSI = _rxComponent->getPropertySetInfo();
182 return xPSI.is()
183 && xPSI->hasPropertyByName( PROPERTY_TARGET_URL )
184 && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE );
187 //--------------------------------------------------------------------
188 Sequence< Property > SAL_CALL ButtonNavigationHandler::doDescribeSupportedProperties() const
190 ::std::vector< Property > aProperties;
192 if ( isNavigationCapableButton( m_xComponent ) )
194 addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL );
195 implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
198 if ( aProperties.empty() )
199 return Sequence< Property >();
200 return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
203 //--------------------------------------------------------------------
204 Sequence< OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( ) throw (RuntimeException)
206 Sequence< OUString > aActuating( 2 );
207 aActuating[0] = PROPERTY_BUTTONTYPE;
208 aActuating[1] = PROPERTY_TARGET_URL;
209 return aActuating;
212 //--------------------------------------------------------------------
213 InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
215 ::osl::MutexGuard aGuard( m_aMutex );
216 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
218 InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled );
220 switch ( nPropId )
222 case PROPERTY_ID_TARGET_URL:
223 eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
224 break;
225 default:
226 eReturn = ButtonNavigationHandler_Base::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
227 break;
230 return eReturn;
233 //--------------------------------------------------------------------
234 void SAL_CALL ButtonNavigationHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException)
236 ::osl::MutexGuard aGuard( m_aMutex );
237 PropertyId nPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
238 switch ( nPropId )
240 case PROPERTY_ID_BUTTONTYPE:
242 PushButtonNavigation aHelper( m_xComponent );
243 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() );
245 break;
247 case PROPERTY_ID_TARGET_URL:
249 PushButtonNavigation aHelper( m_xComponent );
250 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() );
252 break;
254 default:
255 OSL_FAIL( "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
259 //--------------------------------------------------------------------
260 LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
262 ::osl::MutexGuard aGuard( m_aMutex );
263 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
265 LineDescriptor aReturn;
267 switch ( nPropId )
269 case PROPERTY_ID_TARGET_URL:
270 aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory );
271 break;
272 default:
273 aReturn = ButtonNavigationHandler_Base::describePropertyLine( _rPropertyName, _rxControlFactory );
274 break;
277 return aReturn;
280 //........................................................................
281 } // namespace pcr
282 //........................................................................
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */