summaryrefslogtreecommitdiffstats
path: root/qt/qextscintillalexer.cpp
blob: 327206f962b92db6153a34a2675d81eabb7f3c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
// This module implements the QextScintillaLexer class.
//
// Copyright (c) 2006
// 	Riverbank Computing Limited <info@riverbankcomputing.co.uk>
// 
// This file is part of TQScintilla.
// 
// This copy of TQScintilla is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option) any
// later version.
// 
// TQScintilla is supplied in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
// 
// You should have received a copy of the GNU General Public License along with
// TQScintilla; see the file LICENSE.  If not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


#include <tqapplication.h>
#include <tqcolor.h>
#include <tqfont.h>
#include <tqsettings.h>

#include "qextscintillalexer.h"
#include "qextscintilla.h"
#include "qextscintillabase.h"


// The ctor.
QextScintillaLexer::QextScintillaLexer(TQObject *parent,const char *name)
    : TQObject(parent,name), autoIndStyle(-1)
{
#if defined(Q_OS_WIN)
    defFont = TQFont("Verdana",10);
#else
    defFont = TQFont("Bitstream Vera Sans",9);
#endif

    // Set the default fore and background colours.
    TQColorGroup cg = TQApplication::palette().active();
    defColor = cg.text();
    defPaper = cg.base();
}


// The dtor.
QextScintillaLexer::~QextScintillaLexer()
{
}


// Default implementation to return the set of fill up characters that can end
// auto-completion.
const char *QextScintillaLexer::autoCompletionFillups() const
{
    return "(";
}


// Default implementation to return the set of characters that can start
// auto-completion.
const char *QextScintillaLexer::autoCompletionStartCharacters() const
{
    return 0;
}


// Default implementation to return the list of keywords that can start a
// block.
const char *QextScintillaLexer::blockStartKeyword(int *) const
{
    return 0;
}


// Default implementation to return the list of characters that can start a
// block.
const char *QextScintillaLexer::blockStart(int *) const
{
    return 0;
}


// Default implementation to return the list of characters that can end a
// block.
const char *QextScintillaLexer::blockEnd(int *) const
{
    return 0;
}


// Default implementation to return the style used for braces.
int QextScintillaLexer::braceStyle() const
{
    return -1;
}


// Default implementation to return the number of lines to look back when
// auto-indenting.
int QextScintillaLexer::blockLookback() const
{
    return 20;
}


// Default implementation to return the characters that make up a word.
const char *QextScintillaLexer::wordCharacters() const
{
    return 0;
}


// Default implementation to return the style used for whitespace.
int QextScintillaLexer::defaultStyle() const
{
    return 0;
}


// Returns the foreground colour of the text for a style.
TQColor QextScintillaLexer::color(int) const
{
    return defaultColor();
}


// Returns the end-of-line fill for a style.
bool QextScintillaLexer::eolFill(int) const
{
    return FALSE;
}


// Returns the font for a style.
TQFont QextScintillaLexer::font(int) const
{
    return defaultFont();
}


// Returns the set of keywords.
const char *QextScintillaLexer::keywords(int) const
{
    return 0;
}


// Returns the background colour of the text for a style.
TQColor QextScintillaLexer::paper(int) const
{
    return defaultPaper();
}


// Returns the default font for all styles.
TQFont QextScintillaLexer::defaultFont() const
{
    return defFont;
}


// Sets the default font for all styles.
void QextScintillaLexer::setDefaultFont(const TQFont &f)
{
    defFont = f;
}


// Returns the default text colour for all styles.
TQColor QextScintillaLexer::defaultColor() const
{
    return defColor;
}


// Sets the default text colour for all styles.
void QextScintillaLexer::setDefaultColor(const TQColor &c)
{
    defColor = c;
}


// Returns the default paper colour for all styles.
TQColor QextScintillaLexer::defaultPaper() const
{
    return defPaper;
}


// Sets the default paper colour for all styles.
void QextScintillaLexer::setDefaultPaper(const TQColor &c)
{
    defPaper = c;
}


// Read properties from the settings.
bool QextScintillaLexer::readProperties(TQSettings &,const TQString &)
{
    return TRUE;
}


// Refresh all properties.
void QextScintillaLexer::refreshProperties()
{
}


// Write properties to the settings.
bool QextScintillaLexer::writeProperties(TQSettings &,const TQString &) const
{
    return TRUE;
}


