xref: /trunk/main/editeng/inc/editeng/splwrap.hxx (revision cc8deb09502b0533680c9dd4ece4278d7699cf65)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SVX_SPLWRAP_HXX
24 #define _SVX_SPLWRAP_HXX
25 
26 // include ---------------------------------------------------------------
27 
28 #include <editeng/svxenum.hxx>
29 #include <tools/string.hxx>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include "editeng/editengdllapi.h"
32 
33 // forward ---------------------------------------------------------------
34 
35 namespace com { namespace sun { namespace star { namespace linguistic2 {
36     class XDictionary;
37     class XSpellChecker1;
38     class XHyphenator;
39 }}}}
40 
41 class Window;
42 
43 // misc functions ---------------------------------------------------------------
44 
45 void EDITENG_DLLPUBLIC SvxPrepareAutoCorrect( String &rOldText, String &rNewText );
46 
47 /*--------------------------------------------------------------------
48      Beschreibung: Der SpellWrapper
49  --------------------------------------------------------------------*/
50 
51 class EDITENG_DLLPUBLIC SvxSpellWrapper {
52 private:
53     friend class SvxSpellCheckDialog;
54     friend class SvxHyphenWordDialog;
55     friend class SvxHyphenWordDialog_Impl;
56 
57     Window*     pWin;
58     ::com::sun::star::uno::Reference<
59         ::com::sun::star::uno::XInterface >             xLast;  // result of last spelling/hyphenation attempt
60     ::com::sun::star::uno::Reference<
61         ::com::sun::star::linguistic2::XSpellChecker1 > xSpell;
62     ::com::sun::star::uno::Reference<
63         ::com::sun::star::linguistic2::XHyphenator >    xHyph;
64     sal_uInt16  nOldLang;       // Sprache merken, nur bei Aenderung SetLanguage rufen
65     sal_Bool    bOtherCntnt : 1; // gesetzt => Sonderbereiche zunaechst pruefen
66     sal_Bool    bDialog     : 1; // Ist pWin der Svx...Dialog?
67     sal_Bool    bHyphen     : 1; // Trennen statt Spellen
68     sal_Bool    bAuto       : 1; // Autokorrektur vorhanden?
69     sal_Bool    bReverse    : 1; // Rueckwaerts Spellen
70     sal_Bool    bStartDone  : 1; // Vorderen Teil bereits korrigiert
71     sal_Bool    bEndDone    : 1; // Hinteren Teil bereits korrigiert
72     sal_Bool    bStartChk   : 1; // Vorderen Teil pruefen
73     sal_Bool    bRevAllowed : 1; // Niemals rueckwaerts spellen
74     sal_Bool    bAllRight   : 1; // falsche Woerter in geignetes Woerterbuch
75                              // aufnehmen und nicht den Dialog starten.
76 
77     EDITENG_DLLPRIVATE sal_Bool     SpellNext();        // naechsten Bereich anwaehlen
78     sal_Bool    FindSpellError();   // Suche nach Fehlern ( ueber Bereiche hinweg )
79 
80 public:
81     SvxSpellWrapper( Window* pWn,
82                      ::com::sun::star::uno::Reference<
83                         ::com::sun::star::linguistic2::XSpellChecker1 >  &xSpellChecker,
84                      const sal_Bool bStart = sal_False, const sal_Bool bIsAllRight = sal_False,
85                      const sal_Bool bOther = sal_False, const sal_Bool bRevAllow = sal_True );
86     SvxSpellWrapper( Window* pWn,
87                      ::com::sun::star::uno::Reference<
88                         ::com::sun::star::linguistic2::XHyphenator >  &xHyphenator,
89                      const sal_Bool bStart = sal_False, const sal_Bool bOther = sal_False );
90 
91     virtual ~SvxSpellWrapper();
92 
93     static sal_Int16    CheckSpellLang(
94                             ::com::sun::star::uno::Reference<
95                                 ::com::sun::star::linguistic2::XSpellChecker1 >  xSpell,
96                             sal_Int16 nLang );
97     static sal_Int16    CheckHyphLang(
98                             ::com::sun::star::uno::Reference<
99                                 ::com::sun::star::linguistic2::XHyphenator >  xHyph,
100                             sal_Int16 nLang );
101 
102     static void         ShowLanguageErrors();
103 
104     void            SpellDocument();        // Rechtschreibpruefung durchfuehren
105     inline sal_Bool IsStartDone(){ return bStartDone; }
106     inline sal_Bool IsEndDone(){ return bEndDone; }
107     inline sal_Bool IsReverse(){ return bReverse; }
108     inline sal_Bool IsDialog(){ return bDialog; } // SvxSpellCheckDialog OnScreen
109     inline sal_Bool IsHyphen(){ return bHyphen; } // Trennen statt Spellen
110     inline void     SetHyphen( const sal_Bool bNew = sal_True ){ bHyphen = bNew; }
111     inline ::com::sun::star::uno::Reference<
112         ::com::sun::star::linguistic2::XSpellChecker1 >
113                     GetXSpellChecker() { return xSpell; }
114     inline ::com::sun::star::uno::Reference<
115         ::com::sun::star::linguistic2::XHyphenator >
116                     GetXHyphenator()    { return xHyph; }
117     inline sal_Bool             IsAllRight()        { return bAllRight; }
118     inline Window*  GetWin() { return pWin; }
119     // kann evtl entfallen in ONE_LINGU:
120     inline void     SetOldLang( const sal_uInt16 nNew ){ nOldLang = nNew; }
121     // kann evtl entfallen in ONE_LINGU:
122     inline void     ChangeLanguage( const sal_uInt16 nNew ) // rufe ggf. SetLanguage
123         { if ( nNew != nOldLang ) { SetLanguage( nNew ); nOldLang = nNew; } }
124     inline void     EnableAutoCorrect() { bAuto = sal_True; }
125 
126 protected:
127     ::com::sun::star::uno::Reference<
128         ::com::sun::star::uno::XInterface >
129                      GetLast()      { return xLast; }
130     void             SetLast(const ::com::sun::star::uno::Reference<
131                                 ::com::sun::star::uno::XInterface >  &xNewLast)
132                             { xLast = xNewLast; }
133     virtual sal_Bool SpellMore();               // weitere Dokumente pruefen?
134     virtual sal_Bool HasOtherCnt();             // gibt es ueberhaupt Sonderbereiche
135     virtual void     SpellStart( SvxSpellArea eSpell ); // Bereich vorbereiten
136     virtual sal_Bool SpellContinue();           // Bereich pruefen
137                                             // Ergebnis mit GetLast verfuegbar
138     virtual void ReplaceAll( const String &rNewText, sal_Int16 nLanguage ); // Wort aus Replace-Liste ersetzen
139     virtual void StartThesaurus( const String &rWord, sal_uInt16 nLang );   // Thesaurus starten
140     virtual ::com::sun::star::uno::Reference<
141         ::com::sun::star::linguistic2::XDictionary >
142                  GetAllRightDic() const;
143     virtual void SpellEnd();                        // Bereich abschliessen
144     virtual void ScrollArea();                      // ScrollArea einstellen
145     // Wort ersetzen
146     virtual void ChangeWord( const String& rNewWord, const sal_uInt16 nLang );
147     virtual String GetThesWord();
148     // Wort via Thesaurus ersetzen
149     virtual void ChangeThesWord( const String& rNewWord );
150     virtual void SetLanguage( const sal_uInt16 nLang ); // Sprache aendern
151     virtual void AutoCorrect( const String& rAktStr, const String& rNewStr );
152     virtual void InsertHyphen( const sal_uInt16 nPos ); // Hyphen einfuegen
153 
154 };
155 
156 #endif
157