forked from benwbooth/tvision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator.cc
138 lines (114 loc) · 3.22 KB
/
validator.cc
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
/*
* TVision example: how to use range validators in input lines
*
* Written by Sergio Sigala <sergio@sigala.it>
*/
#define Uses_TApplication
#define Uses_TButton
#define Uses_TCombo
#define Uses_TDeskTop
#define Uses_TDialog
#define Uses_TInputLine
#define Uses_TKeys
#define Uses_TLabel
#define Uses_TMemo
#define Uses_TMenuBar
#define Uses_TMenuItem
#define Uses_TPXPictureValidator
#define Uses_TRangeValidator
#define Uses_TScrollBar
#define Uses_TSubMenu
#define Uses_TStaticText
#include <tvision/tv.h>
const int cmOpenDialog = 100;
class Demo: public TApplication
{
public:
Demo();
void handleEvent(TEvent &event);
static TMenuBar *initMenuBar(TRect r);
};
class MyDialog: public TDialog
{
public:
MyDialog();
};
Demo::Demo(): TProgInit(&Demo::initStatusLine, &Demo::initMenuBar,
&Demo::initDeskTop)
{
}
void Demo::handleEvent(TEvent &event)
{
TApplication::handleEvent(event);
if (event.what == evCommand)
{
switch (event.message.command)
{
case cmOpenDialog:
{
MyDialog *d = new MyDialog;
executeDialog(d);
}
break;
default:
return;
}
clearEvent (event);
}
}
TMenuBar *Demo::initMenuBar(TRect r)
{
r.b.y = r.a.y + 1;
return new TMenuBar(r,
*new TSubMenu( "~F~ile", kbAltF, hcNoContext ) +
*new TMenuItem( "~D~ialog...", cmOpenDialog, kbNoKey, hcNoContext) +
newLine() +
*new TMenuItem( "E~x~it...", cmQuit, kbAltX, hcNoContext)
);
}
MyDialog::MyDialog():
TDialog(TRect(0, 0, 42, 16), "TValidator example"),
TWindowInit( &TDialog::initFrame )
{
TInputLine *line;
TScrollBar *bar;
TView *obj;
options |= ofCentered;
insert(obj = new TInputLine(TRect(23, 1, 40, 2), 40));
insert(new TLabel(TRect(1, 1, 22, 2), "No validator", obj));
//first approach: create the validator and next attach it to the
//input line
insert(obj = new TInputLine(TRect(23, 3, 27, 4), 3,
new TRangeValidator(1, 31)));
insert(new TLabel(TRect(1, 3, 22, 4), "Date style", obj));
insert(new TStaticText(TRect(27, 3, 28, 4), "/"));
//second approach: create the input line and then add the
//validator
insert(line = new TInputLine(TRect(28, 3, 32, 4), 3));
line->setValidator(new TRangeValidator(1, 12));
insert(new TStaticText(TRect(32, 3, 33, 4), "/"));
insert(new TInputLine(TRect(33, 3, 39, 4), 5,
new TRangeValidator(1950, 2050)));
insert(obj = new TInputLine(TRect(23, 5, 27, 6), 10,
new TPXPictureValidator("&&", False)));
insert(new TLabel(TRect(1, 5, 22, 6), "Two letters", obj));
insert(obj = new TInputLine(TRect(23, 7, 40, 8), 20,
new TPXPictureValidator("#####-###", True)));
insert(new TLabel(TRect(1, 7, 22, 8), "Fixed-length code", obj));
insert(obj = new TInputLine(TRect(23, 9, 40, 10), 10,
new TPXPictureValidator("*#", False)));
insert(new TLabel(TRect(1, 9, 22, 10), "Variable-length code", obj));
insert(obj = new TInputLine(TRect(23, 11, 40, 12), 20,
new TPXPictureValidator("##/##/####", True)));
insert(new TLabel(TRect(1, 11, 22, 12), "Another date style", obj));
insert(new TButton(TRect(1, 13, 11, 15), "O~K~", cmOK, bfDefault));
insert(new TButton(TRect(12, 13, 24, 15), "~C~ancel", cmCancel,
bfNormal));
selectNext(False);
}
int main()
{
Demo a;
a.run();
return 0;
}