LCOV - code coverage report
Current view: top level - sw/source/uibase/lingu - hhcwrp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 191 283 67.5 %
Date: 2015-06-13 12:38:46 Functions: 17 22 77.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : #include <view.hxx>
      22             : #include <wrtsh.hxx>
      23             : #include <swundo.hxx>
      24             : #include <globals.hrc>
      25             : #include <splargs.hxx>
      26             : 
      27             : #include <vcl/msgbox.hxx>
      28             : #include <editeng/unolingu.hxx>
      29             : #include <editeng/langitem.hxx>
      30             : #include <editeng/fontitem.hxx>
      31             : #include <rtl/ustring.hxx>
      32             : #include <com/sun/star/text/RubyAdjust.hpp>
      33             : #include <hhcwrp.hxx>
      34             : #include <sdrhhcwrap.hxx>
      35             : #include <doc.hxx>
      36             : #include <docsh.hxx>
      37             : #include <mdiexp.hxx>
      38             : #include <edtwin.hxx>
      39             : #include <crsskip.hxx>
      40             : #include <index.hxx>
      41             : #include <pam.hxx>
      42             : #include <swcrsr.hxx>
      43             : #include <viscrs.hxx>
      44             : #include <ndtxt.hxx>
      45             : #include <fmtruby.hxx>
      46             : #include <breakit.hxx>
      47             : 
      48             : #include <olmenu.hrc>
      49             : 
      50             : #include <unomid.h>
      51             : 
      52             : using namespace ::com::sun::star;
      53             : using namespace ::com::sun::star::text;
      54             : using namespace ::com::sun::star::uno;
      55             : using namespace ::com::sun::star::linguistic2;
      56             : using namespace ::com::sun::star::i18n;
      57             : 
      58             : //     Description: Turn off frame/object shell if applicable
      59             : 
      60           2 : static void lcl_ActivateTextShell( SwWrtShell & rWrtSh )
      61             : {
      62           2 :     if( rWrtSh.IsSelFrmMode() || rWrtSh.IsObjSelected() )
      63           0 :         rWrtSh.EnterStdMode();
      64           2 : }
      65             : 
      66             : class SwKeepConversionDirectionStateContext
      67             : {
      68             : public:
      69           0 :     SwKeepConversionDirectionStateContext()
      70             :     {
      71             :         //!! hack to transport the current conversion direction state settings
      72             :         //!! into the next incarnation that iterates over the drawing objets
      73             :         //!! ( see SwHHCWrapper::~SwHHCWrapper() )
      74           0 :         editeng::HangulHanjaConversion::SetUseSavedConversionDirectionState( true );
      75           0 :     }
      76             : 
      77           0 :     ~SwKeepConversionDirectionStateContext()
      78             :     {
      79           0 :         editeng::HangulHanjaConversion::SetUseSavedConversionDirectionState( false );
      80           0 :     }
      81             : };
      82             : 
      83           4 : SwHHCWrapper::SwHHCWrapper(
      84             :         SwView* pSwView,
      85             :         const uno::Reference< uno::XComponentContext >& rxContext,
      86             :         LanguageType nSourceLanguage,
      87             :         LanguageType nTargetLanguage,
      88             :         const vcl::Font *pTargetFont,
      89             :         sal_Int32 nConvOptions,
      90             :         bool bIsInteractive,
      91             :         bool bStart, bool bOther, bool bSelection )
      92           4 :     : editeng::HangulHanjaConversion( &pSwView->GetEditWin(), rxContext,
      93             :                                 LanguageTag::convertToLocale( nSourceLanguage ),
      94             :                                 LanguageTag::convertToLocale( nTargetLanguage ),
      95             :                                 pTargetFont,
      96             :                                 nConvOptions,
      97             :                                 bIsInteractive )
      98             :     , m_pView( pSwView )
      99           4 :     , m_pWin( &pSwView->GetEditWin() )
     100           4 :     , m_rWrtShell( pSwView->GetWrtShell() )
     101             :     , m_pConvArgs( 0 )
     102             :     , m_nLastPos( 0 )
     103             :     , m_nUnitOffset( 0 )
     104             :     , m_nPageCount( 0 )
     105             :     , m_nPageStart( 0 )
     106             :     , m_bIsDrawObj( false )
     107             :     , m_bIsOtherContent( bOther )
     108             :     , m_bStartChk( bOther )
     109             :     , m_bIsSelection( bSelection )
     110           4 :     , m_bStartDone( bOther || bStart )
     111          20 :     , m_bEndDone( false )
     112             : {
     113           4 : }
     114             : 
     115           8 : SwHHCWrapper::~SwHHCWrapper()
     116             : {
     117           4 :     delete m_pConvArgs;
     118             : 
     119           4 :     SwViewShell::SetCareWin( NULL );
     120             : 
     121             :     // check for existence of a draw view which means that there are
     122             :     // (or previously were) draw objects present in the document.
     123             :     // I.e. we like to check those too.
     124           4 :     if ( IsDrawObj() /*&& bLastRet*/ && m_pView->GetWrtShell().HasDrawView() )
     125             :     {
     126           0 :         vcl::Cursor *pSave = m_pView->GetWindow()->GetCursor();
     127             :         {
     128           0 :             SwKeepConversionDirectionStateContext aContext;
     129             : 
     130           0 :             SdrHHCWrapper aSdrConvWrap( m_pView, GetSourceLanguage(),
     131           0 :                     GetTargetLanguage(), GetTargetFont(),
     132           0 :                     GetConversionOptions(), IsInteractive() );
     133           0 :             aSdrConvWrap.StartTextConversion();
     134             :         }
     135           0 :         m_pView->GetWindow()->SetCursor( pSave );
     136             :     }
     137             : 
     138           4 :     if( m_nPageCount )
     139           4 :         ::EndProgress( m_pView->GetDocShell() );
     140             : 
     141             :     // finally for chinese translation we need to change the documents
     142             :     // default language and font to the new ones to be used.
     143           4 :     LanguageType nTargetLang = GetTargetLanguage();
     144           4 :     if (IsChinese( nTargetLang ))
     145             :     {
     146           4 :         SwDoc *pDoc = m_pView->GetDocShell()->GetDoc();
     147             : 
     148             :         //!! Note: This also effects the default language of text boxes (EditEngine/EditView) !!
     149           4 :         pDoc->SetDefault( SvxLanguageItem( nTargetLang, RES_CHRATR_CJK_LANGUAGE ) );
     150             : 
     151           4 :         const vcl::Font *pFont = GetTargetFont();
     152           4 :         if (pFont)
     153             :         {
     154           0 :             SvxFontItem aFontItem( pFont->GetFamily(), pFont->GetName(),
     155           0 :                     pFont->GetStyleName(), pFont->GetPitch(),
     156           0 :                     pFont->GetCharSet(), RES_CHRATR_CJK_FONT );
     157           0 :             pDoc->SetDefault( aFontItem );
     158             :         }
     159             : 
     160             :     }
     161           4 : }
     162             : 
     163           6 : void SwHHCWrapper::GetNextPortion(
     164             :         OUString&           rNextPortion,
     165             :         LanguageType&       rLangOfPortion,
     166             :         bool bAllowChanges )
     167             : {
     168           6 :     m_pConvArgs->bAllowImplicitChangesForNotConvertibleText = bAllowChanges;
     169             : 
     170           6 :     FindConvText_impl();
     171           6 :     rNextPortion    = m_pConvArgs->aConvText;
     172           6 :     rLangOfPortion  = m_pConvArgs->nConvTextLang;
     173             : 
     174           6 :     m_nUnitOffset  = 0;
     175             : 
     176             :     // build last pos from currently selected text
     177           6 :     SwPaM* pCrsr = m_rWrtShell.GetCrsr();
     178           6 :     m_nLastPos =  pCrsr->Start()->nContent.GetIndex();
     179           6 : }
     180             : 
     181           2 : void SwHHCWrapper::SelectNewUnit_impl( sal_Int32 nUnitStart, sal_Int32 nUnitEnd )
     182             : {
     183           2 :     SwPaM *pCrsr = m_rWrtShell.GetCrsr();
     184           2 :     pCrsr->GetPoint()->nContent = m_nLastPos;
     185           2 :     pCrsr->DeleteMark();
     186             : 
     187             :     m_rWrtShell.Right( CRSR_SKIP_CHARS, /*bExpand*/ false,
     188           2 :                   (sal_uInt16) (m_nUnitOffset + nUnitStart), true );
     189           2 :     pCrsr->SetMark();
     190             :     m_rWrtShell.Right( CRSR_SKIP_CHARS, /*bExpand*/ true,
     191           2 :                   (sal_uInt16) (nUnitEnd - nUnitStart), true );
     192             :     // end selection now. Otherwise SHIFT+HOME (extending the selection)
     193             :     // won't work when the dialog is closed without any replacement.
     194             :     // (see #116346#)
     195           2 :     m_rWrtShell.EndSelect();
     196           2 : }
     197             : 
     198           0 : void SwHHCWrapper::HandleNewUnit(
     199             :         const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd )
     200             : {
     201             :     OSL_ENSURE( nUnitStart >= 0 && nUnitEnd >= nUnitStart, "wrong arguments" );
     202           0 :     if (!(0 <= nUnitStart && nUnitStart <= nUnitEnd))
     203           0 :         return;
     204             : 
     205           0 :     lcl_ActivateTextShell( m_rWrtShell );
     206             : 
     207           0 :     m_rWrtShell.StartAllAction();
     208             : 
     209             :     // select current unit
     210           0 :     SelectNewUnit_impl( nUnitStart, nUnitEnd );
     211             : 
     212           0 :     m_rWrtShell.EndAllAction();
     213             : }
     214             : 
     215           2 : void SwHHCWrapper::ChangeText( const OUString &rNewText,
     216             :         const OUString& rOrigText,
     217             :         const uno::Sequence< sal_Int32 > *pOffsets,
     218             :         SwPaM *pCrsr )
     219             : {
     220             :     //!! please see also TextConvWrapper::ChangeText with is a modified
     221             :     //!! copy of this code
     222             : 
     223             :     OSL_ENSURE( !rNewText.isEmpty(), "unexpected empty string" );
     224           2 :     if (rNewText.isEmpty())
     225           2 :         return;
     226             : 
     227           2 :     if (pOffsets && pCrsr)  // try to keep as much attributation as possible ?
     228             :     {
     229             :         // remember cursor start position for later setting of the cursor
     230           2 :         const SwPosition *pStart = pCrsr->Start();
     231           2 :         const sal_Int32 nStartIndex = pStart->nContent.GetIndex();
     232           2 :         const SwNodeIndex aStartNodeIndex  = pStart->nNode;
     233           2 :         SwTextNode *pStartTextNode = aStartNodeIndex.GetNode().GetTextNode();
     234             : 
     235           2 :         const sal_Int32  nIndices = pOffsets->getLength();
     236           2 :         const sal_Int32 *pIndices = pOffsets->getConstArray();
     237           2 :         sal_Int32 nConvTextLen = rNewText.getLength();
     238           2 :         sal_Int32 nPos = 0;
     239           2 :         sal_Int32 nChgPos = -1;
     240           2 :         sal_Int32 nChgLen = 0;
     241           2 :         sal_Int32 nConvChgPos = -1;
     242           2 :         sal_Int32 nConvChgLen = 0;
     243             : 
     244             :         // offset to calculate the position in the text taking into
     245             :         // account that text may have been replaced with new text of
     246             :         // different length. Negative values allowed!
     247           2 :         long nCorrectionOffset = 0;
     248             : 
     249             :         OSL_ENSURE(nIndices == 0 || nIndices == nConvTextLen,
     250             :                 "mismatch between string length and sequence length!" );
     251             : 
     252             :         // find all substrings that need to be replaced (and only those)
     253             :         while (true)
     254             :         {
     255             :             // get index in original text that matches nPos in new text
     256             :             sal_Int32 nIndex;
     257           4 :             if (nPos < nConvTextLen)
     258           2 :                 nIndex = nPos < nIndices ? pIndices[nPos] : nPos;
     259             :             else
     260             :             {
     261           2 :                 nPos   = nConvTextLen;
     262           2 :                 nIndex = rOrigText.getLength();
     263             :             }
     264             : 
     265           6 :             if (nPos == nConvTextLen || /* end of string also terminates non-matching char sequence */
     266           2 :                 rOrigText[nIndex] == rNewText[nPos])
     267             :             {
     268             :                 // substring that needs to be replaced found?
     269           2 :                 if (nChgPos != -1 && nConvChgPos != -1)
     270             :                 {
     271           2 :                     nChgLen = nIndex - nChgPos;
     272           2 :                     nConvChgLen = nPos - nConvChgPos;
     273           2 :                     OUString aInNew( rNewText.copy( nConvChgPos, nConvChgLen ) );
     274             : 
     275             :                     // set selection to sub string to be replaced in original text
     276           2 :                     sal_Int32 nChgInNodeStartIndex = nStartIndex + nCorrectionOffset + nChgPos;
     277             :                     OSL_ENSURE( m_rWrtShell.GetCrsr()->HasMark(), "cursor misplaced (nothing selected)" );
     278           2 :                     m_rWrtShell.GetCrsr()->GetMark()->nContent.Assign( pStartTextNode, nChgInNodeStartIndex );
     279           2 :                     m_rWrtShell.GetCrsr()->GetPoint()->nContent.Assign( pStartTextNode, nChgInNodeStartIndex + nChgLen );
     280             : 
     281             :                     // replace selected sub string with the corresponding
     282             :                     // sub string from the new text while keeping as
     283             :                     // much from the attributes as possible
     284           2 :                     ChangeText_impl( aInNew, true );
     285             : 
     286           2 :                     nCorrectionOffset += nConvChgLen - nChgLen;
     287             : 
     288           2 :                     nChgPos = -1;
     289           2 :                     nConvChgPos = -1;
     290             :                 }
     291             :             }
     292             :             else
     293             :             {
     294             :                 // begin of non-matching char sequence found ?
     295           2 :                 if (nChgPos == -1 && nConvChgPos == -1)
     296             :                 {
     297           2 :                     nChgPos = nIndex;
     298           2 :                     nConvChgPos = nPos;
     299             :                 }
     300             :             }
     301           4 :             if (nPos >= nConvTextLen)
     302           2 :                 break;
     303           2 :             ++nPos;
     304             :         }
     305             : 
     306             :         // set cursor to the end of all the new text
     307             :         // (as it would happen after ChangeText_impl (Delete and Insert)
     308             :         // of the whole text in the 'else' branch below)
     309           2 :         m_rWrtShell.ClearMark();
     310           2 :         m_rWrtShell.GetCrsr()->Start()->nContent.Assign( pStartTextNode, nStartIndex + nConvTextLen );
     311             :     }
     312             :     else
     313             :     {
     314           0 :         ChangeText_impl( rNewText, false );
     315             :     }
     316             : }
     317             : 
     318           2 : void SwHHCWrapper::ChangeText_impl( const OUString &rNewText, bool bKeepAttributes )
     319             : {
     320           2 :     if (bKeepAttributes)
     321             :     {
     322             :         // get item set with all relevant attributes
     323             :         sal_uInt16 aRanges[] = {
     324             :                 RES_CHRATR_BEGIN, RES_FRMATR_END,
     325           2 :                 0, 0, 0  };
     326           2 :         SfxItemSet aItemSet( m_rWrtShell.GetAttrPool(), aRanges );
     327             :         // get all attributes spanning the whole selection in order to
     328             :         // restore those for the new text
     329           2 :         m_rWrtShell.GetCurAttr( aItemSet );
     330             : 
     331           2 :         m_rWrtShell.Delete();
     332           2 :         m_rWrtShell.Insert( rNewText );
     333             : 
     334             :         // select new inserted text (currently the Point is right after the new text)
     335           2 :         if (!m_rWrtShell.GetCrsr()->HasMark())
     336           2 :             m_rWrtShell.GetCrsr()->SetMark();
     337           2 :         SwPosition *pMark = m_rWrtShell.GetCrsr()->GetMark();
     338           2 :         pMark->nContent = pMark->nContent.GetIndex() - rNewText.getLength();
     339             : 
     340             :         // since 'SetAttr' below functions like merging with the attributes
     341             :         // from the itemset with any existing ones we have to get rid of all
     342             :         // all attributes now. (Those attributes that may take effect left
     343             :         // to the position where the new text gets inserted after the old text
     344             :         // was deleted)
     345           2 :         m_rWrtShell.ResetAttr();
     346             :         // apply previously saved attributes to new text
     347           2 :         m_rWrtShell.SetAttrSet( aItemSet );
     348             :     }
     349             :     else
     350             :     {
     351           0 :         m_rWrtShell.Delete();
     352           0 :         m_rWrtShell.Insert( rNewText );
     353             :     }
     354           2 : }
     355             : 
     356           2 : void SwHHCWrapper::ReplaceUnit(
     357             :          const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd,
     358             :          const OUString& rOrigText,
     359             :          const OUString& rReplaceWith,
     360             :          const uno::Sequence< sal_Int32 > &rOffsets,
     361             :          ReplacementAction eAction,
     362             :          LanguageType *pNewUnitLanguage )
     363             : {
     364             :     OSL_ENSURE( nUnitStart >= 0 && nUnitEnd >= nUnitStart, "wrong arguments" );
     365           2 :     if (!(nUnitStart >= 0 && nUnitEnd >= nUnitStart))
     366           2 :         return;
     367             : 
     368           2 :     lcl_ActivateTextShell( m_rWrtShell );
     369             : 
     370             :     // replace the current word
     371           2 :     m_rWrtShell.StartAllAction();
     372             : 
     373             :     // select current unit
     374           2 :     SelectNewUnit_impl( nUnitStart, nUnitEnd );
     375             : 
     376           2 :     OUString aOrigText( m_rWrtShell.GetSelText() );
     377           4 :     OUString aNewText( rReplaceWith );
     378             :     OSL_ENSURE( aOrigText == rOrigText, "!! text mismatch !!" );
     379           2 :     SwFormatRuby *pRuby = 0;
     380           2 :     bool bRubyBelow = false;
     381           4 :     OUString  aNewOrigText;
     382           2 :     switch (eAction)
     383             :     {
     384             :         case eExchange :
     385           2 :         break;
     386             :         case eReplacementBracketed :
     387             :         {
     388           0 :             aNewText = aOrigText + "(" + rReplaceWith + ")";
     389             :         }
     390           0 :         break;
     391             :         case eOriginalBracketed :
     392             :         {
     393           0 :             aNewText = rReplaceWith + "(" + aOrigText + ")";
     394             :         }
     395           0 :         break;
     396             :         case eReplacementAbove  :
     397             :         {
     398           0 :             pRuby = new SwFormatRuby( rReplaceWith );
     399             :         }
     400           0 :         break;
     401             :         case eOriginalAbove :
     402             :         {
     403           0 :             pRuby = new SwFormatRuby( aOrigText );
     404           0 :             aNewOrigText = rReplaceWith;
     405             :         }
     406           0 :         break;
     407             :         case eReplacementBelow :
     408             :         {
     409           0 :             pRuby = new SwFormatRuby( rReplaceWith );
     410           0 :             bRubyBelow = true;
     411             :         }
     412           0 :         break;
     413             :         case eOriginalBelow :
     414             :         {
     415           0 :             pRuby = new SwFormatRuby( aOrigText );
     416           0 :             aNewOrigText = rReplaceWith;
     417           0 :             bRubyBelow = true;
     418             :         }
     419           0 :         break;
     420             :         default:
     421             :             OSL_FAIL("unexpected case" );
     422             :     }
     423           2 :     m_nUnitOffset += nUnitStart + aNewText.getLength();
     424             : 
     425           2 :     if (pRuby)
     426             :     {
     427           0 :         m_rWrtShell.StartUndo( UNDO_SETRUBYATTR );
     428           0 :         if (!aNewOrigText.isEmpty())
     429             :         {
     430             :             // according to FT we currently should not bother about keeping
     431             :             // attributes in Hangul/Hanja conversion
     432           0 :             ChangeText( aNewOrigText, rOrigText, NULL, NULL );
     433             : 
     434             :             //!! since Delete, Insert in 'ChangeText' do not set the WrtShells
     435             :             //!! bInSelect flag
     436             :             //!! back to false we do it now manually in order for the selection
     437             :             //!! to be done properly in the following call to Left.
     438             :             // We didn't fix it in Delete and Insert since it is currently
     439             :             // unclear if someone depends on this incorrect behvaiour
     440             :             // of the flag.
     441           0 :             m_rWrtShell.EndSelect();
     442             : 
     443           0 :             m_rWrtShell.Left( 0, true, aNewOrigText.getLength(), true, true );
     444             :         }
     445             : 
     446           0 :         pRuby->SetPosition( static_cast<sal_uInt16>(bRubyBelow) );
     447           0 :         pRuby->SetAdjustment( RubyAdjust_CENTER );
     448             : 
     449             : #if OSL_DEBUG_LEVEL > 1
     450             :         SwPaM *pPaM = m_rWrtShell.GetCrsr();
     451             :         (void)pPaM;
     452             : #endif
     453           0 :         m_rWrtShell.SetAttrItem(*pRuby);
     454           0 :         delete pRuby;
     455           0 :         m_rWrtShell.EndUndo( UNDO_SETRUBYATTR );
     456             :     }
     457             :     else
     458             :     {
     459           2 :         m_rWrtShell.StartUndo( UNDO_OVERWRITE );
     460             : 
     461             :         // according to FT we should currently not bother about keeping
     462             :         // attributes in Hangul/Hanja conversion and leave that untouched.
     463             :         // Thus we do this only for Chinese translation...
     464           2 :         const bool bIsChineseConversion = IsChinese( GetSourceLanguage() );
     465           2 :         if (bIsChineseConversion)
     466           2 :             ChangeText( aNewText, rOrigText, &rOffsets, m_rWrtShell.GetCrsr() );
     467             :         else
     468           0 :             ChangeText( aNewText, rOrigText, NULL, NULL );
     469             : 
     470             :         // change language and font if necessary
     471           2 :         if (bIsChineseConversion)
     472             :         {
     473           2 :             m_rWrtShell.SetMark();
     474           2 :             m_rWrtShell.GetCrsr()->GetMark()->nContent -= aNewText.getLength();
     475             : 
     476             :             OSL_ENSURE( GetTargetLanguage() == LANGUAGE_CHINESE_SIMPLIFIED || GetTargetLanguage() == LANGUAGE_CHINESE_TRADITIONAL,
     477             :                     "SwHHCWrapper::ReplaceUnit : unexpected target language" );
     478             : 
     479             :             sal_uInt16 aRanges[] = {
     480             :                     RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
     481             :                     RES_CHRATR_CJK_FONT,     RES_CHRATR_CJK_FONT,
     482           2 :                     0, 0, 0  };
     483             : 
     484           2 :             SfxItemSet aSet( m_rWrtShell.GetAttrPool(), aRanges );
     485           2 :             if (pNewUnitLanguage)
     486             :             {
     487           1 :                 aSet.Put( SvxLanguageItem( *pNewUnitLanguage, RES_CHRATR_CJK_LANGUAGE ) );
     488             :             }
     489             : 
     490           2 :             const vcl::Font *pTargetFont = GetTargetFont();
     491             :             OSL_ENSURE( pTargetFont, "target font missing?" );
     492           2 :             if (pTargetFont && pNewUnitLanguage)
     493             :             {
     494           0 :                 SvxFontItem aFontItem(static_cast<const SvxFontItem&>( aSet.Get( RES_CHRATR_CJK_FONT ) ));
     495           0 :                 aFontItem.SetFamilyName(    pTargetFont->GetName());
     496           0 :                 aFontItem.SetFamily(        pTargetFont->GetFamily());
     497           0 :                 aFontItem.SetStyleName(     pTargetFont->GetStyleName());
     498           0 :                 aFontItem.SetPitch(         pTargetFont->GetPitch());
     499           0 :                 aFontItem.SetCharSet( pTargetFont->GetCharSet() );
     500           0 :                 aSet.Put( aFontItem );
     501             :             }
     502             : 
     503           2 :             m_rWrtShell.SetAttrSet( aSet );
     504             : 
     505           2 :             m_rWrtShell.ClearMark();
     506             :         }
     507             : 
     508           2 :         m_rWrtShell.EndUndo( UNDO_OVERWRITE );
     509             :     }
     510             : 
     511           4 :     m_rWrtShell.EndAllAction();
     512             : }
     513             : 
     514           0 : bool SwHHCWrapper::HasRubySupport() const
     515             : {
     516           0 :     return true;
     517             : }
     518             : 
     519           4 : void SwHHCWrapper::Convert()
     520             : {
     521             :     OSL_ENSURE( m_pConvArgs == 0, "NULL pointer expected" );
     522             :     {
     523           4 :         SwPaM *pCrsr = m_pView->GetWrtShell().GetCrsr();
     524           4 :         SwPosition* pSttPos = pCrsr->Start();
     525           4 :         SwPosition* pEndPos = pCrsr->End();
     526             : 
     527           8 :         if (pSttPos->nNode.GetNode().IsTextNode() &&
     528           4 :             pEndPos->nNode.GetNode().IsTextNode())
     529             :         {
     530           4 :             m_pConvArgs = new SwConversionArgs( GetSourceLanguage(),
     531           4 :                             pSttPos->nNode.GetNode().GetTextNode(), pSttPos->nContent,
     532           8 :                             pEndPos->nNode.GetNode().GetTextNode(), pEndPos->nContent );
     533             :         }
     534             :         else    // we are not in the text (maybe a graphic or OLE object is selected) let's start from the top
     535             :         {
     536             :             // get PaM that points to the start of the document
     537           0 :             SwNode& rNode = m_pView->GetDocShell()->GetDoc()->GetNodes().GetEndOfContent();
     538           0 :             SwPaM aPam(rNode);
     539           0 :             aPam.Move( fnMoveBackward, fnGoDoc ); // move to start of document
     540             : 
     541           0 :             pSttPos = aPam.GetPoint();  //! using a PaM here makes sure we will get only text nodes
     542           0 :             SwTextNode *pTextNode = pSttPos->nNode.GetNode().GetTextNode();
     543             :             // just in case we check anyway...
     544           0 :             if (!pTextNode || !pTextNode->IsTextNode())
     545           4 :                 return;
     546           0 :             m_pConvArgs = new SwConversionArgs( GetSourceLanguage(),
     547             :                             pTextNode, pSttPos->nContent,
     548           0 :                             pTextNode, pSttPos->nContent );
     549             :         }
     550             :         OSL_ENSURE( m_pConvArgs->pStartNode && m_pConvArgs->pStartNode->IsTextNode(),
     551             :                 "failed to get proper start text node" );
     552             :         OSL_ENSURE( m_pConvArgs->pEndNode && m_pConvArgs->pEndNode->IsTextNode(),
     553             :                 "failed to get proper end text node" );
     554             : 
     555             :         // chinese conversion specific settings
     556             :         OSL_ENSURE( IsChinese( GetSourceLanguage() ) == IsChinese( GetTargetLanguage() ),
     557             :                 "source and target language mismatch?" );
     558           4 :         if (IsChinese( GetTargetLanguage() ))
     559             :         {
     560           4 :             m_pConvArgs->nConvTargetLang = GetTargetLanguage();
     561           4 :             m_pConvArgs->pTargetFont = GetTargetFont();
     562           4 :             m_pConvArgs->bAllowImplicitChangesForNotConvertibleText = true;
     563             :         }
     564             : 
     565             :         // if it is not just a selection and we are about to begin
     566             :         // with the current conversion for the very first time
     567             :         // we need to find the start of the current (initial)
     568             :         // convertible unit in order for the text conversion to give
     569             :         // the correct result for that. Since it is easier to obtain
     570             :         // the start of the word we use that though.
     571           4 :         if (!pCrsr->HasMark())   // is not a selection?
     572             :         {
     573             :             // since #118246 / #117803 still occurs if the cursor is placed
     574             :             // between the two chinese characters to be converted (because both
     575             :             // of them are words on their own!) using the word boundary here does
     576             :             // not work. Thus since chinese conversion is not interactive we start
     577             :             // at the begin of the paragraph to solve the problem, i.e. have the
     578             :             // TextConversion service get those characters together in the same call.
     579           4 :             sal_Int32 nStartIdx = -1;
     580           4 :             if (editeng::HangulHanjaConversion::IsChinese( GetSourceLanguage() ) )
     581           4 :                 nStartIdx = 0;
     582             :             else
     583             :             {
     584           0 :                 OUString aText( m_pConvArgs->pStartNode->GetText() );
     585           0 :                 const sal_Int32 nPos = m_pConvArgs->pStartIdx->GetIndex();
     586           0 :                 Boundary aBoundary( g_pBreakIt->GetBreakIter()->
     587           0 :                         getWordBoundary( aText, nPos, g_pBreakIt->GetLocale( m_pConvArgs->nConvSrcLang ),
     588           0 :                                 WordType::DICTIONARY_WORD, true ) );
     589             : 
     590             :                 // valid result found?
     591           0 :                 if (aBoundary.startPos < aText.getLength() &&
     592           0 :                     aBoundary.startPos != aBoundary.endPos)
     593             :                 {
     594           0 :                     nStartIdx = aBoundary.startPos;
     595           0 :                 }
     596             :             }
     597             : 
     598           4 :             if (nStartIdx != -1)
     599           4 :                 *m_pConvArgs->pStartIdx = nStartIdx;
     600             :         }
     601             :     }
     602             : 
     603           4 :     if ( m_bIsOtherContent )
     604           0 :         ConvStart_impl( m_pConvArgs, SVX_SPELL_OTHER );
     605             :     else
     606             :     {
     607           4 :         m_bStartChk = false;
     608           4 :         ConvStart_impl( m_pConvArgs, SVX_SPELL_BODY_END );
     609             :     }
     610             : 
     611           4 :     ConvertDocument();
     612             : 
     613           4 :     ConvEnd_impl( m_pConvArgs );
     614             : }
     615             : 
     616           4 : bool SwHHCWrapper::ConvNext_impl( )
     617             : {
     618             :     //! modified version of SvxSpellWrapper::SpellNext
     619             : 
     620             :     // no change of direction so the desired region is fully processed
     621           4 :     if( m_bStartChk )
     622           0 :         m_bStartDone = true;
     623             :     else
     624           4 :         m_bEndDone = true;
     625             : 
     626           4 :     if( m_bIsOtherContent && m_bStartDone && m_bEndDone ) // document completely checked?
     627             :     {
     628           0 :         return false;
     629             :     }
     630             : 
     631           4 :     bool bGoOn = false;
     632             : 
     633           4 :     if ( m_bIsOtherContent )
     634             :     {
     635           0 :         m_bStartChk = false;
     636           0 :         ConvStart_impl( m_pConvArgs, SVX_SPELL_BODY );
     637           0 :         bGoOn = true;
     638             :     }
     639           4 :     else if ( m_bStartDone && m_bEndDone )
     640             :     {
     641             :         // body region done, ask about special region
     642           8 :         if( HasOtherCnt_impl() )
     643             :         {
     644           0 :             ConvStart_impl( m_pConvArgs, SVX_SPELL_OTHER );
     645           0 :             m_bIsOtherContent = bGoOn = true;
     646             :         }
     647             :     }
     648             :     else
     649             :     {
     650           0 :             m_bStartChk = !m_bStartDone;
     651           0 :             ConvStart_impl( m_pConvArgs, m_bStartChk ? SVX_SPELL_BODY_START : SVX_SPELL_BODY_END );
     652           0 :             bGoOn = true;
     653             :     }
     654           4 :     return bGoOn;
     655             : }
     656             : 
     657           6 : bool SwHHCWrapper::FindConvText_impl()
     658             : {
     659             :     //! modified version of SvxSpellWrapper::FindSpellError
     660             : 
     661           6 :     bool bFound = false;
     662             : 
     663           6 :     m_pWin->EnterWait();
     664           6 :     bool bConv = true;
     665             : 
     666          18 :     while ( bConv )
     667             :     {
     668           6 :         bFound = ConvContinue_impl( m_pConvArgs );
     669           6 :         if (bFound)
     670             :         {
     671           2 :             bConv = false;
     672             :         }
     673             :         else
     674             :         {
     675           4 :             ConvEnd_impl( m_pConvArgs );
     676           4 :             bConv = ConvNext_impl();
     677             :         }
     678             :     }
     679           6 :     m_pWin->LeaveWait();
     680           6 :     return bFound;
     681             : }
     682             : 
     683           4 : bool SwHHCWrapper::HasOtherCnt_impl()
     684             : {
     685           4 :     return !m_bIsSelection && m_rWrtShell.HasOtherCnt();
     686             : }
     687             : 
     688           4 : void SwHHCWrapper::ConvStart_impl( SwConversionArgs /* [out] */ *pConversionArgs, SvxSpellArea eArea )
     689             : {
     690           4 :     SetDrawObj( SVX_SPELL_OTHER == eArea );
     691           4 :     m_pView->SpellStart( eArea, m_bStartDone, m_bEndDone, /* [out] */ pConversionArgs );
     692           4 : }
     693             : 
     694           8 : void SwHHCWrapper::ConvEnd_impl( SwConversionArgs *pConversionArgs )
     695             : {
     696           8 :     m_pView->SpellEnd( pConversionArgs );
     697           8 : }
     698             : 
     699           6 : bool SwHHCWrapper::ConvContinue_impl( SwConversionArgs *pConversionArgs )
     700             : {
     701           6 :     bool bProgress = !m_bIsDrawObj && !m_bIsSelection;
     702           6 :     (pConversionArgs->aConvText).clear();
     703           6 :     pConversionArgs->nConvTextLang = LANGUAGE_NONE;
     704           6 :     m_pView->GetWrtShell().SpellContinue( &m_nPageCount, bProgress ? &m_nPageStart : NULL, pConversionArgs );
     705           6 :     return !pConversionArgs->aConvText.isEmpty();
     706         177 : }
     707             : 
     708             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11