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