-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialogs.cpp
326 lines (292 loc) · 8.19 KB
/
dialogs.cpp
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
/*
Authors : Guru Kathiresan - [email protected] ,
FreePascal Team - http://www.freepascal.org
License :
Short Verion : wxVCL is distributed under Modified LGPL
(the same license used by FCL, LCL). In short,
this license allows you to use wxVCL in your application either
statically or dynamically linked (and keep your source code as
closed source) but you cannot sell wxVCL alone as a seperate
product or claim owner ship for it and when you make a change to
the wxVCL library (not your application code), you have to give
the changes (of the wxVCL library code) back to the community.
Long Version : The source code of wxVCL is distributed under the
Library GNU General Public License with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,
and to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a module
which is not derived from or based on this library. If you modify this
library, you may extend this exception to your version of the library, but you are
not obligated to do so. If you do not wish to do so, delete this exception
statement from your version.
*/
#include "dialogs.h"
#include <wx/textdlg.h>
/* MessageDlg */
long GetDlgType(TMsgDlgType DlgType)
{
switch (DlgType)
{
case mtWarning:
return wxICON_EXCLAMATION;
case mtError:
return wxICON_ERROR;
case mtInformation:
return wxICON_INFORMATION;
case mtConfirmation:
return wxICON_QUESTION;
// case mtCustom:
// default:
}
return 0;
}
long GetMsgDlgButtonStyle(TMsgDlgButtons Buttons)
{
long Result = 0;
if (Buttons.Has(mbYes))
Result |= wxYES;
if (Buttons.Has(mbNo))
Result |= wxNO;
if (Buttons.Has(mbOK))
Result |= wxOK;
if (Buttons.Has(mbCancel))
Result |= wxCANCEL;
if (Buttons.Has(mbAbort))
Result |= wxCANCEL;
if (Buttons.Has(mbRetry))
Result |= wxCANCEL;
if (Buttons.Has(mbIgnore))
Result |= wxCANCEL;
if (Buttons.Has(mbAll))
Result |= wxYES;
if (Buttons.Has(mbNoToAll))
Result |= wxNO; ;
if (Buttons.Has(mbYesToAll))
Result |= wxYES;
if (Buttons.Has(mbClose))
Result |= wxCANCEL;
return Result;
}
long GetMsgDlgButtonDefaultStyle(TMsgDlgBtn Button)
{
long Result = 0;
if (Button == (mbYes))
Result |= wxYES_DEFAULT;
if (Button == (mbNo))
Result |= wxNO_DEFAULT;
if (Button == (mbOK))
Result = 0;
if (Button == (mbCancel))
Result = 0;
if (Button == (mbAbort))
Result = 0;
if (Button == (mbRetry))
Result = 0;
if (Button == (mbIgnore))
Result = 0;
if (Button == (mbAll))
Result |= wxYES_DEFAULT;
if (Button == (mbNoToAll))
Result |= wxNO_DEFAULT;
if (Button == (mbYesToAll))
Result |= wxYES_DEFAULT;
if (Button == (mbClose))
Result = 0;
return Result;
}
TModalResult wxIDToModalResult(int IDValue)
{
switch (IDValue)
{
case wxID_OK:
return mrOk;
case wxID_CANCEL:
return mrCancel;
case wxID_ABORT:
return mrAbort;
case wxID_RETRY:
return mrRetry;
case wxID_IGNORE:
return mrIgnore;
case wxID_YES:
return mrYes;
case wxID_NO:
return mrNo;
// case wxID_ALL:
// return mrAll;
case wxID_NOTOALL:
return mrNoToAll;
case wxID_YESTOALL:
return mrYesToAll;
}
return mrNone;
}
int MessageDlg(wxString const & aMsg, TMsgDlgType DlgType,
TMsgDlgButtons Buttons, long HelpCtx)
{
return MessageDlg(wxT(""), aMsg, DlgType, Buttons, HelpCtx, mbClose);
}
int MessageDlg(wxString const & aCaption, wxString const & aMsg,
TMsgDlgType DlgType, TMsgDlgButtons Buttons, long HelpCtx)
{
return MessageDlg(aCaption, aMsg, DlgType, Buttons, HelpCtx, mbClose);
}
int MessageDlg(wxString const & aCaption, wxString const & aMsg,
TMsgDlgType DlgType, TMsgDlgButtons Buttons, long HelpCtx,
TMsgDlgBtn DefaultButton)
{
wxUnusedVar(HelpCtx);
wxMessageDialog Dlg(NULL, aMsg, aCaption,
GetDlgType(DlgType) | GetMsgDlgButtonStyle(Buttons)
| GetMsgDlgButtonDefaultStyle(DefaultButton));
return wxIDToModalResult(Dlg.ShowModal());
}
int MessageDlg(wxString const & aCaption, wxString const & aMsg,
TMsgDlgType DlgType, TMsgDlgButtons Buttons, wxString const & HelpKeyword)
{
wxUnusedVar(HelpKeyword);
return MessageDlg(aCaption, aMsg, DlgType, Buttons, 0, mbClose);
}
int MessageDlgPos(wxString const & aMsg, TMsgDlgType DlgType,
TMsgDlgButtons Buttons, long HelpCtx, int X, int Y)
{
wxUnusedVar(HelpCtx);
wxMessageDialog Dlg(NULL, aMsg, wxT(""),
GetDlgType(DlgType) | GetMsgDlgButtonStyle(Buttons), wxPoint(X, Y));
return wxIDToModalResult(Dlg.ShowModal());
}
int MessageDlgPosHelp(wxString const & aMsg, TMsgDlgType DlgType,
TMsgDlgButtons Buttons, long HelpCtx, int X, int Y,
wxString const & HelpFileName)
{
wxUnusedVar(HelpFileName);
return MessageDlgPos(aMsg, DlgType, Buttons, HelpCtx, X, Y);
}
TModalResult QuestionDlg(wxString const & aCaption, wxString const & aMsg,
TMsgDlgType DlgType, TMsgDlgButtons Buttons, long HelpCtx)
{
return TModalResult(MessageDlg(aCaption, aMsg, DlgType, Buttons, HelpCtx));
}
TModalResult QuestionDlg(wxString const & aCaption, wxString const & aMsg,
TMsgDlgType DlgType, TMsgDlgButtons Buttons, wxString const & HelpKeyword)
{
return TModalResult(MessageDlg(aCaption, aMsg, DlgType, Buttons,
HelpKeyword));
}
void ShowMessage(wxString const & aMsg)
{
MessageDlg(wxT(""), aMsg, mtCustom, TMsgDlgButtons::Init(mbOK), wxT(""));
}
void ShowMessageFmt(wxString const & aMsg, ...)
{
wxString Result;
va_list argList;
va_start(argList, aMsg);
Result = wxString::Format(aMsg.c_str(), argList);
va_end(argList);
MessageDlg(wxT(""), Result, mtCustom, TMsgDlgButtons::Init(mbOK), wxT(""));
}
void ShowMessagePos(wxString const & aMsg, int X, int Y)
{
MessageDlgPos(aMsg, mtCustom, TMsgDlgButtons::Init(mbOK), 0, X, Y);
}
bool InputQuery(wxString const & aCaption, wxString const & APrompt,
bool MaskInput, wxString & Value)
{
wxUnusedVar(MaskInput);
wxTextEntryDialog Dlg(NULL, aCaption, APrompt, Value);
if (Dlg.ShowModal() != wxID_OK)
return false;
Value = Dlg.GetValue();
return true;
}
bool InputQuery(wxString const & aCaption, wxString const & APrompt,
wxString & Value)
{
return InputQuery(aCaption, APrompt, false, Value);
}
wxString InputBox(wxString const & aCaption, wxString const & APrompt,
wxString const & ADefault)
{
wxString Value = ADefault;
if (InputQuery(aCaption, APrompt, false, Value) == false)
return ADefault;
else
return Value;
}
wxString PasswordBox(wxString const & aCaption, wxString const & APrompt)
{
wxPasswordEntryDialog Dlg(NULL, aCaption, APrompt);
if (Dlg.ShowModal() != wxID_OK)
return wxT("");
else
return Dlg.GetValue();
}
bool SelectDirectory(wxString const & Caption,
wxString const & InitialDirectory, wxString & Directory)
{
return SelectDirectory(Caption, InitialDirectory, Directory, true, 0);
}
bool SelectDirectory(wxString const & Caption,
wxString const & InitialDirectory, wxString & Directory, bool ShowHidden,
long HelpCtx)
{
wxUnusedVar(ShowHidden);
wxUnusedVar(HelpCtx);
wxDirDialog Dlg(NULL, Caption, InitialDirectory);
if (Dlg.ShowModal() != wxID_OK)
{
return false;
}
else
{
Directory = Dlg.GetPath();
return true;
}
}
bool SelectDirectory(wxString & Directory, TSelectDirOpts Options, long HelpCtx)
{
wxUnusedVar(HelpCtx);
wxUnusedVar(Options);
return SelectDirectory(wxT("Select"), Directory, Directory);
}
bool QuestionDlg(const wxString &Msg, wxWindow* parent)
{
wxMessageDialog msgDlg(parent, Msg, wxT("Question"),
wxYES_NO | wxICON_QUESTION);
if (msgDlg.ShowModal() == wxID_YES)
{
return true;
}
else
{
return false;
}
}
void InformationDlg(const wxString &Msg, wxWindow* parent)
{
wxMessageDialog msgDlg(parent, Msg, wxT("Question"),
wxOK | wxICON_INFORMATION);
msgDlg.ShowModal();
}
bool ConfirmationDlg(const wxString &Msg, wxWindow* parent)
{
wxMessageDialog msgDlg(parent, Msg, wxT("Confirmation"),
wxYES | wxNO | wxICON_QUESTION);
if (msgDlg.ShowModal() == wxID_YES)
{
return true;
}
else
{
return false;
}
}
void ErrorDlg(const wxString &Msg, wxWindow* parent)
{
wxMessageDialog msgDlg(parent, Msg, wxT("Error"), wxOK | wxICON_ERROR);
msgDlg.ShowModal();
}