1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustements for conditional building + new menu
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "../sample.xpm"
25 #include "wx/datetime.h"
27 #include "wx/bookctrl.h"
28 #include "wx/artprov.h"
29 #include "wx/imaglist.h"
30 #include "wx/sysopt.h"
33 #include "wx/colordlg.h"
34 #endif // wxUSE_COLOURDLG
37 #include "wx/choicdlg.h"
38 #endif // wxUSE_CHOICEDLG
40 #if wxUSE_STARTUP_TIPS
41 #include "wx/tipdlg.h"
42 #endif // wxUSE_STARTUP_TIPS
45 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
46 #include "wx/datetime.h" // wxDateTime
49 #include "wx/progdlg.h"
50 #endif // wxUSE_PROGRESSDLG
53 #include "wx/aboutdlg.h"
55 // these headers are only needed for custom about dialog
56 #include "wx/statline.h"
57 #include "wx/generic/aboutdlgg.h"
58 #endif // wxUSE_ABOUTDLG
61 #include "wx/busyinfo.h"
62 #endif // wxUSE_BUSYINFO
65 #include "wx/numdlg.h"
66 #endif // wxUSE_NUMBERDLG
69 #include "wx/filedlg.h"
70 #endif // wxUSE_FILEDLG
73 #include "wx/dirdlg.h"
74 #endif // wxUSE_DIRDLG
77 #include "wx/fontdlg.h"
78 #endif // wxUSE_FONTDLG
81 #include "wx/fdrepdlg.h"
82 #endif // wxUSE_FINDREPLDLG
85 #include "wx/spinctrl.h"
88 #include "wx/propdlg.h"
92 #if USE_COLOURDLG_GENERIC
93 #include "wx/generic/colrdlgg.h"
94 #endif // USE_COLOURDLG_GENERIC
96 #if USE_DIRDLG_GENERIC
97 #include "wx/generic/dirdlgg.h"
98 #endif // USE_DIRDLG_GENERIC
100 #if USE_FILEDLG_GENERIC
101 #include "wx/generic/filedlgg.h"
102 #endif // USE_FILEDLG_GENERIC
104 #if USE_FONTDLG_GENERIC
105 #include "wx/generic/fontdlgg.h"
106 #endif // USE_FONTDLG_GENERIC
110 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
111 EVT_PAINT(MyCanvas::OnPaint
)
116 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
117 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
120 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
121 #endif // wxUSE_COLOURDLG
124 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
125 #endif // wxUSE_FONTDLG
128 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
129 #endif // wxUSE_LOG_DIALOG
132 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
133 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
134 #endif // wxUSE_TEXTDLG
137 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
138 #endif // wxUSE_NUMBERDLG
141 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
142 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
143 #endif // wxUSE_CHOICEDLG
146 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
147 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
148 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
149 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
150 #endif // wxUSE_FILEDLG
152 #if USE_FILEDLG_GENERIC
153 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
154 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
155 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
156 #endif // USE_FILEDLG_GENERIC
159 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
160 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
161 #endif // wxUSE_DIRDLG
163 #if USE_MODAL_PRESENTATION
164 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
165 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
166 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
167 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
170 #if wxUSE_STARTUP_TIPS
171 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
172 #endif // wxUSE_STARTUP_TIPS
174 #if USE_FONTDLG_GENERIC
175 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
176 #endif // USE_FONTDLG_GENERIC
178 #if USE_DIRDLG_GENERIC
179 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
180 #endif // wxMSW || wxMAC
182 #if USE_COLOURDLG_GENERIC
183 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
184 #endif // USE_COLOURDLG_GENERIC
186 #if wxUSE_PROGRESSDLG
187 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
188 #endif // wxUSE_PROGRESSDLG
191 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
192 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
193 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
194 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
195 #endif // wxUSE_ABOUTDLG
198 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
199 #endif // wxUSE_BUSYINFO
201 #if wxUSE_FINDREPLDLG
202 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
203 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
205 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
206 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
207 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
208 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
209 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
210 #endif // wxUSE_FINDREPLDLG
212 #if USE_SETTINGS_DIALOG
213 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
214 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
215 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
218 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
220 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
223 #if USE_MODAL_PRESENTATION
225 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
226 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
229 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
230 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
231 EVT_CLOSE(MyModelessDialog::OnClose
)
234 #endif // USE_MODAL_PRESENTATION
236 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
238 // `Main program' equivalent, creating windows and returning main app frame
241 if ( !wxApp::OnInit() )
245 wxInitAllImageHandlers();
248 m_canvasTextColour
= *wxBLACK
;
249 m_canvasFont
= *wxNORMAL_FONT
;
251 // Create the main frame window
252 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
255 wxMenu
*menuDlg
= new wxMenu
;
257 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
260 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
262 wxMenu
*choices_menu
= new wxMenu
;
265 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
266 #endif // wxUSE_COLOURDLG
269 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
270 #endif // wxUSE_FONTDLG
273 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
274 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
275 #endif // wxUSE_CHOICEDLG
277 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
278 choices_menu
->AppendSeparator();
279 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
281 #if USE_COLOURDLG_GENERIC
282 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
283 #endif // USE_COLOURDLG_GENERIC
285 #if USE_FONTDLG_GENERIC
286 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
287 #endif // USE_FONTDLG_GENERIC
289 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
290 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
293 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
295 wxMenu
*entry_menu
= new wxMenu
;
298 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
299 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
300 #endif // wxUSE_TEXTDLG
303 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
304 #endif // wxUSE_NUMBERDLG
306 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
308 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
313 wxMenu
*filedlg_menu
= new wxMenu
;
314 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
315 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
316 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
317 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
319 #if USE_FILEDLG_GENERIC
320 filedlg_menu
->AppendSeparator();
321 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
322 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
323 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
324 #endif // USE_FILEDLG_GENERIC
326 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
328 #endif // wxUSE_FILEDLG
331 wxMenu
*dir_menu
= new wxMenu
;
333 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
334 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
335 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
337 #if USE_DIRDLG_GENERIC
338 dir_menu
->AppendSeparator();
339 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
340 #endif // USE_DIRDLG_GENERIC
342 #endif // wxUSE_DIRDLG
345 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
347 wxMenu
*info_menu
= new wxMenu
;
349 #if wxUSE_STARTUP_TIPS
350 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
351 #endif // wxUSE_STARTUP_TIPS
353 #if wxUSE_PROGRESSDLG
354 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
355 #endif // wxUSE_PROGRESSDLG
358 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
359 #endif // wxUSE_BUSYINFO
362 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
363 #endif // wxUSE_LOG_DIALOG
365 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
367 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
370 #if wxUSE_FINDREPLDLG
371 wxMenu
*find_menu
= new wxMenu
;
372 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
373 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
374 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
375 #endif // wxUSE_FINDREPLDLG
377 #if USE_MODAL_PRESENTATION
378 wxMenu
*dialogs_menu
= new wxMenu
;
379 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
380 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
381 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
382 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
383 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
384 #endif // USE_MODAL_PRESENTATION
386 #if USE_SETTINGS_DIALOG
387 wxMenu
*sheet_menu
= new wxMenu
;
388 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
389 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
391 if (wxPlatformIs(wxPORT_MAC
))
392 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
395 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
398 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
399 #endif // USE_SETTINGS_DIALOG
401 menuDlg
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
403 menuDlg
->AppendSeparator();
404 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
407 wxMenu
*menuHelp
= new wxMenu
;
408 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
409 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
410 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
411 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
412 #endif // wxUSE_ABOUTDLG
414 wxMenuBar
*menubar
= new wxMenuBar
;
415 menubar
->Append(menuDlg
, _T("&Dialogs"));
417 menubar
->Append(menuHelp
, _T("&Help"));
418 #endif // wxUSE_ABOUTDLG
420 frame
->SetMenuBar(menubar
);
422 myCanvas
= new MyCanvas(frame
);
423 myCanvas
->SetBackgroundColour(*wxWHITE
);
425 frame
->Centre(wxBOTH
);
435 // My frame constructor
436 MyFrame::MyFrame(wxWindow
*parent
,
437 const wxString
& title
)
438 : wxFrame(parent
, wxID_ANY
, title
)
442 #if USE_MODAL_PRESENTATION
443 m_dialog
= (MyModelessDialog
*)NULL
;
444 #endif // USE_MODAL_PRESENTATION
446 #if wxUSE_FINDREPLDLG
452 m_clrData
.SetChooseFull(true);
453 for (int i
= 0; i
< 16; i
++)
455 m_clrData
.SetCustomColour(
458 (unsigned char)(i
*16),
459 (unsigned char)(i
*16),
460 (unsigned char)(i
*16)
464 #endif // wxUSE_COLOURDLG
468 #endif // wxUSE_STATUSBAR
472 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
474 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
476 wxColourDialog
dialog(this, &m_clrData
);
477 dialog
.SetTitle(_T("Choose the background colour"));
478 if (dialog
.ShowModal() == wxID_OK
)
480 m_clrData
= dialog
.GetColourData();
481 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
482 myCanvas
->ClearBackground();
486 #endif // wxUSE_COLOURDLG
488 #if USE_COLOURDLG_GENERIC
489 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
491 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
493 //FIXME:TODO:This has no effect...
494 m_clrData
.SetChooseFull(true);
496 for (int i
= 0; i
< 16; i
++)
499 (unsigned char)(i
*16),
500 (unsigned char)(i
*16),
501 (unsigned char)(i
*16)
503 m_clrData
.SetCustomColour(i
, colour
);
506 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
507 if (dialog
->ShowModal() == wxID_OK
)
509 m_clrData
= dialog
->GetColourData();
510 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
511 myCanvas
->ClearBackground();
516 #endif // USE_COLOURDLG_GENERIC
519 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
522 data
.SetInitialFont(wxGetApp().m_canvasFont
);
523 data
.SetColour(wxGetApp().m_canvasTextColour
);
525 // you might also do this:
527 // wxFontDialog dialog;
528 // if ( !dialog.Create(this, data) { ... error ... }
530 wxFontDialog
dialog(this, data
);
532 if (dialog
.ShowModal() == wxID_OK
)
534 wxFontData retData
= dialog
.GetFontData();
535 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
536 wxGetApp().m_canvasTextColour
= retData
.GetColour();
539 //else: cancelled by the user, don't change the font
541 #endif // wxUSE_FONTDLG
543 #if USE_FONTDLG_GENERIC
544 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
547 data
.SetInitialFont(wxGetApp().m_canvasFont
);
548 data
.SetColour(wxGetApp().m_canvasTextColour
);
550 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
551 if (dialog
->ShowModal() == wxID_OK
)
553 wxFontData retData
= dialog
->GetFontData();
554 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
555 wxGetApp().m_canvasTextColour
= retData
.GetColour();
560 #endif // USE_FONTDLG_GENERIC
563 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
565 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
566 // being flushed -- test it
569 wxLogMessage(wxT("This is some message - everything is ok so far."));
570 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
571 wxLogWarning(wxT("And then something went wrong!"));
573 // and if ~wxBusyCursor doesn't do it, then call it manually
577 wxLogError(wxT("Intermediary error handler decided to abort."));
578 wxLogError(wxT("The top level caller detected an unrecoverable error."));
580 wxLog::FlushActive();
582 wxLogMessage(wxT("And this is the same dialog but with only one message."));
584 #endif // wxUSE_LOG_DIALOG
586 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
588 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
589 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
591 switch ( dialog
.ShowModal() )
594 wxLogStatus(wxT("You pressed \"Yes\""));
598 wxLogStatus(wxT("You pressed \"No\""));
602 wxLogStatus(wxT("You pressed \"Cancel\""));
606 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
611 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
613 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
614 _T("Even two rows of text."),
615 _T("Enter a number:"), _T("Numeric input test"),
622 msg
= _T("Invalid number entered or dialog cancelled.");
627 msg
.Printf(_T("You've entered %lu"), res
);
628 icon
= wxICON_INFORMATION
;
631 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
633 #endif // wxUSE_NUMBERDLG
636 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
638 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
639 _T("Password entry dialog"),
644 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
645 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
649 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
651 wxTextEntryDialog
dialog(this,
652 _T("This is a small sample\n")
653 _T("A long, long string to test out the text entrybox"),
654 _T("Please enter a string"),
658 if (dialog
.ShowModal() == wxID_OK
)
660 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
663 #endif // wxUSE_TEXTDLG
666 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
668 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
670 wxSingleChoiceDialog
dialog(this,
671 _T("This is a small sample\n")
672 _T("A single-choice convenience dialog"),
673 _T("Please select a value"),
674 WXSIZEOF(choices
), choices
);
676 dialog
.SetSelection(2);
678 if (dialog
.ShowModal() == wxID_OK
)
680 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
685 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
687 const wxString choices
[] =
689 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
690 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
691 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
694 wxArrayInt selections
;
695 size_t count
= wxGetMultipleChoices(selections
,
696 _T("This is a small sample\n")
697 _T("A multi-choice convenience dialog"),
698 _T("Please select a value"),
699 WXSIZEOF(choices
), choices
,
704 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
705 for ( size_t n
= 0; n
< count
; n
++ )
707 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
708 (unsigned)n
, (unsigned)selections
[n
],
709 choices
[selections
[n
]].c_str());
713 //else: cancelled or nothing selected
715 #endif // wxUSE_CHOICEDLG
718 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
723 _T("Testing open file dialog"),
727 _T("C++ files (*.cpp)|*.cpp")
729 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
733 dialog
.CentreOnParent();
734 dialog
.SetDirectory(wxGetHomeDir());
736 if (dialog
.ShowModal() == wxID_OK
)
739 info
.Printf(_T("Full file name: %s\n")
742 dialog
.GetPath().c_str(),
743 dialog
.GetDirectory().c_str(),
744 dialog
.GetFilename().c_str());
745 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
750 // this shows how to take advantage of specifying a default extension in the
751 // call to wxFileSelector: it is remembered after each new call and the next
752 // one will use it by default
753 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
755 static wxString s_extDef
;
756 wxString path
= wxFileSelector(
757 _T("Select the file to load"),
758 wxEmptyString
, wxEmptyString
,
762 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
763 wxFileSelectorDefaultWildcardStr
,
764 wxFileSelectorDefaultWildcardStr
766 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
773 // it is just a sample, would use wxSplitPath in real program
774 s_extDef
= path
.AfterLast(_T('.'));
776 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
777 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
780 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
784 _T("C++ files (*.cpp)|*.cpp");
788 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
789 wxFileSelectorDefaultWildcardStr
,
790 wxFileSelectorDefaultWildcardStr
793 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
794 wxEmptyString
, wxEmptyString
, wildcards
,
795 wxFD_OPEN
|wxFD_MULTIPLE
);
797 if (dialog
.ShowModal() == wxID_OK
)
799 wxArrayString paths
, filenames
;
801 dialog
.GetPaths(paths
);
802 dialog
.GetFilenames(filenames
);
805 size_t count
= paths
.GetCount();
806 for ( size_t n
= 0; n
< count
; n
++ )
808 s
.Printf(_T("File %d: %s (%s)\n"),
809 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
813 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
816 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
821 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
823 wxFileDialog
dialog(this,
824 _T("Testing save file dialog"),
827 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
828 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
830 dialog
.SetFilterIndex(1);
832 if (dialog
.ShowModal() == wxID_OK
)
834 wxLogMessage(_T("%s, filter %d"),
835 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
838 #endif // wxUSE_FILEDLG
840 #if USE_FILEDLG_GENERIC
841 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
843 wxGenericFileDialog dialog
846 _T("Testing open file dialog"),
849 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
852 dialog
.SetDirectory(wxGetHomeDir());
854 if (dialog
.ShowModal() == wxID_OK
)
857 info
.Printf(_T("Full file name: %s\n")
860 dialog
.GetPath().c_str(),
861 dialog
.GetDirectory().c_str(),
862 dialog
.GetFilename().c_str());
863 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
868 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
870 // On PocketPC you can disable OK-only dialogs policy using system option
871 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
872 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
874 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
875 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
876 wxEmptyString
, wxEmptyString
, wildcards
,
879 if (dialog
.ShowModal() == wxID_OK
)
881 wxArrayString paths
, filenames
;
883 dialog
.GetPaths(paths
);
884 dialog
.GetFilenames(filenames
);
887 size_t count
= paths
.GetCount();
888 for ( size_t n
= 0; n
< count
; n
++ )
890 s
.Printf(_T("File %d: %s (%s)\n"),
891 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
895 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
898 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
902 // restore system option
903 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
906 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
908 wxGenericFileDialog
dialog(this,
909 _T("Testing save file dialog"),
912 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
913 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
915 dialog
.SetFilterIndex(1);
917 if (dialog
.ShowModal() == wxID_OK
)
919 wxLogMessage(_T("%s, filter %d"),
920 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
923 #endif // USE_FILEDLG_GENERIC
926 void MyFrame::DoDirChoose(int style
)
928 // pass some initial dir to wxDirDialog
930 wxGetHomeDir(&dirHome
);
932 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
934 if (dialog
.ShowModal() == wxID_OK
)
936 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
940 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
942 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
945 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
947 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
949 #endif // wxUSE_DIRDLG
951 #if USE_DIRDLG_GENERIC
952 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
954 // pass some initial dir to wxDirDialog
956 wxGetHomeDir(&dirHome
);
958 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
960 if (dialog
.ShowModal() == wxID_OK
)
962 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
966 #endif // USE_DIRDLG_GENERIC
968 #if USE_MODAL_PRESENTATION
969 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
971 MyModalDialog
dlg(this);
975 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
977 bool show
= GetMenuBar()->IsChecked(event
.GetId());
983 m_dialog
= new MyModelessDialog(this);
986 m_dialog
->Show(true);
990 // If m_dialog is NULL, then possibly the system
991 // didn't report the checked menu item status correctly.
992 // It should be true just after the menu item was selected,
993 // if there was no modeless dialog yet.
995 wxASSERT( m_dialog
!= NULL
);
1001 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1003 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1004 wxDefaultPosition
, wxSize(200, 100));
1005 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1006 dlg
.CentreOnScreen();
1010 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1012 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1013 wxDefaultPosition
, wxSize(200, 100));
1014 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1015 dlg
.CentreOnParent();
1019 #endif // USE_MODAL_PRESENTATION
1021 #if wxUSE_STARTUP_TIPS
1022 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1024 static size_t s_index
= (size_t)-1;
1026 if ( s_index
== (size_t)-1 )
1030 // this is completely bogus, we don't know how many lines are there
1031 // in the file, but who cares, it's a demo only...
1032 s_index
= rand() % 5;
1035 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1037 bool showAtStartup
= wxShowTip(this, tipProvider
);
1039 if ( showAtStartup
)
1041 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1042 wxOK
| wxICON_INFORMATION
, this);
1045 s_index
= tipProvider
->GetCurrentTip();
1048 #endif // wxUSE_STARTUP_TIPS
1050 #if USE_SETTINGS_DIALOG
1051 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1053 SettingsDialog
dialog(this, event
.GetId());
1056 #endif // USE_SETTINGS_DIALOG
1058 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1060 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1064 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1067 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1072 #if wxUSE_PROGRESSDLG
1074 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1076 static const int max
= 100;
1078 wxProgressDialog
dialog(_T("Progress dialog example"),
1079 _T("An informative message"),
1085 // wxPD_AUTO_HIDE | -- try this as well
1087 wxPD_ESTIMATED_TIME
|
1089 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1093 for ( int i
= 0; i
<= max
; i
++ )
1099 // test both modes of wxProgressDialog behaviour: start in
1100 // indeterminate mode but switch to the determinate one later
1101 const bool determinate
= i
> max
/2;
1105 msg
= _T("That's all, folks!");
1107 else if ( !determinate
)
1109 msg
= _T("Testing indeterminate mode");
1111 else if ( determinate
)
1113 msg
= _T("Now in standard determinate mode");
1116 // will be set to true if "Skip" button was pressed
1120 cont
= dialog
.Update(i
, msg
, &skip
);
1124 cont
= dialog
.Pulse(msg
, &skip
);
1127 // each skip will move progress about quarter forward
1133 if ( wxMessageBox(_T("Do you really want to cancel?"),
1134 _T("Progress dialog question"), // caption
1135 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1145 wxLogStatus(wxT("Progress dialog aborted!"));
1149 wxLogStatus(wxT("Countdown from %d finished"), max
);
1153 #endif // wxUSE_PROGRESSDLG
1157 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1159 info
.SetName(_T("Dialogs Sample"));
1160 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1161 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1162 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1163 info
.AddDeveloper(_T("Vadim Zeitlin"));
1166 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1168 InitAboutInfoMinimal(info
);
1170 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1173 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1175 InitAboutInfoMinimal(info
);
1177 // we can add a second developer
1178 info
.AddDeveloper(_T("A.N. Other"));
1180 // or we can add several persons at once like this
1181 static const wxChar
*docwriters
[] =
1183 _T("First D. Writer"),
1187 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1188 info
.SetLicence(wxString::FromAscii(
1189 " wxWindows Library Licence, Version 3.1\n"
1190 " ======================================\n"
1192 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1194 " Everyone is permitted to copy and distribute verbatim copies\n"
1195 " of this licence document, but changing it is not allowed.\n"
1197 " WXWINDOWS LIBRARY LICENCE\n"
1198 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1200 " ...and so on and so forth...\n"
1203 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1206 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1208 wxAboutDialogInfo info
;
1209 InitAboutInfoMinimal(info
);
1214 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1216 wxAboutDialogInfo info
;
1217 InitAboutInfoWebsite(info
);
1222 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1224 wxAboutDialogInfo info
;
1225 InitAboutInfoAll(info
);
1230 // a trivial example of a custom dialog class
1231 class MyAboutDialog
: public wxGenericAboutDialog
1234 MyAboutDialog(const wxAboutDialogInfo
& info
)
1239 // add some custom controls
1240 virtual void DoAddCustomControls()
1242 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1243 AddText(_T("Some custom text"));
1244 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1248 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1250 wxAboutDialogInfo info
;
1251 InitAboutInfoAll(info
);
1253 MyAboutDialog
dlg(info
);
1257 #endif // wxUSE_ABOUTDLG
1261 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1263 wxWindowDisabler disableAll
;
1265 wxBusyInfo
info(_T("Working, please wait..."), this);
1267 for ( int i
= 0; i
< 18; i
++ )
1277 #endif // wxUSE_BUSYINFO
1279 #if wxUSE_FINDREPLDLG
1281 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1285 delete m_dlgReplace
;
1286 m_dlgReplace
= NULL
;
1290 m_dlgReplace
= new wxFindReplaceDialog
1294 _T("Find and replace dialog"),
1298 m_dlgReplace
->Show(true);
1302 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1311 m_dlgFind
= new wxFindReplaceDialog
1320 m_dlgFind
->Show(true);
1324 static wxString
DecodeFindDialogEventFlags(int flags
)
1327 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1328 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1329 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1330 << _T("case sensitive");
1335 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1337 wxEventType type
= event
.GetEventType();
1339 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1341 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1342 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1343 event
.GetFindString().c_str(),
1344 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1346 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1347 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1349 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1350 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1351 event
.GetFindString().c_str(),
1352 event
.GetReplaceString().c_str(),
1353 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1355 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1357 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1361 if ( dlg
== m_dlgFind
)
1364 idMenu
= DIALOGS_FIND
;
1367 else if ( dlg
== m_dlgReplace
)
1369 txt
= _T("Replace");
1370 idMenu
= DIALOGS_REPLACE
;
1371 m_dlgReplace
= NULL
;
1375 txt
= _T("Unknown");
1378 wxFAIL_MSG( _T("unexpected event") );
1381 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1383 if ( idMenu
!= wxID_ANY
)
1385 GetMenuBar()->Check(idMenu
, false);
1392 wxLogError(wxT("Unknown find dialog event!"));
1396 #endif // wxUSE_FINDREPLDLG
1398 // ----------------------------------------------------------------------------
1400 // ----------------------------------------------------------------------------
1402 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1405 dc
.SetFont(wxGetApp().m_canvasFont
);
1406 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1407 dc
.SetBackgroundMode(wxTRANSPARENT
);
1409 _T("wxWidgets common dialogs")
1410 #if !defined(__SMARTPHONE__)
1411 _T(" test application")
1416 #if USE_MODAL_PRESENTATION
1418 // ----------------------------------------------------------------------------
1420 // ----------------------------------------------------------------------------
1422 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1423 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1425 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1427 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1428 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1431 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1432 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1436 sizerTop
->SetSizeHints(this);
1437 sizerTop
->Fit(this);
1440 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1442 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1443 wxOK
| wxICON_INFORMATION
, this);
1446 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1448 if ( event
.CanVeto() )
1450 wxMessageBox(_T("Use the menu item to close this dialog"),
1451 _T("Modeless dialog"),
1452 wxOK
| wxICON_INFORMATION
, this);
1458 // ----------------------------------------------------------------------------
1460 // ----------------------------------------------------------------------------
1462 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1463 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1465 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1467 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1468 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1469 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1471 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1472 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1473 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1474 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1475 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1479 sizerTop
->SetSizeHints(this);
1480 sizerTop
->Fit(this);
1482 m_btnModal
->SetFocus();
1483 m_btnModal
->SetDefault();
1486 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1488 if ( event
.GetEventObject() == m_btnDelete
)
1493 m_btnDelete
->Disable();
1495 else if ( event
.GetEventObject() == m_btnModal
)
1498 wxGetTextFromUser(_T("Dummy prompt"),
1499 _T("Modal dialog called from dialog"),
1500 wxEmptyString
, this);
1502 wxMessageBox(_T("Modal dialog called from dialog"));
1503 #endif // wxUSE_TEXTDLG
1505 else if ( event
.GetEventObject() == m_btnModeless
)
1507 (new MyModelessDialog(this))->Show();
1515 #endif // USE_MODAL_PRESENTATION
1517 #if USE_SETTINGS_DIALOG
1518 // ----------------------------------------------------------------------------
1520 // ----------------------------------------------------------------------------
1522 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1524 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1527 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1529 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1534 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1535 int resizeBorder
= wxRESIZE_BORDER
;
1543 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1544 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1545 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1547 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1549 SetSheetStyle(sheetStyle
);
1550 SetSheetInnerBorder(0);
1551 SetSheetOuterBorder(0);
1553 // create a dummy image list with a few icons
1554 const wxSize
imageSize(32, 32);
1556 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1558 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1560 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1562 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1564 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1569 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1570 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1573 // If using a toolbook, also follow Mac style and don't create buttons
1575 CreateButtons(wxOK
| wxCANCEL
|
1576 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1579 wxBookCtrlBase
* notebook
= GetBookCtrl();
1580 notebook
->SetImageList(m_imageList
);
1582 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1583 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1585 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1586 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1591 SettingsDialog::~SettingsDialog()
1596 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1598 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1600 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1601 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1605 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1606 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1607 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1608 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1612 wxString autoSaveLabel
= _("&Auto-save every");
1613 wxString minsLabel
= _("mins");
1615 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1616 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1619 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1620 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1623 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1625 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1627 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1628 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1632 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1633 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1634 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1635 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1637 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1639 panel
->SetSizer(topSizer
);
1640 topSizer
->Fit(panel
);
1645 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1647 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1649 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1650 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1652 //// PROJECT OR GLOBAL
1653 wxString globalOrProjectChoices
[2];
1654 globalOrProjectChoices
[0] = _("&New projects");
1655 globalOrProjectChoices
[1] = _("&This project");
1657 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1658 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1659 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1661 projectOrGlobal
->SetSelection(0);
1663 //// BACKGROUND STYLE
1664 wxArrayString backgroundStyleChoices
;
1665 backgroundStyleChoices
.Add(wxT("Colour"));
1666 backgroundStyleChoices
.Add(wxT("Image"));
1667 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1669 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1670 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1672 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1674 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1676 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1677 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1678 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1680 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1683 //// FONT SIZE SELECTION
1685 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1686 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1688 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1689 wxSize(80, wxDefaultCoord
));
1690 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1692 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1695 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1696 topSizer
->AddSpacer(5);
1698 panel
->SetSizer(topSizer
);
1699 topSizer
->Fit(panel
);
1704 #endif // USE_SETTINGS_DIALOG