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