forked from sebastianbiallas/ht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htdialog.h
628 lines (540 loc) · 13.4 KB
/
htdialog.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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
/*
* HT Editor
* htdialog.h
*
* Copyright (C) 1999-2002 Stefan Weyergraf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __HTDIALOG_H__
#define __HTDIALOG_H__
#include <stdarg.h>
#include "htdebug.h"
#include "htobj.h"
#include "strtools.h"
#include "io/keyb.h"
/*
* CLASS ht_dialog
*/
#define ds_normal 0
#define ds_term_ok 1
#define ds_term_cancel 2
#define button_cancel 0
#define button_ok 1
#define button_yes button_ok
#define button_no 2
#define button_skip button_no
#define button_all 3
#define button_none 4
class ht_queued_msg: public Object {
public:
ht_view *target;
htmsg msg;
ht_queued_msg(ht_view *target, htmsg &msg);
};
class ht_dialog: public ht_window {
protected:
int state;
int return_val;
Queue *msgqueue;
/* overwritten */
virtual const char *defaultpalette();
ht_queued_msg *dequeuemsg();
public:
ht_dialog() {};
ht_dialog(BuildCtorArg&a): ht_window(a) {};
void init(Bounds *b, const char *desc, uint framestyle);
virtual void done();
/* overwritten */
virtual int aclone();
virtual void draw();
virtual void handlemsg(htmsg *msg);
/* new */
void queuemsg(ht_view *target, htmsg &msg);
virtual int getstate(int *return_val);
virtual int run(bool modal);
virtual void setstate(int state, int return_val);
};
/*
* CLASS ht_cluster
*/
class ht_cluster: public ht_dialog_widget {
protected:
ht_string_list *strings;
int sel;
int scount;
ht_key shortcuts[32];
/* overwritten */
virtual const char *defaultpalette();
public:
void init(Bounds *b, ht_string_list *strings);
virtual void done();
};
/*
* CLASS ht_checkboxes
*/
struct ht_checkboxes_data {
DDECL_UINT(state);
};
class ht_checkboxes: public ht_cluster {
protected:
uint32 state;
public:
void init(Bounds *b, ht_string_list *strings);
virtual void done();
/* overwritten */
virtual int datasize();
virtual void draw();
virtual void handlemsg(htmsg *msg);
virtual void getdata(ObjectStream &s);
virtual void setdata(ObjectStream &s);
};
/*
* CLASS ht_radioboxes
*/
struct ht_radioboxes_data {
DDECL_UINT(sel);
};
class ht_radioboxes: public ht_cluster {
public:
void init(Bounds *b, ht_string_list *strings);
virtual void done();
/* overwritten */
virtual int datasize();
virtual void draw();
virtual void handlemsg(htmsg *msg);
virtual void getdata(ObjectStream &s);
virtual void setdata(ObjectStream &s);
};
/*
* CLASS ht_inputfield
*/
class ht_inputfield;
struct ht_inputfield_data {
DDECL_UINT(textlen);
DDECL_PTR(const byte, text);
};
class ht_inputfield: public ht_dialog_widget {
protected:
byte **text, *textv;
byte **curchar, *curcharv;
byte **selstart, *selstartv;
byte **selend, *selendv;
int *textlen, textlenv;
int *maxtextlen, maxtextlenv;
int insert;
int ofs;
ht_inputfield *attachedto;
List *history;
void freebuf();
int insertbyte(byte *pos, byte b);
void select_add(byte *start, byte *end);
/* overwritten */
virtual const char *defaultpalette();
public:
void init(Bounds *b, int maxtextlen, List *history = NULL);
virtual void done();
/* overwritten */
virtual int datasize();
virtual void getdata(ObjectStream &s);
virtual void setdata(ObjectStream &s);
/* new */
void attach(ht_inputfield *inputfield);
void query(byte ***curchar, byte ***text, byte ***selstart, byte ***selend, int **textlen, int **maxtextlen);
void isetcursor(uint pos);
};
/*
* CLASS ht_strinputfield
*/
#define ht_strinputfield_data ht_inputfield_data
class ht_strinputfield: public ht_inputfield {
protected:
bool is_virgin; /* untouched except for cursor keys */
bool selectmode;
/* new */
void correct_viewpoint();
void history_dialog();
bool inputbyte(byte a);
bool setbyte(byte a);
public:
void init(Bounds *b, int maxtextlen, List *history = NULL);
virtual void done();
/* overwritten */
virtual void draw();
virtual void handlemsg(htmsg *msg);
virtual void receivefocus();
};
/*
* CLASS ht_hexinputfield
*/
#define ht_hexinputfield_data ht_inputfield_data
class ht_hexinputfield: public ht_inputfield {
protected:
int nib;
void correct_viewpoint();
public:
void init(Bounds *b, int maxtextlen);
virtual void done();
/* overwritten */
virtual void draw();
virtual void handlemsg(htmsg *msg);
virtual void receivefocus();
/* new */
void setnibble(byte a);
};
/*
* CLASS ht_button
*/
class ht_button: public ht_dialog_widget {
protected:
int value;
int pressed;
char *text;
char *magicchar;
ht_key shortcut1;
ht_key shortcut2;
/* overwritten */
virtual const char *defaultpalette();
public:
void init(Bounds *b, const char *text, int value);
virtual void done();
/* overwritten */
virtual void draw();
virtual void handlemsg(htmsg *msg);
virtual void getminbounds(int *width, int *height);
/* new */
virtual void push();
};
/*
* CLASS ht_listbox_title
*/
class ht_listbox;
class ht_listbox_title: public ht_dialog_widget {
public:
ht_listbox *listbox;
protected:
char **texts;
int cols;
/* overwritten */
virtual const char *defaultpalette();
public:
void init(Bounds *b);
virtual void done();
/* overwritten */
virtual void draw();
/* new */
virtual vcp getTextColor();
void setText(int cols, ...);
void setTextv(int cols, va_list arguments);
void update();
};
/*
* CLASS ht_listbox
*/
struct ht_listbox_data_internal {
void *top_ptr;
void *cursor_ptr;
};
struct ht_listbox_data {
DDECL_PTR(ht_listbox_data_internal, data);
};
#define LISTBOX_NORMAL 0
#define LISTBOX_QUICKFIND 1
class ht_listbox: public ht_dialog_widget {
protected:
public:
int cursor, pos, cached_count;
int visible_height;
void *e_top, *e_cursor;
int x;
char quickfinder[100];
char *qpos;
uint listboxcaps;
int cols;
int *widths;
ht_scrollbar *scrollbar;
bool mScrollbarEnabled;
ht_listbox_title *title;
public:
void init(Bounds *b, uint Listboxcaps=LISTBOX_QUICKFIND);
virtual void done();
void attachTitle(ht_listbox_title *title);
void adjustPosHack();
void adjustScrollbar();
virtual int calcCount() = 0;
void clearQuickfind();
virtual int cursorAdjust();
int cursorUp(int n);
int cursorDown(int n);
virtual int datasize();
virtual const char * defaultpalette();
virtual void draw();
virtual int estimateEntryPos(void *entry);
virtual void getdata(ObjectStream &s);
virtual void * getFirst() = 0;
virtual void * getLast() = 0;
virtual void * getNext(void *entry) = 0;
virtual void * getPrev(void *entry) = 0;
virtual const char * getStr(int col, void *entry) = 0;
void gotoItemByEntry(void *entry, bool clear_quickfind = true);
virtual void gotoItemByPosition(uint pos);
virtual void handlemsg(htmsg *msg);
virtual int numColumns();
virtual void * quickfind(const char *s) = 0;
virtual char * quickfindCompletition(const char *s);
virtual void redraw();
virtual void resize(int rw, int rh);
virtual bool selectEntry(void *entry);
virtual void setdata(ObjectStream &s);
virtual void stateChanged();
virtual void update();
void updateCursor();
virtual Object * vstate_create();
void vstate_save();
protected:
void rearrangeColumns();
};
/*
* CLASS ht_text_listbox
*/
#define ht_text_listbox_data ht_listbox_data
struct ht_text_listbox_item {
ht_text_listbox_item *next, *prev;
int id;
void *extra_data;
char *data[0];
};
struct ht_text_listbox_sort_order {
int col;
int (*compare_func)(const char *key_a, const char *key_b);
};
class ht_text_listbox: public ht_listbox {
protected:
int cols, keycol, count;
ht_text_listbox_item *first, *last;
int Cursor_adjust;
public:
void init(Bounds *b, int Cols=1, int Keycol=0, uint Listboxcaps=LISTBOX_QUICKFIND);
virtual void done();
virtual int calcCount();
virtual int compare_strn(const char *s1, const char *s2, int l);
virtual int compare_ccomm(const char *s1, const char *s2);
virtual int cursorAdjust();
void * getEntryByID(uint id);
virtual void * getFirst();
virtual void * getLast();
uint getID(void *entry);
void * getExtra(void *entry);
virtual void * getNext(void *entry);
virtual void * getPrev(void *entry);
virtual const char *getStr(int col, void *entry);
void insert_str(int id, const char *str, ...);
void insert_str(int id, const char **strs);
void insert_str_extra(int id, void *extra_data, const char *str, ...);
void insert_str_extra(int id, void *extra_data, const char **strs);
virtual int numColumns();
virtual void * quickfind(const char *s);
virtual char * quickfindCompletition(const char *s);
void sort(int count, ht_text_listbox_sort_order *so);
virtual void update();
protected:
virtual void clearAll();
virtual void freeExtraData(void *extra_data);
};
#define ht_itext_listbox_data ht_text_listbox_data
class ht_itext_listbox: public ht_text_listbox {
public:
void init(Bounds *b, int Cols=1, int Keycol=0);
virtual int compare_strn(const char *s1, const char *s2, int l);
virtual int compare_ccomm(const char *s1, const char *s2);
};
/*
* CLASS ht_statictext
*/
enum statictext_align {
align_left,
align_center,
align_right,
align_custom
};
#define ALIGN_CHAR_ESCAPE '\e'
#define ALIGN_CHAR_LEFT 'l'
#define ALIGN_CHAR_CENTER 'c'
#define ALIGN_CHAR_RIGHT 'r'
struct ht_statictext_linedesc {
int ofs;
int len;
char *text;
};
class ht_statictext: public ht_text {
protected:
char *text;
statictext_align align;
bool breaklines;
bool transparent;
/* overwritten */
virtual const char *defaultpalette();
public:
void init(Bounds *b, const char *text, statictext_align align, bool breaklines=true, bool transparent=false);
virtual void done();
/* overwritten */
virtual void draw();
virtual void settext(const char *text);
/* new */
virtual int gettext(char *text, int maxlen);
virtual vcp gettextcolor();
};
/*
* CLASS ht_listpopup_dialog
*/
struct ht_listpopup_dialog_data {
DDECL_UINT(cursor_pos);
DDECL_PTR(char, cursor_string);
};
class ht_listpopup_dialog: public ht_dialog {
protected:
ht_listbox *listbox;
virtual void init_text_listbox(Bounds *b);
public:
void init(Bounds *b, const char *desc);
/* overwritten */
virtual const char *defaultpalette();
virtual int datasize();
virtual void getdata(ObjectStream &s);
void insertstring(const char *string);
virtual void setdata(ObjectStream &s);
/* new */
void select_next();
void select_prev();
};
/*
* CLASS ht_listpopup
*/
#define ht_listpopup_data ht_listpopup_dialog_data
class ht_listpopup: public ht_statictext {
protected:
ht_listpopup_dialog *listpopup;
/* new */
int run_listpopup();
public:
void init(Bounds *b);
virtual void done();
/* overwritten */
virtual int datasize();
virtual void draw();
virtual vcp gettextcolor();
virtual void getdata(ObjectStream &s);
virtual int gettext(char *text, int maxlen);
virtual void handlemsg(htmsg *msg);
virtual void setdata(ObjectStream &s);
/* new */
void insertstring(const char *string);
};
/*
* CLASS ht_history_listbox
*/
class ht_history_listbox: public ht_listbox {
List *history;
public:
void init(Bounds *b, List *hist);
virtual int calcCount();
virtual void *getFirst();
virtual void *getLast();
virtual void *getNext(void *entry);
virtual void *getPrev(void *entry);
virtual const char *getStr(int col, void *entry);
virtual void handlemsg(htmsg *msg);
virtual void *quickfind(const char *s);
virtual char *quickfindCompletition(const char *s);
};
/*
* CLASS ht_history_popup_dialog
*/
class ht_history_popup_dialog: public ht_listpopup_dialog {
protected:
List *history;
virtual void init_text_listbox(Bounds *b);
public:
void init(Bounds *b, List *hist);
virtual void getdata(ObjectStream &s);
virtual void setdata(ObjectStream &s);
};
/*
* CLASS ht_label
*/
class ht_label: public ht_dialog_widget {
protected:
ht_view *connected;
char *text;
char *magicchar;
ht_key shortcut;
/* overwritten */
virtual const char *defaultpalette();
public:
void init(Bounds *b, const char *text, ht_view *connected);
virtual void done();
/* overwritten */
virtual void draw();
virtual void handlemsg(htmsg *msg);
};
/*
* CLASS ht_progress_indicator
*/
class ht_progress_indicator: public ht_window {
protected:
/* overwritten */
virtual const char *defaultpalette();
public:
ht_statictext *text;
void init(Bounds *b, const char *hint);
/* new */
void settext(const char *text);
};
/*
* CLASS ht_color_block
*/
struct ht_color_block_data {
DDECL_UINT(color);
};
#define cf_light 1
#define cf_transparent 2
class ht_color_block: public ht_dialog_widget {
protected:
int color;
int colors;
int flags;
/* overwritten */
virtual const char *defaultpalette();
public:
void init(Bounds *b, int selected, int flags);
/* overwritten */
virtual int datasize();
virtual void draw();
virtual void getdata(ObjectStream &s);
virtual void setdata(ObjectStream &s);
virtual void handlemsg(htmsg *msg);
};
/*
* CLASS ht_listbox_ptr
*/
class ht_listbox_ptr: public Object {
public:
ht_listbox *listbox;
ht_listbox_ptr(ht_listbox *aListbox)
: listbox(aListbox)
{
}
};
void center_bounds(Bounds *b);
#endif /* !__HTDIALOG_H__ */