LCOV - code coverage report
Current view: top level - libreoffice/editeng/source/editeng - textconv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 225 0.0 %
Date: 2012-12-27 Functions: 0 18 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             : 
      21             : #include <vcl/wrkwin.hxx>
      22             : #include <vcl/dialog.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : 
      26             : #include <impedit.hxx>
      27             : #include <editeng/editview.hxx>
      28             : #include <editeng/editeng.hxx>
      29             : #include <editeng/unolingu.hxx>
      30             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      31             : #include <com/sun/star/lang/Locale.hpp>
      32             : #include <editeng/langitem.hxx>
      33             : #include <editeng/fontitem.hxx>
      34             : #include <textconv.hxx>
      35             : 
      36             : 
      37             : using ::rtl::OUString;
      38             : using namespace com::sun::star;
      39             : using namespace com::sun::star::uno;
      40             : using namespace com::sun::star::beans;
      41             : using namespace com::sun::star::lang;
      42             : using namespace com::sun::star::linguistic2;
      43             : 
      44             : #define C2U(cChar) OUString::createFromAscii(cChar)
      45             : 
      46             : //////////////////////////////////////////////////////////////////////
      47             : 
      48           0 : TextConvWrapper::TextConvWrapper( Window* pWindow,
      49             :         const Reference< XComponentContext >& rxContext,
      50             :         const Locale& rSourceLocale,
      51             :         const Locale& rTargetLocale,
      52             :         const Font* pTargetFont,
      53             :         sal_Int32 nOptions,
      54             :         sal_Bool bIsInteractive,
      55             :         sal_Bool bIsStart,
      56             :         EditView* pView ) :
      57           0 :     HangulHanjaConversion( pWindow, rxContext, rSourceLocale, rTargetLocale, pTargetFont, nOptions, bIsInteractive )
      58             : {
      59             :     DBG_ASSERT( pWindow, "TextConvWrapper: window missing" );
      60             : 
      61           0 :     nConvTextLang = LANGUAGE_NONE;
      62           0 :     nUnitOffset = 0;
      63             : 
      64           0 :     bStartChk   = sal_False;
      65           0 :     bStartDone  = bIsStart;
      66           0 :     bEndDone    = sal_False;
      67           0 :     pWin        = pWindow;
      68           0 :     pEditView   = pView;
      69             : 
      70           0 :     aConvSel    = pEditView->GetSelection();
      71           0 :     aConvSel.Adjust();  // make Start <= End
      72             : 
      73           0 :     bAllowChange = sal_False;
      74           0 : }
      75             : 
      76             : 
      77           0 : TextConvWrapper::~TextConvWrapper()
      78             : {
      79           0 : }
      80             : 
      81             : 
      82           0 : sal_Bool TextConvWrapper::ConvNext_impl()
      83             : {
      84             :     // modified version of SvxSpellWrapper::SpellNext
      85             : 
      86           0 :     if( bStartChk )
      87           0 :         bStartDone = sal_True;
      88             :     else
      89           0 :         bEndDone = sal_True;
      90             : 
      91           0 :     if ( bStartDone && bEndDone )
      92             :     {
      93           0 :         if ( ConvMore_impl() )  // examine another document?
      94             :         {
      95           0 :             bStartDone = sal_True;
      96           0 :             bEndDone  = sal_False;
      97           0 :             ConvStart_impl( SVX_SPELL_BODY );
      98           0 :             return sal_True;
      99             :         }
     100           0 :         return sal_False;
     101             : 
     102             :     }
     103             : 
     104           0 :     sal_Bool bGoOn = sal_False;
     105             : 
     106           0 :     if ( bStartDone && bEndDone )
     107             :     {
     108           0 :         if ( ConvMore_impl() )  // examine another document?
     109             :         {
     110           0 :             bStartDone = sal_True;
     111           0 :             bEndDone  = sal_False;
     112           0 :             ConvStart_impl( SVX_SPELL_BODY );
     113           0 :             return sal_True;
     114             :         }
     115             :     }
     116           0 :     else if (!aConvSel.HasRange())
     117             :     {
     118           0 :         bStartChk = !bStartDone;
     119           0 :         ConvStart_impl( bStartChk ? SVX_SPELL_BODY_START : SVX_SPELL_BODY_END );
     120           0 :         bGoOn = sal_True;
     121             :     }
     122           0 :     return bGoOn;
     123             : }
     124             : 
     125             : 
     126           0 : sal_Bool TextConvWrapper::FindConvText_impl()
     127             : {
     128             :     // modified version of SvxSpellWrapper::FindSpellError
     129             : 
     130           0 :     sal_Bool bFound = sal_False;
     131             : 
     132           0 :     pWin->EnterWait();
     133           0 :     sal_Bool bConvert = sal_True;
     134             : 
     135           0 :     while ( bConvert )
     136             :     {
     137           0 :         bFound = ConvContinue_impl();
     138           0 :         if (bFound)
     139             :         {
     140           0 :             bConvert = sal_False;
     141             :         }
     142             :         else
     143             :         {
     144           0 :             ConvEnd_impl();
     145           0 :             bConvert = ConvNext_impl();
     146             :         }
     147             :     }
     148           0 :     pWin->LeaveWait();
     149           0 :     return bFound;
     150             : }
     151             : 
     152             : 
     153           0 : sal_Bool TextConvWrapper::ConvMore_impl()
     154             : {
     155             :     // modified version of SvxSpellWrapper::SpellMore
     156             : 
     157           0 :     bool bMore = false;
     158           0 :     EditEngine* pEE = pEditView->GetEditEngine();
     159           0 :     ImpEditEngine* pImpEE = pEditView->GetImpEditEngine();
     160           0 :     ConvInfo* pConvInfo = pImpEE->GetConvInfo();
     161           0 :     if ( pConvInfo->bMultipleDoc )
     162             :     {
     163           0 :         bMore = pEE->ConvertNextDocument();
     164           0 :         if ( bMore )
     165             :         {
     166             :             // The text has been entered in this engine ...
     167             :             pEditView->GetImpEditView()->SetEditSelection(
     168           0 :                         pEE->GetEditDoc().GetStartPaM() );
     169             :         }
     170             :     }
     171           0 :     return bMore;
     172             : }
     173             : 
     174             : 
     175           0 : void TextConvWrapper::ConvStart_impl( SvxSpellArea eArea )
     176             : {
     177             :     // modified version of EditSpellWrapper::SpellStart
     178             : 
     179           0 :     EditEngine* pEE = pEditView->GetEditEngine();
     180           0 :     ImpEditEngine* pImpEE = pEditView->GetImpEditEngine();
     181           0 :     ConvInfo* pConvInfo = pImpEE->GetConvInfo();
     182             : 
     183           0 :     if ( eArea == SVX_SPELL_BODY_START )
     184             :     {
     185             :         // Is called when Spell-forward has reached the end, and to start over
     186           0 :         if ( bEndDone )
     187             :         {
     188           0 :             pConvInfo->bConvToEnd = sal_False;
     189           0 :             pConvInfo->aConvTo = pConvInfo->aConvStart;
     190           0 :             pConvInfo->aConvContinue = EPaM( 0, 0 );
     191             :             pEditView->GetImpEditView()->SetEditSelection(
     192           0 :                     pEE->GetEditDoc().GetStartPaM() );
     193             :         }
     194             :         else
     195             :         {
     196           0 :             pConvInfo->bConvToEnd = sal_True;
     197             :             pConvInfo->aConvTo = pImpEE->CreateEPaM(
     198           0 :                     pEE->GetEditDoc().GetStartPaM() );
     199             :         }
     200             :     }
     201           0 :     else if ( eArea == SVX_SPELL_BODY_END )
     202             :     {
     203             :         // Is called when Spell-forward starts
     204           0 :         pConvInfo->bConvToEnd = sal_True;
     205           0 :         if (aConvSel.HasRange())
     206             :         {
     207             :             // user selection: convert to end of selection
     208           0 :             pConvInfo->aConvTo.nPara    = aConvSel.nEndPara;
     209           0 :             pConvInfo->aConvTo.nIndex   = aConvSel.nEndPos;
     210           0 :             pConvInfo->bConvToEnd       = sal_False;
     211             :         }
     212             :         else
     213             :         {
     214             :             // nothing selected: convert to end of document
     215             :             pConvInfo->aConvTo = pImpEE->CreateEPaM(
     216           0 :                 pEE->GetEditDoc().GetEndPaM() );
     217             :         }
     218             :     }
     219           0 :     else if ( eArea == SVX_SPELL_BODY )
     220             :     {
     221             :         // called by ConvNext_impl...
     222           0 :         pConvInfo->aConvContinue = pConvInfo->aConvStart;
     223             :         pConvInfo->aConvTo = pImpEE->CreateEPaM(
     224           0 :             pEE->GetEditDoc().GetEndPaM() );
     225             :     }
     226             :     else
     227             :     {
     228             :         OSL_FAIL( "ConvStart_impl: Unknown Area!" );
     229             :     }
     230           0 : }
     231             : 
     232             : 
     233           0 : void TextConvWrapper::ConvEnd_impl()
     234             : {
     235           0 : }
     236             : 
     237             : 
     238           0 : sal_Bool TextConvWrapper::ConvContinue_impl()
     239             : {
     240             :     // modified version of EditSpellWrapper::SpellContinue
     241             : 
     242             :     // get next convertible text portion and its language
     243           0 :     aConvText = rtl::OUString();
     244           0 :     nConvTextLang = LANGUAGE_NONE;
     245             :     pEditView->GetImpEditEngine()->ImpConvert( aConvText, nConvTextLang,
     246           0 :             pEditView, GetSourceLanguage(), aConvSel,
     247           0 :             bAllowChange, GetTargetLanguage(), GetTargetFont() );
     248           0 :     return !aConvText.isEmpty();
     249             : }
     250             : 
     251             : 
     252           0 : void TextConvWrapper::SetLanguageAndFont( const ESelection &rESel,
     253             :     LanguageType nLang, sal_uInt16 nLangWhichId,
     254             :     const Font *pFont,  sal_uInt16 nFontWhichId )
     255             : {
     256           0 :     ESelection aOldSel = pEditView->GetSelection();
     257           0 :     pEditView->SetSelection( rESel );
     258             : 
     259             :     // set new language attribute
     260           0 :     SfxItemSet aNewSet( pEditView->GetEmptyItemSet() );
     261           0 :     aNewSet.Put( SvxLanguageItem( nLang, nLangWhichId ) );
     262             : 
     263             :     // new font to be set?
     264             :     DBG_ASSERT( pFont, "target font missing?" );
     265           0 :     if (pFont)
     266             :     {
     267             :         // set new font attribute
     268           0 :         SvxFontItem aFontItem = (SvxFontItem&) aNewSet.Get( nFontWhichId );
     269           0 :         aFontItem.SetFamilyName( pFont->GetName());
     270           0 :         aFontItem.SetFamily( pFont->GetFamily());
     271           0 :         aFontItem.SetStyleName( pFont->GetStyleName());
     272           0 :         aFontItem.SetPitch( pFont->GetPitch());
     273           0 :         aFontItem.SetCharSet(pFont->GetCharSet());
     274           0 :         aNewSet.Put( aFontItem );
     275             :     }
     276             : 
     277             :     // apply new attributes
     278           0 :     pEditView->SetAttribs( aNewSet );
     279             : 
     280           0 :     pEditView->SetSelection( aOldSel );
     281           0 : }
     282             : 
     283             : 
     284           0 : void TextConvWrapper::SelectNewUnit_impl(
     285             :         const sal_Int32 nUnitStart,
     286             :         const sal_Int32 nUnitEnd )
     287             : {
     288           0 :     sal_Bool bOK = 0 <= nUnitStart && 0 <= nUnitEnd && nUnitStart <= nUnitEnd;
     289             :     DBG_ASSERT( bOK, "invalid arguments" );
     290           0 :     if (!bOK)
     291           0 :         return;
     292             : 
     293           0 :     ESelection  aSelection = pEditView->GetSelection();
     294             :     DBG_ASSERT( aSelection.nStartPara == aSelection.nEndPara,
     295             :         "paragraph mismatch in selection" );
     296           0 :     aSelection.nStartPos = (sal_uInt16) (nLastPos + nUnitOffset + nUnitStart);
     297           0 :     aSelection.nEndPos   = (sal_uInt16) (nLastPos + nUnitOffset + nUnitEnd);
     298           0 :     pEditView->SetSelection( aSelection );
     299             : }
     300             : 
     301             : 
     302           0 : void TextConvWrapper::GetNextPortion(
     303             :         ::rtl::OUString& /* [out] */ rNextPortion,
     304             :         LanguageType&    /* [out] */ rLangOfPortion,
     305             :         sal_Bool /* [in] */ _bAllowImplicitChangesForNotConvertibleText )
     306             : {
     307           0 :     bAllowChange = _bAllowImplicitChangesForNotConvertibleText;
     308             : 
     309           0 :     FindConvText_impl();
     310           0 :     rNextPortion    = aConvText;
     311           0 :     rLangOfPortion  = nConvTextLang;
     312           0 :     nUnitOffset  = 0;
     313             : 
     314           0 :     ESelection  aSelection = pEditView->GetSelection();
     315             :     DBG_ASSERT( aSelection.nStartPara == aSelection.nEndPara,
     316             :             "paragraph mismatch in selection" );
     317             :     DBG_ASSERT( aSelection.nStartPos  <= aSelection.nEndPos,
     318             :             "start pos > end pos" );
     319           0 :     nLastPos =  aSelection.nStartPos;
     320           0 : }
     321             : 
     322             : 
     323           0 : void TextConvWrapper::HandleNewUnit(
     324             :         const sal_Int32 nUnitStart,
     325             :         const sal_Int32 nUnitEnd )
     326             : {
     327           0 :     SelectNewUnit_impl( nUnitStart, nUnitEnd );
     328           0 : }
     329             : 
     330             : #ifdef DBG_UTIL
     331             : namespace
     332             : {
     333             :     sal_Bool IsSimilarChinese( LanguageType nLang1, LanguageType nLang2 )
     334             :     {
     335             :         using namespace editeng;
     336             :         return (HangulHanjaConversion::IsTraditional(nLang1) && HangulHanjaConversion::IsTraditional(nLang2)) ||
     337             :                (HangulHanjaConversion::IsSimplified(nLang1)  && HangulHanjaConversion::IsSimplified(nLang2));
     338             :     }
     339             : }
     340             : #endif
     341             : 
     342           0 : void TextConvWrapper::ReplaceUnit(
     343             :         const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd,
     344             :         const ::rtl::OUString& rOrigText,
     345             :         const ::rtl::OUString& rReplaceWith,
     346             :         const ::com::sun::star::uno::Sequence< sal_Int32 > &rOffsets,
     347             :         ReplacementAction eAction,
     348             :         LanguageType *pNewUnitLanguage )
     349             : {
     350           0 :     sal_Bool bOK = 0 <= nUnitStart && 0 <= nUnitEnd && nUnitStart <= nUnitEnd;
     351             :     DBG_ASSERT( bOK, "invalid arguments" );
     352           0 :     if (!bOK)
     353           0 :         return;
     354             : 
     355           0 :     static OUString aBracketedStart( C2U( "(" ) );
     356           0 :     static OUString aBracketedEnd( C2U( ")" ) );
     357             : 
     358             :     // select current unit
     359           0 :     SelectNewUnit_impl( nUnitStart, nUnitEnd );
     360             : 
     361           0 :     OUString aOrigTxt( pEditView->GetSelected() );
     362           0 :     OUString aNewTxt( rReplaceWith );
     363           0 :     String  aNewOrigText;
     364           0 :     switch (eAction)
     365             :     {
     366             :         case eExchange :
     367           0 :         break;
     368             :         case eReplacementBracketed :
     369           0 :             (((aNewTxt = aOrigTxt) += aBracketedStart) += rReplaceWith) += aBracketedEnd;
     370           0 :         break;
     371             :         case eOriginalBracketed :
     372           0 :             (((aNewTxt = rReplaceWith) += aBracketedStart) += aOrigTxt) += aBracketedEnd;
     373           0 :         break;
     374             :         case eReplacementAbove  :
     375             :         case eOriginalAbove :
     376             :         case eReplacementBelow :
     377             :         case eOriginalBelow :
     378             :             OSL_FAIL( "Rubies not supported" );
     379           0 :             break;
     380             :         default:
     381             :             OSL_FAIL( "unexpected case" );
     382             :     }
     383             :     nUnitOffset = sal::static_int_cast< sal_uInt16 >(
     384           0 :         nUnitOffset + nUnitStart + aNewTxt.getLength());
     385             : 
     386             :     // remember current original language for kater use
     387           0 :     ImpEditEngine *pImpEditEng = pEditView->GetImpEditEngine();
     388           0 :     ESelection _aOldSel     = pEditView->GetSelection();
     389             :     //EditSelection aOldEditSel = pEditView->GetImpEditView()->GetEditSelection();
     390             : 
     391             : #ifdef DBG_UTIL
     392             :     LanguageType nOldLang   = pImpEditEng->GetLanguage( pImpEditEng->CreateSel( _aOldSel ).Min() );
     393             : #endif
     394             : 
     395           0 :     pImpEditEng->UndoActionStart( EDITUNDO_INSERT );
     396             : 
     397             :     // according to FT we should currently not bother about keeping
     398             :     // attributes in Hangul/Hanja conversion and leave that untouched.
     399             :     // Thus we do this only for Chinese translation...
     400           0 :     sal_Bool bIsChineseConversion = IsChinese( GetSourceLanguage() );
     401           0 :     if (bIsChineseConversion)
     402           0 :         ChangeText( aNewTxt, rOrigText, &rOffsets, &_aOldSel );
     403             :     else
     404           0 :         ChangeText( aNewTxt, rOrigText, NULL, NULL );
     405             : 
     406             :     // change language and font if necessary
     407           0 :     if (bIsChineseConversion)
     408             :     {
     409             :         DBG_ASSERT( GetTargetLanguage() == LANGUAGE_CHINESE_SIMPLIFIED || GetTargetLanguage() == LANGUAGE_CHINESE_TRADITIONAL,
     410             :                 "TextConvWrapper::ReplaceUnit : unexpected target language" );
     411             : 
     412           0 :         ESelection aOldSel = pEditView->GetSelection();
     413           0 :         ESelection aNewSel( aOldSel );
     414             :         aNewSel.nStartPos = sal::static_int_cast< xub_StrLen >(
     415           0 :             aNewSel.nStartPos - aNewTxt.getLength());
     416             : 
     417           0 :         if (pNewUnitLanguage)
     418             :         {
     419             :             DBG_ASSERT(!IsSimilarChinese( *pNewUnitLanguage, nOldLang ),
     420             :                     "similar language should not be changed!");
     421             :             SetLanguageAndFont( aNewSel, *pNewUnitLanguage, EE_CHAR_LANGUAGE_CJK,
     422           0 :                                           GetTargetFont(), EE_CHAR_FONTINFO_CJK );
     423             :         }
     424             :     }
     425             : 
     426           0 :     pImpEditEng->UndoActionEnd( EDITUNDO_INSERT );
     427             : 
     428             :     // adjust ConvContinue / ConvTo if necessary
     429           0 :     ImpEditEngine* pImpEE = pEditView->GetImpEditEngine();
     430           0 :     ConvInfo* pConvInfo = pImpEE->GetConvInfo();
     431           0 :     sal_Int32 nDelta = aNewTxt.getLength() - aOrigTxt.getLength();
     432           0 :     if (nDelta != 0)
     433             :     {
     434             :         // Note: replacement is always done in the current paragraph
     435             :         // which is the one ConvContinue points to
     436             :         pConvInfo->aConvContinue.nIndex = sal::static_int_cast< sal_uInt16 >(
     437           0 :             pConvInfo->aConvContinue.nIndex + nDelta);
     438             : 
     439             :         // if that is the same as the one where the conversions ends
     440             :         // the end needs to be updated also
     441           0 :         if (pConvInfo->aConvTo.nPara == pConvInfo->aConvContinue.nPara)
     442             :             pConvInfo->aConvTo.nIndex = sal::static_int_cast< sal_uInt16 >(
     443           0 :                 pConvInfo->aConvTo.nIndex + nDelta);
     444           0 :     }
     445             : }
     446             : 
     447             : 
     448           0 : void TextConvWrapper::ChangeText( const String &rNewText,
     449             :         const OUString& rOrigText,
     450             :         const uno::Sequence< sal_Int32 > *pOffsets,
     451             :         ESelection *pESelection )
     452             : {
     453             :     //!! code is a modifed copy of SwHHCWrapper::ChangeText from sw !!
     454             : 
     455             :     DBG_ASSERT( rNewText.Len() != 0, "unexpected empty string" );
     456           0 :     if (rNewText.Len() == 0)
     457           0 :         return;
     458             : 
     459           0 :     if (pOffsets && pESelection)  // try to keep as much attributation as possible ?
     460             :     {
     461           0 :         pESelection->Adjust();
     462             : 
     463             :         // remember cursor start position for later setting of the cursor
     464           0 :         const xub_StrLen nStartIndex = pESelection->nStartPos;
     465             : 
     466           0 :         const sal_Int32  nIndices = pOffsets->getLength();
     467           0 :         const sal_Int32 *pIndices = pOffsets->getConstArray();
     468           0 :         xub_StrLen nConvTextLen = rNewText.Len();
     469           0 :         xub_StrLen nPos = 0;
     470           0 :         xub_StrLen nChgPos = STRING_NOTFOUND;
     471           0 :         xub_StrLen nChgLen = 0;
     472           0 :         xub_StrLen nConvChgPos = STRING_NOTFOUND;
     473           0 :         xub_StrLen nConvChgLen = 0;
     474             : 
     475             :         // offset to calculate the position in the text taking into
     476             :         // account that text may have been replaced with new text of
     477             :         // different length. Negative values allowed!
     478           0 :         long nCorrectionOffset = 0;
     479             : 
     480             :         DBG_ASSERT(nIndices == 0 || nIndices == nConvTextLen,
     481             :                 "mismatch between string length and sequence length!" );
     482             : 
     483             :         // find all substrings that need to be replaced (and only those)
     484           0 :         while (sal_True)
     485             :         {
     486             :             // get index in original text that matches nPos in new text
     487             :             xub_StrLen nIndex;
     488           0 :             if (nPos < nConvTextLen)
     489           0 :                 nIndex = (sal_Int32) nPos < nIndices ? (xub_StrLen) pIndices[nPos] : nPos;
     490             :             else
     491             :             {
     492           0 :                 nPos   = nConvTextLen;
     493           0 :                 nIndex = static_cast< xub_StrLen >( rOrigText.getLength() );
     494             :             }
     495             : 
     496           0 :             if (rOrigText.getStr()[nIndex] == rNewText.GetChar(nPos) ||
     497             :                 nPos == nConvTextLen /* end of string also terminates non-matching char sequence */)
     498             :             {
     499             :                 // substring that needs to be replaced found?
     500           0 :                 if (nChgPos != STRING_NOTFOUND && nConvChgPos != STRING_NOTFOUND)
     501             :                 {
     502           0 :                     nChgLen = nIndex - nChgPos;
     503           0 :                     nConvChgLen = nPos - nConvChgPos;
     504             : #ifdef DEBUG
     505             :                     String aInOrig( rOrigText.copy( nChgPos, nChgLen ) );
     506             : #endif
     507           0 :                     String aInNew( rNewText.Copy( nConvChgPos, nConvChgLen ) );
     508             : 
     509             :                     // set selection to sub string to be replaced in original text
     510           0 :                     ESelection aSel( *pESelection );
     511           0 :                     xub_StrLen nChgInNodeStartIndex = static_cast< xub_StrLen >( nStartIndex + nCorrectionOffset + nChgPos );
     512           0 :                     aSel.nStartPos = nChgInNodeStartIndex;
     513           0 :                     aSel.nEndPos   = nChgInNodeStartIndex + nChgLen;
     514           0 :                     pEditView->SetSelection( aSel );
     515             : #ifdef DEBUG
     516             :                     String aSelTxt1( pEditView->GetSelected() );
     517             : #endif
     518             : 
     519             :                     // replace selected sub string with the corresponding
     520             :                     // sub string from the new text while keeping as
     521             :                     // much from the attributes as possible
     522           0 :                     ChangeText_impl( aInNew, sal_True );
     523             : 
     524           0 :                     nCorrectionOffset += nConvChgLen - nChgLen;
     525             : 
     526           0 :                     nChgPos = STRING_NOTFOUND;
     527           0 :                     nConvChgPos = STRING_NOTFOUND;
     528             :                 }
     529             :             }
     530             :             else
     531             :             {
     532             :                 // begin of non-matching char sequence found ?
     533           0 :                 if (nChgPos == STRING_NOTFOUND && nConvChgPos == STRING_NOTFOUND)
     534             :                 {
     535           0 :                     nChgPos = nIndex;
     536           0 :                     nConvChgPos = nPos;
     537             :                 }
     538             :             }
     539           0 :             if (nPos >= nConvTextLen)
     540           0 :                 break;
     541           0 :             ++nPos;
     542             :         }
     543             : 
     544             :         // set cursor to the end of the inserted text
     545             :         // (as it would happen after ChangeText_impl (Delete and Insert)
     546             :         // of the whole text in the 'else' branch below)
     547           0 :         pESelection->nStartPos = pESelection->nEndPos = nStartIndex + nConvTextLen;
     548             :     }
     549             :     else
     550             :     {
     551           0 :         ChangeText_impl( rNewText, sal_False );
     552             :     }
     553             : }
     554             : 
     555             : 
     556           0 : void TextConvWrapper::ChangeText_impl( const String &rNewText, sal_Bool bKeepAttributes )
     557             : {
     558           0 :     if (bKeepAttributes)
     559             :     {
     560             :         // save attributes to be restored
     561           0 :         SfxItemSet aSet( pEditView->GetAttribs() );
     562             : 
     563             : #ifdef DEBUG
     564             :         String aSelTxt1( pEditView->GetSelected() );
     565             : #endif
     566             :         // replace old text and select new text
     567           0 :         pEditView->InsertText( rNewText, sal_True );
     568             : #ifdef DEBUG
     569             :         String aSelTxt2( pEditView->GetSelected() );
     570             : #endif
     571             : 
     572             :         // since 'SetAttribs' below function like merging with the attributes
     573             :         // from the itemset with any existing ones we have to get rid of all
     574             :         // all attributes now. (Those attributes that may take effect left
     575             :         // to the position where the new text gets inserted after the old text
     576             :         // was deleted)
     577           0 :         pEditView->RemoveAttribs();
     578             :         // apply saved attributes to new inserted text
     579           0 :         pEditView->SetAttribs( aSet );
     580             :     }
     581             :     else
     582             :     {
     583           0 :         pEditView->InsertText( rNewText );
     584             :     }
     585           0 : }
     586             : 
     587             : 
     588           0 : void TextConvWrapper::Convert()
     589             : {
     590           0 :     bStartChk = sal_False;
     591           0 :     ConvStart_impl( SVX_SPELL_BODY_END );
     592           0 :     ConvertDocument();
     593           0 :     ConvEnd_impl();
     594           0 : }
     595             : 
     596             : 
     597           0 : sal_Bool TextConvWrapper::HasRubySupport() const
     598             : {
     599           0 :     return sal_False;
     600             : }
     601             : 
     602             : //////////////////////////////////////////////////////////////////////
     603             : 
     604             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10