LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/editeng/source/editeng - impedit4.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 298 1600 18.6 %
Date: 2013-07-09 Functions: 21 60 35.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 <svl/srchitem.hxx>
      27             : #include <editeng/lspcitem.hxx>
      28             : #include <editeng/adjustitem.hxx>
      29             : #include <editeng/tstpitem.hxx>
      30             : 
      31             : #include <eertfpar.hxx>
      32             : #include <editeng/editeng.hxx>
      33             : #include <impedit.hxx>
      34             : #include <editeng/editview.hxx>
      35             : #include <eehtml.hxx>
      36             : #include <editobj2.hxx>
      37             : #include <i18nlangtag/lang.h>
      38             : 
      39             : #include "editxml.hxx"
      40             : 
      41             : #include <editeng/autokernitem.hxx>
      42             : #include <editeng/contouritem.hxx>
      43             : #include <editeng/colritem.hxx>
      44             : #include <editeng/crossedoutitem.hxx>
      45             : #include <editeng/escapementitem.hxx>
      46             : #include <editeng/fhgtitem.hxx>
      47             : #include <editeng/fontitem.hxx>
      48             : #include <editeng/kernitem.hxx>
      49             : #include <editeng/lrspitem.hxx>
      50             : #include <editeng/postitem.hxx>
      51             : #include <editeng/shdditem.hxx>
      52             : #include <editeng/udlnitem.hxx>
      53             : #include <editeng/ulspitem.hxx>
      54             : #include <editeng/wghtitem.hxx>
      55             : #include <editeng/langitem.hxx>
      56             : #include <editeng/charreliefitem.hxx>
      57             : #include <editeng/frmdiritem.hxx>
      58             : #include <editeng/emphasismarkitem.hxx>
      59             : #include <textconv.hxx>
      60             : #include <rtl/tencinfo.h>
      61             : #include <svtools/rtfout.hxx>
      62             : #include <edtspell.hxx>
      63             : #include <editeng/scripttypeitem.hxx>
      64             : #include <editeng/unolingu.hxx>
      65             : #include <linguistic/lngprops.hxx>
      66             : #include <com/sun/star/linguistic2/XThesaurus.hpp>
      67             : #include <com/sun/star/linguistic2/XMeaning.hpp>
      68             : #include <com/sun/star/i18n/ScriptType.hpp>
      69             : #include <com/sun/star/i18n/WordType.hpp>
      70             : #include <com/sun/star/i18n/TransliterationModules.hpp>
      71             : #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
      72             : #include <unotools/transliterationwrapper.hxx>
      73             : #include <unotools/textsearch.hxx>
      74             : #include <comphelper/processfactory.hxx>
      75             : #include <vcl/help.hxx>
      76             : #include <svtools/rtfkeywd.hxx>
      77             : #include <editeng/edtdlg.hxx>
      78             : 
      79             : #include <vector>
      80             : #include <boost/scoped_ptr.hpp>
      81             : 
      82             : using namespace ::com::sun::star;
      83             : using namespace ::com::sun::star::uno;
      84             : using namespace ::com::sun::star::beans;
      85             : using namespace ::com::sun::star::linguistic2;
      86             : 
      87           0 : void Swapsal_uIt16s( sal_uInt16& rX, sal_uInt16& rY )
      88             : {
      89           0 :     sal_uInt16 n = rX;
      90           0 :     rX = rY;
      91           0 :     rY = n;
      92           0 : }
      93             : 
      94           1 : EditPaM ImpEditEngine::Read( SvStream& rInput, const String& rBaseURL, EETextFormat eFormat, EditSelection aSel, SvKeyValueIterator* pHTTPHeaderAttrs )
      95             : {
      96           1 :     sal_Bool _bUpdate = GetUpdateMode();
      97           1 :     SetUpdateMode( sal_False );
      98           1 :     EditPaM aPaM;
      99           1 :     if ( eFormat == EE_FORMAT_TEXT )
     100           0 :         aPaM = ReadText( rInput, aSel );
     101           1 :     else if ( eFormat == EE_FORMAT_RTF )
     102           0 :         aPaM = ReadRTF( rInput, aSel );
     103           1 :     else if ( eFormat == EE_FORMAT_XML )
     104           0 :         aPaM = ReadXML( rInput, aSel );
     105           1 :     else if ( eFormat == EE_FORMAT_HTML )
     106           1 :         aPaM = ReadHTML( rInput, rBaseURL, aSel, pHTTPHeaderAttrs );
     107           0 :     else if ( eFormat == EE_FORMAT_BIN)
     108           0 :         aPaM = ReadBin( rInput, aSel );
     109             :     else
     110             :     {
     111             :         OSL_FAIL( "Read: Unknown Format" );
     112             :     }
     113             : 
     114           1 :     FormatFullDoc();        // perhaps a simple format is enough?
     115           1 :     SetUpdateMode( _bUpdate );
     116             : 
     117           1 :     return aPaM;
     118             : }
     119             : 
     120           0 : EditPaM ImpEditEngine::ReadText( SvStream& rInput, EditSelection aSel )
     121             : {
     122           0 :     if ( aSel.HasRange() )
     123           0 :         aSel = ImpDeleteSelection( aSel );
     124           0 :     EditPaM aPaM = aSel.Max();
     125             : 
     126           0 :     OUString aTmpStr;
     127           0 :     bool bDone = rInput.ReadByteStringLine( aTmpStr, rInput.GetStreamCharSet() );
     128           0 :     while ( bDone )
     129             :     {
     130           0 :         aTmpStr = aTmpStr.copy(0, MAXCHARSINPARA );
     131           0 :         aPaM = ImpInsertText( EditSelection( aPaM, aPaM ), aTmpStr );
     132           0 :         aPaM = ImpInsertParaBreak( aPaM );
     133           0 :         bDone = rInput.ReadByteStringLine( aTmpStr, rInput.GetStreamCharSet() );
     134             :     }
     135           0 :     return aPaM;
     136             : }
     137             : 
     138           0 : EditPaM ImpEditEngine::ReadXML( SvStream& rInput, EditSelection aSel )
     139             : {
     140           0 :     if ( aSel.HasRange() )
     141           0 :         aSel = ImpDeleteSelection( aSel );
     142             : 
     143           0 :     ESelection aESel = CreateESel( aSel );
     144             : 
     145           0 :     ::SvxReadXML( *GetEditEnginePtr(), rInput, aESel );
     146             : 
     147           0 :     return aSel.Max();
     148             : }
     149             : 
     150           0 : EditPaM ImpEditEngine::ReadRTF( SvStream& rInput, EditSelection aSel )
     151             : {
     152             : #if (OSL_DEBUG_LEVEL > 2) && !defined( UNX )
     153             :     SvFileStream aRTFOut( String( RTL_CONSTASCII_USTRINGPARAM ( "d:\\rtf_in.rtf" ) ), STREAM_WRITE );
     154             :     aRTFOut << rInput;
     155             :     aRTFOut.Close();
     156             :     rInput.Seek( 0 );
     157             : #endif
     158           0 :     if ( aSel.HasRange() )
     159           0 :         aSel = ImpDeleteSelection( aSel );
     160             : 
     161             :     // The SvRTF parser expects the Which-mapping passed on in the pool, not
     162             :     // dependant on a secondary.
     163           0 :     SfxItemPool* pPool = &aEditDoc.GetItemPool();
     164           0 :     while (pPool->GetSecondaryPool() && !pPool->GetName().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EditEngineItemPool")))
     165             :     {
     166           0 :         pPool = pPool->GetSecondaryPool();
     167             : 
     168             :     }
     169             : 
     170             :     DBG_ASSERT(pPool && pPool->GetName().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EditEngineItemPool")),
     171             :         "ReadRTF: no EditEnginePool!");
     172             : 
     173           0 :     EditRTFParserRef xPrsr = new EditRTFParser(rInput, aSel, *pPool, pEditEngine);
     174           0 :     SvParserState eState = xPrsr->CallParser();
     175           0 :     if ( ( eState != SVPAR_ACCEPTED ) && ( !rInput.GetError() ) )
     176             :     {
     177           0 :         rInput.SetError( EE_READWRITE_WRONGFORMAT );
     178           0 :         return aSel.Min();
     179             :     }
     180           0 :     return xPrsr->GetCurPaM();
     181             : }
     182             : 
     183           1 : EditPaM ImpEditEngine::ReadHTML( SvStream& rInput, const String& rBaseURL, EditSelection aSel, SvKeyValueIterator* pHTTPHeaderAttrs )
     184             : {
     185           1 :     if ( aSel.HasRange() )
     186           0 :         aSel = ImpDeleteSelection( aSel );
     187             : 
     188           1 :     EditHTMLParserRef xPrsr = new EditHTMLParser( rInput, rBaseURL, pHTTPHeaderAttrs );
     189           1 :     SvParserState eState = xPrsr->CallParser(pEditEngine, aSel.Max());
     190           1 :     if ( ( eState != SVPAR_ACCEPTED ) && ( !rInput.GetError() ) )
     191             :     {
     192           0 :         rInput.SetError( EE_READWRITE_WRONGFORMAT );
     193           0 :         return aSel.Min();
     194             :     }
     195           1 :     return xPrsr->GetCurSelection().Max();
     196             : }
     197             : 
     198           0 : EditPaM ImpEditEngine::ReadBin( SvStream& rInput, EditSelection aSel )
     199             : {
     200             :     // Simply abuse a temporary text object ...
     201           0 :     EditTextObject* pObj = EditTextObject::Create( rInput, NULL );
     202             : 
     203           0 :     EditPaM aLastPaM = aSel.Max();
     204           0 :     if ( pObj )
     205           0 :         aLastPaM = InsertText( *pObj, aSel ).Max();
     206             : 
     207           0 :     delete pObj;
     208           0 :     return aLastPaM;
     209             : }
     210             : 
     211           0 : void ImpEditEngine::Write( SvStream& rOutput, EETextFormat eFormat, EditSelection aSel )
     212             : {
     213           0 :     if ( !rOutput.IsWritable() )
     214           0 :         rOutput.SetError( SVSTREAM_WRITE_ERROR );
     215             : 
     216           0 :     if ( !rOutput.GetError() )
     217             :     {
     218           0 :         if ( eFormat == EE_FORMAT_TEXT )
     219           0 :             WriteText( rOutput, aSel );
     220           0 :         else if ( eFormat == EE_FORMAT_RTF )
     221           0 :             WriteRTF( rOutput, aSel );
     222           0 :         else if ( eFormat == EE_FORMAT_XML )
     223           0 :             WriteXML( rOutput, aSel );
     224           0 :         else if ( eFormat == EE_FORMAT_HTML )
     225           0 :             WriteHTML( rOutput, aSel );
     226           0 :         else if ( eFormat == EE_FORMAT_BIN)
     227           0 :             WriteBin( rOutput, aSel );
     228             :         else
     229             :         {
     230             :             OSL_FAIL( "Write: Unknown Format" );
     231             :         }
     232             :     }
     233           0 : }
     234             : 
     235           0 : sal_uInt32 ImpEditEngine::WriteText( SvStream& rOutput, EditSelection aSel )
     236             : {
     237             :     sal_Int32 nStartNode, nEndNode;
     238           0 :     sal_Bool bRange = aSel.HasRange();
     239           0 :     if ( bRange )
     240             :     {
     241           0 :         aSel.Adjust( aEditDoc );
     242           0 :         nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
     243           0 :         nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
     244             :     }
     245             :     else
     246             :     {
     247           0 :         nStartNode = 0;
     248           0 :         nEndNode = aEditDoc.Count()-1;
     249             :     }
     250             : 
     251             :     // iterate over the paragraphs ...
     252           0 :     for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++  )
     253             :     {
     254           0 :         ContentNode* pNode = aEditDoc.GetObject( nNode );
     255             :         DBG_ASSERT( pNode, "Node not founden: Search&Replace" );
     256             : 
     257           0 :         sal_uInt16 nStartPos = 0;
     258           0 :         sal_uInt16 nEndPos = pNode->Len();
     259           0 :         if ( bRange )
     260             :         {
     261           0 :             if ( nNode == nStartNode )
     262           0 :                 nStartPos = aSel.Min().GetIndex();
     263           0 :             if ( nNode == nEndNode ) // can also be == nStart!
     264           0 :                 nEndPos = aSel.Max().GetIndex();
     265             :         }
     266           0 :         XubString aTmpStr = aEditDoc.GetParaAsString( pNode, nStartPos, nEndPos );
     267           0 :         rOutput.WriteByteStringLine( aTmpStr, rOutput.GetStreamCharSet() );
     268           0 :     }
     269             : 
     270           0 :     return rOutput.GetError();
     271             : }
     272             : 
     273           0 : sal_Bool ImpEditEngine::WriteItemListAsRTF( ItemList& rLst, SvStream& rOutput, sal_Int32 nPara, sal_uInt16 nPos,
     274             :                         std::vector<SvxFontItem*>& rFontTable, SvxColorList& rColorList )
     275             : {
     276           0 :     const SfxPoolItem* pAttrItem = rLst.First();
     277           0 :     while ( pAttrItem )
     278             :     {
     279           0 :         WriteItemAsRTF( *pAttrItem, rOutput, nPara, nPos,rFontTable, rColorList );
     280           0 :         pAttrItem = rLst.Next();
     281             :     }
     282           0 :     return ( rLst.Count() ? sal_True : sal_False );
     283             : }
     284             : 
     285           0 : static void lcl_FindValidAttribs( ItemList& rLst, ContentNode* pNode, sal_uInt16 nIndex, sal_uInt16 nScriptType )
     286             : {
     287           0 :     sal_uInt16 nAttr = 0;
     288           0 :     EditCharAttrib* pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
     289           0 :     while ( pAttr && ( pAttr->GetStart() <= nIndex ) )
     290             :     {
     291             :         // Start is checked in while ...
     292           0 :         if ( pAttr->GetEnd() > nIndex )
     293             :         {
     294           0 :             if ( IsScriptItemValid( pAttr->GetItem()->Which(), nScriptType ) )
     295           0 :                 rLst.Insert( pAttr->GetItem() );
     296             :         }
     297           0 :         nAttr++;
     298           0 :         pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
     299             :     }
     300           0 : }
     301             : 
     302           0 : sal_uInt32 ImpEditEngine::WriteBin( SvStream& rOutput, EditSelection aSel, bool bStoreUnicodeStrings )
     303             : {
     304           0 :     boost::scoped_ptr<EditTextObject> pObj(CreateTextObject(aSel, NULL));
     305           0 :     pObj->mpImpl->StoreUnicodeStrings(bStoreUnicodeStrings);
     306           0 :     pObj->Store(rOutput);
     307           0 :     return 0;
     308             : }
     309             : 
     310           0 : sal_uInt32 ImpEditEngine::WriteXML( SvStream& rOutput, EditSelection aSel )
     311             : {
     312           0 :     ESelection aESel = CreateESel( aSel );
     313             : 
     314           0 :     SvxWriteXML( *GetEditEnginePtr(), rOutput, aESel );
     315             : 
     316           0 :     return 0;
     317             : }
     318             : 
     319           0 : static sal_uInt16 getStylePos( const SfxStyles& rStyles, SfxStyleSheet* pSheet )
     320             : {
     321           0 :     sal_uInt16 nNumber = 0;
     322           0 :     SfxStyles::const_iterator iter( rStyles.begin() );
     323           0 :     while( iter != rStyles.end() )
     324             :     {
     325           0 :         if( (*iter++).get() == pSheet )
     326           0 :             return nNumber;
     327           0 :         ++nNumber;
     328             :     }
     329           0 :     return 0;
     330             : }
     331             : 
     332           0 : sal_uInt32 ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel )
     333             : {
     334             :     DBG_ASSERT( GetUpdateMode(), "WriteRTF for UpdateMode = sal_False!" );
     335           0 :     CheckIdleFormatter();
     336           0 :     if ( !IsFormatted() )
     337           0 :         FormatDoc();
     338             : 
     339             :     sal_Int32 nStartNode, nEndNode;
     340           0 :     aSel.Adjust( aEditDoc );
     341             : 
     342           0 :     nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
     343           0 :     nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
     344             : 
     345             :     // RTF header ...
     346           0 :     rOutput << '{' ;
     347             : 
     348           0 :     rOutput << OOO_STRING_SVTOOLS_RTF_RTF;
     349             : 
     350           0 :     rOutput << OOO_STRING_SVTOOLS_RTF_ANSI;
     351           0 :     rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_MS_1252;
     352             : 
     353             :     // Generate and write out Font table  ...
     354           0 :     std::vector<SvxFontItem*> aFontTable;
     355             :     // default font must be up front, so DEF font in RTF
     356           0 :     aFontTable.push_back( new SvxFontItem( (const SvxFontItem&)aEditDoc.GetItemPool().GetDefaultItem( EE_CHAR_FONTINFO ) ) );
     357           0 :     aFontTable.push_back( new SvxFontItem( (const SvxFontItem&)aEditDoc.GetItemPool().GetDefaultItem( EE_CHAR_FONTINFO_CJK ) ) );
     358           0 :     aFontTable.push_back( new SvxFontItem( (const SvxFontItem&)aEditDoc.GetItemPool().GetDefaultItem( EE_CHAR_FONTINFO_CTL ) ) );
     359           0 :     for ( sal_uInt16 nScriptType = 0; nScriptType < 3; nScriptType++ )
     360             :     {
     361           0 :         sal_uInt16 nWhich = EE_CHAR_FONTINFO;
     362           0 :         if ( nScriptType == 1 )
     363           0 :             nWhich = EE_CHAR_FONTINFO_CJK;
     364           0 :         else if ( nScriptType == 2 )
     365           0 :             nWhich = EE_CHAR_FONTINFO_CTL;
     366             : 
     367           0 :         sal_uInt32 i = 0;
     368           0 :         SvxFontItem* pFontItem = (SvxFontItem*)aEditDoc.GetItemPool().GetItem2( nWhich, i );
     369           0 :         while ( pFontItem )
     370             :         {
     371           0 :             bool bAlreadyExist = false;
     372           0 :             sal_uLong nTestMax = nScriptType ? aFontTable.size() : 1;
     373           0 :             for ( sal_uLong nTest = 0; !bAlreadyExist && ( nTest < nTestMax ); nTest++ )
     374             :             {
     375           0 :                 bAlreadyExist = *aFontTable[ nTest ] == *pFontItem;
     376             :             }
     377             : 
     378           0 :             if ( !bAlreadyExist )
     379           0 :                 aFontTable.push_back( new SvxFontItem( *pFontItem ) );
     380             : 
     381           0 :             pFontItem = (SvxFontItem*)aEditDoc.GetItemPool().GetItem2( nWhich, ++i );
     382             :         }
     383             :     }
     384             : 
     385           0 :     rOutput << endl << '{' << OOO_STRING_SVTOOLS_RTF_FONTTBL;
     386             :     sal_uInt16 j;
     387           0 :     for ( j = 0; j < aFontTable.size(); j++ )
     388             :     {
     389           0 :         SvxFontItem* pFontItem = aFontTable[ j ];
     390           0 :         rOutput << '{';
     391           0 :         rOutput << OOO_STRING_SVTOOLS_RTF_F;
     392           0 :         rOutput.WriteNumber( static_cast<sal_uInt32>( j ) );
     393           0 :         switch ( pFontItem->GetFamily()  )
     394             :         {
     395           0 :             case FAMILY_DONTKNOW:       rOutput << OOO_STRING_SVTOOLS_RTF_FNIL;
     396           0 :                                         break;
     397           0 :             case FAMILY_DECORATIVE:     rOutput << OOO_STRING_SVTOOLS_RTF_FDECOR;
     398           0 :                                         break;
     399           0 :             case FAMILY_MODERN:         rOutput << OOO_STRING_SVTOOLS_RTF_FMODERN;
     400           0 :                                         break;
     401           0 :             case FAMILY_ROMAN:          rOutput << OOO_STRING_SVTOOLS_RTF_FROMAN;
     402           0 :                                         break;
     403           0 :             case FAMILY_SCRIPT:         rOutput << OOO_STRING_SVTOOLS_RTF_FSCRIPT;
     404           0 :                                         break;
     405           0 :             case FAMILY_SWISS:          rOutput << OOO_STRING_SVTOOLS_RTF_FSWISS;
     406           0 :                                         break;
     407             :             default:
     408           0 :                 break;
     409             :         }
     410           0 :         rOutput << OOO_STRING_SVTOOLS_RTF_FPRQ;
     411           0 :         sal_uInt16 nVal = 0;
     412           0 :         switch( pFontItem->GetPitch() )
     413             :         {
     414           0 :             case PITCH_FIXED:       nVal = 1;       break;
     415           0 :             case PITCH_VARIABLE:    nVal = 2;       break;
     416             :             default:
     417           0 :                 break;
     418             :         }
     419           0 :         rOutput.WriteNumber( static_cast<sal_uInt32>( nVal ) );
     420             : 
     421           0 :         CharSet eChrSet = pFontItem->GetCharSet();
     422             :         DBG_ASSERT( eChrSet != 9, "SystemCharSet?!" );
     423           0 :         if( RTL_TEXTENCODING_DONTKNOW == eChrSet )
     424           0 :             eChrSet = osl_getThreadTextEncoding();
     425           0 :         rOutput << OOO_STRING_SVTOOLS_RTF_FCHARSET;
     426           0 :         rOutput.WriteNumber( static_cast<sal_uInt32>( rtl_getBestWindowsCharsetFromTextEncoding( eChrSet ) ) );
     427             : 
     428           0 :         rOutput << ' ';
     429           0 :         RTFOutFuncs::Out_String( rOutput, pFontItem->GetFamilyName(), eDestEnc );
     430           0 :         rOutput << ";}";
     431             :     }
     432           0 :     rOutput << '}';
     433           0 :     rOutput << endl;
     434             : 
     435             :     // Write out ColorList  ...
     436           0 :     SvxColorList aColorList;
     437           0 :     sal_uInt32 i = 0;
     438           0 :     SvxColorItem* pColorItem = (SvxColorItem*)aEditDoc.GetItemPool().GetItem2( EE_CHAR_COLOR, i );
     439           0 :     while ( pColorItem )
     440             :     {
     441           0 :         sal_uInt32 nPos = i;
     442           0 :         if ( pColorItem->GetValue() == COL_AUTO )
     443           0 :             nPos = 0;
     444           0 :         aColorList.Insert( new SvxColorItem( *pColorItem ), nPos );
     445           0 :         pColorItem = (SvxColorItem*)aEditDoc.GetItemPool().GetItem2( EE_CHAR_COLOR, ++i );
     446             :     }
     447           0 :     aColorList.Insert( new SvxColorItem( (const SvxColorItem&)aEditDoc.GetItemPool().GetDefaultItem( EE_CHAR_COLOR) ), i );
     448             : 
     449           0 :     rOutput << '{' << OOO_STRING_SVTOOLS_RTF_COLORTBL;
     450           0 :     for ( j = 0; j < aColorList.Count(); j++ )
     451             :     {
     452           0 :         pColorItem = aColorList.GetObject( j );
     453           0 :         if ( !j || ( pColorItem->GetValue() != COL_AUTO ) )
     454             :         {
     455           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_RED;
     456           0 :             rOutput.WriteNumber( static_cast<sal_uInt32>(pColorItem->GetValue().GetRed()) );
     457           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_GREEN;
     458           0 :             rOutput.WriteNumber( static_cast<sal_uInt32>(pColorItem->GetValue().GetGreen()) );
     459           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_BLUE;
     460           0 :             rOutput.WriteNumber( static_cast<sal_uInt32>(pColorItem->GetValue().GetBlue()) );
     461             :         }
     462           0 :         rOutput << ';';
     463             :     }
     464           0 :     rOutput << '}';
     465           0 :     rOutput << endl;
     466             : 
     467             :     // StyleSheets...
     468           0 :     if ( GetStyleSheetPool() )
     469             :     {
     470           0 :         sal_uInt16 nStyles = (sal_uInt16)GetStyleSheetPool()->GetStyles().size();
     471           0 :         if ( nStyles )
     472             :         {
     473           0 :             rOutput << '{' << OOO_STRING_SVTOOLS_RTF_STYLESHEET;
     474             : 
     475           0 :             for ( sal_uInt16 nStyle = 0; nStyle < nStyles; nStyle++ )
     476             :             {
     477             : 
     478           0 :                 SfxStyleSheet* pStyle = (SfxStyleSheet*)GetStyleSheetPool()->GetStyles()[ nStyle ].get();
     479             : 
     480           0 :                 rOutput << endl << '{' << OOO_STRING_SVTOOLS_RTF_S;
     481           0 :                 sal_uInt32 nNumber = nStyle + 1;
     482           0 :                 rOutput.WriteNumber( nNumber );
     483             : 
     484             :                 // Attribute, alos from Parent!
     485           0 :                 for ( sal_uInt16 nParAttr = EE_PARA_START; nParAttr <= EE_CHAR_END; nParAttr++ )
     486             :                 {
     487           0 :                     if ( pStyle->GetItemSet().GetItemState( nParAttr ) == SFX_ITEM_ON )
     488             :                     {
     489           0 :                         const SfxPoolItem& rItem = pStyle->GetItemSet().Get( nParAttr );
     490           0 :                         WriteItemAsRTF( rItem, rOutput, 0, 0, aFontTable, aColorList );
     491             :                     }
     492             :                 }
     493             : 
     494             :                 // Parent ... (only if necessary)
     495           0 :                 if ( !pStyle->GetParent().isEmpty() && ( pStyle->GetParent() != pStyle->GetName() ) )
     496             :                 {
     497           0 :                     SfxStyleSheet* pParent = (SfxStyleSheet*)GetStyleSheetPool()->Find( pStyle->GetParent(), pStyle->GetFamily() );
     498             :                     DBG_ASSERT( pParent, "Parent not found!" );
     499           0 :                     rOutput << OOO_STRING_SVTOOLS_RTF_SBASEDON;
     500           0 :                     nNumber = getStylePos( GetStyleSheetPool()->GetStyles(), pParent ) + 1;
     501           0 :                     rOutput.WriteNumber( nNumber );
     502             :                 }
     503             : 
     504             :                 // Next Style ... (more)
     505           0 :                 SfxStyleSheet* pNext = pStyle;
     506           0 :                 if ( !pStyle->GetFollow().isEmpty() && ( pStyle->GetFollow() != pStyle->GetName() ) )
     507           0 :                     pNext = (SfxStyleSheet*)GetStyleSheetPool()->Find( pStyle->GetFollow(), pStyle->GetFamily() );
     508             : 
     509             :                 DBG_ASSERT( pNext, "Next ot found!" );
     510           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_SNEXT;
     511           0 :                 nNumber = getStylePos( GetStyleSheetPool()->GetStyles(), pNext ) + 1;
     512           0 :                 rOutput.WriteNumber( nNumber );
     513             : 
     514             :                 // Name of the template ...
     515           0 :                 rOutput << " " << OUStringToOString(pStyle->GetName(), eDestEnc).getStr();
     516           0 :                 rOutput << ";}";
     517             :             }
     518           0 :             rOutput << '}';
     519           0 :             rOutput << endl;
     520             :         }
     521             :     }
     522             : 
     523             :     // Write the pool defaults in advance ...
     524           0 :     rOutput << '{' << OOO_STRING_SVTOOLS_RTF_IGNORE << "\\EditEnginePoolDefaults";
     525           0 :     for ( sal_uInt16 nPoolDefItem = EE_PARA_START; nPoolDefItem <= EE_CHAR_END; nPoolDefItem++)
     526             :     {
     527           0 :         const SfxPoolItem& rItem = aEditDoc.GetItemPool().GetDefaultItem( nPoolDefItem );
     528           0 :         WriteItemAsRTF( rItem, rOutput, 0, 0, aFontTable, aColorList );
     529             :     }
     530           0 :     rOutput << '}' << endl;
     531             : 
     532             :     // DefTab:
     533           0 :     MapMode aTwpMode( MAP_TWIP );
     534             :     sal_uInt16 nDefTabTwps = (sal_uInt16) GetRefDevice()->LogicToLogic(
     535           0 :                                         Point( aEditDoc.GetDefTab(), 0 ),
     536           0 :                                         &GetRefMapMode(), &aTwpMode ).X();
     537           0 :     rOutput << OOO_STRING_SVTOOLS_RTF_DEFTAB;
     538           0 :     rOutput.WriteNumber( static_cast<sal_uInt32>( nDefTabTwps ) );
     539           0 :     rOutput << endl;
     540             : 
     541             :     // iterate over the paragraphs ...
     542           0 :     rOutput << '{' << endl;
     543           0 :     for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++  )
     544             :     {
     545           0 :         ContentNode* pNode = aEditDoc.GetObject( nNode );
     546             :         DBG_ASSERT( pNode, "Node not found: Search&Replace" );
     547             : 
     548             :         // The paragraph attributes in advance ...
     549           0 :         sal_Bool bAttr = sal_False;
     550             : 
     551             :         // Template?
     552           0 :         if ( pNode->GetStyleSheet() )
     553             :         {
     554             :             // Number of template
     555           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_S;
     556           0 :             sal_uInt32 nNumber = getStylePos( GetStyleSheetPool()->GetStyles(), pNode->GetStyleSheet() ) + 1;
     557           0 :             rOutput.WriteNumber( nNumber );
     558             : 
     559             :             // All Attribute
     560             :             // Attribute, also from Parent!
     561           0 :             for ( sal_uInt16 nParAttr = EE_PARA_START; nParAttr <= EE_CHAR_END; nParAttr++ )
     562             :             {
     563           0 :                 if ( pNode->GetStyleSheet()->GetItemSet().GetItemState( nParAttr ) == SFX_ITEM_ON )
     564             :                 {
     565           0 :                     const SfxPoolItem& rItem = pNode->GetStyleSheet()->GetItemSet().Get( nParAttr );
     566           0 :                     WriteItemAsRTF( rItem, rOutput, nNode, 0, aFontTable, aColorList );
     567           0 :                     bAttr = sal_True;
     568             :                 }
     569             :             }
     570             :         }
     571             : 
     572           0 :         for ( sal_uInt16 nParAttr = EE_PARA_START; nParAttr <= EE_CHAR_END; nParAttr++ )
     573             :         {
     574             :             // Now where stylesheet processing, only hard paragraph attributes!
     575           0 :             if ( pNode->GetContentAttribs().GetItems().GetItemState( nParAttr ) == SFX_ITEM_ON )
     576             :             {
     577           0 :                 const SfxPoolItem& rItem = pNode->GetContentAttribs().GetItems().Get( nParAttr );
     578           0 :                 WriteItemAsRTF( rItem, rOutput, nNode, 0, aFontTable, aColorList );
     579           0 :                 bAttr = sal_True;
     580             :             }
     581             :         }
     582           0 :         if ( bAttr )
     583           0 :             rOutput << ' '; // Separator
     584             : 
     585           0 :         ItemList aAttribItems;
     586           0 :         ParaPortion* pParaPortion = FindParaPortion( pNode );
     587             :         DBG_ASSERT( pParaPortion, "Portion not found: WriteRTF" );
     588             : 
     589           0 :         sal_uInt16 nIndex = 0;
     590           0 :         sal_uInt16 nStartPos = 0;
     591           0 :         sal_uInt16 nEndPos = pNode->Len();
     592           0 :         sal_uInt16 nStartPortion = 0;
     593           0 :         sal_uInt16 nEndPortion = (sal_uInt16)pParaPortion->GetTextPortions().Count() - 1;
     594           0 :         sal_Bool bFinishPortion = sal_False;
     595             :         sal_uInt16 nPortionStart;
     596             : 
     597           0 :         if ( nNode == nStartNode )
     598             :         {
     599           0 :             nStartPos = aSel.Min().GetIndex();
     600           0 :             nStartPortion = pParaPortion->GetTextPortions().FindPortion( nStartPos, nPortionStart );
     601           0 :             if ( nStartPos != 0 )
     602             :             {
     603           0 :                 aAttribItems.Clear();
     604           0 :                 lcl_FindValidAttribs( aAttribItems, pNode, nStartPos, GetScriptType( EditPaM( pNode, 0 ) ) );
     605           0 :                 if ( aAttribItems.Count() )
     606             :                 {
     607             :                     // These attributes may not apply to the entire paragraph:
     608           0 :                     rOutput << '{';
     609           0 :                     WriteItemListAsRTF( aAttribItems, rOutput, nNode, nStartPos, aFontTable, aColorList );
     610           0 :                     bFinishPortion = sal_True;
     611             :                 }
     612           0 :                 aAttribItems.Clear();
     613             :             }
     614             :         }
     615           0 :         if ( nNode == nEndNode ) // can also be == nStart!
     616             :         {
     617           0 :             nEndPos = aSel.Max().GetIndex();
     618           0 :             nEndPortion = pParaPortion->GetTextPortions().FindPortion( nEndPos, nPortionStart );
     619             :         }
     620             : 
     621           0 :         const EditCharAttrib* pNextFeature = pNode->GetCharAttribs().FindFeature(nIndex);
     622             :         // start at 0, so the index is right ...
     623           0 :         for ( sal_uInt16 n = 0; n <= nEndPortion; n++ )
     624             :         {
     625           0 :             const TextPortion* pTextPortion = pParaPortion->GetTextPortions()[n];
     626           0 :             if ( n < nStartPortion )
     627             :             {
     628           0 :                 nIndex = nIndex + pTextPortion->GetLen();
     629           0 :                 continue;
     630             :             }
     631             : 
     632           0 :             if ( pNextFeature && ( pNextFeature->GetStart() == nIndex ) && ( pNextFeature->GetItem()->Which() != EE_FEATURE_FIELD ) )
     633             :             {
     634           0 :                 WriteItemAsRTF( *pNextFeature->GetItem(), rOutput, nNode, nIndex, aFontTable, aColorList );
     635           0 :                 pNextFeature = pNode->GetCharAttribs().FindFeature( pNextFeature->GetStart() + 1 );
     636             :             }
     637             :             else
     638             :             {
     639           0 :                 aAttribItems.Clear();
     640           0 :                 sal_uInt16 nScriptType = GetScriptType( EditPaM( pNode, nIndex+1 ) );
     641           0 :                 if ( !n || IsScriptChange( EditPaM( pNode, nIndex ) ) )
     642             :                 {
     643           0 :                     SfxItemSet aAttribs = GetAttribs( nNode, nIndex+1, nIndex+1 );
     644           0 :                     aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_FONTINFO, nScriptType ) ) );
     645           0 :                     aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_FONTHEIGHT, nScriptType ) ) );
     646           0 :                     aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_WEIGHT, nScriptType ) ) );
     647           0 :                     aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_ITALIC, nScriptType ) ) );
     648           0 :                     aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_LANGUAGE, nScriptType ) ) );
     649             :                 }
     650             :                 // Insert hard attribs AFTER CJK attribs...
     651           0 :                 lcl_FindValidAttribs( aAttribItems, pNode, nIndex, nScriptType );
     652             : 
     653           0 :                 rOutput << '{';
     654           0 :                 if ( WriteItemListAsRTF( aAttribItems, rOutput, nNode, nIndex, aFontTable, aColorList ) )
     655           0 :                     rOutput << ' ';
     656             : 
     657           0 :                 sal_uInt16 nS = nIndex;
     658           0 :                 sal_uInt16 nE = nIndex + pTextPortion->GetLen();
     659           0 :                 if ( n == nStartPortion )
     660           0 :                     nS = nStartPos;
     661           0 :                 if ( n == nEndPortion )
     662           0 :                     nE = nEndPos;
     663             : 
     664           0 :                 XubString aRTFStr = aEditDoc.GetParaAsString( pNode, nS, nE);
     665           0 :                 RTFOutFuncs::Out_String( rOutput, aRTFStr, eDestEnc );
     666           0 :                 rOutput << '}';
     667             :             }
     668           0 :             if ( bFinishPortion )
     669             :             {
     670           0 :                 rOutput << '}';
     671           0 :                 bFinishPortion = sal_False;
     672             :             }
     673             : 
     674           0 :             nIndex = nIndex + pTextPortion->GetLen();
     675             :         }
     676             : 
     677           0 :         rOutput << OOO_STRING_SVTOOLS_RTF_PAR << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_PLAIN;;
     678           0 :         rOutput << endl;
     679           0 :     }
     680             :     // RTF-trailer ...
     681           0 :     rOutput << "}}";    // 1xparentheses paragraphs, 1xparentheses RTF document
     682           0 :     rOutput.Flush();
     683             : 
     684           0 :     std::vector<SvxFontItem*>::iterator it;
     685           0 :     for (it = aFontTable.begin(); it != aFontTable.end(); ++it)
     686           0 :         delete *it;
     687             : 
     688             : #if (OSL_DEBUG_LEVEL > 2) && !defined( UNX )
     689             :     {
     690             :         SvFileStream aStream( String( RTL_CONSTASCII_USTRINGPARAM ( "d:\\rtf_out.rtf" ) ), STREAM_WRITE|STREAM_TRUNC );
     691             :         sal_uLong nP = rOutput.Tell();
     692             :         rOutput.Seek( 0 );
     693             :         aStream << rOutput;
     694             :         rOutput.Seek( nP );
     695             :     }
     696             : #endif
     697             : 
     698           0 :     return rOutput.GetError();
     699             : }
     700             : 
     701             : 
     702           0 : void ImpEditEngine::WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput, sal_Int32 nPara, sal_uInt16 nPos,
     703             :                             std::vector<SvxFontItem*>& rFontTable, SvxColorList& rColorList )
     704             : {
     705           0 :     sal_uInt16 nWhich = rItem.Which();
     706           0 :     switch ( nWhich )
     707             :     {
     708             :         case EE_PARA_WRITINGDIR:
     709             :         {
     710           0 :             const SvxFrameDirectionItem& rWritingMode = (const SvxFrameDirectionItem&)rItem;
     711           0 :             if ( rWritingMode.GetValue() == FRMDIR_HORI_RIGHT_TOP )
     712           0 :                 rOutput << "\\rtlpar";
     713             :             else
     714           0 :                 rOutput << "\\ltrpar";
     715             :         }
     716           0 :         break;
     717             :         case EE_PARA_OUTLLEVEL:
     718             :         {
     719           0 :             sal_Int32 nLevel = ((const SfxInt16Item&)rItem).GetValue();
     720           0 :             if( nLevel >= 0 )
     721             :             {
     722           0 :                 rOutput << "\\level";
     723           0 :                 rOutput.WriteNumber( nLevel );
     724             :             }
     725             :         }
     726           0 :         break;
     727             :         case EE_PARA_OUTLLRSPACE:
     728             :         case EE_PARA_LRSPACE:
     729             :         {
     730           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_FI;
     731           0 :             sal_Int32 nTxtFirst = ((const SvxLRSpaceItem&)rItem).GetTxtFirstLineOfst();
     732           0 :             nTxtFirst = LogicToTwips( nTxtFirst );
     733           0 :             rOutput.WriteNumber( nTxtFirst );
     734           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_LI;
     735           0 :             sal_uInt32 nTxtLeft = static_cast< sal_uInt32 >(((const SvxLRSpaceItem&)rItem).GetTxtLeft());
     736           0 :             nTxtLeft = (sal_uInt32)LogicToTwips( nTxtLeft );
     737           0 :             rOutput.WriteNumber( nTxtLeft );
     738           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_RI;
     739           0 :             sal_uInt32 nTxtRight = ((const SvxLRSpaceItem&)rItem).GetRight();
     740           0 :             nTxtRight = LogicToTwips( nTxtRight);
     741           0 :             rOutput.WriteNumber( nTxtRight );
     742             :         }
     743           0 :         break;
     744             :         case EE_PARA_ULSPACE:
     745             :         {
     746           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_SB;
     747           0 :             sal_uInt32 nUpper = ((const SvxULSpaceItem&)rItem).GetUpper();
     748           0 :             nUpper = (sal_uInt32)LogicToTwips( nUpper );
     749           0 :             rOutput.WriteNumber( nUpper );
     750           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_SA;
     751           0 :             sal_uInt32 nLower = ((const SvxULSpaceItem&)rItem).GetLower();
     752           0 :             nLower = LogicToTwips( nLower );
     753           0 :             rOutput.WriteNumber( nLower );
     754             :         }
     755           0 :         break;
     756             :         case EE_PARA_SBL:
     757             :         {
     758           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_SL;
     759           0 :             sal_Int32 nVal = ((const SvxLineSpacingItem&)rItem).GetLineHeight();
     760           0 :             char cMult = '0';
     761           0 :             if ( ((const SvxLineSpacingItem&)rItem).GetInterLineSpaceRule() == SVX_INTER_LINE_SPACE_PROP )
     762             :             {
     763             :                 // From where do I get the value now?
     764             :                 // The SwRTF parser is based on a 240 Font!
     765           0 :                 nVal = ((const SvxLineSpacingItem&)rItem).GetPropLineSpace();
     766           0 :                 nVal *= 240;
     767           0 :                 nVal /= 100;
     768           0 :                 cMult = '1';
     769             :             }
     770           0 :             rOutput.WriteNumber( nVal );
     771           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_SLMULT << cMult;
     772             :         }
     773           0 :         break;
     774             :         case EE_PARA_JUST:
     775             :         {
     776           0 :             SvxAdjust eJustification = ((const SvxAdjustItem&)rItem).GetAdjust();
     777           0 :             switch ( eJustification )
     778             :             {
     779           0 :                 case SVX_ADJUST_CENTER: rOutput << OOO_STRING_SVTOOLS_RTF_QC;
     780           0 :                                         break;
     781           0 :                 case SVX_ADJUST_RIGHT:  rOutput << OOO_STRING_SVTOOLS_RTF_QR;
     782           0 :                                         break;
     783           0 :                 default:                rOutput << OOO_STRING_SVTOOLS_RTF_QL;
     784           0 :                                         break;
     785             :             }
     786             :         }
     787           0 :         break;
     788             :         case EE_PARA_TABS:
     789             :         {
     790           0 :             const SvxTabStopItem& rTabs = (const SvxTabStopItem&) rItem;
     791           0 :             for ( sal_uInt16 i = 0; i < rTabs.Count(); i++ )
     792             :             {
     793           0 :                 const SvxTabStop& rTab = rTabs[i];
     794           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_TX;
     795           0 :                 rOutput.WriteNumber( LogicToTwips( rTab.GetTabPos() ) );
     796             :             }
     797             :         }
     798           0 :         break;
     799             :         case EE_CHAR_COLOR:
     800             :         {
     801           0 :             sal_uInt32 n = rColorList.GetId( (const SvxColorItem&)rItem );
     802           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_CF;
     803           0 :             rOutput.WriteNumber( n );
     804             :         }
     805           0 :         break;
     806             :         case EE_CHAR_FONTINFO:
     807             :         case EE_CHAR_FONTINFO_CJK:
     808             :         case EE_CHAR_FONTINFO_CTL:
     809             :         {
     810           0 :             sal_uInt32 n = 0;
     811           0 :             for (size_t i = 0; i < rFontTable.size(); ++i)
     812             :             {
     813           0 :                 if (*rFontTable[i] == rItem)
     814             :                 {
     815           0 :                     n = i;
     816           0 :                     break;
     817             :                 }
     818             :             }
     819             : 
     820           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_F;
     821           0 :             rOutput.WriteNumber( n );
     822             :         }
     823           0 :         break;
     824             :         case EE_CHAR_FONTHEIGHT:
     825             :         case EE_CHAR_FONTHEIGHT_CJK:
     826             :         case EE_CHAR_FONTHEIGHT_CTL:
     827             :         {
     828           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_FS;
     829           0 :             sal_Int32 nHeight = ((const SvxFontHeightItem&)rItem).GetHeight();
     830           0 :             nHeight = LogicToTwips( nHeight );
     831             :             // Twips => HalfPoints
     832           0 :             nHeight /= 10;
     833           0 :             rOutput.WriteNumber( nHeight );
     834             :         }
     835           0 :         break;
     836             :         case EE_CHAR_WEIGHT:
     837             :         case EE_CHAR_WEIGHT_CJK:
     838             :         case EE_CHAR_WEIGHT_CTL:
     839             :         {
     840           0 :             FontWeight e = ((const SvxWeightItem&)rItem).GetWeight();
     841           0 :             switch ( e )
     842             :             {
     843           0 :                 case WEIGHT_BOLD:   rOutput << OOO_STRING_SVTOOLS_RTF_B;                break;
     844           0 :                 default:            rOutput << OOO_STRING_SVTOOLS_RTF_B << '0';     break;
     845             :             }
     846             :         }
     847           0 :         break;
     848             :         case EE_CHAR_UNDERLINE:
     849             :         {
     850             :             // Must underlined if in WordLineMode, but the information is
     851             :             // missing here
     852           0 :             FontUnderline e = ((const SvxUnderlineItem&)rItem).GetLineStyle();
     853           0 :             switch ( e )
     854             :             {
     855           0 :                 case UNDERLINE_NONE:    rOutput << OOO_STRING_SVTOOLS_RTF_ULNONE;       break;
     856           0 :                 case UNDERLINE_SINGLE:  rOutput << OOO_STRING_SVTOOLS_RTF_UL;       break;
     857           0 :                 case UNDERLINE_DOUBLE:  rOutput << OOO_STRING_SVTOOLS_RTF_ULDB;     break;
     858           0 :                 case UNDERLINE_DOTTED:  rOutput << OOO_STRING_SVTOOLS_RTF_ULD;      break;
     859             :                 default:
     860           0 :                     break;
     861             :             }
     862             :         }
     863           0 :         break;
     864             :         case EE_CHAR_OVERLINE:
     865             :         {
     866           0 :             FontUnderline e = ((const SvxOverlineItem&)rItem).GetLineStyle();
     867           0 :             switch ( e )
     868             :             {
     869           0 :                 case UNDERLINE_NONE:    rOutput << OOO_STRING_SVTOOLS_RTF_OLNONE;       break;
     870           0 :                 case UNDERLINE_SINGLE:  rOutput << OOO_STRING_SVTOOLS_RTF_OL;       break;
     871           0 :                 case UNDERLINE_DOUBLE:  rOutput << OOO_STRING_SVTOOLS_RTF_OLDB;     break;
     872           0 :                 case UNDERLINE_DOTTED:  rOutput << OOO_STRING_SVTOOLS_RTF_OLD;      break;
     873             :                 default:
     874           0 :                     break;
     875             :             }
     876             :         }
     877           0 :         break;
     878             :         case EE_CHAR_STRIKEOUT:
     879             :         {
     880           0 :             FontStrikeout e = ((const SvxCrossedOutItem&)rItem).GetStrikeout();
     881           0 :             switch ( e )
     882             :             {
     883             :                 case STRIKEOUT_SINGLE:
     884           0 :                 case STRIKEOUT_DOUBLE:  rOutput << OOO_STRING_SVTOOLS_RTF_STRIKE;       break;
     885           0 :                 case STRIKEOUT_NONE:    rOutput << OOO_STRING_SVTOOLS_RTF_STRIKE << '0';    break;
     886             :                 default:
     887           0 :                     break;
     888             :             }
     889             :         }
     890           0 :         break;
     891             :         case EE_CHAR_ITALIC:
     892             :         case EE_CHAR_ITALIC_CJK:
     893             :         case EE_CHAR_ITALIC_CTL:
     894             :         {
     895           0 :             FontItalic e = ((const SvxPostureItem&)rItem).GetPosture();
     896           0 :             switch ( e )
     897             :             {
     898             :                 case ITALIC_OBLIQUE:
     899           0 :                 case ITALIC_NORMAL: rOutput << OOO_STRING_SVTOOLS_RTF_I;        break;
     900           0 :                 case ITALIC_NONE:   rOutput << OOO_STRING_SVTOOLS_RTF_I << '0'; break;
     901             :                 default:
     902           0 :                     break;
     903             :             }
     904             :         }
     905           0 :         break;
     906             :         case EE_CHAR_OUTLINE:
     907             :         {
     908           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_OUTL;
     909           0 :             if ( ((const SvxContourItem&)rItem).GetValue() == 0 )
     910           0 :                 rOutput << '0';
     911             :         }
     912           0 :         break;
     913             :         case EE_CHAR_RELIEF:
     914             :         {
     915           0 :             sal_uInt16 nRelief = ((const SvxCharReliefItem&)rItem).GetValue();
     916           0 :             if ( nRelief == RELIEF_EMBOSSED )
     917           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_EMBO;
     918           0 :             if ( nRelief == RELIEF_ENGRAVED )
     919           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_IMPR;
     920             :         }
     921           0 :         break;
     922             :         case EE_CHAR_EMPHASISMARK:
     923             :         {
     924           0 :             sal_uInt16 nMark = ((const SvxEmphasisMarkItem&)rItem).GetValue();
     925           0 :             if ( nMark == EMPHASISMARK_NONE )
     926           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_ACCNONE;
     927           0 :             else if ( nMark == EMPHASISMARK_SIDE_DOTS )
     928           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_ACCCOMMA;
     929             :             else
     930           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_ACCDOT;
     931             :         }
     932           0 :         break;
     933             :         case EE_CHAR_SHADOW:
     934             :         {
     935           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_SHAD;
     936           0 :             if ( ((const SvxShadowedItem&)rItem).GetValue() == 0 )
     937           0 :                 rOutput << '0';
     938             :         }
     939           0 :         break;
     940             :         case EE_FEATURE_TAB:
     941             :         {
     942           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_TAB;
     943             :         }
     944           0 :         break;
     945             :         case EE_FEATURE_LINEBR:
     946             :         {
     947           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_SL;
     948             :         }
     949           0 :         break;
     950             :         case EE_CHAR_KERNING:
     951             :         {
     952           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_EXPNDTW;
     953             :             rOutput.WriteNumber( LogicToTwips(
     954           0 :                 ((const SvxKerningItem&)rItem).GetValue() ) );
     955             :         }
     956           0 :         break;
     957             :         case EE_CHAR_PAIRKERNING:
     958             :         {
     959           0 :             rOutput << OOO_STRING_SVTOOLS_RTF_KERNING;
     960           0 :             rOutput.WriteNumber( static_cast<sal_uInt32>(((const SvxAutoKernItem&)rItem).GetValue() ? 1 : 0 ));
     961             :         }
     962           0 :         break;
     963             :         case EE_CHAR_ESCAPEMENT:
     964             :         {
     965           0 :             SvxFont aFont;
     966           0 :             ContentNode* pNode = aEditDoc.GetObject( nPara );
     967           0 :             SeekCursor( pNode, nPos, aFont );
     968           0 :             MapMode aPntMode( MAP_POINT );
     969             :             long nFontHeight = GetRefDevice()->LogicToLogic(
     970           0 :                     aFont.GetSize(), &GetRefMapMode(), &aPntMode ).Height();
     971           0 :             nFontHeight *=2;    // HalfP oints
     972           0 :             sal_uInt16 nProp = ((const SvxEscapementItem&)rItem).GetProp();
     973           0 :             sal_uInt16 nProp100 = nProp*100;    // For SWG-Token Prop in 100th percent.
     974           0 :             short nEsc = ((const SvxEscapementItem&)rItem).GetEsc();
     975           0 :             if ( nEsc == DFLT_ESC_AUTO_SUPER )
     976             :             {
     977           0 :                 nEsc = 100 - nProp;
     978           0 :                 nProp100++; // A 1 afterwards means 'automatic'.
     979             :             }
     980           0 :             else if ( nEsc == DFLT_ESC_AUTO_SUB )
     981             :             {
     982           0 :                 nEsc = sal::static_int_cast< short >( -( 100 - nProp ) );
     983           0 :                 nProp100++;
     984             :             }
     985             :             // SWG:
     986           0 :             if ( nEsc )
     987             :             {
     988           0 :                 rOutput << "{\\*\\updnprop" << OString::valueOf(
     989           0 :                     static_cast<sal_Int32>(nProp100)).getStr() << '}';
     990             :             }
     991           0 :             long nUpDown = nFontHeight * std::abs( nEsc ) / 100;
     992             :             OString aUpDown = OString::valueOf(
     993           0 :                 static_cast<sal_Int32>(nUpDown));
     994           0 :             if ( nEsc < 0 )
     995           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_DN << aUpDown.getStr();
     996           0 :             else if ( nEsc > 0 )
     997           0 :                 rOutput << OOO_STRING_SVTOOLS_RTF_UP << aUpDown.getStr();
     998             :         }
     999           0 :         break;
    1000             :     }
    1001           0 : }
    1002             : 
    1003           0 : sal_uInt32 ImpEditEngine::WriteHTML( SvStream&, EditSelection )
    1004             : {
    1005           0 :     return 0;
    1006             : }
    1007             : 
    1008             : 
    1009        7014 : EditTextObject* ImpEditEngine::CreateTextObject()
    1010             : {
    1011        7014 :     EditSelection aCompleteSelection;
    1012        7014 :     aCompleteSelection.Min() = aEditDoc.GetStartPaM();
    1013        7014 :     aCompleteSelection.Max() = aEditDoc.GetEndPaM();
    1014             : 
    1015        7014 :     return CreateTextObject( aCompleteSelection );
    1016             : }
    1017             : 
    1018       42369 : EditTextObject* ImpEditEngine::CreateTextObject( EditSelection aSel )
    1019             : {
    1020       42369 :     return CreateTextObject( aSel, GetEditTextObjectPool(), aStatus.AllowBigObjects(), nBigTextObjectStart );
    1021             : }
    1022             : 
    1023       42369 : EditTextObject* ImpEditEngine::CreateTextObject( EditSelection aSel, SfxItemPool* pPool, sal_Bool bAllowBigObjects, sal_uInt16 nBigObjectStart )
    1024             : {
    1025       42369 :     EditTextObject* pTxtObj = new EditTextObject(pPool);
    1026       42369 :     pTxtObj->SetVertical( IsVertical() );
    1027       42369 :     MapUnit eMapUnit = (MapUnit)aEditDoc.GetItemPool().GetMetric( DEF_METRIC );
    1028       42369 :     pTxtObj->mpImpl->SetMetric( (sal_uInt16) eMapUnit );
    1029       42369 :     if ( pTxtObj->mpImpl->IsOwnerOfPool() )
    1030        6543 :         pTxtObj->mpImpl->GetPool()->SetDefaultMetric( (SfxMapUnit) eMapUnit );
    1031             : 
    1032             :     sal_Int32 nStartNode, nEndNode;
    1033       42369 :     sal_uInt32 nTextPortions = 0;
    1034             : 
    1035       42369 :     aSel.Adjust( aEditDoc );
    1036       42369 :     nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
    1037       42369 :     nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
    1038             : 
    1039       42369 :     sal_Bool bOnlyFullParagraphs = ( aSel.Min().GetIndex() ||
    1040       42369 :         ( aSel.Max().GetIndex() < aSel.Max().GetNode()->Len() ) ) ?
    1041       84738 :             sal_False : sal_True;
    1042             : 
    1043             :     // Templates are not saved!
    1044             :     // (Only the name and family, template itself must be in App!)
    1045       42369 :     pTxtObj->mpImpl->SetScriptType(GetScriptType(aSel));
    1046             : 
    1047             :     // iterate over the paragraphs ...
    1048             :     sal_Int32 nNode;
    1049       88617 :     for ( nNode = nStartNode; nNode <= nEndNode; nNode++  )
    1050             :     {
    1051       46248 :         ContentNode* pNode = aEditDoc.GetObject( nNode );
    1052             :         DBG_ASSERT( pNode, "Node not found: Search&Replace" );
    1053             : 
    1054       46248 :         if ( bOnlyFullParagraphs )
    1055             :         {
    1056       46248 :             const ParaPortion* pParaPortion = GetParaPortions()[nNode];
    1057       46248 :             nTextPortions += pParaPortion->GetTextPortions().Count();
    1058             :         }
    1059             : 
    1060       46248 :         sal_uInt16 nStartPos = 0;
    1061       46248 :         sal_uInt16 nEndPos = pNode->Len();
    1062             : 
    1063       46248 :         sal_Bool bEmptyPara = nEndPos ? sal_False : sal_True;
    1064             : 
    1065       46248 :         if ( ( nNode == nStartNode ) && !bOnlyFullParagraphs )
    1066           0 :             nStartPos = aSel.Min().GetIndex();
    1067       46248 :         if ( ( nNode == nEndNode ) && !bOnlyFullParagraphs )
    1068           0 :             nEndPos = aSel.Max().GetIndex();
    1069             : 
    1070             : 
    1071       46248 :         ContentInfo *pC = pTxtObj->mpImpl->CreateAndInsertContent();
    1072             : 
    1073             :         // The paragraph attributes ...
    1074       46248 :         pC->GetParaAttribs().Set( pNode->GetContentAttribs().GetItems() );
    1075             : 
    1076             :         // The StyleSheet...
    1077       46248 :         if ( pNode->GetStyleSheet() )
    1078             :         {
    1079        6980 :             pC->GetStyle() = pNode->GetStyleSheet()->GetName();
    1080        6980 :             pC->GetFamily() = pNode->GetStyleSheet()->GetFamily();
    1081             :         }
    1082             : 
    1083             :         // The Text...
    1084       46248 :         pC->GetText() = pNode->Copy( nStartPos, nEndPos-nStartPos );
    1085             : 
    1086             :         // and the Attribute...
    1087       46248 :         sal_uInt16 nAttr = 0;
    1088       46248 :         EditCharAttrib* pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
    1089      157592 :         while ( pAttr )
    1090             :         {
    1091             :             // In a blank paragraph keep the attributes!
    1092      188312 :             if ( bEmptyPara ||
    1093      116240 :                  ( ( pAttr->GetEnd() > nStartPos ) && ( pAttr->GetStart() < nEndPos ) ) )
    1094             :             {
    1095       65096 :                 XEditAttribute* pX = pTxtObj->mpImpl->CreateAttrib(*pAttr->GetItem(), pAttr->GetStart(), pAttr->GetEnd());
    1096             :                 // Possibly Correct ...
    1097       65096 :                 if ( ( nNode == nStartNode ) && ( nStartPos != 0 ) )
    1098             :                 {
    1099           0 :                     pX->GetStart() = ( pX->GetStart() > nStartPos ) ? pX->GetStart()-nStartPos : 0;
    1100           0 :                     pX->GetEnd() = pX->GetEnd() - nStartPos;
    1101             : 
    1102             :                 }
    1103       65096 :                 if ( nNode == nEndNode )
    1104             :                 {
    1105       49494 :                     if ( pX->GetEnd() > (nEndPos-nStartPos) )
    1106           0 :                         pX->GetEnd() = nEndPos-nStartPos;
    1107             :                 }
    1108             :                 DBG_ASSERT( pX->GetEnd() <= (nEndPos-nStartPos), "CreateBinTextObject: Attribute too long!" );
    1109       65096 :                 if ( !pX->GetLen() && !bEmptyPara )
    1110           0 :                     pTxtObj->mpImpl->DestroyAttrib(pX);
    1111             :                 else
    1112       65096 :                     pC->GetAttribs().push_back(pX);
    1113             :             }
    1114       65096 :             nAttr++;
    1115       65096 :             pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
    1116             :         }
    1117             : 
    1118             :         // If possible online spelling
    1119       46248 :         if ( bAllowBigObjects && bOnlyFullParagraphs && pNode->GetWrongList() )
    1120        8072 :             pC->SetWrongList( pNode->GetWrongList()->Clone() );
    1121             : 
    1122             :     }
    1123             : 
    1124             :     // Remember the portions info in case of large text objects:
    1125             :     // sleeper set up when Olli paragraphs not hacked!
    1126       42369 :     if ( bAllowBigObjects && bOnlyFullParagraphs && IsFormatted() && GetUpdateMode() && ( nTextPortions >= nBigObjectStart ) )
    1127             :     {
    1128           0 :         XParaPortionList* pXList = new XParaPortionList( GetRefDevice(), aPaperSize.Width(), nStretchX, nStretchY );
    1129           0 :         pTxtObj->mpImpl->SetPortionInfo(pXList);
    1130           0 :         for ( nNode = nStartNode; nNode <= nEndNode; nNode++  )
    1131             :         {
    1132           0 :             const ParaPortion* pParaPortion = GetParaPortions()[nNode];
    1133           0 :             XParaPortion* pX = new XParaPortion;
    1134           0 :             pXList->push_back(pX);
    1135             : 
    1136           0 :             pX->nHeight = pParaPortion->GetHeight();
    1137           0 :             pX->nFirstLineOffset = pParaPortion->GetFirstLineOffset();
    1138             : 
    1139             :             // The TextPortions
    1140           0 :             sal_uInt16 nCount = pParaPortion->GetTextPortions().Count();
    1141             :             sal_uInt16 n;
    1142           0 :             for ( n = 0; n < nCount; n++ )
    1143             :             {
    1144           0 :                 const TextPortion* pTextPortion = pParaPortion->GetTextPortions()[n];
    1145           0 :                 TextPortion* pNew = new TextPortion( *pTextPortion );
    1146           0 :                 pX->aTextPortions.Append(pNew);
    1147             :             }
    1148             : 
    1149             :             // The lines
    1150           0 :             nCount = pParaPortion->GetLines().Count();
    1151           0 :             for ( n = 0; n < nCount; n++ )
    1152             :             {
    1153           0 :                 const EditLine* pLine = pParaPortion->GetLines()[n];
    1154           0 :                 EditLine* pNew = pLine->Clone();
    1155           0 :                 pX->aLines.Append(pNew);
    1156             :             }
    1157             : #ifdef DBG_UTIL
    1158             :             sal_uInt16 nTest;
    1159             :             int nTPLen = 0, nTxtLen = 0;
    1160             :             for ( nTest = pParaPortion->GetTextPortions().Count(); nTest; )
    1161             :                 nTPLen += pParaPortion->GetTextPortions()[--nTest]->GetLen();
    1162             :             for ( nTest = pParaPortion->GetLines().Count(); nTest; )
    1163             :                 nTxtLen += pParaPortion->GetLines()[--nTest]->GetLen();
    1164             :             DBG_ASSERT( ( nTPLen == pParaPortion->GetNode()->Len() ) && ( nTxtLen == pParaPortion->GetNode()->Len() ), "CreateBinTextObject: ParaPortion not completely formatted!" );
    1165             : #endif
    1166             :         }
    1167             :     }
    1168       42369 :     return pTxtObj;
    1169             : }
    1170             : 
    1171      211356 : void ImpEditEngine::SetText( const EditTextObject& rTextObject )
    1172             : {
    1173             :     // Since setting a text object is not undo-able!
    1174      211356 :     ResetUndoManager();
    1175      211356 :     sal_Bool _bUpdate = GetUpdateMode();
    1176      211356 :     sal_Bool _bUndo = IsUndoEnabled();
    1177             : 
    1178      211356 :     SetText( XubString() );
    1179      211356 :     EditPaM aPaM = aEditDoc.GetStartPaM();
    1180             : 
    1181      211356 :     SetUpdateMode( sal_False );
    1182      211356 :     EnableUndo( sal_False );
    1183             : 
    1184      211356 :     InsertText( rTextObject, EditSelection( aPaM, aPaM ) );
    1185      211356 :     SetVertical( rTextObject.IsVertical() );
    1186             : 
    1187             :     DBG_ASSERT( !HasUndoManager() || !GetUndoManager().GetUndoActionCount(), "From where comes the Undo in SetText ?!" );
    1188      211356 :     SetUpdateMode( _bUpdate );
    1189      211356 :     EnableUndo( _bUndo );
    1190      211356 : }
    1191             : 
    1192      211356 : EditSelection ImpEditEngine::InsertText( const EditTextObject& rTextObject, EditSelection aSel )
    1193             : {
    1194      211356 :     EnterBlockNotifications();
    1195      211356 :     aSel.Adjust( aEditDoc );
    1196      211356 :     if ( aSel.HasRange() )
    1197           0 :         aSel = ImpDeleteSelection( aSel );
    1198      211356 :     EditSelection aNewSel = InsertTextObject( rTextObject, aSel.Max() );
    1199      211356 :     LeaveBlockNotifications();
    1200      211356 :     return aNewSel;
    1201             : }
    1202             : 
    1203      211356 : EditSelection ImpEditEngine::InsertTextObject( const EditTextObject& rTextObject, EditPaM aPaM )
    1204             : {
    1205             :     // Optimize: No getPos undFindParaportion, instead calculate index!
    1206      211356 :     EditSelection aSel( aPaM, aPaM );
    1207             :     DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "InsertBibTextObject: Selection broken!(1)" );
    1208             : 
    1209      211356 :     sal_Bool bUsePortionInfo = sal_False;
    1210      211356 :     XParaPortionList* pPortionInfo = rTextObject.mpImpl->GetPortionInfo();
    1211             : 
    1212      211356 :     if ( pPortionInfo && ( (long)pPortionInfo->GetPaperWidth() == aPaperSize.Width() )
    1213           0 :             && ( pPortionInfo->GetRefMapMode() == GetRefDevice()->GetMapMode() )
    1214           0 :             && ( pPortionInfo->GetStretchX() == nStretchX )
    1215      211356 :             && ( pPortionInfo->GetStretchY() == nStretchY ) )
    1216             :     {
    1217           0 :         if ( ( pPortionInfo->GetRefDevPtr() == (sal_uIntPtr)GetRefDevice() ) ||
    1218           0 :              ( ( pPortionInfo->GetRefDevType() == OUTDEV_VIRDEV ) &&
    1219           0 :                ( GetRefDevice()->GetOutDevType() == OUTDEV_VIRDEV ) ) )
    1220           0 :         bUsePortionInfo = sal_True;
    1221             :     }
    1222             : 
    1223      211356 :     sal_Bool bConvertItems = sal_False;
    1224      211356 :     MapUnit eSourceUnit = MapUnit(), eDestUnit = MapUnit();
    1225      211356 :     if (rTextObject.mpImpl->HasMetric())
    1226             :     {
    1227      211356 :         eSourceUnit = (MapUnit)rTextObject.mpImpl->GetMetric();
    1228      211356 :         eDestUnit = (MapUnit)aEditDoc.GetItemPool().GetMetric( DEF_METRIC );
    1229      211356 :         if ( eSourceUnit != eDestUnit )
    1230           0 :             bConvertItems = sal_True;
    1231             :     }
    1232             : 
    1233             :     // Before, paragraph count was of type sal_uInt16 so if nContents exceeded
    1234             :     // 0xFFFF this wouldn't had worked anyway, given that nPara is used to
    1235             :     // number paragraphs and is fearlessly incremented.
    1236      211356 :     sal_Int32 nContents = static_cast<sal_Int32>(rTextObject.mpImpl->GetContents().size());
    1237             :     SAL_WARN_IF( nContents < 0, "editeng", "ImpEditEngine::InsertTextObject - contents overflow " << nContents);
    1238      211356 :     sal_Int32 nPara = aEditDoc.GetPos( aPaM.GetNode() );
    1239             : 
    1240      427483 :     for (sal_Int32 n = 0; n < nContents; ++n, ++nPara)
    1241             :     {
    1242      216127 :         const ContentInfo* pC = &rTextObject.mpImpl->GetContents()[n];
    1243      216127 :         sal_Bool bNewContent = aPaM.GetNode()->Len() ? sal_False: sal_True;
    1244      216127 :         sal_uInt16 nStartPos = aPaM.GetIndex();
    1245             : 
    1246      216127 :         aPaM = ImpFastInsertText( aPaM, pC->GetText() );
    1247             : 
    1248      216127 :         ParaPortion* pPortion = FindParaPortion( aPaM.GetNode() );
    1249             :         DBG_ASSERT( pPortion, "Blind Portion in FastInsertText" );
    1250      216127 :         pPortion->MarkInvalid( nStartPos, pC->GetText().Len() );
    1251             : 
    1252             :         // Character attributes ...
    1253      216127 :         sal_Bool bAllreadyHasAttribs = aPaM.GetNode()->GetCharAttribs().Count() ? sal_True : sal_False;
    1254      216127 :         size_t nNewAttribs = pC->GetAttribs().size();
    1255      216127 :         if ( nNewAttribs )
    1256             :         {
    1257       93834 :             sal_Bool bUpdateFields = sal_False;
    1258     1154909 :             for (size_t nAttr = 0; nAttr < nNewAttribs; ++nAttr)
    1259             :             {
    1260     1061075 :                 const XEditAttribute& rX = pC->GetAttribs()[nAttr];
    1261             :                 // Can happen when paragraphs > 16K, it is simply wrapped.
    1262     1061075 :                 if ( rX.GetEnd() <= aPaM.GetNode()->Len() )
    1263             :                 {
    1264     1061075 :                     if ( !bAllreadyHasAttribs || rX.IsFeature() )
    1265             :                     {
    1266             :                         // Normal attributes then go faster ...
    1267             :                         // Features shall not be inserted through
    1268             :                         // EditDoc:: InsertAttrib, using FastInsertText they are
    1269             :                         // already in the flow
    1270             :                         DBG_ASSERT( rX.GetEnd() <= aPaM.GetNode()->Len(), "InsertBinTextObject: Attribute too large!" );
    1271             :                         EditCharAttrib* pAttr;
    1272     1061075 :                         if ( !bConvertItems )
    1273     1061075 :                             pAttr = MakeCharAttrib( aEditDoc.GetItemPool(), *(rX.GetItem()), rX.GetStart()+nStartPos, rX.GetEnd()+nStartPos );
    1274             :                         else
    1275             :                         {
    1276           0 :                             SfxPoolItem* pNew = rX.GetItem()->Clone();
    1277           0 :                             ConvertItem( *pNew, eSourceUnit, eDestUnit );
    1278           0 :                             pAttr = MakeCharAttrib( aEditDoc.GetItemPool(), *pNew, rX.GetStart()+nStartPos, rX.GetEnd()+nStartPos );
    1279           0 :                             delete pNew;
    1280             :                         }
    1281             :                         DBG_ASSERT( pAttr->GetEnd() <= aPaM.GetNode()->Len(), "InsertBinTextObject: Attribute does not fit! (1)" );
    1282     1061075 :                         aPaM.GetNode()->GetCharAttribs().InsertAttrib( pAttr );
    1283     1061075 :                         if ( pAttr->Which() == EE_FEATURE_FIELD )
    1284        2650 :                             bUpdateFields = sal_True;
    1285             :                     }
    1286             :                     else
    1287             :                     {
    1288             :                         DBG_ASSERT( rX.GetEnd()+nStartPos <= aPaM.GetNode()->Len(), "InsertBinTextObject: Attribute does not fit! (2)" );
    1289             :                         // Tabs and other Features can not be inserted through InsertAttrib:
    1290           0 :                         aEditDoc.InsertAttrib( aPaM.GetNode(), rX.GetStart()+nStartPos, rX.GetEnd()+nStartPos, *rX.GetItem() );
    1291             :                     }
    1292             :                 }
    1293             :             }
    1294       93834 :             if ( bUpdateFields )
    1295        2428 :                 UpdateFields();
    1296             : 
    1297             :             // Otherwise, quick format => no attributes!
    1298       93834 :             pPortion->MarkSelectionInvalid( nStartPos, pC->GetText().Len() );
    1299             :         }
    1300             : 
    1301             :         DBG_ASSERT( CheckOrderedList( aPaM.GetNode()->GetCharAttribs().GetAttribs(), sal_True ), "InsertBinTextObject: Start-Liste distorted" );
    1302             : 
    1303      216127 :         sal_Bool bParaAttribs = sal_False;
    1304      216127 :         if ( bNewContent || ( ( n > 0 ) && ( n < (nContents-1) ) ) )
    1305             :         {
    1306      216127 :             bParaAttribs = sal_False;
    1307             :             {
    1308             :                 // only style and ParaAttribs when new paragraph, or
    1309             :                 // completely internal ...
    1310      216127 :                 bParaAttribs = pC->GetParaAttribs().Count() ? sal_True : sal_False;
    1311      216127 :                 if ( GetStyleSheetPool() && pC->GetStyle().Len() )
    1312             :                 {
    1313       99134 :                     SfxStyleSheet* pStyle = (SfxStyleSheet*)GetStyleSheetPool()->Find( pC->GetStyle(), pC->GetFamily() );
    1314             :                     DBG_ASSERT( pStyle, "InsertBinTextObject - Style not found!" );
    1315       99134 :                     SetStyleSheet( nPara, pStyle );
    1316             :                 }
    1317      216127 :                 if ( !bConvertItems )
    1318      216127 :                     SetParaAttribs( aEditDoc.GetPos( aPaM.GetNode() ), pC->GetParaAttribs() );
    1319             :                 else
    1320             :                 {
    1321           0 :                     SfxItemSet aAttribs( GetEmptyItemSet() );
    1322           0 :                     ConvertAndPutItems( aAttribs, pC->GetParaAttribs(), &eSourceUnit, &eDestUnit );
    1323           0 :                     SetParaAttribs( aEditDoc.GetPos( aPaM.GetNode() ), aAttribs );
    1324             :                 }
    1325             :             }
    1326      216127 :             if ( bNewContent && bUsePortionInfo )
    1327             :             {
    1328           0 :                 const XParaPortion& rXP = (*pPortionInfo)[n];
    1329           0 :                 ParaPortion* pParaPortion = GetParaPortions()[ nPara ];
    1330             :                 DBG_ASSERT( pParaPortion, "InsertBinTextObject: ParaPortion?" );
    1331           0 :                 pParaPortion->nHeight = rXP.nHeight;
    1332           0 :                 pParaPortion->nFirstLineOffset = rXP.nFirstLineOffset;
    1333           0 :                 pParaPortion->bForceRepaint = sal_True;
    1334           0 :                 pParaPortion->SetValid();   // Do not format
    1335             : 
    1336             :                 // The Text Portions
    1337           0 :                 pParaPortion->GetTextPortions().Reset();
    1338           0 :                 sal_uInt16 nCount = rXP.aTextPortions.Count();
    1339           0 :                 for ( sal_uInt16 _n = 0; _n < nCount; _n++ )
    1340             :                 {
    1341           0 :                     const TextPortion* pTextPortion = rXP.aTextPortions[_n];
    1342           0 :                     TextPortion* pNew = new TextPortion( *pTextPortion );
    1343           0 :                     pParaPortion->GetTextPortions().Insert(_n, pNew);
    1344             :                 }
    1345             : 
    1346             :                 // The lines
    1347           0 :                 pParaPortion->GetLines().Reset();
    1348           0 :                 nCount = rXP.aLines.Count();
    1349           0 :                 for ( sal_uInt16 m = 0; m < nCount; m++ )
    1350             :                 {
    1351           0 :                     const EditLine* pLine = rXP.aLines[m];
    1352           0 :                     EditLine* pNew = pLine->Clone();
    1353           0 :                     pNew->SetInvalid(); // Paint again!
    1354           0 :                     pParaPortion->GetLines().Insert(m, pNew);
    1355             :                 }
    1356             : #ifdef DBG_UTIL
    1357             :                 sal_uInt16 nTest;
    1358             :                 int nTPLen = 0, nTxtLen = 0;
    1359             :                 for ( nTest = pParaPortion->GetTextPortions().Count(); nTest; )
    1360             :                     nTPLen += pParaPortion->GetTextPortions()[--nTest]->GetLen();
    1361             :                 for ( nTest = pParaPortion->GetLines().Count(); nTest; )
    1362             :                     nTxtLen += pParaPortion->GetLines()[--nTest]->GetLen();
    1363             :                 DBG_ASSERT( ( nTPLen == pParaPortion->GetNode()->Len() ) && ( nTxtLen == pParaPortion->GetNode()->Len() ), "InsertBinTextObject: ParaPortion not completely formatted!" );
    1364             : #endif
    1365             :             }
    1366             :         }
    1367      216127 :         if ( !bParaAttribs ) // DefFont is not calculated for FastInsertParagraph
    1368             :         {
    1369        4308 :             aPaM.GetNode()->GetCharAttribs().GetDefFont() = aEditDoc.GetDefFont();
    1370        4308 :             if ( aStatus.UseCharAttribs() )
    1371        4308 :                 aPaM.GetNode()->CreateDefFont();
    1372             :         }
    1373             : 
    1374      216127 :         if ( bNewContent && GetStatus().DoOnlineSpelling() && pC->GetWrongList() )
    1375             :         {
    1376      104416 :             aPaM.GetNode()->DestroyWrongList(); // otherwise MLK, if list exists...
    1377      104416 :             aPaM.GetNode()->SetWrongList( pC->GetWrongList()->Clone() );
    1378             :         }
    1379             : 
    1380             :         // Wrap when followed by other ...
    1381      216127 :         if ( n < ( nContents-1) )
    1382             :         {
    1383        4771 :             if ( bNewContent )
    1384        4771 :                 aPaM = ImpFastInsertParagraph( nPara+1 );
    1385             :             else
    1386           0 :                 aPaM = ImpInsertParaBreak( aPaM, sal_False );
    1387             :         }
    1388             :     }
    1389             : 
    1390      211356 :     aSel.Max() = aPaM;
    1391             :     DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "InsertBibTextObject: Selection broken!(1)" );
    1392      211356 :     return aSel;
    1393             : }
    1394             : 
    1395      129780 : LanguageType ImpEditEngine::GetLanguage( const EditPaM& rPaM, sal_uInt16* pEndPos ) const
    1396             : {
    1397      129780 :     short nScriptType = GetScriptType( rPaM, pEndPos ); // pEndPos will be valid now, pointing to ScriptChange or NodeLen
    1398      129780 :     sal_uInt16 nLangId = GetScriptItemId( EE_CHAR_LANGUAGE, nScriptType );
    1399      129780 :     const SvxLanguageItem* pLangItem = &(const SvxLanguageItem&)rPaM.GetNode()->GetContentAttribs().GetItem( nLangId );
    1400      129780 :     const EditCharAttrib* pAttr = rPaM.GetNode()->GetCharAttribs().FindAttrib( nLangId, rPaM.GetIndex() );
    1401      129780 :     if ( pAttr )
    1402        8368 :         pLangItem = (const SvxLanguageItem*)pAttr->GetItem();
    1403             : 
    1404      129780 :     if ( pEndPos && pAttr && ( pAttr->GetEnd() < *pEndPos ) )
    1405           0 :         *pEndPos = pAttr->GetEnd();
    1406             : 
    1407      129780 :     return pLangItem->GetLanguage();
    1408             : }
    1409             : 
    1410      123305 : ::com::sun::star::lang::Locale ImpEditEngine::GetLocale( const EditPaM& rPaM ) const
    1411             : {
    1412      123305 :     return LanguageTag( GetLanguage( rPaM ) ).getLocale();
    1413             : }
    1414             : 
    1415           9 : Reference< XSpellChecker1 > ImpEditEngine::GetSpeller()
    1416             : {
    1417           9 :     if ( !xSpeller.is() )
    1418           9 :         xSpeller = SvxGetSpellChecker();
    1419           9 :     return xSpeller;
    1420             : }
    1421             : 
    1422             : 
    1423           9 : SpellInfo * ImpEditEngine::CreateSpellInfo( bool bMultipleDocs )
    1424             : {
    1425           9 :     if (!pSpellInfo)
    1426           9 :         pSpellInfo = new SpellInfo;
    1427             :     else
    1428           0 :         *pSpellInfo = SpellInfo();  // reset to default values
    1429             : 
    1430           9 :     pSpellInfo->bMultipleDoc = bMultipleDocs;
    1431             :     // always spell draw objects completely, startting at the top.
    1432             :     // (spelling in only a selection or not starting with the top requires
    1433             :     // further changes elsewehe to work properly)
    1434           9 :     pSpellInfo->aSpellStart = EPaM();
    1435           9 :     pSpellInfo->aSpellTo    = EPaM( EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND );
    1436           9 :     return pSpellInfo;
    1437             : }
    1438             : 
    1439             : 
    1440           9 : EESpellState ImpEditEngine::Spell( EditView* pEditView, sal_Bool bMultipleDoc )
    1441             : {
    1442             :     DBG_ASSERTWARNING( xSpeller.is(), "No Spell checker set!" );
    1443             : 
    1444           9 :     if ( !xSpeller.is() )
    1445           0 :         return EE_SPELL_NOSPELLER;
    1446             : 
    1447           9 :     aOnlineSpellTimer.Stop();
    1448             : 
    1449             :     // In MultipleDoc always from the front / rear ...
    1450           9 :     if ( bMultipleDoc )
    1451             :     {
    1452           0 :         pEditView->pImpEditView->SetEditSelection( aEditDoc.GetStartPaM() );
    1453             :     }
    1454             : 
    1455           9 :     EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() );
    1456           9 :     pSpellInfo = CreateSpellInfo( bMultipleDoc );
    1457             : 
    1458           9 :     sal_Bool bIsStart = sal_False;
    1459           9 :     if ( bMultipleDoc )
    1460           0 :         bIsStart = sal_True;    // Accessible from the front or from behind ...
    1461           9 :     else if ( ( CreateEPaM( aEditDoc.GetStartPaM() ) == pSpellInfo->aSpellStart ) )
    1462           9 :         bIsStart = sal_True;
    1463             : 
    1464             :     EditSpellWrapper* pWrp = new EditSpellWrapper( Application::GetDefDialogParent(),
    1465           9 :             xSpeller, bIsStart, sal_False, pEditView );
    1466           9 :     pWrp->SpellDocument();
    1467           9 :     delete pWrp;
    1468             : 
    1469           9 :     if ( !bMultipleDoc )
    1470             :     {
    1471           9 :         pEditView->pImpEditView->DrawSelection();
    1472           9 :         if ( aCurSel.Max().GetIndex() > aCurSel.Max().GetNode()->Len() )
    1473           0 :             aCurSel.Max().GetIndex() = aCurSel.Max().GetNode()->Len();
    1474           9 :         aCurSel.Min() = aCurSel.Max();
    1475           9 :         pEditView->pImpEditView->SetEditSelection( aCurSel );
    1476           9 :         pEditView->pImpEditView->DrawSelection();
    1477           9 :         pEditView->ShowCursor( sal_True, sal_False );
    1478             :     }
    1479           9 :     EESpellState eState = pSpellInfo->eState;
    1480           9 :     delete pSpellInfo;
    1481           9 :     pSpellInfo = 0;
    1482           9 :     return eState;
    1483             : }
    1484             : 
    1485             : 
    1486           0 : sal_Bool ImpEditEngine::HasConvertibleTextPortion( LanguageType nSrcLang )
    1487             : {
    1488           0 :     sal_Bool    bHasConvTxt = sal_False;
    1489             : 
    1490           0 :     sal_Int32 nParas = pEditEngine->GetParagraphCount();
    1491           0 :     for (sal_Int32 k = 0;  k < nParas;  ++k)
    1492             :     {
    1493           0 :         std::vector<sal_uInt16> aPortions;
    1494           0 :         pEditEngine->GetPortions( k, aPortions );
    1495           0 :         for ( size_t nPos = 0; nPos < aPortions.size(); ++nPos )
    1496             :         {
    1497           0 :             sal_uInt16 nEnd   = aPortions[ nPos ];
    1498           0 :             sal_uInt16 nStart = nPos > 0 ? aPortions[ nPos - 1 ] : 0;
    1499             : 
    1500             :             // if the paragraph is not empty we need to increase the index
    1501             :             // by one since the attribute of the character left to the
    1502             :             // specified position is evaluated.
    1503           0 :             if (nEnd > nStart)  // empty para?
    1504           0 :                 ++nStart;
    1505           0 :             LanguageType nLangFound = pEditEngine->GetLanguage( k, nStart );
    1506             : #ifdef DEBUG
    1507             :             lang::Locale aLocale( LanguageTag( nLangFound ).getLocale() );
    1508             : #endif
    1509           0 :             bHasConvTxt =   (nSrcLang == nLangFound) ||
    1510           0 :                             (editeng::HangulHanjaConversion::IsChinese( nLangFound ) &&
    1511           0 :                              editeng::HangulHanjaConversion::IsChinese( nSrcLang ));
    1512           0 :             if (bHasConvTxt)
    1513           0 :                 return bHasConvTxt;
    1514             :        }
    1515           0 :     }
    1516             : 
    1517           0 :     return bHasConvTxt;
    1518             : }
    1519             : 
    1520             : 
    1521           0 : void ImpEditEngine::Convert( EditView* pEditView,
    1522             :         LanguageType nSrcLang, LanguageType nDestLang, const Font *pDestFont,
    1523             :         sal_Int32 nOptions, bool bIsInteractive, bool bMultipleDoc )
    1524             : {
    1525             :     // modified version of ImpEditEngine::Spell
    1526             : 
    1527             :     // In MultipleDoc always from the front / rear ...
    1528           0 :     if ( bMultipleDoc )
    1529           0 :         pEditView->pImpEditView->SetEditSelection( aEditDoc.GetStartPaM() );
    1530             : 
    1531             : 
    1532             :     // initialize pConvInfo
    1533           0 :     EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() );
    1534           0 :     aCurSel.Adjust( aEditDoc );
    1535           0 :     pConvInfo = new ConvInfo;
    1536           0 :     pConvInfo->bMultipleDoc = bMultipleDoc;
    1537           0 :     pConvInfo->aConvStart = CreateEPaM( aCurSel.Min() );
    1538             :     //
    1539             :     // if it is not just a selection and we are about to begin
    1540             :     // with the current conversion for the very first time
    1541             :     // we need to find the start of the current (initial)
    1542             :     // convertible unit in order for the text conversion to give
    1543             :     // the correct result for that. Since it is easier to obtain
    1544             :     // the start of the word we use that though.
    1545           0 :     if (!aCurSel.HasRange() && ImplGetBreakIterator().is())
    1546             :     {
    1547           0 :         EditPaM aWordStartPaM(  SelectWord( aCurSel, i18n::WordType::DICTIONARY_WORD ).Min() );
    1548             : 
    1549             :         // since #118246 / #117803 still occurs if the cursor is placed
    1550             :         // between the two chinese characters to be converted (because both
    1551             :         // of them are words on their own!) using the word boundary here does
    1552             :         // not work. Thus since chinese conversion is not interactive we start
    1553             :         // at the begin of the paragraph to solve the problem, i.e. have the
    1554             :         // TextConversion service get those characters together in the same call.
    1555           0 :         sal_uInt16 nStartIdx = ( editeng::HangulHanjaConversion::IsChinese( nSrcLang ) ) ?
    1556           0 :                                 0 : aWordStartPaM.GetIndex();
    1557           0 :         pConvInfo->aConvStart.nIndex = nStartIdx;
    1558             :     }
    1559             :     //
    1560           0 :     pConvInfo->aConvContinue = pConvInfo->aConvStart;
    1561             : 
    1562           0 :     bool bIsStart = false;
    1563           0 :     if ( bMultipleDoc )
    1564           0 :         bIsStart = true;    // Accessible from the front or from behind ...
    1565           0 :     else if ( CreateEPaM( aEditDoc.GetStartPaM() ) == pConvInfo->aConvStart )
    1566           0 :         bIsStart = true;
    1567             : 
    1568           0 :     bImpConvertFirstCall = true;    // next ImpConvert call is the very first in this conversion turn
    1569             : 
    1570             :     TextConvWrapper aWrp( Application::GetDefDialogParent(),
    1571             :                           ::comphelper::getProcessComponentContext(),
    1572           0 :                           LanguageTag( nSrcLang ).getLocale(),
    1573           0 :                           LanguageTag( nDestLang ).getLocale(),
    1574             :                           pDestFont,
    1575             :                           nOptions, bIsInteractive,
    1576           0 :                           bIsStart, pEditView );
    1577             : 
    1578             :     //
    1579             :     //!! optimization does not work since when update mode is false
    1580             :     //!! the object is 'lying' about it portions, paragraphs,
    1581             :     //!! EndPaM... later on.
    1582             :     //!! Should not be a great problem since text boxes or cells in
    1583             :     //!! Calc usually have only a rather short text.
    1584             :     //
    1585             :     // disallow formatting, updating the view, ... while
    1586             :     // non-interactively converting the document. (saves time)
    1587             :     //if (!bIsInteractive)
    1588             :     //  SetUpdateMode( sal_False );
    1589             : 
    1590           0 :     aWrp.Convert();
    1591             : 
    1592             :     //if (!bIsInteractive)
    1593             :     //SetUpdateMode( sal_True, 0, sal_True );
    1594             : 
    1595           0 :     if ( !bMultipleDoc )
    1596             :     {
    1597           0 :         pEditView->pImpEditView->DrawSelection();
    1598           0 :         if ( aCurSel.Max().GetIndex() > aCurSel.Max().GetNode()->Len() )
    1599           0 :             aCurSel.Max().GetIndex() = aCurSel.Max().GetNode()->Len();
    1600           0 :         aCurSel.Min() = aCurSel.Max();
    1601           0 :         pEditView->pImpEditView->SetEditSelection( aCurSel );
    1602           0 :         pEditView->pImpEditView->DrawSelection();
    1603           0 :         pEditView->ShowCursor( sal_True, sal_False );
    1604             :     }
    1605           0 :     delete pConvInfo;
    1606           0 :     pConvInfo = 0;
    1607           0 : }
    1608             : 
    1609             : 
    1610           0 : void ImpEditEngine::SetLanguageAndFont(
    1611             :     const ESelection &rESel,
    1612             :     LanguageType nLang, sal_uInt16 nLangWhichId,
    1613             :     const Font *pFont,  sal_uInt16 nFontWhichId )
    1614             : {
    1615           0 :     ESelection aOldSel = pActiveView->GetSelection();
    1616           0 :     pActiveView->SetSelection( rESel );
    1617             : 
    1618             :     // set new language attribute
    1619           0 :     SfxItemSet aNewSet( pActiveView->GetEmptyItemSet() );
    1620           0 :     aNewSet.Put( SvxLanguageItem( nLang, nLangWhichId ) );
    1621             : 
    1622             :     // new font to be set?
    1623             :     DBG_ASSERT( pFont, "target font missing?" );
    1624           0 :     if (pFont)
    1625             :     {
    1626             :         // set new font attribute
    1627           0 :         SvxFontItem aFontItem = (SvxFontItem&) aNewSet.Get( nFontWhichId );
    1628           0 :         aFontItem.SetFamilyName( pFont->GetName());
    1629           0 :         aFontItem.SetFamily( pFont->GetFamily());
    1630           0 :         aFontItem.SetStyleName( pFont->GetStyleName());
    1631           0 :         aFontItem.SetPitch( pFont->GetPitch());
    1632           0 :         aFontItem.SetCharSet( pFont->GetCharSet() );
    1633           0 :         aNewSet.Put( aFontItem );
    1634             :     }
    1635             : 
    1636             :     // apply new attributes
    1637           0 :     pActiveView->SetAttribs( aNewSet );
    1638             : 
    1639           0 :     pActiveView->SetSelection( aOldSel );
    1640           0 : }
    1641             : 
    1642             : 
    1643           0 : void ImpEditEngine::ImpConvert( OUString &rConvTxt, LanguageType &rConvTxtLang,
    1644             :         EditView* pEditView, LanguageType nSrcLang, const ESelection &rConvRange,
    1645             :         bool bAllowImplicitChangesForNotConvertibleText,
    1646             :         LanguageType nTargetLang, const Font *pTargetFont  )
    1647             : {
    1648             :     // modified version of ImpEditEngine::ImpSpell
    1649             : 
    1650             :     // looks for next convertible text portion to be passed on to the wrapper
    1651             : 
    1652           0 :     String aRes;
    1653           0 :     LanguageType nResLang = LANGUAGE_NONE;
    1654             : 
    1655           0 :     /* ContentNode* pLastNode = */ aEditDoc.GetObject( aEditDoc.Count()-1 );
    1656             : 
    1657           0 :     EditPaM aPos( CreateEditPaM( pConvInfo->aConvContinue ) );
    1658           0 :     EditSelection aCurSel = EditSelection( aPos, aPos );
    1659             : 
    1660           0 :     String aWord;
    1661             : 
    1662           0 :     while (!aRes.Len())
    1663             :     {
    1664             :         // empty paragraph found that needs to have language and font set?
    1665           0 :         if (bAllowImplicitChangesForNotConvertibleText &&
    1666           0 :             !pEditEngine->GetText( pConvInfo->aConvContinue.nPara ).Len())
    1667             :         {
    1668           0 :             sal_Int32 nPara = pConvInfo->aConvContinue.nPara;
    1669           0 :             ESelection aESel( nPara, 0, nPara, 0 );
    1670             :             // see comment for below same function call
    1671             :             SetLanguageAndFont( aESel,
    1672             :                     nTargetLang, EE_CHAR_LANGUAGE_CJK,
    1673           0 :                     pTargetFont, EE_CHAR_FONTINFO_CJK );
    1674             :         }
    1675             : 
    1676             : 
    1677           0 :         if (pConvInfo->aConvContinue.nPara  == pConvInfo->aConvTo.nPara &&
    1678           0 :             pConvInfo->aConvContinue.nIndex >= pConvInfo->aConvTo.nIndex)
    1679           0 :             break;
    1680             : 
    1681           0 :         sal_uInt16 nAttribStart = USHRT_MAX;
    1682           0 :         sal_uInt16 nAttribEnd   = USHRT_MAX;
    1683           0 :         sal_uInt16 nCurPos      = USHRT_MAX;
    1684           0 :         EPaM aCurStart = CreateEPaM( aCurSel.Min() );
    1685           0 :         std::vector<sal_uInt16> aPortions;
    1686           0 :         pEditEngine->GetPortions( aCurStart.nPara, aPortions );
    1687           0 :         for ( size_t nPos = 0; nPos < aPortions.size(); ++nPos )
    1688             :         {
    1689           0 :             sal_uInt16 nEnd   = aPortions[ nPos ];
    1690           0 :             sal_uInt16 nStart = nPos > 0 ? aPortions[ nPos - 1 ] : 0;
    1691             : 
    1692             :             // the language attribute is obtained from the left character
    1693             :             // (like usually all other attributes)
    1694             :             // thus we usually have to add 1 in order to get the language
    1695             :             // of the text right to the cursor position
    1696           0 :             sal_uInt16 nLangIdx = nEnd > nStart ? nStart + 1 : nStart;
    1697           0 :             LanguageType nLangFound = pEditEngine->GetLanguage( aCurStart.nPara, nLangIdx );
    1698             : #ifdef DEBUG
    1699             :             lang::Locale aLocale( LanguageTag( nLangFound ).getLocale() );
    1700             : #endif
    1701           0 :             sal_Bool bLangOk =  (nLangFound == nSrcLang) ||
    1702           0 :                                 (editeng::HangulHanjaConversion::IsChinese( nLangFound ) &&
    1703           0 :                                  editeng::HangulHanjaConversion::IsChinese( nSrcLang ));
    1704             : 
    1705           0 :             if (nAttribEnd != USHRT_MAX) // start already found?
    1706             :             {
    1707             :                 DBG_ASSERT(nEnd >= aCurStart.nIndex, "error while scanning attributes (a)" );
    1708             :                 DBG_ASSERT(nEnd >= nAttribEnd, "error while scanning attributes (b)" );
    1709           0 :                 if (/*nEnd >= aCurStart.nIndex &&*/ nLangFound == nResLang)
    1710           0 :                     nAttribEnd = nEnd;
    1711             :                 else  // language attrib has changed
    1712           0 :                     break;
    1713             :             }
    1714           0 :             if (nAttribStart == USHRT_MAX && // start not yet found?
    1715           0 :                 nEnd > aCurStart.nIndex && bLangOk)
    1716             :             {
    1717           0 :                 nAttribStart = nStart;
    1718           0 :                 nAttribEnd   = nEnd;
    1719           0 :                 nResLang = nLangFound;
    1720             :             }
    1721             :             //! the list of portions may have changed compared to the previous
    1722             :             //! call to this function (because of possibly changed language
    1723             :             //! attribute!)
    1724             :             //! But since we don't want to start in the already processed part
    1725             :             //! we clip the start accordingly.
    1726           0 :             if (nAttribStart < aCurStart.nIndex)
    1727             :             {
    1728           0 :                 nAttribStart = aCurStart.nIndex;
    1729             :             }
    1730             : 
    1731             :             // check script type to the right of the start of the current portion
    1732           0 :             EditPaM aPaM( CreateEditPaM( EPaM(aCurStart.nPara, nLangIdx) ) );
    1733           0 :             sal_Bool bIsAsianScript = (i18n::ScriptType::ASIAN == GetScriptType( aPaM ));
    1734             :             // not yet processed text part with for conversion
    1735             :             // not suitable language found that needs to be changed?
    1736           0 :             if (bAllowImplicitChangesForNotConvertibleText &&
    1737           0 :                 !bLangOk && !bIsAsianScript && nEnd > aCurStart.nIndex)
    1738             :             {
    1739           0 :                 ESelection aESel( aCurStart.nPara, nStart, aCurStart.nPara, nEnd );
    1740             :                 // set language and font to target language and font of conversion
    1741             :                 //! Now this especially includes all non convertible text e.g.
    1742             :                 //! spaces, empty paragraphs and western text.
    1743             :                 // This is in order for every *new* text entered at *any* position to
    1744             :                 // have the correct language and font attributes set.
    1745             :                 SetLanguageAndFont( aESel,
    1746             :                         nTargetLang, EE_CHAR_LANGUAGE_CJK,
    1747           0 :                         pTargetFont, EE_CHAR_FONTINFO_CJK );
    1748             :             }
    1749             : 
    1750           0 :             nCurPos = nEnd;
    1751             :         }
    1752             : 
    1753           0 :         if (nAttribStart != USHRT_MAX  &&  nAttribEnd != USHRT_MAX)
    1754             :         {
    1755           0 :             aCurSel.Min().SetIndex( nAttribStart );
    1756           0 :             aCurSel.Max().SetIndex( nAttribEnd );
    1757             :         }
    1758           0 :         else if (nCurPos != USHRT_MAX)
    1759             :         {
    1760             :             // set selection to end of scanned text
    1761             :             // (used to set the position where to continue from later on)
    1762           0 :             aCurSel.Min().SetIndex( nCurPos );
    1763           0 :             aCurSel.Max().SetIndex( nCurPos );
    1764             :         }
    1765             : 
    1766           0 :         if ( !pConvInfo->bConvToEnd )
    1767             :         {
    1768           0 :             EPaM aEPaM( CreateEPaM( aCurSel.Min() ) );
    1769           0 :             if ( !( aEPaM < pConvInfo->aConvTo ) )
    1770           0 :                 break;
    1771             :         }
    1772             : 
    1773             :         // clip selected word to the converted area
    1774             :         // (main use when conversion starts/ends **within** a word)
    1775           0 :         EditPaM aPaM( CreateEditPaM( pConvInfo->aConvStart ) );
    1776           0 :         if (pConvInfo->bConvToEnd &&
    1777           0 :             aCurSel.Min().GetNode() == aPaM.GetNode() &&
    1778           0 :             aCurSel.Min().GetIndex() < aPaM.GetIndex())
    1779           0 :                 aCurSel.Min().SetIndex( aPaM.GetIndex() );
    1780           0 :         aPaM = CreateEditPaM( pConvInfo->aConvContinue );
    1781           0 :         if (aCurSel.Min().GetNode() == aPaM.GetNode() &&
    1782           0 :             aCurSel.Min().GetIndex() < aPaM.GetIndex())
    1783           0 :                 aCurSel.Min().SetIndex( aPaM.GetIndex() );
    1784           0 :         aPaM = CreateEditPaM( pConvInfo->aConvTo );
    1785           0 :         if ((!pConvInfo->bConvToEnd || rConvRange.HasRange())&&
    1786           0 :             aCurSel.Max().GetNode() == aPaM.GetNode() &&
    1787           0 :             aCurSel.Max().GetIndex() > aPaM.GetIndex())
    1788           0 :                 aCurSel.Max().SetIndex( aPaM.GetIndex() );
    1789             : 
    1790           0 :         aWord = GetSelected( aCurSel );
    1791             : 
    1792           0 :         if ( aWord.Len() > 0 /* && bLangOk */)
    1793           0 :             aRes = aWord;
    1794             : 
    1795             :         // move to next word/paragraph if necessary
    1796           0 :         if ( !aRes.Len() )
    1797           0 :             aCurSel = WordRight( aCurSel.Min(), ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    1798             : 
    1799           0 :         pConvInfo->aConvContinue = CreateEPaM( aCurSel.Max() );
    1800           0 :     }
    1801             : 
    1802           0 :     pEditView->pImpEditView->DrawSelection();
    1803           0 :     pEditView->pImpEditView->SetEditSelection( aCurSel );
    1804           0 :     pEditView->pImpEditView->DrawSelection();
    1805           0 :     pEditView->ShowCursor( sal_True, sal_False );
    1806             : 
    1807           0 :     rConvTxt = aRes;
    1808           0 :     if ( !rConvTxt.isEmpty() )
    1809           0 :         rConvTxtLang = nResLang;
    1810           0 : }
    1811             : 
    1812             : 
    1813           9 : Reference< XSpellAlternatives > ImpEditEngine::ImpSpell( EditView* pEditView )
    1814             : {
    1815             :     DBG_ASSERT( xSpeller.is(), "No spell checker set!" );
    1816             : 
    1817           9 :     ContentNode* pLastNode = aEditDoc.GetObject( (aEditDoc.Count()-1) );
    1818           9 :     EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() );
    1819           9 :     aCurSel.Min() = aCurSel.Max();
    1820             : 
    1821           9 :     String aWord;
    1822           9 :     Reference< XSpellAlternatives > xSpellAlt;
    1823          18 :     Sequence< PropertyValue > aEmptySeq;
    1824          18 :     while (!xSpellAlt.is())
    1825             :     {
    1826             :         // Known (most likely) bug: If SpellToCurrent, the current has to be
    1827             :         // corrected at each replacement, otherwise it may not fit exactly in
    1828             :         // the end ...
    1829           9 :         if ( pSpellInfo->bSpellToEnd || pSpellInfo->bMultipleDoc )
    1830             :         {
    1831           0 :             if ( aCurSel.Max().GetNode() == pLastNode )
    1832             :             {
    1833           0 :                 if ( ( aCurSel.Max().GetIndex() >= pLastNode->Len() ) )
    1834           0 :                     break;
    1835             :             }
    1836             :         }
    1837           9 :         else if ( !pSpellInfo->bSpellToEnd )
    1838             :         {
    1839           9 :             EPaM aEPaM( CreateEPaM( aCurSel.Max() ) );
    1840           9 :             if ( !( aEPaM < pSpellInfo->aSpellTo ) )
    1841           9 :                 break;
    1842             :         }
    1843             : 
    1844           0 :         aCurSel = SelectWord( aCurSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    1845           0 :         aWord = GetSelected( aCurSel );
    1846             : 
    1847             :         // If afterwards a dot, this must be handed over!
    1848             :         // If an abbreviation ...
    1849           0 :         if ( aWord.Len() && ( aCurSel.Max().GetIndex() < aCurSel.Max().GetNode()->Len() ) )
    1850             :         {
    1851           0 :             sal_Unicode cNext = aCurSel.Max().GetNode()->GetChar( aCurSel.Max().GetIndex() );
    1852           0 :             if ( cNext == '.' )
    1853             :             {
    1854           0 :                 aCurSel.Max().GetIndex()++;
    1855           0 :                 aWord += cNext;
    1856             :             }
    1857             :         }
    1858             : 
    1859           0 :         if ( aWord.Len() > 0 )
    1860             :         {
    1861           0 :             LanguageType eLang = GetLanguage( aCurSel.Max() );
    1862           0 :             SvxSpellWrapper::CheckSpellLang( xSpeller, eLang );
    1863           0 :             xSpellAlt = xSpeller->spell( aWord, eLang, aEmptySeq );
    1864             :         }
    1865             : 
    1866           0 :         if ( !xSpellAlt.is() )
    1867           0 :             aCurSel = WordRight( aCurSel.Min(), ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    1868             :         else
    1869           0 :             pSpellInfo->eState = EE_SPELL_ERRORFOUND;
    1870             :     }
    1871             : 
    1872           9 :     pEditView->pImpEditView->DrawSelection();
    1873           9 :     pEditView->pImpEditView->SetEditSelection( aCurSel );
    1874           9 :     pEditView->pImpEditView->DrawSelection();
    1875           9 :     pEditView->ShowCursor( sal_True, sal_False );
    1876          18 :     return xSpellAlt;
    1877             : }
    1878             : 
    1879           0 : void ImpEditEngine::StartSpelling(EditView& rEditView, sal_Bool bMultipleDoc)
    1880             : {
    1881             :     DBG_ASSERT(!pSpellInfo, "pSpellInfo already set?");
    1882           0 :     rEditView.pImpEditView->SetEditSelection( aEditDoc.GetStartPaM() );
    1883           0 :     pSpellInfo = CreateSpellInfo( bMultipleDoc );
    1884           0 : }
    1885             : 
    1886           0 : Reference< XSpellAlternatives > ImpEditEngine::ImpFindNextError(EditSelection& rSelection)
    1887             : {
    1888           0 :     aEditDoc.GetObject( (aEditDoc.Count()-1) );
    1889           0 :     EditSelection aCurSel( rSelection.Min() );
    1890             : 
    1891           0 :     String aWord;
    1892           0 :     Reference< XSpellAlternatives > xSpellAlt;
    1893           0 :     Sequence< PropertyValue > aEmptySeq;
    1894           0 :     while (!xSpellAlt.is())
    1895             :     {
    1896             :         //check if the end of the selection has been reached
    1897             :         {
    1898           0 :             EPaM aEPaM( CreateEPaM( aCurSel.Max() ) );
    1899           0 :             if ( !( aEPaM < CreateEPaM( rSelection.Max()) ) )
    1900           0 :                 break;
    1901             :         }
    1902             : 
    1903           0 :         aCurSel = SelectWord( aCurSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    1904           0 :         aWord = GetSelected( aCurSel );
    1905             : 
    1906             :         // If afterwards a dot, this must be handed over!
    1907             :         // If an abbreviation ...
    1908           0 :         if ( aWord.Len() && ( aCurSel.Max().GetIndex() < aCurSel.Max().GetNode()->Len() ) )
    1909             :         {
    1910           0 :             sal_Unicode cNext = aCurSel.Max().GetNode()->GetChar( aCurSel.Max().GetIndex() );
    1911           0 :             if ( cNext == '.' )
    1912             :             {
    1913           0 :                 aCurSel.Max().GetIndex()++;
    1914           0 :                 aWord += cNext;
    1915             :             }
    1916             :         }
    1917             : 
    1918           0 :         if ( aWord.Len() > 0 )
    1919           0 :             xSpellAlt = xSpeller->spell( aWord, GetLanguage( aCurSel.Max() ), aEmptySeq );
    1920             : 
    1921           0 :         if ( !xSpellAlt.is() )
    1922           0 :             aCurSel = WordRight( aCurSel.Min(), ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    1923             :         else
    1924             :         {
    1925           0 :             pSpellInfo->eState = EE_SPELL_ERRORFOUND;
    1926           0 :             rSelection = aCurSel;
    1927             :         }
    1928             :     }
    1929           0 :     return xSpellAlt;
    1930             : }
    1931             : 
    1932           0 : bool ImpEditEngine::SpellSentence(EditView& rEditView,
    1933             :     ::svx::SpellPortions& rToFill,
    1934             :     bool /*bIsGrammarChecking*/ )
    1935             : {
    1936           0 :     bool bRet = false;
    1937           0 :     EditSelection aCurSel( rEditView.pImpEditView->GetEditSelection() );
    1938           0 :     if(!pSpellInfo)
    1939           0 :         pSpellInfo = CreateSpellInfo( true );
    1940           0 :     pSpellInfo->aCurSentenceStart = aCurSel.Min();
    1941             :     DBG_ASSERT( xSpeller.is(), "No spell checker set!" );
    1942           0 :     pSpellInfo->aLastSpellPortions.clear();
    1943           0 :     pSpellInfo->aLastSpellContentSelections.clear();
    1944           0 :     rToFill.clear();
    1945             :     //if no selection previously exists the range is extended to the end of the object
    1946           0 :     if(aCurSel.Min() == aCurSel.Max())
    1947             :     {
    1948           0 :         ContentNode* pLastNode = aEditDoc.GetObject( aEditDoc.Count()-1);
    1949           0 :         aCurSel.Max() = EditPaM(pLastNode, pLastNode->Len());
    1950             :     }
    1951             :     // check for next error in aCurSel and set aCurSel to that one if any was found
    1952           0 :     Reference< XSpellAlternatives > xAlt = ImpFindNextError(aCurSel);
    1953           0 :     if (xAlt.is())
    1954             :     {
    1955           0 :         bRet = true;
    1956             :         //find the sentence boundaries
    1957           0 :         EditSelection aSentencePaM = SelectSentence(aCurSel);
    1958             :         //make sure that the sentence is never smaller than the error range!
    1959           0 :         if(aSentencePaM.Max().GetIndex() < aCurSel.Max().GetIndex())
    1960           0 :             aSentencePaM.Max() = aCurSel.Max();
    1961             :         //add the portion preceeding the error
    1962           0 :         EditSelection aStartSelection(aSentencePaM.Min(), aCurSel.Min());
    1963           0 :         if(aStartSelection.HasRange())
    1964           0 :             AddPortionIterated(rEditView, aStartSelection, 0, rToFill);
    1965             :         //add the error portion
    1966           0 :         AddPortionIterated(rEditView, aCurSel, xAlt, rToFill);
    1967             :         //find the end of the sentence
    1968             :         //search for all errors in the rest of the sentence and add all the portions
    1969           0 :         do
    1970             :         {
    1971           0 :             EditSelection aNextSel = EditSelection(aCurSel.Max(), aSentencePaM.Max());
    1972           0 :             xAlt = ImpFindNextError(aNextSel);
    1973           0 :             if(xAlt.is())
    1974             :             {
    1975             :                 //add the part between the previous and the current error
    1976           0 :                 AddPortionIterated(rEditView, EditSelection(aCurSel.Max(), aNextSel.Min()), 0, rToFill);
    1977             :                 //add the current error
    1978           0 :                 AddPortionIterated(rEditView, aNextSel, xAlt, rToFill);
    1979             :             }
    1980             :             else
    1981           0 :                 AddPortionIterated(rEditView, EditSelection(aCurSel.Max(), aSentencePaM.Max()), xAlt, rToFill);
    1982           0 :             aCurSel = aNextSel;
    1983             :         }
    1984           0 :         while( xAlt.is() );
    1985             : 
    1986             :         //set the selection to the end of the current sentence
    1987           0 :         rEditView.pImpEditView->SetEditSelection(aSentencePaM.Max());
    1988             :     }
    1989           0 :     return bRet;
    1990             : }
    1991             : 
    1992             : // Adds one portion to the SpellPortions
    1993           0 : void ImpEditEngine::AddPortion(
    1994             :                             const EditSelection& rSel,
    1995             :                             uno::Reference< XSpellAlternatives > xAlt,
    1996             :                                 ::svx::SpellPortions& rToFill,
    1997             :                                 bool bIsField)
    1998             : {
    1999           0 :     if(rSel.HasRange())
    2000             :     {
    2001           0 :         svx::SpellPortion aPortion;
    2002           0 :         aPortion.sText = GetSelected( rSel );
    2003           0 :         aPortion.eLanguage = GetLanguage( rSel.Min() );
    2004           0 :         aPortion.xAlternatives = xAlt;
    2005           0 :         aPortion.bIsField = bIsField;
    2006           0 :         rToFill.push_back(aPortion);
    2007             : 
    2008             :         //save the spelled portions for later use
    2009           0 :         pSpellInfo->aLastSpellPortions.push_back(aPortion);
    2010           0 :         pSpellInfo->aLastSpellContentSelections.push_back(rSel);
    2011             : 
    2012             :     }
    2013           0 : }
    2014             : 
    2015             : // Adds one or more portions of text to the SpellPortions depending on language changes
    2016           0 : void ImpEditEngine::AddPortionIterated(
    2017             :                             EditView& rEditView,
    2018             :                             const EditSelection& rSel,
    2019             :                             Reference< XSpellAlternatives > xAlt,
    2020             :                                 ::svx::SpellPortions& rToFill)
    2021             : {
    2022           0 :     if(rSel.Min() != rSel.Max())
    2023             :     {
    2024           0 :         if(xAlt.is())
    2025             :         {
    2026           0 :             AddPortion(rSel, xAlt, rToFill, false);
    2027             :         }
    2028             :         else
    2029             :         {
    2030             :             //iterate and search for language attribute changes
    2031             :             //save the start and end positions
    2032           0 :             bool bTest = rSel.Min().GetIndex() <= rSel.Max().GetIndex();
    2033           0 :             EditPaM aStart(bTest ? rSel.Min() : rSel.Max());
    2034           0 :             EditPaM aEnd(bTest ? rSel.Max() : rSel.Min());
    2035             :             //iterate over the text to find changes in language
    2036             :             //set the mark equal to the point
    2037           0 :             EditPaM aCursor(aStart);
    2038           0 :             rEditView.pImpEditView->SetEditSelection( aCursor );
    2039           0 :             LanguageType eStartLanguage = GetLanguage( aCursor );
    2040             :             //search for a field attribute at the beginning - only the end position
    2041             :             //of this field is kept to end a portion at that position
    2042           0 :             const EditCharAttrib* pFieldAttr = aCursor.GetNode()->GetCharAttribs().
    2043           0 :                                                     FindFeature( aCursor.GetIndex() );
    2044           0 :             bool bIsField = pFieldAttr &&
    2045           0 :                     pFieldAttr->GetStart() == aCursor.GetIndex() &&
    2046           0 :                     pFieldAttr->GetStart() != pFieldAttr->GetEnd() &&
    2047           0 :                     pFieldAttr->Which() == EE_FEATURE_FIELD;
    2048           0 :             sal_uInt16 nEndField = bIsField ? pFieldAttr->GetEnd() : USHRT_MAX;
    2049           0 :             bool bIsEndField = false;
    2050           0 :             do
    2051             :             {
    2052           0 :                 aCursor = CursorRight( aCursor);
    2053             :                 //determine whether a field and has been reached
    2054           0 :                 bIsEndField = nEndField == aCursor.GetIndex();
    2055             :                 //search for a new field attribute
    2056           0 :                 const EditCharAttrib* _pFieldAttr = aCursor.GetNode()->GetCharAttribs().
    2057           0 :                                                         FindFeature( aCursor.GetIndex() );
    2058           0 :                 bIsField = _pFieldAttr &&
    2059           0 :                         _pFieldAttr->GetStart() == aCursor.GetIndex() &&
    2060           0 :                         _pFieldAttr->GetStart() != _pFieldAttr->GetEnd() &&
    2061           0 :                         _pFieldAttr->Which() == EE_FEATURE_FIELD;
    2062             :                 //on every new field move the end position
    2063           0 :                 if(bIsField)
    2064           0 :                     nEndField = bIsField ? _pFieldAttr->GetEnd() : USHRT_MAX;
    2065             : 
    2066           0 :                 LanguageType eCurLanguage = GetLanguage( aCursor );
    2067           0 :                 if(eCurLanguage != eStartLanguage || bIsField || bIsEndField)
    2068             :                 {
    2069           0 :                     eStartLanguage = eCurLanguage;
    2070             :                     //go one step back - the cursor currently selects the first character
    2071             :                     //with a different language
    2072             :                     //create a selection from start to the current Cursor
    2073           0 :                     EditSelection aSelection(aStart, aCursor);
    2074           0 :                     AddPortion(aSelection, xAlt, rToFill, bIsEndField);
    2075           0 :                     aStart = aCursor;
    2076             :                 }
    2077             :             }
    2078           0 :             while(aCursor.GetIndex() < aEnd.GetIndex());
    2079           0 :             EditSelection aSelection(aStart, aCursor);
    2080           0 :             AddPortion(aSelection, xAlt, rToFill, bIsField);
    2081             :         }
    2082             :     }
    2083           0 : }
    2084             : 
    2085           0 : void ImpEditEngine::ApplyChangedSentence(EditView& rEditView,
    2086             :     const ::svx::SpellPortions& rNewPortions,
    2087             :     bool bRecheck )
    2088             : {
    2089             :     // Note: rNewPortions.size() == 0 is valid and happens when the whole
    2090             :     // sentence got removed in the dialog
    2091             : 
    2092             :     DBG_ASSERT(pSpellInfo, "pSpellInfo not initialized");
    2093           0 :     if (pSpellInfo &&
    2094           0 :         pSpellInfo->aLastSpellPortions.size() > 0)  // no portions -> no text to be changed
    2095             :     {
    2096             :         // get current paragraph length to calculate later on how the sentence length changed,
    2097             :         // in order to place the cursor at the end of the sentence again
    2098           0 :         EditSelection aOldSel( rEditView.pImpEditView->GetEditSelection() );
    2099           0 :         xub_StrLen nOldLen = aOldSel.Max().GetNode()->Len();
    2100             : 
    2101           0 :         UndoActionStart( EDITUNDO_INSERT );
    2102           0 :         if(pSpellInfo->aLastSpellPortions.size() == rNewPortions.size())
    2103             :         {
    2104             :             DBG_ASSERT( rNewPortions.size() > 0, "rNewPortions should not be empty here" );
    2105             :             DBG_ASSERT( pSpellInfo->aLastSpellPortions.size() == pSpellInfo->aLastSpellContentSelections.size(),
    2106             :                     "aLastSpellPortions and aLastSpellContentSelections size mismatch" );
    2107             : 
    2108             :             //the simple case: the same number of elements on both sides
    2109             :             //each changed element has to be applied to the corresponding source element
    2110           0 :             svx::SpellPortions::const_iterator aCurrentNewPortion = rNewPortions.end();
    2111           0 :             svx::SpellPortions::const_iterator aCurrentOldPortion = pSpellInfo->aLastSpellPortions.end();
    2112           0 :             SpellContentSelections::const_iterator aCurrentOldPosition = pSpellInfo->aLastSpellContentSelections.end();
    2113           0 :             bool bSetToEnd = false;
    2114           0 :             do
    2115             :             {
    2116           0 :                 --aCurrentNewPortion;
    2117           0 :                 --aCurrentOldPortion;
    2118           0 :                 --aCurrentOldPosition;
    2119             :                 //set the cursor to the end of the sentence - necessary to
    2120             :                 //resume there at the next step
    2121           0 :                 if(!bSetToEnd)
    2122             :                 {
    2123           0 :                     bSetToEnd = true;
    2124           0 :                     rEditView.pImpEditView->SetEditSelection( aCurrentOldPosition->Max() );
    2125             :                 }
    2126             : 
    2127           0 :                 sal_uInt16 nScriptType = GetI18NScriptTypeOfLanguage( aCurrentNewPortion->eLanguage );
    2128           0 :                 sal_uInt16 nLangWhichId = EE_CHAR_LANGUAGE;
    2129           0 :                 switch(nScriptType)
    2130             :                 {
    2131           0 :                     case SCRIPTTYPE_ASIAN : nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
    2132           0 :                     case SCRIPTTYPE_COMPLEX : nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
    2133             :                 }
    2134           0 :                 if(aCurrentNewPortion->sText != aCurrentOldPortion->sText)
    2135             :                 {
    2136             :                     //change text and apply language
    2137           0 :                     SfxItemSet aSet( aEditDoc.GetItemPool(), nLangWhichId, nLangWhichId);
    2138           0 :                     aSet.Put(SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId));
    2139           0 :                     SetAttribs( *aCurrentOldPosition, aSet );
    2140           0 :                     ImpInsertText( *aCurrentOldPosition, aCurrentNewPortion->sText );
    2141             :                 }
    2142           0 :                 else if(aCurrentNewPortion->eLanguage != aCurrentOldPortion->eLanguage)
    2143             :                 {
    2144             :                     //apply language
    2145           0 :                     SfxItemSet aSet( aEditDoc.GetItemPool(), nLangWhichId, nLangWhichId);
    2146           0 :                     aSet.Put(SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId));
    2147           0 :                     SetAttribs( *aCurrentOldPosition, aSet );
    2148             :                 }
    2149           0 :                 if(aCurrentNewPortion == rNewPortions.begin())
    2150           0 :                     break;
    2151             :             }
    2152           0 :             while(aCurrentNewPortion != rNewPortions.begin());
    2153             :         }
    2154             :         else
    2155             :         {
    2156             :             DBG_ASSERT( !pSpellInfo->aLastSpellContentSelections.empty(), "aLastSpellContentSelections should not be empty here" );
    2157             : 
    2158             :             //select the complete sentence
    2159           0 :             SpellContentSelections::const_iterator aCurrentEndPosition = pSpellInfo->aLastSpellContentSelections.end();
    2160           0 :             --aCurrentEndPosition;
    2161           0 :             SpellContentSelections::const_iterator aCurrentStartPosition = pSpellInfo->aLastSpellContentSelections.begin();
    2162           0 :             EditSelection aAllSentence(aCurrentStartPosition->Min(), aCurrentEndPosition->Max());
    2163             : 
    2164             :             //delete the sentence completely
    2165           0 :             ImpDeleteSelection( aAllSentence );
    2166           0 :             svx::SpellPortions::const_iterator aCurrentNewPortion = rNewPortions.begin();
    2167           0 :             EditPaM aCurrentPaM = aAllSentence.Min();
    2168           0 :             while(aCurrentNewPortion != rNewPortions.end())
    2169             :             {
    2170             :                 //set the language attribute
    2171           0 :                 LanguageType eCurLanguage = GetLanguage( aCurrentPaM );
    2172           0 :                 if(eCurLanguage != aCurrentNewPortion->eLanguage)
    2173             :                 {
    2174           0 :                     sal_uInt16 nScriptType = GetI18NScriptTypeOfLanguage( aCurrentNewPortion->eLanguage );
    2175           0 :                     sal_uInt16 nLangWhichId = EE_CHAR_LANGUAGE;
    2176           0 :                     switch(nScriptType)
    2177             :                     {
    2178           0 :                         case SCRIPTTYPE_ASIAN : nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
    2179           0 :                         case SCRIPTTYPE_COMPLEX : nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
    2180             :                     }
    2181           0 :                     SfxItemSet aSet( aEditDoc.GetItemPool(), nLangWhichId, nLangWhichId);
    2182           0 :                     aSet.Put(SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId));
    2183           0 :                     SetAttribs( aCurrentPaM, aSet );
    2184             :                 }
    2185             :                 //insert the new string and set the cursor to the end of the inserted string
    2186           0 :                 aCurrentPaM = ImpInsertText( aCurrentPaM , aCurrentNewPortion->sText );
    2187           0 :                 ++aCurrentNewPortion;
    2188             :             }
    2189             :         }
    2190           0 :         UndoActionEnd( EDITUNDO_INSERT );
    2191             : 
    2192           0 :         EditPaM aNext;
    2193           0 :         if (bRecheck)
    2194           0 :             aNext = pSpellInfo->aCurSentenceStart;
    2195             :         else
    2196             :         {
    2197             :             // restore cursor position to the end of the modified sentence.
    2198             :             // (This will define the continuation position for spell/grammar checking)
    2199             :             // First: check if the sentence/para length changed
    2200           0 :             sal_Int32 nDelta = rEditView.pImpEditView->GetEditSelection().Max().GetNode()->Len() - nOldLen;
    2201           0 :             xub_StrLen nEndOfSentence = aOldSel.Max().GetIndex() + nDelta;
    2202           0 :             aNext = EditPaM( aOldSel.Max().GetNode(), nEndOfSentence );
    2203             :         }
    2204           0 :         rEditView.pImpEditView->SetEditSelection( aNext );
    2205             : 
    2206           0 :         FormatAndUpdate();
    2207           0 :         aEditDoc.SetModified(sal_True);
    2208             :     }
    2209           0 : }
    2210             : 
    2211           0 : void ImpEditEngine::PutSpellingToSentenceStart( EditView& rEditView )
    2212             : {
    2213           0 :     if( pSpellInfo && !pSpellInfo->aLastSpellContentSelections.empty() )
    2214             :     {
    2215           0 :         rEditView.pImpEditView->SetEditSelection( pSpellInfo->aLastSpellContentSelections.begin()->Min() );
    2216             :     }
    2217           0 : }
    2218             : 
    2219             : 
    2220        2871 : void ImpEditEngine::DoOnlineSpelling( ContentNode* pThisNodeOnly, sal_Bool bSpellAtCursorPos, sal_Bool bInteruptable )
    2221             : {
    2222             :     /*
    2223             :      It will iterate over all the paragraphs, paragraphs with only
    2224             :      invalidated wrong list will be checked ...
    2225             : 
    2226             :      All the words are checked in the invalidated region. Is a word wrong,
    2227             :      but not in the wrong list, or vice versa, the range of the word will be
    2228             :      invalidated
    2229             :      (no Invalidate, but if only transitions wrong from right =>, simple Paint,
    2230             :       even out properly with VDev on transitions from wrong => right)
    2231             :     */
    2232             : 
    2233        2871 :      if ( !xSpeller.is() )
    2234        2880 :         return;
    2235             : 
    2236        2862 :     EditPaM aCursorPos;
    2237        2862 :     if( pActiveView && !bSpellAtCursorPos )
    2238             :     {
    2239             :         DBG_CHKOBJ( pActiveView, EditView, 0 );
    2240           0 :         aCursorPos = pActiveView->pImpEditView->GetEditSelection().Max();
    2241             :     }
    2242        2862 :     sal_Bool bRestartTimer = sal_False;
    2243             : 
    2244        2862 :     ContentNode* pLastNode = aEditDoc.GetObject( aEditDoc.Count() - 1 );
    2245        2862 :     sal_Int32 nNodes = GetEditDoc().Count();
    2246        2862 :     sal_Int32 nInvalids = 0;
    2247        2862 :     Sequence< PropertyValue > aEmptySeq;
    2248        5755 :     for ( sal_Int32 n = 0; n < nNodes; n++ )
    2249             :     {
    2250        2893 :         ContentNode* pNode = GetEditDoc().GetObject( n );
    2251        2893 :         if ( pThisNodeOnly )
    2252           0 :             pNode = pThisNodeOnly;
    2253             : 
    2254        2893 :         if ( pNode->GetWrongList()->IsInvalid() )
    2255             :         {
    2256        2748 :             WrongList* pWrongList = pNode->GetWrongList();
    2257        2748 :             sal_uInt16 nInvStart = pWrongList->GetInvalidStart();
    2258        2748 :             sal_uInt16 nInvEnd = pWrongList->GetInvalidEnd();
    2259             : 
    2260        2748 :             sal_uInt16 nWrongs = 0; // Lose control also in the paragraphs
    2261        2748 :             sal_uInt16 nPaintFrom = 0xFFFF, nPaintTo = 0;
    2262        2748 :             sal_Bool bSimpleRepaint = sal_True;
    2263             : 
    2264        2748 :             pWrongList->SetValid();
    2265             : 
    2266        2748 :             EditPaM aPaM( pNode, nInvStart );
    2267        2748 :             EditSelection aSel( aPaM, aPaM );
    2268        9253 :             while ( ( aSel.Max().GetNode() == pNode ) /* && !bStop */ )
    2269             :             {
    2270       12948 :                 if ( ( aSel.Min().GetIndex() > nInvEnd )
    2271        6474 :                         || ( ( aSel.Max().GetNode() == pLastNode ) && ( aSel.Max().GetIndex() >= pLastNode->Len() ) ) )
    2272        2717 :                     break;  // Document end or end of invalid region
    2273             : 
    2274        3757 :                 aSel = SelectWord( aSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    2275        3757 :                 String aWord( GetSelected( aSel ) );
    2276             :                 // If afterwards a dot, this must be handed over!
    2277             :                 // If an abbreviation ...
    2278        3757 :                 sal_Bool bDottAdded = sal_False;
    2279        3757 :                 if ( aSel.Max().GetIndex() < aSel.Max().GetNode()->Len() )
    2280             :                 {
    2281        1092 :                     sal_Unicode cNext = aSel.Max().GetNode()->GetChar( aSel.Max().GetIndex() );
    2282        1092 :                     if ( cNext == '.' )
    2283             :                     {
    2284           0 :                         aSel.Max().GetIndex()++;
    2285           0 :                         aWord += cNext;
    2286           0 :                         bDottAdded = sal_True;
    2287             :                     }
    2288             :                 }
    2289             : 
    2290             : 
    2291        3757 :                 sal_Bool bChanged = sal_False;
    2292        3757 :                 if ( aWord.Len() > 0 )
    2293             :                 {
    2294        3716 :                     sal_uInt16 nWStart = aSel.Min().GetIndex();
    2295        3716 :                     sal_uInt16 nWEnd= aSel.Max().GetIndex();
    2296        3716 :                     if ( !xSpeller->isValid( aWord, GetLanguage( EditPaM( aSel.Min().GetNode(), nWStart+1 ) ), aEmptySeq ) )
    2297             :                     {
    2298             :                         // Check if already marked correctly...
    2299         160 :                         nWrongs++;
    2300         160 :                         sal_uInt16 nXEnd = bDottAdded ? nWEnd -1 : nWEnd;
    2301         160 :                         if ( !pWrongList->HasWrong( nWStart, nXEnd ) )
    2302             :                         {
    2303             :                             // Mark Word as wrong...
    2304             :                             // But only when not at Cursor-Position...
    2305         160 :                             sal_Bool bCursorPos = sal_False;
    2306         160 :                             if ( aCursorPos.GetNode() == pNode )
    2307             :                             {
    2308           0 :                                 if ( ( nWStart <= aCursorPos.GetIndex() ) && nWEnd >= aCursorPos.GetIndex() )
    2309           0 :                                     bCursorPos = sal_True;
    2310             :                             }
    2311         160 :                             if ( bCursorPos )
    2312             :                             {
    2313             :                                 // Then continue to mark as invalid ...
    2314           0 :                                 pWrongList->GetInvalidStart() = nWStart;
    2315           0 :                                 pWrongList->GetInvalidEnd() = nWEnd;
    2316           0 :                                 bRestartTimer = sal_True;
    2317             :                             }
    2318             :                             else
    2319             :                             {
    2320             :                                 // It may be that the Wrongs in the list ar not
    2321             :                                 // spanning exactly over words because the
    2322             :                                 // WordDelimiters during expansion are not
    2323             :                                 // evaluated.
    2324         160 :                                 pWrongList->InsertWrong( nWStart, nXEnd, sal_True );
    2325         160 :                                 bChanged = sal_True;
    2326             :                             }
    2327             :                         }
    2328             :                     }
    2329             :                     else
    2330             :                     {
    2331             :                         // Check if not marked as wrong
    2332        3556 :                         if ( pWrongList->HasAnyWrong( nWStart, nWEnd ) )
    2333             :                         {
    2334           0 :                             pWrongList->ClearWrongs( nWStart, nWEnd, pNode );
    2335           0 :                             bSimpleRepaint = sal_False;
    2336           0 :                             bChanged = sal_True;
    2337             :                         }
    2338             :                     }
    2339        3716 :                     if ( bChanged  )
    2340             :                     {
    2341         160 :                         if ( nPaintFrom == 0xFFFF )
    2342         159 :                             nPaintFrom = nWStart;
    2343         160 :                         nPaintTo = nWEnd;
    2344             :                     }
    2345             :                 }
    2346             : 
    2347        3757 :                 EditPaM aLastEnd( aSel.Max() );
    2348        3757 :                 aSel = WordRight( aSel.Max(), ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    2349        3917 :                 if ( bChanged && ( aSel.Min().GetNode() == pNode ) &&
    2350         160 :                         ( ( aSel.Min().GetIndex()-aLastEnd.GetIndex() > 1 ) ) )
    2351             :                 {
    2352             :                     // If two words are separated by more than one blank, it
    2353             :                     // can happen that when splitting a Wrongs the start of
    2354             :                     // the second word is before the actually word
    2355           0 :                     pWrongList->ClearWrongs( aLastEnd.GetIndex(), aSel.Min().GetIndex(), pNode );
    2356             :                 }
    2357        3757 :             }
    2358             : 
    2359             :             // Invalidate?
    2360        2748 :             if ( ( nPaintFrom != 0xFFFF ) )
    2361             :             {
    2362         159 :                 aStatus.GetStatusWord() |= EE_STAT_WRONGWORDCHANGED;
    2363         159 :                 CallStatusHdl();
    2364             : 
    2365         159 :                 if (!aEditViews.empty())
    2366             :                 {
    2367             :                     // For SimpleRepaint one was painted over a range without
    2368             :                     // reaching VDEV, but then one would have to intersect, c
    2369             :                     // clipping, ... over all views. Probably not worthwhile.
    2370           0 :                     EditPaM aStartPaM( pNode, nPaintFrom );
    2371           0 :                     EditPaM aEndPaM( pNode, nPaintTo );
    2372           0 :                     Rectangle aStartCursor( PaMtoEditCursor( aStartPaM ) );
    2373           0 :                     Rectangle aEndCursor( PaMtoEditCursor( aEndPaM ) );
    2374             :                     DBG_ASSERT( aInvalidRect.IsEmpty(), "InvalidRect set!" );
    2375           0 :                     aInvalidRect.Left() = 0;
    2376           0 :                     aInvalidRect.Right() = GetPaperSize().Width();
    2377           0 :                     aInvalidRect.Top() = aStartCursor.Top();
    2378           0 :                     aInvalidRect.Bottom() = aEndCursor.Bottom();
    2379           0 :                     if ( pActiveView && pActiveView->HasSelection() )
    2380             :                     {
    2381             :                         // Then no output through VDev.
    2382           0 :                         UpdateViews( NULL );
    2383             :                     }
    2384           0 :                     else if ( bSimpleRepaint )
    2385             :                     {
    2386           0 :                         for (size_t nView = 0; nView < aEditViews.size(); ++nView)
    2387             :                         {
    2388           0 :                             EditView* pView = aEditViews[nView];
    2389           0 :                             Rectangle aClipRect( aInvalidRect );
    2390           0 :                             aClipRect.Intersection( pView->GetVisArea() );
    2391           0 :                             if ( !aClipRect.IsEmpty() )
    2392             :                             {
    2393             :                                 // convert to window coordinates ....
    2394           0 :                                 aClipRect.SetPos( pView->pImpEditView->GetWindowPos( aClipRect.TopLeft() ) );
    2395             :                                 // If selected, then VDev ...
    2396           0 :                                 Paint( pView->pImpEditView, aClipRect, 0, pView->HasSelection() );
    2397             :                             }
    2398             :                         }
    2399             :                     }
    2400             :                     else
    2401             :                     {
    2402           0 :                         UpdateViews( pActiveView );
    2403             :                     }
    2404           0 :                     aInvalidRect = Rectangle();
    2405             :                 }
    2406             :             }
    2407             :             // After two corrected nodes give up the control ...
    2408        2748 :             nInvalids++;
    2409        2748 :             if ( bInteruptable && ( nInvalids >= 2 ) )
    2410             :             {
    2411           0 :                 bRestartTimer = sal_True;
    2412           0 :                 break;
    2413             :             }
    2414             :         }
    2415             : 
    2416        2893 :         if ( pThisNodeOnly )
    2417           0 :             break;
    2418             :     }
    2419        2862 :     if ( bRestartTimer )
    2420           0 :         aOnlineSpellTimer.Start();
    2421             : }
    2422             : 
    2423             : 
    2424           0 : EESpellState ImpEditEngine::HasSpellErrors()
    2425             : {
    2426             :     DBG_ASSERT( xSpeller.is(), "No spell checker set!" );
    2427             : 
    2428           0 :     ContentNode* pLastNode = aEditDoc.GetObject( aEditDoc.Count() - 1 );
    2429           0 :     EditSelection aCurSel( aEditDoc.GetStartPaM() );
    2430             : 
    2431           0 :     String aWord;
    2432           0 :     Reference< XSpellAlternatives > xSpellAlt;
    2433           0 :     Sequence< PropertyValue > aEmptySeq;
    2434           0 :     while ( !xSpellAlt.is() )
    2435             :     {
    2436           0 :         if ( ( aCurSel.Max().GetNode() == pLastNode ) &&
    2437           0 :              ( aCurSel.Max().GetIndex() >= pLastNode->Len() ) )
    2438             :         {
    2439           0 :             return EE_SPELL_OK;
    2440             :         }
    2441             : 
    2442           0 :         aCurSel = SelectWord( aCurSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    2443           0 :         aWord = GetSelected( aCurSel );
    2444           0 :         if ( aWord.Len() > 0 )
    2445             :         {
    2446           0 :             LanguageType eLang = GetLanguage( aCurSel.Max() );
    2447           0 :             SvxSpellWrapper::CheckSpellLang( xSpeller, eLang );
    2448           0 :             xSpellAlt = xSpeller->spell( aWord, eLang, aEmptySeq );
    2449             :         }
    2450           0 :         aCurSel = WordRight( aCurSel.Max(), ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    2451             :     }
    2452             : 
    2453           0 :     return EE_SPELL_ERRORFOUND;
    2454             : }
    2455             : 
    2456           0 : EESpellState ImpEditEngine::StartThesaurus( EditView* pEditView )
    2457             : {
    2458           0 :     EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() );
    2459           0 :     if ( !aCurSel.HasRange() )
    2460           0 :         aCurSel = SelectWord( aCurSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
    2461           0 :     String aWord( GetSelected( aCurSel ) );
    2462             : 
    2463           0 :     Reference< XThesaurus > xThes( SvxGetThesaurus() );
    2464           0 :     if (!xThes.is())
    2465           0 :         return EE_SPELL_ERRORFOUND;
    2466             : 
    2467           0 :     EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create();
    2468           0 :     AbstractThesaurusDialog* pDlg = pFact->CreateThesaurusDialog( pEditView->GetWindow(), xThes, aWord, GetLanguage( aCurSel.Max() ) );
    2469           0 :     if ( pDlg->Execute() == RET_OK )
    2470             :     {
    2471             :         // Replace Word...
    2472           0 :         pEditView->pImpEditView->DrawSelection();
    2473           0 :         pEditView->pImpEditView->SetEditSelection( aCurSel );
    2474           0 :         pEditView->pImpEditView->DrawSelection();
    2475           0 :         pEditView->InsertText( pDlg->GetWord() );
    2476           0 :         pEditView->ShowCursor( sal_True, sal_False );
    2477             :     }
    2478             : 
    2479           0 :     delete pDlg;
    2480           0 :     return EE_SPELL_OK;
    2481             : }
    2482             : 
    2483           0 : sal_uInt16 ImpEditEngine::StartSearchAndReplace( EditView* pEditView, const SvxSearchItem& rSearchItem )
    2484             : {
    2485           0 :     sal_uInt16 nFound = 0;
    2486             : 
    2487           0 :     EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() );
    2488             : 
    2489             :     // FIND_ALL is not possible without multiple selection.
    2490           0 :     if ( ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND ) ||
    2491           0 :          ( rSearchItem.GetCommand() == SVX_SEARCHCMD_FIND_ALL ) )
    2492             :     {
    2493           0 :         if ( Search( rSearchItem, pEditView ) )
    2494           0 :             nFound++;
    2495             :     }
    2496           0 :     else if ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE )
    2497             :     {
    2498             :         // The word is selected if the user not altered the selection
    2499             :         // in between:
    2500           0 :         if ( aCurSel.HasRange() )
    2501             :         {
    2502           0 :             pEditView->InsertText( rSearchItem.GetReplaceString() );
    2503           0 :             nFound = 1;
    2504             :         }
    2505             :         else
    2506           0 :             if( Search( rSearchItem, pEditView ) )
    2507           0 :                 nFound = 1;
    2508             :     }
    2509           0 :     else if ( rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL )
    2510             :     {
    2511             :         // The Writer replaces all front beginning to end ...
    2512           0 :         SvxSearchItem aTmpItem( rSearchItem );
    2513           0 :         aTmpItem.SetBackward( sal_False );
    2514             : 
    2515           0 :         pEditView->pImpEditView->DrawSelection();
    2516             : 
    2517           0 :         aCurSel.Adjust( aEditDoc );
    2518           0 :         EditPaM aStartPaM = aTmpItem.GetSelection() ? aCurSel.Min() : aEditDoc.GetStartPaM();
    2519           0 :         EditSelection aFoundSel( aCurSel.Max() );
    2520           0 :         sal_Bool bFound = ImpSearch( aTmpItem, aCurSel, aStartPaM, aFoundSel );
    2521           0 :         if ( bFound )
    2522           0 :             UndoActionStart( EDITUNDO_REPLACEALL );
    2523           0 :         while ( bFound )
    2524             :         {
    2525           0 :             nFound++;
    2526           0 :             aStartPaM = ImpInsertText( aFoundSel, rSearchItem.GetReplaceString() );
    2527           0 :             bFound = ImpSearch( aTmpItem, aCurSel, aStartPaM, aFoundSel );
    2528             :         }
    2529           0 :         if ( nFound )
    2530             :         {
    2531           0 :             EditPaM aNewPaM( aFoundSel.Max() );
    2532           0 :             if ( aNewPaM.GetIndex() > aNewPaM.GetNode()->Len() )
    2533           0 :                 aNewPaM.GetIndex() =  aNewPaM.GetNode()->Len();
    2534           0 :             pEditView->pImpEditView->SetEditSelection( aNewPaM );
    2535           0 :             FormatAndUpdate( pEditView );
    2536           0 :             UndoActionEnd( EDITUNDO_REPLACEALL );
    2537             :         }
    2538             :         else
    2539             :         {
    2540           0 :             pEditView->pImpEditView->DrawSelection();
    2541           0 :             pEditView->ShowCursor( sal_True, sal_False );
    2542           0 :         }
    2543             :     }
    2544           0 :     return nFound;
    2545             : }
    2546             : 
    2547           0 : sal_Bool ImpEditEngine::Search( const SvxSearchItem& rSearchItem, EditView* pEditView )
    2548             : {
    2549           0 :     EditSelection aSel( pEditView->pImpEditView->GetEditSelection() );
    2550           0 :     aSel.Adjust( aEditDoc );
    2551           0 :     EditPaM aStartPaM( aSel.Max() );
    2552           0 :     if ( rSearchItem.GetSelection() && !rSearchItem.GetBackward() )
    2553           0 :         aStartPaM = aSel.Min();
    2554             : 
    2555           0 :     EditSelection aFoundSel;
    2556           0 :     sal_Bool bFound = ImpSearch( rSearchItem, aSel, aStartPaM, aFoundSel );
    2557           0 :     if ( bFound && ( aFoundSel == aSel ) )  // For backwards-search
    2558             :     {
    2559           0 :         aStartPaM = aSel.Min();
    2560           0 :         bFound = ImpSearch( rSearchItem, aSel, aStartPaM, aFoundSel );
    2561             :     }
    2562             : 
    2563           0 :     pEditView->pImpEditView->DrawSelection();
    2564           0 :     if ( bFound )
    2565             :     {
    2566             :         // First, set the minimum, so the whole word is in the visible range.
    2567           0 :         pEditView->pImpEditView->SetEditSelection( aFoundSel.Min() );
    2568           0 :         pEditView->ShowCursor( sal_True, sal_False );
    2569           0 :         pEditView->pImpEditView->SetEditSelection( aFoundSel );
    2570             :     }
    2571             :     else
    2572           0 :         pEditView->pImpEditView->SetEditSelection( aSel.Max() );
    2573             : 
    2574           0 :     pEditView->pImpEditView->DrawSelection();
    2575           0 :     pEditView->ShowCursor( sal_True, sal_False );
    2576           0 :     return bFound;
    2577             : }
    2578             : 
    2579           0 : sal_Bool ImpEditEngine::ImpSearch( const SvxSearchItem& rSearchItem,
    2580             :     const EditSelection& rSearchSelection, const EditPaM& rStartPos, EditSelection& rFoundSel )
    2581             : {
    2582           0 :     util::SearchOptions aSearchOptions( rSearchItem.GetSearchOptions() );
    2583           0 :     aSearchOptions.Locale = GetLocale( rStartPos );
    2584             : 
    2585           0 :     sal_Bool bBack = rSearchItem.GetBackward();
    2586           0 :     sal_Bool bSearchInSelection = rSearchItem.GetSelection();
    2587           0 :     sal_Int32 nStartNode = aEditDoc.GetPos( rStartPos.GetNode() );
    2588             :     sal_Int32 nEndNode;
    2589           0 :     if ( bSearchInSelection )
    2590             :     {
    2591           0 :         nEndNode = aEditDoc.GetPos( bBack ? rSearchSelection.Min().GetNode() : rSearchSelection.Max().GetNode() );
    2592             :     }
    2593             :     else
    2594             :     {
    2595           0 :         nEndNode = bBack ? 0 : aEditDoc.Count()-1;
    2596             :     }
    2597             : 
    2598           0 :     utl::TextSearch aSearcher( aSearchOptions );
    2599             : 
    2600             :     // iterate over the paragraphs ...
    2601           0 :     for ( sal_Int32 nNode = nStartNode;
    2602             :             bBack ? ( nNode >= nEndNode ) : ( nNode <= nEndNode) ;
    2603             :             bBack ? nNode-- : nNode++ )
    2604             :     {
    2605             :         // For backwards-search if nEndNode = 0:
    2606           0 :         if ( nNode < 0 )
    2607           0 :             return sal_False;
    2608             : 
    2609           0 :         ContentNode* pNode = aEditDoc.GetObject( nNode );
    2610             : 
    2611           0 :         sal_Int32 nStartPos = 0;
    2612           0 :         sal_Int32 nEndPos = pNode->Len();
    2613           0 :         if ( nNode == nStartNode )
    2614             :         {
    2615           0 :             if ( bBack )
    2616           0 :                 nEndPos = rStartPos.GetIndex();
    2617             :             else
    2618           0 :                 nStartPos = rStartPos.GetIndex();
    2619             :         }
    2620           0 :         if ( ( nNode == nEndNode ) && bSearchInSelection )
    2621             :         {
    2622           0 :             if ( bBack )
    2623           0 :                 nStartPos = rSearchSelection.Min().GetIndex();
    2624             :             else
    2625           0 :                 nEndPos = rSearchSelection.Max().GetIndex();
    2626             :         }
    2627             : 
    2628             :         // Searching ...
    2629           0 :         OUString aParaStr( GetEditDoc().GetParaAsString( pNode ) );
    2630           0 :         bool bFound = false;
    2631           0 :         if ( bBack )
    2632             :         {
    2633             :             sal_Int32 nTemp;
    2634           0 :             nTemp = nStartPos;
    2635           0 :             nStartPos = nEndPos;
    2636           0 :             nEndPos = nTemp;
    2637             : 
    2638           0 :             bFound = aSearcher.SearchBackward( aParaStr, &nStartPos, &nEndPos);
    2639             :         }
    2640             :         else
    2641             :         {
    2642           0 :             bFound = aSearcher.SearchForward( aParaStr, &nStartPos, &nEndPos);
    2643             :         }
    2644           0 :         if ( bFound )
    2645             :         {
    2646           0 :             rFoundSel.Min().SetNode( pNode );
    2647           0 :             rFoundSel.Min().SetIndex( nStartPos );
    2648           0 :             rFoundSel.Max().SetNode( pNode );
    2649           0 :             rFoundSel.Max().SetIndex( nEndPos );
    2650           0 :             return sal_True;
    2651             :         }
    2652           0 :     }
    2653           0 :     return sal_False;
    2654             : }
    2655             : 
    2656           0 : sal_Bool ImpEditEngine::HasText( const SvxSearchItem& rSearchItem )
    2657             : {
    2658           0 :     SvxSearchItem aTmpItem( rSearchItem );
    2659           0 :     aTmpItem.SetBackward( sal_False );
    2660           0 :     aTmpItem.SetSelection( sal_False );
    2661             : 
    2662           0 :     EditPaM aStartPaM( aEditDoc.GetStartPaM() );
    2663           0 :     EditSelection aDummySel( aStartPaM );
    2664           0 :     EditSelection aFoundSel;
    2665           0 :     return ImpSearch( aTmpItem, aDummySel, aStartPaM, aFoundSel );
    2666             : }
    2667             : 
    2668           0 : void ImpEditEngine::SetAutoCompleteText( const String& rStr, sal_Bool bClearTipWindow )
    2669             : {
    2670           0 :     aAutoCompleteText = rStr;
    2671           0 :     if ( bClearTipWindow && pActiveView )
    2672           0 :         Help::ShowQuickHelp( pActiveView->GetWindow(), Rectangle(), String(), 0 );
    2673           0 : }
    2674             : 
    2675             : namespace
    2676             : {
    2677           0 :     struct eeTransliterationChgData
    2678             :     {
    2679             :         sal_uInt16                      nStart;
    2680             :         xub_StrLen                  nLen;
    2681             :         EditSelection               aSelection;
    2682             :         String                      aNewText;
    2683             :         uno::Sequence< sal_Int32 >  aOffsets;
    2684             :     };
    2685             : }
    2686             : 
    2687           0 : EditSelection ImpEditEngine::TransliterateText( const EditSelection& rSelection, sal_Int32 nTransliterationMode )
    2688             : {
    2689           0 :     uno::Reference < i18n::XBreakIterator > _xBI( ImplGetBreakIterator() );
    2690           0 :     if (!_xBI.is())
    2691           0 :         return rSelection;
    2692             : 
    2693           0 :     EditSelection aSel( rSelection );
    2694           0 :     aSel.Adjust( aEditDoc );
    2695             : 
    2696           0 :     if ( !aSel.HasRange() )
    2697           0 :         aSel = SelectWord( aSel );
    2698             : 
    2699           0 :     EditSelection aNewSel( aSel );
    2700             : 
    2701           0 :     const sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
    2702           0 :     const sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
    2703             : 
    2704           0 :     sal_Bool bChanges = sal_False;
    2705           0 :     sal_Bool bLenChanged = sal_False;
    2706           0 :     EditUndoTransliteration* pUndo = NULL;
    2707             : 
    2708           0 :     utl::TransliterationWrapper aTranslitarationWrapper( ::comphelper::getProcessComponentContext(), nTransliterationMode );
    2709           0 :     sal_Bool bConsiderLanguage = aTranslitarationWrapper.needLanguageForTheMode();
    2710             : 
    2711           0 :     for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++ )
    2712             :     {
    2713           0 :         ContentNode* pNode = aEditDoc.GetObject( nNode );
    2714           0 :         const XubString& aNodeStr = pNode->GetString();
    2715           0 :         xub_StrLen nStartPos = 0;
    2716           0 :         xub_StrLen nEndPos = aNodeStr.Len();
    2717           0 :         if ( nNode == nStartNode )
    2718           0 :             nStartPos = aSel.Min().GetIndex();
    2719           0 :         if ( nNode == nEndNode ) // can also be == nStart!
    2720           0 :             nEndPos = aSel.Max().GetIndex();
    2721             : 
    2722           0 :         sal_uInt16 nCurrentStart = nStartPos;
    2723           0 :         sal_uInt16 nCurrentEnd = nEndPos;
    2724           0 :         sal_uInt16 nLanguage = LANGUAGE_SYSTEM;
    2725             : 
    2726             :         // since we don't use Hiragana/Katakana or half-width/full-width transliterations here
    2727             :         // it is fine to use ANYWORD_IGNOREWHITESPACES. (ANY_WORD btw is broken and will
    2728             :         // occasionaly miss words in consecutive sentences). Also with ANYWORD_IGNOREWHITESPACES
    2729             :         // text like 'just-in-time' will be converted to 'Just-In-Time' which seems to be the
    2730             :         // proper thing to do.
    2731           0 :         const sal_Int16 nWordType = i18n::WordType::ANYWORD_IGNOREWHITESPACES;
    2732             : 
    2733             :         //! In order to have less trouble with changing text size, e.g. because
    2734             :         //! of ligatures or � (German small sz) being resolved, we need to process
    2735             :         //! the text replacements from end to start.
    2736             :         //! This way the offsets for the yet to be changed words will be
    2737             :         //! left unchanged by the already replaced text.
    2738             :         //! For this we temporarily save the changes to be done in this vector
    2739           0 :         std::vector< eeTransliterationChgData >   aChanges;
    2740           0 :         eeTransliterationChgData                  aChgData;
    2741             : 
    2742           0 :         if (nTransliterationMode == i18n::TransliterationModulesExtra::TITLE_CASE)
    2743             :         {
    2744             :             // for 'capitalize every word' we need to iterate over each word
    2745             : 
    2746           0 :             i18n::Boundary aSttBndry;
    2747           0 :             i18n::Boundary aEndBndry;
    2748           0 :             aSttBndry = _xBI->getWordBoundary(
    2749             :                         aNodeStr, nStartPos,
    2750             :                         GetLocale( EditPaM( pNode, nStartPos + 1 ) ),
    2751           0 :                         nWordType, true /*prefer forward direction*/);
    2752           0 :             aEndBndry = _xBI->getWordBoundary(
    2753             :                         aNodeStr, nEndPos,
    2754             :                         GetLocale( EditPaM( pNode, nEndPos + 1 ) ),
    2755           0 :                         nWordType, false /*prefer backward direction*/);
    2756             : 
    2757             :             // prevent backtracking to the previous word if selection is at word boundary
    2758           0 :             if (aSttBndry.endPos <= nStartPos)
    2759             :             {
    2760           0 :                 aSttBndry = _xBI->nextWord(
    2761             :                         aNodeStr, aSttBndry.endPos,
    2762             :                         GetLocale( EditPaM( pNode, aSttBndry.endPos + 1 ) ),
    2763           0 :                         nWordType);
    2764             :             }
    2765             :             // prevent advancing to the next word if selection is at word boundary
    2766           0 :             if (aEndBndry.startPos >= nEndPos)
    2767             :             {
    2768           0 :                 aEndBndry = _xBI->previousWord(
    2769             :                         aNodeStr, aEndBndry.startPos,
    2770             :                         GetLocale( EditPaM( pNode, aEndBndry.startPos + 1 ) ),
    2771           0 :                         nWordType);
    2772             :             }
    2773             : 
    2774           0 :             i18n::Boundary aCurWordBndry( aSttBndry );
    2775           0 :             while (aCurWordBndry.startPos <= aEndBndry.startPos)
    2776             :             {
    2777           0 :                 nCurrentStart = (xub_StrLen)aCurWordBndry.startPos;
    2778           0 :                 nCurrentEnd   = (xub_StrLen)aCurWordBndry.endPos;
    2779           0 :                 sal_Int32 nLen = nCurrentEnd - nCurrentStart;
    2780             :                 DBG_ASSERT( nLen > 0, "invalid word length of 0" );
    2781             : #if OSL_DEBUG_LEVEL > 1
    2782             :                 String aText(aNodeStr.Copy(nCurrentStart, nLen) );
    2783             : #endif
    2784             : 
    2785           0 :                 Sequence< sal_Int32 > aOffsets;
    2786             :                 String aNewText( aTranslitarationWrapper.transliterate(aNodeStr,
    2787           0 :                         GetLanguage( EditPaM( pNode, nCurrentStart + 1 ) ),
    2788           0 :                         nCurrentStart, nLen, &aOffsets ));
    2789             : 
    2790           0 :                 if (!aNodeStr.Equals( aNewText, nCurrentStart, nLen ))
    2791             :                 {
    2792           0 :                     aChgData.nStart     = nCurrentStart;
    2793           0 :                     aChgData.nLen       = nLen;
    2794           0 :                     aChgData.aSelection = EditSelection( EditPaM( pNode, nCurrentStart ), EditPaM( pNode, nCurrentEnd ) );
    2795           0 :                     aChgData.aNewText   = aNewText;
    2796           0 :                     aChgData.aOffsets   = aOffsets;
    2797           0 :                     aChanges.push_back( aChgData );
    2798             :                 }
    2799             : #if OSL_DEBUG_LEVEL > 1
    2800             :                 String aSelTxt ( GetSelected( aChgData.aSelection ) );
    2801             :                 (void) aSelTxt;
    2802             : #endif
    2803             : 
    2804           0 :                 aCurWordBndry = _xBI->nextWord(aNodeStr, nCurrentEnd,
    2805             :                         GetLocale( EditPaM( pNode, nCurrentEnd + 1 ) ),
    2806           0 :                         nWordType);
    2807           0 :             }
    2808             :             DBG_ASSERT( nCurrentEnd >= aEndBndry.endPos, "failed to reach end of transliteration" );
    2809             :         }
    2810           0 :         else if (nTransliterationMode == i18n::TransliterationModulesExtra::SENTENCE_CASE)
    2811             :         {
    2812             :             // for 'sentence case' we need to iterate sentence by sentence
    2813             : 
    2814           0 :             sal_Int32 nLastStart = _xBI->beginOfSentence(
    2815             :                     aNodeStr, nEndPos,
    2816           0 :                     GetLocale( EditPaM( pNode, nEndPos + 1 ) ) );
    2817           0 :             sal_Int32 nLastEnd = _xBI->endOfSentence(
    2818             :                     aNodeStr, nLastStart,
    2819           0 :                     GetLocale( EditPaM( pNode, nLastStart + 1 ) ) );
    2820             : 
    2821             :             // extend nCurrentStart, nCurrentEnd to the current sentence boundaries
    2822           0 :             nCurrentStart = _xBI->beginOfSentence(
    2823             :                     aNodeStr, nStartPos,
    2824           0 :                     GetLocale( EditPaM( pNode, nStartPos + 1 ) ) );
    2825           0 :             nCurrentEnd = _xBI->endOfSentence(
    2826             :                     aNodeStr, nCurrentStart,
    2827           0 :                     GetLocale( EditPaM( pNode, nCurrentStart + 1 ) ) );
    2828             : 
    2829             :             // prevent backtracking to the previous sentence if selection starts at end of a sentence
    2830           0 :             if (nCurrentEnd <= nStartPos)
    2831             :             {
    2832             :                 // now nCurrentStart is probably located on a non-letter word. (unless we
    2833             :                 // are in Asian text with no spaces...)
    2834             :                 // Thus to get the real sentence start we should locate the next real word,
    2835             :                 // that is one found by DICTIONARY_WORD
    2836           0 :                 i18n::Boundary aBndry = _xBI->nextWord( aNodeStr, nCurrentEnd,
    2837             :                         GetLocale( EditPaM( pNode, nCurrentEnd + 1 ) ),
    2838           0 :                         i18n::WordType::DICTIONARY_WORD);
    2839             : 
    2840             :                 // now get new current sentence boundaries
    2841           0 :                 nCurrentStart = _xBI->beginOfSentence(
    2842             :                         aNodeStr, aBndry.startPos,
    2843           0 :                         GetLocale( EditPaM( pNode, aBndry.startPos + 1 ) ) );
    2844           0 :                 nCurrentEnd = _xBI->endOfSentence(
    2845             :                         aNodeStr, nCurrentStart,
    2846           0 :                         GetLocale( EditPaM( pNode, nCurrentStart + 1 ) ) );
    2847             :             }
    2848             :             // prevent advancing to the next sentence if selection ends at start of a sentence
    2849           0 :             if (nLastStart >= nEndPos)
    2850             :             {
    2851             :                 // now nCurrentStart is probably located on a non-letter word. (unless we
    2852             :                 // are in Asian text with no spaces...)
    2853             :                 // Thus to get the real sentence start we should locate the previous real word,
    2854             :                 // that is one found by DICTIONARY_WORD
    2855           0 :                 i18n::Boundary aBndry = _xBI->previousWord( aNodeStr, nLastStart,
    2856             :                         GetLocale( EditPaM( pNode, nLastStart + 1 ) ),
    2857           0 :                         i18n::WordType::DICTIONARY_WORD);
    2858           0 :                 nLastEnd = _xBI->endOfSentence(
    2859             :                         aNodeStr, aBndry.startPos,
    2860           0 :                         GetLocale( EditPaM( pNode, aBndry.startPos + 1 ) ) );
    2861           0 :                 if (nCurrentEnd > nLastEnd)
    2862           0 :                     nCurrentEnd = nLastEnd;
    2863             :             }
    2864             : 
    2865           0 :             while (nCurrentStart < nLastEnd)
    2866             :             {
    2867           0 :                 sal_Int32 nLen = nCurrentEnd - nCurrentStart;
    2868             :                 DBG_ASSERT( nLen > 0, "invalid word length of 0" );
    2869             : #if OSL_DEBUG_LEVEL > 1
    2870             :                 String aText( aNodeStr.Copy( nCurrentStart, nLen ) );
    2871             : #endif
    2872             : 
    2873           0 :                 Sequence< sal_Int32 > aOffsets;
    2874             :                 String aNewText( aTranslitarationWrapper.transliterate( aNodeStr,
    2875           0 :                         GetLanguage( EditPaM( pNode, nCurrentStart + 1 ) ),
    2876           0 :                         nCurrentStart, nLen, &aOffsets ));
    2877             : 
    2878           0 :                 if (!aNodeStr.Equals( aNewText, nCurrentStart, nLen ))
    2879             :                 {
    2880           0 :                     aChgData.nStart     = nCurrentStart;
    2881           0 :                     aChgData.nLen       = nLen;
    2882           0 :                     aChgData.aSelection = EditSelection( EditPaM( pNode, nCurrentStart ), EditPaM( pNode, nCurrentEnd ) );
    2883           0 :                     aChgData.aNewText   = aNewText;
    2884           0 :                     aChgData.aOffsets   = aOffsets;
    2885           0 :                     aChanges.push_back( aChgData );
    2886             :                 }
    2887             : 
    2888           0 :                 i18n::Boundary aFirstWordBndry;
    2889           0 :                 aFirstWordBndry = _xBI->nextWord(
    2890             :                         aNodeStr, nCurrentEnd,
    2891             :                         GetLocale( EditPaM( pNode, nCurrentEnd + 1 ) ),
    2892           0 :                         nWordType);
    2893           0 :                 nCurrentStart = aFirstWordBndry.startPos;
    2894           0 :                 nCurrentEnd = _xBI->endOfSentence(
    2895             :                         aNodeStr, nCurrentStart,
    2896           0 :                         GetLocale( EditPaM( pNode, nCurrentStart + 1 ) ) );
    2897           0 :             }
    2898             :             DBG_ASSERT( nCurrentEnd >= nLastEnd, "failed to reach end of transliteration" );
    2899             :         }
    2900             :         else
    2901             :         {
    2902           0 :             do
    2903             :             {
    2904           0 :                 if ( bConsiderLanguage )
    2905             :                 {
    2906           0 :                     nLanguage = GetLanguage( EditPaM( pNode, nCurrentStart+1 ), &nCurrentEnd );
    2907           0 :                     if ( nCurrentEnd > nEndPos )
    2908           0 :                         nCurrentEnd = nEndPos;
    2909             :                 }
    2910             : 
    2911           0 :                 xub_StrLen nLen = nCurrentEnd - nCurrentStart;
    2912             : 
    2913           0 :                 Sequence< sal_Int32 > aOffsets;
    2914           0 :                 String aNewText( aTranslitarationWrapper.transliterate( aNodeStr, nLanguage, nCurrentStart, nLen, &aOffsets ) );
    2915             : 
    2916           0 :                 if (!aNodeStr.Equals( aNewText, nCurrentStart, nLen ))
    2917             :                 {
    2918           0 :                     aChgData.nStart     = nCurrentStart;
    2919           0 :                     aChgData.nLen       = nLen;
    2920           0 :                     aChgData.aSelection = EditSelection( EditPaM( pNode, nCurrentStart ), EditPaM( pNode, nCurrentEnd ) );
    2921           0 :                     aChgData.aNewText   = aNewText;
    2922           0 :                     aChgData.aOffsets   = aOffsets;
    2923           0 :                     aChanges.push_back( aChgData );
    2924             :                 }
    2925             : 
    2926           0 :                 nCurrentStart = nCurrentEnd;
    2927           0 :             } while( nCurrentEnd < nEndPos );
    2928             :         }
    2929             : 
    2930           0 :         if (!aChanges.empty())
    2931             :         {
    2932             :             // Create a single UndoAction on Demand for all the changes ...
    2933           0 :             if ( !pUndo && IsUndoEnabled() && !IsInUndo() )
    2934             :             {
    2935             :                 // adjust selection to include all changes
    2936           0 :                 for (size_t i = 0; i < aChanges.size(); ++i)
    2937             :                 {
    2938           0 :                     const EditSelection &rSel = aChanges[i].aSelection;
    2939           0 :                     if (aSel.Min().GetNode() == rSel.Min().GetNode() &&
    2940           0 :                         aSel.Min().GetIndex() > rSel.Min().GetIndex())
    2941           0 :                         aSel.Min().SetIndex( rSel.Min().GetIndex() );
    2942           0 :                     if (aSel.Max().GetNode() == rSel.Max().GetNode() &&
    2943           0 :                         aSel.Max().GetIndex() < rSel.Max().GetIndex())
    2944           0 :                         aSel.Max().SetIndex( rSel.Max().GetIndex() );
    2945             :                 }
    2946           0 :                 aNewSel = aSel;
    2947             : 
    2948           0 :                 ESelection aESel( CreateESel( aSel ) );
    2949           0 :                 pUndo = new EditUndoTransliteration(pEditEngine, aESel, nTransliterationMode);
    2950             : 
    2951           0 :                 const bool bSingleNode = aSel.Min().GetNode()== aSel.Max().GetNode();
    2952           0 :                 const bool bHasAttribs = aSel.Min().GetNode()->GetCharAttribs().HasAttrib( aSel.Min().GetIndex(), aSel.Max().GetIndex() );
    2953           0 :                 if (bSingleNode && !bHasAttribs)
    2954           0 :                     pUndo->SetText( aSel.Min().GetNode()->Copy( aSel.Min().GetIndex(), aSel.Max().GetIndex()-aSel.Min().GetIndex() ) );
    2955             :                 else
    2956           0 :                     pUndo->SetText( CreateTextObject( aSel, NULL ) );
    2957             :             }
    2958             : 
    2959             :             // now apply the changes from end to start to leave the offsets of the
    2960             :             // yet unchanged text parts remain the same.
    2961           0 :             for (size_t i = 0; i < aChanges.size(); ++i)
    2962             :             {
    2963           0 :                 eeTransliterationChgData& rData = aChanges[ aChanges.size() - 1 - i ];
    2964             : 
    2965           0 :                 bChanges = sal_True;
    2966           0 :                 if (rData.nLen != rData.aNewText.Len())
    2967           0 :                     bLenChanged = sal_True;
    2968             : 
    2969             :                 // Change text without loosing the attributes
    2970           0 :                 sal_uInt16 nDiffs = ReplaceTextOnly( rData.aSelection.Min().GetNode(),
    2971           0 :                         rData.nStart, rData.nLen, rData.aNewText, rData.aOffsets );
    2972             : 
    2973             :                 // adjust selection in end node to possibly changed size
    2974           0 :                 if (aSel.Max().GetNode() == rData.aSelection.Max().GetNode())
    2975           0 :                     aNewSel.Max().GetIndex() = aNewSel.Max().GetIndex() + nDiffs;
    2976             : 
    2977           0 :                 sal_Int32 nSelNode = aEditDoc.GetPos( rData.aSelection.Min().GetNode() );
    2978           0 :                 ParaPortion* pParaPortion = GetParaPortions()[nSelNode];
    2979             :                 pParaPortion->MarkSelectionInvalid( rData.nStart,
    2980             :                         std::max< sal_uInt16 >( rData.nStart + rData.nLen,
    2981           0 :                                             rData.nStart + rData.aNewText.Len() ) );
    2982             :             }
    2983             :         }
    2984           0 :     }
    2985             : 
    2986           0 :     if ( pUndo )
    2987             :     {
    2988           0 :         ESelection aESel( CreateESel( aNewSel ) );
    2989           0 :         pUndo->SetNewSelection( aESel );
    2990           0 :         InsertUndo( pUndo );
    2991             :     }
    2992             : 
    2993           0 :     if ( bChanges )
    2994             :     {
    2995           0 :         TextModified();
    2996           0 :         SetModifyFlag( sal_True );
    2997           0 :         if ( bLenChanged )
    2998           0 :             UpdateSelections();
    2999           0 :         FormatAndUpdate();
    3000             :     }
    3001             : 
    3002           0 :     return aNewSel;
    3003             : }
    3004             : 
    3005             : 
    3006           0 : short ImpEditEngine::ReplaceTextOnly(
    3007             :     ContentNode* pNode,
    3008             :     sal_uInt16 nCurrentStart, xub_StrLen nLen,
    3009             :     const String& rNewText,
    3010             :     const uno::Sequence< sal_Int32 >& rOffsets )
    3011             : {
    3012             :     (void)  nLen;
    3013             : 
    3014             :     // Change text without loosing the attributes
    3015             :     sal_uInt16 nCharsAfterTransliteration =
    3016           0 :         sal::static_int_cast< sal_uInt16 >(rOffsets.getLength());
    3017           0 :     const sal_Int32* pOffsets = rOffsets.getConstArray();
    3018           0 :     short nDiffs = 0;
    3019           0 :     for ( sal_uInt16 n = 0; n < nCharsAfterTransliteration; n++ )
    3020             :     {
    3021           0 :         sal_uInt16 nCurrentPos = nCurrentStart+n;
    3022           0 :         sal_Int32 nDiff = (nCurrentPos-nDiffs) - pOffsets[n];
    3023             : 
    3024           0 :         if ( !nDiff )
    3025             :         {
    3026             :             DBG_ASSERT( nCurrentPos < pNode->Len(), "TransliterateText - String smaller than expected!" );
    3027           0 :             pNode->SetChar( nCurrentPos, rNewText.GetChar(n) );
    3028             :         }
    3029           0 :         else if ( nDiff < 0 )
    3030             :         {
    3031             :             // Replace first char, delete the rest...
    3032             :             DBG_ASSERT( nCurrentPos < pNode->Len(), "TransliterateText - String smaller than expected!" );
    3033           0 :             pNode->SetChar( nCurrentPos, rNewText.GetChar(n) );
    3034             : 
    3035             :             DBG_ASSERT( (nCurrentPos+1) < pNode->Len(), "TransliterateText - String smaller than expected!" );
    3036           0 :             GetEditDoc().RemoveChars( EditPaM( pNode, nCurrentPos+1 ), sal::static_int_cast< sal_uInt16 >(-nDiff) );
    3037             :         }
    3038             :         else
    3039             :         {
    3040             :             DBG_ASSERT( nDiff == 1, "TransliterateText - Diff other than expected! But should work..." );
    3041           0 :             GetEditDoc().InsertText( EditPaM( pNode, nCurrentPos ), OUString(rNewText.GetChar(n)) );
    3042             : 
    3043             :         }
    3044           0 :         nDiffs = sal::static_int_cast< short >(nDiffs + nDiff);
    3045             :     }
    3046             : 
    3047           0 :     return nDiffs;
    3048             : }
    3049             : 
    3050             : 
    3051       25083 : void ImpEditEngine::SetAsianCompressionMode( sal_uInt16 n )
    3052             : {
    3053       25083 :     if ( n != nAsianCompressionMode )
    3054             :     {
    3055          10 :         nAsianCompressionMode = n;
    3056          10 :         if ( ImplHasText() )
    3057             :         {
    3058           0 :             FormatFullDoc();
    3059           0 :             UpdateViews();
    3060             :         }
    3061             :     }
    3062       25083 : }
    3063             : 
    3064       25083 : void ImpEditEngine::SetKernAsianPunctuation( bool b )
    3065             : {
    3066       25083 :     if ( b != bKernAsianPunctuation )
    3067             :     {
    3068           4 :         bKernAsianPunctuation = b;
    3069           4 :         if ( ImplHasText() )
    3070             :         {
    3071           0 :             FormatFullDoc();
    3072           0 :             UpdateViews();
    3073             :         }
    3074             :     }
    3075       25083 : }
    3076             : 
    3077       23960 : void ImpEditEngine::SetAddExtLeading( bool bExtLeading )
    3078             : {
    3079       23960 :     if ( IsAddExtLeading() != bExtLeading )
    3080             :     {
    3081        1700 :         bAddExtLeading = bExtLeading;
    3082        1700 :         if ( ImplHasText() )
    3083             :         {
    3084           0 :             FormatFullDoc();
    3085           0 :             UpdateViews();
    3086             :         }
    3087             :     }
    3088       23960 : };
    3089             : 
    3090             : 
    3091             : 
    3092        1714 : sal_Bool ImpEditEngine::ImplHasText() const
    3093             : {
    3094        1714 :     return ( ( GetEditDoc().Count() > 1 ) || GetEditDoc().GetObject(0)->Len() );
    3095             : }
    3096             : 
    3097           0 : sal_Int32 ImpEditEngine::LogicToTwips(sal_Int32 n)
    3098             : {
    3099           0 :     Size aSz(n, 0);
    3100           0 :     MapMode aTwipsMode( MAP_TWIP );
    3101           0 :     aSz = pRefDev->LogicToLogic( aSz, NULL, &aTwipsMode );
    3102           0 :     return aSz.Width();
    3103         267 : }
    3104             : 
    3105             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10