LCOV - code coverage report
Current view: top level - sw/source/core/crsr - callnk.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 93 107 86.9 %
Date: 2014-11-03 Functions: 6 7 85.7 %
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 <com/sun/star/i18n/ScriptType.hpp>
      22             : #include <fmtcntnt.hxx>
      23             : #include <txatbase.hxx>
      24             : #include <frmatr.hxx>
      25             : #include <viscrs.hxx>
      26             : #include <callnk.hxx>
      27             : #include <crsrsh.hxx>
      28             : #include <doc.hxx>
      29             : #include <frmfmt.hxx>
      30             : #include <txtfrm.hxx>
      31             : #include <tabfrm.hxx>
      32             : #include <rowfrm.hxx>
      33             : #include <fmtfsize.hxx>
      34             : #include <ndtxt.hxx>
      35             : #include <flyfrm.hxx>
      36             : #include <breakit.hxx>
      37             : #include <vcl/window.hxx>
      38             : 
      39           0 : SwCallLink::SwCallLink( SwCrsrShell & rSh, sal_uLong nAktNode, sal_Int32 nAktCntnt,
      40             :                         sal_uInt8 nAktNdTyp, long nLRPos, bool bAktSelection )
      41             :     : rShell( rSh ), nNode( nAktNode ), nCntnt( nAktCntnt ),
      42             :       nNdTyp( nAktNdTyp ), nLeftFrmPos( nLRPos ),
      43           0 :       bHasSelection( bAktSelection )
      44             : {
      45           0 : }
      46             : 
      47       72664 : SwCallLink::SwCallLink( SwCrsrShell & rSh )
      48       72664 :     : rShell( rSh )
      49             : {
      50             :     // remember SPoint-values of current cursor
      51       72664 :     SwPaM* pCrsr = rShell.IsTableMode() ? rShell.GetTblCrs() : rShell.GetCrsr();
      52       72664 :     SwNode& rNd = pCrsr->GetPoint()->nNode.GetNode();
      53       72664 :     nNode = rNd.GetIndex();
      54       72664 :     nCntnt = pCrsr->GetPoint()->nContent.GetIndex();
      55       72664 :     nNdTyp = rNd.GetNodeType();
      56       72664 :     bHasSelection = ( *pCrsr->GetPoint() != *pCrsr->GetMark() );
      57             : 
      58       72664 :     if( rNd.IsTxtNode() )
      59       72656 :         nLeftFrmPos = SwCallLink::getLayoutFrm( rShell.GetLayout(), (SwTxtNode&)rNd, nCntnt,
      60      145312 :                                             !rShell.ActionPend() );
      61             :     else
      62             :     {
      63           8 :         nLeftFrmPos = 0;
      64             : 
      65             :         // A special treatment for SwFeShell:
      66             :         // When deleting the header/footer, footnotes SwFeShell sets the
      67             :         // Cursor to NULL (Node + Content).
      68             :         // If the Cursor is not on a CntntNode (ContentNode) this fact gets
      69             :         // saved in NdType.
      70           8 :         if( ND_CONTENTNODE & nNdTyp )
      71           0 :             nNdTyp = 0;
      72             :     }
      73       72664 : }
      74             : 
      75      145328 : static void lcl_notifyRow(const SwCntntNode* pNode, SwCrsrShell& rShell)
      76             : {
      77      145328 :     if ( !pNode )
      78         336 :         return;
      79             : 
      80      144992 :     SwFrm *const pMyFrm = pNode->getLayoutFrm( rShell.GetLayout() );
      81      144992 :     if ( !pMyFrm )
      82           0 :         return;
      83             : 
      84             :     // We need to emulated a change of the row height in order
      85             :     // to have the complete row redrawn
      86      144992 :     SwRowFrm *const pRow = pMyFrm->FindRowFrm();
      87      144992 :     if ( !pRow )
      88      136498 :         return;
      89             : 
      90        8494 :     const SwTableLine* pLine = pRow->GetTabLine( );
      91             :     // Avoid redrawing the complete row if there are no nested tables
      92       25876 :     for (SwFrm *pCell = pRow->GetLower(); pCell; pCell = pCell->GetNext())
      93             :     {
      94       39874 :         for (SwFrm *pContent = pCell->GetLower(); pContent; pContent = pContent->GetNext())
      95             :         {
      96       22492 :             if (pContent->GetType() == FRM_TAB)
      97             :             {
      98         136 :                 SwFmtFrmSize pSize = pLine->GetFrmFmt()->GetFrmSize();
      99         136 :                 pRow->ModifyNotification(NULL, &pSize);
     100         136 :                 return;
     101             :             }
     102             :         }
     103             :     }
     104             : }
     105             : 
     106       72664 : SwCallLink::~SwCallLink()
     107             : {
     108       72664 :     if( !nNdTyp || !rShell.m_bCallChgLnk ) // see ctor
     109             :         return ;
     110             : 
     111             :     // If travelling over Nodes check formats and register them anew at the
     112             :     // new Node.
     113       72664 :     SwPaM* pCurCrsr = rShell.IsTableMode() ? rShell.GetTblCrs() : rShell.GetCrsr();
     114       72664 :     SwCntntNode * pCNd = pCurCrsr->GetCntntNode();
     115       72664 :     if( !pCNd )
     116           0 :         return;
     117             : 
     118       72664 :     lcl_notifyRow(pCNd, rShell);
     119             : 
     120       72664 :     const SwDoc *pDoc=rShell.GetDoc();
     121       72664 :     const SwCntntNode *pNode = NULL;
     122       72664 :     if ( ( pDoc != NULL && nNode < pDoc->GetNodes( ).Count( ) ) )
     123             :     {
     124       72628 :         pNode = pDoc->GetNodes()[nNode]->GetCntntNode();
     125             :     }
     126       72664 :     lcl_notifyRow(pNode, rShell);
     127             : 
     128       72664 :     sal_Int32 nCmp, nAktCntnt = pCurCrsr->GetPoint()->nContent.GetIndex();
     129       72664 :     sal_uInt16 nNdWhich = pCNd->GetNodeType();
     130       72664 :     sal_uLong nAktNode = pCurCrsr->GetPoint()->nNode.GetIndex();
     131             : 
     132             :     // Register the Shell as dependent at the current Node. By doing this all
     133             :     // attribute changes can be signaled over the link.
     134       72664 :     pCNd->Add( &rShell );
     135             : 
     136       72664 :     if( nNdTyp != nNdWhich || nNode != nAktNode )
     137             :     {
     138             :         // Every time a switch between nodes occurs, there is a chance that
     139             :         // new attributes do apply - meaning text-attributes.
     140             :         // So the currently applying attributes would have to be determined.
     141             :         // That can be done in one go by the handler.
     142         652 :         rShell.CallChgLnk();
     143             :     }
     144       72012 :     else if( !bHasSelection != !(*pCurCrsr->GetPoint() != *pCurCrsr->GetMark()) )
     145             :     {
     146             :         // always call change link when selection changes
     147          42 :         rShell.CallChgLnk();
     148             :     }
     149      143856 :     else if( rShell.m_aChgLnk.IsSet() && ND_TEXTNODE == nNdWhich &&
     150       71886 :              nCntnt != nAktCntnt )
     151             :     {
     152             :         // If travelling with left/right only and the frame is
     153             :         // unchanged (columns!) then check text hints.
     154       12012 :         if( nLeftFrmPos == SwCallLink::getLayoutFrm( rShell.GetLayout(), (SwTxtNode&)*pCNd, nAktCntnt,
     155       12838 :                                                     !rShell.ActionPend() ) &&
     156        6706 :             (( nCmp = nCntnt ) + 1 == nAktCntnt ||          // Right
     157        2876 :             nCntnt -1 == ( nCmp = nAktCntnt )) )            // Left
     158             :         {
     159        1000 :             if( nCmp == nAktCntnt && pCurCrsr->HasMark() ) // left & select
     160           8 :                 ++nCmp;
     161             : 
     162        1000 :             if ( ((SwTxtNode*)pCNd)->HasHints() )
     163             :             {
     164         732 :                 const SwpHints &rHts = ((SwTxtNode*)pCNd)->GetSwpHints();
     165             : 
     166        1446 :                 for( size_t n = 0; n < rHts.Count(); ++n )
     167             :                 {
     168        1274 :                     const SwTxtAttr* pHt = rHts[ n ];
     169        1274 :                     const sal_Int32 *pEnd = pHt->End();
     170        1274 :                     const sal_Int32 nStart = pHt->GetStart();
     171             : 
     172             :                     // If "only start" or "start and end equal" then call on
     173             :                     // every overflow of start.
     174        2192 :                     if( ( !pEnd || ( nStart == *pEnd ) ) &&
     175        1310 :                         ( nStart == nCntnt || nStart == nAktCntnt) )
     176             :                     {
     177         528 :                         rShell.CallChgLnk();
     178         528 :                         return;
     179             :                     }
     180             : 
     181             :                     // If the attribute has an area and that area is not empty ...
     182        1130 :                     else if( pEnd && nStart < *pEnd &&
     183             :                         // ... then test if travelling occurred via start/end.
     184         352 :                         ( nStart == nCmp ||
     185         704 :                             ( pHt->DontExpand() ? nCmp == *pEnd-1
     186           0 :                                                 : nCmp == *pEnd ) ))
     187             :                     {
     188          32 :                         rShell.CallChgLnk();
     189          32 :                         return;
     190             :                     }
     191             :                 }
     192             :             }
     193             : 
     194         440 :             if( g_pBreakIt->GetBreakIter().is() )
     195             :             {
     196         440 :                 const OUString rTxt = ((SwTxtNode*)pCNd)->GetTxt();
     197        2168 :                 if( !nCmp ||
     198        1712 :                     g_pBreakIt->GetBreakIter()->getScriptType( rTxt, nCmp )
     199        1288 :                      != g_pBreakIt->GetBreakIter()->getScriptType( rTxt, nCmp - 1 ))
     200             :                 {
     201          48 :                     rShell.CallChgLnk();
     202          48 :                     return;
     203         392 :                 }
     204             :             }
     205             :         }
     206             :         else
     207             :             // If travelling more than one character with home/end/.. then
     208             :             // always call ChgLnk, because it can not be determined here what
     209             :             // has changed. Something may have changed.
     210        3004 :             rShell.CallChgLnk();
     211             :     }
     212             : 
     213             :     const SwFrm* pFrm;
     214             :     const SwFlyFrm *pFlyFrm;
     215      216010 :     if( !rShell.ActionPend() && 0 != ( pFrm = pCNd->getLayoutFrm(rShell.GetLayout(), 0, 0, false) ) &&
     216       72056 :         0 != ( pFlyFrm = pFrm->FindFlyFrm() ) && !rShell.IsTableMode() )
     217             :     {
     218           0 :         const SwNodeIndex* pIndex = pFlyFrm->GetFmt()->GetCntnt().GetCntntIdx();
     219             :         OSL_ENSURE( pIndex, "Fly without Cntnt" );
     220             : 
     221           0 :         if (!pIndex)
     222           0 :             return;
     223             : 
     224           0 :         const SwNode& rStNd = pIndex->GetNode();
     225             : 
     226           0 :         if( rStNd.EndOfSectionNode()->StartOfSectionIndex() > nNode ||
     227           0 :             nNode > rStNd.EndOfSectionIndex() )
     228           0 :             rShell.GetFlyMacroLnk().Call( (void*)pFlyFrm->GetFmt() );
     229             :     }
     230      144720 : }
     231             : 
     232      147972 : long SwCallLink::getLayoutFrm( const SwRootFrm* pRoot, SwTxtNode& rNd, sal_Int32 nCntPos, bool bCalcFrm )
     233             : {
     234      147972 :     SwTxtFrm* pFrm = (SwTxtFrm*)rNd.getLayoutFrm(pRoot,0,0,bCalcFrm), *pNext = pFrm;
     235      147972 :     if ( pFrm && !pFrm->IsHiddenNow() )
     236             :     {
     237      147857 :         if( pFrm->HasFollow() )
     238      109162 :             while( 0 != ( pNext = (SwTxtFrm*)pFrm->GetFollow() ) &&
     239       35148 :                     nCntPos >= pNext->GetOfst() )
     240       35030 :                 pFrm = pNext;
     241             : 
     242      147857 :         return pFrm->Frm().Left();
     243             :     }
     244         115 :     return 0;
     245         270 : }
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10