LCOV - code coverage report
Current view: top level - sw/source/core/crsr - callnk.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 87 106 82.1 %
Date: 2014-04-11 Functions: 4 5 80.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 <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       25868 : SwCallLink::SwCallLink( SwCrsrShell & rSh )
      48       25868 :     : rShell( rSh )
      49             : {
      50             :     // remember SPoint-values of current cursor
      51       25868 :     SwPaM* pCrsr = rShell.IsTableMode() ? rShell.GetTblCrs() : rShell.GetCrsr();
      52       25868 :     SwNode& rNd = pCrsr->GetPoint()->nNode.GetNode();
      53       25868 :     nNode = rNd.GetIndex();
      54       25868 :     nCntnt = pCrsr->GetPoint()->nContent.GetIndex();
      55       25868 :     nNdTyp = rNd.GetNodeType();
      56       25868 :     bHasSelection = ( *pCrsr->GetPoint() != *pCrsr->GetMark() );
      57             : 
      58       25868 :     if( rNd.IsTxtNode() )
      59       25868 :         nLeftFrmPos = SwCallLink::getLayoutFrm( rShell.GetLayout(), (SwTxtNode&)rNd, nCntnt,
      60       51736 :                                             !rShell.ActionPend() );
      61             :     else
      62             :     {
      63           0 :         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           0 :         if( ND_CONTENTNODE & nNdTyp )
      71           0 :             nNdTyp = 0;
      72             :     }
      73       25868 : }
      74             : 
      75       51736 : static void lcl_notifyRow(const SwCntntNode* pNode, SwCrsrShell& rShell)
      76             : {
      77       51736 :     if ( !pNode )
      78         157 :         return;
      79             : 
      80       51579 :     SwFrm *const pMyFrm = pNode->getLayoutFrm( rShell.GetLayout() );
      81       51579 :     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       51579 :     SwRowFrm *const pRow = pMyFrm->FindRowFrm();
      87       51579 :     if ( !pRow )
      88       49176 :         return;
      89             : 
      90        2403 :     const SwTableLine* pLine = pRow->GetTabLine( );
      91             :     // Avoid redrawing the complete row if there are no nested tables
      92        7656 :     for (SwFrm *pCell = pRow->GetLower(); pCell; pCell = pCell->GetNext())
      93             :     {
      94       12263 :         for (SwFrm *pContent = pCell->GetLower(); pContent; pContent = pContent->GetNext())
      95             :         {
      96        7010 :             if (pContent->GetType() == FRM_TAB)
      97             :             {
      98           0 :                 SwFmtFrmSize pSize = pLine->GetFrmFmt()->GetFrmSize();
      99           0 :                 pRow->ModifyNotification(NULL, &pSize);
     100           0 :                 return;
     101             :             }
     102             :         }
     103             :     }
     104             : }
     105             : 
     106       25868 : SwCallLink::~SwCallLink()
     107             : {
     108       25868 :     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       25868 :     SwPaM* pCurCrsr = rShell.IsTableMode() ? rShell.GetTblCrs() : rShell.GetCrsr();
     114       25868 :     SwCntntNode * pCNd = pCurCrsr->GetCntntNode();
     115       25868 :     if( !pCNd )
     116           0 :         return;
     117             : 
     118       25868 :     lcl_notifyRow(pCNd, rShell);
     119             : 
     120       25868 :     const SwDoc *pDoc=rShell.GetDoc();
     121       25868 :     const SwCntntNode *pNode = NULL;
     122       25868 :     if ( ( pDoc != NULL && nNode < pDoc->GetNodes( ).Count( ) ) )
     123             :     {
     124       25851 :         pNode = pDoc->GetNodes()[nNode]->GetCntntNode();
     125             :     }
     126       25868 :     lcl_notifyRow(pNode, rShell);
     127             : 
     128       25868 :     sal_Int32 nCmp, nAktCntnt = pCurCrsr->GetPoint()->nContent.GetIndex();
     129       25868 :     sal_uInt16 nNdWhich = pCNd->GetNodeType();
     130       25868 :     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       25868 :     pCNd->Add( &rShell );
     135             : 
     136       25868 :     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         276 :         rShell.CallChgLnk();
     143             :     }
     144       25592 :     else if( !bHasSelection != !(*pCurCrsr->GetPoint() != *pCurCrsr->GetMark()) )
     145             :     {
     146             :         // always call change link when selection changes
     147          18 :         rShell.CallChgLnk();
     148             :     }
     149       51120 :     else if( rShell.m_aChgLnk.IsSet() && ND_TEXTNODE == nNdWhich &&
     150       25546 :              nCntnt != nAktCntnt )
     151             :     {
     152             :         // If travelling with left/right only and the frame is
     153             :         // unchanged (columns!) then check text hints.
     154        5979 :         if( nLeftFrmPos == SwCallLink::getLayoutFrm( rShell.GetLayout(), (SwTxtNode&)*pCNd, nAktCntnt,
     155        6389 :                                                     !rShell.ActionPend() ) &&
     156        3341 :             (( nCmp = nCntnt ) + 1 == nAktCntnt ||          // Right
     157        1434 :             nCntnt -1 == ( nCmp = nAktCntnt )) )            // Left
     158             :         {
     159         496 :             if( nCmp == nAktCntnt && pCurCrsr->HasMark() ) // left & select
     160           4 :                 ++nCmp;
     161             : 
     162         496 :             if ( ((SwTxtNode*)pCNd)->HasHints() )
     163             :             {
     164         366 :                 const SwpHints &rHts = ((SwTxtNode*)pCNd)->GetSwpHints();
     165             : 
     166         723 :                 for( sal_uInt16 n = 0; n < rHts.Count(); n++ )
     167             :                 {
     168         637 :                     const SwTxtAttr* pHt = rHts[ n ];
     169         637 :                     const sal_Int32 *pEnd = pHt->End();
     170         637 :                     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        1096 :                     if( ( !pEnd || ( nStart == *pEnd ) ) &&
     175         655 :                         ( nStart == nCntnt || nStart == nAktCntnt) )
     176             :                     {
     177         264 :                         rShell.CallChgLnk();
     178         264 :                         return;
     179             :                     }
     180             : 
     181             :                     // If the attribute has an area and that area is not empty ...
     182         565 :                     else if( pEnd && nStart < *pEnd &&
     183             :                         // ... then test if travelling occurred via start/end.
     184         176 :                         ( nStart == nCmp ||
     185         352 :                             ( pHt->DontExpand() ? nCmp == *pEnd-1
     186           0 :                                                 : nCmp == *pEnd ) ))
     187             :                     {
     188          16 :                         rShell.CallChgLnk();
     189          16 :                         return;
     190             :                     }
     191             :                 }
     192             :             }
     193             : 
     194         216 :             if( g_pBreakIt->GetBreakIter().is() )
     195             :             {
     196         216 :                 const OUString rTxt = ((SwTxtNode*)pCNd)->GetTxt();
     197        1072 :                 if( !nCmp ||
     198         852 :                     g_pBreakIt->GetBreakIter()->getScriptType( rTxt, nCmp )
     199         640 :                      != g_pBreakIt->GetBreakIter()->getScriptType( rTxt, nCmp - 1 ))
     200             :                 {
     201          20 :                     rShell.CallChgLnk();
     202          20 :                     return;
     203         196 :                 }
     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        1497 :             rShell.CallChgLnk();
     211             :     }
     212             : 
     213             :     const SwFrm* pFrm;
     214             :     const SwFlyFrm *pFlyFrm;
     215       76634 :     if( !rShell.ActionPend() && 0 != ( pFrm = pCNd->getLayoutFrm(rShell.GetLayout(), 0, 0, false) ) &&
     216       25568 :         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       25868 : }
     231             : 
     232       53539 : long SwCallLink::getLayoutFrm( const SwRootFrm* pRoot, SwTxtNode& rNd, sal_Int32 nCntPos, bool bCalcFrm )
     233             : {
     234       53539 :     SwTxtFrm* pFrm = (SwTxtFrm*)rNd.getLayoutFrm(pRoot,0,0,bCalcFrm), *pNext = pFrm;
     235       53539 :     if ( pFrm && !pFrm->IsHiddenNow() )
     236             :     {
     237       53480 :         if( pFrm->HasFollow() )
     238       58034 :             while( 0 != ( pNext = (SwTxtFrm*)pFrm->GetFollow() ) &&
     239       18404 :                     nCntPos >= pNext->GetOfst() )
     240       18356 :                 pFrm = pNext;
     241             : 
     242       53480 :         return pFrm->Frm().Left();
     243             :     }
     244          59 :     return 0;
     245             : }
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10