Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
72 andreas 1
/*
262 andreas 2
 * Copyright (C) 2021 to 2023 by Andreas Theofilu <andreas@theosys.at>
72 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#include <fstream>
20
#include <functional>
21
 
22
#include <expat.h>
23
 
24
#include "tsystemdraw.h"
80 andreas 25
#include "tdirectory.h"
72 andreas 26
#include "tresources.h"
27
#include "terror.h"
28
 
29
using std::string;
30
using std::vector;
31
using std::ifstream;
32
 
33
TSystemDraw::XELEMENTS_t TSystemDraw::mActData = TSystemDraw::X_NONE;
34
TSystemDraw::XELEMENTS_t TSystemDraw::mActFamily = TSystemDraw::X_NONE;
35
string TSystemDraw::mActElement;
36
 
37
TSystemDraw::TSystemDraw(const string &path)
38
    : mPath(path)
39
{
40
    DECL_TRACER("TSystemDraw::TSystemDraw(const string &path)");
41
 
42
    if (isValidDir(path))
43
        mValid = true;
44
    else
45
    {
46
        MSG_WARNING("No or invalid path!");
47
        return;
48
    }
49
 
50
    if (isValidDir(path + "/borders"))
115 andreas 51
        mHaveBorders = true;
52
    else
99 andreas 53
    {
54
        MSG_WARNING("Have no system border images");
55
    }
72 andreas 56
 
57
    if (isValidDir(path + "/cursors"))
115 andreas 58
        mHaveCursors = true;
59
    else
99 andreas 60
    {
61
        MSG_WARNING("Have no system cursor images");
62
    }
72 andreas 63
 
64
    if (isValidDir(path + "/fonts"))
115 andreas 65
        mHaveFonts = true;
99 andreas 66
    {
67
        MSG_WARNING("Have no system fonts");
156 andreas 68
        string perms = getPermissions(path);
69
        MSG_PROTOCOL("Looked for system fonts at: " << path << "/fonts -- [" << perms << "]");
99 andreas 70
    }
72 andreas 71
 
72
    if (isValidDir(path + "/images"))
115 andreas 73
        mHaveImages = true;
74
    else
99 andreas 75
    {
76
        MSG_WARNING("Have no system images");
77
    }
72 andreas 78
 
79
    if (isValidDir(path + "/sliders"))
115 andreas 80
        mHaveSliders = true;
81
    else
99 andreas 82
    {
83
        MSG_WARNING("Have no system slider images");
84
    }
72 andreas 85
 
86
    if (isValidFile(path + "/draw.xma"))
87
        loadConfig();
99 andreas 88
    else
89
    {
90
        MSG_WARNING("Have no system configuration file draw.xma!");
91
    }
72 andreas 92
}
93
 
94
TSystemDraw::~TSystemDraw()
95
{
96
    DECL_TRACER("TSystemDraw::~TSystemDraw()");
97
}
98
 
99
bool TSystemDraw::loadConfig()
100
{
101
    DECL_TRACER("TSystemDraw::loadConfig()");
102
 
103
    string buf;
104
    string file = mPath + "/draw.xma";
105
    size_t size = 0;
106
 
107
    // First we read the whole XML file into a buffer
108
    try
109
    {
110
        ifstream stream(file, std::ios::in);
111
 
112
        if (!stream || !stream.is_open())
113
            return false;
114
 
115
        stream.seekg(0, stream.end);    // Find the end of the file
116
        size = stream.tellg();          // Get the position and save it
117
        stream.seekg(0, stream.beg);    // rewind to the beginning of the file
118
 
119
        buf.resize(size, '\0');         // Initialize the buffer with zeros
120
        char *begin = &*buf.begin();    // Assign the plain data buffer
121
        stream.read(begin, size);       // Read the whole file
122
        stream.close();                 // Close the file
123
    }
124
    catch (std::exception& e)
125
    {
126
        MSG_ERROR("File error: " << e.what());
127
        return false;
128
    }
129
 
130
    // Now we parse the file and write the relevant contents into our internal
131
    // variables.
132
    // First we initialialize the parser.
133
    int depth = 0;
134
    int done = 1;   // 1 = Buffer is complete
135
    XML_Parser parser = XML_ParserCreate(NULL);
136
    XML_SetUserData(parser, &depth);
137
    XML_SetElementHandler(parser, &TSystemDraw::startElement, &TSystemDraw::endElement);
138
    XML_SetCharacterDataHandler(parser, &TSystemDraw::CharacterDataHandler);
139
    XML_SetUserData(parser, &mDraw);
140
 
141
    if (XML_Parse(parser, buf.data(), size, done) == XML_STATUS_ERROR)
142
    {
143
        MSG_ERROR(XML_ErrorString(XML_GetErrorCode(parser)) << " at line " << XML_GetCurrentLineNumber(parser));
144
        XML_ParserFree(parser);
145
        return false;
146
    }
147
 
148
    XML_ParserFree(parser);
194 andreas 149
/*
73 andreas 150
    if (TStreamError::checkFilter(HLOG_DEBUG))
151
    {
152
        for (size_t i = 0; i < mDraw.borders.size(); i++)
153
        {
154
            MSG_DEBUG("Border family: " << mDraw.borders.at(i).name);
155
 
156
            for (size_t j = 0; j < mDraw.borders.at(i).member.size(); j++)
157
            {
158
                MSG_DEBUG("       Member: " << mDraw.borders.at(i).member.at(j));
159
                MSG_DEBUG("Border styles:");
160
 
161
                for (size_t x = 0; x < mDraw.borderStyles.size(); x++)
162
                {
163
                    if (mDraw.borderStyles.at(x).name.compare(mDraw.borders.at(i).member.at(j)) == 0)
164
                    {
165
                        MSG_DEBUG("         Name: " << mDraw.borderStyles.at(x).name);
166
                        MSG_DEBUG("          Off: " << mDraw.borderStyles.at(x).off);
167
                        MSG_DEBUG("           On: " << mDraw.borderStyles.at(x).on);
168
                        MSG_DEBUG("         Drag: " << mDraw.borderStyles.at(x).drag);
169
                        MSG_DEBUG("         Drop: " << mDraw.borderStyles.at(x).drop);
170
 
171
                        if (mDraw.borderStyles.at(x).g3Equiv.size() > 0)
172
                        {
173
                            for (size_t y = 0; y < mDraw.borderStyles.at(x).g3Equiv.size(); y++)
174
                                MSG_DEBUG("      g3Equiv: " << mDraw.borderStyles.at(x).g3Equiv.at(y));
175
                        }
176
 
79 andreas 177
                        vector<BORDER_DATA_t>::iterator bdIter;
73 andreas 178
 
79 andreas 179
                        for (bdIter = mDraw.borderData.begin(); bdIter != mDraw.borderData.end(); ++bdIter)
73 andreas 180
                        {
79 andreas 181
                            if (bdIter->name.compare(mDraw.borderStyles.at(x).name) == 0)
182
                            {
183
                                MSG_DEBUG("           Name: " << bdIter->name);
184
                                MSG_DEBUG("       baseFile: " << bdIter->baseFile);
185
                                MSG_DEBUG("     idealWidth: " << bdIter->idealWidth);
186
                                MSG_DEBUG("    idealHeight: " << bdIter->idealHeight);
187
                                break;
188
                            }
73 andreas 189
                        }
190
                    }
191
                }
192
            }
193
        }
99 andreas 194
 
195
        for (size_t i = 0; i < mDraw.sliders.size(); i++)
196
        {
197
            MSG_DEBUG("Slider family: " << mDraw.sliders.at(i).name);
198
 
199
            for (size_t j = 0; j < mDraw.sliders.at(i).member.size(); j++)
200
            {
201
                MSG_DEBUG("       Member: " << mDraw.sliders.at(i).member.at(j));
202
                MSG_DEBUG("Slider styles:");
203
 
204
                for (size_t x = 0; x < mDraw.sliderStyles.size(); x++)
205
                {
206
                    if (mDraw.sliderStyles.at(x).name.compare(mDraw.sliders.at(i).member.at(j)) == 0)
207
                    {
208
                        MSG_DEBUG("         Name: " << mDraw.sliderStyles.at(x).name);
209
                        MSG_DEBUG("     baseFile: " << mDraw.sliderStyles.at(x).baseFile);
210
                        MSG_DEBUG("   multiColor: " << mDraw.sliderStyles.at(x).multiColor);
211
                        MSG_DEBUG("    incRepeat: " << mDraw.sliderStyles.at(x).incRepeat);
212
                        MSG_DEBUG("      minSize: " << mDraw.sliderStyles.at(x).minSize);
213
                        MSG_DEBUG("    fixedSize: " << mDraw.sliderStyles.at(x).fixedSize);
214
                    }
215
                }
216
            }
217
        }
73 andreas 218
    }
194 andreas 219
*/
72 andreas 220
    return true;
