merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / lingu / hhcwrp.cxx
blobe41c5ba97fbc7b40d6947a2465435d67b30b31cd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hhcwrp.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef PRECOMPILED
34 #include "ui_pch.hxx"
35 #endif
38 #include <hintids.hxx>
39 #ifndef _VIEW_HXX
40 #include <view.hxx>
41 #endif
42 #include <wrtsh.hxx>
43 #include <swundo.hxx> // fuer Undo-Ids
44 #ifndef _GLOBALS_HRC
45 #include <globals.hrc>
46 #endif
47 #include <splargs.hxx>
50 #ifndef _MSGBOX_HXX //autogen
51 #include <vcl/msgbox.hxx>
52 #endif
53 #include <svx/unolingu.hxx>
54 #include <svx/langitem.hxx>
55 #include <svx/fontitem.hxx>
56 #include <rtl/ustring.hxx>
57 #include <com/sun/star/text/RubyAdjust.hpp>
58 #include <hhcwrp.hxx>
59 #include <sdrhhcwrap.hxx>
60 #include <doc.hxx>
61 #include <docsh.hxx>
62 #include <txatritr.hxx>
63 #include <mdiexp.hxx> // Progress
64 #include <edtwin.hxx>
65 #include <crsskip.hxx>
66 #include <index.hxx>
67 #include <pam.hxx>
68 #include <swcrsr.hxx>
69 #include <viscrs.hxx>
70 #include <ndtxt.hxx>
71 #include <fmtruby.hxx>
72 #include <breakit.hxx>
73 #include <docsh.hxx>
75 #ifndef _OLMENU_HRC
76 #include <olmenu.hrc>
77 #endif
79 #include <unomid.h>
81 using ::rtl::OUString;
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::text;
84 using namespace ::com::sun::star::uno;
85 using namespace ::com::sun::star::linguistic2;
86 using namespace ::com::sun::star::i18n;
88 #define CHAR_PAR_BRK ((sal_Char) 0x0D)
90 //////////////////////////////////////////////////////////////////////
91 // Beschreibung: Ggf. Rahmen/Objektshell abschalten
93 static void lcl_ActivateTextShell( SwWrtShell & rWrtSh )
95 if( rWrtSh.IsSelFrmMode() || rWrtSh.IsObjSelected() )
96 rWrtSh.EnterStdMode();
99 //////////////////////////////////////////////////////////////////////
101 class SwKeepConversionDirectionStateContext
103 public:
104 SwKeepConversionDirectionStateContext()
106 //!! hack to transport the current conversion direction state settings
107 //!! into the next incarnation that iterates over the drawing objets
108 //!! ( see SwHHCWrapper::~SwHHCWrapper() )
109 svx::HangulHanjaConversion::SetUseSavedConversionDirectionState( sal_True );
112 ~SwKeepConversionDirectionStateContext()
114 svx::HangulHanjaConversion::SetUseSavedConversionDirectionState( sal_False );
118 //////////////////////////////////////////////////////////////////////
120 SwHHCWrapper::SwHHCWrapper(
121 SwView* pSwView,
122 const uno::Reference< lang::XMultiServiceFactory >& rxMSF,
123 LanguageType nSourceLanguage,
124 LanguageType nTargetLanguage,
125 const Font *pTargetFont,
126 sal_Int32 nConvOptions,
127 sal_Bool bIsInteractive,
128 sal_Bool bStart, sal_Bool bOther, sal_Bool bSelection ) :
129 svx::HangulHanjaConversion( &pSwView->GetEditWin(), rxMSF,
130 SvxCreateLocale( nSourceLanguage ),
131 SvxCreateLocale( nTargetLanguage ),
132 pTargetFont,
133 nConvOptions,
134 bIsInteractive ),
135 rWrtShell( pSwView->GetWrtShell() )
137 pConvArgs = 0;
138 nLastPos = 0;
139 nUnitOffset = 0;
141 pView = pSwView;
142 pWin = &pSwView->GetEditWin();
143 bIsDrawObj = sal_False;
144 bIsStart = bStart;
145 bIsOtherCntnt = bStartChk = bOther;
146 bIsConvSpecial = sal_True;
147 bIsSelection = bSelection;
148 bInfoBox = sal_False;
149 bStartDone = bOther || bStart;
150 bEndDone = sal_False;
151 // bLastRet = sal_True;
152 nPageCount = nPageStart = 0;
156 SwHHCWrapper::~SwHHCWrapper()
158 delete pConvArgs;
160 rWrtShell.SetCareWin( NULL );
162 // check for existence of a draw view which means that there are
163 // (or previously were) draw objects present in the document.
164 // I.e. we like to check those too.
165 if ( IsDrawObj() /*&& bLastRet*/ && pView->GetWrtShell().HasDrawView() )
167 Cursor *pSave = pView->GetWindow()->GetCursor();
169 SwKeepConversionDirectionStateContext aContext;
171 SdrHHCWrapper aSdrConvWrap( pView, GetSourceLanguage(),
172 GetTargetLanguage(), GetTargetFont(),
173 GetConversionOptions(), IsInteractive() );
174 aSdrConvWrap.StartTextConversion();
176 pView->GetWindow()->SetCursor( pSave );
179 if( nPageCount )
180 ::EndProgress( pView->GetDocShell() );
182 // finally for chinese translation we need to change the the documents
183 // default language and font to the new ones to be used.
184 LanguageType nTargetLang = GetTargetLanguage();
185 if (IsChinese( nTargetLang ))
187 SwDoc *pDoc = pView->GetDocShell()->GetDoc();
189 //!! Note: This also effects the default language of text boxes (EditEngine/EditView) !!
190 pDoc->SetDefault( SvxLanguageItem( nTargetLang, RES_CHRATR_CJK_LANGUAGE ) );
192 const Font *pFont = GetTargetFont();
193 if (pFont)
195 SvxFontItem aFontItem( pFont->GetFamily(), pFont->GetName(),
196 pFont->GetStyleName(), pFont->GetPitch(),
197 pFont->GetCharSet(), RES_CHRATR_CJK_FONT );
198 pDoc->SetDefault( aFontItem );
204 if( bInfoBox )
205 InfoBox(&pView->GetEditWin(), String(SW_RES(STR_SPELL_OK)) ).Execute();
210 void SwHHCWrapper::GetNextPortion(
211 ::rtl::OUString& rNextPortion,
212 LanguageType& rLangOfPortion,
213 sal_Bool bAllowChanges )
215 pConvArgs->bAllowImplicitChangesForNotConvertibleText = bAllowChanges;
217 FindConvText_impl();
218 rNextPortion = pConvArgs->aConvText;
219 rLangOfPortion = pConvArgs->nConvTextLang;
221 nUnitOffset = 0;
223 // build last pos from currently selected text
224 SwPaM* pCrsr = rWrtShell.GetCrsr();
225 nLastPos = pCrsr->Start()->nContent.GetIndex();
229 void SwHHCWrapper::SelectNewUnit_impl( sal_Int32 nUnitStart, sal_Int32 nUnitEnd )
231 SwPaM *pCrsr = rWrtShell.GetCrsr();
232 pCrsr->GetPoint()->nContent = nLastPos;
233 pCrsr->DeleteMark();
235 rWrtShell.Right( CRSR_SKIP_CHARS, /*bExpand*/ sal_False,
236 (USHORT) (nUnitOffset + nUnitStart), sal_True );
237 pCrsr->SetMark();
238 rWrtShell.Right( CRSR_SKIP_CHARS, /*bExpand*/ sal_True,
239 (USHORT) (nUnitEnd - nUnitStart), sal_True );
240 // end selection now. Otherwise SHIFT+HOME (extending the selection)
241 // won't work when the dialog is closed without any replacement.
242 // (see #116346#)
243 rWrtShell.EndSelect();
247 void SwHHCWrapper::HandleNewUnit(
248 const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd )
250 DBG_ASSERT( nUnitStart >= 0 && nUnitEnd >= nUnitStart, "wrong arguments" );
251 if (!(0 <= nUnitStart && nUnitStart <= nUnitEnd))
252 return;
254 lcl_ActivateTextShell( rWrtShell );
256 rWrtShell.StartAllAction();
258 // select current unit
259 SelectNewUnit_impl( nUnitStart, nUnitEnd );
261 rWrtShell.EndAllAction();
265 void SwHHCWrapper::ChangeText( const String &rNewText,
266 const OUString& rOrigText,
267 const uno::Sequence< sal_Int32 > *pOffsets,
268 SwPaM *pCrsr )
270 //!! please see also TextConvWrapper::ChangeText with is a modified
271 //!! copy of this code
273 DBG_ASSERT( rNewText.Len() != 0, "unexpected empty string" );
274 if (rNewText.Len() == 0)
275 return;
277 if (pOffsets && pCrsr) // try to keep as much attributation as possible ?
279 // remember cursor start position for later setting of the cursor
280 const SwPosition *pStart = pCrsr->Start();
281 const xub_StrLen nStartIndex = pStart->nContent.GetIndex();
282 const SwNodeIndex aStartNodeIndex = pStart->nNode;
283 SwTxtNode *pStartTxtNode = aStartNodeIndex.GetNode().GetTxtNode();
285 const sal_Int32 nIndices = pOffsets->getLength();
286 const sal_Int32 *pIndices = pOffsets->getConstArray();
287 xub_StrLen nConvTextLen = rNewText.Len();
288 xub_StrLen nPos = 0;
289 xub_StrLen nChgPos = STRING_NOTFOUND;
290 xub_StrLen nChgLen = 0;
291 xub_StrLen nConvChgPos = STRING_NOTFOUND;
292 xub_StrLen nConvChgLen = 0;
294 // offset to calculate the position in the text taking into
295 // account that text may have been replaced with new text of
296 // different length. Negative values allowed!
297 long nCorrectionOffset = 0;
299 DBG_ASSERT(nIndices == 0 || nIndices == nConvTextLen,
300 "mismatch between string length and sequence length!" );
302 // find all substrings that need to be replaced (and only those)
303 while (sal_True)
305 // get index in original text that matches nPos in new text
306 xub_StrLen nIndex;
307 if (nPos < nConvTextLen)
308 nIndex = (sal_Int32) nPos < nIndices ? (xub_StrLen) pIndices[nPos] : nPos;
309 else
311 nPos = nConvTextLen;
312 nIndex = static_cast< xub_StrLen >( rOrigText.getLength() );
315 if (rOrigText.getStr()[nIndex] == rNewText.GetChar(nPos) ||
316 nPos == nConvTextLen /* end of string also terminates non-matching char sequence */)
318 // substring that needs to be replaced found?
319 if (nChgPos != STRING_NOTFOUND && nConvChgPos != STRING_NOTFOUND)
321 nChgLen = nIndex - nChgPos;
322 nConvChgLen = nPos - nConvChgPos;
323 #ifdef DEBUG
324 String aInOrig( rOrigText.copy( nChgPos, nChgLen ) );
325 #endif
326 String aInNew( rNewText.Copy( nConvChgPos, nConvChgLen ) );
328 // set selection to sub string to be replaced in original text
329 xub_StrLen nChgInNodeStartIndex = static_cast< xub_StrLen >( nStartIndex + nCorrectionOffset + nChgPos );
330 DBG_ASSERT( rWrtShell.GetCrsr()->HasMark(), "cursor misplaced (nothing selected)" );
331 rWrtShell.GetCrsr()->GetMark()->nContent.Assign( pStartTxtNode, nChgInNodeStartIndex );
332 rWrtShell.GetCrsr()->GetPoint()->nContent.Assign( pStartTxtNode, nChgInNodeStartIndex + nChgLen );
333 #ifdef DEBUG
334 String aSelTxt1( rWrtShell.GetSelTxt() );
335 #endif
337 // replace selected sub string with the corresponding
338 // sub string from the new text while keeping as
339 // much from the attributes as possible
340 ChangeText_impl( aInNew, sal_True );
342 nCorrectionOffset += nConvChgLen - nChgLen;
344 nChgPos = STRING_NOTFOUND;
345 nConvChgPos = STRING_NOTFOUND;
348 else
350 // begin of non-matching char sequence found ?
351 if (nChgPos == STRING_NOTFOUND && nConvChgPos == STRING_NOTFOUND)
353 nChgPos = nIndex;
354 nConvChgPos = nPos;
357 if (nPos >= nConvTextLen)
358 break;
359 ++nPos;
362 // set cursor to the end of all the new text
363 // (as it would happen after ChangeText_impl (Delete and Insert)
364 // of the whole text in the 'else' branch below)
365 rWrtShell.ClearMark();
366 rWrtShell.GetCrsr()->Start()->nContent.Assign( pStartTxtNode, nStartIndex + nConvTextLen );
368 else
370 ChangeText_impl( rNewText, sal_False );
375 void SwHHCWrapper::ChangeText_impl( const String &rNewText, sal_Bool bKeepAttributes )
377 if (bKeepAttributes)
379 // get item set with all relevant attributes
380 sal_uInt16 aRanges[] = {
381 RES_CHRATR_BEGIN, RES_FRMATR_END,
382 0, 0, 0 };
383 SfxItemSet aItemSet( rWrtShell.GetAttrPool(), aRanges );
384 // get all attributes spanning the whole selection in order to
385 // restore those for the new text
386 rWrtShell.GetCurAttr( aItemSet );
388 #ifdef DEBUG
389 String aSelTxt1( rWrtShell.GetSelTxt() );
390 #endif
391 rWrtShell.Delete();
392 rWrtShell.Insert( rNewText );
394 // select new inserted text (currently the Point is right after the new text)
395 if (!rWrtShell.GetCrsr()->HasMark())
396 rWrtShell.GetCrsr()->SetMark();
397 SwPosition *pMark = rWrtShell.GetCrsr()->GetMark();
398 pMark->nContent = pMark->nContent.GetIndex() - rNewText.Len();
399 #ifdef DEBUG
400 String aSelTxt2( rWrtShell.GetSelTxt() );
401 #endif
403 // since 'SetAttr' below functions like merging with the attributes
404 // from the itemset with any existing ones we have to get rid of all
405 // all attributes now. (Those attributes that may take effect left
406 // to the position where the new text gets inserted after the old text
407 // was deleted)
408 rWrtShell.ResetAttr();
409 // apply previously saved attributes to new text
410 rWrtShell.SetAttr( aItemSet );
412 else
414 rWrtShell.Delete();
415 rWrtShell.Insert( rNewText );
420 void SwHHCWrapper::ReplaceUnit(
421 const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd,
422 const ::rtl::OUString& rOrigText,
423 const OUString& rReplaceWith,
424 const uno::Sequence< sal_Int32 > &rOffsets,
425 ReplacementAction eAction,
426 LanguageType *pNewUnitLanguage )
428 static OUString aBracketedStart( C2U( "(" ) );
429 static OUString aBracketedEnd( C2U( ")" ) );
431 DBG_ASSERT( nUnitStart >= 0 && nUnitEnd >= nUnitStart, "wrong arguments" );
432 if (!(nUnitStart >= 0 && nUnitEnd >= nUnitStart))
433 return;
435 lcl_ActivateTextShell( rWrtShell );
437 // Das aktuelle Wort austauschen
438 rWrtShell.StartAllAction();
440 // select current unit
441 SelectNewUnit_impl( nUnitStart, nUnitEnd );
443 OUString aOrigTxt( rWrtShell.GetSelTxt() );
444 OUString aNewTxt( rReplaceWith );
445 DBG_ASSERT( aOrigTxt == rOrigText, "!! text mismatch !!" );
446 SwFmtRuby *pRuby = 0;
447 sal_Bool bRubyBelow = sal_False;
448 String aNewOrigText;
449 switch (eAction)
451 case eExchange :
452 break;
453 case eReplacementBracketed :
455 (((aNewTxt = aOrigTxt) += aBracketedStart) += rReplaceWith) += aBracketedEnd;
457 break;
458 case eOriginalBracketed :
460 (((aNewTxt = rReplaceWith) += aBracketedStart) += aOrigTxt) += aBracketedEnd;
462 break;
463 case eReplacementAbove :
465 pRuby = new SwFmtRuby( rReplaceWith );
467 break;
468 case eOriginalAbove :
470 pRuby = new SwFmtRuby( aOrigTxt );
471 aNewOrigText = rReplaceWith;
473 break;
474 case eReplacementBelow :
476 pRuby = new SwFmtRuby( rReplaceWith );
477 bRubyBelow = sal_True;
479 break;
480 case eOriginalBelow :
482 pRuby = new SwFmtRuby( aOrigTxt );
483 aNewOrigText = rReplaceWith;
484 bRubyBelow = sal_True;
486 break;
487 default:
488 DBG_ERROR( "unexpected case" );
490 nUnitOffset += nUnitStart + aNewTxt.getLength();
492 if (pRuby)
494 rWrtShell.StartUndo( UNDO_SETRUBYATTR );
495 if (aNewOrigText.Len())
497 // according to FT we currently should not bother about keeping
498 // attributes in Hangul/Hanja conversion
499 ChangeText( aNewOrigText, rOrigText, NULL, NULL );
501 //!! since Delete, Insert in 'ChangeText' do not set the WrtShells
502 //!! bInSelect flag
503 //!! back to false we do it now manually in order for the selection
504 //!! to be done properly in the following call to Left.
505 // We didn't fix it in Delete and Insert since it is currently
506 // unclear if someone depends on this incorrect behvaiour
507 // of the flag.
508 rWrtShell.EndSelect();
510 rWrtShell.Left( 0, TRUE, aNewOrigText.Len(), TRUE, TRUE );
513 pRuby->SetPosition( bRubyBelow );
514 pRuby->SetAdjustment( RubyAdjust_CENTER );
515 //!! the following seem not to be needed
516 //pRuby->SetCharFmtName( const String& rNm );
517 //pRuby->SetCharFmtId( USHORT nNew );
518 #ifdef DEBUG
519 SwPaM *pPaM = rWrtShell.GetCrsr();
520 (void)pPaM;
521 #endif
522 rWrtShell.SetAttr(*pRuby);
523 delete pRuby;
524 rWrtShell.EndUndo( UNDO_SETRUBYATTR );
526 else
528 rWrtShell.StartUndo( UNDO_OVERWRITE );
530 // according to FT we should currently not bother about keeping
531 // attributes in Hangul/Hanja conversion and leave that untouched.
532 // Thus we do this only for Chinese translation...
533 sal_Bool bIsChineseConversion = IsChinese( GetSourceLanguage() );
534 if (bIsChineseConversion)
535 ChangeText( aNewTxt, rOrigText, &rOffsets, rWrtShell.GetCrsr() );
536 else
537 ChangeText( aNewTxt, rOrigText, NULL, NULL );
539 // change language and font if necessary
540 if (bIsChineseConversion)
542 rWrtShell.SetMark();
543 rWrtShell.GetCrsr()->GetMark()->nContent -= (xub_StrLen) aNewTxt.getLength();
545 DBG_ASSERT( GetTargetLanguage() == LANGUAGE_CHINESE_SIMPLIFIED || GetTargetLanguage() == LANGUAGE_CHINESE_TRADITIONAL,
546 "SwHHCWrapper::ReplaceUnit : unexpected target language" );
548 sal_uInt16 aRanges[] = {
549 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
550 RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
551 0, 0, 0 };
553 SfxItemSet aSet( rWrtShell.GetAttrPool(), aRanges );
554 if (pNewUnitLanguage)
556 //DBG_ASSERT(!IsSimilarChinese( *pNewUnitLanguage, nOldLang ),
557 // "similar language should not be changed!");
558 aSet.Put( SvxLanguageItem( *pNewUnitLanguage, RES_CHRATR_CJK_LANGUAGE ) );
561 const Font *pTargetFont = GetTargetFont();
562 DBG_ASSERT( pTargetFont, "target font missing?" );
563 if (pTargetFont && pNewUnitLanguage)
565 SvxFontItem aFontItem = (SvxFontItem&) aSet.Get( RES_CHRATR_CJK_FONT );
566 aFontItem.GetFamilyName() = pTargetFont->GetName();
567 aFontItem.GetFamily() = pTargetFont->GetFamily();
568 aFontItem.GetStyleName() = pTargetFont->GetStyleName();
569 aFontItem.GetPitch() = pTargetFont->GetPitch();
570 aFontItem.GetCharSet() = pTargetFont->GetCharSet();
571 aSet.Put( aFontItem );
574 rWrtShell.SetAttr( aSet );
576 rWrtShell.ClearMark();
579 rWrtShell.EndUndo( UNDO_OVERWRITE );
582 rWrtShell.EndAllAction();
586 sal_Bool SwHHCWrapper::HasRubySupport() const
588 return sal_True;
592 void SwHHCWrapper::Convert()
594 DBG_ASSERT( pConvArgs == 0, "NULL pointer expected" );
596 SwPaM *pCrsr = pView->GetWrtShell().GetCrsr();
597 SwPosition* pSttPos = pCrsr->Start();
598 SwPosition* pEndPos = pCrsr->End();
601 if (pSttPos->nNode.GetNode().IsTxtNode() &&
602 pEndPos->nNode.GetNode().IsTxtNode())
604 pConvArgs = new SwConversionArgs( GetSourceLanguage(),
605 pSttPos->nNode.GetNode().GetTxtNode(), pSttPos->nContent,
606 pEndPos->nNode.GetNode().GetTxtNode(), pEndPos->nContent );
608 else // we are not in the text (maybe a graphic or OLE object is selected) let's start from the top
610 // get PaM that points to the start of the document
611 SwNode& rNode = pView->GetDocShell()->GetDoc()->GetNodes().GetEndOfContent();
612 SwPaM aPam(rNode);
613 aPam.Move( fnMoveBackward, fnGoDoc ); // move to start of document
615 pSttPos = aPam.GetPoint(); //! using a PaM here makes sure we will get only text nodes
616 SwTxtNode *pTxtNode = pSttPos->nNode.GetNode().GetTxtNode();
617 // just in case we check anyway...
618 if (!pTxtNode || !pTxtNode->IsTxtNode())
619 return;
620 pConvArgs = new SwConversionArgs( GetSourceLanguage(),
621 pTxtNode, pSttPos->nContent,
622 pTxtNode, pSttPos->nContent );
624 DBG_ASSERT( pConvArgs->pStartNode && pConvArgs->pStartNode->IsTxtNode(),
625 "failed to get proper start text node" );
626 DBG_ASSERT( pConvArgs->pEndNode && pConvArgs->pEndNode->IsTxtNode(),
627 "failed to get proper end text node" );
629 // chinese conversion specific settings
630 DBG_ASSERT( IsChinese( GetSourceLanguage() ) == IsChinese( GetTargetLanguage() ),
631 "source and target language mismatch?" );
632 if (IsChinese( GetTargetLanguage() ))
634 pConvArgs->nConvTargetLang = GetTargetLanguage();
635 pConvArgs->pTargetFont = GetTargetFont();
636 pConvArgs->bAllowImplicitChangesForNotConvertibleText = sal_True;
639 // if it is not just a selection and we are about to begin
640 // with the current conversion for the very first time
641 // we need to find the start of the current (initial)
642 // convertible unit in order for the text conversion to give
643 // the correct result for that. Since it is easier to obtain
644 // the start of the word we use that though.
645 if (!pCrsr->HasMark()) // is not a selection?
647 // since #118246 / #117803 still occurs if the cursor is placed
648 // between the two chinese characters to be converted (because both
649 // of them are words on their own!) using the word boundary here does
650 // not work. Thus since chinese conversion is not interactive we start
651 // at the begin of the paragraph to solve the problem, i.e. have the
652 // TextConversion service get those charcters together in the same call.
653 xub_StrLen nStartIdx = STRING_MAXLEN;
654 if (svx::HangulHanjaConversion::IsChinese( GetSourceLanguage() ) )
655 nStartIdx = 0;
656 else
658 OUString aText( pConvArgs->pStartNode->GetTxt() );
659 long nPos = pConvArgs->pStartIdx->GetIndex();
660 Boundary aBoundary( pBreakIt->GetBreakIter()->
661 getWordBoundary( aText, nPos, pBreakIt->GetLocale( pConvArgs->nConvSrcLang ),
662 WordType::DICTIONARY_WORD, sal_True ) );
664 // valid result found?
665 if (aBoundary.startPos < aText.getLength() &&
666 aBoundary.startPos != aBoundary.endPos)
668 nStartIdx = static_cast< xub_StrLen >(aBoundary.startPos );
672 if (STRING_MAXLEN != nStartIdx)
673 *pConvArgs->pStartIdx = nStartIdx;
677 if ( bIsOtherCntnt )
678 ConvStart_impl( pConvArgs, SVX_SPELL_OTHER );
679 else
681 bStartChk = sal_False;
682 ConvStart_impl( pConvArgs, SVX_SPELL_BODY_END );
685 ConvertDocument();
687 ConvEnd_impl( pConvArgs );
691 sal_Bool SwHHCWrapper::ConvNext_impl( )
693 //! modified version of SvxSpellWrapper::SpellNext
695 // Keine Richtungsaenderung, also ist der gewuenschte Bereich ( bStartChk )
696 // vollstaendig abgearbeitet.
697 if( bStartChk )
698 bStartDone = sal_True;
699 else
700 bEndDone = sal_True;
702 if( bIsOtherCntnt && bStartDone && bEndDone ) // Dokument komplett geprueft?
704 bInfoBox = sal_True;
705 return sal_False;
708 //ResMgr* pMgr = DIALOG_MGR();
709 sal_Bool bGoOn = sal_False;
711 if ( bIsOtherCntnt )
713 bStartChk = sal_False;
714 ConvStart_impl( pConvArgs, SVX_SPELL_BODY );
715 bGoOn = sal_True;
717 else if ( bStartDone && bEndDone )
719 // Bodybereich erledigt, Frage nach Sonderbereich
720 if( bIsConvSpecial && HasOtherCnt_impl() )
722 ConvStart_impl( pConvArgs, SVX_SPELL_OTHER );
723 bIsOtherCntnt = bGoOn = sal_True;
725 else
726 bInfoBox = sal_True;
728 else
730 // Ein BODY_Bereich erledigt, Frage nach dem anderen BODY_Bereich
732 //pWin->LeaveWait();
734 sal_uInt16 nResId = RID_SVXQB_CONTINUE;
735 QueryBox aBox( pWin, ResId( nResId, pMgr ) );
736 if ( aBox.Execute() != RET_YES )
738 // Verzicht auf den anderen Bereich, ggf. Frage nach Sonderbereich
739 //pWin->EnterWait();
740 bStartDone = bEndDone = sal_True;
741 return SpellNext();
743 else
746 bStartChk = !bStartDone;
747 ConvStart_impl( pConvArgs, bStartChk ? SVX_SPELL_BODY_START : SVX_SPELL_BODY_END );
748 bGoOn = sal_True;
751 pWin->EnterWait();
754 return bGoOn;
758 sal_Bool SwHHCWrapper::FindConvText_impl()
760 //! modified version of SvxSpellWrapper::FindSpellError
762 //ShowLanguageErrors();
764 sal_Bool bFound = sal_False;
766 pWin->EnterWait();
767 sal_Bool bConv = sal_True;
769 while ( bConv )
771 bFound = ConvContinue_impl( pConvArgs );
772 if (bFound)
774 bConv = sal_False;
776 else
778 ConvEnd_impl( pConvArgs );
779 bConv = ConvNext_impl();
782 pWin->LeaveWait();
783 return bFound;
787 sal_Bool SwHHCWrapper::HasOtherCnt_impl()
789 return bIsSelection ? sal_False : rWrtShell.HasOtherCnt();
793 void SwHHCWrapper::ConvStart_impl( SwConversionArgs /* [out] */ *pConversionArgs, SvxSpellArea eArea )
795 SetDrawObj( SVX_SPELL_OTHER == eArea );
796 pView->SpellStart( eArea, bStartDone, bEndDone, /* [out] */ pConversionArgs );
800 void SwHHCWrapper::ConvEnd_impl( SwConversionArgs *pConversionArgs )
802 pView->SpellEnd( pConversionArgs );
803 //ShowLanguageErrors();
807 sal_Bool SwHHCWrapper::ConvContinue_impl( SwConversionArgs *pConversionArgs )
809 sal_Bool bProgress = !bIsDrawObj && !bIsSelection;
810 // bLastRet = aConvText.getLength() == 0;
811 pConversionArgs->aConvText = OUString();
812 pConversionArgs->nConvTextLang = LANGUAGE_NONE;
813 uno::Any aRet = bProgress ?
814 pView->GetWrtShell().SpellContinue( &nPageCount, &nPageStart, pConversionArgs ) :
815 pView->GetWrtShell().SpellContinue( &nPageCount, NULL, pConversionArgs );
816 //aRet >>= aConvText;
817 return pConversionArgs->aConvText.getLength() != 0;
820 //////////////////////////////////////////////////////////////////////