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