LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/txtnode - txtatr2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 128 141 90.8 %
Date: 2013-07-09 Functions: 31 38 81.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             : 
      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         144 : TYPEINIT1(SwTxtINetFmt,SwClient);
      39         216 : TYPEINIT1(SwTxtRuby,SwClient);
      40             : 
      41             : 
      42             : /*************************************************************************
      43             :  *                      class SwTxtCharFmt
      44             :  *************************************************************************/
      45             : 
      46          39 : SwTxtCharFmt::SwTxtCharFmt( SwFmtCharFmt& rAttr,
      47             :                     xub_StrLen nStt, xub_StrLen nEnde )
      48             :     : SwTxtAttrEnd( rAttr, nStt, nEnde )
      49             :     , m_pTxtNode( 0 )
      50          39 :     , m_nSortNumber( 0 )
      51             : {
      52          39 :     rAttr.pTxtAttr = this;
      53          39 :     SetCharFmtAttr( sal_True );
      54          39 : }
      55             : 
      56          78 : SwTxtCharFmt::~SwTxtCharFmt( )
      57             : {
      58          78 : }
      59             : 
      60         148 : void SwTxtCharFmt::ModifyNotification( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
      61             : {
      62         148 :     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         148 :     if ( m_pTxtNode )
      68             :     {
      69         148 :         SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
      70         148 :         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
      71             :     }
      72         148 : }
      73             : 
      74          11 : bool SwTxtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
      75             : {
      76          22 :     if ( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
      77          11 :         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
      78             :     {
      79           0 :         return true;
      80             :     }
      81             : 
      82          11 :     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
      83          11 :     return false;
      84             : }
      85             : 
      86             : 
      87             : /*************************************************************************
      88             :  *                        class SwTxtAttrNesting
      89             :  *************************************************************************/
      90             : 
      91         346 : SwTxtAttrNesting::SwTxtAttrNesting( SfxPoolItem & i_rAttr,
      92             :             const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
      93         346 :     : SwTxtAttrEnd( i_rAttr, i_nStart, i_nEnd )
      94             : {
      95         346 :     SetDontExpand( true );  // never expand this attribute
      96             :     // lock the expand flag: simple guarantee that nesting will not be
      97             :     // invalidated by expand operations
      98         346 :     SetLockExpandFlag( true );
      99         346 :     SetDontExpandStartAttr( true );
     100         346 :     SetNesting( true );
     101         346 : }
     102             : 
     103         346 : SwTxtAttrNesting::~SwTxtAttrNesting()
     104             : {
     105         346 : }
     106             : 
     107             : 
     108             : /*************************************************************************
     109             :  *                      class SwTxtINetFmt
     110             :  *************************************************************************/
     111             : 
     112          69 : 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          69 :     , m_bVisitedValid( false )
     119             : {
     120          69 :     rAttr.pTxtAttr  = this;
     121          69 :     SetCharFmtAttr( true );
     122          69 : }
     123             : 
     124         138 : SwTxtINetFmt::~SwTxtINetFmt( )
     125             : {
     126         138 : }
     127             : 
     128        2202 : SwCharFmt* SwTxtINetFmt::GetCharFmt()
     129             : {
     130        2202 :     const SwFmtINetFmt& rFmt = SwTxtAttrEnd::GetINetFmt();
     131        2202 :     SwCharFmt* pRet = NULL;
     132             : 
     133        2202 :     if( rFmt.GetValue().Len() )
     134             :     {
     135        2202 :         const SwDoc* pDoc = GetTxtNode().GetDoc();
     136        2202 :         if( !IsVisitedValid() )
     137             :         {
     138          66 :             SetVisited( pDoc->IsVisitedURL( rFmt.GetValue() ) );
     139          66 :             SetVisitedValid( true );
     140             :         }
     141             :         sal_uInt16 nId;
     142        2202 :         const String& rStr = IsVisited() ? rFmt.GetVisitedFmt()
     143        2202 :                                            : rFmt.GetINetFmt();
     144        2202 :         if( rStr.Len() )
     145         209 :             nId = IsVisited() ? rFmt.GetVisitedFmtId() : rFmt.GetINetFmtId();
     146             :         else
     147        1993 :             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        2202 :         bool bResetMod = !pDoc->IsModified();
     152        2202 :         Link aOle2Lnk;
     153        2202 :         if( bResetMod )
     154             :         {
     155         177 :             aOle2Lnk = pDoc->GetOle2Link();
     156         177 :             ((SwDoc*)pDoc)->SetOle2Link( Link() );
     157             :         }
     158             : 
     159        2202 :         pRet = IsPoolUserFmt( nId )
     160             :                 ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
     161        2202 :                 : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
     162             : 
     163        2202 :         if( bResetMod )
     164             :         {
     165         177 :             ((SwDoc*)pDoc)->ResetModified();
     166         177 :             ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
     167             :         }
     168             :     }
     169             : 
     170        2202 :     if( pRet )
     171        2047 :         pRet->Add( this );
     172         155 :     else if( GetRegisteredIn() )
     173           2 :         GetRegisteredInNonConst()->Remove( this );
     174             : 
     175        2202 :     return pRet;
     176             : }
     177             : 
     178          48 : void SwTxtINetFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
     179             : {
     180          48 :     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          48 :     if ( m_pTxtNode )
     186             :     {
     187          48 :         SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
     188          48 :         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
     189             :     }
     190          48 : }
     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         180 : SwTxtRuby::SwTxtRuby( SwFmtRuby& rAttr,
     215             :                       xub_StrLen nStart, xub_StrLen nEnd )
     216             :     : SwTxtAttrNesting( rAttr, nStart, nEnd )
     217             :     , SwClient( 0 )
     218         180 :     , m_pTxtNode( 0 )
     219             : {
     220         180 :     rAttr.pTxtAttr  = this;
     221         180 : }
     222             : 
     223         360 : SwTxtRuby::~SwTxtRuby()
     224             : {
     225         360 : }
     226             : 
     227          72 : void SwTxtRuby::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
     228             : {
     229          72 :     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          72 :     if ( m_pTxtNode )
     235             :     {
     236          72 :         SwUpdateAttr aUpdateAttr( *GetStart(), *GetEnd(), nWhich );
     237          72 :         m_pTxtNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
     238             :     }
     239          72 : }
     240             : 
     241           1 : bool SwTxtRuby::GetInfo( SfxPoolItem& rInfo ) const
     242             : {
     243           2 :     if( RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTxtNode ||
     244           1 :         &m_pTxtNode->GetNodes() != static_cast<SwAutoFmtGetDocNode&>(rInfo).pNodes )
     245             :     {
     246           0 :         return true;
     247             :     }
     248             : 
     249           1 :     static_cast<SwAutoFmtGetDocNode&>(rInfo).pCntntNode = m_pTxtNode;
     250           1 :     return false;
     251             : }
     252             : 
     253         168 : SwCharFmt* SwTxtRuby::GetCharFmt()
     254             : {
     255         168 :     const SwFmtRuby& rFmt = SwTxtAttrEnd::GetRuby();
     256         168 :     SwCharFmt* pRet = 0;
     257             : 
     258         168 :     if( rFmt.GetText().Len() )
     259             :     {
     260         168 :         const SwDoc* pDoc = GetTxtNode().GetDoc();
     261         168 :         const String& rStr = rFmt.GetCharFmtName();
     262         168 :         sal_uInt16 nId = RES_POOLCHR_RUBYTEXT;
     263         168 :         if ( rStr.Len() )
     264          30 :             nId = rFmt.GetCharFmtId();
     265             : 
     266             :         // JP 10.02.2000, Bug 72806: dont modify the doc for getting the
     267             :         //              correct charstyle.
     268         168 :         bool bResetMod = !pDoc->IsModified();
     269         168 :         Link aOle2Lnk;
     270         168 :         if( bResetMod )
     271             :         {
     272           6 :             aOle2Lnk = pDoc->GetOle2Link();
     273           6 :             ((SwDoc*)pDoc)->SetOle2Link( Link() );
     274             :         }
     275             : 
     276         168 :         pRet = IsPoolUserFmt( nId )
     277             :                 ? ((SwDoc*)pDoc)->FindCharFmtByName( rStr )
     278         168 :                 : ((SwDoc*)pDoc)->GetCharFmtFromPool( nId );
     279             : 
     280         168 :         if( bResetMod )
     281             :         {
     282           6 :             ((SwDoc*)pDoc)->ResetModified();
     283           6 :             ((SwDoc*)pDoc)->SetOle2Link( aOle2Lnk );
     284             :         }
     285             :     }
     286             : 
     287         168 :     if( pRet )
     288         168 :         pRet->Add( this );
     289           0 :     else if( GetRegisteredIn() )
     290           0 :         GetRegisteredInNonConst()->Remove( this );
     291             : 
     292         168 :     return pRet;
     293             : }
     294             : 
     295             : 
     296             : /*************************************************************************
     297             :  *                        class SwTxtMeta
     298             :  *************************************************************************/
     299             : 
     300             : SwTxtMeta *
     301          97 : 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          97 :     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          97 :     SwTxtMeta *const pTxtMeta(new SwTxtMeta(i_rAttr, i_nStart, i_nEnd));
     313          97 :     return pTxtMeta;
     314             : }
     315             : 
     316          97 : SwTxtMeta::SwTxtMeta( SwFmtMeta & i_rAttr,
     317             :         const xub_StrLen i_nStart, const xub_StrLen i_nEnd )
     318          97 :     : SwTxtAttrNesting( i_rAttr, i_nStart, i_nEnd )
     319             : {
     320          97 :     i_rAttr.SetTxtAttr( this );
     321          97 :     SetHasDummyChar(true);
     322          97 : }
     323             : 
     324         291 : SwTxtMeta::~SwTxtMeta()
     325             : {
     326          97 :     SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
     327          97 :     if (rFmtMeta.GetTxtAttr() == this)
     328             :     {
     329          97 :         rFmtMeta.SetTxtAttr(0);
     330             :     }
     331         194 : }
     332             : 
     333         194 : void SwTxtMeta::ChgTxtNode(SwTxtNode * const pNode)
     334             : {
     335         194 :     SwFmtMeta & rFmtMeta( static_cast<SwFmtMeta &>(GetAttr()) );
     336         194 :     if (rFmtMeta.GetTxtAttr() == this)
     337             :     {
     338         194 :         rFmtMeta.NotifyChangeTxtNode(pNode);
     339             :     }
     340         293 : }
     341             : 
     342             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10