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