author | jowenn <jowenn> | 2002-11-10 21:08:01 (UTC) |
---|---|---|
committer | jowenn <jowenn> | 2002-11-10 21:08:01 (UTC) |
commit | e97a6da57804aa14907dec327fbae71bff9b383e (patch) (unidiff) | |
tree | 15f6ee292dba24bdda72f5c72f6d2224c3516763 /noncore/apps/tinykate/libkate/document/katehighlight.h | |
parent | 7c012ee8cd16d8befacc6f6750711443fac0fd5e (diff) | |
download | opie-e97a6da57804aa14907dec327fbae71bff9b383e.zip opie-e97a6da57804aa14907dec327fbae71bff9b383e.tar.gz opie-e97a6da57804aa14907dec327fbae71bff9b383e.tar.bz2 |
import of tiny kate. (saving not possible yet)
Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katehighlight.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katehighlight.h | 349 |
1 files changed, 349 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.h b/noncore/apps/tinykate/libkate/document/katehighlight.h new file mode 100644 index 0000000..1baddcc --- a/dev/null +++ b/noncore/apps/tinykate/libkate/document/katehighlight.h | |||
@@ -0,0 +1,349 @@ | |||
1 | /* | ||
2 | Copyright (C) 1998, 1999 Jochen Wilhelmy | ||
3 | digisnap@cs.tu-berlin.de | ||
4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> | ||
5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> | ||
6 | |||
7 | This library is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU Library General Public | ||
9 | License as published by the Free Software Foundation; either | ||
10 | version 2 of the License, or (at your option) any later version. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Library General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Library General Public License | ||
18 | along with this library; see the file COPYING.LIB. If not, write to | ||
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
20 | Boston, MA 02111-1307, USA. | ||
21 | */ | ||
22 | |||
23 | #ifndef _HIGHLIGHT_H_ | ||
24 | #define _HIGHLIGHT_H_ | ||
25 | |||
26 | #include <qlist.h> | ||
27 | #include <qdialog.h> | ||
28 | |||
29 | #include <kcolorbtn.h> | ||
30 | #include <qstrvec.h> | ||
31 | #include <qdict.h> | ||
32 | #include <qregexp.h> | ||
33 | #include "../qt3back/qregexp3.h" | ||
34 | #include <kdebug.h> | ||
35 | |||
36 | class SyntaxDocument; | ||
37 | struct syntaxModeListItem; | ||
38 | struct syntaxContextData; | ||
39 | |||
40 | class QCheckBox; | ||
41 | class QComboBox; | ||
42 | class QLineEdit; | ||
43 | |||
44 | class TextLine; | ||
45 | class Attribute; | ||
46 | |||
47 | class HlItem { | ||
48 | public: | ||
49 | HlItem(int attribute, int context); | ||
50 | virtual ~HlItem(); | ||
51 | virtual bool startEnable(QChar); | ||
52 | virtual const QChar *checkHgl(const QChar *, int len, bool) = 0; | ||
53 | QList<HlItem> *subItems; | ||
54 | int attr; | ||
55 | int ctx; | ||
56 | }; | ||
57 | |||
58 | class HlCharDetect : public HlItem { | ||
59 | public: | ||
60 | HlCharDetect(int attribute, int context, QChar); | ||
61 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
62 | protected: | ||
63 | QChar sChar; | ||
64 | }; | ||
65 | |||
66 | class Hl2CharDetect : public HlItem { | ||
67 | public: | ||
68 | Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2); | ||
69 | Hl2CharDetect(int attribute, int context, const QChar *ch); | ||
70 | |||
71 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
72 | protected: | ||
73 | QChar sChar1; | ||
74 | QChar sChar2; | ||
75 | }; | ||
76 | |||
77 | class HlStringDetect : public HlItem { | ||
78 | public: | ||
79 | HlStringDetect(int attribute, int context, const QString &, bool inSensitive=false); | ||
80 | virtual ~HlStringDetect(); | ||
81 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
82 | protected: | ||
83 | const QString str; | ||
84 | bool _inSensitive; | ||
85 | }; | ||
86 | |||
87 | class HlRangeDetect : public HlItem { | ||
88 | public: | ||
89 | HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2); | ||
90 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
91 | protected: | ||
92 | QChar sChar1; | ||
93 | QChar sChar2; | ||
94 | }; | ||
95 | |||
96 | class HlKeyword : public HlItem | ||
97 | { | ||
98 | public: | ||
99 | HlKeyword(int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen); | ||
100 | virtual ~HlKeyword(); | ||
101 | |||
102 | virtual void addWord(const QString &); | ||
103 | virtual void addList(const QStringList &); | ||
104 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
105 | QStringList getList() { return words;}; | ||
106 | virtual bool startEnable(QChar c); | ||
107 | |||
108 | protected: | ||
109 | QStringList words; | ||
110 | QDict<bool> dict; | ||
111 | bool _caseSensitive; | ||
112 | const QChar *deliminatorChars; | ||
113 | uint deliminatorLen; | ||
114 | }; | ||
115 | |||
116 | class HlPHex : public HlItem { | ||
117 | public: | ||
118 | HlPHex(int attribute,int context); | ||
119 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
120 | }; | ||
121 | class HlInt : public HlItem { | ||
122 | public: | ||
123 | HlInt(int attribute, int context); | ||
124 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
125 | }; | ||
126 | |||
127 | class HlFloat : public HlItem { | ||
128 | public: | ||
129 | HlFloat(int attribute, int context); | ||
130 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
131 | }; | ||
132 | |||
133 | class HlCInt : public HlInt { | ||
134 | public: | ||
135 | HlCInt(int attribute, int context); | ||
136 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
137 | }; | ||
138 | |||
139 | class HlCOct : public HlItem { | ||
140 | public: | ||
141 | HlCOct(int attribute, int context); | ||
142 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
143 | }; | ||
144 | |||
145 | class HlCHex : public HlItem { | ||
146 | public: | ||
147 | HlCHex(int attribute, int context); | ||
148 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
149 | }; | ||
150 | |||
151 | class HlCFloat : public HlFloat { | ||
152 | public: | ||
153 | HlCFloat(int attribute, int context); | ||
154 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
155 | }; | ||
156 | |||
157 | class HlLineContinue : public HlItem { | ||
158 | public: | ||
159 | HlLineContinue(int attribute, int context); | ||
160 | virtual bool endEnable(QChar c) {return c == '\0';} | ||
161 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
162 | }; | ||
163 | |||
164 | class HlCStringChar : public HlItem { | ||
165 | public: | ||
166 | HlCStringChar(int attribute, int context); | ||
167 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
168 | }; | ||
169 | |||
170 | class HlCChar : public HlItem { | ||
171 | public: | ||
172 | HlCChar(int attribute, int context); | ||
173 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
174 | }; | ||
175 | |||
176 | class HlAnyChar : public HlItem { | ||
177 | public: | ||
178 | HlAnyChar(int attribute, int context, const QChar* charList, uint len); | ||
179 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
180 | const QChar* _charList; | ||
181 | uint _charListLen; | ||
182 | }; | ||
183 | |||
184 | class HlRegExpr : public HlItem { | ||
185 | public: | ||
186 | HlRegExpr(int attribute, int context,QString expr); | ||
187 | ~HlRegExpr(){delete Expr;}; | ||
188 | virtual const QChar *checkHgl(const QChar *, int len, bool); | ||
189 | QRegExp3 *Expr; | ||
190 | bool handlesLinestart; | ||
191 | }; | ||
192 | |||
193 | //-------- | ||
194 | |||
195 | |||
196 | //Item Style: color, selected color, bold, italic | ||
197 | class ItemStyle { | ||
198 | public: | ||
199 | ItemStyle(); | ||
200 | // ItemStyle(const ItemStyle &); | ||
201 | ItemStyle(const QColor &, const QColor &, bool bold, bool italic); | ||
202 | ItemStyle(ItemStyle *its){col=its->col;selCol=its->selCol; bold=its->bold; italic=its->italic;} | ||
203 | // void setData(const ItemStyle &); | ||
204 | QColor col; | ||
205 | QColor selCol; | ||
206 | int bold; //boolean value | ||
207 | int italic; //boolean value | ||
208 | }; | ||
209 | |||
210 | typedef QList<ItemStyle> ItemStyleList; | ||
211 | |||
212 | //Item Properties: name, Item Style, Item Font | ||
213 | class ItemData : public ItemStyle { | ||
214 | public: | ||
215 | ItemData(const QString name, int defStyleNum); | ||
216 | ItemData(const QString name, int defStyleNum, | ||
217 | const QColor&, const QColor&, bool bold, bool italic); | ||
218 | ItemData(ItemData | ||
219 | *itd):ItemStyle((ItemStyle*)itd),name(itd->name),defStyleNum(itd->defStyleNum),defStyle(itd->defStyle){;} | ||
220 | const QString name; | ||
221 | int defStyleNum; | ||
222 | int defStyle; //boolean value | ||
223 | }; | ||
224 | |||
225 | typedef QList<ItemData> ItemDataList; | ||
226 | |||
227 | class HlData { | ||
228 | public: | ||
229 | HlData(const QString &wildcards, const QString &mimetypes,const QString &identifier); | ||
230 | ItemDataList itemDataList; | ||
231 | QString wildcards; | ||
232 | QString mimetypes; | ||
233 | QString identifier; | ||
234 | }; | ||
235 | |||
236 | typedef QList<HlData> HlDataList; | ||
237 | |||
238 | class HlManager; | ||
239 | class KConfig; | ||
240 | |||
241 | //context | ||
242 | class HlContext { | ||
243 | public: | ||
244 | HlContext(int attribute, int lineEndContext,int _lineBeginContext); | ||
245 | QList<HlItem> items; | ||
246 | int attr; | ||
247 | int ctx; | ||
248 | int lineBeginContext; | ||
249 | }; | ||
250 | |||
251 | class Highlight | ||
252 | { | ||
253 | friend class HlManager; | ||
254 | |||
255 | public: | ||
256 | Highlight(syntaxModeListItem *def); | ||
257 | ~Highlight(); | ||
258 | |||
259 | int doHighlight(int ctxNum, TextLine *); | ||
260 | |||
261 | KConfig *getKConfig(); | ||
262 | QString getWildcards(); | ||
263 | QString getMimetypes(); | ||
264 | HlData *getData(); | ||
265 | void setData(HlData *); | ||
266 | void getItemDataList(ItemDataList &); | ||
267 | void getItemDataList(ItemDataList &, KConfig *); | ||
268 | void setItemDataList(ItemDataList &, KConfig *); | ||
269 | QString name() {return iName;} | ||
270 | QString section() {return iSection;} | ||
271 | void use(); | ||
272 | void release(); | ||
273 | bool isInWord(QChar c); | ||
274 | |||
275 | QString getCommentStart() {return cmlStart;}; | ||
276 | QString getCommentEnd() {return cmlEnd;}; | ||
277 | QString getCommentSingleLineStart() { return cslStart;}; | ||
278 | |||
279 | protected: | ||
280 | void init(); | ||
281 | void done(); | ||
282 | void makeContextList (); | ||
283 | void createItemData (ItemDataList &list); | ||
284 | void readGlobalKeywordConfig(); | ||
285 | void readCommentConfig(); | ||
286 | HlItem *createHlItem(struct syntaxContextData *data, ItemDataList &iDl); | ||
287 | int lookupAttrName(const QString& name, ItemDataList &iDl); | ||
288 | ItemDataList internalIDList; | ||
289 | static const int nContexts = 32; | ||
290 | HlContext *contextList[nContexts]; | ||
291 | |||
292 | bool noHl; | ||
293 | bool casesensitive; | ||
294 | QString weakDeliminator; | ||
295 | QString deliminator; | ||
296 | const QChar *deliminatorChars; | ||
297 | uint deliminatorLen; | ||
298 | QString cmlStart; | ||
299 | QString cmlEnd; | ||
300 | QString cslStart; | ||
301 | QString iName; | ||
302 | QString iSection; | ||
303 | QString iWildcards; | ||
304 | QString iMimetypes; | ||
305 | QString identifier; | ||
306 | int refCount; | ||
307 | }; | ||
308 | |||
309 | class HlManager : public QObject { | ||
310 | Q_OBJECT | ||
311 | public: | ||
312 | HlManager(); | ||
313 | ~HlManager(); | ||
314 | |||
315 | static HlManager *self(); | ||
316 | |||
317 | Highlight *getHl(int n); | ||
318 | int defaultHl(); | ||
319 | int nameFind(const QString &name); | ||
320 | |||
321 | int wildcardFind(const QString &fileName); | ||
322 | int findHl(Highlight *h) {return hlList.find(h);} | ||
323 | |||
324 | int makeAttribs(Highlight *, Attribute *, int maxAttribs); | ||
325 | |||
326 | int defaultStyles(); | ||
327 | QString defaultStyleName(int n); | ||
328 | void getDefaults(ItemStyleList &); | ||
329 | void setDefaults(ItemStyleList &); | ||
330 | |||
331 | int highlights(); | ||
332 | QString hlName(int n); | ||
333 | QString hlSection(int n); | ||
334 | void getHlDataList(HlDataList &); | ||
335 | void setHlDataList(HlDataList &); | ||
336 | |||
337 | SyntaxDocument *syntax; | ||
338 | |||
339 | signals: | ||
340 | void changed(); | ||
341 | protected: | ||
342 | QList<Highlight> hlList; | ||
343 | static HlManager *s_pSelf; | ||
344 | }; | ||
345 | |||
346 | |||
347 | |||
348 | |||
349 | #endif //_HIGHLIGHT_H_ | ||