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