LibreOffice Module forms (master) 1
richtextmodel.cxx
Go to the documentation of this file.
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"
23
24#include <property.hxx>
25#include <services.hxx>
26
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>
32
37#include <tools/debug.hxx>
39#include <editeng/editstat.hxx>
40#include <vcl/outdev.hxx>
41#include <vcl/svapp.hxx>
42
43
44namespace frm
45{
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::io;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::form;
52 using namespace ::com::sun::star::util;
53 using namespace ::com::sun::star::style;
54
55 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
56
57 ORichTextModel::ORichTextModel( const Reference< XComponentContext >& _rxFactory )
58 :OControlModel ( _rxFactory, OUString() )
59 ,FontControlModel ( true )
60 ,m_pEngine ( RichTextEngine::Create() )
61 ,m_bSettingEngineText( false )
62 ,m_aModifyListeners ( m_aMutex )
63 {
64 m_nClassId = FormComponentType::TEXTFIELD;
65
66 getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL ) >>= m_sDefaultControl;
67 // Default to 'flat' instead of '3D Look' for form controls, but don't change
68 // getPropertyDefaultByHandle, see tdf#152974
69 m_nBorder = 2;
70 getPropertyDefaultByHandle( PROPERTY_ID_ENABLED ) >>= m_bEnabled;
71 getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE ) >>= m_bEnableVisible;
72 getPropertyDefaultByHandle( PROPERTY_ID_HARDLINEBREAKS ) >>= m_bHardLineBreaks;
73 getPropertyDefaultByHandle( PROPERTY_ID_HSCROLL ) >>= m_bHScroll;
74 getPropertyDefaultByHandle( PROPERTY_ID_VSCROLL ) >>= m_bVScroll;
75 getPropertyDefaultByHandle( PROPERTY_ID_READONLY ) >>= m_bReadonly;
76 getPropertyDefaultByHandle( PROPERTY_ID_PRINTABLE ) >>= m_bPrintable;
77 m_aAlign = getPropertyDefaultByHandle( PROPERTY_ID_ALIGN );
78 getPropertyDefaultByHandle( PROPERTY_ID_ECHO_CHAR ) >>= m_nEchoChar;
79 getPropertyDefaultByHandle( PROPERTY_ID_MAXTEXTLEN ) >>= m_nMaxTextLength;
80 getPropertyDefaultByHandle( PROPERTY_ID_MULTILINE ) >>= m_bMultiLine;
81 getPropertyDefaultByHandle( PROPERTY_ID_RICH_TEXT ) >>= m_bReallyActAsRichText;
82 getPropertyDefaultByHandle( PROPERTY_ID_HIDEINACTIVESELECTION ) >>= m_bHideInactiveSelection;
83 getPropertyDefaultByHandle( PROPERTY_ID_LINEEND_FORMAT ) >>= m_nLineEndFormat;
84 getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE ) >>= m_nTextWritingMode;
85 getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE ) >>= m_nContextWritingMode;
86
87 implInit();
88 }
89
90
91 ORichTextModel::ORichTextModel( const ORichTextModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
92 :OControlModel ( _pOriginal, _rxFactory, false )
93 ,FontControlModel ( _pOriginal )
94 ,m_bSettingEngineText( false )
95 ,m_aModifyListeners ( m_aMutex )
96 {
97
98 m_aTabStop = _pOriginal->m_aTabStop;
99 m_aBackgroundColor = _pOriginal->m_aBackgroundColor;
100 m_aBorderColor = _pOriginal->m_aBorderColor;
101 m_aVerticalAlignment = _pOriginal->m_aVerticalAlignment;
102 m_sDefaultControl = _pOriginal->m_sDefaultControl;
103 m_sHelpText = _pOriginal->m_sHelpText;
104 m_sHelpURL = _pOriginal->m_sHelpURL;
105 m_nBorder = _pOriginal->m_nBorder;
106 m_bEnabled = _pOriginal->m_bEnabled;
107 m_bEnableVisible = _pOriginal->m_bEnableVisible;
108 m_bHardLineBreaks = _pOriginal->m_bHardLineBreaks;
109 m_bHScroll = _pOriginal->m_bHScroll;
110 m_bVScroll = _pOriginal->m_bVScroll;
111 m_bReadonly = _pOriginal->m_bReadonly;
112 m_bPrintable = _pOriginal->m_bPrintable;
113 m_bReallyActAsRichText = _pOriginal->m_bReallyActAsRichText;
114 m_bHideInactiveSelection = _pOriginal->m_bHideInactiveSelection;
115 m_nLineEndFormat = _pOriginal->m_nLineEndFormat;
116 m_nTextWritingMode = _pOriginal->m_nTextWritingMode;
117 m_nContextWritingMode = _pOriginal->m_nContextWritingMode;
118
119 m_aAlign = _pOriginal->m_aAlign;
120 m_nEchoChar = _pOriginal->m_nEchoChar;
121 m_nMaxTextLength = _pOriginal->m_nMaxTextLength;
122 m_bMultiLine = _pOriginal->m_bMultiLine;
123
124 m_pEngine.reset(_pOriginal->m_pEngine->Clone());
125 m_sLastKnownEngineText = m_pEngine->GetText();
126
127 implInit();
128 }
129
130
131 void ORichTextModel::implInit()
132 {
133 OSL_ENSURE(m_pEngine, "ORichTextModel::implInit: where's the engine?");
134 if (m_pEngine)
135 {
136 m_pEngine->SetModifyHdl( LINK( this, ORichTextModel, OnEngineContentModified ) );
137
138 EEControlBits nEngineControlWord = m_pEngine->GetControlWord();
139 nEngineControlWord = nEngineControlWord & ~EEControlBits::AUTOPAGESIZE;
140 m_pEngine->SetControlWord( nEngineControlWord );
141
142 rtl::Reference<VCLXDevice> pUnoRefDevice = new VCLXDevice;
143 {
145 pUnoRefDevice->SetOutputDevice( m_pEngine->GetRefDevice() );
146 }
147 m_xReferenceDevice = pUnoRefDevice;
148 }
149
150 implDoAggregation();
151 implRegisterProperties();
152 }
153
154
155 void ORichTextModel::implDoAggregation()
156 {
157 osl_atomic_increment( &m_refCount );
158
159 {
160 m_xAggregate = new ORichTextUnoWrapper( *m_pEngine, this );
161 setAggregation( m_xAggregate );
162 doSetDelegator();
163 }
164
165 osl_atomic_decrement( &m_refCount );
166 }
167
168
169 void ORichTextModel::implRegisterProperties()
170 {
171 registerProperty( PROPERTY_DEFAULTCONTROL, PROPERTY_ID_DEFAULTCONTROL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
172 &m_sDefaultControl, cppu::UnoType<decltype(m_sDefaultControl)>::get() );
173 registerProperty( PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
174 &m_sHelpText, cppu::UnoType<decltype(m_sHelpText)>::get() );
175 registerProperty( PROPERTY_HELPURL, PROPERTY_ID_HELPURL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
176 &m_sHelpURL, cppu::UnoType<decltype(m_sHelpURL)>::get() );
177 registerProperty( PROPERTY_ENABLED, PROPERTY_ID_ENABLED, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
178 &m_bEnabled, cppu::UnoType<decltype(m_bEnabled)>::get() );
179 registerProperty( PROPERTY_ENABLEVISIBLE, PROPERTY_ID_ENABLEVISIBLE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
180 &m_bEnableVisible, cppu::UnoType<decltype(m_bEnableVisible)>::get() );
181 registerProperty( PROPERTY_BORDER, PROPERTY_ID_BORDER, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
182 &m_nBorder, cppu::UnoType<decltype(m_nBorder)>::get() );
183 registerProperty( PROPERTY_HARDLINEBREAKS, PROPERTY_ID_HARDLINEBREAKS, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
184 &m_bHardLineBreaks, cppu::UnoType<decltype(m_bHardLineBreaks)>::get() );
185 registerProperty( PROPERTY_HSCROLL, PROPERTY_ID_HSCROLL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
186 &m_bHScroll, cppu::UnoType<decltype(m_bHScroll)>::get() );
187 registerProperty( PROPERTY_VSCROLL, PROPERTY_ID_VSCROLL, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
188 &m_bVScroll, cppu::UnoType<decltype(m_bVScroll)>::get() );
189 registerProperty( PROPERTY_READONLY, PROPERTY_ID_READONLY, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
190 &m_bReadonly, cppu::UnoType<decltype(m_bReadonly)>::get() );
191 registerProperty( PROPERTY_PRINTABLE, PROPERTY_ID_PRINTABLE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
192 &m_bPrintable, cppu::UnoType<decltype(m_bPrintable)>::get() );
193 registerProperty( PROPERTY_REFERENCE_DEVICE, PROPERTY_ID_REFERENCE_DEVICE, PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT,
194 &m_xReferenceDevice, cppu::UnoType<decltype(m_xReferenceDevice)>::get() );
195 registerProperty( PROPERTY_RICH_TEXT, PROPERTY_ID_RICH_TEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
196 &m_bReallyActAsRichText, cppu::UnoType<decltype(m_bReallyActAsRichText)>::get() );
197 registerProperty( PROPERTY_HIDEINACTIVESELECTION, PROPERTY_ID_HIDEINACTIVESELECTION, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
198 &m_bHideInactiveSelection, cppu::UnoType<decltype(m_bHideInactiveSelection)>::get() );
199
200 registerMayBeVoidProperty( PROPERTY_TABSTOP, PROPERTY_ID_TABSTOP, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
201 &m_aTabStop, cppu::UnoType<sal_Bool>::get() );
202 registerMayBeVoidProperty( PROPERTY_BACKGROUNDCOLOR, PROPERTY_ID_BACKGROUNDCOLOR, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
203 &m_aBackgroundColor, cppu::UnoType<sal_Int32>::get() );
204 registerMayBeVoidProperty( PROPERTY_BORDERCOLOR, PROPERTY_ID_BORDERCOLOR, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
205 &m_aBorderColor, cppu::UnoType<sal_Int32>::get() );
206 registerMayBeVoidProperty( PROPERTY_VERTICAL_ALIGN, PROPERTY_ID_VERTICAL_ALIGN, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
207 &m_aVerticalAlignment, cppu::UnoType<VerticalAlignment>::get() );
208
209 // properties which exist only for compatibility with the css.swt.UnoControlEditModel,
210 // since we replace the default implementation for this service
211 registerProperty( PROPERTY_ECHO_CHAR, PROPERTY_ID_ECHO_CHAR, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
212 &m_nEchoChar, cppu::UnoType<decltype(m_nEchoChar)>::get() );
213 registerProperty( PROPERTY_MAXTEXTLEN, PROPERTY_ID_MAXTEXTLEN, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
214 &m_nMaxTextLength, cppu::UnoType<decltype(m_nMaxTextLength)>::get() );
215 registerProperty( PROPERTY_MULTILINE, PROPERTY_ID_MULTILINE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
216 &m_bMultiLine, cppu::UnoType<decltype(m_bMultiLine)>::get() );
217 registerProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
218 &m_sLastKnownEngineText, cppu::UnoType<decltype(m_sLastKnownEngineText)>::get() );
219 registerProperty( PROPERTY_LINEEND_FORMAT, PROPERTY_ID_LINEEND_FORMAT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
220 &m_nLineEndFormat, cppu::UnoType<decltype(m_nLineEndFormat)>::get() );
221 registerProperty( PROPERTY_WRITING_MODE, PROPERTY_ID_WRITING_MODE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
222 &m_nTextWritingMode, cppu::UnoType<decltype(m_nTextWritingMode)>::get() );
223
224 registerProperty( PROPERTY_CONTEXT_WRITING_MODE, PROPERTY_ID_CONTEXT_WRITING_MODE, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT |
225 PropertyAttribute::TRANSIENT, &m_nContextWritingMode, cppu::UnoType<decltype(m_nContextWritingMode)>::get() );
226
227 registerMayBeVoidProperty( PROPERTY_ALIGN, PROPERTY_ID_ALIGN, PropertyAttribute::MAYBEVOID | PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
228 &m_aAlign, cppu::UnoType<sal_Int16>::get() );
229 }
230
231
232 ORichTextModel::~ORichTextModel( )
233 {
234 if ( !OComponentHelper::rBHelper.bDisposed )
235 {
236 acquire();
237 dispose();
238 }
239 if (m_pEngine)
240 {
242 m_pEngine.reset();
243 }
244 }
245
246
247 Any SAL_CALL ORichTextModel::queryAggregation( const Type& _rType )
248 {
249 Any aReturn = ORichTextModel_BASE::queryInterface( _rType );
250
251 if ( !aReturn.hasValue() )
252 aReturn = OControlModel::queryAggregation( _rType );
253
254 return aReturn;
255 }
256
257
259
260 OUString SAL_CALL ORichTextModel::getImplementationName()
261 {
262 return "com.sun.star.comp.forms.ORichTextModel";
263 }
264
265 Sequence< OUString > SAL_CALL ORichTextModel::getSupportedServiceNames()
266 {
267 Sequence< OUString > aOwnNames {
269 "com.sun.star.text.TextRange",
270 "com.sun.star.style.CharacterProperties",
271 "com.sun.star.style.ParagraphProperties",
272 "com.sun.star.style.CharacterPropertiesAsian",
273 "com.sun.star.style.CharacterPropertiesComplex",
274 "com.sun.star.style.ParagraphPropertiesAsian",
275 "com.sun.star.style.ParagraphPropertiesComplex" };
276
277 return ::comphelper::combineSequences(
278 getAggregateServiceNames(),
279 ::comphelper::concatSequences(
280 OControlModel::getSupportedServiceNames_Static(),
281 aOwnNames)
282 );
283 }
284
285 css::uno::Reference< css::util::XCloneable > SAL_CALL ORichTextModel::createClone()
286{
287 rtl::Reference<ORichTextModel> pClone = new ORichTextModel(this, getContext());
288 pClone->clonedFrom(this);
289 return pClone;
290}
291
292
293 void SAL_CALL ORichTextModel::disposing()
294 {
295 m_aModifyListeners.disposeAndClear( EventObject( *this ) );
296 OControlModel::disposing();
297 }
298
299
300 namespace
301 {
302 void lcl_removeProperty( Sequence< Property >& _rSeq, std::u16string_view _rPropertyName )
303 {
304 Property* pLoop = _rSeq.getArray();
305 Property* pEnd = _rSeq.getArray() + _rSeq.getLength();
306 while ( pLoop != pEnd )
307 {
308 if ( pLoop->Name == _rPropertyName )
309 {
310 ::std::copy( pLoop + 1, pEnd, pLoop );
311 _rSeq.realloc( _rSeq.getLength() - 1 );
312 break;
313 }
314 ++pLoop;
315 }
316 }
317 }
318
319 void ORichTextModel::describeFixedProperties( Sequence< Property >& _rProps ) const
320 {
321 OControlModel::describeFixedProperties( _rProps );
322 sal_Int32 nOldCount = _rProps.getLength();
323 _rProps.realloc( nOldCount + 1);
324 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
325 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT);
326 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
327
328 // properties which the OPropertyContainerHelper is responsible for
329 Sequence< Property > aContainedProperties;
330 describeProperties( aContainedProperties );
331
332 // properties which the FontControlModel is responsible for
333 Sequence< Property > aFontProperties;
334 describeFontRelatedProperties( aFontProperties );
335
336 _rProps = concatSequences( aContainedProperties, aFontProperties, _rProps );
337 }
338
339
340 void ORichTextModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
341 {
342 OControlModel::describeAggregateProperties( _rAggregateProps );
343
344 // our aggregate (the SvxUnoText) declares a FontDescriptor property, as does
345 // our FormControlFont base class. We remove it from the base class' sequence
346 // here, and later on care for both instances being in sync
347 lcl_removeProperty( _rAggregateProps, PROPERTY_FONT );
348
349 // similar, the WritingMode property is declared in our aggregate, too, but we override
350 // it, since the aggregate does no proper PropertyState handling.
351 lcl_removeProperty( _rAggregateProps, PROPERTY_WRITING_MODE );
352 }
353
354
355 void SAL_CALL ORichTextModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
356 {
357 if ( isRegisteredProperty( _nHandle ) )
358 {
359 OPropertyContainerHelper::getFastPropertyValue( _rValue, _nHandle );
360 }
361 else if ( isFontRelatedProperty( _nHandle ) )
362 {
363 FontControlModel::getFastPropertyValue( _rValue, _nHandle );
364 }
365 else
366 {
367 OControlModel::getFastPropertyValue( _rValue, _nHandle );
368 }
369 }
370
371
372 sal_Bool SAL_CALL ORichTextModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
373 {
374 bool bModified = false;
375
376 if ( isRegisteredProperty( _nHandle ) )
377 {
378 bModified = OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
379 }
380 else if ( isFontRelatedProperty( _nHandle ) )
381 {
382 bModified = FontControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
383 }
384 else
385 {
386 bModified = OControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
387 }
388
389 return bModified;
390 }
391
392
393 void SAL_CALL ORichTextModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
394 {
395 if ( isRegisteredProperty( _nHandle ) )
396 {
397 OPropertyContainerHelper::setFastPropertyValue( _nHandle, _rValue );
398
399 switch ( _nHandle )
400 {
402 {
403 #if OSL_DEBUG_LEVEL > 0
404 MapMode aOldMapMode = m_pEngine->GetRefDevice()->GetMapMode();
405 #endif
406
407 OutputDevice* pRefDevice = VCLUnoHelper::GetOutputDevice( m_xReferenceDevice );
408 OSL_ENSURE( pRefDevice, "ORichTextModel::setFastPropertyValue_NoBroadcast: empty reference device?" );
409 m_pEngine->SetRefDevice( pRefDevice );
410
411 #if OSL_DEBUG_LEVEL > 0
412 MapMode aNewMapMode = m_pEngine->GetRefDevice()->GetMapMode();
413 OSL_ENSURE( aNewMapMode.GetMapUnit() == aOldMapMode.GetMapUnit(),
414 "ORichTextModel::setFastPropertyValue_NoBroadcast: You should not tamper with the MapUnit of the ref device!" );
415 // if this assertion here is triggered, then we would need to adjust all
416 // items in all text portions in all paragraphs in the attributes of the EditEngine,
417 // as long as they are MapUnit-dependent. This holds at least for the FontSize.
418 #endif
419 }
420 break;
421
422 case PROPERTY_ID_TEXT:
423 {
424 MutexRelease aReleaseMutex( m_aMutex );
425 impl_smlock_setEngineText( m_sLastKnownEngineText );
426 }
427 break;
428 } // switch ( _nHandle )
429 }
430 else if ( isFontRelatedProperty( _nHandle ) )
431 {
432 FontControlModel::setFastPropertyValue_NoBroadcast_impl(
433 *this, &ORichTextModel::setDependentFastPropertyValue,
434 _nHandle, _rValue);
435 }
436 else
437 {
438 switch ( _nHandle )
439 {
441 {
442 // forward to our aggregate, so the EditEngine knows about it
443 if ( m_xAggregateSet.is() )
444 m_xAggregateSet->setPropertyValue( "WritingMode", _rValue );
445 }
446 break;
447
448 default:
449 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
450 break;
451 }
452 }
453 }
454
455 // note tdf#152974, we can't simply change a default here because properties
456 // that match the default are not exported, so for compatibility these
457 // can't be changed without some sort of solution for that
458 Any ORichTextModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
459 {
460 Any aDefault;
461
462 switch ( _nHandle )
463 {
466 aDefault <<= WritingMode2::CONTEXT;
467 break;
468
470 aDefault <<= sal_Int16(LineEndFormat::LINE_FEED);
471 break;
472
476 aDefault <<= sal_Int16(0);
477 break;
478
483 /* void */
484 break;
485
490 aDefault <<= true;
491 break;
492
499 aDefault <<= false;
500 break;
501
503 aDefault <<= OUString(FRM_SUN_CONTROL_RICHTEXTCONTROL);
504 break;
505
508 case PROPERTY_ID_TEXT:
509 aDefault <<= OUString();
510 break;
511
513 aDefault <<= sal_Int16(1);
514 break;
515
516 default:
517 if ( isFontRelatedProperty( _nHandle ) )
518 aDefault = FontControlModel::getPropertyDefaultByHandle( _nHandle );
519 else
520 aDefault = OControlModel::getPropertyDefaultByHandle( _nHandle );
521 }
522
523 return aDefault;
524 }
525
526
527 void ORichTextModel::impl_smlock_setEngineText( const OUString& _rText )
528 {
529 if (m_pEngine)
530 {
531 SolarMutexGuard aSolarGuard;
532 m_bSettingEngineText = true;
533 m_pEngine->SetText( _rText );
534 m_bSettingEngineText = false;
535 }
536 }
537
538
539 OUString SAL_CALL ORichTextModel::getServiceName()
540 {
542 }
543
544
545 RichTextEngine* ORichTextModel::getEditEngine( const Reference< XControlModel >& _rxModel )
546 {
547 RichTextEngine* pEngine = nullptr;
548
549 Reference< XUnoTunnel > xTunnel( _rxModel, UNO_QUERY );
550 OSL_ENSURE( xTunnel.is(), "ORichTextModel::getEditEngine: invalid model!" );
551 if ( xTunnel.is() )
552 {
553 try
554 {
555 pEngine = comphelper::getSomething_cast<RichTextEngine>(xTunnel->getSomething(getUnoTunnelId()));
556 }
557 catch( const Exception& )
558 {
559 TOOLS_WARN_EXCEPTION( "forms.richtext", "ORichTextModel::getEditEngine" );
560 }
561 }
562 return pEngine;
563 }
564
565
566 const Sequence<sal_Int8> & ORichTextModel::getUnoTunnelId()
567 {
568 static const comphelper::UnoIdInit aId;
569 return aId.getSeq();
570 }
571
572
573 IMPL_LINK_NOARG( ORichTextModel, OnEngineContentModified, LinkParamNone*, void )
574 {
575 if ( !m_bSettingEngineText )
576 {
577 m_aModifyListeners.notifyEach( &XModifyListener::modified, EventObject( *this ) );
578
579 potentialTextChange();
580 // is this a good idea? It may become expensive in case of larger texts,
581 // and this method here is called for every single changed character ...
582 // On the other hand, the API *requires* us to notify changes in the "Text"
583 // property immediately ...
584 }
585 }
586
587
588 sal_Int64 SAL_CALL ORichTextModel::getSomething( const Sequence< sal_Int8 >& _rId )
589 {
590 if (comphelper::isUnoTunnelId<ORichTextModel>(_rId))
591 return comphelper::getSomething_cast(m_pEngine.get()); // Note returning a different type
592
593 Reference< XUnoTunnel > xAggTunnel;
594 if ( query_aggregation( m_xAggregate, xAggTunnel ) )
595 return xAggTunnel->getSomething( _rId );
596
597 return 0;
598 }
599
600
601 void SAL_CALL ORichTextModel::addModifyListener( const Reference< XModifyListener >& _rxListener )
602 {
603 m_aModifyListeners.addInterface( _rxListener );
604 }
605
606
607 void SAL_CALL ORichTextModel::removeModifyListener( const Reference< XModifyListener >& _rxListener )
608 {
609 m_aModifyListeners.removeInterface( _rxListener );
610 }
611
612
613 void ORichTextModel::potentialTextChange( )
614 {
615 OUString sCurrentEngineText;
616 if (m_pEngine)
617 sCurrentEngineText = m_pEngine->GetText();
618
619 if ( sCurrentEngineText != m_sLastKnownEngineText )
620 {
621 sal_Int32 nHandle = PROPERTY_ID_TEXT;
622 Any aOldValue; aOldValue <<= m_sLastKnownEngineText;
623 Any aNewValue; aNewValue <<= sCurrentEngineText;
624 fire( &nHandle, &aNewValue, &aOldValue, 1, false );
625
626 m_sLastKnownEngineText = sCurrentEngineText;
627 }
628 }
629
630
631} // namespace frm
632
633
634extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
636 css::uno::Sequence<css::uno::Any> const &)
637{
638 return cppu::acquire(new frm::ORichTextModel(context));
639}
640
641/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
MapUnit GetMapUnit() const
static OutputDevice * GetOutputDevice(const css::uno::Reference< css::awt::XDevice > &rxDevice)
const css::uno::Sequence< sal_Int8 > & getSeq() const
ORichTextModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
ULONG m_refCount
EEControlBits
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_DEFAULTCONTROL
Definition: frm_strings.hxx:51
constexpr OUStringLiteral PROPERTY_REFERENCE_DEVICE
constexpr OUStringLiteral PROPERTY_READONLY
Definition: frm_strings.hxx:41
constexpr OUStringLiteral PROPERTY_TEXT
Definition: frm_strings.hxx:33
constexpr OUStringLiteral PROPERTY_BACKGROUNDCOLOR
constexpr OUStringLiteral PROPERTY_VERTICAL_ALIGN
Definition: frm_strings.hxx:85
constexpr OUStringLiteral PROPERTY_LINEEND_FORMAT
constexpr OUStringLiteral PROPERTY_ALIGN
Definition: frm_strings.hxx:84
constexpr OUStringLiteral PROPERTY_HELPURL
constexpr OUStringLiteral PROPERTY_VSCROLL
constexpr OUStringLiteral PROPERTY_MAXTEXTLEN
Definition: frm_strings.hxx:52
constexpr OUStringLiteral PROPERTY_HELPTEXT
constexpr OUStringLiteral PROPERTY_PRINTABLE
constexpr OUStringLiteral PROPERTY_HSCROLL
constexpr OUStringLiteral PROPERTY_FONT
constexpr OUStringLiteral PROPERTY_ECHO_CHAR
constexpr OUStringLiteral PROPERTY_HARDLINEBREAKS
constexpr OUStringLiteral PROPERTY_ENABLEVISIBLE
Definition: frm_strings.hxx:40
constexpr OUStringLiteral PROPERTY_WRITING_MODE
constexpr OUStringLiteral PROPERTY_BORDERCOLOR
constexpr OUStringLiteral PROPERTY_TABSTOP
constexpr OUStringLiteral PROPERTY_HIDEINACTIVESELECTION
constexpr OUStringLiteral PROPERTY_RICH_TEXT
constexpr OUStringLiteral PROPERTY_BORDER
constexpr OUStringLiteral PROPERTY_MULTILINE
Definition: frm_strings.hxx:48
constexpr OUStringLiteral PROPERTY_ENABLED
Definition: frm_strings.hxx:39
constexpr OUStringLiteral PROPERTY_CONTEXT_WRITING_MODE
std::mutex m_aMutex
@ Exception
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
bool query_aggregation(const css::uno::Reference< css::uno::XAggregation > &_rxAggregate, css::uno::Reference< iface > &_rxOut)
sal_Int64 getSomething_cast(void *p)
Type
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
IMPL_LINK_NOARG(ORichTextModel, OnEngineContentModified, LinkParamNone *, void)
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
void dispose()
void copy(const css::uno::Reference< css::beans::XPropertySet > &, css::uno::Reference< css::beans::XPropertySet > const &)
copy the properties from one PropertySet into the next
#define PROPERTY_ID_LINEEND_FORMAT
Definition: property.hxx:299
#define PROPERTY_ID_READONLY
Definition: property.hxx:47
#define PROPERTY_ID_PRINTABLE
Definition: property.hxx:152
#define PROPERTY_ID_WRITING_MODE
Definition: property.hxx:55
#define PROPERTY_ID_MAXTEXTLEN
Definition: property.hxx:147
#define PROPERTY_ID_VSCROLL
Definition: property.hxx:102
#define PROPERTY_ID_ENABLEVISIBLE
Definition: property.hxx:200
#define PROPERTY_ID_BACKGROUNDCOLOR
Definition: property.hxx:93
#define PROPERTY_ID_HSCROLL
Definition: property.hxx:101
#define PROPERTY_ID_ECHO_CHAR
Definition: property.hxx:156
#define PROPERTY_ID_ENABLED
Definition: property.hxx:144
#define PROPERTY_ID_HELPTEXT
Definition: property.hxx:176
#define PROPERTY_ID_BORDERCOLOR
Definition: property.hxx:91
#define PROPERTY_ID_HARDLINEBREAKS
Definition: property.hxx:151
#define PROPERTY_ID_HIDEINACTIVESELECTION
Definition: property.hxx:86
#define PROPERTY_ID_ALIGN
Definition: property.hxx:98
#define PROPERTY_ID_VERTICAL_ALIGN
Definition: property.hxx:57
#define PROPERTY_ID_RICH_TEXT
Definition: property.hxx:262
#define PROPERTY_ID_TABSTOP
Definition: property.hxx:103
#define PROPERTY_ID_DEFAULTCONTROL
Definition: property.hxx:78
#define PROPERTY_ID_REFERENCE_DEVICE
Definition: property.hxx:73
#define PROPERTY_ID_MULTILINE
Definition: property.hxx:129
#define PROPERTY_ID_CONTEXT_WRITING_MODE
Definition: property.hxx:56
#define PROPERTY_ID_HELPURL
Definition: property.hxx:187
#define PROPERTY_ID_TEXT
Definition: property.hxx:83
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
#define PROPERTY_ID_BORDER
Definition: property.hxx:97
sal_Int32 nHandle
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_forms_ORichTextModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral FRM_SUN_CONTROL_RICHTEXTCONTROL
Definition: services.hxx:166
constexpr OUStringLiteral FRM_SUN_COMPONENT_RICHTEXTCONTROL
Definition: services.hxx:133
unsigned char sal_Bool