LCOV - code coverage report
Current view: top level - sw/source/core/layout - flyincnt.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 118 138 85.5 %
Date: 2014-11-03 Functions: 17 19 89.5 %
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 "doc.hxx"
      21             : #include "frmtool.hxx"
      22             : #include "hints.hxx"
      23             : #include <fmtornt.hxx>
      24             : #include "txtfrm.hxx"
      25             : #include "flyfrms.hxx"
      26             : #include <dflyobj.hxx>
      27             : #include <IDocumentSettingAccess.hxx>
      28             : #include <IDocumentDrawModelAccess.hxx>
      29             : 
      30        1464 : SwFlyInCntFrm::SwFlyInCntFrm( SwFlyFrmFmt *pFmt, SwFrm* pSib, SwFrm *pAnch ) :
      31        1464 :     SwFlyFrm( pFmt, pSib, pAnch )
      32             : {
      33        1464 :     bInCnt = bInvalidLayout = bInvalidCntnt = true;
      34        1464 :     SwTwips nRel = pFmt->GetVertOrient().GetPos();
      35             :     // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
      36        1464 :     Point aRelPos;
      37        1464 :     if( pAnch && pAnch->IsVertical() )
      38           0 :         aRelPos.setX(pAnch->IsReverse() ? nRel : -nRel);
      39             :     else
      40        1464 :         aRelPos.setY(nRel);
      41        1464 :     SetCurrRelPos( aRelPos );
      42        1464 : }
      43             : 
      44        4392 : SwFlyInCntFrm::~SwFlyInCntFrm()
      45             : {
      46        1464 :     if ( !GetFmt()->GetDoc()->IsInDtor() && GetAnchorFrm() )
      47             :     {
      48        1464 :         SwRect aTmp( GetObjRectWithSpaces() );
      49        1464 :         SwFlyInCntFrm::NotifyBackground( FindPageFrm(), aTmp, PREP_FLY_LEAVE );
      50             :     }
      51        2928 : }
      52             : 
      53             : // #i28701#
      54      105144 : TYPEINIT1(SwFlyInCntFrm,SwFlyFrm);
      55             : 
      56        2888 : void SwFlyInCntFrm::SetRefPoint( const Point& rPoint,
      57             :                                  const Point& rRelAttr,
      58             :                                  const Point& rRelPos )
      59             : {
      60             :     // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
      61             :     OSL_ENSURE( rPoint != aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" );
      62        2888 :     SwFlyNotify *pNotify = NULL;
      63             :     // No notify at a locked fly frame, if a fly frame is locked, there's
      64             :     // already a SwFlyNotify object on the stack (MakeAll).
      65        2888 :     if( !IsLocked() )
      66        2888 :         pNotify = new SwFlyNotify( this );
      67        2888 :     aRef = rPoint;
      68        2888 :     SetCurrRelPos( rRelAttr );
      69        2888 :     SWRECTFN( GetAnchorFrm() )
      70        2888 :     (Frm().*fnRect->fnSetPos)( rPoint + rRelPos );
      71             :     // #i68520#
      72        2888 :     InvalidateObjRectWithSpaces();
      73        2888 :     if( pNotify )
      74             :     {
      75        2888 :         InvalidatePage();
      76        2888 :         mbValidPos = false;
      77        2888 :         bInvalid  = true;
      78        2888 :         Calc();
      79        2888 :         delete pNotify;
      80             :     }
      81        2888 : }
      82             : 
      83         156 : void SwFlyInCntFrm::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
      84             : {
      85         156 :     bool bCallPrepare = false;
      86         156 :     sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
      87         156 :     if (RES_ATTRSET_CHG == nWhich && pNew)
      88             :     {
      89          62 :         if(pOld &&
      90          28 :             (SfxItemState::SET == ((SwAttrSetChg*)pNew)->GetChgSet()->
      91          50 :             GetItemState(RES_SURROUND, false) ||
      92          22 :             SfxItemState::SET == ((SwAttrSetChg*)pNew)->GetChgSet()->
      93          22 :             GetItemState(RES_FRMMACRO, false)) )
      94             :         {
      95           6 :             SwAttrSetChg aOld( *(SwAttrSetChg*)pOld );
      96          12 :             SwAttrSetChg aNew( *(SwAttrSetChg*)pNew );
      97             : 
      98           6 :             aOld.ClearItem( RES_SURROUND );
      99           6 :             aNew.ClearItem( RES_SURROUND );
     100           6 :             aOld.ClearItem( RES_FRMMACRO );
     101           6 :             aNew.ClearItem( RES_FRMMACRO );
     102           6 :             if( aNew.Count() )
     103             :             {
     104           0 :                 SwFlyFrm::Modify( &aOld, &aNew );
     105           0 :                 bCallPrepare = true;
     106           6 :             }
     107             :         }
     108          22 :         else if( ((SwAttrSetChg*)pNew)->GetChgSet()->Count())
     109             :         {
     110          22 :             SwFlyFrm::Modify( pOld, pNew );
     111          22 :             bCallPrepare = true;
     112          28 :         }
     113             :     }
     114         128 :     else if( nWhich != RES_SURROUND && RES_FRMMACRO != nWhich )
     115             :     {
     116         128 :         SwFlyFrm::Modify( pOld, pNew );
     117         128 :         bCallPrepare = true;
     118             :     }
     119             : 
     120         156 :     if ( bCallPrepare && GetAnchorFrm() )
     121         150 :         AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, GetFmt() );
     122         156 : }
     123             : 
     124             : /// Here the content gets formatted initially.
     125        2945 : void SwFlyInCntFrm::Format( const SwBorderAttrs *pAttrs )
     126             : {
     127        2945 :     if ( !Frm().Height() )
     128             :     {
     129           0 :         Lock(); //don't format the anchor on the crook.
     130           0 :         SwCntntFrm *pCntnt = ContainsCntnt();
     131           0 :         while ( pCntnt )
     132           0 :         {   pCntnt->Calc();
     133           0 :             pCntnt = pCntnt->GetNextCntntFrm();
     134             :         }
     135           0 :         Unlock();
     136             :     }
     137        2945 :     SwFlyFrm::Format( pAttrs );
     138        2945 : }
     139             : 
     140             : /** Calculate object position
     141             :  *
     142             :  * @note: In contrast to other Frames, we only calculate the relative position
     143             :  *        here. The absolute position is only calculated using SetAbsPos.
     144             :  **/
     145        4261 : void SwFlyInCntFrm::MakeObjPos()
     146             : {
     147        4261 :     if ( !mbValidPos )
     148             :     {
     149        4261 :         mbValidPos = true;
     150        4261 :         SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
     151        4261 :         const SwFmtVertOrient &rVert = pFmt->GetVertOrient();
     152             :         //Update the current values in the format if needed, during this we of
     153             :         //course must not send any Modify.
     154        4261 :         const bool bVert = GetAnchorFrm()->IsVertical();
     155        4261 :         const bool bRev = GetAnchorFrm()->IsReverse();
     156        4261 :         SwTwips nOld = rVert.GetPos();
     157        4261 :         SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y();
     158        4261 :         if( bRev )
     159           0 :             nAct = -nAct;
     160        4261 :         if( nAct != nOld )
     161             :         {
     162        1442 :             SwFmtVertOrient aVert( rVert );
     163        1442 :             aVert.SetPos( nAct );
     164        1442 :             pFmt->LockModify();
     165        1442 :             pFmt->SetFmtAttr( aVert );
     166        1442 :             pFmt->UnlockModify();
     167             :         }
     168             :     }
     169        4261 : }
     170             : 
     171             : // #115759#
     172        1537 : void SwFlyInCntFrm::_ActionOnInvalidation( const InvalidationType _nInvalid )
     173             : {
     174        1537 :     if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
     175          35 :         AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, &GetFrmFmt() );
     176        1537 : }
     177             : 
     178        3068 : void SwFlyInCntFrm::NotifyBackground( SwPageFrm *, const SwRect& rRect,
     179             :                                        PrepareHint eHint)
     180             : {
     181        3068 :     if ( eHint == PREP_FLY_ATTR_CHG )
     182           0 :         AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG );
     183             :     else
     184        3068 :         AnchorFrm()->Prepare( eHint, (void*)&rRect );
     185        3068 : }
     186             : 
     187        1041 : const Point SwFlyInCntFrm::GetRelPos() const
     188             : {
     189        1041 :     Calc();
     190        1041 :     return GetCurrRelPos();
     191             : }
     192             : 
     193             : /// @see SwRowFrm::RegistFlys()
     194        1336 : void SwFlyInCntFrm::RegistFlys()
     195             : {
     196        1336 :     SwPageFrm *pPage = FindPageFrm();
     197             :     OSL_ENSURE( pPage, "Register Flys without pages?" );
     198        1336 :     ::RegistFlys( pPage, this );
     199        1336 : }
     200             : 
     201        5715 : void SwFlyInCntFrm::MakeAll()
     202             : {
     203             :     // OD 2004-01-19 #110582#
     204        5715 :     if ( !GetFmt()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
     205             :     {
     206           0 :         return;
     207             :     }
     208             : 
     209        5715 :     if ( !GetAnchorFrm() || IsLocked() || IsColLocked() || !FindPageFrm() )
     210           0 :         return;
     211             : 
     212        5715 :     Lock(); // The curtain falls
     213             : 
     214             :         //does the notification in the DTor
     215        5715 :     const SwFlyNotify aNotify( this );
     216       11430 :     SwBorderAttrAccess aAccess( SwFrm::GetCache(), this );
     217        5715 :     const SwBorderAttrs &rAttrs = *aAccess.Get();
     218             : 
     219        5715 :     if ( IsClipped() )
     220           0 :         mbValidSize = bHeightClipped = bWidthClipped = false;
     221             : 
     222       17145 :     while ( !mbValidPos || !mbValidSize || !mbValidPrtArea || !m_bValidContentPos )
     223             :     {
     224             :         //Only stop, if the flag is set!!
     225        5715 :         if ( !mbValidSize )
     226             :         {
     227        2945 :             mbValidPrtArea = false;
     228             :         }
     229             : 
     230        5715 :         if ( !mbValidPrtArea )
     231             :         {
     232        2945 :             MakePrtArea( rAttrs );
     233        2945 :             m_bValidContentPos = false;
     234             :         }
     235             : 
     236        5715 :         if ( !mbValidSize )
     237        2945 :             Format( &rAttrs );
     238             : 
     239        5715 :         if ( !mbValidPos )
     240             :         {
     241        4261 :             MakeObjPos();
     242             :         }
     243             : 
     244        5715 :         if ( !m_bValidContentPos )
     245        2945 :             MakeContentPos( rAttrs );
     246             : 
     247             :         // re-activate clipping of as-character anchored Writer fly frames
     248             :         // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
     249       11430 :         if ( mbValidPos && mbValidSize &&
     250        5715 :              GetFmt()->getIDocumentSettingAccess()->get( IDocumentSettingAccess::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
     251             :         {
     252           0 :             SwFrm* pFrm = AnchorFrm();
     253           0 :             if ( Frm().Left() == (pFrm->Frm().Left()+pFrm->Prt().Left()) &&
     254           0 :                  Frm().Width() > pFrm->Prt().Width() )
     255             :             {
     256           0 :                 Frm().Width( pFrm->Prt().Width() );
     257           0 :                 mbValidPrtArea = false;
     258           0 :                 bWidthClipped = true;
     259             :             }
     260             :         }
     261             :     }
     262       11430 :     Unlock();
     263         270 : }
     264             : 
     265             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10