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"
34 #include "wx/colordlg.h"
35 #endif // wxUSE_COLOURDLG
38 #include "wx/choicdlg.h"
39 #endif // wxUSE_CHOICEDLG
41 #if wxUSE_STARTUP_TIPS
42 #include "wx/tipdlg.h"
43 #endif // wxUSE_STARTUP_TIPS
46 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
47 #include "wx/datetime.h" // wxDateTime
50 #include "wx/progdlg.h"
51 #endif // wxUSE_PROGRESSDLG
54 #include "wx/aboutdlg.h"
56 // these headers are only needed for custom about dialog
57 #include "wx/statline.h"
58 #include "wx/generic/aboutdlgg.h"
59 #endif // wxUSE_ABOUTDLG
62 #include "wx/busyinfo.h"
63 #endif // wxUSE_BUSYINFO
66 #include "wx/numdlg.h"
67 #endif // wxUSE_NUMBERDLG
70 #include "wx/filedlg.h"
71 #endif // wxUSE_FILEDLG
74 #include "wx/dirdlg.h"
75 #endif // wxUSE_DIRDLG
78 #include "wx/fontdlg.h"
79 #endif // wxUSE_FONTDLG
82 #include "wx/fdrepdlg.h"
83 #endif // wxUSE_FINDREPLDLG
86 #include "wx/spinctrl.h"
89 #include "wx/propdlg.h"
93 #if USE_COLOURDLG_GENERIC
94 #include "wx/generic/colrdlgg.h"
95 #endif // USE_COLOURDLG_GENERIC
97 #if USE_DIRDLG_GENERIC
98 #include "wx/generic/dirdlgg.h"
99 #endif // USE_DIRDLG_GENERIC
101 #if USE_FILEDLG_GENERIC
102 #include "wx/generic/filedlgg.h"
103 #endif // USE_FILEDLG_GENERIC
105 #if USE_FONTDLG_GENERIC
106 #include "wx/generic/fontdlgg.h"
107 #endif // USE_FONTDLG_GENERIC
111 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
112 EVT_PAINT(MyCanvas::OnPaint
)
117 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
119 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
120 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO
, MyFrame::MessageBoxInfo
)
121 #endif // wxUSE_MSGDLG
123 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
124 EVT_MENU(DIALOGS_GET_COLOUR
, MyFrame::GetColour
)
125 #endif // wxUSE_COLOURDLG
128 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
129 #endif // wxUSE_FONTDLG
132 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
133 #endif // wxUSE_LOG_DIALOG
136 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
137 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
138 #endif // wxUSE_TEXTDLG
141 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
142 #endif // wxUSE_NUMBERDLG
145 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
146 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
147 #endif // wxUSE_CHOICEDLG
150 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
151 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
152 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
153 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
154 #endif // wxUSE_FILEDLG
156 #if USE_FILEDLG_GENERIC
157 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
158 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
159 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
160 #endif // USE_FILEDLG_GENERIC
163 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
164 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
165 #endif // wxUSE_DIRDLG
167 #if USE_MODAL_PRESENTATION
168 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
169 #endif // USE_MODAL_PRESENTATION
170 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
171 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
172 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
173 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
174 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
176 #if wxUSE_STARTUP_TIPS
177 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
178 #endif // wxUSE_STARTUP_TIPS
180 #if USE_FONTDLG_GENERIC
181 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
182 #endif // USE_FONTDLG_GENERIC
184 #if USE_DIRDLG_GENERIC
185 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
186 #endif // wxMSW || wxMAC
188 #if USE_COLOURDLG_GENERIC
189 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
190 #endif // USE_COLOURDLG_GENERIC
192 #if wxUSE_PROGRESSDLG
193 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
194 #endif // wxUSE_PROGRESSDLG
197 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
198 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
199 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
200 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
201 #endif // wxUSE_ABOUTDLG
204 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
205 #endif // wxUSE_BUSYINFO
207 #if wxUSE_FINDREPLDLG
208 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
209 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
211 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
212 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
213 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
214 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
215 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
216 #endif // wxUSE_FINDREPLDLG
218 #if USE_SETTINGS_DIALOG
219 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
220 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
221 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
224 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
225 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
227 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
230 #if USE_MODAL_PRESENTATION
232 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
233 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
236 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
237 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
238 EVT_CLOSE(MyModelessDialog::OnClose
)
241 #endif // USE_MODAL_PRESENTATION
243 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
244 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
245 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
248 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
250 // `Main program' equivalent, creating windows and returning main app frame
253 if ( !wxApp::OnInit() )
257 wxInitAllImageHandlers();
260 m_canvasTextColour
= *wxBLACK
;
261 m_canvasFont
= *wxNORMAL_FONT
;
263 // Create the main frame window
264 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
267 wxMenu
*menuDlg
= new wxMenu
;
269 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
272 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
274 wxMenu
*choices_menu
= new wxMenu
;
277 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose bg colour"));
278 choices_menu
->Append(DIALOGS_GET_COLOUR
, _T("&Choose fg colour"));
279 #endif // wxUSE_COLOURDLG
282 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
283 #endif // wxUSE_FONTDLG
286 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
287 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
288 #endif // wxUSE_CHOICEDLG
290 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
291 choices_menu
->AppendSeparator();
292 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
294 #if USE_COLOURDLG_GENERIC
295 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
296 #endif // USE_COLOURDLG_GENERIC
298 #if USE_FONTDLG_GENERIC
299 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
300 #endif // USE_FONTDLG_GENERIC
302 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
303 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
306 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
308 wxMenu
*entry_menu
= new wxMenu
;
311 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
312 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
313 #endif // wxUSE_TEXTDLG
316 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
317 #endif // wxUSE_NUMBERDLG
319 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
321 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
326 wxMenu
*filedlg_menu
= new wxMenu
;
327 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
328 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
329 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
330 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
332 #if USE_FILEDLG_GENERIC
333 filedlg_menu
->AppendSeparator();
334 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
335 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
336 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
337 #endif // USE_FILEDLG_GENERIC
339 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
341 #endif // wxUSE_FILEDLG
344 wxMenu
*dir_menu
= new wxMenu
;
346 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
347 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
348 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
350 #if USE_DIRDLG_GENERIC
351 dir_menu
->AppendSeparator();
352 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
353 #endif // USE_DIRDLG_GENERIC
355 #endif // wxUSE_DIRDLG
358 #if wxUSE_STARTUP_TIPS || \
359 wxUSE_PROGRESSDLG || \
361 wxUSE_LOG_DIALOG || \
364 wxMenu
*info_menu
= new wxMenu
;
366 #if wxUSE_STARTUP_TIPS
367 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
368 #endif // wxUSE_STARTUP_TIPS
370 #if wxUSE_PROGRESSDLG
371 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
372 #endif // wxUSE_PROGRESSDLG
375 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
376 #endif // wxUSE_BUSYINFO
379 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
380 #endif // wxUSE_LOG_DIALOG
383 info_menu
->Append(DIALOGS_MESSAGE_BOX_WXINFO
,
384 _T("&wxWidgets information\tCtrl-I"));
385 #endif // wxUSE_MSGDLG
387 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
389 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
392 #if wxUSE_FINDREPLDLG
393 wxMenu
*find_menu
= new wxMenu
;
394 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
395 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
396 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
397 #endif // wxUSE_FINDREPLDLG
399 wxMenu
*dialogs_menu
= new wxMenu
;
400 #if USE_MODAL_PRESENTATION
401 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
402 #endif // USE_MODAL_PRESENTATION
403 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
404 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
405 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
406 dialogs_menu
->Append(DIALOGS_MINIFRAME
, _T("&Mini frame"));
407 dialogs_menu
->Append(DIALOGS_ONTOP
, _T("Dialog staying on &top"));
408 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
410 #if USE_SETTINGS_DIALOG
411 wxMenu
*sheet_menu
= new wxMenu
;
412 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
413 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
415 if (wxPlatformIs(wxPORT_MAC
))
416 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
419 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
422 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
423 #endif // USE_SETTINGS_DIALOG
425 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, _T("&Standard Buttons Sizer Dialog"));
427 menuDlg
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
429 menuDlg
->AppendSeparator();
430 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
433 wxMenu
*menuHelp
= new wxMenu
;
434 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
435 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
436 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
437 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
438 #endif // wxUSE_ABOUTDLG
440 wxMenuBar
*menubar
= new wxMenuBar
;
441 menubar
->Append(menuDlg
, _T("&Dialogs"));
443 menubar
->Append(menuHelp
, _T("&Help"));
444 #endif // wxUSE_ABOUTDLG
446 frame
->SetMenuBar(menubar
);
448 myCanvas
= new MyCanvas(frame
);
449 myCanvas
->SetBackgroundColour(*wxWHITE
);
451 frame
->Centre(wxBOTH
);
461 // My frame constructor
462 MyFrame::MyFrame(wxWindow
*parent
,
463 const wxString
& title
)
464 : wxFrame(parent
, wxID_ANY
, title
)
468 #if USE_MODAL_PRESENTATION
469 m_dialog
= (MyModelessDialog
*)NULL
;
470 #endif // USE_MODAL_PRESENTATION
472 #if wxUSE_FINDREPLDLG
478 m_clrData
.SetChooseFull(true);
479 for (int i
= 0; i
< wxColourData::NUM_CUSTOM
; i
++)
481 unsigned char n
= i
*16;
482 m_clrData
.SetCustomColour(i
, wxColour(n
, n
, n
));
484 #endif // wxUSE_COLOURDLG
488 #endif // wxUSE_STATUSBAR
493 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
))
495 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
497 wxColourDialog
dialog(this, &m_clrData
);
498 dialog
.SetTitle(_("Please choose the background colour"));
499 if ( dialog
.ShowModal() == wxID_OK
)
501 m_clrData
= dialog
.GetColourData();
502 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
503 myCanvas
->ClearBackground();
508 void MyFrame::GetColour(wxCommandEvent
& WXUNUSED(event
))
510 wxColour clr
= wxGetColourFromUser
513 wxGetApp().m_canvasTextColour
,
514 "Please choose the foreground colour"
518 wxGetApp().m_canvasTextColour
= clr
;
521 //else: dialog cancelled by user
524 #endif // wxUSE_COLOURDLG
527 #if USE_COLOURDLG_GENERIC
528 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
530 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
532 //FIXME:TODO:This has no effect...
533 m_clrData
.SetChooseFull(true);
535 for (int i
= 0; i
< 16; i
++)
538 (unsigned char)(i
*16),
539 (unsigned char)(i
*16),
540 (unsigned char)(i
*16)
542 m_clrData
.SetCustomColour(i
, colour
);
545 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
546 if (dialog
->ShowModal() == wxID_OK
)
548 m_clrData
= dialog
->GetColourData();
549 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
550 myCanvas
->ClearBackground();
555 #endif // USE_COLOURDLG_GENERIC
558 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
561 data
.SetInitialFont(wxGetApp().m_canvasFont
);
562 data
.SetColour(wxGetApp().m_canvasTextColour
);
564 // you might also do this:
566 // wxFontDialog dialog;
567 // if ( !dialog.Create(this, data) { ... error ... }
569 wxFontDialog
dialog(this, data
);
571 if (dialog
.ShowModal() == wxID_OK
)
573 wxFontData retData
= dialog
.GetFontData();
574 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
575 wxGetApp().m_canvasTextColour
= retData
.GetColour();
578 //else: cancelled by the user, don't change the font
580 #endif // wxUSE_FONTDLG
582 #if USE_FONTDLG_GENERIC
583 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
586 data
.SetInitialFont(wxGetApp().m_canvasFont
);
587 data
.SetColour(wxGetApp().m_canvasTextColour
);
589 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
590 if (dialog
->ShowModal() == wxID_OK
)
592 wxFontData retData
= dialog
->GetFontData();
593 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
594 wxGetApp().m_canvasTextColour
= retData
.GetColour();
599 #endif // USE_FONTDLG_GENERIC
602 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
604 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
605 // being flushed -- test it
608 wxLogMessage(wxT("This is some message - everything is ok so far."));
609 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
610 wxLogWarning(wxT("And then something went wrong!"));
612 // and if ~wxBusyCursor doesn't do it, then call it manually
616 wxLogError(wxT("Intermediary error handler decided to abort."));
617 wxLogError(wxT("The top level caller detected an unrecoverable error."));
619 wxLog::FlushActive();
621 wxLogMessage(wxT("And this is the same dialog but with only one message."));
623 #endif // wxUSE_LOG_DIALOG
626 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
628 wxMessageDialog
dialog(NULL
,
629 _T("This is a message box\nA long, long string to test out the message box properly"),
630 _T("Message box text"),
631 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
| wxICON_INFORMATION
);
633 if ( dialog
.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
635 dialog
.SetExtendedMessage(_T("This platform supports custom button labels"));
639 dialog
.SetExtendedMessage(_T("Custom button labels are not supported."));
642 switch ( dialog
.ShowModal() )
645 wxLogStatus(wxT("You pressed \"Yes\""));
649 wxLogStatus(wxT("You pressed \"No\""));
653 wxLogStatus(wxT("You pressed \"Cancel\""));
657 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
661 void MyFrame::MessageBoxInfo(wxCommandEvent
& WXUNUSED(event
))
663 ::wxInfoMessageBox(this);
665 #endif // wxUSE_MSGDLG
668 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
))
670 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
671 _T("Even two rows of text."),
672 _T("Enter a number:"), _T("Numeric input test"),
679 msg
= _T("Invalid number entered or dialog cancelled.");
684 msg
.Printf(_T("You've entered %lu"), res
);
685 icon
= wxICON_INFORMATION
;
688 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
690 #endif // wxUSE_NUMBERDLG
693 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
695 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
696 _T("Password entry dialog"),
701 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
702 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
706 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
708 wxTextEntryDialog
dialog(this,
709 _T("This is a small sample\n")
710 _T("A long, long string to test out the text entrybox"),
711 _T("Please enter a string"),
715 if (dialog
.ShowModal() == wxID_OK
)
717 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
720 #endif // wxUSE_TEXTDLG
723 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
725 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
727 wxSingleChoiceDialog
dialog(this,
728 _T("This is a small sample\n")
729 _T("A single-choice convenience dialog"),
730 _T("Please select a value"),
731 WXSIZEOF(choices
), choices
);
733 dialog
.SetSelection(2);
735 if (dialog
.ShowModal() == wxID_OK
)
737 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
742 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
744 const wxString choices
[] =
746 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
747 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
748 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
751 wxArrayInt selections
;
752 size_t count
= wxGetMultipleChoices(selections
,
753 _T("This is a small sample\n")
754 _T("A multi-choice convenience dialog"),
755 _T("Please select a value"),
756 WXSIZEOF(choices
), choices
,
761 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
762 for ( size_t n
= 0; n
< count
; n
++ )
764 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
765 (unsigned)n
, (unsigned)selections
[n
],
766 choices
[selections
[n
]].c_str());
770 //else: cancelled or nothing selected
772 #endif // wxUSE_CHOICEDLG
775 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
780 _T("Testing open file dialog"),
784 _T("C++ files (*.cpp)|*.cpp")
786 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
790 dialog
.CentreOnParent();
791 dialog
.SetDirectory(wxGetHomeDir());
793 if (dialog
.ShowModal() == wxID_OK
)
796 info
.Printf(_T("Full file name: %s\n")
799 dialog
.GetPath().c_str(),
800 dialog
.GetDirectory().c_str(),
801 dialog
.GetFilename().c_str());
802 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
807 // this shows how to take advantage of specifying a default extension in the
808 // call to wxFileSelector: it is remembered after each new call and the next
809 // one will use it by default
810 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
812 static wxString s_extDef
;
813 wxString path
= wxFileSelector(
814 _T("Select the file to load"),
815 wxEmptyString
, wxEmptyString
,
819 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
820 wxFileSelectorDefaultWildcardStr
,
821 wxFileSelectorDefaultWildcardStr
823 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
830 // it is just a sample, would use wxSplitPath in real program
831 s_extDef
= path
.AfterLast(_T('.'));
833 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
837 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
841 _T("C++ files (*.cpp)|*.cpp");
845 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
846 wxFileSelectorDefaultWildcardStr
,
847 wxFileSelectorDefaultWildcardStr
850 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
851 wxEmptyString
, wxEmptyString
, wildcards
,
852 wxFD_OPEN
|wxFD_MULTIPLE
);
854 if (dialog
.ShowModal() == wxID_OK
)
856 wxArrayString paths
, filenames
;
858 dialog
.GetPaths(paths
);
859 dialog
.GetFilenames(filenames
);
862 size_t count
= paths
.GetCount();
863 for ( size_t n
= 0; n
< count
; n
++ )
865 s
.Printf(_T("File %d: %s (%s)\n"),
866 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
870 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
873 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
878 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
880 wxFileDialog
dialog(this,
881 _T("Testing save file dialog"),
884 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
885 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
887 dialog
.SetFilterIndex(1);
889 if (dialog
.ShowModal() == wxID_OK
)
891 wxLogMessage(_T("%s, filter %d"),
892 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
895 #endif // wxUSE_FILEDLG
897 #if USE_FILEDLG_GENERIC
898 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
900 wxGenericFileDialog dialog
903 _T("Testing open file dialog"),
906 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
909 dialog
.SetDirectory(wxGetHomeDir());
911 if (dialog
.ShowModal() == wxID_OK
)
914 info
.Printf(_T("Full file name: %s\n")
917 dialog
.GetPath().c_str(),
918 dialog
.GetDirectory().c_str(),
919 dialog
.GetFilename().c_str());
920 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
925 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
927 // On PocketPC you can disable OK-only dialogs policy using system option
928 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
929 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
931 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
932 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
933 wxEmptyString
, wxEmptyString
, wildcards
,
936 if (dialog
.ShowModal() == wxID_OK
)
938 wxArrayString paths
, filenames
;
940 dialog
.GetPaths(paths
);
941 dialog
.GetFilenames(filenames
);
944 size_t count
= paths
.GetCount();
945 for ( size_t n
= 0; n
< count
; n
++ )
947 s
.Printf(_T("File %d: %s (%s)\n"),
948 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
952 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
955 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
959 // restore system option
960 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
963 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
965 wxGenericFileDialog
dialog(this,
966 _T("Testing save file dialog"),
969 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
970 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
972 dialog
.SetFilterIndex(1);
974 if (dialog
.ShowModal() == wxID_OK
)
976 wxLogMessage(_T("%s, filter %d"),
977 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
980 #endif // USE_FILEDLG_GENERIC
983 void MyFrame::DoDirChoose(int style
)
985 // pass some initial dir to wxDirDialog
987 wxGetHomeDir(&dirHome
);
989 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
991 if (dialog
.ShowModal() == wxID_OK
)
993 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
997 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
999 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
1002 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
1004 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
1006 #endif // wxUSE_DIRDLG
1008 #if USE_DIRDLG_GENERIC
1009 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
1011 // pass some initial dir to wxDirDialog
1013 wxGetHomeDir(&dirHome
);
1015 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
1017 if (dialog
.ShowModal() == wxID_OK
)
1019 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
1020 dialog2
.ShowModal();
1023 #endif // USE_DIRDLG_GENERIC
1025 #if USE_MODAL_PRESENTATION
1026 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
1028 MyModalDialog
dlg(this);
1031 #endif // USE_MODAL_PRESENTATION
1033 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1035 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1041 m_dialog
= new MyModelessDialog(this);
1044 m_dialog
->Show(true);
1048 // If m_dialog is NULL, then possibly the system
1049 // didn't report the checked menu item status correctly.
1050 // It should be true just after the menu item was selected,
1051 // if there was no modeless dialog yet.
1053 wxASSERT( m_dialog
!= NULL
);
1059 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1061 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1062 wxDefaultPosition
, wxSize(200, 100));
1063 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1064 dlg
.CentreOnScreen();
1068 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1070 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1071 wxDefaultPosition
, wxSize(200, 100));
1072 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1073 dlg
.CentreOnParent();
1077 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1079 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, _T("Mini frame"),
1080 wxDefaultPosition
, wxSize(300, 100),
1081 wxCAPTION
| wxCLOSE_BOX
);
1082 new wxStaticText(frame
,
1084 _T("Mini frames have slightly different appearance"),
1086 new wxStaticText(frame
,
1088 _T("from the normal frames but that's the only difference."),
1091 frame
->CentreOnParent();
1095 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1097 wxDialog
dlg(this, wxID_ANY
, _T("Dialog staying on top of other windows"),
1098 wxDefaultPosition
, wxSize(300, 100),
1099 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1100 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1104 #if wxUSE_STARTUP_TIPS
1105 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1107 static size_t s_index
= (size_t)-1;
1109 if ( s_index
== (size_t)-1 )
1113 // this is completely bogus, we don't know how many lines are there
1114 // in the file, but who cares, it's a demo only...
1115 s_index
= rand() % 5;
1118 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1120 bool showAtStartup
= wxShowTip(this, tipProvider
);
1122 if ( showAtStartup
)
1124 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1125 wxOK
| wxICON_INFORMATION
, this);
1128 s_index
= tipProvider
->GetCurrentTip();
1131 #endif // wxUSE_STARTUP_TIPS
1133 #if USE_SETTINGS_DIALOG
1134 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1136 SettingsDialog
dialog(this, event
.GetId());
1139 #endif // USE_SETTINGS_DIALOG
1141 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1143 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1147 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1150 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1152 StdButtonSizerDialog
dialog(this);
1156 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1161 #if wxUSE_PROGRESSDLG
1163 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1165 static const int max
= 100;
1167 wxProgressDialog
dialog(_T("Progress dialog example"),
1168 _T("An informative message"),
1174 // wxPD_AUTO_HIDE | -- try this as well
1176 wxPD_ESTIMATED_TIME
|
1178 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1182 for ( int i
= 0; i
<= max
; i
++ )
1188 // test both modes of wxProgressDialog behaviour: start in
1189 // indeterminate mode but switch to the determinate one later
1190 const bool determinate
= i
> max
/2;
1194 msg
= _T("That's all, folks!");
1196 else if ( !determinate
)
1198 msg
= _T("Testing indeterminate mode");
1200 else if ( determinate
)
1202 msg
= _T("Now in standard determinate mode");
1205 // will be set to true if "Skip" button was pressed
1209 cont
= dialog
.Update(i
, msg
, &skip
);
1213 cont
= dialog
.Pulse(msg
, &skip
);
1216 // each skip will move progress about quarter forward
1222 if ( wxMessageBox(_T("Do you really want to cancel?"),
1223 _T("Progress dialog question"), // caption
1224 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1234 wxLogStatus(wxT("Progress dialog aborted!"));
1238 wxLogStatus(wxT("Countdown from %d finished"), max
);
1242 #endif // wxUSE_PROGRESSDLG
1246 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1248 info
.SetName(_T("Dialogs Sample"));
1249 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1250 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1251 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1252 info
.AddDeveloper(_T("Vadim Zeitlin"));
1255 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1257 InitAboutInfoMinimal(info
);
1259 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1262 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1264 InitAboutInfoMinimal(info
);
1266 // we can add a second developer
1267 info
.AddDeveloper(_T("A.N. Other"));
1269 // or we can add several persons at once like this
1270 static const wxChar
*docwriters
[] =
1272 _T("First D. Writer"),
1276 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1277 info
.SetLicence(wxString::FromAscii(
1278 " wxWindows Library Licence, Version 3.1\n"
1279 " ======================================\n"
1281 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1283 " Everyone is permitted to copy and distribute verbatim copies\n"
1284 " of this licence document, but changing it is not allowed.\n"
1286 " WXWINDOWS LIBRARY LICENCE\n"
1287 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1289 " ...and so on and so forth...\n"
1292 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1295 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1297 wxAboutDialogInfo info
;
1298 InitAboutInfoMinimal(info
);
1303 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1305 wxAboutDialogInfo info
;
1306 InitAboutInfoWebsite(info
);
1311 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1313 wxAboutDialogInfo info
;
1314 InitAboutInfoAll(info
);
1319 // a trivial example of a custom dialog class
1320 class MyAboutDialog
: public wxGenericAboutDialog
1323 MyAboutDialog(const wxAboutDialogInfo
& info
)
1328 // add some custom controls
1329 virtual void DoAddCustomControls()
1331 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1332 AddText(_T("Some custom text"));
1333 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1337 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1339 wxAboutDialogInfo info
;
1340 InitAboutInfoAll(info
);
1342 MyAboutDialog
dlg(info
);
1346 #endif // wxUSE_ABOUTDLG
1350 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1352 wxWindowDisabler disableAll
;
1354 wxBusyInfo
info(_T("Working, please wait..."), this);
1356 for ( int i
= 0; i
< 18; i
++ )
1366 #endif // wxUSE_BUSYINFO
1368 #if wxUSE_FINDREPLDLG
1370 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1374 delete m_dlgReplace
;
1375 m_dlgReplace
= NULL
;
1379 m_dlgReplace
= new wxFindReplaceDialog
1383 _T("Find and replace dialog"),
1387 m_dlgReplace
->Show(true);
1391 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1400 m_dlgFind
= new wxFindReplaceDialog
1409 m_dlgFind
->Show(true);
1413 static wxString
DecodeFindDialogEventFlags(int flags
)
1416 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1417 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1418 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1419 << _T("case sensitive");
1424 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1426 wxEventType type
= event
.GetEventType();
1428 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1430 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1431 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1432 event
.GetFindString().c_str(),
1433 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1435 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1436 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1438 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1439 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1440 event
.GetFindString().c_str(),
1441 event
.GetReplaceString().c_str(),
1442 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1444 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1446 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1450 if ( dlg
== m_dlgFind
)
1453 idMenu
= DIALOGS_FIND
;
1456 else if ( dlg
== m_dlgReplace
)
1458 txt
= _T("Replace");
1459 idMenu
= DIALOGS_REPLACE
;
1460 m_dlgReplace
= NULL
;
1464 txt
= _T("Unknown");
1467 wxFAIL_MSG( _T("unexpected event") );
1470 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1472 if ( idMenu
!= wxID_ANY
)
1474 GetMenuBar()->Check(idMenu
, false);
1481 wxLogError(wxT("Unknown find dialog event!"));
1485 #endif // wxUSE_FINDREPLDLG
1487 // ----------------------------------------------------------------------------
1489 // ----------------------------------------------------------------------------
1491 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1494 dc
.SetFont(wxGetApp().m_canvasFont
);
1495 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1496 dc
.SetBackgroundMode(wxTRANSPARENT
);
1498 _T("wxWidgets common dialogs")
1499 #if !defined(__SMARTPHONE__)
1500 _T(" test application")
1505 #if USE_MODAL_PRESENTATION
1507 // ----------------------------------------------------------------------------
1509 // ----------------------------------------------------------------------------
1511 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1512 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1514 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1516 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1517 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1520 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1521 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1525 sizerTop
->SetSizeHints(this);
1526 sizerTop
->Fit(this);
1529 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1531 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1532 wxOK
| wxICON_INFORMATION
, this);
1535 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1537 if ( event
.CanVeto() )
1539 wxMessageBox(_T("Use the menu item to close this dialog"),
1540 _T("Modeless dialog"),
1541 wxOK
| wxICON_INFORMATION
, this);
1547 // ----------------------------------------------------------------------------
1549 // ----------------------------------------------------------------------------
1551 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1552 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1554 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1556 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1557 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1558 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1560 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1561 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1562 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1563 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1564 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1568 sizerTop
->SetSizeHints(this);
1569 sizerTop
->Fit(this);
1571 m_btnModal
->SetFocus();
1572 m_btnModal
->SetDefault();
1575 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1577 if ( event
.GetEventObject() == m_btnDelete
)
1582 m_btnDelete
->Disable();
1584 else if ( event
.GetEventObject() == m_btnModal
)
1587 wxGetTextFromUser(_T("Dummy prompt"),
1588 _T("Modal dialog called from dialog"),
1589 wxEmptyString
, this);
1591 wxMessageBox(_T("Modal dialog called from dialog"));
1592 #endif // wxUSE_TEXTDLG
1594 else if ( event
.GetEventObject() == m_btnModeless
)
1596 (new MyModelessDialog(this))->Show();
1604 #endif // USE_MODAL_PRESENTATION
1606 // ----------------------------------------------------------------------------
1607 // StdButtonSizerDialog
1608 // ----------------------------------------------------------------------------
1610 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1611 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1612 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1613 m_buttonsSizer(NULL
)
1615 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1617 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1618 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1620 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
1622 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
1624 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1625 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
1627 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
1629 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
1631 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
1633 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1634 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
1636 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
1638 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
1639 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
1640 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
1642 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
1644 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
1645 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
1647 sizer
->Add(sizerInside1
, 0, 0, 0);
1648 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
1649 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
1650 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1652 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
1653 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
1655 sizer
->Add(sizerInside2
, 0, 0, 0);
1656 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
1657 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
1658 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1660 sizerTop
->Add(sizer
, 0, wxALL
, 5);
1662 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
1663 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
1664 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
1666 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
1668 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
1670 EnableDisableControls();
1674 sizerTop
->SetSizeHints(this);
1679 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
1683 m_buttonsSizer
->DeleteWindows();
1684 GetSizer()->Remove(m_buttonsSizer
);
1687 EnableDisableControls();
1690 unsigned long numButtons
= 0;
1692 if (m_chkboxAffirmativeButton
->IsChecked())
1694 if (m_radiobtnOk
->GetValue())
1699 else if (m_radiobtnYes
->GetValue())
1706 if (m_chkboxDismissButton
->IsChecked())
1708 if (m_radiobtnCancel
->GetValue())
1714 else if (m_radiobtnClose
->GetValue())
1722 if (m_chkboxApply
->IsChecked())
1728 if (m_chkboxNo
->IsChecked())
1734 if (m_chkboxHelp
->IsChecked())
1740 if (m_chkboxNoDefault
->IsChecked())
1742 flags
|= wxNO_DEFAULT
;
1745 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
1746 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
1749 GetSizer()->SetSizeHints(this);
1752 void StdButtonSizerDialog::EnableDisableControls()
1754 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
1756 m_radiobtnOk
->Enable(affButtonEnabled
);
1757 m_radiobtnYes
->Enable(affButtonEnabled
);
1759 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
1761 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
1762 m_radiobtnClose
->Enable(dismissButtonEnabled
);
1765 #if USE_SETTINGS_DIALOG
1766 // ----------------------------------------------------------------------------
1768 // ----------------------------------------------------------------------------
1770 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1772 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1775 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1777 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1782 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1783 int resizeBorder
= wxRESIZE_BORDER
;
1791 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1792 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1793 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1795 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1797 SetSheetStyle(sheetStyle
);
1798 SetSheetInnerBorder(0);
1799 SetSheetOuterBorder(0);
1801 // create a dummy image list with a few icons
1802 const wxSize
imageSize(32, 32);
1804 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1806 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1808 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1810 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1812 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1817 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1818 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1821 // If using a toolbook, also follow Mac style and don't create buttons
1823 CreateButtons(wxOK
| wxCANCEL
|
1824 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1827 wxBookCtrlBase
* notebook
= GetBookCtrl();
1828 notebook
->SetImageList(m_imageList
);
1830 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1831 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1833 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1834 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1839 SettingsDialog::~SettingsDialog()
1844 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1846 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1848 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1849 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1853 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1854 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1855 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1856 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1860 wxString autoSaveLabel
= _("&Auto-save every");
1861 wxString minsLabel
= _("mins");
1863 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1864 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1867 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1868 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1871 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1873 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1875 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1876 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1880 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1881 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1882 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1883 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1885 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1887 panel
->SetSizer(topSizer
);
1888 topSizer
->Fit(panel
);
1893 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1895 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1897 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1898 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1900 //// PROJECT OR GLOBAL
1901 wxString globalOrProjectChoices
[2];
1902 globalOrProjectChoices
[0] = _("&New projects");
1903 globalOrProjectChoices
[1] = _("&This project");
1905 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1906 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1907 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1909 projectOrGlobal
->SetSelection(0);
1911 //// BACKGROUND STYLE
1912 wxArrayString backgroundStyleChoices
;
1913 backgroundStyleChoices
.Add(wxT("Colour"));
1914 backgroundStyleChoices
.Add(wxT("Image"));
1915 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1917 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1918 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1920 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1922 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1924 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1925 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1926 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1928 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1931 //// FONT SIZE SELECTION
1933 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1934 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1936 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1937 wxSize(80, wxDefaultCoord
));
1938 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1940 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1943 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1944 topSizer
->AddSpacer(5);
1946 panel
->SetSizer(topSizer
);
1947 topSizer
->Fit(panel
);
1952 #endif // USE_SETTINGS_DIALOG