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