1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
6 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "../sample.xpm"
25 #include "wx/apptrait.h"
26 #include "wx/datetime.h"
27 #include "wx/filename.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"
35 #include "wx/modalhook.h"
38 #include "wx/richmsgdlg.h"
39 #endif // wxUSE_RICHMSGDLG
42 #include "wx/colordlg.h"
43 #endif // wxUSE_COLOURDLG
46 #include "wx/choicdlg.h"
47 #endif // wxUSE_CHOICEDLG
49 #include "wx/rearrangectrl.h"
51 #if wxUSE_STARTUP_TIPS
52 #include "wx/tipdlg.h"
53 #endif // wxUSE_STARTUP_TIPS
56 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
57 #include "wx/datetime.h" // wxDateTime
60 #include "wx/progdlg.h"
61 #endif // wxUSE_PROGRESSDLG
64 #include "wx/aboutdlg.h"
66 // these headers are only needed for custom about dialog
67 #include "wx/statline.h"
68 #include "wx/generic/aboutdlgg.h"
69 #endif // wxUSE_ABOUTDLG
72 #include "wx/busyinfo.h"
73 #endif // wxUSE_BUSYINFO
76 #include "wx/numdlg.h"
77 #endif // wxUSE_NUMBERDLG
80 #include "wx/filedlg.h"
81 #endif // wxUSE_FILEDLG
84 #include "wx/dirdlg.h"
85 #endif // wxUSE_DIRDLG
88 #include "wx/fontdlg.h"
89 #endif // wxUSE_FONTDLG
92 #include "wx/fdrepdlg.h"
93 #endif // wxUSE_FINDREPLDLG
96 #include "wx/infobar.h"
97 #endif // wxUSE_INFOBAR
99 #include "wx/spinctrl.h"
100 #include "wx/propdlg.h"
104 #if USE_COLOURDLG_GENERIC
105 #include "wx/generic/colrdlgg.h"
106 #endif // USE_COLOURDLG_GENERIC
108 #if USE_DIRDLG_GENERIC
109 #include "wx/generic/dirdlgg.h"
110 #endif // USE_DIRDLG_GENERIC
112 #if USE_FILEDLG_GENERIC
113 #include "wx/generic/filedlgg.h"
114 #endif // USE_FILEDLG_GENERIC
116 #if USE_FONTDLG_GENERIC
117 #include "wx/generic/fontdlgg.h"
118 #endif // USE_FONTDLG_GENERIC
122 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
123 EVT_PAINT(MyCanvas::OnPaint
)
128 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
130 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
131 EVT_MENU(DIALOGS_MESSAGE_BOX_WINDOW_MODAL
, MyFrame::MessageBoxWindowModal
)
132 EVT_MENU(DIALOGS_MESSAGE_DIALOG
, MyFrame::MessageBoxDialog
)
133 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
134 #endif // wxUSE_MSGDLG
136 EVT_MENU(DIALOGS_RICH_MESSAGE_DIALOG
, MyFrame::RichMessageDialog
)
137 #endif // wxUSE_RICHMSGDLG
139 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
140 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
141 #endif // wxUSE_COLOURDLG
144 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
145 #endif // wxUSE_FONTDLG
148 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
149 #endif // wxUSE_LOG_DIALOG
151 EVT_MENU(DIALOGS_INFOBAR_SIMPLE
, MyFrame::InfoBarSimple
)
152 EVT_MENU(DIALOGS_INFOBAR_ADVANCED
, MyFrame::InfoBarAdvanced
)
153 #endif // wxUSE_INFOBAR
156 EVT_MENU(DIALOGS_LINE_ENTRY
, MyFrame::LineEntry
)
157 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
158 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
159 #endif // wxUSE_TEXTDLG
162 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
163 #endif // wxUSE_NUMBERDLG
166 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
167 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
168 #endif // wxUSE_CHOICEDLG
170 #if wxUSE_REARRANGECTRL
171 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
172 #endif // wxUSE_REARRANGECTRL
175 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
176 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
177 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
178 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
179 #endif // wxUSE_FILEDLG
181 #if USE_FILEDLG_GENERIC
182 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
183 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
184 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
185 #endif // USE_FILEDLG_GENERIC
188 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
189 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
190 #endif // wxUSE_DIRDLG
192 #if USE_MODAL_PRESENTATION
193 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
194 #endif // USE_MODAL_PRESENTATION
195 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
196 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
197 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
199 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
200 #endif // wxUSE_MINIFRAME
201 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
203 #if wxUSE_STARTUP_TIPS
204 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
205 #endif // wxUSE_STARTUP_TIPS
207 #if USE_FONTDLG_GENERIC
208 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
209 #endif // USE_FONTDLG_GENERIC
211 #if USE_DIRDLG_GENERIC
212 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
213 #endif // wxMSW || wxMAC
215 #if USE_COLOURDLG_GENERIC
216 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
217 #endif // USE_COLOURDLG_GENERIC
219 #if wxUSE_PROGRESSDLG
220 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
221 #endif // wxUSE_PROGRESSDLG
224 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
225 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
226 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
227 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
228 #endif // wxUSE_ABOUTDLG
231 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
232 #endif // wxUSE_BUSYINFO
234 #if wxUSE_FINDREPLDLG
235 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
236 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
238 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
239 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
240 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
241 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
242 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
243 #endif // wxUSE_FINDREPLDLG
245 #if USE_SETTINGS_DIALOG
246 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
247 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
248 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
249 #endif // USE_SETTINGS_DIALOG
251 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
252 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
253 EVT_MENU(DIALOGS_MODAL_HOOK
, MyFrame::OnModalHook
)
255 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
256 #if wxUSE_NOTIFICATION_MESSAGE
257 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
258 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
259 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
260 #endif // wxUSE_NOTIFICATION_MESSAGE
262 #if wxUSE_RICHTOOLTIP
263 EVT_MENU(DIALOGS_RICHTIP_DIALOG
, MyFrame::OnRichTipDialog
)
264 #endif // wxUSE_RICHTOOLTIP
266 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
269 #if USE_MODAL_PRESENTATION
271 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
272 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
275 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
276 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
277 EVT_CLOSE(MyModelessDialog::OnClose
)
280 #endif // USE_MODAL_PRESENTATION
282 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
283 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
284 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
287 #if wxUSE_CMDLINE_PARSER
289 #include "wx/cmdline.h"
291 static const char *PROGRESS_SWITCH
= "progress";
293 void MyApp::OnInitCmdLine(wxCmdLineParser
& parser
)
295 wxApp::OnInitCmdLine(parser
);
297 parser
.AddOption("", PROGRESS_SWITCH
,
298 "Style for the startup progress dialog (wxPD_XXX)",
299 wxCMD_LINE_VAL_NUMBER
);
302 bool MyApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
304 if ( !wxApp::OnCmdLineParsed(parser
) )
307 parser
.Found(PROGRESS_SWITCH
, &m_startupProgressStyle
);
312 #endif // wxUSE_CMDLINE_PARSER
314 // `Main program' equivalent, creating windows and returning main app frame
317 if ( !wxApp::OnInit() )
320 #if wxUSE_PROGRESSDLG
321 if ( m_startupProgressStyle
!= -1 )
323 // Show a test progress dialog before the main event loop is started:
324 // it should still work.
325 const int PROGRESS_COUNT
= 100;
328 "Progress in progress",
329 "Please wait, starting...",
332 m_startupProgressStyle
334 for ( int i
= 0; i
<= PROGRESS_COUNT
; i
++ )
336 if ( !dlg
.Update(i
) )
342 #endif // wxUSE_PROGRESSDLG
345 wxInitAllImageHandlers();
348 // Create the main frame window
349 MyFrame
*frame
= new MyFrame(wxT("wxWidgets dialogs example"));
352 wxMenu
*menuDlg
= new wxMenu
;
354 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
355 menuDlg
->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL
, wxT("Window-Modal Message box "));
356 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
358 menuDlg
->Append(DIALOGS_RICH_MESSAGE_DIALOG
, wxT("Rich message dialog"));
359 #endif // wxUSE_RICHMSGDLG
362 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
364 wxMenu
*choices_menu
= new wxMenu
;
367 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
368 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
369 #endif // wxUSE_COLOURDLG
372 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
373 #endif // wxUSE_FONTDLG
376 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
377 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
378 #endif // wxUSE_CHOICEDLG
380 #if wxUSE_REARRANGECTRL
381 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
382 #endif // wxUSE_REARRANGECTRL
384 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
385 choices_menu
->AppendSeparator();
386 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
388 #if USE_COLOURDLG_GENERIC
389 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
390 #endif // USE_COLOURDLG_GENERIC
392 #if USE_FONTDLG_GENERIC
393 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
394 #endif // USE_FONTDLG_GENERIC
396 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
397 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
400 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
402 wxMenu
*entry_menu
= new wxMenu
;
405 entry_menu
->Append(DIALOGS_LINE_ENTRY
, wxT("Single line &entry\tCtrl-E"));
406 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Multi line text &entry\tShift-Ctrl-E"));
407 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
408 #endif // wxUSE_TEXTDLG
411 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
412 #endif // wxUSE_NUMBERDLG
414 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
416 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
421 wxMenu
*filedlg_menu
= new wxMenu
;
422 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
423 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
424 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
425 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
427 #if USE_FILEDLG_GENERIC
428 filedlg_menu
->AppendSeparator();
429 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
430 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
431 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
432 #endif // USE_FILEDLG_GENERIC
434 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
436 #endif // wxUSE_FILEDLG
439 wxMenu
*dir_menu
= new wxMenu
;
441 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
442 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
443 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
445 #if USE_DIRDLG_GENERIC
446 dir_menu
->AppendSeparator();
447 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
448 #endif // USE_DIRDLG_GENERIC
450 #endif // wxUSE_DIRDLG
453 #if wxUSE_STARTUP_TIPS || \
454 wxUSE_PROGRESSDLG || \
456 wxUSE_LOG_DIALOG || \
459 wxMenu
*info_menu
= new wxMenu
;
461 #if wxUSE_STARTUP_TIPS
462 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
463 #endif // wxUSE_STARTUP_TIPS
465 #if wxUSE_PROGRESSDLG
466 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
467 #endif // wxUSE_PROGRESSDLG
470 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
471 #endif // wxUSE_BUSYINFO
474 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
475 #endif // wxUSE_LOG_DIALOG
478 info_menu
->Append(DIALOGS_INFOBAR_SIMPLE
, "Simple &info bar\tCtrl-I");
479 info_menu
->Append(DIALOGS_INFOBAR_ADVANCED
, "&Advanced info bar\tShift-Ctrl-I");
480 #endif // wxUSE_INFOBAR
483 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
484 wxT("&wxWidgets information\tCtrl-W"));
485 #endif // wxUSE_MSGDLG
487 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
489 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
492 #if wxUSE_FINDREPLDLG
493 wxMenu
*find_menu
= new wxMenu
;
494 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
495 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
496 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
497 #endif // wxUSE_FINDREPLDLG
499 wxMenu
*dialogs_menu
= new wxMenu
;
500 #if USE_MODAL_PRESENTATION
501 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tShift-Ctrl-W"));
502 #endif // USE_MODAL_PRESENTATION
503 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tShift-Ctrl-Z"));
504 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
505 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
507 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
508 #endif // wxUSE_MINIFRAME
509 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
510 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
512 #if USE_SETTINGS_DIALOG
513 wxMenu
*sheet_menu
= new wxMenu
;
514 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
515 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
517 if (wxPlatformIs(wxPORT_MAC
))
518 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
521 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
524 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
525 #endif // USE_SETTINGS_DIALOG
527 wxMenu
*menuNotif
= new wxMenu
;
528 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
529 #if wxUSE_NOTIFICATION_MESSAGE
530 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
531 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
532 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
533 #endif // wxUSE_NOTIFICATION_MESSAGE
534 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
536 #if wxUSE_RICHTOOLTIP
537 menuDlg
->Append(DIALOGS_RICHTIP_DIALOG
, "Rich &tooltip dialog...\tCtrl-H");
538 menuDlg
->AppendSeparator();
539 #endif // wxUSE_RICHTOOLTIP
541 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
542 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
543 menuDlg
->AppendCheckItem(DIALOGS_MODAL_HOOK
, "Enable modal dialog hook");
545 menuDlg
->AppendSeparator();
546 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
549 wxMenu
*menuHelp
= new wxMenu
;
550 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
551 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
552 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
553 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
554 #endif // wxUSE_ABOUTDLG
556 wxMenu
* editMenu
= new wxMenu
;
557 editMenu
->Append(wxID_UNDO
, _("&Undo\tCtrl+Z"));
558 editMenu
->Append(wxID_REDO
, _("&Redo\tCtrl+Y"));
559 editMenu
->AppendSeparator();
560 editMenu
->Append(wxID_CUT
, _("Cu&t\tCtrl+X"));
561 editMenu
->Append(wxID_COPY
, _("&Copy\tCtrl+C"));
562 editMenu
->Append(wxID_PASTE
, _("&Paste\tCtrl+V"));
563 editMenu
->Append(wxID_CLEAR
, _("&Delete"));
565 editMenu
->AppendSeparator();
566 editMenu
->Append(wxID_SELECTALL
, _("Select All\tCtrl+A"));
568 wxMenuBar
*menubar
= new wxMenuBar
;
569 menubar
->Append(menuDlg
, wxT("&Dialogs"));
571 menubar
->Append(editMenu
, wxT("&Edit"));
574 menubar
->Append(menuHelp
, wxT("&Help"));
575 #endif // wxUSE_ABOUTDLG
577 frame
->SetMenuBar(menubar
);
579 frame
->Centre(wxBOTH
);
585 // My frame constructor
586 MyFrame::MyFrame(const wxString
& title
)
587 : wxFrame(NULL
, wxID_ANY
, title
)
589 SetIcon(wxICON(sample
));
591 #if USE_MODAL_PRESENTATION
592 m_dialog
= (MyModelessDialog
*)NULL
;
593 #endif // USE_MODAL_PRESENTATION
595 #if wxUSE_FINDREPLDLG
601 m_clrData
.SetChooseFull(true);
602 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
604 unsigned char n
= i
*16;
605 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
607 #endif // wxUSE_COLOURDLG
609 #if wxUSE_NOTIFICATION_MESSAGE
611 #endif // wxUSE_NOTIFICATION_MESSAGE
615 #endif // wxUSE_STATUSBAR
617 m_canvas
= new MyCanvas(this);
620 // an info bar can be created very simply and used without any extra effort
621 m_infoBarSimple
= new wxInfoBar(this);
623 // or it can also be customized by
624 m_infoBarAdvanced
= new wxInfoBar(this);
626 // ... adding extra buttons (but more than two will usually be too many)
627 m_infoBarAdvanced
->AddButton(wxID_UNDO
);
628 m_infoBarAdvanced
->AddButton(wxID_REDO
);
630 m_infoBarAdvanced
->Connect(wxID_REDO
, wxEVT_BUTTON
,
631 wxCommandEventHandler(MyFrame::OnInfoBarRedo
),
635 // adding and removing a button immediately doesn't make sense here, of
636 // course, it's done just to show that it is possible
637 m_infoBarAdvanced
->AddButton(wxID_EXIT
);
638 m_infoBarAdvanced
->RemoveButton(wxID_EXIT
);
640 // ... changing the colours and/or fonts
641 m_infoBarAdvanced
->SetOwnBackgroundColour(0xc8ffff);
642 m_infoBarAdvanced
->SetFont(GetFont().Bold().Larger());
644 // ... and changing the effect (only does anything under MSW currently)
645 m_infoBarAdvanced
->SetShowHideEffects(wxSHOW_EFFECT_EXPAND
,
646 wxSHOW_EFFECT_EXPAND
);
647 m_infoBarAdvanced
->SetEffectDuration(1500);
650 // to use the info bars we need to use sizer for the window layout
651 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
652 sizer
->Add(m_infoBarSimple
, wxSizerFlags().Expand());
653 sizer
->Add(m_canvas
, wxSizerFlags(1).Expand());
654 sizer
->Add(m_infoBarAdvanced
, wxSizerFlags().Expand());
657 // final touch: under MSW the info bars are shown progressively and parts
658 // of the parent window can be seen during the process, so use the same
659 // background colour for our background as for the canvas window which
660 // covers our entire client area to avoid jarring colour jumps
661 SetOwnBackgroundColour(m_canvas
->GetBackgroundColour());
662 #endif // wxUSE_INFOBAR
665 // Test MSW-specific function allowing to access the "system" menu.
666 wxMenu
* const menu
= MSWGetSystemMenu();
669 menu
->AppendSeparator();
671 // The ids of the menu commands in MSW system menu must be multiple of
672 // 16 so we can't use DIALOGS_ABOUTDLG_SIMPLE here because it might not
673 // satisfy this condition and need to define and connect a separate id.
674 static const int DIALOGS_SYSTEM_ABOUT
= 0x4010;
676 menu
->Append(DIALOGS_SYSTEM_ABOUT
, "&About");
677 Connect(DIALOGS_SYSTEM_ABOUT
, wxEVT_MENU
,
678 wxCommandEventHandler(MyFrame::ShowSimpleAboutDialog
));
685 #if wxUSE_NOTIFICATION_MESSAGE
687 #endif // wxUSE_NOTIFICATION_MESSAGE
692 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
694 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
696 wxColourDialog
dialog(this, &m_clrData
);
697 dialog
.SetTitle(_("Please choose the background colour"));
698 if ( dialog
.ShowModal() == wxID_OK
)
700 m_clrData
= dialog
.GetColourData();
701 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
702 m_canvas
->ClearBackground();
707 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
709 wxColour clr
= wxGetColourFromUser
712 m_canvas
->GetForegroundColour(),
713 "Please choose the foreground colour"
717 m_canvas
->SetForegroundColour(clr
);
720 //else: dialog cancelled by user
723 #endif // wxUSE_COLOURDLG
726 #if USE_COLOURDLG_GENERIC
727 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
729 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
731 //FIXME:TODO:This has no effect...
732 m_clrData
.SetChooseFull(true);
734 for (int i
= 0; i
< 16; i
++)
737 (unsigned char)(i
*16),
738 (unsigned char)(i
*16),
739 (unsigned char)(i
*16)
741 m_clrData
.SetCustomColour(i
, colour
);
744 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
745 if (dialog
->ShowModal() == wxID_OK
)
747 m_clrData
= dialog
->GetColourData();
748 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
749 m_canvas
->ClearBackground();
754 #endif // USE_COLOURDLG_GENERIC
757 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
760 data
.SetInitialFont(m_canvas
->GetFont());
761 data
.SetColour(m_canvas
->GetForegroundColour());
763 // you might also do this:
765 // wxFontDialog dialog;
766 // if ( !dialog.Create(this, data) { ... error ... }
768 wxFontDialog
dialog(this, data
);
770 if (dialog
.ShowModal() == wxID_OK
)
772 wxFontData retData
= dialog
.GetFontData();
773 m_canvas
->SetFont(retData
.GetChosenFont());
774 m_canvas
->SetForegroundColour(retData
.GetColour());
777 //else: cancelled by the user, don't change the font
779 #endif // wxUSE_FONTDLG
781 #if USE_FONTDLG_GENERIC
782 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
785 data
.SetInitialFont(m_canvas
->GetFont());
786 data
.SetColour(m_canvas
->GetForegroundColour());
788 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
789 if (dialog
->ShowModal() == wxID_OK
)
791 wxFontData retData
= dialog
->GetFontData();
792 m_canvas
->SetFont(retData
.GetChosenFont());
793 m_canvas
->SetForegroundColour(retData
.GetColour());
798 #endif // USE_FONTDLG_GENERIC
801 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
803 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
804 // being flushed -- test it
807 wxLogMessage(wxT("This is some message - everything is ok so far."));
808 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
809 wxLogWarning(wxT("And then something went wrong!"));
811 // and if ~wxBusyCursor doesn't do it, then call it manually
815 wxLogError(wxT("Intermediary error handler decided to abort."));
816 wxLogError(wxT("The top level caller detected an unrecoverable error."));
818 wxLog::FlushActive();
820 wxLogMessage(wxT("And this is the same dialog but with only one message."));
822 #endif // wxUSE_LOG_DIALOG
826 void MyFrame::InfoBarSimple(wxCommandEvent
& WXUNUSED(event
))
828 static int s_count
= 0;
829 m_infoBarSimple
->ShowMessage
831 wxString::Format("Message #%d in the info bar.", ++s_count
)
835 void MyFrame::InfoBarAdvanced(wxCommandEvent
& WXUNUSED(event
))
837 m_infoBarAdvanced
->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING
);
840 void MyFrame::OnInfoBarRedo(wxCommandEvent
& WXUNUSED(event
))
842 m_infoBarAdvanced
->ShowMessage("Still no, sorry again.", wxICON_ERROR
);
845 #endif // wxUSE_INFOBAR
849 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
851 wxMessageDialog
dialog(this,
852 "This is a message box\n"
853 "This is a long, long string to test out if the message box "
854 "is laid out properly.",
857 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
861 if ( dialog
.SetYesNoCancelLabels
868 extmsg
= "This platform supports custom button labels,\n"
869 "so you should see the descriptive labels below.";
873 extmsg
= "Custom button labels are not supported on this platform,\n"
874 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
876 dialog
.SetExtendedMessage(extmsg
);
878 switch ( dialog
.ShowModal() )
881 wxLogStatus(wxT("You pressed \"Yes\""));
885 wxLogStatus(wxT("You pressed \"No\""));
889 wxLogStatus(wxT("You pressed \"Cancel\""));
893 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
897 void MyFrame::MessageBoxWindowModal(wxCommandEvent
& WXUNUSED(event
))
899 wxMessageDialog
* dialog
= new wxMessageDialog(this,
900 "This is a message box\n"
901 "This is a long, long string to test out if the message box "
902 "is laid out properly.",
905 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
909 if ( dialog
->SetYesNoCancelLabels
916 extmsg
= "This platform supports custom button labels,\n"
917 "so you should see the descriptive labels below.";
921 extmsg
= "Custom button labels are not supported on this platform,\n"
922 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
924 dialog
->SetExtendedMessage(extmsg
);
925 dialog
->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed
), NULL
, this );
926 dialog
->ShowWindowModal();
929 void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
)
931 wxDialog
* dialog
= event
.GetDialog();
932 switch ( dialog
->GetReturnCode() )
935 wxLogStatus(wxT("You pressed \"Yes\""));
939 wxLogStatus(wxT("You pressed \"No\""));
943 wxLogStatus(wxT("You pressed \"Cancel\""));
947 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
952 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
954 TestMessageBoxDialog
dlg(this);
959 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
961 ::wxInfoMessageBox(this);
963 #endif // wxUSE_MSGDLG
966 void MyFrame::RichMessageDialog(wxCommandEvent
& WXUNUSED(event
))
968 TestRichMessageDialog
dlg(this);
972 #endif // wxUSE_RICHMSGDLG
975 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
977 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
978 wxT("Even two rows of text."),
979 wxT("Enter a number:"), wxT("Numeric input test"),
986 msg
= wxT("Invalid number entered or dialog cancelled.");
991 msg
.Printf(wxT("You've entered %lu"), res
);
992 icon
= wxICON_INFORMATION
;
995 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
997 #endif // wxUSE_NUMBERDLG
1000 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
1002 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
1003 wxT("Password entry dialog"),
1008 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
1009 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
1013 void MyFrame::LineEntry(wxCommandEvent
& WXUNUSED(event
))
1015 wxTextEntryDialog
dialog(this,
1016 wxT("This is a small sample\n")
1017 wxT("A long, long string to test out the text entrybox"),
1018 wxT("Please enter a string"),
1019 wxT("Default value"),
1022 if (dialog
.ShowModal() == wxID_OK
)
1024 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
1028 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
1030 wxTextEntryDialog
dialog(this, "You can enter a multiline string here.",
1031 "Please enter some text",
1032 "First line\nSecond one\nAnd another one too",
1033 wxOK
| wxCANCEL
| wxTE_MULTILINE
);
1035 if (dialog
.ShowModal() == wxID_OK
)
1037 wxMessageBox(dialog
.GetValue(), wxT("Got text"), wxOK
| wxICON_INFORMATION
, this);
1040 #endif // wxUSE_TEXTDLG
1043 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
1045 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
1047 wxSingleChoiceDialog
dialog(this,
1048 wxT("This is a small sample\n")
1049 wxT("A single-choice convenience dialog"),
1050 wxT("Please select a value"),
1051 WXSIZEOF(choices
), choices
);
1053 dialog
.SetSelection(2);
1055 if (dialog
.ShowModal() == wxID_OK
)
1057 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
1058 dialog2
.ShowModal();
1062 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
1064 const wxString choices
[] =
1066 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
1067 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
1068 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
1071 wxArrayInt selections
;
1072 const int count
= wxGetSelectedChoices(selections
,
1073 wxT("This is a small sample\n")
1074 wxT("A multi-choice convenience dialog"),
1075 wxT("Please select a value"),
1076 WXSIZEOF(choices
), choices
,
1083 msg
= wxT("You did not select any items");
1087 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
1088 for ( int n
= 0; n
< count
; n
++ )
1090 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
1091 (unsigned)n
, (unsigned)selections
[n
],
1092 choices
[selections
[n
]].c_str());
1099 #endif // wxUSE_CHOICEDLG
1101 #if wxUSE_REARRANGECTRL
1102 // custom rearrange dialog: it adds the possibility to rename an item to the
1103 // base class functionality
1104 class MyRearrangeDialog
: public wxRearrangeDialog
1107 MyRearrangeDialog(wxWindow
*parent
,
1109 wxArrayString
& labels
,
1110 wxArrayString
& labelsOrig
)
1114 "Configure the columns shown:",
1115 "wxRearrangeDialog example",
1121 m_labelsOrig(labelsOrig
)
1123 m_sel
= wxNOT_FOUND
;
1125 wxPanel
* const panel
= new wxPanel(this);
1126 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1128 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
1129 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
1131 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
1132 wxDefaultPosition
, wxDefaultSize
,
1133 wxTE_PROCESS_ENTER
);
1134 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
1136 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
1137 wxSizerFlags().Centre());
1139 panel
->SetSizer(sizer
);
1141 // call this first to ensure that the controls have a reasonable best
1142 // size before they're added
1143 DoUpdateExtraControls(GetList()->GetSelection());
1145 AddExtraControls(panel
);
1148 // another customization not directly supported by the dialog: add a
1150 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
1151 wxCHECK_RET( btnOk
, "no Ok button?" );
1153 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
1154 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
1156 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
1157 wxSizerFlags().Border(wxLEFT
));
1160 // call this instead of ShowModal() to update order and labels array in
1161 // case the dialog was not cancelled
1164 switch ( ShowModal() )
1170 m_order
= GetOrder();
1174 // order already reset
1182 void OnSelChange(wxCommandEvent
& event
)
1184 DoUpdateExtraControls(event
.GetInt());
1187 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
1189 event
.Enable( CanRename() );
1192 void OnRename(wxCommandEvent
& WXUNUSED(event
))
1197 m_labels
[m_sel
] = m_text
->GetValue();
1198 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
1201 void OnReset(wxCommandEvent
& WXUNUSED(event
))
1203 // in a real program we should probably ask if the user really wants to
1204 // do this but here we just go ahead and reset all columns labels and
1205 // their order without confirmation
1206 const unsigned count
= m_order
.size();
1207 for ( unsigned n
= 0; n
< count
; n
++ )
1210 m_labels
[n
] = m_labelsOrig
[n
];
1213 EndModal(wxID_RESET
);
1216 bool CanRename() const
1218 // only allow renaming if the user modified the currently selected item
1219 // text (which presupposes that we do have a current item)
1220 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
1223 void DoUpdateExtraControls(int sel
)
1227 if ( m_sel
== wxNOT_FOUND
)
1229 m_labelOrig
->SetLabel("<no selection>");
1233 else // have valid item
1235 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
1237 m_text
->SetValue(m_labels
[m_sel
]);
1241 wxArrayInt
& m_order
;
1242 wxArrayString
& m_labels
,
1246 wxStaticText
*m_labelOrig
;
1249 DECLARE_EVENT_TABLE()
1250 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
1253 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
1254 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
1256 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
1258 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
1259 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
1260 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
1263 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
1265 // the arrays are static so that we preserve the items order between calls
1267 static wxArrayInt s_order
;
1268 static wxArrayString s_labels
,
1271 // initialize them on the first call
1272 if ( s_labelsOrig
.empty() )
1274 static const struct ItemInfo
1277 const char *labelOrig
;
1281 { "File name", "Name", 0 },
1282 { "File type", "Ext", 1 },
1283 { "Size", "Size", 2 },
1284 { "Creation time", "Ctime", ~3 }, // negated so hidden
1285 { "Last accessed", "Atime", ~4 },
1286 { "Last modified", "Mtime", 5 },
1289 s_order
.reserve(WXSIZEOF(items
));
1290 s_labels
.reserve(WXSIZEOF(items
));
1291 s_labelsOrig
.reserve(WXSIZEOF(items
));
1292 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1294 const ItemInfo
& item
= items
[n
];
1295 s_order
.push_back(item
.order
);
1296 s_labels
.push_back(item
.label
);
1297 s_labelsOrig
.push_back(item
.labelOrig
);
1301 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1302 if ( !dlg
.Rearrange() )
1306 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1308 columns
+= wxString::Format("\n %u: ", n
);
1309 int idx
= s_order
[n
];
1312 columns
+= "[hidden] ";
1316 columns
+= s_labels
[idx
];
1317 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1319 columns
+= wxString::Format(" (original label: \"%s\")",
1324 wxLogMessage("The columns order now is:%s", columns
);
1326 #endif // wxUSE_REARRANGECTRL
1330 // panel with custom controls for file dialog
1331 class MyExtraPanel
: public wxPanel
1334 MyExtraPanel(wxWindow
*parent
);
1335 wxString
GetInfo() const
1337 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1341 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1342 void OnUpdateLabelUI(wxUpdateUIEvent
& event
)
1344 wxFileDialog
* const dialog
= wxStaticCast(GetParent(), wxFileDialog
);
1345 const wxString fn
= dialog
->GetCurrentlySelectedFilename();
1350 else if ( wxFileName::FileExists(fn
) )
1352 else if ( wxFileName::DirExists(fn
) )
1355 msg
= "Something else";
1357 event
.SetText(msg
+ " selected");
1362 wxStaticText
*m_label
;
1365 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1368 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1369 m_btn
->Enable(false);
1370 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1371 m_cb
->Connect(wxEVT_CHECKBOX
,
1372 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1373 m_label
= new wxStaticText(this, wxID_ANY
, "Nothing selected");
1374 m_label
->Connect(wxEVT_UPDATE_UI
,
1375 wxUpdateUIEventHandler(MyExtraPanel::OnUpdateLabelUI
),
1378 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1379 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1380 sizerTop
->AddStretchSpacer();
1381 sizerTop
->Add(m_btn
, wxSizerFlags().Centre().Border());
1382 sizerTop
->AddStretchSpacer();
1383 sizerTop
->Add(m_label
, wxSizerFlags().Centre().Border());
1385 SetSizerAndFit(sizerTop
);
1388 // a static method can be used instead of a function with most of compilers
1389 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1391 return new MyExtraPanel(parent
);
1394 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1399 wxT("Testing open file dialog"),
1403 wxT("C++ files (*.cpp)|*.cpp")
1405 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1409 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1410 dialog
.CentreOnParent();
1411 dialog
.SetDirectory(wxGetHomeDir());
1413 if (dialog
.ShowModal() == wxID_OK
)
1416 wxWindow
* const extra
= dialog
.GetExtraControl();
1417 info
.Printf(wxT("Full file name: %s\n")
1420 wxT("Custom window: %s"),
1421 dialog
.GetPath().c_str(),
1422 dialog
.GetDirectory().c_str(),
1423 dialog
.GetFilename().c_str(),
1424 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1425 : wxString("None"));
1426 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1427 dialog2
.ShowModal();
1431 // this shows how to take advantage of specifying a default extension in the
1432 // call to wxFileSelector: it is remembered after each new call and the next
1433 // one will use it by default
1434 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1436 static wxString s_extDef
;
1437 wxString path
= wxFileSelector(
1438 wxT("Select the file to load"),
1439 wxEmptyString
, wxEmptyString
,
1443 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1444 wxFileSelectorDefaultWildcardStr
,
1445 wxFileSelectorDefaultWildcardStr
1447 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1454 // it is just a sample, would use wxSplitPath in real program
1455 s_extDef
= path
.AfterLast(wxT('.'));
1457 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1461 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1463 wxString wildcards
=
1465 wxT("C++ files (*.cpp)|*.cpp");
1469 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1470 wxFileSelectorDefaultWildcardStr
,
1471 wxFileSelectorDefaultWildcardStr
1474 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1475 wxEmptyString
, wxEmptyString
, wildcards
,
1476 wxFD_OPEN
|wxFD_MULTIPLE
);
1478 if (dialog
.ShowModal() == wxID_OK
)
1480 wxArrayString paths
, filenames
;
1482 dialog
.GetPaths(paths
);
1483 dialog
.GetFilenames(filenames
);
1486 size_t count
= paths
.GetCount();
1487 for ( size_t n
= 0; n
< count
; n
++ )
1489 s
.Printf(wxT("File %d: %s (%s)\n"),
1490 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1494 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1497 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1498 dialog2
.ShowModal();
1502 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1504 wxFileDialog
dialog(this,
1505 wxT("Testing save file dialog"),
1507 wxT("myletter.doc"),
1508 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1509 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1511 dialog
.SetFilterIndex(1);
1513 if (dialog
.ShowModal() == wxID_OK
)
1515 wxLogMessage(wxT("%s, filter %d"),
1516 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1519 #endif // wxUSE_FILEDLG
1521 #if USE_FILEDLG_GENERIC
1522 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1524 wxGenericFileDialog dialog
1527 wxT("Testing open file dialog"),
1530 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1533 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1534 dialog
.SetDirectory(wxGetHomeDir());
1536 if (dialog
.ShowModal() == wxID_OK
)
1539 info
.Printf(wxT("Full file name: %s\n")
1542 dialog
.GetPath().c_str(),
1543 dialog
.GetDirectory().c_str(),
1544 dialog
.GetFilename().c_str());
1545 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1546 dialog2
.ShowModal();
1550 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1552 // On PocketPC you can disable OK-only dialogs policy using system option
1553 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1554 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1556 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1557 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1558 wxEmptyString
, wxEmptyString
, wildcards
,
1561 if (dialog
.ShowModal() == wxID_OK
)
1563 wxArrayString paths
, filenames
;
1565 dialog
.GetPaths(paths
);
1566 dialog
.GetFilenames(filenames
);
1569 size_t count
= paths
.GetCount();
1570 for ( size_t n
= 0; n
< count
; n
++ )
1572 s
.Printf(wxT("File %d: %s (%s)\n"),
1573 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1577 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1580 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1581 dialog2
.ShowModal();
1584 // restore system option
1585 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1588 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1590 wxGenericFileDialog
dialog(this,
1591 wxT("Testing save file dialog"),
1593 wxT("myletter.doc"),
1594 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1595 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1597 dialog
.SetFilterIndex(1);
1599 if (dialog
.ShowModal() == wxID_OK
)
1601 wxLogMessage(wxT("%s, filter %d"),
1602 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1605 #endif // USE_FILEDLG_GENERIC
1608 void MyFrame::DoDirChoose(int style
)
1610 // pass some initial dir to wxDirDialog
1612 wxGetHomeDir(&dirHome
);
1614 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1616 if (dialog
.ShowModal() == wxID_OK
)
1618 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1622 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1624 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1627 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1629 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1631 #endif // wxUSE_DIRDLG
1633 #if USE_DIRDLG_GENERIC
1634 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1636 // pass some initial dir to wxDirDialog
1638 wxGetHomeDir(&dirHome
);
1640 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1642 if (dialog
.ShowModal() == wxID_OK
)
1644 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1645 dialog2
.ShowModal();
1648 #endif // USE_DIRDLG_GENERIC
1650 #if USE_MODAL_PRESENTATION
1651 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1653 MyModalDialog
dlg(this);
1656 #endif // USE_MODAL_PRESENTATION
1658 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1660 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1666 m_dialog
= new MyModelessDialog(this);
1669 m_dialog
->Show(true);
1673 // If m_dialog is NULL, then possibly the system
1674 // didn't report the checked menu item status correctly.
1675 // It should be true just after the menu item was selected,
1676 // if there was no modeless dialog yet.
1678 wxASSERT( m_dialog
!= NULL
);
1684 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1686 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1687 wxDefaultPosition
, wxSize(200, 100));
1688 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1689 dlg
.CentreOnScreen();
1693 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1695 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1696 wxDefaultPosition
, wxSize(200, 100));
1697 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1698 dlg
.CentreOnParent();
1703 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1705 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1706 wxDefaultPosition
, wxSize(300, 100),
1707 wxCAPTION
| wxCLOSE_BOX
);
1708 new wxStaticText(frame
,
1710 wxT("Mini frames have slightly different appearance"),
1712 new wxStaticText(frame
,
1714 wxT("from the normal frames but that's the only difference."),
1717 frame
->CentreOnParent();
1720 #endif // wxUSE_MINIFRAME
1722 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1724 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1725 wxDefaultPosition
, wxSize(300, 100),
1726 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1727 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1731 #if wxUSE_STARTUP_TIPS
1732 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1734 static size_t s_index
= (size_t)-1;
1736 if ( s_index
== (size_t)-1 )
1740 // this is completely bogus, we don't know how many lines are there
1741 // in the file, but who cares, it's a demo only...
1742 s_index
= rand() % 5;
1745 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1747 bool showAtStartup
= wxShowTip(this, tipProvider
);
1749 if ( showAtStartup
)
1751 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1752 wxOK
| wxICON_INFORMATION
, this);
1755 s_index
= tipProvider
->GetCurrentTip();
1758 #endif // wxUSE_STARTUP_TIPS
1760 #if USE_SETTINGS_DIALOG
1761 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1763 SettingsDialog
dialog(this, event
.GetId());
1766 #endif // USE_SETTINGS_DIALOG
1768 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1770 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1774 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1777 #if wxUSE_NOTIFICATION_MESSAGE
1779 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1781 // Notice that the notification remains shown even after the
1782 // wxNotificationMessage object itself is destroyed so we can show simple
1783 // notifications using temporary objects.
1784 if ( !wxNotificationMessage
1786 "Automatic Notification",
1787 "Nothing important has happened\n"
1788 "this notification will disappear soon."
1791 wxLogStatus("Failed to show notification message");
1794 // But it doesn't have to be a temporary, of course.
1795 wxNotificationMessage
n("Dummy Warning", "Example of a warning notification.");
1796 n
.SetFlags(wxICON_ERROR
);
1797 n
.Show(5); // Just for testing, use 5 second delay.
1800 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1804 m_notifMsg
= new wxNotificationMessage
1806 "wxWidgets Manual Notification",
1807 "You can hide this notification from the menu",
1812 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1814 wxLogStatus("Failed to show manual notification message");
1818 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1820 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1822 wxLogStatus("Failed to hide manual notification message");
1826 #endif // wxUSE_NOTIFICATION_MESSAGE
1828 #if wxUSE_RICHTOOLTIP
1830 #include "wx/richtooltip.h"
1834 class RichTipDialog
: public wxDialog
1837 RichTipDialog(wxWindow
* parent
)
1838 : wxDialog(parent
, wxID_ANY
, "wxRichToolTip Test",
1839 wxDefaultPosition
, wxDefaultSize
,
1840 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
1842 // Create the controls.
1843 m_textTitle
= new wxTextCtrl(this, wxID_ANY
, "Tooltip title");
1844 m_textBody
= new wxTextCtrl(this, wxID_ANY
, "Main tooltip text\n"
1845 "possibly on several\n"
1847 wxDefaultPosition
, wxDefaultSize
,
1849 wxButton
* btnShowText
= new wxButton(this, wxID_ANY
, "Show for &text");
1850 wxButton
* btnShowBtn
= new wxButton(this, wxID_ANY
, "Show for &button");
1852 const wxString icons
[] =
1860 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == Icon_Max
, IconMismatch
);
1861 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon choice:",
1862 wxDefaultPosition
, wxDefaultSize
,
1863 WXSIZEOF(icons
), icons
,
1864 1, wxRA_SPECIFY_ROWS
);
1865 m_icons
->SetSelection(Icon_Info
);
1867 const wxString tipKinds
[] =
1869 "&None", "Top left", "Top", "Top right",
1870 "Bottom left", "Bottom", "Bottom right", "&Auto"
1872 m_tipKinds
= new wxRadioBox(this, wxID_ANY
, "Tip &kind:",
1873 wxDefaultPosition
, wxDefaultSize
,
1874 WXSIZEOF(tipKinds
), tipKinds
,
1875 4, wxRA_SPECIFY_COLS
);
1876 m_tipKinds
->SetSelection(wxTipKind_Auto
);
1878 const wxString bgStyles
[] =
1880 "&Default", "&Solid", "&Gradient",
1882 wxCOMPILE_TIME_ASSERT( WXSIZEOF(bgStyles
) == Bg_Max
, BgMismatch
);
1883 m_bgStyles
= new wxRadioBox(this, wxID_ANY
, "Background style:",
1884 wxDefaultPosition
, wxDefaultSize
,
1885 WXSIZEOF(bgStyles
), bgStyles
,
1886 1, wxRA_SPECIFY_ROWS
);
1888 const wxString timeouts
[] = { "&None", "&Default (no delay)", "&3 seconds" };
1889 wxCOMPILE_TIME_ASSERT( WXSIZEOF(timeouts
) == Timeout_Max
, TmMismatch
);
1890 m_timeouts
= new wxRadioBox(this, wxID_ANY
, "Timeout:",
1891 wxDefaultPosition
, wxDefaultSize
,
1892 WXSIZEOF(timeouts
), timeouts
,
1893 1, wxRA_SPECIFY_ROWS
);
1894 m_timeouts
->SetSelection(Timeout_Default
);
1895 m_timeDelay
= new wxCheckBox(this, wxID_ANY
, "Delay show" );
1898 m_textBody
->SetMinSize(wxSize(300, 200));
1900 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
1901 sizer
->Add(m_textTitle
, wxSizerFlags().Expand().Border());
1902 sizer
->Add(m_textBody
, wxSizerFlags(1).Expand().Border());
1903 sizer
->Add(m_icons
, wxSizerFlags().Expand().Border());
1904 sizer
->Add(m_tipKinds
, wxSizerFlags().Centre().Border());
1905 sizer
->Add(m_bgStyles
, wxSizerFlags().Centre().Border());
1906 sizer
->Add(m_timeouts
, wxSizerFlags().Centre().Border());
1907 sizer
->Add(m_timeDelay
, wxSizerFlags().Centre().Border());
1908 wxBoxSizer
* const sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
1909 sizerBtns
->Add(btnShowText
, wxSizerFlags().Border(wxRIGHT
));
1910 sizerBtns
->Add(btnShowBtn
, wxSizerFlags().Border(wxLEFT
));
1911 sizer
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
1912 sizer
->Add(CreateStdDialogButtonSizer(wxOK
),
1913 wxSizerFlags().Expand().Border());
1914 SetSizerAndFit(sizer
);
1917 // And connect the event handlers.
1918 btnShowText
->Connect
1921 wxCommandEventHandler(RichTipDialog::OnShowTipForText
),
1929 wxCommandEventHandler(RichTipDialog::OnShowTipForBtn
),
1963 void OnShowTipForText(wxCommandEvent
& WXUNUSED(event
))
1965 DoShowTip(m_textTitle
);
1968 void OnShowTipForBtn(wxCommandEvent
& WXUNUSED(event
))
1970 DoShowTip(FindWindow(wxID_OK
));
1973 void DoShowTip(wxWindow
* win
)
1975 wxRichToolTip
tip(m_textTitle
->GetValue(), m_textBody
->GetValue());
1976 const int iconSel
= m_icons
->GetSelection();
1977 if ( iconSel
== Icon_Custom
)
1979 tip
.SetIcon(tip_xpm
);
1981 else // Use a standard icon.
1983 static const int stdIcons
[] =
1991 tip
.SetIcon(stdIcons
[iconSel
]);
1994 switch ( m_bgStyles
->GetSelection() )
2000 tip
.SetBackgroundColour(*wxLIGHT_GREY
);
2004 tip
.SetBackgroundColour(*wxWHITE
, wxColour(0xe4, 0xe5, 0xf0));
2008 int delay
= m_timeDelay
->IsChecked() ? 500 : 0;
2010 switch ( m_timeouts
->GetSelection() )
2013 // Don't call SetTimeout unnecessarily
2014 // or msw will show generic impl
2016 tip
.SetTimeout(0, delay
);
2019 case Timeout_Default
:
2023 tip
.SetTimeout(3000, delay
);
2027 tip
.SetTipKind(static_cast<wxTipKind
>(m_tipKinds
->GetSelection()));
2032 wxTextCtrl
* m_textTitle
;
2033 wxTextCtrl
* m_textBody
;
2034 wxRadioBox
* m_icons
;
2035 wxRadioBox
* m_tipKinds
;
2036 wxRadioBox
* m_bgStyles
;
2037 wxRadioBox
* m_timeouts
;
2038 wxCheckBox
* m_timeDelay
;
2041 void MyFrame::OnRichTipDialog(wxCommandEvent
& WXUNUSED(event
))
2043 RichTipDialog
dialog(this);
2047 #endif // wxUSE_RICHTOOLTIP
2049 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
2051 StdButtonSizerDialog
dialog(this);
2055 // TestDefaultAction
2057 #define ID_CATCH_LISTBOX_DCLICK 100
2058 #define ID_LISTBOX 101
2059 #define ID_DISABLE_OK 102
2060 #define ID_DISABLE_CANCEL 103
2062 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
2063 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
2064 EVT_CHECKBOX(ID_DISABLE_OK
, TestDefaultActionDialog::OnDisableOK
)
2065 EVT_CHECKBOX(ID_DISABLE_CANCEL
, TestDefaultActionDialog::OnDisableCancel
)
2066 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
2067 EVT_TEXT_ENTER(wxID_ANY
, TestDefaultActionDialog::OnTextEnter
)
2070 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
2071 wxDialog( parent
, -1, "Test default action" )
2073 m_catchListBoxDClick
= false;
2075 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
2077 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
2080 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
2081 listbox
->Append( "String 1" );
2082 listbox
->Append( "String 2" );
2083 listbox
->Append( "String 3" );
2084 listbox
->Append( "String 4" );
2085 grid_sizer
->Add( listbox
);
2086 #endif // wxUSE_LISTBOX
2088 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
2090 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
2091 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
2093 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
2094 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
2096 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_OK
, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL
);
2097 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_CANCEL
, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL
);
2099 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
2101 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
2103 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
2105 SetSizerAndFit( main_sizer
);
2108 void TestDefaultActionDialog::OnDisableOK(wxCommandEvent
& event
)
2110 FindWindow(wxID_OK
)->Enable(!event
.IsChecked());
2113 void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent
& event
)
2115 FindWindow(wxID_CANCEL
)->Enable(!event
.IsChecked());
2118 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
2120 event
.Skip( !m_catchListBoxDClick
);
2123 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
2125 m_catchListBoxDClick
= !m_catchListBoxDClick
;
2128 void TestDefaultActionDialog::OnTextEnter(wxCommandEvent
& event
)
2130 wxLogMessage("Text \"%s\" entered.", event
.GetString());
2133 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
2135 TestDefaultActionDialog
dialog( this );
2139 void MyFrame::OnModalHook(wxCommandEvent
& event
)
2141 class TestModalHook
: public wxModalDialogHook
2144 virtual int Enter(wxDialog
* dialog
)
2146 wxLogStatus("Showing %s modal dialog",
2147 dialog
->GetClassInfo()->GetClassName());
2151 virtual void Exit(wxDialog
* dialog
)
2153 wxLogStatus("Leaving %s modal dialog",
2154 dialog
->GetClassInfo()->GetClassName());
2158 static TestModalHook s_hook
;
2159 if ( event
.IsChecked() )
2162 s_hook
.Unregister();
2165 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
2170 #if wxUSE_PROGRESSDLG
2172 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
2174 static const int max
= 100;
2176 wxProgressDialog
dialog("Progress dialog example",
2177 // "Reserve" enough space for the multiline
2178 // messages below, we'll change it anyhow
2179 // immediately in the loop below
2180 wxString(' ', 100) + "\n\n\n\n",
2186 //wxPD_AUTO_HIDE | // -- try this as well
2188 wxPD_ESTIMATED_TIME
|
2189 wxPD_REMAINING_TIME
|
2190 wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
2194 for ( int i
= 0; i
<= max
; i
++ )
2198 // test both modes of wxProgressDialog behaviour: start in
2199 // indeterminate mode but switch to the determinate one later
2200 const bool determinate
= i
> max
/2;
2204 msg
= "That's all, folks!\n"
2206 "Nothing to see here any more.";
2208 else if ( !determinate
)
2210 msg
= "Testing indeterminate mode\n"
2212 "This mode allows you to show to the user\n"
2213 "that something is going on even if you don't know\n"
2214 "when exactly will you finish.";
2216 else if ( determinate
)
2218 msg
= "Now in standard determinate mode\n"
2220 "This is the standard usage mode in which you\n"
2221 "update the dialog after performing each new step of work.\n"
2222 "It requires knowing the total number of steps in advance.";
2225 // will be set to true if "Skip" button was pressed
2229 cont
= dialog
.Update(i
, msg
, &skip
);
2233 cont
= dialog
.Pulse(msg
, &skip
);
2236 // each skip will move progress about quarter forward
2247 if ( wxMessageBox(wxT("Do you really want to cancel?"),
2248 wxT("Progress dialog question"), // caption
2249 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
2261 wxLogStatus(wxT("Progress dialog aborted!"));
2265 wxLogStatus(wxT("Countdown from %d finished"), max
);
2269 #endif // wxUSE_PROGRESSDLG
2273 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
2275 info
.SetName(wxT("Dialogs Sample"));
2276 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
2280 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
2281 wxVERSION_NUM_DOT_STRING
2283 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
2284 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
2285 info
.AddDeveloper(wxT("Vadim Zeitlin"));
2288 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
2290 InitAboutInfoMinimal(info
);
2292 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
2295 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
2297 InitAboutInfoWebsite(info
);
2299 // we can add a second developer
2300 info
.AddDeveloper(wxT("A.N. Other"));
2302 // or we can add several persons at once like this
2303 static const wxChar
*docwriters
[] =
2305 wxT("First D. Writer"),
2309 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
2310 info
.SetLicence(wxString::FromAscii(
2311 " wxWindows Library Licence, Version 3.1\n"
2312 " ======================================\n"
2314 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
2316 " Everyone is permitted to copy and distribute verbatim copies\n"
2317 " of this licence document, but changing it is not allowed.\n"
2319 " WXWINDOWS LIBRARY LICENCE\n"
2320 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
2322 " ...and so on and so forth...\n"
2325 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
2328 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2330 wxAboutDialogInfo info
;
2331 InitAboutInfoMinimal(info
);
2333 wxAboutBox(info
, this);
2336 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2338 wxAboutDialogInfo info
;
2339 InitAboutInfoWebsite(info
);
2341 wxAboutBox(info
, this);
2344 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2346 wxAboutDialogInfo info
;
2347 InitAboutInfoAll(info
);
2349 wxAboutBox(info
, this);
2352 // a trivial example of a custom dialog class
2353 class MyAboutDialog
: public wxGenericAboutDialog
2356 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
2358 Create(info
, parent
);
2361 // add some custom controls
2362 virtual void DoAddCustomControls()
2364 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2365 AddText(wxT("Some custom text"));
2366 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2370 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2372 wxAboutDialogInfo info
;
2373 InitAboutInfoAll(info
);
2375 MyAboutDialog
dlg(info
, this);
2379 #endif // wxUSE_ABOUTDLG
2383 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
2385 wxWindowDisabler disableAll
;
2387 wxBusyInfo
info(wxT("Working, please wait..."), this);
2389 for ( int i
= 0; i
< 18; i
++ )
2399 #endif // wxUSE_BUSYINFO
2401 #if wxUSE_FINDREPLDLG
2403 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
2407 wxDELETE(m_dlgReplace
);
2411 m_dlgReplace
= new wxFindReplaceDialog
2415 wxT("Find and replace dialog"),
2419 m_dlgReplace
->Show(true);
2423 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
2427 wxDELETE(m_dlgFind
);
2431 m_dlgFind
= new wxFindReplaceDialog
2440 m_dlgFind
->Show(true);
2444 static wxString
DecodeFindDialogEventFlags(int flags
)
2447 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
2448 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
2449 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
2450 << wxT("case sensitive");
2455 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
2457 wxEventType type
= event
.GetEventType();
2459 if ( type
== wxEVT_FIND
|| type
== wxEVT_FIND_NEXT
)
2461 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
2462 type
== wxEVT_FIND_NEXT
? wxT("next ") : wxT(""),
2463 event
.GetFindString().c_str(),
2464 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2466 else if ( type
== wxEVT_FIND_REPLACE
||
2467 type
== wxEVT_FIND_REPLACE_ALL
)
2469 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
2470 type
== wxEVT_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
2471 event
.GetFindString().c_str(),
2472 event
.GetReplaceString().c_str(),
2473 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2475 else if ( type
== wxEVT_FIND_CLOSE
)
2477 wxFindReplaceDialog
*dlg
= event
.GetDialog();
2481 if ( dlg
== m_dlgFind
)
2484 idMenu
= DIALOGS_FIND
;
2487 else if ( dlg
== m_dlgReplace
)
2489 txt
= wxT("Replace");
2490 idMenu
= DIALOGS_REPLACE
;
2491 m_dlgReplace
= NULL
;
2495 txt
= wxT("Unknown");
2498 wxFAIL_MSG( wxT("unexpected event") );
2501 wxLogMessage(wxT("%s dialog is being closed."), txt
);
2503 if ( idMenu
!= wxID_ANY
)
2505 GetMenuBar()->Check(idMenu
, false);
2512 wxLogError(wxT("Unknown find dialog event!"));
2516 #endif // wxUSE_FINDREPLDLG
2518 // ----------------------------------------------------------------------------
2520 // ----------------------------------------------------------------------------
2522 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
2525 dc
.SetBackgroundMode(wxTRANSPARENT
);
2527 wxT("wxWidgets common dialogs")
2528 #if !defined(__SMARTPHONE__)
2529 wxT(" test application")
2534 #if USE_MODAL_PRESENTATION
2536 // ----------------------------------------------------------------------------
2538 // ----------------------------------------------------------------------------
2540 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
2541 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
2543 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
2545 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
2546 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
2549 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
2550 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
2552 SetSizerAndFit(sizerTop
);
2555 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
2557 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
2558 wxOK
| wxICON_INFORMATION
, this);
2561 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
2563 if ( event
.CanVeto() )
2565 wxMessageBox(wxT("Use the menu item to close this dialog"),
2566 wxT("Modeless dialog"),
2567 wxOK
| wxICON_INFORMATION
, this);
2573 // ----------------------------------------------------------------------------
2575 // ----------------------------------------------------------------------------
2577 MyModalDialog::MyModalDialog(wxWindow
*parent
)
2578 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
2580 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
2582 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2583 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2584 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2586 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2587 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2588 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2589 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2591 SetSizerAndFit(sizerTop
);
2593 SetEscapeId(wxID_CLOSE
);
2595 m_btnModal
->SetFocus();
2596 m_btnModal
->SetDefault();
2599 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2601 if ( event
.GetEventObject() == m_btnDelete
)
2603 wxDELETE(m_btnModal
);
2604 m_btnDelete
->Disable();
2606 else if ( event
.GetEventObject() == m_btnModal
)
2609 wxGetTextFromUser(wxT("Dummy prompt"),
2610 wxT("Modal dialog called from dialog"),
2611 wxEmptyString
, this);
2613 wxMessageBox(wxT("Modal dialog called from dialog"));
2614 #endif // wxUSE_TEXTDLG
2616 else if ( event
.GetEventObject() == m_btnModeless
)
2618 (new MyModelessDialog(this))->Show();
2626 #endif // USE_MODAL_PRESENTATION
2628 // ----------------------------------------------------------------------------
2629 // StdButtonSizerDialog
2630 // ----------------------------------------------------------------------------
2632 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2633 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2634 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2635 m_buttonsSizer(NULL
)
2637 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2639 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2640 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2642 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2644 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2646 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2647 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2649 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2651 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2653 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2655 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2656 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2658 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2660 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2661 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2662 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2664 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2666 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2667 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2669 sizer
->Add(sizerInside1
, 0, 0, 0);
2670 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2671 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2672 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2674 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2675 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2677 sizer
->Add(sizerInside2
, 0, 0, 0);
2678 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2679 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2680 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2682 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2684 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2685 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2686 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2688 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2690 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2692 EnableDisableControls();
2694 SetSizerAndFit(sizerTop
);
2700 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2704 m_buttonsSizer
->DeleteWindows();
2705 GetSizer()->Remove(m_buttonsSizer
);
2708 EnableDisableControls();
2711 unsigned long numButtons
= 0;
2713 if (m_chkboxAffirmativeButton
->IsChecked())
2715 if (m_radiobtnOk
->GetValue())
2720 else if (m_radiobtnYes
->GetValue())
2727 if (m_chkboxDismissButton
->IsChecked())
2729 if (m_radiobtnCancel
->GetValue())
2735 else if (m_radiobtnClose
->GetValue())
2743 if (m_chkboxApply
->IsChecked())
2749 if (m_chkboxNo
->IsChecked())
2755 if (m_chkboxHelp
->IsChecked())
2761 if (m_chkboxNoDefault
->IsChecked())
2763 flags
|= wxNO_DEFAULT
;
2766 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2767 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2770 GetSizer()->SetSizeHints(this);
2773 void StdButtonSizerDialog::EnableDisableControls()
2775 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2777 m_radiobtnOk
->Enable(affButtonEnabled
);
2778 m_radiobtnYes
->Enable(affButtonEnabled
);
2780 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2782 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2783 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2786 #if USE_SETTINGS_DIALOG
2787 // ----------------------------------------------------------------------------
2789 // ----------------------------------------------------------------------------
2791 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2793 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2796 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2798 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2803 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2804 int resizeBorder
= wxRESIZE_BORDER
;
2812 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2813 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2814 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2816 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2818 SetSheetStyle(sheetStyle
);
2819 SetSheetInnerBorder(0);
2820 SetSheetOuterBorder(0);
2822 // create a dummy image list with a few icons
2823 const wxSize
imageSize(32, 32);
2825 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2827 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2829 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2831 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2833 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2838 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2839 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2842 // If using a toolbook, also follow Mac style and don't create buttons
2844 CreateButtons(wxOK
| wxCANCEL
|
2845 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2848 wxBookCtrlBase
* notebook
= GetBookCtrl();
2849 notebook
->SetImageList(m_imageList
);
2851 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2852 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2854 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2855 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2860 SettingsDialog::~SettingsDialog()
2865 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2867 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2869 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2870 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2874 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2875 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2876 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2877 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2881 wxString autoSaveLabel
= _("&Auto-save every");
2882 wxString minsLabel
= _("mins");
2884 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2885 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2888 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2889 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2892 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2894 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2896 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2897 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2901 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2902 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2903 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2904 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2906 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2908 panel
->SetSizerAndFit(topSizer
);
2913 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2915 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2917 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2918 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2920 //// PROJECT OR GLOBAL
2921 wxString globalOrProjectChoices
[2];
2922 globalOrProjectChoices
[0] = _("&New projects");
2923 globalOrProjectChoices
[1] = _("&This project");
2925 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2926 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2927 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2929 projectOrGlobal
->SetSelection(0);
2931 //// BACKGROUND STYLE
2932 wxArrayString backgroundStyleChoices
;
2933 backgroundStyleChoices
.Add(wxT("Colour"));
2934 backgroundStyleChoices
.Add(wxT("Image"));
2935 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2937 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2938 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2940 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2942 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2944 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2945 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2946 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2948 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2951 //// FONT SIZE SELECTION
2953 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2954 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2956 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2957 wxSize(80, wxDefaultCoord
));
2958 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2960 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2963 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2964 topSizer
->AddSpacer(5);
2966 panel
->SetSizerAndFit(topSizer
);
2971 #endif // USE_SETTINGS_DIALOG
2974 // ----------------------------------------------------------------------------
2975 // TestMessageBoxDialog
2976 // ----------------------------------------------------------------------------
2979 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2984 { wxCANCEL
, "&Cancel" },
2985 { wxHELP
, "&Help" },
2988 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2989 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2990 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2993 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2994 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2995 wxDefaultPosition
, wxDefaultSize
,
2996 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
3000 bool TestMessageBoxDialog::Create()
3002 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
3004 // this sizer allows to configure the messages shown in the message box
3006 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
3007 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Title:"));
3008 m_textTitle
= new wxTextCtrl(this, wxID_ANY
, "Test Message Box");
3009 sizerMsgs
->Add(m_textTitle
, wxSizerFlags().Expand().Border(wxBOTTOM
));
3011 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
3012 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
3013 wxDefaultPosition
, wxDefaultSize
,
3015 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
3017 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
3018 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
3019 wxDefaultPosition
, wxDefaultSize
,
3021 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
3023 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
3025 // if a derived class provides more message configurations, add these.
3026 AddAdditionalTextOptions(sizerTop
);
3028 // this one is for configuring the buttons
3030 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
3032 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
3033 sizerBtns
->AddGrowableCol(1);
3035 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
3036 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
3038 for ( int n
= 0; n
< Btn_Max
; n
++ )
3040 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
3041 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
3043 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
3044 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
3046 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
3047 wxUpdateUIEventHandler(
3048 TestMessageBoxDialog::OnUpdateLabelUI
),
3053 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
3054 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
3058 const wxString icons
[] =
3062 "&Information icon",
3069 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == MsgDlgIcon_Max
, IconMismatch
);
3071 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon style",
3072 wxDefaultPosition
, wxDefaultSize
,
3073 WXSIZEOF(icons
), icons
,
3074 2, wxRA_SPECIFY_ROWS
);
3075 // Make the 'Information' icon the default one:
3076 m_icons
->SetSelection(MsgDlgIcon_Info
);
3077 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
3080 // miscellaneous other stuff
3082 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
3084 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
3085 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
3086 wxUpdateUIEventHandler(
3087 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
3090 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
3092 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
3093 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
3095 // add any additional flag from subclasses
3096 AddAdditionalFlags(sizerFlags
);
3098 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
3100 // finally buttons to show the resulting message box and close this dialog
3101 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
3102 wxSizerFlags().Right().Border());
3104 SetSizerAndFit(sizerTop
);
3106 m_buttons
[Btn_Ok
]->SetValue(true);
3111 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
3113 for ( int n
= 0; n
< Btn_Max
; n
++ )
3115 if ( event
.GetEventObject() == m_labels
[n
] )
3117 event
.Enable( m_buttons
[n
]->IsChecked() );
3122 wxFAIL_MSG( "called for unknown label" );
3125 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
3127 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
3130 long TestMessageBoxDialog::GetStyle()
3134 for ( int n
= 0; n
< Btn_Max
; n
++ )
3136 if ( m_buttons
[n
]->IsChecked() )
3137 style
|= ms_btnInfo
[n
].flag
;
3140 switch ( m_icons
->GetSelection() )
3142 case MsgDlgIcon_Max
:
3143 wxFAIL_MSG( "unexpected selection" );
3148 case MsgDlgIcon_None
:
3149 style
|= wxICON_NONE
;
3152 case MsgDlgIcon_Info
:
3153 style
|= wxICON_INFORMATION
;
3156 case MsgDlgIcon_Question
:
3157 style
|= wxICON_QUESTION
;
3160 case MsgDlgIcon_Warning
:
3161 style
|= wxICON_WARNING
;
3164 case MsgDlgIcon_Error
:
3165 style
|= wxICON_ERROR
;
3168 case MsgDlgIcon_AuthNeeded
:
3169 style
|= wxICON_AUTH_NEEDED
;
3173 if ( m_chkCentre
->IsChecked() )
3176 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
3177 style
|= wxNO_DEFAULT
;
3182 void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase
&dlg
)
3184 long style
= dlg
.GetMessageDialogStyle();
3186 if ( !m_textExtMsg
->IsEmpty() )
3187 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
3189 if ( style
& wxYES_NO
)
3191 if ( style
& wxCANCEL
)
3193 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
3194 m_labels
[Btn_No
]->GetValue(),
3195 m_labels
[Btn_Cancel
]->GetValue());
3199 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
3200 m_labels
[Btn_No
]->GetValue());
3205 if ( style
& wxCANCEL
)
3207 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
3208 m_labels
[Btn_Cancel
]->GetValue());
3212 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
3216 if ( style
& wxHELP
)
3218 dlg
.SetHelpLabel(m_labels
[Btn_Help
]->GetValue());
3222 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
3224 wxMessageDialog
dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3225 PrepareMessageDialog(dlg
);
3228 switch ( dlg
.ShowModal() )
3235 // Avoid the extra message box if the dialog was cancelled.
3251 btnName
= "Unknown";
3254 wxLogMessage("Dialog was closed with the \"%s\" button.", btnName
);
3257 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
3259 EndModal(wxID_CANCEL
);
3261 #endif // wxUSE_MSGDLG
3263 #if wxUSE_RICHMSGDLG
3264 // ----------------------------------------------------------------------------
3265 // TestRichMessageDialog
3266 // ----------------------------------------------------------------------------
3268 BEGIN_EVENT_TABLE(TestRichMessageDialog
, TestMessageBoxDialog
)
3269 EVT_BUTTON(wxID_APPLY
, TestRichMessageDialog::OnApply
)
3272 TestRichMessageDialog::TestRichMessageDialog(wxWindow
*parent
)
3273 : TestMessageBoxDialog(parent
)
3275 SetTitle("Rich Message Dialog Test Dialog");
3278 void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer
*sizer
)
3280 wxSizer
* const sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this,
3281 "&Additional Elements");
3283 // add a option to show a check box.
3284 wxFlexGridSizer
* const sizerCheckBox
= new wxFlexGridSizer(2, 5, 5);
3285 sizerCheckBox
->AddGrowableCol(1);
3286 sizerCheckBox
->Add(new wxStaticText(this, wxID_ANY
, "&Check box:"));
3287 m_textCheckBox
= new wxTextCtrl(this, wxID_ANY
);
3288 sizerCheckBox
->Add(m_textCheckBox
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
3289 sizerMsgs
->Add(sizerCheckBox
, wxSizerFlags(1).Expand());
3291 // add option to show a detailed text.
3292 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Detailed message:"));
3293 m_textDetailed
= new wxTextCtrl(this, wxID_ANY
, "",
3294 wxDefaultPosition
, wxDefaultSize
,
3296 sizerMsgs
->Add(m_textDetailed
, wxSizerFlags(1).Expand());
3298 sizer
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
3301 void TestRichMessageDialog::AddAdditionalFlags(wxSizer
*sizer
)
3303 // add checkbox to set the initial state for the checkbox shown
3305 m_initialValueCheckBox
=
3306 new wxCheckBox(this, wxID_ANY
, "Checkbox initially checked");
3307 sizer
->Add(m_initialValueCheckBox
, wxSizerFlags(1).Border());
3310 void TestRichMessageDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
3312 wxRichMessageDialog
dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3313 PrepareMessageDialog(dlg
);
3315 dlg
.ShowCheckBox(m_textCheckBox
->GetValue(),
3316 m_initialValueCheckBox
->GetValue());
3317 dlg
.ShowDetailedText(m_textDetailed
->GetValue());
3322 #endif // wxUSE_RICHMSGDLG
3326 // ----------------------------------------------------------------------------
3327 // custom log target
3328 // ----------------------------------------------------------------------------
3330 class MyLogGui
: public wxLogGui
3333 virtual void DoShowSingleLogMessage(const wxString
& message
,
3334 const wxString
& title
,
3337 wxMessageDialog
dlg(NULL
, message
, title
,
3338 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
3339 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
3340 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
3345 wxLog
*MyAppTraits::CreateLogTarget()
3347 return new MyLogGui
;