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"
28 #include "wx/filename.h"
30 #include "wx/bookctrl.h"
31 #include "wx/artprov.h"
32 #include "wx/imaglist.h"
33 #include "wx/minifram.h"
34 #include "wx/sysopt.h"
35 #include "wx/notifmsg.h"
36 #include "wx/modalhook.h"
39 #include "wx/richmsgdlg.h"
40 #endif // wxUSE_RICHMSGDLG
43 #include "wx/colordlg.h"
44 #endif // wxUSE_COLOURDLG
47 #include "wx/choicdlg.h"
48 #endif // wxUSE_CHOICEDLG
50 #include "wx/rearrangectrl.h"
52 #if wxUSE_STARTUP_TIPS
53 #include "wx/tipdlg.h"
54 #endif // wxUSE_STARTUP_TIPS
57 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
58 #include "wx/datetime.h" // wxDateTime
61 #include "wx/progdlg.h"
62 #endif // wxUSE_PROGRESSDLG
65 #include "wx/aboutdlg.h"
67 // these headers are only needed for custom about dialog
68 #include "wx/statline.h"
69 #include "wx/generic/aboutdlgg.h"
70 #endif // wxUSE_ABOUTDLG
73 #include "wx/busyinfo.h"
74 #endif // wxUSE_BUSYINFO
77 #include "wx/numdlg.h"
78 #endif // wxUSE_NUMBERDLG
81 #include "wx/filedlg.h"
82 #endif // wxUSE_FILEDLG
85 #include "wx/dirdlg.h"
86 #endif // wxUSE_DIRDLG
89 #include "wx/fontdlg.h"
90 #endif // wxUSE_FONTDLG
93 #include "wx/fdrepdlg.h"
94 #endif // wxUSE_FINDREPLDLG
97 #include "wx/infobar.h"
98 #endif // wxUSE_INFOBAR
100 #include "wx/spinctrl.h"
101 #include "wx/propdlg.h"
105 #if USE_COLOURDLG_GENERIC
106 #include "wx/generic/colrdlgg.h"
107 #endif // USE_COLOURDLG_GENERIC
109 #if USE_DIRDLG_GENERIC
110 #include "wx/generic/dirdlgg.h"
111 #endif // USE_DIRDLG_GENERIC
113 #if USE_FILEDLG_GENERIC
114 #include "wx/generic/filedlgg.h"
115 #endif // USE_FILEDLG_GENERIC
117 #if USE_FONTDLG_GENERIC
118 #include "wx/generic/fontdlgg.h"
119 #endif // USE_FONTDLG_GENERIC
123 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
124 EVT_PAINT(MyCanvas::OnPaint
)
129 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
131 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
132 EVT_MENU(DIALOGS_MESSAGE_BOX_WINDOW_MODAL
, MyFrame::MessageBoxWindowModal
)
133 EVT_MENU(DIALOGS_MESSAGE_DIALOG
, MyFrame::MessageBoxDialog
)
134 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
135 #endif // wxUSE_MSGDLG
137 EVT_MENU(DIALOGS_RICH_MESSAGE_DIALOG
, MyFrame::RichMessageDialog
)
138 #endif // wxUSE_RICHMSGDLG
140 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
141 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
142 #endif // wxUSE_COLOURDLG
145 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
146 #endif // wxUSE_FONTDLG
149 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
150 #endif // wxUSE_LOG_DIALOG
152 EVT_MENU(DIALOGS_INFOBAR_SIMPLE
, MyFrame::InfoBarSimple
)
153 EVT_MENU(DIALOGS_INFOBAR_ADVANCED
, MyFrame::InfoBarAdvanced
)
154 #endif // wxUSE_INFOBAR
157 EVT_MENU(DIALOGS_LINE_ENTRY
, MyFrame::LineEntry
)
158 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
159 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
160 #endif // wxUSE_TEXTDLG
163 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
164 #endif // wxUSE_NUMBERDLG
167 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
168 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
169 #endif // wxUSE_CHOICEDLG
171 #if wxUSE_REARRANGECTRL
172 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
173 #endif // wxUSE_REARRANGECTRL
176 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
177 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
178 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
179 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
180 #endif // wxUSE_FILEDLG
182 #if USE_FILEDLG_GENERIC
183 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
184 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
185 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
186 #endif // USE_FILEDLG_GENERIC
189 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
190 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
191 #endif // wxUSE_DIRDLG
193 #if USE_MODAL_PRESENTATION
194 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
195 #endif // USE_MODAL_PRESENTATION
196 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
197 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
198 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
200 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
201 #endif // wxUSE_MINIFRAME
202 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
204 #if wxUSE_STARTUP_TIPS
205 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
206 #endif // wxUSE_STARTUP_TIPS
208 #if USE_FONTDLG_GENERIC
209 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
210 #endif // USE_FONTDLG_GENERIC
212 #if USE_DIRDLG_GENERIC
213 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
214 #endif // wxMSW || wxMAC
216 #if USE_COLOURDLG_GENERIC
217 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
218 #endif // USE_COLOURDLG_GENERIC
220 #if wxUSE_PROGRESSDLG
221 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
222 #endif // wxUSE_PROGRESSDLG
225 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
226 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
227 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
228 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
229 #endif // wxUSE_ABOUTDLG
232 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
233 #endif // wxUSE_BUSYINFO
235 #if wxUSE_FINDREPLDLG
236 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
237 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
239 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
240 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
241 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
242 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
243 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
244 #endif // wxUSE_FINDREPLDLG
246 #if USE_SETTINGS_DIALOG
247 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
248 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
249 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
250 #endif // USE_SETTINGS_DIALOG
252 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
253 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
254 EVT_MENU(DIALOGS_MODAL_HOOK
, MyFrame::OnModalHook
)
256 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
257 #if wxUSE_NOTIFICATION_MESSAGE
258 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
259 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
260 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
261 #endif // wxUSE_NOTIFICATION_MESSAGE
263 #if wxUSE_RICHTOOLTIP
264 EVT_MENU(DIALOGS_RICHTIP_DIALOG
, MyFrame::OnRichTipDialog
)
265 #endif // wxUSE_RICHTOOLTIP
267 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
270 #if USE_MODAL_PRESENTATION
272 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
273 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
276 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
277 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
278 EVT_CLOSE(MyModelessDialog::OnClose
)
281 #endif // USE_MODAL_PRESENTATION
283 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
284 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
285 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
288 #if wxUSE_CMDLINE_PARSER
290 #include "wx/cmdline.h"
292 static const char *PROGRESS_SWITCH
= "progress";
294 void MyApp::OnInitCmdLine(wxCmdLineParser
& parser
)
296 wxApp::OnInitCmdLine(parser
);
298 parser
.AddOption("", PROGRESS_SWITCH
,
299 "Style for the startup progress dialog (wxPD_XXX)",
300 wxCMD_LINE_VAL_NUMBER
);
303 bool MyApp::OnCmdLineParsed(wxCmdLineParser
& parser
)
305 if ( !wxApp::OnCmdLineParsed(parser
) )
308 parser
.Found(PROGRESS_SWITCH
, &m_startupProgressStyle
);
313 #endif // wxUSE_CMDLINE_PARSER
315 // `Main program' equivalent, creating windows and returning main app frame
318 if ( !wxApp::OnInit() )
321 #if wxUSE_PROGRESSDLG
322 if ( m_startupProgressStyle
!= -1 )
324 // Show a test progress dialog before the main event loop is started:
325 // it should still work.
326 const int PROGRESS_COUNT
= 100;
329 "Progress in progress",
330 "Please wait, starting...",
333 m_startupProgressStyle
335 for ( int i
= 0; i
<= PROGRESS_COUNT
; i
++ )
337 if ( !dlg
.Update(i
) )
343 #endif // wxUSE_PROGRESSDLG
346 wxInitAllImageHandlers();
349 // Create the main frame window
350 MyFrame
*frame
= new MyFrame(wxT("wxWidgets dialogs example"));
353 wxMenu
*menuDlg
= new wxMenu
;
355 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
356 menuDlg
->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL
, wxT("Window-Modal Message box "));
357 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
359 menuDlg
->Append(DIALOGS_RICH_MESSAGE_DIALOG
, wxT("Rich message dialog"));
360 #endif // wxUSE_RICHMSGDLG
363 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
365 wxMenu
*choices_menu
= new wxMenu
;
368 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
369 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
370 #endif // wxUSE_COLOURDLG
373 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
374 #endif // wxUSE_FONTDLG
377 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
378 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
379 #endif // wxUSE_CHOICEDLG
381 #if wxUSE_REARRANGECTRL
382 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
383 #endif // wxUSE_REARRANGECTRL
385 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
386 choices_menu
->AppendSeparator();
387 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
389 #if USE_COLOURDLG_GENERIC
390 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
391 #endif // USE_COLOURDLG_GENERIC
393 #if USE_FONTDLG_GENERIC
394 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
395 #endif // USE_FONTDLG_GENERIC
397 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
398 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
401 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
403 wxMenu
*entry_menu
= new wxMenu
;
406 entry_menu
->Append(DIALOGS_LINE_ENTRY
, wxT("Single line &entry\tCtrl-E"));
407 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Multi line text &entry\tShift-Ctrl-E"));
408 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
409 #endif // wxUSE_TEXTDLG
412 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
413 #endif // wxUSE_NUMBERDLG
415 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
417 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
422 wxMenu
*filedlg_menu
= new wxMenu
;
423 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
424 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
425 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
426 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
428 #if USE_FILEDLG_GENERIC
429 filedlg_menu
->AppendSeparator();
430 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
431 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
432 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
433 #endif // USE_FILEDLG_GENERIC
435 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
437 #endif // wxUSE_FILEDLG
440 wxMenu
*dir_menu
= new wxMenu
;
442 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
443 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
444 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
446 #if USE_DIRDLG_GENERIC
447 dir_menu
->AppendSeparator();
448 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
449 #endif // USE_DIRDLG_GENERIC
451 #endif // wxUSE_DIRDLG
454 #if wxUSE_STARTUP_TIPS || \
455 wxUSE_PROGRESSDLG || \
457 wxUSE_LOG_DIALOG || \
460 wxMenu
*info_menu
= new wxMenu
;
462 #if wxUSE_STARTUP_TIPS
463 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
464 #endif // wxUSE_STARTUP_TIPS
466 #if wxUSE_PROGRESSDLG
467 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
468 #endif // wxUSE_PROGRESSDLG
471 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
472 #endif // wxUSE_BUSYINFO
475 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
476 #endif // wxUSE_LOG_DIALOG
479 info_menu
->Append(DIALOGS_INFOBAR_SIMPLE
, "Simple &info bar\tCtrl-I");
480 info_menu
->Append(DIALOGS_INFOBAR_ADVANCED
, "&Advanced info bar\tShift-Ctrl-I");
481 #endif // wxUSE_INFOBAR
484 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
485 wxT("&wxWidgets information\tCtrl-W"));
486 #endif // wxUSE_MSGDLG
488 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
490 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
493 #if wxUSE_FINDREPLDLG
494 wxMenu
*find_menu
= new wxMenu
;
495 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
496 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
497 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
498 #endif // wxUSE_FINDREPLDLG
500 wxMenu
*dialogs_menu
= new wxMenu
;
501 #if USE_MODAL_PRESENTATION
502 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tShift-Ctrl-W"));
503 #endif // USE_MODAL_PRESENTATION
504 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tShift-Ctrl-Z"));
505 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
506 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
508 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
509 #endif // wxUSE_MINIFRAME
510 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
511 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
513 #if USE_SETTINGS_DIALOG
514 wxMenu
*sheet_menu
= new wxMenu
;
515 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
516 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
518 if (wxPlatformIs(wxPORT_MAC
))
519 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
522 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
525 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
526 #endif // USE_SETTINGS_DIALOG
528 wxMenu
*menuNotif
= new wxMenu
;
529 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
530 #if wxUSE_NOTIFICATION_MESSAGE
531 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
532 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
533 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
534 #endif // wxUSE_NOTIFICATION_MESSAGE
535 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
537 #if wxUSE_RICHTOOLTIP
538 menuDlg
->Append(DIALOGS_RICHTIP_DIALOG
, "Rich &tooltip dialog...\tCtrl-H");
539 menuDlg
->AppendSeparator();
540 #endif // wxUSE_RICHTOOLTIP
542 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
543 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
544 menuDlg
->AppendCheckItem(DIALOGS_MODAL_HOOK
, "Enable modal dialog hook");
546 menuDlg
->AppendSeparator();
547 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
550 wxMenu
*menuHelp
= new wxMenu
;
551 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
552 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
553 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
554 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
555 #endif // wxUSE_ABOUTDLG
557 wxMenu
* editMenu
= new wxMenu
;
558 editMenu
->Append(wxID_UNDO
, _("&Undo\tCtrl+Z"));
559 editMenu
->Append(wxID_REDO
, _("&Redo\tCtrl+Y"));
560 editMenu
->AppendSeparator();
561 editMenu
->Append(wxID_CUT
, _("Cu&t\tCtrl+X"));
562 editMenu
->Append(wxID_COPY
, _("&Copy\tCtrl+C"));
563 editMenu
->Append(wxID_PASTE
, _("&Paste\tCtrl+V"));
564 editMenu
->Append(wxID_CLEAR
, _("&Delete"));
566 editMenu
->AppendSeparator();
567 editMenu
->Append(wxID_SELECTALL
, _("Select All\tCtrl+A"));
569 wxMenuBar
*menubar
= new wxMenuBar
;
570 menubar
->Append(menuDlg
, wxT("&Dialogs"));
572 menubar
->Append(editMenu
, wxT("&Edit"));
575 menubar
->Append(menuHelp
, wxT("&Help"));
576 #endif // wxUSE_ABOUTDLG
578 frame
->SetMenuBar(menubar
);
580 frame
->Centre(wxBOTH
);
586 // My frame constructor
587 MyFrame::MyFrame(const wxString
& title
)
588 : wxFrame(NULL
, wxID_ANY
, title
)
590 SetIcon(wxICON(sample
));
592 #if USE_MODAL_PRESENTATION
593 m_dialog
= (MyModelessDialog
*)NULL
;
594 #endif // USE_MODAL_PRESENTATION
596 #if wxUSE_FINDREPLDLG
602 m_clrData
.SetChooseFull(true);
603 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
605 unsigned char n
= i
*16;
606 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
608 #endif // wxUSE_COLOURDLG
610 #if wxUSE_NOTIFICATION_MESSAGE
612 #endif // wxUSE_NOTIFICATION_MESSAGE
616 #endif // wxUSE_STATUSBAR
618 m_canvas
= new MyCanvas(this);
621 // an info bar can be created very simply and used without any extra effort
622 m_infoBarSimple
= new wxInfoBar(this);
624 // or it can also be customized by
625 m_infoBarAdvanced
= new wxInfoBar(this);
627 // ... adding extra buttons (but more than two will usually be too many)
628 m_infoBarAdvanced
->AddButton(wxID_UNDO
);
629 m_infoBarAdvanced
->AddButton(wxID_REDO
);
631 m_infoBarAdvanced
->Connect(wxID_REDO
, wxEVT_BUTTON
,
632 wxCommandEventHandler(MyFrame::OnInfoBarRedo
),
636 // adding and removing a button immediately doesn't make sense here, of
637 // course, it's done just to show that it is possible
638 m_infoBarAdvanced
->AddButton(wxID_EXIT
);
639 m_infoBarAdvanced
->RemoveButton(wxID_EXIT
);
641 // ... changing the colours and/or fonts
642 m_infoBarAdvanced
->SetOwnBackgroundColour(0xc8ffff);
643 m_infoBarAdvanced
->SetFont(GetFont().Bold().Larger());
645 // ... and changing the effect (only does anything under MSW currently)
646 m_infoBarAdvanced
->SetShowHideEffects(wxSHOW_EFFECT_EXPAND
,
647 wxSHOW_EFFECT_EXPAND
);
648 m_infoBarAdvanced
->SetEffectDuration(1500);
651 // to use the info bars we need to use sizer for the window layout
652 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
653 sizer
->Add(m_infoBarSimple
, wxSizerFlags().Expand());
654 sizer
->Add(m_canvas
, wxSizerFlags(1).Expand());
655 sizer
->Add(m_infoBarAdvanced
, wxSizerFlags().Expand());
658 // final touch: under MSW the info bars are shown progressively and parts
659 // of the parent window can be seen during the process, so use the same
660 // background colour for our background as for the canvas window which
661 // covers our entire client area to avoid jarring colour jumps
662 SetOwnBackgroundColour(m_canvas
->GetBackgroundColour());
663 #endif // wxUSE_INFOBAR
666 // Test MSW-specific function allowing to access the "system" menu.
667 wxMenu
* const menu
= MSWGetSystemMenu();
670 menu
->AppendSeparator();
672 // The ids of the menu commands in MSW system menu must be multiple of
673 // 16 so we can't use DIALOGS_ABOUTDLG_SIMPLE here because it might not
674 // satisfy this condition and need to define and connect a separate id.
675 static const int DIALOGS_SYSTEM_ABOUT
= 0x4010;
677 menu
->Append(DIALOGS_SYSTEM_ABOUT
, "&About");
678 Connect(DIALOGS_SYSTEM_ABOUT
, wxEVT_MENU
,
679 wxCommandEventHandler(MyFrame::ShowSimpleAboutDialog
));
686 #if wxUSE_NOTIFICATION_MESSAGE
688 #endif // wxUSE_NOTIFICATION_MESSAGE
693 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
695 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
697 wxColourDialog
dialog(this, &m_clrData
);
698 dialog
.SetTitle(_("Please choose the background colour"));
699 if ( dialog
.ShowModal() == wxID_OK
)
701 m_clrData
= dialog
.GetColourData();
702 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
703 m_canvas
->ClearBackground();
708 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
710 wxColour clr
= wxGetColourFromUser
713 m_canvas
->GetForegroundColour(),
714 "Please choose the foreground colour"
718 m_canvas
->SetForegroundColour(clr
);
721 //else: dialog cancelled by user
724 #endif // wxUSE_COLOURDLG
727 #if USE_COLOURDLG_GENERIC
728 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
730 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
732 //FIXME:TODO:This has no effect...
733 m_clrData
.SetChooseFull(true);
735 for (int i
= 0; i
< 16; i
++)
738 (unsigned char)(i
*16),
739 (unsigned char)(i
*16),
740 (unsigned char)(i
*16)
742 m_clrData
.SetCustomColour(i
, colour
);
745 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
746 if (dialog
->ShowModal() == wxID_OK
)
748 m_clrData
= dialog
->GetColourData();
749 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
750 m_canvas
->ClearBackground();
755 #endif // USE_COLOURDLG_GENERIC
758 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
761 data
.SetInitialFont(m_canvas
->GetFont());
762 data
.SetColour(m_canvas
->GetForegroundColour());
764 // you might also do this:
766 // wxFontDialog dialog;
767 // if ( !dialog.Create(this, data) { ... error ... }
769 wxFontDialog
dialog(this, data
);
771 if (dialog
.ShowModal() == wxID_OK
)
773 wxFontData retData
= dialog
.GetFontData();
774 m_canvas
->SetFont(retData
.GetChosenFont());
775 m_canvas
->SetForegroundColour(retData
.GetColour());
778 //else: cancelled by the user, don't change the font
780 #endif // wxUSE_FONTDLG
782 #if USE_FONTDLG_GENERIC
783 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
786 data
.SetInitialFont(m_canvas
->GetFont());
787 data
.SetColour(m_canvas
->GetForegroundColour());
789 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
790 if (dialog
->ShowModal() == wxID_OK
)
792 wxFontData retData
= dialog
->GetFontData();
793 m_canvas
->SetFont(retData
.GetChosenFont());
794 m_canvas
->SetForegroundColour(retData
.GetColour());
799 #endif // USE_FONTDLG_GENERIC
802 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
804 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
805 // being flushed -- test it
808 wxLogMessage(wxT("This is some message - everything is ok so far."));
809 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
810 wxLogWarning(wxT("And then something went wrong!"));
812 // and if ~wxBusyCursor doesn't do it, then call it manually
816 wxLogError(wxT("Intermediary error handler decided to abort."));
817 wxLogError(wxT("The top level caller detected an unrecoverable error."));
819 wxLog::FlushActive();
821 wxLogMessage(wxT("And this is the same dialog but with only one message."));
823 #endif // wxUSE_LOG_DIALOG
827 void MyFrame::InfoBarSimple(wxCommandEvent
& WXUNUSED(event
))
829 static int s_count
= 0;
830 m_infoBarSimple
->ShowMessage
832 wxString::Format("Message #%d in the info bar.", ++s_count
)
836 void MyFrame::InfoBarAdvanced(wxCommandEvent
& WXUNUSED(event
))
838 m_infoBarAdvanced
->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING
);
841 void MyFrame::OnInfoBarRedo(wxCommandEvent
& WXUNUSED(event
))
843 m_infoBarAdvanced
->ShowMessage("Still no, sorry again.", wxICON_ERROR
);
846 #endif // wxUSE_INFOBAR
850 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
852 wxMessageDialog
dialog(this,
853 "This is a message box\n"
854 "This is a long, long string to test out if the message box "
855 "is laid out properly.",
858 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
862 if ( dialog
.SetYesNoCancelLabels
869 extmsg
= "This platform supports custom button labels,\n"
870 "so you should see the descriptive labels below.";
874 extmsg
= "Custom button labels are not supported on this platform,\n"
875 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
877 dialog
.SetExtendedMessage(extmsg
);
879 switch ( dialog
.ShowModal() )
882 wxLogStatus(wxT("You pressed \"Yes\""));
886 wxLogStatus(wxT("You pressed \"No\""));
890 wxLogStatus(wxT("You pressed \"Cancel\""));
894 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
898 void MyFrame::MessageBoxWindowModal(wxCommandEvent
& WXUNUSED(event
))
900 wxMessageDialog
* dialog
= new wxMessageDialog(this,
901 "This is a message box\n"
902 "This is a long, long string to test out if the message box "
903 "is laid out properly.",
906 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
910 if ( dialog
->SetYesNoCancelLabels
917 extmsg
= "This platform supports custom button labels,\n"
918 "so you should see the descriptive labels below.";
922 extmsg
= "Custom button labels are not supported on this platform,\n"
923 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
925 dialog
->SetExtendedMessage(extmsg
);
926 dialog
->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed
), NULL
, this );
927 dialog
->ShowWindowModal();
930 void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent
& event
)
932 wxDialog
* dialog
= event
.GetDialog();
933 switch ( dialog
->GetReturnCode() )
936 wxLogStatus(wxT("You pressed \"Yes\""));
940 wxLogStatus(wxT("You pressed \"No\""));
944 wxLogStatus(wxT("You pressed \"Cancel\""));
948 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
953 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
955 TestMessageBoxDialog
dlg(this);
960 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
962 ::wxInfoMessageBox(this);
964 #endif // wxUSE_MSGDLG
967 void MyFrame::RichMessageDialog(wxCommandEvent
& WXUNUSED(event
))
969 TestRichMessageDialog
dlg(this);
973 #endif // wxUSE_RICHMSGDLG
976 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
978 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
979 wxT("Even two rows of text."),
980 wxT("Enter a number:"), wxT("Numeric input test"),
987 msg
= wxT("Invalid number entered or dialog cancelled.");
992 msg
.Printf(wxT("You've entered %lu"), res
);
993 icon
= wxICON_INFORMATION
;
996 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
998 #endif // wxUSE_NUMBERDLG
1001 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
1003 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
1004 wxT("Password entry dialog"),
1009 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
1010 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
1014 void MyFrame::LineEntry(wxCommandEvent
& WXUNUSED(event
))
1016 wxTextEntryDialog
dialog(this,
1017 wxT("This is a small sample\n")
1018 wxT("A long, long string to test out the text entrybox"),
1019 wxT("Please enter a string"),
1020 wxT("Default value"),
1023 if (dialog
.ShowModal() == wxID_OK
)
1025 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
1029 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
1031 wxTextEntryDialog
dialog(this, "You can enter a multiline string here.",
1032 "Please enter some text",
1033 "First line\nSecond one\nAnd another one too",
1034 wxOK
| wxCANCEL
| wxTE_MULTILINE
);
1036 if (dialog
.ShowModal() == wxID_OK
)
1038 wxMessageBox(dialog
.GetValue(), wxT("Got text"), wxOK
| wxICON_INFORMATION
, this);
1041 #endif // wxUSE_TEXTDLG
1044 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
1046 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
1048 wxSingleChoiceDialog
dialog(this,
1049 wxT("This is a small sample\n")
1050 wxT("A single-choice convenience dialog"),
1051 wxT("Please select a value"),
1052 WXSIZEOF(choices
), choices
);
1054 dialog
.SetSelection(2);
1056 if (dialog
.ShowModal() == wxID_OK
)
1058 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
1059 dialog2
.ShowModal();
1063 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
1065 const wxString choices
[] =
1067 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
1068 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
1069 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
1072 wxArrayInt selections
;
1073 const int count
= wxGetSelectedChoices(selections
,
1074 wxT("This is a small sample\n")
1075 wxT("A multi-choice convenience dialog"),
1076 wxT("Please select a value"),
1077 WXSIZEOF(choices
), choices
,
1084 msg
= wxT("You did not select any items");
1088 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
1089 for ( int n
= 0; n
< count
; n
++ )
1091 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
1092 (unsigned)n
, (unsigned)selections
[n
],
1093 choices
[selections
[n
]].c_str());
1100 #endif // wxUSE_CHOICEDLG
1102 #if wxUSE_REARRANGECTRL
1103 // custom rearrange dialog: it adds the possibility to rename an item to the
1104 // base class functionality
1105 class MyRearrangeDialog
: public wxRearrangeDialog
1108 MyRearrangeDialog(wxWindow
*parent
,
1110 wxArrayString
& labels
,
1111 wxArrayString
& labelsOrig
)
1115 "Configure the columns shown:",
1116 "wxRearrangeDialog example",
1122 m_labelsOrig(labelsOrig
)
1124 m_sel
= wxNOT_FOUND
;
1126 wxPanel
* const panel
= new wxPanel(this);
1127 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1129 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
1130 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
1132 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
1133 wxDefaultPosition
, wxDefaultSize
,
1134 wxTE_PROCESS_ENTER
);
1135 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
1137 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
1138 wxSizerFlags().Centre());
1140 panel
->SetSizer(sizer
);
1142 // call this first to ensure that the controls have a reasonable best
1143 // size before they're added
1144 DoUpdateExtraControls(GetList()->GetSelection());
1146 AddExtraControls(panel
);
1149 // another customization not directly supported by the dialog: add a
1151 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
1152 wxCHECK_RET( btnOk
, "no Ok button?" );
1154 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
1155 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
1157 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
1158 wxSizerFlags().Border(wxLEFT
));
1161 // call this instead of ShowModal() to update order and labels array in
1162 // case the dialog was not cancelled
1165 switch ( ShowModal() )
1171 m_order
= GetOrder();
1175 // order already reset
1183 void OnSelChange(wxCommandEvent
& event
)
1185 DoUpdateExtraControls(event
.GetInt());
1188 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
1190 event
.Enable( CanRename() );
1193 void OnRename(wxCommandEvent
& WXUNUSED(event
))
1198 m_labels
[m_sel
] = m_text
->GetValue();
1199 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
1202 void OnReset(wxCommandEvent
& WXUNUSED(event
))
1204 // in a real program we should probably ask if the user really wants to
1205 // do this but here we just go ahead and reset all columns labels and
1206 // their order without confirmation
1207 const unsigned count
= m_order
.size();
1208 for ( unsigned n
= 0; n
< count
; n
++ )
1211 m_labels
[n
] = m_labelsOrig
[n
];
1214 EndModal(wxID_RESET
);
1217 bool CanRename() const
1219 // only allow renaming if the user modified the currently selected item
1220 // text (which presupposes that we do have a current item)
1221 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
1224 void DoUpdateExtraControls(int sel
)
1228 if ( m_sel
== wxNOT_FOUND
)
1230 m_labelOrig
->SetLabel("<no selection>");
1234 else // have valid item
1236 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
1238 m_text
->SetValue(m_labels
[m_sel
]);
1242 wxArrayInt
& m_order
;
1243 wxArrayString
& m_labels
,
1247 wxStaticText
*m_labelOrig
;
1250 DECLARE_EVENT_TABLE()
1251 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
1254 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
1255 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
1257 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
1259 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
1260 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
1261 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
1264 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
1266 // the arrays are static so that we preserve the items order between calls
1268 static wxArrayInt s_order
;
1269 static wxArrayString s_labels
,
1272 // initialize them on the first call
1273 if ( s_labelsOrig
.empty() )
1275 static const struct ItemInfo
1278 const char *labelOrig
;
1282 { "File name", "Name", 0 },
1283 { "File type", "Ext", 1 },
1284 { "Size", "Size", 2 },
1285 { "Creation time", "Ctime", ~3 }, // negated so hidden
1286 { "Last accessed", "Atime", ~4 },
1287 { "Last modified", "Mtime", 5 },
1290 s_order
.reserve(WXSIZEOF(items
));
1291 s_labels
.reserve(WXSIZEOF(items
));
1292 s_labelsOrig
.reserve(WXSIZEOF(items
));
1293 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1295 const ItemInfo
& item
= items
[n
];
1296 s_order
.push_back(item
.order
);
1297 s_labels
.push_back(item
.label
);
1298 s_labelsOrig
.push_back(item
.labelOrig
);
1302 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1303 if ( !dlg
.Rearrange() )
1307 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1309 columns
+= wxString::Format("\n %u: ", n
);
1310 int idx
= s_order
[n
];
1313 columns
+= "[hidden] ";
1317 columns
+= s_labels
[idx
];
1318 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1320 columns
+= wxString::Format(" (original label: \"%s\")",
1325 wxLogMessage("The columns order now is:%s", columns
);
1327 #endif // wxUSE_REARRANGECTRL
1331 // panel with custom controls for file dialog
1332 class MyExtraPanel
: public wxPanel
1335 MyExtraPanel(wxWindow
*parent
);
1336 wxString
GetInfo() const
1338 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1342 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1343 void OnUpdateLabelUI(wxUpdateUIEvent
& event
)
1345 wxFileDialog
* const dialog
= wxStaticCast(GetParent(), wxFileDialog
);
1346 const wxString fn
= dialog
->GetCurrentlySelectedFilename();
1351 else if ( wxFileName::FileExists(fn
) )
1353 else if ( wxFileName::DirExists(fn
) )
1356 msg
= "Something else";
1358 event
.SetText(msg
+ " selected");
1363 wxStaticText
*m_label
;
1366 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1369 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1370 m_btn
->Enable(false);
1371 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1372 m_cb
->Connect(wxEVT_CHECKBOX
,
1373 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1374 m_label
= new wxStaticText(this, wxID_ANY
, "Nothing selected");
1375 m_label
->Connect(wxEVT_UPDATE_UI
,
1376 wxUpdateUIEventHandler(MyExtraPanel::OnUpdateLabelUI
),
1379 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1380 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1381 sizerTop
->AddStretchSpacer();
1382 sizerTop
->Add(m_btn
, wxSizerFlags().Centre().Border());
1383 sizerTop
->AddStretchSpacer();
1384 sizerTop
->Add(m_label
, wxSizerFlags().Centre().Border());
1386 SetSizerAndFit(sizerTop
);
1389 // a static method can be used instead of a function with most of compilers
1390 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1392 return new MyExtraPanel(parent
);
1395 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1400 wxT("Testing open file dialog"),
1404 wxT("C++ files (*.cpp)|*.cpp")
1406 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1410 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1411 dialog
.CentreOnParent();
1412 dialog
.SetDirectory(wxGetHomeDir());
1414 if (dialog
.ShowModal() == wxID_OK
)
1417 wxWindow
* const extra
= dialog
.GetExtraControl();
1418 info
.Printf(wxT("Full file name: %s\n")
1421 wxT("Custom window: %s"),
1422 dialog
.GetPath().c_str(),
1423 dialog
.GetDirectory().c_str(),
1424 dialog
.GetFilename().c_str(),
1425 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1426 : wxString("None"));
1427 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1428 dialog2
.ShowModal();
1432 // this shows how to take advantage of specifying a default extension in the
1433 // call to wxFileSelector: it is remembered after each new call and the next
1434 // one will use it by default
1435 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1437 static wxString s_extDef
;
1438 wxString path
= wxFileSelector(
1439 wxT("Select the file to load"),
1440 wxEmptyString
, wxEmptyString
,
1444 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1445 wxFileSelectorDefaultWildcardStr
,
1446 wxFileSelectorDefaultWildcardStr
1448 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1455 // it is just a sample, would use wxSplitPath in real program
1456 s_extDef
= path
.AfterLast(wxT('.'));
1458 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1462 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1464 wxString wildcards
=
1466 wxT("C++ files (*.cpp)|*.cpp");
1470 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1471 wxFileSelectorDefaultWildcardStr
,
1472 wxFileSelectorDefaultWildcardStr
1475 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1476 wxEmptyString
, wxEmptyString
, wildcards
,
1477 wxFD_OPEN
|wxFD_MULTIPLE
);
1479 if (dialog
.ShowModal() == wxID_OK
)
1481 wxArrayString paths
, filenames
;
1483 dialog
.GetPaths(paths
);
1484 dialog
.GetFilenames(filenames
);
1487 size_t count
= paths
.GetCount();
1488 for ( size_t n
= 0; n
< count
; n
++ )
1490 s
.Printf(wxT("File %d: %s (%s)\n"),
1491 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1495 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1498 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1499 dialog2
.ShowModal();
1503 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1505 wxFileDialog
dialog(this,
1506 wxT("Testing save file dialog"),
1508 wxT("myletter.doc"),
1509 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1510 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1512 dialog
.SetFilterIndex(1);
1514 if (dialog
.ShowModal() == wxID_OK
)
1516 wxLogMessage(wxT("%s, filter %d"),
1517 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1520 #endif // wxUSE_FILEDLG
1522 #if USE_FILEDLG_GENERIC
1523 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1525 wxGenericFileDialog dialog
1528 wxT("Testing open file dialog"),
1531 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1534 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1535 dialog
.SetDirectory(wxGetHomeDir());
1537 if (dialog
.ShowModal() == wxID_OK
)
1540 info
.Printf(wxT("Full file name: %s\n")
1543 dialog
.GetPath().c_str(),
1544 dialog
.GetDirectory().c_str(),
1545 dialog
.GetFilename().c_str());
1546 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1547 dialog2
.ShowModal();
1551 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1553 // On PocketPC you can disable OK-only dialogs policy using system option
1554 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1555 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1557 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1558 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1559 wxEmptyString
, wxEmptyString
, wildcards
,
1562 if (dialog
.ShowModal() == wxID_OK
)
1564 wxArrayString paths
, filenames
;
1566 dialog
.GetPaths(paths
);
1567 dialog
.GetFilenames(filenames
);
1570 size_t count
= paths
.GetCount();
1571 for ( size_t n
= 0; n
< count
; n
++ )
1573 s
.Printf(wxT("File %d: %s (%s)\n"),
1574 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1578 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1581 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1582 dialog2
.ShowModal();
1585 // restore system option
1586 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1589 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1591 wxGenericFileDialog
dialog(this,
1592 wxT("Testing save file dialog"),
1594 wxT("myletter.doc"),
1595 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1596 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1598 dialog
.SetFilterIndex(1);
1600 if (dialog
.ShowModal() == wxID_OK
)
1602 wxLogMessage(wxT("%s, filter %d"),
1603 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1606 #endif // USE_FILEDLG_GENERIC
1609 void MyFrame::DoDirChoose(int style
)
1611 // pass some initial dir to wxDirDialog
1613 wxGetHomeDir(&dirHome
);
1615 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1617 if (dialog
.ShowModal() == wxID_OK
)
1619 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1623 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1625 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1628 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1630 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1632 #endif // wxUSE_DIRDLG
1634 #if USE_DIRDLG_GENERIC
1635 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1637 // pass some initial dir to wxDirDialog
1639 wxGetHomeDir(&dirHome
);
1641 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1643 if (dialog
.ShowModal() == wxID_OK
)
1645 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1646 dialog2
.ShowModal();
1649 #endif // USE_DIRDLG_GENERIC
1651 #if USE_MODAL_PRESENTATION
1652 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1654 MyModalDialog
dlg(this);
1657 #endif // USE_MODAL_PRESENTATION
1659 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1661 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1667 m_dialog
= new MyModelessDialog(this);
1670 m_dialog
->Show(true);
1674 // If m_dialog is NULL, then possibly the system
1675 // didn't report the checked menu item status correctly.
1676 // It should be true just after the menu item was selected,
1677 // if there was no modeless dialog yet.
1679 wxASSERT( m_dialog
!= NULL
);
1685 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1687 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1688 wxDefaultPosition
, wxSize(200, 100));
1689 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1690 dlg
.CentreOnScreen();
1694 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1696 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1697 wxDefaultPosition
, wxSize(200, 100));
1698 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1699 dlg
.CentreOnParent();
1704 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1706 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1707 wxDefaultPosition
, wxSize(300, 100),
1708 wxCAPTION
| wxCLOSE_BOX
);
1709 new wxStaticText(frame
,
1711 wxT("Mini frames have slightly different appearance"),
1713 new wxStaticText(frame
,
1715 wxT("from the normal frames but that's the only difference."),
1718 frame
->CentreOnParent();
1721 #endif // wxUSE_MINIFRAME
1723 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1725 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1726 wxDefaultPosition
, wxSize(300, 100),
1727 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1728 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1732 #if wxUSE_STARTUP_TIPS
1733 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1735 static size_t s_index
= (size_t)-1;
1737 if ( s_index
== (size_t)-1 )
1741 // this is completely bogus, we don't know how many lines are there
1742 // in the file, but who cares, it's a demo only...
1743 s_index
= rand() % 5;
1746 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1748 bool showAtStartup
= wxShowTip(this, tipProvider
);
1750 if ( showAtStartup
)
1752 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1753 wxOK
| wxICON_INFORMATION
, this);
1756 s_index
= tipProvider
->GetCurrentTip();
1759 #endif // wxUSE_STARTUP_TIPS
1761 #if USE_SETTINGS_DIALOG
1762 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1764 SettingsDialog
dialog(this, event
.GetId());
1767 #endif // USE_SETTINGS_DIALOG
1769 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1771 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1775 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1778 #if wxUSE_NOTIFICATION_MESSAGE
1780 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1782 // Notice that the notification remains shown even after the
1783 // wxNotificationMessage object itself is destroyed so we can show simple
1784 // notifications using temporary objects.
1785 if ( !wxNotificationMessage
1787 "Automatic Notification",
1788 "Nothing important has happened\n"
1789 "this notification will disappear soon."
1792 wxLogStatus("Failed to show notification message");
1795 // But it doesn't have to be a temporary, of course.
1796 wxNotificationMessage
n("Dummy Warning", "Example of a warning notification.");
1797 n
.SetFlags(wxICON_ERROR
);
1798 n
.Show(5); // Just for testing, use 5 second delay.
1801 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1805 m_notifMsg
= new wxNotificationMessage
1807 "wxWidgets Manual Notification",
1808 "You can hide this notification from the menu",
1813 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1815 wxLogStatus("Failed to show manual notification message");
1819 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1821 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1823 wxLogStatus("Failed to hide manual notification message");
1827 #endif // wxUSE_NOTIFICATION_MESSAGE
1829 #if wxUSE_RICHTOOLTIP
1831 #include "wx/richtooltip.h"
1835 class RichTipDialog
: public wxDialog
1838 RichTipDialog(wxWindow
* parent
)
1839 : wxDialog(parent
, wxID_ANY
, "wxRichToolTip Test",
1840 wxDefaultPosition
, wxDefaultSize
,
1841 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
1843 // Create the controls.
1844 m_textTitle
= new wxTextCtrl(this, wxID_ANY
, "Tooltip title");
1845 m_textBody
= new wxTextCtrl(this, wxID_ANY
, "Main tooltip text\n"
1846 "possibly on several\n"
1848 wxDefaultPosition
, wxDefaultSize
,
1850 wxButton
* btnShowText
= new wxButton(this, wxID_ANY
, "Show for &text");
1851 wxButton
* btnShowBtn
= new wxButton(this, wxID_ANY
, "Show for &button");
1853 const wxString icons
[] =
1861 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == Icon_Max
, IconMismatch
);
1862 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon choice:",
1863 wxDefaultPosition
, wxDefaultSize
,
1864 WXSIZEOF(icons
), icons
,
1865 1, wxRA_SPECIFY_ROWS
);
1866 m_icons
->SetSelection(Icon_Info
);
1868 const wxString tipKinds
[] =
1870 "&None", "Top left", "Top", "Top right",
1871 "Bottom left", "Bottom", "Bottom right", "&Auto"
1873 m_tipKinds
= new wxRadioBox(this, wxID_ANY
, "Tip &kind:",
1874 wxDefaultPosition
, wxDefaultSize
,
1875 WXSIZEOF(tipKinds
), tipKinds
,
1876 4, wxRA_SPECIFY_COLS
);
1877 m_tipKinds
->SetSelection(wxTipKind_Auto
);
1879 const wxString bgStyles
[] =
1881 "&Default", "&Solid", "&Gradient",
1883 wxCOMPILE_TIME_ASSERT( WXSIZEOF(bgStyles
) == Bg_Max
, BgMismatch
);
1884 m_bgStyles
= new wxRadioBox(this, wxID_ANY
, "Background style:",
1885 wxDefaultPosition
, wxDefaultSize
,
1886 WXSIZEOF(bgStyles
), bgStyles
,
1887 1, wxRA_SPECIFY_ROWS
);
1889 const wxString timeouts
[] = { "&None", "&Default (no delay)", "&3 seconds" };
1890 wxCOMPILE_TIME_ASSERT( WXSIZEOF(timeouts
) == Timeout_Max
, TmMismatch
);
1891 m_timeouts
= new wxRadioBox(this, wxID_ANY
, "Timeout:",
1892 wxDefaultPosition
, wxDefaultSize
,
1893 WXSIZEOF(timeouts
), timeouts
,
1894 1, wxRA_SPECIFY_ROWS
);
1895 m_timeouts
->SetSelection(Timeout_Default
);
1896 m_timeDelay
= new wxCheckBox(this, wxID_ANY
, "Delay show" );
1899 m_textBody
->SetMinSize(wxSize(300, 200));
1901 wxBoxSizer
* const sizer
= new wxBoxSizer(wxVERTICAL
);
1902 sizer
->Add(m_textTitle
, wxSizerFlags().Expand().Border());
1903 sizer
->Add(m_textBody
, wxSizerFlags(1).Expand().Border());
1904 sizer
->Add(m_icons
, wxSizerFlags().Expand().Border());
1905 sizer
->Add(m_tipKinds
, wxSizerFlags().Centre().Border());
1906 sizer
->Add(m_bgStyles
, wxSizerFlags().Centre().Border());
1907 sizer
->Add(m_timeouts
, wxSizerFlags().Centre().Border());
1908 sizer
->Add(m_timeDelay
, wxSizerFlags().Centre().Border());
1909 wxBoxSizer
* const sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
1910 sizerBtns
->Add(btnShowText
, wxSizerFlags().Border(wxRIGHT
));
1911 sizerBtns
->Add(btnShowBtn
, wxSizerFlags().Border(wxLEFT
));
1912 sizer
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
1913 sizer
->Add(CreateStdDialogButtonSizer(wxOK
),
1914 wxSizerFlags().Expand().Border());
1915 SetSizerAndFit(sizer
);
1918 // And connect the event handlers.
1919 btnShowText
->Connect
1922 wxCommandEventHandler(RichTipDialog::OnShowTipForText
),
1930 wxCommandEventHandler(RichTipDialog::OnShowTipForBtn
),
1964 void OnShowTipForText(wxCommandEvent
& WXUNUSED(event
))
1966 DoShowTip(m_textTitle
);
1969 void OnShowTipForBtn(wxCommandEvent
& WXUNUSED(event
))
1971 DoShowTip(FindWindow(wxID_OK
));
1974 void DoShowTip(wxWindow
* win
)
1976 wxRichToolTip
tip(m_textTitle
->GetValue(), m_textBody
->GetValue());
1977 const int iconSel
= m_icons
->GetSelection();
1978 if ( iconSel
== Icon_Custom
)
1980 tip
.SetIcon(tip_xpm
);
1982 else // Use a standard icon.
1984 static const int stdIcons
[] =
1992 tip
.SetIcon(stdIcons
[iconSel
]);
1995 switch ( m_bgStyles
->GetSelection() )
2001 tip
.SetBackgroundColour(*wxLIGHT_GREY
);
2005 tip
.SetBackgroundColour(*wxWHITE
, wxColour(0xe4, 0xe5, 0xf0));
2009 int delay
= m_timeDelay
->IsChecked() ? 500 : 0;
2011 switch ( m_timeouts
->GetSelection() )
2014 // Don't call SetTimeout unnecessarily
2015 // or msw will show generic impl
2017 tip
.SetTimeout(0, delay
);
2020 case Timeout_Default
:
2024 tip
.SetTimeout(3000, delay
);
2028 tip
.SetTipKind(static_cast<wxTipKind
>(m_tipKinds
->GetSelection()));
2033 wxTextCtrl
* m_textTitle
;
2034 wxTextCtrl
* m_textBody
;
2035 wxRadioBox
* m_icons
;
2036 wxRadioBox
* m_tipKinds
;
2037 wxRadioBox
* m_bgStyles
;
2038 wxRadioBox
* m_timeouts
;
2039 wxCheckBox
* m_timeDelay
;
2042 void MyFrame::OnRichTipDialog(wxCommandEvent
& WXUNUSED(event
))
2044 RichTipDialog
dialog(this);
2048 #endif // wxUSE_RICHTOOLTIP
2050 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
2052 StdButtonSizerDialog
dialog(this);
2056 // TestDefaultAction
2058 #define ID_CATCH_LISTBOX_DCLICK 100
2059 #define ID_LISTBOX 101
2060 #define ID_DISABLE_OK 102
2061 #define ID_DISABLE_CANCEL 103
2063 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
2064 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
2065 EVT_CHECKBOX(ID_DISABLE_OK
, TestDefaultActionDialog::OnDisableOK
)
2066 EVT_CHECKBOX(ID_DISABLE_CANCEL
, TestDefaultActionDialog::OnDisableCancel
)
2067 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
2068 EVT_TEXT_ENTER(wxID_ANY
, TestDefaultActionDialog::OnTextEnter
)
2071 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
2072 wxDialog( parent
, -1, "Test default action" )
2074 m_catchListBoxDClick
= false;
2076 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
2078 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
2081 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
2082 listbox
->Append( "String 1" );
2083 listbox
->Append( "String 2" );
2084 listbox
->Append( "String 3" );
2085 listbox
->Append( "String 4" );
2086 grid_sizer
->Add( listbox
);
2087 #endif // wxUSE_LISTBOX
2089 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
2091 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
2092 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
2094 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
2095 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
2097 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_OK
, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL
);
2098 grid_sizer
->Add( new wxCheckBox(this, ID_DISABLE_CANCEL
, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL
);
2100 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
2102 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
2104 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
2106 SetSizerAndFit( main_sizer
);
2109 void TestDefaultActionDialog::OnDisableOK(wxCommandEvent
& event
)
2111 FindWindow(wxID_OK
)->Enable(!event
.IsChecked());
2114 void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent
& event
)
2116 FindWindow(wxID_CANCEL
)->Enable(!event
.IsChecked());
2119 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
2121 event
.Skip( !m_catchListBoxDClick
);
2124 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
2126 m_catchListBoxDClick
= !m_catchListBoxDClick
;
2129 void TestDefaultActionDialog::OnTextEnter(wxCommandEvent
& event
)
2131 wxLogMessage("Text \"%s\" entered.", event
.GetString());
2134 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
2136 TestDefaultActionDialog
dialog( this );
2140 void MyFrame::OnModalHook(wxCommandEvent
& event
)
2142 class TestModalHook
: public wxModalDialogHook
2145 virtual int Enter(wxDialog
* dialog
)
2147 wxLogStatus("Showing %s modal dialog",
2148 dialog
->GetClassInfo()->GetClassName());
2152 virtual void Exit(wxDialog
* dialog
)
2154 wxLogStatus("Leaving %s modal dialog",
2155 dialog
->GetClassInfo()->GetClassName());
2159 static TestModalHook s_hook
;
2160 if ( event
.IsChecked() )
2163 s_hook
.Unregister();
2166 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
2171 #if wxUSE_PROGRESSDLG
2173 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
2175 static const int max
= 100;
2177 wxProgressDialog
dialog("Progress dialog example",
2178 // "Reserve" enough space for the multiline
2179 // messages below, we'll change it anyhow
2180 // immediately in the loop below
2181 wxString(' ', 100) + "\n\n\n\n",
2187 //wxPD_AUTO_HIDE | // -- try this as well
2189 wxPD_ESTIMATED_TIME
|
2190 wxPD_REMAINING_TIME
|
2191 wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
2195 for ( int i
= 0; i
<= max
; i
++ )
2199 // test both modes of wxProgressDialog behaviour: start in
2200 // indeterminate mode but switch to the determinate one later
2201 const bool determinate
= i
> max
/2;
2205 msg
= "That's all, folks!\n"
2207 "Nothing to see here any more.";
2209 else if ( !determinate
)
2211 msg
= "Testing indeterminate mode\n"
2213 "This mode allows you to show to the user\n"
2214 "that something is going on even if you don't know\n"
2215 "when exactly will you finish.";
2217 else if ( determinate
)
2219 msg
= "Now in standard determinate mode\n"
2221 "This is the standard usage mode in which you\n"
2222 "update the dialog after performing each new step of work.\n"
2223 "It requires knowing the total number of steps in advance.";
2226 // will be set to true if "Skip" button was pressed
2230 cont
= dialog
.Update(i
, msg
, &skip
);
2234 cont
= dialog
.Pulse(msg
, &skip
);
2237 // each skip will move progress about quarter forward
2248 if ( wxMessageBox(wxT("Do you really want to cancel?"),
2249 wxT("Progress dialog question"), // caption
2250 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
2262 wxLogStatus(wxT("Progress dialog aborted!"));
2266 wxLogStatus(wxT("Countdown from %d finished"), max
);
2270 #endif // wxUSE_PROGRESSDLG
2274 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
2276 info
.SetName(wxT("Dialogs Sample"));
2277 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
2281 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
2282 wxVERSION_NUM_DOT_STRING
2284 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
2285 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
2286 info
.AddDeveloper(wxT("Vadim Zeitlin"));
2289 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
2291 InitAboutInfoMinimal(info
);
2293 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
2296 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
2298 InitAboutInfoWebsite(info
);
2300 // we can add a second developer
2301 info
.AddDeveloper(wxT("A.N. Other"));
2303 // or we can add several persons at once like this
2304 static const wxChar
*docwriters
[] =
2306 wxT("First D. Writer"),
2310 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
2311 info
.SetLicence(wxString::FromAscii(
2312 " wxWindows Library Licence, Version 3.1\n"
2313 " ======================================\n"
2315 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
2317 " Everyone is permitted to copy and distribute verbatim copies\n"
2318 " of this licence document, but changing it is not allowed.\n"
2320 " WXWINDOWS LIBRARY LICENCE\n"
2321 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
2323 " ...and so on and so forth...\n"
2326 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
2329 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2331 wxAboutDialogInfo info
;
2332 InitAboutInfoMinimal(info
);
2334 wxAboutBox(info
, this);
2337 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2339 wxAboutDialogInfo info
;
2340 InitAboutInfoWebsite(info
);
2342 wxAboutBox(info
, this);
2345 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2347 wxAboutDialogInfo info
;
2348 InitAboutInfoAll(info
);
2350 wxAboutBox(info
, this);
2353 // a trivial example of a custom dialog class
2354 class MyAboutDialog
: public wxGenericAboutDialog
2357 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
2359 Create(info
, parent
);
2362 // add some custom controls
2363 virtual void DoAddCustomControls()
2365 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2366 AddText(wxT("Some custom text"));
2367 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2371 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
2373 wxAboutDialogInfo info
;
2374 InitAboutInfoAll(info
);
2376 MyAboutDialog
dlg(info
, this);
2380 #endif // wxUSE_ABOUTDLG
2384 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
2386 wxWindowDisabler disableAll
;
2388 wxBusyInfo
info(wxT("Working, please wait..."), this);
2390 for ( int i
= 0; i
< 18; i
++ )
2400 #endif // wxUSE_BUSYINFO
2402 #if wxUSE_FINDREPLDLG
2404 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
2408 wxDELETE(m_dlgReplace
);
2412 m_dlgReplace
= new wxFindReplaceDialog
2416 wxT("Find and replace dialog"),
2420 m_dlgReplace
->Show(true);
2424 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
2428 wxDELETE(m_dlgFind
);
2432 m_dlgFind
= new wxFindReplaceDialog
2441 m_dlgFind
->Show(true);
2445 static wxString
DecodeFindDialogEventFlags(int flags
)
2448 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
2449 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
2450 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
2451 << wxT("case sensitive");
2456 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
2458 wxEventType type
= event
.GetEventType();
2460 if ( type
== wxEVT_FIND
|| type
== wxEVT_FIND_NEXT
)
2462 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
2463 type
== wxEVT_FIND_NEXT
? wxT("next ") : wxT(""),
2464 event
.GetFindString().c_str(),
2465 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2467 else if ( type
== wxEVT_FIND_REPLACE
||
2468 type
== wxEVT_FIND_REPLACE_ALL
)
2470 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
2471 type
== wxEVT_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
2472 event
.GetFindString().c_str(),
2473 event
.GetReplaceString().c_str(),
2474 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
2476 else if ( type
== wxEVT_FIND_CLOSE
)
2478 wxFindReplaceDialog
*dlg
= event
.GetDialog();
2482 if ( dlg
== m_dlgFind
)
2485 idMenu
= DIALOGS_FIND
;
2488 else if ( dlg
== m_dlgReplace
)
2490 txt
= wxT("Replace");
2491 idMenu
= DIALOGS_REPLACE
;
2492 m_dlgReplace
= NULL
;
2496 txt
= wxT("Unknown");
2499 wxFAIL_MSG( wxT("unexpected event") );
2502 wxLogMessage(wxT("%s dialog is being closed."), txt
);
2504 if ( idMenu
!= wxID_ANY
)
2506 GetMenuBar()->Check(idMenu
, false);
2513 wxLogError(wxT("Unknown find dialog event!"));
2517 #endif // wxUSE_FINDREPLDLG
2519 // ----------------------------------------------------------------------------
2521 // ----------------------------------------------------------------------------
2523 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
2526 dc
.SetBackgroundMode(wxTRANSPARENT
);
2528 wxT("wxWidgets common dialogs")
2529 #if !defined(__SMARTPHONE__)
2530 wxT(" test application")
2535 #if USE_MODAL_PRESENTATION
2537 // ----------------------------------------------------------------------------
2539 // ----------------------------------------------------------------------------
2541 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
2542 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
2544 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
2546 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
2547 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
2550 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
2551 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
2553 SetSizerAndFit(sizerTop
);
2556 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
2558 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
2559 wxOK
| wxICON_INFORMATION
, this);
2562 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
2564 if ( event
.CanVeto() )
2566 wxMessageBox(wxT("Use the menu item to close this dialog"),
2567 wxT("Modeless dialog"),
2568 wxOK
| wxICON_INFORMATION
, this);
2574 // ----------------------------------------------------------------------------
2576 // ----------------------------------------------------------------------------
2578 MyModalDialog::MyModalDialog(wxWindow
*parent
)
2579 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
2581 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
2583 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2584 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2585 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2587 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2588 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2589 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2590 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2592 SetSizerAndFit(sizerTop
);
2594 SetEscapeId(wxID_CLOSE
);
2596 m_btnModal
->SetFocus();
2597 m_btnModal
->SetDefault();
2600 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2602 if ( event
.GetEventObject() == m_btnDelete
)
2604 wxDELETE(m_btnModal
);
2605 m_btnDelete
->Disable();
2607 else if ( event
.GetEventObject() == m_btnModal
)
2610 wxGetTextFromUser(wxT("Dummy prompt"),
2611 wxT("Modal dialog called from dialog"),
2612 wxEmptyString
, this);
2614 wxMessageBox(wxT("Modal dialog called from dialog"));
2615 #endif // wxUSE_TEXTDLG
2617 else if ( event
.GetEventObject() == m_btnModeless
)
2619 (new MyModelessDialog(this))->Show();
2627 #endif // USE_MODAL_PRESENTATION
2629 // ----------------------------------------------------------------------------
2630 // StdButtonSizerDialog
2631 // ----------------------------------------------------------------------------
2633 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2634 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2635 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2636 m_buttonsSizer(NULL
)
2638 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2640 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2641 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2643 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2645 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2647 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2648 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2650 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2652 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2654 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2656 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2657 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2659 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2661 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2662 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2663 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2665 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2667 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2668 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2670 sizer
->Add(sizerInside1
, 0, 0, 0);
2671 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2672 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2673 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2675 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2676 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2678 sizer
->Add(sizerInside2
, 0, 0, 0);
2679 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2680 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2681 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2683 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2685 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2686 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2687 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2689 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2691 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2693 EnableDisableControls();
2695 SetSizerAndFit(sizerTop
);
2701 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2705 m_buttonsSizer
->DeleteWindows();
2706 GetSizer()->Remove(m_buttonsSizer
);
2709 EnableDisableControls();
2712 unsigned long numButtons
= 0;
2714 if (m_chkboxAffirmativeButton
->IsChecked())
2716 if (m_radiobtnOk
->GetValue())
2721 else if (m_radiobtnYes
->GetValue())
2728 if (m_chkboxDismissButton
->IsChecked())
2730 if (m_radiobtnCancel
->GetValue())
2736 else if (m_radiobtnClose
->GetValue())
2744 if (m_chkboxApply
->IsChecked())
2750 if (m_chkboxNo
->IsChecked())
2756 if (m_chkboxHelp
->IsChecked())
2762 if (m_chkboxNoDefault
->IsChecked())
2764 flags
|= wxNO_DEFAULT
;
2767 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2768 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2771 GetSizer()->SetSizeHints(this);
2774 void StdButtonSizerDialog::EnableDisableControls()
2776 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2778 m_radiobtnOk
->Enable(affButtonEnabled
);
2779 m_radiobtnYes
->Enable(affButtonEnabled
);
2781 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2783 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2784 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2787 #if USE_SETTINGS_DIALOG
2788 // ----------------------------------------------------------------------------
2790 // ----------------------------------------------------------------------------
2792 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2794 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2797 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2799 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2804 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2805 int resizeBorder
= wxRESIZE_BORDER
;
2813 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2814 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2815 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2817 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2819 SetSheetStyle(sheetStyle
);
2820 SetSheetInnerBorder(0);
2821 SetSheetOuterBorder(0);
2823 // create a dummy image list with a few icons
2824 const wxSize
imageSize(32, 32);
2826 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2828 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2830 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2832 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2834 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2839 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2840 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2843 // If using a toolbook, also follow Mac style and don't create buttons
2845 CreateButtons(wxOK
| wxCANCEL
|
2846 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2849 wxBookCtrlBase
* notebook
= GetBookCtrl();
2850 notebook
->SetImageList(m_imageList
);
2852 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2853 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2855 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2856 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2861 SettingsDialog::~SettingsDialog()
2866 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2868 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2870 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2871 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2875 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2876 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2877 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2878 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2882 wxString autoSaveLabel
= _("&Auto-save every");
2883 wxString minsLabel
= _("mins");
2885 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2886 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2889 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2890 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2893 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2895 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2897 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2898 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2902 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2903 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2904 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2905 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2907 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2909 panel
->SetSizerAndFit(topSizer
);
2914 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2916 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2918 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2919 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2921 //// PROJECT OR GLOBAL
2922 wxString globalOrProjectChoices
[2];
2923 globalOrProjectChoices
[0] = _("&New projects");
2924 globalOrProjectChoices
[1] = _("&This project");
2926 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2927 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2928 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2930 projectOrGlobal
->SetSelection(0);
2932 //// BACKGROUND STYLE
2933 wxArrayString backgroundStyleChoices
;
2934 backgroundStyleChoices
.Add(wxT("Colour"));
2935 backgroundStyleChoices
.Add(wxT("Image"));
2936 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2938 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2939 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2941 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2943 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2945 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2946 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2947 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2949 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2952 //// FONT SIZE SELECTION
2954 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2955 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2957 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2958 wxSize(80, wxDefaultCoord
));
2959 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2961 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2964 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2965 topSizer
->AddSpacer(5);
2967 panel
->SetSizerAndFit(topSizer
);
2972 #endif // USE_SETTINGS_DIALOG
2975 // ----------------------------------------------------------------------------
2976 // TestMessageBoxDialog
2977 // ----------------------------------------------------------------------------
2980 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2985 { wxCANCEL
, "&Cancel" },
2986 { wxHELP
, "&Help" },
2989 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2990 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2991 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2994 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2995 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2996 wxDefaultPosition
, wxDefaultSize
,
2997 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
3001 bool TestMessageBoxDialog::Create()
3003 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
3005 // this sizer allows to configure the messages shown in the message box
3007 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
3008 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Title:"));
3009 m_textTitle
= new wxTextCtrl(this, wxID_ANY
, "Test Message Box");
3010 sizerMsgs
->Add(m_textTitle
, wxSizerFlags().Expand().Border(wxBOTTOM
));
3012 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
3013 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
3014 wxDefaultPosition
, wxDefaultSize
,
3016 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
3018 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
3019 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
3020 wxDefaultPosition
, wxDefaultSize
,
3022 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
3024 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
3026 // if a derived class provides more message configurations, add these.
3027 AddAdditionalTextOptions(sizerTop
);
3029 // this one is for configuring the buttons
3031 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
3033 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
3034 sizerBtns
->AddGrowableCol(1);
3036 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
3037 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
3039 for ( int n
= 0; n
< Btn_Max
; n
++ )
3041 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
3042 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
3044 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
3045 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
3047 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
3048 wxUpdateUIEventHandler(
3049 TestMessageBoxDialog::OnUpdateLabelUI
),
3054 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
3055 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
3059 const wxString icons
[] =
3063 "&Information icon",
3070 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons
) == MsgDlgIcon_Max
, IconMismatch
);
3072 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon style",
3073 wxDefaultPosition
, wxDefaultSize
,
3074 WXSIZEOF(icons
), icons
,
3075 2, wxRA_SPECIFY_ROWS
);
3076 // Make the 'Information' icon the default one:
3077 m_icons
->SetSelection(MsgDlgIcon_Info
);
3078 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
3081 // miscellaneous other stuff
3083 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
3085 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
3086 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
3087 wxUpdateUIEventHandler(
3088 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
3091 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
3093 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
3094 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
3096 // add any additional flag from subclasses
3097 AddAdditionalFlags(sizerFlags
);
3099 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
3101 // finally buttons to show the resulting message box and close this dialog
3102 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
3103 wxSizerFlags().Right().Border());
3105 SetSizerAndFit(sizerTop
);
3107 m_buttons
[Btn_Ok
]->SetValue(true);
3112 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
3114 for ( int n
= 0; n
< Btn_Max
; n
++ )
3116 if ( event
.GetEventObject() == m_labels
[n
] )
3118 event
.Enable( m_buttons
[n
]->IsChecked() );
3123 wxFAIL_MSG( "called for unknown label" );
3126 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
3128 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
3131 long TestMessageBoxDialog::GetStyle()
3135 for ( int n
= 0; n
< Btn_Max
; n
++ )
3137 if ( m_buttons
[n
]->IsChecked() )
3138 style
|= ms_btnInfo
[n
].flag
;
3141 switch ( m_icons
->GetSelection() )
3143 case MsgDlgIcon_Max
:
3144 wxFAIL_MSG( "unexpected selection" );
3149 case MsgDlgIcon_None
:
3150 style
|= wxICON_NONE
;
3153 case MsgDlgIcon_Info
:
3154 style
|= wxICON_INFORMATION
;
3157 case MsgDlgIcon_Question
:
3158 style
|= wxICON_QUESTION
;
3161 case MsgDlgIcon_Warning
:
3162 style
|= wxICON_WARNING
;
3165 case MsgDlgIcon_Error
:
3166 style
|= wxICON_ERROR
;
3169 case MsgDlgIcon_AuthNeeded
:
3170 style
|= wxICON_AUTH_NEEDED
;
3174 if ( m_chkCentre
->IsChecked() )
3177 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
3178 style
|= wxNO_DEFAULT
;
3183 void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase
&dlg
)
3185 long style
= dlg
.GetMessageDialogStyle();
3187 if ( !m_textExtMsg
->IsEmpty() )
3188 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
3190 if ( style
& wxYES_NO
)
3192 if ( style
& wxCANCEL
)
3194 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
3195 m_labels
[Btn_No
]->GetValue(),
3196 m_labels
[Btn_Cancel
]->GetValue());
3200 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
3201 m_labels
[Btn_No
]->GetValue());
3206 if ( style
& wxCANCEL
)
3208 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
3209 m_labels
[Btn_Cancel
]->GetValue());
3213 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
3217 if ( style
& wxHELP
)
3219 dlg
.SetHelpLabel(m_labels
[Btn_Help
]->GetValue());
3223 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
3225 wxMessageDialog
dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3226 PrepareMessageDialog(dlg
);
3229 switch ( dlg
.ShowModal() )
3236 // Avoid the extra message box if the dialog was cancelled.
3252 btnName
= "Unknown";
3255 wxLogMessage("Dialog was closed with the \"%s\" button.", btnName
);
3258 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
3260 EndModal(wxID_CANCEL
);
3262 #endif // wxUSE_MSGDLG
3264 #if wxUSE_RICHMSGDLG
3265 // ----------------------------------------------------------------------------
3266 // TestRichMessageDialog
3267 // ----------------------------------------------------------------------------
3269 BEGIN_EVENT_TABLE(TestRichMessageDialog
, TestMessageBoxDialog
)
3270 EVT_BUTTON(wxID_APPLY
, TestRichMessageDialog::OnApply
)
3273 TestRichMessageDialog::TestRichMessageDialog(wxWindow
*parent
)
3274 : TestMessageBoxDialog(parent
)
3276 SetTitle("Rich Message Dialog Test Dialog");
3279 void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer
*sizer
)
3281 wxSizer
* const sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this,
3282 "&Additional Elements");
3284 // add a option to show a check box.
3285 wxFlexGridSizer
* const sizerCheckBox
= new wxFlexGridSizer(2, 5, 5);
3286 sizerCheckBox
->AddGrowableCol(1);
3287 sizerCheckBox
->Add(new wxStaticText(this, wxID_ANY
, "&Check box:"));
3288 m_textCheckBox
= new wxTextCtrl(this, wxID_ANY
);
3289 sizerCheckBox
->Add(m_textCheckBox
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
3290 sizerMsgs
->Add(sizerCheckBox
, wxSizerFlags(1).Expand());
3292 // add option to show a detailed text.
3293 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Detailed message:"));
3294 m_textDetailed
= new wxTextCtrl(this, wxID_ANY
, "",
3295 wxDefaultPosition
, wxDefaultSize
,
3297 sizerMsgs
->Add(m_textDetailed
, wxSizerFlags(1).Expand());
3299 sizer
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
3302 void TestRichMessageDialog::AddAdditionalFlags(wxSizer
*sizer
)
3304 // add checkbox to set the initial state for the checkbox shown
3306 m_initialValueCheckBox
=
3307 new wxCheckBox(this, wxID_ANY
, "Checkbox initially checked");
3308 sizer
->Add(m_initialValueCheckBox
, wxSizerFlags(1).Border());
3311 void TestRichMessageDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
3313 wxRichMessageDialog
dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3314 PrepareMessageDialog(dlg
);
3316 dlg
.ShowCheckBox(m_textCheckBox
->GetValue(),
3317 m_initialValueCheckBox
->GetValue());
3318 dlg
.ShowDetailedText(m_textDetailed
->GetValue());
3323 #endif // wxUSE_RICHMSGDLG
3327 // ----------------------------------------------------------------------------
3328 // custom log target
3329 // ----------------------------------------------------------------------------
3331 class MyLogGui
: public wxLogGui
3334 virtual void DoShowSingleLogMessage(const wxString
& message
,
3335 const wxString
& title
,
3338 wxMessageDialog
dlg(NULL
, message
, title
,
3339 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
3340 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
3341 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
3346 wxLog
*MyAppTraits::CreateLogTarget()
3348 return new MyLogGui
;