xref: /aoo41x/main/cui/source/inc/SpellDialog.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _SVX_SPELLDDIALOG_HXX
28 #define _SVX_SPELLDDIALOG_HXX
29 
30 // include ---------------------------------------------------------------
31 
32 #include <sfx2/basedlgs.hxx>
33 #include <vcl/fixed.hxx>
34 #include <vcl/edit.hxx>
35 #include <vcl/lstbox.hxx>
36 #include <svtools/stdctrl.hxx>
37 #include <vcl/button.hxx>
38 #include <vcl/menubtn.hxx>
39 #include <vcl/group.hxx>
40 #include <vcl/decoview.hxx>
41 #include <vcl/image.hxx>
42 #include <com/sun/star/uno/Reference.hxx>
43 
44 
45 #include <svtools/svxbox.hxx>
46 #include <svx/langbox.hxx>
47 #include <memory>
48 #include <svtools/svmedit.hxx>
49 #include <svl/lstner.hxx>
50 #include <svtools/xtextedt.hxx>
51 #include <editeng/SpellPortions.hxx>
52 
53 #include <set>
54 
55 class ScrollBar;
56 class TextEngine;
57 class ExtTextView;
58 namespace svx{ class SpellUndoAction_Impl;}
59 
60 // forward ---------------------------------------------------------------
61 
62 struct SpellDialog_Impl;
63 
64 namespace com{namespace sun{namespace star{
65 namespace linguistic2{
66     class XSpellChecker1;
67 }}}}
68 namespace svx{
69 class SpellDialog;
70 struct SpellErrorDescription;
71 // ------------------------------------------------------------------
72 class SentenceEditWindow_Impl : public MultiLineEdit/*, public SfxListener*/
73 {
74 	using MultiLineEdit::SetText;
75 
76 private:
77     std::set< sal_uInt16 >      m_aIgnoreErrorsAt;
78     sal_uInt16          m_nErrorStart;
79     sal_uInt16          m_nErrorEnd;
80     bool            m_bIsUndoEditMode;
81 
82     Link            m_aModifyLink;
83 
84     void            CallModifyLink() {m_aModifyLink.Call(this);}
85 
86     SpellDialog*    GetSpellDialog() const {return (SpellDialog*)GetParent();}
87 protected:
88     virtual long    PreNotify( NotifyEvent& rNEvt );
89 
90 public:
91                     SentenceEditWindow_Impl( SpellDialog* pParent, const ResId& rResId );
92                     ~SentenceEditWindow_Impl();
93 
94     void            SetModifyHdl(const Link& rLink) { m_aModifyLink = rLink;}
95 
96     void            SetAttrib( const TextAttrib& rAttr, sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd );
97     void            SetText( const String& rStr );
98 
99     bool            MarkNextError( bool bIgnoreCurrentError );
100     void            ChangeMarkedWord(const String& rNewWord, LanguageType eLanguage);
101     void            MoveErrorMarkTo(sal_uInt16 nErrorStart, sal_uInt16 nErrorEnd, bool bGrammar);
102     String          GetErrorText() const;
103     void            RestoreCurrentError();
104 
105     void            SetAlternatives(
106                         com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellAlternatives> );
107 
108     const SpellErrorDescription* GetAlternatives();
109 
110 
111     void            ResetModified()   { GetTextEngine()->SetModified(sal_False); m_bIsUndoEditMode = false;}
112     sal_Bool            IsModified() const              { return GetTextEngine()->IsModified(); }
113 
114     bool            IsUndoEditMode() const { return m_bIsUndoEditMode;}
115     void            SetUndoEditMode(bool bSet);
116 
117     svx::SpellPortions  CreateSpellPortions( bool bSetIgnoreFlag ) const;
118 
119     void            ResetUndo();
120     void            Undo();
121     void            AddUndoAction( SfxUndoAction *pAction, sal_Bool bTryMerg=sal_False );
122     sal_uInt16      GetUndoActionCount();
123     void            UndoActionStart( sal_uInt16 nId );
124     void            UndoActionEnd();
125 
126     void            MoveErrorEnd(long nOffset);
127 
128     void            ResetIgnoreErrorsAt()   { m_aIgnoreErrorsAt.clear(); }
129 };
130 
131 
132 // class SvxSpellDialog ---------------------------------------------
133 class SpellDialogChildWindow;
134 class ExplainButton : public PushButton
135 {
136     String              m_sExplanation;
137 
138     virtual void        RequestHelp( const HelpEvent& rHEvt );
139     virtual void        Click();
140 public:
141     ExplainButton( Window* pParent, const ResId& rResId ) : PushButton( pParent, rResId ){}
142     ~ExplainButton();
143     void                SetExplanation( const String& rText ) {m_sExplanation = rText;}
144     bool                HasExplanation() { return m_sExplanation.Len() > 0;}
145 
146 };
147 
148 class SpellDialog : public SfxModelessDialog
149 {
150 	using Window::Invalidate;
151 
152 	friend class SentenceEditWindow_Impl;
153 private:
154 
155     FixedImage      aVendorImageFI;
156 
157     FixedText       aLanguageFT;
158     SvxLanguageBox  aLanguageLB;
159 
160     FixedText           aNotInDictFT;
161     SentenceEditWindow_Impl  aSentenceED;
162 
163     FixedText       aSuggestionFT;
164     ListBox         aSuggestionLB;
165 
166     PushButton      aIgnorePB;
167     PushButton      aIgnoreAllPB;
168     PushButton      aIgnoreRulePB;
169     MenuButton      aAddToDictMB;
170 
171     PushButton      aChangePB;
172     PushButton      aChangeAllPB;
173     ExplainButton   aExplainPB;
174     PushButton      aAutoCorrPB;
175 
176     CheckBox        aCheckGrammarCB;
177 
178     HelpButton      aHelpPB;
179     PushButton      aOptionsPB;
180     PushButton      aUndoPB;
181     PushButton      aClosePB;
182 
183     GroupBox        aBackgroundGB;
184 
185     Image           aVendorImage;
186     Image           aVendorImageHC;
187 
188     String          aResumeST;
189     String          aIgnoreOnceST;
190     String          aNoSuggestionsST;
191 
192     const String    m_sTitleSpelling;
193     const String    m_sTitleSpellingGrammar;
194     const String    m_sTitleSpellingGrammarVendor;
195 
196     Size            aOldWordEDSize;
197     Link            aDialogUndoLink;
198 
199     bool            bModified;
200     bool            bFocusLocked;
201 
202     svx::SpellDialogChildWindow& rParent;
203     svx::SpellPortions           m_aSavedSentence;
204 
205     SpellDialog_Impl* pImpl;
206 	::com::sun::star::uno::Reference<
207 		::com::sun::star::linguistic2::XSpellChecker1 > 	xSpell;
208 	LanguageType		nOldLang;
209 
210     DECL_LINK( ChangeHdl, Button * );
211     DECL_LINK( ChangeAllHdl, Button * );
212     DECL_LINK( IgnoreAllHdl, Button * );
213     DECL_LINK( IgnoreHdl, Button * );
214     DECL_LINK( CheckGrammarHdl, CheckBox* );
215 	DECL_LINK( ExtClickHdl, Button * );
216 	DECL_LINK( CancelHdl, Button * );
217     DECL_LINK( ModifyHdl, SentenceEditWindow_Impl *);
218     DECL_LINK( UndoHdl, Button * );
219     DECL_LINK( AddToDictionaryHdl, MenuButton* );
220     DECL_LINK( LanguageSelectHdl, SvxLanguageBox* );
221     DECL_LINK( DialogUndoHdl, SpellUndoAction_Impl* );
222 
223     DECL_STATIC_LINK( SpellDialog, InitHdl, SpellDialog * );
224 
225 	void            StartSpellOptDlg_Impl();
226 	void            InitUserDicts();
227 	void            UpdateBoxes_Impl();
228 	void            Init_Impl();
229     void            SpellContinue_Impl(bool UseSavedSentence = false, bool bIgnoreCurrentError = false );
230     void            LockFocusChanges( bool bLock ) {bFocusLocked = bLock;}
231     void            Impl_Restore();
232 
233 	void			SetSelectedLang_Impl( LanguageType nLang );
234 	LanguageType	GetSelectedLang_Impl() const;
235 
236     /** Retrieves the next sentence.
237      */
238     bool            GetNextSentence_Impl(bool bUseSavedSentence, bool bRechek /*for rechecking the curretn sentence*/);
239     /** Corrects all errors that have been selected to be changed always
240      */
241     bool            ApplyChangeAllList_Impl(SpellPortions& rSentence, bool& bHasReplaced);
242     void            SetTitle_Impl(LanguageType nLang);
243 
244 protected:
245     virtual void    Paint( const Rectangle& rRect );
246     virtual long    Notify( NotifyEvent& rNEvt );
247 
248 public:
249     SpellDialog(
250         svx::SpellDialogChildWindow* pChildWindow,
251         Window * pParent,
252         SfxBindings* pBindings);
253     ~SpellDialog();
254 
255 	void			SetLanguage( sal_uInt16 nLang );
256 	virtual sal_Bool	Close();
257 
258     void            InvalidateDialog();
259 };
260 } //namespace svx
261 
262 #endif
263 
264