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