221
}
222
 
73 andreas 223
void TSystemDraw::startElement(void *, const XML_Char *name, const XML_Char **)
72 andreas 224
{
225
    mActElement.assign(name);
226
 
227
    if (strCaseCompare(name, "borderData") == 0)
228
        mActData = X_BORDER_DATA;
229
 
79 andreas 230
    if (strCaseCompare(name, "border") == 0)
231
        mActFamily = X_BORDER;
232
 
72 andreas 233
    if (strCaseCompare(name, "borderFamily") == 0)
234
        mActFamily = X_BORDER_FAMILY;
73 andreas 235
 
236
    if (strCaseCompare(name, "borderStyle") == 0)
237
        mActFamily = X_BORDER_STYLE;
238
 
239
    if (strCaseCompare(name, "cursorData") == 0)
240
        mActData = X_CURSOR_DATA;
241
 
242
    if (strCaseCompare(name, "cursorFamily") == 0)
243
        mActFamily = X_CURSOR_FAMILY;
244
 
245
    if (strCaseCompare(name, "cursorStyle") == 0)
246
        mActFamily = X_CURSOR_STYLE;
247
 
248
    if (strCaseCompare(name, "sliderData") == 0)
249
        mActData = X_SLIDER_DATA;
250
 
251
    if (strCaseCompare(name, "sliderFamily") == 0)
252
        mActFamily = X_SLIDER_FAMILY;
253
 
99 andreas 254
    if (strCaseCompare(name, "slider") == 0)
73 andreas 255
        mActFamily = X_SLIDER_STYLE;
256
 
257
    if (strCaseCompare(name, "effectData") == 0)
258
        mActData = X_EFFECT_DATA;
259
 
260
    if (strCaseCompare(name, "effectFamily") == 0)
261
        mActFamily = X_EFFECT_FAMILY;
262
 
263
    if (strCaseCompare(name, "effect") == 0)
264
        mActFamily = X_EFFECT_STYLE;
265
 
266
    if (strCaseCompare(name, "popupEffectData") == 0)
267
        mActData = X_POPUP_EFFECT_DATA;
268
 
269
    if (strCaseCompare(name, "popupEffect") == 0)
270
        mActFamily = X_POPUP_EFFECT;
72 andreas 271
}
272
 
