lib

KoAutoFormat.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 2001 Sven Leiber <s.leiber@web.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef koautoformat_h
22#define koautoformat_h
23
24#include <tqstring.h>
25#include <tqmap.h>
26#include <tqvaluelist.h>
27#include <tqstringlist.h>
28#include <tqptrvector.h>
29#include <tqdom.h>
30#include <tqdict.h>
31#include <tqlabel.h>
32#include <tqwidget.h>
33#include <koffice_export.h>
34
35class KoDocument;
36class KoTextParag;
37class KoTextObject;
38class KoVariableCollection;
40class TDECompletion;
41class KoTextCursor;
42class KCommand;
43class KoSearchContext;
44class KoTextFormat;
45
46
47
48
49class KoCompletionBox : public TQLabel
50{
51 TQ_OBJECT
52
53 public:
54 KoCompletionBox( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 );
55 ~KoCompletionBox();
56 TQString& lastWord();
57 void setLastWord(TQString const &);
58
59 protected:
60 void mousePressEvent( TQMouseEvent * );
61
62 private:
63 TQString m_lastWord;
64};
65
66
67
68/******************************************************************/
69/* Class: KWAutoFormatEntry */
70/******************************************************************/
71class KoAutoFormatEntry
72{
73public:
74 // The text to find is actually the key in KWAutoFormat's map.
75 // What we replace it with is replace().
76 KoAutoFormatEntry(const TQString& replace = TQString());
77 ~KoAutoFormatEntry();
78 TQString replace() const { return m_replace; }
79 void changeReplace(const TQString & rep){ m_replace = rep; }
80
81 KoSearchContext *formatEntryContext()const;
82 void createNewEntryContext();
83 void setFormatEntryContext( KoSearchContext * );
84 void clearFormatEntryContext( );
85
86protected:
87 TQString m_replace;
88 // For formatting in the replacement - not implemented yet
89 KoSearchContext *m_formatOptions;
90};
91
92typedef TQMap< TQString, KoAutoFormatEntry > KoAutoFormatEntryMap;
93
94/******************************************************************/
95/* Class: KoAutoFormat */
96/******************************************************************/
97class KOTEXT_EXPORT KoAutoFormat
98{
99public:
104 KoAutoFormat( KoDocument *_doc, KoVariableCollection *_varCollection, KoVariableFormatCollection *_varFormatCollection );
105
107 KoAutoFormat( const KoAutoFormat& format );
108
109 ~KoAutoFormat();
110
111 enum KeyCompletionAction { Enter = 0, Tab = 1, Space = 2, End = 3, Right = 4};
112
113 KCommand *applyAutoFormat( KoTextObject * obj );
118 void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, TQChar ch,KoTextObject *txtObj );
119
123 bool doCompletion( KoTextCursor* textEditCursor, KoTextParag *parag, int const index,KoTextObject *txtObj );
124
125 bool doToolTipCompletion( KoTextCursor* textEditCursor, KoTextParag *parag, int index,KoTextObject *txtObj,int keyPress );
126 void showToolTipBox(KoTextParag *parag, int index, TQWidget *widget, const TQPoint &pos);
127 void removeToolTipCompletion();
128
129 bool doIgnoreDoubleSpace( KoTextParag *parag, int index,TQChar ch );
130
134 static TQString getLastWord( KoTextParag *parag, int const index );
135 TQString getLastWord( const int max_words, KoTextParag *parag, int const index );
136
142 static TQString getWordAfterSpace( KoTextParag * parag, int const index);
143
144 // Config for the typographic quotes. Used by the dialog.
145 struct TypographicQuotes
146 {
147 TQChar begin, end;
148 bool replace; // aka enabled
149 };
150
151 // Configuration (on/off/settings). Called by the dialog.
152 void configTypographicDoubleQuotes( TypographicQuotes _tq );
153 void configTypographicSimpleQuotes( TypographicQuotes _tq );
154
155 void configUpperCase( bool _uc );
156 void configUpperUpper( bool _uu );
157 void configAdvancedAutocorrect( bool _aa );
158 void configAutoDetectUrl(bool _au);
159 void configIgnoreDoubleSpace( bool _ids);
160 void configRemoveSpaceBeginEndLine( bool _space);
161 void configUseBulletStyle( bool _ubs);
162
163 void configBulletStyle( TQChar b );
164
165 void configAutoChangeFormat( bool b);
166
167 void configAutoReplaceNumber( bool b );
168
169 void configAutoNumberStyle( bool b );
170
171 void configCompletion( bool b );
172
173 void configToolTipCompletion( bool b );
174
175 void configAppendSpace( bool b);
176
177 void configMinWordLength( uint val );
178
179 void configNbMaxCompletionWord( uint val );
180
181 void configAddCompletionWord( bool b );
182
183 void configIncludeTwoUpperUpperLetterException( bool b);
184
185 void configIncludeAbbreviation( bool b );
186
187 void configAutoSuperScript( bool b );
188
189 void configCorrectionWithFormat( bool b);
190
191 void configCapitalizeNameOfDays( bool b);
192
193 void configAutoFormatLanguage( const TQString &_lang);
194
195 void configKeyCompletionAction( KeyCompletionAction action );
196
197 TypographicQuotes getConfigTypographicSimpleQuotes() const
198 { return m_typographicSimpleQuotes; }
199
200 TypographicQuotes getConfigTypographicDoubleQuotes() const
201 { return m_typographicDoubleQuotes; }
202
203 TypographicQuotes getDefaultTypographicDoubleQuotes() const
204 { return m_typographicDefaultDoubleQuotes; }
205
206 TypographicQuotes getDefaultTypographicSimpleQuotes() const
207 { return m_typographicDefaultSimpleQuotes; }
208
209 bool getConfigUpperCase() const
210 { return m_convertUpperCase; }
211 bool getConfigUpperUpper() const
212 { return m_convertUpperUpper; }
213 bool getConfigAdvancedAutoCorrect() const
214 { return m_advancedAutoCorrect;}
215 bool getConfigAutoDetectUrl() const
216 { return m_autoDetectUrl;}
217
218 bool getConfigIgnoreDoubleSpace() const
219 { return m_ignoreDoubleSpace;}
220
221 bool getConfigRemoveSpaceBeginEndLine() const
222 { return m_removeSpaceBeginEndLine;}
223
224 bool getConfigUseBulletSyle() const
225 { return m_useBulletStyle;}
226
227 TQChar getConfigBulletStyle() const
228 { return m_bulletStyle; }
229
230 bool getConfigAutoChangeFormat() const
231 { return m_autoChangeFormat;}
232
233 bool getConfigAutoReplaceNumber() const
234 { return m_autoReplaceNumber; }
235
236 bool getConfigAutoNumberStyle() const
237 { return m_useAutoNumberStyle; }
238
239 bool getConfigCompletion() const
240 { return m_completion; }
241
242 bool getConfigToolTipCompletion() const
243 { return m_toolTipCompletion; }
244
245 bool getConfigAppendSpace() const
246 { return m_completionAppendSpace; }
247
248 uint getConfigMinWordLength() const
249 { return m_minCompletionWordLength; }
250
251 uint getConfigNbMaxCompletionWord() const
252 { return m_nbMaxCompletionWord; }
253
254 bool getConfigAddCompletionWord() const
255 { return m_addCompletionWord; }
256
257 bool getConfigIncludeTwoUpperUpperLetterException() const
258 { return m_includeTwoUpperLetterException; }
259
260 bool getConfigIncludeAbbreviation() const
261 { return m_includeAbbreviation; }
262
263 bool getConfigAutoSuperScript( ) const
264 { return m_bAutoSuperScript; }
265
266 bool getConfigCorrectionWithFormat() const
267 { return m_bAutoCorrectionWithFormat; }
268
269 bool getConfigCapitalizeNameOfDays() const
270 { return m_bCapitalizeNameOfDays; }
271
272 TQString getConfigAutoFormatLanguage( )const
273 { return m_autoFormatLanguage;}
274
275 KeyCompletionAction getConfigKeyAction() const
276 { return m_keyCompletionAction;}
277
278 const TQDict<KoAutoFormatEntry> & getAutoFormatEntries() const{
279 return m_entries;
280 }
281
282 KoAutoFormatEntry * findFormatEntry(const TQString & text) {
283 return m_entries[text];
284 }
285
286 // Add/remove entries, called by the dialog
287 void addAutoFormatEntry( const TQString &key, KoAutoFormatEntry *entry ) {
288 m_entries.insert( key, entry );
289 buildMaxLen();
290 }
291
292 void addAutoFormatEntry( const TQString &key, const TQString &replace );
293
294
295 void removeAutoFormatEntry( const TQString &key ) {
296 m_entries.setAutoDelete(true);
297 m_entries.remove( key );
298 m_entries.setAutoDelete(false);
299 buildMaxLen();
300 }
301
302 // Copy all autoformat entries from another KWAutoFormat. Called by the dialog
303 void copyAutoFormatEntries( const KoAutoFormat & other )
304 { m_entries = other.m_entries; }
305
306 void copyListException( const TQStringList & _list)
307 { m_upperCaseExceptions=_list;}
308
309 void copyListTwoUpperCaseException( const TQStringList &_list)
310 { m_twoUpperLetterException=_list; }
311
312 TQStringList listException() const {return m_upperCaseExceptions;}
313
314 TQStringList listTwoUpperLetterException() const {return m_twoUpperLetterException;}
315
316 TQStringList listCompletion() const;
317
318 TDECompletion *getCompletion() const { return m_listCompletion; }
319
320 int nbSuperScriptEntry() const
321 { return m_superScriptEntries.count(); }
322
323 // Read/save config ( into kwordrc )
324 void readConfig(bool force = false);
325 void saveConfig();
326
327 static bool isUpper( const TQChar &c );
328 static bool isLower( const TQChar &c );
329 static bool isMark( const TQChar &c ); // End of sentence
330 static bool isSeparator( const TQChar &c );
331
332 void updateMaxWords();
333protected:
334 //return a ref to index otherwise when we uperCase, index is bad !
335 KCommand *doAutoCorrect( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, KoTextObject *txtObj );
336 KCommand *doUpperCase( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const TQString & word , KoTextObject *txtObj );
337 KCommand * doTypographicQuotes( KoTextCursor* textEditCursor, KoTextParag *parag, int index, KoTextObject *txtObj, bool doubleQuotes );
338 void buildMaxLen();
339
340 void doAutoDetectUrl( KoTextCursor *textEditCursor, KoTextParag *parag, int & index, TQString & word, KoTextObject *txtObj );
341 KCommand *doRemoveSpaceBeginEndLine( KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj, int& index );
342 KCommand *doAutoChangeFormat( KoTextCursor *textEditCursor, KoTextParag *parag, int index, const TQString & word, KoTextObject *txtObj );
343 KCommand *doUseBulletStyle(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj, int& index );
344
345 KCommand *doAutoReplaceNumber( KoTextCursor* textEditCursor, KoTextParag *parag, int & index, const TQString & word , KoTextObject *txtObj );
346
347 KCommand *doUseNumberStyle(KoTextCursor * /*textEditCursor*/, KoTextParag *parag, KoTextObject *txtObj, int& index );
348
349 void doAutoIncludeUpperUpper(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj );
350 void doAutoIncludeAbbreviation(KoTextCursor *textEditCursor, KoTextParag *parag, KoTextObject *txtObj );
351
352 KCommand *doAutoSuperScript( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const TQString & word , KoTextObject *txtObj );
353
354 KCommand *doCapitalizeNameOfDays( KoTextCursor* textEditCursor, KoTextParag *parag, int index, const TQString & word , KoTextObject *txtObj );
355
356 static void changeTextFormat(KoSearchContext *formatOptions, KoTextFormat * format, int & flags );
357 void loadEntry( const TQDomElement &nl, bool _allLanguages = false);
358 TQDomElement saveEntry( TQDictIterator<KoAutoFormatEntry> _entry, TQDomDocument doc);
359private:
360 void detectStartOfLink(KoTextParag * parag, int const index, bool const insertedDot);
361 void autoFormatIsActive();
362 void loadListOfWordCompletion();
363 void loadAutoCorrection( const TQDomElement & _de, bool _allLanguages = false );
364 void loadAllLanguagesAutoCorrection();
365 KCommand *autoFormatWord( KoTextCursor* textEditCursor, KoTextParag *parag, int &index, KoTextObject *txtObj, TQString * _wordArray, bool _allLanguages );
366 void readAutoCorrectConfig();
367
368 KoDocument *m_doc;
369 KoVariableCollection *m_varCollection;
370 KoVariableFormatCollection *m_varFormatCollection;
371
372 TQString m_autoFormatLanguage;
373 bool m_configRead;
374 bool m_convertUpperCase, m_convertUpperUpper,m_advancedAutoCorrect;
375 bool m_autoDetectUrl, m_ignoreDoubleSpace, m_removeSpaceBeginEndLine;
376 bool m_useBulletStyle, m_autoChangeFormat, m_autoReplaceNumber;
377 bool m_useAutoNumberStyle;
378 bool m_completion;
379 bool m_toolTipCompletion;
380 bool m_completionAppendSpace;
381 bool m_addCompletionWord;
382 bool m_includeTwoUpperLetterException;
383 bool m_includeAbbreviation;
384 bool m_ignoreUpperCase;
385 bool m_bAutoFormatActive;
386
387 bool m_bAutoSuperScript;
388 bool m_bAutoCorrectionWithFormat;
389 bool m_bCapitalizeNameOfDays;
391 bool m_wordInserted;
392 TQChar m_bulletStyle;
393
394 TypographicQuotes m_typographicSimpleQuotes;
395
396 TypographicQuotes m_typographicDoubleQuotes;
397
398 TypographicQuotes m_typographicDefaultDoubleQuotes;
399
400 TypographicQuotes m_typographicDefaultSimpleQuotes;
401
402 TDECompletion *m_listCompletion;
403
404 TQDict<KoAutoFormatEntry> m_entries;
405 TQDict<KoAutoFormatEntry> m_allLanguages;
406
407 KoAutoFormatEntryMap m_superScriptEntries;
408
409 TQStringList m_upperCaseExceptions;
410 TQStringList m_twoUpperLetterException;
411
412 uint m_maxFindLength;
413 uint m_minCompletionWordLength;
414 uint m_nbMaxCompletionWord;
415 uint m_countMaxWords;
416 TQStringList m_cacheNameOfDays;
417 KoCompletionBox *m_completionBox;
418 KeyCompletionAction m_keyCompletionAction;
419};
420
421#endif
The KOffice document class.
Definition KoDocument.h:61
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
The KoTextObject is the high-level object that contains a KoTextDocument (the list of paragraphs),...
The collection of formats for variables.
Definition KoVariable.h:263
TDEAction * replace(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)