Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

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