1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: richtextmodel.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
34 #ifndef FORMS_SOURCE_RICHTEXT_RICHTEXTMODEL_CXX
35 #include "richtextmodel.hxx"
37 #include "richtextengine.hxx"
38 #include "richtextunowrapper.hxx"
40 /** === begin UNO includes === **/
41 #include <com/sun/star/awt/LineEndFormat.hpp>
42 #include <com/sun/star/text/WritingMode2.hpp>
43 /** === end UNO includes === **/
44 #include <cppuhelper/typeprovider.hxx>
45 #include <comphelper/guarding.hxx>
46 #include <toolkit/awt/vclxdevice.hxx>
47 #include <toolkit/helper/vclunohelper.hxx>
48 #include <svx/editstat.hxx>
49 #include <vcl/outdev.hxx>
50 #include <vcl/svapp.hxx>
52 //--------------------------------------------------------------------------
53 extern "C" void SAL_CALL
createRegistryInfo_ORichTextModel()
55 static ::frm::OMultiInstanceAutoRegistration
< ::frm::ORichTextModel
> aRegisterModel
;
58 //........................................................................
61 //........................................................................
63 using namespace ::com::sun::star::uno
;
64 using namespace ::com::sun::star::awt
;
65 using namespace ::com::sun::star::lang
;
66 using namespace ::com::sun::star::io
;
67 using namespace ::com::sun::star::beans
;
68 using namespace ::com::sun::star::form
;
69 using namespace ::com::sun::star::util
;
71 namespace WritingMode2
= ::com::sun::star::text::WritingMode2
;
73 //====================================================================
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
)
85 DBG_CTOR( ORichTextModel
, NULL
);
86 m_nClassId
= FormComponentType::TEXTFIELD
;
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
;
110 //------------------------------------------------------------------
111 ORichTextModel::ORichTextModel( const ORichTextModel
* _pOriginal
, const Reference
< XMultiServiceFactory
>& _rxFactory
)
112 :OControlModel ( _pOriginal
, _rxFactory
, sal_False
)
113 ,FontControlModel ( _pOriginal
)
115 ,m_bSettingEngineText( false )
116 ,m_aModifyListeners ( m_aMutex
)
118 DBG_CTOR( ORichTextModel
, NULL
);
120 m_aTabStop
= _pOriginal
->m_aTabStop
;
121 m_aBackgroundColor
= _pOriginal
->m_aBackgroundColor
;
122 m_aBorderColor
= _pOriginal
->m_aBorderColor
;
123 m_sDefaultControl
= _pOriginal
->m_sDefaultControl
;
124 m_sHelpText
= _pOriginal
->m_sHelpText
;
125 m_sHelpURL
= _pOriginal
->m_sHelpURL
;
126 m_nBorder
= _pOriginal
->m_nBorder
;
127 m_bEnabled
= _pOriginal
->m_bEnabled
;
128 m_bEnableVisible
= _pOriginal
->m_bEnableVisible
;
129 m_bHardLineBreaks
= _pOriginal
->m_bHardLineBreaks
;
130 m_bHScroll
= _pOriginal
->m_bHScroll
;
131 m_bVScroll
= _pOriginal
->m_bVScroll
;
132 m_bReadonly
= _pOriginal
->m_bReadonly
;
133 m_bPrintable
= _pOriginal
->m_bPrintable
;
134 m_bReallyActAsRichText
= _pOriginal
->m_bReallyActAsRichText
;
135 m_bHideInactiveSelection
= _pOriginal
->m_bHideInactiveSelection
;
136 m_nLineEndFormat
= _pOriginal
->m_nLineEndFormat
;
137 m_nTextWritingMode
= _pOriginal
->m_nTextWritingMode
;
138 m_nContextWritingMode
= _pOriginal
->m_nContextWritingMode
;
140 m_aAlign
= _pOriginal
->m_aAlign
;
141 m_nEchoChar
= _pOriginal
->m_nEchoChar
;
142 m_nMaxTextLength
= _pOriginal
->m_nMaxTextLength
;
143 m_bMultiLine
= _pOriginal
->m_bMultiLine
;
145 m_pEngine
.reset(_pOriginal
->m_pEngine
->Clone());
146 m_sLastKnownEngineText
= m_pEngine
->GetText();
151 //------------------------------------------------------------------
152 void ORichTextModel::implInit()
154 OSL_ENSURE( m_pEngine
.get(), "ORichTextModel::implInit: where's the engine?" );
155 if ( m_pEngine
.get() )
157 m_pEngine
->SetModifyHdl( LINK( this, ORichTextModel
, OnEngineContentModified
) );
159 ULONG nEngineControlWord
= m_pEngine
->GetControlWord();
160 nEngineControlWord
= nEngineControlWord
& ~EE_CNTRL_AUTOPAGESIZE
;
161 m_pEngine
->SetControlWord( nEngineControlWord
);
163 VCLXDevice
* pUnoRefDevice
= new VCLXDevice
;
164 pUnoRefDevice
->SetOutputDevice( m_pEngine
->GetRefDevice() );
165 m_xReferenceDevice
= pUnoRefDevice
;
169 implRegisterProperties();
172 //------------------------------------------------------------------
173 void ORichTextModel::implDoAggregation()
175 increment( m_refCount
);
178 m_xAggregate
= new ORichTextUnoWrapper( *m_pEngine
, this );
179 setAggregation( m_xAggregate
);
183 decrement( m_refCount
);
186 //------------------------------------------------------------------
187 void ORichTextModel::implRegisterProperties()
189 REGISTER_PROP_2( DEFAULTCONTROL
, m_sDefaultControl
, BOUND
, MAYBEDEFAULT
);
190 REGISTER_PROP_2( HELPTEXT
, m_sHelpText
, BOUND
, MAYBEDEFAULT
);
191 REGISTER_PROP_2( HELPURL
, m_sHelpURL
, BOUND
, MAYBEDEFAULT
);
192 REGISTER_PROP_2( ENABLED
, m_bEnabled
, BOUND
, MAYBEDEFAULT
);
193 REGISTER_PROP_2( ENABLEVISIBLE
, m_bEnableVisible
, BOUND
, MAYBEDEFAULT
);
194 REGISTER_PROP_2( BORDER
, m_nBorder
, BOUND
, MAYBEDEFAULT
);
195 REGISTER_PROP_2( HARDLINEBREAKS
, m_bHardLineBreaks
, BOUND
, MAYBEDEFAULT
);
196 REGISTER_PROP_2( HSCROLL
, m_bHScroll
, BOUND
, MAYBEDEFAULT
);
197 REGISTER_PROP_2( VSCROLL
, m_bVScroll
, BOUND
, MAYBEDEFAULT
);
198 REGISTER_PROP_2( READONLY
, m_bReadonly
, BOUND
, MAYBEDEFAULT
);
199 REGISTER_PROP_2( PRINTABLE
, m_bPrintable
, BOUND
, MAYBEDEFAULT
);
200 REGISTER_PROP_2( REFERENCE_DEVICE
, m_xReferenceDevice
, BOUND
, TRANSIENT
);
201 REGISTER_PROP_2( RICH_TEXT
, m_bReallyActAsRichText
, BOUND
, MAYBEDEFAULT
);
202 REGISTER_PROP_2( HIDEINACTIVESELECTION
, m_bHideInactiveSelection
, BOUND
, MAYBEDEFAULT
);
204 REGISTER_VOID_PROP_2( TABSTOP
, m_aTabStop
, sal_Bool
, BOUND
, MAYBEDEFAULT
);
205 REGISTER_VOID_PROP_2( BACKGROUNDCOLOR
, m_aBackgroundColor
, sal_Int32
, BOUND
, MAYBEDEFAULT
);
206 REGISTER_VOID_PROP_2( BORDERCOLOR
, m_aBorderColor
, sal_Int32
, BOUND
, MAYBEDEFAULT
);
208 // properties which exist only for compatibility with the css.swt.UnoControlEditModel,
209 // since we replace the default implementation for this service
210 REGISTER_PROP_2( ECHO_CHAR
, m_nEchoChar
, BOUND
, MAYBEDEFAULT
);
211 REGISTER_PROP_2( MAXTEXTLEN
, m_nMaxTextLength
, BOUND
, MAYBEDEFAULT
);
212 REGISTER_PROP_2( MULTILINE
, m_bMultiLine
, BOUND
, MAYBEDEFAULT
);
213 REGISTER_PROP_2( TEXT
, m_sLastKnownEngineText
, BOUND
, MAYBEDEFAULT
);
214 REGISTER_PROP_2( LINEEND_FORMAT
, m_nLineEndFormat
, BOUND
, MAYBEDEFAULT
);
215 REGISTER_PROP_2( WRITING_MODE
, m_nTextWritingMode
, BOUND
, MAYBEDEFAULT
);
216 REGISTER_PROP_3( CONTEXT_WRITING_MODE
, m_nContextWritingMode
, BOUND
, MAYBEDEFAULT
, TRANSIENT
);
218 REGISTER_VOID_PROP_2( ALIGN
, m_aAlign
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
221 //--------------------------------------------------------------------
222 ORichTextModel::~ORichTextModel( )
224 if ( !OComponentHelper::rBHelper
.bDisposed
)
229 if ( m_pEngine
.get() )
231 SfxItemPool
* pPool
= m_pEngine
->getPool();
233 SfxItemPool::Free(pPool
);
237 DBG_DTOR( ORichTextModel
, NULL
);
240 //------------------------------------------------------------------
241 Any SAL_CALL
ORichTextModel::queryAggregation( const Type
& _rType
) throw ( RuntimeException
)
243 Any aReturn
= ORichTextModel_BASE::queryInterface( _rType
);
245 if ( !aReturn
.hasValue() )
246 aReturn
= OControlModel::queryAggregation( _rType
);
251 //------------------------------------------------------------------
252 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ORichTextModel
, OControlModel
, ORichTextModel_BASE
)
254 //--------------------------------------------------------------------
255 IMPLEMENT_SERVICE_REGISTRATION_8( ORichTextModel
, OControlModel
,
256 FRM_SUN_COMPONENT_RICHTEXTCONTROL
,
257 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextRange" ) ),
258 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterProperties" ) ),
259 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphProperties" ) ),
260 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterPropertiesAsian" ) ),
261 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterPropertiesComplex" ) ),
262 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphPropertiesAsian" ) ),
263 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphPropertiesComplex" ) )
266 //------------------------------------------------------------------------------
267 IMPLEMENT_DEFAULT_CLONING( ORichTextModel
)
269 //------------------------------------------------------------------------------
270 void SAL_CALL
ORichTextModel::disposing()
272 m_aModifyListeners
.disposeAndClear( EventObject( *this ) );
273 OControlModel::disposing();
276 //------------------------------------------------------------------------------
279 void lcl_removeProperty( Sequence
< Property
>& _rSeq
, const ::rtl::OUString
& _rPropertyName
)
281 Property
* pLoop
= _rSeq
.getArray();
282 Property
* pEnd
= _rSeq
.getArray() + _rSeq
.getLength();
283 while ( pLoop
!= pEnd
)
285 if ( pLoop
->Name
== _rPropertyName
)
287 ::std::copy( pLoop
+ 1, pEnd
, pLoop
);
288 _rSeq
.realloc( _rSeq
.getLength() - 1 );
295 //------------------------------------------------------------------------------
296 void ORichTextModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
298 BEGIN_DESCRIBE_PROPERTIES( 1, OControlModel
)
299 DECL_PROP2( TABINDEX
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
300 END_DESCRIBE_PROPERTIES();
302 // properties which the OPropertyContainerHelper is responsible for
303 Sequence
< Property
> aContainedProperties
;
304 describeProperties( aContainedProperties
);
306 // properties which the FontControlModel is responsible for
307 Sequence
< Property
> aFontProperties
;
308 describeFontRelatedProperties( aFontProperties
);
310 _rProps
= concatSequences( aContainedProperties
, aFontProperties
, _rProps
);
313 //------------------------------------------------------------------------------
314 void ORichTextModel::describeAggregateProperties( Sequence
< Property
>& _rAggregateProps
) const
316 OControlModel::describeAggregateProperties( _rAggregateProps
);
318 // our aggregate (the SvxUnoText) declares a FontDescriptor property, as does
319 // our FormControlFont base class. We remove it from the base class' sequence
320 // here, and later on care for both instances being in sync
321 lcl_removeProperty( _rAggregateProps
, PROPERTY_FONT
);
323 // similar, the WritingMode property is declared in our aggregate, too, but we override
324 // it, since the aggregate does no proper PropertyState handling.
325 lcl_removeProperty( _rAggregateProps
, PROPERTY_WRITING_MODE
);
328 //--------------------------------------------------------------------
329 void SAL_CALL
ORichTextModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
331 if ( isRegisteredProperty( _nHandle
) )
333 OPropertyContainerHelper::getFastPropertyValue( _rValue
, _nHandle
);
335 else if ( isFontRelatedProperty( _nHandle
) )
337 FontControlModel::getFastPropertyValue( _rValue
, _nHandle
);
341 OControlModel::getFastPropertyValue( _rValue
, _nHandle
);
345 //--------------------------------------------------------------------
346 sal_Bool SAL_CALL
ORichTextModel::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
) throw( IllegalArgumentException
)
348 sal_Bool bModified
= sal_False
;
350 if ( isRegisteredProperty( _nHandle
) )
352 bModified
= OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
354 else if ( isFontRelatedProperty( _nHandle
) )
356 bModified
= FontControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
360 bModified
= OControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
366 //--------------------------------------------------------------------
367 void SAL_CALL
ORichTextModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw ( Exception
)
369 if ( isRegisteredProperty( _nHandle
) )
371 OPropertyContainerHelper::setFastPropertyValue( _nHandle
, _rValue
);
375 case PROPERTY_ID_REFERENCE_DEVICE
:
377 #if OSL_DEBUG_LEVEL > 0
378 MapMode aOldMapMode
= m_pEngine
->GetRefDevice()->GetMapMode();
381 OutputDevice
* pRefDevice
= VCLUnoHelper::GetOutputDevice( m_xReferenceDevice
);
382 OSL_ENSURE( pRefDevice
, "ORichTextModel::setFastPropertyValue_NoBroadcast: empty reference device?" );
383 m_pEngine
->SetRefDevice( pRefDevice
);
385 #if OSL_DEBUG_LEVEL > 0
386 MapMode aNewMapMode
= m_pEngine
->GetRefDevice()->GetMapMode();
387 OSL_ENSURE( aNewMapMode
.GetMapUnit() == aOldMapMode
.GetMapUnit(),
388 "ORichTextModel::setFastPropertyValue_NoBroadcast: You should not tamper with the MapUnit of the ref device!" );
389 // if this assertion here is triggered, then we would need to adjust all
390 // items in all text portions in all paragraphs in the attributes of the EditEngine,
391 // as long as they are MapUnit-dependent. This holds at least for the FontSize.
396 case PROPERTY_ID_TEXT
:
398 MutexRelease
aReleaseMutex( m_aMutex
);
399 impl_smlock_setEngineText( m_sLastKnownEngineText
);
402 } // switch ( _nHandle )
404 else if ( isFontRelatedProperty( _nHandle
) )
406 FontDescriptor
aOldFont( getFont() );
408 FontControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
410 if ( isFontAggregateProperty( _nHandle
) )
411 firePropertyChange( PROPERTY_ID_FONT
, makeAny( getFont() ), makeAny( aOldFont
) );
417 case PROPERTY_ID_WRITING_MODE
:
419 // forward to our aggregate, so the EditEngine knows about it
420 if ( m_xAggregateSet
.is() )
421 m_xAggregateSet
->setPropertyValue(
422 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WritingMode" ) ), _rValue
);
427 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
433 //--------------------------------------------------------------------
434 Any
ORichTextModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
440 case PROPERTY_ID_WRITING_MODE
:
441 case PROPERTY_ID_CONTEXT_WRITING_MODE
:
442 aDefault
<<= WritingMode2::CONTEXT
;
445 case PROPERTY_ID_LINEEND_FORMAT
:
446 aDefault
<<= (sal_Int16
)LineEndFormat::LINE_FEED
;
449 case PROPERTY_ID_ECHO_CHAR
:
450 case PROPERTY_ID_ALIGN
:
451 case PROPERTY_ID_MAXTEXTLEN
:
452 aDefault
<<= (sal_Int16
)0;
455 case PROPERTY_ID_TABSTOP
:
456 case PROPERTY_ID_BACKGROUNDCOLOR
:
457 case PROPERTY_ID_BORDERCOLOR
:
461 case PROPERTY_ID_ENABLED
:
462 case PROPERTY_ID_ENABLEVISIBLE
:
463 case PROPERTY_ID_PRINTABLE
:
464 case PROPERTY_ID_HIDEINACTIVESELECTION
:
465 aDefault
<<= (sal_Bool
)sal_True
;
468 case PROPERTY_ID_HARDLINEBREAKS
:
469 case PROPERTY_ID_HSCROLL
:
470 case PROPERTY_ID_VSCROLL
:
471 case PROPERTY_ID_READONLY
:
472 case PROPERTY_ID_MULTILINE
:
473 case PROPERTY_ID_RICH_TEXT
:
474 aDefault
<<= (sal_Bool
)sal_False
;
477 case PROPERTY_ID_DEFAULTCONTROL
:
478 aDefault
<<= (::rtl::OUString
)FRM_SUN_CONTROL_RICHTEXTCONTROL
;
481 case PROPERTY_ID_HELPTEXT
:
482 case PROPERTY_ID_HELPURL
:
483 case PROPERTY_ID_TEXT
:
484 aDefault
<<= ::rtl::OUString();
487 case PROPERTY_ID_BORDER
:
488 aDefault
<<= (sal_Int16
)1;
492 if ( isFontRelatedProperty( _nHandle
) )
493 aDefault
= FontControlModel::getPropertyDefaultByHandle( _nHandle
);
495 aDefault
= OControlModel::getPropertyDefaultByHandle( _nHandle
);
501 //--------------------------------------------------------------------
502 void ORichTextModel::impl_smlock_setEngineText( const ::rtl::OUString
& _rText
)
504 if ( m_pEngine
.get() )
506 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
507 m_bSettingEngineText
= true;
508 m_pEngine
->SetText( _rText
);
509 m_bSettingEngineText
= false;
513 //--------------------------------------------------------------------
514 ::rtl::OUString SAL_CALL
ORichTextModel::getServiceName() throw ( RuntimeException
)
516 return FRM_SUN_COMPONENT_RICHTEXTCONTROL
;
519 //--------------------------------------------------------------------
520 void SAL_CALL
ORichTextModel::write(const Reference
< XObjectOutputStream
>& _rxOutStream
) throw ( IOException
, RuntimeException
)
522 OControlModel::write( _rxOutStream
);
523 // TODO: place your code here
526 //--------------------------------------------------------------------
527 void SAL_CALL
ORichTextModel::read(const Reference
< XObjectInputStream
>& _rxInStream
) throw ( IOException
, RuntimeException
)
529 OControlModel::read( _rxInStream
);
530 // TODO: place your code here
533 //--------------------------------------------------------------------
534 RichTextEngine
* ORichTextModel::getEditEngine( const Reference
< XControlModel
>& _rxModel
)
536 RichTextEngine
* pEngine
= NULL
;
538 Reference
< XUnoTunnel
> xTunnel( _rxModel
, UNO_QUERY
);
539 OSL_ENSURE( xTunnel
.is(), "ORichTextModel::getEditEngine: invalid model!" );
544 pEngine
= reinterpret_cast< RichTextEngine
* >( xTunnel
->getSomething( getEditEngineTunnelId() ) );
546 catch( const Exception
& )
548 OSL_ENSURE( sal_False
, "ORichTextModel::getEditEngine: caught an exception!" );
554 //--------------------------------------------------------------------
555 Sequence
< sal_Int8
> ORichTextModel::getEditEngineTunnelId()
557 static ::cppu::OImplementationId
* pId
= 0;
560 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
563 static ::cppu::OImplementationId aId
;
567 return pId
->getImplementationId();
570 //--------------------------------------------------------------------
571 IMPL_LINK( ORichTextModel
, OnEngineContentModified
, void*, /*_pNotInterestedIn*/ )
573 if ( !m_bSettingEngineText
)
575 m_aModifyListeners
.notifyEach( &XModifyListener::modified
, EventObject( *this ) );
577 potentialTextChange();
578 // is this a good idea? It may become expensive in case of larger texts,
579 // and this method here is called for every single changed character ...
580 // On the other hand, the API *requires* us to notify changes in the "Text"
581 // property immediately ...
587 //--------------------------------------------------------------------
588 sal_Int64 SAL_CALL
ORichTextModel::getSomething( const Sequence
< sal_Int8
>& _rId
) throw (RuntimeException
)
590 Sequence
< sal_Int8
> aEditEngineAccessId( getEditEngineTunnelId() );
591 if ( ( _rId
.getLength() == aEditEngineAccessId
.getLength() )
592 && ( 0 == rtl_compareMemory( aEditEngineAccessId
.getConstArray(), _rId
.getConstArray(), _rId
.getLength() ) )
594 return reinterpret_cast< sal_Int64
>( m_pEngine
.get() );
596 Reference
< XUnoTunnel
> xAggTunnel
;
597 if ( query_aggregation( m_xAggregate
, xAggTunnel
) )
598 return xAggTunnel
->getSomething( _rId
);
603 //--------------------------------------------------------------------
604 void SAL_CALL
ORichTextModel::addModifyListener( const Reference
< XModifyListener
>& _rxListener
) throw (RuntimeException
)
606 m_aModifyListeners
.addInterface( _rxListener
);
609 //--------------------------------------------------------------------
610 void SAL_CALL
ORichTextModel::removeModifyListener( const Reference
< XModifyListener
>& _rxListener
) throw (RuntimeException
)
612 m_aModifyListeners
.removeInterface( _rxListener
);
615 //--------------------------------------------------------------------
616 void ORichTextModel::potentialTextChange( )
618 ::rtl::OUString sCurrentEngineText
;
619 if ( m_pEngine
.get() )
620 sCurrentEngineText
= m_pEngine
->GetText();
622 if ( sCurrentEngineText
!= m_sLastKnownEngineText
)
624 sal_Int32 nHandle
= PROPERTY_ID_TEXT
;
625 Any aOldValue
; aOldValue
<<= m_sLastKnownEngineText
;
626 Any aNewValue
; aNewValue
<<= sCurrentEngineText
;
627 fire( &nHandle
, &aNewValue
, &aOldValue
, 1, sal_False
);
629 m_sLastKnownEngineText
= sCurrentEngineText
;
633 //........................................................................
635 //........................................................................