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 // call this instead of ShowModal() to update order and labels array in
873 // case the dialog was not cancelled
876 if ( ShowModal() == wxID_CANCEL
)
879 m_order
= GetOrder();
885 void OnSelChange(wxCommandEvent
& event
)
887 DoUpdateExtraControls(event
.GetInt());
890 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
892 event
.Enable( CanRename() );
895 void OnRename(wxCommandEvent
& WXUNUSED(event
))
900 m_labels
[m_sel
] = m_text
->GetValue();
901 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
904 bool CanRename() const
906 // only allow renaming if the user modified the currently selected item
907 // text (which presupposes that we do have a current item)
908 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
911 void DoUpdateExtraControls(int sel
)
915 if ( m_sel
== wxNOT_FOUND
)
917 m_labelOrig
->SetLabel("<no selection>");
921 else // have valid item
923 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
925 m_text
->SetValue(m_labels
[m_sel
]);
930 wxArrayString
& m_labels
,
934 wxStaticText
*m_labelOrig
;
937 DECLARE_EVENT_TABLE()
938 DECLARE_NO_COPY_CLASS(MyRearrangeDialog
)
941 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
942 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
943 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
944 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
945 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
948 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
950 // the arrays are static so that we preserve the items order between calls
952 static wxArrayInt s_order
;
953 static wxArrayString s_labels
,
956 // initialize them on the first call
957 if ( s_labelsOrig
.empty() )
959 static const struct ItemInfo
962 const char *labelOrig
;
966 { "File name", "Name", 0 },
967 { "File type", "Ext", 1 },
968 { "Size", "Size", 2 },
969 { "Creation time", "Ctime", ~3 }, // negated so hidden
970 { "Last accessed", "Atime", ~4 },
971 { "Last modified", "Mtime", 5 },
974 s_order
.reserve(WXSIZEOF(items
));
975 s_labels
.reserve(WXSIZEOF(items
));
976 s_labelsOrig
.reserve(WXSIZEOF(items
));
977 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
979 const ItemInfo
& item
= items
[n
];
980 s_order
.push_back(item
.order
);
981 s_labels
.push_back(item
.label
);
982 s_labelsOrig
.push_back(item
.labelOrig
);
986 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
987 if ( !dlg
.Rearrange() )
991 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
993 columns
+= wxString::Format("\n %u: ", n
);
994 int idx
= s_order
[n
];
997 columns
+= "[hidden] ";
1001 columns
+= s_labels
[idx
];
1002 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1004 columns
+= wxString::Format(" (original label: \"%s\")",
1009 wxLogMessage("The columns order now is:%s", columns
);
1014 // panel with custom controls for file dialog
1015 class MyExtraPanel
: public wxPanel
1018 MyExtraPanel(wxWindow
*parent
);
1019 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1020 wxString
GetInfo() const
1022 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1029 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1032 m_btn
= new wxButton(this, -1, _T("Custom Button"));
1033 m_btn
->Enable(false);
1034 m_cb
= new wxCheckBox(this, -1, _T("Enable Custom Button"));
1035 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1036 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1037 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1038 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1039 sizerTop
->AddStretchSpacer();
1040 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1041 SetSizerAndFit(sizerTop
);
1044 // a static method can be used instead of a function with most of compilers
1045 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1047 return new MyExtraPanel(parent
);
1050 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1055 _T("Testing open file dialog"),
1059 _T("C++ files (*.cpp)|*.cpp")
1061 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
1065 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1066 dialog
.CentreOnParent();
1067 dialog
.SetDirectory(wxGetHomeDir());
1069 if (dialog
.ShowModal() == wxID_OK
)
1072 wxWindow
* const extra
= dialog
.GetExtraControl();
1073 info
.Printf(_T("Full file name: %s\n")
1076 _T("Custom window: %s"),
1077 dialog
.GetPath().c_str(),
1078 dialog
.GetDirectory().c_str(),
1079 dialog
.GetFilename().c_str(),
1080 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1081 : wxString("None"));
1082 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
1083 dialog2
.ShowModal();
1087 // this shows how to take advantage of specifying a default extension in the
1088 // call to wxFileSelector: it is remembered after each new call and the next
1089 // one will use it by default
1090 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1092 static wxString s_extDef
;
1093 wxString path
= wxFileSelector(
1094 _T("Select the file to load"),
1095 wxEmptyString
, wxEmptyString
,
1099 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1100 wxFileSelectorDefaultWildcardStr
,
1101 wxFileSelectorDefaultWildcardStr
1103 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1110 // it is just a sample, would use wxSplitPath in real program
1111 s_extDef
= path
.AfterLast(_T('.'));
1113 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
1117 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1119 wxString wildcards
=
1121 _T("C++ files (*.cpp)|*.cpp");
1125 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1126 wxFileSelectorDefaultWildcardStr
,
1127 wxFileSelectorDefaultWildcardStr
1130 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
1131 wxEmptyString
, wxEmptyString
, wildcards
,
1132 wxFD_OPEN
|wxFD_MULTIPLE
);
1134 if (dialog
.ShowModal() == wxID_OK
)
1136 wxArrayString paths
, filenames
;
1138 dialog
.GetPaths(paths
);
1139 dialog
.GetFilenames(filenames
);
1142 size_t count
= paths
.GetCount();
1143 for ( size_t n
= 0; n
< count
; n
++ )
1145 s
.Printf(_T("File %d: %s (%s)\n"),
1146 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1150 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
1153 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
1154 dialog2
.ShowModal();
1158 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1160 wxFileDialog
dialog(this,
1161 _T("Testing save file dialog"),
1164 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1165 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1167 dialog
.SetFilterIndex(1);
1169 if (dialog
.ShowModal() == wxID_OK
)
1171 wxLogMessage(_T("%s, filter %d"),
1172 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1175 #endif // wxUSE_FILEDLG
1177 #if USE_FILEDLG_GENERIC
1178 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1180 wxGenericFileDialog dialog
1183 _T("Testing open file dialog"),
1186 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
1189 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1190 dialog
.SetDirectory(wxGetHomeDir());
1192 if (dialog
.ShowModal() == wxID_OK
)
1195 info
.Printf(_T("Full file name: %s\n")
1198 dialog
.GetPath().c_str(),
1199 dialog
.GetDirectory().c_str(),
1200 dialog
.GetFilename().c_str());
1201 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
1202 dialog2
.ShowModal();
1206 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1208 // On PocketPC you can disable OK-only dialogs policy using system option
1209 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1210 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1212 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1213 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
1214 wxEmptyString
, wxEmptyString
, wildcards
,
1217 if (dialog
.ShowModal() == wxID_OK
)
1219 wxArrayString paths
, filenames
;
1221 dialog
.GetPaths(paths
);
1222 dialog
.GetFilenames(filenames
);
1225 size_t count
= paths
.GetCount();
1226 for ( size_t n
= 0; n
< count
; n
++ )
1228 s
.Printf(_T("File %d: %s (%s)\n"),
1229 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1233 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
1236 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
1237 dialog2
.ShowModal();
1240 // restore system option
1241 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1244 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1246 wxGenericFileDialog
dialog(this,
1247 _T("Testing save file dialog"),
1250 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1251 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1253 dialog
.SetFilterIndex(1);
1255 if (dialog
.ShowModal() == wxID_OK
)
1257 wxLogMessage(_T("%s, filter %d"),
1258 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1261 #endif // USE_FILEDLG_GENERIC
1264 void MyFrame::DoDirChoose(int style
)
1266 // pass some initial dir to wxDirDialog
1268 wxGetHomeDir(&dirHome
);
1270 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
1272 if (dialog
.ShowModal() == wxID_OK
)
1274 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
1278 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1280 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1283 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1285 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1287 #endif // wxUSE_DIRDLG
1289 #if USE_DIRDLG_GENERIC
1290 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1292 // pass some initial dir to wxDirDialog
1294 wxGetHomeDir(&dirHome
);
1296 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
1298 if (dialog
.ShowModal() == wxID_OK
)
1300 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
1301 dialog2
.ShowModal();
1304 #endif // USE_DIRDLG_GENERIC
1306 #if USE_MODAL_PRESENTATION
1307 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1309 MyModalDialog
dlg(this);
1312 #endif // USE_MODAL_PRESENTATION
1314 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1316 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1322 m_dialog
= new MyModelessDialog(this);
1325 m_dialog
->Show(true);
1329 // If m_dialog is NULL, then possibly the system
1330 // didn't report the checked menu item status correctly.
1331 // It should be true just after the menu item was selected,
1332 // if there was no modeless dialog yet.
1334 wxASSERT( m_dialog
!= NULL
);
1340 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1342 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1343 wxDefaultPosition
, wxSize(200, 100));
1344 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1345 dlg
.CentreOnScreen();
1349 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1351 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1352 wxDefaultPosition
, wxSize(200, 100));
1353 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1354 dlg
.CentreOnParent();
1358 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1360 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, _T("Mini frame"),
1361 wxDefaultPosition
, wxSize(300, 100),
1362 wxCAPTION
| wxCLOSE_BOX
);
1363 new wxStaticText(frame
,
1365 _T("Mini frames have slightly different appearance"),
1367 new wxStaticText(frame
,
1369 _T("from the normal frames but that's the only difference."),
1372 frame
->CentreOnParent();
1376 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1378 wxDialog
dlg(this, wxID_ANY
, _T("Dialog staying on top of other windows"),
1379 wxDefaultPosition
, wxSize(300, 100),
1380 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1381 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1385 #if wxUSE_STARTUP_TIPS
1386 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1388 static size_t s_index
= (size_t)-1;
1390 if ( s_index
== (size_t)-1 )
1394 // this is completely bogus, we don't know how many lines are there
1395 // in the file, but who cares, it's a demo only...
1396 s_index
= rand() % 5;
1399 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1401 bool showAtStartup
= wxShowTip(this, tipProvider
);
1403 if ( showAtStartup
)
1405 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1406 wxOK
| wxICON_INFORMATION
, this);
1409 s_index
= tipProvider
->GetCurrentTip();
1412 #endif // wxUSE_STARTUP_TIPS
1414 #if USE_SETTINGS_DIALOG
1415 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1417 SettingsDialog
dialog(this, event
.GetId());
1420 #endif // USE_SETTINGS_DIALOG
1422 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1424 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1428 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1431 #if wxUSE_NOTIFICATION_MESSAGE
1433 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1435 if ( !wxNotificationMessage
1437 "Automatic Notification",
1438 "Nothing important has happened\n"
1439 "this notification will disappear soon."
1442 wxLogStatus("Failed to show notification message");
1446 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1450 m_notifMsg
= new wxNotificationMessage
1452 "wxWidgets Manual Notification",
1453 "You can hide this notification from the menu",
1458 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1460 wxLogStatus("Failed to show manual notification message");
1464 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1468 if ( !m_notifMsg
->Close() )
1469 wxLogStatus("Failed to hide manual notification message");
1473 #endif // wxUSE_NOTIFICATION_MESSAGE
1475 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1477 StdButtonSizerDialog
dialog(this);
1481 // TestDefaultAction
1483 #define ID_CATCH_LISTBOX_DCLICK 100
1484 #define ID_LISTBOX 101
1486 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1487 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1488 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1491 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1492 wxDialog( parent
, -1, "Test default action" )
1494 m_catchListBoxDClick
= false;
1496 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1498 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1500 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1501 listbox
->Append( "String 1" );
1502 listbox
->Append( "String 2" );
1503 listbox
->Append( "String 3" );
1504 listbox
->Append( "String 4" );
1505 grid_sizer
->Add( listbox
);
1507 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1509 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1510 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1512 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1513 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1515 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1517 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1519 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1521 SetSizerAndFit( main_sizer
);
1524 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1526 event
.Skip( !m_catchListBoxDClick
);
1529 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1531 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1534 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1536 TestDefaultActionDialog
dialog( this );
1540 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1545 #if wxUSE_PROGRESSDLG
1547 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1549 static const int max
= 100;
1551 wxProgressDialog
dialog(_T("Progress dialog example"),
1552 _T("An informative message"),
1558 // wxPD_AUTO_HIDE | -- try this as well
1560 wxPD_ESTIMATED_TIME
|
1562 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1566 for ( int i
= 0; i
<= max
; i
++ )
1572 // test both modes of wxProgressDialog behaviour: start in
1573 // indeterminate mode but switch to the determinate one later
1574 const bool determinate
= i
> max
/2;
1578 msg
= _T("That's all, folks!");
1580 else if ( !determinate
)
1582 msg
= _T("Testing indeterminate mode");
1584 else if ( determinate
)
1586 msg
= _T("Now in standard determinate mode");
1589 // will be set to true if "Skip" button was pressed
1593 cont
= dialog
.Update(i
, msg
, &skip
);
1597 cont
= dialog
.Pulse(msg
, &skip
);
1600 // each skip will move progress about quarter forward
1606 if ( wxMessageBox(_T("Do you really want to cancel?"),
1607 _T("Progress dialog question"), // caption
1608 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1618 wxLogStatus(wxT("Progress dialog aborted!"));
1622 wxLogStatus(wxT("Countdown from %d finished"), max
);
1626 #endif // wxUSE_PROGRESSDLG
1630 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1632 info
.SetName(_T("Dialogs Sample"));
1633 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1634 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1635 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1636 info
.AddDeveloper(_T("Vadim Zeitlin"));
1639 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1641 InitAboutInfoMinimal(info
);
1643 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1646 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1648 InitAboutInfoWebsite(info
);
1650 // we can add a second developer
1651 info
.AddDeveloper(_T("A.N. Other"));
1653 // or we can add several persons at once like this
1654 static const wxChar
*docwriters
[] =
1656 _T("First D. Writer"),
1660 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1661 info
.SetLicence(wxString::FromAscii(
1662 " wxWindows Library Licence, Version 3.1\n"
1663 " ======================================\n"
1665 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1667 " Everyone is permitted to copy and distribute verbatim copies\n"
1668 " of this licence document, but changing it is not allowed.\n"
1670 " WXWINDOWS LIBRARY LICENCE\n"
1671 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1673 " ...and so on and so forth...\n"
1676 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1679 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1681 wxAboutDialogInfo info
;
1682 InitAboutInfoMinimal(info
);
1687 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1689 wxAboutDialogInfo info
;
1690 InitAboutInfoWebsite(info
);
1695 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1697 wxAboutDialogInfo info
;
1698 InitAboutInfoAll(info
);
1703 // a trivial example of a custom dialog class
1704 class MyAboutDialog
: public wxGenericAboutDialog
1707 MyAboutDialog(const wxAboutDialogInfo
& info
)
1712 // add some custom controls
1713 virtual void DoAddCustomControls()
1715 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1716 AddText(_T("Some custom text"));
1717 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1721 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1723 wxAboutDialogInfo info
;
1724 InitAboutInfoAll(info
);
1726 MyAboutDialog
dlg(info
);
1730 #endif // wxUSE_ABOUTDLG
1734 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1736 wxWindowDisabler disableAll
;
1738 wxBusyInfo
info(_T("Working, please wait..."), this);
1740 for ( int i
= 0; i
< 18; i
++ )
1750 #endif // wxUSE_BUSYINFO
1752 #if wxUSE_FINDREPLDLG
1754 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1758 delete m_dlgReplace
;
1759 m_dlgReplace
= NULL
;
1763 m_dlgReplace
= new wxFindReplaceDialog
1767 _T("Find and replace dialog"),
1771 m_dlgReplace
->Show(true);
1775 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1784 m_dlgFind
= new wxFindReplaceDialog
1793 m_dlgFind
->Show(true);
1797 static wxString
DecodeFindDialogEventFlags(int flags
)
1800 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1801 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1802 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1803 << _T("case sensitive");
1808 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1810 wxEventType type
= event
.GetEventType();
1812 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1814 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1815 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1816 event
.GetFindString().c_str(),
1817 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1819 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1820 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1822 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1823 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1824 event
.GetFindString().c_str(),
1825 event
.GetReplaceString().c_str(),
1826 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1828 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1830 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1834 if ( dlg
== m_dlgFind
)
1837 idMenu
= DIALOGS_FIND
;
1840 else if ( dlg
== m_dlgReplace
)
1842 txt
= _T("Replace");
1843 idMenu
= DIALOGS_REPLACE
;
1844 m_dlgReplace
= NULL
;
1848 txt
= _T("Unknown");
1851 wxFAIL_MSG( _T("unexpected event") );
1854 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1856 if ( idMenu
!= wxID_ANY
)
1858 GetMenuBar()->Check(idMenu
, false);
1865 wxLogError(wxT("Unknown find dialog event!"));
1869 #endif // wxUSE_FINDREPLDLG
1871 // ----------------------------------------------------------------------------
1873 // ----------------------------------------------------------------------------
1875 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1878 dc
.SetFont(wxGetApp().m_canvasFont
);
1879 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1880 dc
.SetBackgroundMode(wxTRANSPARENT
);
1882 _T("wxWidgets common dialogs")
1883 #if !defined(__SMARTPHONE__)
1884 _T(" test application")
1889 #if USE_MODAL_PRESENTATION
1891 // ----------------------------------------------------------------------------
1893 // ----------------------------------------------------------------------------
1895 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1896 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1898 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1900 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1901 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1904 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1905 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1907 SetSizerAndFit(sizerTop
);
1910 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1912 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1913 wxOK
| wxICON_INFORMATION
, this);
1916 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1918 if ( event
.CanVeto() )
1920 wxMessageBox(_T("Use the menu item to close this dialog"),
1921 _T("Modeless dialog"),
1922 wxOK
| wxICON_INFORMATION
, this);
1928 // ----------------------------------------------------------------------------
1930 // ----------------------------------------------------------------------------
1932 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1933 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1935 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1937 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1938 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1939 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1941 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1942 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1943 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1944 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1945 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1947 SetSizerAndFit(sizerTop
);
1949 m_btnModal
->SetFocus();
1950 m_btnModal
->SetDefault();
1953 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1955 if ( event
.GetEventObject() == m_btnDelete
)
1960 m_btnDelete
->Disable();
1962 else if ( event
.GetEventObject() == m_btnModal
)
1965 wxGetTextFromUser(_T("Dummy prompt"),
1966 _T("Modal dialog called from dialog"),
1967 wxEmptyString
, this);
1969 wxMessageBox(_T("Modal dialog called from dialog"));
1970 #endif // wxUSE_TEXTDLG
1972 else if ( event
.GetEventObject() == m_btnModeless
)
1974 (new MyModelessDialog(this))->Show();
1982 #endif // USE_MODAL_PRESENTATION
1984 // ----------------------------------------------------------------------------
1985 // StdButtonSizerDialog
1986 // ----------------------------------------------------------------------------
1988 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1989 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1990 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1991 m_buttonsSizer(NULL
)
1993 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1995 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1996 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1998 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2000 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2002 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2003 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2005 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2007 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2009 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2011 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2012 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2014 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2016 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2017 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2018 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2020 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2022 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2023 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2025 sizer
->Add(sizerInside1
, 0, 0, 0);
2026 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2027 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2028 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2030 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2031 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2033 sizer
->Add(sizerInside2
, 0, 0, 0);
2034 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2035 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2036 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2038 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2040 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2041 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2042 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2044 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2046 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2048 EnableDisableControls();
2050 SetSizerAndFit(sizerTop
);
2056 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2060 m_buttonsSizer
->DeleteWindows();
2061 GetSizer()->Remove(m_buttonsSizer
);
2064 EnableDisableControls();
2067 unsigned long numButtons
= 0;
2069 if (m_chkboxAffirmativeButton
->IsChecked())
2071 if (m_radiobtnOk
->GetValue())
2076 else if (m_radiobtnYes
->GetValue())
2083 if (m_chkboxDismissButton
->IsChecked())
2085 if (m_radiobtnCancel
->GetValue())
2091 else if (m_radiobtnClose
->GetValue())
2099 if (m_chkboxApply
->IsChecked())
2105 if (m_chkboxNo
->IsChecked())
2111 if (m_chkboxHelp
->IsChecked())
2117 if (m_chkboxNoDefault
->IsChecked())
2119 flags
|= wxNO_DEFAULT
;
2122 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2123 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2126 GetSizer()->SetSizeHints(this);
2129 void StdButtonSizerDialog::EnableDisableControls()
2131 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2133 m_radiobtnOk
->Enable(affButtonEnabled
);
2134 m_radiobtnYes
->Enable(affButtonEnabled
);
2136 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2138 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2139 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2142 #if USE_SETTINGS_DIALOG
2143 // ----------------------------------------------------------------------------
2145 // ----------------------------------------------------------------------------
2147 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2149 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2152 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2154 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2159 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2160 int resizeBorder
= wxRESIZE_BORDER
;
2168 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2169 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2170 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2172 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2174 SetSheetStyle(sheetStyle
);
2175 SetSheetInnerBorder(0);
2176 SetSheetOuterBorder(0);
2178 // create a dummy image list with a few icons
2179 const wxSize
imageSize(32, 32);
2181 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2183 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2185 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2187 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2189 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2194 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2195 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2198 // If using a toolbook, also follow Mac style and don't create buttons
2200 CreateButtons(wxOK
| wxCANCEL
|
2201 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2204 wxBookCtrlBase
* notebook
= GetBookCtrl();
2205 notebook
->SetImageList(m_imageList
);
2207 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2208 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2210 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2211 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2216 SettingsDialog::~SettingsDialog()
2221 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2223 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2225 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2226 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2230 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2231 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2232 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2233 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2237 wxString autoSaveLabel
= _("&Auto-save every");
2238 wxString minsLabel
= _("mins");
2240 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2241 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2244 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2245 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2248 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2250 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2252 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2253 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2257 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2258 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2259 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2260 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2262 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2264 panel
->SetSizerAndFit(topSizer
);
2269 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2271 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2273 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2274 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2276 //// PROJECT OR GLOBAL
2277 wxString globalOrProjectChoices
[2];
2278 globalOrProjectChoices
[0] = _("&New projects");
2279 globalOrProjectChoices
[1] = _("&This project");
2281 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2282 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2283 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2285 projectOrGlobal
->SetSelection(0);
2287 //// BACKGROUND STYLE
2288 wxArrayString backgroundStyleChoices
;
2289 backgroundStyleChoices
.Add(wxT("Colour"));
2290 backgroundStyleChoices
.Add(wxT("Image"));
2291 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2293 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2294 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2296 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2298 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2300 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2301 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2302 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2304 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2307 //// FONT SIZE SELECTION
2309 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2310 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2312 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2313 wxSize(80, wxDefaultCoord
));
2314 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2316 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2319 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2320 topSizer
->AddSpacer(5);
2322 panel
->SetSizerAndFit(topSizer
);
2327 // ----------------------------------------------------------------------------
2328 // TestMessageBoxDialog
2329 // ----------------------------------------------------------------------------
2332 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2337 { wxCANCEL
, "&Cancel" },
2340 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2341 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2342 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2345 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2346 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2347 wxDefaultPosition
, wxDefaultSize
,
2348 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2350 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2352 // this sizer allows to configure the messages shown in the message box
2354 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2355 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2356 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2357 wxDefaultPosition
, wxDefaultSize
,
2359 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2361 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2362 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2363 wxDefaultPosition
, wxDefaultSize
,
2365 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2367 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2370 // this one is for configuring the buttons
2371 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2372 sizerBtns
->AddGrowableCol(1);
2374 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2375 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2377 for ( int n
= 0; n
< Btn_Max
; n
++ )
2379 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2380 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2382 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2383 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2385 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2386 wxUpdateUIEventHandler(
2387 TestMessageBoxDialog::OnUpdateLabelUI
),
2393 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2394 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2395 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2399 const wxString icons
[] = {
2400 "&Information", "&Question", "&Warning", "&Error"
2403 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icon:",
2404 wxDefaultPosition
, wxDefaultSize
,
2405 WXSIZEOF(icons
), icons
);
2406 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2409 // miscellaneous other stuff
2411 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2413 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2414 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2415 wxUpdateUIEventHandler(
2416 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2419 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2421 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2422 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2424 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2426 // finally buttons to show the resulting message box and close this dialog
2427 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2428 wxSizerFlags().Right().Border());
2430 SetSizerAndFit(sizerTop
);
2432 m_buttons
[Btn_Ok
]->SetValue(true);
2435 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2437 for ( int n
= 0; n
< Btn_Max
; n
++ )
2439 if ( event
.GetEventObject() == m_labels
[n
] )
2441 event
.Enable( m_buttons
[n
]->IsChecked() );
2446 wxFAIL_MSG( "called for unknown label" );
2449 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2451 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2454 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2458 for ( int n
= 0; n
< Btn_Max
; n
++ )
2460 if ( m_buttons
[n
]->IsChecked() )
2461 style
|= ms_btnInfo
[n
].flag
;
2464 switch ( m_icons
->GetSelection() )
2466 case 0: style
|= wxICON_INFORMATION
; break;
2467 case 1: style
|= wxICON_QUESTION
; break;
2468 case 2: style
|= wxICON_WARNING
; break;
2469 case 3: style
|= wxICON_ERROR
; break;
2472 if ( m_chkCentre
->IsChecked() )
2475 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2476 style
|= wxNO_DEFAULT
;
2479 wxMessageDialog
dlg(this, m_textMsg
->GetValue(), "Test Message Box",
2481 if ( !m_textExtMsg
->IsEmpty() )
2482 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2484 if ( style
& wxYES_NO
)
2486 if ( style
& wxCANCEL
)
2488 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2489 m_labels
[Btn_No
]->GetValue(),
2490 m_labels
[Btn_Cancel
]->GetValue());
2494 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2495 m_labels
[Btn_No
]->GetValue());
2500 if ( style
& wxCANCEL
)
2502 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2503 m_labels
[Btn_Cancel
]->GetValue());
2507 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2514 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2516 EndModal(wxID_CANCEL
);
2519 #endif // USE_SETTINGS_DIALOG
2523 // ----------------------------------------------------------------------------
2524 // custom log target
2525 // ----------------------------------------------------------------------------
2527 class MyLogGui
: public wxLogGui
2530 virtual void DoShowSingleLogMessage(const wxString
& message
,
2531 const wxString
& title
,
2534 wxMessageDialog
dlg(NULL
, message
, title
,
2535 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2536 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2537 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2542 wxLog
*MyAppTraits::CreateLogTarget()
2544 return new MyLogGui
;