1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustements for conditional building + new menu
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "../sample.xpm"
25 #include "wx/apptrait.h"
26 #include "wx/datetime.h"
28 #include "wx/bookctrl.h"
29 #include "wx/artprov.h"
30 #include "wx/imaglist.h"
31 #include "wx/minifram.h"
32 #include "wx/sysopt.h"
33 #include "wx/notifmsg.h"
36 #include "wx/colordlg.h"
37 #endif // wxUSE_COLOURDLG
40 #include "wx/choicdlg.h"
41 #endif // wxUSE_CHOICEDLG
43 #include "wx/rearrangectrl.h"
45 #if wxUSE_STARTUP_TIPS
46 #include "wx/tipdlg.h"
47 #endif // wxUSE_STARTUP_TIPS
50 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
51 #include "wx/datetime.h" // wxDateTime
54 #include "wx/progdlg.h"
55 #endif // wxUSE_PROGRESSDLG
58 #include "wx/aboutdlg.h"
60 // these headers are only needed for custom about dialog
61 #include "wx/statline.h"
62 #include "wx/generic/aboutdlgg.h"
63 #endif // wxUSE_ABOUTDLG
66 #include "wx/busyinfo.h"
67 #endif // wxUSE_BUSYINFO
70 #include "wx/numdlg.h"
71 #endif // wxUSE_NUMBERDLG
74 #include "wx/filedlg.h"
75 #endif // wxUSE_FILEDLG
78 #include "wx/dirdlg.h"
79 #endif // wxUSE_DIRDLG
82 #include "wx/fontdlg.h"
83 #endif // wxUSE_FONTDLG
86 #include "wx/fdrepdlg.h"
87 #endif // wxUSE_FINDREPLDLG
89 #include "wx/spinctrl.h"
90 #include "wx/propdlg.h"
94 #if USE_COLOURDLG_GENERIC
95 #include "wx/generic/colrdlgg.h"
96 #endif // USE_COLOURDLG_GENERIC
98 #if USE_DIRDLG_GENERIC
99 #include "wx/generic/dirdlgg.h"
100 #endif // USE_DIRDLG_GENERIC
102 #if USE_FILEDLG_GENERIC
103 #include "wx/generic/filedlgg.h"
104 #endif // USE_FILEDLG_GENERIC
106 #if USE_FONTDLG_GENERIC
107 #include "wx/generic/fontdlgg.h"
108 #endif // USE_FONTDLG_GENERIC
112 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
113 EVT_PAINT(MyCanvas::OnPaint
)
118 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
120 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
121 EVT_MENU(DIALOGS_MESSAGE_DIALOG
, MyFrame::MessageBoxDialog
)
122 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
123 #endif // wxUSE_MSGDLG
125 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
126 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
127 #endif // wxUSE_COLOURDLG
130 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
131 #endif // wxUSE_FONTDLG
134 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
135 #endif // wxUSE_LOG_DIALOG
138 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
139 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
140 #endif // wxUSE_TEXTDLG
143 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
144 #endif // wxUSE_NUMBERDLG
147 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
148 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
149 #endif // wxUSE_CHOICEDLG
151 #if wxUSE_REARRANGECTRL
152 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
153 #endif // wxUSE_REARRANGECTRL
156 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
157 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
158 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
159 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
160 #endif // wxUSE_FILEDLG
162 #if USE_FILEDLG_GENERIC
163 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
164 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
165 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
166 #endif // USE_FILEDLG_GENERIC
169 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
170 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
171 #endif // wxUSE_DIRDLG
173 #if USE_MODAL_PRESENTATION
174 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
175 #endif // USE_MODAL_PRESENTATION
176 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
177 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
178 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
180 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
181 #endif // wxUSE_MINIFRAME
182 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
184 #if wxUSE_STARTUP_TIPS
185 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
186 #endif // wxUSE_STARTUP_TIPS
188 #if USE_FONTDLG_GENERIC
189 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
190 #endif // USE_FONTDLG_GENERIC
192 #if USE_DIRDLG_GENERIC
193 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
194 #endif // wxMSW || wxMAC
196 #if USE_COLOURDLG_GENERIC
197 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
198 #endif // USE_COLOURDLG_GENERIC
200 #if wxUSE_PROGRESSDLG
201 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
202 #endif // wxUSE_PROGRESSDLG
205 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
206 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
207 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
208 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
209 #endif // wxUSE_ABOUTDLG
212 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
213 #endif // wxUSE_BUSYINFO
215 #if wxUSE_FINDREPLDLG
216 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
217 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
219 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
220 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
221 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
222 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
223 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
224 #endif // wxUSE_FINDREPLDLG
226 #if USE_SETTINGS_DIALOG
227 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
228 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
229 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
230 #endif // USE_SETTINGS_DIALOG
232 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
233 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
235 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
236 #if wxUSE_NOTIFICATION_MESSAGE
237 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
238 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
239 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
240 #endif // wxUSE_NOTIFICATION_MESSAGE
242 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
245 #if USE_MODAL_PRESENTATION
247 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
248 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
251 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
252 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
253 EVT_CLOSE(MyModelessDialog::OnClose
)
256 #endif // USE_MODAL_PRESENTATION
258 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
259 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
260 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
263 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
265 // `Main program' equivalent, creating windows and returning main app frame
268 if ( !wxApp::OnInit() )
272 wxInitAllImageHandlers();
275 m_canvasTextColour
= *wxBLACK
;
276 m_canvasFont
= *wxNORMAL_FONT
;
278 // Create the main frame window
279 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, wxT("wxWidgets dialogs example"));
282 wxMenu
*menuDlg
= new wxMenu
;
284 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
285 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
288 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
290 wxMenu
*choices_menu
= new wxMenu
;
293 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
294 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
295 #endif // wxUSE_COLOURDLG
298 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
299 #endif // wxUSE_FONTDLG
302 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
303 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
304 #endif // wxUSE_CHOICEDLG
306 #if wxUSE_REARRANGECTRL
307 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
308 #endif // wxUSE_REARRANGECTRL
310 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
311 choices_menu
->AppendSeparator();
312 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
314 #if USE_COLOURDLG_GENERIC
315 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
316 #endif // USE_COLOURDLG_GENERIC
318 #if USE_FONTDLG_GENERIC
319 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
320 #endif // USE_FONTDLG_GENERIC
322 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
323 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
326 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
328 wxMenu
*entry_menu
= new wxMenu
;
331 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Text &entry\tCtrl-E"));
332 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
333 #endif // wxUSE_TEXTDLG
336 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
337 #endif // wxUSE_NUMBERDLG
339 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
341 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
346 wxMenu
*filedlg_menu
= new wxMenu
;
347 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
348 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
349 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
350 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
352 #if USE_FILEDLG_GENERIC
353 filedlg_menu
->AppendSeparator();
354 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
355 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
356 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
357 #endif // USE_FILEDLG_GENERIC
359 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
361 #endif // wxUSE_FILEDLG
364 wxMenu
*dir_menu
= new wxMenu
;
366 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
367 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
368 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
370 #if USE_DIRDLG_GENERIC
371 dir_menu
->AppendSeparator();
372 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
373 #endif // USE_DIRDLG_GENERIC
375 #endif // wxUSE_DIRDLG
378 #if wxUSE_STARTUP_TIPS || \
379 wxUSE_PROGRESSDLG || \
381 wxUSE_LOG_DIALOG || \
384 wxMenu
*info_menu
= new wxMenu
;
386 #if wxUSE_STARTUP_TIPS
387 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
388 #endif // wxUSE_STARTUP_TIPS
390 #if wxUSE_PROGRESSDLG
391 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
392 #endif // wxUSE_PROGRESSDLG
395 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
396 #endif // wxUSE_BUSYINFO
399 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
400 #endif // wxUSE_LOG_DIALOG
403 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
404 wxT("&wxWidgets information\tCtrl-I"));
405 #endif // wxUSE_MSGDLG
407 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
409 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
412 #if wxUSE_FINDREPLDLG
413 wxMenu
*find_menu
= new wxMenu
;
414 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
415 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
416 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
417 #endif // wxUSE_FINDREPLDLG
419 wxMenu
*dialogs_menu
= new wxMenu
;
420 #if USE_MODAL_PRESENTATION
421 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tCtrl-W"));
422 #endif // USE_MODAL_PRESENTATION
423 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tCtrl-Z"));
424 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
425 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
427 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
428 #endif // wxUSE_MINIFRAME
429 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
430 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
432 #if USE_SETTINGS_DIALOG
433 wxMenu
*sheet_menu
= new wxMenu
;
434 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
435 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
437 if (wxPlatformIs(wxPORT_MAC
))
438 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
441 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
444 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
445 #endif // USE_SETTINGS_DIALOG
447 wxMenu
*menuNotif
= new wxMenu
;
448 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
449 #if wxUSE_NOTIFICATION_MESSAGE
450 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
451 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
452 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
453 #endif // wxUSE_NOTIFICATION_MESSAGE
454 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
456 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
457 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
459 menuDlg
->AppendSeparator();
460 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
463 wxMenu
*menuHelp
= new wxMenu
;
464 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
465 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
466 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
467 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
468 #endif // wxUSE_ABOUTDLG
470 wxMenuBar
*menubar
= new wxMenuBar
;
471 menubar
->Append(menuDlg
, wxT("&Dialogs"));
473 menubar
->Append(menuHelp
, wxT("&Help"));
474 #endif // wxUSE_ABOUTDLG
476 frame
->SetMenuBar(menubar
);
478 myCanvas
= new MyCanvas(frame
);
479 myCanvas
->SetBackgroundColour(*wxWHITE
);
481 frame
->Centre(wxBOTH
);
491 // My frame constructor
492 MyFrame::MyFrame(wxWindow
*parent
,
493 const wxString
& title
)
494 : wxFrame(parent
, wxID_ANY
, title
)
498 #if USE_MODAL_PRESENTATION
499 m_dialog
= (MyModelessDialog
*)NULL
;
500 #endif // USE_MODAL_PRESENTATION
502 #if wxUSE_FINDREPLDLG
508 m_clrData
.SetChooseFull(true);
509 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
511 unsigned char n
= i
*16;
512 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
514 #endif // wxUSE_COLOURDLG
516 #if wxUSE_NOTIFICATION_MESSAGE
518 #endif // wxUSE_NOTIFICATION_MESSAGE
522 #endif // wxUSE_STATUSBAR
527 #if wxUSE_NOTIFICATION_MESSAGE
529 #endif // wxUSE_NOTIFICATION_MESSAGE
534 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
536 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
538 wxColourDialog
dialog(this, &m_clrData
);
539 dialog
.SetTitle(_("Please choose the background colour"));
540 if ( dialog
.ShowModal() == wxID_OK
)
542 m_clrData
= dialog
.GetColourData();
543 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
544 myCanvas
->ClearBackground();
549 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
551 wxColour clr
= wxGetColourFromUser
554 wxGetApp().m_canvasTextColour
,
555 "Please choose the foreground colour"
559 wxGetApp().m_canvasTextColour
= clr
;
562 //else: dialog cancelled by user
565 #endif // wxUSE_COLOURDLG
568 #if USE_COLOURDLG_GENERIC
569 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
571 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
573 //FIXME:TODO:This has no effect...
574 m_clrData
.SetChooseFull(true);
576 for (int i
= 0; i
< 16; i
++)
579 (unsigned char)(i
*16),
580 (unsigned char)(i
*16),
581 (unsigned char)(i
*16)
583 m_clrData
.SetCustomColour(i
, colour
);
586 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
587 if (dialog
->ShowModal() == wxID_OK
)
589 m_clrData
= dialog
->GetColourData();
590 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
591 myCanvas
->ClearBackground();
596 #endif // USE_COLOURDLG_GENERIC
599 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
602 data
.SetInitialFont(wxGetApp().m_canvasFont
);
603 data
.SetColour(wxGetApp().m_canvasTextColour
);
605 // you might also do this:
607 // wxFontDialog dialog;
608 // if ( !dialog.Create(this, data) { ... error ... }
610 wxFontDialog
dialog(this, data
);
612 if (dialog
.ShowModal() == wxID_OK
)
614 wxFontData retData
= dialog
.GetFontData();
615 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
616 wxGetApp().m_canvasTextColour
= retData
.GetColour();
619 //else: cancelled by the user, don't change the font
621 #endif // wxUSE_FONTDLG
623 #if USE_FONTDLG_GENERIC
624 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
627 data
.SetInitialFont(wxGetApp().m_canvasFont
);
628 data
.SetColour(wxGetApp().m_canvasTextColour
);
630 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
631 if (dialog
->ShowModal() == wxID_OK
)
633 wxFontData retData
= dialog
->GetFontData();
634 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
635 wxGetApp().m_canvasTextColour
= retData
.GetColour();
640 #endif // USE_FONTDLG_GENERIC
643 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
645 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
646 // being flushed -- test it
649 wxLogMessage(wxT("This is some message - everything is ok so far."));
650 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
651 wxLogWarning(wxT("And then something went wrong!"));
653 // and if ~wxBusyCursor doesn't do it, then call it manually
657 wxLogError(wxT("Intermediary error handler decided to abort."));
658 wxLogError(wxT("The top level caller detected an unrecoverable error."));
660 wxLog::FlushActive();
662 wxLogMessage(wxT("And this is the same dialog but with only one message."));
664 #endif // wxUSE_LOG_DIALOG
667 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
669 wxMessageDialog
dialog(this,
670 "This is a message box\n"
671 "This is a long, long string to test out if the message box "
672 "is laid out properly.",
675 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
679 if ( dialog
.SetYesNoCancelLabels
686 extmsg
= "This platform supports custom button labels,\n"
687 "so you should see the descriptive labels below.";
691 extmsg
= "Custom button labels are not supported on this platform,\n"
692 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
694 dialog
.SetExtendedMessage(extmsg
);
696 switch ( dialog
.ShowModal() )
699 wxLogStatus(wxT("You pressed \"Yes\""));
703 wxLogStatus(wxT("You pressed \"No\""));
707 wxLogStatus(wxT("You pressed \"Cancel\""));
711 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
715 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
717 TestMessageBoxDialog
dlg(this);
721 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
723 ::wxInfoMessageBox(this);
725 #endif // wxUSE_MSGDLG
728 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
730 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
731 wxT("Even two rows of text."),
732 wxT("Enter a number:"), wxT("Numeric input test"),
739 msg
= wxT("Invalid number entered or dialog cancelled.");
744 msg
.Printf(wxT("You've entered %lu"), res
);
745 icon
= wxICON_INFORMATION
;
748 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
750 #endif // wxUSE_NUMBERDLG
753 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
755 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
756 wxT("Password entry dialog"),
761 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
762 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
766 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
768 wxTextEntryDialog
dialog(this,
769 wxT("This is a small sample\n")
770 wxT("A long, long string to test out the text entrybox"),
771 wxT("Please enter a string"),
772 wxT("Default value"),
775 if (dialog
.ShowModal() == wxID_OK
)
777 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
780 #endif // wxUSE_TEXTDLG
783 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
785 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
787 wxSingleChoiceDialog
dialog(this,
788 wxT("This is a small sample\n")
789 wxT("A single-choice convenience dialog"),
790 wxT("Please select a value"),
791 WXSIZEOF(choices
), choices
);
793 dialog
.SetSelection(2);
795 if (dialog
.ShowModal() == wxID_OK
)
797 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
802 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
804 const wxString choices
[] =
806 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
807 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
808 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
811 wxArrayInt selections
;
812 const int count
= wxGetSelectedChoices(selections
,
813 wxT("This is a small sample\n")
814 wxT("A multi-choice convenience dialog"),
815 wxT("Please select a value"),
816 WXSIZEOF(choices
), choices
,
823 msg
= wxT("You did not select any items");
827 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
828 for ( int n
= 0; n
< count
; n
++ )
830 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
831 (unsigned)n
, (unsigned)selections
[n
],
832 choices
[selections
[n
]].c_str());
839 #endif // wxUSE_CHOICEDLG
841 #if wxUSE_REARRANGECTRL
842 // custom rearrange dialog: it adds the possibility to rename an item to the
843 // base class functionality
844 class MyRearrangeDialog
: public wxRearrangeDialog
847 MyRearrangeDialog(wxWindow
*parent
,
849 wxArrayString
& labels
,
850 wxArrayString
& labelsOrig
)
854 "Configure the columns shown:",
855 "wxRearrangeDialog example",
861 m_labelsOrig(labelsOrig
)
865 wxPanel
* const panel
= new wxPanel(this);
866 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
868 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
869 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
871 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
872 wxDefaultPosition
, wxDefaultSize
,
874 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
876 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
877 wxSizerFlags().Centre());
879 panel
->SetSizer(sizer
);
881 // call this first to ensure that the controls have a reasonable best
882 // size before they're added
883 DoUpdateExtraControls(GetList()->GetSelection());
885 AddExtraControls(panel
);
888 // another customization not directly supported by the dialog: add a
890 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
891 wxCHECK_RET( btnOk
, "no Ok button?" );
893 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
894 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
896 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
897 wxSizerFlags().Border(wxLEFT
));
900 // call this instead of ShowModal() to update order and labels array in
901 // case the dialog was not cancelled
904 switch ( ShowModal() )
910 m_order
= GetOrder();
914 // order already reset
922 void OnSelChange(wxCommandEvent
& event
)
924 DoUpdateExtraControls(event
.GetInt());
927 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
929 event
.Enable( CanRename() );
932 void OnRename(wxCommandEvent
& WXUNUSED(event
))
937 m_labels
[m_sel
] = m_text
->GetValue();
938 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
941 void OnReset(wxCommandEvent
& WXUNUSED(event
))
943 // in a real program we should probably ask if the user really wants to
944 // do this but here we just go ahead and reset all columns labels and
945 // their order without confirmation
946 const unsigned count
= m_order
.size();
947 for ( unsigned n
= 0; n
< count
; n
++ )
950 m_labels
[n
] = m_labelsOrig
[n
];
953 EndModal(wxID_RESET
);
956 bool CanRename() const
958 // only allow renaming if the user modified the currently selected item
959 // text (which presupposes that we do have a current item)
960 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
963 void DoUpdateExtraControls(int sel
)
967 if ( m_sel
== wxNOT_FOUND
)
969 m_labelOrig
->SetLabel("<no selection>");
973 else // have valid item
975 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
977 m_text
->SetValue(m_labels
[m_sel
]);
982 wxArrayString
& m_labels
,
986 wxStaticText
*m_labelOrig
;
989 DECLARE_EVENT_TABLE()
990 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
993 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
994 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
996 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
998 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
999 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
1000 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
1003 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
1005 // the arrays are static so that we preserve the items order between calls
1007 static wxArrayInt s_order
;
1008 static wxArrayString s_labels
,
1011 // initialize them on the first call
1012 if ( s_labelsOrig
.empty() )
1014 static const struct ItemInfo
1017 const char *labelOrig
;
1021 { "File name", "Name", 0 },
1022 { "File type", "Ext", 1 },
1023 { "Size", "Size", 2 },
1024 { "Creation time", "Ctime", ~3 }, // negated so hidden
1025 { "Last accessed", "Atime", ~4 },
1026 { "Last modified", "Mtime", 5 },
1029 s_order
.reserve(WXSIZEOF(items
));
1030 s_labels
.reserve(WXSIZEOF(items
));
1031 s_labelsOrig
.reserve(WXSIZEOF(items
));
1032 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1034 const ItemInfo
& item
= items
[n
];
1035 s_order
.push_back(item
.order
);
1036 s_labels
.push_back(item
.label
);
1037 s_labelsOrig
.push_back(item
.labelOrig
);
1041 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1042 if ( !dlg
.Rearrange() )
1046 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1048 columns
+= wxString::Format("\n %u: ", n
);
1049 int idx
= s_order
[n
];
1052 columns
+= "[hidden] ";
1056 columns
+= s_labels
[idx
];
1057 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1059 columns
+= wxString::Format(" (original label: \"%s\")",
1064 wxLogMessage("The columns order now is:%s", columns
);
1066 #endif // wxUSE_REARRANGECTRL
1070 // panel with custom controls for file dialog
1071 class MyExtraPanel
: public wxPanel
1074 MyExtraPanel(wxWindow
*parent
);
1075 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1076 wxString
GetInfo() const
1078 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1085 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1088 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1089 m_btn
->Enable(false);
1090 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1091 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1092 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1093 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1094 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1095 sizerTop
->AddStretchSpacer();
1096 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1097 SetSizerAndFit(sizerTop
);
1100 // a static method can be used instead of a function with most of compilers
1101 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1103 return new MyExtraPanel(parent
);
1106 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1111 wxT("Testing open file dialog"),
1115 wxT("C++ files (*.cpp)|*.cpp")
1117 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1121 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1122 dialog
.CentreOnParent();
1123 dialog
.SetDirectory(wxGetHomeDir());
1125 if (dialog
.ShowModal() == wxID_OK
)
1128 wxWindow
* const extra
= dialog
.GetExtraControl();
1129 info
.Printf(wxT("Full file name: %s\n")
1132 wxT("Custom window: %s"),
1133 dialog
.GetPath().c_str(),
1134 dialog
.GetDirectory().c_str(),
1135 dialog
.GetFilename().c_str(),
1136 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1137 : wxString("None"));
1138 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1139 dialog2
.ShowModal();
1143 // this shows how to take advantage of specifying a default extension in the
1144 // call to wxFileSelector: it is remembered after each new call and the next
1145 // one will use it by default
1146 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1148 static wxString s_extDef
;
1149 wxString path
= wxFileSelector(
1150 wxT("Select the file to load"),
1151 wxEmptyString
, wxEmptyString
,
1155 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1156 wxFileSelectorDefaultWildcardStr
,
1157 wxFileSelectorDefaultWildcardStr
1159 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1166 // it is just a sample, would use wxSplitPath in real program
1167 s_extDef
= path
.AfterLast(wxT('.'));
1169 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1173 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1175 wxString wildcards
=
1177 wxT("C++ files (*.cpp)|*.cpp");
1181 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1182 wxFileSelectorDefaultWildcardStr
,
1183 wxFileSelectorDefaultWildcardStr
1186 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1187 wxEmptyString
, wxEmptyString
, wildcards
,
1188 wxFD_OPEN
|wxFD_MULTIPLE
);
1190 if (dialog
.ShowModal() == wxID_OK
)
1192 wxArrayString paths
, filenames
;
1194 dialog
.GetPaths(paths
);
1195 dialog
.GetFilenames(filenames
);
1198 size_t count
= paths
.GetCount();
1199 for ( size_t n
= 0; n
< count
; n
++ )
1201 s
.Printf(wxT("File %d: %s (%s)\n"),
1202 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1206 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1209 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1210 dialog2
.ShowModal();
1214 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1216 wxFileDialog
dialog(this,
1217 wxT("Testing save file dialog"),
1219 wxT("myletter.doc"),
1220 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1221 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1223 dialog
.SetFilterIndex(1);
1225 if (dialog
.ShowModal() == wxID_OK
)
1227 wxLogMessage(wxT("%s, filter %d"),
1228 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1231 #endif // wxUSE_FILEDLG
1233 #if USE_FILEDLG_GENERIC
1234 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1236 wxGenericFileDialog dialog
1239 wxT("Testing open file dialog"),
1242 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1245 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1246 dialog
.SetDirectory(wxGetHomeDir());
1248 if (dialog
.ShowModal() == wxID_OK
)
1251 info
.Printf(wxT("Full file name: %s\n")
1254 dialog
.GetPath().c_str(),
1255 dialog
.GetDirectory().c_str(),
1256 dialog
.GetFilename().c_str());
1257 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1258 dialog2
.ShowModal();
1262 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1264 // On PocketPC you can disable OK-only dialogs policy using system option
1265 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1266 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1268 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1269 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1270 wxEmptyString
, wxEmptyString
, wildcards
,
1273 if (dialog
.ShowModal() == wxID_OK
)
1275 wxArrayString paths
, filenames
;
1277 dialog
.GetPaths(paths
);
1278 dialog
.GetFilenames(filenames
);
1281 size_t count
= paths
.GetCount();
1282 for ( size_t n
= 0; n
< count
; n
++ )
1284 s
.Printf(wxT("File %d: %s (%s)\n"),
1285 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1289 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1292 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1293 dialog2
.ShowModal();
1296 // restore system option
1297 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1300 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1302 wxGenericFileDialog
dialog(this,
1303 wxT("Testing save file dialog"),
1305 wxT("myletter.doc"),
1306 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1307 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1309 dialog
.SetFilterIndex(1);
1311 if (dialog
.ShowModal() == wxID_OK
)
1313 wxLogMessage(wxT("%s, filter %d"),
1314 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1317 #endif // USE_FILEDLG_GENERIC
1320 void MyFrame::DoDirChoose(int style
)
1322 // pass some initial dir to wxDirDialog
1324 wxGetHomeDir(&dirHome
);
1326 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1328 if (dialog
.ShowModal() == wxID_OK
)
1330 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1334 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1336 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1339 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1341 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1343 #endif // wxUSE_DIRDLG
1345 #if USE_DIRDLG_GENERIC
1346 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1348 // pass some initial dir to wxDirDialog
1350 wxGetHomeDir(&dirHome
);
1352 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1354 if (dialog
.ShowModal() == wxID_OK
)
1356 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1357 dialog2
.ShowModal();
1360 #endif // USE_DIRDLG_GENERIC
1362 #if USE_MODAL_PRESENTATION
1363 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1365 MyModalDialog
dlg(this);
1368 #endif // USE_MODAL_PRESENTATION
1370 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1372 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1378 m_dialog
= new MyModelessDialog(this);
1381 m_dialog
->Show(true);
1385 // If m_dialog is NULL, then possibly the system
1386 // didn't report the checked menu item status correctly.
1387 // It should be true just after the menu item was selected,
1388 // if there was no modeless dialog yet.
1390 wxASSERT( m_dialog
!= NULL
);
1396 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1398 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1399 wxDefaultPosition
, wxSize(200, 100));
1400 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1401 dlg
.CentreOnScreen();
1405 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1407 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1408 wxDefaultPosition
, wxSize(200, 100));
1409 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1410 dlg
.CentreOnParent();
1415 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1417 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1418 wxDefaultPosition
, wxSize(300, 100),
1419 wxCAPTION
| wxCLOSE_BOX
);
1420 new wxStaticText(frame
,
1422 wxT("Mini frames have slightly different appearance"),
1424 new wxStaticText(frame
,
1426 wxT("from the normal frames but that's the only difference."),
1429 frame
->CentreOnParent();
1432 #endif // wxUSE_MINIFRAME
1434 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1436 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1437 wxDefaultPosition
, wxSize(300, 100),
1438 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1439 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1443 #if wxUSE_STARTUP_TIPS
1444 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1446 static size_t s_index
= (size_t)-1;
1448 if ( s_index
== (size_t)-1 )
1452 // this is completely bogus, we don't know how many lines are there
1453 // in the file, but who cares, it's a demo only...
1454 s_index
= rand() % 5;
1457 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1459 bool showAtStartup
= wxShowTip(this, tipProvider
);
1461 if ( showAtStartup
)
1463 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1464 wxOK
| wxICON_INFORMATION
, this);
1467 s_index
= tipProvider
->GetCurrentTip();
1470 #endif // wxUSE_STARTUP_TIPS
1472 #if USE_SETTINGS_DIALOG
1473 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1475 SettingsDialog
dialog(this, event
.GetId());
1478 #endif // USE_SETTINGS_DIALOG
1480 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1482 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1486 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1489 #if wxUSE_NOTIFICATION_MESSAGE
1491 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1493 if ( !wxNotificationMessage
1495 "Automatic Notification",
1496 "Nothing important has happened\n"
1497 "this notification will disappear soon."
1500 wxLogStatus("Failed to show notification message");
1504 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1508 m_notifMsg
= new wxNotificationMessage
1510 "wxWidgets Manual Notification",
1511 "You can hide this notification from the menu",
1516 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1518 wxLogStatus("Failed to show manual notification message");
1522 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1524 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1526 wxLogStatus("Failed to hide manual notification message");
1530 #endif // wxUSE_NOTIFICATION_MESSAGE
1532 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1534 StdButtonSizerDialog
dialog(this);
1538 // TestDefaultAction
1540 #define ID_CATCH_LISTBOX_DCLICK 100
1541 #define ID_LISTBOX 101
1543 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1544 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1545 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1548 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1549 wxDialog( parent
, -1, "Test default action" )
1551 m_catchListBoxDClick
= false;
1553 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1555 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1558 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1559 listbox
->Append( "String 1" );
1560 listbox
->Append( "String 2" );
1561 listbox
->Append( "String 3" );
1562 listbox
->Append( "String 4" );
1563 grid_sizer
->Add( listbox
);
1564 #endif // wxUSE_LISTBOX
1566 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1568 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1569 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1571 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1572 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1574 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1576 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1578 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1580 SetSizerAndFit( main_sizer
);
1583 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1585 event
.Skip( !m_catchListBoxDClick
);
1588 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1590 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1593 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1595 TestDefaultActionDialog
dialog( this );
1599 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1604 #if wxUSE_PROGRESSDLG
1606 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1608 static const int max
= 100;
1610 wxProgressDialog
dialog(wxT("Progress dialog example"),
1611 wxT("An informative message"),
1617 // wxPD_AUTO_HIDE | -- try this as well
1619 wxPD_ESTIMATED_TIME
|
1621 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1625 for ( int i
= 0; i
<= max
; i
++ )
1631 // test both modes of wxProgressDialog behaviour: start in
1632 // indeterminate mode but switch to the determinate one later
1633 const bool determinate
= i
> max
/2;
1637 msg
= wxT("That's all, folks!");
1639 else if ( !determinate
)
1641 msg
= wxT("Testing indeterminate mode");
1643 else if ( determinate
)
1645 msg
= wxT("Now in standard determinate mode");
1648 // will be set to true if "Skip" button was pressed
1652 cont
= dialog
.Update(i
, msg
, &skip
);
1656 cont
= dialog
.Pulse(msg
, &skip
);
1659 // each skip will move progress about quarter forward
1665 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1666 wxT("Progress dialog question"), // caption
1667 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1677 wxLogStatus(wxT("Progress dialog aborted!"));
1681 wxLogStatus(wxT("Countdown from %d finished"), max
);
1685 #endif // wxUSE_PROGRESSDLG
1689 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1691 info
.SetName(wxT("Dialogs Sample"));
1692 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
1696 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
1697 wxVERSION_NUM_DOT_STRING
1699 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1700 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1701 info
.AddDeveloper(wxT("Vadim Zeitlin"));
1704 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1706 InitAboutInfoMinimal(info
);
1708 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
1711 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1713 InitAboutInfoWebsite(info
);
1715 // we can add a second developer
1716 info
.AddDeveloper(wxT("A.N. Other"));
1718 // or we can add several persons at once like this
1719 static const wxChar
*docwriters
[] =
1721 wxT("First D. Writer"),
1725 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1726 info
.SetLicence(wxString::FromAscii(
1727 " wxWindows Library Licence, Version 3.1\n"
1728 " ======================================\n"
1730 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1732 " Everyone is permitted to copy and distribute verbatim copies\n"
1733 " of this licence document, but changing it is not allowed.\n"
1735 " WXWINDOWS LIBRARY LICENCE\n"
1736 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1738 " ...and so on and so forth...\n"
1741 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
1744 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1746 wxAboutDialogInfo info
;
1747 InitAboutInfoMinimal(info
);
1749 wxAboutBox(info
, this);
1752 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1754 wxAboutDialogInfo info
;
1755 InitAboutInfoWebsite(info
);
1757 wxAboutBox(info
, this);
1760 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1762 wxAboutDialogInfo info
;
1763 InitAboutInfoAll(info
);
1765 wxAboutBox(info
, this);
1768 // a trivial example of a custom dialog class
1769 class MyAboutDialog
: public wxGenericAboutDialog
1772 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
1774 Create(info
, parent
);
1777 // add some custom controls
1778 virtual void DoAddCustomControls()
1780 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1781 AddText(wxT("Some custom text"));
1782 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1786 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1788 wxAboutDialogInfo info
;
1789 InitAboutInfoAll(info
);
1791 MyAboutDialog
dlg(info
, this);
1795 #endif // wxUSE_ABOUTDLG
1799 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1801 wxWindowDisabler disableAll
;
1803 wxBusyInfo
info(wxT("Working, please wait..."), this);
1805 for ( int i
= 0; i
< 18; i
++ )
1815 #endif // wxUSE_BUSYINFO
1817 #if wxUSE_FINDREPLDLG
1819 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1823 delete m_dlgReplace
;
1824 m_dlgReplace
= NULL
;
1828 m_dlgReplace
= new wxFindReplaceDialog
1832 wxT("Find and replace dialog"),
1836 m_dlgReplace
->Show(true);
1840 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1849 m_dlgFind
= new wxFindReplaceDialog
1858 m_dlgFind
->Show(true);
1862 static wxString
DecodeFindDialogEventFlags(int flags
)
1865 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
1866 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
1867 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
1868 << wxT("case sensitive");
1873 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1875 wxEventType type
= event
.GetEventType();
1877 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1879 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1880 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1881 event
.GetFindString().c_str(),
1882 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1884 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1885 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1887 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1888 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
1889 event
.GetFindString().c_str(),
1890 event
.GetReplaceString().c_str(),
1891 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1893 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1895 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1899 if ( dlg
== m_dlgFind
)
1902 idMenu
= DIALOGS_FIND
;
1905 else if ( dlg
== m_dlgReplace
)
1907 txt
= wxT("Replace");
1908 idMenu
= DIALOGS_REPLACE
;
1909 m_dlgReplace
= NULL
;
1913 txt
= wxT("Unknown");
1916 wxFAIL_MSG( wxT("unexpected event") );
1919 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1921 if ( idMenu
!= wxID_ANY
)
1923 GetMenuBar()->Check(idMenu
, false);
1930 wxLogError(wxT("Unknown find dialog event!"));
1934 #endif // wxUSE_FINDREPLDLG
1936 // ----------------------------------------------------------------------------
1938 // ----------------------------------------------------------------------------
1940 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1943 dc
.SetFont(wxGetApp().m_canvasFont
);
1944 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1945 dc
.SetBackgroundMode(wxTRANSPARENT
);
1947 wxT("wxWidgets common dialogs")
1948 #if !defined(__SMARTPHONE__)
1949 wxT(" test application")
1954 #if USE_MODAL_PRESENTATION
1956 // ----------------------------------------------------------------------------
1958 // ----------------------------------------------------------------------------
1960 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1961 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
1963 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1965 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
1966 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
1969 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1970 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1972 SetSizerAndFit(sizerTop
);
1975 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1977 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
1978 wxOK
| wxICON_INFORMATION
, this);
1981 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1983 if ( event
.CanVeto() )
1985 wxMessageBox(wxT("Use the menu item to close this dialog"),
1986 wxT("Modeless dialog"),
1987 wxOK
| wxICON_INFORMATION
, this);
1993 // ----------------------------------------------------------------------------
1995 // ----------------------------------------------------------------------------
1997 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1998 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
2000 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
2002 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2003 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2004 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2006 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2007 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2008 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2009 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2011 SetSizerAndFit(sizerTop
);
2013 SetEscapeId(wxID_CLOSE
);
2015 m_btnModal
->SetFocus();
2016 m_btnModal
->SetDefault();
2019 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2021 if ( event
.GetEventObject() == m_btnDelete
)
2026 m_btnDelete
->Disable();
2028 else if ( event
.GetEventObject() == m_btnModal
)
2031 wxGetTextFromUser(wxT("Dummy prompt"),
2032 wxT("Modal dialog called from dialog"),
2033 wxEmptyString
, this);
2035 wxMessageBox(wxT("Modal dialog called from dialog"));
2036 #endif // wxUSE_TEXTDLG
2038 else if ( event
.GetEventObject() == m_btnModeless
)
2040 (new MyModelessDialog(this))->Show();
2048 #endif // USE_MODAL_PRESENTATION
2050 // ----------------------------------------------------------------------------
2051 // StdButtonSizerDialog
2052 // ----------------------------------------------------------------------------
2054 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2055 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2056 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2057 m_buttonsSizer(NULL
)
2059 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2061 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2062 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2064 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2066 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2068 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2069 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2071 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2073 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2075 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2077 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2078 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2080 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2082 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2083 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2084 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2086 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2088 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2089 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2091 sizer
->Add(sizerInside1
, 0, 0, 0);
2092 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2093 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2094 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2096 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2097 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2099 sizer
->Add(sizerInside2
, 0, 0, 0);
2100 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2101 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2102 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2104 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2106 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2107 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2108 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2110 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2112 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2114 EnableDisableControls();
2116 SetSizerAndFit(sizerTop
);
2122 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2126 m_buttonsSizer
->DeleteWindows();
2127 GetSizer()->Remove(m_buttonsSizer
);
2130 EnableDisableControls();
2133 unsigned long numButtons
= 0;
2135 if (m_chkboxAffirmativeButton
->IsChecked())
2137 if (m_radiobtnOk
->GetValue())
2142 else if (m_radiobtnYes
->GetValue())
2149 if (m_chkboxDismissButton
->IsChecked())
2151 if (m_radiobtnCancel
->GetValue())
2157 else if (m_radiobtnClose
->GetValue())
2165 if (m_chkboxApply
->IsChecked())
2171 if (m_chkboxNo
->IsChecked())
2177 if (m_chkboxHelp
->IsChecked())
2183 if (m_chkboxNoDefault
->IsChecked())
2185 flags
|= wxNO_DEFAULT
;
2188 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2189 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2192 GetSizer()->SetSizeHints(this);
2195 void StdButtonSizerDialog::EnableDisableControls()
2197 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2199 m_radiobtnOk
->Enable(affButtonEnabled
);
2200 m_radiobtnYes
->Enable(affButtonEnabled
);
2202 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2204 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2205 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2208 #if USE_SETTINGS_DIALOG
2209 // ----------------------------------------------------------------------------
2211 // ----------------------------------------------------------------------------
2213 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2215 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2218 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2220 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2225 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2226 int resizeBorder
= wxRESIZE_BORDER
;
2234 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2235 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2236 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2238 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2240 SetSheetStyle(sheetStyle
);
2241 SetSheetInnerBorder(0);
2242 SetSheetOuterBorder(0);
2244 // create a dummy image list with a few icons
2245 const wxSize
imageSize(32, 32);
2247 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2249 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2251 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2253 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2255 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2260 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2261 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2264 // If using a toolbook, also follow Mac style and don't create buttons
2266 CreateButtons(wxOK
| wxCANCEL
|
2267 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2270 wxBookCtrlBase
* notebook
= GetBookCtrl();
2271 notebook
->SetImageList(m_imageList
);
2273 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2274 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2276 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2277 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2282 SettingsDialog::~SettingsDialog()
2287 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2289 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2291 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2292 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2296 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2297 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2298 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2299 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2303 wxString autoSaveLabel
= _("&Auto-save every");
2304 wxString minsLabel
= _("mins");
2306 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2307 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2310 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2311 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2314 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2316 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2318 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2319 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2323 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2324 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2325 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2326 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2328 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2330 panel
->SetSizerAndFit(topSizer
);
2335 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2337 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2339 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2340 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2342 //// PROJECT OR GLOBAL
2343 wxString globalOrProjectChoices
[2];
2344 globalOrProjectChoices
[0] = _("&New projects");
2345 globalOrProjectChoices
[1] = _("&This project");
2347 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2348 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2349 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2351 projectOrGlobal
->SetSelection(0);
2353 //// BACKGROUND STYLE
2354 wxArrayString backgroundStyleChoices
;
2355 backgroundStyleChoices
.Add(wxT("Colour"));
2356 backgroundStyleChoices
.Add(wxT("Image"));
2357 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2359 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2360 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2362 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2364 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2366 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2367 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2368 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2370 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2373 //// FONT SIZE SELECTION
2375 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2376 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2378 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2379 wxSize(80, wxDefaultCoord
));
2380 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2382 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2385 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2386 topSizer
->AddSpacer(5);
2388 panel
->SetSizerAndFit(topSizer
);
2393 // ----------------------------------------------------------------------------
2394 // TestMessageBoxDialog
2395 // ----------------------------------------------------------------------------
2398 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2403 { wxCANCEL
, "&Cancel" },
2406 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2407 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2408 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2411 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2412 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2413 wxDefaultPosition
, wxDefaultSize
,
2414 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2416 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2418 // this sizer allows to configure the messages shown in the message box
2420 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2421 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2422 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2423 wxDefaultPosition
, wxDefaultSize
,
2425 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2427 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2428 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2429 wxDefaultPosition
, wxDefaultSize
,
2431 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2433 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2436 // this one is for configuring the buttons
2437 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2438 sizerBtns
->AddGrowableCol(1);
2440 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2441 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2443 for ( int n
= 0; n
< Btn_Max
; n
++ )
2445 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2446 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2448 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2449 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2451 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2452 wxUpdateUIEventHandler(
2453 TestMessageBoxDialog::OnUpdateLabelUI
),
2459 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2460 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2461 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2465 const wxString icons
[] = {
2466 "&None", "&Information", "&Question", "&Warning", "&Error"
2469 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icons",
2470 wxDefaultPosition
, wxDefaultSize
,
2471 WXSIZEOF(icons
), icons
);
2472 // Make the 'Information' icon the default one:
2473 m_icons
->SetSelection(1);
2474 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2477 // miscellaneous other stuff
2479 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2481 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2482 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2483 wxUpdateUIEventHandler(
2484 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2487 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2489 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2490 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2492 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2494 // finally buttons to show the resulting message box and close this dialog
2495 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2496 wxSizerFlags().Right().Border());
2498 SetSizerAndFit(sizerTop
);
2500 m_buttons
[Btn_Ok
]->SetValue(true);
2503 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2505 for ( int n
= 0; n
< Btn_Max
; n
++ )
2507 if ( event
.GetEventObject() == m_labels
[n
] )
2509 event
.Enable( m_buttons
[n
]->IsChecked() );
2514 wxFAIL_MSG( "called for unknown label" );
2517 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2519 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2522 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2526 for ( int n
= 0; n
< Btn_Max
; n
++ )
2528 if ( m_buttons
[n
]->IsChecked() )
2529 style
|= ms_btnInfo
[n
].flag
;
2532 switch ( m_icons
->GetSelection() )
2534 case 0: style
|= wxICON_NONE
; break;
2535 case 1: style
|= wxICON_INFORMATION
; break;
2536 case 2: style
|= wxICON_QUESTION
; break;
2537 case 3: style
|= wxICON_WARNING
; break;
2538 case 4: style
|= wxICON_ERROR
; break;
2541 if ( m_chkCentre
->IsChecked() )
2544 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2545 style
|= wxNO_DEFAULT
;
2548 wxMessageDialog
dlg(this, m_textMsg
->GetValue(), "Test Message Box",
2550 if ( !m_textExtMsg
->IsEmpty() )
2551 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2553 if ( style
& wxYES_NO
)
2555 if ( style
& wxCANCEL
)
2557 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2558 m_labels
[Btn_No
]->GetValue(),
2559 m_labels
[Btn_Cancel
]->GetValue());
2563 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2564 m_labels
[Btn_No
]->GetValue());
2569 if ( style
& wxCANCEL
)
2571 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2572 m_labels
[Btn_Cancel
]->GetValue());
2576 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2583 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2585 EndModal(wxID_CANCEL
);
2588 #endif // USE_SETTINGS_DIALOG
2592 // ----------------------------------------------------------------------------
2593 // custom log target
2594 // ----------------------------------------------------------------------------
2596 class MyLogGui
: public wxLogGui
2599 virtual void DoShowSingleLogMessage(const wxString
& message
,
2600 const wxString
& title
,
2603 wxMessageDialog
dlg(NULL
, message
, title
,
2604 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2605 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2606 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2611 wxLog
*MyAppTraits::CreateLogTarget()
2613 return new MyLogGui
;