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 <tools/shl.hxx>
21 : #include <vcl/wrkwin.hxx>
22 : #include <vcl/menu.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <vcl/scrbar.hxx>
25 : #include <vcl/settings.hxx>
26 : #include <SpellAttrib.hxx>
27 : #include <sfx2/dispatch.hxx>
28 : #include <sfx2/bindings.hxx>
29 : #include <svl/undo.hxx>
30 : #include <unotools/lingucfg.hxx>
31 : #include <vcl/textdata.hxx>
32 : #include <vcl/graphicfilter.hxx>
33 : #include <editeng/unolingu.hxx>
34 : #include <editeng/splwrap.hxx>
35 : #include <linguistic/lngprops.hxx>
36 : #include <linguistic/misc.hxx>
37 : #include <comphelper/processfactory.hxx>
38 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 : #include <com/sun/star/lang/XServiceInfo.hpp>
40 : #include <com/sun/star/lang/XServiceDisplayName.hpp>
41 : #include <com/sun/star/linguistic2/SpellFailure.hpp>
42 : #include <com/sun/star/frame/XStorable.hpp>
43 : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
44 : #include <com/sun/star/system/SystemShellExecute.hpp>
45 : #include <sfx2/app.hxx>
46 : #include <vcl/help.hxx>
47 : #include <vcl/graph.hxx>
48 : #include <osl/file.hxx>
49 : #include <cuires.hrc>
50 : #include <editeng/optitems.hxx>
51 : #include <editeng/svxenum.hxx>
52 : #include <svx/SpellDialogChildWindow.hxx>
53 : #include "SpellDialog.hxx"
54 : #include <svx/dlgutil.hxx>
55 : #include "optlingu.hxx"
56 : #include <dialmgr.hxx>
57 : #include <svx/svxerr.hxx>
58 : #include "treeopt.hxx"
59 : #include <svtools/langtab.hxx>
60 : #include <comphelper/anytostring.hxx>
61 : #include <cppuhelper/exc_hlp.hxx>
62 :
63 : using namespace ::com::sun::star;
64 : using namespace ::com::sun::star::uno;
65 : using namespace ::com::sun::star::beans;
66 : using namespace ::com::sun::star::linguistic2;
67 :
68 :
69 : // struct SpellDialog_Impl ---------------------------------------------
70 :
71 0 : struct SpellDialog_Impl
72 : {
73 : Sequence< Reference< XDictionary > > aDics;
74 : };
75 :
76 :
77 : #define SPELLUNDO_START 200
78 :
79 : #define SPELLUNDO_CHANGE_LANGUAGE (SPELLUNDO_START + 1)
80 : #define SPELLUNDO_CHANGE_TEXTENGINE (SPELLUNDO_START + 2)
81 : #define SPELLUNDO_CHANGE_NEXTERROR (SPELLUNDO_START + 3)
82 : #define SPELLUNDO_CHANGE_ADD_TO_DICTIONARY (SPELLUNDO_START + 4)
83 : #define SPELLUNDO_CHANGE_GROUP (SPELLUNDO_START + 5) //undo list
84 : #define SPELLUNDO_MOVE_ERROREND (SPELLUNDO_START + 6)
85 : #define SPELLUNDO_UNDO_EDIT_MODE (SPELLUNDO_START + 7)
86 : #define SPELLUNDO_ADD_IGNORE_RULE (SPELLUNDO_START + 8)
87 :
88 : namespace svx{
89 : class SpellUndoAction_Impl : public SfxUndoAction
90 : {
91 : sal_uInt16 m_nId;
92 : const Link& m_rActionLink;
93 : //undo of button enabling
94 : bool m_bEnableChangePB;
95 : bool m_bEnableChangeAllPB;
96 : //undo of MarkNextError - used in change and change all, ignore and ignore all
97 : long m_nNewErrorStart;
98 : long m_nNewErrorEnd;
99 : long m_nOldErrorStart;
100 : long m_nOldErrorEnd;
101 : bool m_bIsErrorLanguageSelected;
102 : OUString m_sRuleId;
103 : //undo of AddToDictionary
104 : Reference<XDictionary> m_xDictionary;
105 : OUString m_sAddedWord;
106 : //move end of error - ::ChangeMarkedWord()
107 : long m_nOffset;
108 :
109 : public:
110 0 : SpellUndoAction_Impl(sal_uInt16 nId, const Link& rActionLink) :
111 : m_nId(nId),
112 : m_rActionLink( rActionLink),
113 : m_bEnableChangePB(false),
114 : m_bEnableChangeAllPB(false),
115 : m_nNewErrorStart(-1),
116 : m_nNewErrorEnd(-1),
117 : m_nOldErrorStart(-1),
118 : m_nOldErrorEnd(-1),
119 : m_bIsErrorLanguageSelected(false),
120 0 : m_nOffset(0)
121 0 : {}
122 :
123 : virtual ~SpellUndoAction_Impl();
124 :
125 : virtual void Undo() SAL_OVERRIDE;
126 : virtual sal_uInt16 GetId() const SAL_OVERRIDE;
127 :
128 0 : void SetEnableChangePB(){m_bEnableChangePB = true;}
129 0 : bool IsEnableChangePB(){return m_bEnableChangePB;}
130 :
131 0 : void SetEnableChangeAllPB(){m_bEnableChangeAllPB = true;}
132 0 : bool IsEnableChangeAllPB(){return m_bEnableChangeAllPB;}
133 :
134 0 : void SetErrorMove(long nNewStart, long nNewEnd, long nOldStart, long nOldEnd)
135 : {
136 0 : m_nNewErrorStart = nNewStart;
137 0 : m_nNewErrorEnd = nNewEnd;
138 0 : m_nOldErrorStart = nOldStart;
139 0 : m_nOldErrorEnd = nOldEnd;
140 0 : }
141 : long GetNewErrorStart() { return m_nNewErrorStart;}
142 : long GetNewErrorEnd() { return m_nNewErrorEnd;}
143 0 : long GetOldErrorStart() { return m_nOldErrorStart;}
144 0 : long GetOldErrorEnd() { return m_nOldErrorEnd;}
145 :
146 0 : void SetErrorLanguageSelected(bool bSet){ m_bIsErrorLanguageSelected = bSet;}
147 0 : bool IsErrorLanguageSelected() const {return m_bIsErrorLanguageSelected;}
148 :
149 0 : void SetDictionary(Reference<XDictionary> xDict) { m_xDictionary = xDict; }
150 0 : Reference<XDictionary> GetDictionary() const {return m_xDictionary;}
151 0 : void SetAddedWord(const OUString& rWord) {m_sAddedWord = rWord;}
152 0 : const OUString& GetAddedWord() const { return m_sAddedWord;}
153 :
154 0 : void SetOffset(long nSet) {m_nOffset = nSet;}
155 0 : long GetOffset() const {return m_nOffset;}
156 :
157 : void SetErrorType( const OUString& rId ) { m_sRuleId = rId; }
158 : const OUString& GetErrorType() const { return m_sRuleId; }
159 :
160 : };
161 : }//namespace svx
162 : using namespace ::svx;
163 :
164 :
165 0 : SpellUndoAction_Impl::~SpellUndoAction_Impl()
166 : {
167 0 : }
168 :
169 :
170 0 : void SpellUndoAction_Impl::Undo()
171 : {
172 0 : m_rActionLink.Call(this);
173 0 : }
174 :
175 :
176 0 : sal_uInt16 SpellUndoAction_Impl::GetId()const
177 : {
178 0 : return m_nId;
179 : }
180 :
181 : // class SvxSpellCheckDialog ---------------------------------------------
182 :
183 0 : SpellDialog::SpellDialog(SpellDialogChildWindow* pChildWindow,
184 : Window * pParent, SfxBindings* _pBindings)
185 : : SfxModelessDialog (_pBindings, pChildWindow,
186 : pParent, "SpellingDialog", "cui/ui/spellingdialog.ui")
187 : , aDialogUndoLink(LINK (this, SpellDialog, DialogUndoHdl))
188 : , bModified(false)
189 : , bFocusLocked(true)
190 0 : , rParent(*pChildWindow)
191 : {
192 0 : m_sTitleSpellingGrammar = GetText();
193 0 : m_sTitleSpelling = get<FixedText>("alttitleft")->GetText();
194 :
195 : // fdo#68794 set initial title for cases where no text has been processed
196 : // yet to show its language attributes
197 0 : OUString sTitle = rParent.HasGrammarChecking() ? m_sTitleSpellingGrammar : m_sTitleSpelling;
198 0 : SetText(sTitle.replaceFirst("$LANGUAGE ($LOCATION)", ""));
199 :
200 0 : m_sResumeST = get<FixedText>("resumeft")->GetText();
201 0 : m_sNoSuggestionsST = get<FixedText>("nosuggestionsft")->GetText();
202 :
203 0 : get(m_pLanguageFT, "languageft");
204 0 : get(m_pLanguageLB, "languagelb");
205 0 : get(m_pExplainFT, "explain");
206 0 : get(m_pExplainLink, "explainlink");
207 0 : get(m_pNotInDictFT, "notindictft");
208 0 : get(m_pSentenceED, "sentence");
209 0 : Size aEdSize(LogicToPixel(Size(197, 48), MAP_APPFONT));
210 0 : m_pSentenceED->set_width_request(aEdSize.Width());
211 0 : m_pSentenceED->set_height_request(aEdSize.Height());
212 0 : get(m_pSuggestionFT, "suggestionsft");
213 0 : get(m_pSuggestionLB, "suggestionslb");
214 0 : m_pSuggestionLB->SetDropDownLineCount(5);
215 0 : m_pSuggestionLB->set_width_request(aEdSize.Width());
216 0 : get(m_pIgnorePB, "ignore");
217 0 : m_sIgnoreOnceST = m_pIgnorePB->GetText();
218 0 : get(m_pIgnoreAllPB, "ignoreall");
219 0 : get(m_pIgnoreRulePB, "ignorerule");
220 0 : get(m_pAddToDictPB, "add");
221 0 : get(m_pAddToDictMB, "addmb");
222 0 : m_pAddToDictMB->SetHelpId(m_pAddToDictPB->GetHelpId());
223 0 : get(m_pChangePB, "change");
224 0 : get(m_pChangeAllPB, "changeall");
225 0 : get(m_pAutoCorrPB, "autocorrect");
226 0 : get(m_pCheckGrammarCB, "checkgrammar");
227 0 : get(m_pOptionsPB, "options");
228 0 : get(m_pUndoPB, "undo");
229 0 : get(m_pClosePB, "close");
230 0 : xSpell = LinguMgr::GetSpellChecker();
231 0 : pImpl = new SpellDialog_Impl;
232 :
233 0 : const StyleSettings& rSettings = GetSettings().GetStyleSettings();
234 0 : Color aCol = rSettings.GetHelpColor();
235 0 : Wallpaper aWall( aCol );
236 0 : m_pExplainLink->SetBackground( aWall );
237 0 : m_pExplainFT->SetBackground( aWall );
238 :
239 0 : Init_Impl();
240 :
241 : // disable controls if service is missing
242 0 : Enable(xSpell.is());
243 :
244 : //InitHdl wants to use virtual methods, so it
245 : //can't be called during the ctor, so init
246 : //it on next event cycle post-ctor
247 : Application::PostUserEvent( STATIC_LINK(
248 0 : this, SpellDialog, InitHdl ) );
249 0 : }
250 :
251 :
252 :
253 0 : SpellDialog::~SpellDialog()
254 : {
255 : // save possibly modified user-dictionaries
256 0 : Reference< XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
257 0 : if (xDicList.is())
258 : {
259 0 : linguistic::SaveDictionaries( xDicList );
260 : }
261 :
262 0 : delete pImpl;
263 0 : }
264 :
265 :
266 :
267 0 : void SpellDialog::Init_Impl()
268 : {
269 : // initialize handler
270 0 : m_pClosePB->SetClickHdl(LINK( this, SpellDialog, CancelHdl ) );
271 0 : m_pChangePB->SetClickHdl(LINK( this, SpellDialog, ChangeHdl ) );
272 0 : m_pChangeAllPB->SetClickHdl(LINK( this, SpellDialog, ChangeAllHdl ) );
273 0 : m_pIgnorePB->SetClickHdl(LINK( this, SpellDialog, IgnoreHdl ) );
274 0 : m_pIgnoreAllPB->SetClickHdl(LINK( this, SpellDialog, IgnoreAllHdl ) );
275 0 : m_pIgnoreRulePB->SetClickHdl(LINK( this, SpellDialog, IgnoreAllHdl ) );
276 0 : m_pUndoPB->SetClickHdl(LINK( this, SpellDialog, UndoHdl ) );
277 :
278 0 : m_pAutoCorrPB->SetClickHdl( LINK( this, SpellDialog, ExtClickHdl ) );
279 0 : m_pCheckGrammarCB->SetClickHdl( LINK( this, SpellDialog, CheckGrammarHdl ));
280 0 : m_pOptionsPB->SetClickHdl( LINK( this, SpellDialog, ExtClickHdl ) );
281 :
282 0 : m_pSuggestionLB->SetDoubleClickHdl( LINK( this, SpellDialog, ChangeHdl ) );
283 :
284 0 : m_pSentenceED->SetModifyHdl(LINK ( this, SpellDialog, ModifyHdl) );
285 :
286 0 : m_pAddToDictMB->SetSelectHdl(LINK ( this, SpellDialog, AddToDictSelectHdl ) );
287 0 : m_pAddToDictPB->SetClickHdl(LINK ( this, SpellDialog, AddToDictClickHdl ) );
288 :
289 0 : m_pLanguageLB->SetSelectHdl(LINK( this, SpellDialog, LanguageSelectHdl ) );
290 :
291 0 : m_pExplainLink->SetClickHdl( LINK( this, SpellDialog, HandleHyperlink ) );
292 :
293 : // initialize language ListBox
294 0 : m_pLanguageLB->SetLanguageList( LANG_LIST_SPELL_USED, false, false, true );
295 :
296 0 : m_pSentenceED->ClearModifyFlag();
297 0 : SvxGetChangeAllList()->clear();
298 0 : }
299 :
300 :
301 :
302 0 : void SpellDialog::UpdateBoxes_Impl()
303 : {
304 : sal_Int32 i;
305 0 : m_pSuggestionLB->Clear();
306 :
307 0 : const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
308 :
309 0 : LanguageType nAltLanguage = LANGUAGE_NONE;
310 0 : Sequence< OUString > aNewWords;
311 0 : bool bIsGrammarError = false;
312 0 : if( pSpellErrorDescription )
313 : {
314 0 : nAltLanguage = LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale );
315 0 : aNewWords = pSpellErrorDescription->aSuggestions;
316 0 : bIsGrammarError = pSpellErrorDescription->bIsGrammarError;
317 0 : m_pExplainLink->SetURL( pSpellErrorDescription->sExplanationURL );
318 0 : m_pExplainFT->SetText( pSpellErrorDescription->sExplanation );
319 : }
320 0 : if( pSpellErrorDescription && !pSpellErrorDescription->sDialogTitle.isEmpty() )
321 : {
322 : // use this function to apply the correct image to be used...
323 0 : SetTitle_Impl( nAltLanguage );
324 : // then change the title to the one to be actually used
325 0 : SetText( pSpellErrorDescription->sDialogTitle );
326 : }
327 : else
328 0 : SetTitle_Impl( nAltLanguage );
329 0 : SetSelectedLang_Impl( nAltLanguage );
330 0 : int nDicts = InitUserDicts();
331 :
332 : // enter alternatives
333 0 : const OUString *pNewWords = aNewWords.getConstArray();
334 0 : const sal_Int32 nSize = aNewWords.getLength();
335 0 : for ( i = 0; i < nSize; ++i )
336 : {
337 0 : OUString aTmp( pNewWords[i] );
338 0 : if ( LISTBOX_ENTRY_NOTFOUND == m_pSuggestionLB->GetEntryPos( aTmp ) )
339 : {
340 0 : m_pSuggestionLB->InsertEntry( aTmp );
341 0 : m_pSuggestionLB->SetEntryFlags(m_pSuggestionLB->GetEntryCount() - 1, LISTBOX_ENTRY_FLAG_MULTILINE);
342 : }
343 0 : }
344 0 : if(!nSize)
345 0 : m_pSuggestionLB->InsertEntry(m_sNoSuggestionsST);
346 0 : m_pAutoCorrPB->Enable( nSize > 0 );
347 :
348 0 : m_pSuggestionFT->Enable(nSize > 0);
349 0 : m_pSuggestionLB->Enable(nSize > 0);
350 0 : if( nSize )
351 : {
352 0 : m_pSuggestionLB->SelectEntryPos(0);
353 : }
354 0 : m_pChangePB->Enable( nSize > 0);
355 0 : m_pChangeAllPB->Enable(nSize > 0);
356 0 : bool bShowChangeAll = !bIsGrammarError;
357 0 : m_pChangeAllPB->Show( bShowChangeAll );
358 0 : m_pExplainFT->Show( !bShowChangeAll );
359 0 : m_pLanguageLB->Enable( bShowChangeAll );
360 0 : m_pIgnoreAllPB->Show( bShowChangeAll );
361 :
362 0 : m_pAddToDictMB->Show( bShowChangeAll && nDicts > 1);
363 0 : m_pAddToDictPB->Show( bShowChangeAll && nDicts <= 1);
364 0 : m_pIgnoreRulePB->Show( !bShowChangeAll );
365 0 : m_pIgnoreRulePB->Enable(pSpellErrorDescription && !pSpellErrorDescription->sRuleId.isEmpty());
366 0 : m_pAutoCorrPB->Show( bShowChangeAll && rParent.HasAutoCorrection() );
367 :
368 0 : bool bOldShowGrammar = m_pCheckGrammarCB->IsVisible();
369 0 : bool bOldShowExplain = m_pExplainLink->IsVisible();
370 :
371 0 : m_pCheckGrammarCB->Show(rParent.HasGrammarChecking());
372 0 : m_pExplainLink->Show(!m_pExplainLink->GetURL().isEmpty());
373 0 : if (m_pExplainFT->GetText().isEmpty())
374 : {
375 0 : m_pExplainFT->Hide();
376 0 : m_pExplainLink->Hide();
377 : }
378 :
379 0 : if (bOldShowExplain != (bool) m_pExplainLink->IsVisible() || bOldShowGrammar != (bool) m_pCheckGrammarCB->IsVisible())
380 0 : setOptimalLayoutSize();
381 0 : }
382 :
383 :
384 0 : void SpellDialog::SpellContinue_Impl(bool bUseSavedSentence, bool bIgnoreCurrentError )
385 : {
386 : //initially or after the last error of a sentence MarkNextError will fail
387 : //then GetNextSentence() has to be called followed again by MarkNextError()
388 : //MarkNextError is not initally called if the UndoEdit mode is active
389 0 : bool bNextSentence = false;
390 0 : if((!m_pSentenceED->IsUndoEditMode() && m_pSentenceED->MarkNextError( bIgnoreCurrentError, xSpell )) ||
391 0 : true == ( bNextSentence = GetNextSentence_Impl(bUseSavedSentence, m_pSentenceED->IsUndoEditMode()) && m_pSentenceED->MarkNextError( false, xSpell )))
392 : {
393 0 : const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
394 0 : if( pSpellErrorDescription )
395 : {
396 0 : UpdateBoxes_Impl();
397 : Control* aControls[] =
398 : {
399 : m_pNotInDictFT,
400 : m_pSentenceED,
401 : m_pLanguageFT,
402 : 0
403 0 : };
404 0 : sal_Int32 nIdx = 0;
405 0 : do
406 : {
407 0 : aControls[nIdx]->Enable(true);
408 : }
409 0 : while(aControls[++nIdx]);
410 :
411 : }
412 0 : if( bNextSentence )
413 : {
414 : //remove undo if a new sentence is active
415 0 : m_pSentenceED->ResetUndo();
416 0 : m_pUndoPB->Enable(false);
417 : }
418 : }
419 0 : }
420 : /* Initialize, asynchronous to prevent virtial calls
421 : from a constructor
422 : */
423 0 : IMPL_STATIC_LINK( SpellDialog, InitHdl, SpellDialog *, EMPTYARG )
424 : {
425 0 : pThis->SetUpdateMode( false );
426 : //show or hide AutoCorrect depending on the modules abilities
427 0 : pThis->m_pAutoCorrPB->Show(pThis->rParent.HasAutoCorrection());
428 0 : pThis->SpellContinue_Impl();
429 0 : pThis->m_pSentenceED->ResetUndo();
430 0 : pThis->m_pUndoPB->Enable(false);
431 :
432 : // get current language
433 0 : pThis->UpdateBoxes_Impl();
434 :
435 : // fill dictionary PopupMenu
436 0 : pThis->InitUserDicts();
437 :
438 0 : pThis->LockFocusChanges(true);
439 0 : if( pThis->m_pChangePB->IsEnabled() )
440 0 : pThis->m_pChangePB->GrabFocus();
441 0 : else if( pThis->m_pIgnorePB->IsEnabled() )
442 0 : pThis->m_pIgnorePB->GrabFocus();
443 0 : else if( pThis->m_pClosePB->IsEnabled() )
444 0 : pThis->m_pClosePB->GrabFocus();
445 0 : pThis->LockFocusChanges(false);
446 : //show grammar CheckBox depending on the modules abilities
447 0 : pThis->m_pCheckGrammarCB->Check( pThis->rParent.IsGrammarChecking() );
448 0 : pThis->SetUpdateMode( true );
449 0 : pThis->Show();
450 0 : return 0;
451 : };
452 :
453 :
454 :
455 0 : IMPL_LINK( SpellDialog, ExtClickHdl, Button *, pBtn )
456 : {
457 0 : if (m_pOptionsPB == pBtn)
458 0 : StartSpellOptDlg_Impl();
459 0 : else if (m_pAutoCorrPB == pBtn)
460 : {
461 : //get the currently selected wrong word
462 0 : OUString sCurrentErrorText = m_pSentenceED->GetErrorText();
463 : //get the wrong word from the XSpellAlternative
464 0 : const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
465 0 : if( pSpellErrorDescription )
466 : {
467 0 : OUString sWrong(pSpellErrorDescription->sErrorText);
468 : //if the word has not been edited in the MultiLineEdit then
469 : //the current suggestion should be used
470 : //if it's not the 'no suggestions' entry
471 0 : if(sWrong == sCurrentErrorText &&
472 0 : m_pSuggestionLB->IsEnabled() && m_pSuggestionLB->GetSelectEntryCount() > 0 &&
473 0 : !m_sNoSuggestionsST.equals(m_pSuggestionLB->GetSelectEntry()))
474 : {
475 0 : sCurrentErrorText = m_pSuggestionLB->GetSelectEntry();
476 : }
477 0 : if(sWrong != sCurrentErrorText)
478 : {
479 0 : SvxPrepareAutoCorrect( sWrong, sCurrentErrorText );
480 0 : LanguageType eLang = GetSelectedLang_Impl();
481 0 : rParent.AddAutoCorrection( sWrong, sCurrentErrorText, eLang );
482 0 : }
483 0 : }
484 : }
485 0 : return 0;
486 : }
487 :
488 0 : IMPL_LINK( SpellDialog, CheckGrammarHdl, CheckBox*, pBox )
489 : {
490 0 : rParent.SetGrammarChecking( pBox->IsChecked() );
491 0 : Impl_Restore();
492 0 : return 0;
493 : }
494 :
495 0 : void SpellDialog::StartSpellOptDlg_Impl()
496 : {
497 : sal_uInt16 aSpellInfos[] =
498 : {
499 : SID_ATTR_SPELL,SID_ATTR_SPELL,
500 : SID_SPELL_MODIFIED, SID_SPELL_MODIFIED,
501 : SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
502 : 0
503 0 : };
504 0 : SfxItemSet aSet( SFX_APP()->GetPool(), aSpellInfos);
505 0 : aSet.Put(SfxSpellCheckItem( xSpell, SID_ATTR_SPELL ));
506 : SfxSingleTabDialog* pDlg =
507 0 : new SfxSingleTabDialog(this, aSet, "SpellOptionsDialog", "cui/ui/spelloptionsdialog.ui");
508 0 : SfxTabPage* pPage = SvxLinguTabPage::Create( pDlg->get_content_area(), aSet );
509 0 : ( (SvxLinguTabPage*)pPage )->HideGroups( GROUP_MODULES );
510 0 : pDlg->SetTabPage( pPage );
511 0 : if(RET_OK == pDlg->Execute())
512 : {
513 0 : InitUserDicts();
514 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
515 0 : if(pOutSet)
516 0 : OfaTreeOptionsDialog::ApplyLanguageOptions(*pOutSet);
517 : }
518 0 : delete pDlg;
519 0 : }
520 :
521 : namespace
522 : {
523 0 : OUString getDotReplacementString(const OUString &rErrorText, const OUString &rSuggestedReplacement)
524 : {
525 0 : OUString aString = rErrorText;
526 :
527 : //dots are sometimes part of the spelled word but they are not necessarily part of the replacement
528 0 : bool bDot = aString.endsWith(".");
529 :
530 0 : aString = rSuggestedReplacement;
531 :
532 0 : if(bDot && (aString.isEmpty() || !aString.endsWith(".")))
533 0 : aString += ".";
534 :
535 0 : return aString;
536 : }
537 : }
538 :
539 :
540 0 : OUString SpellDialog::getReplacementString() const
541 : {
542 0 : OUString sOrigString = m_pSentenceED->GetErrorText();
543 :
544 0 : OUString sReplacement(sOrigString);
545 :
546 0 : if(m_pSuggestionLB->IsEnabled() &&
547 0 : m_pSuggestionLB->GetSelectEntryCount()>0 &&
548 0 : !m_sNoSuggestionsST.equals(m_pSuggestionLB->GetSelectEntry()))
549 0 : sReplacement = m_pSuggestionLB->GetSelectEntry();
550 :
551 0 : return getDotReplacementString(sOrigString, sReplacement);
552 : }
553 :
554 :
555 :
556 0 : IMPL_LINK_NOARG(SpellDialog, ChangeHdl)
557 : {
558 0 : if(m_pSentenceED->IsUndoEditMode())
559 : {
560 0 : SpellContinue_Impl();
561 : }
562 : else
563 : {
564 0 : m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
565 0 : OUString aString = getReplacementString();
566 0 : m_pSentenceED->ChangeMarkedWord(aString, GetSelectedLang_Impl());
567 0 : SpellContinue_Impl();
568 0 : bModified = false;
569 0 : m_pSentenceED->UndoActionEnd();
570 : }
571 0 : if(!m_pChangePB->IsEnabled())
572 0 : m_pIgnorePB->GrabFocus();
573 0 : return 1;
574 : }
575 :
576 :
577 :
578 0 : IMPL_LINK_NOARG(SpellDialog, ChangeAllHdl)
579 : {
580 0 : m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
581 0 : OUString aString = getReplacementString();
582 0 : LanguageType eLang = GetSelectedLang_Impl();
583 :
584 : // add new word to ChangeAll list
585 0 : OUString aOldWord( m_pSentenceED->GetErrorText() );
586 0 : SvxPrepareAutoCorrect( aOldWord, aString );
587 0 : Reference<XDictionary> aXDictionary( SvxGetChangeAllList(), UNO_QUERY );
588 : sal_uInt8 nAdded = linguistic::AddEntryToDic( aXDictionary,
589 : aOldWord, true,
590 0 : aString, eLang );
591 :
592 0 : if(nAdded == DIC_ERR_NONE)
593 : {
594 : SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
595 0 : SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
596 0 : pAction->SetDictionary(aXDictionary);
597 0 : pAction->SetAddedWord(aOldWord);
598 0 : m_pSentenceED->AddUndoAction(pAction);
599 : }
600 :
601 0 : m_pSentenceED->ChangeMarkedWord(aString, eLang);
602 0 : SpellContinue_Impl();
603 0 : bModified = false;
604 0 : m_pSentenceED->UndoActionEnd();
605 0 : return 1;
606 : }
607 :
608 :
609 0 : IMPL_LINK( SpellDialog, IgnoreAllHdl, Button *, pButton )
610 : {
611 0 : m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
612 : // add word to IgnoreAll list
613 0 : Reference< XDictionary > aXDictionary( SvxGetIgnoreAllList(), UNO_QUERY );
614 : //in case the error has been changed manually it has to be restored
615 0 : m_pSentenceED->RestoreCurrentError();
616 0 : if (pButton == m_pIgnoreRulePB)
617 : {
618 0 : const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
619 : try
620 : {
621 0 : if( pSpellErrorDescription && pSpellErrorDescription->xGrammarChecker.is() )
622 : {
623 0 : pSpellErrorDescription->xGrammarChecker->ignoreRule( pSpellErrorDescription->sRuleId,
624 0 : pSpellErrorDescription->aLocale );
625 : // refresh the layout (workaround to launch a dictionary event)
626 0 : aXDictionary->setActive(sal_False);
627 0 : aXDictionary->setActive(sal_True);
628 : }
629 : }
630 0 : catch( const uno::Exception& )
631 : {
632 : }
633 : }
634 : else
635 : {
636 0 : OUString sErrorText(m_pSentenceED->GetErrorText());
637 : sal_uInt8 nAdded = linguistic::AddEntryToDic( aXDictionary,
638 : sErrorText, false,
639 0 : OUString(), LANGUAGE_NONE );
640 0 : if(nAdded == DIC_ERR_NONE)
641 : {
642 : SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
643 0 : SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
644 0 : pAction->SetDictionary(aXDictionary);
645 0 : pAction->SetAddedWord(sErrorText);
646 0 : m_pSentenceED->AddUndoAction(pAction);
647 0 : }
648 : }
649 :
650 0 : SpellContinue_Impl();
651 0 : bModified = false;
652 0 : m_pSentenceED->UndoActionEnd();
653 0 : return 1;
654 : }
655 :
656 :
657 0 : IMPL_LINK_NOARG(SpellDialog, UndoHdl)
658 : {
659 0 : m_pSentenceED->Undo();
660 0 : if(!m_pSentenceED->GetUndoActionCount())
661 0 : m_pUndoPB->Enable(false);
662 0 : return 0;
663 : }
664 :
665 :
666 0 : IMPL_LINK( SpellDialog, DialogUndoHdl, SpellUndoAction_Impl*, pAction )
667 : {
668 0 : switch(pAction->GetId())
669 : {
670 : case SPELLUNDO_CHANGE_TEXTENGINE:
671 : {
672 0 : if(pAction->IsEnableChangePB())
673 0 : m_pChangePB->Enable(false);
674 0 : if(pAction->IsEnableChangeAllPB())
675 0 : m_pChangeAllPB->Enable(false);
676 : }
677 0 : break;
678 : case SPELLUNDO_CHANGE_NEXTERROR:
679 : {
680 0 : m_pSentenceED->MoveErrorMarkTo((sal_uInt16)pAction->GetOldErrorStart(), (sal_uInt16)pAction->GetOldErrorEnd(), false);
681 0 : if(pAction->IsErrorLanguageSelected())
682 : {
683 0 : UpdateBoxes_Impl();
684 : }
685 : }
686 0 : break;
687 : case SPELLUNDO_CHANGE_ADD_TO_DICTIONARY:
688 : {
689 0 : if(pAction->GetDictionary().is())
690 0 : pAction->GetDictionary()->remove(pAction->GetAddedWord());
691 : }
692 0 : break;
693 : case SPELLUNDO_MOVE_ERROREND :
694 : {
695 0 : if(pAction->GetOffset() != 0)
696 0 : m_pSentenceED->MoveErrorEnd(pAction->GetOffset());
697 : }
698 0 : break;
699 : case SPELLUNDO_UNDO_EDIT_MODE :
700 : {
701 : //refill the dialog with the currently spelled sentence - throw away all changes
702 0 : SpellContinue_Impl(true);
703 : }
704 0 : break;
705 : case SPELLUNDO_ADD_IGNORE_RULE:
706 : //undo of ignored rules is not supported
707 0 : break;
708 : }
709 :
710 0 : return 0;
711 : }
712 :
713 0 : void SpellDialog::Impl_Restore()
714 : {
715 : //clear the "ChangeAllList"
716 0 : SvxGetChangeAllList()->clear();
717 : //get a new sentence
718 0 : m_pSentenceED->SetText(OUString());
719 0 : m_pSentenceED->ResetModified();
720 : //Resolves: fdo#39348 refill the dialog with the currently spelled sentence
721 0 : SpellContinue_Impl(true);
722 0 : m_pIgnorePB->SetText(m_sIgnoreOnceST);
723 0 : }
724 :
725 0 : IMPL_LINK_NOARG(SpellDialog, IgnoreHdl)
726 : {
727 0 : if (m_sResumeST.equals(m_pIgnorePB->GetText()))
728 : {
729 0 : Impl_Restore();
730 : }
731 : else
732 : {
733 : //in case the error has been changed manually it has to be restored,
734 : // since the users choice now was to ignore the error
735 0 : m_pSentenceED->RestoreCurrentError();
736 :
737 : // the word is being ignored
738 0 : SpellContinue_Impl( false, true );
739 : }
740 0 : return 1;
741 : }
742 :
743 :
744 :
745 0 : bool SpellDialog::Close()
746 : {
747 0 : GetBindings().GetDispatcher()->
748 0 : Execute(rParent.GetType(),
749 0 : SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
750 0 : return true;
751 : }
752 :
753 :
754 0 : void SpellDialog::SetSelectedLang_Impl( LanguageType nLang )
755 : {
756 0 : m_pLanguageLB->SelectLanguage( nLang );
757 0 : }
758 :
759 :
760 :
761 0 : LanguageType SpellDialog::GetSelectedLang_Impl() const
762 : {
763 0 : sal_Int16 nLang = m_pLanguageLB->GetSelectLanguage();
764 0 : return nLang;
765 : }
766 :
767 :
768 0 : IMPL_LINK(SpellDialog, LanguageSelectHdl, SvxLanguageBox*, pBox)
769 : {
770 : //If selected language changes, then add->list should be regenerated to
771 : //match
772 0 : InitUserDicts();
773 :
774 : //if currently an error is selected then search for alternatives for
775 : //this word and fill the alternatives ListBox accordingly
776 0 : OUString sError = m_pSentenceED->GetErrorText();
777 0 : m_pSuggestionLB->Clear();
778 0 : if(!sError.isEmpty())
779 : {
780 0 : LanguageType eLanguage = pBox->GetSelectLanguage();
781 0 : Reference <XSpellAlternatives> xAlt = xSpell->spell( sError, eLanguage,
782 0 : Sequence< PropertyValue >() );
783 0 : if( xAlt.is() )
784 0 : m_pSentenceED->SetAlternatives( xAlt );
785 : else
786 : {
787 0 : m_pSentenceED->ChangeMarkedWord( sError, eLanguage );
788 0 : SpellContinue_Impl();
789 : }
790 :
791 0 : m_pSentenceED->AddUndoAction(new SpellUndoAction_Impl(SPELLUNDO_CHANGE_LANGUAGE, aDialogUndoLink));
792 : }
793 0 : SpellDialog::UpdateBoxes_Impl();
794 0 : return 0;
795 : }
796 :
797 :
798 0 : void SpellDialog::SetLanguage( sal_uInt16 nLang )
799 : /*
800 : Description:
801 : If the language has been changed in thesaurus,
802 : it must be changed here, too.
803 : */
804 : {
805 0 : SetTitle_Impl( nLang );
806 0 : m_pLanguageLB->SelectLanguage( nLang );
807 0 : }
808 :
809 0 : void SpellDialog::SetTitle_Impl(LanguageType nLang)
810 : {
811 0 : OUString sTitle = rParent.HasGrammarChecking() ? m_sTitleSpellingGrammar : m_sTitleSpelling;
812 0 : sTitle = sTitle.replaceFirst( "$LANGUAGE ($LOCATION)", SvtLanguageTable::GetLanguageString(nLang) );
813 0 : SetText( sTitle );
814 0 : }
815 :
816 0 : int SpellDialog::InitUserDicts()
817 : {
818 0 : const LanguageType nLang = m_pLanguageLB->GetSelectLanguage();
819 :
820 0 : const Reference< XDictionary > *pDic = 0;
821 :
822 : // get list of dictionaries
823 0 : Reference< XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
824 0 : if (xDicList.is())
825 : {
826 : // add active, positive dictionary to dic-list (if not already done).
827 : // This is to ensure that there is at least on dictionary to which
828 : // words could be added.
829 0 : Reference< XDictionary > xDic( SvxGetOrCreatePosDic( xDicList ) );
830 0 : if (xDic.is())
831 0 : xDic->setActive( sal_True );
832 :
833 0 : pImpl->aDics = xDicList->getDictionaries();
834 : }
835 :
836 0 : SvtLinguConfig aCfg;
837 :
838 : // list suitable dictionaries
839 0 : bool bEnable = false;
840 0 : const sal_Int32 nSize = pImpl->aDics.getLength();
841 0 : pDic = pImpl->aDics.getConstArray();
842 0 : PopupMenu* pMenu = m_pAddToDictMB->GetPopupMenu();
843 : assert(pMenu);
844 0 : pMenu->Clear();
845 0 : pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
846 0 : sal_uInt16 nItemId = 1; // menu items should be enumerated from 1 and not 0
847 0 : for (sal_Int32 i = 0; i < nSize; ++i)
848 : {
849 0 : uno::Reference< linguistic2::XDictionary > xDicTmp( pDic[i], uno::UNO_QUERY );
850 0 : if (!xDicTmp.is() || SvxGetIgnoreAllList() == xDicTmp)
851 0 : continue;
852 :
853 0 : uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
854 0 : LanguageType nActLanguage = LanguageTag( xDicTmp->getLocale() ).getLanguageType();
855 0 : if( xDicTmp->isActive()
856 0 : && xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
857 0 : && (nLang == nActLanguage || LANGUAGE_NONE == nActLanguage )
858 0 : && (!xStor.is() || !xStor->isReadonly()) )
859 : {
860 0 : pMenu->InsertItem( nItemId, xDicTmp->getName() );
861 0 : bEnable = true;
862 :
863 0 : uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
864 0 : if (xSvcInfo.is())
865 : {
866 : OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
867 0 : xSvcInfo->getImplementationName()) );
868 0 : if (!aDictionaryImageUrl.isEmpty())
869 : {
870 0 : Image aImage( aDictionaryImageUrl );
871 0 : pMenu->SetItemImage( nItemId, aImage );
872 0 : }
873 : }
874 :
875 0 : ++nItemId;
876 : }
877 0 : }
878 0 : m_pAddToDictMB->Enable( bEnable );
879 0 : m_pAddToDictPB->Enable( bEnable );
880 :
881 0 : int nDicts = nItemId-1;
882 :
883 0 : m_pAddToDictMB->Show( nDicts > 1 );
884 0 : m_pAddToDictPB->Show( nDicts <= 1 );
885 :
886 0 : return nDicts;
887 : }
888 :
889 :
890 0 : IMPL_LINK(SpellDialog, AddToDictClickHdl, PushButton*, EMPTYARG )
891 : {
892 0 : return AddToDictionaryExecute(1, m_pAddToDictMB->GetPopupMenu());
893 : }
894 :
895 :
896 0 : IMPL_LINK(SpellDialog, AddToDictSelectHdl, MenuButton*, pButton )
897 : {
898 0 : return AddToDictionaryExecute(pButton->GetCurItemId(), pButton->GetPopupMenu());
899 : }
900 :
901 :
902 0 : int SpellDialog::AddToDictionaryExecute( sal_uInt16 nItemId, PopupMenu *pMenu )
903 : {
904 0 : m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
905 :
906 : //GetErrorText() returns the current error even if the text is already
907 : //manually changed
908 0 : const OUString aNewWord = m_pSentenceED->GetErrorText();
909 :
910 0 : OUString aDicName ( pMenu->GetItemText( nItemId ) );
911 :
912 0 : uno::Reference< linguistic2::XDictionary > xDic;
913 0 : uno::Reference< linguistic2::XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
914 0 : if (xDicList.is())
915 0 : xDic = xDicList->getDictionaryByName( aDicName );
916 :
917 0 : sal_Int16 nAddRes = DIC_ERR_UNKNOWN;
918 0 : if (xDic.is())
919 : {
920 0 : nAddRes = linguistic::AddEntryToDic( xDic, aNewWord, false, OUString(), LANGUAGE_NONE );
921 : // save modified user-dictionary if it is persistent
922 0 : uno::Reference< frame::XStorable > xSavDic( xDic, uno::UNO_QUERY );
923 0 : if (xSavDic.is())
924 0 : xSavDic->store();
925 :
926 0 : if (nAddRes == DIC_ERR_NONE)
927 : {
928 : SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
929 0 : SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
930 0 : pAction->SetDictionary( xDic );
931 0 : pAction->SetAddedWord( aNewWord );
932 0 : m_pSentenceED->AddUndoAction( pAction );
933 : }
934 : // failed because there is already an entry?
935 0 : if (DIC_ERR_NONE != nAddRes && xDic->getEntry( aNewWord ).is())
936 0 : nAddRes = DIC_ERR_NONE;
937 : }
938 0 : if (DIC_ERR_NONE != nAddRes)
939 : {
940 0 : SvxDicError( this, nAddRes );
941 0 : return 0; // don't continue
942 : }
943 :
944 : // go on
945 0 : SpellContinue_Impl();
946 0 : m_pSentenceED->UndoActionEnd();
947 0 : return 0;
948 : }
949 :
950 :
951 0 : IMPL_LINK(SpellDialog, ModifyHdl, SentenceEditWindow_Impl*, pEd)
952 : {
953 0 : if (m_pSentenceED == pEd)
954 : {
955 0 : bModified = true;
956 0 : m_pSuggestionLB->SetNoSelection();
957 0 : m_pSuggestionLB->Disable();
958 0 : OUString sNewText( m_pSentenceED->GetText() );
959 0 : m_pAutoCorrPB->Enable( sNewText != m_pSentenceED->GetText() );
960 0 : SpellUndoAction_Impl* pSpellAction = new SpellUndoAction_Impl(SPELLUNDO_CHANGE_TEXTENGINE, aDialogUndoLink);
961 0 : if(!m_pChangeAllPB->IsEnabled())
962 : {
963 0 : m_pChangeAllPB->Enable();
964 0 : pSpellAction->SetEnableChangeAllPB();
965 : }
966 0 : if(!m_pChangePB->IsEnabled())
967 : {
968 0 : m_pChangePB->Enable();
969 0 : pSpellAction->SetEnableChangePB();
970 : }
971 0 : m_pSentenceED->AddUndoAction(pSpellAction);
972 : }
973 0 : return 0;
974 : };
975 :
976 :
977 0 : IMPL_LINK_NOARG(SpellDialog, CancelHdl)
978 : {
979 : //apply changes and ignored text parts first - if there are any
980 0 : rParent.ApplyChangedSentence(m_pSentenceED->CreateSpellPortions(true), false);
981 0 : Close();
982 0 : return 0;
983 : }
984 :
985 :
986 0 : bool SpellDialog::Notify( NotifyEvent& rNEvt )
987 : {
988 : /* #i38338#
989 : * FIXME: LoseFocus and GetFocus are signals from vcl that
990 : * a window actually got/lost the focus, it never should be
991 : * forwarded from another window, that is simply wrong.
992 : * FIXME: overloading the virtual methods GetFocus and LoseFocus
993 : * in SpellDialogChildWindow by making them pure is at least questionable.
994 : * The only sensible thing would be to call the new Method differently,
995 : * e.g. DialogGot/LostFocus or so.
996 : */
997 0 : if( IsVisible() && !bFocusLocked )
998 : {
999 0 : if( rNEvt.GetType() == EVENT_GETFOCUS )
1000 : {
1001 : //notify the child window of the focus change
1002 0 : rParent.GetFocus();
1003 : }
1004 0 : else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
1005 : {
1006 : //notify the child window of the focus change
1007 0 : rParent.LoseFocus();
1008 : }
1009 : }
1010 0 : return SfxModelessDialog::Notify(rNEvt);
1011 : }
1012 :
1013 :
1014 0 : void SpellDialog::InvalidateDialog()
1015 : {
1016 0 : if( bFocusLocked )
1017 0 : return;
1018 0 : m_pIgnorePB->SetText(m_sResumeST);
1019 : Window* aDisableArr[] =
1020 : {
1021 : m_pNotInDictFT,
1022 : m_pSentenceED,
1023 : m_pSuggestionFT,
1024 : m_pSuggestionLB,
1025 : m_pLanguageFT,
1026 : m_pLanguageLB,
1027 : m_pIgnoreAllPB,
1028 : m_pIgnoreRulePB,
1029 : m_pAddToDictMB,
1030 : m_pAddToDictPB,
1031 : m_pChangePB,
1032 : m_pChangeAllPB,
1033 : m_pAutoCorrPB,
1034 : m_pUndoPB,
1035 : 0
1036 0 : };
1037 0 : sal_Int16 i = 0;
1038 0 : while(aDisableArr[i])
1039 : {
1040 0 : aDisableArr[i]->Enable(false);
1041 0 : i++;
1042 : }
1043 0 : SfxModelessDialog::Deactivate();
1044 : }
1045 :
1046 :
1047 0 : bool SpellDialog::GetNextSentence_Impl(bool bUseSavedSentence, bool bRecheck)
1048 : {
1049 0 : bool bRet = false;
1050 0 : if(!bUseSavedSentence)
1051 : {
1052 : //apply changes and ignored text parts
1053 0 : rParent.ApplyChangedSentence(m_pSentenceED->CreateSpellPortions(true), bRecheck);
1054 : }
1055 0 : m_pSentenceED->ResetIgnoreErrorsAt();
1056 0 : m_pSentenceED->ResetModified();
1057 0 : SpellPortions aSentence = bUseSavedSentence ? m_aSavedSentence : rParent.GetNextWrongSentence( bRecheck );
1058 0 : if(!bUseSavedSentence)
1059 0 : m_aSavedSentence = aSentence;
1060 0 : bool bHasReplaced = false;
1061 0 : while(!aSentence.empty())
1062 : {
1063 : //apply all changes that are already part of the "ChangeAllList"
1064 : //returns true if the list still contains errors after the changes have been applied
1065 :
1066 0 : if(!ApplyChangeAllList_Impl(aSentence, bHasReplaced))
1067 : {
1068 0 : rParent.ApplyChangedSentence(aSentence, bRecheck);
1069 0 : aSentence = rParent.GetNextWrongSentence( bRecheck );
1070 : }
1071 : else
1072 0 : break;
1073 : }
1074 :
1075 0 : if(!aSentence.empty())
1076 : {
1077 0 : SpellPortions::iterator aStart = aSentence.begin();
1078 0 : OUString sText;
1079 0 : while(aStart != aSentence.end())
1080 : {
1081 : // hidden text has to be ignored
1082 0 : if(!aStart->bIsHidden)
1083 0 : sText += aStart->sText;
1084 0 : ++aStart;
1085 : }
1086 0 : m_pSentenceED->SetText(sText);
1087 0 : aStart = aSentence.begin();
1088 0 : sal_Int32 nStartPosition = 0;
1089 0 : sal_Int32 nEndPosition = 0;
1090 :
1091 0 : while(aStart != aSentence.end())
1092 : {
1093 : // hidden text has to be ignored
1094 0 : if(!aStart->bIsHidden)
1095 : {
1096 0 : nEndPosition += aStart->sText.getLength();
1097 0 : if(aStart->xAlternatives.is())
1098 : {
1099 0 : uno::Reference< container::XNamed > xNamed( aStart->xAlternatives, uno::UNO_QUERY );
1100 0 : OUString sServiceName;
1101 0 : if( xNamed.is() )
1102 0 : sServiceName = xNamed->getName();
1103 0 : SpellErrorDescription aDesc( false, aStart->xAlternatives->getWord(),
1104 0 : aStart->xAlternatives->getLocale(), aStart->xAlternatives->getAlternatives(), 0, sServiceName);
1105 0 : m_pSentenceED->SetAttrib( SpellErrorAttrib(aDesc), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
1106 : }
1107 0 : else if(aStart->bIsGrammarError )
1108 : {
1109 0 : beans::PropertyValues aProperties = aStart->aGrammarError.aProperties;
1110 0 : OUString sFullCommentURL;
1111 0 : sal_Int32 i = 0;
1112 0 : while ( sFullCommentURL.isEmpty() && i < aProperties.getLength() )
1113 : {
1114 0 : if ( aProperties[i].Name == "FullCommentURL" )
1115 : {
1116 0 : uno::Any aValue = aProperties[i].Value;
1117 0 : aValue >>= sFullCommentURL;
1118 : }
1119 0 : ++i;
1120 : }
1121 :
1122 0 : uno::Reference< lang::XServiceInfo > xInfo( aStart->xGrammarChecker, uno::UNO_QUERY );
1123 : SpellErrorDescription aDesc( true,
1124 0 : aStart->sText,
1125 0 : LanguageTag::convertToLocale( aStart->eLanguage ),
1126 0 : aStart->aGrammarError.aSuggestions,
1127 0 : aStart->xGrammarChecker,
1128 0 : xInfo->getImplementationName(),
1129 0 : &aStart->sDialogTitle,
1130 0 : &aStart->aGrammarError.aFullComment,
1131 0 : &aStart->aGrammarError.aRuleIdentifier,
1132 0 : &sFullCommentURL );
1133 0 : m_pSentenceED->SetAttrib( SpellErrorAttrib(aDesc), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
1134 : }
1135 0 : if(aStart->bIsField)
1136 0 : m_pSentenceED->SetAttrib( SpellBackgroundAttrib(COL_LIGHTGRAY), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
1137 0 : m_pSentenceED->SetAttrib( SpellLanguageAttrib(aStart->eLanguage), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
1138 0 : nStartPosition = nEndPosition;
1139 : }
1140 0 : ++aStart;
1141 : }
1142 : //the edit field needs to be modified to apply the change from the ApplyChangeAllList
1143 0 : if(!bHasReplaced)
1144 0 : m_pSentenceED->ClearModifyFlag();
1145 0 : m_pSentenceED->ResetUndo();
1146 0 : m_pUndoPB->Enable(false);
1147 0 : bRet = nStartPosition > 0;
1148 : }
1149 0 : return bRet;
1150 : }
1151 : /*-------------------------------------------------------------------------
1152 : replace errors that have a replacement in the ChangeAllList
1153 : returns false if the result doesn't contain errors after the replacement
1154 : -----------------------------------------------------------------------*/
1155 0 : bool SpellDialog::ApplyChangeAllList_Impl(SpellPortions& rSentence, bool &bHasReplaced)
1156 : {
1157 0 : bHasReplaced = false;
1158 0 : bool bRet = true;
1159 0 : SpellPortions::iterator aStart = rSentence.begin();
1160 0 : Reference<XDictionary> xChangeAll( SvxGetChangeAllList(), UNO_QUERY );
1161 0 : if(!xChangeAll->getCount())
1162 0 : return bRet;
1163 0 : bRet = false;
1164 0 : while(aStart != rSentence.end())
1165 : {
1166 0 : if(aStart->xAlternatives.is())
1167 : {
1168 0 : const OUString &rString = aStart->sText;
1169 :
1170 0 : Reference<XDictionaryEntry> xEntry = xChangeAll->getEntry(rString);
1171 :
1172 0 : if(xEntry.is())
1173 : {
1174 0 : aStart->sText = getDotReplacementString(rString, xEntry->getReplacementText());
1175 0 : aStart->xAlternatives = 0;
1176 0 : bHasReplaced = true;
1177 : }
1178 : else
1179 0 : bRet = true;
1180 : }
1181 0 : else if( aStart->bIsGrammarError )
1182 0 : bRet = true;
1183 0 : ++aStart;
1184 : }
1185 0 : return bRet;
1186 : }
1187 :
1188 :
1189 0 : SentenceEditWindow_Impl::SentenceEditWindow_Impl(Window * pParent, WinBits nBits)
1190 : : VclMultiLineEdit(pParent, nBits)
1191 : , m_nErrorStart(0)
1192 : , m_nErrorEnd(0)
1193 0 : , m_bIsUndoEditMode(false)
1194 : {
1195 0 : DisableSelectionOnFocus();
1196 0 : }
1197 :
1198 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSentenceEditWindow(Window *pParent,
1199 : VclBuilder::stringmap &)
1200 : {
1201 0 : return new SentenceEditWindow_Impl(pParent, WB_BORDER|WB_VSCROLL|WB_IGNORETAB);
1202 : }
1203 :
1204 :
1205 0 : SentenceEditWindow_Impl::~SentenceEditWindow_Impl()
1206 : {
1207 0 : }
1208 : /*-------------------------------------------------------------------------
1209 : The selection before inputting a key may have a range or not
1210 : and it may be inside or outside of field or error attributes.
1211 : A range may include the attribute partially, completely or together
1212 : with surrounding text. It may also contain more than one attribute
1213 : or no attribute at all.
1214 : Depending on this starting conditions some actions are necessary:
1215 : Attempts to delete a field are only allowed if the selection is the same
1216 : as the field's selection. Otherwise the field has to be selected and the key
1217 : input action has to be skipped.
1218 : Input of text at the start of the field requires the field attribute to be
1219 : corrected - it is not allowed to grow.
1220 :
1221 : In case of errors the appending of text should grow the error attribute because
1222 : that is what the user usually wants to do.
1223 :
1224 : Backspace at the start of the attribute requires to find out if a field ends
1225 : directly in front of the cursor position. In case of a field this attribute has to be
1226 : selected otherwise the key input method is allowed.
1227 :
1228 : All changes outside of the error attributes switch the dialog mode to a "Undo edit" state that
1229 : removes all visible attributes and switches off further attribute checks.
1230 : Undo in this restarts the dialog with a current sentence newly presented.
1231 : All changes to the sentence are undone including the ones before the "Undo edit state" has been reached
1232 :
1233 : We end up with 9 types of selection
1234 : 1 (LEFT_NO) - no range, start of attribute - can also be 3 at the same time
1235 : 2 (INSIDE_NO) - no range, inside of attribute
1236 : 3 (RIGHT_NO) - no range, end of attribute - can also be 1 at the same time
1237 : 4 (FULL) - range, same as attribute
1238 : 5 (INSIDE_YES) - range, inside of the attribute
1239 : 6 (BRACE)- range, from outside of the attribute to the inside or
1240 : including the complete attribute and something outside,
1241 : maybe more than one attribute
1242 : 7 (OUTSIDE_NO) - no range, not at an attribute
1243 : 8 (OUTSIDE_YES) - range, completely outside of all attributes
1244 :
1245 : What has to be done depending on the attribute type involved
1246 : possible actions: UE - Undo edit mode
1247 : CO - Continue, no additional action is required
1248 : FS - Field has to be completely selected
1249 : EX - The attribute has to be expanded to include the added text
1250 :
1251 : 1 - backspace delete any other
1252 : UE on field FS on error CO on field FS on error CO
1253 :
1254 : 2 - on field FS on error C
1255 : 3 - backspace delete any other
1256 : on field FS on error CO UE on field UE on error EX
1257 :
1258 : if 1 and 3 happen to apply both then backspace and other handling is 1 delete is 3
1259 :
1260 : 4 - on field UE and on error CO
1261 : 5 - on field FS and on error CO
1262 : 6 - on field FS and on error UE
1263 : 7 - UE
1264 : 8 - UE
1265 : -----------------------------------------------------------------------*/
1266 : #define INVALID 0
1267 : #define LEFT_NO 1
1268 : #define INSIDE_NO 2
1269 : #define RIGHT_NO 3
1270 : #define FULL 4
1271 : #define INSIDE_YES 5
1272 : #define BRACE 6
1273 : #define OUTSIDE_NO 7
1274 : #define OUTSIDE_YES 8
1275 :
1276 : #define ACTION_UNDOEDIT 0
1277 : #define ACTION_CONTINUE 1
1278 : #define ACTION_SELECTFIELD 2
1279 : #define ACTION_EXPAND 3
1280 :
1281 0 : bool SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
1282 : {
1283 0 : bool bChange = false;
1284 0 : const TextCharAttrib* pErrorAttrib = 0;
1285 0 : if(rNEvt.GetType() == EVENT_KEYINPUT)
1286 : {
1287 0 : const KeyEvent& rKeyEvt = *rNEvt.GetKeyEvent();
1288 0 : bChange = TextEngine::DoesKeyChangeText( rKeyEvt );
1289 0 : if(bChange && !IsUndoEditMode() &&
1290 0 : rKeyEvt.GetKeyCode().GetCode() != KEY_TAB)
1291 : {
1292 0 : TextEngine* pTextEngine = GetTextEngine();
1293 0 : TextView* pTextView = pTextEngine->GetActiveView();
1294 0 : const TextSelection& rCurrentSelection = pTextView->GetSelection();
1295 : //determine if the selection contains a field
1296 0 : bool bHasField = false;
1297 0 : bool bHasError = false;
1298 0 : bool bHasFieldLeft = false;
1299 0 : bool bHasErrorLeft = false;
1300 :
1301 0 : bool bHasRange = rCurrentSelection.HasRange();
1302 0 : sal_uInt8 nSelectionType = 0; // invalid type!
1303 :
1304 0 : TextPaM aCursor(rCurrentSelection.GetStart());
1305 0 : const TextCharAttrib* pBackAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
1306 0 : const TextCharAttrib* pErrorAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
1307 0 : const TextCharAttrib* pBackAttrLeft = 0;
1308 0 : const TextCharAttrib* pErrorAttrLeft = 0;
1309 :
1310 0 : bHasField = pBackAttr != 0 && (bHasRange || pBackAttr->GetEnd() > aCursor.GetIndex());
1311 0 : bHasError = pErrorAttr != 0 && (bHasRange || pErrorAttr->GetEnd() > aCursor.GetIndex());
1312 0 : if(bHasRange)
1313 : {
1314 0 : if(pBackAttr &&
1315 0 : pBackAttr->GetStart() == rCurrentSelection.GetStart().GetIndex() &&
1316 0 : pBackAttr->GetEnd() == rCurrentSelection.GetEnd().GetIndex())
1317 : {
1318 0 : nSelectionType = FULL;
1319 : }
1320 0 : else if(pErrorAttr &&
1321 0 : pErrorAttr->GetStart() <= rCurrentSelection.GetStart().GetIndex() &&
1322 0 : pErrorAttr->GetEnd() >= rCurrentSelection.GetEnd().GetIndex())
1323 : {
1324 0 : nSelectionType = INSIDE_YES;
1325 : }
1326 : else
1327 : {
1328 0 : nSelectionType = bHasField||bHasError ? BRACE : OUTSIDE_NO;
1329 0 : while(aCursor.GetIndex() < rCurrentSelection.GetEnd().GetIndex())
1330 : {
1331 0 : ++aCursor.GetIndex();
1332 0 : const TextCharAttrib* pIntBackAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
1333 0 : const TextCharAttrib* pIntErrorAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
1334 : //if any attr has been found then BRACE
1335 0 : if(pIntBackAttr || pIntErrorAttr)
1336 0 : nSelectionType = BRACE;
1337 : //the field has to be selected
1338 0 : if(pIntBackAttr && !pBackAttr)
1339 0 : pBackAttr = pIntBackAttr;
1340 0 : bHasField |= pIntBackAttr != 0;
1341 : }
1342 : }
1343 : }
1344 : else
1345 : {
1346 : //no range selection: then 1 2 3 and 8 are possible
1347 0 : const TextCharAttrib* pCurAttr = pBackAttr ? pBackAttr : pErrorAttr;
1348 0 : if(pCurAttr)
1349 : {
1350 0 : nSelectionType = pCurAttr->GetStart() == rCurrentSelection.GetStart().GetIndex() ?
1351 0 : LEFT_NO : pCurAttr->GetEnd() == rCurrentSelection.GetEnd().GetIndex() ? RIGHT_NO : INSIDE_NO;
1352 : }
1353 : else
1354 0 : nSelectionType = OUTSIDE_NO;
1355 :
1356 0 : bHasFieldLeft = pBackAttr && pBackAttr->GetEnd() == aCursor.GetIndex();
1357 0 : if(bHasFieldLeft)
1358 : {
1359 0 : pBackAttrLeft = pBackAttr;
1360 0 : pBackAttr = 0;
1361 : }
1362 0 : bHasErrorLeft = pErrorAttr && pErrorAttr->GetEnd() == aCursor.GetIndex();
1363 0 : if(bHasErrorLeft)
1364 : {
1365 0 : pErrorAttrLeft = pErrorAttr;
1366 0 : pErrorAttr = 0;
1367 : }
1368 :
1369 : //check previous position if this exists
1370 : //that is a redundant in the case the attribute found above already is on the left cursor side
1371 : //but it's o.k. for two errors/fields side by side
1372 0 : if(aCursor.GetIndex())
1373 : {
1374 0 : --aCursor.GetIndex();
1375 0 : pBackAttrLeft = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
1376 0 : pErrorAttrLeft = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
1377 0 : bHasFieldLeft = pBackAttrLeft !=0;
1378 0 : bHasErrorLeft = pErrorAttrLeft != 0;
1379 0 : ++aCursor.GetIndex();
1380 : }
1381 : }
1382 : //Here we have to determine if the error found is the one currently active
1383 0 : bool bIsErrorActive = (pErrorAttr && pErrorAttr->GetStart() == m_nErrorStart) ||
1384 0 : (pErrorAttrLeft && pErrorAttrLeft->GetStart() == m_nErrorStart);
1385 :
1386 : SAL_WARN_IF(
1387 : nSelectionType == INVALID, "cui.dialogs",
1388 : "selection type not set");
1389 :
1390 0 : const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
1391 0 : bool bDelete = rKeyCode.GetCode() == KEY_DELETE;
1392 0 : bool bBackspace = rKeyCode.GetCode() == KEY_BACKSPACE;
1393 :
1394 0 : sal_Int8 nAction = ACTION_CONTINUE;
1395 0 : switch(nSelectionType)
1396 : {
1397 : // 1 - backspace delete any other
1398 : // UE on field FS on error CO on field FS on error CO
1399 : case LEFT_NO :
1400 0 : if(bBackspace)
1401 : {
1402 0 : nAction = bHasFieldLeft ? ACTION_SELECTFIELD : ACTION_UNDOEDIT;
1403 : //to force the use of pBackAttrLeft
1404 0 : pBackAttr = 0;
1405 : }
1406 0 : else if(bDelete)
1407 0 : nAction = bHasField ? ACTION_SELECTFIELD : ACTION_CONTINUE;
1408 : else
1409 0 : nAction = bHasError && !aCursor.GetIndex() ? ACTION_CONTINUE :
1410 0 : bHasError ? ACTION_EXPAND : bHasErrorLeft ? ACTION_CONTINUE : ACTION_UNDOEDIT;
1411 0 : break;
1412 : // 2 - on field FS on error C
1413 : case INSIDE_NO :
1414 : nAction = bHasField ? ACTION_SELECTFIELD :
1415 0 : bIsErrorActive ? ACTION_CONTINUE : ACTION_UNDOEDIT;
1416 0 : break;
1417 : // 3 - backspace delete any other
1418 : // on field FS on error CO UE on field UE on error EX
1419 : case RIGHT_NO :
1420 0 : if(bBackspace)
1421 0 : nAction = bHasFieldLeft ? ACTION_SELECTFIELD : ACTION_CONTINUE;
1422 0 : else if(bDelete)
1423 0 : nAction = bHasFieldLeft && bHasError ? ACTION_CONTINUE : ACTION_UNDOEDIT;
1424 : else
1425 0 : nAction = bHasFieldLeft && bHasError ? ACTION_EXPAND :
1426 0 : bHasError ? ACTION_CONTINUE : bHasErrorLeft ? ACTION_EXPAND :ACTION_UNDOEDIT;
1427 0 : break;
1428 : // 4 - on field UE and on error CO
1429 : case FULL :
1430 0 : nAction = bHasField ? ACTION_UNDOEDIT : ACTION_CONTINUE;
1431 0 : break;
1432 : // 5 - on field FS and on error CO
1433 : case INSIDE_YES :
1434 0 : nAction = bHasField ? ACTION_SELECTFIELD : ACTION_CONTINUE;
1435 0 : break;
1436 : // 6 - on field FS and on error UE
1437 : case BRACE :
1438 0 : nAction = bHasField ? ACTION_SELECTFIELD : ACTION_UNDOEDIT;;
1439 0 : break;
1440 : // 7 - UE
1441 : // 8 - UE
1442 : case OUTSIDE_NO :
1443 : case OUTSIDE_YES:
1444 0 : nAction = ACTION_UNDOEDIT;
1445 0 : break;
1446 : }
1447 : //save the current paragraph
1448 0 : sal_Int32 nCurrentLen = GetText().getLength();
1449 0 : if(nAction != ACTION_SELECTFIELD)
1450 0 : pTextView->GetWindow()->KeyInput(rKeyEvt);
1451 : else
1452 : {
1453 0 : const TextCharAttrib* pCharAttr = pBackAttr ? pBackAttr : pBackAttrLeft;
1454 0 : if(pCharAttr)
1455 : {
1456 0 : TextPaM aStart(0, pCharAttr->GetStart());
1457 0 : TextPaM aEnd(0, pCharAttr->GetEnd());
1458 0 : TextSelection aNewSel(aStart, aEnd);
1459 0 : pTextView->SetSelection( aNewSel);
1460 : }
1461 : }
1462 0 : if(nAction == ACTION_EXPAND)
1463 : {
1464 : DBG_ASSERT(pErrorAttrLeft || pErrorAttr, "where is the error");
1465 : //text has been added on the right and only the 'error attribute has to be corrected
1466 0 : if(pErrorAttrLeft)
1467 : {
1468 0 : TextAttrib* pNewError = pErrorAttrLeft->GetAttr().Clone();
1469 0 : sal_uInt16 nStart = pErrorAttrLeft->GetStart();
1470 0 : sal_uInt16 nEnd = pErrorAttrLeft->GetEnd();
1471 0 : pTextEngine->RemoveAttrib( 0, *pErrorAttrLeft );
1472 0 : SetAttrib( *pNewError, 0, nStart, ++nEnd );
1473 : //only active errors move the mark
1474 0 : if(bIsErrorActive)
1475 : {
1476 0 : bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
1477 0 : MoveErrorMarkTo(nStart, nEnd, bGrammar);
1478 : }
1479 0 : delete pNewError;
1480 : }
1481 : //text has been added on the left then the error attribute has to be expanded and the
1482 : //field attribute on the right - if any - has to be contracted
1483 0 : else if(pErrorAttr)
1484 : {
1485 : //determine the change
1486 0 : sal_Int32 nAddedChars = GetText().getLength() - nCurrentLen;
1487 :
1488 0 : TextAttrib* pNewError = pErrorAttr->GetAttr().Clone();
1489 0 : sal_Int32 nStart = pErrorAttr->GetStart();
1490 0 : sal_Int32 nEnd = pErrorAttr->GetEnd();
1491 0 : pTextEngine->RemoveAttrib( 0, *pErrorAttr );
1492 0 : nStart = nStart - nAddedChars;
1493 0 : SetAttrib( *pNewError, 0, nStart - nAddedChars, nEnd );
1494 : //only if the error is active the mark is moved here
1495 0 : if(bIsErrorActive)
1496 : {
1497 0 : bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
1498 0 : MoveErrorMarkTo(nStart, nEnd, bGrammar);
1499 : }
1500 0 : delete pNewError;
1501 :
1502 0 : if(pBackAttrLeft)
1503 : {
1504 0 : TextAttrib* pNewBack = pBackAttrLeft->GetAttr().Clone();
1505 0 : sal_uInt16 _nStart = pBackAttrLeft->GetStart();
1506 0 : sal_uInt16 _nEnd = pBackAttrLeft->GetEnd();
1507 0 : pTextEngine->RemoveAttrib( 0, *pBackAttrLeft );
1508 0 : SetAttrib( *pNewBack, 0, _nStart, _nEnd - nAddedChars);
1509 0 : delete pNewBack;
1510 : }
1511 : }
1512 : }
1513 0 : else if(nAction == ACTION_UNDOEDIT)
1514 : {
1515 0 : SetUndoEditMode(true);
1516 : }
1517 : //make sure the error positions are correct after text changes
1518 : //the old attribute may have been deleted
1519 : //all changes inside of the current error leave the error attribute at the current
1520 : //start position
1521 0 : if(!IsUndoEditMode() && bIsErrorActive)
1522 : {
1523 0 : const TextCharAttrib* pFontColor = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_FONTCOLOR );
1524 0 : pErrorAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_ERROR );
1525 0 : if(pFontColor && pErrorAttrib )
1526 : {
1527 0 : m_nErrorStart = pFontColor->GetStart();
1528 0 : m_nErrorEnd = pFontColor->GetEnd();
1529 0 : if(pErrorAttrib->GetStart() != m_nErrorStart || pErrorAttrib->GetEnd() != m_nErrorEnd)
1530 : {
1531 0 : TextAttrib* pNewError = pErrorAttrib->GetAttr().Clone();
1532 0 : pTextEngine->RemoveAttrib( 0, *pErrorAttr );
1533 0 : SetAttrib( *pNewError, 0, m_nErrorStart, m_nErrorEnd );
1534 0 : delete pNewError;
1535 : }
1536 : }
1537 : }
1538 : //this is not a modification anymore
1539 0 : if(nAction != ACTION_SELECTFIELD && !m_bIsUndoEditMode)
1540 0 : CallModifyLink();
1541 : }
1542 : else
1543 0 : bChange = false;
1544 : }
1545 0 : return bChange || VclMultiLineEdit::PreNotify(rNEvt);
1546 : }
1547 :
1548 :
1549 0 : bool SentenceEditWindow_Impl::MarkNextError( bool bIgnoreCurrentError, com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellChecker1> xSpell )
1550 : {
1551 0 : if (bIgnoreCurrentError)
1552 0 : m_aIgnoreErrorsAt.insert( m_nErrorStart );
1553 0 : ExtTextEngine* pTextEngine = GetTextEngine();
1554 0 : sal_uInt16 nTextLen = pTextEngine->GetTextLen(0);
1555 0 : if(m_nErrorEnd >= nTextLen - 1)
1556 0 : return false;
1557 : //if it's not already modified the modified flag has to be reset at the and of the marking
1558 0 : bool bModified = IsModified();
1559 0 : bool bRet = false;
1560 0 : const sal_uInt16 nOldErrorStart = m_nErrorStart;
1561 0 : const sal_uInt16 nOldErrorEnd = m_nErrorEnd;
1562 :
1563 : //create a cursor behind the end of the last error
1564 : //- or at 0 at the start of the sentence
1565 0 : TextPaM aCursor(0, m_nErrorEnd ? m_nErrorEnd + 1 : 0);
1566 : //search for SpellErrorAttrib
1567 :
1568 0 : const TextCharAttrib* pNextError = 0;
1569 : //iterate over the text and search for the next error that maybe has
1570 : //to be replace by a ChangeAllList replacement
1571 0 : bool bGrammarError = false;
1572 0 : while(aCursor.GetIndex() < nTextLen)
1573 : {
1574 0 : while(aCursor.GetIndex() < nTextLen &&
1575 0 : 0 == (pNextError = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR)))
1576 : {
1577 0 : ++aCursor.GetIndex();
1578 : }
1579 : // maybe the error found here is already in the ChangeAllList and has to be replaced
1580 :
1581 0 : Reference<XDictionary> xChangeAll( SvxGetChangeAllList(), UNO_QUERY );
1582 0 : Reference<XDictionaryEntry> xEntry;
1583 :
1584 0 : const SpellErrorDescription* pSpellErrorDescription = 0;
1585 0 : if(pNextError)
1586 : {
1587 0 : pSpellErrorDescription = &static_cast<const SpellErrorAttrib&>(pNextError->GetAttr()).GetErrorDescription();
1588 0 : bGrammarError = pSpellErrorDescription->bIsGrammarError;
1589 0 : m_nErrorStart = pNextError->GetStart();
1590 0 : m_nErrorEnd = pNextError->GetEnd();
1591 : }
1592 0 : if(xChangeAll->getCount() && pSpellErrorDescription &&
1593 0 : (xEntry = xChangeAll->getEntry( pSpellErrorDescription->sErrorText )).is())
1594 : {
1595 :
1596 0 : OUString sReplacement(getDotReplacementString(GetErrorText(), xEntry->getReplacementText()));
1597 :
1598 0 : ChangeMarkedWord(sReplacement, LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale ));
1599 :
1600 0 : aCursor.GetIndex() = aCursor.GetIndex() + (sal_uInt16)(xEntry->getReplacementText().getLength());
1601 : // maybe the error found here is already added to the dictionary and has to be ignored
1602 0 : } else if(pSpellErrorDescription && !bGrammarError && xSpell->isValid( GetErrorText(), LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale ), Sequence< PropertyValue >() )) {
1603 0 : aCursor.GetIndex() = aCursor.GetIndex() + 1;
1604 : }
1605 : else
1606 0 : break;
1607 0 : }
1608 :
1609 : //if an attrib has been found search for the end of the error string
1610 0 : if(aCursor.GetIndex() < nTextLen)
1611 : {
1612 0 : m_nErrorStart = aCursor.GetIndex();
1613 0 : m_nErrorEnd = pNextError->GetEnd();
1614 0 : MoveErrorMarkTo(m_nErrorStart, m_nErrorEnd, bGrammarError);
1615 0 : bRet = true;
1616 : //add an undo action
1617 : SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
1618 0 : SPELLUNDO_CHANGE_NEXTERROR, GetSpellDialog()->aDialogUndoLink);
1619 0 : pAction->SetErrorMove(m_nErrorStart, m_nErrorEnd, nOldErrorStart, nOldErrorEnd);
1620 : const SpellErrorAttrib* pOldAttrib = static_cast<const SpellErrorAttrib*>(
1621 0 : pTextEngine->FindAttrib( TextPaM(0, nOldErrorStart), TEXTATTR_SPELL_ERROR ));
1622 0 : pAction->SetErrorLanguageSelected(pOldAttrib && pOldAttrib->GetErrorDescription().aSuggestions.getLength() &&
1623 0 : LanguageTag( pOldAttrib->GetErrorDescription().aLocale).getLanguageType() ==
1624 0 : GetSpellDialog()->m_pLanguageLB->GetSelectLanguage());
1625 0 : AddUndoAction(pAction);
1626 : }
1627 : else
1628 0 : m_nErrorStart = m_nErrorEnd = nTextLen;
1629 0 : if( !bModified )
1630 0 : ClearModifyFlag();
1631 0 : SpellDialog* pSpellDialog = GetSpellDialog();
1632 0 : pSpellDialog->m_pIgnorePB->Enable(bRet);
1633 0 : pSpellDialog->m_pIgnoreAllPB->Enable(bRet);
1634 0 : pSpellDialog->m_pAutoCorrPB->Enable(bRet);
1635 0 : pSpellDialog->m_pAddToDictMB->Enable(bRet);
1636 0 : pSpellDialog->m_pAddToDictPB->Enable(bRet);
1637 0 : return bRet;
1638 : }
1639 :
1640 :
1641 0 : void SentenceEditWindow_Impl::MoveErrorMarkTo(sal_uInt16 nStart, sal_uInt16 nEnd, bool bGrammarError)
1642 : {
1643 0 : TextEngine* pTextEngine = GetTextEngine();
1644 0 : pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTCOLOR, true );
1645 0 : pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTWEIGHT, true );
1646 0 : pTextEngine->SetAttrib( TextAttribFontWeight(WEIGHT_BOLD), 0, nStart, nEnd );
1647 0 : pTextEngine->SetAttrib( TextAttribFontColor(bGrammarError ? COL_LIGHTBLUE : COL_LIGHTRED), 0, nStart, nEnd );
1648 0 : m_nErrorStart = nStart;
1649 0 : m_nErrorEnd = nEnd;
1650 0 : }
1651 :
1652 :
1653 0 : void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, LanguageType eLanguage)
1654 : {
1655 : //calculate length changes
1656 0 : long nDiffLen = rNewWord.getLength() - m_nErrorEnd + m_nErrorStart;
1657 0 : TextSelection aSel(TextPaM(0, m_nErrorStart), TextPaM(0, m_nErrorEnd));
1658 : //Remove spell error attribute
1659 0 : ExtTextEngine* pTextEngine = GetTextEngine();
1660 0 : pTextEngine->UndoActionStart();
1661 0 : const TextCharAttrib* pErrorAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_ERROR );
1662 : DBG_ASSERT(pErrorAttrib, "no error attribute found");
1663 0 : const SpellErrorDescription* pSpellErrorDescription = 0;
1664 0 : if(pErrorAttrib)
1665 : {
1666 0 : pTextEngine->RemoveAttrib(0, *pErrorAttrib);
1667 0 : pSpellErrorDescription = &static_cast<const SpellErrorAttrib&>(pErrorAttrib->GetAttr()).GetErrorDescription();
1668 : }
1669 0 : const TextCharAttrib* pBackAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_BACKGROUND );
1670 0 : pTextEngine->ReplaceText( aSel, rNewWord );
1671 :
1672 0 : if(!m_nErrorStart)
1673 : {
1674 : //attributes following an error at the start of the text are not moved but expanded from the
1675 : //text engine - this is done to keep full-paragraph-attributes
1676 : //in the current case that handling is not desired
1677 : const TextCharAttrib* pLangAttrib =
1678 : pTextEngine->FindCharAttrib(
1679 0 : TextPaM(0, m_nErrorEnd), TEXTATTR_SPELL_LANGUAGE );
1680 0 : sal_uInt16 nTextLen = pTextEngine->GetTextLen( 0 );
1681 0 : if(pLangAttrib && !pLangAttrib->GetStart() && pLangAttrib->GetEnd() ==
1682 : nTextLen)
1683 : {
1684 0 : SpellLanguageAttrib aNewLangAttrib( static_cast<const SpellLanguageAttrib&>(pLangAttrib->GetAttr()).GetLanguage());
1685 0 : pTextEngine->RemoveAttrib(0, *pLangAttrib);
1686 0 : pTextEngine->SetAttrib( aNewLangAttrib, 0, (sal_uInt16)(m_nErrorEnd + nDiffLen) , nTextLen );
1687 : }
1688 : }
1689 : // undo expanded attributes!
1690 0 : if( pBackAttrib && pBackAttrib->GetStart() < m_nErrorStart && pBackAttrib->GetEnd() == m_nErrorEnd + nDiffLen)
1691 : {
1692 0 : TextAttrib* pNewBackground = pBackAttrib->GetAttr().Clone();
1693 0 : sal_uInt16 nStart = pBackAttrib->GetStart();
1694 0 : pTextEngine->RemoveAttrib(0, *pBackAttrib);
1695 0 : pTextEngine->SetAttrib(*pNewBackground, 0, nStart, m_nErrorStart);
1696 0 : delete pNewBackground;
1697 : }
1698 0 : pTextEngine->SetModified(true);
1699 :
1700 : //adjust end position
1701 0 : long nEndTemp = m_nErrorEnd;
1702 0 : nEndTemp += nDiffLen;
1703 0 : m_nErrorEnd = (sal_uInt16)nEndTemp;
1704 :
1705 : SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
1706 0 : SPELLUNDO_MOVE_ERROREND, GetSpellDialog()->aDialogUndoLink);
1707 0 : pAction->SetOffset(nDiffLen);
1708 0 : AddUndoAction(pAction);
1709 0 : if(pSpellErrorDescription)
1710 0 : SetAttrib( SpellErrorAttrib(*pSpellErrorDescription), 0, m_nErrorStart, m_nErrorEnd );
1711 0 : SetAttrib( SpellLanguageAttrib(eLanguage), 0, m_nErrorStart, m_nErrorEnd );
1712 0 : pTextEngine->UndoActionEnd();
1713 0 : }
1714 :
1715 :
1716 0 : OUString SentenceEditWindow_Impl::GetErrorText() const
1717 : {
1718 0 : return GetTextEngine()->GetText(TextSelection(TextPaM(0, m_nErrorStart), TextPaM(0, m_nErrorEnd) ));
1719 : }
1720 :
1721 :
1722 0 : const SpellErrorDescription* SentenceEditWindow_Impl::GetAlternatives()
1723 : {
1724 0 : TextPaM aCursor(0, m_nErrorStart);
1725 : const SpellErrorAttrib* pAttrib = static_cast<const SpellErrorAttrib*>(
1726 0 : GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR));
1727 0 : return pAttrib ? &pAttrib->GetErrorDescription() : 0;
1728 : }
1729 :
1730 :
1731 0 : void SentenceEditWindow_Impl::RestoreCurrentError()
1732 : {
1733 0 : TextPaM aCursor(0, m_nErrorStart);
1734 : const SpellErrorAttrib* pAttrib = static_cast<const SpellErrorAttrib*>(
1735 0 : GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR));
1736 0 : if( pAttrib )
1737 : {
1738 0 : const SpellErrorDescription& rDesc = pAttrib->GetErrorDescription();
1739 0 : if( !rDesc.sErrorText.equals( GetErrorText() ) )
1740 0 : ChangeMarkedWord(rDesc.sErrorText, LanguageTag::convertToLanguageType( rDesc.aLocale ));
1741 : }
1742 0 : }
1743 :
1744 :
1745 0 : void SentenceEditWindow_Impl::SetAlternatives( Reference< XSpellAlternatives> xAlt )
1746 : {
1747 0 : TextPaM aCursor(0, m_nErrorStart);
1748 : DBG_ASSERT(static_cast<const SpellErrorAttrib*>(
1749 : GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR)), "no error set?");
1750 :
1751 0 : OUString aWord;
1752 0 : lang::Locale aLocale;
1753 0 : uno::Sequence< OUString > aAlts;
1754 0 : OUString sServiceName;
1755 0 : if (xAlt.is())
1756 : {
1757 0 : aWord = xAlt->getWord();
1758 0 : aLocale = xAlt->getLocale();
1759 0 : aAlts = xAlt->getAlternatives();
1760 0 : uno::Reference< container::XNamed > xNamed( xAlt, uno::UNO_QUERY );
1761 0 : if (xNamed.is())
1762 0 : sServiceName = xNamed->getName();
1763 : }
1764 0 : SpellErrorDescription aDesc( false, aWord, aLocale, aAlts, 0, sServiceName);
1765 0 : GetTextEngine()->SetAttrib( SpellErrorAttrib(aDesc), 0, m_nErrorStart, m_nErrorEnd );
1766 0 : }
1767 :
1768 :
1769 0 : void SentenceEditWindow_Impl::SetAttrib( const TextAttrib& rAttr, sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd )
1770 : {
1771 0 : GetTextEngine()->SetAttrib(rAttr, nPara, nStart, nEnd);
1772 0 : }
1773 :
1774 :
1775 0 : void SentenceEditWindow_Impl::SetText( const OUString& rStr )
1776 : {
1777 0 : m_nErrorStart = m_nErrorEnd = 0;
1778 0 : GetTextEngine()->SetText(rStr);
1779 0 : }
1780 :
1781 :
1782 : struct LanguagePosition_Impl
1783 : {
1784 : sal_uInt16 nPosition;
1785 : LanguageType eLanguage;
1786 :
1787 0 : LanguagePosition_Impl(sal_uInt16 nPos, LanguageType eLang) :
1788 : nPosition(nPos),
1789 0 : eLanguage(eLang)
1790 0 : {}
1791 : };
1792 : typedef std::vector<LanguagePosition_Impl> LanguagePositions_Impl;
1793 :
1794 0 : static void lcl_InsertBreakPosition_Impl(
1795 : LanguagePositions_Impl& rBreakPositions, sal_uInt16 nInsert, LanguageType eLanguage)
1796 : {
1797 0 : LanguagePositions_Impl::iterator aStart = rBreakPositions.begin();
1798 0 : while(aStart != rBreakPositions.end())
1799 : {
1800 0 : if(aStart->nPosition == nInsert)
1801 : {
1802 : //the language of following starts has to overwrite
1803 : //the one of previous ends
1804 0 : aStart->eLanguage = eLanguage;
1805 0 : return;
1806 : }
1807 0 : else if(aStart->nPosition > nInsert)
1808 : {
1809 :
1810 0 : rBreakPositions.insert(aStart, LanguagePosition_Impl(nInsert, eLanguage));
1811 0 : return;
1812 : }
1813 : else
1814 0 : ++aStart;
1815 : }
1816 0 : rBreakPositions.push_back(LanguagePosition_Impl(nInsert, eLanguage));
1817 : }
1818 : /*-------------------------------------------------------------------------
1819 : Returns the text in spell portions. Each portion contains text with an
1820 : equal language and attribute. The spell alternatives are empty.
1821 : -----------------------------------------------------------------------*/
1822 0 : svx::SpellPortions SentenceEditWindow_Impl::CreateSpellPortions( bool bSetIgnoreFlag ) const
1823 : {
1824 0 : svx::SpellPortions aRet;
1825 0 : ExtTextEngine* pTextEngine = GetTextEngine();
1826 0 : const sal_uInt16 nTextLen = pTextEngine->GetTextLen(0);
1827 0 : if(nTextLen)
1828 : {
1829 0 : TextPaM aCursor(0, 0);
1830 0 : LanguagePositions_Impl aBreakPositions;
1831 0 : const TextCharAttrib* pLastLang = 0;
1832 0 : const TextCharAttrib* pLastError = 0;
1833 0 : LanguageType eLang = LANGUAGE_DONTKNOW;
1834 0 : const TextCharAttrib* pError = 0;
1835 0 : while(aCursor.GetIndex() < nTextLen)
1836 : {
1837 0 : const TextCharAttrib* pLang = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_LANGUAGE);
1838 0 : if(pLang && pLang != pLastLang)
1839 : {
1840 0 : eLang = static_cast<const SpellLanguageAttrib&>(pLang->GetAttr()).GetLanguage();
1841 0 : lcl_InsertBreakPosition_Impl(aBreakPositions, pLang->GetStart(), eLang);
1842 0 : lcl_InsertBreakPosition_Impl(aBreakPositions, pLang->GetEnd(), eLang);
1843 0 : pLastLang = pLang;
1844 : }
1845 0 : pError = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR);
1846 0 : if(pError && pLastError != pError)
1847 : {
1848 0 : lcl_InsertBreakPosition_Impl(aBreakPositions, pError->GetStart(), eLang);
1849 0 : lcl_InsertBreakPosition_Impl(aBreakPositions, pError->GetEnd(), eLang);
1850 0 : pLastError = pError;
1851 :
1852 : }
1853 0 : aCursor.GetIndex()++;
1854 : }
1855 :
1856 0 : if(nTextLen && aBreakPositions.empty())
1857 : {
1858 : //if all content has been overwritten the attributes may have been removed, too
1859 0 : svx::SpellPortion aPortion1;
1860 0 : aPortion1.eLanguage = GetSpellDialog()->GetSelectedLang_Impl();
1861 0 : aPortion1.sText = pTextEngine->GetText(
1862 0 : TextSelection(TextPaM(0, 0), TextPaM(0, nTextLen)));
1863 :
1864 0 : aRet.push_back(aPortion1);
1865 :
1866 : }
1867 0 : else if(!aBreakPositions.empty())
1868 : {
1869 0 : LanguagePositions_Impl::iterator aStart = aBreakPositions.begin();
1870 : //start should always be Null
1871 0 : eLang = aStart->eLanguage;
1872 0 : sal_uInt16 nStart = aStart->nPosition;
1873 : DBG_ASSERT(!nStart, "invalid start position - language attribute missing?");
1874 0 : ++aStart;
1875 :
1876 0 : while(aStart != aBreakPositions.end())
1877 : {
1878 0 : svx::SpellPortion aPortion1;
1879 0 : aPortion1.eLanguage = eLang;
1880 0 : aPortion1.sText = pTextEngine->GetText(
1881 0 : TextSelection(TextPaM(0, nStart), TextPaM(0, aStart->nPosition)));
1882 0 : bool bIsIgnoreError = m_aIgnoreErrorsAt.find( nStart ) != m_aIgnoreErrorsAt.end();
1883 0 : if( bSetIgnoreFlag && bIsIgnoreError )
1884 : {
1885 0 : aPortion1.bIgnoreThisError = true;
1886 : }
1887 0 : aRet.push_back(aPortion1);
1888 0 : nStart = aStart->nPosition;
1889 0 : eLang = aStart->eLanguage;
1890 0 : ++aStart;
1891 0 : }
1892 : }
1893 :
1894 : // quick partly fix of #i71318. Correct fix needs to patch the TextEngine itself...
1895 : // this one will only prevent text from disappearing. It may to not have the
1896 : // correct language and will probably not spell checked...
1897 0 : sal_uLong nPara = pTextEngine->GetParagraphCount();
1898 0 : if (nPara > 1)
1899 : {
1900 0 : OUString aLeftOverText;
1901 0 : for (sal_uLong i = 1; i < nPara; ++i)
1902 : {
1903 0 : aLeftOverText += "\x0a"; // the manual line break...
1904 0 : aLeftOverText += pTextEngine->GetText(i);
1905 : }
1906 0 : if (pError)
1907 : { // we need to add a new portion containing the left-over text
1908 0 : svx::SpellPortion aPortion2;
1909 0 : aPortion2.eLanguage = eLang;
1910 0 : aPortion2.sText = aLeftOverText;
1911 0 : aRet.push_back( aPortion2 );
1912 : }
1913 : else
1914 : { // we just need to append the left-over text to the last portion (which had no errors)
1915 0 : aRet[ aRet.size() - 1 ].sText += aLeftOverText;
1916 0 : }
1917 0 : }
1918 : }
1919 0 : return aRet;
1920 : }
1921 :
1922 :
1923 0 : void SentenceEditWindow_Impl::Undo()
1924 : {
1925 0 : ::svl::IUndoManager& rUndoMgr = GetTextEngine()->GetUndoManager();
1926 : DBG_ASSERT(GetUndoActionCount(), "no undo actions available" );
1927 0 : if(!GetUndoActionCount())
1928 0 : return;
1929 0 : bool bSaveUndoEdit = IsUndoEditMode();
1930 : sal_uInt16 nId;
1931 : //if the undo edit mode is active then undo all changes until the UNDO_EDIT_MODE action has been found
1932 0 : do
1933 : {
1934 0 : nId = rUndoMgr.GetUndoActionId();
1935 0 : rUndoMgr.Undo();
1936 0 : }while(bSaveUndoEdit && SPELLUNDO_UNDO_EDIT_MODE != nId && GetUndoActionCount());
1937 :
1938 0 : if(bSaveUndoEdit || SPELLUNDO_CHANGE_GROUP == nId)
1939 0 : GetSpellDialog()->UpdateBoxes_Impl();
1940 : }
1941 :
1942 :
1943 0 : void SentenceEditWindow_Impl::ResetUndo()
1944 : {
1945 0 : GetTextEngine()->ResetUndo();
1946 0 : }
1947 :
1948 :
1949 0 : void SentenceEditWindow_Impl::AddUndoAction( SfxUndoAction *pAction, sal_Bool bTryMerg )
1950 : {
1951 0 : ::svl::IUndoManager& rUndoMgr = GetTextEngine()->GetUndoManager();
1952 0 : rUndoMgr.AddUndoAction(pAction, bTryMerg);
1953 0 : GetSpellDialog()->m_pUndoPB->Enable();
1954 0 : }
1955 :
1956 :
1957 0 : sal_uInt16 SentenceEditWindow_Impl::GetUndoActionCount()
1958 : {
1959 0 : return GetTextEngine()->GetUndoManager().GetUndoActionCount();
1960 : }
1961 :
1962 :
1963 0 : void SentenceEditWindow_Impl::UndoActionStart( sal_uInt16 nId )
1964 : {
1965 0 : GetTextEngine()->UndoActionStart(nId);
1966 0 : }
1967 :
1968 :
1969 0 : void SentenceEditWindow_Impl::UndoActionEnd()
1970 : {
1971 0 : GetTextEngine()->UndoActionEnd();
1972 0 : }
1973 :
1974 :
1975 0 : void SentenceEditWindow_Impl::MoveErrorEnd(long nOffset)
1976 : {
1977 0 : if(nOffset > 0)
1978 0 : m_nErrorEnd = m_nErrorEnd - (sal_uInt16)nOffset;
1979 : else
1980 0 : m_nErrorEnd = m_nErrorEnd -(sal_uInt16)- nOffset;
1981 0 : }
1982 :
1983 :
1984 0 : void SentenceEditWindow_Impl::SetUndoEditMode(bool bSet)
1985 : {
1986 : DBG_ASSERT(!bSet || m_bIsUndoEditMode != bSet, "SetUndoEditMode with equal values?");
1987 0 : m_bIsUndoEditMode = bSet;
1988 : //disable all buttons except the Change
1989 0 : SpellDialog* pSpellDialog = GetSpellDialog();
1990 : Control* aControls[] =
1991 : {
1992 : pSpellDialog->m_pChangeAllPB,
1993 : pSpellDialog->m_pExplainFT,
1994 : pSpellDialog->m_pIgnoreAllPB,
1995 : pSpellDialog->m_pIgnoreRulePB,
1996 : pSpellDialog->m_pIgnorePB,
1997 : pSpellDialog->m_pSuggestionLB,
1998 : pSpellDialog->m_pSuggestionFT,
1999 : pSpellDialog->m_pLanguageFT,
2000 : pSpellDialog->m_pLanguageLB,
2001 : pSpellDialog->m_pAddToDictMB,
2002 : pSpellDialog->m_pAddToDictPB,
2003 : pSpellDialog->m_pAutoCorrPB,
2004 : 0
2005 0 : };
2006 0 : sal_Int32 nIdx = 0;
2007 0 : do
2008 : {
2009 0 : aControls[nIdx]->Enable(false);
2010 : }
2011 0 : while(aControls[++nIdx]);
2012 :
2013 : //remove error marks
2014 0 : TextEngine* pTextEngine = GetTextEngine();
2015 0 : pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTCOLOR, true );
2016 0 : pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTWEIGHT, true );
2017 :
2018 : //put the appropriate action on the Undo-stack
2019 : SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
2020 0 : SPELLUNDO_UNDO_EDIT_MODE, GetSpellDialog()->aDialogUndoLink);
2021 0 : AddUndoAction(pAction);
2022 0 : pSpellDialog->m_pChangePB->Enable();
2023 0 : }
2024 :
2025 0 : IMPL_LINK( SpellDialog, HandleHyperlink, FixedHyperlink*, pHyperlink )
2026 : {
2027 0 : OUString sURL=pHyperlink->GetURL();
2028 0 : OUString sTitle=GetText();
2029 :
2030 0 : if ( sURL.isEmpty() ) // Nothing to do, when the URL is empty
2031 0 : return 1;
2032 : try
2033 : {
2034 : uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
2035 0 : com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext()) );
2036 0 : xSystemShellExecute->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
2037 : }
2038 0 : catch ( uno::Exception& )
2039 : {
2040 0 : uno::Any exc( ::cppu::getCaughtException() );
2041 0 : OUString msg( ::comphelper::anyToString( exc ) );
2042 0 : const SolarMutexGuard guard;
2043 0 : ErrorBox aErrorBox( NULL, WB_OK, msg );
2044 0 : aErrorBox.SetText( sTitle );
2045 0 : aErrorBox.Execute();
2046 : }
2047 :
2048 0 : return 1;
2049 0 : }
2050 :
2051 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|