1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
7 // Copyright: (c) Julian Smart
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
24 #include "../sample.xpm"
26 #include "wx/apptrait.h"
27 #include "wx/datetime.h"
29 #include "wx/bookctrl.h"
30 #include "wx/artprov.h"
31 #include "wx/imaglist.h"
32 #include "wx/minifram.h"
33 #include "wx/sysopt.h"
34 #include "wx/notifmsg.h"
37 #include "wx/colordlg.h"
38 #endif // wxUSE_COLOURDLG
41 #include "wx/choicdlg.h"
42 #endif // wxUSE_CHOICEDLG
44 #include "wx/rearrangectrl.h"
46 #if wxUSE_STARTUP_TIPS
47 #include "wx/tipdlg.h"
48 #endif // wxUSE_STARTUP_TIPS
51 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
52 #include "wx/datetime.h" // wxDateTime
55 #include "wx/progdlg.h"
56 #endif // wxUSE_PROGRESSDLG
59 #include "wx/aboutdlg.h"
61 // these headers are only needed for custom about dialog
62 #include "wx/statline.h"
63 #include "wx/generic/aboutdlgg.h"
64 #endif // wxUSE_ABOUTDLG
67 #include "wx/busyinfo.h"
68 #endif // wxUSE_BUSYINFO
71 #include "wx/numdlg.h"
72 #endif // wxUSE_NUMBERDLG
75 #include "wx/filedlg.h"
76 #endif // wxUSE_FILEDLG
79 #include "wx/dirdlg.h"
80 #endif // wxUSE_DIRDLG
83 #include "wx/fontdlg.h"
84 #endif // wxUSE_FONTDLG
87 #include "wx/fdrepdlg.h"
88 #endif // wxUSE_FINDREPLDLG
91 #include "wx/infobar.h"
92 #endif // wxUSE_INFOBAR
94 #include "wx/spinctrl.h"
95 #include "wx/propdlg.h"
99 #if USE_COLOURDLG_GENERIC
100 #include "wx/generic/colrdlgg.h"
101 #endif // USE_COLOURDLG_GENERIC
103 #if USE_DIRDLG_GENERIC
104 #include "wx/generic/dirdlgg.h"
105 #endif // USE_DIRDLG_GENERIC
107 #if USE_FILEDLG_GENERIC
108 #include "wx/generic/filedlgg.h"
109 #endif // USE_FILEDLG_GENERIC
111 #if USE_FONTDLG_GENERIC
112 #include "wx/generic/fontdlgg.h"
113 #endif // USE_FONTDLG_GENERIC
117 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
118 EVT_PAINT(MyCanvas::OnPaint
)
123 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
125 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
126 EVT_MENU(DIALOGS_MESSAGE_DIALOG
, MyFrame::MessageBoxDialog
)
127 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
128 #endif // wxUSE_MSGDLG
130 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
131 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
132 #endif // wxUSE_COLOURDLG
135 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
136 #endif // wxUSE_FONTDLG
139 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
140 #endif // wxUSE_LOG_DIALOG
142 EVT_MENU(DIALOGS_INFOBAR_SIMPLE
, MyFrame::InfoBarSimple
)
143 EVT_MENU(DIALOGS_INFOBAR_ADVANCED
, MyFrame::InfoBarAdvanced
)
144 #endif // wxUSE_INFOBAR
147 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
148 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
149 #endif // wxUSE_TEXTDLG
152 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
153 #endif // wxUSE_NUMBERDLG
156 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
157 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
158 #endif // wxUSE_CHOICEDLG
160 #if wxUSE_REARRANGECTRL
161 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
162 #endif // wxUSE_REARRANGECTRL
165 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
166 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
167 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
168 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
169 #endif // wxUSE_FILEDLG
171 #if USE_FILEDLG_GENERIC
172 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
173 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
174 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
175 #endif // USE_FILEDLG_GENERIC
178 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
179 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
180 #endif // wxUSE_DIRDLG
182 #if USE_MODAL_PRESENTATION
183 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
184 #endif // USE_MODAL_PRESENTATION
185 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
186 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
187 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
189 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
190 #endif // wxUSE_MINIFRAME
191 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
193 #if wxUSE_STARTUP_TIPS
194 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
195 #endif // wxUSE_STARTUP_TIPS
197 #if USE_FONTDLG_GENERIC
198 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
199 #endif // USE_FONTDLG_GENERIC
201 #if USE_DIRDLG_GENERIC
202 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
203 #endif // wxMSW || wxMAC
205 #if USE_COLOURDLG_GENERIC
206 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
207 #endif // USE_COLOURDLG_GENERIC
209 #if wxUSE_PROGRESSDLG
210 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
211 #endif // wxUSE_PROGRESSDLG
214 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
215 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
216 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
217 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
218 #endif // wxUSE_ABOUTDLG
221 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
222 #endif // wxUSE_BUSYINFO
224 #if wxUSE_FINDREPLDLG
225 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
226 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
228 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
229 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
230 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
231 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
232 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
233 #endif // wxUSE_FINDREPLDLG
235 #if USE_SETTINGS_DIALOG
236 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
237 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
238 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
239 #endif // USE_SETTINGS_DIALOG
241 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
242 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
244 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
245 #if wxUSE_NOTIFICATION_MESSAGE
246 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
247 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
248 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
249 #endif // wxUSE_NOTIFICATION_MESSAGE
251 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
254 #if USE_MODAL_PRESENTATION
256 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
257 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
260 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
261 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
262 EVT_CLOSE(MyModelessDialog::OnClose
)
265 #endif // USE_MODAL_PRESENTATION
267 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
268 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
269 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
272 // `Main program' equivalent, creating windows and returning main app frame
275 if ( !wxApp::OnInit() )
279 wxInitAllImageHandlers();
282 // Create the main frame window
283 MyFrame
*frame
= new MyFrame(wxT("wxWidgets dialogs example"));
286 wxMenu
*menuDlg
= new wxMenu
;
288 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
289 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
292 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
294 wxMenu
*choices_menu
= new wxMenu
;
297 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
298 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
299 #endif // wxUSE_COLOURDLG
302 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
303 #endif // wxUSE_FONTDLG
306 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
307 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
308 #endif // wxUSE_CHOICEDLG
310 #if wxUSE_REARRANGECTRL
311 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
312 #endif // wxUSE_REARRANGECTRL
314 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
315 choices_menu
->AppendSeparator();
316 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
318 #if USE_COLOURDLG_GENERIC
319 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
320 #endif // USE_COLOURDLG_GENERIC
322 #if USE_FONTDLG_GENERIC
323 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
324 #endif // USE_FONTDLG_GENERIC
326 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
327 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
330 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
332 wxMenu
*entry_menu
= new wxMenu
;
335 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Text &entry\tCtrl-E"));
336 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
337 #endif // wxUSE_TEXTDLG
340 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
341 #endif // wxUSE_NUMBERDLG
343 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
345 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
350 wxMenu
*filedlg_menu
= new wxMenu
;
351 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
352 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
353 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
354 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
356 #if USE_FILEDLG_GENERIC
357 filedlg_menu
->AppendSeparator();
358 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
359 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
360 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
361 #endif // USE_FILEDLG_GENERIC
363 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
365 #endif // wxUSE_FILEDLG
368 wxMenu
*dir_menu
= new wxMenu
;
370 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
371 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
372 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
374 #if USE_DIRDLG_GENERIC
375 dir_menu
->AppendSeparator();
376 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
377 #endif // USE_DIRDLG_GENERIC
379 #endif // wxUSE_DIRDLG
382 #if wxUSE_STARTUP_TIPS || \
383 wxUSE_PROGRESSDLG || \
385 wxUSE_LOG_DIALOG || \
388 wxMenu
*info_menu
= new wxMenu
;
390 #if wxUSE_STARTUP_TIPS
391 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
392 #endif // wxUSE_STARTUP_TIPS
394 #if wxUSE_PROGRESSDLG
395 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
396 #endif // wxUSE_PROGRESSDLG
399 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
400 #endif // wxUSE_BUSYINFO
403 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
404 #endif // wxUSE_LOG_DIALOG
407 info_menu
->Append(DIALOGS_INFOBAR_SIMPLE
, "Simple &info bar\tCtrl-I");
408 info_menu
->Append(DIALOGS_INFOBAR_ADVANCED
, "&Advanced info bar\tShift-Ctrl-I");
409 #endif // wxUSE_INFOBAR
412 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
413 wxT("&wxWidgets information\tCtrl-W"));
414 #endif // wxUSE_MSGDLG
416 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
418 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
421 #if wxUSE_FINDREPLDLG
422 wxMenu
*find_menu
= new wxMenu
;
423 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
424 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
425 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
426 #endif // wxUSE_FINDREPLDLG
428 wxMenu
*dialogs_menu
= new wxMenu
;
429 #if USE_MODAL_PRESENTATION
430 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tShift-Ctrl-W"));
431 #endif // USE_MODAL_PRESENTATION
432 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tShift-Ctrl-Z"));
433 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
434 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
436 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
437 #endif // wxUSE_MINIFRAME
438 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
439 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
441 #if USE_SETTINGS_DIALOG
442 wxMenu
*sheet_menu
= new wxMenu
;
443 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
444 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
446 if (wxPlatformIs(wxPORT_MAC
))
447 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
450 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
453 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
454 #endif // USE_SETTINGS_DIALOG
456 wxMenu
*menuNotif
= new wxMenu
;
457 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
458 #if wxUSE_NOTIFICATION_MESSAGE
459 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
460 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
461 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
462 #endif // wxUSE_NOTIFICATION_MESSAGE
463 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
465 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
466 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
468 menuDlg
->AppendSeparator();
469 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
472 wxMenu
*menuHelp
= new wxMenu
;
473 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
474 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
475 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
476 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
477 #endif // wxUSE_ABOUTDLG
479 wxMenuBar
*menubar
= new wxMenuBar
;
480 menubar
->Append(menuDlg
, wxT("&Dialogs"));
482 menubar
->Append(menuHelp
, wxT("&Help"));
483 #endif // wxUSE_ABOUTDLG
485 frame
->SetMenuBar(menubar
);
487 frame
->Centre(wxBOTH
);
493 // My frame constructor
494 MyFrame::MyFrame(const wxString
& title
)
495 : wxFrame(NULL
, wxID_ANY
, title
)
499 #if USE_MODAL_PRESENTATION
500 m_dialog
= (MyModelessDialog
*)NULL
;
501 #endif // USE_MODAL_PRESENTATION
503 #if wxUSE_FINDREPLDLG
509 m_clrData
.SetChooseFull(true);
510 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
512 unsigned char n
= i
*16;
513 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
515 #endif // wxUSE_COLOURDLG
517 #if wxUSE_NOTIFICATION_MESSAGE
519 #endif // wxUSE_NOTIFICATION_MESSAGE
523 #endif // wxUSE_STATUSBAR
525 m_canvas
= new MyCanvas(this);
528 // an info bar can be created very simply and used without any extra effort
529 m_infoBarSimple
= new wxInfoBar(this);
531 // or it can also be customized
532 m_infoBarAdvanced
= new wxInfoBar(this);
533 m_infoBarAdvanced
->AddButton(wxID_UNDO
);
535 m_infoBarAdvanced
->SetOwnBackgroundColour(0xc8ffff);
536 m_infoBarAdvanced
->SetShowHideEffects(wxSHOW_EFFECT_EXPAND
,
537 wxSHOW_EFFECT_EXPAND
);
538 m_infoBarAdvanced
->SetEffectDuration(1500);
540 // to use the info bars we need to use sizer for the window layout
541 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
542 sizer
->Add(m_infoBarSimple
, wxSizerFlags().Expand());
543 sizer
->Add(m_canvas
, wxSizerFlags(1).Expand());
544 sizer
->Add(m_infoBarAdvanced
, wxSizerFlags().Expand());
546 #endif // wxUSE_INFOBAR
551 #if wxUSE_NOTIFICATION_MESSAGE
553 #endif // wxUSE_NOTIFICATION_MESSAGE
558 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
560 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
562 wxColourDialog
dialog(this, &m_clrData
);
563 dialog
.SetTitle(_("Please choose the background colour"));
564 if ( dialog
.ShowModal() == wxID_OK
)
566 m_clrData
= dialog
.GetColourData();
567 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
568 m_canvas
->ClearBackground();
573 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
575 wxColour clr
= wxGetColourFromUser
578 m_canvas
->GetForegroundColour(),
579 "Please choose the foreground colour"
583 m_canvas
->SetForegroundColour(clr
);
586 //else: dialog cancelled by user
589 #endif // wxUSE_COLOURDLG
592 #if USE_COLOURDLG_GENERIC
593 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
595 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
597 //FIXME:TODO:This has no effect...
598 m_clrData
.SetChooseFull(true);
600 for (int i
= 0; i
< 16; i
++)
603 (unsigned char)(i
*16),
604 (unsigned char)(i
*16),
605 (unsigned char)(i
*16)
607 m_clrData
.SetCustomColour(i
, colour
);
610 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
611 if (dialog
->ShowModal() == wxID_OK
)
613 m_clrData
= dialog
->GetColourData();
614 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
615 m_canvas
->ClearBackground();
620 #endif // USE_COLOURDLG_GENERIC
623 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
626 data
.SetInitialFont(m_canvas
->GetFont());
627 data
.SetColour(m_canvas
->GetForegroundColour());
629 // you might also do this:
631 // wxFontDialog dialog;
632 // if ( !dialog.Create(this, data) { ... error ... }
634 wxFontDialog
dialog(this, data
);
636 if (dialog
.ShowModal() == wxID_OK
)
638 wxFontData retData
= dialog
.GetFontData();
639 m_canvas
->SetFont(retData
.GetChosenFont());
640 m_canvas
->SetForegroundColour(retData
.GetColour());
643 //else: cancelled by the user, don't change the font
645 #endif // wxUSE_FONTDLG
647 #if USE_FONTDLG_GENERIC
648 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
651 data
.SetInitialFont(m_canvas
->GetFont());
652 data
.SetColour(m_canvas
->GetForegroundColour());
654 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
655 if (dialog
->ShowModal() == wxID_OK
)
657 wxFontData retData
= dialog
->GetFontData();
658 m_canvas
->SetFont(retData
.GetChosenFont());
659 m_canvas
->SetForegroundColour(retData
.GetColour());
664 #endif // USE_FONTDLG_GENERIC
667 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
669 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
670 // being flushed -- test it
673 wxLogMessage(wxT("This is some message - everything is ok so far."));
674 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
675 wxLogWarning(wxT("And then something went wrong!"));
677 // and if ~wxBusyCursor doesn't do it, then call it manually
681 wxLogError(wxT("Intermediary error handler decided to abort."));
682 wxLogError(wxT("The top level caller detected an unrecoverable error."));
684 wxLog::FlushActive();
686 wxLogMessage(wxT("And this is the same dialog but with only one message."));
688 #endif // wxUSE_LOG_DIALOG
692 void MyFrame::InfoBarSimple(wxCommandEvent
& WXUNUSED(event
))
694 static int s_count
= 0;
695 m_infoBarSimple
->ShowMessage
697 wxString::Format("Message #%d in the info bar.", ++s_count
)
701 void MyFrame::InfoBarAdvanced(wxCommandEvent
& WXUNUSED(event
))
703 m_infoBarAdvanced
->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING
);
706 #endif // wxUSE_INFOBAR
710 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
712 wxMessageDialog
dialog(this,
713 "This is a message box\n"
714 "This is a long, long string to test out if the message box "
715 "is laid out properly.",
718 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
722 if ( dialog
.SetYesNoCancelLabels
729 extmsg
= "This platform supports custom button labels,\n"
730 "so you should see the descriptive labels below.";
734 extmsg
= "Custom button labels are not supported on this platform,\n"
735 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
737 dialog
.SetExtendedMessage(extmsg
);
739 switch ( dialog
.ShowModal() )
742 wxLogStatus(wxT("You pressed \"Yes\""));
746 wxLogStatus(wxT("You pressed \"No\""));
750 wxLogStatus(wxT("You pressed \"Cancel\""));
754 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
758 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
760 TestMessageBoxDialog
dlg(this);
764 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
766 ::wxInfoMessageBox(this);
768 #endif // wxUSE_MSGDLG
771 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
773 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
774 wxT("Even two rows of text."),
775 wxT("Enter a number:"), wxT("Numeric input test"),
782 msg
= wxT("Invalid number entered or dialog cancelled.");
787 msg
.Printf(wxT("You've entered %lu"), res
);
788 icon
= wxICON_INFORMATION
;
791 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
793 #endif // wxUSE_NUMBERDLG
796 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
798 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
799 wxT("Password entry dialog"),
804 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
805 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
809 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
811 wxTextEntryDialog
dialog(this,
812 wxT("This is a small sample\n")
813 wxT("A long, long string to test out the text entrybox"),
814 wxT("Please enter a string"),
815 wxT("Default value"),
818 if (dialog
.ShowModal() == wxID_OK
)
820 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
823 #endif // wxUSE_TEXTDLG
826 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
828 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
830 wxSingleChoiceDialog
dialog(this,
831 wxT("This is a small sample\n")
832 wxT("A single-choice convenience dialog"),
833 wxT("Please select a value"),
834 WXSIZEOF(choices
), choices
);
836 dialog
.SetSelection(2);
838 if (dialog
.ShowModal() == wxID_OK
)
840 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
845 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
847 const wxString choices
[] =
849 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
850 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
851 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
854 wxArrayInt selections
;
855 const int count
= wxGetSelectedChoices(selections
,
856 wxT("This is a small sample\n")
857 wxT("A multi-choice convenience dialog"),
858 wxT("Please select a value"),
859 WXSIZEOF(choices
), choices
,
866 msg
= wxT("You did not select any items");
870 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
871 for ( int n
= 0; n
< count
; n
++ )
873 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
874 (unsigned)n
, (unsigned)selections
[n
],
875 choices
[selections
[n
]].c_str());
882 #endif // wxUSE_CHOICEDLG
884 #if wxUSE_REARRANGECTRL
885 // custom rearrange dialog: it adds the possibility to rename an item to the
886 // base class functionality
887 class MyRearrangeDialog
: public wxRearrangeDialog
890 MyRearrangeDialog(wxWindow
*parent
,
892 wxArrayString
& labels
,
893 wxArrayString
& labelsOrig
)
897 "Configure the columns shown:",
898 "wxRearrangeDialog example",
904 m_labelsOrig(labelsOrig
)
908 wxPanel
* const panel
= new wxPanel(this);
909 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
911 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
912 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
914 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
915 wxDefaultPosition
, wxDefaultSize
,
917 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
919 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
920 wxSizerFlags().Centre());
922 panel
->SetSizer(sizer
);
924 // call this first to ensure that the controls have a reasonable best
925 // size before they're added
926 DoUpdateExtraControls(GetList()->GetSelection());
928 AddExtraControls(panel
);
931 // another customization not directly supported by the dialog: add a
933 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
934 wxCHECK_RET( btnOk
, "no Ok button?" );
936 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
937 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
939 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
940 wxSizerFlags().Border(wxLEFT
));
943 // call this instead of ShowModal() to update order and labels array in
944 // case the dialog was not cancelled
947 switch ( ShowModal() )
953 m_order
= GetOrder();
957 // order already reset
965 void OnSelChange(wxCommandEvent
& event
)
967 DoUpdateExtraControls(event
.GetInt());
970 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
972 event
.Enable( CanRename() );
975 void OnRename(wxCommandEvent
& WXUNUSED(event
))
980 m_labels
[m_sel
] = m_text
->GetValue();
981 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
984 void OnReset(wxCommandEvent
& WXUNUSED(event
))
986 // in a real program we should probably ask if the user really wants to
987 // do this but here we just go ahead and reset all columns labels and
988 // their order without confirmation
989 const unsigned count
= m_order
.size();
990 for ( unsigned n
= 0; n
< count
; n
++ )
993 m_labels
[n
] = m_labelsOrig
[n
];
996 EndModal(wxID_RESET
);
999 bool CanRename() const
1001 // only allow renaming if the user modified the currently selected item
1002 // text (which presupposes that we do have a current item)
1003 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
1006 void DoUpdateExtraControls(int sel
)
1010 if ( m_sel
== wxNOT_FOUND
)
1012 m_labelOrig
->SetLabel("<no selection>");
1016 else // have valid item
1018 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
1020 m_text
->SetValue(m_labels
[m_sel
]);
1024 wxArrayInt
& m_order
;
1025 wxArrayString
& m_labels
,
1029 wxStaticText
*m_labelOrig
;
1032 DECLARE_EVENT_TABLE()
1033 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
1036 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
1037 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
1039 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
1041 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
1042 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
1043 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
1046 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
1048 // the arrays are static so that we preserve the items order between calls
1050 static wxArrayInt s_order
;
1051 static wxArrayString s_labels
,
1054 // initialize them on the first call
1055 if ( s_labelsOrig
.empty() )
1057 static const struct ItemInfo
1060 const char *labelOrig
;
1064 { "File name", "Name", 0 },
1065 { "File type", "Ext", 1 },
1066 { "Size", "Size", 2 },
1067 { "Creation time", "Ctime", ~3 }, // negated so hidden
1068 { "Last accessed", "Atime", ~4 },
1069 { "Last modified", "Mtime", 5 },
1072 s_order
.reserve(WXSIZEOF(items
));
1073 s_labels
.reserve(WXSIZEOF(items
));
1074 s_labelsOrig
.reserve(WXSIZEOF(items
));
1075 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1077 const ItemInfo
& item
= items
[n
];
1078 s_order
.push_back(item
.order
);
1079 s_labels
.push_back(item
.label
);
1080 s_labelsOrig
.push_back(item
.labelOrig
);
1084 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1085 if ( !dlg
.Rearrange() )
1089 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1091 columns
+= wxString::Format("\n %u: ", n
);
1092 int idx
= s_order
[n
];
1095 columns
+= "[hidden] ";
1099 columns
+= s_labels
[idx
];
1100 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1102 columns
+= wxString::Format(" (original label: \"%s\")",
1107 wxLogMessage("The columns order now is:%s", columns
);
1109 #endif // wxUSE_REARRANGECTRL
1113 // panel with custom controls for file dialog
1114 class MyExtraPanel
: public wxPanel
1117 MyExtraPanel(wxWindow
*parent
);
1118 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1119 wxString
GetInfo() const
1121 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1128 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1131 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1132 m_btn
->Enable(false);
1133 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1134 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1135 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1136 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1137 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1138 sizerTop
->AddStretchSpacer();
1139 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1140 SetSizerAndFit(sizerTop
);
1143 // a static method can be used instead of a function with most of compilers
1144 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1146 return new MyExtraPanel(parent
);
1149 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1154 wxT("Testing open file dialog"),
1158 wxT("C++ files (*.cpp)|*.cpp")
1160 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1164 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1165 dialog
.CentreOnParent();
1166 dialog
.SetDirectory(wxGetHomeDir());
1168 if (dialog
.ShowModal() == wxID_OK
)
1171 wxWindow
* const extra
= dialog
.GetExtraControl();
1172 info
.Printf(wxT("Full file name: %s\n")
1175 wxT("Custom window: %s"),
1176 dialog
.GetPath().c_str(),
1177 dialog
.GetDirectory().c_str(),
1178 dialog
.GetFilename().c_str(),
1179 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1180 : wxString("None"));
1181 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1182 dialog2
.ShowModal();
1186 // this shows how to take advantage of specifying a default extension in the
1187 // call to wxFileSelector: it is remembered after each new call and the next
1188 // one will use it by default
1189 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1191 static wxString s_extDef
;
1192 wxString path
= wxFileSelector(
1193 wxT("Select the file to load"),
1194 wxEmptyString
, wxEmptyString
,
1198 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1199 wxFileSelectorDefaultWildcardStr
,
1200 wxFileSelectorDefaultWildcardStr
1202 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1209 // it is just a sample, would use wxSplitPath in real program
1210 s_extDef
= path
.AfterLast(wxT('.'));
1212 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1216 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1218 wxString wildcards
=
1220 wxT("C++ files (*.cpp)|*.cpp");
1224 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1225 wxFileSelectorDefaultWildcardStr
,
1226 wxFileSelectorDefaultWildcardStr
1229 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1230 wxEmptyString
, wxEmptyString
, wildcards
,
1231 wxFD_OPEN
|wxFD_MULTIPLE
);
1233 if (dialog
.ShowModal() == wxID_OK
)
1235 wxArrayString paths
, filenames
;
1237 dialog
.GetPaths(paths
);
1238 dialog
.GetFilenames(filenames
);
1241 size_t count
= paths
.GetCount();
1242 for ( size_t n
= 0; n
< count
; n
++ )
1244 s
.Printf(wxT("File %d: %s (%s)\n"),
1245 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1249 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1252 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1253 dialog2
.ShowModal();
1257 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1259 wxFileDialog
dialog(this,
1260 wxT("Testing save file dialog"),
1262 wxT("myletter.doc"),
1263 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1264 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1266 dialog
.SetFilterIndex(1);
1268 if (dialog
.ShowModal() == wxID_OK
)
1270 wxLogMessage(wxT("%s, filter %d"),
1271 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1274 #endif // wxUSE_FILEDLG
1276 #if USE_FILEDLG_GENERIC
1277 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1279 wxGenericFileDialog dialog
1282 wxT("Testing open file dialog"),
1285 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1288 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1289 dialog
.SetDirectory(wxGetHomeDir());
1291 if (dialog
.ShowModal() == wxID_OK
)
1294 info
.Printf(wxT("Full file name: %s\n")
1297 dialog
.GetPath().c_str(),
1298 dialog
.GetDirectory().c_str(),
1299 dialog
.GetFilename().c_str());
1300 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1301 dialog2
.ShowModal();
1305 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1307 // On PocketPC you can disable OK-only dialogs policy using system option
1308 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1309 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1311 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1312 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1313 wxEmptyString
, wxEmptyString
, wildcards
,
1316 if (dialog
.ShowModal() == wxID_OK
)
1318 wxArrayString paths
, filenames
;
1320 dialog
.GetPaths(paths
);
1321 dialog
.GetFilenames(filenames
);
1324 size_t count
= paths
.GetCount();
1325 for ( size_t n
= 0; n
< count
; n
++ )
1327 s
.Printf(wxT("File %d: %s (%s)\n"),
1328 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1332 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1335 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1336 dialog2
.ShowModal();
1339 // restore system option
1340 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1343 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1345 wxGenericFileDialog
dialog(this,
1346 wxT("Testing save file dialog"),
1348 wxT("myletter.doc"),
1349 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1350 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1352 dialog
.SetFilterIndex(1);
1354 if (dialog
.ShowModal() == wxID_OK
)
1356 wxLogMessage(wxT("%s, filter %d"),
1357 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1360 #endif // USE_FILEDLG_GENERIC
1363 void MyFrame::DoDirChoose(int style
)
1365 // pass some initial dir to wxDirDialog
1367 wxGetHomeDir(&dirHome
);
1369 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1371 if (dialog
.ShowModal() == wxID_OK
)
1373 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1377 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1379 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1382 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1384 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1386 #endif // wxUSE_DIRDLG
1388 #if USE_DIRDLG_GENERIC
1389 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1391 // pass some initial dir to wxDirDialog
1393 wxGetHomeDir(&dirHome
);
1395 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1397 if (dialog
.ShowModal() == wxID_OK
)
1399 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1400 dialog2
.ShowModal();
1403 #endif // USE_DIRDLG_GENERIC
1405 #if USE_MODAL_PRESENTATION
1406 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1408 MyModalDialog
dlg(this);
1411 #endif // USE_MODAL_PRESENTATION
1413 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1415 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1421 m_dialog
= new MyModelessDialog(this);
1424 m_dialog
->Show(true);
1428 // If m_dialog is NULL, then possibly the system
1429 // didn't report the checked menu item status correctly.
1430 // It should be true just after the menu item was selected,
1431 // if there was no modeless dialog yet.
1433 wxASSERT( m_dialog
!= NULL
);
1439 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1441 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1442 wxDefaultPosition
, wxSize(200, 100));
1443 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1444 dlg
.CentreOnScreen();
1448 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1450 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1451 wxDefaultPosition
, wxSize(200, 100));
1452 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1453 dlg
.CentreOnParent();
1458 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1460 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1461 wxDefaultPosition
, wxSize(300, 100),
1462 wxCAPTION
| wxCLOSE_BOX
);
1463 new wxStaticText(frame
,
1465 wxT("Mini frames have slightly different appearance"),
1467 new wxStaticText(frame
,
1469 wxT("from the normal frames but that's the only difference."),
1472 frame
->CentreOnParent();
1475 #endif // wxUSE_MINIFRAME
1477 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1479 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1480 wxDefaultPosition
, wxSize(300, 100),
1481 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1482 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1486 #if wxUSE_STARTUP_TIPS
1487 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1489 static size_t s_index
= (size_t)-1;
1491 if ( s_index
== (size_t)-1 )
1495 // this is completely bogus, we don't know how many lines are there
1496 // in the file, but who cares, it's a demo only...
1497 s_index
= rand() % 5;
1500 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1502 bool showAtStartup
= wxShowTip(this, tipProvider
);
1504 if ( showAtStartup
)
1506 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1507 wxOK
| wxICON_INFORMATION
, this);
1510 s_index
= tipProvider
->GetCurrentTip();
1513 #endif // wxUSE_STARTUP_TIPS
1515 #if USE_SETTINGS_DIALOG
1516 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1518 SettingsDialog
dialog(this, event
.GetId());
1521 #endif // USE_SETTINGS_DIALOG
1523 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1525 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1529 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1532 #if wxUSE_NOTIFICATION_MESSAGE
1534 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1536 if ( !wxNotificationMessage
1538 "Automatic Notification",
1539 "Nothing important has happened\n"
1540 "this notification will disappear soon."
1543 wxLogStatus("Failed to show notification message");
1547 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1551 m_notifMsg
= new wxNotificationMessage
1553 "wxWidgets Manual Notification",
1554 "You can hide this notification from the menu",
1559 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1561 wxLogStatus("Failed to show manual notification message");
1565 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1567 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1569 wxLogStatus("Failed to hide manual notification message");
1573 #endif // wxUSE_NOTIFICATION_MESSAGE
1575 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1577 StdButtonSizerDialog
dialog(this);
1581 // TestDefaultAction
1583 #define ID_CATCH_LISTBOX_DCLICK 100
1584 #define ID_LISTBOX 101
1586 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1587 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1588 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1591 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1592 wxDialog( parent
, -1, "Test default action" )
1594 m_catchListBoxDClick
= false;
1596 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1598 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1601 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1602 listbox
->Append( "String 1" );
1603 listbox
->Append( "String 2" );
1604 listbox
->Append( "String 3" );
1605 listbox
->Append( "String 4" );
1606 grid_sizer
->Add( listbox
);
1607 #endif // wxUSE_LISTBOX
1609 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1611 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1612 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1614 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1615 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1617 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1619 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1621 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1623 SetSizerAndFit( main_sizer
);
1626 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1628 event
.Skip( !m_catchListBoxDClick
);
1631 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1633 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1636 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1638 TestDefaultActionDialog
dialog( this );
1642 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1647 #if wxUSE_PROGRESSDLG
1649 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1651 static const int max
= 100;
1653 wxProgressDialog
dialog(wxT("Progress dialog example"),
1654 wxT("An informative message"),
1660 // wxPD_AUTO_HIDE | -- try this as well
1662 wxPD_ESTIMATED_TIME
|
1664 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1668 for ( int i
= 0; i
<= max
; i
++ )
1674 // test both modes of wxProgressDialog behaviour: start in
1675 // indeterminate mode but switch to the determinate one later
1676 const bool determinate
= i
> max
/2;
1680 msg
= wxT("That's all, folks!");
1682 else if ( !determinate
)
1684 msg
= wxT("Testing indeterminate mode");
1686 else if ( determinate
)
1688 msg
= wxT("Now in standard determinate mode");
1691 // will be set to true if "Skip" button was pressed
1695 cont
= dialog
.Update(i
, msg
, &skip
);
1699 cont
= dialog
.Pulse(msg
, &skip
);
1702 // each skip will move progress about quarter forward
1708 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1709 wxT("Progress dialog question"), // caption
1710 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1720 wxLogStatus(wxT("Progress dialog aborted!"));
1724 wxLogStatus(wxT("Countdown from %d finished"), max
);
1728 #endif // wxUSE_PROGRESSDLG
1732 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1734 info
.SetName(wxT("Dialogs Sample"));
1735 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
1739 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
1740 wxVERSION_NUM_DOT_STRING
1742 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1743 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1744 info
.AddDeveloper(wxT("Vadim Zeitlin"));
1747 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1749 InitAboutInfoMinimal(info
);
1751 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
1754 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1756 InitAboutInfoWebsite(info
);
1758 // we can add a second developer
1759 info
.AddDeveloper(wxT("A.N. Other"));
1761 // or we can add several persons at once like this
1762 static const wxChar
*docwriters
[] =
1764 wxT("First D. Writer"),
1768 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1769 info
.SetLicence(wxString::FromAscii(
1770 " wxWindows Library Licence, Version 3.1\n"
1771 " ======================================\n"
1773 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1775 " Everyone is permitted to copy and distribute verbatim copies\n"
1776 " of this licence document, but changing it is not allowed.\n"
1778 " WXWINDOWS LIBRARY LICENCE\n"
1779 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1781 " ...and so on and so forth...\n"
1784 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
1787 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1789 wxAboutDialogInfo info
;
1790 InitAboutInfoMinimal(info
);
1792 wxAboutBox(info
, this);
1795 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1797 wxAboutDialogInfo info
;
1798 InitAboutInfoWebsite(info
);
1800 wxAboutBox(info
, this);
1803 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1805 wxAboutDialogInfo info
;
1806 InitAboutInfoAll(info
);
1808 wxAboutBox(info
, this);
1811 // a trivial example of a custom dialog class
1812 class MyAboutDialog
: public wxGenericAboutDialog
1815 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
1817 Create(info
, parent
);
1820 // add some custom controls
1821 virtual void DoAddCustomControls()
1823 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1824 AddText(wxT("Some custom text"));
1825 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1829 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1831 wxAboutDialogInfo info
;
1832 InitAboutInfoAll(info
);
1834 MyAboutDialog
dlg(info
, this);
1838 #endif // wxUSE_ABOUTDLG
1842 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1844 wxWindowDisabler disableAll
;
1846 wxBusyInfo
info(wxT("Working, please wait..."), this);
1848 for ( int i
= 0; i
< 18; i
++ )
1858 #endif // wxUSE_BUSYINFO
1860 #if wxUSE_FINDREPLDLG
1862 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1866 delete m_dlgReplace
;
1867 m_dlgReplace
= NULL
;
1871 m_dlgReplace
= new wxFindReplaceDialog
1875 wxT("Find and replace dialog"),
1879 m_dlgReplace
->Show(true);
1883 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1892 m_dlgFind
= new wxFindReplaceDialog
1901 m_dlgFind
->Show(true);
1905 static wxString
DecodeFindDialogEventFlags(int flags
)
1908 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
1909 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
1910 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
1911 << wxT("case sensitive");
1916 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1918 wxEventType type
= event
.GetEventType();
1920 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1922 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1923 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1924 event
.GetFindString().c_str(),
1925 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1927 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1928 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1930 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1931 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
1932 event
.GetFindString().c_str(),
1933 event
.GetReplaceString().c_str(),
1934 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1936 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1938 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1942 if ( dlg
== m_dlgFind
)
1945 idMenu
= DIALOGS_FIND
;
1948 else if ( dlg
== m_dlgReplace
)
1950 txt
= wxT("Replace");
1951 idMenu
= DIALOGS_REPLACE
;
1952 m_dlgReplace
= NULL
;
1956 txt
= wxT("Unknown");
1959 wxFAIL_MSG( wxT("unexpected event") );
1962 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1964 if ( idMenu
!= wxID_ANY
)
1966 GetMenuBar()->Check(idMenu
, false);
1973 wxLogError(wxT("Unknown find dialog event!"));
1977 #endif // wxUSE_FINDREPLDLG
1979 // ----------------------------------------------------------------------------
1981 // ----------------------------------------------------------------------------
1983 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1986 dc
.SetBackgroundMode(wxTRANSPARENT
);
1988 wxT("wxWidgets common dialogs")
1989 #if !defined(__SMARTPHONE__)
1990 wxT(" test application")
1995 #if USE_MODAL_PRESENTATION
1997 // ----------------------------------------------------------------------------
1999 // ----------------------------------------------------------------------------
2001 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
2002 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
2004 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
2006 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
2007 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
2010 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
2011 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
2013 SetSizerAndFit(sizerTop
);
2016 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
2018 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
2019 wxOK
| wxICON_INFORMATION
, this);
2022 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
2024 if ( event
.CanVeto() )
2026 wxMessageBox(wxT("Use the menu item to close this dialog"),
2027 wxT("Modeless dialog"),
2028 wxOK
| wxICON_INFORMATION
, this);
2034 // ----------------------------------------------------------------------------
2036 // ----------------------------------------------------------------------------
2038 MyModalDialog::MyModalDialog(wxWindow
*parent
)
2039 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
2041 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
2043 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2044 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2045 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2047 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2048 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2049 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2050 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2052 SetSizerAndFit(sizerTop
);
2054 SetEscapeId(wxID_CLOSE
);
2056 m_btnModal
->SetFocus();
2057 m_btnModal
->SetDefault();
2060 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2062 if ( event
.GetEventObject() == m_btnDelete
)
2067 m_btnDelete
->Disable();
2069 else if ( event
.GetEventObject() == m_btnModal
)
2072 wxGetTextFromUser(wxT("Dummy prompt"),
2073 wxT("Modal dialog called from dialog"),
2074 wxEmptyString
, this);
2076 wxMessageBox(wxT("Modal dialog called from dialog"));
2077 #endif // wxUSE_TEXTDLG
2079 else if ( event
.GetEventObject() == m_btnModeless
)
2081 (new MyModelessDialog(this))->Show();
2089 #endif // USE_MODAL_PRESENTATION
2091 // ----------------------------------------------------------------------------
2092 // StdButtonSizerDialog
2093 // ----------------------------------------------------------------------------
2095 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2096 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2097 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2098 m_buttonsSizer(NULL
)
2100 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2102 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2103 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2105 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2107 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2109 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2110 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2112 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2114 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2116 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2118 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2119 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2121 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2123 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2124 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2125 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2127 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2129 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2130 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2132 sizer
->Add(sizerInside1
, 0, 0, 0);
2133 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2134 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2135 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2137 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2138 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2140 sizer
->Add(sizerInside2
, 0, 0, 0);
2141 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2142 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2143 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2145 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2147 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2148 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2149 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2151 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2153 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2155 EnableDisableControls();
2157 SetSizerAndFit(sizerTop
);
2163 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2167 m_buttonsSizer
->DeleteWindows();
2168 GetSizer()->Remove(m_buttonsSizer
);
2171 EnableDisableControls();
2174 unsigned long numButtons
= 0;
2176 if (m_chkboxAffirmativeButton
->IsChecked())
2178 if (m_radiobtnOk
->GetValue())
2183 else if (m_radiobtnYes
->GetValue())
2190 if (m_chkboxDismissButton
->IsChecked())
2192 if (m_radiobtnCancel
->GetValue())
2198 else if (m_radiobtnClose
->GetValue())
2206 if (m_chkboxApply
->IsChecked())
2212 if (m_chkboxNo
->IsChecked())
2218 if (m_chkboxHelp
->IsChecked())
2224 if (m_chkboxNoDefault
->IsChecked())
2226 flags
|= wxNO_DEFAULT
;
2229 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2230 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2233 GetSizer()->SetSizeHints(this);
2236 void StdButtonSizerDialog::EnableDisableControls()
2238 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2240 m_radiobtnOk
->Enable(affButtonEnabled
);
2241 m_radiobtnYes
->Enable(affButtonEnabled
);
2243 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2245 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2246 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2249 #if USE_SETTINGS_DIALOG
2250 // ----------------------------------------------------------------------------
2252 // ----------------------------------------------------------------------------
2254 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2256 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2259 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2261 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2266 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2267 int resizeBorder
= wxRESIZE_BORDER
;
2275 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2276 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2277 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2279 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2281 SetSheetStyle(sheetStyle
);
2282 SetSheetInnerBorder(0);
2283 SetSheetOuterBorder(0);
2285 // create a dummy image list with a few icons
2286 const wxSize
imageSize(32, 32);
2288 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2290 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2292 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2294 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2296 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2301 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2302 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2305 // If using a toolbook, also follow Mac style and don't create buttons
2307 CreateButtons(wxOK
| wxCANCEL
|
2308 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2311 wxBookCtrlBase
* notebook
= GetBookCtrl();
2312 notebook
->SetImageList(m_imageList
);
2314 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2315 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2317 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2318 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2323 SettingsDialog::~SettingsDialog()
2328 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2330 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2332 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2333 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2337 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2338 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2339 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2340 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2344 wxString autoSaveLabel
= _("&Auto-save every");
2345 wxString minsLabel
= _("mins");
2347 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2348 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2351 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2352 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2355 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2357 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2359 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2360 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2364 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2365 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2366 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2367 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2369 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2371 panel
->SetSizerAndFit(topSizer
);
2376 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2378 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2380 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2381 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2383 //// PROJECT OR GLOBAL
2384 wxString globalOrProjectChoices
[2];
2385 globalOrProjectChoices
[0] = _("&New projects");
2386 globalOrProjectChoices
[1] = _("&This project");
2388 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2389 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2390 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2392 projectOrGlobal
->SetSelection(0);
2394 //// BACKGROUND STYLE
2395 wxArrayString backgroundStyleChoices
;
2396 backgroundStyleChoices
.Add(wxT("Colour"));
2397 backgroundStyleChoices
.Add(wxT("Image"));
2398 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2400 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2401 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2403 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2405 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2407 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2408 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2409 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2411 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2414 //// FONT SIZE SELECTION
2416 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2417 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2419 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2420 wxSize(80, wxDefaultCoord
));
2421 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2423 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2426 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2427 topSizer
->AddSpacer(5);
2429 panel
->SetSizerAndFit(topSizer
);
2434 // ----------------------------------------------------------------------------
2435 // TestMessageBoxDialog
2436 // ----------------------------------------------------------------------------
2439 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2444 { wxCANCEL
, "&Cancel" },
2447 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2448 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2449 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2452 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2453 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2454 wxDefaultPosition
, wxDefaultSize
,
2455 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2457 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2459 // this sizer allows to configure the messages shown in the message box
2461 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2462 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2463 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2464 wxDefaultPosition
, wxDefaultSize
,
2466 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2468 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2469 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2470 wxDefaultPosition
, wxDefaultSize
,
2472 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2474 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2477 // this one is for configuring the buttons
2478 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2479 sizerBtns
->AddGrowableCol(1);
2481 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2482 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2484 for ( int n
= 0; n
< Btn_Max
; n
++ )
2486 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2487 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2489 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2490 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2492 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2493 wxUpdateUIEventHandler(
2494 TestMessageBoxDialog::OnUpdateLabelUI
),
2500 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2501 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2502 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2506 const wxString icons
[] = {
2507 "&None", "&Information", "&Question", "&Warning", "&Error"
2510 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icons",
2511 wxDefaultPosition
, wxDefaultSize
,
2512 WXSIZEOF(icons
), icons
);
2513 // Make the 'Information' icon the default one:
2514 m_icons
->SetSelection(1);
2515 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2518 // miscellaneous other stuff
2520 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2522 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2523 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2524 wxUpdateUIEventHandler(
2525 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2528 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2530 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2531 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2533 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2535 // finally buttons to show the resulting message box and close this dialog
2536 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2537 wxSizerFlags().Right().Border());
2539 SetSizerAndFit(sizerTop
);
2541 m_buttons
[Btn_Ok
]->SetValue(true);
2544 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2546 for ( int n
= 0; n
< Btn_Max
; n
++ )
2548 if ( event
.GetEventObject() == m_labels
[n
] )
2550 event
.Enable( m_buttons
[n
]->IsChecked() );
2555 wxFAIL_MSG( "called for unknown label" );
2558 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2560 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2563 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2567 for ( int n
= 0; n
< Btn_Max
; n
++ )
2569 if ( m_buttons
[n
]->IsChecked() )
2570 style
|= ms_btnInfo
[n
].flag
;
2573 switch ( m_icons
->GetSelection() )
2575 case 0: style
|= wxICON_NONE
; break;
2576 case 1: style
|= wxICON_INFORMATION
; break;
2577 case 2: style
|= wxICON_QUESTION
; break;
2578 case 3: style
|= wxICON_WARNING
; break;
2579 case 4: style
|= wxICON_ERROR
; break;
2582 if ( m_chkCentre
->IsChecked() )
2585 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2586 style
|= wxNO_DEFAULT
;
2589 wxMessageDialog
dlg(this, m_textMsg
->GetValue(), "Test Message Box",
2591 if ( !m_textExtMsg
->IsEmpty() )
2592 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2594 if ( style
& wxYES_NO
)
2596 if ( style
& wxCANCEL
)
2598 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2599 m_labels
[Btn_No
]->GetValue(),
2600 m_labels
[Btn_Cancel
]->GetValue());
2604 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2605 m_labels
[Btn_No
]->GetValue());
2610 if ( style
& wxCANCEL
)
2612 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2613 m_labels
[Btn_Cancel
]->GetValue());
2617 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2624 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2626 EndModal(wxID_CANCEL
);
2629 #endif // USE_SETTINGS_DIALOG
2633 // ----------------------------------------------------------------------------
2634 // custom log target
2635 // ----------------------------------------------------------------------------
2637 class MyLogGui
: public wxLogGui
2640 virtual void DoShowSingleLogMessage(const wxString
& message
,
2641 const wxString
& title
,
2644 wxMessageDialog
dlg(NULL
, message
, title
,
2645 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2646 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2647 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2652 wxLog
*MyAppTraits::CreateLogTarget()
2654 return new MyLogGui
;