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_TEXT_ENTRY
, MyFrame::TextEntry
)
156 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
157 #endif // wxUSE_TEXTDLG
160 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
161 #endif // wxUSE_NUMBERDLG
164 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
165 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
166 #endif // wxUSE_CHOICEDLG
168 #if wxUSE_REARRANGECTRL
169 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
170 #endif // wxUSE_REARRANGECTRL
173 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
174 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
175 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
176 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
177 #endif // wxUSE_FILEDLG
179 #if USE_FILEDLG_GENERIC
180 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
181 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
182 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
183 #endif // USE_FILEDLG_GENERIC
186 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
187 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
188 #endif // wxUSE_DIRDLG
190 #if USE_MODAL_PRESENTATION
191 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
192 #endif // USE_MODAL_PRESENTATION
193 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
194 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
195 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
197 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
198 #endif // wxUSE_MINIFRAME
199 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
201 #if wxUSE_STARTUP_TIPS
202 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
203 #endif // wxUSE_STARTUP_TIPS
205 #if USE_FONTDLG_GENERIC
206 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
207 #endif // USE_FONTDLG_GENERIC
209 #if USE_DIRDLG_GENERIC
210 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
211 #endif // wxMSW || wxMAC
213 #if USE_COLOURDLG_GENERIC
214 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
215 #endif // USE_COLOURDLG_GENERIC
217 #if wxUSE_PROGRESSDLG
218 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
219 #endif // wxUSE_PROGRESSDLG
222 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
223 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
224 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
225 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
226 #endif // wxUSE_ABOUTDLG
229 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
230 #endif // wxUSE_BUSYINFO
232 #if wxUSE_FINDREPLDLG
233 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
234 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
236 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
237 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
238 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
239 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
240 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
241 #endif // wxUSE_FINDREPLDLG
243 #if USE_SETTINGS_DIALOG
244 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
245 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
246 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
247 #endif // USE_SETTINGS_DIALOG
249 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
250 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
252 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
253 #if wxUSE_NOTIFICATION_MESSAGE
254 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
255 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
256 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
257 #endif // wxUSE_NOTIFICATION_MESSAGE
259 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
262 #if USE_MODAL_PRESENTATION
264 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
265 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
268 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
269 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
270 EVT_CLOSE(MyModelessDialog::OnClose
)
273 #endif // USE_MODAL_PRESENTATION
275 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
276 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
277 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
280 #if wxUSE_CMDLINE_PARSER
282 #include "wx/cmdline.h"
284 static const char *PROGRESS_SWITCH
= "progress";
286 void MyApp::OnInitCmdLine(wxCmdLineParser
& parser
)
288 wxApp::OnInitCmdLine(parser
);
290 parser
.AddOption("", PROGRESS_SWITCH
,
291 "Style for the startup progress dialog (wxPD_XXX)",
292 wxCMD_LINE_VAL_NUMBER
);
295 bool MyApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
297 if ( !wxApp::OnCmdLineParsed(parser
) )
300 parser
.Found(PROGRESS_SWITCH
, &m_startupProgressStyle
);
305 #endif // wxUSE_CMDLINE_PARSER
307 // `Main program' equivalent, creating windows and returning main app frame
310 if ( !wxApp::OnInit() )
313 #if wxUSE_PROGRESSDLG
314 if ( m_startupProgressStyle
!= -1 )
316 // Show a test progress dialog before the main event loop is started:
317 // it should still work.
318 const int PROGRESS_COUNT
= 100;
321 "Progress in progress",
322 "Please wait, starting...",
325 m_startupProgressStyle
327 for ( int i
= 0; i
<= PROGRESS_COUNT
; i
++ )
329 if ( !dlg
.Update(i
) )
335 #endif // wxUSE_PROGRESSDLG
338 wxInitAllImageHandlers();
341 // Create the main frame window
342 MyFrame
*frame
= new MyFrame(wxT("wxWidgets dialogs example"));
345 wxMenu
*menuDlg
= new wxMenu
;
347 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
348 menuDlg
->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL
, wxT("Window-Modal Message box "));
349 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
351 menuDlg
->Append(DIALOGS_RICH_MESSAGE_DIALOG
, wxT("Rich message dialog"));
352 #endif // wxUSE_RICHMSGDLG
355 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
357 wxMenu
*choices_menu
= new wxMenu
;
360 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
361 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
362 #endif // wxUSE_COLOURDLG
365 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
366 #endif // wxUSE_FONTDLG
369 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
370 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
371 #endif // wxUSE_CHOICEDLG
373 #if wxUSE_REARRANGECTRL
374 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
375 #endif // wxUSE_REARRANGECTRL
377 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
378 choices_menu
->AppendSeparator();
379 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
381 #if USE_COLOURDLG_GENERIC
382 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
383 #endif // USE_COLOURDLG_GENERIC
385 #if USE_FONTDLG_GENERIC
386 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
387 #endif // USE_FONTDLG_GENERIC
389 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
390 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
393 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
395 wxMenu
*entry_menu
= new wxMenu
;
398 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Text &entry\tCtrl-E"));
399 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
400 #endif // wxUSE_TEXTDLG
403 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
404 #endif // wxUSE_NUMBERDLG
406 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
408 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
413 wxMenu
*filedlg_menu
= new wxMenu
;
414 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
415 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
416 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
417 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
419 #if USE_FILEDLG_GENERIC
420 filedlg_menu
->AppendSeparator();
421 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
422 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
423 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
424 #endif // USE_FILEDLG_GENERIC
426 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
428 #endif // wxUSE_FILEDLG
431 wxMenu
*dir_menu
= new wxMenu
;
433 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
434 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
435 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
437 #if USE_DIRDLG_GENERIC
438 dir_menu
->AppendSeparator();
439 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
440 #endif // USE_DIRDLG_GENERIC
442 #endif // wxUSE_DIRDLG
445 #if wxUSE_STARTUP_TIPS || \
446 wxUSE_PROGRESSDLG || \
448 wxUSE_LOG_DIALOG || \
451 wxMenu
*info_menu
= new wxMenu
;
453 #if wxUSE_STARTUP_TIPS
454 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
455 #endif // wxUSE_STARTUP_TIPS
457 #if wxUSE_PROGRESSDLG
458 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
459 #endif // wxUSE_PROGRESSDLG
462 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
463 #endif // wxUSE_BUSYINFO
466 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
467 #endif // wxUSE_LOG_DIALOG
470 info_menu
->Append(DIALOGS_INFOBAR_SIMPLE
, "Simple &info bar\tCtrl-I");
471 info_menu
->Append(DIALOGS_INFOBAR_ADVANCED
, "&Advanced info bar\tShift-Ctrl-I");
472 #endif // wxUSE_INFOBAR
475 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
476 wxT("&wxWidgets information\tCtrl-W"));
477 #endif // wxUSE_MSGDLG
479 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
481 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
484 #if wxUSE_FINDREPLDLG
485 wxMenu
*find_menu
= new wxMenu
;
486 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
487 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
488 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
489 #endif // wxUSE_FINDREPLDLG
491 wxMenu
*dialogs_menu
= new wxMenu
;
492 #if USE_MODAL_PRESENTATION
493 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tShift-Ctrl-W"));
494 #endif // USE_MODAL_PRESENTATION
495 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tShift-Ctrl-Z"));
496 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
497 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
499 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
500 #endif // wxUSE_MINIFRAME
501 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
502 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
504 #if USE_SETTINGS_DIALOG
505 wxMenu
*sheet_menu
= new wxMenu
;
506 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
507 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
509 if (wxPlatformIs(wxPORT_MAC
))
510 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
513 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
516 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
517 #endif // USE_SETTINGS_DIALOG
519 wxMenu
*menuNotif
= new wxMenu
;
520 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
521 #if wxUSE_NOTIFICATION_MESSAGE
522 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
523 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
524 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
525 #endif // wxUSE_NOTIFICATION_MESSAGE
526 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
528 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
529 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
531 menuDlg
->AppendSeparator();
532 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
535 wxMenu
*menuHelp
= new wxMenu
;
536 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
537 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
538 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
539 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
540 #endif // wxUSE_ABOUTDLG
542 wxMenu
* editMenu
= new wxMenu
;
543 editMenu
->Append(wxID_UNDO
, _("&Undo\tCtrl+Z"));
544 editMenu
->Append(wxID_REDO
, _("&Redo\tCtrl+Y"));
545 editMenu
->AppendSeparator();
546 editMenu
->Append(wxID_CUT
, _("Cu&t\tCtrl+X"));
547 editMenu
->Append(wxID_COPY
, _("&Copy\tCtrl+C"));
548 editMenu
->Append(wxID_PASTE
, _("&Paste\tCtrl+V"));
549 editMenu
->Append(wxID_CLEAR
, _("&Delete"));
551 editMenu
->AppendSeparator();
552 editMenu
->Append(wxID_SELECTALL
, _("Select All\tCtrl+A"));
554 wxMenuBar
*menubar
= new wxMenuBar
;
555 menubar
->Append(menuDlg
, wxT("&Dialogs"));
557 menubar
->Append(editMenu
, wxT("&Edit"));
560 menubar
->Append(menuHelp
, wxT("&Help"));
561 #endif // wxUSE_ABOUTDLG
563 frame
->SetMenuBar(menubar
);
565 frame
->Centre(wxBOTH
);
571 // My frame constructor
572 MyFrame::MyFrame(const wxString
& title
)
573 : wxFrame(NULL
, wxID_ANY
, title
)
575 SetIcon(wxICON(sample
));
577 #if USE_MODAL_PRESENTATION
578 m_dialog
= (MyModelessDialog
*)NULL
;
579 #endif // USE_MODAL_PRESENTATION
581 #if wxUSE_FINDREPLDLG
587 m_clrData
.SetChooseFull(true);
588 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
590 unsigned char n
= i
*16;
591 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
593 #endif // wxUSE_COLOURDLG
595 #if wxUSE_NOTIFICATION_MESSAGE
597 #endif // wxUSE_NOTIFICATION_MESSAGE
601 #endif // wxUSE_STATUSBAR
603 m_canvas
= new MyCanvas(this);
606 // an info bar can be created very simply and used without any extra effort
607 m_infoBarSimple
= new wxInfoBar(this);
609 // or it can also be customized by
610 m_infoBarAdvanced
= new wxInfoBar(this);
612 // ... adding extra buttons (but more than two will usually be too many)
613 m_infoBarAdvanced
->AddButton(wxID_UNDO
);
614 m_infoBarAdvanced
->AddButton(wxID_REDO
);
616 m_infoBarAdvanced
->Connect(wxID_REDO
, wxEVT_COMMAND_BUTTON_CLICKED
,
617 wxCommandEventHandler(MyFrame::OnInfoBarRedo
),
621 // adding and removing a button immediately doesn't make sense here, of
622 // course, it's done just to show that it is possible
623 m_infoBarAdvanced
->AddButton(wxID_EXIT
);
624 m_infoBarAdvanced
->RemoveButton(wxID_EXIT
);
626 // ... changing the colours and/or fonts
627 m_infoBarAdvanced
->SetOwnBackgroundColour(0xc8ffff);
628 m_infoBarAdvanced
->SetFont(GetFont().Bold().Larger());
630 // ... and changing the effect (only does anything under MSW currently)
631 m_infoBarAdvanced
->SetShowHideEffects(wxSHOW_EFFECT_EXPAND
,
632 wxSHOW_EFFECT_EXPAND
);
633 m_infoBarAdvanced
->SetEffectDuration(1500);
636 // to use the info bars we need to use sizer for the window layout
637 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
638 sizer
->Add(m_infoBarSimple
, wxSizerFlags().Expand());
639 sizer
->Add(m_canvas
, wxSizerFlags(1).Expand());
640 sizer
->Add(m_infoBarAdvanced
, wxSizerFlags().Expand());
643 // final touch: under MSW the info bars are shown progressively and parts
644 // of the parent window can be seen during the process, so use the same
645 // background colour for our background as for the canvas window which
646 // covers our entire client area to avoid jarring colour jumps
647 SetOwnBackgroundColour(m_canvas
->GetBackgroundColour());
648 #endif // wxUSE_INFOBAR
653 #if wxUSE_NOTIFICATION_MESSAGE
655 #endif // wxUSE_NOTIFICATION_MESSAGE
660 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
662 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
664 wxColourDialog
dialog(this, &m_clrData
);
665 dialog
.SetTitle(_("Please choose the background colour"));
666 if ( dialog
.ShowModal() == wxID_OK
)
668 m_clrData
= dialog
.GetColourData();
669 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
670 m_canvas
->ClearBackground();
675 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
677 wxColour clr
= wxGetColourFromUser
680 m_canvas
->GetForegroundColour(),
681 "Please choose the foreground colour"
685 m_canvas
->SetForegroundColour(clr
);
688 //else: dialog cancelled by user
691 #endif // wxUSE_COLOURDLG
694 #if USE_COLOURDLG_GENERIC
695 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
697 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
699 //FIXME:TODO:This has no effect...
700 m_clrData
.SetChooseFull(true);
702 for (int i
= 0; i
< 16; i
++)
705 (unsigned char)(i
*16),
706 (unsigned char)(i
*16),
707 (unsigned char)(i
*16)
709 m_clrData
.SetCustomColour(i
, colour
);
712 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
713 if (dialog
->ShowModal() == wxID_OK
)
715 m_clrData
= dialog
->GetColourData();
716 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
717 m_canvas
->ClearBackground();
722 #endif // USE_COLOURDLG_GENERIC
725 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
728 data
.SetInitialFont(m_canvas
->GetFont());
729 data
.SetColour(m_canvas
->GetForegroundColour());
731 // you might also do this:
733 // wxFontDialog dialog;
734 // if ( !dialog.Create(this, data) { ... error ... }
736 wxFontDialog
dialog(this, data
);
738 if (dialog
.ShowModal() == wxID_OK
)
740 wxFontData retData
= dialog
.GetFontData();
741 m_canvas
->SetFont(retData
.GetChosenFont());
742 m_canvas
->SetForegroundColour(retData
.GetColour());
745 //else: cancelled by the user, don't change the font
747 #endif // wxUSE_FONTDLG
749 #if USE_FONTDLG_GENERIC
750 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
753 data
.SetInitialFont(m_canvas
->GetFont());
754 data
.SetColour(m_canvas
->GetForegroundColour());
756 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
757 if (dialog
->ShowModal() == wxID_OK
)
759 wxFontData retData
= dialog
->GetFontData();
760 m_canvas
->SetFont(retData
.GetChosenFont());
761 m_canvas
->SetForegroundColour(retData
.GetColour());
766 #endif // USE_FONTDLG_GENERIC
769 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
771 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
772 // being flushed -- test it
775 wxLogMessage(wxT("This is some message - everything is ok so far."));
776 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
777 wxLogWarning(wxT("And then something went wrong!"));
779 // and if ~wxBusyCursor doesn't do it, then call it manually
783 wxLogError(wxT("Intermediary error handler decided to abort."));
784 wxLogError(wxT("The top level caller detected an unrecoverable error."));
786 wxLog::FlushActive();
788 wxLogMessage(wxT("And this is the same dialog but with only one message."));
790 #endif // wxUSE_LOG_DIALOG
794 void MyFrame::InfoBarSimple(wxCommandEvent
& WXUNUSED(event
))
796 static int s_count
= 0;
797 m_infoBarSimple
->ShowMessage
799 wxString::Format("Message #%d in the info bar.", ++s_count
)
803 void MyFrame::InfoBarAdvanced(wxCommandEvent
& WXUNUSED(event
))
805 m_infoBarAdvanced
->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING
);
808 void MyFrame::OnInfoBarRedo(wxCommandEvent
& WXUNUSED(event
))
810 m_infoBarAdvanced
->ShowMessage("Still no, sorry again.", wxICON_ERROR
);
813 #endif // wxUSE_INFOBAR
817 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
819 wxMessageDialog
dialog(this,
820 "This is a message box\n"
821 "This is a long, long string to test out if the message box "
822 "is laid out properly.",
825 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
829 if ( dialog
.SetYesNoCancelLabels
836 extmsg
= "This platform supports custom button labels,\n"
837 "so you should see the descriptive labels below.";
841 extmsg
= "Custom button labels are not supported on this platform,\n"
842 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
844 dialog
.SetExtendedMessage(extmsg
);
846 switch ( dialog
.ShowModal() )
849 wxLogStatus(wxT("You pressed \"Yes\""));
853 wxLogStatus(wxT("You pressed \"No\""));
857 wxLogStatus(wxT("You pressed \"Cancel\""));
861 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
865 void MyFrame::MessageBoxWindowModal(wxCommandEvent
& WXUNUSED(event
))
867 wxMessageDialog
* dialog
= new wxMessageDialog(this,
868 "This is a message box\n"
869 "This is a long, long string to test out if the message box "
870 "is laid out properly.",
873 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
877 if ( dialog
->SetYesNoCancelLabels
884 extmsg
= "This platform supports custom button labels,\n"
885 "so you should see the descriptive labels below.";
889 extmsg
= "Custom button labels are not supported on this platform,\n"
890 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
892 dialog
->SetExtendedMessage(extmsg
);
893 dialog
->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed
), NULL
, this );
894 dialog
->ShowWindowModal();
897 void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
)
899 wxDialog
* dialog
= event
.GetDialog();
900 switch ( dialog
->GetReturnCode() )
903 wxLogStatus(wxT("You pressed \"Yes\""));
907 wxLogStatus(wxT("You pressed \"No\""));
911 wxLogStatus(wxT("You pressed \"Cancel\""));
915 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
920 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
922 TestMessageBoxDialog
dlg(this);
927 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
929 ::wxInfoMessageBox(this);
931 #endif // wxUSE_MSGDLG
934 void MyFrame::RichMessageDialog(wxCommandEvent
& WXUNUSED(event
))
936 TestRichMessageDialog
dlg(this);
940 #endif // wxUSE_RICHMSGDLG
943 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
945 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
946 wxT("Even two rows of text."),
947 wxT("Enter a number:"), wxT("Numeric input test"),
954 msg
= wxT("Invalid number entered or dialog cancelled.");
959 msg
.Printf(wxT("You've entered %lu"), res
);
960 icon
= wxICON_INFORMATION
;
963 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
965 #endif // wxUSE_NUMBERDLG
968 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
970 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
971 wxT("Password entry dialog"),
976 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
977 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
981 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
983 wxTextEntryDialog
dialog(this,
984 wxT("This is a small sample\n")
985 wxT("A long, long string to test out the text entrybox"),
986 wxT("Please enter a string"),
987 wxT("Default value"),
990 if (dialog
.ShowModal() == wxID_OK
)
992 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
995 #endif // wxUSE_TEXTDLG
998 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
1000 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
1002 wxSingleChoiceDialog
dialog(this,
1003 wxT("This is a small sample\n")
1004 wxT("A single-choice convenience dialog"),
1005 wxT("Please select a value"),
1006 WXSIZEOF(choices
), choices
);
1008 dialog
.SetSelection(2);
1010 if (dialog
.ShowModal() == wxID_OK
)
1012 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
1013 dialog2
.ShowModal();
1017 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
1019 const wxString choices
[] =
1021 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
1022 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
1023 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
1026 wxArrayInt selections
;
1027 const int count
= wxGetSelectedChoices(selections
,
1028 wxT("This is a small sample\n")
1029 wxT("A multi-choice convenience dialog"),
1030 wxT("Please select a value"),
1031 WXSIZEOF(choices
), choices
,
1038 msg
= wxT("You did not select any items");
1042 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
1043 for ( int n
= 0; n
< count
; n
++ )
1045 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
1046 (unsigned)n
, (unsigned)selections
[n
],
1047 choices
[selections
[n
]].c_str());
1054 #endif // wxUSE_CHOICEDLG
1056 #if wxUSE_REARRANGECTRL
1057 // custom rearrange dialog: it adds the possibility to rename an item to the
1058 // base class functionality
1059 class MyRearrangeDialog
: public wxRearrangeDialog
1062 MyRearrangeDialog(wxWindow
*parent
,
1064 wxArrayString
& labels
,
1065 wxArrayString
& labelsOrig
)
1069 "Configure the columns shown:",
1070 "wxRearrangeDialog example",
1076 m_labelsOrig(labelsOrig
)
1078 m_sel
= wxNOT_FOUND
;
1080 wxPanel
* const panel
= new wxPanel(this);
1081 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1083 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
1084 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
1086 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
1087 wxDefaultPosition
, wxDefaultSize
,
1088 wxTE_PROCESS_ENTER
);
1089 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
1091 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
1092 wxSizerFlags().Centre());
1094 panel
->SetSizer(sizer
);
1096 // call this first to ensure that the controls have a reasonable best
1097 // size before they're added
1098 DoUpdateExtraControls(GetList()->GetSelection());
1100 AddExtraControls(panel
);
1103 // another customization not directly supported by the dialog: add a
1105 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
1106 wxCHECK_RET( btnOk
, "no Ok button?" );
1108 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
1109 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
1111 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
1112 wxSizerFlags().Border(wxLEFT
));
1115 // call this instead of ShowModal() to update order and labels array in
1116 // case the dialog was not cancelled
1119 switch ( ShowModal() )
1125 m_order
= GetOrder();
1129 // order already reset
1137 void OnSelChange(wxCommandEvent
& event
)
1139 DoUpdateExtraControls(event
.GetInt());
1142 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
1144 event
.Enable( CanRename() );
1147 void OnRename(wxCommandEvent
& WXUNUSED(event
))
1152 m_labels
[m_sel
] = m_text
->GetValue();
1153 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
1156 void OnReset(wxCommandEvent
& WXUNUSED(event
))
1158 // in a real program we should probably ask if the user really wants to
1159 // do this but here we just go ahead and reset all columns labels and
1160 // their order without confirmation
1161 const unsigned count
= m_order
.size();
1162 for ( unsigned n
= 0; n
< count
; n
++ )
1165 m_labels
[n
] = m_labelsOrig
[n
];
1168 EndModal(wxID_RESET
);
1171 bool CanRename() const
1173 // only allow renaming if the user modified the currently selected item
1174 // text (which presupposes that we do have a current item)
1175 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
1178 void DoUpdateExtraControls(int sel
)
1182 if ( m_sel
== wxNOT_FOUND
)
1184 m_labelOrig
->SetLabel("<no selection>");
1188 else // have valid item
1190 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
1192 m_text
->SetValue(m_labels
[m_sel
]);
1196 wxArrayInt
& m_order
;
1197 wxArrayString
& m_labels
,
1201 wxStaticText
*m_labelOrig
;
1204 DECLARE_EVENT_TABLE()
1205 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
1208 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
1209 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
1211 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
1213 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
1214 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
1215 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
1218 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
1220 // the arrays are static so that we preserve the items order between calls
1222 static wxArrayInt s_order
;
1223 static wxArrayString s_labels
,
1226 // initialize them on the first call
1227 if ( s_labelsOrig
.empty() )
1229 static const struct ItemInfo
1232 const char *labelOrig
;
1236 { "File name", "Name", 0 },
1237 { "File type", "Ext", 1 },
1238 { "Size", "Size", 2 },
1239 { "Creation time", "Ctime", ~3 }, // negated so hidden
1240 { "Last accessed", "Atime", ~4 },
1241 { "Last modified", "Mtime", 5 },
1244 s_order
.reserve(WXSIZEOF(items
));
1245 s_labels
.reserve(WXSIZEOF(items
));
1246 s_labelsOrig
.reserve(WXSIZEOF(items
));
1247 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1249 const ItemInfo
& item
= items
[n
];
1250 s_order
.push_back(item
.order
);
1251 s_labels
.push_back(item
.label
);
1252 s_labelsOrig
.push_back(item
.labelOrig
);
1256 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1257 if ( !dlg
.Rearrange() )
1261 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1263 columns
+= wxString::Format("\n %u: ", n
);
1264 int idx
= s_order
[n
];
1267 columns
+= "[hidden] ";
1271 columns
+= s_labels
[idx
];
1272 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1274 columns
+= wxString::Format(" (original label: \"%s\")",
1279 wxLogMessage("The columns order now is:%s", columns
);
1281 #endif // wxUSE_REARRANGECTRL
1285 // panel with custom controls for file dialog
1286 class MyExtraPanel
: public wxPanel
1289 MyExtraPanel(wxWindow
*parent
);
1290 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1291 wxString
GetInfo() const
1293 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1300 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1303 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1304 m_btn
->Enable(false);
1305 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1306 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1307 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1308 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1309 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1310 sizerTop
->AddStretchSpacer();
1311 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1312 SetSizerAndFit(sizerTop
);
1315 // a static method can be used instead of a function with most of compilers
1316 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1318 return new MyExtraPanel(parent
);
1321 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1326 wxT("Testing open file dialog"),
1330 wxT("C++ files (*.cpp)|*.cpp")
1332 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1336 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1337 dialog
.CentreOnParent();
1338 dialog
.SetDirectory(wxGetHomeDir());
1340 if (dialog
.ShowModal() == wxID_OK
)
1343 wxWindow
* const extra
= dialog
.GetExtraControl();
1344 info
.Printf(wxT("Full file name: %s\n")
1347 wxT("Custom window: %s"),
1348 dialog
.GetPath().c_str(),
1349 dialog
.GetDirectory().c_str(),
1350 dialog
.GetFilename().c_str(),
1351 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1352 : wxString("None"));
1353 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1354 dialog2
.ShowModal();
1358 // this shows how to take advantage of specifying a default extension in the
1359 // call to wxFileSelector: it is remembered after each new call and the next
1360 // one will use it by default
1361 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1363 static wxString s_extDef
;
1364 wxString path
= wxFileSelector(
1365 wxT("Select the file to load"),
1366 wxEmptyString
, wxEmptyString
,
1370 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1371 wxFileSelectorDefaultWildcardStr
,
1372 wxFileSelectorDefaultWildcardStr
1374 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1381 // it is just a sample, would use wxSplitPath in real program
1382 s_extDef
= path
.AfterLast(wxT('.'));
1384 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1388 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1390 wxString wildcards
=
1392 wxT("C++ files (*.cpp)|*.cpp");
1396 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1397 wxFileSelectorDefaultWildcardStr
,
1398 wxFileSelectorDefaultWildcardStr
1401 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1402 wxEmptyString
, wxEmptyString
, wildcards
,
1403 wxFD_OPEN
|wxFD_MULTIPLE
);
1405 if (dialog
.ShowModal() == wxID_OK
)
1407 wxArrayString paths
, filenames
;
1409 dialog
.GetPaths(paths
);
1410 dialog
.GetFilenames(filenames
);
1413 size_t count
= paths
.GetCount();
1414 for ( size_t n
= 0; n
< count
; n
++ )
1416 s
.Printf(wxT("File %d: %s (%s)\n"),
1417 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1421 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1424 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1425 dialog2
.ShowModal();
1429 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1431 wxFileDialog
dialog(this,
1432 wxT("Testing save file dialog"),
1434 wxT("myletter.doc"),
1435 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1436 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1438 dialog
.SetFilterIndex(1);
1440 if (dialog
.ShowModal() == wxID_OK
)
1442 wxLogMessage(wxT("%s, filter %d"),
1443 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1446 #endif // wxUSE_FILEDLG
1448 #if USE_FILEDLG_GENERIC
1449 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1451 wxGenericFileDialog dialog
1454 wxT("Testing open file dialog"),
1457 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1460 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1461 dialog
.SetDirectory(wxGetHomeDir());
1463 if (dialog
.ShowModal() == wxID_OK
)
1466 info
.Printf(wxT("Full file name: %s\n")
1469 dialog
.GetPath().c_str(),
1470 dialog
.GetDirectory().c_str(),
1471 dialog
.GetFilename().c_str());
1472 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1473 dialog2
.ShowModal();
1477 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1479 // On PocketPC you can disable OK-only dialogs policy using system option
1480 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1481 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1483 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1484 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1485 wxEmptyString
, wxEmptyString
, wildcards
,
1488 if (dialog
.ShowModal() == wxID_OK
)
1490 wxArrayString paths
, filenames
;
1492 dialog
.GetPaths(paths
);
1493 dialog
.GetFilenames(filenames
);
1496 size_t count
= paths
.GetCount();
1497 for ( size_t n
= 0; n
< count
; n
++ )
1499 s
.Printf(wxT("File %d: %s (%s)\n"),
1500 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1504 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1507 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1508 dialog2
.ShowModal();
1511 // restore system option
1512 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1515 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1517 wxGenericFileDialog
dialog(this,
1518 wxT("Testing save file dialog"),
1520 wxT("myletter.doc"),
1521 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1522 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1524 dialog
.SetFilterIndex(1);
1526 if (dialog
.ShowModal() == wxID_OK
)
1528 wxLogMessage(wxT("%s, filter %d"),
1529 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1532 #endif // USE_FILEDLG_GENERIC
1535 void MyFrame::DoDirChoose(int style
)
1537 // pass some initial dir to wxDirDialog
1539 wxGetHomeDir(&dirHome
);
1541 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1543 if (dialog
.ShowModal() == wxID_OK
)
1545 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1549 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1551 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1554 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1556 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1558 #endif // wxUSE_DIRDLG
1560 #if USE_DIRDLG_GENERIC
1561 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1563 // pass some initial dir to wxDirDialog
1565 wxGetHomeDir(&dirHome
);
1567 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1569 if (dialog
.ShowModal() == wxID_OK
)
1571 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1572 dialog2
.ShowModal();
1575 #endif // USE_DIRDLG_GENERIC
1577 #if USE_MODAL_PRESENTATION
1578 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1580 MyModalDialog
dlg(this);
1583 #endif // USE_MODAL_PRESENTATION
1585 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1587 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1593 m_dialog
= new MyModelessDialog(this);
1596 m_dialog
->Show(true);
1600 // If m_dialog is NULL, then possibly the system
1601 // didn't report the checked menu item status correctly.
1602 // It should be true just after the menu item was selected,
1603 // if there was no modeless dialog yet.
1605 wxASSERT( m_dialog
!= NULL
);
1611 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1613 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1614 wxDefaultPosition
, wxSize(200, 100));
1615 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1616 dlg
.CentreOnScreen();
1620 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1622 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1623 wxDefaultPosition
, wxSize(200, 100));
1624 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1625 dlg
.CentreOnParent();
1630 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1632 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1633 wxDefaultPosition
, wxSize(300, 100),
1634 wxCAPTION
| wxCLOSE_BOX
);
1635 new wxStaticText(frame
,
1637 wxT("Mini frames have slightly different appearance"),
1639 new wxStaticText(frame
,
1641 wxT("from the normal frames but that's the only difference."),
1644 frame
->CentreOnParent();
1647 #endif // wxUSE_MINIFRAME
1649 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1651 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1652 wxDefaultPosition
, wxSize(300, 100),
1653 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1654 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1658 #if wxUSE_STARTUP_TIPS
1659 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1661 static size_t s_index
= (size_t)-1;
1663 if ( s_index
== (size_t)-1 )
1667 // this is completely bogus, we don't know how many lines are there
1668 // in the file, but who cares, it's a demo only...
1669 s_index
= rand() % 5;
1672 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1674 bool showAtStartup
= wxShowTip(this, tipProvider
);
1676 if ( showAtStartup
)
1678 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1679 wxOK
| wxICON_INFORMATION
, this);
1682 s_index
= tipProvider
->GetCurrentTip();
1685 #endif // wxUSE_STARTUP_TIPS
1687 #if USE_SETTINGS_DIALOG
1688 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1690 SettingsDialog
dialog(this, event
.GetId());
1693 #endif // USE_SETTINGS_DIALOG
1695 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1697 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1701 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1704 #if wxUSE_NOTIFICATION_MESSAGE
1706 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1708 if ( !wxNotificationMessage
1710 "Automatic Notification",
1711 "Nothing important has happened\n"
1712 "this notification will disappear soon."
1715 wxLogStatus("Failed to show notification message");
1719 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1723 m_notifMsg
= new wxNotificationMessage
1725 "wxWidgets Manual Notification",
1726 "You can hide this notification from the menu",
1731 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1733 wxLogStatus("Failed to show manual notification message");
1737 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1739 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1741 wxLogStatus("Failed to hide manual notification message");
1745 #endif // wxUSE_NOTIFICATION_MESSAGE
1747 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1749 StdButtonSizerDialog
dialog(this);
1753 // TestDefaultAction
1755 #define ID_CATCH_LISTBOX_DCLICK 100
1756 #define ID_LISTBOX 101
1758 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1759 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1760 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1763 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1764 wxDialog( parent
, -1, "Test default action" )
1766 m_catchListBoxDClick
= false;
1768 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1770 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1773 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1774 listbox
->Append( "String 1" );
1775 listbox
->Append( "String 2" );
1776 listbox
->Append( "String 3" );
1777 listbox
->Append( "String 4" );
1778 grid_sizer
->Add( listbox
);
1779 #endif // wxUSE_LISTBOX
1781 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1783 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1784 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1786 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1787 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1789 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1791 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1793 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1795 SetSizerAndFit( main_sizer
);
1798 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1800 event
.Skip( !m_catchListBoxDClick
);
1803 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1805 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1808 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1810 TestDefaultActionDialog
dialog( this );
1814 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1819 #if wxUSE_PROGRESSDLG
1821 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1823 static const int max
= 100;
1825 wxProgressDialog
dialog("Progress dialog example",
1826 // "Reserve" enough space for the multiline
1827 // messages below, we'll change it anyhow
1828 // immediately in the loop below
1829 wxString(' ', 100) + "\n\n\n\n",
1835 //wxPD_AUTO_HIDE | // -- try this as well
1837 wxPD_ESTIMATED_TIME
|
1838 wxPD_REMAINING_TIME
|
1839 wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1843 for ( int i
= 0; i
<= max
; i
++ )
1847 // test both modes of wxProgressDialog behaviour: start in
1848 // indeterminate mode but switch to the determinate one later
1849 const bool determinate
= i
> max
/2;
1853 msg
= "That's all, folks!\n"
1855 "Nothing to see here any more.";
1857 else if ( !determinate
)
1859 msg
= "Testing indeterminate mode\n"
1861 "This mode allows you to show to the user\n"
1862 "that something is going on even if you don't know\n"
1863 "when exactly will you finish.";
1865 else if ( determinate
)
1867 msg
= "Now in standard determinate mode\n"
1869 "This is the standard usage mode in which you\n"
1870 "update the dialog after performing each new step of work.\n"
1871 "It requires knowing the total number of steps in advance.";
1874 // will be set to true if "Skip" button was pressed
1878 cont
= dialog
.Update(i
, msg
, &skip
);
1882 cont
= dialog
.Pulse(msg
, &skip
);
1885 // each skip will move progress about quarter forward
1896 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1897 wxT("Progress dialog question"), // caption
1898 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1910 wxLogStatus(wxT("Progress dialog aborted!"));
1914 wxLogStatus(wxT("Countdown from %d finished"), max
);
1918 #endif // wxUSE_PROGRESSDLG
1922 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1924 info
.SetName(wxT("Dialogs Sample"));
1925 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
1929 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
1930 wxVERSION_NUM_DOT_STRING
1932 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1933 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1934 info
.AddDeveloper(wxT("Vadim Zeitlin"));
1937 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1939 InitAboutInfoMinimal(info
);
1941 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
1944 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1946 InitAboutInfoWebsite(info
);
1948 // we can add a second developer
1949 info
.AddDeveloper(wxT("A.N. Other"));
1951 // or we can add several persons at once like this
1952 static const wxChar
*docwriters
[] =
1954 wxT("First D. Writer"),
1958 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1959 info
.SetLicence(wxString::FromAscii(
1960 " wxWindows Library Licence, Version 3.1\n"
1961 " ======================================\n"
1963 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1965 " Everyone is permitted to copy and distribute verbatim copies\n"
1966 " of this licence document, but changing it is not allowed.\n"
1968 " WXWINDOWS LIBRARY LICENCE\n"
1969 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1971 " ...and so on and so forth...\n"
1974 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
1977 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1979 wxAboutDialogInfo info
;
1980 InitAboutInfoMinimal(info
);
1982 wxAboutBox(info
, this);
1985 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1987 wxAboutDialogInfo info
;
1988 InitAboutInfoWebsite(info
);
1990 wxAboutBox(info
, this);
1993 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1995 wxAboutDialogInfo info
;
1996 InitAboutInfoAll(info
);
1998 wxAboutBox(info
, this);
2001 // a trivial example of a custom dialog class
2002 class MyAboutDialog
: public wxGenericAboutDialog
2005 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
2007 Create(info
, parent
);
2010 // add some custom controls
2011 virtual void DoAddCustomControls()
2013 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2014 AddText(wxT("Some custom text"));
2015 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2019 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2021 wxAboutDialogInfo info
;
2022 InitAboutInfoAll(info
);
2024 MyAboutDialog
dlg(info
, this);
2028 #endif // wxUSE_ABOUTDLG
2032 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
2034 wxWindowDisabler disableAll
;
2036 wxBusyInfo
info(wxT("Working, please wait..."), this);
2038 for ( int i
= 0; i
< 18; i
++ )
2048 #endif // wxUSE_BUSYINFO
2050 #if wxUSE_FINDREPLDLG
2052 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
2056 wxDELETE(m_dlgReplace
);
2060 m_dlgReplace
= new wxFindReplaceDialog
2064 wxT("Find and replace dialog"),
2068 m_dlgReplace
->Show(true);
2072 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
2076 wxDELETE(m_dlgFind
);
2080 m_dlgFind
= new wxFindReplaceDialog
2089 m_dlgFind
->Show(true);
2093 static wxString
DecodeFindDialogEventFlags(int flags
)
2096 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
2097 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
2098 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
2099 << wxT("case sensitive");
2104 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
2106 wxEventType type
= event
.GetEventType();
2108 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
2110 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
2111 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
2112 event
.GetFindString().c_str(),
2113 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2115 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
2116 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
2118 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
2119 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
2120 event
.GetFindString().c_str(),
2121 event
.GetReplaceString().c_str(),
2122 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2124 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
2126 wxFindReplaceDialog
*dlg
= event
.GetDialog();
2130 if ( dlg
== m_dlgFind
)
2133 idMenu
= DIALOGS_FIND
;
2136 else if ( dlg
== m_dlgReplace
)
2138 txt
= wxT("Replace");
2139 idMenu
= DIALOGS_REPLACE
;
2140 m_dlgReplace
= NULL
;
2144 txt
= wxT("Unknown");
2147 wxFAIL_MSG( wxT("unexpected event") );
2150 wxLogMessage(wxT("%s dialog is being closed."), txt
);
2152 if ( idMenu
!= wxID_ANY
)
2154 GetMenuBar()->Check(idMenu
, false);
2161 wxLogError(wxT("Unknown find dialog event!"));
2165 #endif // wxUSE_FINDREPLDLG
2167 // ----------------------------------------------------------------------------
2169 // ----------------------------------------------------------------------------
2171 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
2174 dc
.SetBackgroundMode(wxTRANSPARENT
);
2176 wxT("wxWidgets common dialogs")
2177 #if !defined(__SMARTPHONE__)
2178 wxT(" test application")
2183 #if USE_MODAL_PRESENTATION
2185 // ----------------------------------------------------------------------------
2187 // ----------------------------------------------------------------------------
2189 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
2190 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
2192 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
2194 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
2195 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
2198 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
2199 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
2201 SetSizerAndFit(sizerTop
);
2204 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
2206 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
2207 wxOK
| wxICON_INFORMATION
, this);
2210 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
2212 if ( event
.CanVeto() )
2214 wxMessageBox(wxT("Use the menu item to close this dialog"),
2215 wxT("Modeless dialog"),
2216 wxOK
| wxICON_INFORMATION
, this);
2222 // ----------------------------------------------------------------------------
2224 // ----------------------------------------------------------------------------
2226 MyModalDialog::MyModalDialog(wxWindow
*parent
)
2227 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
2229 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
2231 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2232 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2233 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2235 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2236 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2237 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2238 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2240 SetSizerAndFit(sizerTop
);
2242 SetEscapeId(wxID_CLOSE
);
2244 m_btnModal
->SetFocus();
2245 m_btnModal
->SetDefault();
2248 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2250 if ( event
.GetEventObject() == m_btnDelete
)
2252 wxDELETE(m_btnModal
);
2253 m_btnDelete
->Disable();
2255 else if ( event
.GetEventObject() == m_btnModal
)
2258 wxGetTextFromUser(wxT("Dummy prompt"),
2259 wxT("Modal dialog called from dialog"),
2260 wxEmptyString
, this);
2262 wxMessageBox(wxT("Modal dialog called from dialog"));
2263 #endif // wxUSE_TEXTDLG
2265 else if ( event
.GetEventObject() == m_btnModeless
)
2267 (new MyModelessDialog(this))->Show();
2275 #endif // USE_MODAL_PRESENTATION
2277 // ----------------------------------------------------------------------------
2278 // StdButtonSizerDialog
2279 // ----------------------------------------------------------------------------
2281 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2282 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2283 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2284 m_buttonsSizer(NULL
)
2286 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2288 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2289 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2291 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2293 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2295 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2296 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2298 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2300 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2302 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2304 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2305 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2307 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2309 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2310 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2311 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2313 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2315 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2316 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2318 sizer
->Add(sizerInside1
, 0, 0, 0);
2319 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2320 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2321 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2323 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2324 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2326 sizer
->Add(sizerInside2
, 0, 0, 0);
2327 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2328 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2329 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2331 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2333 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2334 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2335 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2337 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2339 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2341 EnableDisableControls();
2343 SetSizerAndFit(sizerTop
);
2349 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2353 m_buttonsSizer
->DeleteWindows();
2354 GetSizer()->Remove(m_buttonsSizer
);
2357 EnableDisableControls();
2360 unsigned long numButtons
= 0;
2362 if (m_chkboxAffirmativeButton
->IsChecked())
2364 if (m_radiobtnOk
->GetValue())
2369 else if (m_radiobtnYes
->GetValue())
2376 if (m_chkboxDismissButton
->IsChecked())
2378 if (m_radiobtnCancel
->GetValue())
2384 else if (m_radiobtnClose
->GetValue())
2392 if (m_chkboxApply
->IsChecked())
2398 if (m_chkboxNo
->IsChecked())
2404 if (m_chkboxHelp
->IsChecked())
2410 if (m_chkboxNoDefault
->IsChecked())
2412 flags
|= wxNO_DEFAULT
;
2415 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2416 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2419 GetSizer()->SetSizeHints(this);
2422 void StdButtonSizerDialog::EnableDisableControls()
2424 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2426 m_radiobtnOk
->Enable(affButtonEnabled
);
2427 m_radiobtnYes
->Enable(affButtonEnabled
);
2429 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2431 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2432 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2435 #if USE_SETTINGS_DIALOG
2436 // ----------------------------------------------------------------------------
2438 // ----------------------------------------------------------------------------
2440 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2442 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2445 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2447 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2452 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2453 int resizeBorder
= wxRESIZE_BORDER
;
2461 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2462 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2463 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2465 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2467 SetSheetStyle(sheetStyle
);
2468 SetSheetInnerBorder(0);
2469 SetSheetOuterBorder(0);
2471 // create a dummy image list with a few icons
2472 const wxSize
imageSize(32, 32);
2474 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2476 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2478 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2480 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2482 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2487 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2488 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2491 // If using a toolbook, also follow Mac style and don't create buttons
2493 CreateButtons(wxOK
| wxCANCEL
|
2494 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2497 wxBookCtrlBase
* notebook
= GetBookCtrl();
2498 notebook
->SetImageList(m_imageList
);
2500 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2501 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2503 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2504 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2509 SettingsDialog::~SettingsDialog()
2514 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2516 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2518 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2519 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2523 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2524 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2525 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2526 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2530 wxString autoSaveLabel
= _("&Auto-save every");
2531 wxString minsLabel
= _("mins");
2533 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2534 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2537 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2538 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2541 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2543 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2545 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2546 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2550 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2551 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2552 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2553 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2555 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2557 panel
->SetSizerAndFit(topSizer
);
2562 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2564 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2566 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2567 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2569 //// PROJECT OR GLOBAL
2570 wxString globalOrProjectChoices
[2];
2571 globalOrProjectChoices
[0] = _("&New projects");
2572 globalOrProjectChoices
[1] = _("&This project");
2574 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2575 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2576 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2578 projectOrGlobal
->SetSelection(0);
2580 //// BACKGROUND STYLE
2581 wxArrayString backgroundStyleChoices
;
2582 backgroundStyleChoices
.Add(wxT("Colour"));
2583 backgroundStyleChoices
.Add(wxT("Image"));
2584 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2586 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2587 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2589 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2591 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2593 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2594 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2595 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2597 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2600 //// FONT SIZE SELECTION
2602 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2603 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2605 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2606 wxSize(80, wxDefaultCoord
));
2607 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2609 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2612 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2613 topSizer
->AddSpacer(5);
2615 panel
->SetSizerAndFit(topSizer
);
2620 #endif // USE_SETTINGS_DIALOG
2623 // ----------------------------------------------------------------------------
2624 // TestMessageBoxDialog
2625 // ----------------------------------------------------------------------------
2628 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2633 { wxCANCEL
, "&Cancel" },
2636 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2637 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2638 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2641 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2642 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2643 wxDefaultPosition
, wxDefaultSize
,
2644 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2648 bool TestMessageBoxDialog::Create()
2650 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2652 // this sizer allows to configure the messages shown in the message box
2654 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2655 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2656 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2657 wxDefaultPosition
, wxDefaultSize
,
2659 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2661 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2662 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2663 wxDefaultPosition
, wxDefaultSize
,
2665 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2667 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2669 // if a derived class provides more message configurations, add these.
2670 AddAdditionalTextOptions(sizerTop
);
2672 // this one is for configuring the buttons
2674 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2676 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2677 sizerBtns
->AddGrowableCol(1);
2679 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2680 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2682 for ( int n
= 0; n
< Btn_Max
; n
++ )
2684 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2685 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2687 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2688 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2690 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2691 wxUpdateUIEventHandler(
2692 TestMessageBoxDialog::OnUpdateLabelUI
),
2697 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2698 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2702 const wxString icons
[] =
2706 "&Information icon",
2712 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == MsgDlgIcon_Max
, IconMismatch
);
2714 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon style",
2715 wxDefaultPosition
, wxDefaultSize
,
2716 WXSIZEOF(icons
), icons
,
2717 2, wxRA_SPECIFY_ROWS
);
2718 // Make the 'Information' icon the default one:
2719 m_icons
->SetSelection(MsgDlgIcon_Info
);
2720 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2723 // miscellaneous other stuff
2725 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2727 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2728 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2729 wxUpdateUIEventHandler(
2730 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2733 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2735 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2736 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2738 // add any additional flag from subclasses
2739 AddAdditionalFlags(sizerFlags
);
2741 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2743 // finally buttons to show the resulting message box and close this dialog
2744 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2745 wxSizerFlags().Right().Border());
2747 SetSizerAndFit(sizerTop
);
2749 m_buttons
[Btn_Ok
]->SetValue(true);
2754 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2756 for ( int n
= 0; n
< Btn_Max
; n
++ )
2758 if ( event
.GetEventObject() == m_labels
[n
] )
2760 event
.Enable( m_buttons
[n
]->IsChecked() );
2765 wxFAIL_MSG( "called for unknown label" );
2768 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2770 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2773 long TestMessageBoxDialog::GetStyle()
2777 for ( int n
= 0; n
< Btn_Max
; n
++ )
2779 if ( m_buttons
[n
]->IsChecked() )
2780 style
|= ms_btnInfo
[n
].flag
;
2783 switch ( m_icons
->GetSelection() )
2785 case MsgDlgIcon_Max
:
2786 wxFAIL_MSG( "unexpected selection" );
2791 case MsgDlgIcon_None
:
2792 style
|= wxICON_NONE
;
2795 case MsgDlgIcon_Info
:
2796 style
|= wxICON_INFORMATION
;
2799 case MsgDlgIcon_Question
:
2800 style
|= wxICON_QUESTION
;
2803 case MsgDlgIcon_Warning
:
2804 style
|= wxICON_WARNING
;
2807 case MsgDlgIcon_Error
:
2808 style
|= wxICON_ERROR
;
2812 if ( m_chkCentre
->IsChecked() )
2815 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2816 style
|= wxNO_DEFAULT
;
2821 void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase
&dlg
)
2823 long style
= dlg
.GetMessageDialogStyle();
2825 if ( !m_textExtMsg
->IsEmpty() )
2826 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2828 if ( style
& wxYES_NO
)
2830 if ( style
& wxCANCEL
)
2832 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2833 m_labels
[Btn_No
]->GetValue(),
2834 m_labels
[Btn_Cancel
]->GetValue());
2838 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2839 m_labels
[Btn_No
]->GetValue());
2844 if ( style
& wxCANCEL
)
2846 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2847 m_labels
[Btn_Cancel
]->GetValue());
2851 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2856 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2858 wxMessageDialog
dlg(this, GetMessage(), "Test Message Box", GetStyle());
2859 PrepareMessageDialog(dlg
);
2864 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2866 EndModal(wxID_CANCEL
);
2868 #endif // wxUSE_MSGDLG
2870 #if wxUSE_RICHMSGDLG
2871 // ----------------------------------------------------------------------------
2872 // TestRichMessageDialog
2873 // ----------------------------------------------------------------------------
2875 BEGIN_EVENT_TABLE(TestRichMessageDialog
, TestMessageBoxDialog
)
2876 EVT_BUTTON(wxID_APPLY
, TestRichMessageDialog::OnApply
)
2879 TestRichMessageDialog::TestRichMessageDialog(wxWindow
*parent
)
2880 : TestMessageBoxDialog(parent
)
2882 SetTitle("Rich Message Dialog Test Dialog");
2885 void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer
*sizer
)
2887 wxSizer
* const sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this,
2888 "&Additional Elements");
2890 // add a option to show a check box.
2891 wxFlexGridSizer
* const sizerCheckBox
= new wxFlexGridSizer(2, 5, 5);
2892 sizerCheckBox
->AddGrowableCol(1);
2893 sizerCheckBox
->Add(new wxStaticText(this, wxID_ANY
, "&Check box:"));
2894 m_textCheckBox
= new wxTextCtrl(this, wxID_ANY
);
2895 sizerCheckBox
->Add(m_textCheckBox
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2896 sizerMsgs
->Add(sizerCheckBox
, wxSizerFlags(1).Expand());
2898 // add option to show a detailed text.
2899 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Detailed message:"));
2900 m_textDetailed
= new wxTextCtrl(this, wxID_ANY
, "",
2901 wxDefaultPosition
, wxDefaultSize
,
2903 sizerMsgs
->Add(m_textDetailed
, wxSizerFlags(1).Expand());
2905 sizer
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2908 void TestRichMessageDialog::AddAdditionalFlags(wxSizer
*sizer
)
2910 // add checkbox to set the initial state for the checkbox shown
2912 m_initialValueCheckBox
=
2913 new wxCheckBox(this, wxID_ANY
, "Checkbox initially checked");
2914 sizer
->Add(m_initialValueCheckBox
, wxSizerFlags(1).Border());
2917 void TestRichMessageDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2919 wxRichMessageDialog
dlg(this, GetMessage(), "Test Rich Message Dialog",
2921 PrepareMessageDialog(dlg
);
2923 dlg
.ShowCheckBox(m_textCheckBox
->GetValue(),
2924 m_initialValueCheckBox
->GetValue());
2925 dlg
.ShowDetailedText(m_textDetailed
->GetValue());
2930 #endif // wxUSE_RICHMSGDLG
2934 // ----------------------------------------------------------------------------
2935 // custom log target
2936 // ----------------------------------------------------------------------------
2938 class MyLogGui
: public wxLogGui
2941 virtual void DoShowSingleLogMessage(const wxString
& message
,
2942 const wxString
& title
,
2945 wxMessageDialog
dlg(NULL
, message
, title
,
2946 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2947 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2948 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2953 wxLog
*MyAppTraits::CreateLogTarget()
2955 return new MyLogGui
;