1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 30*cdf0e10cSrcweir #include <toolkit/controls/formattedcontrol.hxx> 31*cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx> 32*cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 38*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 39*cdf0e10cSrcweir #include <osl/diagnose.h> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //........................................................................ 42*cdf0e10cSrcweir namespace toolkit 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir //........................................................................ 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 47*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 48*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 49*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 50*cdf0e10cSrcweir using namespace ::com::sun::star::util; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // ------------------------------------------------------------------- 53*cdf0e10cSrcweir namespace 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir // ............................................................... 56*cdf0e10cSrcweir ::osl::Mutex& getDefaultFormatsMutex() 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir static ::osl::Mutex s_aDefaultFormatsMutex; 59*cdf0e10cSrcweir return s_aDefaultFormatsMutex; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // ............................................................... 63*cdf0e10cSrcweir Reference< XNumberFormatsSupplier >& lcl_getDefaultFormatsAccess_nothrow() 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir static Reference< XNumberFormatsSupplier > s_xDefaultFormats; 66*cdf0e10cSrcweir return s_xDefaultFormats; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // ............................................................... 70*cdf0e10cSrcweir bool& lcl_getTriedCreation() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir static bool s_bTriedCreation = false; 73*cdf0e10cSrcweir return s_bTriedCreation; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // ............................................................... 77*cdf0e10cSrcweir const Reference< XNumberFormatsSupplier >& lcl_getDefaultFormats_throw() 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getDefaultFormatsMutex() ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir bool& rbTriedCreation = lcl_getTriedCreation(); 82*cdf0e10cSrcweir Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() ); 83*cdf0e10cSrcweir if ( !rDefaultFormats.is() && !rbTriedCreation ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir rbTriedCreation = true; 86*cdf0e10cSrcweir rDefaultFormats = Reference< XNumberFormatsSupplier >( 87*cdf0e10cSrcweir ::comphelper::createProcessComponent( 88*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatsSupplier" ) ) ), 89*cdf0e10cSrcweir UNO_QUERY_THROW 90*cdf0e10cSrcweir ); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir if ( !rDefaultFormats.is() ) 93*cdf0e10cSrcweir throw RuntimeException(); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir return rDefaultFormats; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // ............................................................... 99*cdf0e10cSrcweir static oslInterlockedCount s_refCount(0); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // ............................................................... 102*cdf0e10cSrcweir void lcl_registerDefaultFormatsClient() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir osl_incrementInterlockedCount( &s_refCount ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // ............................................................... 108*cdf0e10cSrcweir void lcl_revokeDefaultFormatsClient() 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( getDefaultFormatsMutex() ); 111*cdf0e10cSrcweir if ( 0 == osl_decrementInterlockedCount( &s_refCount ) ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() ); 114*cdf0e10cSrcweir Reference< XNumberFormatsSupplier > xReleasePotentialLastReference( rDefaultFormats ); 115*cdf0e10cSrcweir rDefaultFormats.clear(); 116*cdf0e10cSrcweir lcl_getTriedCreation() = false; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir aGuard.clear(); 119*cdf0e10cSrcweir xReleasePotentialLastReference.clear(); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // =================================================================== 125*cdf0e10cSrcweir // = UnoControlFormattedFieldModel 126*cdf0e10cSrcweir // =================================================================== 127*cdf0e10cSrcweir // ------------------------------------------------------------------- 128*cdf0e10cSrcweir UnoControlFormattedFieldModel::UnoControlFormattedFieldModel( const Reference< XMultiServiceFactory >& i_factory ) 129*cdf0e10cSrcweir :UnoControlModel( i_factory ) 130*cdf0e10cSrcweir ,m_bRevokedAsClient( false ) 131*cdf0e10cSrcweir ,m_bSettingValueAndText( false ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ALIGN ); 134*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); 135*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BORDER ); 136*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); 137*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); 138*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_DEFAULT ); 139*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_VALUE ); 140*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_MAX ); 141*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_MIN ); 142*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ENABLED ); 143*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); 144*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); 145*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_FORMATKEY ); 146*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_FORMATSSUPPLIER ); 147*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); 148*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPURL ); 149*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_MAXTEXTLEN ); 150*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); 151*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_REPEAT ); 152*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY ); 153*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_READONLY ); 154*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_SPIN ); 155*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_STRICTFORMAT ); 156*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TABSTOP ); 157*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TEXT ); 158*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR ); 159*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION ); 160*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ENFORCE_FORMAT ); 161*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN ); 162*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); 163*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); 164*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir Any aTreatAsNumber; 167*cdf0e10cSrcweir aTreatAsNumber <<= (sal_Bool) sal_True; 168*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREATASNUMBER, aTreatAsNumber ); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir lcl_registerDefaultFormatsClient(); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir // ------------------------------------------------------------------- 174*cdf0e10cSrcweir UnoControlFormattedFieldModel::~UnoControlFormattedFieldModel() 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // ------------------------------------------------------------------- 179*cdf0e10cSrcweir ::rtl::OUString UnoControlFormattedFieldModel::getServiceName() throw(RuntimeException) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFormattedFieldModel ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // ------------------------------------------------------------------- 185*cdf0e10cSrcweir void SAL_CALL UnoControlFormattedFieldModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir switch ( nHandle ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir case BASEPROPERTY_EFFECTIVE_VALUE: 192*cdf0e10cSrcweir if ( !m_bSettingValueAndText ) 193*cdf0e10cSrcweir impl_updateTextFromValue_nothrow(); 194*cdf0e10cSrcweir break; 195*cdf0e10cSrcweir case BASEPROPERTY_FORMATSSUPPLIER: 196*cdf0e10cSrcweir impl_updateCachedFormatter_nothrow(); 197*cdf0e10cSrcweir impl_updateTextFromValue_nothrow(); 198*cdf0e10cSrcweir break; 199*cdf0e10cSrcweir case BASEPROPERTY_FORMATKEY: 200*cdf0e10cSrcweir impl_updateCachedFormatKey_nothrow(); 201*cdf0e10cSrcweir impl_updateTextFromValue_nothrow(); 202*cdf0e10cSrcweir break; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // ------------------------------------------------------------------- 207*cdf0e10cSrcweir void UnoControlFormattedFieldModel::impl_updateTextFromValue_nothrow() 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir if ( !m_xCachedFormatter.is() ) 210*cdf0e10cSrcweir impl_updateCachedFormatter_nothrow(); 211*cdf0e10cSrcweir if ( !m_xCachedFormatter.is() ) 212*cdf0e10cSrcweir return; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir try 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir Any aEffectiveValue; 217*cdf0e10cSrcweir getFastPropertyValue( aEffectiveValue, BASEPROPERTY_EFFECTIVE_VALUE ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir ::rtl::OUString sStringValue; 220*cdf0e10cSrcweir if ( !( aEffectiveValue >>= sStringValue ) ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir double nDoubleValue(0); 223*cdf0e10cSrcweir if ( aEffectiveValue >>= nDoubleValue ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir sal_Int32 nFormatKey( 0 ); 226*cdf0e10cSrcweir if ( m_aCachedFormat.hasValue() ) 227*cdf0e10cSrcweir m_aCachedFormat >>= nFormatKey; 228*cdf0e10cSrcweir sStringValue = m_xCachedFormatter->convertNumberToString( nFormatKey, nDoubleValue ); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir Reference< XPropertySet > xThis( *this, UNO_QUERY ); 233*cdf0e10cSrcweir xThis->setPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), makeAny( sStringValue ) ); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir catch( const Exception& ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir // ------------------------------------------------------------------- 242*cdf0e10cSrcweir void UnoControlFormattedFieldModel::impl_updateCachedFormatter_nothrow() 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir Any aFormatsSupplier; 245*cdf0e10cSrcweir getFastPropertyValue( aFormatsSupplier, BASEPROPERTY_FORMATSSUPPLIER ); 246*cdf0e10cSrcweir try 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir Reference< XNumberFormatsSupplier > xSupplier( aFormatsSupplier, UNO_QUERY ); 249*cdf0e10cSrcweir if ( !xSupplier.is() ) 250*cdf0e10cSrcweir xSupplier = lcl_getDefaultFormats_throw(); 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir if ( !m_xCachedFormatter.is() ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir m_xCachedFormatter = Reference< XNumberFormatter >( 255*cdf0e10cSrcweir ::comphelper::createProcessComponent( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatter" ) ) ), 256*cdf0e10cSrcweir UNO_QUERY_THROW 257*cdf0e10cSrcweir ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir m_xCachedFormatter->attachNumberFormatsSupplier( xSupplier ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir catch( const Exception& ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir // ------------------------------------------------------------------- 268*cdf0e10cSrcweir void UnoControlFormattedFieldModel::impl_updateCachedFormatKey_nothrow() 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir Any aFormatKey; 271*cdf0e10cSrcweir getFastPropertyValue( aFormatKey, BASEPROPERTY_FORMATKEY ); 272*cdf0e10cSrcweir m_aCachedFormat = aFormatKey; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // ------------------------------------------------------------------- 276*cdf0e10cSrcweir void UnoControlFormattedFieldModel::dispose( ) throw(RuntimeException) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir UnoControlModel::dispose(); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir ::osl::MutexGuard aGuard( GetMutex() ); 281*cdf0e10cSrcweir if ( !m_bRevokedAsClient ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir lcl_revokeDefaultFormatsClient(); 284*cdf0e10cSrcweir m_bRevokedAsClient = true; 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir // ------------------------------------------------------------------- 289*cdf0e10cSrcweir void UnoControlFormattedFieldModel::ImplNormalizePropertySequence( const sal_Int32 _nCount, sal_Int32* _pHandles, 290*cdf0e10cSrcweir Any* _pValues, sal_Int32* _pValidHandles ) const SAL_THROW(()) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir ImplEnsureHandleOrder( _nCount, _pHandles, _pValues, BASEPROPERTY_EFFECTIVE_VALUE, BASEPROPERTY_TEXT ); 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir UnoControlModel::ImplNormalizePropertySequence( _nCount, _pHandles, _pValues, _pValidHandles ); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir // ------------------------------------------------------------------- 298*cdf0e10cSrcweir namespace 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir class ResetFlagOnExit 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir private: 303*cdf0e10cSrcweir bool& m_rFlag; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir public: 306*cdf0e10cSrcweir ResetFlagOnExit( bool& _rFlag ) 307*cdf0e10cSrcweir :m_rFlag( _rFlag ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir ~ResetFlagOnExit() 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir m_rFlag = false; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir }; 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir // ------------------------------------------------------------------- 318*cdf0e10cSrcweir void SAL_CALL UnoControlFormattedFieldModel::setPropertyValues( const Sequence< ::rtl::OUString >& _rPropertyNames, const Sequence< Any >& _rValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir bool bSettingValue = false; 321*cdf0e10cSrcweir bool bSettingText = false; 322*cdf0e10cSrcweir for ( const ::rtl::OUString* pPropertyNames = _rPropertyNames.getConstArray(); 323*cdf0e10cSrcweir pPropertyNames != _rPropertyNames.getConstArray() + _rPropertyNames.getLength(); 324*cdf0e10cSrcweir ++pPropertyNames 325*cdf0e10cSrcweir ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir if ( BASEPROPERTY_EFFECTIVE_VALUE == GetPropertyId( *pPropertyNames ) ) 328*cdf0e10cSrcweir bSettingValue = true; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir if ( BASEPROPERTY_TEXT == GetPropertyId( *pPropertyNames ) ) 331*cdf0e10cSrcweir bSettingText = true; 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir m_bSettingValueAndText = ( bSettingValue && bSettingText ); 335*cdf0e10cSrcweir ResetFlagOnExit aResetFlag( m_bSettingValueAndText ); 336*cdf0e10cSrcweir UnoControlModel::setPropertyValues( _rPropertyNames, _rValues ); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir // ------------------------------------------------------------------- 340*cdf0e10cSrcweir sal_Bool UnoControlFormattedFieldModel::convertFastPropertyValue( 341*cdf0e10cSrcweir Any& rConvertedValue, Any& rOldValue, sal_Int32 nPropId, 342*cdf0e10cSrcweir const Any& rValue ) throw (IllegalArgumentException) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir if ( BASEPROPERTY_EFFECTIVE_DEFAULT == nPropId && rValue.hasValue() ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir double dVal = 0; 347*cdf0e10cSrcweir sal_Int32 nVal = 0; 348*cdf0e10cSrcweir ::rtl::OUString sVal; 349*cdf0e10cSrcweir sal_Bool bStreamed = (rValue >>= dVal); 350*cdf0e10cSrcweir if ( bStreamed ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir rConvertedValue <<= dVal; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir else 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir bStreamed = (rValue >>= nVal); 357*cdf0e10cSrcweir if ( bStreamed ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir rConvertedValue <<= static_cast<double>(nVal); 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir else 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir bStreamed = (rValue >>= sVal); 364*cdf0e10cSrcweir if ( bStreamed ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir rConvertedValue <<= sVal; 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir if ( bStreamed ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir getFastPropertyValue( rOldValue, nPropId ); 374*cdf0e10cSrcweir return !CompareProperties( rConvertedValue, rOldValue ); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir throw IllegalArgumentException( 378*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii("Unable to convert the given value for the property ") 379*cdf0e10cSrcweir += GetPropertyName((sal_uInt16)nPropId) ) 380*cdf0e10cSrcweir += ::rtl::OUString::createFromAscii(" (double, integer, or string expected)."), 381*cdf0e10cSrcweir static_cast< XPropertySet* >(this), 382*cdf0e10cSrcweir 1); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir return UnoControlModel::convertFastPropertyValue( rConvertedValue, rOldValue, nPropId, rValue ); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir // ------------------------------------------------------------------- 389*cdf0e10cSrcweir Any UnoControlFormattedFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir Any aReturn; 392*cdf0e10cSrcweir switch (nPropId) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir case BASEPROPERTY_DEFAULTCONTROL: aReturn <<= ::rtl::OUString( ::rtl::OUString::createFromAscii( szServiceName_UnoControlFormattedField ) ); break; 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir case BASEPROPERTY_TREATASNUMBER: aReturn <<= (sal_Bool)sal_True; break; 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir case BASEPROPERTY_EFFECTIVE_DEFAULT: 399*cdf0e10cSrcweir case BASEPROPERTY_EFFECTIVE_VALUE: 400*cdf0e10cSrcweir case BASEPROPERTY_EFFECTIVE_MAX: 401*cdf0e10cSrcweir case BASEPROPERTY_EFFECTIVE_MIN: 402*cdf0e10cSrcweir case BASEPROPERTY_FORMATKEY: 403*cdf0e10cSrcweir case BASEPROPERTY_FORMATSSUPPLIER: 404*cdf0e10cSrcweir // (void) 405*cdf0e10cSrcweir break; 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir default : aReturn = UnoControlModel::ImplGetDefaultValue( nPropId ); break; 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir return aReturn; 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir // ------------------------------------------------------------------- 414*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoControlFormattedFieldModel::getInfoHelper() 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir static UnoPropertyArrayHelper* pHelper = NULL; 417*cdf0e10cSrcweir if ( !pHelper ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 420*cdf0e10cSrcweir pHelper = new UnoPropertyArrayHelper( aIDs ); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir return *pHelper; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir // beans::XMultiPropertySet 426*cdf0e10cSrcweir // ------------------------------------------------------------------- 427*cdf0e10cSrcweir Reference< XPropertySetInfo > UnoControlFormattedFieldModel::getPropertySetInfo( ) throw(RuntimeException) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 430*cdf0e10cSrcweir return xInfo; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir // =================================================================== 434*cdf0e10cSrcweir // = UnoFormattedFieldControl 435*cdf0e10cSrcweir // =================================================================== 436*cdf0e10cSrcweir // ------------------------------------------------------------------- 437*cdf0e10cSrcweir UnoFormattedFieldControl::UnoFormattedFieldControl( const Reference< XMultiServiceFactory >& i_factory ) 438*cdf0e10cSrcweir :UnoSpinFieldControl( i_factory ) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir // ------------------------------------------------------------------- 443*cdf0e10cSrcweir ::rtl::OUString UnoFormattedFieldControl::GetComponentServiceName() 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "FormattedField" ); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir // ------------------------------------------------------------------- 449*cdf0e10cSrcweir void UnoFormattedFieldControl::textChanged(const TextEvent& e) throw(RuntimeException) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir Reference< XVclWindowPeer > xPeer(getPeer(), UNO_QUERY); 452*cdf0e10cSrcweir OSL_ENSURE(xPeer.is(), "UnoFormattedFieldControl::textChanged : what kind of peer do I have ?"); 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( 2 ); 455*cdf0e10cSrcweir aNames[0] = GetPropertyName( BASEPROPERTY_EFFECTIVE_VALUE ); 456*cdf0e10cSrcweir aNames[1] = GetPropertyName( BASEPROPERTY_TEXT ); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir Sequence< Any > aValues( 2 ); 459*cdf0e10cSrcweir aValues[0] = xPeer->getProperty( aNames[0] ); 460*cdf0e10cSrcweir aValues[1] = xPeer->getProperty( aNames[1] ); 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir ImplSetPropertyValues( aNames, aValues, sal_False ); 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir if ( GetTextListeners().getLength() ) 465*cdf0e10cSrcweir GetTextListeners().textChanged( e ); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir //........................................................................ 469*cdf0e10cSrcweir } // namespace toolkit 470*cdf0e10cSrcweir //........................................................................ 471