LCOV - code coverage report
Current view: top level - sw/source/core/text - porfly.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 155 178 87.1 %
Date: 2014-11-03 Functions: 12 13 92.3 %
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 "dcontact.hxx"
      21             : #include "dflyobj.hxx"
      22             : #include "pam.hxx"
      23             : #include "flyfrm.hxx"
      24             : #include "rootfrm.hxx"
      25             : #include "frmfmt.hxx"
      26             : #include "viewsh.hxx"
      27             : #include "textboxhelper.hxx"
      28             : 
      29             : #include <vcl/outdev.hxx>
      30             : #include <editeng/lrspitem.hxx>
      31             : #include <editeng/ulspitem.hxx>
      32             : #include <fmtanchr.hxx>
      33             : #include <fmtflcnt.hxx>
      34             : #include <fmtornt.hxx>
      35             : #include <frmatr.hxx>
      36             : #include "flyfrms.hxx"
      37             : #include "txatbase.hxx"
      38             : #include "porfly.hxx"
      39             : #include "porlay.hxx"
      40             : #include "inftxt.hxx"
      41             : 
      42             : #include <sortedobjs.hxx>
      43             : 
      44             : // class SwFlyPortion => we expect a frame-locale SwRect!
      45             : 
      46         161 : void SwFlyPortion::Paint( const SwTxtPaintInfo& ) const
      47             : {
      48         161 : }
      49             : 
      50         820 : bool SwFlyPortion::Format( SwTxtFormatInfo &rInf )
      51             : {
      52             :     OSL_ENSURE( Fix() >= rInf.X(), "SwFlyPortion::Format" );
      53             :     // tabs must be expanded (Bug 8537)
      54         820 :     if( rInf.GetLastTab() )
      55           0 :         ((SwLinePortion*)rInf.GetLastTab())->FormatEOL( rInf );
      56             : 
      57         820 :     rInf.GetLast()->FormatEOL( rInf );
      58         820 :     PrtWidth( static_cast<sal_uInt16>(Fix() - rInf.X() + PrtWidth()) );
      59         820 :     if( !Width() )
      60             :     {
      61             :         OSL_ENSURE( Width(), "+SwFlyPortion::Format: a fly is a fly is a fly" );
      62           0 :         Width(1);
      63             :     }
      64             : 
      65             :     // resetting
      66         820 :     rInf.SetFly( 0 );
      67         820 :     rInf.Width( rInf.RealWidth() );
      68         820 :     rInf.GetParaPortion()->SetFly( true );
      69             : 
      70             :     // trailing blank:
      71        2280 :     if( rInf.GetIdx() < rInf.GetTxt().getLength() &&  1 < rInf.GetIdx()
      72         440 :         && !rInf.GetRest()
      73         440 :         && ' ' == rInf.GetChar( rInf.GetIdx() )
      74           0 :         && ' ' != rInf.GetChar( rInf.GetIdx() - 1 )
      75         820 :         && ( !rInf.GetLast() || !rInf.GetLast()->IsBreakPortion() ) )
      76             :     {
      77           0 :         SetBlankWidth( rInf.GetTxtSize(OUString(' ')).Width() );
      78           0 :         SetLen( 1 );
      79             :     }
      80             : 
      81         820 :     const sal_uInt16 nNewWidth = static_cast<sal_uInt16>(rInf.X() + PrtWidth());
      82         820 :     if( rInf.Width() <= nNewWidth )
      83             :     {
      84         236 :         Truncate();
      85         236 :         if( nNewWidth > rInf.Width() )
      86             :         {
      87           0 :             PrtWidth( nNewWidth - rInf.Width() );
      88           0 :             SetFixWidth( PrtWidth() );
      89             :         }
      90         236 :         return true;
      91             :     }
      92         584 :     return false;
      93             : }
      94             : 
      95        4112 : bool SwFlyCntPortion::Format( SwTxtFormatInfo &rInf )
      96             : {
      97        4112 :     bool bFull = rInf.Width() < rInf.X() + PrtWidth();
      98             : 
      99        4112 :     if( bFull )
     100             :     {
     101             :         // 3924: if the line is full, and the character-bound frame is at
     102             :         //       the beginning of a line
     103             :         // 5157: if it is not possible to side step into a Fly
     104             :         // "Begin of line" criteria ( ! rInf.X() ) has to be extended.
     105             :         // KerningPortions at beginning of line, e.g., for grid layout
     106             :         // must be considered.
     107         518 :         const SwLinePortion* pLastPor = rInf.GetLast();
     108         518 :         const sal_uInt16 nLeft = ( pLastPor &&
     109        1036 :                                     ( pLastPor->IsKernPortion() ||
     110         518 :                                       pLastPor->IsErgoSumPortion() ) ) ?
     111           0 :                                pLastPor->Width() :
     112         518 :                                0;
     113             : 
     114         518 :         if( nLeft == rInf.X() && ! rInf.GetFly() )
     115             :         {
     116         324 :             Width( rInf.Width() );
     117         324 :             bFull = false; // so that notes can still be placed in this line
     118             :         }
     119             :         else
     120             :         {
     121         194 :             if( !rInf.GetFly() )
     122         194 :                 rInf.SetNewLine( true );
     123         194 :             Width(0);
     124         194 :             SetAscent(0);
     125         194 :             SetLen(0);
     126         194 :             if( rInf.GetLast() )
     127         194 :                 rInf.GetLast()->FormatEOL( rInf );
     128             : 
     129         194 :             return bFull;
     130             :         }
     131             :     }
     132             : 
     133        3918 :     rInf.GetParaPortion()->SetFly( true );
     134        3918 :     return bFull;
     135             : }
     136             : 
     137             : //TODO: improve documentation
     138             : /** move character-bound objects inside the given area
     139             :  *
     140             :  * This allows moving those objects from Master to Follow, or vice versa.
     141             :  *
     142             :  * @param pNew
     143             :  * @param nStart
     144             :  * @param nEnd
     145             :  */
     146        3748 : void SwTxtFrm::MoveFlyInCnt( SwTxtFrm *pNew, sal_Int32 nStart, sal_Int32 nEnd )
     147             : {
     148        3748 :     SwSortedObjs *pObjs = 0L;
     149        3748 :     if ( 0 != (pObjs = GetDrawObjs()) )
     150             :     {
     151         320 :         for ( size_t i = 0; GetDrawObjs() && i < pObjs->size(); ++i )
     152             :         {
     153             :             // OD 2004-03-29 #i26791#
     154             :             // #i28701# - consider changed type of
     155             :             // <SwSortedList> entries
     156         194 :             SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     157         194 :             const SwFmtAnchor& rAnch = pAnchoredObj->GetFrmFmt().GetAnchor();
     158         194 :             if (rAnch.GetAnchorId() == FLY_AS_CHAR)
     159             :             {
     160         180 :                 const SwPosition* pPos = rAnch.GetCntntAnchor();
     161         180 :                 const sal_Int32 nIdx = pPos->nContent.GetIndex();
     162         180 :                 if ( nIdx >= nStart && nEnd > nIdx )
     163             :                 {
     164         126 :                     if ( pAnchoredObj->ISA(SwFlyFrm) )
     165             :                     {
     166          76 :                         RemoveFly( static_cast<SwFlyFrm*>(pAnchoredObj) );
     167          76 :                         pNew->AppendFly( static_cast<SwFlyFrm*>(pAnchoredObj) );
     168             :                     }
     169          50 :                     else if ( pAnchoredObj->ISA(SwAnchoredDrawObject) )
     170             :                     {
     171          50 :                         RemoveDrawObj( *pAnchoredObj );
     172          50 :                         pNew->AppendDrawObj( *pAnchoredObj );
     173             :                     }
     174         126 :                     --i;
     175             :                 }
     176             :             }
     177             :         }
     178             :     }
     179        3748 : }
     180             : 
     181         531 : sal_Int32 SwTxtFrm::CalcFlyPos( SwFrmFmt* pSearch )
     182             : {
     183         531 :     SwpHints* pHints = GetTxtNode()->GetpSwpHints();
     184             :     OSL_ENSURE( pHints, "CalcFlyPos: Why me?" );
     185         531 :     if( !pHints )
     186           0 :         return COMPLETE_STRING;
     187         531 :     SwTxtAttr* pFound = NULL;
     188        2228 :     for ( size_t i = 0; i < pHints->Count(); ++i )
     189             :     {
     190        1697 :         SwTxtAttr *pHt = pHints->GetTextHint( i );
     191        1697 :         if( RES_TXTATR_FLYCNT == pHt->Which() )
     192             :         {
     193         957 :             SwFrmFmt* pFrmFmt = pHt->GetFlyCnt().GetFrmFmt();
     194         957 :             if( pFrmFmt == pSearch )
     195         531 :                 pFound = pHt;
     196             :         }
     197             :     }
     198             :     OSL_ENSURE( pHints, "CalcFlyPos: Not Found!" );
     199         531 :     if( !pFound )
     200           0 :         return COMPLETE_STRING;
     201         531 :     return pFound->GetStart();
     202             : }
     203             : 
     204        4809 : void SwFlyCntPortion::Paint( const SwTxtPaintInfo &rInf ) const
     205             : {
     206        4809 :     if( bDraw )
     207             :     {
     208        4571 :         if( !((SwDrawContact*)pContact)->GetAnchorFrm() )
     209             :         {
     210             :             // OD 2004-04-01 #i26791# - no direct positioning of the drawing
     211             :             // object is needed.
     212           0 :             SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pContact);
     213           0 :             pDrawContact->ConnectToLayout();
     214             :         }
     215             :     }
     216             :     else
     217             :     {
     218             :         // baseline output
     219             :         // 7922: re-paint everything at a CompletePaint call
     220         238 :         SwRect aRepaintRect( rInf.GetPaintRect() );
     221             : 
     222         238 :         if ( rInf.GetTxtFrm()->IsRightToLeft() )
     223           0 :             rInf.GetTxtFrm()->SwitchLTRtoRTL( aRepaintRect );
     224             : 
     225         238 :         if ( rInf.GetTxtFrm()->IsVertical() )
     226           0 :             rInf.GetTxtFrm()->SwitchHorizontalToVertical( aRepaintRect );
     227             : 
     228         714 :         if( (GetFlyFrm()->IsCompletePaint() ||
     229         460 :              GetFlyFrm()->Frm().IsOver( aRepaintRect )) &&
     230         222 :              SwFlyFrm::IsPaint( (SdrObject*)GetFlyFrm()->GetVirtDrawObj(),
     231         444 :                                 GetFlyFrm()->getRootFrm()->GetCurrShell() ))
     232             :         {
     233         222 :             SwRect aRect( GetFlyFrm()->Frm() );
     234         222 :             if( !GetFlyFrm()->IsCompletePaint() )
     235         222 :                 aRect._Intersection( aRepaintRect );
     236             : 
     237             :             // GetFlyFrm() may change the layout mode at the output device.
     238             :             {
     239         222 :                 SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
     240         222 :                 GetFlyFrm()->Paint( aRect );
     241             :             }
     242             :             ((SwTxtPaintInfo&)rInf).GetRefDev()->SetLayoutMode(
     243         222 :                     rInf.GetOut()->GetLayoutMode() );
     244             : 
     245             :             // As the OutputDevice might be anything, the font must be re-selected.
     246             :             // Being in const method should not be a problem.
     247         222 :             ((SwTxtPaintInfo&)rInf).SelectFont();
     248             : 
     249             :             OSL_ENSURE( ! rInf.GetVsh() || rInf.GetVsh()->GetOut() == rInf.GetOut(),
     250             :                     "SwFlyCntPortion::Paint: Outdev has changed" );
     251         222 :             if( rInf.GetVsh() )
     252         222 :                 ((SwTxtPaintInfo&)rInf).SetOut( rInf.GetVsh()->GetOut() );
     253             :         }
     254             :     }
     255        4809 : }
     256             : 
     257             : // use the dimensions of pFly->OutRect()
     258             : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
     259        2530 : SwFlyCntPortion::SwFlyCntPortion( const SwTxtFrm& rFrm,
     260             :                                   SwFlyInCntFrm *pFly, const Point &rBase,
     261             :                                   long nLnAscent, long nLnDescent,
     262             :                                   long nFlyAsc, long nFlyDesc,
     263             :                                   objectpositioning::AsCharFlags nFlags ) :
     264             :     pContact( pFly ),
     265             :     bDraw( false ),
     266             :     bMax( false ),
     267        2530 :     nAlign( 0 )
     268             : {
     269             :     OSL_ENSURE( pFly, "SwFlyCntPortion::SwFlyCntPortion: no SwFlyInCntFrm!" );
     270        2530 :     nLineLength = 1;
     271        2530 :     nFlags |= AS_CHAR_ULSPACE | AS_CHAR_INIT;
     272        2530 :     SetBase( rFrm, rBase, nLnAscent, nLnDescent, nFlyAsc, nFlyDesc, nFlags );
     273        2530 :     SetWhichPor( POR_FLYCNT );
     274        2530 : }
     275             : 
     276             : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
     277        1582 : SwFlyCntPortion::SwFlyCntPortion( const SwTxtFrm& rFrm,
     278             :                                   SwDrawContact *pDrawContact, const Point &rBase,
     279             :                                   long nLnAscent, long nLnDescent,
     280             :                                   long nFlyAsc, long nFlyDesc,
     281             :                                   objectpositioning::AsCharFlags nFlags ) :
     282             :     pContact( pDrawContact ),
     283             :     bDraw( true ),
     284             :     bMax( false ),
     285        1582 :     nAlign( 0 )
     286             : {
     287             :     OSL_ENSURE( pDrawContact, "SwFlyCntPortion::SwFlyCntPortion: no SwDrawContact!" );
     288        1582 :     if( !pDrawContact->GetAnchorFrm() )
     289             :     {
     290             :         // OD 2004-04-01 #i26791# - no direct positioning needed any more
     291         168 :         pDrawContact->ConnectToLayout();
     292             :         // #i40333# - follow-up of #i35635#
     293             :         // move object to visible layer
     294         168 :         pDrawContact->MoveObjToVisibleLayer( pDrawContact->GetMaster() );
     295             :     }
     296        1582 :     nLineLength = 1;
     297        1582 :     nFlags |= AS_CHAR_ULSPACE | AS_CHAR_INIT;
     298             : 
     299        1582 :     SetBase( rFrm, rBase, nLnAscent, nLnDescent, nFlyAsc, nFlyDesc, nFlags );
     300             : 
     301        1582 :     SetWhichPor( POR_FLYCNT );
     302        1582 : }
     303             : 
     304             : // after setting the RefPoints, the ascent needs to be recalculated because it is dependent on RelPos.
     305             : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
     306             : /// @param rBase CAUTION:needs to be an absolute value
     307       13361 : void SwFlyCntPortion::SetBase( const SwTxtFrm& rFrm, const Point &rBase,
     308             :                                long nLnAscent, long nLnDescent,
     309             :                                long nFlyAsc, long nFlyDesc,
     310             :                                objectpositioning::AsCharFlags nFlags )
     311             : {
     312             :     // OD 28.10.2003 #113049# - use new class to position object
     313             :     // determine drawing object
     314       13361 :     SdrObject* pSdrObj = 0L;
     315       13361 :     if( bDraw )
     316             :     {
     317             :         // OD 20.06.2003 #108784# - determine drawing object ('master' or 'virtual')
     318             :         // by frame.
     319        4660 :         pSdrObj = GetDrawContact()->GetDrawObjectByAnchorFrm( rFrm );
     320        4660 :         if ( !pSdrObj )
     321             :         {
     322             :             OSL_FAIL( "SwFlyCntPortion::SetBase(..) - No drawing object found by <GetDrawContact()->GetDrawObjectByAnchorFrm( rFrm )>" );
     323           0 :             pSdrObj = GetDrawContact()->GetMaster();
     324             :         }
     325             :         // #i65798#
     326             :         // call <SwAnchoredDrawObject::MakeObjPos()> to assure that flag at
     327             :         // the <DrawFrmFmt> and at the <SwAnchoredDrawObject> instance are
     328             :         // correctly set.
     329        4660 :         if ( pSdrObj )
     330             :         {
     331        4660 :             GetDrawContact()->GetAnchoredObj( pSdrObj )->MakeObjPos();
     332             :         }
     333             :     }
     334             :     else
     335             :     {
     336        8701 :         pSdrObj = GetFlyFrm()->GetVirtDrawObj();
     337             :     }
     338             : 
     339       13361 :     if (!pSdrObj)
     340       13361 :         return;
     341             : 
     342             :     // position object
     343             :     objectpositioning::SwAsCharAnchoredObjectPosition aObjPositioning(
     344             :                                     *pSdrObj,
     345             :                                     rBase, nFlags,
     346       13361 :                                     nLnAscent, nLnDescent, nFlyAsc, nFlyDesc );
     347             : 
     348             :     // OD 2004-04-13 #i26791# - scope of local variable <aObjPosInProgress>
     349             :     {
     350             :         // OD 2004-04-13 #i26791#
     351       13361 :         SwObjPositioningInProgress aObjPosInProgress( *pSdrObj );
     352       13361 :         aObjPositioning.CalcPosition();
     353             :     }
     354             : 
     355       13361 :     SwFrmFmt* pShape = FindFrmFmt(pSdrObj);
     356       13361 :     const SwFmtAnchor& rAnchor(pShape->GetAnchor());
     357       13361 :     if (rAnchor.GetAnchorId() == FLY_AS_CHAR)
     358             :     {
     359             :         // This is an inline draw shape, see if it has a textbox.
     360       13361 :         SwFrmFmt* pTextBox = SwTextBoxHelper::findTextBox(pShape);
     361       13361 :         if (pTextBox)
     362             :         {
     363             :             // It has, so look up its text rectangle, and adjust the position
     364             :             // of the textbox accordingly.
     365          72 :             Rectangle aTextRectangle = SwTextBoxHelper::getTextRectangle(pShape);
     366             : 
     367          72 :             SwFmtHoriOrient aHori(pTextBox->GetHoriOrient());
     368          72 :             aHori.SetHoriOrient(css::text::HoriOrientation::NONE);
     369          72 :             sal_Int32 nLeft = aTextRectangle.getX() - rFrm.Frm().Left();
     370          72 :             aHori.SetPos(nLeft);
     371             : 
     372         144 :             SwFmtVertOrient aVert(pTextBox->GetVertOrient());
     373          72 :             aVert.SetVertOrient(css::text::VertOrientation::NONE);
     374          72 :             sal_Int32 nTop = aTextRectangle.getY() - rFrm.Frm().Top() - nFlyAsc;
     375          72 :             aVert.SetPos(nTop);
     376             : 
     377          72 :             pTextBox->LockModify();
     378          72 :             pTextBox->SetFmtAttr(aHori);
     379          72 :             pTextBox->SetFmtAttr(aVert);
     380         144 :             pTextBox->UnlockModify();
     381             :         }
     382             :     }
     383             : 
     384       13361 :     SetAlign( aObjPositioning.GetLineAlignment() );
     385             : 
     386       13361 :     aRef = aObjPositioning.GetAnchorPos();
     387       13361 :     if( nFlags & AS_CHAR_ROTATE )
     388           0 :         SvXSize( aObjPositioning.GetObjBoundRectInclSpacing().SSize() );
     389             :     else
     390       13361 :         SvLSize( aObjPositioning.GetObjBoundRectInclSpacing().SSize() );
     391       13361 :     if( Height() )
     392             :     {
     393             :         // GetRelPosY returns the relative position to baseline (if 0, the
     394             :         // upper border of the FlyCnt if on the baseline of a line)
     395       13361 :         SwTwips nRelPos = aObjPositioning.GetRelPosY();
     396       13361 :         if ( nRelPos < 0 )
     397             :         {
     398        8553 :             nAscent = static_cast<sal_uInt16>(-nRelPos);
     399        8553 :             if( nAscent > Height() )
     400         112 :                 Height( nAscent );
     401             :         }
     402             :         else
     403             :         {
     404        4808 :             nAscent = 0;
     405        4808 :             Height( Height() + static_cast<sal_uInt16>(nRelPos) );
     406             :         }
     407             :     }
     408             :     else
     409             :     {
     410           0 :         Height( 1 );
     411           0 :         nAscent = 0;
     412       13361 :     }
     413             : }
     414             : 
     415           0 : sal_Int32 SwFlyCntPortion::GetFlyCrsrOfst( const sal_uInt16 nOfst,
     416             :     const Point &rPoint, SwPosition *pPos, SwCrsrMoveState* pCMS ) const
     417             : {
     418             :     // Da die FlyCnt nicht an der Seite haengen, wird ihr
     419             :     // GetCrsrOfst() nicht gerufen. Um die Layoutseite
     420             :     // von unnoetiger Verwaltung zu entlasten, ruft der Absatz
     421             :     // das GetCrsrOfst des FlyFrm, wenn es erforderlich ist.
     422           0 :     Point aPoint( rPoint );
     423           0 :     if( !pPos || bDraw || !( GetFlyFrm()->GetCrsrOfst( pPos, aPoint, pCMS ) ) )
     424           0 :         return SwLinePortion::GetCrsrOfst( nOfst );
     425             :     else
     426           0 :         return 0;
     427             : }
     428             : 
     429          58 : sal_Int32 SwFlyCntPortion::GetCrsrOfst( const sal_uInt16 nOfst ) const
     430             : {
     431             :     // OSL_FAIL("SwFlyCntPortion::GetCrsrOfst: use GetFlyCrsrOfst()");
     432          58 :     return SwLinePortion::GetCrsrOfst( nOfst );
     433         270 : }
     434             : 
     435             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10