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