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