LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/fields - textapi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 82 89.0 %
Date: 2013-07-09 Functions: 18 18 100.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             : #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          12 : static const SvxItemPropertySet* ImplGetSvxTextPortionPropertySet()
      33             : {
      34             :     static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
      35             :     {
      36         138 :         SVX_UNOEDIT_CHAR_PROPERTIES,
      37           3 :         SVX_UNOEDIT_FONT_PROPERTIES,
      38          15 :         SVX_UNOEDIT_OUTLINER_PROPERTIES,
      39          42 :         SVX_UNOEDIT_PARA_PROPERTIES,
      40             :         {MAP_CHAR_LEN("TextField"),                 EE_FEATURE_FIELD,
      41           3 :             &::getCppuType((const uno::Reference< text::XTextField >*)0), beans::PropertyAttribute::READONLY, 0 },
      42             :         {MAP_CHAR_LEN("TextPortionType"),           WID_PORTIONTYPE,
      43           3 :             &::getCppuType((const OUString*)0), beans::PropertyAttribute::READONLY, 0 },
      44             :         {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS,
      45           3 :             &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0), 0, 0},
      46             :         {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS,
      47           3 :             &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0), 0, 0},
      48             :         {0,0,0,0,0,0}
      49         222 :     };
      50          12 :     static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
      51          12 :     return &aSvxTextPortionPropertySet;
      52             : }
      53             : 
      54          12 : SwTextAPIObject::SwTextAPIObject( SwTextAPIEditSource* p )
      55             : : SvxUnoText( p, ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() )
      56          12 : , pSource(p)
      57             : {
      58          12 : }
      59             : 
      60          36 : SwTextAPIObject::~SwTextAPIObject() throw()
      61             : {
      62          12 :     pSource->Dispose();
      63          12 :     delete pSource;
      64          24 : }
      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          66 : SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource )
      77          66 : : SvxEditSource( *this )
      78             : {
      79             :     // shallow copy; uses internal refcounting
      80          66 :     pImpl = rSource.pImpl;
      81          66 :     pImpl->mnRef++;
      82          66 : }
      83             : 
      84          66 : SvxEditSource* SwTextAPIEditSource::Clone() const
      85             : {
      86          66 :     return new SwTextAPIEditSource( *this );
      87             : }
      88             : 
      89          30 : void SwTextAPIEditSource::UpdateData()
      90             : {
      91             :     // data is kept in outliner all the time
      92          30 : }
      93             : 
      94          12 : SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc)
      95          12 : : pImpl(new SwTextAPIEditSource_Impl)
      96             : {
      97          12 :     pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
      98          12 :     pImpl->mpDoc = pDoc;
      99          12 :     pImpl->mpOutliner = 0;
     100          12 :     pImpl->mpTextForwarder = 0;
     101          12 :     pImpl->mnRef = 1;
     102          12 : }
     103             : 
     104         234 : SwTextAPIEditSource::~SwTextAPIEditSource()
     105             : {
     106          78 :     if (!--pImpl->mnRef)
     107          12 :         delete pImpl;
     108         156 : }
     109             : 
     110          24 : void SwTextAPIEditSource::Dispose()
     111             : {
     112          24 :     pImpl->mpPool=0;
     113          24 :     pImpl->mpDoc=0;
     114          24 :     DELETEZ(pImpl->mpTextForwarder);
     115          24 :     DELETEZ(pImpl->mpOutliner);
     116          24 : }
     117             : 
     118         464 : SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder()
     119             : {
     120         464 :     if( !pImpl->mpPool )
     121           0 :         return 0; // mpPool == 0 can be used to flag this as disposed
     122             : 
     123         464 :     if( !pImpl->mpOutliner )
     124             :     {
     125             :         //init draw model first
     126          12 :         pImpl->mpDoc->GetOrCreateDrawModel();
     127          12 :         pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
     128          12 :         pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
     129             :     }
     130             : 
     131         464 :     if( !pImpl->mpTextForwarder )
     132          12 :         pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, 0 );
     133             : 
     134         464 :     return pImpl->mpTextForwarder;
     135             : }
     136             : 
     137           2 : void SwTextAPIEditSource::SetText( OutlinerParaObject& rText )
     138             : {
     139           2 :     if ( pImpl->mpPool )
     140             :     {
     141           2 :         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           2 :         pImpl->mpOutliner->SetText( rText );
     150             :     }
     151           2 : }
     152             : 
     153           4 : void SwTextAPIEditSource::SetString( const String& rText )
     154             : {
     155           4 :     if ( pImpl->mpPool )
     156             :     {
     157           4 :         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           4 :             pImpl->mpOutliner->Clear();
     166           4 :         pImpl->mpOutliner->Insert( rText );
     167             :     }
     168           4 : }
     169             : 
     170           8 : OutlinerParaObject* SwTextAPIEditSource::CreateText()
     171             : {
     172           8 :     if ( pImpl->mpPool && pImpl->mpOutliner )
     173           8 :         return pImpl->mpOutliner->CreateParaObject();
     174             :     else
     175           0 :         return 0;
     176             : }
     177             : 
     178           8 : String SwTextAPIEditSource::GetText()
     179             : {
     180           8 :     if ( pImpl->mpPool && pImpl->mpOutliner )
     181           8 :         return pImpl->mpOutliner->GetEditEngine().GetText();
     182             :     else
     183           0 :         return String();
     184          99 : }
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10