73 andreas 273
void TSystemDraw::endElement(void *, const XML_Char *name)
72 andreas 274
{
275
    if (strCaseCompare(name, "borderData") == 0)
276
        mActData = X_NONE;
277
 
79 andreas 278
    if (strCaseCompare(name, "border") == 0)
279
        mActFamily = X_NONE;
280
 
72 andreas 281
    if (strCaseCompare(name, "borderFamily") == 0)
282
        mActFamily = X_NONE;
73 andreas 283
 
284
    if (strCaseCompare(name, "borderStyle") == 0)
285
        mActFamily = X_NONE;
286
 
287
    if (strCaseCompare(name, "cursorData") == 0)
288
        mActData = X_NONE;
289
 
290
    if (strCaseCompare(name, "cursorFamily") == 0)
291
        mActFamily = X_NONE;
292
 
293
    if (strCaseCompare(name, "cursorStyle") == 0)
294
        mActFamily = X_NONE;
295
 
296
    if (strCaseCompare(name, "sliderData") == 0)
297
        mActData = X_NONE;
298
 
299
    if (strCaseCompare(name, "sliderFamily") == 0)
300
        mActFamily = X_NONE;
301
 
302
    if (strCaseCompare(name, "sliderStyle") == 0)
303
        mActFamily = X_NONE;
304
 
305
    if (strCaseCompare(name, "effectData") == 0)
306
        mActData = X_NONE;
307
 
308
    if (strCaseCompare(name, "effectFamily") == 0)
309
        mActFamily = X_NONE;
310
 
311
    if (strCaseCompare(name, "effect") == 0)
312
        mActFamily = X_NONE;
313
 
314
    if (strCaseCompare(name, "popupEffectData") == 0)
315
        mActData = X_NONE;
316
 
317
    if (strCaseCompare(name, "popupEffect") == 0)
318
        mActFamily = X_NONE;
72 andreas 319
}
320
 
