]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialogs.cpp | |
3 | // Purpose: Common dialogs demo | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
c50f1fb9 | 9 | // Licence: wxWindows license |
457814b5 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation | |
14 | #pragma interface | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx/wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #endif | |
27 | ||
329e86bf RR |
28 | #include "wx/colordlg.h" |
29 | #include "wx/filedlg.h" | |
30 | #include "wx/dirdlg.h" | |
31 | #include "wx/fontdlg.h" | |
32 | #include "wx/choicdlg.h" | |
33 | #include "wx/tipdlg.h" | |
abceee76 | 34 | #include "wx/progdlg.h" |
761989ff | 35 | #include "wx/fdrepdlg.h" |
a62b0bcc | 36 | #include "wx/busyinfo.h" |
457814b5 | 37 | |
dfad0599 JS |
38 | #define wxTEST_GENERIC_DIALOGS_IN_MSW 0 |
39 | ||
40 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW | |
012f2cb2 GD |
41 | #include "wx/generic/colrdlgg.h" |
42 | #include "wx/generic/fontdlgg.h" | |
457814b5 JS |
43 | #endif |
44 | ||
7e5c1138 | 45 | #define wxUSE_DIRDLGG 0 |
d7d17624 | 46 | |
4ad3c82f | 47 | #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG |
d7d17624 | 48 | #include "wx/generic/dirdlgg.h" |
4ad3c82f VZ |
49 | #endif |
50 | ||
457814b5 JS |
51 | #include "dialogs.h" |
52 | ||
53 | IMPLEMENT_APP(MyApp) | |
54 | ||
4c45f240 VZ |
55 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
56 | EVT_PAINT(MyCanvas::OnPaint) | |
57 | END_EVENT_TABLE() | |
58 | ||
59 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
60 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) | |
61 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) | |
62 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) | |
63 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) | |
64 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) | |
65 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
66 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) | |
67 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) | |
d6c9c1b7 | 68 | EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice) |
4c45f240 | 69 | EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) |
35b45b33 | 70 | EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) |
4c45f240 VZ |
71 | EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) |
72 | EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) | |
73 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) | |
af2b012d | 74 | #if defined(__WXMSW__) || defined(__WXMAC__) |
51a58d8b | 75 | EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) |
af2b012d | 76 | #endif // wxMSW || wxMAC |
f6bcfd97 | 77 | EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg) |
4c45f240 VZ |
78 | EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg) |
79 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) | |
80 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW | |
81 | EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) | |
82 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) | |
abceee76 | 83 | #endif |
a62b0bcc | 84 | |
abceee76 VZ |
85 | #if wxUSE_PROGRESSDLG |
86 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
761989ff | 87 | #endif // wxUSE_PROGRESSDLG |
a62b0bcc VZ |
88 | |
89 | #if wxUSE_BUSYINFO | |
90 | EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo) | |
91 | #endif // wxUSE_BUSYINFO | |
92 | ||
761989ff VZ |
93 | #if wxUSE_FINDREPLDLG |
94 | EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog) | |
95 | EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog) | |
96 | ||
97 | EVT_FIND(-1, MyFrame::OnFindDialog) | |
98 | EVT_FIND_NEXT(-1, MyFrame::OnFindDialog) | |
99 | EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog) | |
100 | EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog) | |
101 | EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog) | |
102 | #endif // wxUSE_FINDREPLDLG | |
4c45f240 | 103 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) |
4c45f240 | 104 | END_EVENT_TABLE() |
abceee76 | 105 | |
f6bcfd97 BP |
106 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) |
107 | EVT_BUTTON(-1, MyModalDialog::OnButton) | |
108 | END_EVENT_TABLE() | |
109 | ||
abceee76 | 110 | BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog) |
5d987909 VZ |
111 | EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton) |
112 | ||
abceee76 VZ |
113 | EVT_CLOSE(MyModelessDialog::OnClose) |
114 | END_EVENT_TABLE() | |
115 | ||
c67daf87 | 116 | MyCanvas *myCanvas = (MyCanvas *) NULL; |
457814b5 | 117 | |
457814b5 | 118 | // `Main program' equivalent, creating windows and returning main app frame |
4c45f240 | 119 | bool MyApp::OnInit() |
457814b5 | 120 | { |
e5ea3f7a | 121 | #if defined(__WXGTK__) && defined(wxUSE_UNICODE) |
dcf924a3 | 122 | wxConvCurrent = &wxConvLibc; |
e5ea3f7a RR |
123 | #endif |
124 | ||
9f84eccd | 125 | m_canvasTextColour = wxColour(_T("BLACK")); |
66bd6b93 | 126 | m_canvasFont = *wxNORMAL_FONT; |
457814b5 JS |
127 | |
128 | // Create the main frame window | |
2f1cd905 | 129 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300)); |
457814b5 JS |
130 | |
131 | // Make a menubar | |
132 | wxMenu *file_menu = new wxMenu; | |
133 | ||
78a189c9 | 134 | file_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour")); |
457814b5 | 135 | |
dfad0599 | 136 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
78a189c9 | 137 | file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("Choose colour (&generic)")); |
457814b5 JS |
138 | #endif |
139 | ||
140 | file_menu->AppendSeparator(); | |
78a189c9 | 141 | file_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font")); |
457814b5 | 142 | |
dfad0599 | 143 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
78a189c9 | 144 | file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose f&ont (generic)")); |
457814b5 JS |
145 | |
146 | #endif | |
147 | file_menu->AppendSeparator(); | |
78a189c9 VZ |
148 | file_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L")); |
149 | file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); | |
150 | file_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E")); | |
151 | file_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P")); | |
152 | file_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N")); | |
153 | file_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C")); | |
154 | file_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U")); | |
457814b5 | 155 | file_menu->AppendSeparator(); |
78a189c9 | 156 | file_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T")); |
c50f1fb9 | 157 | file_menu->AppendSeparator(); |
78a189c9 VZ |
158 | file_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O")); |
159 | file_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2")); | |
160 | file_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); | |
161 | file_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); | |
162 | file_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D")); | |
af2b012d | 163 | #if defined(__WXMSW__) || defined(__WXMAC__) |
78a189c9 | 164 | file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic implementation)")); |
af2b012d | 165 | #endif // wxMSW || wxMAC |
abceee76 | 166 | #if wxUSE_PROGRESSDLG |
78a189c9 | 167 | file_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G")); |
abceee76 | 168 | #endif // wxUSE_PROGRESSDLG |
a62b0bcc | 169 | #if wxUSE_BUSYINFO |
78a189c9 | 170 | file_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B")); |
a62b0bcc | 171 | #endif // wxUSE_BUSYINFO |
761989ff | 172 | #if wxUSE_FINDREPLDLG |
9f84eccd MB |
173 | file_menu->Append(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"), _T(""), TRUE); |
174 | file_menu->Append(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE); | |
761989ff | 175 | #endif // wxUSE_FINDREPLDLG |
f6bcfd97 | 176 | file_menu->AppendSeparator(); |
78a189c9 | 177 | file_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W")); |
9f84eccd | 178 | file_menu->Append(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE); |
4c45f240 | 179 | file_menu->AppendSeparator(); |
78a189c9 | 180 | file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X")); |
457814b5 | 181 | wxMenuBar *menu_bar = new wxMenuBar; |
78a189c9 | 182 | menu_bar->Append(file_menu, _T("&File")); |
457814b5 JS |
183 | frame->SetMenuBar(menu_bar); |
184 | ||
185 | myCanvas = new MyCanvas(frame); | |
186 | myCanvas->SetBackgroundColour(*wxWHITE); | |
187 | ||
188 | frame->Centre(wxBOTH); | |
d93c719a | 189 | |
457814b5 JS |
190 | // Show the frame |
191 | frame->Show(TRUE); | |
192 | ||
193 | SetTopWindow(frame); | |
194 | ||
195 | return TRUE; | |
196 | } | |
197 | ||
198 | // My frame constructor | |
4c45f240 VZ |
199 | MyFrame::MyFrame(wxWindow *parent, |
200 | const wxString& title, | |
201 | const wxPoint& pos, | |
202 | const wxSize& size) | |
203 | : wxFrame(parent, -1, title, pos, size) | |
204 | { | |
205 | m_dialog = (MyModelessDialog *)NULL; | |
f1e1ed3b | 206 | |
043dcdaa | 207 | #if wxUSE_FINDREPLDLG |
14fca738 VZ |
208 | m_dlgFind = |
209 | m_dlgReplace = NULL; | |
043dcdaa JJ |
210 | #endif |
211 | ||
f1e1ed3b | 212 | CreateStatusBar(); |
4c45f240 | 213 | } |
457814b5 | 214 | |
d355d3fe | 215 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 216 | { |
afbd36dd VZ |
217 | wxColour col = myCanvas->GetBackgroundColour(); |
218 | ||
f6bcfd97 | 219 | wxColourData data; |
afbd36dd | 220 | data.SetColour(col); |
f6bcfd97 BP |
221 | data.SetChooseFull(TRUE); |
222 | for (int i = 0; i < 16; i++) | |
223 | { | |
457814b5 JS |
224 | wxColour colour(i*16, i*16, i*16); |
225 | data.SetCustomColour(i, colour); | |
f6bcfd97 | 226 | } |
d93c719a | 227 | |
afbd36dd | 228 | wxColourDialog dialog(this, &data); |
9f84eccd | 229 | dialog.SetTitle(_T("Choose the background colour")); |
afbd36dd | 230 | if (dialog.ShowModal() == wxID_OK) |
f6bcfd97 | 231 | { |
afbd36dd VZ |
232 | wxColourData retData = dialog.GetColourData(); |
233 | col = retData.GetColour(); | |
457814b5 JS |
234 | myCanvas->SetBackgroundColour(col); |
235 | myCanvas->Clear(); | |
236 | myCanvas->Refresh(); | |
f6bcfd97 | 237 | } |
457814b5 JS |
238 | } |
239 | ||
d355d3fe | 240 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 241 | { |
dbc65e27 VZ |
242 | wxFontData data; |
243 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
244 | data.SetColour(wxGetApp().m_canvasTextColour); | |
d93c719a | 245 | |
dbc65e27 VZ |
246 | // you might also do this: |
247 | // | |
248 | // wxFontDialog dialog; | |
249 | // if ( !dialog.Create(this, data) { ... error ... } | |
250 | // | |
251 | wxFontDialog dialog(this, data); | |
252 | ||
253 | if (dialog.ShowModal() == wxID_OK) | |
254 | { | |
255 | wxFontData retData = dialog.GetFontData(); | |
457814b5 JS |
256 | wxGetApp().m_canvasFont = retData.GetChosenFont(); |
257 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
258 | myCanvas->Refresh(); | |
dbc65e27 VZ |
259 | } |
260 | //else: cancelled by the user, don't change the font | |
457814b5 JS |
261 | } |
262 | ||
dfad0599 | 263 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
d355d3fe | 264 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) |
457814b5 JS |
265 | { |
266 | wxColourData data; | |
267 | data.SetChooseFull(TRUE); | |
268 | for (int i = 0; i < 16; i++) | |
269 | { | |
270 | wxColour colour(i*16, i*16, i*16); | |
271 | data.SetCustomColour(i, colour); | |
272 | } | |
d93c719a | 273 | |
457814b5 JS |
274 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data); |
275 | if (dialog->ShowModal() == wxID_OK) | |
276 | { | |
277 | wxColourData retData = dialog->GetColourData(); | |
278 | wxColour col = retData.GetColour(); | |
279 | // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID); | |
280 | myCanvas->SetBackgroundColour(col); | |
281 | myCanvas->Clear(); | |
282 | myCanvas->Refresh(); | |
283 | } | |
5919d76b | 284 | dialog->Destroy(); |
457814b5 JS |
285 | } |
286 | ||
d355d3fe | 287 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) |
457814b5 JS |
288 | { |
289 | wxFontData data; | |
290 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
291 | data.SetColour(wxGetApp().m_canvasTextColour); | |
292 | ||
293 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data); | |
294 | if (dialog->ShowModal() == wxID_OK) | |
295 | { | |
296 | wxFontData retData = dialog->GetFontData(); | |
297 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
298 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
299 | myCanvas->Refresh(); | |
300 | } | |
5919d76b | 301 | dialog->Destroy(); |
457814b5 | 302 | } |
d93c719a VZ |
303 | #endif // wxTEST_GENERIC_DIALOGS_IN_MSW |
304 | ||
305 | void MyFrame::LogDialog(wxCommandEvent& event) | |
306 | { | |
2c8e4738 VZ |
307 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages |
308 | // being flushed -- test it | |
309 | { | |
310 | wxBusyCursor bc; | |
4693b20c MB |
311 | wxLogMessage(wxT("This is some message - everything is ok so far.")); |
312 | wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); | |
313 | wxLogWarning(wxT("And then something went wrong!")); | |
9fe52545 VZ |
314 | |
315 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
316 | wxYield(); | |
2c8e4738 VZ |
317 | } |
318 | ||
4693b20c MB |
319 | wxLogError(wxT("Intermediary error handler decided to abort.")); |
320 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
5888ef1e | 321 | |
7923c649 VZ |
322 | wxLog::FlushActive(); |
323 | ||
4693b20c | 324 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); |
d93c719a | 325 | } |
457814b5 | 326 | |
d355d3fe | 327 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 328 | { |
78a189c9 VZ |
329 | wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"), |
330 | _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION); | |
457814b5 | 331 | |
49b957be VZ |
332 | switch ( dialog.ShowModal() ) |
333 | { | |
334 | case wxID_YES: | |
4fce73fc | 335 | wxLogStatus(wxT("You pressed \"Yes\"")); |
49b957be VZ |
336 | break; |
337 | ||
338 | case wxID_NO: | |
4fce73fc | 339 | wxLogStatus(wxT("You pressed \"No\"")); |
49b957be VZ |
340 | break; |
341 | ||
342 | case wxID_CANCEL: | |
4fce73fc | 343 | wxLogStatus(wxT("You pressed \"Cancel\"")); |
49b957be VZ |
344 | break; |
345 | ||
346 | default: | |
4fce73fc | 347 | wxLogError(wxT("Unexpected wxMessageDialog return code!")); |
49b957be | 348 | } |
457814b5 JS |
349 | } |
350 | ||
c49245f8 VZ |
351 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) ) |
352 | { | |
78a189c9 VZ |
353 | long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n") |
354 | _T("Even two rows of text."), | |
355 | _T("Enter a number:"), _T("Numeric input test"), | |
e65cc56a | 356 | 50, 0, 100, this ); |
c49245f8 VZ |
357 | |
358 | wxString msg; | |
359 | int icon; | |
360 | if ( res == -1 ) | |
361 | { | |
78a189c9 | 362 | msg = _T("Invalid number entered or dialog cancelled."); |
c49245f8 VZ |
363 | icon = wxICON_HAND; |
364 | } | |
365 | else | |
d93c719a VZ |
366 | { |
367 | msg.Printf(_T("You've entered %lu"), res ); | |
c49245f8 VZ |
368 | icon = wxICON_INFORMATION; |
369 | } | |
370 | ||
78a189c9 | 371 | wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this); |
c49245f8 VZ |
372 | } |
373 | ||
a294c6d5 | 374 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 375 | { |
2f1cd905 | 376 | wxString pwd = wxGetPasswordFromUser(_T("Enter password:"), |
78a189c9 | 377 | _T("Password entry dialog"), |
9f84eccd | 378 | _T(""), |
a294c6d5 VZ |
379 | this); |
380 | if ( !!pwd ) | |
381 | { | |
4693b20c | 382 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), |
78a189c9 | 383 | _T("Got password"), wxOK | wxICON_INFORMATION, this); |
a294c6d5 VZ |
384 | } |
385 | } | |
386 | ||
387 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
388 | { | |
389 | wxTextEntryDialog dialog(this, | |
78a189c9 VZ |
390 | _T("This is a small sample\n") |
391 | _T("A long, long string to test out the text entrybox"), | |
392 | _T("Please enter a string"), | |
393 | _T("Default value"), | |
a294c6d5 | 394 | wxOK | wxCANCEL); |
457814b5 JS |
395 | |
396 | if (dialog.ShowModal() == wxID_OK) | |
397 | { | |
78a189c9 | 398 | wxMessageDialog dialog2(this, dialog.GetValue(), _T("Got string")); |
c50f1fb9 | 399 | dialog2.ShowModal(); |
457814b5 JS |
400 | } |
401 | } | |
402 | ||
d355d3fe | 403 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 404 | { |
78a189c9 | 405 | const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ; |
457814b5 | 406 | |
5f95bb70 | 407 | wxSingleChoiceDialog dialog(this, |
78a189c9 VZ |
408 | _T("This is a small sample\n") |
409 | _T("A single-choice convenience dialog"), | |
410 | _T("Please select a value"), | |
5f95bb70 | 411 | WXSIZEOF(choices), choices); |
457814b5 | 412 | |
ef77f91e JS |
413 | dialog.SetSelection(2); |
414 | ||
415 | if (dialog.ShowModal() == wxID_OK) | |
416 | { | |
78a189c9 | 417 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string")); |
ef77f91e JS |
418 | dialog2.ShowModal(); |
419 | } | |
457814b5 JS |
420 | } |
421 | ||
d6c9c1b7 VZ |
422 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) |
423 | { | |
5f95bb70 VZ |
424 | const wxString choices[] = |
425 | { | |
78a189c9 VZ |
426 | _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"), |
427 | _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"), | |
428 | _T("Eleven"), _T("Twelve"), _T("Seventeen"), | |
5f95bb70 | 429 | }; |
d6c9c1b7 VZ |
430 | |
431 | wxArrayInt selections; | |
432 | size_t count = wxGetMultipleChoices(selections, | |
78a189c9 VZ |
433 | _T("This is a small sample\n") |
434 | _T("A multi-choice convenience dialog"), | |
435 | _T("Please select a value"), | |
5f95bb70 | 436 | WXSIZEOF(choices), choices, |
d6c9c1b7 VZ |
437 | this); |
438 | if ( count ) | |
439 | { | |
3d49ce44 | 440 | wxString msg; |
4693b20c | 441 | msg.Printf(wxT("You selected %u items:\n"), count); |
d6c9c1b7 VZ |
442 | for ( size_t n = 0; n < count; n++ ) |
443 | { | |
4693b20c | 444 | msg += wxString::Format(wxT("\t%u: %u (%s)\n"), n, selections[n], |
3d49ce44 | 445 | choices[selections[n]].c_str()); |
d6c9c1b7 | 446 | } |
3d49ce44 | 447 | wxLogMessage(msg); |
d6c9c1b7 VZ |
448 | } |
449 | //else: cancelled or nothing selected | |
450 | } | |
451 | ||
d355d3fe | 452 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 453 | { |
fbf4eacb VZ |
454 | wxFileDialog dialog |
455 | ( | |
456 | this, | |
457 | _T("Testing open file dialog"), | |
458 | _T(""), | |
459 | _T(""), | |
a4e64fb5 MB |
460 | #ifdef __WXMOTIF__ |
461 | _T("C++ files (*.cpp)|*.cpp") | |
462 | #else | |
fbf4eacb | 463 | _T("C++ files (*.h;*.cpp)|*.h;*.cpp") |
a4e64fb5 | 464 | #endif |
fbf4eacb | 465 | ); |
457814b5 | 466 | |
5b636c67 VZ |
467 | dialog.SetDirectory(wxGetHomeDir()); |
468 | ||
c50f1fb9 VZ |
469 | if (dialog.ShowModal() == wxID_OK) |
470 | { | |
5919d76b | 471 | wxString info; |
13393ab6 RR |
472 | info.Printf(_T("Full file name: %s\n") |
473 | _T("Path: %s\n") | |
474 | _T("Name: %s"), | |
5919d76b VZ |
475 | dialog.GetPath().c_str(), |
476 | dialog.GetDirectory().c_str(), | |
477 | dialog.GetFilename().c_str()); | |
78a189c9 | 478 | wxMessageDialog dialog2(this, info, _T("Selected file")); |
c50f1fb9 VZ |
479 | dialog2.ShowModal(); |
480 | } | |
457814b5 JS |
481 | } |
482 | ||
35b45b33 VZ |
483 | // this shows how to take advantage of specifying a default extension in the |
484 | // call to wxFileSelector: it is remembered after each new call and the next | |
485 | // one will use it by default | |
486 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
487 | { | |
488 | static wxString s_extDef; | |
489 | wxString path = wxFileSelector( | |
490 | _T("Select the file to load"), | |
2f1cd905 | 491 | _T(""), _T(""), |
35b45b33 VZ |
492 | s_extDef, |
493 | _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"), | |
fbf4eacb | 494 | wxCHANGE_DIR, |
35b45b33 VZ |
495 | this |
496 | ); | |
497 | ||
498 | if ( !path ) | |
499 | return; | |
500 | ||
501 | // it is just a sample, would use wxSplitPath in real program | |
502 | s_extDef = path.AfterLast(_T('.')); | |
503 | ||
504 | wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), | |
37d403aa | 505 | (const wxChar*) path, (const wxChar*) s_extDef); |
35b45b33 VZ |
506 | } |
507 | ||
c61f4f6d VZ |
508 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) |
509 | { | |
78a189c9 | 510 | wxFileDialog dialog(this, _T("Testing open multiple file dialog"), |
811ad6a1 | 511 | _T(""), _T(""), wxFileSelectorDefaultWildcardStr, |
470caaf9 | 512 | wxMULTIPLE); |
c61f4f6d VZ |
513 | |
514 | if (dialog.ShowModal() == wxID_OK) | |
515 | { | |
516 | wxArrayString paths, filenames; | |
517 | ||
518 | dialog.GetPaths(paths); | |
519 | dialog.GetFilenames(filenames); | |
520 | ||
521 | wxString msg, s; | |
522 | size_t count = paths.GetCount(); | |
523 | for ( size_t n = 0; n < count; n++ ) | |
524 | { | |
525 | s.Printf(_T("File %d: %s (%s)\n"), | |
526 | n, paths[n].c_str(), filenames[n].c_str()); | |
527 | ||
528 | msg += s; | |
529 | } | |
530 | ||
78a189c9 | 531 | wxMessageDialog dialog2(this, msg, _T("Selected files")); |
c61f4f6d VZ |
532 | dialog2.ShowModal(); |
533 | } | |
534 | } | |
535 | ||
d355d3fe | 536 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 537 | { |
2f1cd905 VZ |
538 | wxFileDialog dialog(this, |
539 | _T("Testing save file dialog"), | |
540 | _T(""), | |
2b5f62a0 | 541 | _T("myletter.doc"), |
2f1cd905 VZ |
542 | _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), |
543 | wxSAVE|wxOVERWRITE_PROMPT); | |
c50f1fb9 | 544 | |
2b5f62a0 VZ |
545 | dialog.SetFilterIndex(1); |
546 | ||
c50f1fb9 VZ |
547 | if (dialog.ShowModal() == wxID_OK) |
548 | { | |
2b5f62a0 VZ |
549 | wxLogMessage(_T("%s, filter %d"), |
550 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
c50f1fb9 | 551 | } |
457814b5 JS |
552 | } |
553 | ||
d355d3fe | 554 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 555 | { |
3f2711d5 VZ |
556 | // pass some initial dir to wxDirDialog |
557 | wxString dirHome; | |
558 | wxGetHomeDir(&dirHome); | |
559 | ||
78a189c9 | 560 | wxDirDialog dialog(this, _T("Testing directory picker"), dirHome); |
c50f1fb9 VZ |
561 | |
562 | if (dialog.ShowModal() == wxID_OK) | |
563 | { | |
2b5f62a0 | 564 | wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str()); |
c50f1fb9 VZ |
565 | } |
566 | } | |
567 | ||
af2b012d VZ |
568 | #if defined(__WXMSW__) || defined(__WXMAC__) |
569 | ||
51a58d8b JS |
570 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) |
571 | { | |
4ad3c82f | 572 | #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG |
51a58d8b JS |
573 | // pass some initial dir to wxDirDialog |
574 | wxString dirHome; | |
575 | wxGetHomeDir(&dirHome); | |
576 | ||
78a189c9 | 577 | wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome); |
51a58d8b JS |
578 | |
579 | if (dialog.ShowModal() == wxID_OK) | |
580 | { | |
78a189c9 | 581 | wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path")); |
51a58d8b JS |
582 | dialog2.ShowModal(); |
583 | } | |
4ad3c82f | 584 | #else |
4693b20c MB |
585 | wxLogError(wxT("Sorry, generic dir dialog not available:\n") |
586 | wxT("set wxUSE_DIRDLGG to 1 and recompile")); | |
4ad3c82f | 587 | #endif |
51a58d8b JS |
588 | } |
589 | ||
af2b012d VZ |
590 | #endif // wxMSW || wxMAC |
591 | ||
f6bcfd97 BP |
592 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) |
593 | { | |
594 | MyModalDialog dlg(this); | |
595 | dlg.ShowModal(); | |
596 | } | |
597 | ||
4c45f240 VZ |
598 | void MyFrame::ModelessDlg(wxCommandEvent& event) |
599 | { | |
2f82899b | 600 | bool show = GetMenuBar()->IsChecked(event.GetId()); |
4c45f240 VZ |
601 | |
602 | if ( show ) | |
603 | { | |
604 | if ( !m_dialog ) | |
605 | { | |
606 | m_dialog = new MyModelessDialog(this); | |
607 | } | |
608 | ||
609 | m_dialog->Show(TRUE); | |
610 | } | |
611 | else // hide | |
612 | { | |
613 | m_dialog->Hide(); | |
614 | } | |
615 | } | |
616 | ||
c50f1fb9 VZ |
617 | void MyFrame::ShowTip(wxCommandEvent& event) |
618 | { | |
78bd7ed3 | 619 | #if wxUSE_STARTUP_TIPS |
c50f1fb9 VZ |
620 | static size_t s_index = (size_t)-1; |
621 | ||
622 | if ( s_index == (size_t)-1 ) | |
623 | { | |
624 | srand(time(NULL)); | |
625 | ||
626 | // this is completely bogus, we don't know how many lines are there | |
627 | // in the file, but who cares, it's a demo only... | |
628 | s_index = rand() % 5; | |
629 | } | |
630 | ||
2f1cd905 | 631 | wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index); |
c50f1fb9 VZ |
632 | |
633 | bool showAtStartup = wxShowTip(this, tipProvider); | |
634 | ||
635 | if ( showAtStartup ) | |
636 | { | |
2f1cd905 | 637 | wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"), |
c50f1fb9 VZ |
638 | wxOK | wxICON_INFORMATION, this); |
639 | } | |
457814b5 | 640 | |
c50f1fb9 VZ |
641 | s_index = tipProvider->GetCurrentTip(); |
642 | delete tipProvider; | |
78bd7ed3 | 643 | #endif |
457814b5 JS |
644 | } |
645 | ||
d355d3fe | 646 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 647 | { |
c50f1fb9 | 648 | Close(TRUE); |
457814b5 JS |
649 | } |
650 | ||
abceee76 VZ |
651 | #if wxUSE_PROGRESSDLG |
652 | ||
653 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
654 | { | |
655 | static const int max = 10; | |
656 | ||
2f1cd905 | 657 | wxProgressDialog dialog(_T("Progress dialog example"), |
78a189c9 | 658 | _T("An informative message"), |
abceee76 VZ |
659 | max, // range |
660 | this, // parent | |
661 | wxPD_CAN_ABORT | | |
662 | wxPD_APP_MODAL | | |
df26c4c6 | 663 | // wxPD_AUTO_HIDE | -- try this as well |
abceee76 VZ |
664 | wxPD_ELAPSED_TIME | |
665 | wxPD_ESTIMATED_TIME | | |
666 | wxPD_REMAINING_TIME); | |
667 | ||
668 | bool cont = TRUE; | |
d8ddee9c | 669 | for ( int i = 0; i <= max; i++ ) |
abceee76 VZ |
670 | { |
671 | wxSleep(1); | |
672 | if ( i == max ) | |
673 | { | |
78a189c9 | 674 | cont = dialog.Update(i, _T("That's all, folks!")); |
abceee76 VZ |
675 | } |
676 | else if ( i == max / 2 ) | |
677 | { | |
78a189c9 | 678 | cont = dialog.Update(i, _T("Only a half left (very long message)!")); |
abceee76 VZ |
679 | } |
680 | else | |
681 | { | |
682 | cont = dialog.Update(i); | |
683 | } | |
d8ddee9c VZ |
684 | |
685 | if ( !cont ) | |
686 | { | |
78a189c9 VZ |
687 | if ( wxMessageBox(_T("Do you really want to cancel?"), |
688 | _T("Progress dialog question"), // caption | |
689 | wxYES_NO | wxICON_QUESTION) == wxYES ) | |
d8ddee9c VZ |
690 | break; |
691 | ||
692 | dialog.Resume(); | |
693 | } | |
abceee76 VZ |
694 | } |
695 | ||
696 | if ( !cont ) | |
697 | { | |
4693b20c | 698 | wxLogStatus(wxT("Progress dialog aborted!")); |
abceee76 VZ |
699 | } |
700 | else | |
701 | { | |
4693b20c | 702 | wxLogStatus(wxT("Countdown from %d finished"), max); |
abceee76 VZ |
703 | } |
704 | } | |
705 | ||
706 | #endif // wxUSE_PROGRESSDLG | |
707 | ||
a62b0bcc VZ |
708 | #if wxUSE_BUSYINFO |
709 | ||
710 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
711 | { | |
21977bac VZ |
712 | wxWindowDisabler disableAll; |
713 | ||
9f84eccd | 714 | wxBusyInfo info(_T("Working, please wait..."), this); |
a62b0bcc | 715 | |
5b636c67 | 716 | for ( int i = 0; i < 18; i++ ) |
a62b0bcc | 717 | { |
5b636c67 | 718 | //wxUsleep(100); |
a62b0bcc VZ |
719 | wxTheApp->Yield(); |
720 | } | |
5b636c67 VZ |
721 | |
722 | wxSleep(2); | |
723 | //wxWakeUpIdle(); | |
a62b0bcc VZ |
724 | } |
725 | ||
726 | #endif // wxUSE_BUSYINFO | |
727 | ||
761989ff VZ |
728 | #if wxUSE_FINDREPLDLG |
729 | ||
730 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
731 | { | |
14fca738 VZ |
732 | if ( m_dlgReplace ) |
733 | { | |
734 | delete m_dlgReplace; | |
735 | m_dlgReplace = NULL; | |
736 | } | |
737 | else | |
738 | { | |
739 | m_dlgReplace = new wxFindReplaceDialog | |
740 | ( | |
741 | this, | |
742 | &m_findData, | |
78a189c9 | 743 | _T("Find and replace dialog"), |
14fca738 VZ |
744 | wxFR_REPLACEDIALOG |
745 | ); | |
746 | ||
747 | m_dlgReplace->Show(TRUE); | |
748 | } | |
761989ff VZ |
749 | } |
750 | ||
751 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
752 | { | |
14fca738 VZ |
753 | if ( m_dlgFind ) |
754 | { | |
755 | delete m_dlgFind; | |
756 | m_dlgFind = NULL; | |
757 | } | |
758 | else | |
759 | { | |
760 | m_dlgFind = new wxFindReplaceDialog | |
761 | ( | |
762 | this, | |
763 | &m_findData, | |
78a189c9 | 764 | _T("Find dialog"), |
14fca738 VZ |
765 | // just for testing |
766 | wxFR_NOWHOLEWORD | |
767 | ); | |
768 | ||
769 | m_dlgFind->Show(TRUE); | |
770 | } | |
761989ff VZ |
771 | } |
772 | ||
773 | static wxString DecodeFindDialogEventFlags(int flags) | |
774 | { | |
775 | wxString str; | |
78a189c9 | 776 | str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ") |
2f1cd905 VZ |
777 | << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T("")) |
778 | << (flags & wxFR_MATCHCASE ? _T("") : _T("not ")) | |
78a189c9 | 779 | << _T("case sensitive"); |
761989ff VZ |
780 | |
781 | return str; | |
782 | } | |
783 | ||
784 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
785 | { | |
786 | wxEventType type = event.GetEventType(); | |
787 | ||
788 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
789 | { | |
4693b20c | 790 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), |
eba33006 | 791 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), |
761989ff VZ |
792 | event.GetFindString().c_str(), |
793 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
794 | } | |
795 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
796 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
797 | { | |
4693b20c | 798 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), |
eba33006 | 799 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""), |
761989ff VZ |
800 | event.GetFindString().c_str(), |
801 | event.GetReplaceString().c_str(), | |
802 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
803 | } | |
804 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
805 | { | |
14fca738 VZ |
806 | wxFindReplaceDialog *dlg = event.GetDialog(); |
807 | ||
df26c4c6 | 808 | int idMenu; |
14fca738 VZ |
809 | const wxChar *txt; |
810 | if ( dlg == m_dlgFind ) | |
811 | { | |
812 | txt = _T("Find"); | |
df26c4c6 | 813 | idMenu = DIALOGS_FIND; |
14fca738 VZ |
814 | m_dlgFind = NULL; |
815 | } | |
816 | else if ( dlg == m_dlgReplace ) | |
817 | { | |
818 | txt = _T("Replace"); | |
df26c4c6 | 819 | idMenu = DIALOGS_REPLACE; |
14fca738 VZ |
820 | m_dlgReplace = NULL; |
821 | } | |
822 | else | |
823 | { | |
824 | txt = _T("Unknown"); | |
df26c4c6 | 825 | idMenu = -1; |
14fca738 | 826 | |
2f1cd905 | 827 | wxFAIL_MSG( _T("unexpected event") ); |
14fca738 VZ |
828 | } |
829 | ||
df26c4c6 VZ |
830 | wxLogMessage(wxT("%s dialog is being closed."), txt); |
831 | ||
832 | if ( idMenu != -1 ) | |
833 | { | |
834 | GetMenuBar()->Check(idMenu, FALSE); | |
835 | } | |
761989ff | 836 | |
14fca738 | 837 | dlg->Destroy(); |
761989ff VZ |
838 | } |
839 | else | |
840 | { | |
4693b20c | 841 | wxLogError(wxT("Unknown find dialog event!")); |
761989ff VZ |
842 | } |
843 | } | |
844 | ||
845 | #endif // wxUSE_FINDREPLDLG | |
846 | ||
abceee76 VZ |
847 | // ---------------------------------------------------------------------------- |
848 | // MyCanvas | |
849 | // ---------------------------------------------------------------------------- | |
850 | ||
d355d3fe | 851 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
457814b5 | 852 | { |
c50f1fb9 | 853 | wxPaintDC dc(this); |
457814b5 JS |
854 | dc.SetFont(wxGetApp().m_canvasFont); |
855 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
856 | dc.SetBackgroundMode(wxTRANSPARENT); | |
9f84eccd | 857 | dc.DrawText(_T("wxWindows common dialogs test application"), 10, 10); |
457814b5 JS |
858 | } |
859 | ||
4c45f240 VZ |
860 | // ---------------------------------------------------------------------------- |
861 | // MyModelessDialog | |
862 | // ---------------------------------------------------------------------------- | |
457814b5 | 863 | |
4c45f240 | 864 | MyModelessDialog::MyModelessDialog(wxWindow *parent) |
9f84eccd | 865 | : wxDialog(parent, -1, wxString(_T("Modeless dialog"))) |
4c45f240 | 866 | { |
cbc66a27 VZ |
867 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
868 | ||
78a189c9 VZ |
869 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me")); |
870 | wxCheckBox *check = new wxCheckBox(this, -1, _T("Should be disabled")); | |
cbc66a27 VZ |
871 | check->Disable(); |
872 | ||
873 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
874 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
875 | ||
876 | SetAutoLayout(TRUE); | |
877 | SetSizer(sizerTop); | |
878 | ||
879 | sizerTop->SetSizeHints(this); | |
880 | sizerTop->Fit(this); | |
4c45f240 | 881 | } |
abceee76 | 882 | |
5d987909 VZ |
883 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) |
884 | { | |
2f1cd905 | 885 | wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"), |
5d987909 VZ |
886 | wxOK | wxICON_INFORMATION, this); |
887 | } | |
888 | ||
abceee76 VZ |
889 | void MyModelessDialog::OnClose(wxCloseEvent& event) |
890 | { | |
891 | if ( event.CanVeto() ) | |
892 | { | |
2f1cd905 | 893 | wxMessageBox(_T("Use the menu item to close this dialog"), |
78a189c9 | 894 | _T("Modeless dialog"), |
abceee76 VZ |
895 | wxOK | wxICON_INFORMATION, this); |
896 | ||
897 | event.Veto(); | |
898 | } | |
899 | } | |
900 | ||
f6bcfd97 BP |
901 | // ---------------------------------------------------------------------------- |
902 | // MyModalDialog | |
903 | // ---------------------------------------------------------------------------- | |
904 | ||
905 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
f3dbeba4 | 906 | : wxDialog(parent, -1, wxString(_T("Modal dialog"))) |
f6bcfd97 BP |
907 | { |
908 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
909 | ||
78a189c9 VZ |
910 | m_btnFocused = new wxButton(this, -1, _T("Default button")); |
911 | m_btnDelete = new wxButton(this, -1, _T("&Delete button")); | |
912 | wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close")); | |
f6bcfd97 BP |
913 | sizerTop->Add(m_btnFocused, 0, wxALIGN_CENTER | wxALL, 5); |
914 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); | |
9b70bb91 | 915 | sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); |
f6bcfd97 BP |
916 | |
917 | SetAutoLayout(TRUE); | |
918 | SetSizer(sizerTop); | |
919 | ||
920 | sizerTop->SetSizeHints(this); | |
921 | sizerTop->Fit(this); | |
922 | ||
923 | m_btnFocused->SetFocus(); | |
924 | m_btnFocused->SetDefault(); | |
925 | } | |
926 | ||
927 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
928 | { | |
929 | if ( event.GetEventObject() == m_btnDelete ) | |
930 | { | |
931 | delete m_btnFocused; | |
932 | m_btnFocused = NULL; | |
933 | ||
934 | m_btnDelete->Disable(); | |
935 | } | |
936 | else if ( event.GetEventObject() == m_btnFocused ) | |
937 | { | |
78a189c9 VZ |
938 | wxGetTextFromUser(_T("Dummy prompt"), |
939 | _T("Modal dialog called from dialog"), | |
940 | _T(""), this); | |
f6bcfd97 BP |
941 | } |
942 | else | |
943 | { | |
944 | event.Skip(); | |
945 | } | |
946 | } |