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
)
118 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
121 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
122 #endif // wxUSE_COLOURDLG
125 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
126 #endif // wxUSE_FONTDLG
129 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
130 #endif // wxUSE_LOG_DIALOG
133 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
134 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
135 #endif // wxUSE_TEXTDLG
138 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
139 #endif // wxUSE_NUMBERDLG
142 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
143 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
144 #endif // wxUSE_CHOICEDLG
147 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
148 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
149 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
150 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
151 #endif // wxUSE_FILEDLG
153 #if USE_FILEDLG_GENERIC
154 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
155 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
156 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
157 #endif // USE_FILEDLG_GENERIC
160 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
161 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
162 #endif // wxUSE_DIRDLG
164 #if USE_MODAL_PRESENTATION
165 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
166 #endif // USE_MODAL_PRESENTATION
167 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
168 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
169 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
170 EVT_MENU(DIALOGS_MINIFRAME
, MyFrame::MiniFrame
)
171 EVT_MENU(DIALOGS_ONTOP
, MyFrame::DlgOnTop
)
173 #if wxUSE_STARTUP_TIPS
174 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
175 #endif // wxUSE_STARTUP_TIPS
177 #if USE_FONTDLG_GENERIC
178 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
179 #endif // USE_FONTDLG_GENERIC
181 #if USE_DIRDLG_GENERIC
182 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
183 #endif // wxMSW || wxMAC
185 #if USE_COLOURDLG_GENERIC
186 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
187 #endif // USE_COLOURDLG_GENERIC
189 #if wxUSE_PROGRESSDLG
190 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
191 #endif // wxUSE_PROGRESSDLG
194 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
195 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
196 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
197 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
198 #endif // wxUSE_ABOUTDLG
201 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
202 #endif // wxUSE_BUSYINFO
204 #if wxUSE_FINDREPLDLG
205 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
206 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
208 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
209 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
210 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
211 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
212 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
213 #endif // wxUSE_FINDREPLDLG
215 #if USE_SETTINGS_DIALOG
216 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
217 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
218 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
221 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, MyFrame::OnStandardButtonsSizerDialog
)
222 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
224 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
227 #if USE_MODAL_PRESENTATION
229 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
230 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
233 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
234 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
235 EVT_CLOSE(MyModelessDialog::OnClose
)
238 #endif // USE_MODAL_PRESENTATION
240 BEGIN_EVENT_TABLE(StdButtonSizerDialog
, wxDialog
)
241 EVT_CHECKBOX(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
242 EVT_RADIOBUTTON(wxID_ANY
, StdButtonSizerDialog::OnEvent
)
245 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
247 // `Main program' equivalent, creating windows and returning main app frame
250 if ( !wxApp::OnInit() )
254 wxInitAllImageHandlers();
257 m_canvasTextColour
= *wxBLACK
;
258 m_canvasFont
= *wxNORMAL_FONT
;
260 // Create the main frame window
261 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
264 wxMenu
*menuDlg
= new wxMenu
;
266 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
269 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
271 wxMenu
*choices_menu
= new wxMenu
;
274 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
275 #endif // wxUSE_COLOURDLG
278 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
279 #endif // wxUSE_FONTDLG
282 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
283 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
284 #endif // wxUSE_CHOICEDLG
286 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
287 choices_menu
->AppendSeparator();
288 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
290 #if USE_COLOURDLG_GENERIC
291 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
292 #endif // USE_COLOURDLG_GENERIC
294 #if USE_FONTDLG_GENERIC
295 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
296 #endif // USE_FONTDLG_GENERIC
298 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
299 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
302 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
304 wxMenu
*entry_menu
= new wxMenu
;
307 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
308 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
309 #endif // wxUSE_TEXTDLG
312 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
313 #endif // wxUSE_NUMBERDLG
315 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
317 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
322 wxMenu
*filedlg_menu
= new wxMenu
;
323 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
324 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
325 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
326 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
328 #if USE_FILEDLG_GENERIC
329 filedlg_menu
->AppendSeparator();
330 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
331 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
332 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
333 #endif // USE_FILEDLG_GENERIC
335 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
337 #endif // wxUSE_FILEDLG
340 wxMenu
*dir_menu
= new wxMenu
;
342 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
343 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
344 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
346 #if USE_DIRDLG_GENERIC
347 dir_menu
->AppendSeparator();
348 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
349 #endif // USE_DIRDLG_GENERIC
351 #endif // wxUSE_DIRDLG
354 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
356 wxMenu
*info_menu
= new wxMenu
;
358 #if wxUSE_STARTUP_TIPS
359 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
360 #endif // wxUSE_STARTUP_TIPS
362 #if wxUSE_PROGRESSDLG
363 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
364 #endif // wxUSE_PROGRESSDLG
367 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
368 #endif // wxUSE_BUSYINFO
371 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
372 #endif // wxUSE_LOG_DIALOG
374 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
376 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
379 #if wxUSE_FINDREPLDLG
380 wxMenu
*find_menu
= new wxMenu
;
381 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
382 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
383 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
384 #endif // wxUSE_FINDREPLDLG
386 wxMenu
*dialogs_menu
= new wxMenu
;
387 #if USE_MODAL_PRESENTATION
388 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
389 #endif // USE_MODAL_PRESENTATION
390 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
391 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
392 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
393 dialogs_menu
->Append(DIALOGS_MINIFRAME
, _T("&Mini frame"));
394 dialogs_menu
->Append(DIALOGS_ONTOP
, _T("Dialog staying on &top"));
395 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
397 #if USE_SETTINGS_DIALOG
398 wxMenu
*sheet_menu
= new wxMenu
;
399 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
400 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
402 if (wxPlatformIs(wxPORT_MAC
))
403 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
406 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
409 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
410 #endif // USE_SETTINGS_DIALOG
412 menuDlg
->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
, _T("&Standard Buttons Sizer Dialog"));
414 menuDlg
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
416 menuDlg
->AppendSeparator();
417 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
420 wxMenu
*menuHelp
= new wxMenu
;
421 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
422 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
423 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
424 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
425 #endif // wxUSE_ABOUTDLG
427 wxMenuBar
*menubar
= new wxMenuBar
;
428 menubar
->Append(menuDlg
, _T("&Dialogs"));
430 menubar
->Append(menuHelp
, _T("&Help"));
431 #endif // wxUSE_ABOUTDLG
433 frame
->SetMenuBar(menubar
);
435 myCanvas
= new MyCanvas(frame
);
436 myCanvas
->SetBackgroundColour(*wxWHITE
);
438 frame
->Centre(wxBOTH
);
448 // My frame constructor
449 MyFrame::MyFrame(wxWindow
*parent
,
450 const wxString
& title
)
451 : wxFrame(parent
, wxID_ANY
, title
)
455 #if USE_MODAL_PRESENTATION
456 m_dialog
= (MyModelessDialog
*)NULL
;
457 #endif // USE_MODAL_PRESENTATION
459 #if wxUSE_FINDREPLDLG
465 m_clrData
.SetChooseFull(true);
466 for (int i
= 0; i
< 16; i
++)
468 m_clrData
.SetCustomColour(
471 (unsigned char)(i
*16),
472 (unsigned char)(i
*16),
473 (unsigned char)(i
*16)
477 #endif // wxUSE_COLOURDLG
481 #endif // wxUSE_STATUSBAR
485 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
487 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
489 wxColourDialog
dialog(this, &m_clrData
);
490 dialog
.SetTitle(_T("Choose the background colour"));
491 if (dialog
.ShowModal() == wxID_OK
)
493 m_clrData
= dialog
.GetColourData();
494 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
495 myCanvas
->ClearBackground();
499 #endif // wxUSE_COLOURDLG
501 #if USE_COLOURDLG_GENERIC
502 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
504 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
506 //FIXME:TODO:This has no effect...
507 m_clrData
.SetChooseFull(true);
509 for (int i
= 0; i
< 16; i
++)
512 (unsigned char)(i
*16),
513 (unsigned char)(i
*16),
514 (unsigned char)(i
*16)
516 m_clrData
.SetCustomColour(i
, colour
);
519 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
520 if (dialog
->ShowModal() == wxID_OK
)
522 m_clrData
= dialog
->GetColourData();
523 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
524 myCanvas
->ClearBackground();
529 #endif // USE_COLOURDLG_GENERIC
532 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
535 data
.SetInitialFont(wxGetApp().m_canvasFont
);
536 data
.SetColour(wxGetApp().m_canvasTextColour
);
538 // you might also do this:
540 // wxFontDialog dialog;
541 // if ( !dialog.Create(this, data) { ... error ... }
543 wxFontDialog
dialog(this, data
);
545 if (dialog
.ShowModal() == wxID_OK
)
547 wxFontData retData
= dialog
.GetFontData();
548 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
549 wxGetApp().m_canvasTextColour
= retData
.GetColour();
552 //else: cancelled by the user, don't change the font
554 #endif // wxUSE_FONTDLG
556 #if USE_FONTDLG_GENERIC
557 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
560 data
.SetInitialFont(wxGetApp().m_canvasFont
);
561 data
.SetColour(wxGetApp().m_canvasTextColour
);
563 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
564 if (dialog
->ShowModal() == wxID_OK
)
566 wxFontData retData
= dialog
->GetFontData();
567 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
568 wxGetApp().m_canvasTextColour
= retData
.GetColour();
573 #endif // USE_FONTDLG_GENERIC
576 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
578 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
579 // being flushed -- test it
582 wxLogMessage(wxT("This is some message - everything is ok so far."));
583 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
584 wxLogWarning(wxT("And then something went wrong!"));
586 // and if ~wxBusyCursor doesn't do it, then call it manually
590 wxLogError(wxT("Intermediary error handler decided to abort."));
591 wxLogError(wxT("The top level caller detected an unrecoverable error."));
593 wxLog::FlushActive();
595 wxLogMessage(wxT("And this is the same dialog but with only one message."));
597 #endif // wxUSE_LOG_DIALOG
599 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
601 wxMessageDialog
dialog(NULL
,
602 _T("This is a message box\nA long, long string to test out the message box properly"),
603 _T("Message box text"),
604 wxNO_DEFAULT
| wxYES_NO
| wxCANCEL
| wxICON_INFORMATION
);
606 if ( dialog
.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
608 dialog
.SetExtendedMessage(_T("This platform supports custom button labels"));
612 dialog
.SetExtendedMessage(_T("Custom button labels are not supported."));
615 switch ( dialog
.ShowModal() )
618 wxLogStatus(wxT("You pressed \"Yes\""));
622 wxLogStatus(wxT("You pressed \"No\""));
626 wxLogStatus(wxT("You pressed \"Cancel\""));
630 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
635 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
637 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
638 _T("Even two rows of text."),
639 _T("Enter a number:"), _T("Numeric input test"),
646 msg
= _T("Invalid number entered or dialog cancelled.");
651 msg
.Printf(_T("You've entered %lu"), res
);
652 icon
= wxICON_INFORMATION
;
655 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
657 #endif // wxUSE_NUMBERDLG
660 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
662 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
663 _T("Password entry dialog"),
668 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
669 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
673 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
675 wxTextEntryDialog
dialog(this,
676 _T("This is a small sample\n")
677 _T("A long, long string to test out the text entrybox"),
678 _T("Please enter a string"),
682 if (dialog
.ShowModal() == wxID_OK
)
684 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
687 #endif // wxUSE_TEXTDLG
690 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
692 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
694 wxSingleChoiceDialog
dialog(this,
695 _T("This is a small sample\n")
696 _T("A single-choice convenience dialog"),
697 _T("Please select a value"),
698 WXSIZEOF(choices
), choices
);
700 dialog
.SetSelection(2);
702 if (dialog
.ShowModal() == wxID_OK
)
704 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
709 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
711 const wxString choices
[] =
713 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
714 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
715 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
718 wxArrayInt selections
;
719 size_t count
= wxGetMultipleChoices(selections
,
720 _T("This is a small sample\n")
721 _T("A multi-choice convenience dialog"),
722 _T("Please select a value"),
723 WXSIZEOF(choices
), choices
,
728 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
729 for ( size_t n
= 0; n
< count
; n
++ )
731 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
732 (unsigned)n
, (unsigned)selections
[n
],
733 choices
[selections
[n
]].c_str());
737 //else: cancelled or nothing selected
739 #endif // wxUSE_CHOICEDLG
742 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
747 _T("Testing open file dialog"),
751 _T("C++ files (*.cpp)|*.cpp")
753 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
757 dialog
.CentreOnParent();
758 dialog
.SetDirectory(wxGetHomeDir());
760 if (dialog
.ShowModal() == wxID_OK
)
763 info
.Printf(_T("Full file name: %s\n")
766 dialog
.GetPath().c_str(),
767 dialog
.GetDirectory().c_str(),
768 dialog
.GetFilename().c_str());
769 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
774 // this shows how to take advantage of specifying a default extension in the
775 // call to wxFileSelector: it is remembered after each new call and the next
776 // one will use it by default
777 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
779 static wxString s_extDef
;
780 wxString path
= wxFileSelector(
781 _T("Select the file to load"),
782 wxEmptyString
, wxEmptyString
,
786 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
787 wxFileSelectorDefaultWildcardStr
,
788 wxFileSelectorDefaultWildcardStr
790 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
797 // it is just a sample, would use wxSplitPath in real program
798 s_extDef
= path
.AfterLast(_T('.'));
800 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
804 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
808 _T("C++ files (*.cpp)|*.cpp");
812 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
813 wxFileSelectorDefaultWildcardStr
,
814 wxFileSelectorDefaultWildcardStr
817 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
818 wxEmptyString
, wxEmptyString
, wildcards
,
819 wxFD_OPEN
|wxFD_MULTIPLE
);
821 if (dialog
.ShowModal() == wxID_OK
)
823 wxArrayString paths
, filenames
;
825 dialog
.GetPaths(paths
);
826 dialog
.GetFilenames(filenames
);
829 size_t count
= paths
.GetCount();
830 for ( size_t n
= 0; n
< count
; n
++ )
832 s
.Printf(_T("File %d: %s (%s)\n"),
833 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
837 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
840 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
845 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
847 wxFileDialog
dialog(this,
848 _T("Testing save file dialog"),
851 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
852 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
854 dialog
.SetFilterIndex(1);
856 if (dialog
.ShowModal() == wxID_OK
)
858 wxLogMessage(_T("%s, filter %d"),
859 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
862 #endif // wxUSE_FILEDLG
864 #if USE_FILEDLG_GENERIC
865 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
867 wxGenericFileDialog dialog
870 _T("Testing open file dialog"),
873 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
876 dialog
.SetDirectory(wxGetHomeDir());
878 if (dialog
.ShowModal() == wxID_OK
)
881 info
.Printf(_T("Full file name: %s\n")
884 dialog
.GetPath().c_str(),
885 dialog
.GetDirectory().c_str(),
886 dialog
.GetFilename().c_str());
887 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
892 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
894 // On PocketPC you can disable OK-only dialogs policy using system option
895 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
896 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
898 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
899 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
900 wxEmptyString
, wxEmptyString
, wildcards
,
903 if (dialog
.ShowModal() == wxID_OK
)
905 wxArrayString paths
, filenames
;
907 dialog
.GetPaths(paths
);
908 dialog
.GetFilenames(filenames
);
911 size_t count
= paths
.GetCount();
912 for ( size_t n
= 0; n
< count
; n
++ )
914 s
.Printf(_T("File %d: %s (%s)\n"),
915 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
919 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
922 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
926 // restore system option
927 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
930 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
932 wxGenericFileDialog
dialog(this,
933 _T("Testing save file dialog"),
936 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
937 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
939 dialog
.SetFilterIndex(1);
941 if (dialog
.ShowModal() == wxID_OK
)
943 wxLogMessage(_T("%s, filter %d"),
944 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
947 #endif // USE_FILEDLG_GENERIC
950 void MyFrame::DoDirChoose(int style
)
952 // pass some initial dir to wxDirDialog
954 wxGetHomeDir(&dirHome
);
956 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
958 if (dialog
.ShowModal() == wxID_OK
)
960 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
964 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
966 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
969 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
971 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
973 #endif // wxUSE_DIRDLG
975 #if USE_DIRDLG_GENERIC
976 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
978 // pass some initial dir to wxDirDialog
980 wxGetHomeDir(&dirHome
);
982 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
984 if (dialog
.ShowModal() == wxID_OK
)
986 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
990 #endif // USE_DIRDLG_GENERIC
992 #if USE_MODAL_PRESENTATION
993 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
995 MyModalDialog
dlg(this);
998 #endif // USE_MODAL_PRESENTATION
1000 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
1002 bool show
= GetMenuBar()->IsChecked(event
.GetId());
1008 m_dialog
= new MyModelessDialog(this);
1011 m_dialog
->Show(true);
1015 // If m_dialog is NULL, then possibly the system
1016 // didn't report the checked menu item status correctly.
1017 // It should be true just after the menu item was selected,
1018 // if there was no modeless dialog yet.
1020 wxASSERT( m_dialog
!= NULL
);
1026 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1028 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1029 wxDefaultPosition
, wxSize(200, 100));
1030 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1031 dlg
.CentreOnScreen();
1035 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1037 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1038 wxDefaultPosition
, wxSize(200, 100));
1039 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1040 dlg
.CentreOnParent();
1044 void MyFrame::MiniFrame(wxCommandEvent
& WXUNUSED(event
))
1046 wxFrame
*frame
= new wxMiniFrame(this, wxID_ANY
, _T("Mini frame"),
1047 wxDefaultPosition
, wxSize(300, 100),
1048 wxCAPTION
| wxCLOSE_BOX
);
1049 new wxStaticText(frame
,
1051 _T("Mini frames have slightly different appearance"),
1053 new wxStaticText(frame
,
1055 _T("from the normal frames but that's the only difference."),
1058 frame
->CentreOnParent();
1062 void MyFrame::DlgOnTop(wxCommandEvent
& WXUNUSED(event
))
1064 wxDialog
dlg(this, wxID_ANY
, _T("Dialog staying on top of other windows"),
1065 wxDefaultPosition
, wxSize(300, 100),
1066 wxDEFAULT_DIALOG_STYLE
| wxSTAY_ON_TOP
);
1067 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1071 #if wxUSE_STARTUP_TIPS
1072 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1074 static size_t s_index
= (size_t)-1;
1076 if ( s_index
== (size_t)-1 )
1080 // this is completely bogus, we don't know how many lines are there
1081 // in the file, but who cares, it's a demo only...
1082 s_index
= rand() % 5;
1085 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1087 bool showAtStartup
= wxShowTip(this, tipProvider
);
1089 if ( showAtStartup
)
1091 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1092 wxOK
| wxICON_INFORMATION
, this);
1095 s_index
= tipProvider
->GetCurrentTip();
1098 #endif // wxUSE_STARTUP_TIPS
1100 #if USE_SETTINGS_DIALOG
1101 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1103 SettingsDialog
dialog(this, event
.GetId());
1106 #endif // USE_SETTINGS_DIALOG
1108 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1110 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1114 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1117 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent
& WXUNUSED(event
))
1119 StdButtonSizerDialog
dialog(this);
1123 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1128 #if wxUSE_PROGRESSDLG
1130 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1132 static const int max
= 100;
1134 wxProgressDialog
dialog(_T("Progress dialog example"),
1135 _T("An informative message"),
1141 // wxPD_AUTO_HIDE | -- try this as well
1143 wxPD_ESTIMATED_TIME
|
1145 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1149 for ( int i
= 0; i
<= max
; i
++ )
1155 // test both modes of wxProgressDialog behaviour: start in
1156 // indeterminate mode but switch to the determinate one later
1157 const bool determinate
= i
> max
/2;
1161 msg
= _T("That's all, folks!");
1163 else if ( !determinate
)
1165 msg
= _T("Testing indeterminate mode");
1167 else if ( determinate
)
1169 msg
= _T("Now in standard determinate mode");
1172 // will be set to true if "Skip" button was pressed
1176 cont
= dialog
.Update(i
, msg
, &skip
);
1180 cont
= dialog
.Pulse(msg
, &skip
);
1183 // each skip will move progress about quarter forward
1189 if ( wxMessageBox(_T("Do you really want to cancel?"),
1190 _T("Progress dialog question"), // caption
1191 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1201 wxLogStatus(wxT("Progress dialog aborted!"));
1205 wxLogStatus(wxT("Countdown from %d finished"), max
);
1209 #endif // wxUSE_PROGRESSDLG
1213 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1215 info
.SetName(_T("Dialogs Sample"));
1216 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1217 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1218 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1219 info
.AddDeveloper(_T("Vadim Zeitlin"));
1222 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1224 InitAboutInfoMinimal(info
);
1226 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1229 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1231 InitAboutInfoMinimal(info
);
1233 // we can add a second developer
1234 info
.AddDeveloper(_T("A.N. Other"));
1236 // or we can add several persons at once like this
1237 static const wxChar
*docwriters
[] =
1239 _T("First D. Writer"),
1243 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1244 info
.SetLicence(wxString::FromAscii(
1245 " wxWindows Library Licence, Version 3.1\n"
1246 " ======================================\n"
1248 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1250 " Everyone is permitted to copy and distribute verbatim copies\n"
1251 " of this licence document, but changing it is not allowed.\n"
1253 " WXWINDOWS LIBRARY LICENCE\n"
1254 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1256 " ...and so on and so forth...\n"
1259 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1262 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1264 wxAboutDialogInfo info
;
1265 InitAboutInfoMinimal(info
);
1270 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1272 wxAboutDialogInfo info
;
1273 InitAboutInfoWebsite(info
);
1278 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1280 wxAboutDialogInfo info
;
1281 InitAboutInfoAll(info
);
1286 // a trivial example of a custom dialog class
1287 class MyAboutDialog
: public wxGenericAboutDialog
1290 MyAboutDialog(const wxAboutDialogInfo
& info
)
1295 // add some custom controls
1296 virtual void DoAddCustomControls()
1298 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1299 AddText(_T("Some custom text"));
1300 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1304 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1306 wxAboutDialogInfo info
;
1307 InitAboutInfoAll(info
);
1309 MyAboutDialog
dlg(info
);
1313 #endif // wxUSE_ABOUTDLG
1317 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1319 wxWindowDisabler disableAll
;
1321 wxBusyInfo
info(_T("Working, please wait..."), this);
1323 for ( int i
= 0; i
< 18; i
++ )
1333 #endif // wxUSE_BUSYINFO
1335 #if wxUSE_FINDREPLDLG
1337 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1341 delete m_dlgReplace
;
1342 m_dlgReplace
= NULL
;
1346 m_dlgReplace
= new wxFindReplaceDialog
1350 _T("Find and replace dialog"),
1354 m_dlgReplace
->Show(true);
1358 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1367 m_dlgFind
= new wxFindReplaceDialog
1376 m_dlgFind
->Show(true);
1380 static wxString
DecodeFindDialogEventFlags(int flags
)
1383 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1384 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1385 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1386 << _T("case sensitive");
1391 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1393 wxEventType type
= event
.GetEventType();
1395 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1397 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1398 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1399 event
.GetFindString().c_str(),
1400 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1402 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1403 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1405 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1406 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1407 event
.GetFindString().c_str(),
1408 event
.GetReplaceString().c_str(),
1409 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1411 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1413 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1417 if ( dlg
== m_dlgFind
)
1420 idMenu
= DIALOGS_FIND
;
1423 else if ( dlg
== m_dlgReplace
)
1425 txt
= _T("Replace");
1426 idMenu
= DIALOGS_REPLACE
;
1427 m_dlgReplace
= NULL
;
1431 txt
= _T("Unknown");
1434 wxFAIL_MSG( _T("unexpected event") );
1437 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1439 if ( idMenu
!= wxID_ANY
)
1441 GetMenuBar()->Check(idMenu
, false);
1448 wxLogError(wxT("Unknown find dialog event!"));
1452 #endif // wxUSE_FINDREPLDLG
1454 // ----------------------------------------------------------------------------
1456 // ----------------------------------------------------------------------------
1458 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1461 dc
.SetFont(wxGetApp().m_canvasFont
);
1462 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1463 dc
.SetBackgroundMode(wxTRANSPARENT
);
1465 _T("wxWidgets common dialogs")
1466 #if !defined(__SMARTPHONE__)
1467 _T(" test application")
1472 #if USE_MODAL_PRESENTATION
1474 // ----------------------------------------------------------------------------
1476 // ----------------------------------------------------------------------------
1478 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1479 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1481 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1483 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1484 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1487 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1488 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1492 sizerTop
->SetSizeHints(this);
1493 sizerTop
->Fit(this);
1496 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1498 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1499 wxOK
| wxICON_INFORMATION
, this);
1502 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1504 if ( event
.CanVeto() )
1506 wxMessageBox(_T("Use the menu item to close this dialog"),
1507 _T("Modeless dialog"),
1508 wxOK
| wxICON_INFORMATION
, this);
1514 // ----------------------------------------------------------------------------
1516 // ----------------------------------------------------------------------------
1518 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1519 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1521 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1523 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1524 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1525 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1527 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1528 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1529 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1530 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1531 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1535 sizerTop
->SetSizeHints(this);
1536 sizerTop
->Fit(this);
1538 m_btnModal
->SetFocus();
1539 m_btnModal
->SetDefault();
1542 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1544 if ( event
.GetEventObject() == m_btnDelete
)
1549 m_btnDelete
->Disable();
1551 else if ( event
.GetEventObject() == m_btnModal
)
1554 wxGetTextFromUser(_T("Dummy prompt"),
1555 _T("Modal dialog called from dialog"),
1556 wxEmptyString
, this);
1558 wxMessageBox(_T("Modal dialog called from dialog"));
1559 #endif // wxUSE_TEXTDLG
1561 else if ( event
.GetEventObject() == m_btnModeless
)
1563 (new MyModelessDialog(this))->Show();
1571 #endif // USE_MODAL_PRESENTATION
1573 // ----------------------------------------------------------------------------
1574 // StdButtonSizerDialog
1575 // ----------------------------------------------------------------------------
1577 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow
*parent
)
1578 : wxDialog(parent
, wxID_ANY
, wxString(_T("StdButtonSizer dialog")),
1579 wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
),
1580 m_buttonsSizer(NULL
)
1582 wxBoxSizer
*const sizerTop
= new wxBoxSizer(wxVERTICAL
);
1584 wxBoxSizer
*const sizer
= new wxBoxSizer(wxHORIZONTAL
);
1585 wxBoxSizer
*const sizerInside1
= new wxBoxSizer(wxVERTICAL
);
1587 m_chkboxAffirmativeButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Affirmative Button"));
1589 wxStaticBoxSizer
*const sizer1
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Affirmative Button"));
1591 m_radiobtnOk
= new wxRadioButton(this, wxID_ANY
, _("Ok"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1592 m_radiobtnYes
= new wxRadioButton(this, wxID_ANY
, _("Yes"));
1594 wxBoxSizer
*const sizerInside2
= new wxBoxSizer(wxVERTICAL
);
1596 m_chkboxDismissButton
= new wxCheckBox(this, wxID_ANY
, _("Enable Dismiss Button"));
1598 wxStaticBoxSizer
*const sizer2
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("Dismiss Button"));
1600 m_radiobtnCancel
= new wxRadioButton(this, wxID_ANY
, _("Cancel"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
);
1601 m_radiobtnClose
= new wxRadioButton(this, wxID_ANY
, _("Close"));
1603 wxBoxSizer
*const sizer3
= new wxBoxSizer(wxHORIZONTAL
);
1605 m_chkboxNo
= new wxCheckBox(this, wxID_ANY
, _("No"));
1606 m_chkboxHelp
= new wxCheckBox(this, wxID_ANY
, _("Help"));
1607 m_chkboxApply
= new wxCheckBox(this, wxID_ANY
, _("Apply"));
1609 m_chkboxNoDefault
= new wxCheckBox(this, wxID_ANY
, wxT("No Default"));
1611 sizer1
->Add(m_radiobtnOk
, 0, wxALL
, 5);
1612 sizer1
->Add(m_radiobtnYes
, 0, wxALL
, 5);
1614 sizer
->Add(sizerInside1
, 0, 0, 0);
1615 sizerInside1
->Add(m_chkboxAffirmativeButton
, 0, wxALL
, 5);
1616 sizerInside1
->Add(sizer1
, 0, wxALL
, 5);
1617 sizerInside1
->SetItemMinSize(sizer1
, sizer1
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1619 sizer2
->Add(m_radiobtnCancel
, 0, wxALL
, 5);
1620 sizer2
->Add(m_radiobtnClose
, 0, wxALL
, 5);
1622 sizer
->Add(sizerInside2
, 0, 0, 0);
1623 sizerInside2
->Add(m_chkboxDismissButton
, 0, wxALL
, 5);
1624 sizerInside2
->Add(sizer2
, 0, wxALL
, 5);
1625 sizerInside2
->SetItemMinSize(sizer2
, sizer2
->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1627 sizerTop
->Add(sizer
, 0, wxALL
, 5);
1629 sizer3
->Add(m_chkboxNo
, 0, wxALL
, 5);
1630 sizer3
->Add(m_chkboxHelp
, 0, wxALL
, 5);
1631 sizer3
->Add(m_chkboxApply
, 0, wxALL
, 5);
1633 sizerTop
->Add(sizer3
, 0, wxALL
, 5);
1635 sizerTop
->Add(m_chkboxNoDefault
, 0, wxLEFT
|wxRIGHT
, 10);
1637 EnableDisableControls();
1641 sizerTop
->SetSizeHints(this);
1646 void StdButtonSizerDialog::OnEvent(wxCommandEvent
& WXUNUSED(event
))
1650 m_buttonsSizer
->DeleteWindows();
1651 GetSizer()->Remove(m_buttonsSizer
);
1654 EnableDisableControls();
1657 unsigned long numButtons
= 0;
1659 if (m_chkboxAffirmativeButton
->IsChecked())
1661 if (m_radiobtnOk
->GetValue())
1666 else if (m_radiobtnYes
->GetValue())
1673 if (m_chkboxDismissButton
->IsChecked())
1675 if (m_radiobtnCancel
->GetValue())
1681 else if (m_radiobtnClose
->GetValue())
1689 if (m_chkboxApply
->IsChecked())
1695 if (m_chkboxNo
->IsChecked())
1701 if (m_chkboxHelp
->IsChecked())
1707 if (m_chkboxNoDefault
->IsChecked())
1709 flags
|= wxNO_DEFAULT
;
1712 m_buttonsSizer
= CreateStdDialogButtonSizer(flags
);
1713 GetSizer()->Add(m_buttonsSizer
, 0, wxGROW
|wxALL
, 5);
1716 GetSizer()->SetSizeHints(this);
1719 void StdButtonSizerDialog::EnableDisableControls()
1721 const bool affButtonEnabled
= m_chkboxAffirmativeButton
->IsChecked();
1723 m_radiobtnOk
->Enable(affButtonEnabled
);
1724 m_radiobtnYes
->Enable(affButtonEnabled
);
1726 const bool dismissButtonEnabled
= m_chkboxDismissButton
->IsChecked();
1728 m_radiobtnCancel
->Enable(dismissButtonEnabled
);
1729 m_radiobtnClose
->Enable(dismissButtonEnabled
);
1732 #if USE_SETTINGS_DIALOG
1733 // ----------------------------------------------------------------------------
1735 // ----------------------------------------------------------------------------
1737 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1739 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1742 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1744 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1749 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1750 int resizeBorder
= wxRESIZE_BORDER
;
1758 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1759 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1760 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1762 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1764 SetSheetStyle(sheetStyle
);
1765 SetSheetInnerBorder(0);
1766 SetSheetOuterBorder(0);
1768 // create a dummy image list with a few icons
1769 const wxSize
imageSize(32, 32);
1771 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1773 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1775 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1777 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1779 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1784 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1785 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1788 // If using a toolbook, also follow Mac style and don't create buttons
1790 CreateButtons(wxOK
| wxCANCEL
|
1791 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1794 wxBookCtrlBase
* notebook
= GetBookCtrl();
1795 notebook
->SetImageList(m_imageList
);
1797 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1798 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1800 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1801 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1806 SettingsDialog::~SettingsDialog()
1811 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1813 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1815 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1816 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1820 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1821 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1822 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1823 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1827 wxString autoSaveLabel
= _("&Auto-save every");
1828 wxString minsLabel
= _("mins");
1830 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1831 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1834 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1835 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1838 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1840 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1842 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1843 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1847 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1848 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1849 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1850 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1852 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1854 panel
->SetSizer(topSizer
);
1855 topSizer
->Fit(panel
);
1860 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1862 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1864 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1865 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1867 //// PROJECT OR GLOBAL
1868 wxString globalOrProjectChoices
[2];
1869 globalOrProjectChoices
[0] = _("&New projects");
1870 globalOrProjectChoices
[1] = _("&This project");
1872 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1873 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1874 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1876 projectOrGlobal
->SetSelection(0);
1878 //// BACKGROUND STYLE
1879 wxArrayString backgroundStyleChoices
;
1880 backgroundStyleChoices
.Add(wxT("Colour"));
1881 backgroundStyleChoices
.Add(wxT("Image"));
1882 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1884 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1885 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1887 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1889 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1891 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1892 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1893 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1895 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1898 //// FONT SIZE SELECTION
1900 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1901 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1903 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1904 wxSize(80, wxDefaultCoord
));
1905 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1907 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1910 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1911 topSizer
->AddSpacer(5);
1913 panel
->SetSizer(topSizer
);
1914 topSizer
->Fit(panel
);
1919 #endif // USE_SETTINGS_DIALOG