321
void TSystemDraw::CharacterDataHandler(void *userData, const XML_Char *s, int len)
322
{
73 andreas 323
    if (len <= 0 || !userData || !s || mActData == X_NONE || mActFamily == X_NONE)
324
        return;
325
 
79 andreas 326
    DRAW_t *draw = (DRAW_t *)userData;
72 andreas 327
    string content(s, len);
73 andreas 328
    content = trim(content);
72 andreas 329
 
73 andreas 330
    if (content.empty())
331
        return;
72 andreas 332
 
73 andreas 333
    switch(mActData)
334
    {
335
        case X_BORDER_DATA:
336
            switch(mActFamily)
337
            {
338
                case X_BORDER_FAMILY:
339
                    if (mActElement.compare("name") == 0)
340
                    {
341
                        FAMILY_t bf;
342
                        bf.name = content;
343
                        draw->borders.push_back(bf);
344
                    }
345
                    else if (mActElement.compare("member") == 0)
346
                        draw->borders.back().member.push_back(content);
347
                break;
348
 
349
                case X_BORDER_STYLE:
350
                    if (mActElement.compare("name") == 0)
351
                    {
352
                        BORDER_STYLE_t bs;
353
                        bs.name = content;
354
                        draw->borderStyles.push_back(bs);
355
                    }
356
                    else if (mActElement.compare("off") == 0)
357
                        draw->borderStyles.back().off = content;
358
                    else if (mActElement.compare("on") == 0)
359
                        draw->borderStyles.back().on = content;
360
                    else if (mActElement.compare("drag") == 0)
361
                        draw->borderStyles.back().drag = content;
362
                    else if (mActElement.compare("drop") == 0)
363
                        draw->borderStyles.back().drop = content;
364
                    else if (mActElement.compare("g3Equiv") == 0)
79 andreas 365
                        draw->borderStyles.back().g3Equiv.push_back(atoi(content.c_str()));
366
                break;
367
 
368
                case X_BORDER:
369
                    if (mActElement.compare("name") == 0)
73 andreas 370
                    {
79 andreas 371
                        BORDER_DATA_t bd;
118 andreas 372
                        bd.init();
79 andreas 373
                        bd.name = content;
374
                        draw->borderData.push_back(bd);
73 andreas 375
                    }
79 andreas 376
                    else if (mActElement.compare("baseFile") == 0)
377
                        draw->borderData.back().baseFile = content;
378
                    else if (mActElement.compare("multiColor") == 0)
379
                        draw->borderData.back().multiColor = atoi(content.c_str());
380
                    else if (mActElement.compare("fillTop") == 0)
381
                        draw->borderData.back().fillTop = atoi(content.c_str());
382
                    else if (mActElement.compare("fillLeft") == 0)
383
                        draw->borderData.back().fillLeft = atoi(content.c_str());
384
                    else if (mActElement.compare("fillBottom") == 0)
385
                        draw->borderData.back().fillBottom = atoi(content.c_str());
386
                    else if (mActElement.compare("fillRight") == 0)
387
                        draw->borderData.back().fillRight = atoi(content.c_str());
388
                    else if (mActElement.compare("textTop") == 0)
389
                        draw->borderData.back().textTop = atoi(content.c_str());
390
                    else if (mActElement.compare("textLeft") == 0)
391
                        draw->borderData.back().textLeft = atoi(content.c_str());
392
                    else if (mActElement.compare("textBottom") == 0)
393
                        draw->borderData.back().textBottom = atoi(content.c_str());
394
                    else if (mActElement.compare("textRight") == 0)
395
                        draw->borderData.back().textRight = atoi(content.c_str());
396
                    else if (mActElement.compare("idealWidth") == 0)
397
                        draw->borderData.back().idealWidth = atoi(content.c_str());
398
                    else if (mActElement.compare("idealHeight") == 0)
399
                        draw->borderData.back().idealHeight = atoi(content.c_str());
400
                    else if (mActElement.compare("minHeight") == 0)
401
                        draw->borderData.back().minHeight = atoi(content.c_str());
402
                    else if (mActElement.compare("minWidth") == 0)
403
                        draw->borderData.back().minWidth = atoi(content.c_str());
404
                    else if (mActElement.compare("incHeight") == 0)
405
                        draw->borderData.back().incHeight = atoi(content.c_str());
406
                    else if (mActElement.compare("incWidth") == 0)
407
                        draw->borderData.back().incWidth = atoi(content.c_str());
73 andreas 408
                break;
409
 
410
                default:
411
                    MSG_WARNING("Unknown border element \"" << mActElement << "\" with content \"" << content << "\"");
412
            }
413
        break;
414
 
415
        case X_CURSOR_DATA:
416
            switch(mActFamily)
417
            {
418
                case X_CURSOR_FAMILY:
419
                    if (mActElement.compare("name") == 0)
420
                    {
421
                        DRAW_t *draw = (DRAW_t *)userData;
422
                        FAMILY_t cf;
423
                        cf.name = content;
424
                        draw->cursors.push_back(cf);
425
                    }
426
                    else if (mActElement.compare("member") == 0)
427
                    {
428
                        DRAW_t *draw = (DRAW_t *)userData;
429
                        draw->cursors.back().member.push_back(content);
430
                    }
431
                break;
432
 
433
                case X_CURSOR_STYLE:
434
                    if (mActElement.compare("name") == 0)
435
                    {
436
                        DRAW_t *draw = (DRAW_t *)userData;
437
                        CURSOR_STYLE_t cs;
118 andreas 438
                        cs.init();
73 andreas 439
                        cs.name = content;
440
                        draw->cursorStyles.push_back(cs);
441
                    }
442
                    else if (mActElement.compare("baseFile") == 0)
443
                    {
444
                        DRAW_t *draw = (DRAW_t *)userData;
445
                        draw->cursorStyles.back().baseFile = content;
446
                    }
447
                    else if (mActElement.compare("multiColor") == 0)
448
                    {
449
                        DRAW_t *draw = (DRAW_t *)userData;
450
                        draw->cursorStyles.back().multiColor = atoi(content.c_str());
451
                    }
452
                    else if (mActElement.compare("g3Equiv") == 0)
453
                    {
454
                        DRAW_t *draw = (DRAW_t *)userData;
455
                        draw->cursorStyles.back().g3Equiv.push_back(atoi(content.c_str()));
456
                    }
457
                break;
458
 
459
                default:
460
                    MSG_WARNING("Unknown cursor element \"" << mActElement << "\" with content \"" << content << "\"");
461
            }
462
        break;
463
 
464
        case X_SLIDER_DATA:
465
            switch(mActFamily)
466
            {
467
                case X_SLIDER_FAMILY:
468
                    if (mActElement.compare("name") == 0)
469
                    {
470
                        DRAW_t *draw = (DRAW_t *)userData;
471
                        FAMILY_t sf;
472
                        sf.name = content;
473
                        draw->sliders.push_back(sf);
474
                    }
475
                    else if (mActElement.compare("member") == 0)
476
                    {
477
                        DRAW_t *draw = (DRAW_t *)userData;
478
                        draw->sliders.back().member.push_back(content);
479
                    }
480
                break;
481
 
482
                case X_SLIDER_STYLE:
483
                    if (mActElement.compare("name") == 0)
484
                    {
485
                        DRAW_t *draw = (DRAW_t *)userData;
486
                        SLIDER_STYLE_t ss;
118 andreas 487
                        ss.init();
73 andreas 488
                        ss.name = content;
489
                        draw->sliderStyles.push_back(ss);
490
                    }
491
                    else if (mActElement.compare("baseFile") == 0)
492
                    {
493
                        DRAW_t *draw = (DRAW_t *)userData;
494
                        draw->sliderStyles.back().baseFile = content;
495
                    }
496
                    else if (mActElement.compare("multiColor") == 0)
497
                    {
498
                        DRAW_t *draw = (DRAW_t *)userData;
499
                        draw->sliderStyles.back().multiColor = atoi(content.c_str());
500
                    }
501
                    else if (mActElement.compare("incRepeat") == 0)
502
                    {
503
                        DRAW_t *draw = (DRAW_t *)userData;
504
                        draw->sliderStyles.back().incRepeat = atoi(content.c_str());
505
                    }
506
                    else if (mActElement.compare("minSize") == 0)
507
                    {
508
                        DRAW_t *draw = (DRAW_t *)userData;
509
                        draw->sliderStyles.back().minSize = atoi(content.c_str());
510
                    }
511
                    else if (mActElement.compare("fixedSize") == 0)
512
                    {
513
                        DRAW_t *draw = (DRAW_t *)userData;
514
                        draw->sliderStyles.back().fixedSize = atoi(content.c_str());
515
                    }
516
                    else if (mActElement.compare("g3Equiv") == 0)
517
                    {
518
                        DRAW_t *draw = (DRAW_t *)userData;
519
                        draw->sliderStyles.back().g3Equiv.push_back(atoi(content.c_str()));
520
                    }
521
                break;
522
 
523
                default:
524
                    MSG_WARNING("Unknown slider element \"" << mActElement << "\" with content \"" << content << "\"");
525
            }
526
        break;
527
 
528
        case X_EFFECT_DATA:
529
            switch(mActFamily)
530
            {
531
                case X_EFFECT_FAMILY:
532
                    if (mActElement.compare("name") == 0)
533
                    {
534
                        DRAW_t *draw = (DRAW_t *)userData;
535
                        FAMILY_t ef;
536
                        ef.name = content;
537
                        draw->effects.push_back(ef);
538
                    }
539
                    else if (mActElement.compare("member") == 0)
540
                    {
541
                        DRAW_t *draw = (DRAW_t *)userData;
542
                        draw->effects.back().member.push_back(content);
543
                    }
544
                break;
545
 
546
                case X_EFFECT_STYLE:
547
                    if (mActElement.compare("name") == 0)
548
                    {
549
                        DRAW_t *draw = (DRAW_t *)userData;
550
                        EFFECT_STYLE_t es;
118 andreas 551
                        es.init();
73 andreas 552
                        es.name = content;
553
                        draw->effectStyles.push_back(es);
554
                    }
555
                    else if (mActElement.compare("number") == 0)
556
                    {
557
                        DRAW_t *draw = (DRAW_t *)userData;
558
                        draw->effectStyles.back().number = atoi(content.c_str());
559
                    }
560
                    else if (mActElement.compare("startX") == 0)
561
                    {
562
                        DRAW_t *draw = (DRAW_t *)userData;
563
                        draw->effectStyles.back().startx = atoi(content.c_str());
564
                    }
565
                    else if (mActElement.compare("startY") == 0)
566
                    {
567
                        DRAW_t *draw = (DRAW_t *)userData;
568
                        draw->effectStyles.back().starty = atoi(content.c_str());
569
                    }
570
                    else if (mActElement.compare("height") == 0)
571
                    {
572
                        DRAW_t *draw = (DRAW_t *)userData;
573
                        draw->effectStyles.back().height = atoi(content.c_str());
574
                    }
575
                    else if (mActElement.compare("width") == 0)
576
                    {
577
                        DRAW_t *draw = (DRAW_t *)userData;
578
                        draw->effectStyles.back().width = atoi(content.c_str());
579
                    }
580
                    else if (mActElement.compare("cutout") == 0)
581
                    {
582
                        DRAW_t *draw = (DRAW_t *)userData;
583
                        draw->effectStyles.back().cutout = atoi(content.c_str());
584
                    }
585
                    else if (mActElement.compare("pixelMap") == 0)
586
                    {
587
                        DRAW_t *draw = (DRAW_t *)userData;
588
                        draw->effectStyles.back().pixelMap = content;
589
                    }
590
                break;
591
 
592
                default:
593
                    MSG_WARNING("Unknown effect element \"" << mActElement << "\" with content \"" << content << "\"");
594
            }
595
        break;
596
 
597
        case X_POPUP_EFFECT_DATA:
598
            if (mActFamily == X_POPUP_EFFECT)
599
            {
600
                if (mActElement.compare("name") == 0)
601
                {
602
                    DRAW_t *draw = (DRAW_t *)userData;
603
                    POPUP_EFFECT_t pe;
118 andreas 604
                    pe.init();
73 andreas 605
                    pe.name = content;
606
                    draw->popupEffects.push_back(pe);
607
                }
608
                else if (mActElement.compare("number") == 0)
609
                {
610
                    DRAW_t *draw = (DRAW_t *)userData;
611
                    draw->popupEffects.back().number = atoi(content.c_str());
612
                }
613
                else if (mActElement.compare("valueUsed") == 0)
614
                {
615
                    DRAW_t *draw = (DRAW_t *)userData;
616
                    draw->popupEffects.back().valueUsed = atoi(content.c_str());
617
                }
618
            }
619
        break;
620
 
621
        default:
622
            MSG_WARNING("Unknown data element \"" << mActElement << "\" with content \"" << content << "\"");
623
    }
72 andreas 624
}
79 andreas 625
 
