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_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
219 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
221 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
224 #if USE_MODAL_PRESENTATION
226 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
227 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
230 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
231 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
232 EVT_CLOSE(MyModelessDialog::OnClose
)
235 #endif // USE_MODAL_PRESENTATION
237 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
238 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
239 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
242 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
244 // `Main program' equivalent, creating windows and returning main app frame
247 if ( !wxApp::OnInit() )
251 wxInitAllImageHandlers();
254 m_canvasTextColour
= *wxBLACK
;
255 m_canvasFont
= *wxNORMAL_FONT
;
257 // Create the main frame window
258 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
261 wxMenu
*menuDlg
= new wxMenu
;
263 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
266 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
268 wxMenu
*choices_menu
= new wxMenu
;
271 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
272 #endif // wxUSE_COLOURDLG
275 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
276 #endif // wxUSE_FONTDLG
279 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
280 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
281 #endif // wxUSE_CHOICEDLG
283 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
284 choices_menu
->AppendSeparator();
285 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
287 #if USE_COLOURDLG_GENERIC
288 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
289 #endif // USE_COLOURDLG_GENERIC
291 #if USE_FONTDLG_GENERIC
292 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
293 #endif // USE_FONTDLG_GENERIC
295 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
296 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
299 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
301 wxMenu
*entry_menu
= new wxMenu
;
304 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
305 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
306 #endif // wxUSE_TEXTDLG
309 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
310 #endif // wxUSE_NUMBERDLG
312 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
314 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
319 wxMenu
*filedlg_menu
= new wxMenu
;
320 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
321 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
322 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
323 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
325 #if USE_FILEDLG_GENERIC
326 filedlg_menu
->AppendSeparator();
327 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
328 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
329 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
330 #endif // USE_FILEDLG_GENERIC
332 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
334 #endif // wxUSE_FILEDLG
337 wxMenu
*dir_menu
= new wxMenu
;
339 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
340 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
341 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
343 #if USE_DIRDLG_GENERIC
344 dir_menu
->AppendSeparator();
345 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
346 #endif // USE_DIRDLG_GENERIC
348 #endif // wxUSE_DIRDLG
351 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
353 wxMenu
*info_menu
= new wxMenu
;
355 #if wxUSE_STARTUP_TIPS
356 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
357 #endif // wxUSE_STARTUP_TIPS
359 #if wxUSE_PROGRESSDLG
360 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
361 #endif // wxUSE_PROGRESSDLG
364 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
365 #endif // wxUSE_BUSYINFO
368 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
369 #endif // wxUSE_LOG_DIALOG
371 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
373 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
376 #if wxUSE_FINDREPLDLG
377 wxMenu
*find_menu
= new wxMenu
;
378 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
379 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
380 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
381 #endif // wxUSE_FINDREPLDLG
383 #if USE_MODAL_PRESENTATION
384 wxMenu
*dialogs_menu
= new wxMenu
;
385 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
386 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
387 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
388 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
389 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
390 #endif // USE_MODAL_PRESENTATION
392 #if USE_SETTINGS_DIALOG
393 wxMenu
*sheet_menu
= new wxMenu
;
394 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
395 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
397 if (wxPlatformIs(wxPORT_MAC
))
398 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
401 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
404 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
405 #endif // USE_SETTINGS_DIALOG
407 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, _T("&Standard Buttons Sizer Dialog"));
409 menuDlg
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
411 menuDlg
->AppendSeparator();
412 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
415 wxMenu
*menuHelp
= new wxMenu
;
416 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
417 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
418 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
419 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
420 #endif // wxUSE_ABOUTDLG
422 wxMenuBar
*menubar
= new wxMenuBar
;
423 menubar
->Append(menuDlg
, _T("&Dialogs"));
425 menubar
->Append(menuHelp
, _T("&Help"));
426 #endif // wxUSE_ABOUTDLG
428 frame
->SetMenuBar(menubar
);
430 myCanvas
= new MyCanvas(frame
);
431 myCanvas
->SetBackgroundColour(*wxWHITE
);
433 frame
->Centre(wxBOTH
);
443 // My frame constructor
444 MyFrame::MyFrame(wxWindow
*parent
,
445 const wxString
& title
)
446 : wxFrame(parent
, wxID_ANY
, title
)
450 #if USE_MODAL_PRESENTATION
451 m_dialog
= (MyModelessDialog
*)NULL
;
452 #endif // USE_MODAL_PRESENTATION
454 #if wxUSE_FINDREPLDLG
460 m_clrData
.SetChooseFull(true);
461 for (int i
= 0; i
< 16; i
++)
463 m_clrData
.SetCustomColour(
466 (unsigned char)(i
*16),
467 (unsigned char)(i
*16),
468 (unsigned char)(i
*16)
472 #endif // wxUSE_COLOURDLG
476 #endif // wxUSE_STATUSBAR
480 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
482 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
484 wxColourDialog
dialog(this, &m_clrData
);
485 dialog
.SetTitle(_T("Choose the background colour"));
486 if (dialog
.ShowModal() == wxID_OK
)
488 m_clrData
= dialog
.GetColourData();
489 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
490 myCanvas
->ClearBackground();
494 #endif // wxUSE_COLOURDLG
496 #if USE_COLOURDLG_GENERIC
497 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
499 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
501 //FIXME:TODO:This has no effect...
502 m_clrData
.SetChooseFull(true);
504 for (int i
= 0; i
< 16; i
++)
507 (unsigned char)(i
*16),
508 (unsigned char)(i
*16),
509 (unsigned char)(i
*16)
511 m_clrData
.SetCustomColour(i
, colour
);
514 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
515 if (dialog
->ShowModal() == wxID_OK
)
517 m_clrData
= dialog
->GetColourData();
518 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
519 myCanvas
->ClearBackground();
524 #endif // USE_COLOURDLG_GENERIC
527 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
530 data
.SetInitialFont(wxGetApp().m_canvasFont
);
531 data
.SetColour(wxGetApp().m_canvasTextColour
);
533 // you might also do this:
535 // wxFontDialog dialog;
536 // if ( !dialog.Create(this, data) { ... error ... }
538 wxFontDialog
dialog(this, data
);
540 if (dialog
.ShowModal() == wxID_OK
)
542 wxFontData retData
= dialog
.GetFontData();
543 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
544 wxGetApp().m_canvasTextColour
= retData
.GetColour();
547 //else: cancelled by the user, don't change the font
549 #endif // wxUSE_FONTDLG
551 #if USE_FONTDLG_GENERIC
552 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
555 data
.SetInitialFont(wxGetApp().m_canvasFont
);
556 data
.SetColour(wxGetApp().m_canvasTextColour
);
558 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
559 if (dialog
->ShowModal() == wxID_OK
)
561 wxFontData retData
= dialog
->GetFontData();
562 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
563 wxGetApp().m_canvasTextColour
= retData
.GetColour();
568 #endif // USE_FONTDLG_GENERIC
571 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
573 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
574 // being flushed -- test it
577 wxLogMessage(wxT("This is some message - everything is ok so far."));
578 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
579 wxLogWarning(wxT("And then something went wrong!"));
581 // and if ~wxBusyCursor doesn't do it, then call it manually
585 wxLogError(wxT("Intermediary error handler decided to abort."));
586 wxLogError(wxT("The top level caller detected an unrecoverable error."));
588 wxLog::FlushActive();
590 wxLogMessage(wxT("And this is the same dialog but with only one message."));
592 #endif // wxUSE_LOG_DIALOG
594 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
596 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
597 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
599 switch ( dialog
.ShowModal() )
602 wxLogStatus(wxT("You pressed \"Yes\""));
606 wxLogStatus(wxT("You pressed \"No\""));
610 wxLogStatus(wxT("You pressed \"Cancel\""));
614 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
619 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
621 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
622 _T("Even two rows of text."),
623 _T("Enter a number:"), _T("Numeric input test"),
630 msg
= _T("Invalid number entered or dialog cancelled.");
635 msg
.Printf(_T("You've entered %lu"), res
);
636 icon
= wxICON_INFORMATION
;
639 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
641 #endif // wxUSE_NUMBERDLG
644 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
646 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
647 _T("Password entry dialog"),
652 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
653 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
657 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
659 wxTextEntryDialog
dialog(this,
660 _T("This is a small sample\n")
661 _T("A long, long string to test out the text entrybox"),
662 _T("Please enter a string"),
666 if (dialog
.ShowModal() == wxID_OK
)
668 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
671 #endif // wxUSE_TEXTDLG
674 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
676 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
678 wxSingleChoiceDialog
dialog(this,
679 _T("This is a small sample\n")
680 _T("A single-choice convenience dialog"),
681 _T("Please select a value"),
682 WXSIZEOF(choices
), choices
);
684 dialog
.SetSelection(2);
686 if (dialog
.ShowModal() == wxID_OK
)
688 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
693 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
695 const wxString choices
[] =
697 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
698 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
699 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
702 wxArrayInt selections
;
703 size_t count
= wxGetMultipleChoices(selections
,
704 _T("This is a small sample\n")
705 _T("A multi-choice convenience dialog"),
706 _T("Please select a value"),
707 WXSIZEOF(choices
), choices
,
712 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
713 for ( size_t n
= 0; n
< count
; n
++ )
715 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
716 (unsigned)n
, (unsigned)selections
[n
],
717 choices
[selections
[n
]].c_str());
721 //else: cancelled or nothing selected
723 #endif // wxUSE_CHOICEDLG
726 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
731 _T("Testing open file dialog"),
735 _T("C++ files (*.cpp)|*.cpp")
737 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
741 dialog
.CentreOnParent();
742 dialog
.SetDirectory(wxGetHomeDir());
744 if (dialog
.ShowModal() == wxID_OK
)
747 info
.Printf(_T("Full file name: %s\n")
750 dialog
.GetPath().c_str(),
751 dialog
.GetDirectory().c_str(),
752 dialog
.GetFilename().c_str());
753 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
758 // this shows how to take advantage of specifying a default extension in the
759 // call to wxFileSelector: it is remembered after each new call and the next
760 // one will use it by default
761 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
763 static wxString s_extDef
;
764 wxString path
= wxFileSelector(
765 _T("Select the file to load"),
766 wxEmptyString
, wxEmptyString
,
770 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
771 wxFileSelectorDefaultWildcardStr
,
772 wxFileSelectorDefaultWildcardStr
774 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
781 // it is just a sample, would use wxSplitPath in real program
782 s_extDef
= path
.AfterLast(_T('.'));
784 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
785 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
788 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
792 _T("C++ files (*.cpp)|*.cpp");
796 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
797 wxFileSelectorDefaultWildcardStr
,
798 wxFileSelectorDefaultWildcardStr
801 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
802 wxEmptyString
, wxEmptyString
, wildcards
,
803 wxFD_OPEN
|wxFD_MULTIPLE
);
805 if (dialog
.ShowModal() == wxID_OK
)
807 wxArrayString paths
, filenames
;
809 dialog
.GetPaths(paths
);
810 dialog
.GetFilenames(filenames
);
813 size_t count
= paths
.GetCount();
814 for ( size_t n
= 0; n
< count
; n
++ )
816 s
.Printf(_T("File %d: %s (%s)\n"),
817 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
821 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
824 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
829 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
831 wxFileDialog
dialog(this,
832 _T("Testing save file dialog"),
835 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
836 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
838 dialog
.SetFilterIndex(1);
840 if (dialog
.ShowModal() == wxID_OK
)
842 wxLogMessage(_T("%s, filter %d"),
843 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
846 #endif // wxUSE_FILEDLG
848 #if USE_FILEDLG_GENERIC
849 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
851 wxGenericFileDialog dialog
854 _T("Testing open file dialog"),
857 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
860 dialog
.SetDirectory(wxGetHomeDir());
862 if (dialog
.ShowModal() == wxID_OK
)
865 info
.Printf(_T("Full file name: %s\n")
868 dialog
.GetPath().c_str(),
869 dialog
.GetDirectory().c_str(),
870 dialog
.GetFilename().c_str());
871 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
876 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
878 // On PocketPC you can disable OK-only dialogs policy using system option
879 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
880 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
882 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
883 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
884 wxEmptyString
, wxEmptyString
, wildcards
,
887 if (dialog
.ShowModal() == wxID_OK
)
889 wxArrayString paths
, filenames
;
891 dialog
.GetPaths(paths
);
892 dialog
.GetFilenames(filenames
);
895 size_t count
= paths
.GetCount();
896 for ( size_t n
= 0; n
< count
; n
++ )
898 s
.Printf(_T("File %d: %s (%s)\n"),
899 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
903 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
906 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
910 // restore system option
911 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
914 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
916 wxGenericFileDialog
dialog(this,
917 _T("Testing save file dialog"),
920 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
921 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
923 dialog
.SetFilterIndex(1);
925 if (dialog
.ShowModal() == wxID_OK
)
927 wxLogMessage(_T("%s, filter %d"),
928 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
931 #endif // USE_FILEDLG_GENERIC
934 void MyFrame::DoDirChoose(int style
)
936 // pass some initial dir to wxDirDialog
938 wxGetHomeDir(&dirHome
);
940 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
942 if (dialog
.ShowModal() == wxID_OK
)
944 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
948 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
950 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
953 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
955 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
957 #endif // wxUSE_DIRDLG
959 #if USE_DIRDLG_GENERIC
960 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
962 // pass some initial dir to wxDirDialog
964 wxGetHomeDir(&dirHome
);
966 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
968 if (dialog
.ShowModal() == wxID_OK
)
970 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
974 #endif // USE_DIRDLG_GENERIC
976 #if USE_MODAL_PRESENTATION
977 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
979 MyModalDialog
dlg(this);
983 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
985 bool show
= GetMenuBar()->IsChecked(event
.GetId());
991 m_dialog
= new MyModelessDialog(this);
994 m_dialog
->Show(true);
998 // If m_dialog is NULL, then possibly the system
999 // didn't report the checked menu item status correctly.
1000 // It should be true just after the menu item was selected,
1001 // if there was no modeless dialog yet.
1003 wxASSERT( m_dialog
!= NULL
);
1009 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1011 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1012 wxDefaultPosition
, wxSize(200, 100));
1013 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1014 dlg
.CentreOnScreen();
1018 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1020 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1021 wxDefaultPosition
, wxSize(200, 100));
1022 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1023 dlg
.CentreOnParent();
1027 #endif // USE_MODAL_PRESENTATION
1029 #if wxUSE_STARTUP_TIPS
1030 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1032 static size_t s_index
= (size_t)-1;
1034 if ( s_index
== (size_t)-1 )
1038 // this is completely bogus, we don't know how many lines are there
1039 // in the file, but who cares, it's a demo only...
1040 s_index
= rand() % 5;
1043 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1045 bool showAtStartup
= wxShowTip(this, tipProvider
);
1047 if ( showAtStartup
)
1049 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1050 wxOK
| wxICON_INFORMATION
, this);
1053 s_index
= tipProvider
->GetCurrentTip();
1056 #endif // wxUSE_STARTUP_TIPS
1058 #if USE_SETTINGS_DIALOG
1059 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1061 SettingsDialog
dialog(this, event
.GetId());
1064 #endif // USE_SETTINGS_DIALOG
1066 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1068 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1072 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1075 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1077 StdButtonSizerDialog
dialog(this);
1081 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1086 #if wxUSE_PROGRESSDLG
1088 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1090 static const int max
= 100;
1092 wxProgressDialog
dialog(_T("Progress dialog example"),
1093 _T("An informative message"),
1099 // wxPD_AUTO_HIDE | -- try this as well
1101 wxPD_ESTIMATED_TIME
|
1103 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1107 for ( int i
= 0; i
<= max
; i
++ )
1113 // test both modes of wxProgressDialog behaviour: start in
1114 // indeterminate mode but switch to the determinate one later
1115 const bool determinate
= i
> max
/2;
1119 msg
= _T("That's all, folks!");
1121 else if ( !determinate
)
1123 msg
= _T("Testing indeterminate mode");
1125 else if ( determinate
)
1127 msg
= _T("Now in standard determinate mode");
1130 // will be set to true if "Skip" button was pressed
1134 cont
= dialog
.Update(i
, msg
, &skip
);
1138 cont
= dialog
.Pulse(msg
, &skip
);
1141 // each skip will move progress about quarter forward
1147 if ( wxMessageBox(_T("Do you really want to cancel?"),
1148 _T("Progress dialog question"), // caption
1149 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1159 wxLogStatus(wxT("Progress dialog aborted!"));
1163 wxLogStatus(wxT("Countdown from %d finished"), max
);
1167 #endif // wxUSE_PROGRESSDLG
1171 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1173 info
.SetName(_T("Dialogs Sample"));
1174 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1175 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1176 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1177 info
.AddDeveloper(_T("Vadim Zeitlin"));
1180 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1182 InitAboutInfoMinimal(info
);
1184 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1187 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1189 InitAboutInfoMinimal(info
);
1191 // we can add a second developer
1192 info
.AddDeveloper(_T("A.N. Other"));
1194 // or we can add several persons at once like this
1195 static const wxChar
*docwriters
[] =
1197 _T("First D. Writer"),
1201 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1202 info
.SetLicence(wxString::FromAscii(
1203 " wxWindows Library Licence, Version 3.1\n"
1204 " ======================================\n"
1206 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1208 " Everyone is permitted to copy and distribute verbatim copies\n"
1209 " of this licence document, but changing it is not allowed.\n"
1211 " WXWINDOWS LIBRARY LICENCE\n"
1212 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1214 " ...and so on and so forth...\n"
1217 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1220 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1222 wxAboutDialogInfo info
;
1223 InitAboutInfoMinimal(info
);
1228 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1230 wxAboutDialogInfo info
;
1231 InitAboutInfoWebsite(info
);
1236 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1238 wxAboutDialogInfo info
;
1239 InitAboutInfoAll(info
);
1244 // a trivial example of a custom dialog class
1245 class MyAboutDialog
: public wxGenericAboutDialog
1248 MyAboutDialog(const wxAboutDialogInfo
& info
)
1253 // add some custom controls
1254 virtual void DoAddCustomControls()
1256 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1257 AddText(_T("Some custom text"));
1258 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1262 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1264 wxAboutDialogInfo info
;
1265 InitAboutInfoAll(info
);
1267 MyAboutDialog
dlg(info
);
1271 #endif // wxUSE_ABOUTDLG
1275 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1277 wxWindowDisabler disableAll
;
1279 wxBusyInfo
info(_T("Working, please wait..."), this);
1281 for ( int i
= 0; i
< 18; i
++ )
1291 #endif // wxUSE_BUSYINFO
1293 #if wxUSE_FINDREPLDLG
1295 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1299 delete m_dlgReplace
;
1300 m_dlgReplace
= NULL
;
1304 m_dlgReplace
= new wxFindReplaceDialog
1308 _T("Find and replace dialog"),
1312 m_dlgReplace
->Show(true);
1316 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1325 m_dlgFind
= new wxFindReplaceDialog
1334 m_dlgFind
->Show(true);
1338 static wxString
DecodeFindDialogEventFlags(int flags
)
1341 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1342 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1343 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1344 << _T("case sensitive");
1349 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1351 wxEventType type
= event
.GetEventType();
1353 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1355 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1356 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1357 event
.GetFindString().c_str(),
1358 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1360 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1361 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1363 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1364 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1365 event
.GetFindString().c_str(),
1366 event
.GetReplaceString().c_str(),
1367 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1369 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1371 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1375 if ( dlg
== m_dlgFind
)
1378 idMenu
= DIALOGS_FIND
;
1381 else if ( dlg
== m_dlgReplace
)
1383 txt
= _T("Replace");
1384 idMenu
= DIALOGS_REPLACE
;
1385 m_dlgReplace
= NULL
;
1389 txt
= _T("Unknown");
1392 wxFAIL_MSG( _T("unexpected event") );
1395 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1397 if ( idMenu
!= wxID_ANY
)
1399 GetMenuBar()->Check(idMenu
, false);
1406 wxLogError(wxT("Unknown find dialog event!"));
1410 #endif // wxUSE_FINDREPLDLG
1412 // ----------------------------------------------------------------------------
1414 // ----------------------------------------------------------------------------
1416 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1419 dc
.SetFont(wxGetApp().m_canvasFont
);
1420 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1421 dc
.SetBackgroundMode(wxTRANSPARENT
);
1423 _T("wxWidgets common dialogs")
1424 #if !defined(__SMARTPHONE__)
1425 _T(" test application")
1430 #if USE_MODAL_PRESENTATION
1432 // ----------------------------------------------------------------------------
1434 // ----------------------------------------------------------------------------
1436 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1437 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1439 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1441 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1442 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1445 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1446 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1450 sizerTop
->SetSizeHints(this);
1451 sizerTop
->Fit(this);
1454 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1456 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1457 wxOK
| wxICON_INFORMATION
, this);
1460 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1462 if ( event
.CanVeto() )
1464 wxMessageBox(_T("Use the menu item to close this dialog"),
1465 _T("Modeless dialog"),
1466 wxOK
| wxICON_INFORMATION
, this);
1472 // ----------------------------------------------------------------------------
1474 // ----------------------------------------------------------------------------
1476 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1477 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1479 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1481 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1482 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1483 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1485 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1486 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1487 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1488 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1489 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1493 sizerTop
->SetSizeHints(this);
1494 sizerTop
->Fit(this);
1496 m_btnModal
->SetFocus();
1497 m_btnModal
->SetDefault();
1500 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1502 if ( event
.GetEventObject() == m_btnDelete
)
1507 m_btnDelete
->Disable();
1509 else if ( event
.GetEventObject() == m_btnModal
)
1512 wxGetTextFromUser(_T("Dummy prompt"),
1513 _T("Modal dialog called from dialog"),
1514 wxEmptyString
, this);
1516 wxMessageBox(_T("Modal dialog called from dialog"));
1517 #endif // wxUSE_TEXTDLG
1519 else if ( event
.GetEventObject() == m_btnModeless
)
1521 (new MyModelessDialog(this))->Show();
1529 #endif // USE_MODAL_PRESENTATION
1531 // ----------------------------------------------------------------------------
1532 // StdButtonSizerDialog
1533 // ----------------------------------------------------------------------------
1535 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1536 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1537 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1538 m_buttonsSizer(NULL
)
1540 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1542 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1543 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1545 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
1547 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
1549 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1550 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
1552 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
1554 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
1556 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
1558 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1559 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
1561 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
1563 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
1564 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
1565 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
1567 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
1569 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
1570 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
1572 sizer
->Add(sizerInside1
, 0, 0, 0);
1573 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
1574 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
1575 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1577 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
1578 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
1580 sizer
->Add(sizerInside2
, 0, 0, 0);
1581 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
1582 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
1583 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1585 sizerTop
->Add(sizer
, 0, wxALL
, 5);
1587 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
1588 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
1589 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
1591 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
1593 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
1595 EnableDisableControls();
1599 sizerTop
->SetSizeHints(this);
1604 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
1608 m_buttonsSizer
->DeleteWindows();
1609 GetSizer()->Remove(m_buttonsSizer
);
1612 EnableDisableControls();
1615 unsigned long numButtons
= 0;
1617 if (m_chkboxAffirmativeButton
->IsChecked())
1619 if (m_radiobtnOk
->GetValue())
1624 else if (m_radiobtnYes
->GetValue())
1631 if (m_chkboxDismissButton
->IsChecked())
1633 if (m_radiobtnCancel
->GetValue())
1639 else if (m_radiobtnClose
->GetValue())
1647 if (m_chkboxApply
->IsChecked())
1653 if (m_chkboxNo
->IsChecked())
1659 if (m_chkboxHelp
->IsChecked())
1665 if (m_chkboxNoDefault
->IsChecked())
1667 flags
|= wxNO_DEFAULT
;
1670 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
1671 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
1674 GetSizer()->SetSizeHints(this);
1677 void StdButtonSizerDialog::EnableDisableControls()
1679 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
1681 m_radiobtnOk
->Enable(affButtonEnabled
);
1682 m_radiobtnYes
->Enable(affButtonEnabled
);
1684 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
1686 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
1687 m_radiobtnClose
->Enable(dismissButtonEnabled
);
1690 #if USE_SETTINGS_DIALOG
1691 // ----------------------------------------------------------------------------
1693 // ----------------------------------------------------------------------------
1695 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1697 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1700 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1702 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1707 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1708 int resizeBorder
= wxRESIZE_BORDER
;
1716 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1717 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1718 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1720 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1722 SetSheetStyle(sheetStyle
);
1723 SetSheetInnerBorder(0);
1724 SetSheetOuterBorder(0);
1726 // create a dummy image list with a few icons
1727 const wxSize
imageSize(32, 32);
1729 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1731 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1733 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1735 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1737 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1742 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1743 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1746 // If using a toolbook, also follow Mac style and don't create buttons
1748 CreateButtons(wxOK
| wxCANCEL
|
1749 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1752 wxBookCtrlBase
* notebook
= GetBookCtrl();
1753 notebook
->SetImageList(m_imageList
);
1755 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1756 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1758 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1759 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1764 SettingsDialog::~SettingsDialog()
1769 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1771 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1773 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1774 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1778 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1779 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1780 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1781 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1785 wxString autoSaveLabel
= _("&Auto-save every");
1786 wxString minsLabel
= _("mins");
1788 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1789 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1792 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1793 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1796 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1798 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1800 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1801 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1805 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1806 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1807 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1808 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1810 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1812 panel
->SetSizer(topSizer
);
1813 topSizer
->Fit(panel
);
1818 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1820 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1822 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1823 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1825 //// PROJECT OR GLOBAL
1826 wxString globalOrProjectChoices
[2];
1827 globalOrProjectChoices
[0] = _("&New projects");
1828 globalOrProjectChoices
[1] = _("&This project");
1830 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1831 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1832 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1834 projectOrGlobal
->SetSelection(0);
1836 //// BACKGROUND STYLE
1837 wxArrayString backgroundStyleChoices
;
1838 backgroundStyleChoices
.Add(wxT("Colour"));
1839 backgroundStyleChoices
.Add(wxT("Image"));
1840 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1842 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1843 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1845 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1847 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1849 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1850 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1851 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1853 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1856 //// FONT SIZE SELECTION
1858 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1859 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1861 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1862 wxSize(80, wxDefaultCoord
));
1863 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1865 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1868 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1869 topSizer
->AddSpacer(5);
1871 panel
->SetSizer(topSizer
);
1872 topSizer
->Fit(panel
);
1877 #endif // USE_SETTINGS_DIALOG