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 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
154 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
155 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
156 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
157 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
158 #endif // wxUSE_FILEDLG
160 #if USE_FILEDLG_GENERIC
161 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
162 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
163 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
164 #endif // USE_FILEDLG_GENERIC
167 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
168 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
169 #endif // wxUSE_DIRDLG
171 #if USE_MODAL_PRESENTATION
172 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
173 #endif // USE_MODAL_PRESENTATION
174 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
175 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
176 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
177 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
178 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
180 #if wxUSE_STARTUP_TIPS
181 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
182 #endif // wxUSE_STARTUP_TIPS
184 #if USE_FONTDLG_GENERIC
185 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
186 #endif // USE_FONTDLG_GENERIC
188 #if USE_DIRDLG_GENERIC
189 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
190 #endif // wxMSW || wxMAC
192 #if USE_COLOURDLG_GENERIC
193 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
194 #endif // USE_COLOURDLG_GENERIC
196 #if wxUSE_PROGRESSDLG
197 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
198 #endif // wxUSE_PROGRESSDLG
201 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
202 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
203 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
204 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
205 #endif // wxUSE_ABOUTDLG
208 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
209 #endif // wxUSE_BUSYINFO
211 #if wxUSE_FINDREPLDLG
212 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
213 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
215 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
216 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
217 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
218 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
219 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
220 #endif // wxUSE_FINDREPLDLG
222 #if USE_SETTINGS_DIALOG
223 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
224 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
225 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
226 #endif // USE_SETTINGS_DIALOG
228 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
229 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
231 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
232 #if wxUSE_NOTIFICATION_MESSAGE
233 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
234 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
235 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
236 #endif // wxUSE_NOTIFICATION_MESSAGE
238 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
241 #if USE_MODAL_PRESENTATION
243 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
244 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
247 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
248 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
249 EVT_CLOSE(MyModelessDialog::OnClose
)
252 #endif // USE_MODAL_PRESENTATION
254 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
255 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
256 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
259 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
261 // `Main program' equivalent, creating windows and returning main app frame
264 if ( !wxApp::OnInit() )
268 wxInitAllImageHandlers();
271 m_canvasTextColour
= *wxBLACK
;
272 m_canvasFont
= *wxNORMAL_FONT
;
274 // Create the main frame window
275 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
278 wxMenu
*menuDlg
= new wxMenu
;
280 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
281 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, _T("Message dialog\tShift-Ctrl-M"));
284 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
286 wxMenu
*choices_menu
= new wxMenu
;
289 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose bg colour"));
290 choices_menu
->Append(DIALOGS_GET_COLOUR
, _T("&Choose fg colour"));
291 #endif // wxUSE_COLOURDLG
294 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
295 #endif // wxUSE_FONTDLG
298 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
299 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
300 #endif // wxUSE_CHOICEDLG
302 choices_menu
->Append(DIALOGS_REARRANGE
, _T("&Rearrange dialog\tCtrl-R"));
304 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
305 choices_menu
->AppendSeparator();
306 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
308 #if USE_COLOURDLG_GENERIC
309 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
310 #endif // USE_COLOURDLG_GENERIC
312 #if USE_FONTDLG_GENERIC
313 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
314 #endif // USE_FONTDLG_GENERIC
316 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
317 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
320 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
322 wxMenu
*entry_menu
= new wxMenu
;
325 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
326 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
327 #endif // wxUSE_TEXTDLG
330 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
331 #endif // wxUSE_NUMBERDLG
333 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
335 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
340 wxMenu
*filedlg_menu
= new wxMenu
;
341 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
342 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
343 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
344 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
346 #if USE_FILEDLG_GENERIC
347 filedlg_menu
->AppendSeparator();
348 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
349 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
350 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
351 #endif // USE_FILEDLG_GENERIC
353 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
355 #endif // wxUSE_FILEDLG
358 wxMenu
*dir_menu
= new wxMenu
;
360 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
361 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
362 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
364 #if USE_DIRDLG_GENERIC
365 dir_menu
->AppendSeparator();
366 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
367 #endif // USE_DIRDLG_GENERIC
369 #endif // wxUSE_DIRDLG
372 #if wxUSE_STARTUP_TIPS || \
373 wxUSE_PROGRESSDLG || \
375 wxUSE_LOG_DIALOG || \
378 wxMenu
*info_menu
= new wxMenu
;
380 #if wxUSE_STARTUP_TIPS
381 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
382 #endif // wxUSE_STARTUP_TIPS
384 #if wxUSE_PROGRESSDLG
385 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
386 #endif // wxUSE_PROGRESSDLG
389 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
390 #endif // wxUSE_BUSYINFO
393 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
394 #endif // wxUSE_LOG_DIALOG
397 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
398 _T("&wxWidgets information\tCtrl-I"));
399 #endif // wxUSE_MSGDLG
401 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
403 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
406 #if wxUSE_FINDREPLDLG
407 wxMenu
*find_menu
= new wxMenu
;
408 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
409 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
410 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
411 #endif // wxUSE_FINDREPLDLG
413 wxMenu
*dialogs_menu
= new wxMenu
;
414 #if USE_MODAL_PRESENTATION
415 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
416 #endif // USE_MODAL_PRESENTATION
417 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
418 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
419 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
420 dialogs_menu
->Append(DIALOGS_MINIFRAME
, _T("&Mini frame"));
421 dialogs_menu
->Append(DIALOGS_ONTOP
, _T("Dialog staying on &top"));
422 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
424 #if USE_SETTINGS_DIALOG
425 wxMenu
*sheet_menu
= new wxMenu
;
426 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
427 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
429 if (wxPlatformIs(wxPORT_MAC
))
430 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
433 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
436 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
437 #endif // USE_SETTINGS_DIALOG
439 wxMenu
*menuNotif
= new wxMenu
;
440 menuNotif
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-Shift-R"));
441 #if wxUSE_NOTIFICATION_MESSAGE
442 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
443 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
444 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
445 #endif // wxUSE_NOTIFICATION_MESSAGE
446 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
448 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, _T("&Standard Buttons Sizer Dialog"));
449 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, _T("&Test dialog default action"));
451 menuDlg
->AppendSeparator();
452 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
455 wxMenu
*menuHelp
= new wxMenu
;
456 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
457 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
458 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
459 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
460 #endif // wxUSE_ABOUTDLG
462 wxMenuBar
*menubar
= new wxMenuBar
;
463 menubar
->Append(menuDlg
, _T("&Dialogs"));
465 menubar
->Append(menuHelp
, _T("&Help"));
466 #endif // wxUSE_ABOUTDLG
468 frame
->SetMenuBar(menubar
);
470 myCanvas
= new MyCanvas(frame
);
471 myCanvas
->SetBackgroundColour(*wxWHITE
);
473 frame
->Centre(wxBOTH
);
483 // My frame constructor
484 MyFrame::MyFrame(wxWindow
*parent
,
485 const wxString
& title
)
486 : wxFrame(parent
, wxID_ANY
, title
)
490 #if USE_MODAL_PRESENTATION
491 m_dialog
= (MyModelessDialog
*)NULL
;
492 #endif // USE_MODAL_PRESENTATION
494 #if wxUSE_FINDREPLDLG
500 m_clrData
.SetChooseFull(true);
501 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
503 unsigned char n
= i
*16;
504 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
506 #endif // wxUSE_COLOURDLG
508 #if wxUSE_NOTIFICATION_MESSAGE
510 #endif // wxUSE_NOTIFICATION_MESSAGE
514 #endif // wxUSE_STATUSBAR
519 #if wxUSE_NOTIFICATION_MESSAGE
521 #endif // wxUSE_NOTIFICATION_MESSAGE
526 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
528 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
530 wxColourDialog
dialog(this, &m_clrData
);
531 dialog
.SetTitle(_("Please choose the background colour"));
532 if ( dialog
.ShowModal() == wxID_OK
)
534 m_clrData
= dialog
.GetColourData();
535 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
536 myCanvas
->ClearBackground();
541 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
543 wxColour clr
= wxGetColourFromUser
546 wxGetApp().m_canvasTextColour
,
547 "Please choose the foreground colour"
551 wxGetApp().m_canvasTextColour
= clr
;
554 //else: dialog cancelled by user
557 #endif // wxUSE_COLOURDLG
560 #if USE_COLOURDLG_GENERIC
561 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
563 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
565 //FIXME:TODO:This has no effect...
566 m_clrData
.SetChooseFull(true);
568 for (int i
= 0; i
< 16; i
++)
571 (unsigned char)(i
*16),
572 (unsigned char)(i
*16),
573 (unsigned char)(i
*16)
575 m_clrData
.SetCustomColour(i
, colour
);
578 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
579 if (dialog
->ShowModal() == wxID_OK
)
581 m_clrData
= dialog
->GetColourData();
582 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
583 myCanvas
->ClearBackground();
588 #endif // USE_COLOURDLG_GENERIC
591 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
594 data
.SetInitialFont(wxGetApp().m_canvasFont
);
595 data
.SetColour(wxGetApp().m_canvasTextColour
);
597 // you might also do this:
599 // wxFontDialog dialog;
600 // if ( !dialog.Create(this, data) { ... error ... }
602 wxFontDialog
dialog(this, data
);
604 if (dialog
.ShowModal() == wxID_OK
)
606 wxFontData retData
= dialog
.GetFontData();
607 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
608 wxGetApp().m_canvasTextColour
= retData
.GetColour();
611 //else: cancelled by the user, don't change the font
613 #endif // wxUSE_FONTDLG
615 #if USE_FONTDLG_GENERIC
616 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
619 data
.SetInitialFont(wxGetApp().m_canvasFont
);
620 data
.SetColour(wxGetApp().m_canvasTextColour
);
622 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
623 if (dialog
->ShowModal() == wxID_OK
)
625 wxFontData retData
= dialog
->GetFontData();
626 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
627 wxGetApp().m_canvasTextColour
= retData
.GetColour();
632 #endif // USE_FONTDLG_GENERIC
635 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
637 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
638 // being flushed -- test it
641 wxLogMessage(wxT("This is some message - everything is ok so far."));
642 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
643 wxLogWarning(wxT("And then something went wrong!"));
645 // and if ~wxBusyCursor doesn't do it, then call it manually
649 wxLogError(wxT("Intermediary error handler decided to abort."));
650 wxLogError(wxT("The top level caller detected an unrecoverable error."));
652 wxLog::FlushActive();
654 wxLogMessage(wxT("And this is the same dialog but with only one message."));
656 #endif // wxUSE_LOG_DIALOG
659 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
661 wxMessageDialog
dialog(this,
662 "This is a message box\n"
663 "This is a long, long string to test out if the message box "
664 "is laid out properly.",
667 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
671 if ( dialog
.SetYesNoCancelLabels
678 extmsg
= "This platform supports custom button labels,\n"
679 "so you should see the descriptive labels below.";
683 extmsg
= "Custom button labels are not supported on this platform,\n"
684 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
686 dialog
.SetExtendedMessage(extmsg
);
688 switch ( dialog
.ShowModal() )
691 wxLogStatus(wxT("You pressed \"Yes\""));
695 wxLogStatus(wxT("You pressed \"No\""));
699 wxLogStatus(wxT("You pressed \"Cancel\""));
703 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
707 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
709 TestMessageBoxDialog
dlg(this);
713 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
715 ::wxInfoMessageBox(this);
717 #endif // wxUSE_MSGDLG
720 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
722 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
723 _T("Even two rows of text."),
724 _T("Enter a number:"), _T("Numeric input test"),
731 msg
= _T("Invalid number entered or dialog cancelled.");
736 msg
.Printf(_T("You've entered %lu"), res
);
737 icon
= wxICON_INFORMATION
;
740 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
742 #endif // wxUSE_NUMBERDLG
745 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
747 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
748 _T("Password entry dialog"),
753 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
754 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
758 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
760 wxTextEntryDialog
dialog(this,
761 _T("This is a small sample\n")
762 _T("A long, long string to test out the text entrybox"),
763 _T("Please enter a string"),
767 if (dialog
.ShowModal() == wxID_OK
)
769 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
772 #endif // wxUSE_TEXTDLG
775 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
777 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
779 wxSingleChoiceDialog
dialog(this,
780 _T("This is a small sample\n")
781 _T("A single-choice convenience dialog"),
782 _T("Please select a value"),
783 WXSIZEOF(choices
), choices
);
785 dialog
.SetSelection(2);
787 if (dialog
.ShowModal() == wxID_OK
)
789 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
794 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
796 const wxString choices
[] =
798 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
799 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
800 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
803 wxArrayInt selections
;
804 size_t count
= wxGetMultipleChoices(selections
,
805 _T("This is a small sample\n")
806 _T("A multi-choice convenience dialog"),
807 _T("Please select a value"),
808 WXSIZEOF(choices
), choices
,
813 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
814 for ( size_t n
= 0; n
< count
; n
++ )
816 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
817 (unsigned)n
, (unsigned)selections
[n
],
818 choices
[selections
[n
]].c_str());
822 //else: cancelled or nothing selected
824 #endif // wxUSE_CHOICEDLG
826 // custom rearrange dialog: it adds the possibility to rename an item to the
827 // base class functionality
828 class MyRearrangeDialog
: public wxRearrangeDialog
831 MyRearrangeDialog(wxWindow
*parent
,
833 wxArrayString
& labels
,
834 wxArrayString
& labelsOrig
)
838 "Configure the columns shown:",
839 "wxRearrangeDialog example",
845 m_labelsOrig(labelsOrig
)
849 wxPanel
* const panel
= new wxPanel(this);
850 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
852 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
853 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
855 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
856 wxDefaultPosition
, wxDefaultSize
,
858 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
860 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
861 wxSizerFlags().Centre());
863 panel
->SetSizer(sizer
);
865 // call this first to ensure that the controls have a reasonable best
866 // size before they're added
867 DoUpdateExtraControls(GetList()->GetSelection());
869 AddExtraControls(panel
);
872 // another customization not directly supported by the dialog: add a
874 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
875 wxCHECK_RET( btnOk
, "no Ok button?" );
877 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
878 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
880 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
881 wxSizerFlags().Border(wxLEFT
));
884 // call this instead of ShowModal() to update order and labels array in
885 // case the dialog was not cancelled
888 switch ( ShowModal() )
894 m_order
= GetOrder();
898 // order already reset
906 void OnSelChange(wxCommandEvent
& event
)
908 DoUpdateExtraControls(event
.GetInt());
911 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
913 event
.Enable( CanRename() );
916 void OnRename(wxCommandEvent
& WXUNUSED(event
))
921 m_labels
[m_sel
] = m_text
->GetValue();
922 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
925 void OnReset(wxCommandEvent
& WXUNUSED(event
))
927 // in a real program we should probably ask if the user really wants to
928 // do this but here we just go ahead and reset all columns labels and
929 // their order without confirmation
930 const unsigned count
= m_order
.size();
931 for ( unsigned n
= 0; n
< count
; n
++ )
934 m_labels
[n
] = m_labelsOrig
[n
];
937 EndModal(wxID_RESET
);
940 bool CanRename() const
942 // only allow renaming if the user modified the currently selected item
943 // text (which presupposes that we do have a current item)
944 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
947 void DoUpdateExtraControls(int sel
)
951 if ( m_sel
== wxNOT_FOUND
)
953 m_labelOrig
->SetLabel("<no selection>");
957 else // have valid item
959 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
961 m_text
->SetValue(m_labels
[m_sel
]);
966 wxArrayString
& m_labels
,
970 wxStaticText
*m_labelOrig
;
973 DECLARE_EVENT_TABLE()
974 DECLARE_NO_COPY_CLASS(MyRearrangeDialog
)
977 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
978 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
980 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
982 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
983 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
984 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
987 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
989 // the arrays are static so that we preserve the items order between calls
991 static wxArrayInt s_order
;
992 static wxArrayString s_labels
,
995 // initialize them on the first call
996 if ( s_labelsOrig
.empty() )
998 static const struct ItemInfo
1001 const char *labelOrig
;
1005 { "File name", "Name", 0 },
1006 { "File type", "Ext", 1 },
1007 { "Size", "Size", 2 },
1008 { "Creation time", "Ctime", ~3 }, // negated so hidden
1009 { "Last accessed", "Atime", ~4 },
1010 { "Last modified", "Mtime", 5 },
1013 s_order
.reserve(WXSIZEOF(items
));
1014 s_labels
.reserve(WXSIZEOF(items
));
1015 s_labelsOrig
.reserve(WXSIZEOF(items
));
1016 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1018 const ItemInfo
& item
= items
[n
];
1019 s_order
.push_back(item
.order
);
1020 s_labels
.push_back(item
.label
);
1021 s_labelsOrig
.push_back(item
.labelOrig
);
1025 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1026 if ( !dlg
.Rearrange() )
1030 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1032 columns
+= wxString::Format("\n %u: ", n
);
1033 int idx
= s_order
[n
];
1036 columns
+= "[hidden] ";
1040 columns
+= s_labels
[idx
];
1041 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1043 columns
+= wxString::Format(" (original label: \"%s\")",
1048 wxLogMessage("The columns order now is:%s", columns
);
1053 // panel with custom controls for file dialog
1054 class MyExtraPanel
: public wxPanel
1057 MyExtraPanel(wxWindow
*parent
);
1058 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1059 wxString
GetInfo() const
1061 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1068 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1071 m_btn
= new wxButton(this, -1, _T("Custom Button"));
1072 m_btn
->Enable(false);
1073 m_cb
= new wxCheckBox(this, -1, _T("Enable Custom Button"));
1074 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1075 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1076 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1077 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1078 sizerTop
->AddStretchSpacer();
1079 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1080 SetSizerAndFit(sizerTop
);
1083 // a static method can be used instead of a function with most of compilers
1084 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1086 return new MyExtraPanel(parent
);
1089 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1094 _T("Testing open file dialog"),
1098 _T("C++ files (*.cpp)|*.cpp")
1100 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
1104 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1105 dialog
.CentreOnParent();
1106 dialog
.SetDirectory(wxGetHomeDir());
1108 if (dialog
.ShowModal() == wxID_OK
)
1111 wxWindow
* const extra
= dialog
.GetExtraControl();
1112 info
.Printf(_T("Full file name: %s\n")
1115 _T("Custom window: %s"),
1116 dialog
.GetPath().c_str(),
1117 dialog
.GetDirectory().c_str(),
1118 dialog
.GetFilename().c_str(),
1119 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1120 : wxString("None"));
1121 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
1122 dialog2
.ShowModal();
1126 // this shows how to take advantage of specifying a default extension in the
1127 // call to wxFileSelector: it is remembered after each new call and the next
1128 // one will use it by default
1129 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1131 static wxString s_extDef
;
1132 wxString path
= wxFileSelector(
1133 _T("Select the file to load"),
1134 wxEmptyString
, wxEmptyString
,
1138 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1139 wxFileSelectorDefaultWildcardStr
,
1140 wxFileSelectorDefaultWildcardStr
1142 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1149 // it is just a sample, would use wxSplitPath in real program
1150 s_extDef
= path
.AfterLast(_T('.'));
1152 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
1156 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1158 wxString wildcards
=
1160 _T("C++ files (*.cpp)|*.cpp");
1164 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1165 wxFileSelectorDefaultWildcardStr
,
1166 wxFileSelectorDefaultWildcardStr
1169 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
1170 wxEmptyString
, wxEmptyString
, wildcards
,
1171 wxFD_OPEN
|wxFD_MULTIPLE
);
1173 if (dialog
.ShowModal() == wxID_OK
)
1175 wxArrayString paths
, filenames
;
1177 dialog
.GetPaths(paths
);
1178 dialog
.GetFilenames(filenames
);
1181 size_t count
= paths
.GetCount();
1182 for ( size_t n
= 0; n
< count
; n
++ )
1184 s
.Printf(_T("File %d: %s (%s)\n"),
1185 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1189 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
1192 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
1193 dialog2
.ShowModal();
1197 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1199 wxFileDialog
dialog(this,
1200 _T("Testing save file dialog"),
1203 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1204 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1206 dialog
.SetFilterIndex(1);
1208 if (dialog
.ShowModal() == wxID_OK
)
1210 wxLogMessage(_T("%s, filter %d"),
1211 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1214 #endif // wxUSE_FILEDLG
1216 #if USE_FILEDLG_GENERIC
1217 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1219 wxGenericFileDialog dialog
1222 _T("Testing open file dialog"),
1225 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
1228 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1229 dialog
.SetDirectory(wxGetHomeDir());
1231 if (dialog
.ShowModal() == wxID_OK
)
1234 info
.Printf(_T("Full file name: %s\n")
1237 dialog
.GetPath().c_str(),
1238 dialog
.GetDirectory().c_str(),
1239 dialog
.GetFilename().c_str());
1240 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
1241 dialog2
.ShowModal();
1245 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1247 // On PocketPC you can disable OK-only dialogs policy using system option
1248 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1249 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1251 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1252 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
1253 wxEmptyString
, wxEmptyString
, wildcards
,
1256 if (dialog
.ShowModal() == wxID_OK
)
1258 wxArrayString paths
, filenames
;
1260 dialog
.GetPaths(paths
);
1261 dialog
.GetFilenames(filenames
);
1264 size_t count
= paths
.GetCount();
1265 for ( size_t n
= 0; n
< count
; n
++ )
1267 s
.Printf(_T("File %d: %s (%s)\n"),
1268 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1272 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
1275 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
1276 dialog2
.ShowModal();
1279 // restore system option
1280 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1283 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1285 wxGenericFileDialog
dialog(this,
1286 _T("Testing save file dialog"),
1289 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1290 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1292 dialog
.SetFilterIndex(1);
1294 if (dialog
.ShowModal() == wxID_OK
)
1296 wxLogMessage(_T("%s, filter %d"),
1297 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1300 #endif // USE_FILEDLG_GENERIC
1303 void MyFrame::DoDirChoose(int style
)
1305 // pass some initial dir to wxDirDialog
1307 wxGetHomeDir(&dirHome
);
1309 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
1311 if (dialog
.ShowModal() == wxID_OK
)
1313 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
1317 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1319 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1322 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1324 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1326 #endif // wxUSE_DIRDLG
1328 #if USE_DIRDLG_GENERIC
1329 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1331 // pass some initial dir to wxDirDialog
1333 wxGetHomeDir(&dirHome
);
1335 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
1337 if (dialog
.ShowModal() == wxID_OK
)
1339 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
1340 dialog2
.ShowModal();
1343 #endif // USE_DIRDLG_GENERIC
1345 #if USE_MODAL_PRESENTATION
1346 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1348 MyModalDialog
dlg(this);
1351 #endif // USE_MODAL_PRESENTATION
1353 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1355 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1361 m_dialog
= new MyModelessDialog(this);
1364 m_dialog
->Show(true);
1368 // If m_dialog is NULL, then possibly the system
1369 // didn't report the checked menu item status correctly.
1370 // It should be true just after the menu item was selected,
1371 // if there was no modeless dialog yet.
1373 wxASSERT( m_dialog
!= NULL
);
1379 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1381 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1382 wxDefaultPosition
, wxSize(200, 100));
1383 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1384 dlg
.CentreOnScreen();
1388 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1390 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1391 wxDefaultPosition
, wxSize(200, 100));
1392 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1393 dlg
.CentreOnParent();
1397 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1399 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, _T("Mini frame"),
1400 wxDefaultPosition
, wxSize(300, 100),
1401 wxCAPTION
| wxCLOSE_BOX
);
1402 new wxStaticText(frame
,
1404 _T("Mini frames have slightly different appearance"),
1406 new wxStaticText(frame
,
1408 _T("from the normal frames but that's the only difference."),
1411 frame
->CentreOnParent();
1415 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1417 wxDialog
dlg(this, wxID_ANY
, _T("Dialog staying on top of other windows"),
1418 wxDefaultPosition
, wxSize(300, 100),
1419 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1420 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1424 #if wxUSE_STARTUP_TIPS
1425 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1427 static size_t s_index
= (size_t)-1;
1429 if ( s_index
== (size_t)-1 )
1433 // this is completely bogus, we don't know how many lines are there
1434 // in the file, but who cares, it's a demo only...
1435 s_index
= rand() % 5;
1438 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1440 bool showAtStartup
= wxShowTip(this, tipProvider
);
1442 if ( showAtStartup
)
1444 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1445 wxOK
| wxICON_INFORMATION
, this);
1448 s_index
= tipProvider
->GetCurrentTip();
1451 #endif // wxUSE_STARTUP_TIPS
1453 #if USE_SETTINGS_DIALOG
1454 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1456 SettingsDialog
dialog(this, event
.GetId());
1459 #endif // USE_SETTINGS_DIALOG
1461 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1463 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1467 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1470 #if wxUSE_NOTIFICATION_MESSAGE
1472 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1474 if ( !wxNotificationMessage
1476 "Automatic Notification",
1477 "Nothing important has happened\n"
1478 "this notification will disappear soon."
1481 wxLogStatus("Failed to show notification message");
1485 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1489 m_notifMsg
= new wxNotificationMessage
1491 "wxWidgets Manual Notification",
1492 "You can hide this notification from the menu",
1497 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1499 wxLogStatus("Failed to show manual notification message");
1503 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1507 if ( !m_notifMsg
->Close() )
1508 wxLogStatus("Failed to hide manual notification message");
1512 #endif // wxUSE_NOTIFICATION_MESSAGE
1514 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1516 StdButtonSizerDialog
dialog(this);
1520 // TestDefaultAction
1522 #define ID_CATCH_LISTBOX_DCLICK 100
1523 #define ID_LISTBOX 101
1525 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1526 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1527 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1530 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1531 wxDialog( parent
, -1, "Test default action" )
1533 m_catchListBoxDClick
= false;
1535 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1537 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1539 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1540 listbox
->Append( "String 1" );
1541 listbox
->Append( "String 2" );
1542 listbox
->Append( "String 3" );
1543 listbox
->Append( "String 4" );
1544 grid_sizer
->Add( listbox
);
1546 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1548 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1549 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1551 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1552 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1554 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1556 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1558 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1560 SetSizerAndFit( main_sizer
);
1563 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1565 event
.Skip( !m_catchListBoxDClick
);
1568 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1570 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1573 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1575 TestDefaultActionDialog
dialog( this );
1579 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1584 #if wxUSE_PROGRESSDLG
1586 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1588 static const int max
= 100;
1590 wxProgressDialog
dialog(_T("Progress dialog example"),
1591 _T("An informative message"),
1597 // wxPD_AUTO_HIDE | -- try this as well
1599 wxPD_ESTIMATED_TIME
|
1601 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1605 for ( int i
= 0; i
<= max
; i
++ )
1611 // test both modes of wxProgressDialog behaviour: start in
1612 // indeterminate mode but switch to the determinate one later
1613 const bool determinate
= i
> max
/2;
1617 msg
= _T("That's all, folks!");
1619 else if ( !determinate
)
1621 msg
= _T("Testing indeterminate mode");
1623 else if ( determinate
)
1625 msg
= _T("Now in standard determinate mode");
1628 // will be set to true if "Skip" button was pressed
1632 cont
= dialog
.Update(i
, msg
, &skip
);
1636 cont
= dialog
.Pulse(msg
, &skip
);
1639 // each skip will move progress about quarter forward
1645 if ( wxMessageBox(_T("Do you really want to cancel?"),
1646 _T("Progress dialog question"), // caption
1647 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1657 wxLogStatus(wxT("Progress dialog aborted!"));
1661 wxLogStatus(wxT("Countdown from %d finished"), max
);
1665 #endif // wxUSE_PROGRESSDLG
1669 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1671 info
.SetName(_T("Dialogs Sample"));
1672 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1673 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1674 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1675 info
.AddDeveloper(_T("Vadim Zeitlin"));
1678 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1680 InitAboutInfoMinimal(info
);
1682 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1685 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1687 InitAboutInfoWebsite(info
);
1689 // we can add a second developer
1690 info
.AddDeveloper(_T("A.N. Other"));
1692 // or we can add several persons at once like this
1693 static const wxChar
*docwriters
[] =
1695 _T("First D. Writer"),
1699 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1700 info
.SetLicence(wxString::FromAscii(
1701 " wxWindows Library Licence, Version 3.1\n"
1702 " ======================================\n"
1704 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1706 " Everyone is permitted to copy and distribute verbatim copies\n"
1707 " of this licence document, but changing it is not allowed.\n"
1709 " WXWINDOWS LIBRARY LICENCE\n"
1710 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1712 " ...and so on and so forth...\n"
1715 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1718 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1720 wxAboutDialogInfo info
;
1721 InitAboutInfoMinimal(info
);
1726 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1728 wxAboutDialogInfo info
;
1729 InitAboutInfoWebsite(info
);
1734 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1736 wxAboutDialogInfo info
;
1737 InitAboutInfoAll(info
);
1742 // a trivial example of a custom dialog class
1743 class MyAboutDialog
: public wxGenericAboutDialog
1746 MyAboutDialog(const wxAboutDialogInfo
& info
)
1751 // add some custom controls
1752 virtual void DoAddCustomControls()
1754 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1755 AddText(_T("Some custom text"));
1756 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1760 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1762 wxAboutDialogInfo info
;
1763 InitAboutInfoAll(info
);
1765 MyAboutDialog
dlg(info
);
1769 #endif // wxUSE_ABOUTDLG
1773 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1775 wxWindowDisabler disableAll
;
1777 wxBusyInfo
info(_T("Working, please wait..."), this);
1779 for ( int i
= 0; i
< 18; i
++ )
1789 #endif // wxUSE_BUSYINFO
1791 #if wxUSE_FINDREPLDLG
1793 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1797 delete m_dlgReplace
;
1798 m_dlgReplace
= NULL
;
1802 m_dlgReplace
= new wxFindReplaceDialog
1806 _T("Find and replace dialog"),
1810 m_dlgReplace
->Show(true);
1814 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1823 m_dlgFind
= new wxFindReplaceDialog
1832 m_dlgFind
->Show(true);
1836 static wxString
DecodeFindDialogEventFlags(int flags
)
1839 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1840 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1841 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1842 << _T("case sensitive");
1847 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1849 wxEventType type
= event
.GetEventType();
1851 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1853 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1854 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1855 event
.GetFindString().c_str(),
1856 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1858 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1859 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1861 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1862 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1863 event
.GetFindString().c_str(),
1864 event
.GetReplaceString().c_str(),
1865 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1867 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1869 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1873 if ( dlg
== m_dlgFind
)
1876 idMenu
= DIALOGS_FIND
;
1879 else if ( dlg
== m_dlgReplace
)
1881 txt
= _T("Replace");
1882 idMenu
= DIALOGS_REPLACE
;
1883 m_dlgReplace
= NULL
;
1887 txt
= _T("Unknown");
1890 wxFAIL_MSG( _T("unexpected event") );
1893 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1895 if ( idMenu
!= wxID_ANY
)
1897 GetMenuBar()->Check(idMenu
, false);
1904 wxLogError(wxT("Unknown find dialog event!"));
1908 #endif // wxUSE_FINDREPLDLG
1910 // ----------------------------------------------------------------------------
1912 // ----------------------------------------------------------------------------
1914 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1917 dc
.SetFont(wxGetApp().m_canvasFont
);
1918 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1919 dc
.SetBackgroundMode(wxTRANSPARENT
);
1921 _T("wxWidgets common dialogs")
1922 #if !defined(__SMARTPHONE__)
1923 _T(" test application")
1928 #if USE_MODAL_PRESENTATION
1930 // ----------------------------------------------------------------------------
1932 // ----------------------------------------------------------------------------
1934 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1935 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1937 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1939 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1940 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1943 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1944 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1946 SetSizerAndFit(sizerTop
);
1949 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1951 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1952 wxOK
| wxICON_INFORMATION
, this);
1955 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1957 if ( event
.CanVeto() )
1959 wxMessageBox(_T("Use the menu item to close this dialog"),
1960 _T("Modeless dialog"),
1961 wxOK
| wxICON_INFORMATION
, this);
1967 // ----------------------------------------------------------------------------
1969 // ----------------------------------------------------------------------------
1971 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1972 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1974 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1976 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1977 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1978 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1980 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1981 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1982 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1983 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1984 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1986 SetSizerAndFit(sizerTop
);
1988 m_btnModal
->SetFocus();
1989 m_btnModal
->SetDefault();
1992 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1994 if ( event
.GetEventObject() == m_btnDelete
)
1999 m_btnDelete
->Disable();
2001 else if ( event
.GetEventObject() == m_btnModal
)
2004 wxGetTextFromUser(_T("Dummy prompt"),
2005 _T("Modal dialog called from dialog"),
2006 wxEmptyString
, this);
2008 wxMessageBox(_T("Modal dialog called from dialog"));
2009 #endif // wxUSE_TEXTDLG
2011 else if ( event
.GetEventObject() == m_btnModeless
)
2013 (new MyModelessDialog(this))->Show();
2021 #endif // USE_MODAL_PRESENTATION
2023 // ----------------------------------------------------------------------------
2024 // StdButtonSizerDialog
2025 // ----------------------------------------------------------------------------
2027 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2028 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
2029 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2030 m_buttonsSizer(NULL
)
2032 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2034 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2035 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2037 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2039 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2041 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2042 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2044 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2046 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2048 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2050 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2051 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2053 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2055 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2056 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2057 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2059 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2061 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2062 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2064 sizer
->Add(sizerInside1
, 0, 0, 0);
2065 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2066 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2067 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2069 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2070 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2072 sizer
->Add(sizerInside2
, 0, 0, 0);
2073 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2074 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2075 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2077 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2079 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2080 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2081 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2083 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2085 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2087 EnableDisableControls();
2089 SetSizerAndFit(sizerTop
);
2095 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2099 m_buttonsSizer
->DeleteWindows();
2100 GetSizer()->Remove(m_buttonsSizer
);
2103 EnableDisableControls();
2106 unsigned long numButtons
= 0;
2108 if (m_chkboxAffirmativeButton
->IsChecked())
2110 if (m_radiobtnOk
->GetValue())
2115 else if (m_radiobtnYes
->GetValue())
2122 if (m_chkboxDismissButton
->IsChecked())
2124 if (m_radiobtnCancel
->GetValue())
2130 else if (m_radiobtnClose
->GetValue())
2138 if (m_chkboxApply
->IsChecked())
2144 if (m_chkboxNo
->IsChecked())
2150 if (m_chkboxHelp
->IsChecked())
2156 if (m_chkboxNoDefault
->IsChecked())
2158 flags
|= wxNO_DEFAULT
;
2161 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2162 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2165 GetSizer()->SetSizeHints(this);
2168 void StdButtonSizerDialog::EnableDisableControls()
2170 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2172 m_radiobtnOk
->Enable(affButtonEnabled
);
2173 m_radiobtnYes
->Enable(affButtonEnabled
);
2175 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2177 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2178 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2181 #if USE_SETTINGS_DIALOG
2182 // ----------------------------------------------------------------------------
2184 // ----------------------------------------------------------------------------
2186 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2188 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2191 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2193 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2198 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2199 int resizeBorder
= wxRESIZE_BORDER
;
2207 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2208 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2209 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2211 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2213 SetSheetStyle(sheetStyle
);
2214 SetSheetInnerBorder(0);
2215 SetSheetOuterBorder(0);
2217 // create a dummy image list with a few icons
2218 const wxSize
imageSize(32, 32);
2220 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2222 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2224 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2226 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2228 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2233 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2234 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2237 // If using a toolbook, also follow Mac style and don't create buttons
2239 CreateButtons(wxOK
| wxCANCEL
|
2240 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2243 wxBookCtrlBase
* notebook
= GetBookCtrl();
2244 notebook
->SetImageList(m_imageList
);
2246 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2247 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2249 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2250 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2255 SettingsDialog::~SettingsDialog()
2260 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2262 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2264 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2265 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2269 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2270 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2271 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2272 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2276 wxString autoSaveLabel
= _("&Auto-save every");
2277 wxString minsLabel
= _("mins");
2279 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2280 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2283 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2284 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2287 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2289 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2291 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2292 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2296 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2297 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2298 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2299 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2301 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2303 panel
->SetSizerAndFit(topSizer
);
2308 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2310 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2312 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2313 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2315 //// PROJECT OR GLOBAL
2316 wxString globalOrProjectChoices
[2];
2317 globalOrProjectChoices
[0] = _("&New projects");
2318 globalOrProjectChoices
[1] = _("&This project");
2320 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2321 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2322 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2324 projectOrGlobal
->SetSelection(0);
2326 //// BACKGROUND STYLE
2327 wxArrayString backgroundStyleChoices
;
2328 backgroundStyleChoices
.Add(wxT("Colour"));
2329 backgroundStyleChoices
.Add(wxT("Image"));
2330 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2332 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2333 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2335 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2337 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2339 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2340 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2341 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2343 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2346 //// FONT SIZE SELECTION
2348 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2349 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2351 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2352 wxSize(80, wxDefaultCoord
));
2353 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2355 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2358 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2359 topSizer
->AddSpacer(5);
2361 panel
->SetSizerAndFit(topSizer
);
2366 // ----------------------------------------------------------------------------
2367 // TestMessageBoxDialog
2368 // ----------------------------------------------------------------------------
2371 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2376 { wxCANCEL
, "&Cancel" },
2379 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2380 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2381 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2384 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2385 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2386 wxDefaultPosition
, wxDefaultSize
,
2387 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2389 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2391 // this sizer allows to configure the messages shown in the message box
2393 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2394 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2395 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2396 wxDefaultPosition
, wxDefaultSize
,
2398 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2400 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2401 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2402 wxDefaultPosition
, wxDefaultSize
,
2404 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2406 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2409 // this one is for configuring the buttons
2410 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2411 sizerBtns
->AddGrowableCol(1);
2413 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2414 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2416 for ( int n
= 0; n
< Btn_Max
; n
++ )
2418 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2419 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2421 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2422 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2424 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2425 wxUpdateUIEventHandler(
2426 TestMessageBoxDialog::OnUpdateLabelUI
),
2432 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2433 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2434 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2438 const wxString icons
[] = {
2439 "&Information", "&Question", "&Warning", "&Error"
2442 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon:",
2443 wxDefaultPosition
, wxDefaultSize
,
2444 WXSIZEOF(icons
), icons
);
2445 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2448 // miscellaneous other stuff
2450 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2452 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2453 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2454 wxUpdateUIEventHandler(
2455 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2458 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2460 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2461 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2463 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2465 // finally buttons to show the resulting message box and close this dialog
2466 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2467 wxSizerFlags().Right().Border());
2469 SetSizerAndFit(sizerTop
);
2471 m_buttons
[Btn_Ok
]->SetValue(true);
2474 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2476 for ( int n
= 0; n
< Btn_Max
; n
++ )
2478 if ( event
.GetEventObject() == m_labels
[n
] )
2480 event
.Enable( m_buttons
[n
]->IsChecked() );
2485 wxFAIL_MSG( "called for unknown label" );
2488 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2490 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2493 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2497 for ( int n
= 0; n
< Btn_Max
; n
++ )
2499 if ( m_buttons
[n
]->IsChecked() )
2500 style
|= ms_btnInfo
[n
].flag
;
2503 switch ( m_icons
->GetSelection() )
2505 case 0: style
|= wxICON_INFORMATION
; break;
2506 case 1: style
|= wxICON_QUESTION
; break;
2507 case 2: style
|= wxICON_WARNING
; break;
2508 case 3: style
|= wxICON_ERROR
; break;
2511 if ( m_chkCentre
->IsChecked() )
2514 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2515 style
|= wxNO_DEFAULT
;
2518 wxMessageDialog
dlg(this, m_textMsg
->GetValue(), "Test Message Box",
2520 if ( !m_textExtMsg
->IsEmpty() )
2521 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2523 if ( style
& wxYES_NO
)
2525 if ( style
& wxCANCEL
)
2527 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2528 m_labels
[Btn_No
]->GetValue(),
2529 m_labels
[Btn_Cancel
]->GetValue());
2533 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2534 m_labels
[Btn_No
]->GetValue());
2539 if ( style
& wxCANCEL
)
2541 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2542 m_labels
[Btn_Cancel
]->GetValue());
2546 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2553 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2555 EndModal(wxID_CANCEL
);
2558 #endif // USE_SETTINGS_DIALOG
2562 // ----------------------------------------------------------------------------
2563 // custom log target
2564 // ----------------------------------------------------------------------------
2566 class MyLogGui
: public wxLogGui
2569 virtual void DoShowSingleLogMessage(const wxString
& message
,
2570 const wxString
& title
,
2573 wxMessageDialog
dlg(NULL
, message
, title
,
2574 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2575 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2576 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2581 wxLog
*MyAppTraits::CreateLogTarget()
2583 return new MyLogGui
;