159 andreas 626
string TSystemDraw::getDirEntry(dir::TDirectory* dir, const string& part, bool alpha)
627
{
628
    DECL_TRACER("TSystemDraw::getDirEntry(dir::TDirectory* dir, const string& part, bool precice)");
629
 
630
    string such = part;
631
 
632
    if (alpha)
633
        such += "_alpha";
634
 
635
    string dirEntry = dir->getEntryWithPart(such, true);
636
    such = part;
637
 
638
    if (dirEntry.empty())
639
        dirEntry = dir->getEntryWithPart(such, false);
640
 
641
    return dirEntry;
642
}
643
 
306 andreas 644
bool TSystemDraw::getBorder(const string &family, LINE_TYPE_t lt, BORDER_t *border, const string& family2, bool info)
79 andreas 645
{
306 andreas 646
    DECL_TRACER("TSystemDraw::getBorder(const string &family, LINE_TYPE_t lt, BORDER_t *border, const string& family2, bool info)");
79 andreas 647
 
99 andreas 648
    if (!border || family.empty() || mDraw.borders.size() == 0)
79 andreas 649
        return false;
650
 
651
    // Find the border details
652
    vector<FAMILY_t>::iterator iter;
653
    bool found = false;
654
    string fullName;
655
 
656
    for (iter = mDraw.borders.begin(); iter != mDraw.borders.end(); ++iter)
657
    {
658
        vector<string>::iterator strIter;
659
 
660
        for (strIter = iter->member.begin(); strIter != iter->member.end(); ++strIter)
661
        {
222 andreas 662
            /*
663
             * In the table we've the "family" name in the first place while in
664
             * the configuration file for a page/subpage we have the whole name.
665
             * Because of this we must look if the whole name starts with the
666
             * family name. If so, we've found what we're looking for.
667
             * Example:
668
             * Whole name in the XML configuration: AMX Elite Raised -M
669
             * Family name: AMX Elite
670
             * Organization:
671
             * The entity "borderFamily" defines the family name (AMX Elite). A
672
             * family has members: "AMX Elite -S", "AMX Elite -M" and "AMX Elite -L"
673
             * in our example.
674
             * The entity "borderStyle" is named like the member. With this
675
             * information we'll find the correct border style and with it the
262 andreas 676
             * file names containing the border graphics.
222 andreas 677
             */
678
            vector<string>parts = StrSplit(*strIter, " ", true);
679
 
680
            if (evaluateName(parts, family))   // Here we find the wanted member
79 andreas 681
            {
682
                // Find the detailed name
683
                vector<BORDER_STYLE_t>::iterator styIter;
222 andreas 684
                // Here we search in the style table for an element with the
685
                // found member name
79 andreas 686
                for (styIter = mDraw.borderStyles.begin(); styIter != mDraw.borderStyles.end(); ++styIter)
687
                {
222 andreas 688
                    if (styIter->name.compare(*strIter) == 0)
79 andreas 689
                    {
690
                        found = true;
81 andreas 691
                        border->bdStyle = *styIter;
79 andreas 692
 
693
                        switch(lt)
694
                        {
695
                            case LT_OFF:    fullName = styIter->off; break;
696
                            case LT_ON:     fullName = styIter->on; break;
697
                            case LT_DRAG:   fullName = styIter->drag; break;
698
                            case LT_DROP:   fullName = styIter->drop; break;
699
                        }
700
 
169 andreas 701
 
79 andreas 702
                        break;
703
                    }
704
                }
705
            }
706
 
707
            if (found)
708
                break;
709
        }
710
 
711
        if (found)
712
            break;
713
    }
714
 
715
    if (!found || fullName.empty())
168 andreas 716
    {
717
        MSG_WARNING("Border " << family << " not found!");
79 andreas 718
        return false;
168 andreas 719
    }
79 andreas 720
 
307 andreas 721
    MSG_DEBUG("External system border " << family << " found.");
80 andreas 722
    dir::TDirectory dir(mPath + "/borders");
723
    dir.setStripPath(true);
79 andreas 724
    vector<BORDER_DATA_t>::iterator brdIter;
169 andreas 725
    string dataName = (family2.length() > 0 ? family2 : fullName);
79 andreas 726
 
727
    for (brdIter = mDraw.borderData.begin(); brdIter != mDraw.borderData.end(); brdIter++)
728
    {
169 andreas 729
        if (brdIter->name.compare(dataName) == 0)
79 andreas 730
        {
306 andreas 731
            if (!info)
732
            {
733
                int num = dir.scanFiles(brdIter->baseFile + "_");
80 andreas 734
 
306 andreas 735
                if (num < 8)
736
                    continue;
80 andreas 737
 
306 andreas 738
                border->b = mPath + "/borders/" + getDirEntry(&dir, "_b", (lt == LT_ON) ? true : false);
739
                border->bl = mPath + "/borders/" + getDirEntry(&dir, "_bl", (lt == LT_ON) ? true : false);
740
                border->br = mPath + "/borders/" + getDirEntry(&dir, "_br", (lt == LT_ON) ? true : false);
741
                border->l = mPath + "/borders/" + getDirEntry(&dir, "_l", (lt == LT_ON) ? true : false);
742
                border->r = mPath + "/borders/" + getDirEntry(&dir, "_r", (lt == LT_ON) ? true : false);
743
                border->t = mPath + "/borders/" + getDirEntry(&dir, "_t", (lt == LT_ON) ? true : false);
744
                border->tl = mPath + "/borders/" + getDirEntry(&dir, "_tl", (lt == LT_ON) ? true : false);
745
                border->tr = mPath + "/borders/" + getDirEntry(&dir, "_tr", (lt == LT_ON) ? true : false);
746
                border->border = *brdIter;
747
                MSG_DEBUG("Bottom      : " << border->b);
748
                MSG_DEBUG("Top         : " << border->t);
749
                MSG_DEBUG("Left        : " << border->l);
750
                MSG_DEBUG("Right       : " << border->r);
751
                MSG_DEBUG("Top left    : " << border->tl);
752
                MSG_DEBUG("Top right   : " << border->tr);
753
                MSG_DEBUG("Bottom left : " << border->bl);
754
                MSG_DEBUG("Bottom right: " << border->br);
755
            }
756
            else
757
                border->border = *brdIter;
758
 
79 andreas 759
            return true;
760
        }
761
    }
762
 
763
    return false;
764
}
765
 
