LCOV - code coverage report
Current view: top level - sw/source/core/txtnode - txtatr2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 126 139 90.6 %
Date: 2014-04-11 Functions: 29 36 80.6 %
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 <hintids.hxx>
      21             : #include <hints.hxx>
      22             : #include <sfx2/objsh.hxx>
      23             : #include <editeng/xmlcnitm.hxx>
      24             : #include <editeng/twolinesitem.hxx>
      25             : #include <txtinet.hxx>
      26             : #include <txtatr.hxx>
      27             : #include <fchrfmt.hxx>
      28             : #include <fmtinfmt.hxx>
      29             : #include <charfmt.hxx>
      30             : #include <ndtxt.hxx>
      31             : #include <poolfmt.hxx>
      32             : #include <doc.hxx>
      33             : #include <fmtruby.hxx>
      34             : #include <fmtmeta.hxx>
      35             : 
      36        2934 : TYPEINIT1(SwTxtINetFmt,SwClient);
      37         216 : TYPEINIT1(SwTxtRuby,SwClient);
      38             : 
      39             : /*************************************************************************
      40             :  *                      class SwTxtCharFmt
      41             :  *************************************************************************/
      42             : 
      43         955 : SwTxtCharFmt::SwTxtCharFmt( SwFmtCharFmt& rAttr,
      44             :                     sal_Int32 nStt, sal_Int32 nEnde )
      45             :     : SwTxtAttrEnd( rAttr, nStt, nEnde )
      46             :     , m_pTxtNode( 0 )
      47         955 :     , m_nSortNumber( 0 )
      48             : {
      49         955 :     rAttr.pTxtAttr = this;
      50         955 :     SetCharFmtAttr( true );
      51         955 : }
      52             : 
      53        1910 : SwTxtCharFmt::~SwTxtCharFmt( )
      54             : {
      55        1910 : }
      56             : 
      57         648 : void SwTxtCharFmt::ModifyNotification( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
      58             : {
      59         648 :     sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
      60             :     OSL_ENSURE(  isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
      61             :              || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
      62             :         "SwTxtCharFmt::Modify(): unknown Modify");
      63             : 
      64         648 :     if ( m_pTxtNode )
      65             :     {
      66         647 :         SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
      67         647 :         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
      68             :     }
      69         648 : }
      70             : 
      71           5 : bool SwTxtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
      72             : {
      73          10 :     if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
      74           5 :         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
      75             :     {
      76           0 :         return true;
      77             :     }
      78             : 
      79           5 :     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
      80           5 :     return false;
      81             : }
      82             : 
      83             : /*************************************************************************
      84             :  *                        class SwTxtAttrNesting
      85             :  *************************************************************************/
      86             : 
      87        1878 : SwTxtAttrNesting::SwTxtAttrNesting( SfxPoolItem & i_rAttr,
      88             :             const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
      89        1878 :     : SwTxtAttrEnd( i_rAttr, i_nStart, i_nEnd )
      90             : {
      91        1878 :     SetDontExpand( true );  // never expand this attribute
      92             :     // lock the expand flag: simple guarantee that nesting will not be
      93             :     // invalidated by expand operations
      94        1878 :     SetLockExpandFlag( true );
      95        1878 :     SetDontExpandStartAttr( true );
      96        1878 :     SetNesting( true );
      97        1878 : }
      98             : 
      99        1878 : SwTxtAttrNesting::~SwTxtAttrNesting()
     100             : {
     101        1878 : }
     102             : 
     103             : /*************************************************************************
     104             :  *                      class SwTxtINetFmt
     105             :  *************************************************************************/
     106             : 
     107        1601 : SwTxtINetFmt::SwTxtINetFmt( SwFmtINetFmt& rAttr,
     108             :                             sal_Int32 nStart, sal_Int32 nEnd )
     109             :     : SwTxtAttrNesting( rAttr, nStart, nEnd )
     110             :     , SwClient( 0 )
     111             :     , m_pTxtNode( 0 )
     112             :     , m_bVisited( false )
     113        1601 :     , m_bVisitedValid( false )
     114             : {
     115        1601 :     rAttr.mpTxtAttr  = this;
     116        1601 :     SetCharFmtAttr( true );
     117        1601 : }
     118             : 
     119        3202 : SwTxtINetFmt::~SwTxtINetFmt( )
     120             : {
     121        3202 : }
     122             : 
     123       17093 : SwCharFmt* SwTxtINetFmt::GetCharFmt()
     124             : {
     125       17093 :     const SwFmtINetFmt& rFmt = SwTxtAttrEnd::GetINetFmt();
     126       17093 :     SwCharFmt* pRet = NULL;
     127             : 
     128       17093 :     if (!rFmt.GetValue().isEmpty())
     129             :     {
     130       17093 :         const SwDoc* pDoc = GetTxtNode().GetDoc();
     131       17093 :         if( !IsVisitedValid() )
     132             :         {
     133        1586 :             SetVisited( pDoc->IsVisitedURL( rFmt.GetValue() ) );
     134        1586 :             SetVisitedValid( true );
     135             :         }
     136             : 
     137       17093 :         const sal_uInt16 nId = IsVisited() ? rFmt.GetVisitedFmtId() : rFmt.GetINetFmtId();
     138       17093 :         const OUString& rStr = IsVisited() ? rFmt.GetVisitedFmt() : rFmt.GetINetFmt();
     139       17093 :         if (rStr.isEmpty())
     140             :         {
     141             :             OSL_ENSURE( false, "<SwTxtINetFmt::GetCharFmt()> - missing character format at hyperlink attribute");
     142             :         }
     143             : 
     144             :         // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
     145             :         //      correct charstyle.
     146       17093 :         bool bResetMod = !pDoc->IsModified();
     147       17093 :         Link aOle2Lnk;
     148       17093 :         if ( bResetMod )
     149             :         {
     150       11803 :             aOle2Lnk = pDoc->GetOle2Link();
     151       11803 :             ( (SwDoc*) pDoc )->SetOle2Link( Link() );
     152             :         }
     153             : 
     154       17093 :         pRet = IsPoolUserFmt( nId )
     155             :                ? ( (SwDoc*) pDoc )->FindCharFmtByName( rStr )
     156       17093 :                : ( (SwDoc*) pDoc )->GetCharFmtFromPool( nId );
     157             : 
     158       17093 :         if ( bResetMod )
     159             :         {
     160       11803 :             ( (SwDoc*) pDoc )->ResetModified();
     161       11803 :             ( (SwDoc*) pDoc )->SetOle2Link( aOle2Lnk );
     162             :         }
     163             :     }
     164             : 
     165       17093 :     if ( pRet )
     166       16848 :         pRet->Add( this );
     167         245 :     else if ( GetRegisteredIn() )
     168           2 :         GetRegisteredInNonConst()->Remove( this );
     169             : 
     170       17093 :     return pRet;
     171             : }
     172             : 
     173         978 : void SwTxtINetFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
     174             : {
     175         978 :     sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
     176             :     OSL_ENSURE(  isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
     177             :              || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
     178             :         "SwTxtINetFmt::Modify(): unknown Modify");
     179             : 
     180         978 :     if ( m_pTxtNode )
     181             :     {
     182         978 :         SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
     183         978 :         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
     184             :     }
     185         978 : }
     186             : 
     187             :     // erfrage vom Modify Informationen
     188           0 : bool SwTxtINetFmt::GetInfo( SfxPoolItem& rInfo ) const
     189             : {
     190           0 :     if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
     191           0 :         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
     192             :     {
     193           0 :         return true;
     194             :     }
     195             : 
     196           0 :     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
     197           0 :     return false;
     198             : }
     199             : 
     200           0 : sal_Bool SwTxtINetFmt::IsProtect( ) const
     201             : {
     202           0 :     return m_pTxtNode && m_pTxtNode->IsProtect();
     203             : }
     204             : 
     205             : /*************************************************************************
     206             :  *                      class SwTxtRuby
     207             :  *************************************************************************/
     208             : 
     209         180 : SwTxtRuby::SwTxtRuby( SwFmtRuby& rAttr,
     210             :                       sal_Int32 nStart, sal_Int32 nEnd )
     211             :     : SwTxtAttrNesting( rAttr, nStart, nEnd )
     212             :     , SwClient( 0 )
     213         180 :     , m_pTxtNode( 0 )
     214             : {
     215         180 :     rAttr.pTxtAttr  = this;
     216         180 : }
     217             : 
     218         360 : SwTxtRuby::~SwTxtRuby()
     219             : {
     220         360 : }
     221             : 
     222          72 : void SwTxtRuby::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
     223             : {
     224          72 :     sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
     225             :     OSL_ENSURE(  isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
     226             :              || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
     227             :         "SwTxtRuby::Modify(): unknown Modify");
     228             : 
     229          72 :     if ( m_pTxtNode )
     230             :     {
     231          72 :         SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
     232          72 :         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
     233             :     }
     234          72 : }
     235             : 
     236           1 : bool SwTxtRuby::GetInfo( SfxPoolItem& rInfo ) const
     237             : {
     238           2 :     if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
     239           1 :         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
     240             :     {
     241           0 :         return true;
     242             :     }
     243             : 
     244           1 :     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
     245           1 :     return false;
     246             : }
     247             : 
     248         168 : SwCharFmt* SwTxtRuby::GetCharFmt()
     249             : {
     250         168 :     const SwFmtRuby& rFmt = SwTxtAttrEnd::GetRuby();
     251         168 :     SwCharFmt* pRet = 0;
     252             : 
     253         168 :     if( !rFmt.GetText().isEmpty() )
     254             :     {
     255         168 :         const SwDoc* pDoc = GetTxtNode().GetDoc();
     256         168 :         const OUString rStr = rFmt.GetCharFmtName();
     257         168 :         const sal_uInt16 nId = rStr.isEmpty()
     258             :                              ? static_cast<sal_uInt16>(RES_POOLCHR_RUBYTEXT)
     259         168 :                              : rFmt.GetCharFmtId();
     260             : 
     261             :         // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
     262             :         //              correct charstyle.
     263         168 :         const bool bResetMod = !pDoc->IsModified();
     264         168 :         Link aOle2Lnk;
     265         168 :         if( bResetMod )
     266             :         {
     267           6 :             aOle2Lnk = pDoc->GetOle2Link();
     268           6 :             ((SwDoc*)pDoc)->SetOle2Link( Link() );
     269             :         }
     270             : 
     271         168 :         pRet = IsPoolUserFmt( nId )
     272             :                 ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
     273         168 :                 : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
     274             : 
     275         168 :         if( bResetMod )
     276             :         {
     277           6 :             ((SwDoc*)pDoc)->ResetModified();
     278           6 :             ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
     279         168 :         }
     280             :     }
     281             : 
     282         168 :     if( pRet )
     283         168 :         pRet->Add( this );
     284           0 :     else if( GetRegisteredIn() )
     285           0 :         GetRegisteredInNonConst()->Remove( this );
     286             : 
     287         168 :     return pRet;
     288             : }
     289             : 
     290             : /*************************************************************************
     291             :  *                        class SwTxtMeta
     292             :  *************************************************************************/
     293             : 
     294             : SwTxtMeta *
     295          97 : SwTxtMeta::CreateTxtMeta(
     296             :     ::sw::MetaFieldManager & i_rTargetDocManager,
     297             :     SwTxtNode *const i_pTargetTxtNode,
     298             :     SwFmtMeta & i_rAttr,
     299             :     sal_Int32 const i_nStart,
     300             :     sal_Int32 const i_nEnd,
     301             :     bool const i_bIsCopy)
     302             : {
     303          97 :     if (i_bIsCopy)
     304             :     {   // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
     305             :         OSL_ENSURE(i_pTargetTxtNode, "cannot copy Meta without target node");
     306           0 :         i_rAttr.DoCopy(i_rTargetDocManager, *i_pTargetTxtNode);
     307             :     }
     308          97 :     SwTxtMeta *const pTxtMeta(new SwTxtMeta(i_rAttr, i_nStart, i_nEnd));
     309          97 :     return pTxtMeta;
     310             : }
     311             : 
     312          97 : SwTxtMeta::SwTxtMeta( SwFmtMeta & i_rAttr,
     313             :         const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
     314          97 :     : SwTxtAttrNesting( i_rAttr, i_nStart, i_nEnd )
     315             : {
     316          97 :     i_rAttr.SetTxtAttr( this );
     317          97 :     SetHasDummyChar(true);
     318          97 : }
     319             : 
     320         291 : SwTxtMeta::~SwTxtMeta()
     321             : {
     322          97 :     SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
     323          97 :     if (rFmtMeta.GetTxtAttr() == this)
     324             :     {
     325          97 :         rFmtMeta.SetTxtAttr(0);
     326             :     }
     327         194 : }
     328             : 
     329         194 : void SwTxtMeta::ChgTxtNode(SwTxtNode * const pNode)
     330             : {
     331         194 :     SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
     332         194 :     if (rFmtMeta.GetTxtAttr() == this)
     333             :     {
     334         194 :         rFmtMeta.NotifyChangeTxtNode(pNode);
     335             :     }
     336         194 : }
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10