LCOV - code coverage report
Current view: top level - sw/source/core/layout - objectformatterlayfrm.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 40 55 72.7 %
Date: 2015-06-13 12:38:46 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        1535 : SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
      29             :                                                   const SwPageFrm& _rPageFrm,
      30             :                                                   SwLayAction* _pLayAction )
      31             :     : SwObjectFormatter( _rPageFrm, _pLayAction ),
      32        1535 :       mrAnchorLayFrm( _rAnchorLayFrm )
      33             : {
      34        1535 : }
      35             : 
      36        3070 : SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
      37             : {
      38        3070 : }
      39             : 
      40       16288 : SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
      41             :                                                 SwLayoutFrm& _rAnchorLayFrm,
      42             :                                                 const SwPageFrm& _rPageFrm,
      43             :                                                 SwLayAction* _pLayAction )
      44             : {
      45       24103 :     if ( !_rAnchorLayFrm.IsPageFrm() &&
      46        7815 :          !_rAnchorLayFrm.IsFlyFrm() )
      47             :     {
      48             :         OSL_FAIL( "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexpected type of anchor frame " );
      49           0 :         return 0L;
      50             :     }
      51             : 
      52       16288 :     SwObjectFormatterLayFrm* pObjFormatter = 0L;
      53             : 
      54             :     // create object formatter, if floating screen objects are registered at
      55             :     // given anchor layout frame.
      56       33933 :     if ( _rAnchorLayFrm.GetDrawObjs() ||
      57       24426 :          ( _rAnchorLayFrm.IsPageFrm() &&
      58        8316 :             static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
      59             :     {
      60             :         pObjFormatter =
      61        1535 :             new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
      62             :     }
      63             : 
      64       16288 :     return pObjFormatter;
      65             : }
      66             : 
      67        7635 : SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
      68             : {
      69        7635 :     return mrAnchorLayFrm;
      70             : }
      71             : 
      72             : // #i40147# - add parameter <_bCheckForMovedFwd>.
      73             : // Not relevant for objects anchored at layout frame.
      74         602 : bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
      75             :                                            const bool )
      76             : {
      77         602 :     _FormatObj( _rAnchoredObj );
      78             : 
      79             :     // #124218# - consider that the layout action has to be
      80             :     // restarted due to a deleted page frame.
      81         602 :     return GetLayAction() == nullptr || !GetLayAction()->IsAgain();
      82             : }
      83             : 
      84        1535 : bool SwObjectFormatterLayFrm::DoFormatObjs()
      85             : {
      86        1535 :     bool bSuccess( true );
      87             : 
      88        1535 :     bSuccess = _FormatObjsAtFrm();
      89             : 
      90        1535 :     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        1514 :         bSuccess = _AdditionalFormatObjsOnPage();
      97             :     }
      98             : 
      99        1535 :     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        1514 : bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
     109             : {
     110        1514 :     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        1514 :     if ( GetLayAction() && GetLayAction()->IsAgain() )
     119             :     {
     120           0 :         return false;
     121             :     }
     122             : 
     123        1514 :     SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
     124             : 
     125        1514 :     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        1514 :     bool bSuccess( true );
     132             : 
     133        6368 :     for ( size_t i = 0; i < rPageFrm.GetSortedObjs()->size(); ++i )
     134             :     {
     135        4854 :         SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
     136             : 
     137             :         // #i51941# - do not format object, which are anchored
     138             :         // inside or at fly frame.
     139        4854 :         if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
     140             :         {
     141         131 :             continue;
     142             :         }
     143             :         // #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
     144             :         // is replaced by method <FindPageFrmOfAnchor()>. It's return value
     145             :         // have to be checked.
     146        4723 :         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        9446 :         if ( pPageFrmOfAnchor &&
     152             :              // #i35911#
     153        4723 :              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        1514 :     return bSuccess;
     188         177 : }
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11