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

Generated by: LCOV version 1.10