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