LCOV - code coverage report
Current view: top level - sw/source/core/layout - objectformatterlayfrm.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 40 55 72.7 %
Date: 2014-11-03 Functions: 10 10 100.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 <objectformatterlayfrm.hxx>
      21             : #include <anchoredobject.hxx>
      22             : #include <sortedobjs.hxx>
      23             : #include <pagefrm.hxx>
      24             : 
      25             : // #124218#
      26             : #include <layact.hxx>
      27             : 
      28        2776 : SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
      29             :                                                   const SwPageFrm& _rPageFrm,
      30             :                                                   SwLayAction* _pLayAction )
      31             :     : SwObjectFormatter( _rPageFrm, _pLayAction ),
      32        2776 :       mrAnchorLayFrm( _rAnchorLayFrm )
      33             : {
      34        2776 : }
      35             : 
      36        5552 : SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
      37             : {
      38        5552 : }
      39             : 
      40       26827 : SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
      41             :                                                 SwLayoutFrm& _rAnchorLayFrm,
      42             :                                                 const SwPageFrm& _rPageFrm,
      43             :                                                 SwLayAction* _pLayAction )
      44             : {
      45       41495 :     if ( !_rAnchorLayFrm.IsPageFrm() &&
      46       14668 :          !_rAnchorLayFrm.IsFlyFrm() )
      47             :     {
      48             :         OSL_FAIL( "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexpected type of anchor frame " );
      49           0 :         return 0L;
      50             :     }
      51             : 
      52       26827 :     SwObjectFormatterLayFrm* pObjFormatter = 0L;
      53             : 
      54             :     // create object formatter, if floating screen objects are registered at
      55             :     // given anchor layout frame.
      56       56076 :     if ( _rAnchorLayFrm.GetDrawObjs() ||
      57       38324 :          ( _rAnchorLayFrm.IsPageFrm() &&
      58       11851 :             static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
      59             :     {
      60             :         pObjFormatter =
      61        2776 :             new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
      62             :     }
      63             : 
      64       26827 :     return pObjFormatter;
      65             : }
      66             : 
      67       13796 : SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
      68             : {
      69       13796 :     return mrAnchorLayFrm;
      70             : }
      71             : 
      72             : // #i40147# - add parameter <_bCheckForMovedFwd>.
      73             : // Not relevant for objects anchored at layout frame.
      74         976 : bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
      75             :                                            const bool )
      76             : {
      77         976 :     _FormatObj( _rAnchoredObj );
      78             : 
      79             :     // #124218# - consider that the layout action has to be
      80             :     // restarted due to a deleted page frame.
      81         976 :     return GetLayAction() ? !GetLayAction()->IsAgain() : true;
      82             : }
      83             : 
      84        2776 : bool SwObjectFormatterLayFrm::DoFormatObjs()
      85             : {
      86        2776 :     bool bSuccess( true );
      87             : 
      88        2776 :     bSuccess = _FormatObjsAtFrm();
      89             : 
      90        2776 :     if ( bSuccess && GetAnchorFrm().IsPageFrm() )
      91             :     {
      92             :         // anchor layout frame is a page frame.
      93             :         // Thus, format also all anchored objects, which are registered at
      94             :         // this page frame, whose 'anchor' isn't on this page frame and whose
      95             :         // anchor frame is valid.
      96        2730 :         bSuccess = _AdditionalFormatObjsOnPage();
      97             :     }
      98             : 
      99        2776 :     return bSuccess;
     100             : }
     101             : 
     102             : /** method to format all anchored objects, which are registered at
     103             :     the page frame, whose 'anchor' isn't on this page frame and whose
     104             :     anchor frame is valid.
     105             : 
     106             :     OD 2004-07-02 #i28701#
     107             : */
     108        2730 : bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
     109             : {
     110        2730 :     if ( !GetAnchorFrm().IsPageFrm() )
     111             :     {
     112             :         OSL_FAIL( "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - mis-usage of method, call only for anchor frames of type page frame" );
     113           0 :         return true;
     114             :     }
     115             : 
     116             :     // #124218# - consider, if the layout action
     117             :     // has to be restarted due to a delete of a page frame.
     118        2730 :     if ( GetLayAction() && GetLayAction()->IsAgain() )
     119             :     {
     120           0 :         return false;
     121             :     }
     122             : 
     123        2730 :     SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
     124             : 
     125        2730 :     if ( !rPageFrm.GetSortedObjs() )
     126             :     {
     127             :         // nothing to do, if no floating screen object is registered at the anchor frame.
     128           0 :         return true;
     129             :     }
     130             : 
     131        2730 :     bool bSuccess( true );
     132             : 
     133       11529 :     for ( size_t i = 0; i < rPageFrm.GetSortedObjs()->size(); ++i )
     134             :     {
     135        8799 :         SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
     136             : 
     137             :         // #i51941# - do not format object, which are anchored
     138             :         // inside or at fly frame.
     139        8799 :         if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
     140             :         {
     141         252 :             continue;
     142             :         }
     143             :         // #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
     144             :         // is replaced by method <FindPageFrmOfAnchor()>. It's return value
     145             :         // have to be checked.
     146        8547 :         SwPageFrm* pPageFrmOfAnchor = pAnchoredObj->FindPageFrmOfAnchor();
     147             :         // #i26945# - check, if the page frame of the
     148             :         // object's anchor frame isn't the given page frame
     149             :         OSL_ENSURE( pPageFrmOfAnchor,
     150             :                 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - missing page frame" );
     151       17094 :         if ( pPageFrmOfAnchor &&
     152             :              // #i35911#
     153        8547 :              pPageFrmOfAnchor->GetPhyPageNum() < rPageFrm.GetPhyPageNum() )
     154             :         {
     155             :             // if format of object fails, stop formatting and pass fail to
     156             :             // calling method via the return value.
     157           0 :             if ( !DoFormatObj( *pAnchoredObj ) )
     158             :             {
     159           0 :                 bSuccess = false;
     160           0 :                 break;
     161             :             }
     162             : 
     163             :             // considering changes at <GetAnchorFrm().GetDrawObjs()> during
     164             :             // format of the object.
     165           0 :             if ( !rPageFrm.GetSortedObjs() ||
     166           0 :                  i > rPageFrm.GetSortedObjs()->size() )
     167             :             {
     168           0 :                 break;
     169             :             }
     170             :             else
     171             :             {
     172             :                 const size_t nActPosOfObj =
     173           0 :                     rPageFrm.GetSortedObjs()->ListPosOf( *pAnchoredObj );
     174           0 :                 if ( nActPosOfObj == rPageFrm.GetSortedObjs()->size() ||
     175             :                      nActPosOfObj > i )
     176             :                 {
     177           0 :                     --i;
     178             :                 }
     179           0 :                 else if ( nActPosOfObj < i )
     180             :                 {
     181           0 :                     i = nActPosOfObj;
     182             :                 }
     183             :             }
     184             :         }
     185             :     } // end of loop on <rPageFrm.GetSortedObjs()>
     186             : 
     187        2730 :     return bSuccess;
     188         270 : }
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10