1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_forms.hxx" 30 31 #ifndef FORMS_SOURCE_RICHTEXT_RICHTEXTMODEL_CXX 32 #include "richtextmodel.hxx" 33 #endif 34 #include "richtextengine.hxx" 35 #include "richtextunowrapper.hxx" 36 37 /** === begin UNO includes === **/ 38 #include <com/sun/star/awt/LineEndFormat.hpp> 39 #include <com/sun/star/text/WritingMode2.hpp> 40 #include <com/sun/star/style/VerticalAlignment.hpp> 41 /** === end UNO includes === **/ 42 43 #include <cppuhelper/typeprovider.hxx> 44 #include <comphelper/guarding.hxx> 45 #include <toolkit/awt/vclxdevice.hxx> 46 #include <toolkit/helper/vclunohelper.hxx> 47 #include <editeng/editstat.hxx> 48 #include <vcl/outdev.hxx> 49 #include <vcl/svapp.hxx> 50 51 //-------------------------------------------------------------------------- 52 extern "C" void SAL_CALL createRegistryInfo_ORichTextModel() 53 { 54 static ::frm::OMultiInstanceAutoRegistration< ::frm::ORichTextModel > aRegisterModel; 55 } 56 57 //........................................................................ 58 namespace frm 59 { 60 //........................................................................ 61 62 using namespace ::com::sun::star::uno; 63 using namespace ::com::sun::star::awt; 64 using namespace ::com::sun::star::lang; 65 using namespace ::com::sun::star::io; 66 using namespace ::com::sun::star::beans; 67 using namespace ::com::sun::star::form; 68 using namespace ::com::sun::star::util; 69 using namespace ::com::sun::star::style; 70 71 namespace WritingMode2 = ::com::sun::star::text::WritingMode2; 72 73 //==================================================================== 74 //= ORichTextModel 75 //==================================================================== 76 DBG_NAME( ORichTextModel ) 77 //-------------------------------------------------------------------- 78 ORichTextModel::ORichTextModel( const Reference< XMultiServiceFactory >& _rxFactory ) 79 :OControlModel ( _rxFactory, ::rtl::OUString() ) 80 ,FontControlModel ( true ) 81 ,m_pEngine ( RichTextEngine::Create() ) 82 ,m_bSettingEngineText( false ) 83 ,m_aModifyListeners ( m_aMutex ) 84 { 85 DBG_CTOR( ORichTextModel, NULL ); 86 m_nClassId = FormComponentType::TEXTFIELD; 87 88 getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL ) >>= m_sDefaultControl; 89 getPropertyDefaultByHandle( PROPERTY_ID_BORDER ) >>= m_nBorder; 90 getPropertyDefaultByHandle( PROPERTY_ID_ENABLED ) >>= m_bEnabled; 91 getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE ) >>= m_bEnableVisible; 92 getPropertyDefaultByHandle( PROPERTY_ID_HARDLINEBREAKS ) >>= m_bHardLineBreaks; 93 getPropertyDefaultByHandle( PROPERTY_ID_HSCROLL ) >>= m_bHScroll; 94 getPropertyDefaultByHandle( PROPERTY_ID_VSCROLL ) >>= m_bVScroll; 95 getPropertyDefaultByHandle( PROPERTY_ID_READONLY ) >>= m_bReadonly; 96 getPropertyDefaultByHandle( PROPERTY_ID_PRINTABLE ) >>= m_bPrintable; 97 getPropertyDefaultByHandle( PROPERTY_ID_ALIGN ) >>= m_aAlign; 98 getPropertyDefaultByHandle( PROPERTY_ID_ECHO_CHAR ) >>= m_nEchoChar; 99 getPropertyDefaultByHandle( PROPERTY_ID_MAXTEXTLEN ) >>= m_nMaxTextLength; 100 getPropertyDefaultByHandle( PROPERTY_ID_MULTILINE ) >>= m_bMultiLine; 101 getPropertyDefaultByHandle( PROPERTY_ID_RICH_TEXT ) >>= m_bReallyActAsRichText; 102 getPropertyDefaultByHandle( PROPERTY_ID_HIDEINACTIVESELECTION ) >>= m_bHideInactiveSelection; 103 getPropertyDefaultByHandle( PROPERTY_ID_LINEEND_FORMAT ) >>= m_nLineEndFormat; 104 getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE ) >>= m_nTextWritingMode; 105 getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE ) >>= m_nContextWritingMode; 106 107 implInit(); 108 } 109 110 //------------------------------------------------------------------ 111 ORichTextModel::ORichTextModel( const ORichTextModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory ) 112 :OControlModel ( _pOriginal, _rxFactory, sal_False ) 113 ,FontControlModel ( _pOriginal ) 114 ,m_pEngine ( NULL ) 115 ,m_bSettingEngineText( false ) 116 ,m_aModifyListeners ( m_aMutex ) 117 { 118 DBG_CTOR( ORichTextModel, NULL ); 119 120 m_aTabStop = _pOriginal->m_aTabStop; 121 m_aBackgroundColor = _pOriginal->m_aBackgroundColor; 122 m_aBorderColor = _pOriginal->m_aBorderColor; 123 m_aVerticalAlignment = _pOriginal->m_aVerticalAlignment; 124 m_sDefaultControl = _pOriginal->m_sDefaultControl; 125 m_sHelpText = _pOriginal->m_sHelpText; 126 m_sHelpURL = _pOriginal->m_sHelpURL; 127 m_nBorder = _pOriginal->m_nBorder; 128 m_bEnabled = _pOriginal->m_bEnabled; 129 m_bEnableVisible = _pOriginal->m_bEnableVisible; 130 m_bHardLineBreaks = _pOriginal->m_bHardLineBreaks; 131 m_bHScroll = _pOriginal->m_bHScroll; 132 m_bVScroll = _pOriginal->m_bVScroll; 133 m_bReadonly = _pOriginal->m_bReadonly; 134 m_bPrintable = _pOriginal->m_bPrintable; 135 m_bReallyActAsRichText = _pOriginal->m_bReallyActAsRichText; 136 m_bHideInactiveSelection = _pOriginal->m_bHideInactiveSelection; 137 m_nLineEndFormat = _pOriginal->m_nLineEndFormat; 138 m_nTextWritingMode = _pOriginal->m_nTextWritingMode; 139 m_nContextWritingMode = _pOriginal->m_nContextWritingMode; 140 141 m_aAlign = _pOriginal->m_aAlign; 142 m_nEchoChar = _pOriginal->m_nEchoChar; 143 m_nMaxTextLength = _pOriginal->m_nMaxTextLength; 144 m_bMultiLine = _pOriginal->m_bMultiLine; 145 146 m_pEngine.reset(_pOriginal->m_pEngine->Clone()); 147 m_sLastKnownEngineText = m_pEngine->GetText(); 148 149 implInit(); 150 } 151 152 //------------------------------------------------------------------ 153 void ORichTextModel::implInit() 154 { 155 OSL_ENSURE( m_pEngine.get(), "ORichTextModel::implInit: where's the engine?" ); 156 if ( m_pEngine.get() ) 157 { 158 m_pEngine->SetModifyHdl( LINK( this, ORichTextModel, OnEngineContentModified ) ); 159 160 sal_uLong nEngineControlWord = m_pEngine->GetControlWord(); 161 nEngineControlWord = nEngineControlWord & ~EE_CNTRL_AUTOPAGESIZE; 162 m_pEngine->SetControlWord( nEngineControlWord ); 163 164 VCLXDevice* pUnoRefDevice = new VCLXDevice; 165 pUnoRefDevice->SetOutputDevice( m_pEngine->GetRefDevice() ); 166 m_xReferenceDevice = pUnoRefDevice; 167 } 168 169 implDoAggregation(); 170 implRegisterProperties(); 171 } 172 173 //------------------------------------------------------------------ 174 void ORichTextModel::implDoAggregation() 175 { 176 increment( m_refCount ); 177 178 { 179 m_xAggregate = new ORichTextUnoWrapper( *m_pEngine, this ); 180 setAggregation( m_xAggregate ); 181 doSetDelegator(); 182 } 183 184 decrement( m_refCount ); 185 } 186 187 //------------------------------------------------------------------ 188 void ORichTextModel::implRegisterProperties() 189 { 190 REGISTER_PROP_2( DEFAULTCONTROL, m_sDefaultControl, BOUND, MAYBEDEFAULT ); 191 REGISTER_PROP_2( HELPTEXT, m_sHelpText, BOUND, MAYBEDEFAULT ); 192 REGISTER_PROP_2( HELPURL, m_sHelpURL, BOUND, MAYBEDEFAULT ); 193 REGISTER_PROP_2( ENABLED, m_bEnabled, BOUND, MAYBEDEFAULT ); 194 REGISTER_PROP_2( ENABLEVISIBLE, m_bEnableVisible, BOUND, MAYBEDEFAULT ); 195 REGISTER_PROP_2( BORDER, m_nBorder, BOUND, MAYBEDEFAULT ); 196 REGISTER_PROP_2( HARDLINEBREAKS, m_bHardLineBreaks, BOUND, MAYBEDEFAULT ); 197 REGISTER_PROP_2( HSCROLL, m_bHScroll, BOUND, MAYBEDEFAULT ); 198 REGISTER_PROP_2( VSCROLL, m_bVScroll, BOUND, MAYBEDEFAULT ); 199 REGISTER_PROP_2( READONLY, m_bReadonly, BOUND, MAYBEDEFAULT ); 200 REGISTER_PROP_2( PRINTABLE, m_bPrintable, BOUND, MAYBEDEFAULT ); 201 REGISTER_PROP_2( REFERENCE_DEVICE, m_xReferenceDevice, BOUND, TRANSIENT ); 202 REGISTER_PROP_2( RICH_TEXT, m_bReallyActAsRichText, BOUND, MAYBEDEFAULT ); 203 REGISTER_PROP_2( HIDEINACTIVESELECTION, m_bHideInactiveSelection, BOUND, MAYBEDEFAULT ); 204 205 REGISTER_VOID_PROP_2( TABSTOP, m_aTabStop, sal_Bool, BOUND, MAYBEDEFAULT ); 206 REGISTER_VOID_PROP_2( BACKGROUNDCOLOR, m_aBackgroundColor, sal_Int32, BOUND, MAYBEDEFAULT ); 207 REGISTER_VOID_PROP_2( BORDERCOLOR, m_aBorderColor, sal_Int32, BOUND, MAYBEDEFAULT ); 208 REGISTER_VOID_PROP_2( VERTICAL_ALIGN, m_aVerticalAlignment, VerticalAlignment, BOUND, MAYBEDEFAULT ); 209 210 // properties which exist only for compatibility with the css.swt.UnoControlEditModel, 211 // since we replace the default implementation for this service 212 REGISTER_PROP_2( ECHO_CHAR, m_nEchoChar, BOUND, MAYBEDEFAULT ); 213 REGISTER_PROP_2( MAXTEXTLEN, m_nMaxTextLength, BOUND, MAYBEDEFAULT ); 214 REGISTER_PROP_2( MULTILINE, m_bMultiLine, BOUND, MAYBEDEFAULT ); 215 REGISTER_PROP_2( TEXT, m_sLastKnownEngineText, BOUND, MAYBEDEFAULT ); 216 REGISTER_PROP_2( LINEEND_FORMAT, m_nLineEndFormat, BOUND, MAYBEDEFAULT ); 217 REGISTER_PROP_2( WRITING_MODE, m_nTextWritingMode, BOUND, MAYBEDEFAULT ); 218 REGISTER_PROP_3( CONTEXT_WRITING_MODE, m_nContextWritingMode, BOUND, MAYBEDEFAULT, TRANSIENT ); 219 220 REGISTER_VOID_PROP_2( ALIGN, m_aAlign, sal_Int16, BOUND, MAYBEDEFAULT ); 221 } 222 223 //-------------------------------------------------------------------- 224 ORichTextModel::~ORichTextModel( ) 225 { 226 if ( !OComponentHelper::rBHelper.bDisposed ) 227 { 228 acquire(); 229 dispose(); 230 } 231 if ( m_pEngine.get() ) 232 { 233 SfxItemPool* pPool = m_pEngine->getPool(); 234 m_pEngine.reset(); 235 SfxItemPool::Free(pPool); 236 } 237 238 239 DBG_DTOR( ORichTextModel, NULL ); 240 } 241 242 //------------------------------------------------------------------ 243 Any SAL_CALL ORichTextModel::queryAggregation( const Type& _rType ) throw ( RuntimeException ) 244 { 245 Any aReturn = ORichTextModel_BASE::queryInterface( _rType ); 246 247 if ( !aReturn.hasValue() ) 248 aReturn = OControlModel::queryAggregation( _rType ); 249 250 return aReturn; 251 } 252 253 //------------------------------------------------------------------ 254 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ORichTextModel, OControlModel, ORichTextModel_BASE ) 255 256 //-------------------------------------------------------------------- 257 IMPLEMENT_SERVICE_REGISTRATION_8( ORichTextModel, OControlModel, 258 FRM_SUN_COMPONENT_RICHTEXTCONTROL, 259 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextRange" ) ), 260 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterProperties" ) ), 261 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphProperties" ) ), 262 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterPropertiesAsian" ) ), 263 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterPropertiesComplex" ) ), 264 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphPropertiesAsian" ) ), 265 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphPropertiesComplex" ) ) 266 ) 267 268 //------------------------------------------------------------------------------ 269 IMPLEMENT_DEFAULT_CLONING( ORichTextModel ) 270 271 //------------------------------------------------------------------------------ 272 void SAL_CALL ORichTextModel::disposing() 273 { 274 m_aModifyListeners.disposeAndClear( EventObject( *this ) ); 275 OControlModel::disposing(); 276 } 277 278 //------------------------------------------------------------------------------ 279 namespace 280 { 281 void lcl_removeProperty( Sequence< Property >& _rSeq, const ::rtl::OUString& _rPropertyName ) 282 { 283 Property* pLoop = _rSeq.getArray(); 284 Property* pEnd = _rSeq.getArray() + _rSeq.getLength(); 285 while ( pLoop != pEnd ) 286 { 287 if ( pLoop->Name == _rPropertyName ) 288 { 289 ::std::copy( pLoop + 1, pEnd, pLoop ); 290 _rSeq.realloc( _rSeq.getLength() - 1 ); 291 break; 292 } 293 ++pLoop; 294 } 295 } 296 } 297 //------------------------------------------------------------------------------ 298 void ORichTextModel::describeFixedProperties( Sequence< Property >& _rProps ) const 299 { 300 BEGIN_DESCRIBE_PROPERTIES( 1, OControlModel ) 301 DECL_PROP2( TABINDEX, sal_Int16, BOUND, MAYBEDEFAULT ); 302 END_DESCRIBE_PROPERTIES(); 303 304 // properties which the OPropertyContainerHelper is responsible for 305 Sequence< Property > aContainedProperties; 306 describeProperties( aContainedProperties ); 307 308 // properties which the FontControlModel is responsible for 309 Sequence< Property > aFontProperties; 310 describeFontRelatedProperties( aFontProperties ); 311 312 _rProps = concatSequences( aContainedProperties, aFontProperties, _rProps ); 313 } 314 315 //------------------------------------------------------------------------------ 316 void ORichTextModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const 317 { 318 OControlModel::describeAggregateProperties( _rAggregateProps ); 319 320 // our aggregate (the SvxUnoText) declares a FontDescriptor property, as does 321 // our FormControlFont base class. We remove it from the base class' sequence 322 // here, and later on care for both instances being in sync 323 lcl_removeProperty( _rAggregateProps, PROPERTY_FONT ); 324 325 // similar, the WritingMode property is declared in our aggregate, too, but we override 326 // it, since the aggregate does no proper PropertyState handling. 327 lcl_removeProperty( _rAggregateProps, PROPERTY_WRITING_MODE ); 328 } 329 330 //-------------------------------------------------------------------- 331 void SAL_CALL ORichTextModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const 332 { 333 if ( isRegisteredProperty( _nHandle ) ) 334 { 335 OPropertyContainerHelper::getFastPropertyValue( _rValue, _nHandle ); 336 } 337 else if ( isFontRelatedProperty( _nHandle ) ) 338 { 339 FontControlModel::getFastPropertyValue( _rValue, _nHandle ); 340 } 341 else 342 { 343 OControlModel::getFastPropertyValue( _rValue, _nHandle ); 344 } 345 } 346 347 //-------------------------------------------------------------------- 348 sal_Bool SAL_CALL ORichTextModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw( IllegalArgumentException ) 349 { 350 sal_Bool bModified = sal_False; 351 352 if ( isRegisteredProperty( _nHandle ) ) 353 { 354 bModified = OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue ); 355 } 356 else if ( isFontRelatedProperty( _nHandle ) ) 357 { 358 bModified = FontControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue ); 359 } 360 else 361 { 362 bModified = OControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue ); 363 } 364 365 return bModified; 366 } 367 368 //-------------------------------------------------------------------- 369 void SAL_CALL ORichTextModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception) 370 { 371 if ( isRegisteredProperty( _nHandle ) ) 372 { 373 OPropertyContainerHelper::setFastPropertyValue( _nHandle, _rValue ); 374 375 switch ( _nHandle ) 376 { 377 case PROPERTY_ID_REFERENCE_DEVICE: 378 { 379 #if OSL_DEBUG_LEVEL > 0 380 MapMode aOldMapMode = m_pEngine->GetRefDevice()->GetMapMode(); 381 #endif 382 383 OutputDevice* pRefDevice = VCLUnoHelper::GetOutputDevice( m_xReferenceDevice ); 384 OSL_ENSURE( pRefDevice, "ORichTextModel::setFastPropertyValue_NoBroadcast: empty reference device?" ); 385 m_pEngine->SetRefDevice( pRefDevice ); 386 387 #if OSL_DEBUG_LEVEL > 0 388 MapMode aNewMapMode = m_pEngine->GetRefDevice()->GetMapMode(); 389 OSL_ENSURE( aNewMapMode.GetMapUnit() == aOldMapMode.GetMapUnit(), 390 "ORichTextModel::setFastPropertyValue_NoBroadcast: You should not tamper with the MapUnit of the ref device!" ); 391 // if this assertion here is triggered, then we would need to adjust all 392 // items in all text portions in all paragraphs in the attributes of the EditEngine, 393 // as long as they are MapUnit-dependent. This holds at least for the FontSize. 394 #endif 395 } 396 break; 397 398 case PROPERTY_ID_TEXT: 399 { 400 MutexRelease aReleaseMutex( m_aMutex ); 401 impl_smlock_setEngineText( m_sLastKnownEngineText ); 402 } 403 break; 404 } // switch ( _nHandle ) 405 } 406 else if ( isFontRelatedProperty( _nHandle ) ) 407 { 408 FontDescriptor aOldFont( getFont() ); 409 410 FontControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); 411 412 if ( isFontAggregateProperty( _nHandle ) ) 413 firePropertyChange( PROPERTY_ID_FONT, makeAny( getFont() ), makeAny( aOldFont ) ); 414 } 415 else 416 { 417 switch ( _nHandle ) 418 { 419 case PROPERTY_ID_WRITING_MODE: 420 { 421 // forward to our aggregate, so the EditEngine knows about it 422 if ( m_xAggregateSet.is() ) 423 m_xAggregateSet->setPropertyValue( 424 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WritingMode" ) ), _rValue ); 425 } 426 break; 427 428 default: 429 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); 430 break; 431 } 432 } 433 } 434 435 //-------------------------------------------------------------------- 436 Any ORichTextModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const 437 { 438 Any aDefault; 439 440 switch ( _nHandle ) 441 { 442 case PROPERTY_ID_WRITING_MODE: 443 case PROPERTY_ID_CONTEXT_WRITING_MODE: 444 aDefault <<= WritingMode2::CONTEXT; 445 break; 446 447 case PROPERTY_ID_LINEEND_FORMAT: 448 aDefault <<= (sal_Int16)LineEndFormat::LINE_FEED; 449 break; 450 451 case PROPERTY_ID_ECHO_CHAR: 452 case PROPERTY_ID_ALIGN: 453 case PROPERTY_ID_MAXTEXTLEN: 454 aDefault <<= (sal_Int16)0; 455 break; 456 457 case PROPERTY_ID_TABSTOP: 458 case PROPERTY_ID_BACKGROUNDCOLOR: 459 case PROPERTY_ID_BORDERCOLOR: 460 case PROPERTY_ID_VERTICAL_ALIGN: 461 /* void */ 462 break; 463 464 case PROPERTY_ID_ENABLED: 465 case PROPERTY_ID_ENABLEVISIBLE: 466 case PROPERTY_ID_PRINTABLE: 467 case PROPERTY_ID_HIDEINACTIVESELECTION: 468 aDefault <<= (sal_Bool)sal_True; 469 break; 470 471 case PROPERTY_ID_HARDLINEBREAKS: 472 case PROPERTY_ID_HSCROLL: 473 case PROPERTY_ID_VSCROLL: 474 case PROPERTY_ID_READONLY: 475 case PROPERTY_ID_MULTILINE: 476 case PROPERTY_ID_RICH_TEXT: 477 aDefault <<= (sal_Bool)sal_False; 478 break; 479 480 case PROPERTY_ID_DEFAULTCONTROL: 481 aDefault <<= (::rtl::OUString)FRM_SUN_CONTROL_RICHTEXTCONTROL; 482 break; 483 484 case PROPERTY_ID_HELPTEXT: 485 case PROPERTY_ID_HELPURL: 486 case PROPERTY_ID_TEXT: 487 aDefault <<= ::rtl::OUString(); 488 break; 489 490 case PROPERTY_ID_BORDER: 491 aDefault <<= (sal_Int16)1; 492 break; 493 494 default: 495 if ( isFontRelatedProperty( _nHandle ) ) 496 aDefault = FontControlModel::getPropertyDefaultByHandle( _nHandle ); 497 else 498 aDefault = OControlModel::getPropertyDefaultByHandle( _nHandle ); 499 } 500 501 return aDefault; 502 } 503 504 //-------------------------------------------------------------------- 505 void ORichTextModel::impl_smlock_setEngineText( const ::rtl::OUString& _rText ) 506 { 507 if ( m_pEngine.get() ) 508 { 509 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 510 m_bSettingEngineText = true; 511 m_pEngine->SetText( _rText ); 512 m_bSettingEngineText = false; 513 } 514 } 515 516 //-------------------------------------------------------------------- 517 ::rtl::OUString SAL_CALL ORichTextModel::getServiceName() throw ( RuntimeException) 518 { 519 return FRM_SUN_COMPONENT_RICHTEXTCONTROL; 520 } 521 522 //-------------------------------------------------------------------- 523 void SAL_CALL ORichTextModel::write(const Reference< XObjectOutputStream >& _rxOutStream) throw ( IOException, RuntimeException) 524 { 525 OControlModel::write( _rxOutStream ); 526 // TODO: place your code here 527 } 528 529 //-------------------------------------------------------------------- 530 void SAL_CALL ORichTextModel::read(const Reference< XObjectInputStream >& _rxInStream) throw ( IOException, RuntimeException) 531 { 532 OControlModel::read( _rxInStream ); 533 // TODO: place your code here 534 } 535 536 //-------------------------------------------------------------------- 537 RichTextEngine* ORichTextModel::getEditEngine( const Reference< XControlModel >& _rxModel ) 538 { 539 RichTextEngine* pEngine = NULL; 540 541 Reference< XUnoTunnel > xTunnel( _rxModel, UNO_QUERY ); 542 OSL_ENSURE( xTunnel.is(), "ORichTextModel::getEditEngine: invalid model!" ); 543 if ( xTunnel.is() ) 544 { 545 try 546 { 547 pEngine = reinterpret_cast< RichTextEngine* >( xTunnel->getSomething( getEditEngineTunnelId() ) ); 548 } 549 catch( const Exception& ) 550 { 551 OSL_ENSURE( sal_False, "ORichTextModel::getEditEngine: caught an exception!" ); 552 } 553 } 554 return pEngine; 555 } 556 557 //-------------------------------------------------------------------- 558 Sequence< sal_Int8 > ORichTextModel::getEditEngineTunnelId() 559 { 560 static ::cppu::OImplementationId * pId = 0; 561 if (! pId) 562 { 563 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 564 if (! pId) 565 { 566 static ::cppu::OImplementationId aId; 567 pId = &aId; 568 } 569 } 570 return pId->getImplementationId(); 571 } 572 573 //-------------------------------------------------------------------- 574 IMPL_LINK( ORichTextModel, OnEngineContentModified, void*, /*_pNotInterestedIn*/ ) 575 { 576 if ( !m_bSettingEngineText ) 577 { 578 m_aModifyListeners.notifyEach( &XModifyListener::modified, EventObject( *this ) ); 579 580 potentialTextChange(); 581 // is this a good idea? It may become expensive in case of larger texts, 582 // and this method here is called for every single changed character ... 583 // On the other hand, the API *requires* us to notify changes in the "Text" 584 // property immediately ... 585 } 586 587 return 0L; 588 } 589 590 //-------------------------------------------------------------------- 591 sal_Int64 SAL_CALL ORichTextModel::getSomething( const Sequence< sal_Int8 >& _rId ) throw (RuntimeException) 592 { 593 Sequence< sal_Int8 > aEditEngineAccessId( getEditEngineTunnelId() ); 594 if ( ( _rId.getLength() == aEditEngineAccessId.getLength() ) 595 && ( 0 == rtl_compareMemory( aEditEngineAccessId.getConstArray(), _rId.getConstArray(), _rId.getLength() ) ) 596 ) 597 return reinterpret_cast< sal_Int64 >( m_pEngine.get() ); 598 599 Reference< XUnoTunnel > xAggTunnel; 600 if ( query_aggregation( m_xAggregate, xAggTunnel ) ) 601 return xAggTunnel->getSomething( _rId ); 602 603 return 0; 604 } 605 606 //-------------------------------------------------------------------- 607 void SAL_CALL ORichTextModel::addModifyListener( const Reference< XModifyListener >& _rxListener ) throw (RuntimeException) 608 { 609 m_aModifyListeners.addInterface( _rxListener ); 610 } 611 612 //-------------------------------------------------------------------- 613 void SAL_CALL ORichTextModel::removeModifyListener( const Reference< XModifyListener >& _rxListener ) throw (RuntimeException) 614 { 615 m_aModifyListeners.removeInterface( _rxListener ); 616 } 617 618 //-------------------------------------------------------------------- 619 void ORichTextModel::potentialTextChange( ) 620 { 621 ::rtl::OUString sCurrentEngineText; 622 if ( m_pEngine.get() ) 623 sCurrentEngineText = m_pEngine->GetText(); 624 625 if ( sCurrentEngineText != m_sLastKnownEngineText ) 626 { 627 sal_Int32 nHandle = PROPERTY_ID_TEXT; 628 Any aOldValue; aOldValue <<= m_sLastKnownEngineText; 629 Any aNewValue; aNewValue <<= sCurrentEngineText; 630 fire( &nHandle, &aNewValue, &aOldValue, 1, sal_False ); 631 632 m_sLastKnownEngineText = sCurrentEngineText; 633 } 634 } 635 636 //........................................................................ 637 } // namespace frm 638 //........................................................................ 639