LCOV - code coverage report
Current view: top level - editeng/source/uno - unoedhlp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 118 0.0 %
Date: 2014-04-14 Functions: 0 20 0.0 %
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 <editeng/unoedhlp.hxx>
      21             : #include <editeng/editdata.hxx>
      22             : #include <editeng/editeng.hxx>
      23             : #include <svl/itemset.hxx>
      24             : 
      25             : 
      26             : 
      27           0 : TYPEINIT1( SvxEditSourceHint, TextHint );
      28             : 
      29           0 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId ) :
      30             :     TextHint( _nId ),
      31             :     mnStart( 0 ),
      32           0 :     mnEnd( 0 )
      33             : {
      34           0 : }
      35             : 
      36           0 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId, sal_uLong nValue, sal_Int32 nStart, sal_Int32 nEnd ) :
      37             :     TextHint( _nId, nValue ),
      38             :     mnStart( nStart),
      39           0 :     mnEnd( nEnd )
      40             : {
      41           0 : }
      42             : 
      43           0 : sal_uLong SvxEditSourceHint::GetValue() const
      44             : {
      45           0 :     return TextHint::GetValue();
      46             : }
      47             : 
      48           0 : sal_Int32 SvxEditSourceHint::GetStartValue() const
      49             : {
      50           0 :     return mnStart;
      51             : }
      52             : 
      53           0 : sal_Int32 SvxEditSourceHint::GetEndValue() const
      54             : {
      55           0 :     return mnEnd;
      56             : }
      57           0 : TYPEINIT1( SvxEditSourceHintEndPara , SvxEditSourceHint );
      58             : 
      59             : 
      60             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
      61           0 : ::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
      62             : {
      63           0 :     if( aNotify )
      64             :     {
      65           0 :         switch( aNotify->eNotificationType )
      66             :         {
      67             :             case EE_NOTIFY_TEXTMODIFIED:
      68           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );
      69             : 
      70             :             case EE_NOTIFY_PARAGRAPHINSERTED:
      71           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );
      72             : 
      73             :             case EE_NOTIFY_PARAGRAPHREMOVED:
      74           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );
      75             : 
      76             :             case EE_NOTIFY_PARAGRAPHSMOVED:
      77           0 :                 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );
      78             : 
      79             :             case EE_NOTIFY_TEXTHEIGHTCHANGED:
      80           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );
      81             : 
      82             :             case EE_NOTIFY_TEXTVIEWSCROLLED:
      83           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );
      84             : 
      85             :             case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
      86           0 :                 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );
      87             : 
      88             :             case EE_NOTIFY_BLOCKNOTIFICATION_START:
      89           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );
      90             : 
      91             :             case EE_NOTIFY_BLOCKNOTIFICATION_END:
      92           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );
      93             : 
      94             :             case EE_NOTIFY_INPUT_START:
      95           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );
      96             : 
      97             :             case EE_NOTIFY_INPUT_END:
      98           0 :                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );
      99             :             case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED_ENDD_PARA:
     100           0 :                 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHintEndPara( EDITSOURCE_HINT_SELECTIONCHANGED ) );
     101             :             default:
     102             :                 OSL_FAIL( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
     103           0 :                 break;
     104             :         }
     105             :     }
     106             : 
     107           0 :     return ::std::auto_ptr<SfxHint>( new SfxHint() );
     108             : }
     109             : SAL_WNODEPRECATED_DECLARATIONS_POP
     110             : 
     111           0 : bool SvxEditSourceHelper::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, const EditEngine& rEE, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell )
     112             : {
     113             :     // IA2 CWS introduced bInCell, but also did many other changes here.
     114             :     // Need to verify implementation with AT (IA2 and ATK)
     115             :     // Old implementation at the end of the method for reference...
     116             : 
     117             :     //added dummy attributes for the default text
     118           0 :     std::vector<EECharAttrib> aCharAttribs, aTempCharAttribs;
     119           0 :     rEE.GetCharAttribs( nPara, aTempCharAttribs );
     120             : 
     121           0 :     if (!aTempCharAttribs.empty())
     122             :     {
     123           0 :         sal_Int32 nIndex2 = 0;
     124           0 :         sal_Int32 nParaLen = rEE.GetTextLen(nPara);
     125           0 :         for (size_t nAttr = 0; nAttr < aTempCharAttribs.size(); ++nAttr)
     126             :         {
     127           0 :             if (nIndex2 < aTempCharAttribs[nAttr].nStart)
     128             :             {
     129             :                 EECharAttrib aEEAttr;
     130           0 :                 aEEAttr.nStart = nIndex2;
     131           0 :                 aEEAttr.nEnd = aTempCharAttribs[nAttr].nStart;
     132           0 :                 aCharAttribs.insert(aCharAttribs.begin() + nAttr, aEEAttr);
     133             :             }
     134           0 :             nIndex2 = aTempCharAttribs[nAttr].nEnd;
     135           0 :             aCharAttribs.push_back(aTempCharAttribs[nAttr]);
     136             :         }
     137           0 :         if ( nIndex2 != nParaLen )
     138             :         {
     139             :             EECharAttrib aEEAttr;
     140           0 :             aEEAttr.nStart = nIndex2;
     141           0 :             aEEAttr.nEnd = nParaLen;
     142           0 :             aCharAttribs.push_back(aEEAttr);
     143             :         }
     144             :     }
     145             :     // find closest index in front of nIndex
     146             :     sal_Int32 nCurrIndex;
     147           0 :     sal_Int32 nClosestStartIndex_s = 0, nClosestStartIndex_e = 0;
     148           0 :     for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
     149             :     {
     150           0 :         nCurrIndex = i->nStart;
     151             : 
     152           0 :         if( nCurrIndex > nClosestStartIndex_s &&
     153             :             nCurrIndex <= nIndex)
     154             :         {
     155           0 :             nClosestStartIndex_s = nCurrIndex;
     156             :         }
     157           0 :         nCurrIndex = i->nEnd;
     158           0 :         if ( nCurrIndex > nClosestStartIndex_e &&
     159             :             nCurrIndex < nIndex )
     160             :         {
     161           0 :             nClosestStartIndex_e = nCurrIndex;
     162             :         }
     163             :     }
     164           0 :     sal_Int32 nClosestStartIndex = nClosestStartIndex_s > nClosestStartIndex_e ? nClosestStartIndex_s : nClosestStartIndex_e;
     165             : 
     166             :     // find closest index behind of nIndex
     167             :     sal_Int32 nClosestEndIndex_s, nClosestEndIndex_e;
     168           0 :     nClosestEndIndex_s = nClosestEndIndex_e = rEE.GetTextLen(nPara);
     169           0 :     for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
     170             :     {
     171           0 :         nCurrIndex = i->nEnd;
     172             : 
     173           0 :         if( nCurrIndex > nIndex &&
     174             :             nCurrIndex < nClosestEndIndex_e )
     175             :         {
     176           0 :             nClosestEndIndex_e = nCurrIndex;
     177             :         }
     178           0 :         nCurrIndex = i->nStart;
     179           0 :         if ( nCurrIndex > nIndex &&
     180             :             nCurrIndex < nClosestEndIndex_s)
     181             :         {
     182           0 :             nClosestEndIndex_s = nCurrIndex;
     183             :         }
     184             :     }
     185           0 :     sal_Int32 nClosestEndIndex = nClosestEndIndex_s < nClosestEndIndex_e ? nClosestEndIndex_s : nClosestEndIndex_e;
     186             : 
     187           0 :     nStartIndex = nClosestStartIndex;
     188           0 :     nEndIndex = nClosestEndIndex;
     189             : 
     190           0 :     if ( bInCell )
     191             :     {
     192           0 :         EPosition aStartPos( nPara, nStartIndex ), aEndPos( nPara, nEndIndex );
     193           0 :         sal_Int32 nParaCount = rEE.GetParagraphCount();
     194           0 :         sal_Int32 nCrrntParaLen = rEE.GetTextLen(nPara);
     195             :         //need to find closest index in front of nIndex in the previous paragraphs
     196           0 :         if ( aStartPos.nIndex == 0 )
     197             :         {
     198           0 :             SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, 0, 1, GETATTRIBS_CHARATTRIBS );
     199           0 :             for ( sal_Int32 nParaIdx = nPara-1; nParaIdx >= 0; nParaIdx-- )
     200             :             {
     201           0 :                 sal_uInt32 nLen = rEE.GetTextLen(nParaIdx);
     202           0 :                 if ( nLen )
     203             :                 {
     204             :                     sal_Int32 nStartIdx, nEndIdx;
     205           0 :                     GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, nLen, false );
     206           0 :                     SfxItemSet aSet = rEE.GetAttribs( nParaIdx, nLen-1, nLen, GETATTRIBS_CHARATTRIBS );
     207           0 :                     if ( aSet == aCrrntSet )
     208             :                     {
     209           0 :                         aStartPos.nPara = nParaIdx;
     210           0 :                         aStartPos.nIndex = nStartIdx;
     211           0 :                         if ( aStartPos.nIndex != 0 )
     212             :                         {
     213           0 :                             break;
     214             :                         }
     215           0 :                     }
     216             :                 }
     217           0 :             }
     218             :         }
     219             :         //need find closest index behind nIndex in the following paragrphs
     220           0 :         if ( aEndPos.nIndex == nCrrntParaLen )
     221             :         {
     222           0 :             SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, nCrrntParaLen-1, nCrrntParaLen, GETATTRIBS_CHARATTRIBS );
     223           0 :             for ( sal_Int32 nParaIdx = nPara+1; nParaIdx < nParaCount; nParaIdx++ )
     224             :             {
     225           0 :                 sal_Int32 nLen = rEE.GetTextLen( nParaIdx );
     226           0 :                 if ( nLen )
     227             :                 {
     228             :                     sal_Int32 nStartIdx, nEndIdx;
     229           0 :                     GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, 0, false );
     230           0 :                     SfxItemSet aSet = rEE.GetAttribs( nParaIdx, 0, 1, GETATTRIBS_CHARATTRIBS );
     231           0 :                     if ( aSet == aCrrntSet )
     232             :                     {
     233           0 :                         aEndPos.nPara = nParaIdx;
     234           0 :                         aEndPos.nIndex = nEndIdx;
     235           0 :                         if ( aEndPos.nIndex != nLen )
     236             :                         {
     237           0 :                             break;
     238             :                         }
     239           0 :                     }
     240             :                 }
     241           0 :             }
     242             :         }
     243           0 :         nStartIndex = 0;
     244           0 :         if ( aStartPos.nPara > 0 )
     245             :         {
     246           0 :             for ( sal_Int32 i = 0; i < aStartPos.nPara; i++ )
     247             :             {
     248           0 :                 nStartIndex += rEE.GetTextLen(i)+1;
     249             :             }
     250             :         }
     251           0 :         nStartIndex += aStartPos.nIndex;
     252           0 :         nEndIndex = 0;
     253           0 :         if ( aEndPos.nPara > 0 )
     254             :         {
     255           0 :            for ( sal_Int32 i = 0; i < aEndPos.nPara; i++ )
     256             :            {
     257           0 :                nEndIndex += rEE.GetTextLen(i)+1;
     258             :            }
     259             :         }
     260           0 :         nEndIndex += aEndPos.nIndex;
     261             :     }
     262             : 
     263           0 :     return true;
     264             : }
     265             : 
     266           0 : Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
     267             : {
     268           0 :     return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
     269             : }
     270             : 
     271           0 : Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
     272             : {
     273           0 :     return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
     274             : }
     275             : 
     276           0 : Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
     277             : {
     278           0 :     return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
     279           0 :                                     EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
     280             : }
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10