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