306 andreas 766
bool TSystemDraw::getBorderInfo(const std::string& family, LINE_TYPE_t lt, BORDER_t *border, const std::string& family2)
767
{
768
    DECL_TRACER("TSystemDraw::getBorderInfo(const std::string& family, LINE_TYPE_t lt, BORDER_t *border, const std::string& family2)");
769
 
770
    return getBorder(family, lt, border, family2, true);
771
}
772
 
79 andreas 773
bool TSystemDraw::existBorder(const string &family)
774
{
775
    DECL_TRACER("TSystemDraw::existBorder(const string &family)");
776
 
99 andreas 777
    if (family.empty() || mDraw.borders.size() == 0)
79 andreas 778
        return false;
779
 
780
    // Find the border details
781
    vector<FAMILY_t>::iterator iter;
782
 
783
    for (iter = mDraw.borders.begin(); iter != mDraw.borders.end(); ++iter)
784
    {
785
        vector<string>::iterator strIter;
786
 
787
        for (strIter = iter->member.begin(); strIter != iter->member.end(); ++strIter)
788
        {
222 andreas 789
            vector<string>parts = StrSplit(*strIter, " ", true);
790
 
791
            if (evaluateName(parts, family))
79 andreas 792
            {
793
                // Find the detailed name
794
                vector<BORDER_STYLE_t>::iterator styIter;
795
 
796
                for (styIter = mDraw.borderStyles.begin(); styIter != mDraw.borderStyles.end(); ++styIter)
797
                {
222 andreas 798
                    if (styIter->name.compare(*strIter) == 0)
79 andreas 799
                        return true;
800
                }
801
            }
802
        }
803
    }
804
 
805
    return false;
806
}
81 andreas 807
 
