1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustements for conditional building + new menu
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "../sample.xpm"
25 #include "wx/apptrait.h"
26 #include "wx/datetime.h"
28 #include "wx/bookctrl.h"
29 #include "wx/artprov.h"
30 #include "wx/imaglist.h"
31 #include "wx/minifram.h"
32 #include "wx/sysopt.h"
33 #include "wx/notifmsg.h"
36 #include "wx/colordlg.h"
37 #endif // wxUSE_COLOURDLG
40 #include "wx/choicdlg.h"
41 #endif // wxUSE_CHOICEDLG
43 #include "wx/rearrangectrl.h"
45 #if wxUSE_STARTUP_TIPS
46 #include "wx/tipdlg.h"
47 #endif // wxUSE_STARTUP_TIPS
50 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
51 #include "wx/datetime.h" // wxDateTime
54 #include "wx/progdlg.h"
55 #endif // wxUSE_PROGRESSDLG
58 #include "wx/aboutdlg.h"
60 // these headers are only needed for custom about dialog
61 #include "wx/statline.h"
62 #include "wx/generic/aboutdlgg.h"
63 #endif // wxUSE_ABOUTDLG
66 #include "wx/busyinfo.h"
67 #endif // wxUSE_BUSYINFO
70 #include "wx/numdlg.h"
71 #endif // wxUSE_NUMBERDLG
74 #include "wx/filedlg.h"
75 #endif // wxUSE_FILEDLG
78 #include "wx/dirdlg.h"
79 #endif // wxUSE_DIRDLG
82 #include "wx/fontdlg.h"
83 #endif // wxUSE_FONTDLG
86 #include "wx/fdrepdlg.h"
87 #endif // wxUSE_FINDREPLDLG
89 #include "wx/spinctrl.h"
90 #include "wx/propdlg.h"
94 #if USE_COLOURDLG_GENERIC
95 #include "wx/generic/colrdlgg.h"
96 #endif // USE_COLOURDLG_GENERIC
98 #if USE_DIRDLG_GENERIC
99 #include "wx/generic/dirdlgg.h"
100 #endif // USE_DIRDLG_GENERIC
102 #if USE_FILEDLG_GENERIC
103 #include "wx/generic/filedlgg.h"
104 #endif // USE_FILEDLG_GENERIC
106 #if USE_FONTDLG_GENERIC
107 #include "wx/generic/fontdlgg.h"
108 #endif // USE_FONTDLG_GENERIC
112 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
113 EVT_PAINT(MyCanvas::OnPaint
)
118 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
120 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
121 EVT_MENU(DIALOGS_MESSAGE_DIALOG
, MyFrame::MessageBoxDialog
)
122 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
123 #endif // wxUSE_MSGDLG
125 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
126 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
127 #endif // wxUSE_COLOURDLG
130 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
131 #endif // wxUSE_FONTDLG
134 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
135 #endif // wxUSE_LOG_DIALOG
138 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
139 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
140 #endif // wxUSE_TEXTDLG
143 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
144 #endif // wxUSE_NUMBERDLG
147 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
148 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
149 #endif // wxUSE_CHOICEDLG
151 #if wxUSE_REARRANGECTRL
152 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
153 #endif // wxUSE_REARRANGECTRL
156 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
157 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
158 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
159 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
160 #endif // wxUSE_FILEDLG
162 #if USE_FILEDLG_GENERIC
163 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
164 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
165 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
166 #endif // USE_FILEDLG_GENERIC
169 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
170 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
171 #endif // wxUSE_DIRDLG
173 #if USE_MODAL_PRESENTATION
174 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
175 #endif // USE_MODAL_PRESENTATION
176 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
177 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
178 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
180 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
181 #endif // wxUSE_MINIFRAME
182 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
184 #if wxUSE_STARTUP_TIPS
185 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
186 #endif // wxUSE_STARTUP_TIPS
188 #if USE_FONTDLG_GENERIC
189 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
190 #endif // USE_FONTDLG_GENERIC
192 #if USE_DIRDLG_GENERIC
193 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
194 #endif // wxMSW || wxMAC
196 #if USE_COLOURDLG_GENERIC
197 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
198 #endif // USE_COLOURDLG_GENERIC
200 #if wxUSE_PROGRESSDLG
201 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
202 #endif // wxUSE_PROGRESSDLG
205 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
206 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
207 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
208 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
209 #endif // wxUSE_ABOUTDLG
212 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
213 #endif // wxUSE_BUSYINFO
215 #if wxUSE_FINDREPLDLG
216 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
217 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
219 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
220 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
221 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
222 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
223 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
224 #endif // wxUSE_FINDREPLDLG
226 #if USE_SETTINGS_DIALOG
227 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
228 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
229 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
230 #endif // USE_SETTINGS_DIALOG
232 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
233 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
235 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
236 #if wxUSE_NOTIFICATION_MESSAGE
237 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
238 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
239 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
240 #endif // wxUSE_NOTIFICATION_MESSAGE
242 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
245 #if USE_MODAL_PRESENTATION
247 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
248 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
251 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
252 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
253 EVT_CLOSE(MyModelessDialog::OnClose
)
256 #endif // USE_MODAL_PRESENTATION
258 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
259 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
260 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
263 // `Main program' equivalent, creating windows and returning main app frame
266 if ( !wxApp::OnInit() )
270 wxInitAllImageHandlers();
273 m_canvasTextColour
= *wxBLACK
;
274 m_canvasFont
= *wxNORMAL_FONT
;
276 // Create the main frame window
277 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, wxT("wxWidgets dialogs example"));
280 wxMenu
*menuDlg
= new wxMenu
;
282 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
283 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
286 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
288 wxMenu
*choices_menu
= new wxMenu
;
291 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
292 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
293 #endif // wxUSE_COLOURDLG
296 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
297 #endif // wxUSE_FONTDLG
300 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
301 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
302 #endif // wxUSE_CHOICEDLG
304 #if wxUSE_REARRANGECTRL
305 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
306 #endif // wxUSE_REARRANGECTRL
308 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
309 choices_menu
->AppendSeparator();
310 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
312 #if USE_COLOURDLG_GENERIC
313 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
314 #endif // USE_COLOURDLG_GENERIC
316 #if USE_FONTDLG_GENERIC
317 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
318 #endif // USE_FONTDLG_GENERIC
320 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
321 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
324 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
326 wxMenu
*entry_menu
= new wxMenu
;
329 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Text &entry\tCtrl-E"));
330 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
331 #endif // wxUSE_TEXTDLG
334 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
335 #endif // wxUSE_NUMBERDLG
337 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
339 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
344 wxMenu
*filedlg_menu
= new wxMenu
;
345 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
346 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
347 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
348 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
350 #if USE_FILEDLG_GENERIC
351 filedlg_menu
->AppendSeparator();
352 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
353 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
354 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
355 #endif // USE_FILEDLG_GENERIC
357 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
359 #endif // wxUSE_FILEDLG
362 wxMenu
*dir_menu
= new wxMenu
;
364 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
365 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
366 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
368 #if USE_DIRDLG_GENERIC
369 dir_menu
->AppendSeparator();
370 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
371 #endif // USE_DIRDLG_GENERIC
373 #endif // wxUSE_DIRDLG
376 #if wxUSE_STARTUP_TIPS || \
377 wxUSE_PROGRESSDLG || \
379 wxUSE_LOG_DIALOG || \
382 wxMenu
*info_menu
= new wxMenu
;
384 #if wxUSE_STARTUP_TIPS
385 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
386 #endif // wxUSE_STARTUP_TIPS
388 #if wxUSE_PROGRESSDLG
389 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
390 #endif // wxUSE_PROGRESSDLG
393 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
394 #endif // wxUSE_BUSYINFO
397 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
398 #endif // wxUSE_LOG_DIALOG
401 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
402 wxT("&wxWidgets information\tCtrl-I"));
403 #endif // wxUSE_MSGDLG
405 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
407 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
410 #if wxUSE_FINDREPLDLG
411 wxMenu
*find_menu
= new wxMenu
;
412 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
413 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
414 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
415 #endif // wxUSE_FINDREPLDLG
417 wxMenu
*dialogs_menu
= new wxMenu
;
418 #if USE_MODAL_PRESENTATION
419 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tCtrl-W"));
420 #endif // USE_MODAL_PRESENTATION
421 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tCtrl-Z"));
422 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
423 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
425 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
426 #endif // wxUSE_MINIFRAME
427 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
428 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
430 #if USE_SETTINGS_DIALOG
431 wxMenu
*sheet_menu
= new wxMenu
;
432 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
433 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
435 if (wxPlatformIs(wxPORT_MAC
))
436 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
439 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
442 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
443 #endif // USE_SETTINGS_DIALOG
445 wxMenu
*menuNotif
= new wxMenu
;
446 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
447 #if wxUSE_NOTIFICATION_MESSAGE
448 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
449 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
450 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
451 #endif // wxUSE_NOTIFICATION_MESSAGE
452 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
454 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
455 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
457 menuDlg
->AppendSeparator();
458 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
461 wxMenu
*menuHelp
= new wxMenu
;
462 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
463 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
464 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
465 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
466 #endif // wxUSE_ABOUTDLG
468 wxMenuBar
*menubar
= new wxMenuBar
;
469 menubar
->Append(menuDlg
, wxT("&Dialogs"));
471 menubar
->Append(menuHelp
, wxT("&Help"));
472 #endif // wxUSE_ABOUTDLG
474 frame
->SetMenuBar(menubar
);
476 frame
->Centre(wxBOTH
);
486 // My frame constructor
487 MyFrame::MyFrame(wxWindow
*parent
,
488 const wxString
& title
)
489 : wxFrame(parent
, wxID_ANY
, title
)
493 #if USE_MODAL_PRESENTATION
494 m_dialog
= (MyModelessDialog
*)NULL
;
495 #endif // USE_MODAL_PRESENTATION
497 #if wxUSE_FINDREPLDLG
503 m_clrData
.SetChooseFull(true);
504 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
506 unsigned char n
= i
*16;
507 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
509 #endif // wxUSE_COLOURDLG
511 #if wxUSE_NOTIFICATION_MESSAGE
513 #endif // wxUSE_NOTIFICATION_MESSAGE
517 #endif // wxUSE_STATUSBAR
519 m_canvas
= new MyCanvas(this);
524 #if wxUSE_NOTIFICATION_MESSAGE
526 #endif // wxUSE_NOTIFICATION_MESSAGE
531 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
533 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
535 wxColourDialog
dialog(this, &m_clrData
);
536 dialog
.SetTitle(_("Please choose the background colour"));
537 if ( dialog
.ShowModal() == wxID_OK
)
539 m_clrData
= dialog
.GetColourData();
540 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
541 m_canvas
->ClearBackground();
546 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
548 wxColour clr
= wxGetColourFromUser
551 wxGetApp().m_canvasTextColour
,
552 "Please choose the foreground colour"
556 wxGetApp().m_canvasTextColour
= clr
;
559 //else: dialog cancelled by user
562 #endif // wxUSE_COLOURDLG
565 #if USE_COLOURDLG_GENERIC
566 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
568 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
570 //FIXME:TODO:This has no effect...
571 m_clrData
.SetChooseFull(true);
573 for (int i
= 0; i
< 16; i
++)
576 (unsigned char)(i
*16),
577 (unsigned char)(i
*16),
578 (unsigned char)(i
*16)
580 m_clrData
.SetCustomColour(i
, colour
);
583 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
584 if (dialog
->ShowModal() == wxID_OK
)
586 m_clrData
= dialog
->GetColourData();
587 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
588 m_canvas
->ClearBackground();
593 #endif // USE_COLOURDLG_GENERIC
596 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
599 data
.SetInitialFont(wxGetApp().m_canvasFont
);
600 data
.SetColour(wxGetApp().m_canvasTextColour
);
602 // you might also do this:
604 // wxFontDialog dialog;
605 // if ( !dialog.Create(this, data) { ... error ... }
607 wxFontDialog
dialog(this, data
);
609 if (dialog
.ShowModal() == wxID_OK
)
611 wxFontData retData
= dialog
.GetFontData();
612 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
613 wxGetApp().m_canvasTextColour
= retData
.GetColour();
616 //else: cancelled by the user, don't change the font
618 #endif // wxUSE_FONTDLG
620 #if USE_FONTDLG_GENERIC
621 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
624 data
.SetInitialFont(wxGetApp().m_canvasFont
);
625 data
.SetColour(wxGetApp().m_canvasTextColour
);
627 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
628 if (dialog
->ShowModal() == wxID_OK
)
630 wxFontData retData
= dialog
->GetFontData();
631 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
632 wxGetApp().m_canvasTextColour
= retData
.GetColour();
637 #endif // USE_FONTDLG_GENERIC
640 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
642 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
643 // being flushed -- test it
646 wxLogMessage(wxT("This is some message - everything is ok so far."));
647 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
648 wxLogWarning(wxT("And then something went wrong!"));
650 // and if ~wxBusyCursor doesn't do it, then call it manually
654 wxLogError(wxT("Intermediary error handler decided to abort."));
655 wxLogError(wxT("The top level caller detected an unrecoverable error."));
657 wxLog::FlushActive();
659 wxLogMessage(wxT("And this is the same dialog but with only one message."));
661 #endif // wxUSE_LOG_DIALOG
664 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
666 wxMessageDialog
dialog(this,
667 "This is a message box\n"
668 "This is a long, long string to test out if the message box "
669 "is laid out properly.",
672 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
676 if ( dialog
.SetYesNoCancelLabels
683 extmsg
= "This platform supports custom button labels,\n"
684 "so you should see the descriptive labels below.";
688 extmsg
= "Custom button labels are not supported on this platform,\n"
689 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
691 dialog
.SetExtendedMessage(extmsg
);
693 switch ( dialog
.ShowModal() )
696 wxLogStatus(wxT("You pressed \"Yes\""));
700 wxLogStatus(wxT("You pressed \"No\""));
704 wxLogStatus(wxT("You pressed \"Cancel\""));
708 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
712 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
714 TestMessageBoxDialog
dlg(this);
718 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
720 ::wxInfoMessageBox(this);
722 #endif // wxUSE_MSGDLG
725 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
727 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
728 wxT("Even two rows of text."),
729 wxT("Enter a number:"), wxT("Numeric input test"),
736 msg
= wxT("Invalid number entered or dialog cancelled.");
741 msg
.Printf(wxT("You've entered %lu"), res
);
742 icon
= wxICON_INFORMATION
;
745 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
747 #endif // wxUSE_NUMBERDLG
750 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
752 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
753 wxT("Password entry dialog"),
758 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
759 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
763 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
765 wxTextEntryDialog
dialog(this,
766 wxT("This is a small sample\n")
767 wxT("A long, long string to test out the text entrybox"),
768 wxT("Please enter a string"),
769 wxT("Default value"),
772 if (dialog
.ShowModal() == wxID_OK
)
774 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
777 #endif // wxUSE_TEXTDLG
780 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
782 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
784 wxSingleChoiceDialog
dialog(this,
785 wxT("This is a small sample\n")
786 wxT("A single-choice convenience dialog"),
787 wxT("Please select a value"),
788 WXSIZEOF(choices
), choices
);
790 dialog
.SetSelection(2);
792 if (dialog
.ShowModal() == wxID_OK
)
794 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
799 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
801 const wxString choices
[] =
803 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
804 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
805 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
808 wxArrayInt selections
;
809 const int count
= wxGetSelectedChoices(selections
,
810 wxT("This is a small sample\n")
811 wxT("A multi-choice convenience dialog"),
812 wxT("Please select a value"),
813 WXSIZEOF(choices
), choices
,
820 msg
= wxT("You did not select any items");
824 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
825 for ( int n
= 0; n
< count
; n
++ )
827 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
828 (unsigned)n
, (unsigned)selections
[n
],
829 choices
[selections
[n
]].c_str());
836 #endif // wxUSE_CHOICEDLG
838 #if wxUSE_REARRANGECTRL
839 // custom rearrange dialog: it adds the possibility to rename an item to the
840 // base class functionality
841 class MyRearrangeDialog
: public wxRearrangeDialog
844 MyRearrangeDialog(wxWindow
*parent
,
846 wxArrayString
& labels
,
847 wxArrayString
& labelsOrig
)
851 "Configure the columns shown:",
852 "wxRearrangeDialog example",
858 m_labelsOrig(labelsOrig
)
862 wxPanel
* const panel
= new wxPanel(this);
863 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
865 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
866 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
868 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
869 wxDefaultPosition
, wxDefaultSize
,
871 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
873 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
874 wxSizerFlags().Centre());
876 panel
->SetSizer(sizer
);
878 // call this first to ensure that the controls have a reasonable best
879 // size before they're added
880 DoUpdateExtraControls(GetList()->GetSelection());
882 AddExtraControls(panel
);
885 // another customization not directly supported by the dialog: add a
887 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
888 wxCHECK_RET( btnOk
, "no Ok button?" );
890 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
891 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
893 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
894 wxSizerFlags().Border(wxLEFT
));
897 // call this instead of ShowModal() to update order and labels array in
898 // case the dialog was not cancelled
901 switch ( ShowModal() )
907 m_order
= GetOrder();
911 // order already reset
919 void OnSelChange(wxCommandEvent
& event
)
921 DoUpdateExtraControls(event
.GetInt());
924 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
926 event
.Enable( CanRename() );
929 void OnRename(wxCommandEvent
& WXUNUSED(event
))
934 m_labels
[m_sel
] = m_text
->GetValue();
935 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
938 void OnReset(wxCommandEvent
& WXUNUSED(event
))
940 // in a real program we should probably ask if the user really wants to
941 // do this but here we just go ahead and reset all columns labels and
942 // their order without confirmation
943 const unsigned count
= m_order
.size();
944 for ( unsigned n
= 0; n
< count
; n
++ )
947 m_labels
[n
] = m_labelsOrig
[n
];
950 EndModal(wxID_RESET
);
953 bool CanRename() const
955 // only allow renaming if the user modified the currently selected item
956 // text (which presupposes that we do have a current item)
957 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
960 void DoUpdateExtraControls(int sel
)
964 if ( m_sel
== wxNOT_FOUND
)
966 m_labelOrig
->SetLabel("<no selection>");
970 else // have valid item
972 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
974 m_text
->SetValue(m_labels
[m_sel
]);
979 wxArrayString
& m_labels
,
983 wxStaticText
*m_labelOrig
;
986 DECLARE_EVENT_TABLE()
987 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
990 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
991 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
993 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
995 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
996 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
997 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
1000 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
1002 // the arrays are static so that we preserve the items order between calls
1004 static wxArrayInt s_order
;
1005 static wxArrayString s_labels
,
1008 // initialize them on the first call
1009 if ( s_labelsOrig
.empty() )
1011 static const struct ItemInfo
1014 const char *labelOrig
;
1018 { "File name", "Name", 0 },
1019 { "File type", "Ext", 1 },
1020 { "Size", "Size", 2 },
1021 { "Creation time", "Ctime", ~3 }, // negated so hidden
1022 { "Last accessed", "Atime", ~4 },
1023 { "Last modified", "Mtime", 5 },
1026 s_order
.reserve(WXSIZEOF(items
));
1027 s_labels
.reserve(WXSIZEOF(items
));
1028 s_labelsOrig
.reserve(WXSIZEOF(items
));
1029 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1031 const ItemInfo
& item
= items
[n
];
1032 s_order
.push_back(item
.order
);
1033 s_labels
.push_back(item
.label
);
1034 s_labelsOrig
.push_back(item
.labelOrig
);
1038 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1039 if ( !dlg
.Rearrange() )
1043 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1045 columns
+= wxString::Format("\n %u: ", n
);
1046 int idx
= s_order
[n
];
1049 columns
+= "[hidden] ";
1053 columns
+= s_labels
[idx
];
1054 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1056 columns
+= wxString::Format(" (original label: \"%s\")",
1061 wxLogMessage("The columns order now is:%s", columns
);
1063 #endif // wxUSE_REARRANGECTRL
1067 // panel with custom controls for file dialog
1068 class MyExtraPanel
: public wxPanel
1071 MyExtraPanel(wxWindow
*parent
);
1072 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1073 wxString
GetInfo() const
1075 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1082 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1085 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1086 m_btn
->Enable(false);
1087 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1088 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1089 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1090 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1091 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1092 sizerTop
->AddStretchSpacer();
1093 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1094 SetSizerAndFit(sizerTop
);
1097 // a static method can be used instead of a function with most of compilers
1098 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1100 return new MyExtraPanel(parent
);
1103 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1108 wxT("Testing open file dialog"),
1112 wxT("C++ files (*.cpp)|*.cpp")
1114 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1118 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1119 dialog
.CentreOnParent();
1120 dialog
.SetDirectory(wxGetHomeDir());
1122 if (dialog
.ShowModal() == wxID_OK
)
1125 wxWindow
* const extra
= dialog
.GetExtraControl();
1126 info
.Printf(wxT("Full file name: %s\n")
1129 wxT("Custom window: %s"),
1130 dialog
.GetPath().c_str(),
1131 dialog
.GetDirectory().c_str(),
1132 dialog
.GetFilename().c_str(),
1133 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1134 : wxString("None"));
1135 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1136 dialog2
.ShowModal();
1140 // this shows how to take advantage of specifying a default extension in the
1141 // call to wxFileSelector: it is remembered after each new call and the next
1142 // one will use it by default
1143 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1145 static wxString s_extDef
;
1146 wxString path
= wxFileSelector(
1147 wxT("Select the file to load"),
1148 wxEmptyString
, wxEmptyString
,
1152 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1153 wxFileSelectorDefaultWildcardStr
,
1154 wxFileSelectorDefaultWildcardStr
1156 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1163 // it is just a sample, would use wxSplitPath in real program
1164 s_extDef
= path
.AfterLast(wxT('.'));
1166 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1170 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1172 wxString wildcards
=
1174 wxT("C++ files (*.cpp)|*.cpp");
1178 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1179 wxFileSelectorDefaultWildcardStr
,
1180 wxFileSelectorDefaultWildcardStr
1183 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1184 wxEmptyString
, wxEmptyString
, wildcards
,
1185 wxFD_OPEN
|wxFD_MULTIPLE
);
1187 if (dialog
.ShowModal() == wxID_OK
)
1189 wxArrayString paths
, filenames
;
1191 dialog
.GetPaths(paths
);
1192 dialog
.GetFilenames(filenames
);
1195 size_t count
= paths
.GetCount();
1196 for ( size_t n
= 0; n
< count
; n
++ )
1198 s
.Printf(wxT("File %d: %s (%s)\n"),
1199 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1203 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1206 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1207 dialog2
.ShowModal();
1211 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1213 wxFileDialog
dialog(this,
1214 wxT("Testing save file dialog"),
1216 wxT("myletter.doc"),
1217 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1218 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1220 dialog
.SetFilterIndex(1);
1222 if (dialog
.ShowModal() == wxID_OK
)
1224 wxLogMessage(wxT("%s, filter %d"),
1225 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1228 #endif // wxUSE_FILEDLG
1230 #if USE_FILEDLG_GENERIC
1231 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1233 wxGenericFileDialog dialog
1236 wxT("Testing open file dialog"),
1239 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1242 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1243 dialog
.SetDirectory(wxGetHomeDir());
1245 if (dialog
.ShowModal() == wxID_OK
)
1248 info
.Printf(wxT("Full file name: %s\n")
1251 dialog
.GetPath().c_str(),
1252 dialog
.GetDirectory().c_str(),
1253 dialog
.GetFilename().c_str());
1254 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1255 dialog2
.ShowModal();
1259 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1261 // On PocketPC you can disable OK-only dialogs policy using system option
1262 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1263 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1265 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1266 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1267 wxEmptyString
, wxEmptyString
, wildcards
,
1270 if (dialog
.ShowModal() == wxID_OK
)
1272 wxArrayString paths
, filenames
;
1274 dialog
.GetPaths(paths
);
1275 dialog
.GetFilenames(filenames
);
1278 size_t count
= paths
.GetCount();
1279 for ( size_t n
= 0; n
< count
; n
++ )
1281 s
.Printf(wxT("File %d: %s (%s)\n"),
1282 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1286 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1289 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1290 dialog2
.ShowModal();
1293 // restore system option
1294 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1297 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1299 wxGenericFileDialog
dialog(this,
1300 wxT("Testing save file dialog"),
1302 wxT("myletter.doc"),
1303 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1304 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1306 dialog
.SetFilterIndex(1);
1308 if (dialog
.ShowModal() == wxID_OK
)
1310 wxLogMessage(wxT("%s, filter %d"),
1311 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1314 #endif // USE_FILEDLG_GENERIC
1317 void MyFrame::DoDirChoose(int style
)
1319 // pass some initial dir to wxDirDialog
1321 wxGetHomeDir(&dirHome
);
1323 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1325 if (dialog
.ShowModal() == wxID_OK
)
1327 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1331 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1333 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1336 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1338 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1340 #endif // wxUSE_DIRDLG
1342 #if USE_DIRDLG_GENERIC
1343 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1345 // pass some initial dir to wxDirDialog
1347 wxGetHomeDir(&dirHome
);
1349 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1351 if (dialog
.ShowModal() == wxID_OK
)
1353 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1354 dialog2
.ShowModal();
1357 #endif // USE_DIRDLG_GENERIC
1359 #if USE_MODAL_PRESENTATION
1360 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1362 MyModalDialog
dlg(this);
1365 #endif // USE_MODAL_PRESENTATION
1367 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1369 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1375 m_dialog
= new MyModelessDialog(this);
1378 m_dialog
->Show(true);
1382 // If m_dialog is NULL, then possibly the system
1383 // didn't report the checked menu item status correctly.
1384 // It should be true just after the menu item was selected,
1385 // if there was no modeless dialog yet.
1387 wxASSERT( m_dialog
!= NULL
);
1393 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1395 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1396 wxDefaultPosition
, wxSize(200, 100));
1397 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1398 dlg
.CentreOnScreen();
1402 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1404 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1405 wxDefaultPosition
, wxSize(200, 100));
1406 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1407 dlg
.CentreOnParent();
1412 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1414 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1415 wxDefaultPosition
, wxSize(300, 100),
1416 wxCAPTION
| wxCLOSE_BOX
);
1417 new wxStaticText(frame
,
1419 wxT("Mini frames have slightly different appearance"),
1421 new wxStaticText(frame
,
1423 wxT("from the normal frames but that's the only difference."),
1426 frame
->CentreOnParent();
1429 #endif // wxUSE_MINIFRAME
1431 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1433 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1434 wxDefaultPosition
, wxSize(300, 100),
1435 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1436 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1440 #if wxUSE_STARTUP_TIPS
1441 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1443 static size_t s_index
= (size_t)-1;
1445 if ( s_index
== (size_t)-1 )
1449 // this is completely bogus, we don't know how many lines are there
1450 // in the file, but who cares, it's a demo only...
1451 s_index
= rand() % 5;
1454 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1456 bool showAtStartup
= wxShowTip(this, tipProvider
);
1458 if ( showAtStartup
)
1460 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1461 wxOK
| wxICON_INFORMATION
, this);
1464 s_index
= tipProvider
->GetCurrentTip();
1467 #endif // wxUSE_STARTUP_TIPS
1469 #if USE_SETTINGS_DIALOG
1470 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1472 SettingsDialog
dialog(this, event
.GetId());
1475 #endif // USE_SETTINGS_DIALOG
1477 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1479 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1483 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1486 #if wxUSE_NOTIFICATION_MESSAGE
1488 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1490 if ( !wxNotificationMessage
1492 "Automatic Notification",
1493 "Nothing important has happened\n"
1494 "this notification will disappear soon."
1497 wxLogStatus("Failed to show notification message");
1501 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1505 m_notifMsg
= new wxNotificationMessage
1507 "wxWidgets Manual Notification",
1508 "You can hide this notification from the menu",
1513 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1515 wxLogStatus("Failed to show manual notification message");
1519 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1521 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1523 wxLogStatus("Failed to hide manual notification message");
1527 #endif // wxUSE_NOTIFICATION_MESSAGE
1529 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1531 StdButtonSizerDialog
dialog(this);
1535 // TestDefaultAction
1537 #define ID_CATCH_LISTBOX_DCLICK 100
1538 #define ID_LISTBOX 101
1540 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1541 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1542 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1545 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1546 wxDialog( parent
, -1, "Test default action" )
1548 m_catchListBoxDClick
= false;
1550 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1552 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1555 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1556 listbox
->Append( "String 1" );
1557 listbox
->Append( "String 2" );
1558 listbox
->Append( "String 3" );
1559 listbox
->Append( "String 4" );
1560 grid_sizer
->Add( listbox
);
1561 #endif // wxUSE_LISTBOX
1563 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1565 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1566 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1568 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1569 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1571 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1573 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1575 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1577 SetSizerAndFit( main_sizer
);
1580 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1582 event
.Skip( !m_catchListBoxDClick
);
1585 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1587 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1590 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1592 TestDefaultActionDialog
dialog( this );
1596 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1601 #if wxUSE_PROGRESSDLG
1603 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1605 static const int max
= 100;
1607 wxProgressDialog
dialog(wxT("Progress dialog example"),
1608 wxT("An informative message"),
1614 // wxPD_AUTO_HIDE | -- try this as well
1616 wxPD_ESTIMATED_TIME
|
1618 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1622 for ( int i
= 0; i
<= max
; i
++ )
1628 // test both modes of wxProgressDialog behaviour: start in
1629 // indeterminate mode but switch to the determinate one later
1630 const bool determinate
= i
> max
/2;
1634 msg
= wxT("That's all, folks!");
1636 else if ( !determinate
)
1638 msg
= wxT("Testing indeterminate mode");
1640 else if ( determinate
)
1642 msg
= wxT("Now in standard determinate mode");
1645 // will be set to true if "Skip" button was pressed
1649 cont
= dialog
.Update(i
, msg
, &skip
);
1653 cont
= dialog
.Pulse(msg
, &skip
);
1656 // each skip will move progress about quarter forward
1662 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1663 wxT("Progress dialog question"), // caption
1664 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1674 wxLogStatus(wxT("Progress dialog aborted!"));
1678 wxLogStatus(wxT("Countdown from %d finished"), max
);
1682 #endif // wxUSE_PROGRESSDLG
1686 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1688 info
.SetName(wxT("Dialogs Sample"));
1689 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
1693 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
1694 wxVERSION_NUM_DOT_STRING
1696 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1697 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1698 info
.AddDeveloper(wxT("Vadim Zeitlin"));
1701 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1703 InitAboutInfoMinimal(info
);
1705 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
1708 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1710 InitAboutInfoWebsite(info
);
1712 // we can add a second developer
1713 info
.AddDeveloper(wxT("A.N. Other"));
1715 // or we can add several persons at once like this
1716 static const wxChar
*docwriters
[] =
1718 wxT("First D. Writer"),
1722 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1723 info
.SetLicence(wxString::FromAscii(
1724 " wxWindows Library Licence, Version 3.1\n"
1725 " ======================================\n"
1727 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1729 " Everyone is permitted to copy and distribute verbatim copies\n"
1730 " of this licence document, but changing it is not allowed.\n"
1732 " WXWINDOWS LIBRARY LICENCE\n"
1733 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1735 " ...and so on and so forth...\n"
1738 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
1741 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1743 wxAboutDialogInfo info
;
1744 InitAboutInfoMinimal(info
);
1746 wxAboutBox(info
, this);
1749 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1751 wxAboutDialogInfo info
;
1752 InitAboutInfoWebsite(info
);
1754 wxAboutBox(info
, this);
1757 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1759 wxAboutDialogInfo info
;
1760 InitAboutInfoAll(info
);
1762 wxAboutBox(info
, this);
1765 // a trivial example of a custom dialog class
1766 class MyAboutDialog
: public wxGenericAboutDialog
1769 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
1771 Create(info
, parent
);
1774 // add some custom controls
1775 virtual void DoAddCustomControls()
1777 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1778 AddText(wxT("Some custom text"));
1779 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1783 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1785 wxAboutDialogInfo info
;
1786 InitAboutInfoAll(info
);
1788 MyAboutDialog
dlg(info
, this);
1792 #endif // wxUSE_ABOUTDLG
1796 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1798 wxWindowDisabler disableAll
;
1800 wxBusyInfo
info(wxT("Working, please wait..."), this);
1802 for ( int i
= 0; i
< 18; i
++ )
1812 #endif // wxUSE_BUSYINFO
1814 #if wxUSE_FINDREPLDLG
1816 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1820 delete m_dlgReplace
;
1821 m_dlgReplace
= NULL
;
1825 m_dlgReplace
= new wxFindReplaceDialog
1829 wxT("Find and replace dialog"),
1833 m_dlgReplace
->Show(true);
1837 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1846 m_dlgFind
= new wxFindReplaceDialog
1855 m_dlgFind
->Show(true);
1859 static wxString
DecodeFindDialogEventFlags(int flags
)
1862 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
1863 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
1864 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
1865 << wxT("case sensitive");
1870 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1872 wxEventType type
= event
.GetEventType();
1874 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1876 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1877 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1878 event
.GetFindString().c_str(),
1879 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1881 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1882 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1884 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1885 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
1886 event
.GetFindString().c_str(),
1887 event
.GetReplaceString().c_str(),
1888 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1890 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1892 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1896 if ( dlg
== m_dlgFind
)
1899 idMenu
= DIALOGS_FIND
;
1902 else if ( dlg
== m_dlgReplace
)
1904 txt
= wxT("Replace");
1905 idMenu
= DIALOGS_REPLACE
;
1906 m_dlgReplace
= NULL
;
1910 txt
= wxT("Unknown");
1913 wxFAIL_MSG( wxT("unexpected event") );
1916 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1918 if ( idMenu
!= wxID_ANY
)
1920 GetMenuBar()->Check(idMenu
, false);
1927 wxLogError(wxT("Unknown find dialog event!"));
1931 #endif // wxUSE_FINDREPLDLG
1933 // ----------------------------------------------------------------------------
1935 // ----------------------------------------------------------------------------
1937 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1940 dc
.SetFont(wxGetApp().m_canvasFont
);
1941 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1942 dc
.SetBackgroundMode(wxTRANSPARENT
);
1944 wxT("wxWidgets common dialogs")
1945 #if !defined(__SMARTPHONE__)
1946 wxT(" test application")
1951 #if USE_MODAL_PRESENTATION
1953 // ----------------------------------------------------------------------------
1955 // ----------------------------------------------------------------------------
1957 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1958 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
1960 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1962 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
1963 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
1966 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1967 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1969 SetSizerAndFit(sizerTop
);
1972 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1974 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
1975 wxOK
| wxICON_INFORMATION
, this);
1978 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1980 if ( event
.CanVeto() )
1982 wxMessageBox(wxT("Use the menu item to close this dialog"),
1983 wxT("Modeless dialog"),
1984 wxOK
| wxICON_INFORMATION
, this);
1990 // ----------------------------------------------------------------------------
1992 // ----------------------------------------------------------------------------
1994 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1995 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
1997 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1999 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
2000 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
2001 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
2003 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2004 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2005 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2006 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2008 SetSizerAndFit(sizerTop
);
2010 SetEscapeId(wxID_CLOSE
);
2012 m_btnModal
->SetFocus();
2013 m_btnModal
->SetDefault();
2016 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2018 if ( event
.GetEventObject() == m_btnDelete
)
2023 m_btnDelete
->Disable();
2025 else if ( event
.GetEventObject() == m_btnModal
)
2028 wxGetTextFromUser(wxT("Dummy prompt"),
2029 wxT("Modal dialog called from dialog"),
2030 wxEmptyString
, this);
2032 wxMessageBox(wxT("Modal dialog called from dialog"));
2033 #endif // wxUSE_TEXTDLG
2035 else if ( event
.GetEventObject() == m_btnModeless
)
2037 (new MyModelessDialog(this))->Show();
2045 #endif // USE_MODAL_PRESENTATION
2047 // ----------------------------------------------------------------------------
2048 // StdButtonSizerDialog
2049 // ----------------------------------------------------------------------------
2051 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2052 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2053 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2054 m_buttonsSizer(NULL
)
2056 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2058 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2059 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2061 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2063 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2065 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2066 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2068 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2070 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2072 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2074 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2075 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2077 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2079 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2080 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2081 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2083 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2085 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2086 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2088 sizer
->Add(sizerInside1
, 0, 0, 0);
2089 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2090 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2091 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2093 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2094 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2096 sizer
->Add(sizerInside2
, 0, 0, 0);
2097 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2098 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2099 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2101 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2103 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2104 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2105 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2107 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2109 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2111 EnableDisableControls();
2113 SetSizerAndFit(sizerTop
);
2119 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2123 m_buttonsSizer
->DeleteWindows();
2124 GetSizer()->Remove(m_buttonsSizer
);
2127 EnableDisableControls();
2130 unsigned long numButtons
= 0;
2132 if (m_chkboxAffirmativeButton
->IsChecked())
2134 if (m_radiobtnOk
->GetValue())
2139 else if (m_radiobtnYes
->GetValue())
2146 if (m_chkboxDismissButton
->IsChecked())
2148 if (m_radiobtnCancel
->GetValue())
2154 else if (m_radiobtnClose
->GetValue())
2162 if (m_chkboxApply
->IsChecked())
2168 if (m_chkboxNo
->IsChecked())
2174 if (m_chkboxHelp
->IsChecked())
2180 if (m_chkboxNoDefault
->IsChecked())
2182 flags
|= wxNO_DEFAULT
;
2185 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2186 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2189 GetSizer()->SetSizeHints(this);
2192 void StdButtonSizerDialog::EnableDisableControls()
2194 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2196 m_radiobtnOk
->Enable(affButtonEnabled
);
2197 m_radiobtnYes
->Enable(affButtonEnabled
);
2199 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2201 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2202 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2205 #if USE_SETTINGS_DIALOG
2206 // ----------------------------------------------------------------------------
2208 // ----------------------------------------------------------------------------
2210 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2212 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2215 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2217 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2222 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2223 int resizeBorder
= wxRESIZE_BORDER
;
2231 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2232 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2233 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2235 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2237 SetSheetStyle(sheetStyle
);
2238 SetSheetInnerBorder(0);
2239 SetSheetOuterBorder(0);
2241 // create a dummy image list with a few icons
2242 const wxSize
imageSize(32, 32);
2244 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2246 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2248 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2250 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2252 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2257 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2258 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2261 // If using a toolbook, also follow Mac style and don't create buttons
2263 CreateButtons(wxOK
| wxCANCEL
|
2264 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2267 wxBookCtrlBase
* notebook
= GetBookCtrl();
2268 notebook
->SetImageList(m_imageList
);
2270 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2271 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2273 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2274 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2279 SettingsDialog::~SettingsDialog()
2284 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2286 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2288 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2289 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2293 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2294 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2295 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2296 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2300 wxString autoSaveLabel
= _("&Auto-save every");
2301 wxString minsLabel
= _("mins");
2303 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2304 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2307 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2308 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2311 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2313 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2315 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2316 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2320 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2321 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2322 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2323 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2325 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2327 panel
->SetSizerAndFit(topSizer
);
2332 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2334 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2336 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2337 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2339 //// PROJECT OR GLOBAL
2340 wxString globalOrProjectChoices
[2];
2341 globalOrProjectChoices
[0] = _("&New projects");
2342 globalOrProjectChoices
[1] = _("&This project");
2344 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2345 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2346 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2348 projectOrGlobal
->SetSelection(0);
2350 //// BACKGROUND STYLE
2351 wxArrayString backgroundStyleChoices
;
2352 backgroundStyleChoices
.Add(wxT("Colour"));
2353 backgroundStyleChoices
.Add(wxT("Image"));
2354 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2356 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2357 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2359 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2361 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2363 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2364 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2365 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2367 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2370 //// FONT SIZE SELECTION
2372 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2373 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2375 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2376 wxSize(80, wxDefaultCoord
));
2377 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2379 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2382 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2383 topSizer
->AddSpacer(5);
2385 panel
->SetSizerAndFit(topSizer
);
2390 // ----------------------------------------------------------------------------
2391 // TestMessageBoxDialog
2392 // ----------------------------------------------------------------------------
2395 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2400 { wxCANCEL
, "&Cancel" },
2403 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2404 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2405 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2408 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2409 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2410 wxDefaultPosition
, wxDefaultSize
,
2411 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2413 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2415 // this sizer allows to configure the messages shown in the message box
2417 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2418 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2419 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2420 wxDefaultPosition
, wxDefaultSize
,
2422 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2424 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2425 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2426 wxDefaultPosition
, wxDefaultSize
,
2428 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2430 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2433 // this one is for configuring the buttons
2434 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2435 sizerBtns
->AddGrowableCol(1);
2437 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2438 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2440 for ( int n
= 0; n
< Btn_Max
; n
++ )
2442 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2443 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2445 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2446 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2448 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2449 wxUpdateUIEventHandler(
2450 TestMessageBoxDialog::OnUpdateLabelUI
),
2456 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2457 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2458 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2462 const wxString icons
[] = {
2463 "&None", "&Information", "&Question", "&Warning", "&Error"
2466 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icons",
2467 wxDefaultPosition
, wxDefaultSize
,
2468 WXSIZEOF(icons
), icons
);
2469 // Make the 'Information' icon the default one:
2470 m_icons
->SetSelection(1);
2471 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2474 // miscellaneous other stuff
2476 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2478 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2479 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2480 wxUpdateUIEventHandler(
2481 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2484 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2486 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2487 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2489 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2491 // finally buttons to show the resulting message box and close this dialog
2492 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2493 wxSizerFlags().Right().Border());
2495 SetSizerAndFit(sizerTop
);
2497 m_buttons
[Btn_Ok
]->SetValue(true);
2500 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2502 for ( int n
= 0; n
< Btn_Max
; n
++ )
2504 if ( event
.GetEventObject() == m_labels
[n
] )
2506 event
.Enable( m_buttons
[n
]->IsChecked() );
2511 wxFAIL_MSG( "called for unknown label" );
2514 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2516 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2519 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2523 for ( int n
= 0; n
< Btn_Max
; n
++ )
2525 if ( m_buttons
[n
]->IsChecked() )
2526 style
|= ms_btnInfo
[n
].flag
;
2529 switch ( m_icons
->GetSelection() )
2531 case 0: style
|= wxICON_NONE
; break;
2532 case 1: style
|= wxICON_INFORMATION
; break;
2533 case 2: style
|= wxICON_QUESTION
; break;
2534 case 3: style
|= wxICON_WARNING
; break;
2535 case 4: style
|= wxICON_ERROR
; break;
2538 if ( m_chkCentre
->IsChecked() )
2541 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2542 style
|= wxNO_DEFAULT
;
2545 wxMessageDialog
dlg(this, m_textMsg
->GetValue(), "Test Message Box",
2547 if ( !m_textExtMsg
->IsEmpty() )
2548 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2550 if ( style
& wxYES_NO
)
2552 if ( style
& wxCANCEL
)
2554 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2555 m_labels
[Btn_No
]->GetValue(),
2556 m_labels
[Btn_Cancel
]->GetValue());
2560 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2561 m_labels
[Btn_No
]->GetValue());
2566 if ( style
& wxCANCEL
)
2568 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2569 m_labels
[Btn_Cancel
]->GetValue());
2573 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2580 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2582 EndModal(wxID_CANCEL
);
2585 #endif // USE_SETTINGS_DIALOG
2589 // ----------------------------------------------------------------------------
2590 // custom log target
2591 // ----------------------------------------------------------------------------
2593 class MyLogGui
: public wxLogGui
2596 virtual void DoShowSingleLogMessage(const wxString
& message
,
2597 const wxString
& title
,
2600 wxMessageDialog
dlg(NULL
, message
, title
,
2601 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2602 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2603 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2608 wxLog
*MyAppTraits::CreateLogTarget()
2610 return new MyLogGui
;