// Restore the user settings.
bool QextScintillaLexer::readSettings(TQSettings &qs,const char *prefix)
{
    bool ok, flag, rc = TRUE;
    int num;
    TQString key;

    // Read the styles.
    for (int i = 0; i < 128; ++i)
    {
        // Ignore invalid styles.
        if (description(i).isNull())
            continue;

        key.sprintf("%s/%s/style%d/",prefix,language(),i);

        // Read the foreground colour.
        num = qs.readNumEntry(key + "color",0,&ok);

        if (ok)
            emit colorChanged(TQColor((num >> 16) & 0xff,(num >> 8) & 0xff,num & 0xff),i);
        else
            rc = FALSE;

        // Read the end-of-line fill.
        flag = qs.readBoolEntry(key + "eolfill",0,&ok);

        if (ok)
            emit eolFillChanged(flag,i);
        else
            rc = FALSE;

        // Read the font
        TQStringList fdesc;

        fdesc = qs.readListEntry(key + "font",',',&ok);

        if (ok && fdesc.count() == 5)
        {
            TQFont f;

            f.setFamily(fdesc[0]);
            f.setPointSize(fdesc[1].toInt());
            f.setBold(fdesc[2].toInt());
            f.setItalic(fdesc[3].toInt());
            f.setUnderline(fdesc[4].toInt());

            emit fontChanged(f,i);
        }
        else
            rc = FALSE;

        // Read the background colour.
        num = qs.readNumEntry(key + "paper",0,&ok);

        if (ok)
            emit paperChanged(TQColor((num >> 16) & 0xff,(num >> 8) & 0xff,num & 0xff),i);
        else
            rc = FALSE;
    }

    // Read the properties.
    key.sprintf("%s/%s/properties/",prefix,language());

    if (!readProperties(qs,key))
        rc = FALSE;

    refreshProperties();

    // Read the rest.
    key.sprintf("%s/%s/",prefix,language());

    num = qs.readNumEntry(key + "autoindentstyle",0,&ok);

    if (ok)
        autoIndStyle = num;
    else
        rc = FALSE;

    return rc;
}


// Save the user settings.
bool QextScintillaLexer::writeSettings(TQSettings &qs,const char *prefix) const
{
    bool rc = TRUE;
    TQString key;

    // Write the styles.
    for (int i = 0; i < 128; ++i)
    {
        // Ignore invalid styles.
        if (description(i).isNull())
            continue;

        int num;
        TQColor c;

        key.sprintf("%s/%s/style%d/",prefix,language(),i);

        // Write the foreground colour.
        c = color(i);
        num = (c.red() << 16) | (c.green() << 8) | c.blue();

        if (!qs.writeEntry(key + "color",num))
            rc = FALSE;

        // Write the end-of-line fill.
        if (!qs.writeEntry(key + "eolfill",eolFill(i)))
            rc = FALSE;

        // Write the font
        TQStringList fdesc;
        TQString fmt("%1");
        TQFont f;

        f = font(i);

        fdesc += f.family();
        fdesc += fmt.tqarg(f.pointSize());

        // The casts are for Borland.
        fdesc += fmt.tqarg((int)f.bold());
        fdesc += fmt.tqarg((int)f.italic());
        fdesc += fmt.tqarg((int)f.underline());

        if (!qs.writeEntry(key + "font",fdesc,','))
            rc = FALSE;

        // Write the background colour.
        c = paper(i);
        num = (c.red() << 16) | (c.green() << 8) | c.blue();

        if (!qs.writeEntry(key + "paper",num))
            rc = FALSE;
    }

    // Write the properties.
    key.sprintf("%s/%s/properties/",prefix,language());

    if (!writeProperties(qs,key))
        rc = FALSE;

    // Write the rest.
    key.sprintf("%s/%s/",prefix,language());

    if (!qs.writeEntry(key + "autoindentstyle",autoIndStyle))
        rc = FALSE;

    return rc;
}


// Return the auto-indentation style.
int QextScintillaLexer::autoIndentStyle()
{
    // We can't do this in the ctor because we want the virtuals to work.
    if (autoIndStyle < 0)
        autoIndStyle = (blockStartKeyword() || blockStart() || blockEnd()) ?
                    0 : QextScintilla::AiMaintain;

    return autoIndStyle;
}


// Set the auto-indentation style.
void QextScintillaLexer::setAutoIndentStyle(int autoindentstyle)
{
    autoIndStyle = autoindentstyle;
}


// Set the foreground colour for a style.
void QextScintillaLexer::setColor(const TQColor &c,int style)
{
    if (style >= 0)
        emit colorChanged(c,style);
    else
        for (int i = 0; i < 128; ++i)
            if (!description(i).isNull())
                emit colorChanged(c,i);
}


// Set the end-of-line fill for a style.
void QextScintillaLexer::setEolFill(bool eolfill,int style)
{
    if (style >= 0)
        emit eolFillChanged(eolfill,style);
    else
        for (int i = 0; i < 128; ++i)
            if (!description(i).isNull())
                emit eolFillChanged(eolfill,i);
}


// Set the font for a style.
void QextScintillaLexer::setFont(const TQFont &f,int style)
{
    if (style >= 0)
        emit fontChanged(f,style);
    else
        for (int i = 0; i < 128; ++i)
            if (!description(i).isNull())
                emit fontChanged(f,i);
}


// Set the background colour for a style.
void QextScintillaLexer::setPaper(const TQColor &c,int style)
{
    if (style >= 0)
        emit paperChanged(c,style);
    else
    {
        for (int i = 0; i < 128; ++i)
            if (!description(i).isNull())
                emit paperChanged(c,i);

        emit paperChanged(c,QextScintillaBase::STYLE_DEFAULT);
    }
}