xref: /trunk/main/editeng/inc/editeng/svxacorr.hxx (revision 67e470da)
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 
24 #ifndef _MySVXACORR_HXX
25 #define _MySVXACORR_HXX
26 
27 #include <com/sun/star/embed/XStorage.hpp>
28 #include <tools/rtti.hxx>
29 #include <svl/svarray.hxx>
30 #include <i18npool/lang.h>
31 #include <tools/time.hxx>
32 #include <tools/date.hxx>
33 #include <tools/string.hxx>
34 #include <editeng/swafopt.hxx>
35 #include "editeng/editengdllapi.h"
36 
37 class CharClass;
38 class SfxPoolItem;
39 class SvxAutoCorrect;
40 class SvStringsISortDtor;
41 class SfxObjectShell;
42 class SvxAutoCorrLanguageTable_Impl;
43 class SvxAutoCorrLastFileAskTable_Impl;
44 class SotStorageRef;
45 class SotStorage;
46 
47 // Flags fuer die AutoKorrekt-Flags
48 const long CptlSttSntnc		= 0x00000001;	// Gross-Buchstaben am SatzAnfang
49 const long CptlSttWrd		= 0x00000002;	// keine 2 Gr.-Buchst. am WordAnfang
50 const long AddNonBrkSpace   = 0x00000004;	// Add non breaking space before :;?!
51 const long ChgOrdinalNumber = 0x00000008;	// Ordinal-Number 1st, 2nd,..
52 const long ChgToEnEmDash    = 0x00000010;	// - -> Endash/Emdash
53 const long ChgWeightUnderl  = 0x00000020;	// * -> Fett, _ -> unterstreichen
54 const long SetINetAttr      = 0x00000040;	// INetAttribut setzen
55 const long Autocorrect 		= 0x00000080;	// Autokorrektur aufrufen
56 const long ChgQuotes		= 0x00000100;	// doppelte Quotes ersetzen
57 const long SaveWordCplSttLst= 0x00000200;	// GrB. am SatzAnf. auto. aufnehmen
58 const long SaveWordWrdSttLst= 0x00000400;	// 2 GrB. am WortAnf. auto. aufnehmen
59 const long IgnoreDoubleSpace= 0x00000800;	// 2 Spaces ignorieren
60 const long ChgSglQuotes		= 0x00001000;	// einfache Quotes ersetzen
61 
62 const long ChgWordLstLoad	= 0x20000000;	// Ersetzungsliste geladen
63 const long CplSttLstLoad	= 0x40000000;	// Exceptionlist fuer CplStart geladen
64 const long WrdSttLstLoad	= 0x80000000;	// Exceptionlist fuer WordStart geladen
65 
66 // TODO: handle unicodes > U+FFFF and check users of this class
67 
68 // nur eine Mappingklasse
69 class EDITENG_DLLPUBLIC SvxAutoCorrDoc
70 {
71 public:
SvxAutoCorrDoc()72 	SvxAutoCorrDoc() {}
73 	virtual ~SvxAutoCorrDoc();
74 
75 	virtual sal_Bool Delete( xub_StrLen nStt, xub_StrLen nEnd ) = 0;
76 	virtual sal_Bool Insert( xub_StrLen nPos, const String& rTxt ) = 0;
77 	virtual sal_Bool Replace( xub_StrLen nPos, const String& rTxt ) = 0;
78     virtual sal_Bool ReplaceRange( xub_StrLen nPos, xub_StrLen nLen, const String& rTxt ) = 0;
79 
80 	virtual sal_Bool SetAttr( xub_StrLen nStt, xub_StrLen nEnd, sal_uInt16 nSlotId,
81 							SfxPoolItem& ) = 0;
82 
83 	virtual sal_Bool SetINetAttr( xub_StrLen nStt, xub_StrLen nEnd, const String& rURL ) = 0;
84 
85 	// returne den Text eines vorherigen Absatzes.
86 	// Dieser darf nicht leer sein!
87 	// Gibt es diesen nicht oder gibt es davor nur Leere, dann returne 0
88 	// Das Flag gibt an:
89 	//		sal_True: den, vor der normalen Einfuegeposition (sal_True)
90 	// 		sal_False: den, in den das korrigierte Wort eingfuegt wurde.
91 	//				(Muss nicht der gleiche Absatz sein!!!!)
92 	virtual const String* GetPrevPara( sal_Bool bAtNormalPos ) = 0;
93 
94 	virtual sal_Bool ChgAutoCorrWord( xub_StrLen& rSttPos, xub_StrLen nEndPos,
95 								  SvxAutoCorrect& rACorrect,
96 								  const String** ppPara ) = 0;
97 	// wird nach dem austauschen der Zeichen von den Funktionen
98 	//	- FnCptlSttWrd
99 	// 	- FnCptlSttSntnc
100 	// gerufen. Dann koennen die Worte ggfs. in die Ausnahmelisten
101 	// aufgenommen werden.
102 	virtual void SaveCpltSttWord( sal_uLong nFlag, xub_StrLen nPos,
103 									const String& rExceptWord,
104 									sal_Unicode cChar );
105 
106 	// welche Sprache gilt an der Position?
107 	virtual LanguageType GetLanguage( xub_StrLen nPos, sal_Bool bPrevPara = sal_False ) const;
108 };
109 
110 
111 class EDITENG_DLLPUBLIC SvxAutocorrWord
112 {
113 	String sShort, sLong;
114 	sal_Bool bIsTxtOnly;				// ist reiner ASCII - Text
115 public:
SvxAutocorrWord(const String & rS,const String & rL,sal_Bool bFlag=sal_True)116 	SvxAutocorrWord( const String& rS, const String& rL, sal_Bool bFlag = sal_True )
117 		: sShort( rS ), sLong( rL ), bIsTxtOnly( bFlag )
118 	{}
119 
GetShort() const120 	const String& GetShort() const					{ return sShort; }
GetLong() const121 	const String& GetLong() const					{ return sLong; }
IsTextOnly() const122 	sal_Bool IsTextOnly() const							{ return bIsTxtOnly; }
123 };
124 
125 typedef SvxAutocorrWord* SvxAutocorrWordPtr;
126 SV_DECL_PTRARR_SORT_DEL_VISIBILITY( SvxAutocorrWordList, SvxAutocorrWordPtr, 10, 10 , EDITENG_DLLPUBLIC)
127 
128 class EDITENG_DLLPUBLIC SvxAutoCorrectLanguageLists
129 {
130 	String sShareAutoCorrFile, sUserAutoCorrFile;
131 	// falls die AutoCorr Datei neuer ist
132 	Date aModifiedDate;
133 	Time aModifiedTime, aLastCheckTime;
134 
135 	LanguageType 			eLanguage; //LANGUAGE_DONTKNOW fuer alle Sprachen verwenden
136 	SvStringsISortDtor* 	pCplStt_ExcptLst;
137 	SvStringsISortDtor* 	pWrdStt_ExcptLst;
138 	SvxAutocorrWordList* 	pAutocorr_List;
139 	SvxAutoCorrect&			rAutoCorrect;
140 
141 	long nFlags;
142 
143 	sal_Bool IsFileChanged_Imp();
144 	void LoadXMLExceptList_Imp( SvStringsISortDtor*& rpLst,
145 								const sal_Char* pStrmName,
146                                 SotStorageRef& rStg);
147 	void SaveExceptList_Imp( const SvStringsISortDtor& rLst,
148 								const sal_Char* pStrmName,
149                                 SotStorageRef& rStg,
150 								sal_Bool bConvert = sal_False);
151 
152     sal_Bool MakeBlocklist_Imp( SotStorage& rStg );
153 	void RemoveStream_Imp( const String& rName );
154 	void MakeUserStorage_Impl();
155 
156 public:
157 	SvxAutoCorrectLanguageLists( SvxAutoCorrect& rParent,
158 			const String& rShareAutoCorrectFile,
159 			const String& rUserAutoCorrectFile,
160 			LanguageType eLang);
161 	~SvxAutoCorrectLanguageLists();
162 
163 	// Lade, Setze, Gebe - die Ersetzungsliste
164 	SvxAutocorrWordList* LoadAutocorrWordList();
165 	void SetAutocorrWordList( SvxAutocorrWordList* pList );
166 	const SvxAutocorrWordList* GetAutocorrWordList();
167 
168 	// Lade, Setze, Gebe - die Ausnahmeliste fuer Grossbuchstabe am
169 	// Satzanfang
170 	SvStringsISortDtor* LoadCplSttExceptList();
171 	void SaveCplSttExceptList();
172 	void SetCplSttExceptList( SvStringsISortDtor* pList );
173     SvStringsISortDtor* GetCplSttExceptList();
174 	sal_Bool AddToCplSttExceptList(const String& rNew);
175 
176 	// Lade, Setze, Gebe die Ausnahmeliste fuer 2 Grossbuchstaben am
177 	// Wortanfang
178 	SvStringsISortDtor* LoadWrdSttExceptList();
179 	void SaveWrdSttExceptList();
180 	void SetWrdSttExceptList( SvStringsISortDtor* pList );
181     SvStringsISortDtor* GetWrdSttExceptList();
182 	sal_Bool AddToWrdSttExceptList(const String& rNew);
183 
184 	// Speichern von Wortersetzungen:
185 	//		Diese speichern direkt im Storage. Die Wortliste wird
186 	//		entsprechend aktualisiert!
187 	//	- purer Text
188 	sal_Bool PutText( const String& rShort, const String& rLong );
189 	//	- Text mit Attributierung (kann nur der SWG - SWG-Format!)
190 	sal_Bool PutText( const String& rShort, SfxObjectShell& );
191 	//	- loesche einen Eintrag
192 	sal_Bool DeleteText( const String& rShort );
193 };
194 
195 
196 class EDITENG_DLLPUBLIC SvxAutoCorrect
197 {
198 	friend class SvxAutoCorrectLanguageLists;
199 
200 	String sShareAutoCorrFile, sUserAutoCorrFile;
201 
202 	SvxSwAutoFmtFlags aSwFlags;		// StarWriter AutoFormat-Flags
203 
204 	// alle Sprachen in einer Tabelle
205 	SvxAutoCorrLanguageTable_Impl* pLangTable;
206 	SvxAutoCorrLastFileAskTable_Impl* pLastFileTable;
207 	CharClass* pCharClass;
208 
209     bool bRunNext;
210 
211 	LanguageType eCharClassLang;
212 
213 	long nFlags;
214 	sal_Unicode cStartDQuote, cEndDQuote, cStartSQuote, cEndSQuote,
215 				cEmDash, cEnDash;
216 
217 
218 	// private methods
219 	SvxAutoCorrectLanguageLists& _GetLanguageList( LanguageType eLang );
220 
221 	void _GetCharClass( LanguageType eLang );
222 
223 protected:
224 	//	- Text mit Attributierung (kann nur der SWG - SWG-Format!)
225 	//		rShort ist der Stream-Name - gecryptet!
226     virtual sal_Bool PutText( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rStg, const String& rFileName, const String& rShort, SfxObjectShell& ,
227 							String& );
228 
229 	// geforderte Sprache in die Tabelle eintragen gfs. nur wenn das file existiert
230 	sal_Bool 	CreateLanguageFile(LanguageType eLang, sal_Bool bNewFile = sal_True);
231 	//	- return den Ersetzungstext (nur fuer SWG-Format, alle anderen
232 	//		koennen aus der Wortliste herausgeholt werden!)
233 	//		rShort ist der Stream-Name - gecryptet!
234 public:
235 	//The method below is changed from private to public by BerryJia for Bug95846 Time:2002-8-13 15:50
236 	sal_Unicode GetQuote( sal_Unicode cInsChar, sal_Bool bSttQuote,
237 							LanguageType eLang ) const;
238     virtual sal_Bool GetLongText( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rStg, const String& rFileName, const String& rShort, String& rLong );
239 
240 	TYPEINFO();
241 
242 	SvxAutoCorrect( const String& rShareAutocorrFile,
243 					const String& rUserAutocorrFile );
244 	SvxAutoCorrect( const SvxAutoCorrect& );
245 	virtual ~SvxAutoCorrect();
246 
247 	// fuehre eine AutoKorrektur aus.
248 	// returnt was ausgefuehrt wurde; entsprechend den obigen Flags
249 	sal_uLong AutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt,
250 						xub_StrLen nPos, sal_Unicode cInsChar, sal_Bool bInsert );
251 
252 	// return fuer die Autotext Expandierung das vorherige Wort, was dem
253 	// AutoCorrect - Algorythmus entspricht.
254 	sal_Bool GetPrevAutoCorrWord( SvxAutoCorrDoc& rDoc, const String& rTxt,
255 								xub_StrLen nPos, String& rWord ) const;
256 
257 	// suche das oder die Worte in der ErsetzungsTabelle.
258 	// rText - ueberpruefe in diesem Text die Worte der Liste
259 	// rStt - die gefundene Startposition
260 	// nEnd - zu ueberpruefende Position - ab dieser Pos nach vorne
261 	// rLang - Input: in welcher Sprache wird gesucht
262 	//			Output: in welcher "Sprach-Liste" wurde es gefunden
263 	const SvxAutocorrWord* SearchWordsInList( const String& rTxt,
264 									xub_StrLen& rStt, xub_StrLen nEndPos,
265 									SvxAutoCorrDoc& rDoc,
266 									LanguageType& rLang );
267 
268 	// erfrage / setze die Zeichen fuer die Quote-Ersetzung
GetStartSingleQuote() const269 	sal_Unicode GetStartSingleQuote() const 		{ return cStartSQuote; }
GetEndSingleQuote() const270 	sal_Unicode GetEndSingleQuote() const			{ return cEndSQuote; }
GetStartDoubleQuote() const271 	sal_Unicode GetStartDoubleQuote() const 		{ return cStartDQuote; }
GetEndDoubleQuote() const272 	sal_Unicode GetEndDoubleQuote() const			{ return cEndDQuote; }
273 
SetStartSingleQuote(const sal_Unicode cStart)274 	void SetStartSingleQuote( const sal_Unicode cStart ) 	{ cStartSQuote = cStart; }
SetEndSingleQuote(const sal_Unicode cEnd)275 	void SetEndSingleQuote( const sal_Unicode cEnd ) 		{ cEndSQuote = cEnd; }
SetStartDoubleQuote(const sal_Unicode cStart)276 	void SetStartDoubleQuote( const sal_Unicode cStart ) 	{ cStartDQuote = cStart; }
SetEndDoubleQuote(const sal_Unicode cEnd)277 	void SetEndDoubleQuote( const sal_Unicode cEnd ) 		{ cEndDQuote = cEnd; }
278 
279 	String GetQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos,
280 					sal_Unicode cInsChar, sal_Bool bSttQuote );
281 	void InsertQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos,
282 					sal_Unicode cInsChar, sal_Bool bSttQuote, sal_Bool bIns );
283 
284 	// erfrage / setze den Namen der AutoKorrektur-Datei
285 	// defaultet auf "autocorr.dat"
286 	String GetAutoCorrFileName( LanguageType eLang = LANGUAGE_SYSTEM,
287 								sal_Bool bNewFile = sal_False,
288 								sal_Bool bTstUserExist = sal_False ) const;
289 	void SetUserAutoCorrFileName( const String& rNew );
290 	void SetShareAutoCorrFileName( const String& rNew );
291 
292 	// erfrage / setze die aktuellen Einstellungen der AutoKorrektur
GetFlags() const293 	long GetFlags() const						{ return nFlags; }
GetSwFlags()294 	inline SvxSwAutoFmtFlags&	GetSwFlags()	{ return aSwFlags;}
IsAutoCorrFlag(long nFlag) const295 	sal_Bool IsAutoCorrFlag( long nFlag ) const
296 								{ return nFlags & nFlag ? sal_True : sal_False; }
297 	void SetAutoCorrFlag( long nFlag, sal_Bool bOn = sal_True );
298 
299 	// Lade, Setze, Gebe - die Ersetzungsliste
LoadAutocorrWordList(LanguageType eLang=LANGUAGE_SYSTEM)300 	SvxAutocorrWordList* LoadAutocorrWordList(
301 									LanguageType eLang = LANGUAGE_SYSTEM )
302 		{ return _GetLanguageList( eLang ).LoadAutocorrWordList(); }
GetAutocorrWordList(LanguageType eLang=LANGUAGE_SYSTEM)303 	const SvxAutocorrWordList* GetAutocorrWordList(
304 									LanguageType eLang = LANGUAGE_SYSTEM )
305 		{ return _GetLanguageList( eLang ).GetAutocorrWordList(); }
306 
307 	// Speichern von Wortersetzungen:
308 	//		Diese speichern direkt im Storage. Die Wortliste wird
309 	//		entsprechend aktualisiert!
310 	//	- purer Text
311 	sal_Bool PutText( const String& rShort, const String& rLong, LanguageType eLang = LANGUAGE_SYSTEM );
312 	//	- Text mit Attributierung (kann nur der SWG - SWG-Format!)
PutText(const String & rShort,SfxObjectShell & rShell,LanguageType eLang=LANGUAGE_SYSTEM)313 	sal_Bool PutText( const String& rShort, SfxObjectShell& rShell,
314 				 LanguageType eLang = LANGUAGE_SYSTEM )
315 		{ return _GetLanguageList( eLang ).PutText(rShort, rShell ); }
316 
317 	//	- loesche einen Eintrag
318 	sal_Bool DeleteText( const String& rShort, LanguageType eLang = LANGUAGE_SYSTEM);
319 
320 	// Lade, Setze, Gebe - die Ausnahmeliste fuer Grossbuchstabe am
321 	// Satzanfang
322 	void SaveCplSttExceptList( LanguageType eLang = LANGUAGE_SYSTEM );
LoadCplSttExceptList(LanguageType eLang=LANGUAGE_SYSTEM)323 	SvStringsISortDtor* LoadCplSttExceptList(
324 									LanguageType eLang = LANGUAGE_SYSTEM)
325 		{	return _GetLanguageList( eLang ).LoadCplSttExceptList(); }
GetCplSttExceptList(LanguageType eLang=LANGUAGE_SYSTEM)326 	const SvStringsISortDtor* GetCplSttExceptList(
327 									LanguageType eLang = LANGUAGE_SYSTEM )
328 		{	return _GetLanguageList( eLang ).GetCplSttExceptList(); }
329 
330 	// fuegt ein einzelnes Wort hinzu. Die Liste wird sofort
331 	// in die Datei geschrieben!
332 	sal_Bool AddCplSttException( const String& rNew,
333 								LanguageType eLang = LANGUAGE_SYSTEM );
334 
335 	// Lade, Setze, Gebe die Ausnahmeliste fuer 2 Grossbuchstaben am
336 	// Wortanfang
337 	void SaveWrdSttExceptList( LanguageType eLang = LANGUAGE_SYSTEM );
LoadWrdSttExceptList(LanguageType eLang=LANGUAGE_SYSTEM)338 	SvStringsISortDtor* LoadWrdSttExceptList(
339 									LanguageType eLang = LANGUAGE_SYSTEM )
340 		{	return _GetLanguageList( eLang ).LoadWrdSttExceptList(); }
GetWrdSttExceptList(LanguageType eLang=LANGUAGE_SYSTEM)341 	const SvStringsISortDtor* GetWrdSttExceptList(
342 									LanguageType eLang = LANGUAGE_SYSTEM )
343 		{	return _GetLanguageList( eLang ).GetWrdSttExceptList(); }
344 	// fuegt ein einzelnes Wort hinzu. Die Liste wird sofort
345 	// in die Datei geschrieben!
346 	sal_Bool AddWrtSttException( const String& rNew, LanguageType eLang = LANGUAGE_SYSTEM);
347 
348 	//ueber die Sprachen nach dem Eintrag suchen
349 	sal_Bool FindInWrdSttExceptList( LanguageType eLang, const String& sWord );
350 	sal_Bool FindInCplSttExceptList( LanguageType eLang, const String& sWord,
351 									sal_Bool bAbbreviation = sal_False);
352 
353 	// die einzelnen Methoden fuer die Autokorrektur
354 	sal_Bool FnCptlSttWrd( SvxAutoCorrDoc&, const String&,
355 								xub_StrLen nSttPos, xub_StrLen nEndPos,
356 								LanguageType eLang = LANGUAGE_SYSTEM );
357 	sal_Bool FnChgOrdinalNumber( SvxAutoCorrDoc&, const String&,
358 								xub_StrLen nSttPos, xub_StrLen nEndPos,
359 								LanguageType eLang = LANGUAGE_SYSTEM );
360 	sal_Bool FnChgToEnEmDash( SvxAutoCorrDoc&, const String&,
361 								xub_StrLen nSttPos, xub_StrLen nEndPos,
362 								LanguageType eLang = LANGUAGE_SYSTEM );
363     sal_Bool FnAddNonBrkSpace( SvxAutoCorrDoc&, const String&,
364                                 xub_StrLen nSttPos, xub_StrLen nEndPos,
365                                 LanguageType eLang = LANGUAGE_SYSTEM );
366 	sal_Bool FnSetINetAttr( SvxAutoCorrDoc&, const String&,
367 								xub_StrLen nSttPos, xub_StrLen nEndPos,
368 								LanguageType eLang = LANGUAGE_SYSTEM );
369 	sal_Bool FnChgWeightUnderl( SvxAutoCorrDoc&, const String&,
370 								xub_StrLen nSttPos, xub_StrLen nEndPos,
371 								LanguageType eLang = LANGUAGE_SYSTEM );
372 	sal_Bool FnCptlSttSntnc( SvxAutoCorrDoc&, const String&, sal_Bool bNormalPos,
373 								xub_StrLen nSttPos, xub_StrLen nEndPos,
374 								LanguageType eLang  = LANGUAGE_SYSTEM);
375 
HasRunNext()376     bool                HasRunNext() { return bRunNext; }
377 
378 	static long			GetDefaultFlags();
379 
380 // returns sal_True for charcters where the function
381 // 'SvxAutoCorrect::AutoCorrect' should be called.
382 // (used to avoid occasional 'collisions' with (Thai) input-sequence-checking)
383 	static sal_Bool		IsAutoCorrectChar( sal_Unicode cChar );
384 
385     sal_Bool NeedsHardspaceAutocorr( sal_Unicode cChar );
386 
GetCharClass(LanguageType eLang)387 	CharClass& GetCharClass( LanguageType eLang )
388 	{
389 		if( !pCharClass || eLang != eCharClassLang )
390 			_GetCharClass( eLang );
391 		return *pCharClass;
392 	}
393 };
394 
395 #endif
396 
397