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