Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
268 andreas 2
 * Copyright (C) 2020 to 2023 by Andreas Theofilu <andreas@theosys.at>
2 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
#ifndef __TBUTTON_H__
19
#define __TBUTTON_H__
20
 
21
#include <string>
22
#include <vector>
3 andreas 23
#include <map>
6 andreas 24
#include <functional>
15 andreas 25
#include <thread>
6 andreas 26
 
4 andreas 27
#include <include/core/SkImage.h>
28
#include <include/core/SkCanvas.h>
6 andreas 29
#include <include/core/SkBitmap.h>
30
 
76 andreas 31
#include "texpat++.h"
4 andreas 32
#include "tpalette.h"
33
#include "tcolor.h"
7 andreas 34
#include "tfont.h"
15 andreas 35
#include "tamxnet.h"
36
#include "ttimer.h"
21 andreas 37
#include "timagerefresh.h"
195 andreas 38
#include "tsystem.h"
306 andreas 39
#include "tintborder.h"
2 andreas 40
 
8 andreas 41
#define ORD_ELEM_COUNT  5
42
 
21 andreas 43
extern bool prg_stopped;
97 andreas 44
extern bool _restart_;
21 andreas 45
 
8 andreas 46
class SkFont;
66 andreas 47
class SkTextBlob;
289 andreas 48
class TBitmap;
66 andreas 49
 
21 andreas 50
struct RESOURCE_T;
8 andreas 51
 
