1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
7 // Copyright: (c) Julian Smart
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
24 #include "../sample.xpm"
26 #include "wx/apptrait.h"
27 #include "wx/datetime.h"
29 #include "wx/bookctrl.h"
30 #include "wx/artprov.h"
31 #include "wx/imaglist.h"
32 #include "wx/minifram.h"
33 #include "wx/sysopt.h"
34 #include "wx/notifmsg.h"
37 #include "wx/colordlg.h"
38 #endif // wxUSE_COLOURDLG
41 #include "wx/choicdlg.h"
42 #endif // wxUSE_CHOICEDLG
44 #include "wx/rearrangectrl.h"
46 #if wxUSE_STARTUP_TIPS
47 #include "wx/tipdlg.h"
48 #endif // wxUSE_STARTUP_TIPS
51 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
52 #include "wx/datetime.h" // wxDateTime
55 #include "wx/progdlg.h"
56 #endif // wxUSE_PROGRESSDLG
59 #include "wx/aboutdlg.h"
61 // these headers are only needed for custom about dialog
62 #include "wx/statline.h"
63 #include "wx/generic/aboutdlgg.h"
64 #endif // wxUSE_ABOUTDLG
67 #include "wx/busyinfo.h"
68 #endif // wxUSE_BUSYINFO
71 #include "wx/numdlg.h"
72 #endif // wxUSE_NUMBERDLG
75 #include "wx/filedlg.h"
76 #endif // wxUSE_FILEDLG
79 #include "wx/dirdlg.h"
80 #endif // wxUSE_DIRDLG
83 #include "wx/fontdlg.h"
84 #endif // wxUSE_FONTDLG
87 #include "wx/fdrepdlg.h"
88 #endif // wxUSE_FINDREPLDLG
90 #include "wx/spinctrl.h"
91 #include "wx/propdlg.h"
95 #if USE_COLOURDLG_GENERIC
96 #include "wx/generic/colrdlgg.h"
97 #endif // USE_COLOURDLG_GENERIC
99 #if USE_DIRDLG_GENERIC
100 #include "wx/generic/dirdlgg.h"
101 #endif // USE_DIRDLG_GENERIC
103 #if USE_FILEDLG_GENERIC
104 #include "wx/generic/filedlgg.h"
105 #endif // USE_FILEDLG_GENERIC
107 #if USE_FONTDLG_GENERIC
108 #include "wx/generic/fontdlgg.h"
109 #endif // USE_FONTDLG_GENERIC
113 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
114 EVT_PAINT(MyCanvas::OnPaint
)
119 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
121 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
122 EVT_MENU(DIALOGS_MESSAGE_DIALOG
, MyFrame::MessageBoxDialog
)
123 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
124 #endif // wxUSE_MSGDLG
126 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
127 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
128 #endif // wxUSE_COLOURDLG
131 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
132 #endif // wxUSE_FONTDLG
135 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
136 #endif // wxUSE_LOG_DIALOG
139 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
140 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
141 #endif // wxUSE_TEXTDLG
144 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
145 #endif // wxUSE_NUMBERDLG
148 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
149 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
150 #endif // wxUSE_CHOICEDLG
152 #if wxUSE_REARRANGECTRL
153 EVT_MENU(DIALOGS_REARRANGE
, MyFrame::Rearrange
)
154 #endif // wxUSE_REARRANGECTRL
157 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
158 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
159 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
160 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
161 #endif // wxUSE_FILEDLG
163 #if USE_FILEDLG_GENERIC
164 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
165 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
166 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
167 #endif // USE_FILEDLG_GENERIC
170 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
171 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
172 #endif // wxUSE_DIRDLG
174 #if USE_MODAL_PRESENTATION
175 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
176 #endif // USE_MODAL_PRESENTATION
177 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
178 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
179 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
181 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
182 #endif // wxUSE_MINIFRAME
183 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
185 #if wxUSE_STARTUP_TIPS
186 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
187 #endif // wxUSE_STARTUP_TIPS
189 #if USE_FONTDLG_GENERIC
190 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
191 #endif // USE_FONTDLG_GENERIC
193 #if USE_DIRDLG_GENERIC
194 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
195 #endif // wxMSW || wxMAC
197 #if USE_COLOURDLG_GENERIC
198 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
199 #endif // USE_COLOURDLG_GENERIC
201 #if wxUSE_PROGRESSDLG
202 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
203 #endif // wxUSE_PROGRESSDLG
206 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
207 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
208 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
209 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
210 #endif // wxUSE_ABOUTDLG
213 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
214 #endif // wxUSE_BUSYINFO
216 #if wxUSE_FINDREPLDLG
217 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
218 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
220 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
221 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
222 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
223 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
224 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
225 #endif // wxUSE_FINDREPLDLG
227 #if USE_SETTINGS_DIALOG
228 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
229 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
230 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
231 #endif // USE_SETTINGS_DIALOG
233 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
234 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION
, MyFrame::OnTestDefaultActionDialog
)
236 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
237 #if wxUSE_NOTIFICATION_MESSAGE
238 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
239 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
240 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
241 #endif // wxUSE_NOTIFICATION_MESSAGE
243 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
246 #if USE_MODAL_PRESENTATION
248 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
249 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
252 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
253 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
254 EVT_CLOSE(MyModelessDialog::OnClose
)
257 #endif // USE_MODAL_PRESENTATION
259 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
260 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
261 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
264 // `Main program' equivalent, creating windows and returning main app frame
267 if ( !wxApp::OnInit() )
271 wxInitAllImageHandlers();
274 m_canvasTextColour
= *wxBLACK
;
275 m_canvasFont
= *wxNORMAL_FONT
;
277 // Create the main frame window
278 MyFrame
*frame
= new MyFrame(wxT("wxWidgets dialogs example"));
281 wxMenu
*menuDlg
= new wxMenu
;
283 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
284 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
287 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
289 wxMenu
*choices_menu
= new wxMenu
;
292 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
293 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
294 #endif // wxUSE_COLOURDLG
297 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
298 #endif // wxUSE_FONTDLG
301 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
302 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
303 #endif // wxUSE_CHOICEDLG
305 #if wxUSE_REARRANGECTRL
306 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
307 #endif // wxUSE_REARRANGECTRL
309 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
310 choices_menu
->AppendSeparator();
311 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
313 #if USE_COLOURDLG_GENERIC
314 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
315 #endif // USE_COLOURDLG_GENERIC
317 #if USE_FONTDLG_GENERIC
318 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
319 #endif // USE_FONTDLG_GENERIC
321 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
322 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
325 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
327 wxMenu
*entry_menu
= new wxMenu
;
330 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Text &entry\tCtrl-E"));
331 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
332 #endif // wxUSE_TEXTDLG
335 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
336 #endif // wxUSE_NUMBERDLG
338 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
340 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
345 wxMenu
*filedlg_menu
= new wxMenu
;
346 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
347 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
348 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
349 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
351 #if USE_FILEDLG_GENERIC
352 filedlg_menu
->AppendSeparator();
353 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
354 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
355 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
356 #endif // USE_FILEDLG_GENERIC
358 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
360 #endif // wxUSE_FILEDLG
363 wxMenu
*dir_menu
= new wxMenu
;
365 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
366 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
367 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
369 #if USE_DIRDLG_GENERIC
370 dir_menu
->AppendSeparator();
371 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
372 #endif // USE_DIRDLG_GENERIC
374 #endif // wxUSE_DIRDLG
377 #if wxUSE_STARTUP_TIPS || \
378 wxUSE_PROGRESSDLG || \
380 wxUSE_LOG_DIALOG || \
383 wxMenu
*info_menu
= new wxMenu
;
385 #if wxUSE_STARTUP_TIPS
386 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
387 #endif // wxUSE_STARTUP_TIPS
389 #if wxUSE_PROGRESSDLG
390 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
391 #endif // wxUSE_PROGRESSDLG
394 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
395 #endif // wxUSE_BUSYINFO
398 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
399 #endif // wxUSE_LOG_DIALOG
402 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
403 wxT("&wxWidgets information\tCtrl-I"));
404 #endif // wxUSE_MSGDLG
406 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
408 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
411 #if wxUSE_FINDREPLDLG
412 wxMenu
*find_menu
= new wxMenu
;
413 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
414 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
415 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
416 #endif // wxUSE_FINDREPLDLG
418 wxMenu
*dialogs_menu
= new wxMenu
;
419 #if USE_MODAL_PRESENTATION
420 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tCtrl-W"));
421 #endif // USE_MODAL_PRESENTATION
422 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tCtrl-Z"));
423 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
424 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
426 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
427 #endif // wxUSE_MINIFRAME
428 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
429 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
431 #if USE_SETTINGS_DIALOG
432 wxMenu
*sheet_menu
= new wxMenu
;
433 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
434 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
436 if (wxPlatformIs(wxPORT_MAC
))
437 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
440 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
443 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
444 #endif // USE_SETTINGS_DIALOG
446 wxMenu
*menuNotif
= new wxMenu
;
447 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
448 #if wxUSE_NOTIFICATION_MESSAGE
449 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
450 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
451 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
452 #endif // wxUSE_NOTIFICATION_MESSAGE
453 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
455 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
456 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
458 menuDlg
->AppendSeparator();
459 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
462 wxMenu
*menuHelp
= new wxMenu
;
463 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
464 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
465 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
466 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
467 #endif // wxUSE_ABOUTDLG
469 wxMenuBar
*menubar
= new wxMenuBar
;
470 menubar
->Append(menuDlg
, wxT("&Dialogs"));
472 menubar
->Append(menuHelp
, wxT("&Help"));
473 #endif // wxUSE_ABOUTDLG
475 frame
->SetMenuBar(menubar
);
477 frame
->Centre(wxBOTH
);
483 // My frame constructor
484 MyFrame::MyFrame(const wxString
& title
)
485 : wxFrame(NULL
, wxID_ANY
, title
)
489 #if USE_MODAL_PRESENTATION
490 m_dialog
= (MyModelessDialog
*)NULL
;
491 #endif // USE_MODAL_PRESENTATION
493 #if wxUSE_FINDREPLDLG
499 m_clrData
.SetChooseFull(true);
500 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
502 unsigned char n
= i
*16;
503 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
505 #endif // wxUSE_COLOURDLG
507 #if wxUSE_NOTIFICATION_MESSAGE
509 #endif // wxUSE_NOTIFICATION_MESSAGE
513 #endif // wxUSE_STATUSBAR
515 m_canvas
= new MyCanvas(this);
520 #if wxUSE_NOTIFICATION_MESSAGE
522 #endif // wxUSE_NOTIFICATION_MESSAGE
527 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
529 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
531 wxColourDialog
dialog(this, &m_clrData
);
532 dialog
.SetTitle(_("Please choose the background colour"));
533 if ( dialog
.ShowModal() == wxID_OK
)
535 m_clrData
= dialog
.GetColourData();
536 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
537 m_canvas
->ClearBackground();
542 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
544 wxColour clr
= wxGetColourFromUser
547 wxGetApp().m_canvasTextColour
,
548 "Please choose the foreground colour"
552 wxGetApp().m_canvasTextColour
= clr
;
555 //else: dialog cancelled by user
558 #endif // wxUSE_COLOURDLG
561 #if USE_COLOURDLG_GENERIC
562 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
564 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
566 //FIXME:TODO:This has no effect...
567 m_clrData
.SetChooseFull(true);
569 for (int i
= 0; i
< 16; i
++)
572 (unsigned char)(i
*16),
573 (unsigned char)(i
*16),
574 (unsigned char)(i
*16)
576 m_clrData
.SetCustomColour(i
, colour
);
579 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
580 if (dialog
->ShowModal() == wxID_OK
)
582 m_clrData
= dialog
->GetColourData();
583 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
584 m_canvas
->ClearBackground();
589 #endif // USE_COLOURDLG_GENERIC
592 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
595 data
.SetInitialFont(wxGetApp().m_canvasFont
);
596 data
.SetColour(wxGetApp().m_canvasTextColour
);
598 // you might also do this:
600 // wxFontDialog dialog;
601 // if ( !dialog.Create(this, data) { ... error ... }
603 wxFontDialog
dialog(this, data
);
605 if (dialog
.ShowModal() == wxID_OK
)
607 wxFontData retData
= dialog
.GetFontData();
608 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
609 wxGetApp().m_canvasTextColour
= retData
.GetColour();
612 //else: cancelled by the user, don't change the font
614 #endif // wxUSE_FONTDLG
616 #if USE_FONTDLG_GENERIC
617 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
620 data
.SetInitialFont(wxGetApp().m_canvasFont
);
621 data
.SetColour(wxGetApp().m_canvasTextColour
);
623 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
624 if (dialog
->ShowModal() == wxID_OK
)
626 wxFontData retData
= dialog
->GetFontData();
627 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
628 wxGetApp().m_canvasTextColour
= retData
.GetColour();
633 #endif // USE_FONTDLG_GENERIC
636 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
638 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
639 // being flushed -- test it
642 wxLogMessage(wxT("This is some message - everything is ok so far."));
643 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
644 wxLogWarning(wxT("And then something went wrong!"));
646 // and if ~wxBusyCursor doesn't do it, then call it manually
650 wxLogError(wxT("Intermediary error handler decided to abort."));
651 wxLogError(wxT("The top level caller detected an unrecoverable error."));
653 wxLog::FlushActive();
655 wxLogMessage(wxT("And this is the same dialog but with only one message."));
657 #endif // wxUSE_LOG_DIALOG
660 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
662 wxMessageDialog
dialog(this,
663 "This is a message box\n"
664 "This is a long, long string to test out if the message box "
665 "is laid out properly.",
668 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
672 if ( dialog
.SetYesNoCancelLabels
679 extmsg
= "This platform supports custom button labels,\n"
680 "so you should see the descriptive labels below.";
684 extmsg
= "Custom button labels are not supported on this platform,\n"
685 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
687 dialog
.SetExtendedMessage(extmsg
);
689 switch ( dialog
.ShowModal() )
692 wxLogStatus(wxT("You pressed \"Yes\""));
696 wxLogStatus(wxT("You pressed \"No\""));
700 wxLogStatus(wxT("You pressed \"Cancel\""));
704 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
708 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
710 TestMessageBoxDialog
dlg(this);
714 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
716 ::wxInfoMessageBox(this);
718 #endif // wxUSE_MSGDLG
721 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
723 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
724 wxT("Even two rows of text."),
725 wxT("Enter a number:"), wxT("Numeric input test"),
732 msg
= wxT("Invalid number entered or dialog cancelled.");
737 msg
.Printf(wxT("You've entered %lu"), res
);
738 icon
= wxICON_INFORMATION
;
741 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
743 #endif // wxUSE_NUMBERDLG
746 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
748 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
749 wxT("Password entry dialog"),
754 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
755 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
759 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
761 wxTextEntryDialog
dialog(this,
762 wxT("This is a small sample\n")
763 wxT("A long, long string to test out the text entrybox"),
764 wxT("Please enter a string"),
765 wxT("Default value"),
768 if (dialog
.ShowModal() == wxID_OK
)
770 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
773 #endif // wxUSE_TEXTDLG
776 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
778 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
780 wxSingleChoiceDialog
dialog(this,
781 wxT("This is a small sample\n")
782 wxT("A single-choice convenience dialog"),
783 wxT("Please select a value"),
784 WXSIZEOF(choices
), choices
);
786 dialog
.SetSelection(2);
788 if (dialog
.ShowModal() == wxID_OK
)
790 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
795 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
797 const wxString choices
[] =
799 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
800 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
801 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
804 wxArrayInt selections
;
805 const int count
= wxGetSelectedChoices(selections
,
806 wxT("This is a small sample\n")
807 wxT("A multi-choice convenience dialog"),
808 wxT("Please select a value"),
809 WXSIZEOF(choices
), choices
,
816 msg
= wxT("You did not select any items");
820 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
821 for ( int n
= 0; n
< count
; n
++ )
823 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
824 (unsigned)n
, (unsigned)selections
[n
],
825 choices
[selections
[n
]].c_str());
832 #endif // wxUSE_CHOICEDLG
834 #if wxUSE_REARRANGECTRL
835 // custom rearrange dialog: it adds the possibility to rename an item to the
836 // base class functionality
837 class MyRearrangeDialog
: public wxRearrangeDialog
840 MyRearrangeDialog(wxWindow
*parent
,
842 wxArrayString
& labels
,
843 wxArrayString
& labelsOrig
)
847 "Configure the columns shown:",
848 "wxRearrangeDialog example",
854 m_labelsOrig(labelsOrig
)
858 wxPanel
* const panel
= new wxPanel(this);
859 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
861 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
862 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
864 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
865 wxDefaultPosition
, wxDefaultSize
,
867 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
869 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
870 wxSizerFlags().Centre());
872 panel
->SetSizer(sizer
);
874 // call this first to ensure that the controls have a reasonable best
875 // size before they're added
876 DoUpdateExtraControls(GetList()->GetSelection());
878 AddExtraControls(panel
);
881 // another customization not directly supported by the dialog: add a
883 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
884 wxCHECK_RET( btnOk
, "no Ok button?" );
886 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
887 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
889 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
890 wxSizerFlags().Border(wxLEFT
));
893 // call this instead of ShowModal() to update order and labels array in
894 // case the dialog was not cancelled
897 switch ( ShowModal() )
903 m_order
= GetOrder();
907 // order already reset
915 void OnSelChange(wxCommandEvent
& event
)
917 DoUpdateExtraControls(event
.GetInt());
920 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
922 event
.Enable( CanRename() );
925 void OnRename(wxCommandEvent
& WXUNUSED(event
))
930 m_labels
[m_sel
] = m_text
->GetValue();
931 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
934 void OnReset(wxCommandEvent
& WXUNUSED(event
))
936 // in a real program we should probably ask if the user really wants to
937 // do this but here we just go ahead and reset all columns labels and
938 // their order without confirmation
939 const unsigned count
= m_order
.size();
940 for ( unsigned n
= 0; n
< count
; n
++ )
943 m_labels
[n
] = m_labelsOrig
[n
];
946 EndModal(wxID_RESET
);
949 bool CanRename() const
951 // only allow renaming if the user modified the currently selected item
952 // text (which presupposes that we do have a current item)
953 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
956 void DoUpdateExtraControls(int sel
)
960 if ( m_sel
== wxNOT_FOUND
)
962 m_labelOrig
->SetLabel("<no selection>");
966 else // have valid item
968 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
970 m_text
->SetValue(m_labels
[m_sel
]);
975 wxArrayString
& m_labels
,
979 wxStaticText
*m_labelOrig
;
982 DECLARE_EVENT_TABLE()
983 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
986 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
987 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
989 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
991 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
992 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
993 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
996 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
998 // the arrays are static so that we preserve the items order between calls
1000 static wxArrayInt s_order
;
1001 static wxArrayString s_labels
,
1004 // initialize them on the first call
1005 if ( s_labelsOrig
.empty() )
1007 static const struct ItemInfo
1010 const char *labelOrig
;
1014 { "File name", "Name", 0 },
1015 { "File type", "Ext", 1 },
1016 { "Size", "Size", 2 },
1017 { "Creation time", "Ctime", ~3 }, // negated so hidden
1018 { "Last accessed", "Atime", ~4 },
1019 { "Last modified", "Mtime", 5 },
1022 s_order
.reserve(WXSIZEOF(items
));
1023 s_labels
.reserve(WXSIZEOF(items
));
1024 s_labelsOrig
.reserve(WXSIZEOF(items
));
1025 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1027 const ItemInfo
& item
= items
[n
];
1028 s_order
.push_back(item
.order
);
1029 s_labels
.push_back(item
.label
);
1030 s_labelsOrig
.push_back(item
.labelOrig
);
1034 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1035 if ( !dlg
.Rearrange() )
1039 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1041 columns
+= wxString::Format("\n %u: ", n
);
1042 int idx
= s_order
[n
];
1045 columns
+= "[hidden] ";
1049 columns
+= s_labels
[idx
];
1050 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1052 columns
+= wxString::Format(" (original label: \"%s\")",
1057 wxLogMessage("The columns order now is:%s", columns
);
1059 #endif // wxUSE_REARRANGECTRL
1063 // panel with custom controls for file dialog
1064 class MyExtraPanel
: public wxPanel
1067 MyExtraPanel(wxWindow
*parent
);
1068 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1069 wxString
GetInfo() const
1071 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1078 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1081 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1082 m_btn
->Enable(false);
1083 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1084 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1085 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1086 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1087 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1088 sizerTop
->AddStretchSpacer();
1089 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1090 SetSizerAndFit(sizerTop
);
1093 // a static method can be used instead of a function with most of compilers
1094 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1096 return new MyExtraPanel(parent
);
1099 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1104 wxT("Testing open file dialog"),
1108 wxT("C++ files (*.cpp)|*.cpp")
1110 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1114 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1115 dialog
.CentreOnParent();
1116 dialog
.SetDirectory(wxGetHomeDir());
1118 if (dialog
.ShowModal() == wxID_OK
)
1121 wxWindow
* const extra
= dialog
.GetExtraControl();
1122 info
.Printf(wxT("Full file name: %s\n")
1125 wxT("Custom window: %s"),
1126 dialog
.GetPath().c_str(),
1127 dialog
.GetDirectory().c_str(),
1128 dialog
.GetFilename().c_str(),
1129 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1130 : wxString("None"));
1131 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1132 dialog2
.ShowModal();
1136 // this shows how to take advantage of specifying a default extension in the
1137 // call to wxFileSelector: it is remembered after each new call and the next
1138 // one will use it by default
1139 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1141 static wxString s_extDef
;
1142 wxString path
= wxFileSelector(
1143 wxT("Select the file to load"),
1144 wxEmptyString
, wxEmptyString
,
1148 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1149 wxFileSelectorDefaultWildcardStr
,
1150 wxFileSelectorDefaultWildcardStr
1152 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1159 // it is just a sample, would use wxSplitPath in real program
1160 s_extDef
= path
.AfterLast(wxT('.'));
1162 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1166 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1168 wxString wildcards
=
1170 wxT("C++ files (*.cpp)|*.cpp");
1174 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1175 wxFileSelectorDefaultWildcardStr
,
1176 wxFileSelectorDefaultWildcardStr
1179 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1180 wxEmptyString
, wxEmptyString
, wildcards
,
1181 wxFD_OPEN
|wxFD_MULTIPLE
);
1183 if (dialog
.ShowModal() == wxID_OK
)
1185 wxArrayString paths
, filenames
;
1187 dialog
.GetPaths(paths
);
1188 dialog
.GetFilenames(filenames
);
1191 size_t count
= paths
.GetCount();
1192 for ( size_t n
= 0; n
< count
; n
++ )
1194 s
.Printf(wxT("File %d: %s (%s)\n"),
1195 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1199 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1202 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1203 dialog2
.ShowModal();
1207 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1209 wxFileDialog
dialog(this,
1210 wxT("Testing save file dialog"),
1212 wxT("myletter.doc"),
1213 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1214 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1216 dialog
.SetFilterIndex(1);
1218 if (dialog
.ShowModal() == wxID_OK
)
1220 wxLogMessage(wxT("%s, filter %d"),
1221 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1224 #endif // wxUSE_FILEDLG
1226 #if USE_FILEDLG_GENERIC
1227 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1229 wxGenericFileDialog dialog
1232 wxT("Testing open file dialog"),
1235 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1238 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1239 dialog
.SetDirectory(wxGetHomeDir());
1241 if (dialog
.ShowModal() == wxID_OK
)
1244 info
.Printf(wxT("Full file name: %s\n")
1247 dialog
.GetPath().c_str(),
1248 dialog
.GetDirectory().c_str(),
1249 dialog
.GetFilename().c_str());
1250 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1251 dialog2
.ShowModal();
1255 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1257 // On PocketPC you can disable OK-only dialogs policy using system option
1258 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1259 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1261 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1262 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1263 wxEmptyString
, wxEmptyString
, wildcards
,
1266 if (dialog
.ShowModal() == wxID_OK
)
1268 wxArrayString paths
, filenames
;
1270 dialog
.GetPaths(paths
);
1271 dialog
.GetFilenames(filenames
);
1274 size_t count
= paths
.GetCount();
1275 for ( size_t n
= 0; n
< count
; n
++ )
1277 s
.Printf(wxT("File %d: %s (%s)\n"),
1278 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1282 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1285 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1286 dialog2
.ShowModal();
1289 // restore system option
1290 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1293 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1295 wxGenericFileDialog
dialog(this,
1296 wxT("Testing save file dialog"),
1298 wxT("myletter.doc"),
1299 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1300 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1302 dialog
.SetFilterIndex(1);
1304 if (dialog
.ShowModal() == wxID_OK
)
1306 wxLogMessage(wxT("%s, filter %d"),
1307 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1310 #endif // USE_FILEDLG_GENERIC
1313 void MyFrame::DoDirChoose(int style
)
1315 // pass some initial dir to wxDirDialog
1317 wxGetHomeDir(&dirHome
);
1319 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1321 if (dialog
.ShowModal() == wxID_OK
)
1323 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1327 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1329 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1332 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1334 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1336 #endif // wxUSE_DIRDLG
1338 #if USE_DIRDLG_GENERIC
1339 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1341 // pass some initial dir to wxDirDialog
1343 wxGetHomeDir(&dirHome
);
1345 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1347 if (dialog
.ShowModal() == wxID_OK
)
1349 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1350 dialog2
.ShowModal();
1353 #endif // USE_DIRDLG_GENERIC
1355 #if USE_MODAL_PRESENTATION
1356 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1358 MyModalDialog
dlg(this);
1361 #endif // USE_MODAL_PRESENTATION
1363 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1365 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1371 m_dialog
= new MyModelessDialog(this);
1374 m_dialog
->Show(true);
1378 // If m_dialog is NULL, then possibly the system
1379 // didn't report the checked menu item status correctly.
1380 // It should be true just after the menu item was selected,
1381 // if there was no modeless dialog yet.
1383 wxASSERT( m_dialog
!= NULL
);
1389 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1391 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1392 wxDefaultPosition
, wxSize(200, 100));
1393 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1394 dlg
.CentreOnScreen();
1398 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1400 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1401 wxDefaultPosition
, wxSize(200, 100));
1402 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1403 dlg
.CentreOnParent();
1408 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1410 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1411 wxDefaultPosition
, wxSize(300, 100),
1412 wxCAPTION
| wxCLOSE_BOX
);
1413 new wxStaticText(frame
,
1415 wxT("Mini frames have slightly different appearance"),
1417 new wxStaticText(frame
,
1419 wxT("from the normal frames but that's the only difference."),
1422 frame
->CentreOnParent();
1425 #endif // wxUSE_MINIFRAME
1427 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1429 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1430 wxDefaultPosition
, wxSize(300, 100),
1431 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1432 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1436 #if wxUSE_STARTUP_TIPS
1437 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1439 static size_t s_index
= (size_t)-1;
1441 if ( s_index
== (size_t)-1 )
1445 // this is completely bogus, we don't know how many lines are there
1446 // in the file, but who cares, it's a demo only...
1447 s_index
= rand() % 5;
1450 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1452 bool showAtStartup
= wxShowTip(this, tipProvider
);
1454 if ( showAtStartup
)
1456 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1457 wxOK
| wxICON_INFORMATION
, this);
1460 s_index
= tipProvider
->GetCurrentTip();
1463 #endif // wxUSE_STARTUP_TIPS
1465 #if USE_SETTINGS_DIALOG
1466 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1468 SettingsDialog
dialog(this, event
.GetId());
1471 #endif // USE_SETTINGS_DIALOG
1473 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1475 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1479 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1482 #if wxUSE_NOTIFICATION_MESSAGE
1484 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1486 if ( !wxNotificationMessage
1488 "Automatic Notification",
1489 "Nothing important has happened\n"
1490 "this notification will disappear soon."
1493 wxLogStatus("Failed to show notification message");
1497 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1501 m_notifMsg
= new wxNotificationMessage
1503 "wxWidgets Manual Notification",
1504 "You can hide this notification from the menu",
1509 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1511 wxLogStatus("Failed to show manual notification message");
1515 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1517 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1519 wxLogStatus("Failed to hide manual notification message");
1523 #endif // wxUSE_NOTIFICATION_MESSAGE
1525 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1527 StdButtonSizerDialog
dialog(this);
1531 // TestDefaultAction
1533 #define ID_CATCH_LISTBOX_DCLICK 100
1534 #define ID_LISTBOX 101
1536 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1537 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1538 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1541 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1542 wxDialog( parent
, -1, "Test default action" )
1544 m_catchListBoxDClick
= false;
1546 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1548 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1551 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1552 listbox
->Append( "String 1" );
1553 listbox
->Append( "String 2" );
1554 listbox
->Append( "String 3" );
1555 listbox
->Append( "String 4" );
1556 grid_sizer
->Add( listbox
);
1557 #endif // wxUSE_LISTBOX
1559 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1561 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1562 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1564 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1565 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1567 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1569 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1571 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1573 SetSizerAndFit( main_sizer
);
1576 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1578 event
.Skip( !m_catchListBoxDClick
);
1581 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1583 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1586 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1588 TestDefaultActionDialog
dialog( this );
1592 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1597 #if wxUSE_PROGRESSDLG
1599 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1601 static const int max
= 100;
1603 wxProgressDialog
dialog(wxT("Progress dialog example"),
1604 wxT("An informative message"),
1610 // wxPD_AUTO_HIDE | -- try this as well
1612 wxPD_ESTIMATED_TIME
|
1614 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1618 for ( int i
= 0; i
<= max
; i
++ )
1624 // test both modes of wxProgressDialog behaviour: start in
1625 // indeterminate mode but switch to the determinate one later
1626 const bool determinate
= i
> max
/2;
1630 msg
= wxT("That's all, folks!");
1632 else if ( !determinate
)
1634 msg
= wxT("Testing indeterminate mode");
1636 else if ( determinate
)
1638 msg
= wxT("Now in standard determinate mode");
1641 // will be set to true if "Skip" button was pressed
1645 cont
= dialog
.Update(i
, msg
, &skip
);
1649 cont
= dialog
.Pulse(msg
, &skip
);
1652 // each skip will move progress about quarter forward
1658 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1659 wxT("Progress dialog question"), // caption
1660 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1670 wxLogStatus(wxT("Progress dialog aborted!"));
1674 wxLogStatus(wxT("Countdown from %d finished"), max
);
1678 #endif // wxUSE_PROGRESSDLG
1682 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1684 info
.SetName(wxT("Dialogs Sample"));
1685 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
1689 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
1690 wxVERSION_NUM_DOT_STRING
1692 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1693 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1694 info
.AddDeveloper(wxT("Vadim Zeitlin"));
1697 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1699 InitAboutInfoMinimal(info
);
1701 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
1704 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1706 InitAboutInfoWebsite(info
);
1708 // we can add a second developer
1709 info
.AddDeveloper(wxT("A.N. Other"));
1711 // or we can add several persons at once like this
1712 static const wxChar
*docwriters
[] =
1714 wxT("First D. Writer"),
1718 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1719 info
.SetLicence(wxString::FromAscii(
1720 " wxWindows Library Licence, Version 3.1\n"
1721 " ======================================\n"
1723 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1725 " Everyone is permitted to copy and distribute verbatim copies\n"
1726 " of this licence document, but changing it is not allowed.\n"
1728 " WXWINDOWS LIBRARY LICENCE\n"
1729 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1731 " ...and so on and so forth...\n"
1734 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
1737 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1739 wxAboutDialogInfo info
;
1740 InitAboutInfoMinimal(info
);
1742 wxAboutBox(info
, this);
1745 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1747 wxAboutDialogInfo info
;
1748 InitAboutInfoWebsite(info
);
1750 wxAboutBox(info
, this);
1753 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1755 wxAboutDialogInfo info
;
1756 InitAboutInfoAll(info
);
1758 wxAboutBox(info
, this);
1761 // a trivial example of a custom dialog class
1762 class MyAboutDialog
: public wxGenericAboutDialog
1765 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
1767 Create(info
, parent
);
1770 // add some custom controls
1771 virtual void DoAddCustomControls()
1773 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1774 AddText(wxT("Some custom text"));
1775 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1779 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1781 wxAboutDialogInfo info
;
1782 InitAboutInfoAll(info
);
1784 MyAboutDialog
dlg(info
, this);
1788 #endif // wxUSE_ABOUTDLG
1792 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1794 wxWindowDisabler disableAll
;
1796 wxBusyInfo
info(wxT("Working, please wait..."), this);
1798 for ( int i
= 0; i
< 18; i
++ )
1808 #endif // wxUSE_BUSYINFO
1810 #if wxUSE_FINDREPLDLG
1812 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1816 delete m_dlgReplace
;
1817 m_dlgReplace
= NULL
;
1821 m_dlgReplace
= new wxFindReplaceDialog
1825 wxT("Find and replace dialog"),
1829 m_dlgReplace
->Show(true);
1833 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1842 m_dlgFind
= new wxFindReplaceDialog
1851 m_dlgFind
->Show(true);
1855 static wxString
DecodeFindDialogEventFlags(int flags
)
1858 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
1859 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
1860 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
1861 << wxT("case sensitive");
1866 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1868 wxEventType type
= event
.GetEventType();
1870 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1872 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1873 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1874 event
.GetFindString().c_str(),
1875 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1877 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1878 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1880 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1881 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
1882 event
.GetFindString().c_str(),
1883 event
.GetReplaceString().c_str(),
1884 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1886 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1888 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1892 if ( dlg
== m_dlgFind
)
1895 idMenu
= DIALOGS_FIND
;
1898 else if ( dlg
== m_dlgReplace
)
1900 txt
= wxT("Replace");
1901 idMenu
= DIALOGS_REPLACE
;
1902 m_dlgReplace
= NULL
;
1906 txt
= wxT("Unknown");
1909 wxFAIL_MSG( wxT("unexpected event") );
1912 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1914 if ( idMenu
!= wxID_ANY
)
1916 GetMenuBar()->Check(idMenu
, false);
1923 wxLogError(wxT("Unknown find dialog event!"));
1927 #endif // wxUSE_FINDREPLDLG
1929 // ----------------------------------------------------------------------------
1931 // ----------------------------------------------------------------------------
1933 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1936 dc
.SetFont(wxGetApp().m_canvasFont
);
1937 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1938 dc
.SetBackgroundMode(wxTRANSPARENT
);
1940 wxT("wxWidgets common dialogs")
1941 #if !defined(__SMARTPHONE__)
1942 wxT(" test application")
1947 #if USE_MODAL_PRESENTATION
1949 // ----------------------------------------------------------------------------
1951 // ----------------------------------------------------------------------------
1953 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1954 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
1956 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1958 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
1959 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
1962 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1963 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1965 SetSizerAndFit(sizerTop
);
1968 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1970 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
1971 wxOK
| wxICON_INFORMATION
, this);
1974 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1976 if ( event
.CanVeto() )
1978 wxMessageBox(wxT("Use the menu item to close this dialog"),
1979 wxT("Modeless dialog"),
1980 wxOK
| wxICON_INFORMATION
, this);
1986 // ----------------------------------------------------------------------------
1988 // ----------------------------------------------------------------------------
1990 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1991 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
1993 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1995 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
1996 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
1997 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
1999 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
2000 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
2001 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
2002 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
2004 SetSizerAndFit(sizerTop
);
2006 SetEscapeId(wxID_CLOSE
);
2008 m_btnModal
->SetFocus();
2009 m_btnModal
->SetDefault();
2012 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2014 if ( event
.GetEventObject() == m_btnDelete
)
2019 m_btnDelete
->Disable();
2021 else if ( event
.GetEventObject() == m_btnModal
)
2024 wxGetTextFromUser(wxT("Dummy prompt"),
2025 wxT("Modal dialog called from dialog"),
2026 wxEmptyString
, this);
2028 wxMessageBox(wxT("Modal dialog called from dialog"));
2029 #endif // wxUSE_TEXTDLG
2031 else if ( event
.GetEventObject() == m_btnModeless
)
2033 (new MyModelessDialog(this))->Show();
2041 #endif // USE_MODAL_PRESENTATION
2043 // ----------------------------------------------------------------------------
2044 // StdButtonSizerDialog
2045 // ----------------------------------------------------------------------------
2047 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2048 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2049 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2050 m_buttonsSizer(NULL
)
2052 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2054 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2055 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2057 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2059 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2061 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2062 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2064 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2066 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2068 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2070 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2071 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2073 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2075 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2076 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2077 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2079 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2081 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2082 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2084 sizer
->Add(sizerInside1
, 0, 0, 0);
2085 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2086 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2087 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2089 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2090 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2092 sizer
->Add(sizerInside2
, 0, 0, 0);
2093 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2094 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2095 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2097 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2099 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2100 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2101 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2103 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2105 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2107 EnableDisableControls();
2109 SetSizerAndFit(sizerTop
);
2115 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2119 m_buttonsSizer
->DeleteWindows();
2120 GetSizer()->Remove(m_buttonsSizer
);
2123 EnableDisableControls();
2126 unsigned long numButtons
= 0;
2128 if (m_chkboxAffirmativeButton
->IsChecked())
2130 if (m_radiobtnOk
->GetValue())
2135 else if (m_radiobtnYes
->GetValue())
2142 if (m_chkboxDismissButton
->IsChecked())
2144 if (m_radiobtnCancel
->GetValue())
2150 else if (m_radiobtnClose
->GetValue())
2158 if (m_chkboxApply
->IsChecked())
2164 if (m_chkboxNo
->IsChecked())
2170 if (m_chkboxHelp
->IsChecked())
2176 if (m_chkboxNoDefault
->IsChecked())
2178 flags
|= wxNO_DEFAULT
;
2181 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2182 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2185 GetSizer()->SetSizeHints(this);
2188 void StdButtonSizerDialog::EnableDisableControls()
2190 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2192 m_radiobtnOk
->Enable(affButtonEnabled
);
2193 m_radiobtnYes
->Enable(affButtonEnabled
);
2195 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2197 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2198 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2201 #if USE_SETTINGS_DIALOG
2202 // ----------------------------------------------------------------------------
2204 // ----------------------------------------------------------------------------
2206 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2208 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2211 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2213 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2218 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2219 int resizeBorder
= wxRESIZE_BORDER
;
2227 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2228 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2229 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2231 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2233 SetSheetStyle(sheetStyle
);
2234 SetSheetInnerBorder(0);
2235 SetSheetOuterBorder(0);
2237 // create a dummy image list with a few icons
2238 const wxSize
imageSize(32, 32);
2240 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2242 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2244 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2246 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2248 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2253 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2254 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2257 // If using a toolbook, also follow Mac style and don't create buttons
2259 CreateButtons(wxOK
| wxCANCEL
|
2260 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2263 wxBookCtrlBase
* notebook
= GetBookCtrl();
2264 notebook
->SetImageList(m_imageList
);
2266 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2267 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2269 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2270 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2275 SettingsDialog::~SettingsDialog()
2280 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2282 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2284 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2285 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2289 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2290 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2291 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2292 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2296 wxString autoSaveLabel
= _("&Auto-save every");
2297 wxString minsLabel
= _("mins");
2299 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2300 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2303 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2304 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2307 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2309 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2311 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2312 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2316 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2317 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2318 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2319 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2321 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2323 panel
->SetSizerAndFit(topSizer
);
2328 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2330 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2332 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2333 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2335 //// PROJECT OR GLOBAL
2336 wxString globalOrProjectChoices
[2];
2337 globalOrProjectChoices
[0] = _("&New projects");
2338 globalOrProjectChoices
[1] = _("&This project");
2340 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2341 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2342 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2344 projectOrGlobal
->SetSelection(0);
2346 //// BACKGROUND STYLE
2347 wxArrayString backgroundStyleChoices
;
2348 backgroundStyleChoices
.Add(wxT("Colour"));
2349 backgroundStyleChoices
.Add(wxT("Image"));
2350 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2352 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2353 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2355 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2357 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2359 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2360 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2361 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2363 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2366 //// FONT SIZE SELECTION
2368 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2369 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2371 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2372 wxSize(80, wxDefaultCoord
));
2373 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2375 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2378 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2379 topSizer
->AddSpacer(5);
2381 panel
->SetSizerAndFit(topSizer
);
2386 // ----------------------------------------------------------------------------
2387 // TestMessageBoxDialog
2388 // ----------------------------------------------------------------------------
2391 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2396 { wxCANCEL
, "&Cancel" },
2399 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2400 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2401 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2404 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2405 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2406 wxDefaultPosition
, wxDefaultSize
,
2407 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2409 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2411 // this sizer allows to configure the messages shown in the message box
2413 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2414 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2415 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2416 wxDefaultPosition
, wxDefaultSize
,
2418 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2420 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2421 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2422 wxDefaultPosition
, wxDefaultSize
,
2424 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2426 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2429 // this one is for configuring the buttons
2430 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2431 sizerBtns
->AddGrowableCol(1);
2433 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2434 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2436 for ( int n
= 0; n
< Btn_Max
; n
++ )
2438 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2439 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2441 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2442 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2444 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2445 wxUpdateUIEventHandler(
2446 TestMessageBoxDialog::OnUpdateLabelUI
),
2452 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2453 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2454 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2458 const wxString icons
[] = {
2459 "&None", "&Information", "&Question", "&Warning", "&Error"
2462 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icons",
2463 wxDefaultPosition
, wxDefaultSize
,
2464 WXSIZEOF(icons
), icons
);
2465 // Make the 'Information' icon the default one:
2466 m_icons
->SetSelection(1);
2467 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2470 // miscellaneous other stuff
2472 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2474 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2475 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2476 wxUpdateUIEventHandler(
2477 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2480 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2482 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2483 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2485 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2487 // finally buttons to show the resulting message box and close this dialog
2488 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2489 wxSizerFlags().Right().Border());
2491 SetSizerAndFit(sizerTop
);
2493 m_buttons
[Btn_Ok
]->SetValue(true);
2496 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2498 for ( int n
= 0; n
< Btn_Max
; n
++ )
2500 if ( event
.GetEventObject() == m_labels
[n
] )
2502 event
.Enable( m_buttons
[n
]->IsChecked() );
2507 wxFAIL_MSG( "called for unknown label" );
2510 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2512 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2515 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2519 for ( int n
= 0; n
< Btn_Max
; n
++ )
2521 if ( m_buttons
[n
]->IsChecked() )
2522 style
|= ms_btnInfo
[n
].flag
;
2525 switch ( m_icons
->GetSelection() )
2527 case 0: style
|= wxICON_NONE
; break;
2528 case 1: style
|= wxICON_INFORMATION
; break;
2529 case 2: style
|= wxICON_QUESTION
; break;
2530 case 3: style
|= wxICON_WARNING
; break;
2531 case 4: style
|= wxICON_ERROR
; break;
2534 if ( m_chkCentre
->IsChecked() )
2537 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2538 style
|= wxNO_DEFAULT
;
2541 wxMessageDialog
dlg(this, m_textMsg
->GetValue(), "Test Message Box",
2543 if ( !m_textExtMsg
->IsEmpty() )
2544 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2546 if ( style
& wxYES_NO
)
2548 if ( style
& wxCANCEL
)
2550 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2551 m_labels
[Btn_No
]->GetValue(),
2552 m_labels
[Btn_Cancel
]->GetValue());
2556 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2557 m_labels
[Btn_No
]->GetValue());
2562 if ( style
& wxCANCEL
)
2564 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2565 m_labels
[Btn_Cancel
]->GetValue());
2569 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2576 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2578 EndModal(wxID_CANCEL
);
2581 #endif // USE_SETTINGS_DIALOG
2585 // ----------------------------------------------------------------------------
2586 // custom log target
2587 // ----------------------------------------------------------------------------
2589 class MyLogGui
: public wxLogGui
2592 virtual void DoShowSingleLogMessage(const wxString
& message
,
2593 const wxString
& title
,
2596 wxMessageDialog
dlg(NULL
, message
, title
,
2597 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2598 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2599 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2604 wxLog
*MyAppTraits::CreateLogTarget()
2606 return new MyLogGui
;