LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/source/edit - textdata.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 85 160 53.1 %
Date: 2013-07-09 Functions: 25 36 69.4 %
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             : 
      21             : #include <vcl/textdata.hxx>
      22             : #include <textdat2.hxx>
      23             : 
      24             : #include <tools/debug.hxx>
      25             : 
      26             : 
      27         154 : TextSelection::TextSelection()
      28             : {
      29         154 : }
      30             : 
      31           0 : TextSelection::TextSelection( const TextPaM& rPaM ) :
      32           0 :     maStartPaM( rPaM ), maEndPaM( rPaM )
      33             : {
      34           0 : }
      35             : 
      36         128 : TextSelection::TextSelection( const TextPaM& rStart, const TextPaM& rEnd ) :
      37         128 :     maStartPaM( rStart ), maEndPaM( rEnd )
      38             : {
      39         128 : }
      40             : 
      41           0 : void TextSelection::Justify()
      42             : {
      43           0 :     if ( maEndPaM < maStartPaM )
      44             :     {
      45           0 :         TextPaM aTemp( maStartPaM );
      46           0 :         maStartPaM = maEndPaM;
      47           0 :         maEndPaM = aTemp;
      48             :     }
      49           0 : }
      50             : 
      51             : 
      52         109 : TETextPortionList::TETextPortionList()
      53             : {
      54         109 : }
      55             : 
      56         218 : TETextPortionList::~TETextPortionList()
      57             : {
      58         109 :     Reset();
      59         109 : }
      60             : 
      61         278 : void TETextPortionList::Reset()
      62             : {
      63         556 :     for ( iterator it = begin(); it != end(); ++it )
      64         278 :         delete *it;
      65         278 :     clear();
      66         278 : }
      67             : 
      68          46 : void TETextPortionList::DeleteFromPortion( sal_uInt16 nDelFrom )
      69             : {
      70             :     DBG_ASSERT( ( nDelFrom < size() ) || ( (nDelFrom == 0) && (size() == 0) ), "DeleteFromPortion: Out of range" );
      71          66 :     for ( iterator it = begin() + nDelFrom; it != end(); ++it )
      72          20 :         delete *it;
      73          46 :     erase( begin() + nDelFrom, end() );
      74          46 : }
      75             : 
      76         294 : sal_uInt16 TETextPortionList::FindPortion( sal_uInt16 nCharPos, sal_uInt16& nPortionStart, sal_Bool bPreferStartingPortion )
      77             : {
      78             :     // find left portion at nCharPos at portion border
      79         294 :     sal_uInt16 nTmpPos = 0;
      80         294 :     for ( sal_uInt16 nPortion = 0; nPortion < size(); nPortion++ )
      81             :     {
      82         294 :         TETextPortion* pPortion = operator[]( nPortion );
      83         294 :         nTmpPos = nTmpPos + pPortion->GetLen();
      84         294 :         if ( nTmpPos >= nCharPos )
      85             :         {
      86             :             // take this one if we don't prefer the starting portion, or if it's the last one
      87         294 :             if ( ( nTmpPos != nCharPos ) || !bPreferStartingPortion || ( nPortion == size() - 1 ) )
      88             :             {
      89         294 :                 nPortionStart = nTmpPos - pPortion->GetLen();
      90         294 :                 return nPortion;
      91             :             }
      92             :         }
      93             :     }
      94             :     OSL_FAIL( "FindPortion: Nicht gefunden!" );
      95           0 :     return ( size() - 1 );
      96             : }
      97             : 
      98             : 
      99         109 : TEParaPortion::TEParaPortion( TextNode* pN )
     100             : {
     101         109 :     mpNode = pN;
     102         109 :     mnInvalidPosStart = mnInvalidDiff = 0;
     103         109 :     mbInvalid = true;
     104         109 :     mbSimple = false;
     105         109 : }
     106             : 
     107         109 : TEParaPortion::~TEParaPortion()
     108             : {
     109         109 : }
     110             : 
     111          26 : void TEParaPortion::MarkInvalid( sal_uInt16 nStart, short nDiff )
     112             : {
     113          26 :     if ( !mbInvalid )
     114             :     {
     115           0 :         mnInvalidPosStart = ( nDiff >= 0 ) ? nStart : ( nStart + nDiff );
     116           0 :         mnInvalidDiff = nDiff;
     117             :     }
     118             :     else
     119             :     {
     120             :         // simple consecutive typing
     121          26 :         if ( ( nDiff > 0 ) && ( mnInvalidDiff > 0 ) &&
     122           0 :              ( ( mnInvalidPosStart+mnInvalidDiff ) == nStart ) )
     123             :         {
     124           0 :             mnInvalidDiff = mnInvalidDiff + nDiff;
     125             :         }
     126             :         // simple consecutive deleting
     127          26 :         else if ( ( nDiff < 0 ) && ( mnInvalidDiff < 0 ) && ( mnInvalidPosStart == nStart ) )
     128             :         {
     129           0 :             mnInvalidPosStart = mnInvalidPosStart + nDiff;
     130           0 :             mnInvalidDiff = mnInvalidDiff + nDiff;
     131             :         }
     132             :         else
     133             :         {
     134             :             DBG_ASSERT( ( nDiff >= 0 ) || ( (nStart+nDiff) >= 0 ), "MarkInvalid: Diff out of Range" );
     135          26 :             mnInvalidPosStart = std::min( mnInvalidPosStart, (sal_uInt16) ( (nDiff < 0) ? nStart+nDiff : nDiff ) );
     136          26 :             mnInvalidDiff = 0;
     137          26 :             mbSimple = false;
     138             :         }
     139             :     }
     140             : 
     141          26 :     maWritingDirectionInfos.clear();
     142             : 
     143          26 :     mbInvalid = true;
     144          26 : }
     145             : 
     146         234 : void TEParaPortion::MarkSelectionInvalid( sal_uInt16 nStart, sal_uInt16 /*nEnd*/ )
     147             : {
     148         234 :     if ( !mbInvalid )
     149             :     {
     150         189 :         mnInvalidPosStart = nStart;
     151             : //      nInvalidPosEnd = nEnd;
     152             :     }
     153             :     else
     154             :     {
     155          45 :         mnInvalidPosStart = std::min( mnInvalidPosStart, nStart );
     156             : //      nInvalidPosEnd = pNode->Len();
     157             :     }
     158             : 
     159         234 :     maWritingDirectionInfos.clear();
     160             : 
     161         234 :     mnInvalidDiff = 0;
     162         234 :     mbInvalid = true;
     163         234 :     mbSimple = false;
     164         234 : }
     165             : 
     166           0 : sal_uInt16 TEParaPortion::GetLineNumber( sal_uInt16 nChar, sal_Bool bInclEnd )
     167             : {
     168           0 :     for ( sal_uInt16 nLine = 0; nLine < maLines.size(); nLine++ )
     169             :     {
     170           0 :         TextLine* pLine = maLines[ nLine ];
     171           0 :         if ( ( bInclEnd && ( pLine->GetEnd() >= nChar ) ) ||
     172           0 :              ( pLine->GetEnd() > nChar ) )
     173             :         {
     174           0 :             return nLine;
     175             :         }
     176             :     }
     177             : 
     178             :     // Then it should be at the end of the last line
     179             :     OSL_ENSURE(nChar == maLines[maLines.size() - 1]->GetEnd(), "wrong Index");
     180             :     OSL_ENSURE(!bInclEnd, "Line not found: FindLine");
     181           0 :     return ( maLines.size() - 1 );
     182             : }
     183             : 
     184             : 
     185           0 : void TEParaPortion::CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine )
     186             : {
     187           0 :     sal_uInt16 nLines = maLines.size();
     188             :     DBG_ASSERT( nLines, "CorrectPortionNumbersFromLine: Leere Portion?" );
     189           0 :     if ( nLastFormattedLine < ( nLines - 1 ) )
     190             :     {
     191           0 :         const TextLine* pLastFormatted = maLines[ nLastFormattedLine ];
     192           0 :         const TextLine* pUnformatted = maLines[ nLastFormattedLine+1 ];
     193           0 :         short nPortionDiff = pUnformatted->GetStartPortion() - pLastFormatted->GetEndPortion();
     194           0 :         short nTextDiff = pUnformatted->GetStart() - pLastFormatted->GetEnd();
     195           0 :         nTextDiff++;    // LastFormatted->GetEnd() was inclusive => subtracted one too much!
     196             : 
     197             :         // The first unformated one has to start exactly one portion past the last
     198             :         // formated one.
     199             :         // If a portion got split in the changed row, nLastEnd could be > nNextStart!
     200           0 :         short nPDiff = sal::static_int_cast< short >(-( nPortionDiff-1 ));
     201           0 :         short nTDiff = sal::static_int_cast< short >(-( nTextDiff-1 ));
     202           0 :         if ( nPDiff || nTDiff )
     203             :         {
     204           0 :             for ( sal_uInt16 nL = nLastFormattedLine+1; nL < nLines; nL++ )
     205             :             {
     206           0 :                 TextLine* pLine = maLines[ nL ];
     207             : 
     208           0 :                 pLine->GetStartPortion() = pLine->GetStartPortion() + nPDiff;
     209           0 :                 pLine->GetEndPortion() = pLine->GetEndPortion() + nPDiff;
     210             : 
     211           0 :                 pLine->GetStart() = pLine->GetStart() + nTDiff;
     212           0 :                 pLine->GetEnd() = pLine->GetEnd() + nTDiff;
     213             : 
     214           0 :                 pLine->SetValid();
     215             :             }
     216             :         }
     217             :     }
     218           0 : }
     219             : 
     220         109 : TEParaPortions::TEParaPortions()
     221             : {
     222         109 : }
     223             : 
     224         218 : TEParaPortions::~TEParaPortions()
     225             : {
     226         109 :     Reset();
     227         109 : }
     228             : 
     229         109 : void TEParaPortions::Reset()
     230             : {
     231         109 :     TEParaPortions::iterator aIter( begin() );
     232         327 :     while ( aIter != end() )
     233         109 :         delete *aIter++;
     234         109 :     clear();
     235         109 : }
     236             : 
     237          45 : IdleFormatter::IdleFormatter()
     238             : {
     239          45 :     mpView = 0;
     240          45 :     mnRestarts = 0;
     241          45 : }
     242             : 
     243         135 : IdleFormatter::~IdleFormatter()
     244             : {
     245          45 :     mpView = 0;
     246          90 : }
     247             : 
     248           0 : void IdleFormatter::DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts )
     249             : {
     250           0 :     mpView = pV;
     251             : 
     252           0 :     if ( IsActive() )
     253           0 :         mnRestarts++;
     254             : 
     255           0 :     if ( mnRestarts > nMaxRestarts )
     256             :     {
     257           0 :         mnRestarts = 0;
     258           0 :         ((Link&)GetTimeoutHdl()).Call( this );
     259             :     }
     260             :     else
     261             :     {
     262           0 :         Start();
     263             :     }
     264           0 : }
     265             : 
     266         263 : void IdleFormatter::ForceTimeout()
     267             : {
     268         263 :     if ( IsActive() )
     269             :     {
     270           0 :         Stop();
     271           0 :         mnRestarts = 0;
     272           0 :         ((Link&)GetTimeoutHdl()).Call( this );
     273             :     }
     274         263 : }
     275             : 
     276        3254 : TYPEINIT1( TextHint, SfxSimpleHint );
     277             : 
     278         448 : TextHint::TextHint( sal_uLong Id ) : SfxSimpleHint( Id )
     279             : {
     280         448 :     mnValue = 0;
     281         448 : }
     282             : 
     283         554 : TextHint::TextHint( sal_uLong Id, sal_uLong nValue ) : SfxSimpleHint( Id )
     284             : {
     285         554 :     mnValue = nValue;
     286         554 : }
     287             : 
     288           0 : TEIMEInfos::TEIMEInfos( const TextPaM& rPos, const String& rOldTextAfterStartPos )
     289           0 : : aOldTextAfterStartPos( rOldTextAfterStartPos )
     290             : {
     291           0 :     aPos = rPos;
     292           0 :     nLen = 0;
     293           0 :     bCursor = sal_True;
     294           0 :     pAttribs = NULL;
     295           0 :     bWasCursorOverwrite = sal_False;
     296           0 : }
     297             : 
     298           0 : TEIMEInfos::~TEIMEInfos()
     299             : {
     300           0 :     delete[] pAttribs;
     301           0 : }
     302             : 
     303           0 : void TEIMEInfos::CopyAttribs( const sal_uInt16* pA, sal_uInt16 nL )
     304             : {
     305           0 :     nLen = nL;
     306           0 :     delete[] pAttribs;
     307           0 :     pAttribs = new sal_uInt16[ nL ];
     308           0 :     memcpy( pAttribs, pA, nL*sizeof(sal_uInt16) );
     309           0 : }
     310             : 
     311           0 : void TEIMEInfos::DestroyAttribs()
     312             : {
     313           0 :     delete[] pAttribs;
     314           0 :     pAttribs = NULL;
     315           0 :     nLen = 0;
     316         465 : }
     317             : 
     318             : 
     319             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10