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 // Create the main frame window
275 MyFrame
*frame
= new MyFrame(wxT("wxWidgets dialogs example"));
278 wxMenu
*menuDlg
= new wxMenu
;
280 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, wxT("&Message box\tCtrl-M"));
281 menuDlg
->Append(DIALOGS_MESSAGE_DIALOG
, wxT("Message dialog\tShift-Ctrl-M"));
284 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
286 wxMenu
*choices_menu
= new wxMenu
;
289 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, wxT("&Choose bg colour"));
290 choices_menu
->Append(DIALOGS_GET_COLOUR
, wxT("&Choose fg colour"));
291 #endif // wxUSE_COLOURDLG
294 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, wxT("Choose &font"));
295 #endif // wxUSE_FONTDLG
298 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, wxT("&Single choice\tCtrl-C"));
299 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, wxT("M&ultiple choice\tCtrl-U"));
300 #endif // wxUSE_CHOICEDLG
302 #if wxUSE_REARRANGECTRL
303 choices_menu
->Append(DIALOGS_REARRANGE
, wxT("&Rearrange dialog\tCtrl-R"));
304 #endif // wxUSE_REARRANGECTRL
306 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
307 choices_menu
->AppendSeparator();
308 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
310 #if USE_COLOURDLG_GENERIC
311 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, wxT("&Choose colour (generic)"));
312 #endif // USE_COLOURDLG_GENERIC
314 #if USE_FONTDLG_GENERIC
315 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, wxT("Choose &font (generic)"));
316 #endif // USE_FONTDLG_GENERIC
318 menuDlg
->Append(wxID_ANY
,wxT("&Choices and selectors"),choices_menu
);
319 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
322 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
324 wxMenu
*entry_menu
= new wxMenu
;
327 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, wxT("Text &entry\tCtrl-E"));
328 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, wxT("&Password entry\tCtrl-P"));
329 #endif // wxUSE_TEXTDLG
332 entry_menu
->Append(DIALOGS_NUM_ENTRY
, wxT("&Numeric entry\tCtrl-N"));
333 #endif // wxUSE_NUMBERDLG
335 menuDlg
->Append(wxID_ANY
,wxT("&Entry dialogs"),entry_menu
);
337 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
342 wxMenu
*filedlg_menu
= new wxMenu
;
343 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, wxT("&Open file\tCtrl-O"));
344 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, wxT("&Second open file\tCtrl-2"));
345 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, wxT("Open &files\tCtrl-Q"));
346 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, wxT("Sa&ve file\tCtrl-S"));
348 #if USE_FILEDLG_GENERIC
349 filedlg_menu
->AppendSeparator();
350 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, wxT("&Open file (generic)"));
351 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, wxT("Open &files (generic)"));
352 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, wxT("Sa&ve file (generic)"));
353 #endif // USE_FILEDLG_GENERIC
355 menuDlg
->Append(wxID_ANY
,wxT("&File operations"),filedlg_menu
);
357 #endif // wxUSE_FILEDLG
360 wxMenu
*dir_menu
= new wxMenu
;
362 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, wxT("&Choose a directory\tCtrl-D"));
363 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
364 menuDlg
->Append(wxID_ANY
,wxT("&Directory operations"),dir_menu
);
366 #if USE_DIRDLG_GENERIC
367 dir_menu
->AppendSeparator();
368 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, wxT("&Choose a directory (generic)"));
369 #endif // USE_DIRDLG_GENERIC
371 #endif // wxUSE_DIRDLG
374 #if wxUSE_STARTUP_TIPS || \
375 wxUSE_PROGRESSDLG || \
377 wxUSE_LOG_DIALOG || \
380 wxMenu
*info_menu
= new wxMenu
;
382 #if wxUSE_STARTUP_TIPS
383 info_menu
->Append(DIALOGS_TIP
, wxT("&Tip of the day\tCtrl-T"));
384 #endif // wxUSE_STARTUP_TIPS
386 #if wxUSE_PROGRESSDLG
387 info_menu
->Append(DIALOGS_PROGRESS
, wxT("Pro&gress dialog\tCtrl-G"));
388 #endif // wxUSE_PROGRESSDLG
391 info_menu
->Append(DIALOGS_BUSYINFO
, wxT("&Busy info dialog\tCtrl-B"));
392 #endif // wxUSE_BUSYINFO
395 info_menu
->Append(DIALOGS_LOG_DIALOG
, wxT("&Log dialog\tCtrl-L"));
396 #endif // wxUSE_LOG_DIALOG
399 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
400 wxT("&wxWidgets information\tCtrl-I"));
401 #endif // wxUSE_MSGDLG
403 menuDlg
->Append(wxID_ANY
,wxT("&Informative dialogs"),info_menu
);
405 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
408 #if wxUSE_FINDREPLDLG
409 wxMenu
*find_menu
= new wxMenu
;
410 find_menu
->AppendCheckItem(DIALOGS_FIND
, wxT("&Find dialog\tCtrl-F"));
411 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, wxT("Find and &replace dialog\tShift-Ctrl-F"));
412 menuDlg
->Append(wxID_ANY
,wxT("&Searching"),find_menu
);
413 #endif // wxUSE_FINDREPLDLG
415 wxMenu
*dialogs_menu
= new wxMenu
;
416 #if USE_MODAL_PRESENTATION
417 dialogs_menu
->Append(DIALOGS_MODAL
, wxT("&Modal dialog\tCtrl-W"));
418 #endif // USE_MODAL_PRESENTATION
419 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, wxT("Mode&less dialog\tCtrl-Z"));
420 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, wxT("Centered on &screen\tShift-Ctrl-1"));
421 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, wxT("Centered on &parent\tShift-Ctrl-2"));
423 dialogs_menu
->Append(DIALOGS_MINIFRAME
, wxT("&Mini frame"));
424 #endif // wxUSE_MINIFRAME
425 dialogs_menu
->Append(DIALOGS_ONTOP
, wxT("Dialog staying on &top"));
426 menuDlg
->Append(wxID_ANY
, wxT("&Generic dialogs"), dialogs_menu
);
428 #if USE_SETTINGS_DIALOG
429 wxMenu
*sheet_menu
= new wxMenu
;
430 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, wxT("&Standard property sheet\tShift-Ctrl-P"));
431 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, wxT("&Toolbook sheet\tShift-Ctrl-T"));
433 if (wxPlatformIs(wxPORT_MAC
))
434 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
437 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
440 menuDlg
->Append(wxID_ANY
, wxT("&Property sheets"), sheet_menu
);
441 #endif // USE_SETTINGS_DIALOG
443 wxMenu
*menuNotif
= new wxMenu
;
444 menuNotif
->Append(DIALOGS_REQUEST
, wxT("&Request user attention\tCtrl-Shift-R"));
445 #if wxUSE_NOTIFICATION_MESSAGE
446 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
447 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
448 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
449 #endif // wxUSE_NOTIFICATION_MESSAGE
450 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
452 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, wxT("&Standard Buttons Sizer Dialog"));
453 menuDlg
->Append(DIALOGS_TEST_DEFAULT_ACTION
, wxT("&Test dialog default action"));
455 menuDlg
->AppendSeparator();
456 menuDlg
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"));
459 wxMenu
*menuHelp
= new wxMenu
;
460 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, wxT("&About (simple)...\tF1"));
461 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, wxT("About (&fancy)...\tShift-F1"));
462 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, wxT("About (f&ull)...\tCtrl-F1"));
463 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, wxT("About (&custom)...\tCtrl-Shift-F1"));
464 #endif // wxUSE_ABOUTDLG
466 wxMenuBar
*menubar
= new wxMenuBar
;
467 menubar
->Append(menuDlg
, wxT("&Dialogs"));
469 menubar
->Append(menuHelp
, wxT("&Help"));
470 #endif // wxUSE_ABOUTDLG
472 frame
->SetMenuBar(menubar
);
474 frame
->Centre(wxBOTH
);
480 // My frame constructor
481 MyFrame::MyFrame(const wxString
& title
)
482 : wxFrame(NULL
, wxID_ANY
, title
)
486 #if USE_MODAL_PRESENTATION
487 m_dialog
= (MyModelessDialog
*)NULL
;
488 #endif // USE_MODAL_PRESENTATION
490 #if wxUSE_FINDREPLDLG
496 m_clrData
.SetChooseFull(true);
497 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
499 unsigned char n
= i
*16;
500 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
502 #endif // wxUSE_COLOURDLG
504 #if wxUSE_NOTIFICATION_MESSAGE
506 #endif // wxUSE_NOTIFICATION_MESSAGE
510 #endif // wxUSE_STATUSBAR
512 m_canvas
= new MyCanvas(this);
517 #if wxUSE_NOTIFICATION_MESSAGE
519 #endif // wxUSE_NOTIFICATION_MESSAGE
524 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
526 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
528 wxColourDialog
dialog(this, &m_clrData
);
529 dialog
.SetTitle(_("Please choose the background colour"));
530 if ( dialog
.ShowModal() == wxID_OK
)
532 m_clrData
= dialog
.GetColourData();
533 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
534 m_canvas
->ClearBackground();
539 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
541 wxColour clr
= wxGetColourFromUser
544 m_canvas
->GetForegroundColour(),
545 "Please choose the foreground colour"
549 m_canvas
->SetForegroundColour(clr
);
552 //else: dialog cancelled by user
555 #endif // wxUSE_COLOURDLG
558 #if USE_COLOURDLG_GENERIC
559 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
561 m_clrData
.SetColour(m_canvas
->GetBackgroundColour());
563 //FIXME:TODO:This has no effect...
564 m_clrData
.SetChooseFull(true);
566 for (int i
= 0; i
< 16; i
++)
569 (unsigned char)(i
*16),
570 (unsigned char)(i
*16),
571 (unsigned char)(i
*16)
573 m_clrData
.SetCustomColour(i
, colour
);
576 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
577 if (dialog
->ShowModal() == wxID_OK
)
579 m_clrData
= dialog
->GetColourData();
580 m_canvas
->SetBackgroundColour(m_clrData
.GetColour());
581 m_canvas
->ClearBackground();
586 #endif // USE_COLOURDLG_GENERIC
589 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
592 data
.SetInitialFont(m_canvas
->GetFont());
593 data
.SetColour(m_canvas
->GetForegroundColour());
595 // you might also do this:
597 // wxFontDialog dialog;
598 // if ( !dialog.Create(this, data) { ... error ... }
600 wxFontDialog
dialog(this, data
);
602 if (dialog
.ShowModal() == wxID_OK
)
604 wxFontData retData
= dialog
.GetFontData();
605 m_canvas
->SetFont(retData
.GetChosenFont());
606 m_canvas
->SetForegroundColour(retData
.GetColour());
609 //else: cancelled by the user, don't change the font
611 #endif // wxUSE_FONTDLG
613 #if USE_FONTDLG_GENERIC
614 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
617 data
.SetInitialFont(m_canvas
->GetFont());
618 data
.SetColour(m_canvas
->GetForegroundColour());
620 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
621 if (dialog
->ShowModal() == wxID_OK
)
623 wxFontData retData
= dialog
->GetFontData();
624 m_canvas
->SetFont(retData
.GetChosenFont());
625 m_canvas
->SetForegroundColour(retData
.GetColour());
630 #endif // USE_FONTDLG_GENERIC
633 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
635 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
636 // being flushed -- test it
639 wxLogMessage(wxT("This is some message - everything is ok so far."));
640 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
641 wxLogWarning(wxT("And then something went wrong!"));
643 // and if ~wxBusyCursor doesn't do it, then call it manually
647 wxLogError(wxT("Intermediary error handler decided to abort."));
648 wxLogError(wxT("The top level caller detected an unrecoverable error."));
650 wxLog::FlushActive();
652 wxLogMessage(wxT("And this is the same dialog but with only one message."));
654 #endif // wxUSE_LOG_DIALOG
657 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
))
659 wxMessageDialog
dialog(this,
660 "This is a message box\n"
661 "This is a long, long string to test out if the message box "
662 "is laid out properly.",
665 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
|
669 if ( dialog
.SetYesNoCancelLabels
676 extmsg
= "This platform supports custom button labels,\n"
677 "so you should see the descriptive labels below.";
681 extmsg
= "Custom button labels are not supported on this platform,\n"
682 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
684 dialog
.SetExtendedMessage(extmsg
);
686 switch ( dialog
.ShowModal() )
689 wxLogStatus(wxT("You pressed \"Yes\""));
693 wxLogStatus(wxT("You pressed \"No\""));
697 wxLogStatus(wxT("You pressed \"Cancel\""));
701 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
705 void MyFrame::MessageBoxDialog(wxCommandEvent
& WXUNUSED(event
))
707 TestMessageBoxDialog
dlg(this);
711 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
713 ::wxInfoMessageBox(this);
715 #endif // wxUSE_MSGDLG
718 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
720 long res
= wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
721 wxT("Even two rows of text."),
722 wxT("Enter a number:"), wxT("Numeric input test"),
729 msg
= wxT("Invalid number entered or dialog cancelled.");
734 msg
.Printf(wxT("You've entered %lu"), res
);
735 icon
= wxICON_INFORMATION
;
738 wxMessageBox(msg
, wxT("Numeric test result"), wxOK
| icon
, this);
740 #endif // wxUSE_NUMBERDLG
743 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
745 wxString pwd
= wxGetPasswordFromUser(wxT("Enter password:"),
746 wxT("Password entry dialog"),
751 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
752 wxT("Got password"), wxOK
| wxICON_INFORMATION
, this);
756 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
758 wxTextEntryDialog
dialog(this,
759 wxT("This is a small sample\n")
760 wxT("A long, long string to test out the text entrybox"),
761 wxT("Please enter a string"),
762 wxT("Default value"),
765 if (dialog
.ShowModal() == wxID_OK
)
767 wxMessageBox(dialog
.GetValue(), wxT("Got string"), wxOK
| wxICON_INFORMATION
, this);
770 #endif // wxUSE_TEXTDLG
773 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
775 const wxString choices
[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
777 wxSingleChoiceDialog
dialog(this,
778 wxT("This is a small sample\n")
779 wxT("A single-choice convenience dialog"),
780 wxT("Please select a value"),
781 WXSIZEOF(choices
), choices
);
783 dialog
.SetSelection(2);
785 if (dialog
.ShowModal() == wxID_OK
)
787 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), wxT("Got string"));
792 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
794 const wxString choices
[] =
796 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
797 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
798 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
801 wxArrayInt selections
;
802 const int count
= wxGetSelectedChoices(selections
,
803 wxT("This is a small sample\n")
804 wxT("A multi-choice convenience dialog"),
805 wxT("Please select a value"),
806 WXSIZEOF(choices
), choices
,
813 msg
= wxT("You did not select any items");
817 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
818 for ( int n
= 0; n
< count
; n
++ )
820 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
821 (unsigned)n
, (unsigned)selections
[n
],
822 choices
[selections
[n
]].c_str());
829 #endif // wxUSE_CHOICEDLG
831 #if wxUSE_REARRANGECTRL
832 // custom rearrange dialog: it adds the possibility to rename an item to the
833 // base class functionality
834 class MyRearrangeDialog
: public wxRearrangeDialog
837 MyRearrangeDialog(wxWindow
*parent
,
839 wxArrayString
& labels
,
840 wxArrayString
& labelsOrig
)
844 "Configure the columns shown:",
845 "wxRearrangeDialog example",
851 m_labelsOrig(labelsOrig
)
855 wxPanel
* const panel
= new wxPanel(this);
856 wxSizer
* const sizer
= new wxBoxSizer(wxHORIZONTAL
);
858 m_labelOrig
= new wxStaticText(panel
, wxID_ANY
, "");
859 sizer
->Add(m_labelOrig
, wxSizerFlags().Centre().Border(wxRIGHT
));
861 m_text
= new wxTextCtrl(panel
, wxID_ANY
, "",
862 wxDefaultPosition
, wxDefaultSize
,
864 sizer
->Add(m_text
, wxSizerFlags().Centre().Border(wxRIGHT
));
866 sizer
->Add(new wxButton(panel
, wxID_APPLY
, "&Rename"),
867 wxSizerFlags().Centre());
869 panel
->SetSizer(sizer
);
871 // call this first to ensure that the controls have a reasonable best
872 // size before they're added
873 DoUpdateExtraControls(GetList()->GetSelection());
875 AddExtraControls(panel
);
878 // another customization not directly supported by the dialog: add a
880 wxWindow
* const btnOk
= FindWindow(wxID_OK
);
881 wxCHECK_RET( btnOk
, "no Ok button?" );
883 wxSizer
* const sizerBtns
= btnOk
->GetContainingSizer();
884 wxCHECK_RET( sizerBtns
, "no buttons sizer?" );
886 sizerBtns
->Add(new wxButton(this, wxID_RESET
, "&Reset all"),
887 wxSizerFlags().Border(wxLEFT
));
890 // call this instead of ShowModal() to update order and labels array in
891 // case the dialog was not cancelled
894 switch ( ShowModal() )
900 m_order
= GetOrder();
904 // order already reset
912 void OnSelChange(wxCommandEvent
& event
)
914 DoUpdateExtraControls(event
.GetInt());
917 void OnUpdateUIRename(wxUpdateUIEvent
& event
)
919 event
.Enable( CanRename() );
922 void OnRename(wxCommandEvent
& WXUNUSED(event
))
927 m_labels
[m_sel
] = m_text
->GetValue();
928 GetList()->SetString(m_sel
, m_labels
[m_sel
]);
931 void OnReset(wxCommandEvent
& WXUNUSED(event
))
933 // in a real program we should probably ask if the user really wants to
934 // do this but here we just go ahead and reset all columns labels and
935 // their order without confirmation
936 const unsigned count
= m_order
.size();
937 for ( unsigned n
= 0; n
< count
; n
++ )
940 m_labels
[n
] = m_labelsOrig
[n
];
943 EndModal(wxID_RESET
);
946 bool CanRename() const
948 // only allow renaming if the user modified the currently selected item
949 // text (which presupposes that we do have a current item)
950 return m_sel
!= wxNOT_FOUND
&& m_text
->GetValue() != m_labels
[m_sel
];
953 void DoUpdateExtraControls(int sel
)
957 if ( m_sel
== wxNOT_FOUND
)
959 m_labelOrig
->SetLabel("<no selection>");
963 else // have valid item
965 m_labelOrig
->SetLabelText(m_labelsOrig
[m_sel
]);
967 m_text
->SetValue(m_labels
[m_sel
]);
972 wxArrayString
& m_labels
,
976 wxStaticText
*m_labelOrig
;
979 DECLARE_EVENT_TABLE()
980 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog
);
983 BEGIN_EVENT_TABLE(MyRearrangeDialog
, wxRearrangeDialog
)
984 EVT_LISTBOX(wxID_ANY
, MyRearrangeDialog::OnSelChange
)
986 EVT_UPDATE_UI(wxID_APPLY
, MyRearrangeDialog::OnUpdateUIRename
)
988 EVT_TEXT_ENTER(wxID_ANY
, MyRearrangeDialog::OnRename
)
989 EVT_BUTTON(wxID_APPLY
, MyRearrangeDialog::OnRename
)
990 EVT_BUTTON(wxID_RESET
, MyRearrangeDialog::OnReset
)
993 void MyFrame::Rearrange(wxCommandEvent
& WXUNUSED(event
))
995 // the arrays are static so that we preserve the items order between calls
997 static wxArrayInt s_order
;
998 static wxArrayString s_labels
,
1001 // initialize them on the first call
1002 if ( s_labelsOrig
.empty() )
1004 static const struct ItemInfo
1007 const char *labelOrig
;
1011 { "File name", "Name", 0 },
1012 { "File type", "Ext", 1 },
1013 { "Size", "Size", 2 },
1014 { "Creation time", "Ctime", ~3 }, // negated so hidden
1015 { "Last accessed", "Atime", ~4 },
1016 { "Last modified", "Mtime", 5 },
1019 s_order
.reserve(WXSIZEOF(items
));
1020 s_labels
.reserve(WXSIZEOF(items
));
1021 s_labelsOrig
.reserve(WXSIZEOF(items
));
1022 for ( unsigned n
= 0; n
< WXSIZEOF(items
); n
++ )
1024 const ItemInfo
& item
= items
[n
];
1025 s_order
.push_back(item
.order
);
1026 s_labels
.push_back(item
.label
);
1027 s_labelsOrig
.push_back(item
.labelOrig
);
1031 MyRearrangeDialog
dlg(this, s_order
, s_labels
, s_labelsOrig
);
1032 if ( !dlg
.Rearrange() )
1036 for ( unsigned n
= 0; n
< s_order
.size(); n
++ )
1038 columns
+= wxString::Format("\n %u: ", n
);
1039 int idx
= s_order
[n
];
1042 columns
+= "[hidden] ";
1046 columns
+= s_labels
[idx
];
1047 if ( s_labels
[idx
] != s_labelsOrig
[idx
] )
1049 columns
+= wxString::Format(" (original label: \"%s\")",
1054 wxLogMessage("The columns order now is:%s", columns
);
1056 #endif // wxUSE_REARRANGECTRL
1060 // panel with custom controls for file dialog
1061 class MyExtraPanel
: public wxPanel
1064 MyExtraPanel(wxWindow
*parent
);
1065 void OnCheckBox(wxCommandEvent
& event
) { m_btn
->Enable(event
.IsChecked()); }
1066 wxString
GetInfo() const
1068 return wxString::Format("checkbox value = %d", (int) m_cb
->GetValue());
1075 MyExtraPanel::MyExtraPanel(wxWindow
*parent
)
1078 m_btn
= new wxButton(this, -1, wxT("Custom Button"));
1079 m_btn
->Enable(false);
1080 m_cb
= new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1081 m_cb
->Connect(wxID_ANY
, wxEVT_COMMAND_CHECKBOX_CLICKED
,
1082 wxCommandEventHandler(MyExtraPanel::OnCheckBox
), NULL
, this);
1083 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1084 sizerTop
->Add(m_cb
, wxSizerFlags().Centre().Border());
1085 sizerTop
->AddStretchSpacer();
1086 sizerTop
->Add(m_btn
, wxSizerFlags().Right().Border());
1087 SetSizerAndFit(sizerTop
);
1090 // a static method can be used instead of a function with most of compilers
1091 static wxWindow
* createMyExtraPanel(wxWindow
*parent
)
1093 return new MyExtraPanel(parent
);
1096 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
1101 wxT("Testing open file dialog"),
1105 wxT("C++ files (*.cpp)|*.cpp")
1107 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1111 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1112 dialog
.CentreOnParent();
1113 dialog
.SetDirectory(wxGetHomeDir());
1115 if (dialog
.ShowModal() == wxID_OK
)
1118 wxWindow
* const extra
= dialog
.GetExtraControl();
1119 info
.Printf(wxT("Full file name: %s\n")
1122 wxT("Custom window: %s"),
1123 dialog
.GetPath().c_str(),
1124 dialog
.GetDirectory().c_str(),
1125 dialog
.GetFilename().c_str(),
1126 extra
? static_cast<MyExtraPanel
*>(extra
)->GetInfo()
1127 : wxString("None"));
1128 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1129 dialog2
.ShowModal();
1133 // this shows how to take advantage of specifying a default extension in the
1134 // call to wxFileSelector: it is remembered after each new call and the next
1135 // one will use it by default
1136 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
1138 static wxString s_extDef
;
1139 wxString path
= wxFileSelector(
1140 wxT("Select the file to load"),
1141 wxEmptyString
, wxEmptyString
,
1145 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1146 wxFileSelectorDefaultWildcardStr
,
1147 wxFileSelectorDefaultWildcardStr
1149 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
1156 // it is just a sample, would use wxSplitPath in real program
1157 s_extDef
= path
.AfterLast(wxT('.'));
1159 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1163 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
1165 wxString wildcards
=
1167 wxT("C++ files (*.cpp)|*.cpp");
1171 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1172 wxFileSelectorDefaultWildcardStr
,
1173 wxFileSelectorDefaultWildcardStr
1176 wxFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1177 wxEmptyString
, wxEmptyString
, wildcards
,
1178 wxFD_OPEN
|wxFD_MULTIPLE
);
1180 if (dialog
.ShowModal() == wxID_OK
)
1182 wxArrayString paths
, filenames
;
1184 dialog
.GetPaths(paths
);
1185 dialog
.GetFilenames(filenames
);
1188 size_t count
= paths
.GetCount();
1189 for ( size_t n
= 0; n
< count
; n
++ )
1191 s
.Printf(wxT("File %d: %s (%s)\n"),
1192 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1196 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1199 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1200 dialog2
.ShowModal();
1204 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
1206 wxFileDialog
dialog(this,
1207 wxT("Testing save file dialog"),
1209 wxT("myletter.doc"),
1210 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1211 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1213 dialog
.SetFilterIndex(1);
1215 if (dialog
.ShowModal() == wxID_OK
)
1217 wxLogMessage(wxT("%s, filter %d"),
1218 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1221 #endif // wxUSE_FILEDLG
1223 #if USE_FILEDLG_GENERIC
1224 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1226 wxGenericFileDialog dialog
1229 wxT("Testing open file dialog"),
1232 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1235 dialog
.SetExtraControlCreator(&createMyExtraPanel
);
1236 dialog
.SetDirectory(wxGetHomeDir());
1238 if (dialog
.ShowModal() == wxID_OK
)
1241 info
.Printf(wxT("Full file name: %s\n")
1244 dialog
.GetPath().c_str(),
1245 dialog
.GetDirectory().c_str(),
1246 dialog
.GetFilename().c_str());
1247 wxMessageDialog
dialog2(this, info
, wxT("Selected file"));
1248 dialog2
.ShowModal();
1252 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
1254 // On PocketPC you can disable OK-only dialogs policy using system option
1255 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1256 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1258 wxString wildcards
= wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1259 wxGenericFileDialog
dialog(this, wxT("Testing open multiple file dialog"),
1260 wxEmptyString
, wxEmptyString
, wildcards
,
1263 if (dialog
.ShowModal() == wxID_OK
)
1265 wxArrayString paths
, filenames
;
1267 dialog
.GetPaths(paths
);
1268 dialog
.GetFilenames(filenames
);
1271 size_t count
= paths
.GetCount();
1272 for ( size_t n
= 0; n
< count
; n
++ )
1274 s
.Printf(wxT("File %d: %s (%s)\n"),
1275 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
1279 s
.Printf(wxT("Filter index: %d"), dialog
.GetFilterIndex());
1282 wxMessageDialog
dialog2(this, msg
, wxT("Selected files"));
1283 dialog2
.ShowModal();
1286 // restore system option
1287 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
1290 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
1292 wxGenericFileDialog
dialog(this,
1293 wxT("Testing save file dialog"),
1295 wxT("myletter.doc"),
1296 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1297 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
1299 dialog
.SetFilterIndex(1);
1301 if (dialog
.ShowModal() == wxID_OK
)
1303 wxLogMessage(wxT("%s, filter %d"),
1304 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1307 #endif // USE_FILEDLG_GENERIC
1310 void MyFrame::DoDirChoose(int style
)
1312 // pass some initial dir to wxDirDialog
1314 wxGetHomeDir(&dirHome
);
1316 wxDirDialog
dialog(this, wxT("Testing directory picker"), dirHome
, style
);
1318 if (dialog
.ShowModal() == wxID_OK
)
1320 wxLogMessage(wxT("Selected path: %s"), dialog
.GetPath().c_str());
1324 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1326 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1329 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1331 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1333 #endif // wxUSE_DIRDLG
1335 #if USE_DIRDLG_GENERIC
1336 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1338 // pass some initial dir to wxDirDialog
1340 wxGetHomeDir(&dirHome
);
1342 wxGenericDirDialog
dialog(this, wxT("Testing generic directory picker"), dirHome
);
1344 if (dialog
.ShowModal() == wxID_OK
)
1346 wxMessageDialog
dialog2(this, dialog
.GetPath(), wxT("Selected path"));
1347 dialog2
.ShowModal();
1350 #endif // USE_DIRDLG_GENERIC
1352 #if USE_MODAL_PRESENTATION
1353 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1355 MyModalDialog
dlg(this);
1358 #endif // USE_MODAL_PRESENTATION
1360 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1362 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1368 m_dialog
= new MyModelessDialog(this);
1371 m_dialog
->Show(true);
1375 // If m_dialog is NULL, then possibly the system
1376 // didn't report the checked menu item status correctly.
1377 // It should be true just after the menu item was selected,
1378 // if there was no modeless dialog yet.
1380 wxASSERT( m_dialog
!= NULL
);
1386 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1388 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on screen"),
1389 wxDefaultPosition
, wxSize(200, 100));
1390 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1391 dlg
.CentreOnScreen();
1395 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1397 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog centered on parent"),
1398 wxDefaultPosition
, wxSize(200, 100));
1399 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1400 dlg
.CentreOnParent();
1405 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1407 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, wxT("Mini frame"),
1408 wxDefaultPosition
, wxSize(300, 100),
1409 wxCAPTION
| wxCLOSE_BOX
);
1410 new wxStaticText(frame
,
1412 wxT("Mini frames have slightly different appearance"),
1414 new wxStaticText(frame
,
1416 wxT("from the normal frames but that's the only difference."),
1419 frame
->CentreOnParent();
1422 #endif // wxUSE_MINIFRAME
1424 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1426 wxDialog
dlg(this, wxID_ANY
, wxT("Dialog staying on top of other windows"),
1427 wxDefaultPosition
, wxSize(300, 100),
1428 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1429 (new wxButton(&dlg
, wxID_OK
, wxT("Close")))->Centre();
1433 #if wxUSE_STARTUP_TIPS
1434 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1436 static size_t s_index
= (size_t)-1;
1438 if ( s_index
== (size_t)-1 )
1442 // this is completely bogus, we don't know how many lines are there
1443 // in the file, but who cares, it's a demo only...
1444 s_index
= rand() % 5;
1447 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(wxT("tips.txt"), s_index
);
1449 bool showAtStartup
= wxShowTip(this, tipProvider
);
1451 if ( showAtStartup
)
1453 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1454 wxOK
| wxICON_INFORMATION
, this);
1457 s_index
= tipProvider
->GetCurrentTip();
1460 #endif // wxUSE_STARTUP_TIPS
1462 #if USE_SETTINGS_DIALOG
1463 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1465 SettingsDialog
dialog(this, event
.GetId());
1468 #endif // USE_SETTINGS_DIALOG
1470 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1472 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1476 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1479 #if wxUSE_NOTIFICATION_MESSAGE
1481 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1483 if ( !wxNotificationMessage
1485 "Automatic Notification",
1486 "Nothing important has happened\n"
1487 "this notification will disappear soon."
1490 wxLogStatus("Failed to show notification message");
1494 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1498 m_notifMsg
= new wxNotificationMessage
1500 "wxWidgets Manual Notification",
1501 "You can hide this notification from the menu",
1506 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1508 wxLogStatus("Failed to show manual notification message");
1512 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1514 if ( m_notifMsg
&& !m_notifMsg
->Close() )
1516 wxLogStatus("Failed to hide manual notification message");
1520 #endif // wxUSE_NOTIFICATION_MESSAGE
1522 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1524 StdButtonSizerDialog
dialog(this);
1528 // TestDefaultAction
1530 #define ID_CATCH_LISTBOX_DCLICK 100
1531 #define ID_LISTBOX 101
1533 BEGIN_EVENT_TABLE(TestDefaultActionDialog
, wxDialog
)
1534 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK
, TestDefaultActionDialog::OnCatchListBoxDClick
)
1535 EVT_LISTBOX_DCLICK(ID_LISTBOX
, TestDefaultActionDialog::OnListBoxDClick
)
1538 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow
*parent
) :
1539 wxDialog( parent
, -1, "Test default action" )
1541 m_catchListBoxDClick
= false;
1543 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
1545 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 5, 5 );
1548 wxListBox
*listbox
= new wxListBox( this, ID_LISTBOX
);
1549 listbox
->Append( "String 1" );
1550 listbox
->Append( "String 2" );
1551 listbox
->Append( "String 3" );
1552 listbox
->Append( "String 4" );
1553 grid_sizer
->Add( listbox
);
1554 #endif // wxUSE_LISTBOX
1556 grid_sizer
->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK
, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL
);
1558 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL
);
1559 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1561 grid_sizer
->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxSize(80,-1), wxTE_PROCESS_ENTER
), 0, wxALIGN_CENTRE_VERTICAL
);
1562 grid_sizer
->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL
);
1564 main_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
1566 wxSizer
*button_sizer
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
1568 main_sizer
->Add( button_sizer
, 0, wxALL
|wxGROW
, 5 );
1570 SetSizerAndFit( main_sizer
);
1573 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent
& event
)
1575 event
.Skip( !m_catchListBoxDClick
);
1578 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent
& WXUNUSED(event
))
1580 m_catchListBoxDClick
= !m_catchListBoxDClick
;
1583 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent
& WXUNUSED(event
))
1585 TestDefaultActionDialog
dialog( this );
1589 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1594 #if wxUSE_PROGRESSDLG
1596 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1598 static const int max
= 100;
1600 wxProgressDialog
dialog(wxT("Progress dialog example"),
1601 wxT("An informative message"),
1607 // wxPD_AUTO_HIDE | -- try this as well
1609 wxPD_ESTIMATED_TIME
|
1611 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1615 for ( int i
= 0; i
<= max
; i
++ )
1621 // test both modes of wxProgressDialog behaviour: start in
1622 // indeterminate mode but switch to the determinate one later
1623 const bool determinate
= i
> max
/2;
1627 msg
= wxT("That's all, folks!");
1629 else if ( !determinate
)
1631 msg
= wxT("Testing indeterminate mode");
1633 else if ( determinate
)
1635 msg
= wxT("Now in standard determinate mode");
1638 // will be set to true if "Skip" button was pressed
1642 cont
= dialog
.Update(i
, msg
, &skip
);
1646 cont
= dialog
.Pulse(msg
, &skip
);
1649 // each skip will move progress about quarter forward
1655 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1656 wxT("Progress dialog question"), // caption
1657 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1667 wxLogStatus(wxT("Progress dialog aborted!"));
1671 wxLogStatus(wxT("Countdown from %d finished"), max
);
1675 #endif // wxUSE_PROGRESSDLG
1679 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1681 info
.SetName(wxT("Dialogs Sample"));
1682 info
.SetVersion(wxVERSION_NUM_DOT_STRING
,
1686 wxMINOR_VERSION
% 2 ? "Development" : "Stable",
1687 wxVERSION_NUM_DOT_STRING
1689 info
.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1690 info
.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1691 info
.AddDeveloper(wxT("Vadim Zeitlin"));
1694 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1696 InitAboutInfoMinimal(info
);
1698 info
.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
1701 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1703 InitAboutInfoWebsite(info
);
1705 // we can add a second developer
1706 info
.AddDeveloper(wxT("A.N. Other"));
1708 // or we can add several persons at once like this
1709 static const wxChar
*docwriters
[] =
1711 wxT("First D. Writer"),
1715 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1716 info
.SetLicence(wxString::FromAscii(
1717 " wxWindows Library Licence, Version 3.1\n"
1718 " ======================================\n"
1720 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1722 " Everyone is permitted to copy and distribute verbatim copies\n"
1723 " of this licence document, but changing it is not allowed.\n"
1725 " WXWINDOWS LIBRARY LICENCE\n"
1726 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1728 " ...and so on and so forth...\n"
1731 info
.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
1734 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1736 wxAboutDialogInfo info
;
1737 InitAboutInfoMinimal(info
);
1739 wxAboutBox(info
, this);
1742 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1744 wxAboutDialogInfo info
;
1745 InitAboutInfoWebsite(info
);
1747 wxAboutBox(info
, this);
1750 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1752 wxAboutDialogInfo info
;
1753 InitAboutInfoAll(info
);
1755 wxAboutBox(info
, this);
1758 // a trivial example of a custom dialog class
1759 class MyAboutDialog
: public wxGenericAboutDialog
1762 MyAboutDialog(const wxAboutDialogInfo
& info
, wxWindow
* parent
)
1764 Create(info
, parent
);
1767 // add some custom controls
1768 virtual void DoAddCustomControls()
1770 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1771 AddText(wxT("Some custom text"));
1772 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1776 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1778 wxAboutDialogInfo info
;
1779 InitAboutInfoAll(info
);
1781 MyAboutDialog
dlg(info
, this);
1785 #endif // wxUSE_ABOUTDLG
1789 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1791 wxWindowDisabler disableAll
;
1793 wxBusyInfo
info(wxT("Working, please wait..."), this);
1795 for ( int i
= 0; i
< 18; i
++ )
1805 #endif // wxUSE_BUSYINFO
1807 #if wxUSE_FINDREPLDLG
1809 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1813 delete m_dlgReplace
;
1814 m_dlgReplace
= NULL
;
1818 m_dlgReplace
= new wxFindReplaceDialog
1822 wxT("Find and replace dialog"),
1826 m_dlgReplace
->Show(true);
1830 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1839 m_dlgFind
= new wxFindReplaceDialog
1848 m_dlgFind
->Show(true);
1852 static wxString
DecodeFindDialogEventFlags(int flags
)
1855 str
<< (flags
& wxFR_DOWN
? wxT("down") : wxT("up")) << wxT(", ")
1856 << (flags
& wxFR_WHOLEWORD
? wxT("whole words only, ") : wxT(""))
1857 << (flags
& wxFR_MATCHCASE
? wxT("") : wxT("not "))
1858 << wxT("case sensitive");
1863 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1865 wxEventType type
= event
.GetEventType();
1867 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1869 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1870 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1871 event
.GetFindString().c_str(),
1872 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1874 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1875 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1877 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1878 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? wxT("all ") : wxT(""),
1879 event
.GetFindString().c_str(),
1880 event
.GetReplaceString().c_str(),
1881 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1883 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1885 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1889 if ( dlg
== m_dlgFind
)
1892 idMenu
= DIALOGS_FIND
;
1895 else if ( dlg
== m_dlgReplace
)
1897 txt
= wxT("Replace");
1898 idMenu
= DIALOGS_REPLACE
;
1899 m_dlgReplace
= NULL
;
1903 txt
= wxT("Unknown");
1906 wxFAIL_MSG( wxT("unexpected event") );
1909 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1911 if ( idMenu
!= wxID_ANY
)
1913 GetMenuBar()->Check(idMenu
, false);
1920 wxLogError(wxT("Unknown find dialog event!"));
1924 #endif // wxUSE_FINDREPLDLG
1926 // ----------------------------------------------------------------------------
1928 // ----------------------------------------------------------------------------
1930 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1933 dc
.SetBackgroundMode(wxTRANSPARENT
);
1935 wxT("wxWidgets common dialogs")
1936 #if !defined(__SMARTPHONE__)
1937 wxT(" test application")
1942 #if USE_MODAL_PRESENTATION
1944 // ----------------------------------------------------------------------------
1946 // ----------------------------------------------------------------------------
1948 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1949 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modeless dialog")))
1951 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1953 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, wxT("Press me"));
1954 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, wxT("Should be disabled"));
1957 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1958 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1960 SetSizerAndFit(sizerTop
);
1963 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1965 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
1966 wxOK
| wxICON_INFORMATION
, this);
1969 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1971 if ( event
.CanVeto() )
1973 wxMessageBox(wxT("Use the menu item to close this dialog"),
1974 wxT("Modeless dialog"),
1975 wxOK
| wxICON_INFORMATION
, this);
1981 // ----------------------------------------------------------------------------
1983 // ----------------------------------------------------------------------------
1985 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1986 : wxDialog(parent
, wxID_ANY
, wxString(wxT("Modal dialog")))
1988 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1990 m_btnModal
= new wxButton(this, wxID_ANY
, wxT("&Modal dialog..."));
1991 m_btnModeless
= new wxButton(this, wxID_ANY
, wxT("Mode&less dialog"));
1992 m_btnDelete
= new wxButton(this, wxID_ANY
, wxT("&Delete button"));
1994 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1995 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1996 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1997 sizerTop
->Add(new wxButton(this, wxID_CLOSE
), 0, wxALIGN_CENTER
| wxALL
, 5);
1999 SetSizerAndFit(sizerTop
);
2001 SetEscapeId(wxID_CLOSE
);
2003 m_btnModal
->SetFocus();
2004 m_btnModal
->SetDefault();
2007 void MyModalDialog::OnButton(wxCommandEvent
& event
)
2009 if ( event
.GetEventObject() == m_btnDelete
)
2014 m_btnDelete
->Disable();
2016 else if ( event
.GetEventObject() == m_btnModal
)
2019 wxGetTextFromUser(wxT("Dummy prompt"),
2020 wxT("Modal dialog called from dialog"),
2021 wxEmptyString
, this);
2023 wxMessageBox(wxT("Modal dialog called from dialog"));
2024 #endif // wxUSE_TEXTDLG
2026 else if ( event
.GetEventObject() == m_btnModeless
)
2028 (new MyModelessDialog(this))->Show();
2036 #endif // USE_MODAL_PRESENTATION
2038 // ----------------------------------------------------------------------------
2039 // StdButtonSizerDialog
2040 // ----------------------------------------------------------------------------
2042 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
2043 : wxDialog(parent
, wxID_ANY
, wxString(wxT("StdButtonSizer dialog")),
2044 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
2045 m_buttonsSizer(NULL
)
2047 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2049 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
2050 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
2052 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
2054 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
2056 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2057 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
2059 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
2061 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
2063 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
2065 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
2066 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
2068 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
2070 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
2071 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
2072 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
2074 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
2076 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
2077 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
2079 sizer
->Add(sizerInside1
, 0, 0, 0);
2080 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
2081 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
2082 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2084 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
2085 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
2087 sizer
->Add(sizerInside2
, 0, 0, 0);
2088 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
2089 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
2090 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2092 sizerTop
->Add(sizer
, 0, wxALL
, 5);
2094 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
2095 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
2096 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
2098 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
2100 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
2102 EnableDisableControls();
2104 SetSizerAndFit(sizerTop
);
2110 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
2114 m_buttonsSizer
->DeleteWindows();
2115 GetSizer()->Remove(m_buttonsSizer
);
2118 EnableDisableControls();
2121 unsigned long numButtons
= 0;
2123 if (m_chkboxAffirmativeButton
->IsChecked())
2125 if (m_radiobtnOk
->GetValue())
2130 else if (m_radiobtnYes
->GetValue())
2137 if (m_chkboxDismissButton
->IsChecked())
2139 if (m_radiobtnCancel
->GetValue())
2145 else if (m_radiobtnClose
->GetValue())
2153 if (m_chkboxApply
->IsChecked())
2159 if (m_chkboxNo
->IsChecked())
2165 if (m_chkboxHelp
->IsChecked())
2171 if (m_chkboxNoDefault
->IsChecked())
2173 flags
|= wxNO_DEFAULT
;
2176 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
2177 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
2180 GetSizer()->SetSizeHints(this);
2183 void StdButtonSizerDialog::EnableDisableControls()
2185 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
2187 m_radiobtnOk
->Enable(affButtonEnabled
);
2188 m_radiobtnYes
->Enable(affButtonEnabled
);
2190 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
2192 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
2193 m_radiobtnClose
->Enable(dismissButtonEnabled
);
2196 #if USE_SETTINGS_DIALOG
2197 // ----------------------------------------------------------------------------
2199 // ----------------------------------------------------------------------------
2201 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
2203 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
2206 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
2208 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
2213 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
2214 int resizeBorder
= wxRESIZE_BORDER
;
2222 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
2223 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
2224 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
2226 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
2228 SetSheetStyle(sheetStyle
);
2229 SetSheetInnerBorder(0);
2230 SetSheetOuterBorder(0);
2232 // create a dummy image list with a few icons
2233 const wxSize
imageSize(32, 32);
2235 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
2237 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
2239 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
2241 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
2243 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
2248 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
2249 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
2252 // If using a toolbook, also follow Mac style and don't create buttons
2254 CreateButtons(wxOK
| wxCANCEL
|
2255 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
2258 wxBookCtrlBase
* notebook
= GetBookCtrl();
2259 notebook
->SetImageList(m_imageList
);
2261 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
2262 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
2264 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
2265 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
2270 SettingsDialog::~SettingsDialog()
2275 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
2277 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2279 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2280 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2284 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
2285 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
2286 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2287 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
2291 wxString autoSaveLabel
= _("&Auto-save every");
2292 wxString minsLabel
= _("mins");
2294 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
2295 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
2298 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
2299 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
2302 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2304 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2306 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2307 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
2311 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
2312 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
2313 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2314 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
2316 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2318 panel
->SetSizerAndFit(topSizer
);
2323 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
2325 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
2327 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
2328 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
2330 //// PROJECT OR GLOBAL
2331 wxString globalOrProjectChoices
[2];
2332 globalOrProjectChoices
[0] = _("&New projects");
2333 globalOrProjectChoices
[1] = _("&This project");
2335 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
2336 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
2337 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
2339 projectOrGlobal
->SetSelection(0);
2341 //// BACKGROUND STYLE
2342 wxArrayString backgroundStyleChoices
;
2343 backgroundStyleChoices
.Add(wxT("Colour"));
2344 backgroundStyleChoices
.Add(wxT("Image"));
2345 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
2347 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
2348 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
2350 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
2352 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
2354 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2355 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
2356 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
2358 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2361 //// FONT SIZE SELECTION
2363 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2364 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2366 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2367 wxSize(80, wxDefaultCoord
));
2368 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2370 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2373 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2374 topSizer
->AddSpacer(5);
2376 panel
->SetSizerAndFit(topSizer
);
2381 // ----------------------------------------------------------------------------
2382 // TestMessageBoxDialog
2383 // ----------------------------------------------------------------------------
2386 const TestMessageBoxDialog::BtnInfo
TestMessageBoxDialog::ms_btnInfo
[] =
2391 { wxCANCEL
, "&Cancel" },
2394 BEGIN_EVENT_TABLE(TestMessageBoxDialog
, wxDialog
)
2395 EVT_BUTTON(wxID_APPLY
, TestMessageBoxDialog::OnApply
)
2396 EVT_BUTTON(wxID_CLOSE
, TestMessageBoxDialog::OnClose
)
2399 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow
*parent
)
2400 : wxDialog(parent
, wxID_ANY
, "Message Box Test Dialog",
2401 wxDefaultPosition
, wxDefaultSize
,
2402 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
2404 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
2406 // this sizer allows to configure the messages shown in the message box
2408 sizerMsgs
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Messages");
2409 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Main message:"));
2410 m_textMsg
= new wxTextCtrl(this, wxID_ANY
, "Hello from a box!",
2411 wxDefaultPosition
, wxDefaultSize
,
2413 sizerMsgs
->Add(m_textMsg
, wxSizerFlags(1).Expand().Border(wxBOTTOM
));
2415 sizerMsgs
->Add(new wxStaticText(this, wxID_ANY
, "&Extended message:"));
2416 m_textExtMsg
= new wxTextCtrl(this, wxID_ANY
, "",
2417 wxDefaultPosition
, wxDefaultSize
,
2419 sizerMsgs
->Add(m_textExtMsg
, wxSizerFlags(1).Expand());
2421 sizerTop
->Add(sizerMsgs
, wxSizerFlags(1).Expand().Border());
2424 // this one is for configuring the buttons
2425 wxFlexGridSizer
* const sizerBtns
= new wxFlexGridSizer(2, 5, 5);
2426 sizerBtns
->AddGrowableCol(1);
2428 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Button(s)"));
2429 sizerBtns
->Add(new wxStaticText(this, wxID_ANY
, "Custom label"));
2431 for ( int n
= 0; n
< Btn_Max
; n
++ )
2433 m_buttons
[n
] = new wxCheckBox(this, wxID_ANY
, ms_btnInfo
[n
].name
);
2434 sizerBtns
->Add(m_buttons
[n
], wxSizerFlags().Centre().Left());
2436 m_labels
[n
] = new wxTextCtrl(this, wxID_ANY
);
2437 sizerBtns
->Add(m_labels
[n
], wxSizerFlags(1).Centre().Expand());
2439 m_labels
[n
]->Connect(wxEVT_UPDATE_UI
,
2440 wxUpdateUIEventHandler(
2441 TestMessageBoxDialog::OnUpdateLabelUI
),
2447 sizerBtnsBox
= new wxStaticBoxSizer(wxVERTICAL
, this, "&Buttons");
2448 sizerBtnsBox
->Add(sizerBtns
, wxSizerFlags(1).Expand());
2449 sizerTop
->Add(sizerBtnsBox
, wxSizerFlags().Expand().Border());
2453 const wxString icons
[] = {
2454 "&None", "&Information", "&Question", "&Warning", "&Error"
2457 m_icons
= new wxRadioBox(this, wxID_ANY
, "&Icons",
2458 wxDefaultPosition
, wxDefaultSize
,
2459 WXSIZEOF(icons
), icons
);
2460 // Make the 'Information' icon the default one:
2461 m_icons
->SetSelection(1);
2462 sizerTop
->Add(m_icons
, wxSizerFlags().Expand().Border());
2465 // miscellaneous other stuff
2467 sizerFlags
= new wxStaticBoxSizer(wxHORIZONTAL
, this, "&Other flags");
2469 m_chkNoDefault
= new wxCheckBox(this, wxID_ANY
, "Make \"No\" &default");
2470 m_chkNoDefault
->Connect(wxEVT_UPDATE_UI
,
2471 wxUpdateUIEventHandler(
2472 TestMessageBoxDialog::OnUpdateNoDefaultUI
),
2475 sizerFlags
->Add(m_chkNoDefault
, wxSizerFlags(1).Border());
2477 m_chkCentre
= new wxCheckBox(this, wxID_ANY
, "Centre on &parent");
2478 sizerFlags
->Add(m_chkCentre
, wxSizerFlags(1).Border());
2480 sizerTop
->Add(sizerFlags
, wxSizerFlags().Expand().Border());
2482 // finally buttons to show the resulting message box and close this dialog
2483 sizerTop
->Add(CreateStdDialogButtonSizer(wxAPPLY
| wxCLOSE
),
2484 wxSizerFlags().Right().Border());
2486 SetSizerAndFit(sizerTop
);
2488 m_buttons
[Btn_Ok
]->SetValue(true);
2491 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent
& event
)
2493 for ( int n
= 0; n
< Btn_Max
; n
++ )
2495 if ( event
.GetEventObject() == m_labels
[n
] )
2497 event
.Enable( m_buttons
[n
]->IsChecked() );
2502 wxFAIL_MSG( "called for unknown label" );
2505 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent
& event
)
2507 event
.Enable( m_buttons
[Btn_No
]->IsChecked() );
2510 void TestMessageBoxDialog::OnApply(wxCommandEvent
& WXUNUSED(event
))
2514 for ( int n
= 0; n
< Btn_Max
; n
++ )
2516 if ( m_buttons
[n
]->IsChecked() )
2517 style
|= ms_btnInfo
[n
].flag
;
2520 switch ( m_icons
->GetSelection() )
2522 case 0: style
|= wxICON_NONE
; break;
2523 case 1: style
|= wxICON_INFORMATION
; break;
2524 case 2: style
|= wxICON_QUESTION
; break;
2525 case 3: style
|= wxICON_WARNING
; break;
2526 case 4: style
|= wxICON_ERROR
; break;
2529 if ( m_chkCentre
->IsChecked() )
2532 if ( m_chkNoDefault
->IsEnabled() && m_chkNoDefault
->IsChecked() )
2533 style
|= wxNO_DEFAULT
;
2536 wxMessageDialog
dlg(this, m_textMsg
->GetValue(), "Test Message Box",
2538 if ( !m_textExtMsg
->IsEmpty() )
2539 dlg
.SetExtendedMessage(m_textExtMsg
->GetValue());
2541 if ( style
& wxYES_NO
)
2543 if ( style
& wxCANCEL
)
2545 dlg
.SetYesNoCancelLabels(m_labels
[Btn_Yes
]->GetValue(),
2546 m_labels
[Btn_No
]->GetValue(),
2547 m_labels
[Btn_Cancel
]->GetValue());
2551 dlg
.SetYesNoLabels(m_labels
[Btn_Yes
]->GetValue(),
2552 m_labels
[Btn_No
]->GetValue());
2557 if ( style
& wxCANCEL
)
2559 dlg
.SetOKCancelLabels(m_labels
[Btn_Ok
]->GetValue(),
2560 m_labels
[Btn_Cancel
]->GetValue());
2564 dlg
.SetOKLabel(m_labels
[Btn_Ok
]->GetValue());
2571 void TestMessageBoxDialog::OnClose(wxCommandEvent
& WXUNUSED(event
))
2573 EndModal(wxID_CANCEL
);
2576 #endif // USE_SETTINGS_DIALOG
2580 // ----------------------------------------------------------------------------
2581 // custom log target
2582 // ----------------------------------------------------------------------------
2584 class MyLogGui
: public wxLogGui
2587 virtual void DoShowSingleLogMessage(const wxString
& message
,
2588 const wxString
& title
,
2591 wxMessageDialog
dlg(NULL
, message
, title
,
2592 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| style
);
2593 dlg
.SetOKCancelLabels(wxID_COPY
, wxID_OK
);
2594 dlg
.SetExtendedMessage("Note that this is a custom log dialog.");
2599 wxLog
*MyAppTraits::CreateLogTarget()
2601 return new MyLogGui
;