12a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 52a97ec55SAndrew Rist * distributed with this work for additional information 62a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 72a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 82a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 92a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 112a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 132a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 142a97ec55SAndrew Rist * software distributed under the License is distributed on an 152a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 172a97ec55SAndrew Rist * specific language governing permissions and limitations 182a97ec55SAndrew Rist * under the License. 19cdf0e10cSrcweir * 202a97ec55SAndrew Rist *************************************************************/ 212a97ec55SAndrew Rist 222a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir #include "editpropertyhandler.hxx" 27cdf0e10cSrcweir #include "formstrings.hxx" 28cdf0e10cSrcweir #include "formmetadata.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** === begin UNO includes === **/ 31cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp> 32cdf0e10cSrcweir /** === end UNO includes === **/ 33cdf0e10cSrcweir #include <tools/debug.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #define TEXTTYPE_SINGLELINE 0 36cdf0e10cSrcweir #define TEXTTYPE_MULTILINE 1 37cdf0e10cSrcweir #define TEXTTYPE_RICHTEXT 2 38cdf0e10cSrcweir 39cdf0e10cSrcweir //------------------------------------------------------------------------ 40cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_EditPropertyHandler() 41cdf0e10cSrcweir { 42cdf0e10cSrcweir ::pcr::EditPropertyHandler::registerImplementation(); 43cdf0e10cSrcweir } 44cdf0e10cSrcweir 45cdf0e10cSrcweir //........................................................................ 46cdf0e10cSrcweir namespace pcr 47cdf0e10cSrcweir { 48cdf0e10cSrcweir //........................................................................ 49cdf0e10cSrcweir 50cdf0e10cSrcweir using namespace ::com::sun::star::uno; 51cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52cdf0e10cSrcweir using namespace ::com::sun::star::beans; 53cdf0e10cSrcweir using namespace ::com::sun::star::script; 54cdf0e10cSrcweir using namespace ::com::sun::star::frame; 55cdf0e10cSrcweir using namespace ::com::sun::star::inspection; 56cdf0e10cSrcweir 57cdf0e10cSrcweir //==================================================================== 58cdf0e10cSrcweir //= EditPropertyHandler 59cdf0e10cSrcweir //==================================================================== 60cdf0e10cSrcweir DBG_NAME( EditPropertyHandler ) 61cdf0e10cSrcweir //-------------------------------------------------------------------- 62cdf0e10cSrcweir EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext ) 63cdf0e10cSrcweir :EditPropertyHandler_Base( _rxContext ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir DBG_CTOR( EditPropertyHandler, NULL ); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir //-------------------------------------------------------------------- 69cdf0e10cSrcweir EditPropertyHandler::~EditPropertyHandler( ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir DBG_DTOR( EditPropertyHandler, NULL ); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir //-------------------------------------------------------------------- 75cdf0e10cSrcweir ::rtl::OUString SAL_CALL EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EditPropertyHandler" ) ); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir //-------------------------------------------------------------------- 81cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported( 1 ); 84cdf0e10cSrcweir aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EditPropertyHandler" ) ); 85cdf0e10cSrcweir return aSupported; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir //-------------------------------------------------------------------- 89cdf0e10cSrcweir Any SAL_CALL EditPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 92cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir Any aReturn; 95cdf0e10cSrcweir try 96cdf0e10cSrcweir { 97cdf0e10cSrcweir switch ( nPropId ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir case PROPERTY_ID_SHOW_SCROLLBARS: 100cdf0e10cSrcweir { 101cdf0e10cSrcweir sal_Bool bHasVScroll = sal_False; 102cdf0e10cSrcweir m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll; 103cdf0e10cSrcweir sal_Bool bHasHScroll = sal_False; 104cdf0e10cSrcweir m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll; 105cdf0e10cSrcweir 106cdf0e10cSrcweir aReturn <<= (sal_Int32)( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) ); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir break; 109cdf0e10cSrcweir 110cdf0e10cSrcweir case PROPERTY_ID_TEXTTYPE: 111cdf0e10cSrcweir { 112cdf0e10cSrcweir sal_Int32 nTextType = TEXTTYPE_SINGLELINE; 113cdf0e10cSrcweir sal_Bool bRichText = sal_False; 114cdf0e10cSrcweir OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText ); 115cdf0e10cSrcweir if ( bRichText ) 116cdf0e10cSrcweir nTextType = TEXTTYPE_RICHTEXT; 117cdf0e10cSrcweir else 118cdf0e10cSrcweir { 119cdf0e10cSrcweir sal_Bool bMultiLine = sal_False; 120cdf0e10cSrcweir OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine ); 121cdf0e10cSrcweir if ( bMultiLine ) 122cdf0e10cSrcweir nTextType = TEXTTYPE_MULTILINE; 123cdf0e10cSrcweir else 124cdf0e10cSrcweir nTextType = TEXTTYPE_SINGLELINE; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir aReturn <<= nTextType; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir break; 129cdf0e10cSrcweir 130cdf0e10cSrcweir 131cdf0e10cSrcweir default: 132cdf0e10cSrcweir DBG_ERROR( "EditPropertyHandler::getPropertyValue: cannot handle this property!" ); 133cdf0e10cSrcweir break; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir catch( const Exception& ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir OSL_ENSURE( sal_False, "EditPropertyHandler::getPropertyValue: caught an exception!" ); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir return aReturn; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir //-------------------------------------------------------------------- 145cdf0e10cSrcweir void SAL_CALL EditPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 148cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir try 151cdf0e10cSrcweir { 152cdf0e10cSrcweir switch ( nPropId ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir case PROPERTY_ID_SHOW_SCROLLBARS: 155cdf0e10cSrcweir { 156cdf0e10cSrcweir sal_Int32 nScrollbars = 0; 157cdf0e10cSrcweir _rValue >>= nScrollbars; 158cdf0e10cSrcweir 159cdf0e10cSrcweir sal_Bool bHasVScroll = 0 != ( nScrollbars & 2 ); 160cdf0e10cSrcweir sal_Bool bHasHScroll = 0 != ( nScrollbars & 1 ); 161cdf0e10cSrcweir 162cdf0e10cSrcweir m_xComponent->setPropertyValue( PROPERTY_VSCROLL, makeAny( (sal_Bool)bHasVScroll ) ); 163cdf0e10cSrcweir m_xComponent->setPropertyValue( PROPERTY_HSCROLL, makeAny( (sal_Bool)bHasHScroll ) ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir break; 166cdf0e10cSrcweir 167cdf0e10cSrcweir case PROPERTY_ID_TEXTTYPE: 168cdf0e10cSrcweir { 169cdf0e10cSrcweir sal_Bool bMultiLine = sal_False; 170cdf0e10cSrcweir sal_Bool bRichText = sal_False; 171cdf0e10cSrcweir sal_Int32 nTextType = TEXTTYPE_SINGLELINE; 172cdf0e10cSrcweir OSL_VERIFY( _rValue >>= nTextType ); 173cdf0e10cSrcweir switch ( nTextType ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir case TEXTTYPE_SINGLELINE: bMultiLine = bRichText = sal_False; break; 176cdf0e10cSrcweir case TEXTTYPE_MULTILINE: bMultiLine = sal_True; bRichText = sal_False; break; 177cdf0e10cSrcweir case TEXTTYPE_RICHTEXT: bMultiLine = sal_True; bRichText = sal_True; break; 178cdf0e10cSrcweir default: 179cdf0e10cSrcweir OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: invalid text type!" ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir m_xComponent->setPropertyValue( PROPERTY_MULTILINE, makeAny( bMultiLine ) ); 183cdf0e10cSrcweir m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, makeAny( bRichText ) ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir break; 186cdf0e10cSrcweir 187cdf0e10cSrcweir default: 188cdf0e10cSrcweir OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: cannot handle this id!" ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir catch( const Exception& ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: caught an exception!" ); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir //-------------------------------------------------------------------- 198cdf0e10cSrcweir bool EditPropertyHandler::implHaveBothScrollBarProperties() const 199cdf0e10cSrcweir { 200cdf0e10cSrcweir // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll" 201cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI; 202cdf0e10cSrcweir if ( m_xComponent.is() ) 203cdf0e10cSrcweir xPSI = m_xComponent->getPropertySetInfo(); 204cdf0e10cSrcweir 205cdf0e10cSrcweir return xPSI.is() 206cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_HSCROLL ) 207cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_VSCROLL ); 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir //-------------------------------------------------------------------- 211cdf0e10cSrcweir bool EditPropertyHandler::implHaveTextTypeProperty() const 212cdf0e10cSrcweir { 213cdf0e10cSrcweir // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll" 214cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI; 215cdf0e10cSrcweir if ( m_xComponent.is() ) 216cdf0e10cSrcweir xPSI = m_xComponent->getPropertySetInfo(); 217cdf0e10cSrcweir 218cdf0e10cSrcweir return xPSI.is() 219cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_RICHTEXT ) 220cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_MULTILINE ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir //-------------------------------------------------------------------- 224cdf0e10cSrcweir Sequence< Property > SAL_CALL EditPropertyHandler::doDescribeSupportedProperties() const 225cdf0e10cSrcweir { 226cdf0e10cSrcweir ::std::vector< Property > aProperties; 227cdf0e10cSrcweir 228cdf0e10cSrcweir if ( implHaveBothScrollBarProperties() ) 229cdf0e10cSrcweir addInt32PropertyDescription( aProperties, PROPERTY_SHOW_SCROLLBARS ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir if ( implHaveTextTypeProperty() ) 232cdf0e10cSrcweir addInt32PropertyDescription( aProperties, PROPERTY_TEXTTYPE ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir if ( aProperties.empty() ) 235cdf0e10cSrcweir return Sequence< Property >(); 236cdf0e10cSrcweir return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir 239cdf0e10cSrcweir //-------------------------------------------------------------------- 240cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 243cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aSuperseded; 244cdf0e10cSrcweir if ( implHaveBothScrollBarProperties() ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir aSuperseded.push_back( PROPERTY_HSCROLL ); 247cdf0e10cSrcweir aSuperseded.push_back( PROPERTY_VSCROLL ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir if ( implHaveTextTypeProperty() ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir aSuperseded.push_back( PROPERTY_RICHTEXT ); 252cdf0e10cSrcweir aSuperseded.push_back( PROPERTY_MULTILINE ); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir if ( aSuperseded.empty() ) 255cdf0e10cSrcweir return Sequence< ::rtl::OUString >(); 256cdf0e10cSrcweir return Sequence< ::rtl::OUString >( &(*aSuperseded.begin()), aSuperseded.size() ); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir //-------------------------------------------------------------------- 260cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 263cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aInterestingActuatingProps; 264cdf0e10cSrcweir if ( implHaveTextTypeProperty() ) 265cdf0e10cSrcweir aInterestingActuatingProps.push_back( PROPERTY_TEXTTYPE ); 266cdf0e10cSrcweir aInterestingActuatingProps.push_back( PROPERTY_MULTILINE ); 267*be099857Smseidel return Sequence< ::rtl::OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() ); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir //-------------------------------------------------------------------- 271cdf0e10cSrcweir void SAL_CALL EditPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir if ( !_rxInspectorUI.is() ) 274cdf0e10cSrcweir throw NullPointerException(); 275cdf0e10cSrcweir 276cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 277cdf0e10cSrcweir PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) ); 278cdf0e10cSrcweir switch ( nActuatingPropId ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir case PROPERTY_ID_TEXTTYPE: 281cdf0e10cSrcweir { 282cdf0e10cSrcweir sal_Int32 nTextType = TEXTTYPE_SINGLELINE; 283cdf0e10cSrcweir getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextType; 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK ) ) 286cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_WORDBREAK, nTextType == TEXTTYPE_RICHTEXT ); 287cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_MAXTEXTLEN, nTextType != TEXTTYPE_RICHTEXT ); 288cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, nTextType == TEXTTYPE_SINGLELINE ); 289cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_FONT, nTextType != TEXTTYPE_RICHTEXT ); 290cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_ALIGN, nTextType != TEXTTYPE_RICHTEXT ); 291cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_DEFAULT_TEXT, nTextType != TEXTTYPE_RICHTEXT ); 292cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, nTextType != TEXTTYPE_SINGLELINE ); 293cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, nTextType != TEXTTYPE_SINGLELINE ); 294cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_VERTICAL_ALIGN, nTextType == TEXTTYPE_SINGLELINE ); 295cdf0e10cSrcweir 296cdf0e10cSrcweir _rxInspectorUI->showCategory( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), nTextType != TEXTTYPE_RICHTEXT ); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir break; 299cdf0e10cSrcweir 300cdf0e10cSrcweir case PROPERTY_ID_MULTILINE: 301cdf0e10cSrcweir { 302cdf0e10cSrcweir sal_Bool bIsMultiline = sal_False; 303cdf0e10cSrcweir _rNewValue >>= bIsMultiline; 304cdf0e10cSrcweir 305cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline ); 306cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline ); 307cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline ); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir break; 310cdf0e10cSrcweir 311cdf0e10cSrcweir default: 312cdf0e10cSrcweir OSL_ENSURE( sal_False, "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" ); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir //........................................................................ 317cdf0e10cSrcweir } // namespace pcr 318cdf0e10cSrcweir //........................................................................ 319