]>
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" |
457814b5 | 35 | |
51a58d8b JS |
36 | // New wxGenericDirCtrl |
37 | #include "wx/dirctrl.h" | |
38 | ||
dfad0599 JS |
39 | #define wxTEST_GENERIC_DIALOGS_IN_MSW 0 |
40 | ||
41 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW | |
457814b5 JS |
42 | #include <wx/generic/colrdlgg.h> |
43 | #include <wx/generic/fontdlgg.h> | |
44 | #endif | |
45 | ||
46 | #include "dialogs.h" | |
47 | ||
48 | IMPLEMENT_APP(MyApp) | |
49 | ||
4c45f240 VZ |
50 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
51 | EVT_PAINT(MyCanvas::OnPaint) | |
52 | END_EVENT_TABLE() | |
53 | ||
54 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
55 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) | |
56 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) | |
57 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) | |
58 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) | |
59 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) | |
60 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
61 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) | |
62 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) | |
63 | EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) | |
64 | EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) | |
65 | EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) | |
66 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) | |
51a58d8b | 67 | EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) |
f6bcfd97 | 68 | EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg) |
4c45f240 VZ |
69 | EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg) |
70 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) | |
71 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW | |
72 | EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) | |
73 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) | |
abceee76 VZ |
74 | #endif |
75 | #if wxUSE_PROGRESSDLG | |
76 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
4c45f240 VZ |
77 | #endif |
78 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) | |
79 | ||
80 | EVT_BUTTON(DIALOGS_MODELESS_BTN, MyFrame::OnButton) | |
81 | END_EVENT_TABLE() | |
abceee76 | 82 | |
f6bcfd97 BP |
83 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) |
84 | EVT_BUTTON(-1, MyModalDialog::OnButton) | |
85 | END_EVENT_TABLE() | |
86 | ||
abceee76 VZ |
87 | BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog) |
88 | EVT_CLOSE(MyModelessDialog::OnClose) | |
89 | END_EVENT_TABLE() | |
90 | ||
c67daf87 | 91 | MyCanvas *myCanvas = (MyCanvas *) NULL; |
457814b5 | 92 | |
457814b5 | 93 | // `Main program' equivalent, creating windows and returning main app frame |
4c45f240 | 94 | bool MyApp::OnInit() |
457814b5 | 95 | { |
e5ea3f7a | 96 | #if defined(__WXGTK__) && defined(wxUSE_UNICODE) |
dcf924a3 | 97 | wxConvCurrent = &wxConvLibc; |
e5ea3f7a RR |
98 | #endif |
99 | ||
457814b5 | 100 | m_canvasTextColour = wxColour("BLACK"); |
66bd6b93 | 101 | m_canvasFont = *wxNORMAL_FONT; |
457814b5 JS |
102 | |
103 | // Create the main frame window | |
8487f887 | 104 | MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300)); |
457814b5 JS |
105 | |
106 | // Make a menubar | |
107 | wxMenu *file_menu = new wxMenu; | |
108 | ||
109 | file_menu->Append(DIALOGS_CHOOSE_COLOUR, "&Choose colour"); | |
110 | ||
dfad0599 | 111 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
457814b5 JS |
112 | file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, "Choose colour (&generic)"); |
113 | #endif | |
114 | ||
115 | file_menu->AppendSeparator(); | |
116 | file_menu->Append(DIALOGS_CHOOSE_FONT, "Choose &font"); | |
117 | ||
dfad0599 | 118 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
457814b5 JS |
119 | file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, "Choose f&ont (generic)"); |
120 | ||
121 | #endif | |
122 | file_menu->AppendSeparator(); | |
d93c719a | 123 | file_menu->Append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L"); |
c61f4f6d VZ |
124 | file_menu->Append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M"); |
125 | file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E"); | |
a294c6d5 | 126 | file_menu->Append(DIALOGS_PASSWORD_ENTRY, "&Password entry\tCtrl-P"); |
c49245f8 | 127 | file_menu->Append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N"); |
4c45f240 | 128 | file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-C"); |
457814b5 | 129 | file_menu->AppendSeparator(); |
c61f4f6d | 130 | file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T"); |
c50f1fb9 | 131 | file_menu->AppendSeparator(); |
c61f4f6d | 132 | file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O"); |
a294c6d5 | 133 | file_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tCtrl-Q"); |
4c45f240 | 134 | file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S"); |
c61f4f6d | 135 | file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D"); |
51a58d8b | 136 | file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, "&Choose a directory (generic implementation)"); |
abceee76 VZ |
137 | #if wxUSE_PROGRESSDLG |
138 | file_menu->Append(DIALOGS_PROGRESS, "Pro&gress dialog\tCtrl-G"); | |
139 | #endif // wxUSE_PROGRESSDLG | |
f6bcfd97 BP |
140 | file_menu->AppendSeparator(); |
141 | file_menu->Append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-F"); | |
4c45f240 VZ |
142 | file_menu->Append(DIALOGS_MODELESS, "Modeless &dialog\tCtrl-Z", "", TRUE); |
143 | file_menu->AppendSeparator(); | |
c61f4f6d | 144 | file_menu->Append(wxID_EXIT, "E&xit\tAlt-X"); |
457814b5 JS |
145 | wxMenuBar *menu_bar = new wxMenuBar; |
146 | menu_bar->Append(file_menu, "&File"); | |
147 | frame->SetMenuBar(menu_bar); | |
148 | ||
149 | myCanvas = new MyCanvas(frame); | |
150 | myCanvas->SetBackgroundColour(*wxWHITE); | |
151 | ||
152 | frame->Centre(wxBOTH); | |
d93c719a | 153 | |
457814b5 JS |
154 | // Show the frame |
155 | frame->Show(TRUE); | |
156 | ||
157 | SetTopWindow(frame); | |
158 | ||
159 | return TRUE; | |
160 | } | |
161 | ||
162 | // My frame constructor | |
4c45f240 VZ |
163 | MyFrame::MyFrame(wxWindow *parent, |
164 | const wxString& title, | |
165 | const wxPoint& pos, | |
166 | const wxSize& size) | |
167 | : wxFrame(parent, -1, title, pos, size) | |
168 | { | |
169 | m_dialog = (MyModelessDialog *)NULL; | |
170 | } | |
457814b5 | 171 | |
d355d3fe | 172 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 173 | { |
f6bcfd97 BP |
174 | wxColourData data; |
175 | data.SetChooseFull(TRUE); | |
176 | for (int i = 0; i < 16; i++) | |
177 | { | |
457814b5 JS |
178 | wxColour colour(i*16, i*16, i*16); |
179 | data.SetCustomColour(i, colour); | |
f6bcfd97 | 180 | } |
d93c719a | 181 | |
f6bcfd97 BP |
182 | wxColourDialog *dialog = new wxColourDialog(this, &data); |
183 | dialog->SetTitle("Choose the background colour"); | |
184 | if (dialog->ShowModal() == wxID_OK) | |
185 | { | |
457814b5 JS |
186 | wxColourData retData = dialog->GetColourData(); |
187 | wxColour col = retData.GetColour(); | |
457814b5 JS |
188 | myCanvas->SetBackgroundColour(col); |
189 | myCanvas->Clear(); | |
190 | myCanvas->Refresh(); | |
f6bcfd97 BP |
191 | } |
192 | dialog->Destroy(); | |
457814b5 JS |
193 | } |
194 | ||
d355d3fe | 195 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) |
457814b5 JS |
196 | { |
197 | wxFontData data; | |
198 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
199 | data.SetColour(wxGetApp().m_canvasTextColour); | |
d93c719a | 200 | |
457814b5 JS |
201 | wxFontDialog *dialog = new wxFontDialog(this, &data); |
202 | if (dialog->ShowModal() == wxID_OK) | |
203 | { | |
204 | wxFontData retData = dialog->GetFontData(); | |
205 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
206 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
207 | myCanvas->Refresh(); | |
208 | } | |
5919d76b | 209 | dialog->Destroy(); |
457814b5 JS |
210 | } |
211 | ||
dfad0599 | 212 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
d355d3fe | 213 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) |
457814b5 JS |
214 | { |
215 | wxColourData data; | |
216 | data.SetChooseFull(TRUE); | |
217 | for (int i = 0; i < 16; i++) | |
218 | { | |
219 | wxColour colour(i*16, i*16, i*16); | |
220 | data.SetCustomColour(i, colour); | |
221 | } | |
d93c719a | 222 | |
457814b5 JS |
223 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data); |
224 | if (dialog->ShowModal() == wxID_OK) | |
225 | { | |
226 | wxColourData retData = dialog->GetColourData(); | |
227 | wxColour col = retData.GetColour(); | |
228 | // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID); | |
229 | myCanvas->SetBackgroundColour(col); | |
230 | myCanvas->Clear(); | |
231 | myCanvas->Refresh(); | |
232 | } | |
5919d76b | 233 | dialog->Destroy(); |
457814b5 JS |
234 | } |
235 | ||
d355d3fe | 236 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) |
457814b5 JS |
237 | { |
238 | wxFontData data; | |
239 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
240 | data.SetColour(wxGetApp().m_canvasTextColour); | |
241 | ||
242 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data); | |
243 | if (dialog->ShowModal() == wxID_OK) | |
244 | { | |
245 | wxFontData retData = dialog->GetFontData(); | |
246 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
247 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
248 | myCanvas->Refresh(); | |
249 | } | |
5919d76b | 250 | dialog->Destroy(); |
457814b5 | 251 | } |
d93c719a VZ |
252 | #endif // wxTEST_GENERIC_DIALOGS_IN_MSW |
253 | ||
254 | void MyFrame::LogDialog(wxCommandEvent& event) | |
255 | { | |
2c8e4738 VZ |
256 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages |
257 | // being flushed -- test it | |
258 | { | |
259 | wxBusyCursor bc; | |
260 | wxLogMessage("This is some message - everything is ok so far."); | |
261 | wxLogMessage("Another message...\n... this one is on multiple lines"); | |
262 | wxLogWarning("And then something went wrong!"); | |
263 | } | |
264 | ||
d93c719a | 265 | wxLogError("Intermediary error handler decided to abort."); |
5888ef1e VZ |
266 | wxLogError("The top level caller detected an unrecoverable error."); |
267 | ||
7923c649 VZ |
268 | wxLog::FlushActive(); |
269 | ||
c86423f9 | 270 | wxLogMessage("And this is the same dialog but with only one message."); |
d93c719a | 271 | } |
457814b5 | 272 | |
d355d3fe | 273 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 274 | { |
f6bcfd97 | 275 | wxMessageDialog dialog( NULL, "This is a message box\nA long, long string to test out the message box properly", |
c50f1fb9 | 276 | "Message box text", wxYES_NO|wxCANCEL|wxICON_INFORMATION); |
457814b5 JS |
277 | |
278 | dialog.ShowModal(); | |
279 | } | |
280 | ||
c49245f8 VZ |
281 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) ) |
282 | { | |
e65cc56a RR |
283 | long res = wxGetNumberFromUser( "This is some text, actually a lot of text.\n" |
284 | "Even two rows of text.", | |
d93c719a | 285 | "Enter a number:", "Numeric input test", |
e65cc56a | 286 | 50, 0, 100, this ); |
c49245f8 VZ |
287 | |
288 | wxString msg; | |
289 | int icon; | |
290 | if ( res == -1 ) | |
291 | { | |
292 | msg = "Invalid number entered or dialog cancelled."; | |
293 | icon = wxICON_HAND; | |
294 | } | |
295 | else | |
d93c719a VZ |
296 | { |
297 | msg.Printf(_T("You've entered %lu"), res ); | |
c49245f8 VZ |
298 | icon = wxICON_INFORMATION; |
299 | } | |
300 | ||
301 | wxMessageBox(msg, "Numeric test result", wxOK | icon, this); | |
302 | } | |
303 | ||
a294c6d5 | 304 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 305 | { |
a294c6d5 | 306 | wxString pwd = wxGetPasswordFromUser("Enter password:", |
3ca6a5f0 | 307 | "Password entry dialog", |
a294c6d5 VZ |
308 | "", |
309 | this); | |
310 | if ( !!pwd ) | |
311 | { | |
312 | wxMessageBox(wxString::Format("Your password is '%s'", pwd.c_str()), | |
313 | "Got password", wxOK | wxICON_INFORMATION, this); | |
314 | } | |
315 | } | |
316 | ||
317 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
318 | { | |
319 | wxTextEntryDialog dialog(this, | |
320 | "This is a small sample\n" | |
321 | "A long, long string to test out the text entrybox", | |
322 | "Please enter a string", | |
323 | "Default value", | |
324 | wxOK | wxCANCEL); | |
457814b5 JS |
325 | |
326 | if (dialog.ShowModal() == wxID_OK) | |
327 | { | |
c50f1fb9 VZ |
328 | wxMessageDialog dialog2(this, dialog.GetValue(), "Got string"); |
329 | dialog2.ShowModal(); | |
457814b5 JS |
330 | } |
331 | } | |
332 | ||
d355d3fe | 333 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 334 | { |
ef77f91e JS |
335 | const wxString choices[] = { "One", "Two", "Three", "Four", "Five" } ; |
336 | int n = 5; | |
457814b5 | 337 | |
ef77f91e JS |
338 | wxSingleChoiceDialog dialog(this, "This is a small sample\nA single-choice convenience dialog", |
339 | "Please select a value", n, (const wxString *)choices); | |
457814b5 | 340 | |
ef77f91e JS |
341 | dialog.SetSelection(2); |
342 | ||
343 | if (dialog.ShowModal() == wxID_OK) | |
344 | { | |
345 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), "Got string"); | |
346 | dialog2.ShowModal(); | |
347 | } | |
457814b5 JS |
348 | } |
349 | ||
d355d3fe | 350 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 351 | { |
c50f1fb9 | 352 | wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0); |
457814b5 | 353 | |
c50f1fb9 VZ |
354 | if (dialog.ShowModal() == wxID_OK) |
355 | { | |
5919d76b | 356 | wxString info; |
13393ab6 RR |
357 | info.Printf(_T("Full file name: %s\n") |
358 | _T("Path: %s\n") | |
359 | _T("Name: %s"), | |
5919d76b VZ |
360 | dialog.GetPath().c_str(), |
361 | dialog.GetDirectory().c_str(), | |
362 | dialog.GetFilename().c_str()); | |
c50f1fb9 VZ |
363 | wxMessageDialog dialog2(this, info, "Selected file"); |
364 | dialog2.ShowModal(); | |
365 | } | |
457814b5 JS |
366 | } |
367 | ||
c61f4f6d VZ |
368 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) |
369 | { | |
370 | wxFileDialog dialog(this, "Testing open multiple file dialog", | |
470caaf9 VZ |
371 | "", "", wxFileSelectorDefaultWildcardStr, |
372 | wxMULTIPLE); | |
c61f4f6d VZ |
373 | |
374 | if (dialog.ShowModal() == wxID_OK) | |
375 | { | |
376 | wxArrayString paths, filenames; | |
377 | ||
378 | dialog.GetPaths(paths); | |
379 | dialog.GetFilenames(filenames); | |
380 | ||
381 | wxString msg, s; | |
382 | size_t count = paths.GetCount(); | |
383 | for ( size_t n = 0; n < count; n++ ) | |
384 | { | |
385 | s.Printf(_T("File %d: %s (%s)\n"), | |
386 | n, paths[n].c_str(), filenames[n].c_str()); | |
387 | ||
388 | msg += s; | |
389 | } | |
390 | ||
391 | wxMessageDialog dialog2(this, msg, "Selected files"); | |
392 | dialog2.ShowModal(); | |
393 | } | |
394 | } | |
395 | ||
d355d3fe | 396 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 397 | { |
ed58dbea | 398 | wxFileDialog dialog(this, "Testing save file dialog", "", "myletter.txt", |
c50f1fb9 VZ |
399 | "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc", |
400 | wxSAVE|wxOVERWRITE_PROMPT); | |
401 | ||
402 | if (dialog.ShowModal() == wxID_OK) | |
403 | { | |
404 | wxChar buf[400]; | |
405 | wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex()); | |
406 | wxMessageDialog dialog2(this, wxString(buf), "Selected path"); | |
407 | dialog2.ShowModal(); | |
408 | } | |
457814b5 JS |
409 | } |
410 | ||
d355d3fe | 411 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 412 | { |
3f2711d5 VZ |
413 | // pass some initial dir to wxDirDialog |
414 | wxString dirHome; | |
415 | wxGetHomeDir(&dirHome); | |
416 | ||
417 | wxDirDialog dialog(this, "Testing directory picker", dirHome); | |
c50f1fb9 VZ |
418 | |
419 | if (dialog.ShowModal() == wxID_OK) | |
420 | { | |
421 | wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path"); | |
422 | dialog2.ShowModal(); | |
423 | } | |
424 | } | |
425 | ||
51a58d8b JS |
426 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) |
427 | { | |
428 | // pass some initial dir to wxDirDialog | |
429 | wxString dirHome; | |
430 | wxGetHomeDir(&dirHome); | |
431 | ||
432 | wxGenericDirDialog dialog(this, "Testing generic directory picker", dirHome); | |
433 | ||
434 | if (dialog.ShowModal() == wxID_OK) | |
435 | { | |
436 | wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path"); | |
437 | dialog2.ShowModal(); | |
438 | } | |
439 | } | |
440 | ||
f6bcfd97 BP |
441 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) |
442 | { | |
443 | MyModalDialog dlg(this); | |
444 | dlg.ShowModal(); | |
445 | } | |
446 | ||
4c45f240 VZ |
447 | void MyFrame::ModelessDlg(wxCommandEvent& event) |
448 | { | |
449 | bool show = GetMenuBar()->IsChecked(event.GetInt()); | |
450 | ||
451 | if ( show ) | |
452 | { | |
453 | if ( !m_dialog ) | |
454 | { | |
455 | m_dialog = new MyModelessDialog(this); | |
456 | } | |
457 | ||
458 | m_dialog->Show(TRUE); | |
459 | } | |
460 | else // hide | |
461 | { | |
462 | m_dialog->Hide(); | |
463 | } | |
464 | } | |
465 | ||
466 | void MyFrame::OnButton(wxCommandEvent& WXUNUSED(event)) | |
467 | { | |
468 | wxMessageBox("Button pressed in modeless dialog", "Info", | |
469 | wxOK | wxICON_INFORMATION, this); | |
470 | } | |
471 | ||
c50f1fb9 VZ |
472 | void MyFrame::ShowTip(wxCommandEvent& event) |
473 | { | |
78bd7ed3 | 474 | #if wxUSE_STARTUP_TIPS |
c50f1fb9 VZ |
475 | static size_t s_index = (size_t)-1; |
476 | ||
477 | if ( s_index == (size_t)-1 ) | |
478 | { | |
479 | srand(time(NULL)); | |
480 | ||
481 | // this is completely bogus, we don't know how many lines are there | |
482 | // in the file, but who cares, it's a demo only... | |
483 | s_index = rand() % 5; | |
484 | } | |
485 | ||
486 | wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", s_index); | |
487 | ||
488 | bool showAtStartup = wxShowTip(this, tipProvider); | |
489 | ||
490 | if ( showAtStartup ) | |
491 | { | |
492 | wxMessageBox("Will show tips on startup", "Tips dialog", | |
493 | wxOK | wxICON_INFORMATION, this); | |
494 | } | |
457814b5 | 495 | |
c50f1fb9 VZ |
496 | s_index = tipProvider->GetCurrentTip(); |
497 | delete tipProvider; | |
78bd7ed3 | 498 | #endif |
457814b5 JS |
499 | } |
500 | ||
d355d3fe | 501 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 502 | { |
c50f1fb9 | 503 | Close(TRUE); |
457814b5 JS |
504 | } |
505 | ||
abceee76 VZ |
506 | #if wxUSE_PROGRESSDLG |
507 | ||
508 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
509 | { | |
510 | static const int max = 10; | |
511 | ||
512 | wxProgressDialog dialog("Progress dialog example", | |
513 | "An informative message", | |
514 | max, // range | |
515 | this, // parent | |
516 | wxPD_CAN_ABORT | | |
517 | wxPD_APP_MODAL | | |
518 | wxPD_ELAPSED_TIME | | |
519 | wxPD_ESTIMATED_TIME | | |
520 | wxPD_REMAINING_TIME); | |
521 | ||
522 | bool cont = TRUE; | |
523 | for ( int i = 0; i <= max && cont; i++ ) | |
524 | { | |
525 | wxSleep(1); | |
526 | if ( i == max ) | |
527 | { | |
528 | cont = dialog.Update(i, "That's all, folks!"); | |
529 | } | |
530 | else if ( i == max / 2 ) | |
531 | { | |
532 | cont = dialog.Update(i, "Only a half left (very long message)!"); | |
533 | } | |
534 | else | |
535 | { | |
536 | cont = dialog.Update(i); | |
537 | } | |
538 | } | |
539 | ||
540 | if ( !cont ) | |
541 | { | |
542 | wxLogStatus("Progress dialog aborted!"); | |
543 | } | |
544 | else | |
545 | { | |
546 | wxLogStatus("Countdown from %d finished", max); | |
547 | } | |
548 | } | |
549 | ||
550 | #endif // wxUSE_PROGRESSDLG | |
551 | ||
552 | // ---------------------------------------------------------------------------- | |
553 | // MyCanvas | |
554 | // ---------------------------------------------------------------------------- | |
555 | ||
d355d3fe | 556 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
457814b5 | 557 | { |
c50f1fb9 | 558 | wxPaintDC dc(this); |
457814b5 JS |
559 | dc.SetFont(wxGetApp().m_canvasFont); |
560 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
561 | dc.SetBackgroundMode(wxTRANSPARENT); | |
562 | dc.DrawText("wxWindows common dialogs test application", 10, 10); | |
563 | } | |
564 | ||
4c45f240 VZ |
565 | // ---------------------------------------------------------------------------- |
566 | // MyModelessDialog | |
567 | // ---------------------------------------------------------------------------- | |
457814b5 | 568 | |
4c45f240 VZ |
569 | MyModelessDialog::MyModelessDialog(wxWindow *parent) |
570 | : wxDialog(parent, -1, wxString("Modeless dialog")) | |
571 | { | |
cbc66a27 VZ |
572 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
573 | ||
574 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me"); | |
575 | wxCheckBox *check = new wxCheckBox(this, -1, "Should be disabled"); | |
576 | check->Disable(); | |
577 | ||
578 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
579 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
580 | ||
581 | SetAutoLayout(TRUE); | |
582 | SetSizer(sizerTop); | |
583 | ||
584 | sizerTop->SetSizeHints(this); | |
585 | sizerTop->Fit(this); | |
4c45f240 | 586 | } |
abceee76 VZ |
587 | |
588 | void MyModelessDialog::OnClose(wxCloseEvent& event) | |
589 | { | |
590 | if ( event.CanVeto() ) | |
591 | { | |
592 | wxMessageBox("Use the menu item to close this dialog", | |
593 | "Modeless dialog", | |
594 | wxOK | wxICON_INFORMATION, this); | |
595 | ||
596 | event.Veto(); | |
597 | } | |
598 | } | |
599 | ||
f6bcfd97 BP |
600 | // ---------------------------------------------------------------------------- |
601 | // MyModalDialog | |
602 | // ---------------------------------------------------------------------------- | |
603 | ||
604 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
605 | : wxDialog(parent, -1, wxString("Modal dialog")) | |
606 | { | |
607 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
608 | ||
609 | m_btnFocused = new wxButton(this, -1, "Default button"); | |
610 | m_btnDelete = new wxButton(this, -1, "&Delete button"); | |
611 | sizerTop->Add(m_btnFocused, 0, wxALIGN_CENTER | wxALL, 5); | |
612 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); | |
613 | ||
614 | SetAutoLayout(TRUE); | |
615 | SetSizer(sizerTop); | |
616 | ||
617 | sizerTop->SetSizeHints(this); | |
618 | sizerTop->Fit(this); | |
619 | ||
620 | m_btnFocused->SetFocus(); | |
621 | m_btnFocused->SetDefault(); | |
622 | } | |
623 | ||
624 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
625 | { | |
626 | if ( event.GetEventObject() == m_btnDelete ) | |
627 | { | |
628 | delete m_btnFocused; | |
629 | m_btnFocused = NULL; | |
630 | ||
631 | m_btnDelete->Disable(); | |
632 | } | |
633 | else if ( event.GetEventObject() == m_btnFocused ) | |
634 | { | |
635 | wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog", | |
636 | "", this); | |
637 | } | |
638 | else | |
639 | { | |
640 | event.Skip(); | |
641 | } | |
642 | } |