LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/text - porfly.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 98 157 62.4 %
Date: 2012-12-27 Functions: 7 11 63.6 %
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" // SwDrawContact
      21             : #include "dflyobj.hxx"  // SwVirtFlyDrawObj
      22             : #include "pam.hxx"      // SwPosition
      23             : #include "flyfrm.hxx"   // SwFlyInCntFrm
      24             : #include "rootfrm.hxx"
      25             : #include "frmfmt.hxx"   // SwFrmFmt
      26             : #include "viewsh.hxx"
      27             : 
      28             : #include <vcl/outdev.hxx>
      29             : #include <editeng/lrspitem.hxx>
      30             : #include <editeng/ulspitem.hxx>
      31             : #include <fmtanchr.hxx>
      32             : #include <fmtflcnt.hxx>
      33             : #include <fmtornt.hxx>
      34             : #include <frmatr.hxx>
      35             : #include "flyfrms.hxx"
      36             : #include "txatbase.hxx" // SwTxtAttr
      37             : #include "porfly.hxx"
      38             : #include "porlay.hxx"   // SetFly
      39             : #include "inftxt.hxx"   // SwTxtPaintInfo
      40             : 
      41             : // OD 2004-05-24 #i28701#
      42             : #include <sortedobjs.hxx>
      43             : 
      44             : 
      45             : /*************************************************************************
      46             :  *                class SwFlyPortion
      47             :  *
      48             :  * Wir erwarten ein framelokales SwRect !
      49             :  *************************************************************************/
      50             : 
      51           4 : void SwFlyPortion::Paint( const SwTxtPaintInfo& ) const
      52             : {
      53           4 : }
      54             : 
      55             : /*************************************************************************
      56             :  *                 virtual SwFlyPortion::Format()
      57             :  *************************************************************************/
      58           8 : sal_Bool SwFlyPortion::Format( SwTxtFormatInfo &rInf )
      59             : {
      60             :     OSL_ENSURE( Fix() >= rInf.X(), "SwFlyPortion::Format: rush hour" );
      61             :     // 8537: Tabs muessen expandiert werden.
      62           8 :     if( rInf.GetLastTab() )
      63           0 :         ((SwLinePortion*)rInf.GetLastTab())->FormatEOL( rInf );
      64             : 
      65             :     // Der Glue wird aufgespannt.
      66           8 :     rInf.GetLast()->FormatEOL( rInf );
      67           8 :     PrtWidth( static_cast<sal_uInt16>(Fix() - rInf.X() + PrtWidth()) );
      68           8 :     if( !Width() )
      69             :     {
      70             :         OSL_ENSURE( Width(), "+SwFlyPortion::Format: a fly is a fly is a fly" );
      71           0 :         Width(1);
      72             :     }
      73             : 
      74             :     // Restaurierung
      75           8 :     rInf.SetFly( 0 );
      76           8 :     rInf.Width( rInf.RealWidth() );
      77           8 :     rInf.GetParaPortion()->SetFly( sal_True );
      78             : 
      79             :     // trailing blank:
      80           8 :     if( rInf.GetIdx() < rInf.GetTxt().Len() &&  1 < rInf.GetIdx()
      81           0 :         && !rInf.GetRest()
      82           0 :         && ' ' == rInf.GetChar( rInf.GetIdx() )
      83           0 :         && ' ' != rInf.GetChar( rInf.GetIdx() - 1 )
      84           0 :         && ( !rInf.GetLast() || !rInf.GetLast()->IsBreakPortion() ) )
      85             :     {
      86           0 :         SetBlankWidth( rInf.GetTxtSize(OUString(' ')).Width() );
      87           0 :         SetLen( 1 );
      88             :     }
      89             : 
      90           8 :     const sal_uInt16 nNewWidth = static_cast<sal_uInt16>(rInf.X() + PrtWidth());
      91           8 :     if( rInf.Width() <= nNewWidth )
      92             :     {
      93           2 :         Truncate();
      94           2 :         if( nNewWidth > rInf.Width() )
      95             :         {
      96           0 :             PrtWidth( nNewWidth - rInf.Width() );
      97           0 :             SetFixWidth( PrtWidth() );
      98             :         }
      99           2 :         return sal_True;
     100             :     }
     101           6 :     return sal_False;
     102             : }
     103             : 
     104             : /*************************************************************************
     105             :  *                 virtual SwFlyCntPortion::Format()
     106             :  *************************************************************************/
     107         165 : sal_Bool SwFlyCntPortion::Format( SwTxtFormatInfo &rInf )
     108             : {
     109         165 :     sal_Bool bFull = rInf.Width() < rInf.X() + PrtWidth();
     110             : 
     111         165 :     if( bFull )
     112             :     {
     113             :         // 3924: wenn die Zeile voll ist und der zeichengebundene Frame am
     114             :         // Anfang der Zeile steht.
     115             :         // 5157: nicht wenn einem Fly ausgewichen werden kann!
     116             :         // "Begin of line" criteria ( ! rInf.X() ) has to be extended.
     117             :         // KerningPortions at beginning of line, e.g., for grid layout
     118             :         // must be considered.
     119           2 :         const SwLinePortion* pLastPor = rInf.GetLast();
     120             :         const sal_uInt16 nLeft = ( pLastPor &&
     121           2 :                                     ( pLastPor->IsKernPortion() ||
     122           2 :                                       pLastPor->IsErgoSumPortion() ) ) ?
     123           0 :                                pLastPor->Width() :
     124           6 :                                0;
     125             : 
     126           2 :         if( nLeft == rInf.X() && ! rInf.GetFly() )
     127             :         {
     128           1 :             Width( rInf.Width() );
     129           1 :             bFull = sal_False; // Damit Notizen noch in dieser Zeile landen
     130             :         }
     131             :         else
     132             :         {
     133           1 :             if( !rInf.GetFly() )
     134           1 :                 rInf.SetNewLine( sal_True );
     135           1 :             Width(0);
     136           1 :             SetAscent(0);
     137           1 :             SetLen(0);
     138           1 :             if( rInf.GetLast() )
     139           1 :                 rInf.GetLast()->FormatEOL( rInf );
     140             : 
     141           1 :             return bFull;
     142             :         }
     143             :     }
     144             : 
     145         164 :     rInf.GetParaPortion()->SetFly( sal_True );
     146         164 :     return bFull;
     147             : }
     148             : 
     149             : /*************************************************************************
     150             :  *  SwTxtFrm::MoveFlyInCnt() haengt jetzt die zeichengebundenen Objekte
     151             :  *  innerhalb des angegebenen Bereichs um, damit koennen diese vom Master
     152             :  *  zum Follow oder umgekehrt wandern.
     153             :  *************************************************************************/
     154           0 : void SwTxtFrm::MoveFlyInCnt( SwTxtFrm *pNew, xub_StrLen nStart, xub_StrLen nEnd )
     155             : {
     156           0 :     SwSortedObjs *pObjs = 0L;
     157           0 :     if ( 0 != (pObjs = GetDrawObjs()) )
     158             :     {
     159           0 :         for ( sal_uInt32 i = 0; GetDrawObjs() && i < pObjs->Count(); ++i )
     160             :         {
     161             :             // OD 2004-03-29 #i26791#
     162             :             // #i28701# - consider changed type of
     163             :             // <SwSortedList> entries
     164           0 :             SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     165           0 :             const SwFmtAnchor& rAnch = pAnchoredObj->GetFrmFmt().GetAnchor();
     166           0 :             if (rAnch.GetAnchorId() == FLY_AS_CHAR)
     167             :             {
     168           0 :                 const SwPosition* pPos = rAnch.GetCntntAnchor();
     169           0 :                 xub_StrLen nIdx = pPos->nContent.GetIndex();
     170           0 :                 if ( nIdx >= nStart && nEnd > nIdx )
     171             :                 {
     172           0 :                     if ( pAnchoredObj->ISA(SwFlyFrm) )
     173             :                     {
     174           0 :                         RemoveFly( static_cast<SwFlyFrm*>(pAnchoredObj) );
     175           0 :                         pNew->AppendFly( static_cast<SwFlyFrm*>(pAnchoredObj) );
     176             :                     }
     177           0 :                     else if ( pAnchoredObj->ISA(SwAnchoredDrawObject) )
     178             :                     {
     179           0 :                         RemoveDrawObj( *pAnchoredObj );
     180           0 :                         pNew->AppendDrawObj( *pAnchoredObj );
     181             :                     }
     182           0 :                     --i;
     183             :                 }
     184             :             }
     185             :         }
     186             :     }
     187           0 : }
     188             : 
     189             : /*************************************************************************
     190             :  *                SwTxtFrm::CalcFlyPos()
     191             :  *************************************************************************/
     192           0 : xub_StrLen SwTxtFrm::CalcFlyPos( SwFrmFmt* pSearch )
     193             : {
     194           0 :     SwpHints* pHints = GetTxtNode()->GetpSwpHints();
     195             :     OSL_ENSURE( pHints, "CalcFlyPos: Why me?" );
     196           0 :     if( !pHints )
     197           0 :         return STRING_LEN;
     198           0 :     SwTxtAttr* pFound = NULL;
     199           0 :     for ( sal_uInt16 i = 0; i < pHints->Count(); i++)
     200             :     {
     201           0 :         SwTxtAttr *pHt = pHints->GetTextHint( i );
     202           0 :         if( RES_TXTATR_FLYCNT == pHt->Which() )
     203             :         {
     204           0 :             SwFrmFmt* pFrmFmt = pHt->GetFlyCnt().GetFrmFmt();
     205           0 :             if( pFrmFmt == pSearch )
     206           0 :                 pFound = pHt;
     207             :         }
     208             :     }
     209             :     OSL_ENSURE( pHints, "CalcFlyPos: Not Found!" );
     210           0 :     if( !pFound )
     211           0 :         return STRING_LEN;
     212           0 :     return *pFound->GetStart();
     213             : }
     214             : 
     215             : /*************************************************************************
     216             :  *                 virtual SwFlyCntPortion::Paint()
     217             :  *************************************************************************/
     218         162 : void SwFlyCntPortion::Paint( const SwTxtPaintInfo &rInf ) const
     219             : {
     220         162 :     if( bDraw )
     221             :     {
     222          10 :         if( !((SwDrawContact*)pContact)->GetAnchorFrm() )
     223             :         {
     224             :             // OD 2004-04-01 #i26791# - no direct positioning of the drawing
     225             :             // object is needed.
     226           0 :             SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pContact);
     227           0 :             pDrawContact->ConnectToLayout();
     228             :         }
     229             :     }
     230             :     else
     231             :     {
     232             :         // Baseline-Ausgabe !
     233             :         // 7922: Bei CompletePaint alles painten
     234         152 :         SwRect aRepaintRect( rInf.GetPaintRect() );
     235             : 
     236         152 :         if ( rInf.GetTxtFrm()->IsRightToLeft() )
     237           0 :             rInf.GetTxtFrm()->SwitchLTRtoRTL( aRepaintRect );
     238             : 
     239         152 :         if ( rInf.GetTxtFrm()->IsVertical() )
     240           0 :             rInf.GetTxtFrm()->SwitchHorizontalToVertical( aRepaintRect );
     241             : 
     242         454 :         if( (GetFlyFrm()->IsCompletePaint() ||
     243         152 :              GetFlyFrm()->Frm().IsOver( aRepaintRect )) &&
     244         150 :              SwFlyFrm::IsPaint( (SdrObject*)GetFlyFrm()->GetVirtDrawObj(),
     245         300 :                                 GetFlyFrm()->getRootFrm()->GetCurrShell() ))
     246             :         {
     247         150 :             SwRect aRect( GetFlyFrm()->Frm() );
     248         150 :             if( !GetFlyFrm()->IsCompletePaint() )
     249         150 :                 aRect._Intersection( aRepaintRect );
     250             : 
     251             : 
     252             :             // GetFlyFrm() may change the layout mode at the output device.
     253             :             {
     254         150 :                 SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
     255         150 :                 GetFlyFrm()->Paint( aRect );
     256             :             }
     257             :             ((SwTxtPaintInfo&)rInf).GetRefDev()->SetLayoutMode(
     258         150 :                     rInf.GetOut()->GetLayoutMode() );
     259             : 
     260             :             // Es hilft alles nichts, im zeichengebundenen Frame kann wer weiss
     261             :             // was am OutputDevice eingestellt sein, wir muessen unseren Font
     262             :             // wieder hineinselektieren. Dass wir im const stehen, soll uns
     263             :             // daran nicht hindern:
     264         150 :             ((SwTxtPaintInfo&)rInf).SelectFont();
     265             : 
     266             :             // I want to know if this can really happen. So here comes a new
     267             :             OSL_ENSURE( ! rInf.GetVsh() || rInf.GetVsh()->GetOut() == rInf.GetOut(),
     268             :                     "SwFlyCntPortion::Paint: Outdev has changed" );
     269         150 :             if( rInf.GetVsh() )
     270         150 :                 ((SwTxtPaintInfo&)rInf).SetOut( rInf.GetVsh()->GetOut() );
     271             :         }
     272             :     }
     273         162 : }
     274             : 
     275             : /*************************************************************************
     276             :  *                  SwFlyCntPortion::SwFlyCntPortion()
     277             :  *
     278             :  * Es werden die Masze vom pFly->OutRect() eingestellt.
     279             :  * Es erfolgt ein SetBase() !
     280             :  *************************************************************************/
     281             : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
     282         157 : SwFlyCntPortion::SwFlyCntPortion( const SwTxtFrm& rFrm,
     283             :                                   SwFlyInCntFrm *pFly, const Point &rBase,
     284             :                                   long nLnAscent, long nLnDescent,
     285             :                                   long nFlyAsc, long nFlyDesc,
     286             :                                   objectpositioning::AsCharFlags nFlags ) :
     287             :     pContact( pFly ),
     288             :     bDraw( sal_False ),
     289             :     bMax( sal_False ),
     290         157 :     nAlign( 0 )
     291             : {
     292             :     OSL_ENSURE( pFly, "SwFlyCntPortion::SwFlyCntPortion: no SwFlyInCntFrm!" );
     293         157 :     nLineLength = 1;
     294         157 :     nFlags |= AS_CHAR_ULSPACE | AS_CHAR_INIT;
     295         157 :     SetBase( rFrm, rBase, nLnAscent, nLnDescent, nFlyAsc, nFlyDesc, nFlags );
     296         157 :     SetWhichPor( POR_FLYCNT );
     297         157 : }
     298             : 
     299             : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
     300           8 : SwFlyCntPortion::SwFlyCntPortion( const SwTxtFrm& rFrm,
     301             :                                   SwDrawContact *pDrawContact, const Point &rBase,
     302             :                                   long nLnAscent, long nLnDescent,
     303             :                                   long nFlyAsc, long nFlyDesc,
     304             :                                   objectpositioning::AsCharFlags nFlags ) :
     305             :     pContact( pDrawContact ),
     306             :     bDraw( sal_True ),
     307             :     bMax( sal_False ),
     308           8 :     nAlign( 0 )
     309             : {
     310             :     OSL_ENSURE( pDrawContact, "SwFlyCntPortion::SwFlyCntPortion: no SwDrawContact!" );
     311           8 :     if( !pDrawContact->GetAnchorFrm() )
     312             :     {
     313             :         // OD 2004-04-01 #i26791# - no direct positioning needed any more
     314           4 :         pDrawContact->ConnectToLayout();
     315             :         // #i40333# - follow-up of #i35635#
     316             :         // move object to visible layer
     317           4 :         pDrawContact->MoveObjToVisibleLayer( pDrawContact->GetMaster() );
     318             :     }
     319           8 :     nLineLength = 1;
     320           8 :     nFlags |= AS_CHAR_ULSPACE | AS_CHAR_INIT;
     321             : 
     322           8 :     SetBase( rFrm, rBase, nLnAscent, nLnDescent, nFlyAsc, nFlyDesc, nFlags );
     323             : 
     324           8 :     SetWhichPor( POR_FLYCNT );
     325           8 : }
     326             : 
     327             : 
     328             : /*************************************************************************
     329             :  *                  SwFlyCntPortion::SetBase()
     330             :  *
     331             :  * Nach dem Setzen des RefPoints muss der Ascent neu berechnet werden,
     332             :  * da er von der RelPos abhaengt.
     333             :  * pFly->GetRelPos().Y() bezeichnet die relative Position zur Baseline.
     334             :  * Bei 0 liegt der obere Rand des FlyCnt auf der Baseline der Zeile.
     335             :  *************************************************************************/
     336             : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
     337         605 : void SwFlyCntPortion::SetBase( const SwTxtFrm& rFrm, const Point &rBase,
     338             :                                long nLnAscent, long nLnDescent,
     339             :                                long nFlyAsc, long nFlyDesc,
     340             :                                objectpositioning::AsCharFlags nFlags )
     341             : {
     342             :     // Note: rBase have to be an absolute value
     343             : 
     344             :     // OD 28.10.2003 #113049# - use new class to position object
     345             :     // determine drawing object
     346         605 :     SdrObject* pSdrObj = 0L;
     347         605 :     if( bDraw )
     348             :     {
     349             :         // OD 20.06.2003 #108784# - determine drawing object ('master' or 'virtual')
     350             :         // by frame.
     351          25 :         pSdrObj = GetDrawContact()->GetDrawObjectByAnchorFrm( rFrm );
     352          25 :         if ( !pSdrObj )
     353             :         {
     354             :             OSL_FAIL( "SwFlyCntPortion::SetBase(..) - No drawing object found by <GetDrawContact()->GetDrawObjectByAnchorFrm( rFrm )>" );
     355           0 :             pSdrObj = GetDrawContact()->GetMaster();
     356             :         }
     357             :         // #i65798#
     358             :         // call <SwAnchoredDrawObject::MakeObjPos()> to assure that flag at
     359             :         // the <DrawFrmFmt> and at the <SwAnchoredDrawObject> instance are
     360             :         // correctly set.
     361          25 :         if ( pSdrObj )
     362             :         {
     363          25 :             GetDrawContact()->GetAnchoredObj( pSdrObj )->MakeObjPos();
     364             :         }
     365             :     }
     366             :     else
     367             :     {
     368         580 :         pSdrObj = GetFlyFrm()->GetVirtDrawObj();
     369             :     }
     370             : 
     371             :     // position object
     372             :     objectpositioning::SwAsCharAnchoredObjectPosition aObjPositioning(
     373             :                                     *pSdrObj,
     374             :                                     rBase, nFlags,
     375         605 :                                     nLnAscent, nLnDescent, nFlyAsc, nFlyDesc );
     376             : 
     377             :     // OD 2004-04-13 #i26791# - scope of local variable <aObjPosInProgress>
     378             :     {
     379             :         // OD 2004-04-13 #i26791#
     380         605 :         SwObjPositioningInProgress aObjPosInProgress( *pSdrObj );
     381         605 :         aObjPositioning.CalcPosition();
     382             :     }
     383             : 
     384         605 :     SetAlign( aObjPositioning.GetLineAlignment() );
     385             : 
     386         605 :     aRef = aObjPositioning.GetAnchorPos();
     387         605 :     if( nFlags & AS_CHAR_ROTATE )
     388           0 :         SvXSize( aObjPositioning.GetObjBoundRectInclSpacing().SSize() );
     389             :     else
     390         605 :         SvLSize( aObjPositioning.GetObjBoundRectInclSpacing().SSize() );
     391         605 :     if( Height() )
     392             :     {
     393         605 :         SwTwips nRelPos = aObjPositioning.GetRelPosY();
     394         605 :         if ( nRelPos < 0 )
     395             :         {
     396         592 :             nAscent = static_cast<sal_uInt16>(-nRelPos);
     397         592 :             if( nAscent > Height() )
     398           0 :                 Height( nAscent );
     399             :         }
     400             :         else
     401             :         {
     402          13 :             nAscent = 0;
     403          13 :             Height( Height() + static_cast<sal_uInt16>(nRelPos) );
     404             :         }
     405             :     }
     406             :     else
     407             :     {
     408           0 :         Height( 1 );
     409           0 :         nAscent = 0;
     410         605 :     }
     411         605 : }
     412             : 
     413             : /*************************************************************************
     414             :  *              virtual SwFlyCntPortion::GetFlyCrsrOfst()
     415             :  *************************************************************************/
     416             : 
     417           0 : xub_StrLen SwFlyCntPortion::GetFlyCrsrOfst( const KSHORT nOfst,
     418             :     const Point &rPoint, SwPosition *pPos, SwCrsrMoveState* pCMS ) const
     419             : {
     420             :     // Da die FlyCnt nicht an der Seite haengen, wird ihr
     421             :     // GetCrsrOfst() nicht gerufen. Um die Layoutseite
     422             :     // von unnoetiger Verwaltung zu entlasten, ruft der Absatz
     423             :     // das GetCrsrOfst des FlyFrm, wenn es erforderlich ist.
     424           0 :     Point aPoint( rPoint );
     425           0 :     if( !pPos || bDraw || !( GetFlyFrm()->GetCrsrOfst( pPos, aPoint, pCMS ) ) )
     426           0 :         return SwLinePortion::GetCrsrOfst( nOfst );
     427             :     else
     428           0 :         return 0;
     429             : }
     430             : 
     431             : /*************************************************************************
     432             :  *              virtual SwFlyCntPortion::GetCrsrOfst()
     433             :  *************************************************************************/
     434             : 
     435           0 : xub_StrLen SwFlyCntPortion::GetCrsrOfst( const KSHORT nOfst ) const
     436             : {
     437             :     // OSL_ENSURE( !this, "SwFlyCntPortion::GetCrsrOfst: use GetFlyCrsrOfst()" );
     438           0 :     return SwLinePortion::GetCrsrOfst( nOfst );
     439             : }
     440             : 
     441             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10