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