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