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