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