LCOV - code coverage report
Current view: top level - forms/source/richtext - richtextmodel.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 244 271 90.0 %
Date: 2014-11-03 Functions: 33 39 84.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10