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