This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
msgbox.cc
244 lines (204 loc) · 5.97 KB
/
msgbox.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
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
/*
* Turbo Vision - Version 2.0
*
* Copyright (c) 1994 by Borland International
* All Rights Reserved.
*
Modified by Robert H”hne to be used for RHIDE.
Modified by Salvador E. Tropea to add mfDontShowAgain, vsnprintf usage and
i18n. Added TValidator, etc.
*
*
*/
// SET: Moved the standard headers here because according to DJ
// they can inconditionally declare symbols like NULL
#include <stdarg.h>
#define Uses_string
#define Uses_stdio
#define Uses_MsgBox
#define Uses_TObject
#define Uses_TDialog
#define Uses_TStaticText
#define Uses_TRect
#define Uses_TButton
#define Uses_TProgram
#define Uses_TInputLine
#define Uses_TDeskTop
#define Uses_TLabel
#define Uses_TCheckBoxes
#define Uses_TSItem
#define Uses_TScreen
#define Uses_AllocLocal
#define Uses_TValidator
#define Uses_snprintf
#include <tv.h>
static const char *buttonName[] =
{
__("~Y~es"),
__("~N~o"),
__("~O~K"),
__("Cancel")
};
static ushort commands[] =
{
cmYes,
cmNo,
cmOK,
cmCancel
};
static const char *Titles[] =
{
__("Warning"),
__("Error"),
__("Information"),
__("Confirm")
};
ushort messageBoxRect( const TRect &r, const char *msg, ushort aOptions )
{
TDialog *dialog;
short i, x, buttonCount;
TView* buttonList[5];
ushort ccode;
int height=r.b.y-r.a.y;
TCheckBoxes *dsa=0;
TRect rlocal=r;
if (aOptions & mfDontShowAgain)
{
rlocal.a.y-=2;
rlocal.b.y++;
}
dialog = new TDialog( rlocal, Titles[aOptions & 0x3] );
stTVIntl *intlMessage=NULL;
if (aOptions & mfDontTranslate)
intlMessage=TVIntl::dontTranslateSt();
else
TVIntl::getText(msg,intlMessage);
dialog->insert(
new TStaticText(TRect(3, 2, dialog->size.x - 2, height - 3),
msg,intlMessage) );
if (aOptions & mfDontShowAgain)
{
dsa=new TCheckBoxes(TRect(2,height-2,dialog->size.x-2,height-1),
new TSItem(__("Don't warn you next time"),0));
dialog->insert(dsa);
}
for( i = 0, x = -2, buttonCount = 0; i < 4; i++ )
{
if( (aOptions & (0x0100 << i)) != 0)
{
buttonList[buttonCount] =
new TButton( TRect(0, 0, 10, 2), _(buttonName[i]), commands[i], bfNormal );
x += buttonList[buttonCount++]->size.x + 2;
}
}
x = (dialog->size.x - x) / 2;
for( i = 0; i < buttonCount; i++ )
{
dialog->insert(buttonList[i]);
buttonList[i]->moveTo(x, dialog->size.y - 3);
x += buttonList[i]->size.x + 2;
}
dialog->selectNext(False);
Boolean oldBusy=TScreen::showBusyState(False);
ccode = TProgram::deskTop->execView(dialog);
TScreen::showBusyState(oldBusy);
if (aOptions & mfDontShowAgain)
{
ushort val;
dsa->getData(&val);
if (val)
ccode|=0x8000; // Not so clean but cmOK,Yes,etc are low values
}
TObject::CLY_destroy( dialog );
return ccode;
}
ushort messageBoxRect( const TRect &r,
ushort aOptions,
const char *fmt,
... )
{
va_list argptr;
char *intlFmt=TVIntl::getTextNew(fmt);
va_start( argptr, fmt );
int l=CLY_vsnprintf(NULL, (size_t)0, intlFmt, argptr);
va_end( argptr );
AllocLocalStr(msg,l+1);
va_start( argptr, fmt );
CLY_vsnprintf(msg, (size_t)l+1, intlFmt, argptr);
va_end( argptr );
DeleteArray(intlFmt);
return messageBoxRect( r, msg, aOptions | mfDontTranslate );
}
static TRect makeRect()
{
TRect r( 0, 0, 40, 9 );
r.move((TProgram::deskTop->size.x - r.b.x) / 2,
(TProgram::deskTop->size.y - r.b.y) / 2);
return r;
}
ushort messageBox( const char *msg, ushort aOptions )
{
return messageBoxRect( makeRect(), msg, aOptions );
}
ushort messageBox( ushort aOptions, const char *fmt, ... )
{
va_list argptr;
char *intlFmt=TVIntl::getTextNew(fmt);
va_start( argptr, fmt );
int l=CLY_vsnprintf(NULL, (size_t)0, intlFmt, argptr);
va_end( argptr );
AllocLocalStr(msg,l+1);
va_start( argptr, fmt );
CLY_vsnprintf(msg, (size_t)l+1, intlFmt, argptr);
va_end( argptr );
DeleteArray(intlFmt);
return messageBoxRect( makeRect(), msg, aOptions | mfDontTranslate );
}
ushort inputBox( const char *Title, const char *aLabel, char *s, int limit,
TValidator *v )
{ // Use a size according to the label+limit and title
int len;
len = max( strlen(aLabel) + 8 + limit, strlen(Title) + 11 );
len = min( len, 60 );
len = max( len , 24 );
TRect r(0, 0, len, 7);
r.move((TProgram::deskTop->size.x - r.b.x) / 2,
(TProgram::deskTop->size.y - r.b.y) / 2);
return inputBoxRect(r, Title, aLabel, s, limit, v);
}
ushort inputBoxRect( const TRect &bounds,
const char *Title,
const char *aLabel,
char *s,
int limit,
TValidator *v )
{
TDialog *dialog;
TInputLine* control;
TRect r;
ushort c;
dialog = new TDialog(bounds, Title);
unsigned x = 4 + strlen( aLabel );
r = TRect( x, 2, min(x + limit + 2, (unsigned int)dialog->size.x - 3), 3 );
control = new TInputLine( r, limit );
control->setValidator( v );
dialog->insert( control );
stTVIntl *intlLabel = NULL;
r = TRect(2, 2, 3 + strlen(TVIntl::getText(aLabel,intlLabel)), 3);
dialog->insert( new TLabel( r, aLabel, control, intlLabel ) );
r = TRect( dialog->size.x / 2 - 11, dialog->size.y - 3,
dialog->size.x / 2 - 1 , dialog->size.y - 1);
dialog->insert( new TButton(r, __("~O~K"), cmOK, bfDefault));
r.a.x += 12;
r.b.x += 12;
dialog->insert( new TButton(r, __("Cancel"), cmCancel, bfNormal));
r.a.x += 12;
r.b.x += 12;
dialog->selectNext(False);
dialog->setData(s);
c = TProgram::deskTop->execView(dialog);
if( c != cmCancel )
dialog->getData(s);
TObject::CLY_destroy( dialog );
return c;
}