808
int TSystemDraw::getBorderWidth(const string &family, LINE_TYPE_t lt)
809
{
810
    DECL_TRACER("TSystemDraw::getBorderWidth(const string &family, LINE_TYPE_t lt)");
811
 
812
    if (family.empty())
813
        return 0;
814
 
815
    BORDER_t bd;
816
 
306 andreas 817
    if (!getBorderInfo(family, lt, &bd))
81 andreas 818
        return 0;
819
 
99 andreas 820
    MSG_DEBUG("Border width of \"" << family << "\" [" << lt << "]: " << bd.border.textLeft);
81 andreas 821
    return bd.border.textLeft;
822
}
823
 
824
int TSystemDraw::getBorderHeight(const string &family, LINE_TYPE_t lt)
825
{
826
    DECL_TRACER("TSystemDraw::getBorderHeight(const string &family, LINE_TYPE_t lt)");
827
 
828
    if (family.empty())
829
        return 0;
830
 
831
    BORDER_t bd;
832
 
306 andreas 833
    if (!getBorderInfo(family, lt, &bd))
81 andreas 834
        return 0;
835
 
836
    return bd.border.textTop;
837
}
99 andreas 838
 
839
bool TSystemDraw::existSlider(const string& slider)
840
{
841
    DECL_TRACER("TSystemDraw::existSlider(const string& slider)");
842
 
843
    if (slider.empty() || mDraw.sliderStyles.size() == 0)
844
    {
845
        MSG_ERROR("Slider " << slider << " has " << mDraw.sliderStyles.size() << " entries.");
846
        return false;
847
    }
848
 
849
    vector<SLIDER_STYLE_t>::iterator iter;
850
 
851
    for (iter = mDraw.sliderStyles.begin(); iter != mDraw.sliderStyles.end(); ++iter)
852
    {
853
        if (iter->name.compare(slider) == 0)
854
             return true;
855
    }
856
 
857
    return false;
858
}
859
 
