LCOV - code coverage report
Current view: top level - sd/source/core/text - textapi.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 112 0.0 %
Date: 2014-04-11 Functions: 0 28 0.0 %
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             : 
      21             : #include <com/sun/star/text/XTextField.hpp>
      22             : #include <com/sun/star/container/XNameContainer.hpp>
      23             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      24             : 
      25             : #include <textapi.hxx>
      26             : #include <drawdoc.hxx>
      27             : #include <editeng/eeitem.hxx>
      28             : #include <editeng/editeng.hxx>
      29             : #include <editeng/outlobj.hxx>
      30             : #include "Outliner.hxx"
      31             : #include <svx/svdpool.hxx>
      32             : 
      33             : 
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::text;
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::container;
      38             : 
      39             : namespace sd {
      40             : 
      41             : class UndoTextAPIChanged : public SdrUndoAction
      42             : {
      43             : public:
      44             :     UndoTextAPIChanged( SdrModel& rModel, TextApiObject* pTextObj );
      45             :     virtual ~UndoTextAPIChanged();
      46             : 
      47             :     virtual void Undo() SAL_OVERRIDE;
      48             :     virtual void Redo() SAL_OVERRIDE;
      49             : 
      50             : protected:
      51             :     OutlinerParaObject* mpOldText;
      52             :     OutlinerParaObject* mpNewText;
      53             :     rtl::Reference< TextApiObject > mxTextObj;
      54             : };
      55             : 
      56           0 : UndoTextAPIChanged::UndoTextAPIChanged(SdrModel& rModel, TextApiObject* pTextObj )
      57             : : SdrUndoAction( rModel )
      58           0 : , mpOldText( pTextObj->CreateText() )
      59             : , mpNewText( 0 )
      60           0 : , mxTextObj( pTextObj )
      61             : {
      62           0 : }
      63             : 
      64           0 : UndoTextAPIChanged::~UndoTextAPIChanged()
      65             : {
      66           0 :     delete mpOldText;
      67           0 :     delete mpNewText;
      68           0 : }
      69             : 
      70           0 : void UndoTextAPIChanged::Undo()
      71             : {
      72           0 :     if( !mpNewText )
      73           0 :         mpNewText = mxTextObj->CreateText();
      74             : 
      75           0 :     mxTextObj->SetText( *mpOldText );
      76           0 : }
      77             : 
      78           0 : void UndoTextAPIChanged::Redo()
      79             : {
      80           0 :     if( mpNewText )
      81             :     {
      82           0 :         mxTextObj->SetText( *mpNewText );
      83             :     }
      84           0 : }
      85             : 
      86             : struct TextAPIEditSource_Impl
      87             : {
      88             :     // needed for "internal" refcounting
      89             :     SdDrawDocument*                 mpDoc;
      90             :     Outliner*                       mpOutliner;
      91             :     SvxOutlinerForwarder*           mpTextForwarder;
      92             :     sal_Int32                       mnRef;
      93             : };
      94             : 
      95             : class TextAPIEditSource : public SvxEditSource
      96             : {
      97             :     TextAPIEditSource_Impl* pImpl;
      98             : 
      99             :     virtual SvxEditSource*      Clone() const SAL_OVERRIDE;
     100             :     virtual SvxTextForwarder*   GetTextForwarder() SAL_OVERRIDE;
     101             :     virtual void                UpdateData() SAL_OVERRIDE;
     102             :     explicit            TextAPIEditSource( const TextAPIEditSource& rSource );
     103             : 
     104             : public:
     105             :                         TextAPIEditSource(SdDrawDocument* pDoc);
     106             :     virtual             ~TextAPIEditSource();
     107             : 
     108             :     void                Dispose();
     109             :     void                SetText( OutlinerParaObject& rText );
     110             :     OutlinerParaObject* CreateText();
     111             :     OUString            GetText();
     112           0 :     SdDrawDocument*     GetDoc() { return pImpl->mpDoc; }
     113             : };
     114             : 
     115           0 : const SvxItemPropertySet* ImplGetSdTextPortionPropertyMap()
     116             : {
     117             :     static const SfxItemPropertyMapEntry aSdTextPortionPropertyEntries[] =
     118             :     {
     119           0 :         SVX_UNOEDIT_CHAR_PROPERTIES,
     120           0 :         SVX_UNOEDIT_FONT_PROPERTIES,
     121           0 :         SVX_UNOEDIT_OUTLINER_PROPERTIES,
     122           0 :         SVX_UNOEDIT_PARA_PROPERTIES,
     123           0 :         {OUString("TextField"),                     EE_FEATURE_FIELD,   ::getCppuType((const Reference< XTextField >*)0),  PropertyAttribute::READONLY, 0 },
     124           0 :         {OUString("TextPortionType"),               WID_PORTIONTYPE,    ::getCppuType((const OUString*)0), PropertyAttribute::READONLY, 0 },
     125           0 :         {OUString("TextUserDefinedAttributes"),     EE_CHAR_XMLATTRIBS,     ::getCppuType((const Reference< XNameContainer >*)0)  ,        0,     0},
     126           0 :         {OUString("ParaUserDefinedAttributes"),     EE_PARA_XMLATTRIBS,     ::getCppuType((const Reference< XNameContainer >*)0)  ,        0,     0},
     127             :         { OUString(), 0, css::uno::Type(), 0, 0 }
     128           0 :     };
     129           0 :     static SvxItemPropertySet aSdTextPortionPropertyMap( aSdTextPortionPropertyEntries, SdrObject::GetGlobalDrawObjectItemPool() );
     130             : 
     131           0 :     return &aSdTextPortionPropertyMap;
     132             : }
     133             : 
     134           0 : TextApiObject::TextApiObject( TextAPIEditSource* pEditSource )
     135             : : SvxUnoText( pEditSource, ImplGetSdTextPortionPropertyMap(), Reference < XText >() )
     136           0 : , mpSource(pEditSource)
     137             : {
     138           0 : }
     139             : 
     140           0 : TextApiObject::~TextApiObject() throw()
     141             : {
     142           0 :     dispose();
     143           0 : }
     144             : 
     145           0 : rtl::Reference< TextApiObject > TextApiObject::create( SdDrawDocument* pDoc )
     146             : {
     147           0 :     rtl::Reference< TextApiObject > xRet( new TextApiObject( new TextAPIEditSource( pDoc ) ) );
     148           0 :     return xRet;
     149             : }
     150             : 
     151           0 : void SAL_CALL TextApiObject::dispose() throw(RuntimeException)
     152             : {
     153           0 :     if( mpSource )
     154             :     {
     155           0 :         mpSource->Dispose();
     156           0 :         delete mpSource;
     157           0 :         mpSource = 0;
     158             :     }
     159             : 
     160           0 : }
     161             : 
     162           0 : OutlinerParaObject* TextApiObject::CreateText()
     163             : {
     164           0 :     return mpSource->CreateText();
     165             : }
     166             : 
     167           0 : void TextApiObject::SetText( OutlinerParaObject& rText )
     168             : {
     169           0 :     SdrModel* pModel = mpSource->GetDoc();
     170           0 :     if( pModel && pModel->IsUndoEnabled() )
     171           0 :         pModel->AddUndo( new UndoTextAPIChanged( *pModel, this ) );
     172             : 
     173           0 :     mpSource->SetText( rText );
     174           0 :     maSelection.nStartPara = EE_PARA_MAX_COUNT;
     175           0 : }
     176             : 
     177           0 : OUString TextApiObject::GetText()
     178             : {
     179           0 :     return mpSource->GetText();
     180             : }
     181             : 
     182           0 : TextApiObject* TextApiObject::getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& xText )
     183             : {
     184           0 :     TextApiObject* pImpl = dynamic_cast< TextApiObject* >( xText.get() );
     185             : 
     186           0 :     if( !pImpl )
     187           0 :         pImpl = dynamic_cast< TextApiObject* >(  SvxUnoTextBase::getImplementation( xText ) );
     188             : 
     189           0 :     return pImpl;
     190             : }
     191             : 
     192           0 : TextAPIEditSource::TextAPIEditSource( const TextAPIEditSource& rSource )
     193           0 : : SvxEditSource( *this )
     194             : {
     195             :     // shallow copy; uses internal refcounting
     196           0 :     pImpl = rSource.pImpl;
     197           0 :     pImpl->mnRef++;
     198           0 : }
     199             : 
     200           0 : SvxEditSource* TextAPIEditSource::Clone() const
     201             : {
     202           0 :     return new TextAPIEditSource( *this );
     203             : }
     204             : 
     205           0 : void TextAPIEditSource::UpdateData()
     206             : {
     207             :     // data is kept in outliner all the time
     208           0 : }
     209             : 
     210           0 : TextAPIEditSource::TextAPIEditSource(SdDrawDocument* pDoc)
     211           0 : : pImpl(new TextAPIEditSource_Impl)
     212             : {
     213           0 :     pImpl->mpDoc = pDoc;
     214           0 :     pImpl->mpOutliner = 0;
     215           0 :     pImpl->mpTextForwarder = 0;
     216           0 :     pImpl->mnRef = 1;
     217           0 : }
     218             : 
     219           0 : TextAPIEditSource::~TextAPIEditSource()
     220             : {
     221           0 :     if (!--pImpl->mnRef)
     222           0 :         delete pImpl;
     223           0 : }
     224             : 
     225           0 : void TextAPIEditSource::Dispose()
     226             : {
     227           0 :     pImpl->mpDoc=0;
     228           0 :     delete pImpl->mpTextForwarder;
     229           0 :     pImpl->mpTextForwarder = 0;
     230             : 
     231           0 :     delete pImpl->mpOutliner;
     232           0 :     pImpl->mpOutliner = 0;
     233           0 : }
     234             : 
     235           0 : SvxTextForwarder* TextAPIEditSource::GetTextForwarder()
     236             : {
     237           0 :     if( !pImpl->mpDoc )
     238           0 :         return 0; // mpDoc == 0 can be used to flag this as disposed
     239             : 
     240           0 :     if( !pImpl->mpOutliner )
     241             :     {
     242             :         //init draw model first
     243           0 :         pImpl->mpOutliner = new Outliner( pImpl->mpDoc, OUTLINERMODE_TEXTOBJECT );
     244           0 :         pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
     245             :     }
     246             : 
     247           0 :     if( !pImpl->mpTextForwarder )
     248           0 :         pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, false );
     249             : 
     250           0 :     return pImpl->mpTextForwarder;
     251             : }
     252             : 
     253           0 : void TextAPIEditSource::SetText( OutlinerParaObject& rText )
     254             : {
     255           0 :     if ( pImpl->mpDoc )
     256             :     {
     257           0 :         if( !pImpl->mpOutliner )
     258             :         {
     259             :             //init draw model first
     260           0 :             pImpl->mpOutliner = new Outliner( pImpl->mpDoc, OUTLINERMODE_TEXTOBJECT );
     261           0 :             pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
     262             :         }
     263             : 
     264           0 :         pImpl->mpOutliner->SetText( rText );
     265             :     }
     266           0 : }
     267             : 
     268           0 : OutlinerParaObject* TextAPIEditSource::CreateText()
     269             : {
     270           0 :     if ( pImpl->mpDoc && pImpl->mpOutliner )
     271           0 :         return pImpl->mpOutliner->CreateParaObject();
     272             :     else
     273           0 :         return 0;
     274             : }
     275             : 
     276           0 : OUString TextAPIEditSource::GetText()
     277             : {
     278           0 :     if ( pImpl->mpDoc && pImpl->mpOutliner )
     279           0 :         return pImpl->mpOutliner->GetEditEngine().GetText();
     280             :     else
     281           0 :         return OUString();
     282             : }
     283             : 
     284             : } // namespace sd
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10