1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustements for conditional building + new menu
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "../sample.xpm"
25 #include "wx/datetime.h"
27 #include "wx/bookctrl.h"
28 #include "wx/artprov.h"
29 #include "wx/imaglist.h"
30 #include "wx/minifram.h"
31 #include "wx/sysopt.h"
32 #include "wx/notifmsg.h"
35 #include "wx/colordlg.h"
36 #endif // wxUSE_COLOURDLG
39 #include "wx/choicdlg.h"
40 #endif // wxUSE_CHOICEDLG
42 #if wxUSE_STARTUP_TIPS
43 #include "wx/tipdlg.h"
44 #endif // wxUSE_STARTUP_TIPS
47 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
48 #include "wx/datetime.h" // wxDateTime
51 #include "wx/progdlg.h"
52 #endif // wxUSE_PROGRESSDLG
55 #include "wx/aboutdlg.h"
57 // these headers are only needed for custom about dialog
58 #include "wx/statline.h"
59 #include "wx/generic/aboutdlgg.h"
60 #endif // wxUSE_ABOUTDLG
63 #include "wx/busyinfo.h"
64 #endif // wxUSE_BUSYINFO
67 #include "wx/numdlg.h"
68 #endif // wxUSE_NUMBERDLG
71 #include "wx/filedlg.h"
72 #endif // wxUSE_FILEDLG
75 #include "wx/dirdlg.h"
76 #endif // wxUSE_DIRDLG
79 #include "wx/fontdlg.h"
80 #endif // wxUSE_FONTDLG
83 #include "wx/fdrepdlg.h"
84 #endif // wxUSE_FINDREPLDLG
87 #include "wx/spinctrl.h"
90 #include "wx/propdlg.h"
94 #if USE_COLOURDLG_GENERIC
95 #include "wx/generic/colrdlgg.h"
96 #endif // USE_COLOURDLG_GENERIC
98 #if USE_DIRDLG_GENERIC
99 #include "wx/generic/dirdlgg.h"
100 #endif // USE_DIRDLG_GENERIC
102 #if USE_FILEDLG_GENERIC
103 #include "wx/generic/filedlgg.h"
104 #endif // USE_FILEDLG_GENERIC
106 #if USE_FONTDLG_GENERIC
107 #include "wx/generic/fontdlgg.h"
108 #endif // USE_FONTDLG_GENERIC
112 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
113 EVT_PAINT(MyCanvas::OnPaint
)
118 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
120 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
121 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
122 #endif // wxUSE_MSGDLG
124 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
125 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
126 #endif // wxUSE_COLOURDLG
129 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
130 #endif // wxUSE_FONTDLG
133 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
134 #endif // wxUSE_LOG_DIALOG
137 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
138 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
139 #endif // wxUSE_TEXTDLG
142 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
143 #endif // wxUSE_NUMBERDLG
146 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
147 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
148 #endif // wxUSE_CHOICEDLG
151 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
152 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
153 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
154 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
155 #endif // wxUSE_FILEDLG
157 #if USE_FILEDLG_GENERIC
158 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
159 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
160 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
161 #endif // USE_FILEDLG_GENERIC
164 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
165 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
166 #endif // wxUSE_DIRDLG
168 #if USE_MODAL_PRESENTATION
169 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
170 #endif // USE_MODAL_PRESENTATION
171 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
172 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
173 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
174 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
175 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
177 #if wxUSE_STARTUP_TIPS
178 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
179 #endif // wxUSE_STARTUP_TIPS
181 #if USE_FONTDLG_GENERIC
182 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
183 #endif // USE_FONTDLG_GENERIC
185 #if USE_DIRDLG_GENERIC
186 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
187 #endif // wxMSW || wxMAC
189 #if USE_COLOURDLG_GENERIC
190 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
191 #endif // USE_COLOURDLG_GENERIC
193 #if wxUSE_PROGRESSDLG
194 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
195 #endif // wxUSE_PROGRESSDLG
198 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
199 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
200 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
201 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
202 #endif // wxUSE_ABOUTDLG
205 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
206 #endif // wxUSE_BUSYINFO
208 #if wxUSE_FINDREPLDLG
209 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
210 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
212 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
213 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
214 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
215 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
216 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
217 #endif // wxUSE_FINDREPLDLG
219 #if USE_SETTINGS_DIALOG
220 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
221 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
222 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
223 #endif // USE_SETTINGS_DIALOG
225 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
227 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
228 #if wxUSE_NOTIFICATION_MESSAGE
229 EVT_MENU(DIALOGS_NOTIFY_AUTO
, MyFrame::OnNotifMsgAuto
)
230 EVT_MENU(DIALOGS_NOTIFY_SHOW
, MyFrame::OnNotifMsgShow
)
231 EVT_MENU(DIALOGS_NOTIFY_HIDE
, MyFrame::OnNotifMsgHide
)
232 #endif // wxUSE_NOTIFICATION_MESSAGE
234 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
237 #if USE_MODAL_PRESENTATION
239 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
240 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
243 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
244 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
245 EVT_CLOSE(MyModelessDialog::OnClose
)
248 #endif // USE_MODAL_PRESENTATION
250 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
251 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
252 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
255 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
257 // `Main program' equivalent, creating windows and returning main app frame
260 if ( !wxApp::OnInit() )
264 wxInitAllImageHandlers();
267 m_canvasTextColour
= *wxBLACK
;
268 m_canvasFont
= *wxNORMAL_FONT
;
270 // Create the main frame window
271 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
274 wxMenu
*menuDlg
= new wxMenu
;
276 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
279 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
281 wxMenu
*choices_menu
= new wxMenu
;
284 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose bg colour"));
285 choices_menu
->Append(DIALOGS_GET_COLOUR
, _T("&Choose fg colour"));
286 #endif // wxUSE_COLOURDLG
289 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
290 #endif // wxUSE_FONTDLG
293 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
294 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
295 #endif // wxUSE_CHOICEDLG
297 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
298 choices_menu
->AppendSeparator();
299 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
301 #if USE_COLOURDLG_GENERIC
302 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
303 #endif // USE_COLOURDLG_GENERIC
305 #if USE_FONTDLG_GENERIC
306 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
307 #endif // USE_FONTDLG_GENERIC
309 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
310 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
313 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
315 wxMenu
*entry_menu
= new wxMenu
;
318 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
319 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
320 #endif // wxUSE_TEXTDLG
323 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
324 #endif // wxUSE_NUMBERDLG
326 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
328 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
333 wxMenu
*filedlg_menu
= new wxMenu
;
334 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
335 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
336 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
337 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
339 #if USE_FILEDLG_GENERIC
340 filedlg_menu
->AppendSeparator();
341 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
342 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
343 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
344 #endif // USE_FILEDLG_GENERIC
346 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
348 #endif // wxUSE_FILEDLG
351 wxMenu
*dir_menu
= new wxMenu
;
353 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
354 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
355 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
357 #if USE_DIRDLG_GENERIC
358 dir_menu
->AppendSeparator();
359 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
360 #endif // USE_DIRDLG_GENERIC
362 #endif // wxUSE_DIRDLG
365 #if wxUSE_STARTUP_TIPS || \
366 wxUSE_PROGRESSDLG || \
368 wxUSE_LOG_DIALOG || \
371 wxMenu
*info_menu
= new wxMenu
;
373 #if wxUSE_STARTUP_TIPS
374 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
375 #endif // wxUSE_STARTUP_TIPS
377 #if wxUSE_PROGRESSDLG
378 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
379 #endif // wxUSE_PROGRESSDLG
382 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
383 #endif // wxUSE_BUSYINFO
386 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
387 #endif // wxUSE_LOG_DIALOG
390 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
391 _T("&wxWidgets information\tCtrl-I"));
392 #endif // wxUSE_MSGDLG
394 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
396 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
399 #if wxUSE_FINDREPLDLG
400 wxMenu
*find_menu
= new wxMenu
;
401 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
402 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
403 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
404 #endif // wxUSE_FINDREPLDLG
406 wxMenu
*dialogs_menu
= new wxMenu
;
407 #if USE_MODAL_PRESENTATION
408 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
409 #endif // USE_MODAL_PRESENTATION
410 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
411 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
412 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
413 dialogs_menu
->Append(DIALOGS_MINIFRAME
, _T("&Mini frame"));
414 dialogs_menu
->Append(DIALOGS_ONTOP
, _T("Dialog staying on &top"));
415 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
417 #if USE_SETTINGS_DIALOG
418 wxMenu
*sheet_menu
= new wxMenu
;
419 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
420 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
422 if (wxPlatformIs(wxPORT_MAC
))
423 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
426 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
429 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
430 #endif // USE_SETTINGS_DIALOG
432 wxMenu
*menuNotif
= new wxMenu
;
433 menuNotif
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
434 #if wxUSE_NOTIFICATION_MESSAGE
435 menuNotif
->Append(DIALOGS_NOTIFY_AUTO
, "&Automatically hidden notification");
436 menuNotif
->Append(DIALOGS_NOTIFY_SHOW
, "&Show manual notification");
437 menuNotif
->Append(DIALOGS_NOTIFY_HIDE
, "&Hide manual notification");
438 #endif // wxUSE_NOTIFICATION_MESSAGE
439 menuDlg
->AppendSubMenu(menuNotif
, "&User notifications");
441 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, _T("&Standard Buttons Sizer Dialog"));
443 menuDlg
->AppendSeparator();
444 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
447 wxMenu
*menuHelp
= new wxMenu
;
448 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
449 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
450 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
451 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
452 #endif // wxUSE_ABOUTDLG
454 wxMenuBar
*menubar
= new wxMenuBar
;
455 menubar
->Append(menuDlg
, _T("&Dialogs"));
457 menubar
->Append(menuHelp
, _T("&Help"));
458 #endif // wxUSE_ABOUTDLG
460 frame
->SetMenuBar(menubar
);
462 myCanvas
= new MyCanvas(frame
);
463 myCanvas
->SetBackgroundColour(*wxWHITE
);
465 frame
->Centre(wxBOTH
);
475 // My frame constructor
476 MyFrame::MyFrame(wxWindow
*parent
,
477 const wxString
& title
)
478 : wxFrame(parent
, wxID_ANY
, title
)
482 #if USE_MODAL_PRESENTATION
483 m_dialog
= (MyModelessDialog
*)NULL
;
484 #endif // USE_MODAL_PRESENTATION
486 #if wxUSE_FINDREPLDLG
492 m_clrData
.SetChooseFull(true);
493 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
495 unsigned char n
= i
*16;
496 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
498 #endif // wxUSE_COLOURDLG
500 #if wxUSE_NOTIFICATION_MESSAGE
502 #endif // wxUSE_NOTIFICATION_MESSAGE
506 #endif // wxUSE_STATUSBAR
511 #if wxUSE_NOTIFICATION_MESSAGE
513 #endif // wxUSE_NOTIFICATION_MESSAGE
518 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
520 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
522 wxColourDialog
dialog(this, &m_clrData
);
523 dialog
.SetTitle(_("Please choose the background colour"));
524 if ( dialog
.ShowModal() == wxID_OK
)
526 m_clrData
= dialog
.GetColourData();
527 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
528 myCanvas
->ClearBackground();
533 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
535 wxColour clr
= wxGetColourFromUser
538 wxGetApp().m_canvasTextColour
,
539 "Please choose the foreground colour"
543 wxGetApp().m_canvasTextColour
= clr
;
546 //else: dialog cancelled by user
549 #endif // wxUSE_COLOURDLG
552 #if USE_COLOURDLG_GENERIC
553 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
555 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
557 //FIXME:TODO:This has no effect...
558 m_clrData
.SetChooseFull(true);
560 for (int i
= 0; i
< 16; i
++)
563 (unsigned char)(i
*16),
564 (unsigned char)(i
*16),
565 (unsigned char)(i
*16)
567 m_clrData
.SetCustomColour(i
, colour
);
570 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
571 if (dialog
->ShowModal() == wxID_OK
)
573 m_clrData
= dialog
->GetColourData();
574 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
575 myCanvas
->ClearBackground();
580 #endif // USE_COLOURDLG_GENERIC
583 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
586 data
.SetInitialFont(wxGetApp().m_canvasFont
);
587 data
.SetColour(wxGetApp().m_canvasTextColour
);
589 // you might also do this:
591 // wxFontDialog dialog;
592 // if ( !dialog.Create(this, data) { ... error ... }
594 wxFontDialog
dialog(this, data
);
596 if (dialog
.ShowModal() == wxID_OK
)
598 wxFontData retData
= dialog
.GetFontData();
599 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
600 wxGetApp().m_canvasTextColour
= retData
.GetColour();
603 //else: cancelled by the user, don't change the font
605 #endif // wxUSE_FONTDLG
607 #if USE_FONTDLG_GENERIC
608 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
611 data
.SetInitialFont(wxGetApp().m_canvasFont
);
612 data
.SetColour(wxGetApp().m_canvasTextColour
);
614 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
615 if (dialog
->ShowModal() == wxID_OK
)
617 wxFontData retData
= dialog
->GetFontData();
618 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
619 wxGetApp().m_canvasTextColour
= retData
.GetColour();
624 #endif // USE_FONTDLG_GENERIC
627 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
629 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
630 // being flushed -- test it
633 wxLogMessage(wxT("This is some message - everything is ok so far."));
634 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
635 wxLogWarning(wxT("And then something went wrong!"));
637 // and if ~wxBusyCursor doesn't do it, then call it manually
641 wxLogError(wxT("Intermediary error handler decided to abort."));
642 wxLogError(wxT("The top level caller detected an unrecoverable error."));
644 wxLog::FlushActive();
646 wxLogMessage(wxT("And this is the same dialog but with only one message."));
648 #endif // wxUSE_LOG_DIALOG
651 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
653 wxMessageDialog
dialog(NULL
,
654 _T("This is a message box\nA long, long string to test out the message box properly"),
655 _T("Message box text"),
656 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
| wxICON_INFORMATION
);
658 if ( dialog
.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
660 dialog
.SetExtendedMessage(_T("This platform supports custom button labels"));
664 dialog
.SetExtendedMessage(_T("Custom button labels are not supported."));
667 switch ( dialog
.ShowModal() )
670 wxLogStatus(wxT("You pressed \"Yes\""));
674 wxLogStatus(wxT("You pressed \"No\""));
678 wxLogStatus(wxT("You pressed \"Cancel\""));
682 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
686 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
688 ::wxInfoMessageBox(this);
690 #endif // wxUSE_MSGDLG
693 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
695 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
696 _T("Even two rows of text."),
697 _T("Enter a number:"), _T("Numeric input test"),
704 msg
= _T("Invalid number entered or dialog cancelled.");
709 msg
.Printf(_T("You've entered %lu"), res
);
710 icon
= wxICON_INFORMATION
;
713 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
715 #endif // wxUSE_NUMBERDLG
718 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
720 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
721 _T("Password entry dialog"),
726 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
727 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
731 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
733 wxTextEntryDialog
dialog(this,
734 _T("This is a small sample\n")
735 _T("A long, long string to test out the text entrybox"),
736 _T("Please enter a string"),
740 if (dialog
.ShowModal() == wxID_OK
)
742 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
745 #endif // wxUSE_TEXTDLG
748 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
750 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
752 wxSingleChoiceDialog
dialog(this,
753 _T("This is a small sample\n")
754 _T("A single-choice convenience dialog"),
755 _T("Please select a value"),
756 WXSIZEOF(choices
), choices
);
758 dialog
.SetSelection(2);
760 if (dialog
.ShowModal() == wxID_OK
)
762 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
767 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
769 const wxString choices
[] =
771 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
772 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
773 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
776 wxArrayInt selections
;
777 size_t count
= wxGetMultipleChoices(selections
,
778 _T("This is a small sample\n")
779 _T("A multi-choice convenience dialog"),
780 _T("Please select a value"),
781 WXSIZEOF(choices
), choices
,
786 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
787 for ( size_t n
= 0; n
< count
; n
++ )
789 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
790 (unsigned)n
, (unsigned)selections
[n
],
791 choices
[selections
[n
]].c_str());
795 //else: cancelled or nothing selected
797 #endif // wxUSE_CHOICEDLG
800 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
805 _T("Testing open file dialog"),
809 _T("C++ files (*.cpp)|*.cpp")
811 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
815 dialog
.CentreOnParent();
816 dialog
.SetDirectory(wxGetHomeDir());
818 if (dialog
.ShowModal() == wxID_OK
)
821 info
.Printf(_T("Full file name: %s\n")
824 dialog
.GetPath().c_str(),
825 dialog
.GetDirectory().c_str(),
826 dialog
.GetFilename().c_str());
827 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
832 // this shows how to take advantage of specifying a default extension in the
833 // call to wxFileSelector: it is remembered after each new call and the next
834 // one will use it by default
835 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
837 static wxString s_extDef
;
838 wxString path
= wxFileSelector(
839 _T("Select the file to load"),
840 wxEmptyString
, wxEmptyString
,
844 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
845 wxFileSelectorDefaultWildcardStr
,
846 wxFileSelectorDefaultWildcardStr
848 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
855 // it is just a sample, would use wxSplitPath in real program
856 s_extDef
= path
.AfterLast(_T('.'));
858 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
862 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
866 _T("C++ files (*.cpp)|*.cpp");
870 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
871 wxFileSelectorDefaultWildcardStr
,
872 wxFileSelectorDefaultWildcardStr
875 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
876 wxEmptyString
, wxEmptyString
, wildcards
,
877 wxFD_OPEN
|wxFD_MULTIPLE
);
879 if (dialog
.ShowModal() == wxID_OK
)
881 wxArrayString paths
, filenames
;
883 dialog
.GetPaths(paths
);
884 dialog
.GetFilenames(filenames
);
887 size_t count
= paths
.GetCount();
888 for ( size_t n
= 0; n
< count
; n
++ )
890 s
.Printf(_T("File %d: %s (%s)\n"),
891 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
895 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
898 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
903 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
905 wxFileDialog
dialog(this,
906 _T("Testing save file dialog"),
909 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
910 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
912 dialog
.SetFilterIndex(1);
914 if (dialog
.ShowModal() == wxID_OK
)
916 wxLogMessage(_T("%s, filter %d"),
917 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
920 #endif // wxUSE_FILEDLG
922 #if USE_FILEDLG_GENERIC
923 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
925 wxGenericFileDialog dialog
928 _T("Testing open file dialog"),
931 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
934 dialog
.SetDirectory(wxGetHomeDir());
936 if (dialog
.ShowModal() == wxID_OK
)
939 info
.Printf(_T("Full file name: %s\n")
942 dialog
.GetPath().c_str(),
943 dialog
.GetDirectory().c_str(),
944 dialog
.GetFilename().c_str());
945 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
950 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
952 // On PocketPC you can disable OK-only dialogs policy using system option
953 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
954 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
956 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
957 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
958 wxEmptyString
, wxEmptyString
, wildcards
,
961 if (dialog
.ShowModal() == wxID_OK
)
963 wxArrayString paths
, filenames
;
965 dialog
.GetPaths(paths
);
966 dialog
.GetFilenames(filenames
);
969 size_t count
= paths
.GetCount();
970 for ( size_t n
= 0; n
< count
; n
++ )
972 s
.Printf(_T("File %d: %s (%s)\n"),
973 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
977 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
980 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
984 // restore system option
985 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
988 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
990 wxGenericFileDialog
dialog(this,
991 _T("Testing save file dialog"),
994 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
995 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
997 dialog
.SetFilterIndex(1);
999 if (dialog
.ShowModal() == wxID_OK
)
1001 wxLogMessage(_T("%s, filter %d"),
1002 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
1005 #endif // USE_FILEDLG_GENERIC
1008 void MyFrame::DoDirChoose(int style
)
1010 // pass some initial dir to wxDirDialog
1012 wxGetHomeDir(&dirHome
);
1014 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
1016 if (dialog
.ShowModal() == wxID_OK
)
1018 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
1022 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
1024 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1027 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1029 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1031 #endif // wxUSE_DIRDLG
1033 #if USE_DIRDLG_GENERIC
1034 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1036 // pass some initial dir to wxDirDialog
1038 wxGetHomeDir(&dirHome
);
1040 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
1042 if (dialog
.ShowModal() == wxID_OK
)
1044 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
1045 dialog2
.ShowModal();
1048 #endif // USE_DIRDLG_GENERIC
1050 #if USE_MODAL_PRESENTATION
1051 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1053 MyModalDialog
dlg(this);
1056 #endif // USE_MODAL_PRESENTATION
1058 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1060 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1066 m_dialog
= new MyModelessDialog(this);
1069 m_dialog
->Show(true);
1073 // If m_dialog is NULL, then possibly the system
1074 // didn't report the checked menu item status correctly.
1075 // It should be true just after the menu item was selected,
1076 // if there was no modeless dialog yet.
1078 wxASSERT( m_dialog
!= NULL
);
1084 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1086 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1087 wxDefaultPosition
, wxSize(200, 100));
1088 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1089 dlg
.CentreOnScreen();
1093 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1095 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1096 wxDefaultPosition
, wxSize(200, 100));
1097 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1098 dlg
.CentreOnParent();
1102 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1104 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, _T("Mini frame"),
1105 wxDefaultPosition
, wxSize(300, 100),
1106 wxCAPTION
| wxCLOSE_BOX
);
1107 new wxStaticText(frame
,
1109 _T("Mini frames have slightly different appearance"),
1111 new wxStaticText(frame
,
1113 _T("from the normal frames but that's the only difference."),
1116 frame
->CentreOnParent();
1120 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1122 wxDialog
dlg(this, wxID_ANY
, _T("Dialog staying on top of other windows"),
1123 wxDefaultPosition
, wxSize(300, 100),
1124 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1125 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1129 #if wxUSE_STARTUP_TIPS
1130 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1132 static size_t s_index
= (size_t)-1;
1134 if ( s_index
== (size_t)-1 )
1138 // this is completely bogus, we don't know how many lines are there
1139 // in the file, but who cares, it's a demo only...
1140 s_index
= rand() % 5;
1143 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1145 bool showAtStartup
= wxShowTip(this, tipProvider
);
1147 if ( showAtStartup
)
1149 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1150 wxOK
| wxICON_INFORMATION
, this);
1153 s_index
= tipProvider
->GetCurrentTip();
1156 #endif // wxUSE_STARTUP_TIPS
1158 #if USE_SETTINGS_DIALOG
1159 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1161 SettingsDialog
dialog(this, event
.GetId());
1164 #endif // USE_SETTINGS_DIALOG
1166 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1168 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1172 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1175 #if wxUSE_NOTIFICATION_MESSAGE
1177 void MyFrame::OnNotifMsgAuto(wxCommandEvent
& WXUNUSED(event
))
1179 if ( !wxNotificationMessage
1181 "Automatic Notification",
1182 "Nothing important has happened\n"
1183 "this notification will disappear soon."
1186 wxLogStatus("Failed to show notification message");
1190 void MyFrame::OnNotifMsgShow(wxCommandEvent
& WXUNUSED(event
))
1194 m_notifMsg
= new wxNotificationMessage
1196 "wxWidgets Manual Notification",
1197 "You can hide this notification from the menu",
1202 if ( !m_notifMsg
->Show(wxNotificationMessage::Timeout_Never
) )
1204 wxLogStatus("Failed to show manual notification message");
1208 void MyFrame::OnNotifMsgHide(wxCommandEvent
& WXUNUSED(event
))
1212 if ( !m_notifMsg
->Close() )
1213 wxLogStatus("Failed to hide manual notification message");
1217 #endif // wxUSE_NOTIFICATION_MESSAGE
1219 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1221 StdButtonSizerDialog
dialog(this);
1225 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1230 #if wxUSE_PROGRESSDLG
1232 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1234 static const int max
= 100;
1236 wxProgressDialog
dialog(_T("Progress dialog example"),
1237 _T("An informative message"),
1243 // wxPD_AUTO_HIDE | -- try this as well
1245 wxPD_ESTIMATED_TIME
|
1247 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1251 for ( int i
= 0; i
<= max
; i
++ )
1257 // test both modes of wxProgressDialog behaviour: start in
1258 // indeterminate mode but switch to the determinate one later
1259 const bool determinate
= i
> max
/2;
1263 msg
= _T("That's all, folks!");
1265 else if ( !determinate
)
1267 msg
= _T("Testing indeterminate mode");
1269 else if ( determinate
)
1271 msg
= _T("Now in standard determinate mode");
1274 // will be set to true if "Skip" button was pressed
1278 cont
= dialog
.Update(i
, msg
, &skip
);
1282 cont
= dialog
.Pulse(msg
, &skip
);
1285 // each skip will move progress about quarter forward
1291 if ( wxMessageBox(_T("Do you really want to cancel?"),
1292 _T("Progress dialog question"), // caption
1293 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1303 wxLogStatus(wxT("Progress dialog aborted!"));
1307 wxLogStatus(wxT("Countdown from %d finished"), max
);
1311 #endif // wxUSE_PROGRESSDLG
1315 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1317 info
.SetName(_T("Dialogs Sample"));
1318 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1319 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1320 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1321 info
.AddDeveloper(_T("Vadim Zeitlin"));
1324 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1326 InitAboutInfoMinimal(info
);
1328 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1331 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1333 InitAboutInfoMinimal(info
);
1335 // we can add a second developer
1336 info
.AddDeveloper(_T("A.N. Other"));
1338 // or we can add several persons at once like this
1339 static const wxChar
*docwriters
[] =
1341 _T("First D. Writer"),
1345 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1346 info
.SetLicence(wxString::FromAscii(
1347 " wxWindows Library Licence, Version 3.1\n"
1348 " ======================================\n"
1350 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1352 " Everyone is permitted to copy and distribute verbatim copies\n"
1353 " of this licence document, but changing it is not allowed.\n"
1355 " WXWINDOWS LIBRARY LICENCE\n"
1356 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1358 " ...and so on and so forth...\n"
1361 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1364 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1366 wxAboutDialogInfo info
;
1367 InitAboutInfoMinimal(info
);
1372 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1374 wxAboutDialogInfo info
;
1375 InitAboutInfoWebsite(info
);
1380 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1382 wxAboutDialogInfo info
;
1383 InitAboutInfoAll(info
);
1388 // a trivial example of a custom dialog class
1389 class MyAboutDialog
: public wxGenericAboutDialog
1392 MyAboutDialog(const wxAboutDialogInfo
& info
)
1397 // add some custom controls
1398 virtual void DoAddCustomControls()
1400 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1401 AddText(_T("Some custom text"));
1402 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1406 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1408 wxAboutDialogInfo info
;
1409 InitAboutInfoAll(info
);
1411 MyAboutDialog
dlg(info
);
1415 #endif // wxUSE_ABOUTDLG
1419 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1421 wxWindowDisabler disableAll
;
1423 wxBusyInfo
info(_T("Working, please wait..."), this);
1425 for ( int i
= 0; i
< 18; i
++ )
1435 #endif // wxUSE_BUSYINFO
1437 #if wxUSE_FINDREPLDLG
1439 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1443 delete m_dlgReplace
;
1444 m_dlgReplace
= NULL
;
1448 m_dlgReplace
= new wxFindReplaceDialog
1452 _T("Find and replace dialog"),
1456 m_dlgReplace
->Show(true);
1460 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1469 m_dlgFind
= new wxFindReplaceDialog
1478 m_dlgFind
->Show(true);
1482 static wxString
DecodeFindDialogEventFlags(int flags
)
1485 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1486 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1487 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1488 << _T("case sensitive");
1493 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1495 wxEventType type
= event
.GetEventType();
1497 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1499 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1500 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1501 event
.GetFindString().c_str(),
1502 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1504 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1505 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1507 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1508 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1509 event
.GetFindString().c_str(),
1510 event
.GetReplaceString().c_str(),
1511 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1513 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1515 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1519 if ( dlg
== m_dlgFind
)
1522 idMenu
= DIALOGS_FIND
;
1525 else if ( dlg
== m_dlgReplace
)
1527 txt
= _T("Replace");
1528 idMenu
= DIALOGS_REPLACE
;
1529 m_dlgReplace
= NULL
;
1533 txt
= _T("Unknown");
1536 wxFAIL_MSG( _T("unexpected event") );
1539 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1541 if ( idMenu
!= wxID_ANY
)
1543 GetMenuBar()->Check(idMenu
, false);
1550 wxLogError(wxT("Unknown find dialog event!"));
1554 #endif // wxUSE_FINDREPLDLG
1556 // ----------------------------------------------------------------------------
1558 // ----------------------------------------------------------------------------
1560 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1563 dc
.SetFont(wxGetApp().m_canvasFont
);
1564 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1565 dc
.SetBackgroundMode(wxTRANSPARENT
);
1567 _T("wxWidgets common dialogs")
1568 #if !defined(__SMARTPHONE__)
1569 _T(" test application")
1574 #if USE_MODAL_PRESENTATION
1576 // ----------------------------------------------------------------------------
1578 // ----------------------------------------------------------------------------
1580 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1581 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1583 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1585 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1586 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1589 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1590 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1594 sizerTop
->SetSizeHints(this);
1595 sizerTop
->Fit(this);
1598 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1600 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1601 wxOK
| wxICON_INFORMATION
, this);
1604 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1606 if ( event
.CanVeto() )
1608 wxMessageBox(_T("Use the menu item to close this dialog"),
1609 _T("Modeless dialog"),
1610 wxOK
| wxICON_INFORMATION
, this);
1616 // ----------------------------------------------------------------------------
1618 // ----------------------------------------------------------------------------
1620 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1621 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1623 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1625 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1626 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1627 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1629 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1630 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1631 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1632 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1633 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1637 sizerTop
->SetSizeHints(this);
1638 sizerTop
->Fit(this);
1640 m_btnModal
->SetFocus();
1641 m_btnModal
->SetDefault();
1644 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1646 if ( event
.GetEventObject() == m_btnDelete
)
1651 m_btnDelete
->Disable();
1653 else if ( event
.GetEventObject() == m_btnModal
)
1656 wxGetTextFromUser(_T("Dummy prompt"),
1657 _T("Modal dialog called from dialog"),
1658 wxEmptyString
, this);
1660 wxMessageBox(_T("Modal dialog called from dialog"));
1661 #endif // wxUSE_TEXTDLG
1663 else if ( event
.GetEventObject() == m_btnModeless
)
1665 (new MyModelessDialog(this))->Show();
1673 #endif // USE_MODAL_PRESENTATION
1675 // ----------------------------------------------------------------------------
1676 // StdButtonSizerDialog
1677 // ----------------------------------------------------------------------------
1679 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1680 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1681 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1682 m_buttonsSizer(NULL
)
1684 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1686 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1687 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1689 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
1691 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
1693 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1694 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
1696 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
1698 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
1700 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
1702 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1703 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
1705 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
1707 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
1708 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
1709 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
1711 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
1713 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
1714 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
1716 sizer
->Add(sizerInside1
, 0, 0, 0);
1717 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
1718 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
1719 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1721 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
1722 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
1724 sizer
->Add(sizerInside2
, 0, 0, 0);
1725 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
1726 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
1727 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1729 sizerTop
->Add(sizer
, 0, wxALL
, 5);
1731 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
1732 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
1733 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
1735 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
1737 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
1739 EnableDisableControls();
1743 sizerTop
->SetSizeHints(this);
1748 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
1752 m_buttonsSizer
->DeleteWindows();
1753 GetSizer()->Remove(m_buttonsSizer
);
1756 EnableDisableControls();
1759 unsigned long numButtons
= 0;
1761 if (m_chkboxAffirmativeButton
->IsChecked())
1763 if (m_radiobtnOk
->GetValue())
1768 else if (m_radiobtnYes
->GetValue())
1775 if (m_chkboxDismissButton
->IsChecked())
1777 if (m_radiobtnCancel
->GetValue())
1783 else if (m_radiobtnClose
->GetValue())
1791 if (m_chkboxApply
->IsChecked())
1797 if (m_chkboxNo
->IsChecked())
1803 if (m_chkboxHelp
->IsChecked())
1809 if (m_chkboxNoDefault
->IsChecked())
1811 flags
|= wxNO_DEFAULT
;
1814 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
1815 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
1818 GetSizer()->SetSizeHints(this);
1821 void StdButtonSizerDialog::EnableDisableControls()
1823 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
1825 m_radiobtnOk
->Enable(affButtonEnabled
);
1826 m_radiobtnYes
->Enable(affButtonEnabled
);
1828 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
1830 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
1831 m_radiobtnClose
->Enable(dismissButtonEnabled
);
1834 #if USE_SETTINGS_DIALOG
1835 // ----------------------------------------------------------------------------
1837 // ----------------------------------------------------------------------------
1839 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1841 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1844 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1846 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1851 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1852 int resizeBorder
= wxRESIZE_BORDER
;
1860 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1861 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1862 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1864 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1866 SetSheetStyle(sheetStyle
);
1867 SetSheetInnerBorder(0);
1868 SetSheetOuterBorder(0);
1870 // create a dummy image list with a few icons
1871 const wxSize
imageSize(32, 32);
1873 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1875 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1877 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1879 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1881 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1886 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1887 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1890 // If using a toolbook, also follow Mac style and don't create buttons
1892 CreateButtons(wxOK
| wxCANCEL
|
1893 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1896 wxBookCtrlBase
* notebook
= GetBookCtrl();
1897 notebook
->SetImageList(m_imageList
);
1899 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1900 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1902 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1903 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1908 SettingsDialog::~SettingsDialog()
1913 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1915 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1917 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1918 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1922 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1923 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1924 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1925 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1929 wxString autoSaveLabel
= _("&Auto-save every");
1930 wxString minsLabel
= _("mins");
1932 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1933 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1936 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1937 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1940 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1942 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1944 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1945 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1949 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1950 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1951 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1952 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1954 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1956 panel
->SetSizer(topSizer
);
1957 topSizer
->Fit(panel
);
1962 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1964 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1966 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1967 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1969 //// PROJECT OR GLOBAL
1970 wxString globalOrProjectChoices
[2];
1971 globalOrProjectChoices
[0] = _("&New projects");
1972 globalOrProjectChoices
[1] = _("&This project");
1974 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1975 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1976 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1978 projectOrGlobal
->SetSelection(0);
1980 //// BACKGROUND STYLE
1981 wxArrayString backgroundStyleChoices
;
1982 backgroundStyleChoices
.Add(wxT("Colour"));
1983 backgroundStyleChoices
.Add(wxT("Image"));
1984 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1986 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1987 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1989 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1991 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1993 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1994 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1995 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1997 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
2000 //// FONT SIZE SELECTION
2002 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
2003 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
2005 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
2006 wxSize(80, wxDefaultCoord
));
2007 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
2009 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
2012 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
2013 topSizer
->AddSpacer(5);
2015 panel
->SetSizer(topSizer
);
2016 topSizer
->Fit(panel
);
2021 #endif // USE_SETTINGS_DIALOG