LCOV - code coverage report
Current view: top level - sw/source/core/fields - postithelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 49 62 79.0 %
Date: 2014-04-11 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 <postithelper.hxx>
      21             : #include <PostItMgr.hxx>
      22             : #include <AnnotationWin.hxx>
      23             : 
      24             : #include <fmtfld.hxx>
      25             : #include <txtfld.hxx>
      26             : #include <docufld.hxx>
      27             : #include <ndtxt.hxx>
      28             : #include <cntfrm.hxx>
      29             : #include <pagefrm.hxx>
      30             : #include <rootfrm.hxx>
      31             : #include <txtfrm.hxx>
      32             : #include <tabfrm.hxx>
      33             : #include <IDocumentRedlineAccess.hxx>
      34             : #include <redline.hxx>
      35             : #include <scriptinfo.hxx>
      36             : #include <editeng/charhiddenitem.hxx>
      37             : #include <switerator.hxx>
      38             : 
      39             : class Point;
      40             : 
      41             : namespace {
      42             : 
      43             : struct LayoutInfoOrder
      44             : {
      45             :     bool operator()( const SwLayoutInfo& rLayoutInfo,
      46             :                      const SwLayoutInfo& rNewLayoutInfo )
      47             :     {
      48             :         if ( rLayoutInfo.mnPageNumber != rNewLayoutInfo.mnPageNumber )
      49             :         {
      50             :             // corresponding <SwFrm> instances are on different pages
      51             :             return rLayoutInfo.mnPageNumber < rNewLayoutInfo.mnPageNumber;
      52             :         }
      53             :         else
      54             :         {
      55             :             // corresponding <SwFrm> instances are in different repeating table header rows
      56             :             OSL_ENSURE( rLayoutInfo.mpAnchorFrm->FindTabFrm(),
      57             :                     "<LayoutInfoOrder::operator()> - table frame not found" );
      58             :             OSL_ENSURE( rNewLayoutInfo.mpAnchorFrm->FindTabFrm(),
      59             :                     "<LayoutInfoOrder::operator()> - table frame not found" );
      60             :             const SwTabFrm* pLayoutInfoTabFrm( rLayoutInfo.mpAnchorFrm->FindTabFrm() );
      61             :             const SwTabFrm* pNewLayoutInfoTabFrm( rNewLayoutInfo.mpAnchorFrm->FindTabFrm() );
      62             :             const SwTabFrm* pTmpTabFrm( pNewLayoutInfoTabFrm );
      63             :             while ( pTmpTabFrm && pTmpTabFrm->GetFollow() )
      64             :             {
      65             :                 pTmpTabFrm = static_cast<const SwTabFrm*>(pTmpTabFrm->GetFollow()->GetFrm());
      66             :                 if ( pTmpTabFrm == pLayoutInfoTabFrm )
      67             :                 {
      68             :                     return false;
      69             :                 }
      70             :             }
      71             :             return true;
      72             :         }
      73             :     }
      74             : };
      75             : 
      76             : } // eof anonymous namespace
      77             : 
      78         354 : SwPostItHelper::SwLayoutStatus SwPostItHelper::getLayoutInfos(
      79             :     SwLayoutInfo& o_rInfo,
      80             :     const SwPosition& rAnchorPos,
      81             :     const SwPosition* pAnnotationStartPos )
      82             : {
      83         354 :     SwLayoutStatus aRet = INVISIBLE;
      84         354 :     SwTxtNode* pTxtNode = rAnchorPos.nNode.GetNode().GetTxtNode();
      85         354 :     if ( pTxtNode == NULL )
      86           0 :         return aRet;
      87             : 
      88         354 :     SwIterator<SwTxtFrm,SwCntntNode> aIter( *pTxtNode );
      89         708 :     for( SwTxtFrm* pTxtFrm = aIter.First(); pTxtFrm != NULL; pTxtFrm = aIter.Next() )
      90             :     {
      91         354 :         if( !pTxtFrm->IsFollow() )
      92             :         {
      93         354 :             pTxtFrm = pTxtFrm->GetFrmAtPos( rAnchorPos );
      94         354 :             SwPageFrm *pPage = pTxtFrm ? pTxtFrm->FindPageFrm() : 0;
      95         354 :             if ( pPage != NULL && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
      96             :             {
      97         322 :                 aRet = VISIBLE;
      98             : 
      99         322 :                 o_rInfo.mpAnchorFrm = pTxtFrm;
     100         322 :                 pTxtFrm->GetCharRect( o_rInfo.mPosition, rAnchorPos, 0 );
     101         322 :                 if ( pAnnotationStartPos != NULL )
     102             :                 {
     103         261 :                     o_rInfo.mnStartNodeIdx = pAnnotationStartPos->nNode.GetIndex();
     104         261 :                     o_rInfo.mnStartContent = pAnnotationStartPos->nContent.GetIndex();
     105             :                 }
     106             :                 else
     107             :                 {
     108          61 :                     o_rInfo.mnStartNodeIdx = 0;
     109          61 :                     o_rInfo.mnStartContent = -1;
     110             :                 }
     111         322 :                 o_rInfo.mPageFrame = pPage->Frm();
     112         322 :                 o_rInfo.mPagePrtArea = pPage->Prt();
     113         322 :                 o_rInfo.mPagePrtArea.Pos() += o_rInfo.mPageFrame.Pos();
     114         322 :                 o_rInfo.mnPageNumber = pPage->GetPhyPageNum();
     115         322 :                 o_rInfo.meSidebarPosition = pPage->SidebarPosition();
     116         322 :                 o_rInfo.mRedlineAuthor = 0;
     117             : 
     118         322 :                 const IDocumentRedlineAccess* pIDRA = pTxtNode->getIDocumentRedlineAccess();
     119         322 :                 if( IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() ) )
     120             :                 {
     121         322 :                     const SwRangeRedline* pRedline = pIDRA->GetRedline( rAnchorPos, 0 );
     122         322 :                     if( pRedline )
     123             :                     {
     124           0 :                         if( nsRedlineType_t::REDLINE_INSERT == pRedline->GetType() )
     125           0 :                             aRet = INSERTED;
     126           0 :                         else if( nsRedlineType_t::REDLINE_DELETE == pRedline->GetType() )
     127           0 :                             aRet = DELETED;
     128           0 :                         o_rInfo.mRedlineAuthor = pRedline->GetAuthor();
     129             :                     }
     130             :                 }
     131             :             }
     132             :         }
     133             :     }
     134             : 
     135         322 :     return ( (aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTxtNode , rAnchorPos.nContent.GetIndex()) )
     136             :              ? HIDDEN
     137         708 :              : aRet;
     138             : }
     139             : 
     140       10749 : long SwPostItHelper::getLayoutHeight( const SwRootFrm* pRoot )
     141             : {
     142       10749 :     long nRet = pRoot ? pRoot->Frm().Height() : 0;
     143       10749 :     return nRet;
     144             : }
     145             : 
     146         142 : void SwPostItHelper::setSidebarChanged( SwRootFrm* pRoot, bool bBrowseMode )
     147             : {
     148         142 :     if( pRoot )
     149             :     {
     150         142 :         pRoot->SetSidebarChanged();
     151         142 :         if( bBrowseMode )
     152          76 :             pRoot->InvalidateBrowseWidth();
     153             :     }
     154         142 : }
     155             : 
     156           0 : unsigned long SwPostItHelper::getPageInfo( SwRect& rPageFrm, const SwRootFrm* pRoot, const Point& rPoint )
     157             : {
     158           0 :     unsigned long nRet = 0;
     159           0 :     const SwFrm* pPage = pRoot->GetPageAtPos( rPoint, 0, true );
     160           0 :     if( pPage )
     161             :     {
     162           0 :         nRet = pPage->GetPhyPageNum();
     163           0 :         rPageFrm = pPage->Frm();
     164             :     }
     165           0 :     return nRet;
     166             : }
     167             : 
     168         764 : SwPosition SwAnnotationItem::GetAnchorPosition() const
     169             : {
     170         764 :     SwTxtFld* pTxtFld = mrFmtFld.GetTxtFld();
     171         764 :     SwTxtNode* pTxtNode = pTxtFld->GetpTxtNode();
     172             : 
     173         764 :     SwPosition aPos( *pTxtNode );
     174         764 :     aPos.nContent.Assign( pTxtNode, *(pTxtFld->GetStart()) );
     175         764 :     return aPos;
     176             : }
     177             : 
     178         354 : bool SwAnnotationItem::UseElement()
     179             : {
     180         354 :     return mrFmtFld.IsFldInDoc();
     181             : }
     182             : 
     183          48 : sw::sidebarwindows::SwSidebarWin* SwAnnotationItem::GetSidebarWindow(
     184             :                                                             SwEditWin& rEditWin,
     185             :                                                             WinBits nBits,
     186             :                                                             SwPostItMgr& aMgr,
     187             :                                                             SwPostItBits aBits)
     188             : {
     189             :     return new sw::annotation::SwAnnotationWin( rEditWin, nBits,
     190             :                                                 aMgr, aBits,
     191             :                                                 *this,
     192          48 :                                                 &mrFmtFld );
     193             : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10