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 17 : extern "C" void SAL_CALL createRegistryInfo_ORichTextModel()
38 : {
39 17 : static ::frm::OMultiInstanceAutoRegistration< ::frm::ORichTextModel > aRegisterModel;
40 17 : }
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 104 : ORichTextModel::ORichTextModel( const Reference< XComponentContext >& _rxFactory )
63 : :OControlModel ( _rxFactory, OUString() )
64 : ,FontControlModel ( true )
65 : ,m_pEngine ( RichTextEngine::Create() )
66 : ,m_bSettingEngineText( false )
67 104 : ,m_aModifyListeners ( m_aMutex )
68 : {
69 104 : m_nClassId = FormComponentType::TEXTFIELD;
70 :
71 104 : getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL ) >>= m_sDefaultControl;
72 104 : getPropertyDefaultByHandle( PROPERTY_ID_BORDER ) >>= m_nBorder;
73 104 : getPropertyDefaultByHandle( PROPERTY_ID_ENABLED ) >>= m_bEnabled;
74 104 : getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE ) >>= m_bEnableVisible;
75 104 : getPropertyDefaultByHandle( PROPERTY_ID_HARDLINEBREAKS ) >>= m_bHardLineBreaks;
76 104 : getPropertyDefaultByHandle( PROPERTY_ID_HSCROLL ) >>= m_bHScroll;
77 104 : getPropertyDefaultByHandle( PROPERTY_ID_VSCROLL ) >>= m_bVScroll;
78 104 : getPropertyDefaultByHandle( PROPERTY_ID_READONLY ) >>= m_bReadonly;
79 104 : getPropertyDefaultByHandle( PROPERTY_ID_PRINTABLE ) >>= m_bPrintable;
80 104 : getPropertyDefaultByHandle( PROPERTY_ID_ALIGN ) >>= m_aAlign;
81 104 : getPropertyDefaultByHandle( PROPERTY_ID_ECHO_CHAR ) >>= m_nEchoChar;
82 104 : getPropertyDefaultByHandle( PROPERTY_ID_MAXTEXTLEN ) >>= m_nMaxTextLength;
83 104 : getPropertyDefaultByHandle( PROPERTY_ID_MULTILINE ) >>= m_bMultiLine;
84 104 : getPropertyDefaultByHandle( PROPERTY_ID_RICH_TEXT ) >>= m_bReallyActAsRichText;
85 104 : getPropertyDefaultByHandle( PROPERTY_ID_HIDEINACTIVESELECTION ) >>= m_bHideInactiveSelection;
86 104 : getPropertyDefaultByHandle( PROPERTY_ID_LINEEND_FORMAT ) >>= m_nLineEndFormat;
87 104 : getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE ) >>= m_nTextWritingMode;
88 104 : getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE ) >>= m_nContextWritingMode;
89 :
90 104 : implInit();
91 104 : }
92 :
93 :
94 2 : 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 2 : ,m_aModifyListeners ( m_aMutex )
100 : {
101 :
102 2 : m_aTabStop = _pOriginal->m_aTabStop;
103 2 : m_aBackgroundColor = _pOriginal->m_aBackgroundColor;
104 2 : m_aBorderColor = _pOriginal->m_aBorderColor;
105 2 : m_aVerticalAlignment = _pOriginal->m_aVerticalAlignment;
106 2 : m_sDefaultControl = _pOriginal->m_sDefaultControl;
107 2 : m_sHelpText = _pOriginal->m_sHelpText;
108 2 : m_sHelpURL = _pOriginal->m_sHelpURL;
109 2 : m_nBorder = _pOriginal->m_nBorder;
110 2 : m_bEnabled = _pOriginal->m_bEnabled;
111 2 : m_bEnableVisible = _pOriginal->m_bEnableVisible;
112 2 : m_bHardLineBreaks = _pOriginal->m_bHardLineBreaks;
113 2 : m_bHScroll = _pOriginal->m_bHScroll;
114 2 : m_bVScroll = _pOriginal->m_bVScroll;
115 2 : m_bReadonly = _pOriginal->m_bReadonly;
116 2 : m_bPrintable = _pOriginal->m_bPrintable;
117 2 : m_bReallyActAsRichText = _pOriginal->m_bReallyActAsRichText;
118 2 : m_bHideInactiveSelection = _pOriginal->m_bHideInactiveSelection;
119 2 : m_nLineEndFormat = _pOriginal->m_nLineEndFormat;
120 2 : m_nTextWritingMode = _pOriginal->m_nTextWritingMode;
121 2 : m_nContextWritingMode = _pOriginal->m_nContextWritingMode;
122 :
123 2 : m_aAlign = _pOriginal->m_aAlign;
124 2 : m_nEchoChar = _pOriginal->m_nEchoChar;
125 2 : m_nMaxTextLength = _pOriginal->m_nMaxTextLength;
126 2 : m_bMultiLine = _pOriginal->m_bMultiLine;
127 :
128 2 : m_pEngine.reset(_pOriginal->m_pEngine->Clone());
129 2 : m_sLastKnownEngineText = m_pEngine->GetText();
130 :
131 2 : implInit();
132 2 : }
133 :
134 :
135 106 : void ORichTextModel::implInit()
136 : {
137 : OSL_ENSURE( m_pEngine.get(), "ORichTextModel::implInit: where's the engine?" );
138 106 : if ( m_pEngine.get() )
139 : {
140 106 : m_pEngine->SetModifyHdl( LINK( this, ORichTextModel, OnEngineContentModified ) );
141 :
142 106 : sal_uLong nEngineControlWord = m_pEngine->GetControlWord();
143 106 : nEngineControlWord = nEngineControlWord & ~EE_CNTRL_AUTOPAGESIZE;
144 106 : m_pEngine->SetControlWord( nEngineControlWord );
145 :
146 106 : VCLXDevice* pUnoRefDevice = new VCLXDevice;
147 106 : pUnoRefDevice->SetOutputDevice( m_pEngine->GetRefDevice() );
148 106 : m_xReferenceDevice = pUnoRefDevice;
149 : }
150 :
151 106 : implDoAggregation();
152 106 : implRegisterProperties();
153 106 : }
154 :
155 :
156 106 : void ORichTextModel::implDoAggregation()
157 : {
158 106 : increment( m_refCount );
159 :
160 : {
161 106 : m_xAggregate = new ORichTextUnoWrapper( *m_pEngine, this );
162 106 : setAggregation( m_xAggregate );
163 106 : doSetDelegator();
164 : }
165 :
166 106 : decrement( m_refCount );
167 106 : }
168 :
169 :
170 106 : void ORichTextModel::implRegisterProperties()
171 : {
172 106 : REGISTER_PROP_2( DEFAULTCONTROL, m_sDefaultControl, BOUND, MAYBEDEFAULT );
173 106 : REGISTER_PROP_2( HELPTEXT, m_sHelpText, BOUND, MAYBEDEFAULT );
174 106 : REGISTER_PROP_2( HELPURL, m_sHelpURL, BOUND, MAYBEDEFAULT );
175 106 : REGISTER_PROP_2( ENABLED, m_bEnabled, BOUND, MAYBEDEFAULT );
176 106 : REGISTER_PROP_2( ENABLEVISIBLE, m_bEnableVisible, BOUND, MAYBEDEFAULT );
177 106 : REGISTER_PROP_2( BORDER, m_nBorder, BOUND, MAYBEDEFAULT );
178 106 : REGISTER_PROP_2( HARDLINEBREAKS, m_bHardLineBreaks, BOUND, MAYBEDEFAULT );
179 106 : REGISTER_PROP_2( HSCROLL, m_bHScroll, BOUND, MAYBEDEFAULT );
180 106 : REGISTER_PROP_2( VSCROLL, m_bVScroll, BOUND, MAYBEDEFAULT );
181 106 : REGISTER_PROP_2( READONLY, m_bReadonly, BOUND, MAYBEDEFAULT );
182 106 : REGISTER_PROP_2( PRINTABLE, m_bPrintable, BOUND, MAYBEDEFAULT );
183 106 : REGISTER_PROP_2( REFERENCE_DEVICE, m_xReferenceDevice, BOUND, TRANSIENT );
184 106 : REGISTER_PROP_2( RICH_TEXT, m_bReallyActAsRichText, BOUND, MAYBEDEFAULT );
185 106 : REGISTER_PROP_2( HIDEINACTIVESELECTION, m_bHideInactiveSelection, BOUND, MAYBEDEFAULT );
186 :
187 106 : REGISTER_VOID_PROP_2( TABSTOP, m_aTabStop, sal_Bool, BOUND, MAYBEDEFAULT );
188 106 : REGISTER_VOID_PROP_2( BACKGROUNDCOLOR, m_aBackgroundColor, sal_Int32, BOUND, MAYBEDEFAULT );
189 106 : REGISTER_VOID_PROP_2( BORDERCOLOR, m_aBorderColor, sal_Int32, BOUND, MAYBEDEFAULT );
190 106 : 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 106 : REGISTER_PROP_2( ECHO_CHAR, m_nEchoChar, BOUND, MAYBEDEFAULT );
195 106 : REGISTER_PROP_2( MAXTEXTLEN, m_nMaxTextLength, BOUND, MAYBEDEFAULT );
196 106 : REGISTER_PROP_2( MULTILINE, m_bMultiLine, BOUND, MAYBEDEFAULT );
197 106 : REGISTER_PROP_2( TEXT, m_sLastKnownEngineText, BOUND, MAYBEDEFAULT );
198 106 : REGISTER_PROP_2( LINEEND_FORMAT, m_nLineEndFormat, BOUND, MAYBEDEFAULT );
199 106 : REGISTER_PROP_2( WRITING_MODE, m_nTextWritingMode, BOUND, MAYBEDEFAULT );
200 106 : REGISTER_PROP_3( CONTEXT_WRITING_MODE, m_nContextWritingMode, BOUND, MAYBEDEFAULT, TRANSIENT );
201 :
202 106 : REGISTER_VOID_PROP_2( ALIGN, m_aAlign, sal_Int16, BOUND, MAYBEDEFAULT );
203 106 : }
204 :
205 :
206 294 : ORichTextModel::~ORichTextModel( )
207 : {
208 98 : if ( !OComponentHelper::rBHelper.bDisposed )
209 : {
210 0 : acquire();
211 0 : dispose();
212 : }
213 98 : if ( m_pEngine.get() )
214 : {
215 98 : SolarMutexGuard g;
216 98 : SfxItemPool* pPool = m_pEngine->getPool();
217 98 : m_pEngine.reset();
218 98 : SfxItemPool::Free(pPool);
219 : }
220 :
221 :
222 196 : }
223 :
224 :
225 13825 : Any SAL_CALL ORichTextModel::queryAggregation( const Type& _rType ) throw ( RuntimeException, std::exception )
226 : {
227 13825 : Any aReturn = ORichTextModel_BASE::queryInterface( _rType );
228 :
229 13825 : if ( !aReturn.hasValue() )
230 1682 : aReturn = OControlModel::queryAggregation( _rType );
231 :
232 13825 : return aReturn;
233 : }
234 :
235 :
236 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ORichTextModel, OControlModel, ORichTextModel_BASE )
237 :
238 :
239 259 : 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 2 : IMPLEMENT_DEFAULT_CLONING( ORichTextModel )
252 :
253 :
254 98 : void SAL_CALL ORichTextModel::disposing()
255 : {
256 98 : m_aModifyListeners.disposeAndClear( EventObject( *this ) );
257 98 : OControlModel::disposing();
258 98 : }
259 :
260 :
261 : namespace
262 : {
263 212 : void lcl_removeProperty( Sequence< Property >& _rSeq, const OUString& _rPropertyName )
264 : {
265 212 : Property* pLoop = _rSeq.getArray();
266 212 : Property* pEnd = _rSeq.getArray() + _rSeq.getLength();
267 7526 : while ( pLoop != pEnd )
268 : {
269 7314 : if ( pLoop->Name == _rPropertyName )
270 : {
271 212 : ::std::copy( pLoop + 1, pEnd, pLoop );
272 212 : _rSeq.realloc( _rSeq.getLength() - 1 );
273 212 : break;
274 : }
275 7102 : ++pLoop;
276 : }
277 212 : }
278 : }
279 :
280 106 : void ORichTextModel::describeFixedProperties( Sequence< Property >& _rProps ) const
281 : {
282 106 : BEGIN_DESCRIBE_PROPERTIES( 1, OControlModel )
283 106 : DECL_PROP2( TABINDEX, sal_Int16, BOUND, MAYBEDEFAULT );
284 : END_DESCRIBE_PROPERTIES();
285 :
286 : // properties which the OPropertyContainerHelper is responsible for
287 106 : Sequence< Property > aContainedProperties;
288 106 : describeProperties( aContainedProperties );
289 :
290 : // properties which the FontControlModel is responsible for
291 212 : Sequence< Property > aFontProperties;
292 106 : describeFontRelatedProperties( aFontProperties );
293 :
294 212 : _rProps = concatSequences( aContainedProperties, aFontProperties, _rProps );
295 106 : }
296 :
297 :
298 106 : void ORichTextModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
299 : {
300 106 : 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 106 : 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 106 : lcl_removeProperty( _rAggregateProps, PROPERTY_WRITING_MODE );
310 106 : }
311 :
312 :
313 6371 : void SAL_CALL ORichTextModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
314 : {
315 6371 : if ( isRegisteredProperty( _nHandle ) )
316 : {
317 4259 : OPropertyContainerHelper::getFastPropertyValue( _rValue, _nHandle );
318 : }
319 2112 : else if ( isFontRelatedProperty( _nHandle ) )
320 : {
321 2112 : FontControlModel::getFastPropertyValue( _rValue, _nHandle );
322 : }
323 : else
324 : {
325 0 : OControlModel::getFastPropertyValue( _rValue, _nHandle );
326 : }
327 6371 : }
328 :
329 :
330 1627 : sal_Bool SAL_CALL ORichTextModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw( IllegalArgumentException )
331 : {
332 1627 : sal_Bool bModified = sal_False;
333 :
334 1627 : if ( isRegisteredProperty( _nHandle ) )
335 : {
336 1346 : bModified = OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
337 : }
338 281 : else if ( isFontRelatedProperty( _nHandle ) )
339 : {
340 281 : bModified = FontControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
341 : }
342 : else
343 : {
344 0 : bModified = OControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
345 : }
346 :
347 1626 : return bModified;
348 : }
349 :
350 :
351 561 : void SAL_CALL ORichTextModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception)
352 : {
353 561 : if ( isRegisteredProperty( _nHandle ) )
354 : {
355 435 : OPropertyContainerHelper::setFastPropertyValue( _nHandle, _rValue );
356 :
357 435 : 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 39 : OutputDevice* pRefDevice = VCLUnoHelper::GetOutputDevice( m_xReferenceDevice );
366 : OSL_ENSURE( pRefDevice, "ORichTextModel::setFastPropertyValue_NoBroadcast: empty reference device?" );
367 39 : 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 39 : break;
379 :
380 : case PROPERTY_ID_TEXT:
381 : {
382 41 : MutexRelease aReleaseMutex( m_aMutex );
383 41 : impl_smlock_setEngineText( m_sLastKnownEngineText );
384 : }
385 41 : break;
386 : } // switch ( _nHandle )
387 : }
388 126 : else if ( isFontRelatedProperty( _nHandle ) )
389 : {
390 : FontControlModel::setFastPropertyValue_NoBroadcast_impl(
391 : *this, &ORichTextModel::setDependentFastPropertyValue,
392 126 : _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 561 : }
413 :
414 :
415 1876 : Any ORichTextModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
416 : {
417 1876 : Any aDefault;
418 :
419 1876 : switch ( _nHandle )
420 : {
421 : case PROPERTY_ID_WRITING_MODE:
422 : case PROPERTY_ID_CONTEXT_WRITING_MODE:
423 208 : aDefault <<= WritingMode2::CONTEXT;
424 208 : break;
425 :
426 : case PROPERTY_ID_LINEEND_FORMAT:
427 104 : aDefault <<= (sal_Int16)LineEndFormat::LINE_FEED;
428 104 : break;
429 :
430 : case PROPERTY_ID_ECHO_CHAR:
431 : case PROPERTY_ID_ALIGN:
432 : case PROPERTY_ID_MAXTEXTLEN:
433 316 : aDefault <<= (sal_Int16)0;
434 316 : 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 416 : aDefault <<= (sal_Bool)sal_True;
448 416 : 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 624 : aDefault <<= (sal_Bool)sal_False;
457 624 : break;
458 :
459 : case PROPERTY_ID_DEFAULTCONTROL:
460 104 : aDefault <<= (OUString)FRM_SUN_CONTROL_RICHTEXTCONTROL;
461 104 : 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 104 : aDefault <<= (sal_Int16)1;
471 104 : 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 1876 : return aDefault;
481 : }
482 :
483 :
484 41 : void ORichTextModel::impl_smlock_setEngineText( const OUString& _rText )
485 : {
486 41 : if ( m_pEngine.get() )
487 : {
488 41 : SolarMutexGuard aSolarGuard;
489 41 : m_bSettingEngineText = true;
490 41 : m_pEngine->SetText( _rText );
491 41 : m_bSettingEngineText = false;
492 : }
493 41 : }
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 20 : RichTextEngine* ORichTextModel::getEditEngine( const Reference< XControlModel >& _rxModel )
517 : {
518 20 : RichTextEngine* pEngine = NULL;
519 :
520 20 : Reference< XUnoTunnel > xTunnel( _rxModel, UNO_QUERY );
521 : OSL_ENSURE( xTunnel.is(), "ORichTextModel::getEditEngine: invalid model!" );
522 20 : if ( xTunnel.is() )
523 : {
524 : try
525 : {
526 20 : 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 20 : return pEngine;
534 : }
535 :
536 :
537 42 : Sequence< sal_Int8 > ORichTextModel::getEditEngineTunnelId()
538 : {
539 : static ::cppu::OImplementationId * pId = 0;
540 42 : if (! pId)
541 : {
542 1 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
543 1 : if (! pId)
544 : {
545 1 : static ::cppu::OImplementationId aId;
546 1 : pId = &aId;
547 1 : }
548 : }
549 42 : return pId->getImplementationId();
550 : }
551 :
552 :
553 1304 : IMPL_LINK( ORichTextModel, OnEngineContentModified, void*, /*_pNotInterestedIn*/ )
554 : {
555 652 : if ( !m_bSettingEngineText )
556 : {
557 572 : m_aModifyListeners.notifyEach( &XModifyListener::modified, EventObject( *this ) );
558 :
559 572 : 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 652 : return 0L;
567 : }
568 :
569 :
570 22 : sal_Int64 SAL_CALL ORichTextModel::getSomething( const Sequence< sal_Int8 >& _rId ) throw (RuntimeException, std::exception)
571 : {
572 22 : Sequence< sal_Int8 > aEditEngineAccessId( getEditEngineTunnelId() );
573 44 : if ( ( _rId.getLength() == aEditEngineAccessId.getLength() )
574 22 : && ( 0 == memcmp( aEditEngineAccessId.getConstArray(), _rId.getConstArray(), _rId.getLength() ) )
575 : )
576 20 : return reinterpret_cast< sal_Int64 >( m_pEngine.get() );
577 :
578 4 : Reference< XUnoTunnel > xAggTunnel;
579 2 : if ( query_aggregation( m_xAggregate, xAggTunnel ) )
580 2 : return xAggTunnel->getSomething( _rId );
581 :
582 22 : return 0;
583 : }
584 :
585 :
586 61 : void SAL_CALL ORichTextModel::addModifyListener( const Reference< XModifyListener >& _rxListener ) throw (RuntimeException, std::exception)
587 : {
588 61 : m_aModifyListeners.addInterface( _rxListener );
589 61 : }
590 :
591 :
592 59 : void SAL_CALL ORichTextModel::removeModifyListener( const Reference< XModifyListener >& _rxListener ) throw (RuntimeException, std::exception)
593 : {
594 59 : m_aModifyListeners.removeInterface( _rxListener );
595 59 : }
596 :
597 :
598 875 : void ORichTextModel::potentialTextChange( )
599 : {
600 875 : OUString sCurrentEngineText;
601 875 : if ( m_pEngine.get() )
602 875 : sCurrentEngineText = m_pEngine->GetText();
603 :
604 875 : if ( sCurrentEngineText != m_sLastKnownEngineText )
605 : {
606 14 : sal_Int32 nHandle = PROPERTY_ID_TEXT;
607 14 : Any aOldValue; aOldValue <<= m_sLastKnownEngineText;
608 28 : Any aNewValue; aNewValue <<= sCurrentEngineText;
609 14 : fire( &nHandle, &aNewValue, &aOldValue, 1, sal_False );
610 :
611 28 : m_sLastKnownEngineText = sCurrentEngineText;
612 875 : }
613 875 : }
614 :
615 :
616 : } // namespace frm
617 :
618 :
619 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|