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