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

Generated by: LCOV version 1.11