1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
7 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
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/richmsgdlg.h"
38 #endif // wxUSE_RICHMSGDLG
41 #include "wx/colordlg.h"
42 #endif // wxUSE_COLOURDLG
45 #include "wx/choicdlg.h"
46 #endif // wxUSE_CHOICEDLG
48 #include "wx/rearrangectrl.h"
50 #if wxUSE_STARTUP_TIPS
51 #include "wx/tipdlg.h"
52 #endif // wxUSE_STARTUP_TIPS
55 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
56 #include "wx/datetime.h" // wxDateTime
59 #include "wx/progdlg.h"
60 #endif // wxUSE_PROGRESSDLG
63 #include "wx/aboutdlg.h"
65 // these headers are only needed for custom about dialog
66 #include "wx/statline.h"
67 #include "wx/generic/aboutdlgg.h"
68 #endif // wxUSE_ABOUTDLG
71 #include "wx/busyinfo.h"
72 #endif // wxUSE_BUSYINFO
75 #include "wx/numdlg.h"
76 #endif // wxUSE_NUMBERDLG
79 #include "wx/filedlg.h"
80 #endif // wxUSE_FILEDLG
83 #include "wx/dirdlg.h"
84 #endif // wxUSE_DIRDLG
87 #include "wx/fontdlg.h"
88 #endif // wxUSE_FONTDLG
91 #include "wx/fdrepdlg.h"
92 #endif // wxUSE_FINDREPLDLG
95 #include "wx/infobar.h"
96 #endif // wxUSE_INFOBAR
98 #include "wx/spinctrl.h"
99 #include "wx/propdlg.h"
103 #if USE_COLOURDLG_GENERIC
104 #include "wx/generic/colrdlgg.h"
105 #endif // USE_COLOURDLG_GENERIC
107 #if USE_DIRDLG_GENERIC
108 #include "wx/generic/dirdlgg.h"
109 #endif // USE_DIRDLG_GENERIC
111 #if USE_FILEDLG_GENERIC
112 #include "wx/generic/filedlgg.h"
113 #endif // USE_FILEDLG_GENERIC
115 #if USE_FONTDLG_GENERIC
116 #include "wx/generic/fontdlgg.h"
117 #endif // USE_FONTDLG_GENERIC
121 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
122 EVT_PAINT(MyCanvas::OnPaint
)
127 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
129 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
130 EVT_MENU(DIALOGS_MESSAGE_BOX_WINDOW_MODAL
, MyFrame::MessageBoxWindowModal
)
131 EVT_MENU(DIALOGS_MESSAGE_DIALOG
, MyFrame::MessageBoxDialog
)
132 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
133 #endif // wxUSE_MSGDLG
135 EVT_MENU(DIALOGS_RICH_MESSAGE_DIALOG
, MyFrame::RichMessageDialog
)
136 #endif // wxUSE_RICHMSGDLG
138 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
139 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
140 #endif // wxUSE_COLOURDLG
143 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
144 #endif // wxUSE_FONTDLG
147 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
148 #endif // wxUSE_LOG_DIALOG
150 EVT_MENU(DIALOGS_INFOBAR_SIMPLE
, MyFrame::InfoBarSimple
)
151 EVT_MENU(DIALOGS_INFOBAR_ADVANCED
, MyFrame::InfoBarAdvanced
)
152 #endif // wxUSE_INFOBAR
155 EVT_MENU(DIALOGS_LINE_ENTRY
, MyFrame::LineEntry
)
156 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
157 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
158 #endif // wxUSE_TEXTDLG
161 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
162 #endif // wxUSE_NUMBERDLG
165 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
166 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
167 #endif // wxUSE_CHOICEDLG
169 #if wxUSE_REARRANGECTRL
170 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
171 #endif // wxUSE_REARRANGECTRL
174 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
175 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
176 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
177 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
178 #endif // wxUSE_FILEDLG
180 #if USE_FILEDLG_GENERIC
181 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
182 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
183 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
184 #endif // USE_FILEDLG_GENERIC
187 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
188 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
189 #endif // wxUSE_DIRDLG
191 #if USE_MODAL_PRESENTATION
192 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
193 #endif // USE_MODAL_PRESENTATION
194 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
195 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
196 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
198 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
199 #endif // wxUSE_MINIFRAME
200 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
202 #if wxUSE_STARTUP_TIPS
203 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
204 #endif // wxUSE_STARTUP_TIPS
206 #if USE_FONTDLG_GENERIC
207 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
208 #endif // USE_FONTDLG_GENERIC
210 #if USE_DIRDLG_GENERIC
211 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
212 #endif // wxMSW || wxMAC
214 #if USE_COLOURDLG_GENERIC
215 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
216 #endif // USE_COLOURDLG_GENERIC
218 #if wxUSE_PROGRESSDLG
219 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
220 #endif // wxUSE_PROGRESSDLG
223 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
224 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
225 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
226 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
227 #endif // wxUSE_ABOUTDLG
230 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
231 #endif // wxUSE_BUSYINFO
233 #if wxUSE_FINDREPLDLG
234 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
235 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
237 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
238 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
239 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
240 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
241 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
242 #endif // wxUSE_FINDREPLDLG
244 #if USE_SETTINGS_DIALOG
245 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
246 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
247 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
248 #endif // USE_SETTINGS_DIALOG
250 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
251 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
253 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
254 #if wxUSE_NOTIFICATION_MESSAGE
255 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
256 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
257 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
258 #endif // wxUSE_NOTIFICATION_MESSAGE
260 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
263 #if USE_MODAL_PRESENTATION
265 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
266 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
269 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
270 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
271 EVT_CLOSE(MyModelessDialog::OnClose
)
274 #endif // USE_MODAL_PRESENTATION
276 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
277 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
278 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
281 #if wxUSE_CMDLINE_PARSER
283 #include "wx/cmdline.h"
285 static const char *PROGRESS_SWITCH
= "progress";
287 void MyApp::OnInitCmdLine(wxCmdLineParser
& parser
)
289 wxApp::OnInitCmdLine(parser
);
291 parser
.AddOption("", PROGRESS_SWITCH
,
292 "Style for the startup progress dialog (wxPD_XXX)",
293 wxCMD_LINE_VAL_NUMBER
);
296 bool MyApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
298 if ( !wxApp::OnCmdLineParsed(parser
) )
301 parser
.Found(PROGRESS_SWITCH
, &m_startupProgressStyle
);
306 #endif // wxUSE_CMDLINE_PARSER
308 // `Main program' equivalent, creating windows and returning main app frame
311 if ( !wxApp::OnInit() )
314 #if wxUSE_PROGRESSDLG
315 if ( m_startupProgressStyle
!= -1 )
317 // Show a test progress dialog before the main event loop is started:
318 // it should still work.
319 const int PROGRESS_COUNT
= 100;
322 "Progress in progress",
323 "Please wait, starting...",
326 m_startupProgressStyle
328 for ( int i
= 0; i
<= PROGRESS_COUNT
; i
++ )
330 if ( !dlg
.Update(i
) )
336 #endif // wxUSE_PROGRESSDLG
339 wxInitAllImageHandlers();
342 // Create the main frame window
343 MyFrame
*frame
= new MyFrame(wxT("wxWidgets dialogs example"));
346 wxMenu
*menuDlg
= new wxMenu
;
348 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
349 menuDlg
->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL
, wxT("Window-Modal Message box "));
350 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
352 menuDlg
->Append(DIALOGS_RICH_MESSAGE_DIALOG
, wxT("Rich message dialog"));
353 #endif // wxUSE_RICHMSGDLG
356 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
358 wxMenu
*choices_menu
= new wxMenu
;
361 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
362 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
363 #endif // wxUSE_COLOURDLG
366 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
367 #endif // wxUSE_FONTDLG
370 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
371 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
372 #endif // wxUSE_CHOICEDLG
374 #if wxUSE_REARRANGECTRL
375 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
376 #endif // wxUSE_REARRANGECTRL
378 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
379 choices_menu
->AppendSeparator();
380 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
382 #if USE_COLOURDLG_GENERIC
383 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
384 #endif // USE_COLOURDLG_GENERIC
386 #if USE_FONTDLG_GENERIC
387 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
388 #endif // USE_FONTDLG_GENERIC
390 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
391 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
394 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
396 wxMenu
*entry_menu
= new wxMenu
;
399 entry_menu
->Append(DIALOGS_LINE_ENTRY
, wxT("Single line &entry\tCtrl-E"));
400 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Multi line text &entry\tShift-Ctrl-E"));
401 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
402 #endif // wxUSE_TEXTDLG
405 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
406 #endif // wxUSE_NUMBERDLG
408 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
410 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
415 wxMenu
*filedlg_menu
= new wxMenu
;
416 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
417 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
418 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
419 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
421 #if USE_FILEDLG_GENERIC
422 filedlg_menu
->AppendSeparator();
423 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
424 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
425 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
426 #endif // USE_FILEDLG_GENERIC
428 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
430 #endif // wxUSE_FILEDLG
433 wxMenu
*dir_menu
= new wxMenu
;
435 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
436 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
437 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
439 #if USE_DIRDLG_GENERIC
440 dir_menu
->AppendSeparator();
441 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
442 #endif // USE_DIRDLG_GENERIC
444 #endif // wxUSE_DIRDLG
447 #if wxUSE_STARTUP_TIPS || \
448 wxUSE_PROGRESSDLG || \
450 wxUSE_LOG_DIALOG || \
453 wxMenu
*info_menu
= new wxMenu
;
455 #if wxUSE_STARTUP_TIPS
456 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
457 #endif // wxUSE_STARTUP_TIPS
459 #if wxUSE_PROGRESSDLG
460 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
461 #endif // wxUSE_PROGRESSDLG
464 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
465 #endif // wxUSE_BUSYINFO
468 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
469 #endif // wxUSE_LOG_DIALOG
472 info_menu
->Append(DIALOGS_INFOBAR_SIMPLE
, "Simple &info bar\tCtrl-I");
473 info_menu
->Append(DIALOGS_INFOBAR_ADVANCED
, "&Advanced info bar\tShift-Ctrl-I");
474 #endif // wxUSE_INFOBAR
477 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
478 wxT("&wxWidgets information\tCtrl-W"));
479 #endif // wxUSE_MSGDLG
481 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
483 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
486 #if wxUSE_FINDREPLDLG
487 wxMenu
*find_menu
= new wxMenu
;
488 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
489 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
490 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
491 #endif // wxUSE_FINDREPLDLG
493 wxMenu
*dialogs_menu
= new wxMenu
;
494 #if USE_MODAL_PRESENTATION
495 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tShift-Ctrl-W"));
496 #endif // USE_MODAL_PRESENTATION
497 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tShift-Ctrl-Z"));
498 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
499 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
501 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
502 #endif // wxUSE_MINIFRAME
503 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
504 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
506 #if USE_SETTINGS_DIALOG
507 wxMenu
*sheet_menu
= new wxMenu
;
508 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
509 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
511 if (wxPlatformIs(wxPORT_MAC
))
512 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
515 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
518 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
519 #endif // USE_SETTINGS_DIALOG
521 wxMenu
*menuNotif
= new wxMenu
;
522 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
523 #if wxUSE_NOTIFICATION_MESSAGE
524 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
525 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
526 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
527 #endif // wxUSE_NOTIFICATION_MESSAGE
528 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
530 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
531 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
533 menuDlg
->AppendSeparator();
534 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
537 wxMenu
*menuHelp
= new wxMenu
;
538 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
539 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
540 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
541 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
542 #endif // wxUSE_ABOUTDLG
544 wxMenu
* editMenu
= new wxMenu
;
545 editMenu
->Append(wxID_UNDO
, _("&Undo\tCtrl+Z"));
546 editMenu
->Append(wxID_REDO
, _("&Redo\tCtrl+Y"));
547 editMenu
->AppendSeparator();
548 editMenu
->Append(wxID_CUT
, _("Cu&t\tCtrl+X"));
549 editMenu
->Append(wxID_COPY
, _("&Copy\tCtrl+C"));
550 editMenu
->Append(wxID_PASTE
, _("&Paste\tCtrl+V"));
551 editMenu
->Append(wxID_CLEAR
, _("&Delete"));
553 editMenu
->AppendSeparator();
554 editMenu
->Append(wxID_SELECTALL
, _("Select All\tCtrl+A"));
556 wxMenuBar
*menubar
= new wxMenuBar
;
557 menubar
->Append(menuDlg
, wxT("&Dialogs"));
559 menubar
->Append(editMenu
, wxT("&Edit"));
562 menubar
->Append(menuHelp
, wxT("&Help"));
563 #endif // wxUSE_ABOUTDLG
565 frame
->SetMenuBar(menubar
);
567 frame
->Centre(wxBOTH
);
573 // My frame constructor
574 MyFrame::MyFrame(const wxString
& title
)
575 : wxFrame(NULL
, wxID_ANY
, title
)
577 SetIcon(wxICON(sample
));
579 #if USE_MODAL_PRESENTATION
580 m_dialog
= (MyModelessDialog
*)NULL
;
581 #endif // USE_MODAL_PRESENTATION
583 #if wxUSE_FINDREPLDLG
589 m_clrData
.SetChooseFull(true);
590 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
592 unsigned char n
= i
*16;
593 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
595 #endif // wxUSE_COLOURDLG
597 #if wxUSE_NOTIFICATION_MESSAGE
599 #endif // wxUSE_NOTIFICATION_MESSAGE
603 #endif // wxUSE_STATUSBAR
605 m_canvas
= new MyCanvas(this);
608 // an info bar can be created very simply and used without any extra effort
609 m_infoBarSimple
= new wxInfoBar(this);
611 // or it can also be customized by
612 m_infoBarAdvanced
= new wxInfoBar(this);
614 // ... adding extra buttons (but more than two will usually be too many)
615 m_infoBarAdvanced
->AddButton(wxID_UNDO
);
616 m_infoBarAdvanced
->AddButton(wxID_REDO
);
618 m_infoBarAdvanced
->Connect(wxID_REDO
, wxEVT_COMMAND_BUTTON_CLICKED
,
619 wxCommandEventHandler(MyFrame::OnInfoBarRedo
),
623 // adding and removing a button immediately doesn't make sense here, of
624 // course, it's done just to show that it is possible
625 m_infoBarAdvanced
->AddButton(wxID_EXIT
);
626 m_infoBarAdvanced
->RemoveButton(wxID_EXIT
);
628 // ... changing the colours and/or fonts
629 m_infoBarAdvanced
->SetOwnBackgroundColour(0xc8ffff);
630 m_infoBarAdvanced
->SetFont(GetFont().Bold().Larger());
632 // ... and changing the effect (only does anything under MSW currently)
633 m_infoBarAdvanced
->SetShowHideEffects(wxSHOW_EFFECT_EXPAND
,
634 wxSHOW_EFFECT_EXPAND
);
635 m_infoBarAdvanced
->SetEffectDuration(1500);
638 // to use the info bars we need to use sizer for the window layout
639 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
640 sizer
->Add(m_infoBarSimple
, wxSizerFlags().Expand());
641 sizer
->Add(m_canvas
, wxSizerFlags(1).Expand());
642 sizer
->Add(m_infoBarAdvanced
, wxSizerFlags().Expand());
645 // final touch: under MSW the info bars are shown progressively and parts
646 // of the parent window can be seen during the process, so use the same
647 // background colour for our background as for the canvas window which
648 // covers our entire client area to avoid jarring colour jumps
649 SetOwnBackgroundColour(m_canvas
->GetBackgroundColour());
650 #endif // wxUSE_INFOBAR
655 #if wxUSE_NOTIFICATION_MESSAGE
657 #endif // wxUSE_NOTIFICATION_MESSAGE
662 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
664 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
666 wxColourDialog
dialog(this, &m_clrData
);
667 dialog
.SetTitle(_("Please choose the background colour"));
668 if ( dialog
.ShowModal() == wxID_OK
)
670 m_clrData
= dialog
.GetColourData();
671 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
672 m_canvas
->ClearBackground();
677 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
679 wxColour clr
= wxGetColourFromUser
682 m_canvas
->GetForegroundColour(),
683 "Please choose the foreground colour"
687 m_canvas
->SetForegroundColour(clr
);
690 //else: dialog cancelled by user
693 #endif // wxUSE_COLOURDLG
696 #if USE_COLOURDLG_GENERIC
697 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
699 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
701 //FIXME:TODO:This has no effect...
702 m_clrData
.SetChooseFull(true);
704 for (int i
= 0; i
< 16; i
++)
707 (unsigned char)(i
*16),
708 (unsigned char)(i
*16),
709 (unsigned char)(i
*16)
711 m_clrData
.SetCustomColour(i
, colour
);
714 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
715 if (dialog
->ShowModal() == wxID_OK
)
717 m_clrData
= dialog
->GetColourData();
718 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
719 m_canvas
->ClearBackground();
724 #endif // USE_COLOURDLG_GENERIC
727 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
730 data
.SetInitialFont(m_canvas
->GetFont());
731 data
.SetColour(m_canvas
->GetForegroundColour());
733 // you might also do this:
735 // wxFontDialog dialog;
736 // if ( !dialog.Create(this, data) { ... error ... }
738 wxFontDialog
dialog(this, data
);
740 if (dialog
.ShowModal() == wxID_OK
)
742 wxFontData retData
= dialog
.GetFontData();
743 m_canvas
->SetFont(retData
.GetChosenFont());
744 m_canvas
->SetForegroundColour(retData
.GetColour());
747 //else: cancelled by the user, don't change the font
749 #endif // wxUSE_FONTDLG
751 #if USE_FONTDLG_GENERIC
752 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
755 data
.SetInitialFont(m_canvas
->GetFont());
756 data
.SetColour(m_canvas
->GetForegroundColour());
758 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
759 if (dialog
->ShowModal() == wxID_OK
)
761 wxFontData retData
= dialog
->GetFontData();
762 m_canvas
->SetFont(retData
.GetChosenFont());
763 m_canvas
->SetForegroundColour(retData
.GetColour());
768 #endif // USE_FONTDLG_GENERIC
771 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
773 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
774 // being flushed -- test it
777 wxLogMessage(wxT("This is some message - everything is ok so far."));
778 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
779 wxLogWarning(wxT("And then something went wrong!"));
781 // and if ~wxBusyCursor doesn't do it, then call it manually
785 wxLogError(wxT("Intermediary error handler decided to abort."));
786 wxLogError(wxT("The top level caller detected an unrecoverable error."));
788 wxLog::FlushActive();
790 wxLogMessage(wxT("And this is the same dialog but with only one message."));
792 #endif // wxUSE_LOG_DIALOG
796 void MyFrame::InfoBarSimple(wxCommandEvent
& WXUNUSED(event
))
798 static int s_count
= 0;
799 m_infoBarSimple
->ShowMessage
801 wxString::Format("Message #%d in the info bar.", ++s_count
)
805 void MyFrame::InfoBarAdvanced(wxCommandEvent
& WXUNUSED(event
))
807 m_infoBarAdvanced
->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING
);
810 void MyFrame::OnInfoBarRedo(wxCommandEvent
& WXUNUSED(event
))
812 m_infoBarAdvanced
->ShowMessage("Still no, sorry again.", wxICON_ERROR
);
815 #endif // wxUSE_INFOBAR
819 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
821 wxMessageDialog
dialog(this,
822 "This is a message box\n"
823 "This is a long, long string to test out if the message box "
824 "is laid out properly.",
827 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
831 if ( dialog
.SetYesNoCancelLabels
838 extmsg
= "This platform supports custom button labels,\n"
839 "so you should see the descriptive labels below.";
843 extmsg
= "Custom button labels are not supported on this platform,\n"
844 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
846 dialog
.SetExtendedMessage(extmsg
);
848 switch ( dialog
.ShowModal() )
851 wxLogStatus(wxT("You pressed \"Yes\""));
855 wxLogStatus(wxT("You pressed \"No\""));
859 wxLogStatus(wxT("You pressed \"Cancel\""));
863 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
867 void MyFrame::MessageBoxWindowModal(wxCommandEvent
& WXUNUSED(event
))
869 wxMessageDialog
* dialog
= new wxMessageDialog(this,
870 "This is a message box\n"
871 "This is a long, long string to test out if the message box "
872 "is laid out properly.",
875 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
879 if ( dialog
->SetYesNoCancelLabels
886 extmsg
= "This platform supports custom button labels,\n"
887 "so you should see the descriptive labels below.";
891 extmsg
= "Custom button labels are not supported on this platform,\n"
892 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
894 dialog
->SetExtendedMessage(extmsg
);
895 dialog
->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed
), NULL
, this );
896 dialog
->ShowWindowModal();
899 void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
)
901 wxDialog
* dialog
= event
.GetDialog();
902 switch ( dialog
->GetReturnCode() )
905 wxLogStatus(wxT("You pressed \"Yes\""));
909 wxLogStatus(wxT("You pressed \"No\""));
913 wxLogStatus(wxT("You pressed \"Cancel\""));
917 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
922 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
924 TestMessageBoxDialog
dlg(this);
929 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
931 ::wxInfoMessageBox(this);
933 #endif // wxUSE_MSGDLG
936 void MyFrame::RichMessageDialog(wxCommandEvent
& WXUNUSED(event
))
938 TestRichMessageDialog
dlg(this);
942 #endif // wxUSE_RICHMSGDLG
945 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
947 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
948 wxT("Even two rows of text."),
949 wxT("Enter a number:"), wxT("Numeric input test"),
956 msg
= wxT("Invalid number entered or dialog cancelled.");
961 msg
.Printf(wxT("You've entered %lu"), res
);
962 icon
= wxICON_INFORMATION
;
965 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
967 #endif // wxUSE_NUMBERDLG
970 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
972 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
973 wxT("Password entry dialog"),
978 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
979 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
983 void MyFrame::LineEntry(wxCommandEvent
& WXUNUSED(event
))
985 wxTextEntryDialog
dialog(this,
986 wxT("This is a small sample\n")
987 wxT("A long, long string to test out the text entrybox"),
988 wxT("Please enter a string"),
989 wxT("Default value"),
992 if (dialog
.ShowModal() == wxID_OK
)
994 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
998 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
1000 wxTextEntryDialog
dialog(this, "You can enter a multiline string here.",
1001 "Please enter some text",
1002 "First line\nSecond one\nAnd another one too",
1003 wxOK
| wxCANCEL
| wxTE_MULTILINE
);
1005 if (dialog
.ShowModal() == wxID_OK
)
1007 wxMessageBox(dialog
.GetValue(), wxT("Got text"), wxOK
| wxICON_INFORMATION
, this);
1010 #endif // wxUSE_TEXTDLG
1013 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
1015 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
1017 wxSingleChoiceDialog
dialog(this,
1018 wxT("This is a small sample\n")
1019 wxT("A single-choice convenience dialog"),
1020 wxT("Please select a value"),
1021 WXSIZEOF(choices
), choices
);
1023 dialog
.SetSelection(2);
1025 if (dialog
.ShowModal() == wxID_OK
)
1027 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
1028 dialog2
.ShowModal();
1032 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
1034 const wxString choices
[] =
1036 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
1037 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
1038 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
1041 wxArrayInt selections
;
1042 const int count
= wxGetSelectedChoices(selections
,
1043 wxT("This is a small sample\n")
1044 wxT("A multi-choice convenience dialog"),
1045 wxT("Please select a value"),
1046 WXSIZEOF(choices
), choices
,
1053 msg
= wxT("You did not select any items");
1057 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
1058 for ( int n
= 0; n
< count
; n
++ )
1060 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
1061 (unsigned)n
, (unsigned)selections
[n
],
1062 choices
[selections
[n
]].c_str());
1069 #endif // wxUSE_CHOICEDLG
1071 #if wxUSE_REARRANGECTRL
1072 // custom rearrange dialog: it adds the possibility to rename an item to the
1073 // base class functionality
1074 class MyRearrangeDialog
: public wxRearrangeDialog
1077 MyRearrangeDialog(wxWindow
*parent
,
1079 wxArrayString
& labels
,
1080 wxArrayString
& labelsOrig
)
1084 "Configure the columns shown:",
1085 "wxRearrangeDialog example",
1091 m_labelsOrig(labelsOrig
)
1093 m_sel
= wxNOT_FOUND
;
1095 wxPanel
* const panel
= new wxPanel(this);
1096 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1098 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
1099 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
1101 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
1102 wxDefaultPosition
, wxDefaultSize
,
1103 wxTE_PROCESS_ENTER
);
1104 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
1106 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
1107 wxSizerFlags().Centre());
1109 panel
->SetSizer(sizer
);
1111 // call this first to ensure that the controls have a reasonable best
1112 // size before they're added
1113 DoUpdateExtraControls(GetList()->GetSelection());
1115 AddExtraControls(panel
);
1118 // another customization not directly supported by the dialog: add a
1120 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
1121 wxCHECK_RET( btnOk
, "no Ok button?" );
1123 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
1124 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
1126 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
1127 wxSizerFlags().Border(wxLEFT
));
1130 // call this instead of ShowModal() to update order and labels array in
1131 // case the dialog was not cancelled
1134 switch ( ShowModal() )
1140 m_order
= GetOrder();
1144 // order already reset
1152 void OnSelChange(wxCommandEvent
& event
)
1154 DoUpdateExtraControls(event
.GetInt());
1157 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
1159 event
.Enable( CanRename() );
1162 void OnRename(wxCommandEvent
& WXUNUSED(event
))
1167 m_labels
[m_sel
] = m_text
->GetValue();
1168 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
1171 void OnReset(wxCommandEvent
& WXUNUSED(event
))
1173 // in a real program we should probably ask if the user really wants to
1174 // do this but here we just go ahead and reset all columns labels and
1175 // their order without confirmation
1176 const unsigned count
= m_order
.size();
1177 for ( unsigned n
= 0; n
< count
; n
++ )
1180 m_labels
[n
] = m_labelsOrig
[n
];
1183 EndModal(wxID_RESET
);
1186 bool CanRename() const
1188 // only allow renaming if the user modified the currently selected item
1189 // text (which presupposes that we do have a current item)
1190 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
1193 void DoUpdateExtraControls(int sel
)
1197 if ( m_sel
== wxNOT_FOUND
)
1199 m_labelOrig
->SetLabel("<no selection>");
1203 else // have valid item
1205 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
1207 m_text
->SetValue(m_labels
[m_sel
]);
1211 wxArrayInt
& m_order
;
1212 wxArrayString
& m_labels
,
1216 wxStaticText
*m_labelOrig
;
1219 DECLARE_EVENT_TABLE()
1220 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
1223 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
1224 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
1226 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
1228 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
1229 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
1230 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
1233 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
1235 // the arrays are static so that we preserve the items order between calls
1237 static wxArrayInt s_order
;
1238 static wxArrayString s_labels
,
1241 // initialize them on the first call
1242 if ( s_labelsOrig
.empty() )
1244 static const struct ItemInfo
1247 const char *labelOrig
;
1251 { "File name", "Name", 0 },
1252 { "File type", "Ext", 1 },
1253 { "Size", "Size", 2 },
1254 { "Creation time", "Ctime", ~3 }, // negated so hidden
1255 { "Last accessed", "Atime", ~4 },
1256 { "Last modified", "Mtime", 5 },
1259 s_order
.reserve(WXSIZEOF(items
));
1260 s_labels
.reserve(WXSIZEOF(items
));
1261 s_labelsOrig
.reserve(WXSIZEOF(items
));
1262 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1264 const ItemInfo
& item
= items
[n
];
1265 s_order
.push_back(item
.order
);
1266 s_labels
.push_back(item
.label
);
1267 s_labelsOrig
.push_back(item
.labelOrig
);
1271 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1272 if ( !dlg
.Rearrange() )
1276 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1278 columns
+= wxString::Format("\n %u: ", n
);
1279 int idx
= s_order
[n
];
1282 columns
+= "[hidden] ";
1286 columns
+= s_labels
[idx
];
1287 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1289 columns
+= wxString::Format(" (original label: \"%s\")",
1294 wxLogMessage("The columns order now is:%s", columns
);
1296 #endif // wxUSE_REARRANGECTRL
1300 // panel with custom controls for file dialog
1301 class MyExtraPanel
: public wxPanel
1304 MyExtraPanel(wxWindow
*parent
);
1305 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1306 wxString
GetInfo() const
1308 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1315 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1318 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1319 m_btn
->Enable(false);
1320 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1321 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1322 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1323 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1324 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1325 sizerTop
->AddStretchSpacer();
1326 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1327 SetSizerAndFit(sizerTop
);
1330 // a static method can be used instead of a function with most of compilers
1331 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1333 return new MyExtraPanel(parent
);
1336 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1341 wxT("Testing open file dialog"),
1345 wxT("C++ files (*.cpp)|*.cpp")
1347 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1351 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1352 dialog
.CentreOnParent();
1353 dialog
.SetDirectory(wxGetHomeDir());
1355 if (dialog
.ShowModal() == wxID_OK
)
1358 wxWindow
* const extra
= dialog
.GetExtraControl();
1359 info
.Printf(wxT("Full file name: %s\n")
1362 wxT("Custom window: %s"),
1363 dialog
.GetPath().c_str(),
1364 dialog
.GetDirectory().c_str(),
1365 dialog
.GetFilename().c_str(),
1366 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1367 : wxString("None"));
1368 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1369 dialog2
.ShowModal();
1373 // this shows how to take advantage of specifying a default extension in the
1374 // call to wxFileSelector: it is remembered after each new call and the next
1375 // one will use it by default
1376 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1378 static wxString s_extDef
;
1379 wxString path
= wxFileSelector(
1380 wxT("Select the file to load"),
1381 wxEmptyString
, wxEmptyString
,
1385 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1386 wxFileSelectorDefaultWildcardStr
,
1387 wxFileSelectorDefaultWildcardStr
1389 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1396 // it is just a sample, would use wxSplitPath in real program
1397 s_extDef
= path
.AfterLast(wxT('.'));
1399 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1403 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1405 wxString wildcards
=
1407 wxT("C++ files (*.cpp)|*.cpp");
1411 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1412 wxFileSelectorDefaultWildcardStr
,
1413 wxFileSelectorDefaultWildcardStr
1416 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1417 wxEmptyString
, wxEmptyString
, wildcards
,
1418 wxFD_OPEN
|wxFD_MULTIPLE
);
1420 if (dialog
.ShowModal() == wxID_OK
)
1422 wxArrayString paths
, filenames
;
1424 dialog
.GetPaths(paths
);
1425 dialog
.GetFilenames(filenames
);
1428 size_t count
= paths
.GetCount();
1429 for ( size_t n
= 0; n
< count
; n
++ )
1431 s
.Printf(wxT("File %d: %s (%s)\n"),
1432 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1436 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1439 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1440 dialog2
.ShowModal();
1444 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1446 wxFileDialog
dialog(this,
1447 wxT("Testing save file dialog"),
1449 wxT("myletter.doc"),
1450 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1451 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1453 dialog
.SetFilterIndex(1);
1455 if (dialog
.ShowModal() == wxID_OK
)
1457 wxLogMessage(wxT("%s, filter %d"),
1458 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1461 #endif // wxUSE_FILEDLG
1463 #if USE_FILEDLG_GENERIC
1464 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1466 wxGenericFileDialog dialog
1469 wxT("Testing open file dialog"),
1472 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1475 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1476 dialog
.SetDirectory(wxGetHomeDir());
1478 if (dialog
.ShowModal() == wxID_OK
)
1481 info
.Printf(wxT("Full file name: %s\n")
1484 dialog
.GetPath().c_str(),
1485 dialog
.GetDirectory().c_str(),
1486 dialog
.GetFilename().c_str());
1487 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1488 dialog2
.ShowModal();
1492 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1494 // On PocketPC you can disable OK-only dialogs policy using system option
1495 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1496 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1498 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1499 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1500 wxEmptyString
, wxEmptyString
, wildcards
,
1503 if (dialog
.ShowModal() == wxID_OK
)
1505 wxArrayString paths
, filenames
;
1507 dialog
.GetPaths(paths
);
1508 dialog
.GetFilenames(filenames
);
1511 size_t count
= paths
.GetCount();
1512 for ( size_t n
= 0; n
< count
; n
++ )
1514 s
.Printf(wxT("File %d: %s (%s)\n"),
1515 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1519 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1522 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1523 dialog2
.ShowModal();
1526 // restore system option
1527 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1530 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1532 wxGenericFileDialog
dialog(this,
1533 wxT("Testing save file dialog"),
1535 wxT("myletter.doc"),
1536 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1537 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1539 dialog
.SetFilterIndex(1);
1541 if (dialog
.ShowModal() == wxID_OK
)
1543 wxLogMessage(wxT("%s, filter %d"),
1544 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1547 #endif // USE_FILEDLG_GENERIC
1550 void MyFrame::DoDirChoose(int style
)
1552 // pass some initial dir to wxDirDialog
1554 wxGetHomeDir(&dirHome
);
1556 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1558 if (dialog
.ShowModal() == wxID_OK
)
1560 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1564 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1566 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1569 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1571 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1573 #endif // wxUSE_DIRDLG
1575 #if USE_DIRDLG_GENERIC
1576 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1578 // pass some initial dir to wxDirDialog
1580 wxGetHomeDir(&dirHome
);
1582 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1584 if (dialog
.ShowModal() == wxID_OK
)
1586 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1587 dialog2
.ShowModal();
1590 #endif // USE_DIRDLG_GENERIC
1592 #if USE_MODAL_PRESENTATION
1593 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1595 MyModalDialog
dlg(this);
1598 #endif // USE_MODAL_PRESENTATION
1600 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1602 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1608 m_dialog
= new MyModelessDialog(this);
1611 m_dialog
->Show(true);
1615 // If m_dialog is NULL, then possibly the system
1616 // didn't report the checked menu item status correctly.
1617 // It should be true just after the menu item was selected,
1618 // if there was no modeless dialog yet.
1620 wxASSERT( m_dialog
!= NULL
);
1626 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1628 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1629 wxDefaultPosition
, wxSize(200, 100));
1630 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1631 dlg
.CentreOnScreen();
1635 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1637 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1638 wxDefaultPosition
, wxSize(200, 100));
1639 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1640 dlg
.CentreOnParent();
1645 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1647 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1648 wxDefaultPosition
, wxSize(300, 100),
1649 wxCAPTION
| wxCLOSE_BOX
);
1650 new wxStaticText(frame
,
1652 wxT("Mini frames have slightly different appearance"),
1654 new wxStaticText(frame
,
1656 wxT("from the normal frames but that's the only difference."),
1659 frame
->CentreOnParent();
1662 #endif // wxUSE_MINIFRAME
1664 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1666 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1667 wxDefaultPosition
, wxSize(300, 100),
1668 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1669 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1673 #if wxUSE_STARTUP_TIPS
1674 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1676 static size_t s_index
= (size_t)-1;
1678 if ( s_index
== (size_t)-1 )
1682 // this is completely bogus, we don't know how many lines are there
1683 // in the file, but who cares, it's a demo only...
1684 s_index
= rand() % 5;
1687 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1689 bool showAtStartup
= wxShowTip(this, tipProvider
);
1691 if ( showAtStartup
)
1693 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1694 wxOK
| wxICON_INFORMATION
, this);
1697 s_index
= tipProvider
->GetCurrentTip();
1700 #endif // wxUSE_STARTUP_TIPS
1702 #if USE_SETTINGS_DIALOG
1703 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1705 SettingsDialog
dialog(this, event
.GetId());
1708 #endif // USE_SETTINGS_DIALOG
1710 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1712 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1716 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1719 #if wxUSE_NOTIFICATION_MESSAGE
1721 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1723 if ( !wxNotificationMessage
1725 "Automatic Notification",
1726 "Nothing important has happened\n"
1727 "this notification will disappear soon."
1730 wxLogStatus("Failed to show notification message");
1734 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1738 m_notifMsg
= new wxNotificationMessage
1740 "wxWidgets Manual Notification",
1741 "You can hide this notification from the menu",
1746 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1748 wxLogStatus("Failed to show manual notification message");
1752 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1754 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1756 wxLogStatus("Failed to hide manual notification message");
1760 #endif // wxUSE_NOTIFICATION_MESSAGE
1762 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1764 StdButtonSizerDialog
dialog(this);
1768 // TestDefaultAction
1770 #define ID_CATCH_LISTBOX_DCLICK 100
1771 #define ID_LISTBOX 101
1772 #define ID_DISABLE_OK 102
1773 #define ID_DISABLE_CANCEL 103
1775 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1776 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1777 EVT_CHECKBOX(ID_DISABLE_OK
, TestDefaultActionDialog::OnDisableOK
)
1778 EVT_CHECKBOX(ID_DISABLE_CANCEL
, TestDefaultActionDialog::OnDisableCancel
)
1779 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1780 EVT_TEXT_ENTER(wxID_ANY
, TestDefaultActionDialog::OnTextEnter
)
1783 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1784 wxDialog( parent
, -1, "Test default action" )
1786 m_catchListBoxDClick
= false;
1788 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1790 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1793 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1794 listbox
->Append( "String 1" );
1795 listbox
->Append( "String 2" );
1796 listbox
->Append( "String 3" );
1797 listbox
->Append( "String 4" );
1798 grid_sizer
->Add( listbox
);
1799 #endif // wxUSE_LISTBOX
1801 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1803 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1804 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1806 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1807 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1809 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_OK
, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL
);
1810 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_CANCEL
, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL
);
1812 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1814 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1816 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1818 SetSizerAndFit( main_sizer
);
1821 void TestDefaultActionDialog::OnDisableOK(wxCommandEvent
& event
)
1823 FindWindow(wxID_OK
)->Enable(!event
.IsChecked());
1826 void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent
& event
)
1828 FindWindow(wxID_CANCEL
)->Enable(!event
.IsChecked());
1831 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1833 event
.Skip( !m_catchListBoxDClick
);
1836 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1838 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1841 void TestDefaultActionDialog::OnTextEnter(wxCommandEvent
& event
)
1843 wxLogMessage("Text \"%s\" entered.", event
.GetString());
1846 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1848 TestDefaultActionDialog
dialog( this );
1852 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1857 #if wxUSE_PROGRESSDLG
1859 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1861 static const int max
= 100;
1863 wxProgressDialog
dialog("Progress dialog example",
1864 // "Reserve" enough space for the multiline
1865 // messages below, we'll change it anyhow
1866 // immediately in the loop below
1867 wxString(' ', 100) + "\n\n\n\n",
1873 //wxPD_AUTO_HIDE | // -- try this as well
1875 wxPD_ESTIMATED_TIME
|
1876 wxPD_REMAINING_TIME
|
1877 wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1881 for ( int i
= 0; i
<= max
; i
++ )
1885 // test both modes of wxProgressDialog behaviour: start in
1886 // indeterminate mode but switch to the determinate one later
1887 const bool determinate
= i
> max
/2;
1891 msg
= "That's all, folks!\n"
1893 "Nothing to see here any more.";
1895 else if ( !determinate
)
1897 msg
= "Testing indeterminate mode\n"
1899 "This mode allows you to show to the user\n"
1900 "that something is going on even if you don't know\n"
1901 "when exactly will you finish.";
1903 else if ( determinate
)
1905 msg
= "Now in standard determinate mode\n"
1907 "This is the standard usage mode in which you\n"
1908 "update the dialog after performing each new step of work.\n"
1909 "It requires knowing the total number of steps in advance.";
1912 // will be set to true if "Skip" button was pressed
1916 cont
= dialog
.Update(i
, msg
, &skip
);
1920 cont
= dialog
.Pulse(msg
, &skip
);
1923 // each skip will move progress about quarter forward
1934 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1935 wxT("Progress dialog question"), // caption
1936 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1948 wxLogStatus(wxT("Progress dialog aborted!"));
1952 wxLogStatus(wxT("Countdown from %d finished"), max
);
1956 #endif // wxUSE_PROGRESSDLG
1960 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1962 info
.SetName(wxT("Dialogs Sample"));
1963 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
1967 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
1968 wxVERSION_NUM_DOT_STRING
1970 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1971 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1972 info
.AddDeveloper(wxT("Vadim Zeitlin"));
1975 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1977 InitAboutInfoMinimal(info
);
1979 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
1982 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1984 InitAboutInfoWebsite(info
);
1986 // we can add a second developer
1987 info
.AddDeveloper(wxT("A.N. Other"));
1989 // or we can add several persons at once like this
1990 static const wxChar
*docwriters
[] =
1992 wxT("First D. Writer"),
1996 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1997 info
.SetLicence(wxString::FromAscii(
1998 " wxWindows Library Licence, Version 3.1\n"
1999 " ======================================\n"
2001 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
2003 " Everyone is permitted to copy and distribute verbatim copies\n"
2004 " of this licence document, but changing it is not allowed.\n"
2006 " WXWINDOWS LIBRARY LICENCE\n"
2007 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
2009 " ...and so on and so forth...\n"
2012 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
2015 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2017 wxAboutDialogInfo info
;
2018 InitAboutInfoMinimal(info
);
2020 wxAboutBox(info
, this);
2023 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2025 wxAboutDialogInfo info
;
2026 InitAboutInfoWebsite(info
);
2028 wxAboutBox(info
, this);
2031 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2033 wxAboutDialogInfo info
;
2034 InitAboutInfoAll(info
);
2036 wxAboutBox(info
, this);
2039 // a trivial example of a custom dialog class
2040 class MyAboutDialog
: public wxGenericAboutDialog
2043 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
2045 Create(info
, parent
);
2048 // add some custom controls
2049 virtual void DoAddCustomControls()
2051 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2052 AddText(wxT("Some custom text"));
2053 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2057 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2059 wxAboutDialogInfo info
;
2060 InitAboutInfoAll(info
);
2062 MyAboutDialog
dlg(info
, this);
2066 #endif // wxUSE_ABOUTDLG
2070 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
2072 wxWindowDisabler disableAll
;
2074 wxBusyInfo
info(wxT("Working, please wait..."), this);
2076 for ( int i
= 0; i
< 18; i
++ )
2086 #endif // wxUSE_BUSYINFO
2088 #if wxUSE_FINDREPLDLG
2090 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
2094 wxDELETE(m_dlgReplace
);
2098 m_dlgReplace
= new wxFindReplaceDialog
2102 wxT("Find and replace dialog"),
2106 m_dlgReplace
->Show(true);
2110 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
2114 wxDELETE(m_dlgFind
);
2118 m_dlgFind
= new wxFindReplaceDialog
2127 m_dlgFind
->Show(true);
2131 static wxString
DecodeFindDialogEventFlags(int flags
)
2134 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
2135 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
2136 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
2137 << wxT("case sensitive");
2142 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
2144 wxEventType type
= event
.GetEventType();
2146 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
2148 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
2149 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
2150 event
.GetFindString().c_str(),
2151 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2153 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
2154 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
2156 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
2157 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
2158 event
.GetFindString().c_str(),
2159 event
.GetReplaceString().c_str(),
2160 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2162 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
2164 wxFindReplaceDialog
*dlg
= event
.GetDialog();
2168 if ( dlg
== m_dlgFind
)
2171 idMenu
= DIALOGS_FIND
;
2174 else if ( dlg
== m_dlgReplace
)
2176 txt
= wxT("Replace");
2177 idMenu
= DIALOGS_REPLACE
;
2178 m_dlgReplace
= NULL
;
2182 txt
= wxT("Unknown");
2185 wxFAIL_MSG( wxT("unexpected event") );
2188 wxLogMessage(wxT("%s dialog is being closed."), txt
);
2190 if ( idMenu
!= wxID_ANY
)
2192 GetMenuBar()->Check(idMenu
, false);
2199 wxLogError(wxT("Unknown find dialog event!"));
2203 #endif // wxUSE_FINDREPLDLG
2205 // ----------------------------------------------------------------------------
2207 // ----------------------------------------------------------------------------
2209 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
2212 dc
.SetBackgroundMode(wxTRANSPARENT
);
2214 wxT("wxWidgets common dialogs")
2215 #if !defined(__SMARTPHONE__)
2216 wxT(" test application")
2221 #if USE_MODAL_PRESENTATION
2223 // ----------------------------------------------------------------------------
2225 // ----------------------------------------------------------------------------
2227 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
2228 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
2230 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
2232 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
2233 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
2236 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
2237 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
2239 SetSizerAndFit(sizerTop
);
2242 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
2244 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
2245 wxOK
| wxICON_INFORMATION
, this);
2248 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
2250 if ( event
.CanVeto() )
2252 wxMessageBox(wxT("Use the menu item to close this dialog"),
2253 wxT("Modeless dialog"),
2254 wxOK
| wxICON_INFORMATION
, this);
2260 // ----------------------------------------------------------------------------
2262 // ----------------------------------------------------------------------------
2264 MyModalDialog::MyModalDialog(wxWindow
*parent
)
2265 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
2267 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
2269 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2270 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2271 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2273 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2274 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2275 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2276 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2278 SetSizerAndFit(sizerTop
);
2280 SetEscapeId(wxID_CLOSE
);
2282 m_btnModal
->SetFocus();
2283 m_btnModal
->SetDefault();
2286 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2288 if ( event
.GetEventObject() == m_btnDelete
)
2290 wxDELETE(m_btnModal
);
2291 m_btnDelete
->Disable();
2293 else if ( event
.GetEventObject() == m_btnModal
)
2296 wxGetTextFromUser(wxT("Dummy prompt"),
2297 wxT("Modal dialog called from dialog"),
2298 wxEmptyString
, this);
2300 wxMessageBox(wxT("Modal dialog called from dialog"));
2301 #endif // wxUSE_TEXTDLG
2303 else if ( event
.GetEventObject() == m_btnModeless
)
2305 (new MyModelessDialog(this))->Show();
2313 #endif // USE_MODAL_PRESENTATION
2315 // ----------------------------------------------------------------------------
2316 // StdButtonSizerDialog
2317 // ----------------------------------------------------------------------------
2319 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2320 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2321 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2322 m_buttonsSizer(NULL
)
2324 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2326 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2327 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2329 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2331 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2333 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2334 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2336 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2338 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2340 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2342 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2343 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2345 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2347 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2348 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2349 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2351 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2353 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2354 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2356 sizer
->Add(sizerInside1
, 0, 0, 0);
2357 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2358 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2359 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2361 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2362 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2364 sizer
->Add(sizerInside2
, 0, 0, 0);
2365 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2366 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2367 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2369 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2371 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2372 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2373 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2375 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2377 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2379 EnableDisableControls();
2381 SetSizerAndFit(sizerTop
);
2387 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2391 m_buttonsSizer
->DeleteWindows();
2392 GetSizer()->Remove(m_buttonsSizer
);
2395 EnableDisableControls();
2398 unsigned long numButtons
= 0;
2400 if (m_chkboxAffirmativeButton
->IsChecked())
2402 if (m_radiobtnOk
->GetValue())
2407 else if (m_radiobtnYes
->GetValue())
2414 if (m_chkboxDismissButton
->IsChecked())
2416 if (m_radiobtnCancel
->GetValue())
2422 else if (m_radiobtnClose
->GetValue())
2430 if (m_chkboxApply
->IsChecked())
2436 if (m_chkboxNo
->IsChecked())
2442 if (m_chkboxHelp
->IsChecked())
2448 if (m_chkboxNoDefault
->IsChecked())
2450 flags
|= wxNO_DEFAULT
;
2453 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2454 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2457 GetSizer()->SetSizeHints(this);
2460 void StdButtonSizerDialog::EnableDisableControls()
2462 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2464 m_radiobtnOk
->Enable(affButtonEnabled
);
2465 m_radiobtnYes
->Enable(affButtonEnabled
);
2467 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2469 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2470 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2473 #if USE_SETTINGS_DIALOG
2474 // ----------------------------------------------------------------------------
2476 // ----------------------------------------------------------------------------
2478 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2480 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2483 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2485 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2490 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2491 int resizeBorder
= wxRESIZE_BORDER
;
2499 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2500 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2501 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2503 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2505 SetSheetStyle(sheetStyle
);
2506 SetSheetInnerBorder(0);
2507 SetSheetOuterBorder(0);
2509 // create a dummy image list with a few icons
2510 const wxSize
imageSize(32, 32);
2512 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2514 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2516 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2518 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2520 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2525 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2526 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2529 // If using a toolbook, also follow Mac style and don't create buttons
2531 CreateButtons(wxOK
| wxCANCEL
|
2532 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2535 wxBookCtrlBase
* notebook
= GetBookCtrl();
2536 notebook
->SetImageList(m_imageList
);
2538 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2539 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2541 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2542 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2547 SettingsDialog::~SettingsDialog()
2552 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2554 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2556 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2557 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2561 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2562 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2563 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2564 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2568 wxString autoSaveLabel
= _("&Auto-save every");
2569 wxString minsLabel
= _("mins");
2571 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2572 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2575 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2576 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2579 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2581 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2583 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2584 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2588 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2589 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2590 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2591 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2593 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2595 panel
->SetSizerAndFit(topSizer
);
2600 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2602 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2604 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2605 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2607 //// PROJECT OR GLOBAL
2608 wxString globalOrProjectChoices
[2];
2609 globalOrProjectChoices
[0] = _("&New projects");
2610 globalOrProjectChoices
[1] = _("&This project");
2612 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2613 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2614 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2616 projectOrGlobal
->SetSelection(0);
2618 //// BACKGROUND STYLE
2619 wxArrayString backgroundStyleChoices
;
2620 backgroundStyleChoices
.Add(wxT("Colour"));
2621 backgroundStyleChoices
.Add(wxT("Image"));
2622 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2624 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2625 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2627 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2629 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2631 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2632 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2633 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2635 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2638 //// FONT SIZE SELECTION
2640 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2641 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2643 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2644 wxSize(80, wxDefaultCoord
));
2645 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2647 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2650 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2651 topSizer
->AddSpacer(5);
2653 panel
->SetSizerAndFit(topSizer
);
2658 #endif // USE_SETTINGS_DIALOG
2661 // ----------------------------------------------------------------------------
2662 // TestMessageBoxDialog
2663 // ----------------------------------------------------------------------------
2666 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2671 { wxCANCEL
, "&Cancel" },
2674 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2675 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2676 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2679 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2680 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2681 wxDefaultPosition
, wxDefaultSize
,
2682 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2686 bool TestMessageBoxDialog::Create()
2688 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2690 // this sizer allows to configure the messages shown in the message box
2692 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2693 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2694 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2695 wxDefaultPosition
, wxDefaultSize
,
2697 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2699 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2700 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2701 wxDefaultPosition
, wxDefaultSize
,
2703 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2705 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2707 // if a derived class provides more message configurations, add these.
2708 AddAdditionalTextOptions(sizerTop
);
2710 // this one is for configuring the buttons
2712 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2714 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2715 sizerBtns
->AddGrowableCol(1);
2717 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2718 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2720 for ( int n
= 0; n
< Btn_Max
; n
++ )
2722 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2723 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2725 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2726 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2728 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2729 wxUpdateUIEventHandler(
2730 TestMessageBoxDialog::OnUpdateLabelUI
),
2735 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2736 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2740 const wxString icons
[] =
2744 "&Information icon",
2750 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == MsgDlgIcon_Max
, IconMismatch
);
2752 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon style",
2753 wxDefaultPosition
, wxDefaultSize
,
2754 WXSIZEOF(icons
), icons
,
2755 2, wxRA_SPECIFY_ROWS
);
2756 // Make the 'Information' icon the default one:
2757 m_icons
->SetSelection(MsgDlgIcon_Info
);
2758 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2761 // miscellaneous other stuff
2763 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2765 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2766 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2767 wxUpdateUIEventHandler(
2768 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2771 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2773 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2774 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2776 // add any additional flag from subclasses
2777 AddAdditionalFlags(sizerFlags
);
2779 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2781 // finally buttons to show the resulting message box and close this dialog
2782 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2783 wxSizerFlags().Right().Border());
2785 SetSizerAndFit(sizerTop
);
2787 m_buttons
[Btn_Ok
]->SetValue(true);
2792 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2794 for ( int n
= 0; n
< Btn_Max
; n
++ )
2796 if ( event
.GetEventObject() == m_labels
[n
] )
2798 event
.Enable( m_buttons
[n
]->IsChecked() );
2803 wxFAIL_MSG( "called for unknown label" );
2806 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2808 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2811 long TestMessageBoxDialog::GetStyle()
2815 for ( int n
= 0; n
< Btn_Max
; n
++ )
2817 if ( m_buttons
[n
]->IsChecked() )
2818 style
|= ms_btnInfo
[n
].flag
;
2821 switch ( m_icons
->GetSelection() )
2823 case MsgDlgIcon_Max
:
2824 wxFAIL_MSG( "unexpected selection" );
2829 case MsgDlgIcon_None
:
2830 style
|= wxICON_NONE
;
2833 case MsgDlgIcon_Info
:
2834 style
|= wxICON_INFORMATION
;
2837 case MsgDlgIcon_Question
:
2838 style
|= wxICON_QUESTION
;
2841 case MsgDlgIcon_Warning
:
2842 style
|= wxICON_WARNING
;
2845 case MsgDlgIcon_Error
:
2846 style
|= wxICON_ERROR
;
2850 if ( m_chkCentre
->IsChecked() )
2853 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2854 style
|= wxNO_DEFAULT
;
2859 void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase
&dlg
)
2861 long style
= dlg
.GetMessageDialogStyle();
2863 if ( !m_textExtMsg
->IsEmpty() )
2864 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2866 if ( style
& wxYES_NO
)
2868 if ( style
& wxCANCEL
)
2870 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2871 m_labels
[Btn_No
]->GetValue(),
2872 m_labels
[Btn_Cancel
]->GetValue());
2876 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2877 m_labels
[Btn_No
]->GetValue());
2882 if ( style
& wxCANCEL
)
2884 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2885 m_labels
[Btn_Cancel
]->GetValue());
2889 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2894 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2896 wxMessageDialog
dlg(this, GetMessage(), "Test Message Box", GetStyle());
2897 PrepareMessageDialog(dlg
);
2902 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2904 EndModal(wxID_CANCEL
);
2906 #endif // wxUSE_MSGDLG
2908 #if wxUSE_RICHMSGDLG
2909 // ----------------------------------------------------------------------------
2910 // TestRichMessageDialog
2911 // ----------------------------------------------------------------------------
2913 BEGIN_EVENT_TABLE(TestRichMessageDialog
, TestMessageBoxDialog
)
2914 EVT_BUTTON(wxID_APPLY
, TestRichMessageDialog::OnApply
)
2917 TestRichMessageDialog::TestRichMessageDialog(wxWindow
*parent
)
2918 : TestMessageBoxDialog(parent
)
2920 SetTitle("Rich Message Dialog Test Dialog");
2923 void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer
*sizer
)
2925 wxSizer
* const sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this,
2926 "&Additional Elements");
2928 // add a option to show a check box.
2929 wxFlexGridSizer
* const sizerCheckBox
= new wxFlexGridSizer(2, 5, 5);
2930 sizerCheckBox
->AddGrowableCol(1);
2931 sizerCheckBox
->Add(new wxStaticText(this, wxID_ANY
, "&Check box:"));
2932 m_textCheckBox
= new wxTextCtrl(this, wxID_ANY
);
2933 sizerCheckBox
->Add(m_textCheckBox
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2934 sizerMsgs
->Add(sizerCheckBox
, wxSizerFlags(1).Expand());
2936 // add option to show a detailed text.
2937 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Detailed message:"));
2938 m_textDetailed
= new wxTextCtrl(this, wxID_ANY
, "",
2939 wxDefaultPosition
, wxDefaultSize
,
2941 sizerMsgs
->Add(m_textDetailed
, wxSizerFlags(1).Expand());
2943 sizer
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2946 void TestRichMessageDialog::AddAdditionalFlags(wxSizer
*sizer
)
2948 // add checkbox to set the initial state for the checkbox shown
2950 m_initialValueCheckBox
=
2951 new wxCheckBox(this, wxID_ANY
, "Checkbox initially checked");
2952 sizer
->Add(m_initialValueCheckBox
, wxSizerFlags(1).Border());
2955 void TestRichMessageDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2957 wxRichMessageDialog
dlg(this, GetMessage(), "Test Rich Message Dialog",
2959 PrepareMessageDialog(dlg
);
2961 dlg
.ShowCheckBox(m_textCheckBox
->GetValue(),
2962 m_initialValueCheckBox
->GetValue());
2963 dlg
.ShowDetailedText(m_textDetailed
->GetValue());
2968 #endif // wxUSE_RICHMSGDLG
2972 // ----------------------------------------------------------------------------
2973 // custom log target
2974 // ----------------------------------------------------------------------------
2976 class MyLogGui
: public wxLogGui
2979 virtual void DoShowSingleLogMessage(const wxString
& message
,
2980 const wxString
& title
,
2983 wxMessageDialog
dlg(NULL
, message
, title
,
2984 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2985 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2986 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2991 wxLog
*MyAppTraits::CreateLogTarget()
2993 return new MyLogGui
;