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 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
123 #endif // wxUSE_COLOURDLG
126 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
127 #endif // wxUSE_FONTDLG
130 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
131 #endif // wxUSE_LOG_DIALOG
134 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
135 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
136 #endif // wxUSE_TEXTDLG
139 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
140 #endif // wxUSE_NUMBERDLG
143 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
144 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
145 #endif // wxUSE_CHOICEDLG
148 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
149 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
150 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
151 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
152 #endif // wxUSE_FILEDLG
154 #if USE_FILEDLG_GENERIC
155 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
156 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
157 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
158 #endif // USE_FILEDLG_GENERIC
161 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
162 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
163 #endif // wxUSE_DIRDLG
165 #if USE_MODAL_PRESENTATION
166 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
167 #endif // USE_MODAL_PRESENTATION
168 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
169 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
170 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
171 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
172 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
174 #if wxUSE_STARTUP_TIPS
175 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
176 #endif // wxUSE_STARTUP_TIPS
178 #if USE_FONTDLG_GENERIC
179 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
180 #endif // USE_FONTDLG_GENERIC
182 #if USE_DIRDLG_GENERIC
183 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
184 #endif // wxMSW || wxMAC
186 #if USE_COLOURDLG_GENERIC
187 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
188 #endif // USE_COLOURDLG_GENERIC
190 #if wxUSE_PROGRESSDLG
191 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
192 #endif // wxUSE_PROGRESSDLG
195 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
196 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
197 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
198 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
199 #endif // wxUSE_ABOUTDLG
202 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
203 #endif // wxUSE_BUSYINFO
205 #if wxUSE_FINDREPLDLG
206 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
207 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
209 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
210 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
211 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
212 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
213 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
214 #endif // wxUSE_FINDREPLDLG
216 #if USE_SETTINGS_DIALOG
217 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
218 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
219 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
222 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
223 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
225 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
228 #if USE_MODAL_PRESENTATION
230 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
231 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
234 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
235 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
236 EVT_CLOSE(MyModelessDialog::OnClose
)
239 #endif // USE_MODAL_PRESENTATION
241 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
242 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
243 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
246 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
248 // `Main program' equivalent, creating windows and returning main app frame
251 if ( !wxApp::OnInit() )
255 wxInitAllImageHandlers();
258 m_canvasTextColour
= *wxBLACK
;
259 m_canvasFont
= *wxNORMAL_FONT
;
261 // Create the main frame window
262 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
265 wxMenu
*menuDlg
= new wxMenu
;
267 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
270 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
272 wxMenu
*choices_menu
= new wxMenu
;
275 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose bg colour"));
276 choices_menu
->Append(DIALOGS_GET_COLOUR
, _T("&Choose fg colour"));
277 #endif // wxUSE_COLOURDLG
280 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
281 #endif // wxUSE_FONTDLG
284 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
285 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
286 #endif // wxUSE_CHOICEDLG
288 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
289 choices_menu
->AppendSeparator();
290 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
292 #if USE_COLOURDLG_GENERIC
293 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
294 #endif // USE_COLOURDLG_GENERIC
296 #if USE_FONTDLG_GENERIC
297 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
298 #endif // USE_FONTDLG_GENERIC
300 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
301 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
304 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
306 wxMenu
*entry_menu
= new wxMenu
;
309 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
310 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
311 #endif // wxUSE_TEXTDLG
314 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
315 #endif // wxUSE_NUMBERDLG
317 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
319 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
324 wxMenu
*filedlg_menu
= new wxMenu
;
325 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
326 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
327 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
328 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
330 #if USE_FILEDLG_GENERIC
331 filedlg_menu
->AppendSeparator();
332 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
333 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
334 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
335 #endif // USE_FILEDLG_GENERIC
337 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
339 #endif // wxUSE_FILEDLG
342 wxMenu
*dir_menu
= new wxMenu
;
344 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
345 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
346 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
348 #if USE_DIRDLG_GENERIC
349 dir_menu
->AppendSeparator();
350 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
351 #endif // USE_DIRDLG_GENERIC
353 #endif // wxUSE_DIRDLG
356 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
358 wxMenu
*info_menu
= new wxMenu
;
360 #if wxUSE_STARTUP_TIPS
361 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
362 #endif // wxUSE_STARTUP_TIPS
364 #if wxUSE_PROGRESSDLG
365 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
366 #endif // wxUSE_PROGRESSDLG
369 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
370 #endif // wxUSE_BUSYINFO
373 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
374 #endif // wxUSE_LOG_DIALOG
376 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
378 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
381 #if wxUSE_FINDREPLDLG
382 wxMenu
*find_menu
= new wxMenu
;
383 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
384 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
385 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
386 #endif // wxUSE_FINDREPLDLG
388 wxMenu
*dialogs_menu
= new wxMenu
;
389 #if USE_MODAL_PRESENTATION
390 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
391 #endif // USE_MODAL_PRESENTATION
392 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
393 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
394 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
395 dialogs_menu
->Append(DIALOGS_MINIFRAME
, _T("&Mini frame"));
396 dialogs_menu
->Append(DIALOGS_ONTOP
, _T("Dialog staying on &top"));
397 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
399 #if USE_SETTINGS_DIALOG
400 wxMenu
*sheet_menu
= new wxMenu
;
401 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
402 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
404 if (wxPlatformIs(wxPORT_MAC
))
405 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
408 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
411 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
412 #endif // USE_SETTINGS_DIALOG
414 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, _T("&Standard Buttons Sizer Dialog"));
416 menuDlg
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
418 menuDlg
->AppendSeparator();
419 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
422 wxMenu
*menuHelp
= new wxMenu
;
423 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
424 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
425 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
426 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
427 #endif // wxUSE_ABOUTDLG
429 wxMenuBar
*menubar
= new wxMenuBar
;
430 menubar
->Append(menuDlg
, _T("&Dialogs"));
432 menubar
->Append(menuHelp
, _T("&Help"));
433 #endif // wxUSE_ABOUTDLG
435 frame
->SetMenuBar(menubar
);
437 myCanvas
= new MyCanvas(frame
);
438 myCanvas
->SetBackgroundColour(*wxWHITE
);
440 frame
->Centre(wxBOTH
);
450 // My frame constructor
451 MyFrame::MyFrame(wxWindow
*parent
,
452 const wxString
& title
)
453 : wxFrame(parent
, wxID_ANY
, title
)
457 #if USE_MODAL_PRESENTATION
458 m_dialog
= (MyModelessDialog
*)NULL
;
459 #endif // USE_MODAL_PRESENTATION
461 #if wxUSE_FINDREPLDLG
467 m_clrData
.SetChooseFull(true);
468 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
470 unsigned char n
= i
*16;
471 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
473 #endif // wxUSE_COLOURDLG
477 #endif // wxUSE_STATUSBAR
482 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
484 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
486 wxColourDialog
dialog(this, &m_clrData
);
487 dialog
.SetTitle(_("Please choose the background colour"));
488 if ( dialog
.ShowModal() == wxID_OK
)
490 m_clrData
= dialog
.GetColourData();
491 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
492 myCanvas
->ClearBackground();
497 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
499 wxColour clr
= wxGetColourFromUser
502 wxGetApp().m_canvasTextColour
,
503 "Please choose the foreground colour"
507 wxGetApp().m_canvasTextColour
= clr
;
510 //else: dialog cancelled by user
513 #endif // wxUSE_COLOURDLG
516 #if USE_COLOURDLG_GENERIC
517 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
519 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
521 //FIXME:TODO:This has no effect...
522 m_clrData
.SetChooseFull(true);
524 for (int i
= 0; i
< 16; i
++)
527 (unsigned char)(i
*16),
528 (unsigned char)(i
*16),
529 (unsigned char)(i
*16)
531 m_clrData
.SetCustomColour(i
, colour
);
534 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
535 if (dialog
->ShowModal() == wxID_OK
)
537 m_clrData
= dialog
->GetColourData();
538 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
539 myCanvas
->ClearBackground();
544 #endif // USE_COLOURDLG_GENERIC
547 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
550 data
.SetInitialFont(wxGetApp().m_canvasFont
);
551 data
.SetColour(wxGetApp().m_canvasTextColour
);
553 // you might also do this:
555 // wxFontDialog dialog;
556 // if ( !dialog.Create(this, data) { ... error ... }
558 wxFontDialog
dialog(this, data
);
560 if (dialog
.ShowModal() == wxID_OK
)
562 wxFontData retData
= dialog
.GetFontData();
563 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
564 wxGetApp().m_canvasTextColour
= retData
.GetColour();
567 //else: cancelled by the user, don't change the font
569 #endif // wxUSE_FONTDLG
571 #if USE_FONTDLG_GENERIC
572 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
575 data
.SetInitialFont(wxGetApp().m_canvasFont
);
576 data
.SetColour(wxGetApp().m_canvasTextColour
);
578 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
579 if (dialog
->ShowModal() == wxID_OK
)
581 wxFontData retData
= dialog
->GetFontData();
582 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
583 wxGetApp().m_canvasTextColour
= retData
.GetColour();
588 #endif // USE_FONTDLG_GENERIC
591 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
593 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
594 // being flushed -- test it
597 wxLogMessage(wxT("This is some message - everything is ok so far."));
598 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
599 wxLogWarning(wxT("And then something went wrong!"));
601 // and if ~wxBusyCursor doesn't do it, then call it manually
605 wxLogError(wxT("Intermediary error handler decided to abort."));
606 wxLogError(wxT("The top level caller detected an unrecoverable error."));
608 wxLog::FlushActive();
610 wxLogMessage(wxT("And this is the same dialog but with only one message."));
612 #endif // wxUSE_LOG_DIALOG
614 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
616 wxMessageDialog
dialog(NULL
,
617 _T("This is a message box\nA long, long string to test out the message box properly"),
618 _T("Message box text"),
619 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
| wxICON_INFORMATION
);
621 if ( dialog
.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
623 dialog
.SetExtendedMessage(_T("This platform supports custom button labels"));
627 dialog
.SetExtendedMessage(_T("Custom button labels are not supported."));
630 switch ( dialog
.ShowModal() )
633 wxLogStatus(wxT("You pressed \"Yes\""));
637 wxLogStatus(wxT("You pressed \"No\""));
641 wxLogStatus(wxT("You pressed \"Cancel\""));
645 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
650 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
652 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
653 _T("Even two rows of text."),
654 _T("Enter a number:"), _T("Numeric input test"),
661 msg
= _T("Invalid number entered or dialog cancelled.");
666 msg
.Printf(_T("You've entered %lu"), res
);
667 icon
= wxICON_INFORMATION
;
670 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
672 #endif // wxUSE_NUMBERDLG
675 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
677 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
678 _T("Password entry dialog"),
683 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
684 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
688 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
690 wxTextEntryDialog
dialog(this,
691 _T("This is a small sample\n")
692 _T("A long, long string to test out the text entrybox"),
693 _T("Please enter a string"),
697 if (dialog
.ShowModal() == wxID_OK
)
699 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
702 #endif // wxUSE_TEXTDLG
705 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
707 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
709 wxSingleChoiceDialog
dialog(this,
710 _T("This is a small sample\n")
711 _T("A single-choice convenience dialog"),
712 _T("Please select a value"),
713 WXSIZEOF(choices
), choices
);
715 dialog
.SetSelection(2);
717 if (dialog
.ShowModal() == wxID_OK
)
719 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
724 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
726 const wxString choices
[] =
728 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
729 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
730 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
733 wxArrayInt selections
;
734 size_t count
= wxGetMultipleChoices(selections
,
735 _T("This is a small sample\n")
736 _T("A multi-choice convenience dialog"),
737 _T("Please select a value"),
738 WXSIZEOF(choices
), choices
,
743 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
744 for ( size_t n
= 0; n
< count
; n
++ )
746 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
747 (unsigned)n
, (unsigned)selections
[n
],
748 choices
[selections
[n
]].c_str());
752 //else: cancelled or nothing selected
754 #endif // wxUSE_CHOICEDLG
757 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
762 _T("Testing open file dialog"),
766 _T("C++ files (*.cpp)|*.cpp")
768 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
772 dialog
.CentreOnParent();
773 dialog
.SetDirectory(wxGetHomeDir());
775 if (dialog
.ShowModal() == wxID_OK
)
778 info
.Printf(_T("Full file name: %s\n")
781 dialog
.GetPath().c_str(),
782 dialog
.GetDirectory().c_str(),
783 dialog
.GetFilename().c_str());
784 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
789 // this shows how to take advantage of specifying a default extension in the
790 // call to wxFileSelector: it is remembered after each new call and the next
791 // one will use it by default
792 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
794 static wxString s_extDef
;
795 wxString path
= wxFileSelector(
796 _T("Select the file to load"),
797 wxEmptyString
, wxEmptyString
,
801 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
802 wxFileSelectorDefaultWildcardStr
,
803 wxFileSelectorDefaultWildcardStr
805 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
812 // it is just a sample, would use wxSplitPath in real program
813 s_extDef
= path
.AfterLast(_T('.'));
815 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
819 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
823 _T("C++ files (*.cpp)|*.cpp");
827 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
828 wxFileSelectorDefaultWildcardStr
,
829 wxFileSelectorDefaultWildcardStr
832 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
833 wxEmptyString
, wxEmptyString
, wildcards
,
834 wxFD_OPEN
|wxFD_MULTIPLE
);
836 if (dialog
.ShowModal() == wxID_OK
)
838 wxArrayString paths
, filenames
;
840 dialog
.GetPaths(paths
);
841 dialog
.GetFilenames(filenames
);
844 size_t count
= paths
.GetCount();
845 for ( size_t n
= 0; n
< count
; n
++ )
847 s
.Printf(_T("File %d: %s (%s)\n"),
848 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
852 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
855 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
860 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
862 wxFileDialog
dialog(this,
863 _T("Testing save file dialog"),
866 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
867 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
869 dialog
.SetFilterIndex(1);
871 if (dialog
.ShowModal() == wxID_OK
)
873 wxLogMessage(_T("%s, filter %d"),
874 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
877 #endif // wxUSE_FILEDLG
879 #if USE_FILEDLG_GENERIC
880 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
882 wxGenericFileDialog dialog
885 _T("Testing open file dialog"),
888 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
891 dialog
.SetDirectory(wxGetHomeDir());
893 if (dialog
.ShowModal() == wxID_OK
)
896 info
.Printf(_T("Full file name: %s\n")
899 dialog
.GetPath().c_str(),
900 dialog
.GetDirectory().c_str(),
901 dialog
.GetFilename().c_str());
902 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
907 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
909 // On PocketPC you can disable OK-only dialogs policy using system option
910 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
911 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
913 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
914 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
915 wxEmptyString
, wxEmptyString
, wildcards
,
918 if (dialog
.ShowModal() == wxID_OK
)
920 wxArrayString paths
, filenames
;
922 dialog
.GetPaths(paths
);
923 dialog
.GetFilenames(filenames
);
926 size_t count
= paths
.GetCount();
927 for ( size_t n
= 0; n
< count
; n
++ )
929 s
.Printf(_T("File %d: %s (%s)\n"),
930 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
934 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
937 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
941 // restore system option
942 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
945 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
947 wxGenericFileDialog
dialog(this,
948 _T("Testing save file dialog"),
951 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
952 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
954 dialog
.SetFilterIndex(1);
956 if (dialog
.ShowModal() == wxID_OK
)
958 wxLogMessage(_T("%s, filter %d"),
959 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
962 #endif // USE_FILEDLG_GENERIC
965 void MyFrame::DoDirChoose(int style
)
967 // pass some initial dir to wxDirDialog
969 wxGetHomeDir(&dirHome
);
971 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
973 if (dialog
.ShowModal() == wxID_OK
)
975 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
979 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
981 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
984 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
986 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
988 #endif // wxUSE_DIRDLG
990 #if USE_DIRDLG_GENERIC
991 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
993 // pass some initial dir to wxDirDialog
995 wxGetHomeDir(&dirHome
);
997 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
999 if (dialog
.ShowModal() == wxID_OK
)
1001 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
1002 dialog2
.ShowModal();
1005 #endif // USE_DIRDLG_GENERIC
1007 #if USE_MODAL_PRESENTATION
1008 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1010 MyModalDialog
dlg(this);
1013 #endif // USE_MODAL_PRESENTATION
1015 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1017 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1023 m_dialog
= new MyModelessDialog(this);
1026 m_dialog
->Show(true);
1030 // If m_dialog is NULL, then possibly the system
1031 // didn't report the checked menu item status correctly.
1032 // It should be true just after the menu item was selected,
1033 // if there was no modeless dialog yet.
1035 wxASSERT( m_dialog
!= NULL
);
1041 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1043 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1044 wxDefaultPosition
, wxSize(200, 100));
1045 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1046 dlg
.CentreOnScreen();
1050 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1052 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1053 wxDefaultPosition
, wxSize(200, 100));
1054 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1055 dlg
.CentreOnParent();
1059 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1061 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, _T("Mini frame"),
1062 wxDefaultPosition
, wxSize(300, 100),
1063 wxCAPTION
| wxCLOSE_BOX
);
1064 new wxStaticText(frame
,
1066 _T("Mini frames have slightly different appearance"),
1068 new wxStaticText(frame
,
1070 _T("from the normal frames but that's the only difference."),
1073 frame
->CentreOnParent();
1077 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1079 wxDialog
dlg(this, wxID_ANY
, _T("Dialog staying on top of other windows"),
1080 wxDefaultPosition
, wxSize(300, 100),
1081 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1082 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1086 #if wxUSE_STARTUP_TIPS
1087 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1089 static size_t s_index
= (size_t)-1;
1091 if ( s_index
== (size_t)-1 )
1095 // this is completely bogus, we don't know how many lines are there
1096 // in the file, but who cares, it's a demo only...
1097 s_index
= rand() % 5;
1100 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1102 bool showAtStartup
= wxShowTip(this, tipProvider
);
1104 if ( showAtStartup
)
1106 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1107 wxOK
| wxICON_INFORMATION
, this);
1110 s_index
= tipProvider
->GetCurrentTip();
1113 #endif // wxUSE_STARTUP_TIPS
1115 #if USE_SETTINGS_DIALOG
1116 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1118 SettingsDialog
dialog(this, event
.GetId());
1121 #endif // USE_SETTINGS_DIALOG
1123 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1125 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1129 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1132 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1134 StdButtonSizerDialog
dialog(this);
1138 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1143 #if wxUSE_PROGRESSDLG
1145 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1147 static const int max
= 100;
1149 wxProgressDialog
dialog(_T("Progress dialog example"),
1150 _T("An informative message"),
1156 // wxPD_AUTO_HIDE | -- try this as well
1158 wxPD_ESTIMATED_TIME
|
1160 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1164 for ( int i
= 0; i
<= max
; i
++ )
1170 // test both modes of wxProgressDialog behaviour: start in
1171 // indeterminate mode but switch to the determinate one later
1172 const bool determinate
= i
> max
/2;
1176 msg
= _T("That's all, folks!");
1178 else if ( !determinate
)
1180 msg
= _T("Testing indeterminate mode");
1182 else if ( determinate
)
1184 msg
= _T("Now in standard determinate mode");
1187 // will be set to true if "Skip" button was pressed
1191 cont
= dialog
.Update(i
, msg
, &skip
);
1195 cont
= dialog
.Pulse(msg
, &skip
);
1198 // each skip will move progress about quarter forward
1204 if ( wxMessageBox(_T("Do you really want to cancel?"),
1205 _T("Progress dialog question"), // caption
1206 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1216 wxLogStatus(wxT("Progress dialog aborted!"));
1220 wxLogStatus(wxT("Countdown from %d finished"), max
);
1224 #endif // wxUSE_PROGRESSDLG
1228 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1230 info
.SetName(_T("Dialogs Sample"));
1231 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1232 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1233 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1234 info
.AddDeveloper(_T("Vadim Zeitlin"));
1237 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1239 InitAboutInfoMinimal(info
);
1241 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1244 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1246 InitAboutInfoMinimal(info
);
1248 // we can add a second developer
1249 info
.AddDeveloper(_T("A.N. Other"));
1251 // or we can add several persons at once like this
1252 static const wxChar
*docwriters
[] =
1254 _T("First D. Writer"),
1258 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1259 info
.SetLicence(wxString::FromAscii(
1260 " wxWindows Library Licence, Version 3.1\n"
1261 " ======================================\n"
1263 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1265 " Everyone is permitted to copy and distribute verbatim copies\n"
1266 " of this licence document, but changing it is not allowed.\n"
1268 " WXWINDOWS LIBRARY LICENCE\n"
1269 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1271 " ...and so on and so forth...\n"
1274 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1277 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1279 wxAboutDialogInfo info
;
1280 InitAboutInfoMinimal(info
);
1285 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1287 wxAboutDialogInfo info
;
1288 InitAboutInfoWebsite(info
);
1293 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1295 wxAboutDialogInfo info
;
1296 InitAboutInfoAll(info
);
1301 // a trivial example of a custom dialog class
1302 class MyAboutDialog
: public wxGenericAboutDialog
1305 MyAboutDialog(const wxAboutDialogInfo
& info
)
1310 // add some custom controls
1311 virtual void DoAddCustomControls()
1313 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1314 AddText(_T("Some custom text"));
1315 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1319 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1321 wxAboutDialogInfo info
;
1322 InitAboutInfoAll(info
);
1324 MyAboutDialog
dlg(info
);
1328 #endif // wxUSE_ABOUTDLG
1332 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1334 wxWindowDisabler disableAll
;
1336 wxBusyInfo
info(_T("Working, please wait..."), this);
1338 for ( int i
= 0; i
< 18; i
++ )
1348 #endif // wxUSE_BUSYINFO
1350 #if wxUSE_FINDREPLDLG
1352 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1356 delete m_dlgReplace
;
1357 m_dlgReplace
= NULL
;
1361 m_dlgReplace
= new wxFindReplaceDialog
1365 _T("Find and replace dialog"),
1369 m_dlgReplace
->Show(true);
1373 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1382 m_dlgFind
= new wxFindReplaceDialog
1391 m_dlgFind
->Show(true);
1395 static wxString
DecodeFindDialogEventFlags(int flags
)
1398 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1399 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1400 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1401 << _T("case sensitive");
1406 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1408 wxEventType type
= event
.GetEventType();
1410 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1412 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1413 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1414 event
.GetFindString().c_str(),
1415 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1417 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1418 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1420 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1421 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1422 event
.GetFindString().c_str(),
1423 event
.GetReplaceString().c_str(),
1424 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1426 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1428 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1432 if ( dlg
== m_dlgFind
)
1435 idMenu
= DIALOGS_FIND
;
1438 else if ( dlg
== m_dlgReplace
)
1440 txt
= _T("Replace");
1441 idMenu
= DIALOGS_REPLACE
;
1442 m_dlgReplace
= NULL
;
1446 txt
= _T("Unknown");
1449 wxFAIL_MSG( _T("unexpected event") );
1452 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1454 if ( idMenu
!= wxID_ANY
)
1456 GetMenuBar()->Check(idMenu
, false);
1463 wxLogError(wxT("Unknown find dialog event!"));
1467 #endif // wxUSE_FINDREPLDLG
1469 // ----------------------------------------------------------------------------
1471 // ----------------------------------------------------------------------------
1473 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1476 dc
.SetFont(wxGetApp().m_canvasFont
);
1477 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1478 dc
.SetBackgroundMode(wxTRANSPARENT
);
1480 _T("wxWidgets common dialogs")
1481 #if !defined(__SMARTPHONE__)
1482 _T(" test application")
1487 #if USE_MODAL_PRESENTATION
1489 // ----------------------------------------------------------------------------
1491 // ----------------------------------------------------------------------------
1493 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1494 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1496 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1498 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1499 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1502 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1503 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1507 sizerTop
->SetSizeHints(this);
1508 sizerTop
->Fit(this);
1511 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1513 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1514 wxOK
| wxICON_INFORMATION
, this);
1517 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1519 if ( event
.CanVeto() )
1521 wxMessageBox(_T("Use the menu item to close this dialog"),
1522 _T("Modeless dialog"),
1523 wxOK
| wxICON_INFORMATION
, this);
1529 // ----------------------------------------------------------------------------
1531 // ----------------------------------------------------------------------------
1533 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1534 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1536 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1538 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1539 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1540 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1542 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1543 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1544 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1545 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1546 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1550 sizerTop
->SetSizeHints(this);
1551 sizerTop
->Fit(this);
1553 m_btnModal
->SetFocus();
1554 m_btnModal
->SetDefault();
1557 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1559 if ( event
.GetEventObject() == m_btnDelete
)
1564 m_btnDelete
->Disable();
1566 else if ( event
.GetEventObject() == m_btnModal
)
1569 wxGetTextFromUser(_T("Dummy prompt"),
1570 _T("Modal dialog called from dialog"),
1571 wxEmptyString
, this);
1573 wxMessageBox(_T("Modal dialog called from dialog"));
1574 #endif // wxUSE_TEXTDLG
1576 else if ( event
.GetEventObject() == m_btnModeless
)
1578 (new MyModelessDialog(this))->Show();
1586 #endif // USE_MODAL_PRESENTATION
1588 // ----------------------------------------------------------------------------
1589 // StdButtonSizerDialog
1590 // ----------------------------------------------------------------------------
1592 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1593 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1594 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1595 m_buttonsSizer(NULL
)
1597 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1599 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1600 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1602 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
1604 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
1606 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1607 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
1609 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
1611 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
1613 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
1615 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1616 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
1618 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
1620 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
1621 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
1622 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
1624 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
1626 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
1627 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
1629 sizer
->Add(sizerInside1
, 0, 0, 0);
1630 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
1631 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
1632 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1634 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
1635 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
1637 sizer
->Add(sizerInside2
, 0, 0, 0);
1638 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
1639 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
1640 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1642 sizerTop
->Add(sizer
, 0, wxALL
, 5);
1644 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
1645 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
1646 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
1648 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
1650 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
1652 EnableDisableControls();
1656 sizerTop
->SetSizeHints(this);
1661 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
1665 m_buttonsSizer
->DeleteWindows();
1666 GetSizer()->Remove(m_buttonsSizer
);
1669 EnableDisableControls();
1672 unsigned long numButtons
= 0;
1674 if (m_chkboxAffirmativeButton
->IsChecked())
1676 if (m_radiobtnOk
->GetValue())
1681 else if (m_radiobtnYes
->GetValue())
1688 if (m_chkboxDismissButton
->IsChecked())
1690 if (m_radiobtnCancel
->GetValue())
1696 else if (m_radiobtnClose
->GetValue())
1704 if (m_chkboxApply
->IsChecked())
1710 if (m_chkboxNo
->IsChecked())
1716 if (m_chkboxHelp
->IsChecked())
1722 if (m_chkboxNoDefault
->IsChecked())
1724 flags
|= wxNO_DEFAULT
;
1727 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
1728 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
1731 GetSizer()->SetSizeHints(this);
1734 void StdButtonSizerDialog::EnableDisableControls()
1736 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
1738 m_radiobtnOk
->Enable(affButtonEnabled
);
1739 m_radiobtnYes
->Enable(affButtonEnabled
);
1741 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
1743 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
1744 m_radiobtnClose
->Enable(dismissButtonEnabled
);
1747 #if USE_SETTINGS_DIALOG
1748 // ----------------------------------------------------------------------------
1750 // ----------------------------------------------------------------------------
1752 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1754 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1757 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1759 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1764 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1765 int resizeBorder
= wxRESIZE_BORDER
;
1773 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1774 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1775 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1777 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1779 SetSheetStyle(sheetStyle
);
1780 SetSheetInnerBorder(0);
1781 SetSheetOuterBorder(0);
1783 // create a dummy image list with a few icons
1784 const wxSize
imageSize(32, 32);
1786 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1788 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1790 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1792 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1794 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1799 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1800 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1803 // If using a toolbook, also follow Mac style and don't create buttons
1805 CreateButtons(wxOK
| wxCANCEL
|
1806 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1809 wxBookCtrlBase
* notebook
= GetBookCtrl();
1810 notebook
->SetImageList(m_imageList
);
1812 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1813 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1815 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1816 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1821 SettingsDialog::~SettingsDialog()
1826 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1828 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1830 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1831 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1835 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1836 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1837 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1838 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1842 wxString autoSaveLabel
= _("&Auto-save every");
1843 wxString minsLabel
= _("mins");
1845 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1846 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1849 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1850 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1853 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1855 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1857 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1858 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1862 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1863 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1864 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1865 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1867 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1869 panel
->SetSizer(topSizer
);
1870 topSizer
->Fit(panel
);
1875 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1877 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1879 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1880 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1882 //// PROJECT OR GLOBAL
1883 wxString globalOrProjectChoices
[2];
1884 globalOrProjectChoices
[0] = _("&New projects");
1885 globalOrProjectChoices
[1] = _("&This project");
1887 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1888 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1889 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1891 projectOrGlobal
->SetSelection(0);
1893 //// BACKGROUND STYLE
1894 wxArrayString backgroundStyleChoices
;
1895 backgroundStyleChoices
.Add(wxT("Colour"));
1896 backgroundStyleChoices
.Add(wxT("Image"));
1897 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1899 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1900 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1902 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1904 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1906 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1907 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1908 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1910 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1913 //// FONT SIZE SELECTION
1915 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1916 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1918 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1919 wxSize(80, wxDefaultCoord
));
1920 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1922 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1925 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1926 topSizer
->AddSpacer(5);
1928 panel
->SetSizer(topSizer
);
1929 topSizer
->Fit(panel
);
1934 #endif // USE_SETTINGS_DIALOG