tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / forms / source / richtext / richtextmodel.cxx
blobfa2900f11903b6700cfe06871ef75d21d702c8a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "richtextmodel.hxx"
21 #include "richtextengine.hxx"
22 #include "richtextunowrapper.hxx"
24 #include <property.hxx>
25 #include <services.hxx>
27 #include <com/sun/star/awt/LineEndFormat.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/form/FormComponentType.hpp>
30 #include <com/sun/star/text/WritingMode2.hpp>
31 #include <com/sun/star/style/VerticalAlignment.hpp>
33 #include <comphelper/guarding.hxx>
34 #include <comphelper/servicehelper.hxx>
35 #include <toolkit/awt/vclxdevice.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <tools/debug.hxx>
38 #include <comphelper/diagnose_ex.hxx>
39 #include <editeng/editstat.hxx>
40 #include <vcl/outdev.hxx>
41 #include <vcl/svapp.hxx>
44 namespace frm
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::awt;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::form;
51 using namespace ::com::sun::star::util;
52 using namespace ::com::sun::star::style;
54 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
56 ORichTextModel::ORichTextModel( const Reference< XComponentContext >& _rxFactory )
57 :OControlModel ( _rxFactory, OUString() )
58 ,FontControlModel ( true )
59 ,m_pEngine ( RichTextEngine::Create() )
60 ,m_bSettingEngineText( false )
61 ,m_aModifyListeners ( m_aMutex )
63 m_nClassId = FormComponentType::TEXTFIELD;
65 getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL ) >>= m_sDefaultControl;
66 // Default to 'flat' instead of '3D Look' for form controls, but don't change
67 // getPropertyDefaultByHandle, see tdf#152974
68 m_nBorder = 2;
69 getPropertyDefaultByHandle( PROPERTY_ID_ENABLED ) >>= m_bEnabled;
70 getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE ) >>= m_bEnableVisible;
71 getPropertyDefaultByHandle( PROPERTY_ID_HARDLINEBREAKS ) >>= m_bHardLineBreaks;
72 getPropertyDefaultByHandle( PROPERTY_ID_HSCROLL ) >>= m_bHScroll;
73 getPropertyDefaultByHandle( PROPERTY_ID_VSCROLL ) >>= m_bVScroll;
74 getPropertyDefaultByHandle( PROPERTY_ID_READONLY ) >>= m_bReadonly;
75 getPropertyDefaultByHandle( PROPERTY_ID_PRINTABLE ) >>= m_bPrintable;
76 m_aAlign = getPropertyDefaultByHandle( PROPERTY_ID_ALIGN );
77 getPropertyDefaultByHandle( PROPERTY_ID_ECHO_CHAR ) >>= m_nEchoChar;
78 getPropertyDefaultByHandle( PROPERTY_ID_MAXTEXTLEN ) >>= m_nMaxTextLength;
79 getPropertyDefaultByHandle( PROPERTY_ID_MULTILINE ) >>= m_bMultiLine;
80 getPropertyDefaultByHandle( PROPERTY_ID_RICH_TEXT ) >>= m_bReallyActAsRichText;
81 getPropertyDefaultByHandle( PROPERTY_ID_HIDEINACTIVESELECTION ) >>= m_bHideInactiveSelection;
82 getPropertyDefaultByHandle( PROPERTY_ID_LINEEND_FORMAT ) >>= m_nLineEndFormat;
83 getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE ) >>= m_nTextWritingMode;
84 getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE ) >>= m_nContextWritingMode;
86 implInit();
90 ORichTextModel::ORichTextModel( const ORichTextModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
91 :OControlModel ( _pOriginal, _rxFactory, false )
92 ,FontControlModel ( _pOriginal )
93 ,m_bSettingEngineText( false )
94 ,m_aModifyListeners ( m_aMutex )
97 m_aTabStop = _pOriginal->m_aTabStop;
98 m_aBackgroundColor = _pOriginal->m_aBackgroundColor;
99 m_aBorderColor = _pOriginal->m_aBorderColor;
100 m_aVerticalAlignment = _pOriginal->m_aVerticalAlignment;
101 m_sDefaultControl = _pOriginal->m_sDefaultControl;
102 m_sHelpText = _pOriginal->m_sHelpText;
103 m_sHelpURL = _pOriginal->m_sHelpURL;
104 m_nBorder = _pOriginal->m_nBorder;
105 m_bEnabled = _pOriginal->m_bEnabled;
106 m_bEnableVisible = _pOriginal->m_bEnableVisible;
107 m_bHardLineBreaks = _pOriginal->m_bHardLineBreaks;
108 m_bHScroll = _pOriginal->m_bHScroll;
109 m_bVScroll = _pOriginal->m_bVScroll;
110 m_bReadonly = _pOriginal->m_bReadonly;
111 m_bPrintable = _pOriginal->m_bPrintable;
112 m_bReallyActAsRichText = _pOriginal->m_bReallyActAsRichText;
113 m_bHideInactiveSelection = _pOriginal->m_bHideInactiveSelection;
114 m_nLineEndFormat = _pOriginal->m_nLineEndFormat;
115 m_nTextWritingMode = _pOriginal->m_nTextWritingMode;
116 m_nContextWritingMode = _pOriginal->m_nContextWritingMode;
118 m_aAlign = _pOriginal->m_aAlign;
119 m_nEchoChar = _pOriginal->m_nEchoChar;
120 m_nMaxTextLength = _pOriginal->m_nMaxTextLength;
121 m_bMultiLine = _pOriginal->m_bMultiLine;
123 m_pEngine.reset(_pOriginal->m_pEngine->Clone());
124 m_sLastKnownEngineText = m_pEngine->GetText();
126 implInit();
130 void ORichTextModel::implInit()
132 OSL_ENSURE(m_pEngine, "ORichTextModel::implInit: where's the engine?");
133 if (m_pEngine)
135 m_pEngine->SetModifyHdl( LINK( this, ORichTextModel, OnEngineContentModified ) );
137 EEControlBits nEngineControlWord = m_pEngine->GetControlWord();
138 nEngineControlWord = nEngineControlWord & ~EEControlBits::AUTOPAGESIZE;
139 m_pEngine->SetControlWord( nEngineControlWord );
141 rtl::Reference<VCLXDevice> pUnoRefDevice = new VCLXDevice;
143 SolarMutexGuard g;
144 pUnoRefDevice->SetOutputDevice( m_pEngine->GetRefDevice() );
146 m_xReferenceDevice = pUnoRefDevice;
149 implDoAggregation();
150 implRegisterProperties();
154 void ORichTextModel::implDoAggregation()
156 osl_atomic_increment( &m_refCount );
159 m_xAggregate = new ORichTextUnoWrapper( *m_pEngine, this );
160 setAggregation( m_xAggregate );
161 doSetDelegator();
164 osl_atomic_decrement( &m_refCount );
168 void ORichTextModel::implRegisterProperties()
170 registerProperty( PROPERTY_DEFAULTCONTROL, PROPERTY_ID_DEFAULTCONTROL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
171 &m_sDefaultControl, cppu::UnoType<decltype(m_sDefaultControl)>::get() );
172 registerProperty( PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
173 &m_sHelpText, cppu::UnoType<decltype(m_sHelpText)>::get() );
174 registerProperty( PROPERTY_HELPURL, PROPERTY_ID_HELPURL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
175 &m_sHelpURL, cppu::UnoType<decltype(m_sHelpURL)>::get() );
176 registerProperty( PROPERTY_ENABLED, PROPERTY_ID_ENABLED, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
177 &m_bEnabled, cppu::UnoType<decltype(m_bEnabled)>::get() );
178 registerProperty( PROPERTY_ENABLEVISIBLE, PROPERTY_ID_ENABLEVISIBLE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
179 &m_bEnableVisible, cppu::UnoType<decltype(m_bEnableVisible)>::get() );
180 registerProperty( PROPERTY_BORDER, PROPERTY_ID_BORDER, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
181 &m_nBorder, cppu::UnoType<decltype(m_nBorder)>::get() );
182 registerProperty( PROPERTY_HARDLINEBREAKS, PROPERTY_ID_HARDLINEBREAKS, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
183 &m_bHardLineBreaks, cppu::UnoType<decltype(m_bHardLineBreaks)>::get() );
184 registerProperty( PROPERTY_HSCROLL, PROPERTY_ID_HSCROLL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
185 &m_bHScroll, cppu::UnoType<decltype(m_bHScroll)>::get() );
186 registerProperty( PROPERTY_VSCROLL, PROPERTY_ID_VSCROLL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
187 &m_bVScroll, cppu::UnoType<decltype(m_bVScroll)>::get() );
188 registerProperty( PROPERTY_READONLY, PROPERTY_ID_READONLY, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
189 &m_bReadonly, cppu::UnoType<decltype(m_bReadonly)>::get() );
190 registerProperty( PROPERTY_PRINTABLE, PROPERTY_ID_PRINTABLE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
191 &m_bPrintable, cppu::UnoType<decltype(m_bPrintable)>::get() );
192 registerProperty( PROPERTY_REFERENCE_DEVICE, PROPERTY_ID_REFERENCE_DEVICE, PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT,
193 &m_xReferenceDevice, cppu::UnoType<decltype(m_xReferenceDevice)>::get() );
194 registerProperty( PROPERTY_RICH_TEXT, PROPERTY_ID_RICH_TEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
195 &m_bReallyActAsRichText, cppu::UnoType<decltype(m_bReallyActAsRichText)>::get() );
196 registerProperty( PROPERTY_HIDEINACTIVESELECTION, PROPERTY_ID_HIDEINACTIVESELECTION, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
197 &m_bHideInactiveSelection, cppu::UnoType<decltype(m_bHideInactiveSelection)>::get() );
199 registerMayBeVoidProperty( PROPERTY_TABSTOP, PROPERTY_ID_TABSTOP, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
200 &m_aTabStop, cppu::UnoType<sal_Bool>::get() );
201 registerMayBeVoidProperty( PROPERTY_BACKGROUNDCOLOR, PROPERTY_ID_BACKGROUNDCOLOR, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
202 &m_aBackgroundColor, cppu::UnoType<sal_Int32>::get() );
203 registerMayBeVoidProperty( PROPERTY_BORDERCOLOR, PROPERTY_ID_BORDERCOLOR, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
204 &m_aBorderColor, cppu::UnoType<sal_Int32>::get() );
205 registerMayBeVoidProperty( PROPERTY_VERTICAL_ALIGN, PROPERTY_ID_VERTICAL_ALIGN, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
206 &m_aVerticalAlignment, cppu::UnoType<VerticalAlignment>::get() );
208 // properties which exist only for compatibility with the css.swt.UnoControlEditModel,
209 // since we replace the default implementation for this service
210 registerProperty( PROPERTY_ECHO_CHAR, PROPERTY_ID_ECHO_CHAR, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
211 &m_nEchoChar, cppu::UnoType<decltype(m_nEchoChar)>::get() );
212 registerProperty( PROPERTY_MAXTEXTLEN, PROPERTY_ID_MAXTEXTLEN, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
213 &m_nMaxTextLength, cppu::UnoType<decltype(m_nMaxTextLength)>::get() );
214 registerProperty( PROPERTY_MULTILINE, PROPERTY_ID_MULTILINE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
215 &m_bMultiLine, cppu::UnoType<decltype(m_bMultiLine)>::get() );
216 registerProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
217 &m_sLastKnownEngineText, cppu::UnoType<decltype(m_sLastKnownEngineText)>::get() );
218 registerProperty( PROPERTY_LINEEND_FORMAT, PROPERTY_ID_LINEEND_FORMAT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
219 &m_nLineEndFormat, cppu::UnoType<decltype(m_nLineEndFormat)>::get() );
220 registerProperty( PROPERTY_WRITING_MODE, PROPERTY_ID_WRITING_MODE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
221 &m_nTextWritingMode, cppu::UnoType<decltype(m_nTextWritingMode)>::get() );
223 registerProperty( PROPERTY_CONTEXT_WRITING_MODE, PROPERTY_ID_CONTEXT_WRITING_MODE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT |
224 PropertyAttribute::TRANSIENT, &m_nContextWritingMode, cppu::UnoType<decltype(m_nContextWritingMode)>::get() );
226 registerMayBeVoidProperty( PROPERTY_ALIGN, PROPERTY_ID_ALIGN, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
227 &m_aAlign, cppu::UnoType<sal_Int16>::get() );
231 ORichTextModel::~ORichTextModel( )
233 if ( !OComponentHelper::rBHelper.bDisposed )
235 acquire();
236 dispose();
238 if (m_pEngine)
240 SolarMutexGuard g;
241 m_pEngine.reset();
246 Any SAL_CALL ORichTextModel::queryAggregation( const Type& _rType )
248 Any aReturn = ORichTextModel_BASE::queryInterface( _rType );
250 if ( !aReturn.hasValue() )
251 aReturn = OControlModel::queryAggregation( _rType );
253 return aReturn;
257 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ORichTextModel, OControlModel, ORichTextModel_BASE )
259 OUString SAL_CALL ORichTextModel::getImplementationName()
261 return u"com.sun.star.comp.forms.ORichTextModel"_ustr;
264 Sequence< OUString > SAL_CALL ORichTextModel::getSupportedServiceNames()
266 static constexpr OUString aOwnNames[] {
267 FRM_SUN_COMPONENT_RICHTEXTCONTROL,
268 u"com.sun.star.text.TextRange"_ustr,
269 u"com.sun.star.style.CharacterProperties"_ustr,
270 u"com.sun.star.style.ParagraphProperties"_ustr,
271 u"com.sun.star.style.CharacterPropertiesAsian"_ustr,
272 u"com.sun.star.style.CharacterPropertiesComplex"_ustr,
273 u"com.sun.star.style.ParagraphPropertiesAsian"_ustr,
274 u"com.sun.star.style.ParagraphPropertiesComplex"_ustr };
276 return ::comphelper::combineSequences(
277 getAggregateServiceNames(),
278 ::comphelper::concatSequences(
279 OControlModel::getSupportedServiceNames_Static(),
280 aOwnNames)
284 css::uno::Reference< css::util::XCloneable > SAL_CALL ORichTextModel::createClone()
286 rtl::Reference<ORichTextModel> pClone = new ORichTextModel(this, getContext());
287 pClone->clonedFrom(this);
288 return pClone;
292 void SAL_CALL ORichTextModel::disposing()
294 m_aModifyListeners.disposeAndClear( EventObject( *this ) );
295 OControlModel::disposing();
299 namespace
301 void lcl_removeProperty( Sequence< Property >& _rSeq, std::u16string_view _rPropertyName )
303 Property* pLoop = _rSeq.getArray();
304 Property* pEnd = _rSeq.getArray() + _rSeq.getLength();
305 while ( pLoop != pEnd )
307 if ( pLoop->Name == _rPropertyName )
309 ::std::copy( pLoop + 1, pEnd, pLoop );
310 _rSeq.realloc( _rSeq.getLength() - 1 );
311 break;
313 ++pLoop;
318 void ORichTextModel::describeFixedProperties( Sequence< Property >& _rProps ) const
320 OControlModel::describeFixedProperties( _rProps );
321 sal_Int32 nOldCount = _rProps.getLength();
322 _rProps.realloc( nOldCount + 1);
323 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
324 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT);
325 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
327 // properties which the OPropertyContainerHelper is responsible for
328 Sequence< Property > aContainedProperties;
329 describeProperties( aContainedProperties );
331 // properties which the FontControlModel is responsible for
332 Sequence< Property > aFontProperties;
333 describeFontRelatedProperties( aFontProperties );
335 _rProps = concatSequences( aContainedProperties, aFontProperties, _rProps );
339 void ORichTextModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
341 OControlModel::describeAggregateProperties( _rAggregateProps );
343 // our aggregate (the SvxUnoText) declares a FontDescriptor property, as does
344 // our FormControlFont base class. We remove it from the base class' sequence
345 // here, and later on care for both instances being in sync
346 lcl_removeProperty( _rAggregateProps, PROPERTY_FONT );
348 // similar, the WritingMode property is declared in our aggregate, too, but we override
349 // it, since the aggregate does no proper PropertyState handling.
350 lcl_removeProperty( _rAggregateProps, PROPERTY_WRITING_MODE );
354 void SAL_CALL ORichTextModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
356 if ( isRegisteredProperty( _nHandle ) )
358 OPropertyContainerHelper::getFastPropertyValue( _rValue, _nHandle );
360 else if ( isFontRelatedProperty( _nHandle ) )
362 FontControlModel::getFastPropertyValue( _rValue, _nHandle );
364 else
366 OControlModel::getFastPropertyValue( _rValue, _nHandle );
371 sal_Bool SAL_CALL ORichTextModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
373 bool bModified = false;
375 if ( isRegisteredProperty( _nHandle ) )
377 bModified = OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
379 else if ( isFontRelatedProperty( _nHandle ) )
381 bModified = FontControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
383 else
385 bModified = OControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
388 return bModified;
392 void SAL_CALL ORichTextModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
394 if ( isRegisteredProperty( _nHandle ) )
396 OPropertyContainerHelper::setFastPropertyValue( _nHandle, _rValue );
398 switch ( _nHandle )
400 case PROPERTY_ID_REFERENCE_DEVICE:
402 #if OSL_DEBUG_LEVEL > 0
403 MapMode aOldMapMode = m_pEngine->GetRefDevice()->GetMapMode();
404 #endif
406 OutputDevice* pRefDevice = VCLUnoHelper::GetOutputDevice( m_xReferenceDevice );
407 OSL_ENSURE( pRefDevice, "ORichTextModel::setFastPropertyValue_NoBroadcast: empty reference device?" );
408 m_pEngine->SetRefDevice( pRefDevice );
410 #if OSL_DEBUG_LEVEL > 0
411 MapMode aNewMapMode = m_pEngine->GetRefDevice()->GetMapMode();
412 OSL_ENSURE( aNewMapMode.GetMapUnit() == aOldMapMode.GetMapUnit(),
413 "ORichTextModel::setFastPropertyValue_NoBroadcast: You should not tamper with the MapUnit of the ref device!" );
414 // if this assertion here is triggered, then we would need to adjust all
415 // items in all text portions in all paragraphs in the attributes of the EditEngine,
416 // as long as they are MapUnit-dependent. This holds at least for the FontSize.
417 #endif
419 break;
421 case PROPERTY_ID_TEXT:
423 MutexRelease aReleaseMutex( m_aMutex );
424 impl_smlock_setEngineText( m_sLastKnownEngineText );
426 break;
427 } // switch ( _nHandle )
429 else if ( isFontRelatedProperty( _nHandle ) )
431 FontControlModel::setFastPropertyValue_NoBroadcast_impl(
432 *this, &ORichTextModel::setDependentFastPropertyValue,
433 _nHandle, _rValue);
435 else
437 switch ( _nHandle )
439 case PROPERTY_ID_WRITING_MODE:
441 // forward to our aggregate, so the EditEngine knows about it
442 if ( m_xAggregateSet.is() )
443 m_xAggregateSet->setPropertyValue( u"WritingMode"_ustr, _rValue );
445 break;
447 default:
448 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
449 break;
454 // note tdf#152974, we can't simply change a default here because properties
455 // that match the default are not exported, so for compatibility these
456 // can't be changed without some sort of solution for that
457 Any ORichTextModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
459 Any aDefault;
461 switch ( _nHandle )
463 case PROPERTY_ID_WRITING_MODE:
464 case PROPERTY_ID_CONTEXT_WRITING_MODE:
465 aDefault <<= WritingMode2::CONTEXT;
466 break;
468 case PROPERTY_ID_LINEEND_FORMAT:
469 aDefault <<= sal_Int16(LineEndFormat::LINE_FEED);
470 break;
472 case PROPERTY_ID_ECHO_CHAR:
473 case PROPERTY_ID_ALIGN:
474 case PROPERTY_ID_MAXTEXTLEN:
475 aDefault <<= sal_Int16(0);
476 break;
478 case PROPERTY_ID_TABSTOP:
479 case PROPERTY_ID_BACKGROUNDCOLOR:
480 case PROPERTY_ID_BORDERCOLOR:
481 case PROPERTY_ID_VERTICAL_ALIGN:
482 /* void */
483 break;
485 case PROPERTY_ID_ENABLED:
486 case PROPERTY_ID_ENABLEVISIBLE:
487 case PROPERTY_ID_PRINTABLE:
488 case PROPERTY_ID_HIDEINACTIVESELECTION:
489 aDefault <<= true;
490 break;
492 case PROPERTY_ID_HARDLINEBREAKS:
493 case PROPERTY_ID_HSCROLL:
494 case PROPERTY_ID_VSCROLL:
495 case PROPERTY_ID_READONLY:
496 case PROPERTY_ID_MULTILINE:
497 case PROPERTY_ID_RICH_TEXT:
498 aDefault <<= false;
499 break;
501 case PROPERTY_ID_DEFAULTCONTROL:
502 aDefault <<= FRM_SUN_CONTROL_RICHTEXTCONTROL;
503 break;
505 case PROPERTY_ID_HELPTEXT:
506 case PROPERTY_ID_HELPURL:
507 case PROPERTY_ID_TEXT:
508 aDefault <<= OUString();
509 break;
511 case PROPERTY_ID_BORDER:
512 aDefault <<= sal_Int16(1);
513 break;
515 default:
516 if ( isFontRelatedProperty( _nHandle ) )
517 aDefault = FontControlModel::getPropertyDefaultByHandle( _nHandle );
518 else
519 aDefault = OControlModel::getPropertyDefaultByHandle( _nHandle );
522 return aDefault;
526 void ORichTextModel::impl_smlock_setEngineText( const OUString& _rText )
528 if (m_pEngine)
530 SolarMutexGuard aSolarGuard;
531 m_bSettingEngineText = true;
532 m_pEngine->SetText( _rText );
533 m_bSettingEngineText = false;
538 OUString SAL_CALL ORichTextModel::getServiceName()
540 return FRM_SUN_COMPONENT_RICHTEXTCONTROL;
544 RichTextEngine* ORichTextModel::getEditEngine( const Reference< XControlModel >& _rxModel )
546 RichTextEngine* pEngine = nullptr;
548 Reference< XUnoTunnel > xTunnel( _rxModel, UNO_QUERY );
549 OSL_ENSURE( xTunnel.is(), "ORichTextModel::getEditEngine: invalid model!" );
550 if ( xTunnel.is() )
554 pEngine = comphelper::getSomething_cast<RichTextEngine>(xTunnel->getSomething(getUnoTunnelId()));
556 catch( const Exception& )
558 TOOLS_WARN_EXCEPTION( "forms.richtext", "ORichTextModel::getEditEngine" );
561 return pEngine;
565 const Sequence<sal_Int8> & ORichTextModel::getUnoTunnelId()
567 static const comphelper::UnoIdInit aId;
568 return aId.getSeq();
572 IMPL_LINK_NOARG( ORichTextModel, OnEngineContentModified, LinkParamNone*, void )
574 if ( !m_bSettingEngineText )
576 m_aModifyListeners.notifyEach( &XModifyListener::modified, EventObject( *this ) );
578 potentialTextChange();
579 // is this a good idea? It may become expensive in case of larger texts,
580 // and this method here is called for every single changed character ...
581 // On the other hand, the API *requires* us to notify changes in the "Text"
582 // property immediately ...
587 sal_Int64 SAL_CALL ORichTextModel::getSomething( const Sequence< sal_Int8 >& _rId )
589 if (comphelper::isUnoTunnelId<ORichTextModel>(_rId))
590 return comphelper::getSomething_cast(m_pEngine.get()); // Note returning a different type
592 if (auto xAggTunnel = query_aggregation<XUnoTunnel>(m_xAggregate))
593 return xAggTunnel->getSomething( _rId );
595 return 0;
599 void SAL_CALL ORichTextModel::addModifyListener( const Reference< XModifyListener >& _rxListener )
601 m_aModifyListeners.addInterface( _rxListener );
605 void SAL_CALL ORichTextModel::removeModifyListener( const Reference< XModifyListener >& _rxListener )
607 m_aModifyListeners.removeInterface( _rxListener );
611 void ORichTextModel::potentialTextChange( )
613 OUString sCurrentEngineText;
614 if (m_pEngine)
615 sCurrentEngineText = m_pEngine->GetText();
617 if ( sCurrentEngineText != m_sLastKnownEngineText )
619 sal_Int32 nHandle = PROPERTY_ID_TEXT;
620 Any aOldValue; aOldValue <<= m_sLastKnownEngineText;
621 Any aNewValue; aNewValue <<= sCurrentEngineText;
622 fire( &nHandle, &aNewValue, &aOldValue, 1, false );
624 m_sLastKnownEngineText = sCurrentEngineText;
629 } // namespace frm
632 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
633 com_sun_star_comp_forms_ORichTextModel_get_implementation(css::uno::XComponentContext* context,
634 css::uno::Sequence<css::uno::Any> const &)
636 return cppu::acquire(new frm::ORichTextModel(context));
639 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */