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