-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStdGadgets.h
508 lines (318 loc) · 11.3 KB
/
StdGadgets.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
#ifndef STDGADGETS_H
#define STDGADGETS_H
/** @file */
#include <map>
#ifdef __amigaos__
#include <intuition/classes.h>
#elif defined(QT_GUI_LIB)
#include "Qt/QtGadgetSlider.h"
#include "Qt/QtGadgetTree.h"
#endif /* QT_GUI_LIB */
/* Forward declarations to reduce the # of includes required */
class CStdGadgetLayout;
class CWindow;
class MStdGadgetLayoutObserver;
class MStdGadgetSliderObserver;
class QBoxLayout;
class QLabel;
class QWidget;
#ifdef __amigaos__
/* A typedef to make usage of the map of item lists easier */
typedef std::map<int, List> ItemsMap;
#endif /* __amigaos__ */
/* Types of gadgets that can be created */
enum TStdGadgetType
{
EStdGadgetVerticalLayout, /* Vertical dynamic layout gadget */
EStdGadgetHorizontalLayout, /* Horizontal dynamic layout gadget */
EStdGadgetVerticalSlider, /* Vertical scroller */
EStdGadgetHorizontalSlider, /* Horizontal scroller */
EStdGadgetStatusBar, /* Status bar */
EStdGadgetTree /* Tree gadget */
};
/* The abstract base class used for all gadgets */
class CStdGadget
{
protected:
bool m_bHidden; /**< true if the gadget is hidden */
TInt m_iGadgetID; /**< Unique ID of the gadget */
TInt m_iX; /**< X and Y positions of the gadget, relative */
TInt m_iY; /**< to the top left hand corner of the client area */
TInt m_iWidth; /**< Width of the gadget in pixels */
TInt m_iHeight; /**< Height of the gadget in pixels */
TInt m_iMinHeight; /**< Minimum height of the gadget in pixels */
CStdGadgetLayout *m_poParentLayout; /**< Ptr to CStdGadgetLayout that owns this gadget */
CWindow *m_poParentWindow; /**< Ptr to window that owns this gadget */
enum TStdGadgetType m_iGadgetType; /**< Type of gadget */
#ifdef __amigaos__
Object *m_poGadget; /**< Ptr to underlying BOOPSI gadget */
#elif defined(QT_GUI_LIB)
QWidget *m_poGadget; /**< Ptr to underlying Qt widget */
#elif defined(WIN32)
HWND m_poGadget; /**< Ptr to the underlying Windows control */
#endif /* WIN32 */
public:
StdListNode<CStdGadget> m_oStdListNode; /**< Standard list node */
private:
void SetPosition(TInt a_iX, TInt a_iY);
protected:
virtual void SetSize(TInt a_iWidth, TInt a_iHeight);
public:
virtual ~CStdGadget();
/* Getters and setters */
#ifdef __amigaos__
Object *GetGadget()
{
return(m_poGadget);
}
#endif /* __amigaos__ */
TInt GetGadgetID()
{
return(m_iGadgetID);
}
enum TStdGadgetType GadgetType()
{
return(m_iGadgetType);
}
CWindow *GetParentWindow()
{
return(m_poParentWindow);
}
virtual void SetFocus() { };
virtual void SetVisible(bool a_bVisible);
bool Visible()
{
return(!m_bHidden);
}
virtual TInt X();
virtual TInt Y();
virtual TInt Width();
virtual TInt Height();
virtual TInt MinHeight();
virtual void Updated(ULONG /*a_ulData*/ = 0) { }
/* CStdGadgetLayout classe needs to be able to access this class's internals in order to */
/* manage the gadgets' positions etc. */
friend class CStdGadgetLayout;
};
/* A special gadget that can automatically layout other gadgets inside itself */
class CStdGadgetLayout : public CStdGadget
{
private:
static CStdGadgetLayout *m_poRethinker; /**< Pointer to layout gadget currently rethinking, if any */
TInt m_iWeight; /**< Weight of the layout gadget */
MStdGadgetLayoutObserver *m_poClient; /**< Pointer to client to notify when gadget changes */
StdList<CStdGadget> m_oGadgets; /**< List of gadgets added to the layout */
StdList<CStdGadgetLayout> m_oLayoutGadgets; /**< List of layout gadgets added to the layout */
#ifdef __amigaos__
Object *m_poLayout; /**< Pointer to the underlying Amiga OS gadget */
#elif defined(QT_GUI_LIB)
QBoxLayout *m_poLayout; /**< Pointer to the underlying Qt widget.
Usually this is stored in m_poGadget but unfortunately
QLayout derived objects do not derive from QWidget */
#endif /* QT_GUI_LIB */
public:
static TBool m_bEnableRefresh; /**< ETrue to disable immediate refresh when adding new
gadgets to the layout. Affects Amiga OS only */
private:
CStdGadgetLayout(CWindow *a_poParentWindow, CStdGadgetLayout *a_poParentLayout, TBool a_bVertical,
MStdGadgetLayoutObserver *a_poClient)
{
m_iGadgetType = (a_bVertical) ? EStdGadgetVerticalLayout : EStdGadgetHorizontalLayout;
m_poParentLayout = a_poParentLayout;
m_poParentWindow = a_poParentWindow;
m_poClient = a_poClient;
}
TInt Construct(bool a_bUseParentWindow);
CStdGadget *FindNativeGadget(void *a_pvGadget);
bool SendUpdate(void *a_pvGadget, ULONG a_ulData);
public:
StdListNode<CStdGadgetLayout> m_oStdListNode; /**< Standard list node */
static CStdGadgetLayout *New(CStdGadgetLayout *a_poParentLayout, TBool a_bVertical,
MStdGadgetLayoutObserver *a_poClient = nullptr, CWindow *a_poParentWindow = nullptr);
~CStdGadgetLayout();
void Attach(CStdGadget *a_poGagdet);
void Attach(CStdGadgetLayout *a_poLayoutGadget);
#ifdef __amigaos__
Object *GetLayout()
{
return(m_poLayout);
}
#elif defined(QT_GUI_LIB)
QBoxLayout *GetLayout()
{
return(m_poLayout);
}
#endif /* QT_GUI_LIB */
const StdList<CStdGadgetLayout> *GetLayoutGadgets()
{
return(&m_oLayoutGadgets);
}
TInt GetSpacing();
#ifdef __amigaos__
void ReAttach(CStdGadget *a_poGadget);
#endif /* __amigaos__ */
void remove(CStdGadget *a_poGagdet);
void remove(CStdGadgetLayout *a_poLayoutGadget);
void rethinkLayout();
bool SetWeight(TInt a_iWeight);
TInt Weight()
{
return(m_iWeight);
}
/* From CStdGadget */
virtual void SetFocus();
virtual TInt X();
virtual TInt Y();
virtual TInt Width();
virtual TInt Height();
virtual TInt MinHeight();
/* CWindow classe needs to be able to access this class's internals in order to map */
/* native events onto standard cross platform events */
friend class CWindow;
};
/* A class representing a slider or proportional gadget */
class CStdGadgetSlider : public CStdGadget
{
private:
TInt m_iMaxRange; /**< Maximum X/Y position of the slider */
TInt m_iPageSize; /**< Number of characters/lines/pixels per page */
TInt m_iPosition; /**< The position of the slider knob within the slider */
MStdGadgetSliderObserver *m_poClient; /**< Ptr to client to notify when gadget changes */
#ifdef QT_GUI_LIB
bool m_bSettingValue; /**< true if the slider's value is being changed */
CQtGadgetSlider m_oSlider; /**< Helper class for listening for signals */
#endif /* QT_GUI_LIB */
private:
#ifdef QT_GUI_LIB
CStdGadgetSlider(CStdGadgetLayout *a_poParentLayout, TBool a_bVertical, MStdGadgetSliderObserver *a_poClient, TInt a_iGadgetID)
: m_oSlider(this)
#else /* ! QT_GUI_LIB */
CStdGadgetSlider(CStdGadgetLayout *a_poParentLayout, TBool a_bVertical, MStdGadgetSliderObserver *a_poClient, TInt a_iGadgetID)
#endif /* ! QT_GUI_LIB */
{
m_iGadgetType = (a_bVertical) ? EStdGadgetVerticalSlider : EStdGadgetHorizontalSlider;
m_poParentLayout = a_poParentLayout;
m_poParentWindow = a_poParentLayout->GetParentWindow();
m_poClient = a_poClient;
m_iGadgetID = a_iGadgetID;
/* Set the default position to the top/left of the slider, which is 1, not 0 */
m_iPosition = 1;
}
TInt Construct();
bool CreateNative();
public:
static CStdGadgetSlider *New(CStdGadgetLayout *a_poParentLayout, TBool a_bVertical,
MStdGadgetSliderObserver *a_poClient, TInt a_iGadgetID);
~CStdGadgetSlider();
TInt MaxRange()
{
return(m_iMaxRange);
}
void SetPosition(TInt a_iPosition);
void SetRange(TInt a_iPageSize, TInt a_iMaxRange);
/* From CStdGadget */
#ifdef __amigaos__
void SetVisible(bool a_bVisible) override;
#endif /* __amigaos__ */
void Updated(ULONG a_ulData);
};
/* A class representing a status bar gadget */
class CStdGadgetStatusBar : public CStdGadget
{
private:
char **m_ppcPartsText; /**< Ptr to an array of ptrs to text strings */
TInt m_iNumParts; /**< Number of parts within the gadget */
#ifdef __amigaos__
Object **m_poPartsGadgets; /**< Ptr to an array of ptrs to parts labels */
#elif defined(QT_GUI_LIB)
QLabel **m_poPartsGadgets; /**< Ptr to an array of ptrs to parts labels */
#else /* ! QT_GUI_LIB */
TInt *m_piPartsOffsets; /**< Pointer to an array of offsets of the parts in
the status bar (as percentages) */
#endif /* ! QT_GUI_LIB */
private:
CStdGadgetStatusBar(CStdGadgetLayout *a_poParentLayout, TInt a_iGadgetID)
{
m_iGadgetType = EStdGadgetStatusBar;
m_poParentLayout = a_poParentLayout;
m_poParentWindow = a_poParentLayout->GetParentWindow();
m_iGadgetID = a_iGadgetID;
}
TInt Construct(TInt a_iNumParts, TInt *a_piPartsOffsets);
void SetSize(TInt a_iWidth, TInt a_iHeight);
public:
~CStdGadgetStatusBar();
static CStdGadgetStatusBar *New(CStdGadgetLayout *a_poParentLayout, TInt a_iNumParts, TInt *a_piPartsOffsets, TInt a_iGadgetID);
const char *GetText(TInt a_iPart);
void SetText(TInt a_iPart, const char *a_pccText);
};
/* A class representing a node in a tree gadget */
class CTreeNode
{
public:
StdListNode<CTreeNode> m_oStdListNode; /**< Standard list node */
std::string m_text; /**< Text to display in the tree gadget */
public:
CTreeNode(const char *a_text) : m_text(a_text) { };
};
/* A class representing an expandable and collapsible tree gadget */
class CStdGadgetTree : public CStdGadget
{
private:
int m_contentID; /**< The content ID of the file list currently in use */
int m_nextContentID; /**< The next content ID that will be assigned to a new list */
#ifdef __amigaos__
std::string m_title; /**< Persistent memory for the title string passed in */
struct List m_fileList; /**< Initial empty list of items in the tree */
ItemsMap m_itemsMap; /**< Map of the lists of items that can be displayed by the tree */
#elif defined(QT_GUI_LIB)
CQtGadgetTree m_tree; /**< Helper class for listening for signals */
std::map<int, QList<QTreeWidgetItem *>> m_itemsMap; /**< Map of the lists of items that can be displayed by the tree */
#endif /* QT_GUI_LIB */
protected:
#ifdef QT_GUI_LIB
CStdGadgetTree(CStdGadgetLayout *a_parentLayout, int a_gadgetID) : m_tree(this)
#else /* ! QT_GUI_LIB */
CStdGadgetTree(CStdGadgetLayout *a_parentLayout, int a_gadgetID)
#endif /* ! QT_GUI_LIB */
{
m_iGadgetID = a_gadgetID;
m_poParentLayout = a_parentLayout;
m_poParentWindow = a_parentLayout->GetParentWindow();
m_iGadgetType = EStdGadgetTree;
/* A content ID with a value of 0 has the special meaning of "remove content", so valid content IDs start at 1 */
m_nextContentID = 1;
#ifdef __amigaos__
NewList(&m_fileList);
#endif /* __amigaos__ */
}
~CStdGadgetTree();
int construct();
bool createNative();
int setContent(StdList<CTreeNode> &a_items);
public:
int getContentID()
{
return m_contentID;
}
std::string getSelectedItem();
void setContent(int a_contentID);
void setTitle(const std::string &a_title);
#ifdef __amigaos__
void SetVisible(bool a_bVisible) override;
#endif /* __amigaos__ */
};
/* Mixin class for the slider or proportional gadget to be able to notify its client */
/* when it has been updated */
class MStdGadgetSliderObserver
{
public:
virtual void SliderUpdated(CStdGadgetSlider *a_poGadget, TInt a_iPosition) = 0;
};
/* Mixin class for the layout gadget to be able to notify its client when it has been updated */
class MStdGadgetLayoutObserver
{
public:
virtual void Resize() = 0;
};
#endif /* ! STDGADGETS_H */