2 andreas 52
namespace Button
53
{
269 andreas 54
#   define STATE_BASE   0
55
#   define STATE_OFF    0
56
#   define STATE_ON     1
57
#   define STATE_1      0
58
#   define STATE_2      1
59
#   define STATE_3      2
60
#   define STATE_4      3
61
#   define STATE_5      4
62
#   define STATE_6      5
63
#   define STATE_7      6
64
#   define STATE_8      7
65
#   define STATE_ALL    -1
66
 
67
#   define HANDLE_UNDEF 0
68
 
110 andreas 69
    typedef struct SYSTEF_t         // Text effect names
70
    {
71
        int idx{0};
72
        std::string name;
73
    }SYSTEF_t;
74
 
3 andreas 75
    typedef enum TEXT_ORIENTATION
76
    {
77
        ORI_ABSOLUT,
78
        ORI_TOP_LEFT,
79
        ORI_TOP_MIDDLE,
80
        ORI_TOP_RIGHT,
81
        ORI_CENTER_LEFT,
82
        ORI_CENTER_MIDDLE,		// default
83
        ORI_CENTER_RIGHT,
84
        ORI_BOTTOM_LEFT,
85
        ORI_BOTTOM_MIDDLE,
86
        ORI_BOTTOM_RIGHT
87
    } TEXT_ORIENTATION;
2 andreas 88
 
7 andreas 89
    typedef enum TEXT_EFFECT
90
    {
91
        EFFECT_NONE,
92
        EFFECT_OUTLINE_S,
93
        EFFECT_OUTLINE_M,
94
        EFFECT_OUTLINE_L,
95
        EFFECT_OUTLINE_X,
96
        EFFECT_GLOW_S,
97
        EFFECT_GLOW_M,
98
        EFFECT_GLOW_L,
99
        EFFECT_GLOW_X,
100
        EFFECT_SOFT_DROP_SHADOW_1,
101
        EFFECT_SOFT_DROP_SHADOW_2,
102
        EFFECT_SOFT_DROP_SHADOW_3,
103
        EFFECT_SOFT_DROP_SHADOW_4,
104
        EFFECT_SOFT_DROP_SHADOW_5,
105
        EFFECT_SOFT_DROP_SHADOW_6,
106
        EFFECT_SOFT_DROP_SHADOW_7,
107
        EFFECT_SOFT_DROP_SHADOW_8,
108
        EFFECT_MEDIUM_DROP_SHADOW_1,
109
        EFFECT_MEDIUM_DROP_SHADOW_2,
110
        EFFECT_MEDIUM_DROP_SHADOW_3,
111
        EFFECT_MEDIUM_DROP_SHADOW_4,
112
        EFFECT_MEDIUM_DROP_SHADOW_5,
113
        EFFECT_MEDIUM_DROP_SHADOW_6,
114
        EFFECT_MEDIUM_DROP_SHADOW_7,
115
        EFFECT_MEDIUM_DROP_SHADOW_8,
116
        EFFECT_HARD_DROP_SHADOW_1,
117
        EFFECT_HARD_DROP_SHADOW_2,
118
        EFFECT_HARD_DROP_SHADOW_3,
119
        EFFECT_HARD_DROP_SHADOW_4,
120
        EFFECT_HARD_DROP_SHADOW_5,
121
        EFFECT_HARD_DROP_SHADOW_6,
122
        EFFECT_HARD_DROP_SHADOW_7,
123
        EFFECT_HARD_DROP_SHADOW_8,
124
        EFFECT_SOFT_DROP_SHADOW_1_WITH_OUTLINE,
125
        EFFECT_SOFT_DROP_SHADOW_2_WITH_OUTLINE,
126
        EFFECT_SOFT_DROP_SHADOW_3_WITH_OUTLINE,
127
        EFFECT_SOFT_DROP_SHADOW_4_WITH_OUTLINE,
128
        EFFECT_SOFT_DROP_SHADOW_5_WITH_OUTLINE,
129
        EFFECT_SOFT_DROP_SHADOW_6_WITH_OUTLINE,
130
        EFFECT_SOFT_DROP_SHADOW_7_WITH_OUTLINE,
131
        EFFECT_SOFT_DROP_SHADOW_8_WITH_OUTLINE,
132
        EFFECT_MEDIUM_DROP_SHADOW_1_WITH_OUTLINE,
133
        EFFECT_MEDIUM_DROP_SHADOW_2_WITH_OUTLINE,
134
        EFFECT_MEDIUM_DROP_SHADOW_3_WITH_OUTLINE,
135
        EFFECT_MEDIUM_DROP_SHADOW_4_WITH_OUTLINE,
136
        EFFECT_MEDIUM_DROP_SHADOW_5_WITH_OUTLINE,
137
        EFFECT_MEDIUM_DROP_SHADOW_6_WITH_OUTLINE,
138
        EFFECT_MEDIUM_DROP_SHADOW_7_WITH_OUTLINE,
139
        EFFECT_MEDIUM_DROP_SHADOW_8_WITH_OUTLINE,
140
        EFFECT_HARD_DROP_SHADOW_1_WITH_OUTLINE,
141
        EFFECT_HARD_DROP_SHADOW_2_WITH_OUTLINE,
142
        EFFECT_HARD_DROP_SHADOW_3_WITH_OUTLINE,
143
        EFFECT_HARD_DROP_SHADOW_4_WITH_OUTLINE,
144
        EFFECT_HARD_DROP_SHADOW_5_WITH_OUTLINE,
145
        EFFECT_HARD_DROP_SHADOW_6_WITH_OUTLINE,
146
        EFFECT_HARD_DROP_SHADOW_7_WITH_OUTLINE,
147
        EFFECT_HARD_DROP_SHADOW_8_WITH_OUTLINE
148
    }TEXT_EFFECT;
149
 
8 andreas 150
    typedef enum DRAW_ORDER
151
    {
152
        ORD_ELEM_NONE,
153
        ORD_ELEM_FILL,
154
        ORD_ELEM_BITMAP,
155
        ORD_ELEM_ICON,
156
        ORD_ELEM_TEXT,
157
        ORD_ELEM_BORDER
158
    }DRAW_ORDER;
159
 
43 andreas 160
    typedef enum FEEDBACK
161
    {
162
        FB_NONE,
163
        FB_CHANNEL,
164
        FB_INV_CHANNEL,     // inverted channel
165
        FB_ALWAYS_ON,
166
        FB_MOMENTARY,
167
        FB_BLINK
168
    } FEEDBACK;
169
 
159 andreas 170
    typedef enum PMIX
171
    {
172
        PMIX_MULTIPLY,
173
        PMIX_XOR,
174
        PMIX_SCREEN,
175
        PMIX_SRC,
176
        PMIX_DST,
177
        PMIX_SRCOVER,
178
        PMIX_SRCTOP,
179
        PMIX_DSTTOP,
180
        PMIX_PLUS
181
    }PMIX;
182
 
300 andreas 183
    typedef enum SUBVIEW_POSITION_t
184
    {
185
        SVP_CENTER,
186
        SVP_LEFT_TOP,
187
        SVP_RIGHT_BOTTOM
188
    }SUBVIEW_POSITION_t;
189
 
3 andreas 190
    typedef struct SR_T
191
    {
192
        int number{0};
6 andreas 193
        std::string _do;        // Order on how to show a multistate bargraph (010203...)
194
        std::string bs;         // Frame type (circle, ...)
195
        std::string mi;         // Chameleon image
196
        int mi_width{0};        // Width of image
197
        int mi_height{0};       // Height of image
198
        std::string cb;         // Border color
199
        std::string cf;         // Fill color
200
        std::string ct;         // Text Color
201
        std::string ec;         // Text effect color
202
        std::string bm;         // bitmap file name
203
        std::string sd;         // Sound file to play
204
        int bm_width{0};        // Width of image
205
        int bm_height{0};       // Height of image
206
        bool dynamic{false};    // TRUE = moving image
207
        int sb{0};              // Index to external graphics download
208
        int ii{0};              // Icon index number
10 andreas 209
        int ix{0};              // Icon X position
210
        int iy{0};              // Icon Y position
7 andreas 211
        int ji{5};              // Icon style / position like "jt", default 5 = center+middle
212
        int jb{5};              // Image position (center, left, ...), default 5 = center+middle
10 andreas 213
        int bx{0};              // Absolute image position x
214
        int by{0};              // Absolute image position y
215
        int fi{0};              // Font index
6 andreas 216
        std::string te;         // Text
217
        TEXT_ORIENTATION jt{ORI_CENTER_MIDDLE}; // Text orientation
218
        int tx{0};              // Text X position
219
        int ty{0};              // Text Y position
220
        int ww{0};              // line break when 1
221
        int et{0};              // Text effect (^TEF)
8 andreas 222
        int oo{-1};             // Over all opacity
3 andreas 223
    } SR_T;
2 andreas 224
 
43 andreas 225
    typedef struct EXTBUTTON_t
3 andreas 226
    {
43 andreas 227
        BUTTONTYPE type;
228
        int bi{0};              // button ID
229
        std::string na;         // name
230
        int lt{0};              // pixel from left
231
        int tp{0};              // pixel from top
232
        int wt{0};              // width
233
        int ht{0};              // height
234
        int zo{0};              // Z-Order
235
        std::string hs;         // bounding, ...
236
        std::string bs;         // Border style (circle, ...)
237
        FEEDBACK fb{FB_NONE};   // Feedback type (momentary, ...)
238
        int ap{1};              // Address port (default: 1)
239
        int ad{0};              // Address channel
240
        int lp{1};              // Level port (default: 1)
241
        int lv{0};              // Level code
242
        std::string dr;         // Level "horizontal" or "vertical"
243
        int lu{0};              // Animate time up (Bargraph)
244
        int ld{0};              // Animate time down (Bargraph)
245
        int rl{0};              // Range low
246
        int rh{0};              // Range high
247
        int rn{0};              // Bargraph: Range drag increment
248
        std::string sc;         // Color of slider (for bargraph)
249
        std::vector<SR_T> sr;
250
    }EXTBUTTON_t;
2 andreas 251
 
3 andreas 252
    typedef struct PUSH_FUNC
253
    {
6 andreas 254
        std::string pfType; // command to execute when button was pushed
255
        std::string pfName; // Name of popup
3 andreas 256
    } PUSH_FUNC_T;
2 andreas 257
 
4 andreas 258
    typedef enum CENTER_CODE
259
    {
260
        SC_ICON = 0,
261
        SC_BITMAP,
262
        SC_TEXT
263
    }CENTER_CODE;
264
 
265
    typedef struct POSITION_t
266
    {
267
        int width{0};
268
        int height{0};
10 andreas 269
        int left{1};
270
        int top{1};
17 andreas 271
        bool overflow{false};
4 andreas 272
        bool valid{false};
273
    }POSITION_t;
274
 
99 andreas 275
    typedef struct IMAGE_SIZE_t
276
    {
277
        int width{0};
278
        int height{0};
279
    }IMAGE_SIZE_t;
280
 
21 andreas 281
    typedef struct THR_REFRESH_t
282
    {
283
        ulong handle{0};
284
        ulong parent{0};
285
        int bi{0};
286
        TImageRefresh *mImageRefresh{nullptr};
287
        THR_REFRESH_t *next{nullptr};
288
    }THR_REFRESH_t;
289
 
50 andreas 290
    typedef struct BITMAP_t
291
    {
52 andreas 292
        unsigned char *buffer{nullptr};
293
        int left{0};
294
        int top{0};
295
        int width{0};
296
        int height{0};
297
        size_t rowBytes{0};
50 andreas 298
    }BITMAP_t;
299
 
94 andreas 300
    typedef struct BITMAP_CACHE
301
    {
302
        ulong handle{0};
303
        ulong parent{0};
304
        int left{0};
305
        int top{0};
306
        int width{0};
307
        int height{0};
308
        int bi{0};
97 andreas 309
        bool show{false};
94 andreas 310
        bool ready{false};
311
        SkBitmap bitmap;
312
    }BITMAP_CACHE;
313
 
225 andreas 314
#   define LIST_IMAGE_CELL     1
315
#   define LIST_TEXT_PRIMARY   2
316
#   define LIST_TEXT_SECONDARY 4
317
 
318
    typedef enum LIST_SORT
319
    {
320
        LIST_SORT_NONE,
321
        LIST_SORT_ASC,
322
        LIST_SORT_DESC,
323
        LIST_SORT_OVERRIDE
324
    }LIST_SORT;
325
 
306 andreas 326
    class TButton : public TSystem, public Border::TIntBorder
3 andreas 327
    {
328
        public:
329
            TButton();
330
            ~TButton();
2 andreas 331
 
14 andreas 332
            /**
333
             * The following function parses the parameters of a particular
334
             * button and creates a new button. This function is called either
335
             * from class TPage or TSubPage when a page or subpage is created.
336
             *
23 andreas 337
             * @param xml     A pointer to the XML reader
338
             * @param node    A pointer to the actual node in the XML tree.
76 andreas 339
             * @return On success the last index processed. On error
340
             * TExpat::npos is returned.
14 andreas 341
             */
76 andreas 342
            size_t initialize(Expat::TExpat *xml, size_t index);
2 andreas 343
 
14 andreas 344
            /**
345
             * Returns the button index. This is a unique number inside a page
346
             * or subpage.
23 andreas 347
             *
348
             * @return return the button index number as defined in the
349
             * configuration file.
14 andreas 350
             */
3 andreas 351
            int getButtonIndex() { return bi; }
14 andreas 352
            /**
353
             * Returns the name of the button.
354
             */
3 andreas 355
            std::string& getButtonName() { return na; }
14 andreas 356
            /**
357
             * Returns the description of the button, if there is one.
358
             */
3 andreas 359
            std::string& getButtonDescription() { return bd; }
14 andreas 360
            /**
361
             * Returns the width of the button in pixels.
362
             */
3 andreas 363
            int getWidth() { return wt; }
14 andreas 364
            /**
365
             * Returns the height of the button in pixels.
366
             */
3 andreas 367
            int getHeight() { return ht; }
14 andreas 368
            /**
369
             * Returns the left position in pixels.
370
             */
3 andreas 371
            int getLeftPosition() { return lt; }
14 andreas 372
            /**
373
             * Returns the top position of the button in pixels.
374
             */
3 andreas 375
            int getTopPosition() { return tp; }
14 andreas 376
            /**
377
             * Returns the Z-order. This number marks the order the buttons
378
             * are drawed on the screen. Inside a page or subpage the buttons
379
             * are always sorted.
380
             */
3 andreas 381
            int getZOrder() { return zo; }
14 andreas 382
            /**
383
             * Returns the type of the button.
384
             */
385
            BUTTONTYPE getButtonType() { return type; }
149 andreas 386
            /**
387
             * Set font file name and optional the size
388
             *
334 andreas 389
             * @param name  File name of the font
149 andreas 390
             * @param size  The size of the font in PT
391
             * @param inst  The instance of the button
334 andreas 392
             *
393
             * @return TRUE success
149 andreas 394
             */
395
            bool setFontFileName(const std::string& name, int size, int inst);
334 andreas 396
            /**
397
             * Set font name.
398
             *
399
             * @param name  The font name
400
             * @param inst  The instance of the button
401
             *
402
             * @return TRUE success
403
             */
404
            bool setFontName(const std::string& name, int inst);
15 andreas 405
 
266 andreas 406
            std::string& getName() { return na; }
15 andreas 407
            int getRangeLow() { return rl; }
408
            int getRangeHigh() { return rh; }
409
            int getStateCount() { return stateCount; }
14 andreas 410
            int getAddressPort() { return ap; }
411
            int getAddressChannel() { return ad; }
412
            int getChannelNumber() { return ch; }
413
            int getChannelPort() { return cp; }
414
            int getLevelPort() { return lp; }
415
            int getLevelValue() { return lv; }
110 andreas 416
            std::string getText(int inst=0);
417
            std::string getTextColor(int inst=0);
418
            std::string getTextEffectColor(int inst=0);
108 andreas 419
            void setTextEffectColor(const std::string& ec, int inst=-1);
205 andreas 420
            bool setTextEffectColorOnly(const std::string& ec, int inst=-1);
110 andreas 421
            int getTextEffect(int inst=0);
422
            void setTextEffect(int et, int inst=-1);
423
            std::string getTextEffectName(int inst=0);
424
            void setTextEffectName(const std::string& name, int inst=-1);
425
            std::string getFillColor(int inst=0);
426
            std::string getBitmapName(int inst=0);
51 andreas 427
            bool isSingleLine() { return ( dt.compare("multiple") != 0); }
428
            bool isMultiLine() { return ( dt.compare("multiple") == 0); }
429
            int getTextMaxChars() { return mt; }
110 andreas 430
            void setTextMaxChars(int m) { mt = m; }
431
            bool getTextWordWrap(int inst=0);
432
            bool setTextWordWrap(bool ww, int inst=-1);
433
            int getFontIndex(int inst=0);
434
            bool setFontIndex(int fi, int inst=-1);
435
            int getIconIndex(int inst=0);
436
            std::string getSound(int inst=0);
437
            void setSound(const std::string& sd, int inst=-1);
438
            bool getDynamic(int inst=0);
107 andreas 439
            void setDynamic(int d, int inst=-1);
14 andreas 440
            int getNumberInstances() { return (int)sr.size(); }
15 andreas 441
            int getActiveInstance() { return mActInstance; }
16 andreas 442
            ulong getHandle() { return mHandle; }
50 andreas 443
            ulong getParent() { return (mHandle & 0xffff0000); }
51 andreas 444
            void setActiveInstance(int inst);
16 andreas 445
            void setEnable(bool en) { mEnabled = en; }
446
            bool isEnabled() { return mEnabled; }
26 andreas 447
            void setHandle(ulong handle) { mHandle = handle; };
4 andreas 448
            void setPalette(TPalette *pal) { mPalette = pal; }
6 andreas 449
            void setParentWidth(int width) { mParentWidth = width; }
450
            void setParentHeight(int height) { mParentHeight = height; }
451
            void setParentSize(int width, int height) { mParentWidth = width; mParentHeight = height; }
7 andreas 452
            void setFonts(TFont *ft) { mFonts = ft; }
10 andreas 453
            void setGlobalOpacity(int oo) { if (oo >= 0 && oo <= 255) mGlobalOO = oo; }
100 andreas 454
            void setVisible(bool v) { visible = v; hd = (v ? 0 : 1); }
97 andreas 455
            bool isVisible() { return visible; }
280 andreas 456
            bool isSubViewVertical() { return on == "vert"; }
199 andreas 457
            bool haveListContent() { return _getListContent != nullptr; }
458
            bool haveListRow() { return _getListRow != nullptr; }
300 andreas 459
            int getSubViewID() { return st; }
460
            bool getSubViewScrollbar() { return (ba == 1 ? true : false); }
461
            int getSubViewScrollbarOffset() { return (ba > 0 ? bo : 0); }
302 andreas 462
            bool getWrapSubViewPages() { return (ws != 0 ? true : false); }
309 andreas 463
            bool isFocused() { return mHasFocus; }
464
            int getTextCursorPosition() { return mCursorPosition; }
344 andreas 465
            void setChanged(bool ch) { mChanged = ch; }
300 andreas 466
            SUBVIEW_POSITION_t getSubViewAnchor();
200 andreas 467
            std::function<std::vector<std::string>(ulong handle, int ap, int ta, int ti, int rows, int columns)> getCallbackListContent() { return _getListContent; }
468
            std::function<std::string(int ti, int row)> getCallbackListRow() { return _getListRow; }
469
            std::function<void (TButton *button)> getCallbackGlobalSettings() { return _getGlobalSettings; };
38 andreas 470
 
471
            /**
472
             * @brief setBitmap Sets a new bitmap to the button
473
             * If there was already a bitmap on this button and if this bitmap
474
             * is different from the one in \p file, then it is erased.
475
             * The new bitmap file name is set and it will be loaded and created.
476
             *
477
             * @param file      File name of a bitmap file.
478
             * @param instance  The instance where to put the new bitmap. If
479
             *                  this is 0, the bitmap is set on all instances.
480
             * @return TRUE if no errors occures, otherwise FALSE.
481
             */
16 andreas 482
            bool setBitmap(const std::string& file, int instance);
38 andreas 483
            /**
104 andreas 484
             * @brief setCameleon Sets a new cameleon bitmap to the button
485
             * If there was already a cameleon bitmap on this button and if this
486
             * cameleon bitmap is different from the one in \p file, then it is
487
             * erased. The new cameleon bitmap file name is set and it will be
488
             * loaded and created.
489
             *
490
             * @param file      File name of a cameleon bitmap file.
491
             * @param instance  The instance where to put the new bitmap. If
492
             *                  this is 0, the bitmap is set on all instances.
493
             * @return TRUE if no errors occures, otherwise FALSE.
494
             */
495
            bool setCameleon(const std::string& file, int instance);
496
            /**
38 andreas 497
             * @brief setOpacity Sets the opacity of this button
498
             *
499
             * @param op        The opacity in a reange of 0 to 255.
500
             * @param instance  The instance where to put the new bitmap. If
501
             *                  this is 0, the bitmap is set on all instances.
502
             * @return TRUE if no errors occures, otherwise FALSE.
503
             */
16 andreas 504
            bool setOpacity(int op, int instance);
110 andreas 505
            int getOpacity(int inst=0);
200 andreas 506
            int getListAp() { return ap; }
507
            int getListTa() { return ta; }
508
            int getListTi() { return ti; }
509
            int getListNumRows() { return tr; }
510
            int getListNumCols() { return tc; }
285 andreas 511
            int getSubViewSpace() { return sa; }
293 andreas 512
            std::string getBounding() { return hs; }
16 andreas 513
            bool setFont(int id, int instance);
205 andreas 514
            bool setFontOnly(int id, int instance);
16 andreas 515
            void setTop(int top);
516
            void setLeft(int left);
517
            void setLeftTop(int left, int top);
152 andreas 518
            void setRectangle(int left, int top, int right, int bottom);
334 andreas 519
            void getRectangle(int *left, int *top, int *height, int *width);
21 andreas 520
            void setResourceName(const std::string& name, int instance);
106 andreas 521
            int getBitmapJustification(int *x, int *y, int instance);
522
            void setBitmapJustification(int j, int x, int y, int instance);
523
            int getIconJustification(int *x, int *y, int instance);
104 andreas 524
            void setIconJustification(int j, int x, int y, int instance);
106 andreas 525
            int getTextJustification(int *x, int *y, int instance);
104 andreas 526
            void setTextJustification(int j, int x, int y, int instance);
205 andreas 527
            bool setTextJustificationOnly(int j, int x, int y, int instance);
38 andreas 528
            bool startAnimation(int start, int end, int time);
529
            /**
530
             * @brief registerSystemButton registers the button as a system button.
531
             *
532
             * If the button is a system button, than it has special functions.
533
             * The action of the button depends on the kind of system button.
534
             */
15 andreas 535
            void registerSystemButton();
536
            bool isSystemButton();
38 andreas 537
            void addPushFunction(std::string& func, std::string& page);
16 andreas 538
            void clearPushFunctions() { pushFunc.clear(); }
539
            void clearPushFunction(const std::string& action);
540
            void refresh();
3 andreas 541
            /**
14 andreas 542
             * Sets a particular instance of the button active. This implies
543
             * a redraw of the button in case the instance is different from
544
             * the one already visible.
545
             *
546
             * @param instance
547
             * The instance of the button to be activated.
548
             *
549
             * @return
550
             * On error returns FALSE.
551
             */
552
            bool setActive(int instance);
553
            /**
554
             * Sets an Icon on the button. This implies a redraw of the button
555
             * in case the instance is different from the one already visible.
556
             *
557
             * @param id
558
             * The id number of the icon.
559
             *
560
             * @param instance
561
             * The instance where the icon should be drawed
562
             *
563
             * @return On error returns FALSE.
564
             */
565
            bool setIcon(int id, int instance);
566
            /**
567
             * Sets an Icon on the button. This implies a redraw of the button
568
             * in case the instance is different from the one already visible.
569
             *
570
             * @param icon
571
             * The file name of the icon.
572
             *
573
             * @param instance
574
             * The instance where the icon should be drawed
575
             *
576
             * @return
577
             * On error returns FALSE.
578
             */
579
            bool setIcon(const std::string& icon, int instance);
580
            /**
581
             * Removes an icon from a button. This implies a redraw of the
582
             * button.
583
             *
584
             * @param instance
585
             * The instance number involved.
586
             *
587
             * @return
588
             * On error returns FALSE.
589
             */
590
            bool revokeIcon(int instance);
591
            /**
592
             * Set a string to a button.
593
             *
594
             * @param txt
595
             * The text to write on top of  a button.
596
             *
597
             * @param instance
598
             * The instance number involved.
599
             *
600
             * @return
601
             * On error returns FALSE.
602
             */
603
            bool setText(const std::string& txt, int instance);
604
            /**
51 andreas 605
             * Set a string to a button. This method does not trigger a new
606
             * drawing of the element.
607
             *
608
             * @param txt
609
             * The text to write on top of  a button.
610
             *
611
             * @param instance
612
             * The instance number involved.
613
             *
614
             * @return
615
             * On error returns FALSE.
616
             */
617
            bool setTextOnly(const std::string& txt, int instance);
618
            /**
43 andreas 619
             * @brief appendText    Append non-unicode text.
620
             * @param txt
621
             * The text to write on top of  a button.
622
             * @param instance
623
             * The instance number involved.
624
             * @return
625
             * On error returns FALSE.
626
             */
627
            bool appendText(const std::string& txt, int instance);
628
            /**
309 andreas 629
             * @brief setTextCursorPosition - Set curso position
630
             * If the button element is of type TEXT_INPUT, this method sets
631
             * the cursor position. This position comes usually from an input
632
             * line managed by the graphical surface.
633
             * If the \b newPos is less then 0 the curser is set in front of the
634
             * first character. If the value \b newPos is grater then the number
635
             * of characters then the curser is set after the last character.
636
             *
637
             * @param oldPos    The old position of the cursor
638
             * @param newPos    The new position of the cursor
639
             */
640
            void setTextCursorPosition(int oldPos, int newPos);
641
            /**
642
             * @brief setTextFocus - Focus of input line changed
643
             * If the button element is of type TEXT_INPUT, this signals the
644
             * state of the focus. If \b in is TRUE then the input line got
645
             * the focus. The ON state of the button is send. If there is
646
             * a keyboard present the line is then related to this keyboard.
647
             * If \b in is FALSE the input line lost the focus. The off state
648
             * is displayed and no more characters are received from a
649
             * keyboard.
650
             * If this input line is a system input line, the focus is ignored.
651
             * It then receives always the keystrokes from a keyboard.
652
             *
653
             * @param in    TRUE: Input line got focus, FALSE: input line
654
             *              lost focus.
655
             */
656
            void setTextFocus(bool in);
657
            /**
43 andreas 658
             * @brief setBorderColor Set the border color.
659
             * Set the border color to the specified color. Only if the
660
             * specified border color is not the same as the current color.
661
             * Note: Color can be assigned by color name (without spaces),
662
             * number or R,G,B value (RRGGBB or RRGGBBAA).
663
             * @param color     the color
664
             * @param instance
665
             * The instance number involved.
666
             * @return
667
             * On error returns FALSE.
668
             */
669
            bool setBorderColor(const std::string& color, int instance);
670
            /**
82 andreas 671
             * @brief retrieves the current border color.
672
             * Determines the current border color of the button and returns
673
             * the color as a string.
674
             * @param instance  The instance number of the button.
675
             * @return
676
             * If everything went well it returns the color string of the button
677
             * instance. On error an empty string is returned.
678
             */
679
            std::string getBorderColor(int instance);
680
            /**
60 andreas 681
             * @brief setFillColor Set the fill color.
682
             * Set the fill color to the specified color. Only if the
683
             * specified fill color is not the same as the current color.
684
             * Note: Color can be assigned by color name (without spaces),
685
             * number or R,G,B value (RRGGBB or RRGGBBAA).
686
             * @param color     the color
687
             * @param instance
688
             * The instance number involved.
689
             * @return
690
             * On error returns FALSE.
691
             */
692
            bool setFillColor(const std::string& color, int instance);
693
            /**
205 andreas 694
             * @brief setTextColor set the text color.
60 andreas 695
             * Set the text color to the specified color. Only if the
205 andreas 696
             * specified text color is not the same as the current color. It
697
             * redraws the button if the color changed.
60 andreas 698
             * Note: Color can be assigned by color name (without spaces),
699
             * number or R,G,B value (RRGGBB or RRGGBBAA).
700
             * @param color     the color
701
             * @param instance
702
             * The instance number involved.
703
             * @return
704
             * On error returns FALSE.
705
             */
706
            bool setTextColor(const std::string& color, int instance);
707
            /**
205 andreas 708
             * @brief setTextColorOnly set the text color only.
709
             * Set the text color to the specified color. Only if the
710
             * specified text color is not the same as the current color.
711
             * Note: Color can be assigned by color name (without spaces),
712
             * number or R,G,B value (RRGGBB or RRGGBBAA).
713
             * @param color     the color
714
             * @param instance
715
             * The instance number involved.
716
             * @return
717
             * On error returns FALSE.
718
             */
719
            bool setTextColorOnly(const std::string& color, int instance);
720
            /**
60 andreas 721
             * @brief setDrawOrder - Set the button draw order.
722
             * Determines what order each layer of the button is drawn.
723
             * @param order     the draw order
724
             * @param instance
725
             * The instance number involved.
726
             * @return
727
             * On error returns FALSE.
728
             */
729
            bool setDrawOrder(const std::string& order, int instance);
730
            /**
731
             * @brief setFeedback - Set the feedback type of the button.
732
             * ONLY works on General-type buttons.
733
             * @param fb    The feedback type
734
             * @return On error returns FALSE.
735
             */
736
            bool setFeedback(FEEDBACK feedback);
737
            /**
335 andreas 738
             * @brief setFeedback - Sets the feedback type.
739
             * This retrieves the feedback type of a button. Only if the button
740
             * is a general type one, a valid value is returned.
741
             *
742
             * @return The feedback type of a button.
743
             */
744
            FEEDBACK getFeedback();
745
            /**
60 andreas 746
             * Set a border to a specific border style associated with a border
747
             * value for those buttons with a defined address range.
748
             * @param style     The name of the border style
749
             * @param instance  -1 = style for all instances
106 andreas 750
             * > 0 means the style is valid only for this instance.
60 andreas 751
             */
752
            bool setBorderStyle(const std::string& style, int instance=-1);
753
            /**
332 andreas 754
             * Set a border to a specific border style associated with a border
755
             * value for those buttons with a defined address range.
756
             * @param style     The index number of the border style
757
             * @param instance  -1 = style for all instances
758
             * > 0 means the style is valid only for this instance.
759
             */
760
            bool setBorderStyle(int style, int instance=-1);
761
            /**
106 andreas 762
             * Retrieves the border style, if any, of the instance \p instance
763
             * and returns it.
764
             * @param instance  The instance from where the border style is
765
             *                  wanted. This value must be between 1 and the
766
             *                  number of available instances.
767
             * @return The border style if there is any or an empty string.
768
             */
769
            std::string getBorderStyle(int instance=-1);
770
            /**
60 andreas 771
             * Set the bargraph upper limit. Range = 1 to 65535.
772
             * @param limit the new limit
773
             * @return TRUE on success.
774
             */
775
            bool setBargraphUpperLimit(int limit);
776
            /**
777
             * Set the bargraph lower limit. Range = 1 to 65535.
778
             * @param limit the new limit
779
             * @return TRUE on success.
780
             */
781
            bool setBargraphLowerLimit(int limit);
782
            /**
108 andreas 783
             * Change the bargraph slider color or joystick cursor color.
784
             * A user can also assign the color by Name and R,G,B value
785
             * (RRGGBB or RRGGBBAA).
786
             * @param color     The color value.
787
             * @return TRUE on success.
788
             */
789
            bool setBargraphSliderColor(const std::string& color);
790
            /**
361 andreas 791
             * Set the name of the bargraph slider name or the joystick cursor
792
             * name.
793
             * @param name  The name of the slider/cursor.
794
             * @return TRUE on success.
795
             */
796
            bool setBargraphSliderName(const std::string& name);
797
            /**
224 andreas 798
             * Sets the input mask for the text area. This method has no
799
             * effect on any non input button.
800
             * @param mask  The mask.
801
             * @return If all mask letters are valid it returns TRUE.
802
             */
803
            bool setInputMask(const std::string& mask);
804
            /**
805
             * Returns the input mask of the button.
806
             * @rturn The input mask of the text area, if there is any. If
807
             * there is no input mask present, an empty string is returned.
808
             */
809
            std::string& getInputMask() { return im; }
810
            /**
3 andreas 811
             * Read the images, if any, from files and create an image. If there
812
             * are no files, draw the image as defined.
14 andreas 813
             *
40 andreas 814
             * @param force
815
             * This parameter forces the function to reload the image. This is
816
             * necessary if the image of the button was changed by a command.
817
             * This parameter is optional. Defaults to FALSE.
818
             *
14 andreas 819
             * @return
820
             * On error returns FALSE.
3 andreas 821
             */
40 andreas 822
            bool createButtons(bool force = false);
4 andreas 823
            /**
53 andreas 824
             * Register a callback function to display a ready image. This
825
             * function is used for nearly every kind of button or bargraph.
826
             * It is up to the surface to bring the buttons to screen.
4 andreas 827
             */
298 andreas 828
            void registerCallback(std::function<void (ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough)> displayButton)
4 andreas 829
            {
830
                _displayButton = displayButton;
831
            }
53 andreas 832
            /**
833
             * Register a callback function to display a video on a special
834
             * button. It is up to the surface to display a video. So the
835
             * callback passes only the size, position and the url together
836
             * with a user name and password, if there is one.
837
             */
21 andreas 838
            void regCallPlayVideo(std::function<void (ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw)> playVideo) { _playVideo = playVideo; };
4 andreas 839
            /**
198 andreas 840
             * Registers a callback function to get the content of a list.
841
             * This function is called to get from the parent the content of
842
             * a list.
843
             */
200 andreas 844
            void regCallListContent(std::function<std::vector<std::string>(ulong handle, int ap, int ta, int ti, int rows, int columns)> getListCtnt) { _getListContent = getListCtnt; }
198 andreas 845
            /**
200 andreas 846
             * Registers a callback function to get the global settings of the
847
             * global page/subpage.
848
             */
849
            void regCallGlobalSettings(std::function<void (TButton *button)> getGlobalSettings) { _getGlobalSettings = getGlobalSettings; };
850
            /**
198 andreas 851
             * Registers a callback function to get the content of a particular
852
             * row of the list. This function is called for each row detected
853
             * in a list. If a row contains more than one column then the
854
             * columns are separated by a "|" symbol.
855
             */
199 andreas 856
            void regCallListRow(std::function<std::string(int ti, int row)> getListRow) { _getListRow = getListRow; }
198 andreas 857
            /**
266 andreas 858
             * @brief Registers a callback which will be called on every button
859
             * press.
860
             * This is used for system buttons to catch the keyboard keys.
271 andreas 861
             *
266 andreas 862
             * @param buttonPress The function pointer.
863
             */
268 andreas 864
            void regCallButtonPress(std::function<void(int channel, uint handle, bool pressed)> buttonPress) { _buttonPress = buttonPress; }
266 andreas 865
            /**
4 andreas 866
             * Make a pixel array and call the callback function to display the
867
             * image. If there is no callback function registered, nothing
868
             * happens.
15 andreas 869
             * This method draws a general button. It is used for most
870
             * specialized buttons too.
14 andreas 871
             *
15 andreas 872
             * @param instance
873
             * Optional. The instance of the button to draw. If the base
874
             * instance should be drawn, the parameter can be omitted.
875
             *
876
             * @param show
877
             * Optional. By defualt TRUE. If set to FALSE, the button image is
878
             * not send to GUI. The image is available in the variable
879
             * "mLastImage" immediately after ending the method.
880
             *
300 andreas 881
             * @param subview
882
             * Optional. If this is set to true, an internal marker is set to
883
             * mark the button as part of a subview. If it is pressed, it calls
884
             * another function to show the changed state.
885
             *
14 andreas 886
             * @return
887
             * On error returns FALSE.
4 andreas 888
             */
300 andreas 889
            bool drawButton(int instance=0, bool show=true, bool subview=false);
6 andreas 890
            /**
50 andreas 891
             * Creates a pixel array and holds it for access through a callback
892
             * function which receives this class as a whole. The callback
893
             * function displays a keyboard and handles input to this text area.
894
             * The created image can be obtained by calling the function
895
             * getLastImage().
896
             *
897
             * @param instance
898
             * Optional. The instance of the button to draw. If the base
899
             * instance should be drawn, the parameter can be omitted.
900
             *
901
             * @param show
902
             * Optional. By defualt TRUE. If set to FALSE, the button image is
903
             * not send to GUI. The image is available in the variable
904
             * "mLastImage" immediately after ending the method.
905
             *
906
             * @return
907
             * On error returns FALSE.
908
             */
909
            bool drawTextArea(int instance=0);
910
            /**
15 andreas 911
             * Method to draw a multistate animated button. It creates a thread
912
             * with a timer and starts an animation by drawing every instance in
913
             * the defined order.
914
             *
915
             * @return
916
             * On error returns FALSE.
917
             */
918
            bool drawButtonMultistateAni();
919
            /**
920
             * Draws a normal bargraph with an ON and OFF state. Takes care
921
             * about cameleon images. If registered, it calls a callback
922
             * function to the GUI to display the ready image.
923
             *
924
             * @param instance
925
             * The instance of the bargraph to draw. This value must be in the
926
             * range of 0 to "stateCount".
927
             *
928
             * @param level
929
             * This is the level to show on the bargraph. It must be a value
930
             * the range of "rl" (range low) and "rh" (range high). A lower
931
             * value than "rl" is interpreted as "rl" and a value higher than
932
             * "rh" is interpreted as "rh".
933
             *
934
             * @param show
935
             * Optional. By default TRUE. If set to FALSE, the bargraph image is
936
             * not send to GUI. The image is available in the variable
937
             * "mLastImage" immediately after ending the method.
938
             *
939
             * @return
940
             * On error returns FALSE.
941
             */
942
            bool drawBargraph(int instance, int level, bool show=true);
943
            /**
38 andreas 944
             * @brief drawMultistateBargraph draws a bargraph comparable to a button.
945
             * This method draws a multistate bargraph. This is like many
946
             * buttons in one. But they behave like a bargraph. This means, that
947
             * it depends on the level how many buttons are ON and which are OFF.
948
             *
949
             * @param level The level. This defines how many buttons are at ON state.
950
             * @param show  If this is false, the button is invisible.
951
             * @return If everything went well, TRUE is returned. If an error
952
             * occurred it returns FALSE.
953
             */
954
            bool drawMultistateBargraph(int level, bool show=true);
955
            /**
387 andreas 956
             * @brief Invert bargraph
957
             * This method sets or unsets inverting bargraphs.
958
             *
959
             * @param invert    TRUE: Invert the bargraph.
960
             */
961
            void setBargraphInvert(bool invert);
962
            /**
963
             * @brief Change ramp down time
964
             *
965
             * @param t     Time in 1/10 seconds
966
             */
967
            void setBargraphRampDownTime(int t);
968
            /**
969
             * @brief Change ramp up time
970
             *
971
             * @param t     Time in 1/10 seconds
972
             */
973
            void setBargraphRampUpTime(int t);
974
            /**
975
             * @brief Set the increment step factor
976
             *
977
             * @param inc   Step increment.
978
             */
979
            void setBargraphDragIncrement(int inc);
980
            /**
200 andreas 981
             * Draws the background and the frame, if any, of the box. It takes
982
             * the number of rows in account.
983
             *
984
             * @param show  Optional: If set to false the button will not be
985
             * shown.
986
             * @return If everything went well, TRUE is returned. If an error
987
             * occurred it returns FALSE.
988
             */
989
            bool drawList(bool show=true);
990
            /**
6 andreas 991
             * Show the button with it's current state.
992
             */
993
            void show();
11 andreas 994
            /**
15 andreas 995
             * Hide the button. In case of an animated button, the animation is
996
             * stopped.
997
             *
998
             * @param total
999
             * Optional. When set to TRUE, a transparent button is displayed.
1000
             */
1001
            void hide(bool total=false);
1002
            /**
1003
             * This method sends the image together with all data to the GUI,
1004
             * where it will be shown. The variable mLastImage must not be
1005
             * empty for the method to succeed.
1006
             */
1007
            void showLastButton();
1008
            /**
11 andreas 1009
             * Handle a mouse click.
15 andreas 1010
             *
38 andreas 1011
             * @param x
1012
             * The x coordinate of the mouse press
1013
             *
1014
             * @param y
1015
             * The y coordinate of the mouse press
1016
             *
15 andreas 1017
             * @param pressed
1018
             * TRUE = Button was pressed, FALSE = Button was released.
1019
             *
1020
             * @return
1021
             * TRUE = Button was clickable and processed. FALSE = Button was not
1022
             * clickable.
11 andreas 1023
             */
15 andreas 1024
            bool doClick(int x, int y, bool pressed);
43 andreas 1025
            /**
1026
             * Creates a button but uses the informations in the structure
1027
             * instead of reading it from a file.
1028
             *
309 andreas 1029
             * @param bt    A structure containing all information to create a button.
43 andreas 1030
             * @return On success returns TRUE, else FALSE.
1031
             */
1032
            bool createSoftButton(const EXTBUTTON_t& bt);
50 andreas 1033
            /**
1034
             * Returns the image in mLastImage as a pixel array with the defined
1035
             * dimensions.
1036
             *
1037
             * @return A typedef IMAGE_t containing the ingredentials of the
1038
             * image. It contains a pointer with allocated memory holding the
1039
             * image. This buffer must NOT be freed!
1040
             */
1041
            BITMAP_t getLastImage();
1042
            /**
289 andreas 1043
             * Returns the image in mLastImage as a TBitmap with the defined
1044
             * dimensions.
1045
             *
1046
             * @return TBitmap class
1047
             */
1048
            TBitmap getLastBitmap();
1049
            /**
50 andreas 1050
             * Returns the fint the button uses.
1051
             * @return A structure containing the informations for the font
1052
             * to load.
1053
             */
1054
            FONT_T getFont();
1055
            /**
1056
             * Returns the style of the font.
1057
             * @return The font style.
1058
             */
51 andreas 1059
            FONT_STYLE getFontStyle();
146 andreas 1060
            /**
1061
             * Tests the button if it is clickable.
1062
             * @return TRUE if it is clickable, FALSE otherwise.
1063
             */
154 andreas 1064
            bool isClickable(int x = -1, int y = -1);
192 andreas 1065
            /**
1066
             * Returns the password character.
1067
             *
1068
             * @return An integer representing the password character. If there
1069
             * is no password character 0 is returned.
1070
             */
1071
            uint getPasswordChar() { return (pc.empty() ? 0 : pc[0]); }
200 andreas 1072
            /**
268 andreas 1073
             * Set the level of a bargraph or a multistate bargraph.
1074
             * The method checks the level whether it is inside the defined
1075
             * range or not.
1076
             *
1077
             * @param level     The new level value
1078
             */
1079
            void setBargraphLevel(int level);
1080
            /**
271 andreas 1081
             * @brief invalidate - Mark a button internal as hidden.
1082
             * This method does not call any surface methods and marks the
1083
             * the button only internal hidden. The graphic remains.
1084
             *
1085
             * @return TRUE on success.
1086
             */
1087
            bool invalidate();
1088
            /**
332 andreas 1089
             * Returns the draw order of the elements of a button.
1090
             *
1091
             * @param instance  The button instance. This value must be >= 0.
1092
             * @return The draw order as a string with a length of 10.
1093
             */
1094
            std::string& getDrawOrder(int instance);
1095
            /**
200 andreas 1096
             * Returns the rows of the list in case this button is a list.
1097
             * Otherwise an empty list is returned.
1098
             *
1099
             * @return A vector list containing the rows of the list.
1100
             */
1101
            std::vector<std::string>& getListContent() { return mListContent; }
225 andreas 1102
            /**
1103
             * @brief Listview Data Source
1104
             * This command sets the data source to drive the Listview entries.
1105
             * Note that this command only configures the data source it does
1106
             * not actually cause the data to be fetched. The ^LVR refresh
1107
             * command must be issued to load the data.
1108
             *
1109
             * @param source    A string containing the source for list data.
1110
             * This can be either a URL or the name of a dynamic resource data.
1111
             * @param configs   One or more configurations defining the layout
1112
             * of the source.
1113
             *
1114
             * @return If the source is valid it returns TRUE.
1115
             */
1116
            bool setListSource(const std::string &source, const std::vector<std::string>& configs);
1117
            /**
1118
             * Returns the set source for list data.
1119
             *
1120
             * @return A string containg the source or and empty string if no
1121
             * valid source was set.
1122
             */
1123
            std::string& getListSource() { return listSource; }
227 andreas 1124
            /**
1125
             * Sets a filter for the data of a listView.
1126
             *
1127
             * @param filter    A string used as a filter for the data.
1128
             *
1129
             * @return Returns true if the string was evaluated ok.
1130
             */
1131
            bool setListSourceFilter(const std::string& filter);
1132
            /**
1133
             * Returns the filter string for a listView data source.
1134
             *
1135
             * @return The filter string.
1136
             */
230 andreas 1137
            std::string& getListSourceFilter() { return listFilter; }
1138
            /**
1139
             * Sets the listView event number. A value of 0 turns off event
1140
             * reporting. Any other number activates the events. Currently are
1141
             * only refresh events are reported.
1142
             *
1143
             * @param num   The event number.
1144
             */
1145
            void setListViewEventNumber(int num) { listEvNum = num; }
1146
            /**
1147
             * Returns the event number of the listView. By default this number
1148
             * is 1401. But with the command ^LVE this number can be changed.
1149
             *
1150
             * @return The event number of the listView.
1151
             */
1152
            int getListViewEventNumber() { return listEvNum; };
233 andreas 1153
            void setListViewColumns(int cols);
1154
            int getListViewColumns() { return tc; }
1155
            void setListViewLayout(int layout);
1156
            int getListViewLayout() { return listLayout; }
1157
            void setListViewComponent(int comp);
1158
            int getListViewComponent() { return listComponent; }
1159
            void setListViewCellheight(int height, bool percent=false);
1160
            int getListViewCellheight() { return tj; }
1161
            void setListViewP1(int p1);
1162
            int getListViewP1() { return listViewP1; }
1163
            void setListViewP2(int p2);
1164
            int getListViewP2() { return listViewP2; }
1165
            void setListViewColumnFilter(bool filter) { listViewColFiler = filter; }
1166
            bool getListViewColumnFilter() { return listViewColFiler; }
1167
            void setListViewFilterHeight(int height, bool percent=false);
1168
            int getListViewFilterHeight() { return listViewColFilterHeight; }
1169
            void setListViewAlphaScroll(bool alpha) { listAlphaScroll = alpha; }
1170
            bool getListViewAlphaScroll() { return listAlphaScroll; }
1171
            void setListViewFieldMap(const std::map<std::string,std::string>& map) { listFieldMap = map; }
1172
            std::map<std::string,std::string>& getListViewFieldMap() { return listFieldMap; }
1173
            void listViewNavigate(const std::string& command, bool select=false);
1174
            void listViewRefresh(int interval, bool force=false);
1175
            void listViewSortData(const std::vector<std::string>& columns, LIST_SORT order, const std::string& override);
3 andreas 1176
 
1177
        protected:
1178
            BUTTONTYPE getButtonType(const std::string& bt);
1179
            FEEDBACK getButtonFeedback(const std::string& fb);
10 andreas 1180
            SkBitmap drawImageButton(SkBitmap& imgRed, SkBitmap& imgMask, int width, int height, SkColor col1, SkColor col2);
99 andreas 1181
            SkBitmap combineImages(SkBitmap& base, SkBitmap& alpha, SkColor col);
3 andreas 1182
 
15 andreas 1183
            void funcTimer(const amx::ANET_BLINK& blink);
1184
            void funcNetwork(int state);
94 andreas 1185
            void funcResource(const RESOURCE_T *resource, const std::string& url, BITMAP_CACHE bc, int instance);
247 andreas 1186
#ifdef __ANDROID__
38 andreas 1187
            void funcBattery(int level, bool charging, int chargeType);
247 andreas 1188
#endif
1189
#if TARGET_OS_SIMULATOR || TARGET_OS_IOS
1190
            void funcBattery(int level, int state);
1191
#endif
36 andreas 1192
            void funcNetworkState(int level);
15 andreas 1193
 
3 andreas 1194
        private:
298 andreas 1195
            std::function<void (ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough)> _displayButton{nullptr};
21 andreas 1196
            std::function<void (ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw)> _playVideo{nullptr};
199 andreas 1197
            std::function<std::vector<std::string>(ulong handle, int ap, int ta, int ti, int rows, int columns)> _getListContent{nullptr};
1198
            std::function<std::string(int ti, int row)> _getListRow{nullptr};
200 andreas 1199
            std::function<void (TButton *button)> _getGlobalSettings{nullptr};
268 andreas 1200
            std::function<void (int channel, uint handle, bool pressed)> _buttonPress{nullptr};
6 andreas 1201
 
292 andreas 1202
            // Mutexes used in class
1203
            std::mutex mutex_button;
293 andreas 1204
            std::mutex mutex_click;
292 andreas 1205
            std::mutex mutex_text;
1206
            std::mutex mutex_bargraph;
1207
            std::mutex mutex_sysdraw;
1208
            std::mutex mutex_bmCache;
1209
 
283 andreas 1210
            std::string buttonTypeToString();
40 andreas 1211
            POSITION_t calcImagePosition(int width, int height, CENTER_CODE cc, int number, int line = 0);
99 andreas 1212
            IMAGE_SIZE_t calcImageSize(int imWidth, int imHeight, int instance, bool aspect=false);
4 andreas 1213
            int getBorderSize(const std::string& name);
1214
            void calcImageSizePercent(int imWidth, int imHeight, int btWidth, int btHeight, int btFrame, int *realX, int *realY);
10 andreas 1215
            SkColor baseColor(SkColor basePix, SkColor maskPix, SkColor col1, SkColor col2);
7 andreas 1216
            TEXT_EFFECT textEffect(const std::string& effect);
8 andreas 1217
            int numberLines(const std::string& str);
1218
            SkRect calcRect(int width, int height, int pen);
15 andreas 1219
            void runAnimation();    // Method started as thread for button animation
38 andreas 1220
            void runAnimationRange(int start, int end, ulong step);     // Method started as thread for a limited time
99 andreas 1221
            bool drawAlongOrder(SkBitmap *imgButton, int instance);
3 andreas 1222
 
8 andreas 1223
            void getDrawOrder(const std::string& sdo, DRAW_ORDER *order);
1224
            bool buttonFill(SkBitmap *bm, int instance);
1225
            bool buttonBitmap(SkBitmap *bm, int instance);
97 andreas 1226
            bool buttonDynamic(SkBitmap *bm, int instance, bool show, bool *state=nullptr);
8 andreas 1227
            bool buttonIcon(SkBitmap *bm, int instance);
1228
            bool buttonText(SkBitmap *bm, int instance);
1229
            bool buttonBorder(SkBitmap *bm, int instance);
15 andreas 1230
            bool isPixelTransparent(int x, int y);
1231
            bool barLevel(SkBitmap *bm, int instance, int level);
1232
            bool makeElement(int instance=-1);
21 andreas 1233
            bool loadImage(SkBitmap *bm, SkBitmap& image, int instance);
15 andreas 1234
            void _TimerCallback(ulong counter);
21 andreas 1235
            void _imageRefresh(const std::string& url);
1236
            static THR_REFRESH_t *_addResource(TImageRefresh *refr, ulong handle, ulong parent, int bi);
1237
            static THR_REFRESH_t *_findResource(ulong handle, ulong parent, int bi);
69 andreas 1238
            int calcLineHeight(const std::string& text, SkFont& font);
66 andreas 1239
            bool textEffect(SkCanvas *canvas, sk_sp<SkTextBlob>& blob, SkScalar startX, SkScalar startY, int instance);
69 andreas 1240
            std::string getFormatString(TEXT_ORIENTATION to);
71 andreas 1241
            bool checkForSound();
79 andreas 1242
            bool scaleImage(SkBitmap *bm, double scaleWidth, double scaleHeight);
1243
            bool stretchImageWidth(SkBitmap *bm, int width);
1244
            bool stretchImageHeight(SkBitmap *bm, int height);
157 andreas 1245
            bool stretchImageWH(SkBitmap *bm, int width, int height);
161 andreas 1246
            SkBitmap colorImage(SkBitmap& base, SkBitmap& alpha, SkColor col, SkColor bg=0, bool useBG=false);
1247
            SkBitmap retrieveBorderImage(const std::string& bs, const std::string& bsa, SkColor color, SkColor bgColor);
99 andreas 1248
            bool retrieveImage(const std::string& path, SkBitmap *image);
1249
            SkBitmap drawSliderButton(const std::string& slider, SkColor col);
8 andreas 1250
 
94 andreas 1251
            void addToBitmapCache(BITMAP_CACHE& bc);
1252
            BITMAP_CACHE& getBCentryByHandle(ulong handle, ulong parent);
1253
            BITMAP_CACHE& getBCentryByBI(int bIdx);
1254
            void removeBCentry(std::vector<BITMAP_CACHE>::iterator *elem);
1255
            void setReady(ulong handle);
97 andreas 1256
            void setInvalid(ulong handle);
94 andreas 1257
            void setBCBitmap(ulong handle, SkBitmap& bm);
1258
            void showBitmapCache();
159 andreas 1259
            uint32_t pixelMix(uint32_t s, uint32_t d, uint32_t a, PMIX mix);
298 andreas 1260
            bool isPassThrough();
94 andreas 1261
 
3 andreas 1262
            BUTTONTYPE type;
1263
            int bi{0};              // button ID
1264
            std::string na;         // name
1265
            std::string bd;         // Description --> ignored
1266
            int lt{0};              // pixel from left
1267
            int tp{0};              // pixel from top
1268
            int wt{0};              // width
1269
            int ht{0};              // height
1270
            int zo{0};              // Z-Order
1271
            std::string hs;         // bounding, ...
1272
            std::string bs;         // Border style (circle, ...)
41 andreas 1273
            FEEDBACK fb{FB_NONE};   // Feedback type (momentary, ...)
14 andreas 1274
            int ap{1};              // Address port (default: 1)
3 andreas 1275
            int ad{0};              // Address channel
1276
            int ch{0};              // Channel number
14 andreas 1277
            int cp{1};              // Channel port (default: 1)
1278
            int lp{1};              // Level port (default: 1)
3 andreas 1279
            int lv{0};              // Level code
193 andreas 1280
            int ta{0};              // Listbox table channel
199 andreas 1281
            int ti{0};              // Listbox table index number of rows (all rows have this number in "cp")
193 andreas 1282
            int tr{0};              // Listbox number of rows
1283
            int tc{0};              // Listbox number of columns
1284
            int tj{0};              // Listbox row height
1285
            int tk{0};              // Listbox preferred row height
1286
            int of{0};              // Listbox list offset: 0=disabled/1=enabled
1287
            int tg{0};              // Listbox managed: 0=no/1=yes
301 andreas 1288
            int so{1};              // String output port
1289
            int co{1};              // Command port
149 andreas 1290
            std::vector<std::string> cm;         // Commands to send on each button hit
3 andreas 1291
            std::string dr;         // Level "horizontal" or "vertical"
1292
            int va{0};
163 andreas 1293
            int stateCount{0};      // State count with multistate buttons (number of states)
3 andreas 1294
            int rm{0};              // State count with multistate buttons?
15 andreas 1295
            int nu{2};              // Animate time up
1296
            int nd{2};              // Animate time down
3 andreas 1297
            int ar{0};              // Auto repeat (1 = true)
1298
            int ru{0};              // Animate time up (bargraph)
1299
            int rd{0};              // Animate time down (bargraph)
1300
            int lu{0};              // Animate time up (Bargraph)
1301
            int ld{0};              // Animate time down (Bargraph)
387 andreas 1302
            int rv{0};              // Bargraph: repeat interval?
3 andreas 1303
            int rl{0};              // Range low
1304
            int rh{0};              // Range high
1305
            int ri{0};              // Bargraph inverted (0 = normal, 1 = inverted)
1306
            int rn{0};              // Bargraph: Range drag increment
193 andreas 1307
            int ac_di{0};           // (guess) Direction of text: 0 = left to right (default); 1 = right to left
51 andreas 1308
            int hd{0};              // 1 = Hidden, 0 = Normal visible
1309
            int da{0};              // 1 = Disabled, 0 = Normal active
49 andreas 1310
            std::string lf;         // Bargraph function: empty = display only, active, active centering, drag, drag centering
3 andreas 1311
            std::string sd;         // Name/Type of slider for a bargraph
1312
            std::string sc;         // Color of slider (for bargraph)
1313
            int mt{0};              // Length of text area (0 = 2000)
1314
            std::string dt;         // "multiple" textarea has multiple lines, else single line
1315
            std::string im;         // Input mask of a text area
279 andreas 1316
            int st{0};              // SubPageView: ID of subview list
1317
            int ws{0};              // SubPageView: Wrap subpages; 1 = YES
1318
            std::string on;         // SubPageView: direction: vert = vertical, if empty: horizontal which is default
1319
            int sa{0};              // SubPageView: Percent of space between items in list
1320
            int dy{0};              // SubPageView: Allow dynamic reordering; 1 = YES
1321
            int rs{0};              // SubPageView: Reset view on show; 1 = YES
300 andreas 1322
            int ba{0};              // SubPageView: 1 = Scrollbar is visible, 0 = No scrollbar visible
1323
            int bo{0};              // SubPageView: Scrollbar offset in pixels; Only valid if "ba" > 0
1324
            std::string we;         // SubPageView: Anchor position: Empty = Center, "l/t" = left/top, "r/b" = right/bottom
51 andreas 1325
            std::string pc;         // Password character for text area
3 andreas 1326
            std::string op;         // String the button send
14 andreas 1327
            bool visible{true};     // TRUE=Button is visible
3 andreas 1328
            std::vector<PUSH_FUNC_T> pushFunc;  // Push functions: This are executed on button press
1329
            std::vector<SR_T> sr;   // The elements the button consists of
225 andreas 1330
            // ListView settings (G5)
1331
            std::string listSource; // Defines the data source for a list.
230 andreas 1332
            int listEvNum{1401};       // ListView event number.
225 andreas 1333
            std::string listFilter; // ListView filter string.
233 andreas 1334
            int listComponent{0};   // ListView component
225 andreas 1335
            int listLayout{0};      // ListView layout.
1336
            std::map<std::string,std::string> listFieldMap; // Maps the fields from the source to the columns of the list
256 andreas 1337
//            LIST_SORT listSort{LIST_SORT_NONE}; // ListView sort algorithm
225 andreas 1338
            std::string listSortOverride;   // A SQL ORDER BY command like sort option. Only valid if listStort == LIST_SORT_OVERRIDE
227 andreas 1339
            std::string listSourceUser;   // The user name (optional)
1340
            std::string listSourcePass;   // The password (optional)
1341
            bool listSourceCsv{false};  // TRUE = Source of listView is in CSV data
1342
            bool listSourceHasHeader{false};    // TRUE = The listView data has a had line which must be ignored.
233 andreas 1343
            int listViewP1{0};      // ListView layout percentage 1
1344
            int listViewP2{0};      // ListView layout percentage 2
1345
            bool listViewColFiler{false};   // ListView column filter state (TRUE = on)
1346
            int listViewColFilterHeight{0}; // ListView column filter height
1347
            bool listAlphaScroll{false};    // ListView alpha scroll state (TRUE = scrollbar visible)
41 andreas 1348
 
7 andreas 1349
            TPalette *mPalette{nullptr}; // The color palette
3 andreas 1350
            // Image management
6 andreas 1351
            SkBitmap mLastImage;    // The last calculated image
5 andreas 1352
            ulong mHandle{0};       // internal used handle to identify button
7 andreas 1353
            int mParentHeight{0};   // The height of the parent page / subpage
1354
            int mParentWidth{0};    // The width of the parent page / subpage
16 andreas 1355
            bool mEnabled{true};    // By default a button is enabled (TRUE); FALSE = Button disabled
7 andreas 1356
            TFont *mFonts{nullptr}; // The font table
10 andreas 1357
            int mGlobalOO{-1};      // Opacity of the whole subpage, if any
14 andreas 1358
            int mActInstance{0};    // Active instance
8 andreas 1359
            DRAW_ORDER mDOrder[ORD_ELEM_COUNT];  // The order to draw the elements of a button
15 andreas 1360
            std::thread mThrAni;    // Thread handle for animation
21 andreas 1361
            std::thread mThrRes;    // A resouce (download of a remote image/video) running in background
38 andreas 1362
            std::atomic<bool> mAniRunning{false}; // TRUE = Animation is running
93 andreas 1363
            std::atomic<bool> mAniStop{false};  // If TRUE, the running animation will stop
15 andreas 1364
            int mLastLevel{0};      // The last level value for a bargraph
1365
            bool mSystemReg{false}; // TRUE = registered as system button
1366
            amx::ANET_BLINK mLastBlink; // This is used for the system clock buttons
21 andreas 1367
            TTimer *mTimer{nullptr};    // This is for buttons displaying the time or a date. It's a thread running in background.
1368
            static THR_REFRESH_t *mThrRefresh;  // If  we have a source to reread periodicaly, this starts a thread to do that.
38 andreas 1369
            ulong mAniRunTime{0};   // The time in milliseconds an animation should run. 0 = run forever.
94 andreas 1370
            BITMAP_CACHE mBCDummy;  // A dummy retuned in case no cache exists or the element was not found.
175 andreas 1371
            bool mChanged{true};    // TRUE=Something changed --> button must be redrawn
192 andreas 1372
            int mBorderWidth{0};    // If there is a border this is set to the pixels the border is using
200 andreas 1373
            std::vector<std::string> mListContent;  // The content of a list, if this button is one
300 andreas 1374
            bool mSubViewPart{false};   // TRUE = The button is part of a subview item.
309 andreas 1375
            int mCursorPosition{0}; // The cursor position if this is of type TEXT_INPUT
1376
            bool mHasFocus{false};  // If this is of type TEXT_INPUT this holds the focus state
332 andreas 1377
            std::string dummy;      // dummy string used to return an empty string.
3 andreas 1378
    };
1379
 
1380
    typedef struct BUTTONS_T
1381
    {
1382
        TButton *button{nullptr};
1383
        BUTTONS_T *previous{nullptr};
1384
        BUTTONS_T *next{nullptr};
1385
    } BUTTONS_T;
2 andreas 1386
}
1387
 
1388
#endif