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 <string.h>
21 :
22 : #include <vcl/window.hxx>
23 :
24 : #include <wrtsh.hxx>
25 : #include <doc.hxx>
26 : #include <docary.hxx>
27 : #include <charfmt.hxx>
28 :
29 : #include <sfx2/bindings.hxx>
30 : #include <sfx2/dispatch.hxx>
31 : #include <sfx2/request.hxx>
32 : #include <editeng/eeitem.hxx>
33 : #include <editeng/editeng.hxx>
34 : #include <editeng/editdata.hxx>
35 : #include <editeng/outliner.hxx>
36 : #include <editeng/editview.hxx>
37 : #include <editeng/scripttypeitem.hxx>
38 : #include <editeng/langitem.hxx>
39 :
40 : #include <svl/languageoptions.hxx>
41 : #include <svtools/langtab.hxx>
42 : #include <svl/slstitm.hxx>
43 : #include <svl/stritem.hxx>
44 :
45 : #include <ndtxt.hxx>
46 : #include <pam.hxx>
47 : #include <view.hxx>
48 : #include <viewopt.hxx>
49 :
50 : #include "swabstdlg.hxx"
51 :
52 : #include <vcl/msgbox.hxx>
53 :
54 : #include <langhelper.hxx>
55 :
56 : using namespace ::com::sun::star;
57 :
58 : namespace SwLangHelper
59 : {
60 :
61 0 : sal_uInt16 GetLanguageStatus( OutlinerView* pOLV, SfxItemSet& rSet )
62 : {
63 0 : ESelection aSelection = pOLV->GetSelection();
64 0 : EditView& rEditView=pOLV->GetEditView();
65 0 : EditEngine* pEditEngine=rEditView.GetEditEngine();
66 :
67 : // the value of used script types
68 0 : const sal_uInt16 nScriptType =pOLV->GetSelectedScriptType();
69 0 : OUString aScriptTypesInUse( OUString::number( nScriptType ) );//pEditEngine->GetScriptType(aSelection)
70 :
71 0 : SvtLanguageTable aLangTable;
72 :
73 : // get keyboard language
74 0 : OUString aKeyboardLang;
75 0 : LanguageType nLang = LANGUAGE_DONTKNOW;
76 :
77 0 : Window* pWin = rEditView.GetWindow();
78 0 : if(pWin)
79 0 : nLang = pWin->GetInputLanguage();
80 0 : if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
81 0 : aKeyboardLang = aLangTable.GetString( nLang );
82 :
83 : // get the language that is in use
84 0 : OUString aCurrentLang("*");
85 0 : SfxItemSet aSet(pOLV->GetAttribs());
86 0 : nLang = SwLangHelper::GetCurrentLanguage( aSet,nScriptType );
87 0 : if (nLang != LANGUAGE_DONTKNOW)
88 0 : aCurrentLang = aLangTable.GetString( nLang );
89 :
90 : // build sequence for status value
91 0 : uno::Sequence< OUString > aSeq( 4 );
92 0 : aSeq[0] = aCurrentLang;
93 0 : aSeq[1] = aScriptTypesInUse;
94 0 : aSeq[2] = aKeyboardLang;
95 0 : aSeq[3] = SwLangHelper::GetTextForLanguageGuessing( pEditEngine, aSelection );
96 :
97 : // set sequence as status value
98 0 : SfxStringListItem aItem( SID_LANGUAGE_STATUS );
99 0 : aItem.SetStringList( aSeq );
100 0 : rSet.Put( aItem, SID_LANGUAGE_STATUS );
101 0 : return 0;
102 : }
103 :
104 0 : bool SetLanguageStatus( OutlinerView* pOLV, SfxRequest &rReq, SwView &rView, SwWrtShell &rSh )
105 : {
106 0 : bool bRestoreSelection = false;
107 0 : SfxItemSet aEditAttr(pOLV->GetAttribs());
108 0 : ESelection aSelection = pOLV->GetSelection();
109 0 : EditView & rEditView = pOLV->GetEditView();
110 0 : EditEngine * pEditEngine = rEditView.GetEditEngine();
111 :
112 : // get the language
113 0 : OUString aNewLangTxt;
114 :
115 0 : SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, SID_LANGUAGE_STATUS , false );
116 0 : if (pItem)
117 0 : aNewLangTxt = pItem->GetValue();
118 :
119 : //!! Remember the view frame right now...
120 : //!! (call to GetView().GetViewFrame() will break if the
121 : //!! SwTextShell got destroyed meanwhile.)
122 0 : SfxViewFrame *pViewFrame = rView.GetViewFrame();
123 :
124 0 : if (aNewLangTxt == "*" )
125 : {
126 : // open the dialog "Tools/Options/Language Settings - Language"
127 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
128 0 : if (pFact)
129 : {
130 0 : VclAbstractDialog* pDlg = pFact->CreateVclDialog( rView.GetWindow(), SID_LANGUAGE_OPTIONS );
131 0 : pDlg->Execute();
132 0 : delete pDlg;
133 : }
134 : }
135 : else
136 : {
137 : // setting the new language...
138 0 : if (!aNewLangTxt.isEmpty())
139 : {
140 0 : const OUString aSelectionLangPrefix("Current_");
141 0 : const OUString aParagraphLangPrefix("Paragraph_");
142 0 : const OUString aDocumentLangPrefix("Default_");
143 0 : const OUString aStrNone("LANGUAGE_NONE");
144 0 : const OUString aStrResetLangs("RESET_LANGUAGES");
145 :
146 0 : sal_Int32 nPos = 0;
147 0 : bool bForSelection = true;
148 0 : bool bForParagraph = false;
149 0 : if (-1 != (nPos = aNewLangTxt.indexOf( aSelectionLangPrefix, 0 )))
150 : {
151 : // ... for the current selection
152 0 : aNewLangTxt = aNewLangTxt.replaceAt(nPos, aSelectionLangPrefix.getLength(), "");
153 0 : bForSelection = true;
154 : }
155 0 : else if (-1 != (nPos = aNewLangTxt.indexOf( aParagraphLangPrefix , 0 )))
156 : {
157 : // ... for the current paragraph language
158 0 : aNewLangTxt = aNewLangTxt.replaceAt(nPos, aParagraphLangPrefix.getLength(), "");
159 0 : bForSelection = true;
160 0 : bForParagraph = true;
161 : }
162 0 : else if (-1 != (nPos = aNewLangTxt.indexOf( aDocumentLangPrefix , 0 )))
163 : {
164 : // ... as default document language
165 0 : aNewLangTxt = aNewLangTxt.replaceAt(nPos, aDocumentLangPrefix.getLength(), "");
166 0 : bForSelection = false;
167 : }
168 :
169 0 : if (bForParagraph)
170 : {
171 0 : bRestoreSelection = true;
172 0 : SwLangHelper::SelectPara( rEditView, aSelection );
173 0 : aSelection = pOLV->GetSelection();
174 : }
175 0 : if (!bForSelection) // document language to be changed...
176 : {
177 0 : rSh.StartAction();
178 0 : rSh.LockView( sal_True );
179 0 : rSh.Push();
180 :
181 : // prepare to apply new language to all text in document
182 0 : rSh.SelAll();
183 0 : rSh.ExtendedSelectAll();
184 : }
185 :
186 0 : if (aNewLangTxt == aStrNone)
187 0 : SwLangHelper::SetLanguage_None( rSh, pOLV, aSelection, bForSelection, aEditAttr );
188 0 : else if (aNewLangTxt == aStrResetLangs)
189 0 : SwLangHelper::ResetLanguages( rSh, pOLV, aSelection, bForSelection );
190 : else
191 0 : SwLangHelper::SetLanguage( rSh, pOLV, aSelection, aNewLangTxt, bForSelection, aEditAttr );
192 :
193 : // ugly hack, as it seems that EditView/EditEngine does not update their spellchecking marks
194 : // when setting a new language attribute
195 0 : if (bForSelection)
196 : {
197 0 : const SwViewOption* pVOpt = rView.GetWrtShellPtr()->GetViewOptions();
198 0 : sal_uLong nCntrl = pEditEngine->GetControlWord();
199 : // turn off
200 0 : nCntrl &= ~EE_CNTRL_ONLINESPELLING;
201 0 : pEditEngine->SetControlWord(nCntrl);
202 :
203 : //turn back on
204 0 : if (pVOpt->IsOnlineSpell())
205 0 : nCntrl |= EE_CNTRL_ONLINESPELLING;
206 : else
207 0 : nCntrl &= ~EE_CNTRL_ONLINESPELLING;
208 0 : pEditEngine->SetControlWord(nCntrl);
209 :
210 0 : pEditEngine->CompleteOnlineSpelling();
211 0 : rEditView.Invalidate();
212 : }
213 :
214 0 : if (!bForSelection)
215 : {
216 : // need to release view and restore selection...
217 0 : rSh.Pop( sal_False );
218 0 : rSh.LockView( sal_False );
219 0 : rSh.EndAction();
220 0 : }
221 : }
222 : }
223 :
224 : // invalidate slot to get the new language displayed
225 0 : pViewFrame->GetBindings().Invalidate( rReq.GetSlot() );
226 :
227 0 : rReq.Done();
228 0 : return bRestoreSelection;
229 : }
230 :
231 0 : void SetLanguage( SwWrtShell &rWrtSh, const OUString &rLangText, bool bIsForSelection, SfxItemSet &rCoreSet )
232 : {
233 0 : SetLanguage( rWrtSh, 0 , ESelection(), rLangText, bIsForSelection, rCoreSet );
234 0 : }
235 :
236 0 : void SetLanguage( SwWrtShell &rWrtSh, OutlinerView* pOLV, ESelection aSelection, const OUString &rLangText, bool bIsForSelection, SfxItemSet &rCoreSet )
237 : {
238 0 : const LanguageType nLang = SvtLanguageTable().GetType( rLangText );
239 0 : if (nLang != LANGUAGE_DONTKNOW)
240 : {
241 0 : sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLang );
242 :
243 0 : EditEngine* pEditEngine = pOLV ? pOLV->GetEditView().GetEditEngine() : NULL;
244 : OSL_ENSURE( !pOLV || pEditEngine, "OutlinerView without EditEngine???" );
245 :
246 : //get ScriptType
247 0 : sal_uInt16 nLangWhichId = 0;
248 0 : bool bIsSingleScriptType = true;
249 0 : switch (nScriptType)
250 : {
251 0 : case SCRIPTTYPE_LATIN : nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE : RES_CHRATR_LANGUAGE; break;
252 0 : case SCRIPTTYPE_ASIAN : nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CJK : RES_CHRATR_CJK_LANGUAGE; break;
253 0 : case SCRIPTTYPE_COMPLEX : nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CTL : RES_CHRATR_CTL_LANGUAGE; break;
254 : default:
255 0 : bIsSingleScriptType = false;
256 : OSL_FAIL("unexpected case" );
257 : }
258 0 : if (bIsSingleScriptType)
259 : {
260 : // change language for selection or paragraph
261 : // (for paragraph is handled by previosuly having set the selection to the
262 : // whole paragraph)
263 0 : if (bIsForSelection)
264 : {
265 : // apply language to current selection
266 0 : if (pEditEngine)
267 : {
268 0 : rCoreSet.Put( SvxLanguageItem( nLang, nLangWhichId ));
269 0 : pEditEngine->QuickSetAttribs( rCoreSet, aSelection);
270 : }
271 : else
272 : {
273 0 : rWrtSh.GetCurAttr( rCoreSet );
274 0 : rCoreSet.Put( SvxLanguageItem( nLang, nLangWhichId ));
275 0 : rWrtSh.SetAttrSet( rCoreSet );
276 : }
277 : }
278 : else // change language for all text
279 : {
280 : // set document default language
281 0 : switch (nLangWhichId)
282 : {
283 0 : case EE_CHAR_LANGUAGE : nLangWhichId = RES_CHRATR_LANGUAGE; break;
284 0 : case EE_CHAR_LANGUAGE_CJK : nLangWhichId = RES_CHRATR_CJK_LANGUAGE; break;
285 0 : case EE_CHAR_LANGUAGE_CTL : nLangWhichId = RES_CHRATR_CTL_LANGUAGE; break;
286 : }
287 : //Set the default document language
288 0 : rWrtSh.SetDefault( SvxLanguageItem( nLang, nLangWhichId ) );
289 :
290 : //Resolves: fdo#35282 Clear the language from all Text Styles, and
291 : //fallback to default document language
292 0 : const SwTxtFmtColls *pColls = rWrtSh.GetDoc()->GetTxtFmtColls();
293 0 : for(sal_uInt16 i = 0, nCount = pColls->size(); i < nCount; ++i)
294 : {
295 0 : SwTxtFmtColl &rTxtColl = *(*pColls)[ i ];
296 0 : rTxtColl.ResetFmtAttr(nLangWhichId);
297 : }
298 : //Resolves: fdo#35282 Clear the language from all Character Styles,
299 : //and fallback to default document language
300 0 : const SwCharFmts *pCharFmts = rWrtSh.GetDoc()->GetCharFmts();
301 0 : for(sal_uInt16 i = 0, nCount = pCharFmts->size(); i < nCount; ++i)
302 : {
303 0 : SwCharFmt &rCharFmt = *(*pCharFmts)[ i ];
304 0 : rCharFmt.ResetFmtAttr(nLangWhichId);
305 : }
306 :
307 : // #i102191: hard set respective language attribute in text document
308 : // (for all text in the document - which should be selected by now...)
309 0 : rWrtSh.SetAttrItem( SvxLanguageItem( nLang, nLangWhichId ) );
310 : }
311 : }
312 : }
313 0 : }
314 :
315 0 : void SetLanguage_None( SwWrtShell &rWrtSh, bool bIsForSelection, SfxItemSet &rCoreSet )
316 : {
317 0 : SetLanguage_None( rWrtSh,0,ESelection(),bIsForSelection,rCoreSet );
318 0 : }
319 :
320 0 : void SetLanguage_None( SwWrtShell &rWrtSh, OutlinerView* pOLV, ESelection aSelection, bool bIsForSelection, SfxItemSet &rCoreSet )
321 : {
322 : // EditEngine IDs
323 : const sal_uInt16 aLangWhichId_EE[3] =
324 : {
325 : EE_CHAR_LANGUAGE,
326 : EE_CHAR_LANGUAGE_CJK,
327 : EE_CHAR_LANGUAGE_CTL
328 0 : };
329 :
330 : // Writewr IDs
331 : const sal_uInt16 aLangWhichId_Writer[3] =
332 : {
333 : RES_CHRATR_LANGUAGE,
334 : RES_CHRATR_CJK_LANGUAGE,
335 : RES_CHRATR_CTL_LANGUAGE
336 0 : };
337 :
338 0 : if (bIsForSelection)
339 : {
340 : // change language for selection or paragraph
341 : // (for paragraph is handled by previosuly having set the selection to the
342 : // whole paragraph)
343 :
344 0 : EditEngine* pEditEngine = pOLV ? pOLV->GetEditView().GetEditEngine() : NULL;
345 : OSL_ENSURE( !pOLV || pEditEngine, "OutlinerView without EditEngine???" );
346 0 : if (pEditEngine)
347 : {
348 0 : for (sal_uInt16 i = 0; i < 3; ++i)
349 0 : rCoreSet.Put( SvxLanguageItem( LANGUAGE_NONE, aLangWhichId_EE[i] ));
350 0 : pEditEngine->QuickSetAttribs( rCoreSet, aSelection);
351 : }
352 : else
353 : {
354 0 : rWrtSh.GetCurAttr( rCoreSet );
355 0 : for (sal_uInt16 i = 0; i < 3; ++i)
356 0 : rCoreSet.Put( SvxLanguageItem( LANGUAGE_NONE, aLangWhichId_Writer[i] ));
357 0 : rWrtSh.SetAttrSet( rCoreSet );
358 : }
359 : }
360 : else // change language for all text
361 : {
362 0 : std::set<sal_uInt16> aAttribs;
363 0 : for (sal_uInt16 i = 0; i < 3; ++i)
364 : {
365 0 : rWrtSh.SetDefault( SvxLanguageItem( LANGUAGE_NONE, aLangWhichId_Writer[i] ) );
366 0 : aAttribs.insert( aLangWhichId_Writer[i] );
367 : }
368 :
369 : // set all language attributes to default
370 : // (for all text in the document - which should be selected by now...)
371 0 : rWrtSh.ResetAttr( aAttribs );
372 : }
373 0 : }
374 :
375 0 : void ResetLanguages( SwWrtShell &rWrtSh, bool bIsForSelection )
376 : {
377 0 : ResetLanguages( rWrtSh, 0 , ESelection(), bIsForSelection );
378 0 : }
379 :
380 0 : void ResetLanguages( SwWrtShell &rWrtSh, OutlinerView* pOLV, ESelection aSelection, bool bIsForSelection )
381 : {
382 : (void) bIsForSelection;
383 : (void) aSelection;
384 :
385 : // reset language for current selection.
386 : // The selection should already have been expanded to the whole paragraph or
387 : // to all text in the document if those are the ranges where to reset
388 : // the language attributes
389 :
390 0 : if (pOLV)
391 : {
392 0 : EditView &rEditView = pOLV->GetEditView();
393 0 : rEditView.RemoveAttribs( true, EE_CHAR_LANGUAGE );
394 0 : rEditView.RemoveAttribs( true, EE_CHAR_LANGUAGE_CJK );
395 0 : rEditView.RemoveAttribs( true, EE_CHAR_LANGUAGE_CTL );
396 : }
397 : else
398 : {
399 0 : std::set<sal_uInt16> aAttribs;
400 0 : aAttribs.insert( RES_CHRATR_LANGUAGE );
401 0 : aAttribs.insert( RES_CHRATR_CJK_LANGUAGE );
402 0 : aAttribs.insert( RES_CHRATR_CTL_LANGUAGE );
403 0 : rWrtSh.ResetAttr( aAttribs );
404 : }
405 0 : }
406 :
407 : /// @returns : the language for the selected text that is set for the
408 : /// specified attribute (script type).
409 : /// If there are more than one languages used LANGUAGE_DONTKNOW will be returned.
410 : /// @param nLangWhichId : one of
411 : /// RES_CHRATR_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
412 0 : LanguageType GetLanguage( SwWrtShell &rSh, sal_uInt16 nLangWhichId )
413 : {
414 0 : SfxItemSet aSet( rSh.GetAttrPool(), nLangWhichId, nLangWhichId );
415 0 : rSh.GetCurAttr( aSet );
416 :
417 0 : return GetLanguage(aSet,nLangWhichId);
418 : }
419 :
420 0 : LanguageType GetLanguage( SfxItemSet aSet, sal_uInt16 nLangWhichId )
421 : {
422 :
423 0 : LanguageType nLang = LANGUAGE_SYSTEM;
424 :
425 0 : const SfxPoolItem *pItem = 0;
426 0 : SfxItemState nState = aSet.GetItemState( nLangWhichId, true, &pItem );
427 0 : if (nState > SFX_ITEM_DEFAULT && pItem)
428 : {
429 : // the item is set and can be used
430 0 : nLang = (dynamic_cast< const SvxLanguageItem* >(pItem))->GetLanguage();
431 : }
432 0 : else if (nState == SFX_ITEM_DEFAULT)
433 : {
434 : // since the attribute is not set: retrieve the default value
435 0 : nLang = (dynamic_cast< const SvxLanguageItem& >(aSet.GetPool()->GetDefaultItem( nLangWhichId ))).GetLanguage();
436 : }
437 0 : else if (nState == SFX_ITEM_DONTCARE)
438 : {
439 : // there is more than one language...
440 0 : nLang = LANGUAGE_DONTKNOW;
441 : }
442 : OSL_ENSURE( nLang != LANGUAGE_SYSTEM, "failed to get the language?" );
443 :
444 0 : return nLang;
445 : }
446 :
447 : /// @returns: the language in use for the selected text.
448 : /// 'In use' means the language(s) matching the script type(s) of the
449 : /// selected text. Or in other words, the language a spell checker would use.
450 : /// If there is more than one language LANGUAGE_DONTKNOW will be returned.
451 0 : LanguageType GetCurrentLanguage( SwWrtShell &rSh )
452 : {
453 : // get all script types used in current selection
454 0 : const sal_uInt16 nScriptType = rSh.GetScriptType();
455 :
456 : //set language attribute to use according to the script type
457 0 : sal_uInt16 nLangWhichId = 0;
458 0 : bool bIsSingleScriptType = true;
459 0 : switch (nScriptType)
460 : {
461 0 : case SCRIPTTYPE_LATIN : nLangWhichId = RES_CHRATR_LANGUAGE; break;
462 0 : case SCRIPTTYPE_ASIAN : nLangWhichId = RES_CHRATR_CJK_LANGUAGE; break;
463 0 : case SCRIPTTYPE_COMPLEX : nLangWhichId = RES_CHRATR_CTL_LANGUAGE; break;
464 0 : default: bIsSingleScriptType = false; break;
465 : }
466 :
467 : // get language according to the script type(s) in use
468 0 : LanguageType nCurrentLang = LANGUAGE_SYSTEM;
469 0 : if (bIsSingleScriptType)
470 0 : nCurrentLang = GetLanguage( rSh, nLangWhichId );
471 : else
472 : {
473 : // check if all script types are set to LANGUAGE_NONE and return
474 : // that if this is the case. Otherwise, having multiple script types
475 : // in use always means there are several languages in use...
476 : const sal_uInt16 aScriptTypes[3] =
477 : {
478 : RES_CHRATR_LANGUAGE,
479 : RES_CHRATR_CJK_LANGUAGE,
480 : RES_CHRATR_CTL_LANGUAGE
481 0 : };
482 0 : nCurrentLang = LANGUAGE_NONE;
483 0 : for (sal_uInt16 i = 0; i < 3; ++i)
484 : {
485 0 : LanguageType nTmpLang = GetLanguage( rSh, aScriptTypes[i] );
486 0 : if (nTmpLang != LANGUAGE_NONE)
487 : {
488 0 : nCurrentLang = LANGUAGE_DONTKNOW;
489 0 : break;
490 : }
491 : }
492 : }
493 : OSL_ENSURE( nCurrentLang != LANGUAGE_SYSTEM, "failed to get the language?" );
494 :
495 0 : return nCurrentLang;
496 : }
497 :
498 : /// @returns: the language in use for the selected text.
499 : /// 'In use' means the language(s) matching the script type(s) of the
500 : /// selected text. Or in other words, the language a spell checker would use.
501 : /// If there is more than one language LANGUAGE_DONTKNOW will be returned.
502 0 : LanguageType GetCurrentLanguage( SfxItemSet aSet, sal_uInt16 nScriptType )
503 : {
504 : //set language attribute to use according to the script type
505 0 : sal_uInt16 nLangWhichId = 0;
506 0 : bool bIsSingleScriptType = true;
507 0 : switch (nScriptType)
508 : {
509 0 : case SCRIPTTYPE_LATIN : nLangWhichId = EE_CHAR_LANGUAGE; break;
510 0 : case SCRIPTTYPE_ASIAN : nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
511 0 : case SCRIPTTYPE_COMPLEX : nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
512 0 : default: bIsSingleScriptType = false;
513 : }
514 :
515 : // get language according to the script type(s) in use
516 0 : LanguageType nCurrentLang = LANGUAGE_SYSTEM;
517 0 : if (bIsSingleScriptType)
518 0 : nCurrentLang = GetLanguage( aSet, nLangWhichId );
519 : else
520 : {
521 : // check if all script types are set to LANGUAGE_NONE and return
522 : // that if this is the case. Otherwise, having multiple script types
523 : // in use always means there are several languages in use...
524 : const sal_uInt16 aScriptTypes[3] =
525 : {
526 : EE_CHAR_LANGUAGE,
527 : EE_CHAR_LANGUAGE_CJK,
528 : EE_CHAR_LANGUAGE_CTL
529 0 : };
530 0 : nCurrentLang = LANGUAGE_NONE;
531 0 : for (sal_uInt16 i = 0; i < 3; ++i)
532 : {
533 0 : LanguageType nTmpLang = GetLanguage( aSet, aScriptTypes[i] );
534 0 : if (nTmpLang != LANGUAGE_NONE)
535 : {
536 0 : nCurrentLang = LANGUAGE_DONTKNOW;
537 0 : break;
538 : }
539 : }
540 : }
541 : OSL_ENSURE( nCurrentLang != LANGUAGE_SYSTEM, "failed to get the language?" );
542 :
543 0 : return nCurrentLang;
544 : }
545 :
546 0 : OUString GetTextForLanguageGuessing( SwWrtShell &rSh )
547 : {
548 : // string for guessing language
549 0 : OUString aText;
550 0 : SwPaM *pCrsr = rSh.GetCrsr();
551 0 : SwTxtNode *pNode = pCrsr->GetNode()->GetTxtNode();
552 0 : if (pNode)
553 : {
554 0 : aText = pNode->GetTxt();
555 0 : if (!aText.isEmpty())
556 : {
557 0 : sal_Int32 nEnd = pCrsr->GetPoint()->nContent.GetIndex();
558 : // at most 100 chars to the left...
559 0 : const sal_Int32 nStt = nEnd > 100 ? nEnd - 100 : 0;
560 : // ... and 100 to the right of the cursor position
561 0 : nEnd = aText.getLength() - nEnd > 100 ? nEnd + 100 : aText.getLength();
562 0 : aText = aText.copy( nStt, nEnd - nStt );
563 : }
564 : }
565 0 : return aText;
566 : }
567 :
568 0 : OUString GetTextForLanguageGuessing( EditEngine* rEditEngine, ESelection aDocSelection )
569 : {
570 : // string for guessing language
571 0 : OUString aText;
572 :
573 0 : aText = rEditEngine->GetText(aDocSelection);
574 0 : if (!aText.isEmpty())
575 : {
576 0 : sal_Int32 nStt = 0;
577 0 : sal_Int32 nEnd = aDocSelection.nEndPos;
578 : // at most 100 chars to the left...
579 0 : nStt = nEnd > 100 ? nEnd - 100 : 0;
580 : // ... and 100 to the right of the cursor position
581 0 : nEnd = aText.getLength() - nEnd > 100 ? nEnd + 100 : aText.getLength();
582 0 : aText = aText.copy( nStt, nEnd - nStt );
583 : }
584 :
585 0 : return aText;
586 : }
587 :
588 0 : void SelectPara( EditView &rEditView, const ESelection &rCurSel )
589 : {
590 0 : ESelection aParaSel( rCurSel.nStartPara, 0, rCurSel.nStartPara, EE_TEXTPOS_ALL );
591 0 : rEditView.SetSelection( aParaSel );
592 0 : }
593 :
594 0 : void SelectCurrentPara( SwWrtShell &rWrtSh )
595 : {
596 : // select current para
597 0 : if (!rWrtSh.IsSttPara())
598 0 : rWrtSh.MovePara( fnParaCurr, fnParaStart );
599 0 : if (!rWrtSh.HasMark())
600 0 : rWrtSh.SetMark();
601 0 : rWrtSh.SwapPam();
602 0 : if (!rWrtSh.IsEndPara())
603 0 : rWrtSh.MovePara( fnParaCurr, fnParaEnd );
604 : #if OSL_DEBUG_LEVEL > 1
605 : OUString aSelTxt;
606 : rWrtSh.GetSelectedText( aSelTxt );
607 : (void) aSelTxt;
608 : #endif
609 0 : }
610 0 : }
611 :
612 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|