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"
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 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1336 wxString
GetInfo() const
1338 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1345 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1348 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1349 m_btn
->Enable(false);
1350 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1351 m_cb
->Connect(wxID_ANY
, wxEVT_CHECKBOX
,
1352 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1353 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1354 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1355 sizerTop
->AddStretchSpacer();
1356 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1357 SetSizerAndFit(sizerTop
);
1360 // a static method can be used instead of a function with most of compilers
1361 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1363 return new MyExtraPanel(parent
);
1366 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1371 wxT("Testing open file dialog"),
1375 wxT("C++ files (*.cpp)|*.cpp")
1377 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1381 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1382 dialog
.CentreOnParent();
1383 dialog
.SetDirectory(wxGetHomeDir());
1385 if (dialog
.ShowModal() == wxID_OK
)
1388 wxWindow
* const extra
= dialog
.GetExtraControl();
1389 info
.Printf(wxT("Full file name: %s\n")
1392 wxT("Custom window: %s"),
1393 dialog
.GetPath().c_str(),
1394 dialog
.GetDirectory().c_str(),
1395 dialog
.GetFilename().c_str(),
1396 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1397 : wxString("None"));
1398 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1399 dialog2
.ShowModal();
1403 // this shows how to take advantage of specifying a default extension in the
1404 // call to wxFileSelector: it is remembered after each new call and the next
1405 // one will use it by default
1406 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1408 static wxString s_extDef
;
1409 wxString path
= wxFileSelector(
1410 wxT("Select the file to load"),
1411 wxEmptyString
, wxEmptyString
,
1415 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1416 wxFileSelectorDefaultWildcardStr
,
1417 wxFileSelectorDefaultWildcardStr
1419 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1426 // it is just a sample, would use wxSplitPath in real program
1427 s_extDef
= path
.AfterLast(wxT('.'));
1429 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1433 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1435 wxString wildcards
=
1437 wxT("C++ files (*.cpp)|*.cpp");
1441 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1442 wxFileSelectorDefaultWildcardStr
,
1443 wxFileSelectorDefaultWildcardStr
1446 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1447 wxEmptyString
, wxEmptyString
, wildcards
,
1448 wxFD_OPEN
|wxFD_MULTIPLE
);
1450 if (dialog
.ShowModal() == wxID_OK
)
1452 wxArrayString paths
, filenames
;
1454 dialog
.GetPaths(paths
);
1455 dialog
.GetFilenames(filenames
);
1458 size_t count
= paths
.GetCount();
1459 for ( size_t n
= 0; n
< count
; n
++ )
1461 s
.Printf(wxT("File %d: %s (%s)\n"),
1462 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1466 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1469 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1470 dialog2
.ShowModal();
1474 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1476 wxFileDialog
dialog(this,
1477 wxT("Testing save file dialog"),
1479 wxT("myletter.doc"),
1480 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1481 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1483 dialog
.SetFilterIndex(1);
1485 if (dialog
.ShowModal() == wxID_OK
)
1487 wxLogMessage(wxT("%s, filter %d"),
1488 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1491 #endif // wxUSE_FILEDLG
1493 #if USE_FILEDLG_GENERIC
1494 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1496 wxGenericFileDialog dialog
1499 wxT("Testing open file dialog"),
1502 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1505 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1506 dialog
.SetDirectory(wxGetHomeDir());
1508 if (dialog
.ShowModal() == wxID_OK
)
1511 info
.Printf(wxT("Full file name: %s\n")
1514 dialog
.GetPath().c_str(),
1515 dialog
.GetDirectory().c_str(),
1516 dialog
.GetFilename().c_str());
1517 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1518 dialog2
.ShowModal();
1522 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1524 // On PocketPC you can disable OK-only dialogs policy using system option
1525 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1526 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1528 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1529 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1530 wxEmptyString
, wxEmptyString
, wildcards
,
1533 if (dialog
.ShowModal() == wxID_OK
)
1535 wxArrayString paths
, filenames
;
1537 dialog
.GetPaths(paths
);
1538 dialog
.GetFilenames(filenames
);
1541 size_t count
= paths
.GetCount();
1542 for ( size_t n
= 0; n
< count
; n
++ )
1544 s
.Printf(wxT("File %d: %s (%s)\n"),
1545 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1549 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1552 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1553 dialog2
.ShowModal();
1556 // restore system option
1557 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1560 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1562 wxGenericFileDialog
dialog(this,
1563 wxT("Testing save file dialog"),
1565 wxT("myletter.doc"),
1566 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1567 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1569 dialog
.SetFilterIndex(1);
1571 if (dialog
.ShowModal() == wxID_OK
)
1573 wxLogMessage(wxT("%s, filter %d"),
1574 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1577 #endif // USE_FILEDLG_GENERIC
1580 void MyFrame::DoDirChoose(int style
)
1582 // pass some initial dir to wxDirDialog
1584 wxGetHomeDir(&dirHome
);
1586 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1588 if (dialog
.ShowModal() == wxID_OK
)
1590 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1594 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1596 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1599 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1601 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1603 #endif // wxUSE_DIRDLG
1605 #if USE_DIRDLG_GENERIC
1606 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1608 // pass some initial dir to wxDirDialog
1610 wxGetHomeDir(&dirHome
);
1612 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1614 if (dialog
.ShowModal() == wxID_OK
)
1616 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1617 dialog2
.ShowModal();
1620 #endif // USE_DIRDLG_GENERIC
1622 #if USE_MODAL_PRESENTATION
1623 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1625 MyModalDialog
dlg(this);
1628 #endif // USE_MODAL_PRESENTATION
1630 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1632 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1638 m_dialog
= new MyModelessDialog(this);
1641 m_dialog
->Show(true);
1645 // If m_dialog is NULL, then possibly the system
1646 // didn't report the checked menu item status correctly.
1647 // It should be true just after the menu item was selected,
1648 // if there was no modeless dialog yet.
1650 wxASSERT( m_dialog
!= NULL
);
1656 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1658 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1659 wxDefaultPosition
, wxSize(200, 100));
1660 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1661 dlg
.CentreOnScreen();
1665 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1667 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1668 wxDefaultPosition
, wxSize(200, 100));
1669 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1670 dlg
.CentreOnParent();
1675 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1677 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1678 wxDefaultPosition
, wxSize(300, 100),
1679 wxCAPTION
| wxCLOSE_BOX
);
1680 new wxStaticText(frame
,
1682 wxT("Mini frames have slightly different appearance"),
1684 new wxStaticText(frame
,
1686 wxT("from the normal frames but that's the only difference."),
1689 frame
->CentreOnParent();
1692 #endif // wxUSE_MINIFRAME
1694 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1696 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1697 wxDefaultPosition
, wxSize(300, 100),
1698 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1699 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1703 #if wxUSE_STARTUP_TIPS
1704 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1706 static size_t s_index
= (size_t)-1;
1708 if ( s_index
== (size_t)-1 )
1712 // this is completely bogus, we don't know how many lines are there
1713 // in the file, but who cares, it's a demo only...
1714 s_index
= rand() % 5;
1717 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1719 bool showAtStartup
= wxShowTip(this, tipProvider
);
1721 if ( showAtStartup
)
1723 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1724 wxOK
| wxICON_INFORMATION
, this);
1727 s_index
= tipProvider
->GetCurrentTip();
1730 #endif // wxUSE_STARTUP_TIPS
1732 #if USE_SETTINGS_DIALOG
1733 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1735 SettingsDialog
dialog(this, event
.GetId());
1738 #endif // USE_SETTINGS_DIALOG
1740 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1742 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1746 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1749 #if wxUSE_NOTIFICATION_MESSAGE
1751 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1753 // Notice that the notification remains shown even after the
1754 // wxNotificationMessage object itself is destroyed so we can show simple
1755 // notifications using temporary objects.
1756 if ( !wxNotificationMessage
1758 "Automatic Notification",
1759 "Nothing important has happened\n"
1760 "this notification will disappear soon."
1763 wxLogStatus("Failed to show notification message");
1766 // But it doesn't have to be a temporary, of course.
1767 wxNotificationMessage
n("Dummy Warning", "Example of a warning notification.");
1768 n
.SetFlags(wxICON_ERROR
);
1769 n
.Show(5); // Just for testing, use 5 second delay.
1772 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1776 m_notifMsg
= new wxNotificationMessage
1778 "wxWidgets Manual Notification",
1779 "You can hide this notification from the menu",
1784 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1786 wxLogStatus("Failed to show manual notification message");
1790 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1792 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1794 wxLogStatus("Failed to hide manual notification message");
1798 #endif // wxUSE_NOTIFICATION_MESSAGE
1800 #if wxUSE_RICHTOOLTIP
1802 #include "wx/richtooltip.h"
1806 class RichTipDialog
: public wxDialog
1809 RichTipDialog(wxWindow
* parent
)
1810 : wxDialog(parent
, wxID_ANY
, "wxRichToolTip Test",
1811 wxDefaultPosition
, wxDefaultSize
,
1812 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
1814 // Create the controls.
1815 m_textTitle
= new wxTextCtrl(this, wxID_ANY
, "Tooltip title");
1816 m_textBody
= new wxTextCtrl(this, wxID_ANY
, "Main tooltip text\n"
1817 "possibly on several\n"
1819 wxDefaultPosition
, wxDefaultSize
,
1821 wxButton
* btnShowText
= new wxButton(this, wxID_ANY
, "Show for &text");
1822 wxButton
* btnShowBtn
= new wxButton(this, wxID_ANY
, "Show for &button");
1824 const wxString icons
[] =
1832 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == Icon_Max
, IconMismatch
);
1833 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon choice:",
1834 wxDefaultPosition
, wxDefaultSize
,
1835 WXSIZEOF(icons
), icons
,
1836 1, wxRA_SPECIFY_ROWS
);
1837 m_icons
->SetSelection(Icon_Info
);
1839 const wxString tipKinds
[] =
1841 "&None", "Top left", "Top", "Top right",
1842 "Bottom left", "Bottom", "Bottom right", "&Auto"
1844 m_tipKinds
= new wxRadioBox(this, wxID_ANY
, "Tip &kind:",
1845 wxDefaultPosition
, wxDefaultSize
,
1846 WXSIZEOF(tipKinds
), tipKinds
,
1847 4, wxRA_SPECIFY_COLS
);
1848 m_tipKinds
->SetSelection(wxTipKind_Auto
);
1850 const wxString bgStyles
[] =
1852 "&Default", "&Solid", "&Gradient",
1854 wxCOMPILE_TIME_ASSERT( WXSIZEOF(bgStyles
) == Bg_Max
, BgMismatch
);
1855 m_bgStyles
= new wxRadioBox(this, wxID_ANY
, "Background style:",
1856 wxDefaultPosition
, wxDefaultSize
,
1857 WXSIZEOF(bgStyles
), bgStyles
,
1858 1, wxRA_SPECIFY_ROWS
);
1860 const wxString timeouts
[] = { "&None", "&Default (no delay)", "&3 seconds" };
1861 wxCOMPILE_TIME_ASSERT( WXSIZEOF(timeouts
) == Timeout_Max
, TmMismatch
);
1862 m_timeouts
= new wxRadioBox(this, wxID_ANY
, "Timeout:",
1863 wxDefaultPosition
, wxDefaultSize
,
1864 WXSIZEOF(timeouts
), timeouts
,
1865 1, wxRA_SPECIFY_ROWS
);
1866 m_timeouts
->SetSelection(Timeout_Default
);
1867 m_timeDelay
= new wxCheckBox(this, wxID_ANY
, "Delay show" );
1870 m_textBody
->SetMinSize(wxSize(300, 200));
1872 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
1873 sizer
->Add(m_textTitle
, wxSizerFlags().Expand().Border());
1874 sizer
->Add(m_textBody
, wxSizerFlags(1).Expand().Border());
1875 sizer
->Add(m_icons
, wxSizerFlags().Expand().Border());
1876 sizer
->Add(m_tipKinds
, wxSizerFlags().Centre().Border());
1877 sizer
->Add(m_bgStyles
, wxSizerFlags().Centre().Border());
1878 sizer
->Add(m_timeouts
, wxSizerFlags().Centre().Border());
1879 sizer
->Add(m_timeDelay
, wxSizerFlags().Centre().Border());
1880 wxBoxSizer
* const sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
1881 sizerBtns
->Add(btnShowText
, wxSizerFlags().Border(wxRIGHT
));
1882 sizerBtns
->Add(btnShowBtn
, wxSizerFlags().Border(wxLEFT
));
1883 sizer
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
1884 sizer
->Add(CreateStdDialogButtonSizer(wxOK
),
1885 wxSizerFlags().Expand().Border());
1886 SetSizerAndFit(sizer
);
1889 // And connect the event handlers.
1890 btnShowText
->Connect
1893 wxCommandEventHandler(RichTipDialog::OnShowTipForText
),
1901 wxCommandEventHandler(RichTipDialog::OnShowTipForBtn
),
1935 void OnShowTipForText(wxCommandEvent
& WXUNUSED(event
))
1937 DoShowTip(m_textTitle
);
1940 void OnShowTipForBtn(wxCommandEvent
& WXUNUSED(event
))
1942 DoShowTip(FindWindow(wxID_OK
));
1945 void DoShowTip(wxWindow
* win
)
1947 wxRichToolTip
tip(m_textTitle
->GetValue(), m_textBody
->GetValue());
1948 const int iconSel
= m_icons
->GetSelection();
1949 if ( iconSel
== Icon_Custom
)
1951 tip
.SetIcon(tip_xpm
);
1953 else // Use a standard icon.
1955 static const int stdIcons
[] =
1963 tip
.SetIcon(stdIcons
[iconSel
]);
1966 switch ( m_bgStyles
->GetSelection() )
1972 tip
.SetBackgroundColour(*wxLIGHT_GREY
);
1976 tip
.SetBackgroundColour(*wxWHITE
, wxColour(0xe4, 0xe5, 0xf0));
1980 int delay
= m_timeDelay
->IsChecked() ? 500 : 0;
1982 switch ( m_timeouts
->GetSelection() )
1985 // Don't call SetTimeout unnecessarily
1986 // or msw will show generic impl
1988 tip
.SetTimeout(0, delay
);
1991 case Timeout_Default
:
1995 tip
.SetTimeout(3000, delay
);
1999 tip
.SetTipKind(static_cast<wxTipKind
>(m_tipKinds
->GetSelection()));
2004 wxTextCtrl
* m_textTitle
;
2005 wxTextCtrl
* m_textBody
;
2006 wxRadioBox
* m_icons
;
2007 wxRadioBox
* m_tipKinds
;
2008 wxRadioBox
* m_bgStyles
;
2009 wxRadioBox
* m_timeouts
;
2010 wxCheckBox
* m_timeDelay
;
2013 void MyFrame::OnRichTipDialog(wxCommandEvent
& WXUNUSED(event
))
2015 RichTipDialog
dialog(this);
2019 #endif // wxUSE_RICHTOOLTIP
2021 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
2023 StdButtonSizerDialog
dialog(this);
2027 // TestDefaultAction
2029 #define ID_CATCH_LISTBOX_DCLICK 100
2030 #define ID_LISTBOX 101
2031 #define ID_DISABLE_OK 102
2032 #define ID_DISABLE_CANCEL 103
2034 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
2035 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
2036 EVT_CHECKBOX(ID_DISABLE_OK
, TestDefaultActionDialog::OnDisableOK
)
2037 EVT_CHECKBOX(ID_DISABLE_CANCEL
, TestDefaultActionDialog::OnDisableCancel
)
2038 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
2039 EVT_TEXT_ENTER(wxID_ANY
, TestDefaultActionDialog::OnTextEnter
)
2042 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
2043 wxDialog( parent
, -1, "Test default action" )
2045 m_catchListBoxDClick
= false;
2047 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
2049 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
2052 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
2053 listbox
->Append( "String 1" );
2054 listbox
->Append( "String 2" );
2055 listbox
->Append( "String 3" );
2056 listbox
->Append( "String 4" );
2057 grid_sizer
->Add( listbox
);
2058 #endif // wxUSE_LISTBOX
2060 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
2062 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
2063 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
2065 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
2066 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
2068 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_OK
, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL
);
2069 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_CANCEL
, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL
);
2071 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
2073 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
2075 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
2077 SetSizerAndFit( main_sizer
);
2080 void TestDefaultActionDialog::OnDisableOK(wxCommandEvent
& event
)
2082 FindWindow(wxID_OK
)->Enable(!event
.IsChecked());
2085 void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent
& event
)
2087 FindWindow(wxID_CANCEL
)->Enable(!event
.IsChecked());
2090 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
2092 event
.Skip( !m_catchListBoxDClick
);
2095 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
2097 m_catchListBoxDClick
= !m_catchListBoxDClick
;
2100 void TestDefaultActionDialog::OnTextEnter(wxCommandEvent
& event
)
2102 wxLogMessage("Text \"%s\" entered.", event
.GetString());
2105 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
2107 TestDefaultActionDialog
dialog( this );
2111 void MyFrame::OnModalHook(wxCommandEvent
& event
)
2113 class TestModalHook
: public wxModalDialogHook
2116 virtual int Enter(wxDialog
* dialog
)
2118 wxLogStatus("Showing %s modal dialog",
2119 dialog
->GetClassInfo()->GetClassName());
2123 virtual void Exit(wxDialog
* dialog
)
2125 wxLogStatus("Leaving %s modal dialog",
2126 dialog
->GetClassInfo()->GetClassName());
2130 static TestModalHook s_hook
;
2131 if ( event
.IsChecked() )
2134 s_hook
.Unregister();
2137 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
2142 #if wxUSE_PROGRESSDLG
2144 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
2146 static const int max
= 100;
2148 wxProgressDialog
dialog("Progress dialog example",
2149 // "Reserve" enough space for the multiline
2150 // messages below, we'll change it anyhow
2151 // immediately in the loop below
2152 wxString(' ', 100) + "\n\n\n\n",
2158 //wxPD_AUTO_HIDE | // -- try this as well
2160 wxPD_ESTIMATED_TIME
|
2161 wxPD_REMAINING_TIME
|
2162 wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
2166 for ( int i
= 0; i
<= max
; i
++ )
2170 // test both modes of wxProgressDialog behaviour: start in
2171 // indeterminate mode but switch to the determinate one later
2172 const bool determinate
= i
> max
/2;
2176 msg
= "That's all, folks!\n"
2178 "Nothing to see here any more.";
2180 else if ( !determinate
)
2182 msg
= "Testing indeterminate mode\n"
2184 "This mode allows you to show to the user\n"
2185 "that something is going on even if you don't know\n"
2186 "when exactly will you finish.";
2188 else if ( determinate
)
2190 msg
= "Now in standard determinate mode\n"
2192 "This is the standard usage mode in which you\n"
2193 "update the dialog after performing each new step of work.\n"
2194 "It requires knowing the total number of steps in advance.";
2197 // will be set to true if "Skip" button was pressed
2201 cont
= dialog
.Update(i
, msg
, &skip
);
2205 cont
= dialog
.Pulse(msg
, &skip
);
2208 // each skip will move progress about quarter forward
2219 if ( wxMessageBox(wxT("Do you really want to cancel?"),
2220 wxT("Progress dialog question"), // caption
2221 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
2233 wxLogStatus(wxT("Progress dialog aborted!"));
2237 wxLogStatus(wxT("Countdown from %d finished"), max
);
2241 #endif // wxUSE_PROGRESSDLG
2245 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
2247 info
.SetName(wxT("Dialogs Sample"));
2248 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
2252 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
2253 wxVERSION_NUM_DOT_STRING
2255 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
2256 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
2257 info
.AddDeveloper(wxT("Vadim Zeitlin"));
2260 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
2262 InitAboutInfoMinimal(info
);
2264 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
2267 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
2269 InitAboutInfoWebsite(info
);
2271 // we can add a second developer
2272 info
.AddDeveloper(wxT("A.N. Other"));
2274 // or we can add several persons at once like this
2275 static const wxChar
*docwriters
[] =
2277 wxT("First D. Writer"),
2281 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
2282 info
.SetLicence(wxString::FromAscii(
2283 " wxWindows Library Licence, Version 3.1\n"
2284 " ======================================\n"
2286 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
2288 " Everyone is permitted to copy and distribute verbatim copies\n"
2289 " of this licence document, but changing it is not allowed.\n"
2291 " WXWINDOWS LIBRARY LICENCE\n"
2292 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
2294 " ...and so on and so forth...\n"
2297 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
2300 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2302 wxAboutDialogInfo info
;
2303 InitAboutInfoMinimal(info
);
2305 wxAboutBox(info
, this);
2308 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2310 wxAboutDialogInfo info
;
2311 InitAboutInfoWebsite(info
);
2313 wxAboutBox(info
, this);
2316 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2318 wxAboutDialogInfo info
;
2319 InitAboutInfoAll(info
);
2321 wxAboutBox(info
, this);
2324 // a trivial example of a custom dialog class
2325 class MyAboutDialog
: public wxGenericAboutDialog
2328 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
2330 Create(info
, parent
);
2333 // add some custom controls
2334 virtual void DoAddCustomControls()
2336 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2337 AddText(wxT("Some custom text"));
2338 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2342 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2344 wxAboutDialogInfo info
;
2345 InitAboutInfoAll(info
);
2347 MyAboutDialog
dlg(info
, this);
2351 #endif // wxUSE_ABOUTDLG
2355 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
2357 wxWindowDisabler disableAll
;
2359 wxBusyInfo
info(wxT("Working, please wait..."), this);
2361 for ( int i
= 0; i
< 18; i
++ )
2371 #endif // wxUSE_BUSYINFO
2373 #if wxUSE_FINDREPLDLG
2375 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
2379 wxDELETE(m_dlgReplace
);
2383 m_dlgReplace
= new wxFindReplaceDialog
2387 wxT("Find and replace dialog"),
2391 m_dlgReplace
->Show(true);
2395 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
2399 wxDELETE(m_dlgFind
);
2403 m_dlgFind
= new wxFindReplaceDialog
2412 m_dlgFind
->Show(true);
2416 static wxString
DecodeFindDialogEventFlags(int flags
)
2419 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
2420 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
2421 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
2422 << wxT("case sensitive");
2427 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
2429 wxEventType type
= event
.GetEventType();
2431 if ( type
== wxEVT_FIND
|| type
== wxEVT_FIND_NEXT
)
2433 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
2434 type
== wxEVT_FIND_NEXT
? wxT("next ") : wxT(""),
2435 event
.GetFindString().c_str(),
2436 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2438 else if ( type
== wxEVT_FIND_REPLACE
||
2439 type
== wxEVT_FIND_REPLACE_ALL
)
2441 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
2442 type
== wxEVT_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
2443 event
.GetFindString().c_str(),
2444 event
.GetReplaceString().c_str(),
2445 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2447 else if ( type
== wxEVT_FIND_CLOSE
)
2449 wxFindReplaceDialog
*dlg
= event
.GetDialog();
2453 if ( dlg
== m_dlgFind
)
2456 idMenu
= DIALOGS_FIND
;
2459 else if ( dlg
== m_dlgReplace
)
2461 txt
= wxT("Replace");
2462 idMenu
= DIALOGS_REPLACE
;
2463 m_dlgReplace
= NULL
;
2467 txt
= wxT("Unknown");
2470 wxFAIL_MSG( wxT("unexpected event") );
2473 wxLogMessage(wxT("%s dialog is being closed."), txt
);
2475 if ( idMenu
!= wxID_ANY
)
2477 GetMenuBar()->Check(idMenu
, false);
2484 wxLogError(wxT("Unknown find dialog event!"));
2488 #endif // wxUSE_FINDREPLDLG
2490 // ----------------------------------------------------------------------------
2492 // ----------------------------------------------------------------------------
2494 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
2497 dc
.SetBackgroundMode(wxTRANSPARENT
);
2499 wxT("wxWidgets common dialogs")
2500 #if !defined(__SMARTPHONE__)
2501 wxT(" test application")
2506 #if USE_MODAL_PRESENTATION
2508 // ----------------------------------------------------------------------------
2510 // ----------------------------------------------------------------------------
2512 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
2513 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
2515 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
2517 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
2518 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
2521 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
2522 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
2524 SetSizerAndFit(sizerTop
);
2527 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
2529 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
2530 wxOK
| wxICON_INFORMATION
, this);
2533 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
2535 if ( event
.CanVeto() )
2537 wxMessageBox(wxT("Use the menu item to close this dialog"),
2538 wxT("Modeless dialog"),
2539 wxOK
| wxICON_INFORMATION
, this);
2545 // ----------------------------------------------------------------------------
2547 // ----------------------------------------------------------------------------
2549 MyModalDialog::MyModalDialog(wxWindow
*parent
)
2550 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
2552 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
2554 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2555 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2556 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2558 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2559 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2560 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2561 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2563 SetSizerAndFit(sizerTop
);
2565 SetEscapeId(wxID_CLOSE
);
2567 m_btnModal
->SetFocus();
2568 m_btnModal
->SetDefault();
2571 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2573 if ( event
.GetEventObject() == m_btnDelete
)
2575 wxDELETE(m_btnModal
);
2576 m_btnDelete
->Disable();
2578 else if ( event
.GetEventObject() == m_btnModal
)
2581 wxGetTextFromUser(wxT("Dummy prompt"),
2582 wxT("Modal dialog called from dialog"),
2583 wxEmptyString
, this);
2585 wxMessageBox(wxT("Modal dialog called from dialog"));
2586 #endif // wxUSE_TEXTDLG
2588 else if ( event
.GetEventObject() == m_btnModeless
)
2590 (new MyModelessDialog(this))->Show();
2598 #endif // USE_MODAL_PRESENTATION
2600 // ----------------------------------------------------------------------------
2601 // StdButtonSizerDialog
2602 // ----------------------------------------------------------------------------
2604 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2605 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2606 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2607 m_buttonsSizer(NULL
)
2609 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2611 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2612 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2614 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2616 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2618 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2619 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2621 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2623 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2625 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2627 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2628 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2630 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2632 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2633 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2634 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2636 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2638 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2639 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2641 sizer
->Add(sizerInside1
, 0, 0, 0);
2642 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2643 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2644 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2646 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2647 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2649 sizer
->Add(sizerInside2
, 0, 0, 0);
2650 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2651 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2652 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2654 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2656 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2657 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2658 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2660 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2662 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2664 EnableDisableControls();
2666 SetSizerAndFit(sizerTop
);
2672 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2676 m_buttonsSizer
->DeleteWindows();
2677 GetSizer()->Remove(m_buttonsSizer
);
2680 EnableDisableControls();
2683 unsigned long numButtons
= 0;
2685 if (m_chkboxAffirmativeButton
->IsChecked())
2687 if (m_radiobtnOk
->GetValue())
2692 else if (m_radiobtnYes
->GetValue())
2699 if (m_chkboxDismissButton
->IsChecked())
2701 if (m_radiobtnCancel
->GetValue())
2707 else if (m_radiobtnClose
->GetValue())
2715 if (m_chkboxApply
->IsChecked())
2721 if (m_chkboxNo
->IsChecked())
2727 if (m_chkboxHelp
->IsChecked())
2733 if (m_chkboxNoDefault
->IsChecked())
2735 flags
|= wxNO_DEFAULT
;
2738 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2739 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2742 GetSizer()->SetSizeHints(this);
2745 void StdButtonSizerDialog::EnableDisableControls()
2747 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2749 m_radiobtnOk
->Enable(affButtonEnabled
);
2750 m_radiobtnYes
->Enable(affButtonEnabled
);
2752 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2754 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2755 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2758 #if USE_SETTINGS_DIALOG
2759 // ----------------------------------------------------------------------------
2761 // ----------------------------------------------------------------------------
2763 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2765 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2768 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2770 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2775 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2776 int resizeBorder
= wxRESIZE_BORDER
;
2784 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2785 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2786 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2788 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2790 SetSheetStyle(sheetStyle
);
2791 SetSheetInnerBorder(0);
2792 SetSheetOuterBorder(0);
2794 // create a dummy image list with a few icons
2795 const wxSize
imageSize(32, 32);
2797 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2799 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2801 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2803 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2805 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2810 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2811 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2814 // If using a toolbook, also follow Mac style and don't create buttons
2816 CreateButtons(wxOK
| wxCANCEL
|
2817 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2820 wxBookCtrlBase
* notebook
= GetBookCtrl();
2821 notebook
->SetImageList(m_imageList
);
2823 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2824 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2826 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2827 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2832 SettingsDialog::~SettingsDialog()
2837 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2839 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2841 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2842 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2846 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2847 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2848 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2849 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2853 wxString autoSaveLabel
= _("&Auto-save every");
2854 wxString minsLabel
= _("mins");
2856 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2857 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2860 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2861 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2864 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2866 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2868 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2869 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2873 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2874 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2875 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2876 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2878 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2880 panel
->SetSizerAndFit(topSizer
);
2885 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2887 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2889 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2890 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2892 //// PROJECT OR GLOBAL
2893 wxString globalOrProjectChoices
[2];
2894 globalOrProjectChoices
[0] = _("&New projects");
2895 globalOrProjectChoices
[1] = _("&This project");
2897 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2898 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2899 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2901 projectOrGlobal
->SetSelection(0);
2903 //// BACKGROUND STYLE
2904 wxArrayString backgroundStyleChoices
;
2905 backgroundStyleChoices
.Add(wxT("Colour"));
2906 backgroundStyleChoices
.Add(wxT("Image"));
2907 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2909 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2910 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2912 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2914 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2916 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2917 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2918 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2920 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2923 //// FONT SIZE SELECTION
2925 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2926 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2928 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2929 wxSize(80, wxDefaultCoord
));
2930 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2932 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2935 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2936 topSizer
->AddSpacer(5);
2938 panel
->SetSizerAndFit(topSizer
);
2943 #endif // USE_SETTINGS_DIALOG
2946 // ----------------------------------------------------------------------------
2947 // TestMessageBoxDialog
2948 // ----------------------------------------------------------------------------
2951 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2956 { wxCANCEL
, "&Cancel" },
2957 { wxHELP
, "&Help" },
2960 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2961 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2962 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2965 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2966 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2967 wxDefaultPosition
, wxDefaultSize
,
2968 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2972 bool TestMessageBoxDialog::Create()
2974 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2976 // this sizer allows to configure the messages shown in the message box
2978 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2979 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Title:"));
2980 m_textTitle
= new wxTextCtrl(this, wxID_ANY
, "Test Message Box");
2981 sizerMsgs
->Add(m_textTitle
, wxSizerFlags().Expand().Border(wxBOTTOM
));
2983 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2984 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2985 wxDefaultPosition
, wxDefaultSize
,
2987 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2989 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2990 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2991 wxDefaultPosition
, wxDefaultSize
,
2993 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2995 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2997 // if a derived class provides more message configurations, add these.
2998 AddAdditionalTextOptions(sizerTop
);
3000 // this one is for configuring the buttons
3002 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
3004 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
3005 sizerBtns
->AddGrowableCol(1);
3007 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
3008 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
3010 for ( int n
= 0; n
< Btn_Max
; n
++ )
3012 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
3013 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
3015 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
3016 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
3018 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
3019 wxUpdateUIEventHandler(
3020 TestMessageBoxDialog::OnUpdateLabelUI
),
3025 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
3026 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
3030 const wxString icons
[] =
3034 "&Information icon",
3041 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == MsgDlgIcon_Max
, IconMismatch
);
3043 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon style",
3044 wxDefaultPosition
, wxDefaultSize
,
3045 WXSIZEOF(icons
), icons
,
3046 2, wxRA_SPECIFY_ROWS
);
3047 // Make the 'Information' icon the default one:
3048 m_icons
->SetSelection(MsgDlgIcon_Info
);
3049 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
3052 // miscellaneous other stuff
3054 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
3056 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
3057 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
3058 wxUpdateUIEventHandler(
3059 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
3062 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
3064 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
3065 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
3067 // add any additional flag from subclasses
3068 AddAdditionalFlags(sizerFlags
);
3070 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
3072 // finally buttons to show the resulting message box and close this dialog
3073 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
3074 wxSizerFlags().Right().Border());
3076 SetSizerAndFit(sizerTop
);
3078 m_buttons
[Btn_Ok
]->SetValue(true);
3083 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
3085 for ( int n
= 0; n
< Btn_Max
; n
++ )
3087 if ( event
.GetEventObject() == m_labels
[n
] )
3089 event
.Enable( m_buttons
[n
]->IsChecked() );
3094 wxFAIL_MSG( "called for unknown label" );
3097 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
3099 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
3102 long TestMessageBoxDialog::GetStyle()
3106 for ( int n
= 0; n
< Btn_Max
; n
++ )
3108 if ( m_buttons
[n
]->IsChecked() )
3109 style
|= ms_btnInfo
[n
].flag
;
3112 switch ( m_icons
->GetSelection() )
3114 case MsgDlgIcon_Max
:
3115 wxFAIL_MSG( "unexpected selection" );
3120 case MsgDlgIcon_None
:
3121 style
|= wxICON_NONE
;
3124 case MsgDlgIcon_Info
:
3125 style
|= wxICON_INFORMATION
;
3128 case MsgDlgIcon_Question
:
3129 style
|= wxICON_QUESTION
;
3132 case MsgDlgIcon_Warning
:
3133 style
|= wxICON_WARNING
;
3136 case MsgDlgIcon_Error
:
3137 style
|= wxICON_ERROR
;
3140 case MsgDlgIcon_AuthNeeded
:
3141 style
|= wxICON_AUTH_NEEDED
;
3145 if ( m_chkCentre
->IsChecked() )
3148 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
3149 style
|= wxNO_DEFAULT
;
3154 void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase
&dlg
)
3156 long style
= dlg
.GetMessageDialogStyle();
3158 if ( !m_textExtMsg
->IsEmpty() )
3159 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
3161 if ( style
& wxYES_NO
)
3163 if ( style
& wxCANCEL
)
3165 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
3166 m_labels
[Btn_No
]->GetValue(),
3167 m_labels
[Btn_Cancel
]->GetValue());
3171 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
3172 m_labels
[Btn_No
]->GetValue());
3177 if ( style
& wxCANCEL
)
3179 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
3180 m_labels
[Btn_Cancel
]->GetValue());
3184 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
3188 if ( style
& wxHELP
)
3190 dlg
.SetHelpLabel(m_labels
[Btn_Help
]->GetValue());
3194 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
3196 wxMessageDialog
dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3197 PrepareMessageDialog(dlg
);
3200 switch ( dlg
.ShowModal() )
3207 // Avoid the extra message box if the dialog was cancelled.
3223 btnName
= "Unknown";
3226 wxLogMessage("Dialog was closed with the \"%s\" button.", btnName
);
3229 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
3231 EndModal(wxID_CANCEL
);
3233 #endif // wxUSE_MSGDLG
3235 #if wxUSE_RICHMSGDLG
3236 // ----------------------------------------------------------------------------
3237 // TestRichMessageDialog
3238 // ----------------------------------------------------------------------------
3240 BEGIN_EVENT_TABLE(TestRichMessageDialog
, TestMessageBoxDialog
)
3241 EVT_BUTTON(wxID_APPLY
, TestRichMessageDialog::OnApply
)
3244 TestRichMessageDialog::TestRichMessageDialog(wxWindow
*parent
)
3245 : TestMessageBoxDialog(parent
)
3247 SetTitle("Rich Message Dialog Test Dialog");
3250 void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer
*sizer
)
3252 wxSizer
* const sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this,
3253 "&Additional Elements");
3255 // add a option to show a check box.
3256 wxFlexGridSizer
* const sizerCheckBox
= new wxFlexGridSizer(2, 5, 5);
3257 sizerCheckBox
->AddGrowableCol(1);
3258 sizerCheckBox
->Add(new wxStaticText(this, wxID_ANY
, "&Check box:"));
3259 m_textCheckBox
= new wxTextCtrl(this, wxID_ANY
);
3260 sizerCheckBox
->Add(m_textCheckBox
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
3261 sizerMsgs
->Add(sizerCheckBox
, wxSizerFlags(1).Expand());
3263 // add option to show a detailed text.
3264 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Detailed message:"));
3265 m_textDetailed
= new wxTextCtrl(this, wxID_ANY
, "",
3266 wxDefaultPosition
, wxDefaultSize
,
3268 sizerMsgs
->Add(m_textDetailed
, wxSizerFlags(1).Expand());
3270 sizer
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
3273 void TestRichMessageDialog::AddAdditionalFlags(wxSizer
*sizer
)
3275 // add checkbox to set the initial state for the checkbox shown
3277 m_initialValueCheckBox
=
3278 new wxCheckBox(this, wxID_ANY
, "Checkbox initially checked");
3279 sizer
->Add(m_initialValueCheckBox
, wxSizerFlags(1).Border());
3282 void TestRichMessageDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
3284 wxRichMessageDialog
dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3285 PrepareMessageDialog(dlg
);
3287 dlg
.ShowCheckBox(m_textCheckBox
->GetValue(),
3288 m_initialValueCheckBox
->GetValue());
3289 dlg
.ShowDetailedText(m_textDetailed
->GetValue());
3294 #endif // wxUSE_RICHMSGDLG
3298 // ----------------------------------------------------------------------------
3299 // custom log target
3300 // ----------------------------------------------------------------------------
3302 class MyLogGui
: public wxLogGui
3305 virtual void DoShowSingleLogMessage(const wxString
& message
,
3306 const wxString
& title
,
3309 wxMessageDialog
dlg(NULL
, message
, title
,
3310 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
3311 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
3312 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
3317 wxLog
*MyAppTraits::CreateLogTarget()
3319 return new MyLogGui
;