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

Generated by: LCOV version 1.10