LCOV - code coverage report
Current view: top level - sw/source/core/layout - objectformatterlayfrm.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 40 55 72.7 %
Date: 2014-04-11 Functions: 8 8 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         847 : SwObjectFormatterLayFrm::SwObjectFormatterLayFrm( SwLayoutFrm& _rAnchorLayFrm,
      29             :                                                   const SwPageFrm& _rPageFrm,
      30             :                                                   SwLayAction* _pLayAction )
      31             :     : SwObjectFormatter( _rPageFrm, _pLayAction ),
      32         847 :       mrAnchorLayFrm( _rAnchorLayFrm )
      33             : {
      34         847 : }
      35             : 
      36        1694 : SwObjectFormatterLayFrm::~SwObjectFormatterLayFrm()
      37             : {
      38        1694 : }
      39             : 
      40        8950 : SwObjectFormatterLayFrm* SwObjectFormatterLayFrm::CreateObjFormatter(
      41             :                                                 SwLayoutFrm& _rAnchorLayFrm,
      42             :                                                 const SwPageFrm& _rPageFrm,
      43             :                                                 SwLayAction* _pLayAction )
      44             : {
      45       13532 :     if ( !_rAnchorLayFrm.IsPageFrm() &&
      46        4582 :          !_rAnchorLayFrm.IsFlyFrm() )
      47             :     {
      48             :         OSL_FAIL( "<SwObjectFormatterLayFrm::CreateObjFormatter(..)> - unexcepted type of anchor frame " );
      49           0 :         return 0L;
      50             :     }
      51             : 
      52        8950 :     SwObjectFormatterLayFrm* pObjFormatter = 0L;
      53             : 
      54             :     // create object formatter, if floating screen objects are registered at
      55             :     // given anchor layout frame.
      56       18670 :     if ( _rAnchorLayFrm.GetDrawObjs() ||
      57       13164 :          ( _rAnchorLayFrm.IsPageFrm() &&
      58        4291 :             static_cast<SwPageFrm&>(_rAnchorLayFrm).GetSortedObjs() ) )
      59             :     {
      60             :         pObjFormatter =
      61         847 :             new SwObjectFormatterLayFrm( _rAnchorLayFrm, _rPageFrm, _pLayAction );
      62             :     }
      63             : 
      64        8950 :     return pObjFormatter;
      65             : }
      66             : 
      67        4237 : SwFrm& SwObjectFormatterLayFrm::GetAnchorFrm()
      68             : {
      69        4237 :     return mrAnchorLayFrm;
      70             : }
      71             : 
      72             : // #i40147# - add parameter <_bCheckForMovedFwd>.
      73             : // Not relevant for objects anchored at layout frame.
      74         126 : bool SwObjectFormatterLayFrm::DoFormatObj( SwAnchoredObject& _rAnchoredObj,
      75             :                                            const bool )
      76             : {
      77         126 :     _FormatObj( _rAnchoredObj );
      78             : 
      79             :     // #124218# - consider that the layout action has to be
      80             :     // restarted due to a deleted page frame.
      81         126 :     return GetLayAction() ? !GetLayAction()->IsAgain() : true;
      82             : }
      83             : 
      84         847 : bool SwObjectFormatterLayFrm::DoFormatObjs()
      85             : {
      86         847 :     bool bSuccess( true );
      87             : 
      88         847 :     bSuccess = _FormatObjsAtFrm();
      89             : 
      90         847 :     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         847 :         bSuccess = _AdditionalFormatObjsOnPage();
      97             :     }
      98             : 
      99         847 :     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         847 : bool SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()
     109             : {
     110         847 :     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         847 :     if ( GetLayAction() && GetLayAction()->IsAgain() )
     119             :     {
     120           0 :         return false;
     121             :     }
     122             : 
     123         847 :     SwPageFrm& rPageFrm = static_cast<SwPageFrm&>(GetAnchorFrm());
     124             : 
     125         847 :     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         847 :     bool bSuccess( true );
     132             : 
     133         847 :     sal_uInt32 i = 0;
     134        3016 :     for ( ; i < rPageFrm.GetSortedObjs()->Count(); ++i )
     135             :     {
     136        2169 :         SwAnchoredObject* pAnchoredObj = (*rPageFrm.GetSortedObjs())[i];
     137             : 
     138             :         // #i51941# - do not format object, which are anchored
     139             :         // inside or at fly frame.
     140        2169 :         if ( pAnchoredObj->GetAnchorFrm()->FindFlyFrm() )
     141             :         {
     142           8 :             continue;
     143             :         }
     144             :         // #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
     145             :         // is replaced by method <FindPageFrmOfAnchor()>. It's return value
     146             :         // have to be checked.
     147        2161 :         SwPageFrm* pPageFrmOfAnchor = pAnchoredObj->FindPageFrmOfAnchor();
     148             :         // #i26945# - check, if the page frame of the
     149             :         // object's anchor frame isn't the given page frame
     150             :         OSL_ENSURE( pPageFrmOfAnchor,
     151             :                 "<SwObjectFormatterLayFrm::_AdditionalFormatObjsOnPage()> - missing page frame" );
     152        4322 :         if ( pPageFrmOfAnchor &&
     153             :              // #i35911#
     154        2161 :              pPageFrmOfAnchor->GetPhyPageNum() < rPageFrm.GetPhyPageNum() )
     155             :         {
     156             :             // if format of object fails, stop formatting and pass fail to
     157             :             // calling method via the return value.
     158           0 :             if ( !DoFormatObj( *pAnchoredObj ) )
     159             :             {
     160           0 :                 bSuccess = false;
     161           0 :                 break;
     162             :             }
     163             : 
     164             :             // considering changes at <GetAnchorFrm().GetDrawObjs()> during
     165             :             // format of the object.
     166           0 :             if ( !rPageFrm.GetSortedObjs() ||
     167           0 :                  i > rPageFrm.GetSortedObjs()->Count() )
     168             :             {
     169           0 :                 break;
     170             :             }
     171             :             else
     172             :             {
     173             :                 sal_uInt32 nActPosOfObj =
     174           0 :                     rPageFrm.GetSortedObjs()->ListPosOf( *pAnchoredObj );
     175           0 :                 if ( nActPosOfObj == rPageFrm.GetSortedObjs()->Count() ||
     176             :                      nActPosOfObj > i )
     177             :                 {
     178           0 :                     --i;
     179             :                 }
     180           0 :                 else if ( nActPosOfObj < i )
     181             :                 {
     182           0 :                     i = nActPosOfObj;
     183             :                 }
     184             :             }
     185             :         }
     186             :     } // end of loop on <rPageFrm.GetSortedObjs()>
     187             : 
     188         847 :     return bSuccess;
     189             : }
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10