]>
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 | ||
457814b5 | 125 | m_canvasTextColour = wxColour("BLACK"); |
66bd6b93 | 126 | m_canvasFont = *wxNORMAL_FONT; |
457814b5 JS |
127 | |
128 | // Create the main frame window | |
8487f887 | 129 | MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300)); |
457814b5 JS |
130 | |
131 | // Make a menubar | |
132 | wxMenu *file_menu = new wxMenu; | |
133 | ||
134 | file_menu->Append(DIALOGS_CHOOSE_COLOUR, "&Choose colour"); | |
135 | ||
dfad0599 | 136 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
457814b5 JS |
137 | file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, "Choose colour (&generic)"); |
138 | #endif | |
139 | ||
140 | file_menu->AppendSeparator(); | |
141 | file_menu->Append(DIALOGS_CHOOSE_FONT, "Choose &font"); | |
142 | ||
dfad0599 | 143 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
457814b5 JS |
144 | file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, "Choose f&ont (generic)"); |
145 | ||
146 | #endif | |
147 | file_menu->AppendSeparator(); | |
d93c719a | 148 | file_menu->Append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L"); |
c61f4f6d VZ |
149 | file_menu->Append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M"); |
150 | file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E"); | |
a294c6d5 | 151 | file_menu->Append(DIALOGS_PASSWORD_ENTRY, "&Password entry\tCtrl-P"); |
c49245f8 | 152 | file_menu->Append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N"); |
4c45f240 | 153 | file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-C"); |
d6c9c1b7 | 154 | file_menu->Append(DIALOGS_MULTI_CHOICE, "M&ultiple choice\tCtrl-U"); |
457814b5 | 155 | file_menu->AppendSeparator(); |
c61f4f6d | 156 | file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T"); |
c50f1fb9 | 157 | file_menu->AppendSeparator(); |
c61f4f6d | 158 | file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O"); |
35b45b33 | 159 | file_menu->Append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2"); |
a294c6d5 | 160 | file_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tCtrl-Q"); |
4c45f240 | 161 | file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S"); |
c61f4f6d | 162 | file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D"); |
af2b012d | 163 | #if defined(__WXMSW__) || defined(__WXMAC__) |
51a58d8b | 164 | file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, "&Choose a directory (generic implementation)"); |
af2b012d | 165 | #endif // wxMSW || wxMAC |
abceee76 VZ |
166 | #if wxUSE_PROGRESSDLG |
167 | file_menu->Append(DIALOGS_PROGRESS, "Pro&gress dialog\tCtrl-G"); | |
168 | #endif // wxUSE_PROGRESSDLG | |
a62b0bcc VZ |
169 | #if wxUSE_BUSYINFO |
170 | file_menu->Append(DIALOGS_BUSYINFO, "&Busy info dialog\tCtrl-B"); | |
171 | #endif // wxUSE_BUSYINFO | |
761989ff | 172 | #if wxUSE_FINDREPLDLG |
14fca738 VZ |
173 | file_menu->Append(DIALOGS_FIND, "&Find dialog\tCtrl-F", "", TRUE); |
174 | file_menu->Append(DIALOGS_REPLACE, "Find and &replace dialog\tShift-Ctrl-F", "", TRUE); | |
761989ff | 175 | #endif // wxUSE_FINDREPLDLG |
f6bcfd97 | 176 | file_menu->AppendSeparator(); |
9b70bb91 | 177 | file_menu->Append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-W"); |
4c45f240 VZ |
178 | file_menu->Append(DIALOGS_MODELESS, "Modeless &dialog\tCtrl-Z", "", TRUE); |
179 | file_menu->AppendSeparator(); | |
c61f4f6d | 180 | file_menu->Append(wxID_EXIT, "E&xit\tAlt-X"); |
457814b5 JS |
181 | wxMenuBar *menu_bar = new wxMenuBar; |
182 | menu_bar->Append(file_menu, "&File"); | |
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 VZ |
228 | wxColourDialog dialog(this, &data); |
229 | dialog.SetTitle("Choose the background colour"); | |
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 JS |
241 | { |
242 | wxFontData data; | |
243 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
244 | data.SetColour(wxGetApp().m_canvasTextColour); | |
d93c719a | 245 | |
457814b5 JS |
246 | wxFontDialog *dialog = new wxFontDialog(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 JS |
255 | } |
256 | ||
dfad0599 | 257 | #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW |
d355d3fe | 258 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) |
457814b5 JS |
259 | { |
260 | wxColourData data; | |
261 | data.SetChooseFull(TRUE); | |
262 | for (int i = 0; i < 16; i++) | |
263 | { | |
264 | wxColour colour(i*16, i*16, i*16); | |
265 | data.SetCustomColour(i, colour); | |
266 | } | |
d93c719a | 267 | |
457814b5 JS |
268 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data); |
269 | if (dialog->ShowModal() == wxID_OK) | |
270 | { | |
271 | wxColourData retData = dialog->GetColourData(); | |
272 | wxColour col = retData.GetColour(); | |
273 | // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID); | |
274 | myCanvas->SetBackgroundColour(col); | |
275 | myCanvas->Clear(); | |
276 | myCanvas->Refresh(); | |
277 | } | |
5919d76b | 278 | dialog->Destroy(); |
457814b5 JS |
279 | } |
280 | ||
d355d3fe | 281 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) |
457814b5 JS |
282 | { |
283 | wxFontData data; | |
284 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
285 | data.SetColour(wxGetApp().m_canvasTextColour); | |
286 | ||
287 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data); | |
288 | if (dialog->ShowModal() == wxID_OK) | |
289 | { | |
290 | wxFontData retData = dialog->GetFontData(); | |
291 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
292 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
293 | myCanvas->Refresh(); | |
294 | } | |
5919d76b | 295 | dialog->Destroy(); |
457814b5 | 296 | } |
d93c719a VZ |
297 | #endif // wxTEST_GENERIC_DIALOGS_IN_MSW |
298 | ||
299 | void MyFrame::LogDialog(wxCommandEvent& event) | |
300 | { | |
2c8e4738 VZ |
301 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages |
302 | // being flushed -- test it | |
303 | { | |
304 | wxBusyCursor bc; | |
4693b20c MB |
305 | wxLogMessage(wxT("This is some message - everything is ok so far.")); |
306 | wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); | |
307 | wxLogWarning(wxT("And then something went wrong!")); | |
9fe52545 VZ |
308 | |
309 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
310 | wxYield(); | |
2c8e4738 VZ |
311 | } |
312 | ||
4693b20c MB |
313 | wxLogError(wxT("Intermediary error handler decided to abort.")); |
314 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
5888ef1e | 315 | |
7923c649 VZ |
316 | wxLog::FlushActive(); |
317 | ||
4693b20c | 318 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); |
d93c719a | 319 | } |
457814b5 | 320 | |
d355d3fe | 321 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 322 | { |
f6bcfd97 | 323 | wxMessageDialog dialog( NULL, "This is a message box\nA long, long string to test out the message box properly", |
49b957be | 324 | "Message box text", wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION); |
457814b5 | 325 | |
49b957be VZ |
326 | switch ( dialog.ShowModal() ) |
327 | { | |
328 | case wxID_YES: | |
329 | wxLogStatus("You pressed \"Yes\""); | |
330 | break; | |
331 | ||
332 | case wxID_NO: | |
333 | wxLogStatus("You pressed \"No\""); | |
334 | break; | |
335 | ||
336 | case wxID_CANCEL: | |
337 | wxLogStatus("You pressed \"Cancel\""); | |
338 | break; | |
339 | ||
340 | default: | |
341 | wxLogError("Unexpected wxMessageDialog return code!"); | |
342 | } | |
457814b5 JS |
343 | } |
344 | ||
c49245f8 VZ |
345 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) ) |
346 | { | |
e65cc56a RR |
347 | long res = wxGetNumberFromUser( "This is some text, actually a lot of text.\n" |
348 | "Even two rows of text.", | |
d93c719a | 349 | "Enter a number:", "Numeric input test", |
e65cc56a | 350 | 50, 0, 100, this ); |
c49245f8 VZ |
351 | |
352 | wxString msg; | |
353 | int icon; | |
354 | if ( res == -1 ) | |
355 | { | |
356 | msg = "Invalid number entered or dialog cancelled."; | |
357 | icon = wxICON_HAND; | |
358 | } | |
359 | else | |
d93c719a VZ |
360 | { |
361 | msg.Printf(_T("You've entered %lu"), res ); | |
c49245f8 VZ |
362 | icon = wxICON_INFORMATION; |
363 | } | |
364 | ||
365 | wxMessageBox(msg, "Numeric test result", wxOK | icon, this); | |
366 | } | |
367 | ||
a294c6d5 | 368 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 369 | { |
a294c6d5 | 370 | wxString pwd = wxGetPasswordFromUser("Enter password:", |
3ca6a5f0 | 371 | "Password entry dialog", |
a294c6d5 VZ |
372 | "", |
373 | this); | |
374 | if ( !!pwd ) | |
375 | { | |
4693b20c | 376 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), |
a294c6d5 VZ |
377 | "Got password", wxOK | wxICON_INFORMATION, this); |
378 | } | |
379 | } | |
380 | ||
381 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
382 | { | |
383 | wxTextEntryDialog dialog(this, | |
384 | "This is a small sample\n" | |
385 | "A long, long string to test out the text entrybox", | |
386 | "Please enter a string", | |
387 | "Default value", | |
388 | wxOK | wxCANCEL); | |
457814b5 JS |
389 | |
390 | if (dialog.ShowModal() == wxID_OK) | |
391 | { | |
c50f1fb9 VZ |
392 | wxMessageDialog dialog2(this, dialog.GetValue(), "Got string"); |
393 | dialog2.ShowModal(); | |
457814b5 JS |
394 | } |
395 | } | |
396 | ||
d355d3fe | 397 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 398 | { |
ef77f91e | 399 | const wxString choices[] = { "One", "Two", "Three", "Four", "Five" } ; |
457814b5 | 400 | |
5f95bb70 VZ |
401 | wxSingleChoiceDialog dialog(this, |
402 | "This is a small sample\n" | |
403 | "A single-choice convenience dialog", | |
404 | "Please select a value", | |
405 | WXSIZEOF(choices), choices); | |
457814b5 | 406 | |
ef77f91e JS |
407 | dialog.SetSelection(2); |
408 | ||
409 | if (dialog.ShowModal() == wxID_OK) | |
410 | { | |
411 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), "Got string"); | |
412 | dialog2.ShowModal(); | |
413 | } | |
457814b5 JS |
414 | } |
415 | ||
d6c9c1b7 VZ |
416 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) |
417 | { | |
5f95bb70 VZ |
418 | const wxString choices[] = |
419 | { | |
420 | "One", "Two", "Three", "Four", "Five", | |
421 | "Six", "Seven", "Eight", "Nine", "Ten", | |
422 | "Eleven", "Twelve", "Seventeen", | |
423 | }; | |
d6c9c1b7 VZ |
424 | |
425 | wxArrayInt selections; | |
426 | size_t count = wxGetMultipleChoices(selections, | |
427 | "This is a small sample\n" | |
428 | "A multi-choice convenience dialog", | |
429 | "Please select a value", | |
5f95bb70 | 430 | WXSIZEOF(choices), choices, |
d6c9c1b7 VZ |
431 | this); |
432 | if ( count ) | |
433 | { | |
3d49ce44 | 434 | wxString msg; |
4693b20c | 435 | msg.Printf(wxT("You selected %u items:\n"), count); |
d6c9c1b7 VZ |
436 | for ( size_t n = 0; n < count; n++ ) |
437 | { | |
4693b20c | 438 | msg += wxString::Format(wxT("\t%u: %u (%s)\n"), n, selections[n], |
3d49ce44 | 439 | choices[selections[n]].c_str()); |
d6c9c1b7 | 440 | } |
3d49ce44 | 441 | wxLogMessage(msg); |
d6c9c1b7 VZ |
442 | } |
443 | //else: cancelled or nothing selected | |
444 | } | |
445 | ||
d355d3fe | 446 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 447 | { |
fbf4eacb VZ |
448 | wxFileDialog dialog |
449 | ( | |
450 | this, | |
451 | _T("Testing open file dialog"), | |
452 | _T(""), | |
453 | _T(""), | |
454 | _T("C++ files (*.h;*.cpp)|*.h;*.cpp") | |
455 | ); | |
457814b5 | 456 | |
c50f1fb9 VZ |
457 | if (dialog.ShowModal() == wxID_OK) |
458 | { | |
5919d76b | 459 | wxString info; |
13393ab6 RR |
460 | info.Printf(_T("Full file name: %s\n") |
461 | _T("Path: %s\n") | |
462 | _T("Name: %s"), | |
5919d76b VZ |
463 | dialog.GetPath().c_str(), |
464 | dialog.GetDirectory().c_str(), | |
465 | dialog.GetFilename().c_str()); | |
c50f1fb9 VZ |
466 | wxMessageDialog dialog2(this, info, "Selected file"); |
467 | dialog2.ShowModal(); | |
468 | } | |
457814b5 JS |
469 | } |
470 | ||
35b45b33 VZ |
471 | // this shows how to take advantage of specifying a default extension in the |
472 | // call to wxFileSelector: it is remembered after each new call and the next | |
473 | // one will use it by default | |
474 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
475 | { | |
476 | static wxString s_extDef; | |
477 | wxString path = wxFileSelector( | |
478 | _T("Select the file to load"), | |
479 | _T(""), _T(""), | |
480 | s_extDef, | |
481 | _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"), | |
fbf4eacb | 482 | wxCHANGE_DIR, |
35b45b33 VZ |
483 | this |
484 | ); | |
485 | ||
486 | if ( !path ) | |
487 | return; | |
488 | ||
489 | // it is just a sample, would use wxSplitPath in real program | |
490 | s_extDef = path.AfterLast(_T('.')); | |
491 | ||
492 | wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), | |
37d403aa | 493 | (const wxChar*) path, (const wxChar*) s_extDef); |
35b45b33 VZ |
494 | } |
495 | ||
c61f4f6d VZ |
496 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) |
497 | { | |
498 | wxFileDialog dialog(this, "Testing open multiple file dialog", | |
470caaf9 VZ |
499 | "", "", wxFileSelectorDefaultWildcardStr, |
500 | wxMULTIPLE); | |
c61f4f6d VZ |
501 | |
502 | if (dialog.ShowModal() == wxID_OK) | |
503 | { | |
504 | wxArrayString paths, filenames; | |
505 | ||
506 | dialog.GetPaths(paths); | |
507 | dialog.GetFilenames(filenames); | |
508 | ||
509 | wxString msg, s; | |
510 | size_t count = paths.GetCount(); | |
511 | for ( size_t n = 0; n < count; n++ ) | |
512 | { | |
513 | s.Printf(_T("File %d: %s (%s)\n"), | |
514 | n, paths[n].c_str(), filenames[n].c_str()); | |
515 | ||
516 | msg += s; | |
517 | } | |
518 | ||
519 | wxMessageDialog dialog2(this, msg, "Selected files"); | |
520 | dialog2.ShowModal(); | |
521 | } | |
522 | } | |
523 | ||
d355d3fe | 524 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 525 | { |
ed58dbea | 526 | wxFileDialog dialog(this, "Testing save file dialog", "", "myletter.txt", |
c50f1fb9 VZ |
527 | "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc", |
528 | wxSAVE|wxOVERWRITE_PROMPT); | |
529 | ||
530 | if (dialog.ShowModal() == wxID_OK) | |
531 | { | |
532 | wxChar buf[400]; | |
533 | wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex()); | |
534 | wxMessageDialog dialog2(this, wxString(buf), "Selected path"); | |
535 | dialog2.ShowModal(); | |
536 | } | |
457814b5 JS |
537 | } |
538 | ||
d355d3fe | 539 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 540 | { |
3f2711d5 VZ |
541 | // pass some initial dir to wxDirDialog |
542 | wxString dirHome; | |
543 | wxGetHomeDir(&dirHome); | |
544 | ||
545 | wxDirDialog dialog(this, "Testing directory picker", dirHome); | |
c50f1fb9 VZ |
546 | |
547 | if (dialog.ShowModal() == wxID_OK) | |
548 | { | |
549 | wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path"); | |
550 | dialog2.ShowModal(); | |
551 | } | |
552 | } | |
553 | ||
af2b012d VZ |
554 | #if defined(__WXMSW__) || defined(__WXMAC__) |
555 | ||
51a58d8b JS |
556 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) |
557 | { | |
4ad3c82f | 558 | #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG |
51a58d8b JS |
559 | // pass some initial dir to wxDirDialog |
560 | wxString dirHome; | |
561 | wxGetHomeDir(&dirHome); | |
562 | ||
563 | wxGenericDirDialog dialog(this, "Testing generic directory picker", dirHome); | |
564 | ||
565 | if (dialog.ShowModal() == wxID_OK) | |
566 | { | |
567 | wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path"); | |
568 | dialog2.ShowModal(); | |
569 | } | |
4ad3c82f | 570 | #else |
4693b20c MB |
571 | wxLogError(wxT("Sorry, generic dir dialog not available:\n") |
572 | wxT("set wxUSE_DIRDLGG to 1 and recompile")); | |
4ad3c82f | 573 | #endif |
51a58d8b JS |
574 | } |
575 | ||
af2b012d VZ |
576 | #endif // wxMSW || wxMAC |
577 | ||
f6bcfd97 BP |
578 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) |
579 | { | |
580 | MyModalDialog dlg(this); | |
581 | dlg.ShowModal(); | |
582 | } | |
583 | ||
4c45f240 VZ |
584 | void MyFrame::ModelessDlg(wxCommandEvent& event) |
585 | { | |
2f82899b | 586 | bool show = GetMenuBar()->IsChecked(event.GetId()); |
4c45f240 VZ |
587 | |
588 | if ( show ) | |
589 | { | |
590 | if ( !m_dialog ) | |
591 | { | |
592 | m_dialog = new MyModelessDialog(this); | |
593 | } | |
594 | ||
595 | m_dialog->Show(TRUE); | |
596 | } | |
597 | else // hide | |
598 | { | |
599 | m_dialog->Hide(); | |
600 | } | |
601 | } | |
602 | ||
c50f1fb9 VZ |
603 | void MyFrame::ShowTip(wxCommandEvent& event) |
604 | { | |
78bd7ed3 | 605 | #if wxUSE_STARTUP_TIPS |
c50f1fb9 VZ |
606 | static size_t s_index = (size_t)-1; |
607 | ||
608 | if ( s_index == (size_t)-1 ) | |
609 | { | |
610 | srand(time(NULL)); | |
611 | ||
612 | // this is completely bogus, we don't know how many lines are there | |
613 | // in the file, but who cares, it's a demo only... | |
614 | s_index = rand() % 5; | |
615 | } | |
616 | ||
617 | wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", s_index); | |
618 | ||
619 | bool showAtStartup = wxShowTip(this, tipProvider); | |
620 | ||
621 | if ( showAtStartup ) | |
622 | { | |
623 | wxMessageBox("Will show tips on startup", "Tips dialog", | |
624 | wxOK | wxICON_INFORMATION, this); | |
625 | } | |
457814b5 | 626 | |
c50f1fb9 VZ |
627 | s_index = tipProvider->GetCurrentTip(); |
628 | delete tipProvider; | |
78bd7ed3 | 629 | #endif |
457814b5 JS |
630 | } |
631 | ||
d355d3fe | 632 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 633 | { |
c50f1fb9 | 634 | Close(TRUE); |
457814b5 JS |
635 | } |
636 | ||
abceee76 VZ |
637 | #if wxUSE_PROGRESSDLG |
638 | ||
639 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
640 | { | |
641 | static const int max = 10; | |
642 | ||
643 | wxProgressDialog dialog("Progress dialog example", | |
644 | "An informative message", | |
645 | max, // range | |
646 | this, // parent | |
647 | wxPD_CAN_ABORT | | |
648 | wxPD_APP_MODAL | | |
649 | wxPD_ELAPSED_TIME | | |
650 | wxPD_ESTIMATED_TIME | | |
651 | wxPD_REMAINING_TIME); | |
652 | ||
653 | bool cont = TRUE; | |
654 | for ( int i = 0; i <= max && cont; i++ ) | |
655 | { | |
656 | wxSleep(1); | |
657 | if ( i == max ) | |
658 | { | |
659 | cont = dialog.Update(i, "That's all, folks!"); | |
660 | } | |
661 | else if ( i == max / 2 ) | |
662 | { | |
663 | cont = dialog.Update(i, "Only a half left (very long message)!"); | |
664 | } | |
665 | else | |
666 | { | |
667 | cont = dialog.Update(i); | |
668 | } | |
669 | } | |
670 | ||
671 | if ( !cont ) | |
672 | { | |
4693b20c | 673 | wxLogStatus(wxT("Progress dialog aborted!")); |
abceee76 VZ |
674 | } |
675 | else | |
676 | { | |
4693b20c | 677 | wxLogStatus(wxT("Countdown from %d finished"), max); |
abceee76 VZ |
678 | } |
679 | } | |
680 | ||
681 | #endif // wxUSE_PROGRESSDLG | |
682 | ||
a62b0bcc VZ |
683 | #if wxUSE_BUSYINFO |
684 | ||
685 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
686 | { | |
21977bac VZ |
687 | wxWindowDisabler disableAll; |
688 | ||
868741e9 | 689 | wxBusyInfo info("Working, please wait...", this); |
a62b0bcc VZ |
690 | |
691 | for ( int i = 0; i < 30; i++ ) | |
692 | { | |
693 | wxUsleep(100); | |
694 | wxTheApp->Yield(); | |
695 | } | |
696 | } | |
697 | ||
698 | #endif // wxUSE_BUSYINFO | |
699 | ||
761989ff VZ |
700 | #if wxUSE_FINDREPLDLG |
701 | ||
702 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
703 | { | |
14fca738 VZ |
704 | if ( m_dlgReplace ) |
705 | { | |
706 | delete m_dlgReplace; | |
707 | m_dlgReplace = NULL; | |
708 | } | |
709 | else | |
710 | { | |
711 | m_dlgReplace = new wxFindReplaceDialog | |
712 | ( | |
713 | this, | |
714 | &m_findData, | |
715 | "Find and replace dialog", | |
716 | wxFR_REPLACEDIALOG | |
717 | ); | |
718 | ||
719 | m_dlgReplace->Show(TRUE); | |
720 | } | |
761989ff VZ |
721 | } |
722 | ||
723 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
724 | { | |
14fca738 VZ |
725 | if ( m_dlgFind ) |
726 | { | |
727 | delete m_dlgFind; | |
728 | m_dlgFind = NULL; | |
729 | } | |
730 | else | |
731 | { | |
732 | m_dlgFind = new wxFindReplaceDialog | |
733 | ( | |
734 | this, | |
735 | &m_findData, | |
736 | "Find dialog", | |
737 | // just for testing | |
738 | wxFR_NOWHOLEWORD | |
739 | ); | |
740 | ||
741 | m_dlgFind->Show(TRUE); | |
742 | } | |
761989ff VZ |
743 | } |
744 | ||
745 | static wxString DecodeFindDialogEventFlags(int flags) | |
746 | { | |
747 | wxString str; | |
748 | str << (flags & wxFR_DOWN ? "down" : "up") << ", " | |
749 | << (flags & wxFR_WHOLEWORD ? "whole words only, " : "") | |
750 | << (flags & wxFR_MATCHCASE ? "" : "not ") | |
751 | << "case sensitive"; | |
752 | ||
753 | return str; | |
754 | } | |
755 | ||
756 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
757 | { | |
758 | wxEventType type = event.GetEventType(); | |
759 | ||
760 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
761 | { | |
4693b20c | 762 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), |
761989ff VZ |
763 | type == wxEVT_COMMAND_FIND_NEXT ? "next " : "", |
764 | event.GetFindString().c_str(), | |
765 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
766 | } | |
767 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
768 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
769 | { | |
4693b20c | 770 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), |
761989ff VZ |
771 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? "all " : "", |
772 | event.GetFindString().c_str(), | |
773 | event.GetReplaceString().c_str(), | |
774 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
775 | } | |
776 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
777 | { | |
14fca738 VZ |
778 | wxFindReplaceDialog *dlg = event.GetDialog(); |
779 | ||
780 | const wxChar *txt; | |
781 | if ( dlg == m_dlgFind ) | |
782 | { | |
783 | txt = _T("Find"); | |
784 | m_dlgFind = NULL; | |
785 | } | |
786 | else if ( dlg == m_dlgReplace ) | |
787 | { | |
788 | txt = _T("Replace"); | |
789 | m_dlgReplace = NULL; | |
790 | } | |
791 | else | |
792 | { | |
793 | txt = _T("Unknown"); | |
794 | ||
795 | wxFAIL_MSG( _T("unexecpted event") ); | |
796 | } | |
797 | ||
798 | wxLogMessage(wxT("%s dialog is being closed."), txt), | |
761989ff | 799 | |
14fca738 | 800 | dlg->Destroy(); |
761989ff VZ |
801 | } |
802 | else | |
803 | { | |
4693b20c | 804 | wxLogError(wxT("Unknown find dialog event!")); |
761989ff VZ |
805 | } |
806 | } | |
807 | ||
808 | #endif // wxUSE_FINDREPLDLG | |
809 | ||
abceee76 VZ |
810 | // ---------------------------------------------------------------------------- |
811 | // MyCanvas | |
812 | // ---------------------------------------------------------------------------- | |
813 | ||
d355d3fe | 814 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
457814b5 | 815 | { |
c50f1fb9 | 816 | wxPaintDC dc(this); |
457814b5 JS |
817 | dc.SetFont(wxGetApp().m_canvasFont); |
818 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
819 | dc.SetBackgroundMode(wxTRANSPARENT); | |
820 | dc.DrawText("wxWindows common dialogs test application", 10, 10); | |
821 | } | |
822 | ||
4c45f240 VZ |
823 | // ---------------------------------------------------------------------------- |
824 | // MyModelessDialog | |
825 | // ---------------------------------------------------------------------------- | |
457814b5 | 826 | |
4c45f240 VZ |
827 | MyModelessDialog::MyModelessDialog(wxWindow *parent) |
828 | : wxDialog(parent, -1, wxString("Modeless dialog")) | |
829 | { | |
cbc66a27 VZ |
830 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
831 | ||
832 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me"); | |
833 | wxCheckBox *check = new wxCheckBox(this, -1, "Should be disabled"); | |
834 | check->Disable(); | |
835 | ||
836 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
837 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
838 | ||
839 | SetAutoLayout(TRUE); | |
840 | SetSizer(sizerTop); | |
841 | ||
842 | sizerTop->SetSizeHints(this); | |
843 | sizerTop->Fit(this); | |
4c45f240 | 844 | } |
abceee76 | 845 | |
5d987909 VZ |
846 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) |
847 | { | |
848 | wxMessageBox("Button pressed in modeless dialog", "Info", | |
849 | wxOK | wxICON_INFORMATION, this); | |
850 | } | |
851 | ||
abceee76 VZ |
852 | void MyModelessDialog::OnClose(wxCloseEvent& event) |
853 | { | |
854 | if ( event.CanVeto() ) | |
855 | { | |
856 | wxMessageBox("Use the menu item to close this dialog", | |
857 | "Modeless dialog", | |
858 | wxOK | wxICON_INFORMATION, this); | |
859 | ||
860 | event.Veto(); | |
861 | } | |
862 | } | |
863 | ||
f6bcfd97 BP |
864 | // ---------------------------------------------------------------------------- |
865 | // MyModalDialog | |
866 | // ---------------------------------------------------------------------------- | |
867 | ||
868 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
869 | : wxDialog(parent, -1, wxString("Modal dialog")) | |
870 | { | |
871 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
872 | ||
873 | m_btnFocused = new wxButton(this, -1, "Default button"); | |
874 | m_btnDelete = new wxButton(this, -1, "&Delete button"); | |
9b70bb91 | 875 | wxButton *btnOk = new wxButton(this, wxID_CANCEL, "&Close"); |
f6bcfd97 BP |
876 | sizerTop->Add(m_btnFocused, 0, wxALIGN_CENTER | wxALL, 5); |
877 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); | |
9b70bb91 | 878 | sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); |
f6bcfd97 BP |
879 | |
880 | SetAutoLayout(TRUE); | |
881 | SetSizer(sizerTop); | |
882 | ||
883 | sizerTop->SetSizeHints(this); | |
884 | sizerTop->Fit(this); | |
885 | ||
886 | m_btnFocused->SetFocus(); | |
887 | m_btnFocused->SetDefault(); | |
888 | } | |
889 | ||
890 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
891 | { | |
892 | if ( event.GetEventObject() == m_btnDelete ) | |
893 | { | |
894 | delete m_btnFocused; | |
895 | m_btnFocused = NULL; | |
896 | ||
897 | m_btnDelete->Disable(); | |
898 | } | |
899 | else if ( event.GetEventObject() == m_btnFocused ) | |
900 | { | |
901 | wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog", | |
902 | "", this); | |
903 | } | |
904 | else | |
905 | { | |
906 | event.Skip(); | |
907 | } | |
908 | } |