]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dialogs.cpp | |
3 | // Purpose: Common dialogs demo | |
4 | // Author: Julian Smart | |
5 | // Modified by: ABX (2004) - adjustements for conditional building + new menu | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #if defined(__GNUG__) && !defined(__APPLE__) | |
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 | ||
28 | #include "../sample.xpm" | |
29 | ||
30 | #include "wx/datetime.h" | |
31 | #include "wx/image.h" | |
32 | ||
33 | #if wxUSE_COLOURDLG | |
34 | #include "wx/colordlg.h" | |
35 | #endif // wxUSE_COLOURDLG | |
36 | ||
37 | #if wxUSE_CHOICEDLG | |
38 | #include "wx/choicdlg.h" | |
39 | #endif // wxUSE_CHOICEDLG | |
40 | ||
41 | #if wxUSE_STARTUP_TIPS | |
42 | #include "wx/tipdlg.h" | |
43 | #endif // wxUSE_STARTUP_TIPS | |
44 | ||
45 | #if wxUSE_PROGRESSDLG | |
46 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
47 | #include <wx/datetime.h> // wxDateTime | |
48 | #endif | |
49 | ||
50 | #include "wx/progdlg.h" | |
51 | #endif // wxUSE_PROGRESSDLG | |
52 | ||
53 | #if wxUSE_BUSYINFO | |
54 | #include "wx/busyinfo.h" | |
55 | #endif // wxUSE_BUSYINFO | |
56 | ||
57 | #if wxUSE_NUMBERDLG | |
58 | #include "wx/numdlg.h" | |
59 | #endif // wxUSE_NUMBERDLG | |
60 | ||
61 | #if wxUSE_FILEDLG | |
62 | #include "wx/filedlg.h" | |
63 | #endif // wxUSE_FILEDLG | |
64 | ||
65 | #if wxUSE_DIRDLG | |
66 | #include "wx/dirdlg.h" | |
67 | #endif // wxUSE_DIRDLG | |
68 | ||
69 | #if wxUSE_FONTDLG | |
70 | #include "wx/fontdlg.h" | |
71 | #endif // wxUSE_FONTDLG | |
72 | ||
73 | #if wxUSE_FINDREPLDLG | |
74 | #include "wx/fdrepdlg.h" | |
75 | #endif // wxUSE_FINDREPLDLG | |
76 | ||
77 | #if wxUSE_SPINCTRL | |
78 | #include "wx/spinctrl.h" | |
79 | #endif | |
80 | ||
81 | #include "wx/propdlg.h" | |
82 | ||
83 | #include "dialogs.h" | |
84 | ||
85 | #if USE_COLOURDLG_GENERIC | |
86 | #include "wx/generic/colrdlgg.h" | |
87 | #endif // USE_COLOURDLG_GENERIC | |
88 | ||
89 | #if USE_DIRDLG_GENERIC | |
90 | #include "wx/generic/dirdlgg.h" | |
91 | #endif // USE_DIRDLG_GENERIC | |
92 | ||
93 | #if USE_FILEDLG_GENERIC | |
94 | #include "wx/generic/filedlgg.h" | |
95 | #endif // USE_FILEDLG_GENERIC | |
96 | ||
97 | #if USE_FONTDLG_GENERIC | |
98 | #include "wx/generic/fontdlgg.h" | |
99 | #endif // USE_FONTDLG_GENERIC | |
100 | ||
101 | IMPLEMENT_APP(MyApp) | |
102 | ||
103 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) | |
104 | EVT_PAINT(MyCanvas::OnPaint) | |
105 | END_EVENT_TABLE() | |
106 | ||
107 | ||
108 | ||
109 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
110 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) | |
111 | ||
112 | #if wxUSE_COLOURDLG | |
113 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) | |
114 | #endif // wxUSE_COLOURDLG | |
115 | ||
116 | #if wxUSE_FONTDLG | |
117 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) | |
118 | #endif // wxUSE_FONTDLG | |
119 | ||
120 | #if wxUSE_LOG_DIALOG | |
121 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) | |
122 | #endif // wxUSE_LOG_DIALOG | |
123 | ||
124 | #if wxUSE_TEXTDLG | |
125 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) | |
126 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
127 | #endif // wxUSE_TEXTDLG | |
128 | ||
129 | #if wxUSE_NUMBERDLG | |
130 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) | |
131 | #endif // wxUSE_NUMBERDLG | |
132 | ||
133 | #if wxUSE_CHOICEDLG | |
134 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) | |
135 | EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice) | |
136 | #endif // wxUSE_CHOICEDLG | |
137 | ||
138 | #if wxUSE_FILEDLG | |
139 | EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) | |
140 | EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) | |
141 | EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) | |
142 | EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) | |
143 | #endif // wxUSE_FILEDLG | |
144 | ||
145 | #if USE_FILEDLG_GENERIC | |
146 | EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric) | |
147 | EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric) | |
148 | EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric) | |
149 | #endif // USE_FILEDLG_GENERIC | |
150 | ||
151 | #if wxUSE_DIRDLG | |
152 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) | |
153 | EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew) | |
154 | #endif // wxUSE_DIRDLG | |
155 | ||
156 | #if USE_MODAL_PRESENTATION | |
157 | EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg) | |
158 | EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg) | |
159 | #endif // USE_MODAL | |
160 | ||
161 | #if wxUSE_STARTUP_TIPS | |
162 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) | |
163 | #endif // wxUSE_STARTUP_TIPS | |
164 | ||
165 | #if USE_FONTDLG_GENERIC | |
166 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) | |
167 | #endif // USE_FONTDLG_GENERIC | |
168 | ||
169 | #if USE_DIRDLG_GENERIC | |
170 | EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) | |
171 | #endif // wxMSW || wxMAC | |
172 | ||
173 | #if USE_COLOURDLG_GENERIC | |
174 | EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) | |
175 | #endif // USE_COLOURDLG_GENERIC | |
176 | ||
177 | #if wxUSE_PROGRESSDLG | |
178 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
179 | #endif // wxUSE_PROGRESSDLG | |
180 | ||
181 | #if wxUSE_BUSYINFO | |
182 | EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo) | |
183 | #endif // wxUSE_BUSYINFO | |
184 | ||
185 | #if wxUSE_FINDREPLDLG | |
186 | EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog) | |
187 | EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog) | |
188 | ||
189 | EVT_FIND(wxID_ANY, MyFrame::OnFindDialog) | |
190 | EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog) | |
191 | EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog) | |
192 | EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog) | |
193 | EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog) | |
194 | #endif // wxUSE_FINDREPLDLG | |
195 | ||
196 | EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet) | |
197 | EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) | |
198 | ||
199 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) | |
200 | END_EVENT_TABLE() | |
201 | ||
202 | #if USE_MODAL_PRESENTATION | |
203 | ||
204 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) | |
205 | EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton) | |
206 | END_EVENT_TABLE() | |
207 | ||
208 | BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog) | |
209 | EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton) | |
210 | EVT_CLOSE(MyModelessDialog::OnClose) | |
211 | END_EVENT_TABLE() | |
212 | ||
213 | #endif // USE_MODAL_PRESENTATION | |
214 | ||
215 | MyCanvas *myCanvas = (MyCanvas *) NULL; | |
216 | ||
217 | // `Main program' equivalent, creating windows and returning main app frame | |
218 | bool MyApp::OnInit() | |
219 | { | |
220 | #if wxUSE_IMAGE | |
221 | wxInitAllImageHandlers(); | |
222 | #endif | |
223 | ||
224 | m_canvasTextColour = wxColour(_T("BLACK")); | |
225 | m_canvasFont = *wxNORMAL_FONT; | |
226 | ||
227 | // Create the main frame window | |
228 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example")); | |
229 | ||
230 | // Make a menubar | |
231 | wxMenu *file_menu = new wxMenu; | |
232 | ||
233 | file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); | |
234 | ||
235 | ||
236 | #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
237 | ||
238 | wxMenu *choices_menu = new wxMenu; | |
239 | ||
240 | #if wxUSE_COLOURDLG | |
241 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour")); | |
242 | #endif // wxUSE_COLOURDLG | |
243 | ||
244 | #if wxUSE_FONTDLG | |
245 | choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font")); | |
246 | #endif // wxUSE_FONTDLG | |
247 | ||
248 | #if wxUSE_CHOICEDLG | |
249 | choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C")); | |
250 | choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U")); | |
251 | #endif // wxUSE_CHOICEDLG | |
252 | ||
253 | #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
254 | choices_menu->AppendSeparator(); | |
255 | #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
256 | ||
257 | #if USE_COLOURDLG_GENERIC | |
258 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)")); | |
259 | #endif // USE_COLOURDLG_GENERIC | |
260 | ||
261 | #if USE_FONTDLG_GENERIC | |
262 | choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)")); | |
263 | #endif // USE_FONTDLG_GENERIC | |
264 | ||
265 | file_menu->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu); | |
266 | #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
267 | ||
268 | ||
269 | #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG | |
270 | ||
271 | wxMenu *entry_menu = new wxMenu; | |
272 | ||
273 | #if wxUSE_TEXTDLG | |
274 | entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E")); | |
275 | entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P")); | |
276 | #endif // wxUSE_TEXTDLG | |
277 | ||
278 | #if wxUSE_NUMBERDLG | |
279 | entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N")); | |
280 | #endif // wxUSE_NUMBERDLG | |
281 | ||
282 | file_menu->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu); | |
283 | ||
284 | #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG | |
285 | ||
286 | ||
287 | #if wxUSE_FILEDLG | |
288 | ||
289 | wxMenu *filedlg_menu = new wxMenu; | |
290 | filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O")); | |
291 | filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2")); | |
292 | filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); | |
293 | filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); | |
294 | ||
295 | #if USE_FILEDLG_GENERIC | |
296 | filedlg_menu->AppendSeparator(); | |
297 | filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)")); | |
298 | filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)")); | |
299 | filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)")); | |
300 | #endif // USE_FILEDLG_GENERIC | |
301 | ||
302 | file_menu->Append(wxID_ANY,_T("&File operations"),filedlg_menu); | |
303 | ||
304 | #endif // wxUSE_FILEDLG | |
305 | ||
306 | #if wxUSE_DIRDLG | |
307 | wxMenu *dir_menu = new wxMenu; | |
308 | ||
309 | dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D")); | |
310 | dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D")); | |
311 | file_menu->Append(wxID_ANY,_T("&Directory operations"),dir_menu); | |
312 | ||
313 | #if USE_DIRDLG_GENERIC | |
314 | dir_menu->AppendSeparator(); | |
315 | dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)")); | |
316 | #endif // USE_DIRDLG_GENERIC | |
317 | ||
318 | #endif // wxUSE_DIRDLG | |
319 | ||
320 | ||
321 | #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG | |
322 | ||
323 | wxMenu *info_menu = new wxMenu; | |
324 | ||
325 | #if wxUSE_STARTUP_TIPS | |
326 | info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T")); | |
327 | #endif // wxUSE_STARTUP_TIPS | |
328 | ||
329 | #if wxUSE_PROGRESSDLG | |
330 | info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G")); | |
331 | #endif // wxUSE_PROGRESSDLG | |
332 | ||
333 | #if wxUSE_BUSYINFO | |
334 | info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B")); | |
335 | #endif // wxUSE_BUSYINFO | |
336 | ||
337 | #if wxUSE_LOG_DIALOG | |
338 | info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L")); | |
339 | #endif // wxUSE_LOG_DIALOG | |
340 | ||
341 | file_menu->Append(wxID_ANY,_T("&Informative dialogs"),info_menu); | |
342 | ||
343 | #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG | |
344 | ||
345 | ||
346 | #if wxUSE_FINDREPLDLG | |
347 | wxMenu *find_menu = new wxMenu; | |
348 | find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F")); | |
349 | find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F")); | |
350 | file_menu->Append(wxID_ANY,_T("&Searching"),find_menu); | |
351 | #endif // wxUSE_FINDREPLDLG | |
352 | ||
353 | #if USE_MODAL_PRESENTATION | |
354 | wxMenu *modal_menu = new wxMenu; | |
355 | modal_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W")); | |
356 | modal_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z")); | |
357 | file_menu->Append(wxID_ANY,_T("&Modal/Modeless"),modal_menu); | |
358 | #endif // USE_MODAL_PRESENTATION | |
359 | ||
360 | file_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Property Sheet Dialog\tCtrl-P")); | |
361 | file_menu->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R")); | |
362 | ||
363 | file_menu->AppendSeparator(); | |
364 | file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X")); | |
365 | ||
366 | wxMenuBar *menu_bar = new wxMenuBar; | |
367 | menu_bar->Append(file_menu, _T("&File")); | |
368 | frame->SetMenuBar(menu_bar); | |
369 | ||
370 | myCanvas = new MyCanvas(frame); | |
371 | myCanvas->SetBackgroundColour(*wxWHITE); | |
372 | ||
373 | frame->Centre(wxBOTH); | |
374 | ||
375 | // Show the frame | |
376 | frame->Show(true); | |
377 | ||
378 | SetTopWindow(frame); | |
379 | ||
380 | return true; | |
381 | } | |
382 | ||
383 | // My frame constructor | |
384 | MyFrame::MyFrame(wxWindow *parent, | |
385 | const wxString& title) | |
386 | : wxFrame(parent, wxID_ANY, title) | |
387 | { | |
388 | SetIcon(sample_xpm); | |
389 | ||
390 | #if USE_MODAL_PRESENTATION | |
391 | m_dialog = (MyModelessDialog *)NULL; | |
392 | #endif // USE_MODAL_PRESENTATION | |
393 | ||
394 | #if wxUSE_FINDREPLDLG | |
395 | m_dlgFind = | |
396 | m_dlgReplace = NULL; | |
397 | #endif | |
398 | ||
399 | #if wxUSE_COLOURDLG | |
400 | m_clrData.SetChooseFull(true); | |
401 | for (int i = 0; i < 16; i++) | |
402 | { | |
403 | m_clrData.SetCustomColour( | |
404 | i, | |
405 | wxColour( | |
406 | (unsigned char)(i*16), | |
407 | (unsigned char)(i*16), | |
408 | (unsigned char)(i*16) | |
409 | ) | |
410 | ); | |
411 | } | |
412 | #endif // wxUSE_COLOURDLG | |
413 | } | |
414 | ||
415 | #if wxUSE_COLOURDLG | |
416 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) | |
417 | { | |
418 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
419 | ||
420 | wxColourDialog dialog(this, &m_clrData); | |
421 | dialog.SetTitle(_T("Choose the background colour")); | |
422 | if (dialog.ShowModal() == wxID_OK) | |
423 | { | |
424 | m_clrData = dialog.GetColourData(); | |
425 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
426 | myCanvas->ClearBackground(); | |
427 | myCanvas->Refresh(); | |
428 | } | |
429 | } | |
430 | #endif // wxUSE_COLOURDLG | |
431 | ||
432 | #if USE_COLOURDLG_GENERIC | |
433 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) | |
434 | { | |
435 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
436 | ||
437 | //FIXME:TODO:This has no effect... | |
438 | m_clrData.SetChooseFull(true); | |
439 | ||
440 | for (int i = 0; i < 16; i++) | |
441 | { | |
442 | wxColour colour( | |
443 | (unsigned char)(i*16), | |
444 | (unsigned char)(i*16), | |
445 | (unsigned char)(i*16) | |
446 | ); | |
447 | m_clrData.SetCustomColour(i, colour); | |
448 | } | |
449 | ||
450 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData); | |
451 | if (dialog->ShowModal() == wxID_OK) | |
452 | { | |
453 | m_clrData = dialog->GetColourData(); | |
454 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
455 | myCanvas->ClearBackground(); | |
456 | myCanvas->Refresh(); | |
457 | } | |
458 | dialog->Destroy(); | |
459 | } | |
460 | #endif // USE_COLOURDLG_GENERIC | |
461 | ||
462 | #if wxUSE_FONTDLG | |
463 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) | |
464 | { | |
465 | wxFontData data; | |
466 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
467 | data.SetColour(wxGetApp().m_canvasTextColour); | |
468 | ||
469 | // you might also do this: | |
470 | // | |
471 | // wxFontDialog dialog; | |
472 | // if ( !dialog.Create(this, data) { ... error ... } | |
473 | // | |
474 | wxFontDialog dialog(this, data); | |
475 | ||
476 | if (dialog.ShowModal() == wxID_OK) | |
477 | { | |
478 | wxFontData retData = dialog.GetFontData(); | |
479 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
480 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
481 | myCanvas->Refresh(); | |
482 | } | |
483 | //else: cancelled by the user, don't change the font | |
484 | } | |
485 | #endif // wxUSE_FONTDLG | |
486 | ||
487 | #if USE_FONTDLG_GENERIC | |
488 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) | |
489 | { | |
490 | wxFontData data; | |
491 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
492 | data.SetColour(wxGetApp().m_canvasTextColour); | |
493 | ||
494 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data); | |
495 | if (dialog->ShowModal() == wxID_OK) | |
496 | { | |
497 | wxFontData retData = dialog->GetFontData(); | |
498 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
499 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
500 | myCanvas->Refresh(); | |
501 | } | |
502 | dialog->Destroy(); | |
503 | } | |
504 | #endif // USE_FONTDLG_GENERIC | |
505 | ||
506 | #if wxUSE_LOG_DIALOG | |
507 | void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event)) | |
508 | { | |
509 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages | |
510 | // being flushed -- test it | |
511 | { | |
512 | wxBusyCursor bc; | |
513 | wxLogMessage(wxT("This is some message - everything is ok so far.")); | |
514 | wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); | |
515 | wxLogWarning(wxT("And then something went wrong!")); | |
516 | ||
517 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
518 | wxYield(); | |
519 | } | |
520 | ||
521 | wxLogError(wxT("Intermediary error handler decided to abort.")); | |
522 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
523 | ||
524 | wxLog::FlushActive(); | |
525 | ||
526 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); | |
527 | } | |
528 | #endif // wxUSE_LOG_DIALOG | |
529 | ||
530 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) | |
531 | { | |
532 | wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"), | |
533 | _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION); | |
534 | ||
535 | switch ( dialog.ShowModal() ) | |
536 | { | |
537 | case wxID_YES: | |
538 | wxLogStatus(wxT("You pressed \"Yes\"")); | |
539 | break; | |
540 | ||
541 | case wxID_NO: | |
542 | wxLogStatus(wxT("You pressed \"No\"")); | |
543 | break; | |
544 | ||
545 | case wxID_CANCEL: | |
546 | wxLogStatus(wxT("You pressed \"Cancel\"")); | |
547 | break; | |
548 | ||
549 | default: | |
550 | wxLogError(wxT("Unexpected wxMessageDialog return code!")); | |
551 | } | |
552 | } | |
553 | ||
554 | #if wxUSE_NUMBERDLG | |
555 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) ) | |
556 | { | |
557 | long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n") | |
558 | _T("Even two rows of text."), | |
559 | _T("Enter a number:"), _T("Numeric input test"), | |
560 | 50, 0, 100, this ); | |
561 | ||
562 | wxString msg; | |
563 | int icon; | |
564 | if ( res == -1 ) | |
565 | { | |
566 | msg = _T("Invalid number entered or dialog cancelled."); | |
567 | icon = wxICON_HAND; | |
568 | } | |
569 | else | |
570 | { | |
571 | msg.Printf(_T("You've entered %lu"), res ); | |
572 | icon = wxICON_INFORMATION; | |
573 | } | |
574 | ||
575 | wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this); | |
576 | } | |
577 | #endif // wxUSE_NUMBERDLG | |
578 | ||
579 | #if wxUSE_TEXTDLG | |
580 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) | |
581 | { | |
582 | wxString pwd = wxGetPasswordFromUser(_T("Enter password:"), | |
583 | _T("Password entry dialog"), | |
584 | wxEmptyString, | |
585 | this); | |
586 | if ( !pwd.empty() ) | |
587 | { | |
588 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), | |
589 | _T("Got password"), wxOK | wxICON_INFORMATION, this); | |
590 | } | |
591 | } | |
592 | ||
593 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
594 | { | |
595 | wxTextEntryDialog dialog(this, | |
596 | _T("This is a small sample\n") | |
597 | _T("A long, long string to test out the text entrybox"), | |
598 | _T("Please enter a string"), | |
599 | _T("Default value"), | |
600 | wxOK | wxCANCEL); | |
601 | ||
602 | if (dialog.ShowModal() == wxID_OK) | |
603 | { | |
604 | wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this); | |
605 | } | |
606 | } | |
607 | #endif // wxUSE_TEXTDLG | |
608 | ||
609 | #if wxUSE_CHOICEDLG | |
610 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) | |
611 | { | |
612 | const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ; | |
613 | ||
614 | wxSingleChoiceDialog dialog(this, | |
615 | _T("This is a small sample\n") | |
616 | _T("A single-choice convenience dialog"), | |
617 | _T("Please select a value"), | |
618 | WXSIZEOF(choices), choices); | |
619 | ||
620 | dialog.SetSelection(2); | |
621 | ||
622 | if (dialog.ShowModal() == wxID_OK) | |
623 | { | |
624 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string")); | |
625 | dialog2.ShowModal(); | |
626 | } | |
627 | } | |
628 | ||
629 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) | |
630 | { | |
631 | const wxString choices[] = | |
632 | { | |
633 | _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"), | |
634 | _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"), | |
635 | _T("Eleven"), _T("Twelve"), _T("Seventeen"), | |
636 | }; | |
637 | ||
638 | wxArrayInt selections; | |
639 | size_t count = wxGetMultipleChoices(selections, | |
640 | _T("This is a small sample\n") | |
641 | _T("A multi-choice convenience dialog"), | |
642 | _T("Please select a value"), | |
643 | WXSIZEOF(choices), choices, | |
644 | this); | |
645 | if ( count ) | |
646 | { | |
647 | wxString msg; | |
648 | msg.Printf(wxT("You selected %u items:\n"), (unsigned)count); | |
649 | for ( size_t n = 0; n < count; n++ ) | |
650 | { | |
651 | msg += wxString::Format(wxT("\t%u: %u (%s)\n"), | |
652 | (unsigned)n, (unsigned)selections[n], | |
653 | choices[selections[n]].c_str()); | |
654 | } | |
655 | wxLogMessage(msg); | |
656 | } | |
657 | //else: cancelled or nothing selected | |
658 | } | |
659 | #endif // wxUSE_CHOICEDLG | |
660 | ||
661 | #if wxUSE_FILEDLG | |
662 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) | |
663 | { | |
664 | wxFileDialog dialog | |
665 | ( | |
666 | this, | |
667 | _T("Testing open file dialog"), | |
668 | wxEmptyString, | |
669 | wxEmptyString, | |
670 | #ifdef __WXMOTIF__ | |
671 | _T("C++ files (*.cpp)|*.cpp") | |
672 | #else | |
673 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") | |
674 | #endif | |
675 | ); | |
676 | ||
677 | dialog.SetDirectory(wxGetHomeDir()); | |
678 | ||
679 | if (dialog.ShowModal() == wxID_OK) | |
680 | { | |
681 | wxString info; | |
682 | info.Printf(_T("Full file name: %s\n") | |
683 | _T("Path: %s\n") | |
684 | _T("Name: %s"), | |
685 | dialog.GetPath().c_str(), | |
686 | dialog.GetDirectory().c_str(), | |
687 | dialog.GetFilename().c_str()); | |
688 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
689 | dialog2.ShowModal(); | |
690 | } | |
691 | } | |
692 | ||
693 | // this shows how to take advantage of specifying a default extension in the | |
694 | // call to wxFileSelector: it is remembered after each new call and the next | |
695 | // one will use it by default | |
696 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
697 | { | |
698 | static wxString s_extDef; | |
699 | wxString path = wxFileSelector( | |
700 | _T("Select the file to load"), | |
701 | wxEmptyString, wxEmptyString, | |
702 | s_extDef, | |
703 | wxString::Format | |
704 | ( | |
705 | _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"), | |
706 | wxFileSelectorDefaultWildcardStr, | |
707 | wxFileSelectorDefaultWildcardStr | |
708 | ), | |
709 | wxCHANGE_DIR, | |
710 | this | |
711 | ); | |
712 | ||
713 | if ( !path ) | |
714 | return; | |
715 | ||
716 | // it is just a sample, would use wxSplitPath in real program | |
717 | s_extDef = path.AfterLast(_T('.')); | |
718 | ||
719 | wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), | |
720 | (const wxChar*) path, (const wxChar*) s_extDef); | |
721 | } | |
722 | ||
723 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) | |
724 | { | |
725 | wxString wildcards = | |
726 | #ifdef __WXMOTIF__ | |
727 | _T("C++ files (*.cpp)|*.cpp"); | |
728 | #else | |
729 | wxString::Format | |
730 | ( | |
731 | _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"), | |
732 | wxFileSelectorDefaultWildcardStr, | |
733 | wxFileSelectorDefaultWildcardStr | |
734 | ); | |
735 | #endif | |
736 | wxFileDialog dialog(this, _T("Testing open multiple file dialog"), | |
737 | wxEmptyString, wxEmptyString, wildcards, | |
738 | wxMULTIPLE); | |
739 | ||
740 | if (dialog.ShowModal() == wxID_OK) | |
741 | { | |
742 | wxArrayString paths, filenames; | |
743 | ||
744 | dialog.GetPaths(paths); | |
745 | dialog.GetFilenames(filenames); | |
746 | ||
747 | wxString msg, s; | |
748 | size_t count = paths.GetCount(); | |
749 | for ( size_t n = 0; n < count; n++ ) | |
750 | { | |
751 | s.Printf(_T("File %d: %s (%s)\n"), | |
752 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
753 | ||
754 | msg += s; | |
755 | } | |
756 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
757 | msg += s; | |
758 | ||
759 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
760 | dialog2.ShowModal(); | |
761 | } | |
762 | } | |
763 | ||
764 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) | |
765 | { | |
766 | wxFileDialog dialog(this, | |
767 | _T("Testing save file dialog"), | |
768 | wxEmptyString, | |
769 | _T("myletter.doc"), | |
770 | _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), | |
771 | wxSAVE|wxOVERWRITE_PROMPT); | |
772 | ||
773 | dialog.SetFilterIndex(1); | |
774 | ||
775 | if (dialog.ShowModal() == wxID_OK) | |
776 | { | |
777 | wxLogMessage(_T("%s, filter %d"), | |
778 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
779 | } | |
780 | } | |
781 | #endif // wxUSE_FILEDLG | |
782 | ||
783 | #if USE_FILEDLG_GENERIC | |
784 | void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
785 | { | |
786 | wxGenericFileDialog dialog | |
787 | ( | |
788 | this, | |
789 | _T("Testing open file dialog"), | |
790 | wxEmptyString, | |
791 | wxEmptyString, | |
792 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") | |
793 | ); | |
794 | ||
795 | dialog.SetDirectory(wxGetHomeDir()); | |
796 | ||
797 | if (dialog.ShowModal() == wxID_OK) | |
798 | { | |
799 | wxString info; | |
800 | info.Printf(_T("Full file name: %s\n") | |
801 | _T("Path: %s\n") | |
802 | _T("Name: %s"), | |
803 | dialog.GetPath().c_str(), | |
804 | dialog.GetDirectory().c_str(), | |
805 | dialog.GetFilename().c_str()); | |
806 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
807 | dialog2.ShowModal(); | |
808 | } | |
809 | } | |
810 | ||
811 | void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
812 | { | |
813 | wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h"); | |
814 | wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"), | |
815 | wxEmptyString, wxEmptyString, wildcards, | |
816 | wxMULTIPLE); | |
817 | ||
818 | if (dialog.ShowModal() == wxID_OK) | |
819 | { | |
820 | wxArrayString paths, filenames; | |
821 | ||
822 | dialog.GetPaths(paths); | |
823 | dialog.GetFilenames(filenames); | |
824 | ||
825 | wxString msg, s; | |
826 | size_t count = paths.GetCount(); | |
827 | for ( size_t n = 0; n < count; n++ ) | |
828 | { | |
829 | s.Printf(_T("File %d: %s (%s)\n"), | |
830 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
831 | ||
832 | msg += s; | |
833 | } | |
834 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
835 | msg += s; | |
836 | ||
837 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
838 | dialog2.ShowModal(); | |
839 | } | |
840 | } | |
841 | ||
842 | void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) ) | |
843 | { | |
844 | wxGenericFileDialog dialog(this, | |
845 | _T("Testing save file dialog"), | |
846 | wxEmptyString, | |
847 | _T("myletter.doc"), | |
848 | _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), | |
849 | wxSAVE|wxOVERWRITE_PROMPT); | |
850 | ||
851 | dialog.SetFilterIndex(1); | |
852 | ||
853 | if (dialog.ShowModal() == wxID_OK) | |
854 | { | |
855 | wxLogMessage(_T("%s, filter %d"), | |
856 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
857 | } | |
858 | } | |
859 | #endif // USE_FILEDLG_GENERIC | |
860 | ||
861 | #if wxUSE_DIRDLG | |
862 | void MyFrame::DoDirChoose(int style) | |
863 | { | |
864 | // pass some initial dir to wxDirDialog | |
865 | wxString dirHome; | |
866 | wxGetHomeDir(&dirHome); | |
867 | ||
868 | wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style); | |
869 | ||
870 | if (dialog.ShowModal() == wxID_OK) | |
871 | { | |
872 | wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str()); | |
873 | } | |
874 | } | |
875 | ||
876 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) | |
877 | { | |
878 | DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON); | |
879 | } | |
880 | ||
881 | void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) ) | |
882 | { | |
883 | DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON); | |
884 | } | |
885 | #endif // wxUSE_DIRDLG | |
886 | ||
887 | #if USE_DIRDLG_GENERIC | |
888 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) | |
889 | { | |
890 | // pass some initial dir to wxDirDialog | |
891 | wxString dirHome; | |
892 | wxGetHomeDir(&dirHome); | |
893 | ||
894 | wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome); | |
895 | ||
896 | if (dialog.ShowModal() == wxID_OK) | |
897 | { | |
898 | wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path")); | |
899 | dialog2.ShowModal(); | |
900 | } | |
901 | } | |
902 | #endif // USE_DIRDLG_GENERIC | |
903 | ||
904 | #if USE_MODAL_PRESENTATION | |
905 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) | |
906 | { | |
907 | MyModalDialog dlg(this); | |
908 | dlg.ShowModal(); | |
909 | } | |
910 | ||
911 | void MyFrame::ModelessDlg(wxCommandEvent& event) | |
912 | { | |
913 | bool show = GetMenuBar()->IsChecked(event.GetId()); | |
914 | ||
915 | if ( show ) | |
916 | { | |
917 | if ( !m_dialog ) | |
918 | { | |
919 | m_dialog = new MyModelessDialog(this); | |
920 | } | |
921 | ||
922 | m_dialog->Show(true); | |
923 | } | |
924 | else // hide | |
925 | { | |
926 | // If m_dialog is NULL, then possibly the system | |
927 | // didn't report the checked menu item status correctly. | |
928 | // It should be true just after the menu item was selected, | |
929 | // if there was no modeless dialog yet. | |
930 | ||
931 | wxASSERT( m_dialog != NULL ); | |
932 | if (m_dialog) | |
933 | m_dialog->Hide(); | |
934 | } | |
935 | } | |
936 | #endif // USE_MODAL_PRESENTATION | |
937 | ||
938 | #if wxUSE_STARTUP_TIPS | |
939 | void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event)) | |
940 | { | |
941 | static size_t s_index = (size_t)-1; | |
942 | ||
943 | if ( s_index == (size_t)-1 ) | |
944 | { | |
945 | srand(time(NULL)); | |
946 | ||
947 | // this is completely bogus, we don't know how many lines are there | |
948 | // in the file, but who cares, it's a demo only... | |
949 | s_index = rand() % 5; | |
950 | } | |
951 | ||
952 | wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index); | |
953 | ||
954 | bool showAtStartup = wxShowTip(this, tipProvider); | |
955 | ||
956 | if ( showAtStartup ) | |
957 | { | |
958 | wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"), | |
959 | wxOK | wxICON_INFORMATION, this); | |
960 | } | |
961 | ||
962 | s_index = tipProvider->GetCurrentTip(); | |
963 | delete tipProvider; | |
964 | } | |
965 | #endif // wxUSE_STARTUP_TIPS | |
966 | ||
967 | void MyFrame::OnPropertySheet(wxCommandEvent& WXUNUSED(event)) | |
968 | { | |
969 | SettingsDialog dialog(this); | |
970 | dialog.ShowModal(); | |
971 | } | |
972 | ||
973 | void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) | |
974 | { | |
975 | wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window")); | |
976 | ||
977 | wxSleep(3); | |
978 | ||
979 | RequestUserAttention(wxUSER_ATTENTION_ERROR); | |
980 | } | |
981 | ||
982 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) | |
983 | { | |
984 | Close(true); | |
985 | } | |
986 | ||
987 | #if wxUSE_PROGRESSDLG | |
988 | ||
989 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
990 | { | |
991 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
992 | // check the performance | |
993 | int countrandomnumbers = 0, count = 0; | |
994 | wxTimeSpan tsTest(0,0,0,250); | |
995 | wxDateTime DT2, DT1 = wxDateTime::UNow(); | |
996 | srand(0); | |
997 | while(1) | |
998 | { | |
999 | rand(); | |
1000 | ++countrandomnumbers; | |
1001 | if ( countrandomnumbers == 1000 ) | |
1002 | { | |
1003 | srand(0); | |
1004 | countrandomnumbers = 0; | |
1005 | ++count; | |
1006 | DT2 = wxDateTime::UNow(); | |
1007 | wxTimeSpan ts = DT2.Subtract( DT1 ); | |
1008 | if ( ts.IsLongerThan( tsTest ) ) | |
1009 | { | |
1010 | break; | |
1011 | } | |
1012 | } | |
1013 | } | |
1014 | const int max = 40 * count; | |
1015 | #else | |
1016 | static const int max = 10; | |
1017 | #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG | |
1018 | ||
1019 | wxProgressDialog dialog(_T("Progress dialog example"), | |
1020 | _T("An informative message"), | |
1021 | max, // range | |
1022 | this, // parent | |
1023 | wxPD_CAN_ABORT | | |
1024 | wxPD_CAN_SKIP | | |
1025 | wxPD_APP_MODAL | | |
1026 | // wxPD_AUTO_HIDE | -- try this as well | |
1027 | wxPD_ELAPSED_TIME | | |
1028 | wxPD_ESTIMATED_TIME | | |
1029 | wxPD_REMAINING_TIME | | |
1030 | wxPD_SMOOTH); | |
1031 | ||
1032 | bool cont = true; | |
1033 | bool skip = false; | |
1034 | // each skip will move progress about quarter forward | |
1035 | for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false ) | |
1036 | { | |
1037 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
1038 | // do (almost) the same operations as we did for the performance test | |
1039 | srand(0); | |
1040 | for ( int j = 0; j < 1000; j++ ) | |
1041 | { | |
1042 | rand(); | |
1043 | if ( j == 999 ) | |
1044 | { | |
1045 | DT2 = wxDateTime::UNow(); | |
1046 | wxTimeSpan ts = DT2.Subtract( DT1 ); | |
1047 | if ( ts.IsLongerThan( tsTest ) ) | |
1048 | { | |
1049 | // nothing to do | |
1050 | } | |
1051 | } | |
1052 | } | |
1053 | #else | |
1054 | wxSleep(1); | |
1055 | #endif | |
1056 | ||
1057 | wxString msg; | |
1058 | ||
1059 | if ( i == max ) | |
1060 | { | |
1061 | msg = _T("That's all, folks!"); | |
1062 | } | |
1063 | else if ( i > max / 2 ) | |
1064 | { | |
1065 | msg = _T("Only a half left (very long message)!"); | |
1066 | } | |
1067 | ||
1068 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
1069 | if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster | |
1070 | { | |
1071 | cont = dialog.Update(i, msg, &skip); | |
1072 | } | |
1073 | #else | |
1074 | cont = dialog.Update(i, msg, &skip); | |
1075 | #endif | |
1076 | ||
1077 | if ( !cont ) | |
1078 | { | |
1079 | if ( wxMessageBox(_T("Do you really want to cancel?"), | |
1080 | _T("Progress dialog question"), // caption | |
1081 | wxYES_NO | wxICON_QUESTION) == wxYES ) | |
1082 | break; | |
1083 | ||
1084 | cont = true; | |
1085 | dialog.Resume(); | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | if ( !cont ) | |
1090 | { | |
1091 | wxLogStatus(wxT("Progress dialog aborted!")); | |
1092 | } | |
1093 | else | |
1094 | { | |
1095 | wxLogStatus(wxT("Countdown from %d finished"), max); | |
1096 | } | |
1097 | } | |
1098 | ||
1099 | #endif // wxUSE_PROGRESSDLG | |
1100 | ||
1101 | #if wxUSE_BUSYINFO | |
1102 | ||
1103 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
1104 | { | |
1105 | wxWindowDisabler disableAll; | |
1106 | ||
1107 | wxBusyInfo info(_T("Working, please wait..."), this); | |
1108 | ||
1109 | for ( int i = 0; i < 18; i++ ) | |
1110 | { | |
1111 | //wxUsleep(100); | |
1112 | wxTheApp->Yield(); | |
1113 | } | |
1114 | ||
1115 | wxSleep(2); | |
1116 | //wxWakeUpIdle(); | |
1117 | } | |
1118 | ||
1119 | #endif // wxUSE_BUSYINFO | |
1120 | ||
1121 | #if wxUSE_FINDREPLDLG | |
1122 | ||
1123 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
1124 | { | |
1125 | if ( m_dlgReplace ) | |
1126 | { | |
1127 | delete m_dlgReplace; | |
1128 | m_dlgReplace = NULL; | |
1129 | } | |
1130 | else | |
1131 | { | |
1132 | m_dlgReplace = new wxFindReplaceDialog | |
1133 | ( | |
1134 | this, | |
1135 | &m_findData, | |
1136 | _T("Find and replace dialog"), | |
1137 | wxFR_REPLACEDIALOG | |
1138 | ); | |
1139 | ||
1140 | m_dlgReplace->Show(true); | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
1145 | { | |
1146 | if ( m_dlgFind ) | |
1147 | { | |
1148 | delete m_dlgFind; | |
1149 | m_dlgFind = NULL; | |
1150 | } | |
1151 | else | |
1152 | { | |
1153 | m_dlgFind = new wxFindReplaceDialog | |
1154 | ( | |
1155 | this, | |
1156 | &m_findData, | |
1157 | _T("Find dialog"), | |
1158 | // just for testing | |
1159 | wxFR_NOWHOLEWORD | |
1160 | ); | |
1161 | ||
1162 | m_dlgFind->Show(true); | |
1163 | } | |
1164 | } | |
1165 | ||
1166 | static wxString DecodeFindDialogEventFlags(int flags) | |
1167 | { | |
1168 | wxString str; | |
1169 | str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ") | |
1170 | << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T("")) | |
1171 | << (flags & wxFR_MATCHCASE ? _T("") : _T("not ")) | |
1172 | << _T("case sensitive"); | |
1173 | ||
1174 | return str; | |
1175 | } | |
1176 | ||
1177 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
1178 | { | |
1179 | wxEventType type = event.GetEventType(); | |
1180 | ||
1181 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
1182 | { | |
1183 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), | |
1184 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), | |
1185 | event.GetFindString().c_str(), | |
1186 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1187 | } | |
1188 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
1189 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
1190 | { | |
1191 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), | |
1192 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""), | |
1193 | event.GetFindString().c_str(), | |
1194 | event.GetReplaceString().c_str(), | |
1195 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1196 | } | |
1197 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
1198 | { | |
1199 | wxFindReplaceDialog *dlg = event.GetDialog(); | |
1200 | ||
1201 | int idMenu; | |
1202 | const wxChar *txt; | |
1203 | if ( dlg == m_dlgFind ) | |
1204 | { | |
1205 | txt = _T("Find"); | |
1206 | idMenu = DIALOGS_FIND; | |
1207 | m_dlgFind = NULL; | |
1208 | } | |
1209 | else if ( dlg == m_dlgReplace ) | |
1210 | { | |
1211 | txt = _T("Replace"); | |
1212 | idMenu = DIALOGS_REPLACE; | |
1213 | m_dlgReplace = NULL; | |
1214 | } | |
1215 | else | |
1216 | { | |
1217 | txt = _T("Unknown"); | |
1218 | idMenu = wxID_ANY; | |
1219 | ||
1220 | wxFAIL_MSG( _T("unexpected event") ); | |
1221 | } | |
1222 | ||
1223 | wxLogMessage(wxT("%s dialog is being closed."), txt); | |
1224 | ||
1225 | if ( idMenu != wxID_ANY ) | |
1226 | { | |
1227 | GetMenuBar()->Check(idMenu, false); | |
1228 | } | |
1229 | ||
1230 | dlg->Destroy(); | |
1231 | } | |
1232 | else | |
1233 | { | |
1234 | wxLogError(wxT("Unknown find dialog event!")); | |
1235 | } | |
1236 | } | |
1237 | ||
1238 | #endif // wxUSE_FINDREPLDLG | |
1239 | ||
1240 | // ---------------------------------------------------------------------------- | |
1241 | // MyCanvas | |
1242 | // ---------------------------------------------------------------------------- | |
1243 | ||
1244 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) | |
1245 | { | |
1246 | wxPaintDC dc(this); | |
1247 | dc.SetFont(wxGetApp().m_canvasFont); | |
1248 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
1249 | dc.SetBackgroundMode(wxTRANSPARENT); | |
1250 | dc.DrawText( | |
1251 | _T("wxWidgets common dialogs") | |
1252 | #if !defined(__SMARTPHONE__) | |
1253 | _T(" test application") | |
1254 | #endif | |
1255 | , 10, 10); | |
1256 | } | |
1257 | ||
1258 | #if USE_MODAL_PRESENTATION | |
1259 | ||
1260 | // ---------------------------------------------------------------------------- | |
1261 | // MyModelessDialog | |
1262 | // ---------------------------------------------------------------------------- | |
1263 | ||
1264 | MyModelessDialog::MyModelessDialog(wxWindow *parent) | |
1265 | : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog"))) | |
1266 | { | |
1267 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
1268 | ||
1269 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me")); | |
1270 | wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled")); | |
1271 | check->Disable(); | |
1272 | ||
1273 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
1274 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
1275 | ||
1276 | SetSizer(sizerTop); | |
1277 | ||
1278 | sizerTop->SetSizeHints(this); | |
1279 | sizerTop->Fit(this); | |
1280 | } | |
1281 | ||
1282 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) | |
1283 | { | |
1284 | wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"), | |
1285 | wxOK | wxICON_INFORMATION, this); | |
1286 | } | |
1287 | ||
1288 | void MyModelessDialog::OnClose(wxCloseEvent& event) | |
1289 | { | |
1290 | if ( event.CanVeto() ) | |
1291 | { | |
1292 | wxMessageBox(_T("Use the menu item to close this dialog"), | |
1293 | _T("Modeless dialog"), | |
1294 | wxOK | wxICON_INFORMATION, this); | |
1295 | ||
1296 | event.Veto(); | |
1297 | } | |
1298 | } | |
1299 | ||
1300 | // ---------------------------------------------------------------------------- | |
1301 | // MyModalDialog | |
1302 | // ---------------------------------------------------------------------------- | |
1303 | ||
1304 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
1305 | : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog"))) | |
1306 | { | |
1307 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
1308 | ||
1309 | m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog...")); | |
1310 | m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog")); | |
1311 | m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button")); | |
1312 | ||
1313 | wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close")); | |
1314 | sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); | |
1315 | sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); | |
1316 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); | |
1317 | sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); | |
1318 | ||
1319 | SetSizer(sizerTop); | |
1320 | ||
1321 | sizerTop->SetSizeHints(this); | |
1322 | sizerTop->Fit(this); | |
1323 | ||
1324 | m_btnModal->SetFocus(); | |
1325 | m_btnModal->SetDefault(); | |
1326 | } | |
1327 | ||
1328 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
1329 | { | |
1330 | if ( event.GetEventObject() == m_btnDelete ) | |
1331 | { | |
1332 | delete m_btnModal; | |
1333 | m_btnModal = NULL; | |
1334 | ||
1335 | m_btnDelete->Disable(); | |
1336 | } | |
1337 | else if ( event.GetEventObject() == m_btnModal ) | |
1338 | { | |
1339 | #if wxUSE_TEXTDLG | |
1340 | wxGetTextFromUser(_T("Dummy prompt"), | |
1341 | _T("Modal dialog called from dialog"), | |
1342 | wxEmptyString, this); | |
1343 | #else | |
1344 | wxMessageBox(_T("Modal dialog called from dialog")); | |
1345 | #endif // wxUSE_TEXTDLG | |
1346 | } | |
1347 | else if ( event.GetEventObject() == m_btnModeless ) | |
1348 | { | |
1349 | (new MyModelessDialog(this))->Show(); | |
1350 | } | |
1351 | else | |
1352 | { | |
1353 | event.Skip(); | |
1354 | } | |
1355 | } | |
1356 | ||
1357 | #endif // USE_MODAL_PRESENTATION | |
1358 | ||
1359 | // ---------------------------------------------------------------------------- | |
1360 | // SettingsDialog | |
1361 | // ---------------------------------------------------------------------------- | |
1362 | ||
1363 | IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog) | |
1364 | ||
1365 | BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog) | |
1366 | END_EVENT_TABLE() | |
1367 | ||
1368 | SettingsDialog::SettingsDialog(wxWindow* win) | |
1369 | { | |
1370 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); | |
1371 | ||
1372 | Create(win, -1, _("Preferences"), wxDefaultPosition, wxDefaultSize); | |
1373 | CreateButtons(wxOK|wxCANCEL|wxHELP); | |
1374 | ||
1375 | wxBookCtrlBase* notebook = GetBookCtrl(); | |
1376 | ||
1377 | wxPanel* generalSettings = CreateGeneralSettingsPage(notebook); | |
1378 | wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook); | |
1379 | ||
1380 | notebook->AddPage(generalSettings, _("General")); | |
1381 | notebook->AddPage(aestheticSettings, _("Aesthetics")); | |
1382 | ||
1383 | LayoutDialog(); | |
1384 | } | |
1385 | ||
1386 | wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent) | |
1387 | { | |
1388 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
1389 | ||
1390 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
1391 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
1392 | ||
1393 | //// LOAD LAST FILE | |
1394 | ||
1395 | wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL ); | |
1396 | wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize); | |
1397 | itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1398 | item0->Add(itemSizer3, 0, wxGROW|wxALL, 0); | |
1399 | ||
1400 | //// AUTOSAVE | |
1401 | ||
1402 | wxString autoSaveLabel = _("&Auto-save every"); | |
1403 | wxString minsLabel = _("mins"); | |
1404 | ||
1405 | wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL ); | |
1406 | wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize); | |
1407 | ||
1408 | #if wxUSE_SPINCTRL | |
1409 | wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString, | |
1410 | wxDefaultPosition, wxSize(40, -1), wxSP_ARROW_KEYS, 1, 60, 1); | |
1411 | #endif | |
1412 | ||
1413 | itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1414 | #if wxUSE_SPINCTRL | |
1415 | itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1416 | #endif | |
1417 | itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1418 | item0->Add(itemSizer12, 0, wxGROW|wxALL, 0); | |
1419 | ||
1420 | //// TOOLTIPS | |
1421 | ||
1422 | wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL ); | |
1423 | wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize); | |
1424 | itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1425 | item0->Add(itemSizer8, 0, wxGROW|wxALL, 0); | |
1426 | ||
1427 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
1428 | ||
1429 | panel->SetSizer(topSizer); | |
1430 | topSizer->Fit(panel); | |
1431 | ||
1432 | return panel; | |
1433 | } | |
1434 | ||
1435 | wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent) | |
1436 | { | |
1437 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
1438 | ||
1439 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
1440 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
1441 | ||
1442 | //// PROJECT OR GLOBAL | |
1443 | wxString globalOrProjectChoices[2]; | |
1444 | globalOrProjectChoices[0] = _("&New projects"); | |
1445 | globalOrProjectChoices[1] = _("&This project"); | |
1446 | ||
1447 | wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"), | |
1448 | wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices); | |
1449 | item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5); | |
1450 | ||
1451 | projectOrGlobal->SetSelection(0); | |
1452 | ||
1453 | //// BACKGROUND STYLE | |
1454 | wxArrayString backgroundStyleChoices; | |
1455 | backgroundStyleChoices.Add(wxT("Colour")); | |
1456 | backgroundStyleChoices.Add(wxT("Image")); | |
1457 | wxStaticBox* staticBox3 = new wxStaticBox(panel, -1, _("Background style:")); | |
1458 | ||
1459 | wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL ); | |
1460 | item0->Add(styleSizer, 0, wxGROW|wxALL, 5); | |
1461 | ||
1462 | wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
1463 | ||
1464 | wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices); | |
1465 | ||
1466 | itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1467 | itemSizer2->Add(5, 5, 1, wxALL, 0); | |
1468 | itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1469 | ||
1470 | styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5); | |
1471 | ||
1472 | #if wxUSE_SPINCTRL | |
1473 | //// FONT SIZE SELECTION | |
1474 | ||
1475 | wxStaticBox* staticBox1 = new wxStaticBox(panel, -1, _("Tile font size:")); | |
1476 | wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL ); | |
1477 | ||
1478 | wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition, | |
1479 | wxSize(80, -1)); | |
1480 | itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); | |
1481 | ||
1482 | item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5); | |
1483 | #endif | |
1484 | ||
1485 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
1486 | topSizer->AddSpacer(5); | |
1487 | ||
1488 | panel->SetSizer(topSizer); | |
1489 | topSizer->Fit(panel); | |
1490 | ||
1491 | return panel; | |
1492 | } | |
1493 |