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