LCOV - code coverage report
Current view: top level - sw/source/core/fields - textapi.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 66 81 81.5 %
Date: 2014-04-11 Functions: 16 17 94.1 %
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 <textapi.hxx>
      21             : #include <doc.hxx>
      22             : #include <docsh.hxx>
      23             : #include <editeng/eeitem.hxx>
      24             : #include <editeng/editeng.hxx>
      25             : 
      26             : #include <com/sun/star/text/XTextField.hpp>
      27             : #include <com/sun/star/container/XNameContainer.hpp>
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : 
      30             : using namespace com::sun::star;
      31             : 
      32          39 : static const SvxItemPropertySet* ImplGetSvxTextPortionPropertySet()
      33             : {
      34             :     static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
      35             :     {
      36         336 :         SVX_UNOEDIT_CHAR_PROPERTIES,
      37           7 :         SVX_UNOEDIT_FONT_PROPERTIES,
      38          35 :         SVX_UNOEDIT_OUTLINER_PROPERTIES,
      39          98 :         SVX_UNOEDIT_PARA_PROPERTIES,
      40             :         {OUString("TextField"),                 EE_FEATURE_FIELD,
      41           7 :             ::getCppuType((const uno::Reference< text::XTextField >*)0), beans::PropertyAttribute::READONLY, 0 },
      42             :         {OUString("TextPortionType"),           WID_PORTIONTYPE,
      43           7 :             ::getCppuType((const OUString*)0), beans::PropertyAttribute::READONLY, 0 },
      44             :         {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS,
      45           7 :             ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0), 0, 0},
      46             :         {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS,
      47           7 :             ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0), 0, 0},
      48             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      49         550 :     };
      50          39 :     static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
      51          39 :     return &aSvxTextPortionPropertySet;
      52             : }
      53             : 
      54          39 : SwTextAPIObject::SwTextAPIObject( SwTextAPIEditSource* p )
      55             : : SvxUnoText( p, ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() )
      56          39 : , pSource(p)
      57             : {
      58          39 : }
      59             : 
      60         117 : SwTextAPIObject::~SwTextAPIObject() throw()
      61             : {
      62          39 :     pSource->Dispose();
      63          39 :     delete pSource;
      64          78 : }
      65             : 
      66             : struct SwTextAPIEditSource_Impl
      67             : {
      68             :     // needed for "internal" refcounting
      69             :     SfxItemPool*                    mpPool;
      70             :     SwDoc*                          mpDoc;
      71             :     Outliner*                       mpOutliner;
      72             :     SvxOutlinerForwarder*           mpTextForwarder;
      73             :     sal_Int32                       mnRef;
      74             : };
      75             : 
      76         198 : SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource )
      77         198 : : SvxEditSource( *this )
      78             : {
      79             :     // shallow copy; uses internal refcounting
      80         198 :     pImpl = rSource.pImpl;
      81         198 :     pImpl->mnRef++;
      82         198 : }
      83             : 
      84         198 : SvxEditSource* SwTextAPIEditSource::Clone() const
      85             : {
      86         198 :     return new SwTextAPIEditSource( *this );
      87             : }
      88             : 
      89         167 : void SwTextAPIEditSource::UpdateData()
      90             : {
      91             :     // data is kept in outliner all the time
      92         167 : }
      93             : 
      94          39 : SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc)
      95          39 : : pImpl(new SwTextAPIEditSource_Impl)
      96             : {
      97          39 :     pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
      98          39 :     pImpl->mpDoc = pDoc;
      99          39 :     pImpl->mpOutliner = 0;
     100          39 :     pImpl->mpTextForwarder = 0;
     101          39 :     pImpl->mnRef = 1;
     102          39 : }
     103             : 
     104         711 : SwTextAPIEditSource::~SwTextAPIEditSource()
     105             : {
     106         237 :     if (!--pImpl->mnRef)
     107          39 :         delete pImpl;
     108         474 : }
     109             : 
     110          78 : void SwTextAPIEditSource::Dispose()
     111             : {
     112          78 :     pImpl->mpPool=0;
     113          78 :     pImpl->mpDoc=0;
     114          78 :     DELETEZ(pImpl->mpTextForwarder);
     115          78 :     DELETEZ(pImpl->mpOutliner);
     116          78 : }
     117             : 
     118        1886 : SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder()
     119             : {
     120        1886 :     if( !pImpl->mpPool )
     121           0 :         return 0; // mpPool == 0 can be used to flag this as disposed
     122             : 
     123        1886 :     if( !pImpl->mpOutliner )
     124             :     {
     125             :         //init draw model first
     126          39 :         pImpl->mpDoc->GetOrCreateDrawModel();
     127          39 :         pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
     128          39 :         pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
     129             :     }
     130             : 
     131        1886 :     if( !pImpl->mpTextForwarder )
     132          39 :         pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, false );
     133             : 
     134        1886 :     return pImpl->mpTextForwarder;
     135             : }
     136             : 
     137           8 : void SwTextAPIEditSource::SetText( OutlinerParaObject& rText )
     138             : {
     139           8 :     if ( pImpl->mpPool )
     140             :     {
     141           8 :         if( !pImpl->mpOutliner )
     142             :         {
     143             :             //init draw model first
     144           0 :             pImpl->mpDoc->GetOrCreateDrawModel();
     145           0 :             pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
     146           0 :             pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
     147             :         }
     148             : 
     149           8 :         pImpl->mpOutliner->SetText( rText );
     150             :     }
     151           8 : }
     152             : 
     153           0 : void SwTextAPIEditSource::SetString( const OUString& rText )
     154             : {
     155           0 :     if ( pImpl->mpPool )
     156             :     {
     157           0 :         if( !pImpl->mpOutliner )
     158             :         {
     159             :             //init draw model first
     160           0 :             pImpl->mpDoc->GetOrCreateDrawModel();
     161           0 :             pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
     162           0 :             pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
     163             :         }
     164             :         else
     165           0 :             pImpl->mpOutliner->Clear();
     166           0 :         pImpl->mpOutliner->Insert( rText );
     167             :     }
     168           0 : }
     169             : 
     170          33 : OutlinerParaObject* SwTextAPIEditSource::CreateText()
     171             : {
     172          33 :     if ( pImpl->mpPool && pImpl->mpOutliner )
     173          33 :         return pImpl->mpOutliner->CreateParaObject();
     174             :     else
     175           0 :         return 0;
     176             : }
     177             : 
     178          33 : OUString SwTextAPIEditSource::GetText()
     179             : {
     180          33 :     if ( pImpl->mpPool && pImpl->mpOutliner )
     181          33 :         return pImpl->mpOutliner->GetEditEngine().GetText();
     182             :     else
     183           0 :         return OUString();
     184             : }
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10