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