Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

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