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