LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/text - porexp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 45 116 38.8 %
Date: 2012-12-27 Functions: 10 18 55.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 <viewopt.hxx>  // SwViewOptions
      21             : #include <SwPortionHandler.hxx>
      22             : #include <inftxt.hxx>
      23             : #include <porexp.hxx>
      24             : 
      25             : /*************************************************************************
      26             :  *                      class SwExpandPortion
      27             :  *************************************************************************/
      28             : 
      29           0 : xub_StrLen SwExpandPortion::GetCrsrOfst( const MSHORT nOfst ) const
      30           0 : { return SwLinePortion::GetCrsrOfst( nOfst ); }
      31             : 
      32             : /*************************************************************************
      33             :  *              virtual SwExpandPortion::GetExpTxt()
      34             :  *************************************************************************/
      35             : 
      36           0 : sal_Bool SwExpandPortion::GetExpTxt( const SwTxtSizeInfo&,
      37             :                                  XubString &rTxt ) const
      38             : {
      39           0 :     rTxt.Erase();
      40             :     // Nicht etwa: return 0 != rTxt.Len();
      41             :     // Weil: leere Felder ersetzen CH_TXTATR gegen einen Leerstring
      42           0 :     return sal_True;
      43             : }
      44             : 
      45             : /*************************************************************************
      46             :  *              virtual SwExpandPortion::HandlePortion()
      47             :  *************************************************************************/
      48             : 
      49           0 : void SwExpandPortion::HandlePortion( SwPortionHandler& rPH ) const
      50             : {
      51           0 :     String aString;
      52           0 :     rPH.Special( GetLen(), aString, GetWhichPor() );
      53           0 : }
      54             : 
      55             : /*************************************************************************
      56             :  *              virtual SwExpandPortion::GetTxtSize()
      57             :  *************************************************************************/
      58             : 
      59           0 : SwPosSize SwExpandPortion::GetTxtSize( const SwTxtSizeInfo &rInf ) const
      60             : {
      61           0 :     SwTxtSlot aDiffTxt( &rInf, this, false, false );
      62           0 :     return rInf.GetTxtSize();
      63             : }
      64             : 
      65             : /*************************************************************************
      66             :  *                 virtual SwExpandPortion::Format()
      67             :  *************************************************************************/
      68             : 
      69             : // 5010: Exp und Tabs
      70             : 
      71           8 : sal_Bool SwExpandPortion::Format( SwTxtFormatInfo &rInf )
      72             : {
      73           8 :     SwTxtSlot aDiffTxt( &rInf, this, true, false );
      74           8 :     const xub_StrLen nFullLen = rInf.GetLen();
      75             : 
      76             :     // So komisch es aussieht, die Abfrage auf GetLen() muss wegen der
      77             :     // ExpandPortions _hinter_ aDiffTxt (vgl. SoftHyphs)
      78             :     // sal_False returnen wegen SetFull ...
      79           8 :     if( !nFullLen )
      80             :     {
      81             :         // nicht Init(), weil wir Hoehe und Ascent brauchen
      82           0 :         Width(0);
      83           0 :         return sal_False;
      84             :     }
      85           8 :     return SwTxtPortion::Format( rInf );
      86             : }
      87             : 
      88             : /*************************************************************************
      89             :  *              virtual SwExpandPortion::Paint()
      90             :  *************************************************************************/
      91             : 
      92          56 : void SwExpandPortion::Paint( const SwTxtPaintInfo &rInf ) const
      93             : {
      94          56 :     SwTxtSlot aDiffTxt( &rInf, this, true, true );
      95             : 
      96          56 :     rInf.DrawBackBrush( *this );
      97             : 
      98             :     // do we have to repaint a post it portion?
      99          56 :     if( rInf.OnWin() && pPortion && !pPortion->Width() )
     100           2 :         pPortion->PrePaint( rInf, this );
     101             : 
     102             :     // The contents of field portions is not considered during the
     103             :     // calculation of the directions. Therefore we let vcl handle
     104             :     // the calculation by removing the BIDI_STRONG_FLAG temporarily.
     105          56 :     SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
     106          56 :     aLayoutModeModifier.SetAuto();
     107             : 
     108             :     // ST2
     109          56 :     if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
     110           0 :         rInf.DrawMarkedText( *this, rInf.GetLen(), sal_False, sal_False,
     111           0 :             0 != rInf.GetSmartTags(), 0 != rInf.GetGrammarCheckList() );
     112             :     else
     113          56 :         rInf.DrawText( *this, rInf.GetLen(), sal_False );
     114          56 : }
     115             : 
     116             : /*************************************************************************
     117             :  *                      class SwBlankPortion
     118             :  *************************************************************************/
     119             : 
     120           8 : SwLinePortion *SwBlankPortion::Compress() { return this; }
     121             : 
     122             : /*************************************************************************
     123             :  *                 SwBlankPortion::MayUnderFlow()
     124             :  *************************************************************************/
     125             : 
     126             : // 5497: Es gibt schon Gemeinheiten auf der Welt...
     127             : // Wenn eine Zeile voll mit HardBlanks ist und diese ueberlaeuft,
     128             : // dann duerfen keine Underflows generiert werden!
     129             : // Komplikationen bei Flys...
     130             : 
     131           0 : MSHORT SwBlankPortion::MayUnderFlow( const SwTxtFormatInfo &rInf,
     132             :     xub_StrLen nIdx, sal_Bool bUnderFlow ) const
     133             : {
     134           0 :     if( rInf.StopUnderFlow() )
     135           0 :         return 0;
     136           0 :     const SwLinePortion *pPos = rInf.GetRoot();
     137           0 :     if( pPos->GetPortion() )
     138           0 :         pPos = pPos->GetPortion();
     139           0 :     while( pPos && pPos->IsBlankPortion() )
     140           0 :         pPos = pPos->GetPortion();
     141           0 :     if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
     142           0 :         return 0; // Nur noch BlankPortions unterwegs
     143             :     // Wenn vor uns ein Blank ist, brauchen wir kein Underflow ausloesen,
     144             :     // wenn hinter uns ein Blank ist, brauchen wir kein Underflow weiterreichen
     145           0 :     if( bUnderFlow && CH_BLANK == rInf.GetTxt().GetChar( nIdx + 1) )
     146           0 :         return 0;
     147           0 :     if( nIdx && !((SwTxtFormatInfo&)rInf).GetFly() )
     148             :     {
     149           0 :         while( pPos && !pPos->IsFlyPortion() )
     150           0 :             pPos = pPos->GetPortion();
     151           0 :         if( !pPos )
     152             :         {
     153             :         //Hier wird ueberprueft, ob es in dieser Zeile noch sinnvolle Umbrueche
     154             :         //gibt, Blanks oder Felder etc., wenn nicht, kein Underflow.
     155             :         //Wenn Flys im Spiel sind, lassen wir das Underflow trotzdem zu.
     156           0 :             xub_StrLen nBlank = nIdx;
     157           0 :             while( --nBlank > rInf.GetLineStart() )
     158             :             {
     159           0 :                 const sal_Unicode cCh = rInf.GetChar( nBlank );
     160           0 :                 if( CH_BLANK == cCh ||
     161             :                     (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
     162           0 :                         && rInf.HasHint( nBlank ) ) )
     163           0 :                     break;
     164             :             }
     165           0 :             if( nBlank <= rInf.GetLineStart() )
     166           0 :                 return 0;
     167             :         }
     168             :     }
     169             :     sal_Unicode cCh;
     170           0 :     if( nIdx < 2 || CH_BLANK == (cCh = rInf.GetChar( nIdx - 1 )) )
     171           0 :         return 1;
     172           0 :     if( CH_BREAK == cCh )
     173           0 :         return 0;
     174           0 :     return 2;
     175             : }
     176             : 
     177             : /*************************************************************************
     178             :  *                 virtual SwBlankPortion::FormatEOL()
     179             :  *************************************************************************/
     180             : // Format end of Line
     181             : 
     182           0 : void SwBlankPortion::FormatEOL( SwTxtFormatInfo &rInf )
     183             : {
     184           0 :     MSHORT nMay = MayUnderFlow( rInf, rInf.GetIdx() - nLineLength, sal_True );
     185           0 :     if( nMay )
     186             :     {
     187           0 :         if( nMay > 1 )
     188             :         {
     189           0 :             if( rInf.GetLast() == this )
     190           0 :                rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
     191           0 :             rInf.X( rInf.X() - PrtWidth() );
     192           0 :             rInf.SetIdx( rInf.GetIdx() - GetLen() );
     193             :         }
     194           0 :         Truncate();
     195           0 :         rInf.SetUnderFlow( this );
     196           0 :         if( rInf.GetLast()->IsKernPortion() )
     197           0 :             rInf.SetUnderFlow( rInf.GetLast() );
     198             :     }
     199           0 : }
     200             : 
     201             : /*************************************************************************
     202             :  *                 virtual SwBlankPortion::Format()
     203             :  *************************************************************************/
     204             : 
     205             : // 7771: UnderFlows weiterreichen und selbst ausloesen!
     206           8 : sal_Bool SwBlankPortion::Format( SwTxtFormatInfo &rInf )
     207             : {
     208           8 :     const sal_Bool bFull = rInf.IsUnderFlow() || SwExpandPortion::Format( rInf );
     209           8 :     if( bFull && MayUnderFlow( rInf, rInf.GetIdx(), rInf.IsUnderFlow() ) )
     210             :     {
     211           0 :         Truncate();
     212           0 :         rInf.SetUnderFlow( this );
     213           0 :         if( rInf.GetLast()->IsKernPortion() )
     214           0 :             rInf.SetUnderFlow( rInf.GetLast() );
     215             :     }
     216           8 :     return bFull;
     217             : }
     218             : 
     219             : /*************************************************************************
     220             :  *                 virtual SwBlankPortion::Paint()
     221             :  *************************************************************************/
     222             : 
     223           8 : void SwBlankPortion::Paint( const SwTxtPaintInfo &rInf ) const
     224             : {
     225           8 :     if( !bMulti ) // No gray background for multiportion brackets
     226           8 :         rInf.DrawViewOpt( *this, POR_BLANK );
     227           8 :     SwExpandPortion::Paint( rInf );
     228           8 : }
     229             : 
     230             : /*************************************************************************
     231             :  *              virtual SwBlankPortion::GetExpTxt()
     232             :  *************************************************************************/
     233             : 
     234          16 : sal_Bool SwBlankPortion::GetExpTxt( const SwTxtSizeInfo&, XubString &rTxt ) const
     235             : {
     236          16 :     rTxt = cChar;
     237          16 :     return sal_True;
     238             : }
     239             : 
     240             : /*************************************************************************
     241             :  *              virtual SwBlankPortion::HandlePortion()
     242             :  *************************************************************************/
     243             : 
     244           0 : void SwBlankPortion::HandlePortion( SwPortionHandler& rPH ) const
     245             : {
     246           0 :     OUString aString( cChar );
     247           0 :     rPH.Special( GetLen(), aString, GetWhichPor() );
     248           0 : }
     249             : 
     250             : /*************************************************************************
     251             :  *                      class SwPostItsPortion
     252             :  *************************************************************************/
     253             : 
     254           6 : SwPostItsPortion::SwPostItsPortion( sal_Bool bScrpt )
     255           6 :     : bScript( bScrpt )
     256             : {
     257           6 :     nLineLength = 1;
     258           6 :     SetWhichPor( POR_POSTITS );
     259           6 : }
     260             : 
     261           7 : void SwPostItsPortion::Paint( const SwTxtPaintInfo &rInf ) const
     262             : {
     263           7 :     if( rInf.OnWin() && Width() )
     264           3 :         rInf.DrawPostIts( *this, IsScript() );
     265           7 : }
     266             : 
     267           3 : KSHORT SwPostItsPortion::GetViewWidth( const SwTxtSizeInfo &rInf ) const
     268             : {
     269             :     // Nicht zu fassen: PostIts sind immer zu sehen.
     270           3 :     return rInf.OnWin() ?
     271           3 :                 (KSHORT)rInf.GetOpt().GetPostItsWidth( rInf.GetOut() ) : 0;
     272             : }
     273             : 
     274             : /*************************************************************************
     275             :  *                 virtual SwPostItsPortion::Format()
     276             :  *************************************************************************/
     277             : 
     278           6 : sal_Bool SwPostItsPortion::Format( SwTxtFormatInfo &rInf )
     279             : {
     280           6 :     sal_Bool bRet = SwLinePortion::Format( rInf );
     281             :     // 32749: PostIts sollen keine Auswirkung auf Zeilenhoehe etc. haben
     282           6 :     SetAscent( 1 );
     283           6 :     Height( 1 );
     284           6 :     return bRet;
     285             : }
     286             : 
     287             : /*************************************************************************
     288             :  *              virtual SwPostItsPortion::GetExpTxt()
     289             :  *************************************************************************/
     290             : 
     291           0 : sal_Bool SwPostItsPortion::GetExpTxt( const SwTxtSizeInfo &rInf,
     292             :                                   XubString &rTxt ) const
     293             : {
     294           0 :     if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
     295           0 :         rTxt = ' ';
     296             :     else
     297           0 :         rTxt.Erase();
     298           0 :     return sal_True;
     299             : }
     300             : 
     301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10