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
,
597 _T("This is a message box\nA long, long string to test out the message box properly"),
598 _T("Message box text"),
599 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
| wxICON_INFORMATION
);
601 if ( dialog
.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
603 dialog
.SetExtendedMessage(_T("This platform supports custom button labels"));
607 dialog
.SetExtendedMessage(_T("Custom button labels are not supported."));
610 switch ( dialog
.ShowModal() )
613 wxLogStatus(wxT("You pressed \"Yes\""));
617 wxLogStatus(wxT("You pressed \"No\""));
621 wxLogStatus(wxT("You pressed \"Cancel\""));
625 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
630 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
632 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
633 _T("Even two rows of text."),
634 _T("Enter a number:"), _T("Numeric input test"),
641 msg
= _T("Invalid number entered or dialog cancelled.");
646 msg
.Printf(_T("You've entered %lu"), res
);
647 icon
= wxICON_INFORMATION
;
650 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
652 #endif // wxUSE_NUMBERDLG
655 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
657 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
658 _T("Password entry dialog"),
663 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
664 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
668 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
670 wxTextEntryDialog
dialog(this,
671 _T("This is a small sample\n")
672 _T("A long, long string to test out the text entrybox"),
673 _T("Please enter a string"),
677 if (dialog
.ShowModal() == wxID_OK
)
679 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
682 #endif // wxUSE_TEXTDLG
685 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
687 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
689 wxSingleChoiceDialog
dialog(this,
690 _T("This is a small sample\n")
691 _T("A single-choice convenience dialog"),
692 _T("Please select a value"),
693 WXSIZEOF(choices
), choices
);
695 dialog
.SetSelection(2);
697 if (dialog
.ShowModal() == wxID_OK
)
699 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
704 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
706 const wxString choices
[] =
708 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
709 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
710 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
713 wxArrayInt selections
;
714 size_t count
= wxGetMultipleChoices(selections
,
715 _T("This is a small sample\n")
716 _T("A multi-choice convenience dialog"),
717 _T("Please select a value"),
718 WXSIZEOF(choices
), choices
,
723 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
724 for ( size_t n
= 0; n
< count
; n
++ )
726 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
727 (unsigned)n
, (unsigned)selections
[n
],
728 choices
[selections
[n
]].c_str());
732 //else: cancelled or nothing selected
734 #endif // wxUSE_CHOICEDLG
737 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
742 _T("Testing open file dialog"),
746 _T("C++ files (*.cpp)|*.cpp")
748 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
752 dialog
.CentreOnParent();
753 dialog
.SetDirectory(wxGetHomeDir());
755 if (dialog
.ShowModal() == wxID_OK
)
758 info
.Printf(_T("Full file name: %s\n")
761 dialog
.GetPath().c_str(),
762 dialog
.GetDirectory().c_str(),
763 dialog
.GetFilename().c_str());
764 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
769 // this shows how to take advantage of specifying a default extension in the
770 // call to wxFileSelector: it is remembered after each new call and the next
771 // one will use it by default
772 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
774 static wxString s_extDef
;
775 wxString path
= wxFileSelector(
776 _T("Select the file to load"),
777 wxEmptyString
, wxEmptyString
,
781 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
782 wxFileSelectorDefaultWildcardStr
,
783 wxFileSelectorDefaultWildcardStr
785 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
792 // it is just a sample, would use wxSplitPath in real program
793 s_extDef
= path
.AfterLast(_T('.'));
795 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
799 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
803 _T("C++ files (*.cpp)|*.cpp");
807 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
808 wxFileSelectorDefaultWildcardStr
,
809 wxFileSelectorDefaultWildcardStr
812 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
813 wxEmptyString
, wxEmptyString
, wildcards
,
814 wxFD_OPEN
|wxFD_MULTIPLE
);
816 if (dialog
.ShowModal() == wxID_OK
)
818 wxArrayString paths
, filenames
;
820 dialog
.GetPaths(paths
);
821 dialog
.GetFilenames(filenames
);
824 size_t count
= paths
.GetCount();
825 for ( size_t n
= 0; n
< count
; n
++ )
827 s
.Printf(_T("File %d: %s (%s)\n"),
828 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
832 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
835 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
840 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
842 wxFileDialog
dialog(this,
843 _T("Testing save file dialog"),
846 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
847 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
849 dialog
.SetFilterIndex(1);
851 if (dialog
.ShowModal() == wxID_OK
)
853 wxLogMessage(_T("%s, filter %d"),
854 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
857 #endif // wxUSE_FILEDLG
859 #if USE_FILEDLG_GENERIC
860 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
862 wxGenericFileDialog dialog
865 _T("Testing open file dialog"),
868 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
871 dialog
.SetDirectory(wxGetHomeDir());
873 if (dialog
.ShowModal() == wxID_OK
)
876 info
.Printf(_T("Full file name: %s\n")
879 dialog
.GetPath().c_str(),
880 dialog
.GetDirectory().c_str(),
881 dialog
.GetFilename().c_str());
882 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
887 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
889 // On PocketPC you can disable OK-only dialogs policy using system option
890 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
891 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
893 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
894 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
895 wxEmptyString
, wxEmptyString
, wildcards
,
898 if (dialog
.ShowModal() == wxID_OK
)
900 wxArrayString paths
, filenames
;
902 dialog
.GetPaths(paths
);
903 dialog
.GetFilenames(filenames
);
906 size_t count
= paths
.GetCount();
907 for ( size_t n
= 0; n
< count
; n
++ )
909 s
.Printf(_T("File %d: %s (%s)\n"),
910 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
914 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
917 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
921 // restore system option
922 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
925 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
927 wxGenericFileDialog
dialog(this,
928 _T("Testing save file dialog"),
931 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
932 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
934 dialog
.SetFilterIndex(1);
936 if (dialog
.ShowModal() == wxID_OK
)
938 wxLogMessage(_T("%s, filter %d"),
939 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
942 #endif // USE_FILEDLG_GENERIC
945 void MyFrame::DoDirChoose(int style
)
947 // pass some initial dir to wxDirDialog
949 wxGetHomeDir(&dirHome
);
951 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
953 if (dialog
.ShowModal() == wxID_OK
)
955 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
959 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
961 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
964 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
966 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
968 #endif // wxUSE_DIRDLG
970 #if USE_DIRDLG_GENERIC
971 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
973 // pass some initial dir to wxDirDialog
975 wxGetHomeDir(&dirHome
);
977 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
979 if (dialog
.ShowModal() == wxID_OK
)
981 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
985 #endif // USE_DIRDLG_GENERIC
987 #if USE_MODAL_PRESENTATION
988 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
990 MyModalDialog
dlg(this);
994 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
996 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1002 m_dialog
= new MyModelessDialog(this);
1005 m_dialog
->Show(true);
1009 // If m_dialog is NULL, then possibly the system
1010 // didn't report the checked menu item status correctly.
1011 // It should be true just after the menu item was selected,
1012 // if there was no modeless dialog yet.
1014 wxASSERT( m_dialog
!= NULL
);
1020 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1022 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1023 wxDefaultPosition
, wxSize(200, 100));
1024 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1025 dlg
.CentreOnScreen();
1029 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1031 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1032 wxDefaultPosition
, wxSize(200, 100));
1033 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1034 dlg
.CentreOnParent();
1038 #endif // USE_MODAL_PRESENTATION
1040 #if wxUSE_STARTUP_TIPS
1041 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1043 static size_t s_index
= (size_t)-1;
1045 if ( s_index
== (size_t)-1 )
1049 // this is completely bogus, we don't know how many lines are there
1050 // in the file, but who cares, it's a demo only...
1051 s_index
= rand() % 5;
1054 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1056 bool showAtStartup
= wxShowTip(this, tipProvider
);
1058 if ( showAtStartup
)
1060 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1061 wxOK
| wxICON_INFORMATION
, this);
1064 s_index
= tipProvider
->GetCurrentTip();
1067 #endif // wxUSE_STARTUP_TIPS
1069 #if USE_SETTINGS_DIALOG
1070 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1072 SettingsDialog
dialog(this, event
.GetId());
1075 #endif // USE_SETTINGS_DIALOG
1077 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1079 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1083 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1086 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1088 StdButtonSizerDialog
dialog(this);
1092 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1097 #if wxUSE_PROGRESSDLG
1099 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1101 static const int max
= 100;
1103 wxProgressDialog
dialog(_T("Progress dialog example"),
1104 _T("An informative message"),
1110 // wxPD_AUTO_HIDE | -- try this as well
1112 wxPD_ESTIMATED_TIME
|
1114 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1118 for ( int i
= 0; i
<= max
; i
++ )
1124 // test both modes of wxProgressDialog behaviour: start in
1125 // indeterminate mode but switch to the determinate one later
1126 const bool determinate
= i
> max
/2;
1130 msg
= _T("That's all, folks!");
1132 else if ( !determinate
)
1134 msg
= _T("Testing indeterminate mode");
1136 else if ( determinate
)
1138 msg
= _T("Now in standard determinate mode");
1141 // will be set to true if "Skip" button was pressed
1145 cont
= dialog
.Update(i
, msg
, &skip
);
1149 cont
= dialog
.Pulse(msg
, &skip
);
1152 // each skip will move progress about quarter forward
1158 if ( wxMessageBox(_T("Do you really want to cancel?"),
1159 _T("Progress dialog question"), // caption
1160 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1170 wxLogStatus(wxT("Progress dialog aborted!"));
1174 wxLogStatus(wxT("Countdown from %d finished"), max
);
1178 #endif // wxUSE_PROGRESSDLG
1182 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1184 info
.SetName(_T("Dialogs Sample"));
1185 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1186 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1187 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1188 info
.AddDeveloper(_T("Vadim Zeitlin"));
1191 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1193 InitAboutInfoMinimal(info
);
1195 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1198 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1200 InitAboutInfoMinimal(info
);
1202 // we can add a second developer
1203 info
.AddDeveloper(_T("A.N. Other"));
1205 // or we can add several persons at once like this
1206 static const wxChar
*docwriters
[] =
1208 _T("First D. Writer"),
1212 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1213 info
.SetLicence(wxString::FromAscii(
1214 " wxWindows Library Licence, Version 3.1\n"
1215 " ======================================\n"
1217 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1219 " Everyone is permitted to copy and distribute verbatim copies\n"
1220 " of this licence document, but changing it is not allowed.\n"
1222 " WXWINDOWS LIBRARY LICENCE\n"
1223 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1225 " ...and so on and so forth...\n"
1228 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1231 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1233 wxAboutDialogInfo info
;
1234 InitAboutInfoMinimal(info
);
1239 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1241 wxAboutDialogInfo info
;
1242 InitAboutInfoWebsite(info
);
1247 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1249 wxAboutDialogInfo info
;
1250 InitAboutInfoAll(info
);
1255 // a trivial example of a custom dialog class
1256 class MyAboutDialog
: public wxGenericAboutDialog
1259 MyAboutDialog(const wxAboutDialogInfo
& info
)
1264 // add some custom controls
1265 virtual void DoAddCustomControls()
1267 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1268 AddText(_T("Some custom text"));
1269 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1273 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1275 wxAboutDialogInfo info
;
1276 InitAboutInfoAll(info
);
1278 MyAboutDialog
dlg(info
);
1282 #endif // wxUSE_ABOUTDLG
1286 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1288 wxWindowDisabler disableAll
;
1290 wxBusyInfo
info(_T("Working, please wait..."), this);
1292 for ( int i
= 0; i
< 18; i
++ )
1302 #endif // wxUSE_BUSYINFO
1304 #if wxUSE_FINDREPLDLG
1306 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1310 delete m_dlgReplace
;
1311 m_dlgReplace
= NULL
;
1315 m_dlgReplace
= new wxFindReplaceDialog
1319 _T("Find and replace dialog"),
1323 m_dlgReplace
->Show(true);
1327 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1336 m_dlgFind
= new wxFindReplaceDialog
1345 m_dlgFind
->Show(true);
1349 static wxString
DecodeFindDialogEventFlags(int flags
)
1352 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1353 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1354 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1355 << _T("case sensitive");
1360 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1362 wxEventType type
= event
.GetEventType();
1364 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1366 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1367 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1368 event
.GetFindString().c_str(),
1369 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1371 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1372 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1374 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1375 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1376 event
.GetFindString().c_str(),
1377 event
.GetReplaceString().c_str(),
1378 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1380 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1382 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1386 if ( dlg
== m_dlgFind
)
1389 idMenu
= DIALOGS_FIND
;
1392 else if ( dlg
== m_dlgReplace
)
1394 txt
= _T("Replace");
1395 idMenu
= DIALOGS_REPLACE
;
1396 m_dlgReplace
= NULL
;
1400 txt
= _T("Unknown");
1403 wxFAIL_MSG( _T("unexpected event") );
1406 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1408 if ( idMenu
!= wxID_ANY
)
1410 GetMenuBar()->Check(idMenu
, false);
1417 wxLogError(wxT("Unknown find dialog event!"));
1421 #endif // wxUSE_FINDREPLDLG
1423 // ----------------------------------------------------------------------------
1425 // ----------------------------------------------------------------------------
1427 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1430 dc
.SetFont(wxGetApp().m_canvasFont
);
1431 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1432 dc
.SetBackgroundMode(wxTRANSPARENT
);
1434 _T("wxWidgets common dialogs")
1435 #if !defined(__SMARTPHONE__)
1436 _T(" test application")
1441 #if USE_MODAL_PRESENTATION
1443 // ----------------------------------------------------------------------------
1445 // ----------------------------------------------------------------------------
1447 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1448 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1450 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1452 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1453 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1456 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1457 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1461 sizerTop
->SetSizeHints(this);
1462 sizerTop
->Fit(this);
1465 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1467 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1468 wxOK
| wxICON_INFORMATION
, this);
1471 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1473 if ( event
.CanVeto() )
1475 wxMessageBox(_T("Use the menu item to close this dialog"),
1476 _T("Modeless dialog"),
1477 wxOK
| wxICON_INFORMATION
, this);
1483 // ----------------------------------------------------------------------------
1485 // ----------------------------------------------------------------------------
1487 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1488 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1490 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1492 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1493 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1494 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1496 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1497 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1498 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1499 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1500 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1504 sizerTop
->SetSizeHints(this);
1505 sizerTop
->Fit(this);
1507 m_btnModal
->SetFocus();
1508 m_btnModal
->SetDefault();
1511 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1513 if ( event
.GetEventObject() == m_btnDelete
)
1518 m_btnDelete
->Disable();
1520 else if ( event
.GetEventObject() == m_btnModal
)
1523 wxGetTextFromUser(_T("Dummy prompt"),
1524 _T("Modal dialog called from dialog"),
1525 wxEmptyString
, this);
1527 wxMessageBox(_T("Modal dialog called from dialog"));
1528 #endif // wxUSE_TEXTDLG
1530 else if ( event
.GetEventObject() == m_btnModeless
)
1532 (new MyModelessDialog(this))->Show();
1540 #endif // USE_MODAL_PRESENTATION
1542 // ----------------------------------------------------------------------------
1543 // StdButtonSizerDialog
1544 // ----------------------------------------------------------------------------
1546 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1547 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1548 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1549 m_buttonsSizer(NULL
)
1551 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1553 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1554 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1556 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
1558 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
1560 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1561 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
1563 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
1565 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
1567 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
1569 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1570 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
1572 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
1574 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
1575 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
1576 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
1578 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
1580 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
1581 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
1583 sizer
->Add(sizerInside1
, 0, 0, 0);
1584 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
1585 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
1586 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1588 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
1589 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
1591 sizer
->Add(sizerInside2
, 0, 0, 0);
1592 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
1593 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
1594 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1596 sizerTop
->Add(sizer
, 0, wxALL
, 5);
1598 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
1599 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
1600 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
1602 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
1604 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
1606 EnableDisableControls();
1610 sizerTop
->SetSizeHints(this);
1615 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
1619 m_buttonsSizer
->DeleteWindows();
1620 GetSizer()->Remove(m_buttonsSizer
);
1623 EnableDisableControls();
1626 unsigned long numButtons
= 0;
1628 if (m_chkboxAffirmativeButton
->IsChecked())
1630 if (m_radiobtnOk
->GetValue())
1635 else if (m_radiobtnYes
->GetValue())
1642 if (m_chkboxDismissButton
->IsChecked())
1644 if (m_radiobtnCancel
->GetValue())
1650 else if (m_radiobtnClose
->GetValue())
1658 if (m_chkboxApply
->IsChecked())
1664 if (m_chkboxNo
->IsChecked())
1670 if (m_chkboxHelp
->IsChecked())
1676 if (m_chkboxNoDefault
->IsChecked())
1678 flags
|= wxNO_DEFAULT
;
1681 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
1682 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
1685 GetSizer()->SetSizeHints(this);
1688 void StdButtonSizerDialog::EnableDisableControls()
1690 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
1692 m_radiobtnOk
->Enable(affButtonEnabled
);
1693 m_radiobtnYes
->Enable(affButtonEnabled
);
1695 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
1697 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
1698 m_radiobtnClose
->Enable(dismissButtonEnabled
);
1701 #if USE_SETTINGS_DIALOG
1702 // ----------------------------------------------------------------------------
1704 // ----------------------------------------------------------------------------
1706 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1708 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1711 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1713 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1718 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1719 int resizeBorder
= wxRESIZE_BORDER
;
1727 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1728 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1729 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1731 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1733 SetSheetStyle(sheetStyle
);
1734 SetSheetInnerBorder(0);
1735 SetSheetOuterBorder(0);
1737 // create a dummy image list with a few icons
1738 const wxSize
imageSize(32, 32);
1740 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1742 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1744 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1746 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1748 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1753 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1754 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1757 // If using a toolbook, also follow Mac style and don't create buttons
1759 CreateButtons(wxOK
| wxCANCEL
|
1760 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1763 wxBookCtrlBase
* notebook
= GetBookCtrl();
1764 notebook
->SetImageList(m_imageList
);
1766 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1767 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1769 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1770 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1775 SettingsDialog::~SettingsDialog()
1780 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1782 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1784 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1785 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1789 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1790 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1791 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1792 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1796 wxString autoSaveLabel
= _("&Auto-save every");
1797 wxString minsLabel
= _("mins");
1799 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1800 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1803 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1804 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1807 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1809 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1811 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1812 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1816 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1817 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1818 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1819 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1821 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1823 panel
->SetSizer(topSizer
);
1824 topSizer
->Fit(panel
);
1829 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1831 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1833 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1834 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1836 //// PROJECT OR GLOBAL
1837 wxString globalOrProjectChoices
[2];
1838 globalOrProjectChoices
[0] = _("&New projects");
1839 globalOrProjectChoices
[1] = _("&This project");
1841 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1842 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1843 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1845 projectOrGlobal
->SetSelection(0);
1847 //// BACKGROUND STYLE
1848 wxArrayString backgroundStyleChoices
;
1849 backgroundStyleChoices
.Add(wxT("Colour"));
1850 backgroundStyleChoices
.Add(wxT("Image"));
1851 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1853 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1854 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1856 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1858 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1860 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1861 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1862 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1864 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1867 //// FONT SIZE SELECTION
1869 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1870 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1872 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1873 wxSize(80, wxDefaultCoord
));
1874 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1876 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1879 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1880 topSizer
->AddSpacer(5);
1882 panel
->SetSizer(topSizer
);
1883 topSizer
->Fit(panel
);
1888 #endif // USE_SETTINGS_DIALOG