LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / richtext / richtextmodel.cxx
blob2dcfd7a18587363cba1bc91e4023af54e3f3e177
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/form/FormComponentType.hpp>
29 #include <com/sun/star/text/WritingMode2.hpp>
30 #include <com/sun/star/style/VerticalAlignment.hpp>
32 #include <comphelper/guarding.hxx>
33 #include <comphelper/servicehelper.hxx>
34 #include <svl/itempool.hxx>
35 #include <toolkit/awt/vclxdevice.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <tools/diagnose_ex.h>
38 #include <editeng/editstat.hxx>
39 #include <vcl/outdev.hxx>
40 #include <vcl/svapp.hxx>
43 namespace frm
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::awt;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::io;
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 getPropertyDefaultByHandle( PROPERTY_ID_BORDER ) >>= m_nBorder;
67 getPropertyDefaultByHandle( PROPERTY_ID_ENABLED ) >>= m_bEnabled;
68 getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE ) >>= m_bEnableVisible;
69 getPropertyDefaultByHandle( PROPERTY_ID_HARDLINEBREAKS ) >>= m_bHardLineBreaks;
70 getPropertyDefaultByHandle( PROPERTY_ID_HSCROLL ) >>= m_bHScroll;
71 getPropertyDefaultByHandle( PROPERTY_ID_VSCROLL ) >>= m_bVScroll;
72 getPropertyDefaultByHandle( PROPERTY_ID_READONLY ) >>= m_bReadonly;
73 getPropertyDefaultByHandle( PROPERTY_ID_PRINTABLE ) >>= m_bPrintable;
74 m_aAlign = getPropertyDefaultByHandle( PROPERTY_ID_ALIGN );
75 getPropertyDefaultByHandle( PROPERTY_ID_ECHO_CHAR ) >>= m_nEchoChar;
76 getPropertyDefaultByHandle( PROPERTY_ID_MAXTEXTLEN ) >>= m_nMaxTextLength;
77 getPropertyDefaultByHandle( PROPERTY_ID_MULTILINE ) >>= m_bMultiLine;
78 getPropertyDefaultByHandle( PROPERTY_ID_RICH_TEXT ) >>= m_bReallyActAsRichText;
79 getPropertyDefaultByHandle( PROPERTY_ID_HIDEINACTIVESELECTION ) >>= m_bHideInactiveSelection;
80 getPropertyDefaultByHandle( PROPERTY_ID_LINEEND_FORMAT ) >>= m_nLineEndFormat;
81 getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE ) >>= m_nTextWritingMode;
82 getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE ) >>= m_nContextWritingMode;
84 implInit();
88 ORichTextModel::ORichTextModel( const ORichTextModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
89 :OControlModel ( _pOriginal, _rxFactory, false )
90 ,FontControlModel ( _pOriginal )
91 ,m_bSettingEngineText( false )
92 ,m_aModifyListeners ( m_aMutex )
95 m_aTabStop = _pOriginal->m_aTabStop;
96 m_aBackgroundColor = _pOriginal->m_aBackgroundColor;
97 m_aBorderColor = _pOriginal->m_aBorderColor;
98 m_aVerticalAlignment = _pOriginal->m_aVerticalAlignment;
99 m_sDefaultControl = _pOriginal->m_sDefaultControl;
100 m_sHelpText = _pOriginal->m_sHelpText;
101 m_sHelpURL = _pOriginal->m_sHelpURL;
102 m_nBorder = _pOriginal->m_nBorder;
103 m_bEnabled = _pOriginal->m_bEnabled;
104 m_bEnableVisible = _pOriginal->m_bEnableVisible;
105 m_bHardLineBreaks = _pOriginal->m_bHardLineBreaks;
106 m_bHScroll = _pOriginal->m_bHScroll;
107 m_bVScroll = _pOriginal->m_bVScroll;
108 m_bReadonly = _pOriginal->m_bReadonly;
109 m_bPrintable = _pOriginal->m_bPrintable;
110 m_bReallyActAsRichText = _pOriginal->m_bReallyActAsRichText;
111 m_bHideInactiveSelection = _pOriginal->m_bHideInactiveSelection;
112 m_nLineEndFormat = _pOriginal->m_nLineEndFormat;
113 m_nTextWritingMode = _pOriginal->m_nTextWritingMode;
114 m_nContextWritingMode = _pOriginal->m_nContextWritingMode;
116 m_aAlign = _pOriginal->m_aAlign;
117 m_nEchoChar = _pOriginal->m_nEchoChar;
118 m_nMaxTextLength = _pOriginal->m_nMaxTextLength;
119 m_bMultiLine = _pOriginal->m_bMultiLine;
121 m_pEngine.reset(_pOriginal->m_pEngine->Clone());
122 m_sLastKnownEngineText = m_pEngine->GetText();
124 implInit();
128 void ORichTextModel::implInit()
130 OSL_ENSURE(m_pEngine, "ORichTextModel::implInit: where's the engine?");
131 if (m_pEngine)
133 m_pEngine->SetModifyHdl( LINK( this, ORichTextModel, OnEngineContentModified ) );
135 EEControlBits nEngineControlWord = m_pEngine->GetControlWord();
136 nEngineControlWord = nEngineControlWord & ~EEControlBits::AUTOPAGESIZE;
137 m_pEngine->SetControlWord( nEngineControlWord );
139 rtl::Reference<VCLXDevice> pUnoRefDevice = new VCLXDevice;
141 SolarMutexGuard g;
142 pUnoRefDevice->SetOutputDevice( m_pEngine->GetRefDevice() );
144 m_xReferenceDevice = pUnoRefDevice;
147 implDoAggregation();
148 implRegisterProperties();
152 void ORichTextModel::implDoAggregation()
154 osl_atomic_increment( &m_refCount );
157 m_xAggregate = new ORichTextUnoWrapper( *m_pEngine, this );
158 setAggregation( m_xAggregate );
159 doSetDelegator();
162 osl_atomic_decrement( &m_refCount );
166 void ORichTextModel::implRegisterProperties()
168 registerProperty( PROPERTY_DEFAULTCONTROL, PROPERTY_ID_DEFAULTCONTROL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
169 &m_sDefaultControl, cppu::UnoType<decltype(m_sDefaultControl)>::get() );
170 registerProperty( PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
171 &m_sHelpText, cppu::UnoType<decltype(m_sHelpText)>::get() );
172 registerProperty( PROPERTY_HELPURL, PROPERTY_ID_HELPURL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
173 &m_sHelpURL, cppu::UnoType<decltype(m_sHelpURL)>::get() );
174 registerProperty( PROPERTY_ENABLED, PROPERTY_ID_ENABLED, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
175 &m_bEnabled, cppu::UnoType<decltype(m_bEnabled)>::get() );
176 registerProperty( PROPERTY_ENABLEVISIBLE, PROPERTY_ID_ENABLEVISIBLE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
177 &m_bEnableVisible, cppu::UnoType<decltype(m_bEnableVisible)>::get() );
178 registerProperty( PROPERTY_BORDER, PROPERTY_ID_BORDER, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
179 &m_nBorder, cppu::UnoType<decltype(m_nBorder)>::get() );
180 registerProperty( PROPERTY_HARDLINEBREAKS, PROPERTY_ID_HARDLINEBREAKS, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
181 &m_bHardLineBreaks, cppu::UnoType<decltype(m_bHardLineBreaks)>::get() );
182 registerProperty( PROPERTY_HSCROLL, PROPERTY_ID_HSCROLL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
183 &m_bHScroll, cppu::UnoType<decltype(m_bHScroll)>::get() );
184 registerProperty( PROPERTY_VSCROLL, PROPERTY_ID_VSCROLL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
185 &m_bVScroll, cppu::UnoType<decltype(m_bVScroll)>::get() );
186 registerProperty( PROPERTY_READONLY, PROPERTY_ID_READONLY, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
187 &m_bReadonly, cppu::UnoType<decltype(m_bReadonly)>::get() );
188 registerProperty( PROPERTY_PRINTABLE, PROPERTY_ID_PRINTABLE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
189 &m_bPrintable, cppu::UnoType<decltype(m_bPrintable)>::get() );
190 registerProperty( PROPERTY_REFERENCE_DEVICE, PROPERTY_ID_REFERENCE_DEVICE, PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT,
191 &m_xReferenceDevice, cppu::UnoType<decltype(m_xReferenceDevice)>::get() );
192 registerProperty( PROPERTY_RICH_TEXT, PROPERTY_ID_RICH_TEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
193 &m_bReallyActAsRichText, cppu::UnoType<decltype(m_bReallyActAsRichText)>::get() );
194 registerProperty( PROPERTY_HIDEINACTIVESELECTION, PROPERTY_ID_HIDEINACTIVESELECTION, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
195 &m_bHideInactiveSelection, cppu::UnoType<decltype(m_bHideInactiveSelection)>::get() );
197 registerMayBeVoidProperty( PROPERTY_TABSTOP, PROPERTY_ID_TABSTOP, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
198 &m_aTabStop, cppu::UnoType<sal_Bool>::get() );
199 registerMayBeVoidProperty( PROPERTY_BACKGROUNDCOLOR, PROPERTY_ID_BACKGROUNDCOLOR, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
200 &m_aBackgroundColor, cppu::UnoType<sal_Int32>::get() );
201 registerMayBeVoidProperty( PROPERTY_BORDERCOLOR, PROPERTY_ID_BORDERCOLOR, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
202 &m_aBorderColor, cppu::UnoType<sal_Int32>::get() );
203 registerMayBeVoidProperty( PROPERTY_VERTICAL_ALIGN, PROPERTY_ID_VERTICAL_ALIGN, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
204 &m_aVerticalAlignment, cppu::UnoType<VerticalAlignment>::get() );
206 // properties which exist only for compatibility with the css.swt.UnoControlEditModel,
207 // since we replace the default implementation for this service
208 registerProperty( PROPERTY_ECHO_CHAR, PROPERTY_ID_ECHO_CHAR, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
209 &m_nEchoChar, cppu::UnoType<decltype(m_nEchoChar)>::get() );
210 registerProperty( PROPERTY_MAXTEXTLEN, PROPERTY_ID_MAXTEXTLEN, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
211 &m_nMaxTextLength, cppu::UnoType<decltype(m_nMaxTextLength)>::get() );
212 registerProperty( PROPERTY_MULTILINE, PROPERTY_ID_MULTILINE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
213 &m_bMultiLine, cppu::UnoType<decltype(m_bMultiLine)>::get() );
214 registerProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
215 &m_sLastKnownEngineText, cppu::UnoType<decltype(m_sLastKnownEngineText)>::get() );
216 registerProperty( PROPERTY_LINEEND_FORMAT, PROPERTY_ID_LINEEND_FORMAT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
217 &m_nLineEndFormat, cppu::UnoType<decltype(m_nLineEndFormat)>::get() );
218 registerProperty( PROPERTY_WRITING_MODE, PROPERTY_ID_WRITING_MODE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
219 &m_nTextWritingMode, cppu::UnoType<decltype(m_nTextWritingMode)>::get() );
221 registerProperty( PROPERTY_CONTEXT_WRITING_MODE, PROPERTY_ID_CONTEXT_WRITING_MODE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT |
222 PropertyAttribute::TRANSIENT, &m_nContextWritingMode, cppu::UnoType<decltype(m_nContextWritingMode)>::get() );
224 registerMayBeVoidProperty( PROPERTY_ALIGN, PROPERTY_ID_ALIGN, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
225 &m_aAlign, cppu::UnoType<sal_Int16>::get() );
229 ORichTextModel::~ORichTextModel( )
231 if ( !OComponentHelper::rBHelper.bDisposed )
233 acquire();
234 dispose();
236 if (m_pEngine)
238 SolarMutexGuard g;
239 m_pEngine.reset();
244 Any SAL_CALL ORichTextModel::queryAggregation( const Type& _rType )
246 Any aReturn = ORichTextModel_BASE::queryInterface( _rType );
248 if ( !aReturn.hasValue() )
249 aReturn = OControlModel::queryAggregation( _rType );
251 return aReturn;
255 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ORichTextModel, OControlModel, ORichTextModel_BASE )
257 OUString SAL_CALL ORichTextModel::getImplementationName()
259 return "com.sun.star.comp.forms.ORichTextModel";
262 Sequence< OUString > SAL_CALL ORichTextModel::getSupportedServiceNames()
264 Sequence< OUString > aOwnNames {
265 FRM_SUN_COMPONENT_RICHTEXTCONTROL,
266 "com.sun.star.text.TextRange",
267 "com.sun.star.style.CharacterProperties",
268 "com.sun.star.style.ParagraphProperties",
269 "com.sun.star.style.CharacterPropertiesAsian",
270 "com.sun.star.style.CharacterPropertiesComplex",
271 "com.sun.star.style.ParagraphPropertiesAsian",
272 "com.sun.star.style.ParagraphPropertiesComplex" };
274 return ::comphelper::combineSequences(
275 getAggregateServiceNames(),
276 ::comphelper::concatSequences(
277 OControlModel::getSupportedServiceNames_Static(),
278 aOwnNames)
282 css::uno::Reference< css::util::XCloneable > SAL_CALL ORichTextModel::createClone()
284 rtl::Reference<ORichTextModel> pClone = new ORichTextModel(this, getContext());
285 pClone->clonedFrom(this);
286 return pClone;
290 void SAL_CALL ORichTextModel::disposing()
292 m_aModifyListeners.disposeAndClear( EventObject( *this ) );
293 OControlModel::disposing();
297 namespace
299 void lcl_removeProperty( Sequence< Property >& _rSeq, std::u16string_view _rPropertyName )
301 Property* pLoop = _rSeq.getArray();
302 Property* pEnd = _rSeq.getArray() + _rSeq.getLength();
303 while ( pLoop != pEnd )
305 if ( pLoop->Name == _rPropertyName )
307 ::std::copy( pLoop + 1, pEnd, pLoop );
308 _rSeq.realloc( _rSeq.getLength() - 1 );
309 break;
311 ++pLoop;
316 void ORichTextModel::describeFixedProperties( Sequence< Property >& _rProps ) const
318 OControlModel::describeFixedProperties( _rProps );
319 sal_Int32 nOldCount = _rProps.getLength();
320 _rProps.realloc( nOldCount + 1);
321 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
322 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT);
323 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
325 // properties which the OPropertyContainerHelper is responsible for
326 Sequence< Property > aContainedProperties;
327 describeProperties( aContainedProperties );
329 // properties which the FontControlModel is responsible for
330 Sequence< Property > aFontProperties;
331 describeFontRelatedProperties( aFontProperties );
333 _rProps = concatSequences( aContainedProperties, aFontProperties, _rProps );
337 void ORichTextModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
339 OControlModel::describeAggregateProperties( _rAggregateProps );
341 // our aggregate (the SvxUnoText) declares a FontDescriptor property, as does
342 // our FormControlFont base class. We remove it from the base class' sequence
343 // here, and later on care for both instances being in sync
344 lcl_removeProperty( _rAggregateProps, PROPERTY_FONT );
346 // similar, the WritingMode property is declared in our aggregate, too, but we override
347 // it, since the aggregate does no proper PropertyState handling.
348 lcl_removeProperty( _rAggregateProps, PROPERTY_WRITING_MODE );
352 void SAL_CALL ORichTextModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
354 if ( isRegisteredProperty( _nHandle ) )
356 OPropertyContainerHelper::getFastPropertyValue( _rValue, _nHandle );
358 else if ( isFontRelatedProperty( _nHandle ) )
360 FontControlModel::getFastPropertyValue( _rValue, _nHandle );
362 else
364 OControlModel::getFastPropertyValue( _rValue, _nHandle );
369 sal_Bool SAL_CALL ORichTextModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
371 bool bModified = false;
373 if ( isRegisteredProperty( _nHandle ) )
375 bModified = OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
377 else if ( isFontRelatedProperty( _nHandle ) )
379 bModified = FontControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
381 else
383 bModified = OControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
386 return bModified;
390 void SAL_CALL ORichTextModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
392 if ( isRegisteredProperty( _nHandle ) )
394 OPropertyContainerHelper::setFastPropertyValue( _nHandle, _rValue );
396 switch ( _nHandle )
398 case PROPERTY_ID_REFERENCE_DEVICE:
400 #if OSL_DEBUG_LEVEL > 0
401 MapMode aOldMapMode = m_pEngine->GetRefDevice()->GetMapMode();
402 #endif
404 OutputDevice* pRefDevice = VCLUnoHelper::GetOutputDevice( m_xReferenceDevice );
405 OSL_ENSURE( pRefDevice, "ORichTextModel::setFastPropertyValue_NoBroadcast: empty reference device?" );
406 m_pEngine->SetRefDevice( pRefDevice );
408 #if OSL_DEBUG_LEVEL > 0
409 MapMode aNewMapMode = m_pEngine->GetRefDevice()->GetMapMode();
410 OSL_ENSURE( aNewMapMode.GetMapUnit() == aOldMapMode.GetMapUnit(),
411 "ORichTextModel::setFastPropertyValue_NoBroadcast: You should not tamper with the MapUnit of the ref device!" );
412 // if this assertion here is triggered, then we would need to adjust all
413 // items in all text portions in all paragraphs in the attributes of the EditEngine,
414 // as long as they are MapUnit-dependent. This holds at least for the FontSize.
415 #endif
417 break;
419 case PROPERTY_ID_TEXT:
421 MutexRelease aReleaseMutex( m_aMutex );
422 impl_smlock_setEngineText( m_sLastKnownEngineText );
424 break;
425 } // switch ( _nHandle )
427 else if ( isFontRelatedProperty( _nHandle ) )
429 FontControlModel::setFastPropertyValue_NoBroadcast_impl(
430 *this, &ORichTextModel::setDependentFastPropertyValue,
431 _nHandle, _rValue);
433 else
435 switch ( _nHandle )
437 case PROPERTY_ID_WRITING_MODE:
439 // forward to our aggregate, so the EditEngine knows about it
440 if ( m_xAggregateSet.is() )
441 m_xAggregateSet->setPropertyValue( "WritingMode", _rValue );
443 break;
445 default:
446 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
447 break;
453 Any ORichTextModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
455 Any aDefault;
457 switch ( _nHandle )
459 case PROPERTY_ID_WRITING_MODE:
460 case PROPERTY_ID_CONTEXT_WRITING_MODE:
461 aDefault <<= WritingMode2::CONTEXT;
462 break;
464 case PROPERTY_ID_LINEEND_FORMAT:
465 aDefault <<= sal_Int16(LineEndFormat::LINE_FEED);
466 break;
468 case PROPERTY_ID_ECHO_CHAR:
469 case PROPERTY_ID_ALIGN:
470 case PROPERTY_ID_MAXTEXTLEN:
471 aDefault <<= sal_Int16(0);
472 break;
474 case PROPERTY_ID_TABSTOP:
475 case PROPERTY_ID_BACKGROUNDCOLOR:
476 case PROPERTY_ID_BORDERCOLOR:
477 case PROPERTY_ID_VERTICAL_ALIGN:
478 /* void */
479 break;
481 case PROPERTY_ID_ENABLED:
482 case PROPERTY_ID_ENABLEVISIBLE:
483 case PROPERTY_ID_PRINTABLE:
484 case PROPERTY_ID_HIDEINACTIVESELECTION:
485 aDefault <<= true;
486 break;
488 case PROPERTY_ID_HARDLINEBREAKS:
489 case PROPERTY_ID_HSCROLL:
490 case PROPERTY_ID_VSCROLL:
491 case PROPERTY_ID_READONLY:
492 case PROPERTY_ID_MULTILINE:
493 case PROPERTY_ID_RICH_TEXT:
494 aDefault <<= false;
495 break;
497 case PROPERTY_ID_DEFAULTCONTROL:
498 aDefault <<= OUString(FRM_SUN_CONTROL_RICHTEXTCONTROL);
499 break;
501 case PROPERTY_ID_HELPTEXT:
502 case PROPERTY_ID_HELPURL:
503 case PROPERTY_ID_TEXT:
504 aDefault <<= OUString();
505 break;
507 case PROPERTY_ID_BORDER:
508 aDefault <<= sal_Int16(1);
509 break;
511 default:
512 if ( isFontRelatedProperty( _nHandle ) )
513 aDefault = FontControlModel::getPropertyDefaultByHandle( _nHandle );
514 else
515 aDefault = OControlModel::getPropertyDefaultByHandle( _nHandle );
518 return aDefault;
522 void ORichTextModel::impl_smlock_setEngineText( const OUString& _rText )
524 if (m_pEngine)
526 SolarMutexGuard aSolarGuard;
527 m_bSettingEngineText = true;
528 m_pEngine->SetText( _rText );
529 m_bSettingEngineText = false;
534 OUString SAL_CALL ORichTextModel::getServiceName()
536 return FRM_SUN_COMPONENT_RICHTEXTCONTROL;
540 RichTextEngine* ORichTextModel::getEditEngine( const Reference< XControlModel >& _rxModel )
542 RichTextEngine* pEngine = nullptr;
544 Reference< XUnoTunnel > xTunnel( _rxModel, UNO_QUERY );
545 OSL_ENSURE( xTunnel.is(), "ORichTextModel::getEditEngine: invalid model!" );
546 if ( xTunnel.is() )
550 pEngine = comphelper::getSomething_cast<RichTextEngine>(xTunnel->getSomething(getUnoTunnelId()));
552 catch( const Exception& )
554 TOOLS_WARN_EXCEPTION( "forms.richtext", "ORichTextModel::getEditEngine" );
557 return pEngine;
561 Sequence<sal_Int8> ORichTextModel::getUnoTunnelId()
563 static const comphelper::UnoIdInit aId;
564 return aId.getSeq();
568 IMPL_LINK_NOARG( ORichTextModel, OnEngineContentModified, LinkParamNone*, void )
570 if ( !m_bSettingEngineText )
572 m_aModifyListeners.notifyEach( &XModifyListener::modified, EventObject( *this ) );
574 potentialTextChange();
575 // is this a good idea? It may become expensive in case of larger texts,
576 // and this method here is called for every single changed character ...
577 // On the other hand, the API *requires* us to notify changes in the "Text"
578 // property immediately ...
583 sal_Int64 SAL_CALL ORichTextModel::getSomething( const Sequence< sal_Int8 >& _rId )
585 if (comphelper::isUnoTunnelId<ORichTextModel>(_rId))
586 return comphelper::getSomething_cast(m_pEngine.get()); // Note returning a different type
588 Reference< XUnoTunnel > xAggTunnel;
589 if ( query_aggregation( m_xAggregate, xAggTunnel ) )
590 return xAggTunnel->getSomething( _rId );
592 return 0;
596 void SAL_CALL ORichTextModel::addModifyListener( const Reference< XModifyListener >& _rxListener )
598 m_aModifyListeners.addInterface( _rxListener );
602 void SAL_CALL ORichTextModel::removeModifyListener( const Reference< XModifyListener >& _rxListener )
604 m_aModifyListeners.removeInterface( _rxListener );
608 void ORichTextModel::potentialTextChange( )
610 OUString sCurrentEngineText;
611 if (m_pEngine)
612 sCurrentEngineText = m_pEngine->GetText();
614 if ( sCurrentEngineText != m_sLastKnownEngineText )
616 sal_Int32 nHandle = PROPERTY_ID_TEXT;
617 Any aOldValue; aOldValue <<= m_sLastKnownEngineText;
618 Any aNewValue; aNewValue <<= sCurrentEngineText;
619 fire( &nHandle, &aNewValue, &aOldValue, 1, false );
621 m_sLastKnownEngineText = sCurrentEngineText;
626 } // namespace frm
629 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
630 com_sun_star_comp_forms_ORichTextModel_get_implementation(css::uno::XComponentContext* context,
631 css::uno::Sequence<css::uno::Any> const &)
633 return cppu::acquire(new frm::ORichTextModel(context));
636 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */