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/minifram.h"
31 #include "wx/sysopt.h"
34 #include "wx/colordlg.h"
35 #endif // wxUSE_COLOURDLG
38 #include "wx/choicdlg.h"
39 #endif // wxUSE_CHOICEDLG
41 #if wxUSE_STARTUP_TIPS
42 #include "wx/tipdlg.h"
43 #endif // wxUSE_STARTUP_TIPS
46 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
47 #include "wx/datetime.h" // wxDateTime
50 #include "wx/progdlg.h"
51 #endif // wxUSE_PROGRESSDLG
54 #include "wx/aboutdlg.h"
56 // these headers are only needed for custom about dialog
57 #include "wx/statline.h"
58 #include "wx/generic/aboutdlgg.h"
59 #endif // wxUSE_ABOUTDLG
62 #include "wx/busyinfo.h"
63 #endif // wxUSE_BUSYINFO
66 #include "wx/numdlg.h"
67 #endif // wxUSE_NUMBERDLG
70 #include "wx/filedlg.h"
71 #endif // wxUSE_FILEDLG
74 #include "wx/dirdlg.h"
75 #endif // wxUSE_DIRDLG
78 #include "wx/fontdlg.h"
79 #endif // wxUSE_FONTDLG
82 #include "wx/fdrepdlg.h"
83 #endif // wxUSE_FINDREPLDLG
86 #include "wx/spinctrl.h"
89 #include "wx/propdlg.h"
93 #if USE_COLOURDLG_GENERIC
94 #include "wx/generic/colrdlgg.h"
95 #endif // USE_COLOURDLG_GENERIC
97 #if USE_DIRDLG_GENERIC
98 #include "wx/generic/dirdlgg.h"
99 #endif // USE_DIRDLG_GENERIC
101 #if USE_FILEDLG_GENERIC
102 #include "wx/generic/filedlgg.h"
103 #endif // USE_FILEDLG_GENERIC
105 #if USE_FONTDLG_GENERIC
106 #include "wx/generic/fontdlgg.h"
107 #endif // USE_FONTDLG_GENERIC
111 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
112 EVT_PAINT(MyCanvas::OnPaint
)
117 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
118 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
121 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
122 #endif // wxUSE_COLOURDLG
125 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
126 #endif // wxUSE_FONTDLG
129 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
130 #endif // wxUSE_LOG_DIALOG
133 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
134 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
135 #endif // wxUSE_TEXTDLG
138 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
139 #endif // wxUSE_NUMBERDLG
142 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
143 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
144 #endif // wxUSE_CHOICEDLG
147 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
148 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
149 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
150 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
151 #endif // wxUSE_FILEDLG
153 #if USE_FILEDLG_GENERIC
154 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
155 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
156 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
157 #endif // USE_FILEDLG_GENERIC
160 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
161 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
162 #endif // wxUSE_DIRDLG
164 #if USE_MODAL_PRESENTATION
165 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
166 #endif // USE_MODAL_PRESENTATION
167 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
168 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
169 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
170 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
172 #if wxUSE_STARTUP_TIPS
173 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
174 #endif // wxUSE_STARTUP_TIPS
176 #if USE_FONTDLG_GENERIC
177 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
178 #endif // USE_FONTDLG_GENERIC
180 #if USE_DIRDLG_GENERIC
181 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
182 #endif // wxMSW || wxMAC
184 #if USE_COLOURDLG_GENERIC
185 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
186 #endif // USE_COLOURDLG_GENERIC
188 #if wxUSE_PROGRESSDLG
189 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
190 #endif // wxUSE_PROGRESSDLG
193 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
194 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
195 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
196 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
197 #endif // wxUSE_ABOUTDLG
200 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
201 #endif // wxUSE_BUSYINFO
203 #if wxUSE_FINDREPLDLG
204 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
205 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
207 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
208 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
209 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
210 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
211 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
212 #endif // wxUSE_FINDREPLDLG
214 #if USE_SETTINGS_DIALOG
215 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
216 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
217 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
220 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
221 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
223 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
226 #if USE_MODAL_PRESENTATION
228 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
229 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
232 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
233 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
234 EVT_CLOSE(MyModelessDialog::OnClose
)
237 #endif // USE_MODAL_PRESENTATION
239 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
240 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
241 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
244 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
246 // `Main program' equivalent, creating windows and returning main app frame
249 if ( !wxApp::OnInit() )
253 wxInitAllImageHandlers();
256 m_canvasTextColour
= *wxBLACK
;
257 m_canvasFont
= *wxNORMAL_FONT
;
259 // Create the main frame window
260 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
263 wxMenu
*menuDlg
= new wxMenu
;
265 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
268 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
270 wxMenu
*choices_menu
= new wxMenu
;
273 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
274 #endif // wxUSE_COLOURDLG
277 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
278 #endif // wxUSE_FONTDLG
281 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
282 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
283 #endif // wxUSE_CHOICEDLG
285 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
286 choices_menu
->AppendSeparator();
287 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
289 #if USE_COLOURDLG_GENERIC
290 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
291 #endif // USE_COLOURDLG_GENERIC
293 #if USE_FONTDLG_GENERIC
294 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
295 #endif // USE_FONTDLG_GENERIC
297 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
298 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
301 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
303 wxMenu
*entry_menu
= new wxMenu
;
306 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
307 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
308 #endif // wxUSE_TEXTDLG
311 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
312 #endif // wxUSE_NUMBERDLG
314 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
316 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
321 wxMenu
*filedlg_menu
= new wxMenu
;
322 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
323 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
324 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
325 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
327 #if USE_FILEDLG_GENERIC
328 filedlg_menu
->AppendSeparator();
329 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
330 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
331 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
332 #endif // USE_FILEDLG_GENERIC
334 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
336 #endif // wxUSE_FILEDLG
339 wxMenu
*dir_menu
= new wxMenu
;
341 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
342 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
343 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
345 #if USE_DIRDLG_GENERIC
346 dir_menu
->AppendSeparator();
347 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
348 #endif // USE_DIRDLG_GENERIC
350 #endif // wxUSE_DIRDLG
353 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
355 wxMenu
*info_menu
= new wxMenu
;
357 #if wxUSE_STARTUP_TIPS
358 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
359 #endif // wxUSE_STARTUP_TIPS
361 #if wxUSE_PROGRESSDLG
362 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
363 #endif // wxUSE_PROGRESSDLG
366 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
367 #endif // wxUSE_BUSYINFO
370 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
371 #endif // wxUSE_LOG_DIALOG
373 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
375 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
378 #if wxUSE_FINDREPLDLG
379 wxMenu
*find_menu
= new wxMenu
;
380 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
381 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
382 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
383 #endif // wxUSE_FINDREPLDLG
385 wxMenu
*dialogs_menu
= new wxMenu
;
386 #if USE_MODAL_PRESENTATION
387 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
388 #endif // USE_MODAL_PRESENTATION
389 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
390 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
391 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
392 dialogs_menu
->Append(DIALOGS_MINIFRAME
, _T("&Mini frame"));
393 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
395 #if USE_SETTINGS_DIALOG
396 wxMenu
*sheet_menu
= new wxMenu
;
397 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
398 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
400 if (wxPlatformIs(wxPORT_MAC
))
401 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
404 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
407 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
408 #endif // USE_SETTINGS_DIALOG
410 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, _T("&Standard Buttons Sizer Dialog"));
412 menuDlg
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
414 menuDlg
->AppendSeparator();
415 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
418 wxMenu
*menuHelp
= new wxMenu
;
419 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
420 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
421 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
422 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
423 #endif // wxUSE_ABOUTDLG
425 wxMenuBar
*menubar
= new wxMenuBar
;
426 menubar
->Append(menuDlg
, _T("&Dialogs"));
428 menubar
->Append(menuHelp
, _T("&Help"));
429 #endif // wxUSE_ABOUTDLG
431 frame
->SetMenuBar(menubar
);
433 myCanvas
= new MyCanvas(frame
);
434 myCanvas
->SetBackgroundColour(*wxWHITE
);
436 frame
->Centre(wxBOTH
);
446 // My frame constructor
447 MyFrame::MyFrame(wxWindow
*parent
,
448 const wxString
& title
)
449 : wxFrame(parent
, wxID_ANY
, title
)
453 #if USE_MODAL_PRESENTATION
454 m_dialog
= (MyModelessDialog
*)NULL
;
455 #endif // USE_MODAL_PRESENTATION
457 #if wxUSE_FINDREPLDLG
463 m_clrData
.SetChooseFull(true);
464 for (int i
= 0; i
< 16; i
++)
466 m_clrData
.SetCustomColour(
469 (unsigned char)(i
*16),
470 (unsigned char)(i
*16),
471 (unsigned char)(i
*16)
475 #endif // wxUSE_COLOURDLG
479 #endif // wxUSE_STATUSBAR
483 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
485 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
487 wxColourDialog
dialog(this, &m_clrData
);
488 dialog
.SetTitle(_T("Choose the background colour"));
489 if (dialog
.ShowModal() == wxID_OK
)
491 m_clrData
= dialog
.GetColourData();
492 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
493 myCanvas
->ClearBackground();
497 #endif // wxUSE_COLOURDLG
499 #if USE_COLOURDLG_GENERIC
500 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
502 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
504 //FIXME:TODO:This has no effect...
505 m_clrData
.SetChooseFull(true);
507 for (int i
= 0; i
< 16; i
++)
510 (unsigned char)(i
*16),
511 (unsigned char)(i
*16),
512 (unsigned char)(i
*16)
514 m_clrData
.SetCustomColour(i
, colour
);
517 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
518 if (dialog
->ShowModal() == wxID_OK
)
520 m_clrData
= dialog
->GetColourData();
521 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
522 myCanvas
->ClearBackground();
527 #endif // USE_COLOURDLG_GENERIC
530 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
533 data
.SetInitialFont(wxGetApp().m_canvasFont
);
534 data
.SetColour(wxGetApp().m_canvasTextColour
);
536 // you might also do this:
538 // wxFontDialog dialog;
539 // if ( !dialog.Create(this, data) { ... error ... }
541 wxFontDialog
dialog(this, data
);
543 if (dialog
.ShowModal() == wxID_OK
)
545 wxFontData retData
= dialog
.GetFontData();
546 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
547 wxGetApp().m_canvasTextColour
= retData
.GetColour();
550 //else: cancelled by the user, don't change the font
552 #endif // wxUSE_FONTDLG
554 #if USE_FONTDLG_GENERIC
555 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
558 data
.SetInitialFont(wxGetApp().m_canvasFont
);
559 data
.SetColour(wxGetApp().m_canvasTextColour
);
561 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
562 if (dialog
->ShowModal() == wxID_OK
)
564 wxFontData retData
= dialog
->GetFontData();
565 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
566 wxGetApp().m_canvasTextColour
= retData
.GetColour();
571 #endif // USE_FONTDLG_GENERIC
574 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
576 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
577 // being flushed -- test it
580 wxLogMessage(wxT("This is some message - everything is ok so far."));
581 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
582 wxLogWarning(wxT("And then something went wrong!"));
584 // and if ~wxBusyCursor doesn't do it, then call it manually
588 wxLogError(wxT("Intermediary error handler decided to abort."));
589 wxLogError(wxT("The top level caller detected an unrecoverable error."));
591 wxLog::FlushActive();
593 wxLogMessage(wxT("And this is the same dialog but with only one message."));
595 #endif // wxUSE_LOG_DIALOG
597 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
599 wxMessageDialog
dialog(NULL
,
600 _T("This is a message box\nA long, long string to test out the message box properly"),
601 _T("Message box text"),
602 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
| wxICON_INFORMATION
);
604 if ( dialog
.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
606 dialog
.SetExtendedMessage(_T("This platform supports custom button labels"));
610 dialog
.SetExtendedMessage(_T("Custom button labels are not supported."));
613 switch ( dialog
.ShowModal() )
616 wxLogStatus(wxT("You pressed \"Yes\""));
620 wxLogStatus(wxT("You pressed \"No\""));
624 wxLogStatus(wxT("You pressed \"Cancel\""));
628 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
633 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
635 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
636 _T("Even two rows of text."),
637 _T("Enter a number:"), _T("Numeric input test"),
644 msg
= _T("Invalid number entered or dialog cancelled.");
649 msg
.Printf(_T("You've entered %lu"), res
);
650 icon
= wxICON_INFORMATION
;
653 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
655 #endif // wxUSE_NUMBERDLG
658 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
660 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
661 _T("Password entry dialog"),
666 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
667 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
671 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
673 wxTextEntryDialog
dialog(this,
674 _T("This is a small sample\n")
675 _T("A long, long string to test out the text entrybox"),
676 _T("Please enter a string"),
680 if (dialog
.ShowModal() == wxID_OK
)
682 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
685 #endif // wxUSE_TEXTDLG
688 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
690 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
692 wxSingleChoiceDialog
dialog(this,
693 _T("This is a small sample\n")
694 _T("A single-choice convenience dialog"),
695 _T("Please select a value"),
696 WXSIZEOF(choices
), choices
);
698 dialog
.SetSelection(2);
700 if (dialog
.ShowModal() == wxID_OK
)
702 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
707 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
709 const wxString choices
[] =
711 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
712 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
713 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
716 wxArrayInt selections
;
717 size_t count
= wxGetMultipleChoices(selections
,
718 _T("This is a small sample\n")
719 _T("A multi-choice convenience dialog"),
720 _T("Please select a value"),
721 WXSIZEOF(choices
), choices
,
726 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
727 for ( size_t n
= 0; n
< count
; n
++ )
729 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
730 (unsigned)n
, (unsigned)selections
[n
],
731 choices
[selections
[n
]].c_str());
735 //else: cancelled or nothing selected
737 #endif // wxUSE_CHOICEDLG
740 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
745 _T("Testing open file dialog"),
749 _T("C++ files (*.cpp)|*.cpp")
751 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
755 dialog
.CentreOnParent();
756 dialog
.SetDirectory(wxGetHomeDir());
758 if (dialog
.ShowModal() == wxID_OK
)
761 info
.Printf(_T("Full file name: %s\n")
764 dialog
.GetPath().c_str(),
765 dialog
.GetDirectory().c_str(),
766 dialog
.GetFilename().c_str());
767 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
772 // this shows how to take advantage of specifying a default extension in the
773 // call to wxFileSelector: it is remembered after each new call and the next
774 // one will use it by default
775 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
777 static wxString s_extDef
;
778 wxString path
= wxFileSelector(
779 _T("Select the file to load"),
780 wxEmptyString
, wxEmptyString
,
784 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
785 wxFileSelectorDefaultWildcardStr
,
786 wxFileSelectorDefaultWildcardStr
788 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
795 // it is just a sample, would use wxSplitPath in real program
796 s_extDef
= path
.AfterLast(_T('.'));
798 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
802 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
806 _T("C++ files (*.cpp)|*.cpp");
810 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
811 wxFileSelectorDefaultWildcardStr
,
812 wxFileSelectorDefaultWildcardStr
815 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
816 wxEmptyString
, wxEmptyString
, wildcards
,
817 wxFD_OPEN
|wxFD_MULTIPLE
);
819 if (dialog
.ShowModal() == wxID_OK
)
821 wxArrayString paths
, filenames
;
823 dialog
.GetPaths(paths
);
824 dialog
.GetFilenames(filenames
);
827 size_t count
= paths
.GetCount();
828 for ( size_t n
= 0; n
< count
; n
++ )
830 s
.Printf(_T("File %d: %s (%s)\n"),
831 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
835 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
838 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
843 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
845 wxFileDialog
dialog(this,
846 _T("Testing save file dialog"),
849 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
850 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
852 dialog
.SetFilterIndex(1);
854 if (dialog
.ShowModal() == wxID_OK
)
856 wxLogMessage(_T("%s, filter %d"),
857 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
860 #endif // wxUSE_FILEDLG
862 #if USE_FILEDLG_GENERIC
863 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
865 wxGenericFileDialog dialog
868 _T("Testing open file dialog"),
871 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
874 dialog
.SetDirectory(wxGetHomeDir());
876 if (dialog
.ShowModal() == wxID_OK
)
879 info
.Printf(_T("Full file name: %s\n")
882 dialog
.GetPath().c_str(),
883 dialog
.GetDirectory().c_str(),
884 dialog
.GetFilename().c_str());
885 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
890 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
892 // On PocketPC you can disable OK-only dialogs policy using system option
893 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
894 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
896 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
897 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
898 wxEmptyString
, wxEmptyString
, wildcards
,
901 if (dialog
.ShowModal() == wxID_OK
)
903 wxArrayString paths
, filenames
;
905 dialog
.GetPaths(paths
);
906 dialog
.GetFilenames(filenames
);
909 size_t count
= paths
.GetCount();
910 for ( size_t n
= 0; n
< count
; n
++ )
912 s
.Printf(_T("File %d: %s (%s)\n"),
913 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
917 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
920 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
924 // restore system option
925 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
928 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
930 wxGenericFileDialog
dialog(this,
931 _T("Testing save file dialog"),
934 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
935 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
937 dialog
.SetFilterIndex(1);
939 if (dialog
.ShowModal() == wxID_OK
)
941 wxLogMessage(_T("%s, filter %d"),
942 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
945 #endif // USE_FILEDLG_GENERIC
948 void MyFrame::DoDirChoose(int style
)
950 // pass some initial dir to wxDirDialog
952 wxGetHomeDir(&dirHome
);
954 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
956 if (dialog
.ShowModal() == wxID_OK
)
958 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
962 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
964 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
967 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
969 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
971 #endif // wxUSE_DIRDLG
973 #if USE_DIRDLG_GENERIC
974 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
976 // pass some initial dir to wxDirDialog
978 wxGetHomeDir(&dirHome
);
980 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
982 if (dialog
.ShowModal() == wxID_OK
)
984 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
988 #endif // USE_DIRDLG_GENERIC
990 #if USE_MODAL_PRESENTATION
991 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
993 MyModalDialog
dlg(this);
996 #endif // USE_MODAL_PRESENTATION
998 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1000 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1006 m_dialog
= new MyModelessDialog(this);
1009 m_dialog
->Show(true);
1013 // If m_dialog is NULL, then possibly the system
1014 // didn't report the checked menu item status correctly.
1015 // It should be true just after the menu item was selected,
1016 // if there was no modeless dialog yet.
1018 wxASSERT( m_dialog
!= NULL
);
1024 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1026 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1027 wxDefaultPosition
, wxSize(200, 100));
1028 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1029 dlg
.CentreOnScreen();
1033 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1035 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1036 wxDefaultPosition
, wxSize(200, 100));
1037 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1038 dlg
.CentreOnParent();
1042 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1044 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, _T("Mini frame"),
1045 wxDefaultPosition
, wxSize(300, 100),
1046 wxCAPTION
| wxCLOSE_BOX
);
1047 new wxStaticText(frame
,
1049 _T("Mini frames have slightly different appearance"),
1051 new wxStaticText(frame
,
1053 _T("from the normal frames but that's the only difference."),
1056 frame
->CentreOnParent();
1060 #if wxUSE_STARTUP_TIPS
1061 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1063 static size_t s_index
= (size_t)-1;
1065 if ( s_index
== (size_t)-1 )
1069 // this is completely bogus, we don't know how many lines are there
1070 // in the file, but who cares, it's a demo only...
1071 s_index
= rand() % 5;
1074 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1076 bool showAtStartup
= wxShowTip(this, tipProvider
);
1078 if ( showAtStartup
)
1080 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1081 wxOK
| wxICON_INFORMATION
, this);
1084 s_index
= tipProvider
->GetCurrentTip();
1087 #endif // wxUSE_STARTUP_TIPS
1089 #if USE_SETTINGS_DIALOG
1090 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1092 SettingsDialog
dialog(this, event
.GetId());
1095 #endif // USE_SETTINGS_DIALOG
1097 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1099 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1103 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1106 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1108 StdButtonSizerDialog
dialog(this);
1112 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1117 #if wxUSE_PROGRESSDLG
1119 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1121 static const int max
= 100;
1123 wxProgressDialog
dialog(_T("Progress dialog example"),
1124 _T("An informative message"),
1130 // wxPD_AUTO_HIDE | -- try this as well
1132 wxPD_ESTIMATED_TIME
|
1134 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1138 for ( int i
= 0; i
<= max
; i
++ )
1144 // test both modes of wxProgressDialog behaviour: start in
1145 // indeterminate mode but switch to the determinate one later
1146 const bool determinate
= i
> max
/2;
1150 msg
= _T("That's all, folks!");
1152 else if ( !determinate
)
1154 msg
= _T("Testing indeterminate mode");
1156 else if ( determinate
)
1158 msg
= _T("Now in standard determinate mode");
1161 // will be set to true if "Skip" button was pressed
1165 cont
= dialog
.Update(i
, msg
, &skip
);
1169 cont
= dialog
.Pulse(msg
, &skip
);
1172 // each skip will move progress about quarter forward
1178 if ( wxMessageBox(_T("Do you really want to cancel?"),
1179 _T("Progress dialog question"), // caption
1180 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1190 wxLogStatus(wxT("Progress dialog aborted!"));
1194 wxLogStatus(wxT("Countdown from %d finished"), max
);
1198 #endif // wxUSE_PROGRESSDLG
1202 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1204 info
.SetName(_T("Dialogs Sample"));
1205 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1206 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1207 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1208 info
.AddDeveloper(_T("Vadim Zeitlin"));
1211 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1213 InitAboutInfoMinimal(info
);
1215 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1218 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1220 InitAboutInfoMinimal(info
);
1222 // we can add a second developer
1223 info
.AddDeveloper(_T("A.N. Other"));
1225 // or we can add several persons at once like this
1226 static const wxChar
*docwriters
[] =
1228 _T("First D. Writer"),
1232 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1233 info
.SetLicence(wxString::FromAscii(
1234 " wxWindows Library Licence, Version 3.1\n"
1235 " ======================================\n"
1237 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1239 " Everyone is permitted to copy and distribute verbatim copies\n"
1240 " of this licence document, but changing it is not allowed.\n"
1242 " WXWINDOWS LIBRARY LICENCE\n"
1243 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1245 " ...and so on and so forth...\n"
1248 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1251 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1253 wxAboutDialogInfo info
;
1254 InitAboutInfoMinimal(info
);
1259 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1261 wxAboutDialogInfo info
;
1262 InitAboutInfoWebsite(info
);
1267 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1269 wxAboutDialogInfo info
;
1270 InitAboutInfoAll(info
);
1275 // a trivial example of a custom dialog class
1276 class MyAboutDialog
: public wxGenericAboutDialog
1279 MyAboutDialog(const wxAboutDialogInfo
& info
)
1284 // add some custom controls
1285 virtual void DoAddCustomControls()
1287 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1288 AddText(_T("Some custom text"));
1289 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1293 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1295 wxAboutDialogInfo info
;
1296 InitAboutInfoAll(info
);
1298 MyAboutDialog
dlg(info
);
1302 #endif // wxUSE_ABOUTDLG
1306 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1308 wxWindowDisabler disableAll
;
1310 wxBusyInfo
info(_T("Working, please wait..."), this);
1312 for ( int i
= 0; i
< 18; i
++ )
1322 #endif // wxUSE_BUSYINFO
1324 #if wxUSE_FINDREPLDLG
1326 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1330 delete m_dlgReplace
;
1331 m_dlgReplace
= NULL
;
1335 m_dlgReplace
= new wxFindReplaceDialog
1339 _T("Find and replace dialog"),
1343 m_dlgReplace
->Show(true);
1347 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1356 m_dlgFind
= new wxFindReplaceDialog
1365 m_dlgFind
->Show(true);
1369 static wxString
DecodeFindDialogEventFlags(int flags
)
1372 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1373 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1374 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1375 << _T("case sensitive");
1380 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1382 wxEventType type
= event
.GetEventType();
1384 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1386 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1387 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1388 event
.GetFindString().c_str(),
1389 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1391 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1392 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1394 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1395 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1396 event
.GetFindString().c_str(),
1397 event
.GetReplaceString().c_str(),
1398 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1400 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1402 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1406 if ( dlg
== m_dlgFind
)
1409 idMenu
= DIALOGS_FIND
;
1412 else if ( dlg
== m_dlgReplace
)
1414 txt
= _T("Replace");
1415 idMenu
= DIALOGS_REPLACE
;
1416 m_dlgReplace
= NULL
;
1420 txt
= _T("Unknown");
1423 wxFAIL_MSG( _T("unexpected event") );
1426 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1428 if ( idMenu
!= wxID_ANY
)
1430 GetMenuBar()->Check(idMenu
, false);
1437 wxLogError(wxT("Unknown find dialog event!"));
1441 #endif // wxUSE_FINDREPLDLG
1443 // ----------------------------------------------------------------------------
1445 // ----------------------------------------------------------------------------
1447 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1450 dc
.SetFont(wxGetApp().m_canvasFont
);
1451 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1452 dc
.SetBackgroundMode(wxTRANSPARENT
);
1454 _T("wxWidgets common dialogs")
1455 #if !defined(__SMARTPHONE__)
1456 _T(" test application")
1461 #if USE_MODAL_PRESENTATION
1463 // ----------------------------------------------------------------------------
1465 // ----------------------------------------------------------------------------
1467 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1468 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1470 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1472 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1473 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1476 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1477 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1481 sizerTop
->SetSizeHints(this);
1482 sizerTop
->Fit(this);
1485 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1487 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1488 wxOK
| wxICON_INFORMATION
, this);
1491 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1493 if ( event
.CanVeto() )
1495 wxMessageBox(_T("Use the menu item to close this dialog"),
1496 _T("Modeless dialog"),
1497 wxOK
| wxICON_INFORMATION
, this);
1503 // ----------------------------------------------------------------------------
1505 // ----------------------------------------------------------------------------
1507 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1508 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1510 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1512 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1513 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1514 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1516 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1517 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1518 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1519 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1520 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1524 sizerTop
->SetSizeHints(this);
1525 sizerTop
->Fit(this);
1527 m_btnModal
->SetFocus();
1528 m_btnModal
->SetDefault();
1531 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1533 if ( event
.GetEventObject() == m_btnDelete
)
1538 m_btnDelete
->Disable();
1540 else if ( event
.GetEventObject() == m_btnModal
)
1543 wxGetTextFromUser(_T("Dummy prompt"),
1544 _T("Modal dialog called from dialog"),
1545 wxEmptyString
, this);
1547 wxMessageBox(_T("Modal dialog called from dialog"));
1548 #endif // wxUSE_TEXTDLG
1550 else if ( event
.GetEventObject() == m_btnModeless
)
1552 (new MyModelessDialog(this))->Show();
1560 #endif // USE_MODAL_PRESENTATION
1562 // ----------------------------------------------------------------------------
1563 // StdButtonSizerDialog
1564 // ----------------------------------------------------------------------------
1566 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1567 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1568 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1569 m_buttonsSizer(NULL
)
1571 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1573 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1574 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1576 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
1578 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
1580 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1581 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
1583 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
1585 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
1587 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
1589 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1590 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
1592 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
1594 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
1595 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
1596 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
1598 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
1600 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
1601 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
1603 sizer
->Add(sizerInside1
, 0, 0, 0);
1604 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
1605 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
1606 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1608 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
1609 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
1611 sizer
->Add(sizerInside2
, 0, 0, 0);
1612 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
1613 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
1614 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1616 sizerTop
->Add(sizer
, 0, wxALL
, 5);
1618 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
1619 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
1620 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
1622 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
1624 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
1626 EnableDisableControls();
1630 sizerTop
->SetSizeHints(this);
1635 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
1639 m_buttonsSizer
->DeleteWindows();
1640 GetSizer()->Remove(m_buttonsSizer
);
1643 EnableDisableControls();
1646 unsigned long numButtons
= 0;
1648 if (m_chkboxAffirmativeButton
->IsChecked())
1650 if (m_radiobtnOk
->GetValue())
1655 else if (m_radiobtnYes
->GetValue())
1662 if (m_chkboxDismissButton
->IsChecked())
1664 if (m_radiobtnCancel
->GetValue())
1670 else if (m_radiobtnClose
->GetValue())
1678 if (m_chkboxApply
->IsChecked())
1684 if (m_chkboxNo
->IsChecked())
1690 if (m_chkboxHelp
->IsChecked())
1696 if (m_chkboxNoDefault
->IsChecked())
1698 flags
|= wxNO_DEFAULT
;
1701 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
1702 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
1705 GetSizer()->SetSizeHints(this);
1708 void StdButtonSizerDialog::EnableDisableControls()
1710 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
1712 m_radiobtnOk
->Enable(affButtonEnabled
);
1713 m_radiobtnYes
->Enable(affButtonEnabled
);
1715 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
1717 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
1718 m_radiobtnClose
->Enable(dismissButtonEnabled
);
1721 #if USE_SETTINGS_DIALOG
1722 // ----------------------------------------------------------------------------
1724 // ----------------------------------------------------------------------------
1726 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1728 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1731 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1733 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1738 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1739 int resizeBorder
= wxRESIZE_BORDER
;
1747 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1748 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1749 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1751 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1753 SetSheetStyle(sheetStyle
);
1754 SetSheetInnerBorder(0);
1755 SetSheetOuterBorder(0);
1757 // create a dummy image list with a few icons
1758 const wxSize
imageSize(32, 32);
1760 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1762 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1764 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1766 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1768 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1773 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1774 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1777 // If using a toolbook, also follow Mac style and don't create buttons
1779 CreateButtons(wxOK
| wxCANCEL
|
1780 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1783 wxBookCtrlBase
* notebook
= GetBookCtrl();
1784 notebook
->SetImageList(m_imageList
);
1786 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1787 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1789 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1790 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1795 SettingsDialog::~SettingsDialog()
1800 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1802 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1804 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1805 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1809 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1810 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1811 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1812 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1816 wxString autoSaveLabel
= _("&Auto-save every");
1817 wxString minsLabel
= _("mins");
1819 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1820 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1823 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1824 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1827 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1829 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1831 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1832 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1836 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1837 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1838 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1839 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1841 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1843 panel
->SetSizer(topSizer
);
1844 topSizer
->Fit(panel
);
1849 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1851 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1853 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1854 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1856 //// PROJECT OR GLOBAL
1857 wxString globalOrProjectChoices
[2];
1858 globalOrProjectChoices
[0] = _("&New projects");
1859 globalOrProjectChoices
[1] = _("&This project");
1861 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1862 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1863 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1865 projectOrGlobal
->SetSelection(0);
1867 //// BACKGROUND STYLE
1868 wxArrayString backgroundStyleChoices
;
1869 backgroundStyleChoices
.Add(wxT("Colour"));
1870 backgroundStyleChoices
.Add(wxT("Image"));
1871 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1873 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1874 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1876 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1878 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1880 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1881 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1882 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1884 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1887 //// FONT SIZE SELECTION
1889 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1890 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1892 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1893 wxSize(80, wxDefaultCoord
));
1894 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1896 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1899 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1900 topSizer
->AddSpacer(5);
1902 panel
->SetSizer(topSizer
);
1903 topSizer
->Fit(panel
);
1908 #endif // USE_SETTINGS_DIALOG