860
bool TSystemDraw::getSlider(const string& slider, SLIDER_STYLE_t* style)
861
{
862
    DECL_TRACER("TSystemDraw::getSlider(const string& slider, SLIDER_STYLE_t* style)");
863
 
864
    if (slider.empty() || mDraw.sliderStyles.size() == 0)
865
        return false;
866
 
867
    if (!style)
868
        return existSlider(slider);
869
 
870
    vector<SLIDER_STYLE_t>::iterator iter;
871
 
872
    for (iter = mDraw.sliderStyles.begin(); iter != mDraw.sliderStyles.end(); ++iter)
873
    {
874
        if (iter->name.compare(slider) == 0)
875
        {
876
            *style = *iter;
877
            return true;
878
        }
879
    }
880
 
881
    return false;
882
}
883
 
884
vector<SLIDER_t> TSystemDraw::getSliderFiles(const string& slider)
885
{
886
    DECL_TRACER("TSystemDraw::getSliderFiles(const string& slider)");
887
 
888
    vector<SLIDER_t> list;
889
 
890
    if (slider.empty())
891
        return list;
892
 
893
    SLIDER_STYLE_t sst;
894
 
895
    if (!getSlider(slider, &sst))
896
        return list;
897
 
898
    string fbase = sst.baseFile;
899
    string myPath = mPath + "/sliders";
900
    dir::TDirectory dir(myPath);
901
    dir.setStripPath(true);
902
    MSG_DEBUG("Scanning for files " << mPath << "/sliders/" << fbase << "_*");
903
    int num = dir.scanFiles(fbase + "_");
904
 
905
    if (num <= 0)
906
        return list;
907
 
908
    myPath += "/";
909
    SLIDER_t slid;
910
 
911
    slid.type = SGR_TOP;
100 andreas 912
    slid.path = myPath + dir.getEntryWithPart(fbase+"_t");
99 andreas 913
    slid.pathAlpha = myPath + dir.getEntryWithPart("_t_alpha");
914
    MSG_DEBUG("Adding paths \"" << slid.path << "\" and \"" << slid.pathAlpha << "\"");
915
    list.push_back(slid);
916
 
917
    slid.type = SGR_BOTTOM;
100 andreas 918
    slid.path = myPath + dir.getEntryWithPart(fbase+"_b");
99 andreas 919
    slid.pathAlpha = myPath + dir.getEntryWithPart("_b_alpha");
920
    MSG_DEBUG("Adding paths \"" << slid.path << "\" and \"" << slid.pathAlpha << "\"");
921
    list.push_back(slid);
922
 
923
    slid.type = SGR_LEFT;
100 andreas 924
    slid.path = myPath + dir.getEntryWithPart(fbase+"_l");
99 andreas 925
    slid.pathAlpha = myPath + dir.getEntryWithPart("_l_alpha");
926
    MSG_DEBUG("Adding paths \"" << slid.path << "\" and \"" << slid.pathAlpha << "\"");
927
    list.push_back(slid);
928
 
929
    slid.type = SGR_RIGHT;
100 andreas 930
    slid.path = myPath + dir.getEntryWithPart(fbase+"_r");
99 andreas 931
    slid.pathAlpha = myPath + dir.getEntryWithPart("_r_alpha");
932
    MSG_DEBUG("Adding paths \"" << slid.path << "\" and \"" << slid.pathAlpha << "\"");
933
    list.push_back(slid);
934
 
935
    slid.type = SGR_HORIZONTAL;
100 andreas 936
    slid.path = myPath + dir.getEntryWithPart(fbase+"_h");
99 andreas 937
    slid.pathAlpha = myPath + dir.getEntryWithPart("_h_alpha");
938
    MSG_DEBUG("Adding paths \"" << slid.path << "\" and \"" << slid.pathAlpha << "\"");
939
    list.push_back(slid);
940
 
941
    slid.type = SGR_VERTICAL;
100 andreas 942
    slid.path = myPath + dir.getEntryWithPart(fbase+"_v");
99 andreas 943
    slid.pathAlpha = myPath + dir.getEntryWithPart("_v_alpha");
944
    MSG_DEBUG("Adding paths \"" << slid.path << "\" and \"" << slid.pathAlpha << "\"");
945
    list.push_back(slid);
946
 
947
    return list;
948
}
222 andreas 949
 
950
/**
951
 * @brief TSystemDraw::evaluateName - Tests for all parts of \b parts in \b name
952
 * The method tests if all strings in \b parts are contained in \b name.
953
 *
954
 * @param parts     A vector array containing one or more strings.
955
 * @param name      A string which may contain all strings from \b parts.
956
 *
957
 * @return In case all strings from \b parts were found in \b name it returns
958
 * TRUE. Otherwise FALSE.
959
 */
960
bool TSystemDraw::evaluateName(const std::vector<std::string>& parts, const std::string& name)
961
{
962
    DECL_TRACER("TSystemDraw::evaluateName(const std::vector<std::string>& parts, const std::string& name)");
963
 
964
    if (parts.empty())
965
        return false;
966
 
967
    size_t found = 0;
968
    vector<string>::const_iterator iter;
969
 
970
    for (iter = parts.begin(); iter != parts.end(); ++iter)
971
    {
972
        if (StrContains(name, *iter))
973
            found++;
974
    }
975
 
976
    if (found == parts.size())
977
        return true;
978
 
979
    return false;
980
}