1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_extensions.hxx" 26 #include "buttonnavigationhandler.hxx" 27 #include "formstrings.hxx" 28 #include "formmetadata.hxx" 29 #include "pushbuttonnavigation.hxx" 30 31 /** === begin UNO includes === **/ 32 /** === end UNO includes === **/ 33 #include <tools/debug.hxx> 34 35 //------------------------------------------------------------------------ 36 extern "C" void SAL_CALL createRegistryInfo_ButtonNavigationHandler() 37 { 38 ::pcr::ButtonNavigationHandler::registerImplementation(); 39 } 40 41 //........................................................................ 42 namespace pcr 43 { 44 //........................................................................ 45 46 using namespace ::com::sun::star::uno; 47 using namespace ::com::sun::star::lang; 48 using namespace ::com::sun::star::beans; 49 using namespace ::com::sun::star::script; 50 using namespace ::com::sun::star::frame; 51 using namespace ::com::sun::star::inspection; 52 53 //==================================================================== 54 //= ButtonNavigationHandler 55 //==================================================================== 56 DBG_NAME( ButtonNavigationHandler ) 57 //-------------------------------------------------------------------- 58 ButtonNavigationHandler::ButtonNavigationHandler( const Reference< XComponentContext >& _rxContext ) 59 :ButtonNavigationHandler_Base( _rxContext ) 60 { 61 DBG_CTOR( ButtonNavigationHandler, NULL ); 62 63 m_aContext.createComponent( 64 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.FormComponentPropertyHandler" ) ), 65 m_xSlaveHandler ); 66 if ( !m_xSlaveHandler.is() ) 67 throw RuntimeException(); 68 } 69 70 //-------------------------------------------------------------------- 71 ButtonNavigationHandler::~ButtonNavigationHandler( ) 72 { 73 DBG_DTOR( ButtonNavigationHandler, NULL ); 74 } 75 76 //-------------------------------------------------------------------- 77 ::rtl::OUString SAL_CALL ButtonNavigationHandler::getImplementationName_static( ) throw (RuntimeException) 78 { 79 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.ButtonNavigationHandler" ) ); 80 } 81 82 //-------------------------------------------------------------------- 83 Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getSupportedServiceNames_static( ) throw (RuntimeException) 84 { 85 Sequence< ::rtl::OUString > aSupported( 1 ); 86 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.ButtonNavigationHandler" ) ); 87 return aSupported; 88 } 89 90 //-------------------------------------------------------------------- 91 void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException) 92 { 93 ButtonNavigationHandler_Base::inspect( _rxIntrospectee ); 94 m_xSlaveHandler->inspect( _rxIntrospectee ); 95 } 96 97 //-------------------------------------------------------------------- 98 PropertyState SAL_CALL ButtonNavigationHandler::getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException) 99 { 100 ::osl::MutexGuard aGuard( m_aMutex ); 101 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 102 PropertyState eState = PropertyState_DIRECT_VALUE; 103 switch ( nPropId ) 104 { 105 case PROPERTY_ID_BUTTONTYPE: 106 { 107 PushButtonNavigation aHelper( m_xComponent ); 108 eState = aHelper.getCurrentButtonTypeState(); 109 } 110 break; 111 case PROPERTY_ID_TARGET_URL: 112 { 113 PushButtonNavigation aHelper( m_xComponent ); 114 eState = aHelper.getCurrentTargetURLState(); 115 } 116 break; 117 118 default: 119 DBG_ERROR( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" ); 120 break; 121 } 122 123 return eState; 124 } 125 126 //-------------------------------------------------------------------- 127 Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException) 128 { 129 ::osl::MutexGuard aGuard( m_aMutex ); 130 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 131 132 Any aReturn; 133 switch ( nPropId ) 134 { 135 case PROPERTY_ID_BUTTONTYPE: 136 { 137 PushButtonNavigation aHelper( m_xComponent ); 138 aReturn = aHelper.getCurrentButtonType(); 139 } 140 break; 141 142 case PROPERTY_ID_TARGET_URL: 143 { 144 PushButtonNavigation aHelper( m_xComponent ); 145 aReturn = aHelper.getCurrentTargetURL(); 146 } 147 break; 148 149 default: 150 DBG_ERROR( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" ); 151 break; 152 } 153 154 return aReturn; 155 } 156 157 //-------------------------------------------------------------------- 158 void SAL_CALL ButtonNavigationHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException) 159 { 160 ::osl::MutexGuard aGuard( m_aMutex ); 161 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 162 switch ( nPropId ) 163 { 164 case PROPERTY_ID_BUTTONTYPE: 165 { 166 PushButtonNavigation aHelper( m_xComponent ); 167 aHelper.setCurrentButtonType( _rValue ); 168 } 169 break; 170 171 case PROPERTY_ID_TARGET_URL: 172 { 173 PushButtonNavigation aHelper( m_xComponent ); 174 aHelper.setCurrentTargetURL( _rValue ); 175 } 176 break; 177 178 default: 179 OSL_ENSURE( sal_False, "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" ); 180 } 181 } 182 183 //-------------------------------------------------------------------- 184 bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent ) 185 { 186 Reference< XPropertySetInfo > xPSI; 187 if ( _rxComponent.is() ) 188 xPSI = _rxComponent->getPropertySetInfo(); 189 190 return xPSI.is() 191 && xPSI->hasPropertyByName( PROPERTY_TARGET_URL ) 192 && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE ); 193 } 194 195 //-------------------------------------------------------------------- 196 Sequence< Property > SAL_CALL ButtonNavigationHandler::doDescribeSupportedProperties() const 197 { 198 ::std::vector< Property > aProperties; 199 200 if ( isNavigationCapableButton( m_xComponent ) ) 201 { 202 addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL ); 203 implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) ); 204 } 205 206 if ( aProperties.empty() ) 207 return Sequence< Property >(); 208 return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); 209 } 210 211 //-------------------------------------------------------------------- 212 Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( ) throw (RuntimeException) 213 { 214 Sequence< ::rtl::OUString > aActuating( 2 ); 215 aActuating[0] = PROPERTY_BUTTONTYPE; 216 aActuating[1] = PROPERTY_TARGET_URL; 217 return aActuating; 218 } 219 220 //-------------------------------------------------------------------- 221 InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException) 222 { 223 ::osl::MutexGuard aGuard( m_aMutex ); 224 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 225 226 InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled ); 227 228 switch ( nPropId ) 229 { 230 case PROPERTY_ID_TARGET_URL: 231 eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI ); 232 break; 233 default: 234 eReturn = ButtonNavigationHandler_Base::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI ); 235 break; 236 } 237 238 return eReturn; 239 } 240 241 //-------------------------------------------------------------------- 242 void SAL_CALL ButtonNavigationHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException) 243 { 244 ::osl::MutexGuard aGuard( m_aMutex ); 245 PropertyId nPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) ); 246 switch ( nPropId ) 247 { 248 case PROPERTY_ID_BUTTONTYPE: 249 { 250 PushButtonNavigation aHelper( m_xComponent ); 251 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() ); 252 } 253 break; 254 255 case PROPERTY_ID_TARGET_URL: 256 { 257 PushButtonNavigation aHelper( m_xComponent ); 258 _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() ); 259 } 260 break; 261 262 default: 263 OSL_ENSURE( sal_False, "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" ); 264 } 265 } 266 267 //-------------------------------------------------------------------- 268 LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory ) throw (UnknownPropertyException, NullPointerException, RuntimeException) 269 { 270 ::osl::MutexGuard aGuard( m_aMutex ); 271 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 272 273 LineDescriptor aReturn; 274 275 switch ( nPropId ) 276 { 277 case PROPERTY_ID_TARGET_URL: 278 aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory ); 279 break; 280 default: 281 aReturn = ButtonNavigationHandler_Base::describePropertyLine( _rPropertyName, _rxControlFactory ); 282 break; 283 } 284 285 return aReturn; 286 } 287 288 //........................................................................ 289 } // namespace pcr 290 //........................................................................ 291 292