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