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

Generated by: LCOV version 1.10