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/sysopt.h"
33 #include "wx/colordlg.h"
34 #endif // wxUSE_COLOURDLG
37 #include "wx/choicdlg.h"
38 #endif // wxUSE_CHOICEDLG
40 #if wxUSE_STARTUP_TIPS
41 #include "wx/tipdlg.h"
42 #endif // wxUSE_STARTUP_TIPS
45 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
46 #include "wx/datetime.h" // wxDateTime
49 #include "wx/progdlg.h"
50 #endif // wxUSE_PROGRESSDLG
53 #include "wx/aboutdlg.h"
55 // these headers are only needed for custom about dialog
56 #include "wx/statline.h"
57 #include "wx/generic/aboutdlgg.h"
58 #endif // wxUSE_ABOUTDLG
61 #include "wx/busyinfo.h"
62 #endif // wxUSE_BUSYINFO
65 #include "wx/numdlg.h"
66 #endif // wxUSE_NUMBERDLG
69 #include "wx/filedlg.h"
70 #endif // wxUSE_FILEDLG
73 #include "wx/dirdlg.h"
74 #endif // wxUSE_DIRDLG
77 #include "wx/fontdlg.h"
78 #endif // wxUSE_FONTDLG
81 #include "wx/fdrepdlg.h"
82 #endif // wxUSE_FINDREPLDLG
85 #include "wx/spinctrl.h"
88 #include "wx/propdlg.h"
92 #if USE_COLOURDLG_GENERIC
93 #include "wx/generic/colrdlgg.h"
94 #endif // USE_COLOURDLG_GENERIC
96 #if USE_DIRDLG_GENERIC
97 #include "wx/generic/dirdlgg.h"
98 #endif // USE_DIRDLG_GENERIC
100 #if USE_FILEDLG_GENERIC
101 #include "wx/generic/filedlgg.h"
102 #endif // USE_FILEDLG_GENERIC
104 #if USE_FONTDLG_GENERIC
105 #include "wx/generic/fontdlgg.h"
106 #endif // USE_FONTDLG_GENERIC
110 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
111 EVT_PAINT(MyCanvas::OnPaint
)
116 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
117 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
120 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
121 #endif // wxUSE_COLOURDLG
124 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
125 #endif // wxUSE_FONTDLG
128 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
129 #endif // wxUSE_LOG_DIALOG
132 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
133 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
134 #endif // wxUSE_TEXTDLG
137 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
138 #endif // wxUSE_NUMBERDLG
141 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
142 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
143 #endif // wxUSE_CHOICEDLG
146 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
147 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
148 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
149 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
150 #endif // wxUSE_FILEDLG
152 #if USE_FILEDLG_GENERIC
153 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
154 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
155 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
156 #endif // USE_FILEDLG_GENERIC
159 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
160 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
161 #endif // wxUSE_DIRDLG
163 #if USE_MODAL_PRESENTATION
164 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
165 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
166 EVT_MENU(DIALOGS_CENTRE_SCREEN
, MyFrame::DlgCenteredScreen
)
167 EVT_MENU(DIALOGS_CENTRE_PARENT
, MyFrame::DlgCenteredParent
)
170 #if wxUSE_STARTUP_TIPS
171 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
172 #endif // wxUSE_STARTUP_TIPS
174 #if USE_FONTDLG_GENERIC
175 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
176 #endif // USE_FONTDLG_GENERIC
178 #if USE_DIRDLG_GENERIC
179 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
180 #endif // wxMSW || wxMAC
182 #if USE_COLOURDLG_GENERIC
183 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
184 #endif // USE_COLOURDLG_GENERIC
186 #if wxUSE_PROGRESSDLG
187 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
188 #endif // wxUSE_PROGRESSDLG
191 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE
, MyFrame::ShowSimpleAboutDialog
)
192 EVT_MENU(DIALOGS_ABOUTDLG_FANCY
, MyFrame::ShowFancyAboutDialog
)
193 EVT_MENU(DIALOGS_ABOUTDLG_FULL
, MyFrame::ShowFullAboutDialog
)
194 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM
, MyFrame::ShowCustomAboutDialog
)
195 #endif // wxUSE_ABOUTDLG
198 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
199 #endif // wxUSE_BUSYINFO
201 #if wxUSE_FINDREPLDLG
202 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
203 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
205 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
206 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
207 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
208 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
209 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
210 #endif // wxUSE_FINDREPLDLG
212 #if USE_SETTINGS_DIALOG
213 EVT_MENU(DIALOGS_PROPERTY_SHEET
, MyFrame::OnPropertySheet
)
214 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, MyFrame::OnPropertySheet
)
215 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, MyFrame::OnPropertySheet
)
218 EVT_MENU(DIALOGS_REQUEST
, MyFrame::OnRequestUserAttention
)
220 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
223 #if USE_MODAL_PRESENTATION
225 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
226 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
229 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
230 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
231 EVT_CLOSE(MyModelessDialog::OnClose
)
234 #endif // USE_MODAL_PRESENTATION
236 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
238 // `Main program' equivalent, creating windows and returning main app frame
242 wxInitAllImageHandlers();
245 m_canvasTextColour
= *wxBLACK
;
246 m_canvasFont
= *wxNORMAL_FONT
;
248 // Create the main frame window
249 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
252 wxMenu
*menuDlg
= new wxMenu
;
254 menuDlg
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
257 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
259 wxMenu
*choices_menu
= new wxMenu
;
262 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
263 #endif // wxUSE_COLOURDLG
266 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
267 #endif // wxUSE_FONTDLG
270 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
271 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
272 #endif // wxUSE_CHOICEDLG
274 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
275 choices_menu
->AppendSeparator();
276 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
278 #if USE_COLOURDLG_GENERIC
279 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
280 #endif // USE_COLOURDLG_GENERIC
282 #if USE_FONTDLG_GENERIC
283 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
284 #endif // USE_FONTDLG_GENERIC
286 menuDlg
->Append(wxID_ANY
,_T("&Choices and selectors"),choices_menu
);
287 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
290 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
292 wxMenu
*entry_menu
= new wxMenu
;
295 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
296 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
297 #endif // wxUSE_TEXTDLG
300 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
301 #endif // wxUSE_NUMBERDLG
303 menuDlg
->Append(wxID_ANY
,_T("&Entry dialogs"),entry_menu
);
305 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
310 wxMenu
*filedlg_menu
= new wxMenu
;
311 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
312 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
313 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
314 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
316 #if USE_FILEDLG_GENERIC
317 filedlg_menu
->AppendSeparator();
318 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
319 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
320 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
321 #endif // USE_FILEDLG_GENERIC
323 menuDlg
->Append(wxID_ANY
,_T("&File operations"),filedlg_menu
);
325 #endif // wxUSE_FILEDLG
328 wxMenu
*dir_menu
= new wxMenu
;
330 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
331 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
332 menuDlg
->Append(wxID_ANY
,_T("&Directory operations"),dir_menu
);
334 #if USE_DIRDLG_GENERIC
335 dir_menu
->AppendSeparator();
336 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
337 #endif // USE_DIRDLG_GENERIC
339 #endif // wxUSE_DIRDLG
342 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
344 wxMenu
*info_menu
= new wxMenu
;
346 #if wxUSE_STARTUP_TIPS
347 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
348 #endif // wxUSE_STARTUP_TIPS
350 #if wxUSE_PROGRESSDLG
351 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
352 #endif // wxUSE_PROGRESSDLG
355 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
356 #endif // wxUSE_BUSYINFO
359 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
360 #endif // wxUSE_LOG_DIALOG
362 menuDlg
->Append(wxID_ANY
,_T("&Informative dialogs"),info_menu
);
364 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
367 #if wxUSE_FINDREPLDLG
368 wxMenu
*find_menu
= new wxMenu
;
369 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
370 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
371 menuDlg
->Append(wxID_ANY
,_T("&Searching"),find_menu
);
372 #endif // wxUSE_FINDREPLDLG
374 #if USE_MODAL_PRESENTATION
375 wxMenu
*dialogs_menu
= new wxMenu
;
376 dialogs_menu
->Append(DIALOGS_MODAL
, _T("&Modal dialog\tCtrl-W"));
377 dialogs_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Mode&less dialog\tCtrl-Z"));
378 dialogs_menu
->Append(DIALOGS_CENTRE_SCREEN
, _T("Centered on &screen\tShift-Ctrl-1"));
379 dialogs_menu
->Append(DIALOGS_CENTRE_PARENT
, _T("Centered on &parent\tShift-Ctrl-2"));
380 menuDlg
->Append(wxID_ANY
, _T("&Generic dialogs"), dialogs_menu
);
381 #endif // USE_MODAL_PRESENTATION
383 #if USE_SETTINGS_DIALOG
384 wxMenu
*sheet_menu
= new wxMenu
;
385 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET
, _T("&Standard property sheet\tShift-Ctrl-P"));
386 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK
, _T("&Toolbook sheet\tShift-Ctrl-T"));
388 if (wxPlatformIs(wxPORT_MAC
))
389 sheet_menu
->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
392 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
395 menuDlg
->Append(wxID_ANY
, _T("&Property sheets"), sheet_menu
);
396 #endif // USE_SETTINGS_DIALOG
398 menuDlg
->Append(DIALOGS_REQUEST
, _T("&Request user attention\tCtrl-R"));
400 menuDlg
->AppendSeparator();
401 menuDlg
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
404 wxMenu
*menuHelp
= new wxMenu
;
405 menuHelp
->Append(DIALOGS_ABOUTDLG_SIMPLE
, _T("&About (simple)...\tF1"));
406 menuHelp
->Append(DIALOGS_ABOUTDLG_FANCY
, _T("About (&fancy)...\tShift-F1"));
407 menuHelp
->Append(DIALOGS_ABOUTDLG_FULL
, _T("About (f&ull)...\tCtrl-F1"));
408 menuHelp
->Append(DIALOGS_ABOUTDLG_CUSTOM
, _T("About (&custom)...\tCtrl-Shift-F1"));
409 #endif // wxUSE_ABOUTDLG
411 wxMenuBar
*menubar
= new wxMenuBar
;
412 menubar
->Append(menuDlg
, _T("&Dialogs"));
414 menubar
->Append(menuHelp
, _T("&Help"));
415 #endif // wxUSE_ABOUTDLG
417 frame
->SetMenuBar(menubar
);
419 myCanvas
= new MyCanvas(frame
);
420 myCanvas
->SetBackgroundColour(*wxWHITE
);
422 frame
->Centre(wxBOTH
);
432 // My frame constructor
433 MyFrame::MyFrame(wxWindow
*parent
,
434 const wxString
& title
)
435 : wxFrame(parent
, wxID_ANY
, title
)
439 #if USE_MODAL_PRESENTATION
440 m_dialog
= (MyModelessDialog
*)NULL
;
441 #endif // USE_MODAL_PRESENTATION
443 #if wxUSE_FINDREPLDLG
449 m_clrData
.SetChooseFull(true);
450 for (int i
= 0; i
< 16; i
++)
452 m_clrData
.SetCustomColour(
455 (unsigned char)(i
*16),
456 (unsigned char)(i
*16),
457 (unsigned char)(i
*16)
461 #endif // wxUSE_COLOURDLG
465 #endif // wxUSE_STATUSBAR
469 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
471 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
473 wxColourDialog
dialog(this, &m_clrData
);
474 dialog
.SetTitle(_T("Choose the background colour"));
475 if (dialog
.ShowModal() == wxID_OK
)
477 m_clrData
= dialog
.GetColourData();
478 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
479 myCanvas
->ClearBackground();
483 #endif // wxUSE_COLOURDLG
485 #if USE_COLOURDLG_GENERIC
486 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
488 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
490 //FIXME:TODO:This has no effect...
491 m_clrData
.SetChooseFull(true);
493 for (int i
= 0; i
< 16; i
++)
496 (unsigned char)(i
*16),
497 (unsigned char)(i
*16),
498 (unsigned char)(i
*16)
500 m_clrData
.SetCustomColour(i
, colour
);
503 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &m_clrData
);
504 if (dialog
->ShowModal() == wxID_OK
)
506 m_clrData
= dialog
->GetColourData();
507 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
508 myCanvas
->ClearBackground();
513 #endif // USE_COLOURDLG_GENERIC
516 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
519 data
.SetInitialFont(wxGetApp().m_canvasFont
);
520 data
.SetColour(wxGetApp().m_canvasTextColour
);
522 // you might also do this:
524 // wxFontDialog dialog;
525 // if ( !dialog.Create(this, data) { ... error ... }
527 wxFontDialog
dialog(this, data
);
529 if (dialog
.ShowModal() == wxID_OK
)
531 wxFontData retData
= dialog
.GetFontData();
532 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
533 wxGetApp().m_canvasTextColour
= retData
.GetColour();
536 //else: cancelled by the user, don't change the font
538 #endif // wxUSE_FONTDLG
540 #if USE_FONTDLG_GENERIC
541 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
544 data
.SetInitialFont(wxGetApp().m_canvasFont
);
545 data
.SetColour(wxGetApp().m_canvasTextColour
);
547 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, data
);
548 if (dialog
->ShowModal() == wxID_OK
)
550 wxFontData retData
= dialog
->GetFontData();
551 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
552 wxGetApp().m_canvasTextColour
= retData
.GetColour();
557 #endif // USE_FONTDLG_GENERIC
560 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
562 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
563 // being flushed -- test it
566 wxLogMessage(wxT("This is some message - everything is ok so far."));
567 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
568 wxLogWarning(wxT("And then something went wrong!"));
570 // and if ~wxBusyCursor doesn't do it, then call it manually
574 wxLogError(wxT("Intermediary error handler decided to abort."));
575 wxLogError(wxT("The top level caller detected an unrecoverable error."));
577 wxLog::FlushActive();
579 wxLogMessage(wxT("And this is the same dialog but with only one message."));
581 #endif // wxUSE_LOG_DIALOG
583 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
585 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
586 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
588 switch ( dialog
.ShowModal() )
591 wxLogStatus(wxT("You pressed \"Yes\""));
595 wxLogStatus(wxT("You pressed \"No\""));
599 wxLogStatus(wxT("You pressed \"Cancel\""));
603 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
608 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
610 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
611 _T("Even two rows of text."),
612 _T("Enter a number:"), _T("Numeric input test"),
619 msg
= _T("Invalid number entered or dialog cancelled.");
624 msg
.Printf(_T("You've entered %lu"), res
);
625 icon
= wxICON_INFORMATION
;
628 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
630 #endif // wxUSE_NUMBERDLG
633 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
635 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
636 _T("Password entry dialog"),
641 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
642 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
646 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
648 wxTextEntryDialog
dialog(this,
649 _T("This is a small sample\n")
650 _T("A long, long string to test out the text entrybox"),
651 _T("Please enter a string"),
655 if (dialog
.ShowModal() == wxID_OK
)
657 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
660 #endif // wxUSE_TEXTDLG
663 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
665 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
667 wxSingleChoiceDialog
dialog(this,
668 _T("This is a small sample\n")
669 _T("A single-choice convenience dialog"),
670 _T("Please select a value"),
671 WXSIZEOF(choices
), choices
);
673 dialog
.SetSelection(2);
675 if (dialog
.ShowModal() == wxID_OK
)
677 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
682 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
684 const wxString choices
[] =
686 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
687 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
688 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
691 wxArrayInt selections
;
692 size_t count
= wxGetMultipleChoices(selections
,
693 _T("This is a small sample\n")
694 _T("A multi-choice convenience dialog"),
695 _T("Please select a value"),
696 WXSIZEOF(choices
), choices
,
701 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
702 for ( size_t n
= 0; n
< count
; n
++ )
704 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
705 (unsigned)n
, (unsigned)selections
[n
],
706 choices
[selections
[n
]].c_str());
710 //else: cancelled or nothing selected
712 #endif // wxUSE_CHOICEDLG
715 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
720 _T("Testing open file dialog"),
724 _T("C++ files (*.cpp)|*.cpp")
726 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
730 dialog
.CentreOnParent();
731 dialog
.SetDirectory(wxGetHomeDir());
733 if (dialog
.ShowModal() == wxID_OK
)
736 info
.Printf(_T("Full file name: %s\n")
739 dialog
.GetPath().c_str(),
740 dialog
.GetDirectory().c_str(),
741 dialog
.GetFilename().c_str());
742 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
747 // this shows how to take advantage of specifying a default extension in the
748 // call to wxFileSelector: it is remembered after each new call and the next
749 // one will use it by default
750 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
752 static wxString s_extDef
;
753 wxString path
= wxFileSelector(
754 _T("Select the file to load"),
755 wxEmptyString
, wxEmptyString
,
759 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
760 wxFileSelectorDefaultWildcardStr
,
761 wxFileSelectorDefaultWildcardStr
763 wxFD_OPEN
|wxFD_CHANGE_DIR
|wxFD_PREVIEW
,
770 // it is just a sample, would use wxSplitPath in real program
771 s_extDef
= path
.AfterLast(_T('.'));
773 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
774 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
777 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
781 _T("C++ files (*.cpp)|*.cpp");
785 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
786 wxFileSelectorDefaultWildcardStr
,
787 wxFileSelectorDefaultWildcardStr
790 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
791 wxEmptyString
, wxEmptyString
, wildcards
,
792 wxFD_OPEN
|wxFD_MULTIPLE
);
794 if (dialog
.ShowModal() == wxID_OK
)
796 wxArrayString paths
, filenames
;
798 dialog
.GetPaths(paths
);
799 dialog
.GetFilenames(filenames
);
802 size_t count
= paths
.GetCount();
803 for ( size_t n
= 0; n
< count
; n
++ )
805 s
.Printf(_T("File %d: %s (%s)\n"),
806 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
810 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
813 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
818 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
820 wxFileDialog
dialog(this,
821 _T("Testing save file dialog"),
824 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
825 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
827 dialog
.SetFilterIndex(1);
829 if (dialog
.ShowModal() == wxID_OK
)
831 wxLogMessage(_T("%s, filter %d"),
832 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
835 #endif // wxUSE_FILEDLG
837 #if USE_FILEDLG_GENERIC
838 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
840 wxGenericFileDialog dialog
843 _T("Testing open file dialog"),
846 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
849 dialog
.SetDirectory(wxGetHomeDir());
851 if (dialog
.ShowModal() == wxID_OK
)
854 info
.Printf(_T("Full file name: %s\n")
857 dialog
.GetPath().c_str(),
858 dialog
.GetDirectory().c_str(),
859 dialog
.GetFilename().c_str());
860 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
865 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
867 // On PocketPC you can disable OK-only dialogs policy using system option
868 int buttons
= wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
869 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
871 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
872 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
873 wxEmptyString
, wxEmptyString
, wildcards
,
876 if (dialog
.ShowModal() == wxID_OK
)
878 wxArrayString paths
, filenames
;
880 dialog
.GetPaths(paths
);
881 dialog
.GetFilenames(filenames
);
884 size_t count
= paths
.GetCount();
885 for ( size_t n
= 0; n
< count
; n
++ )
887 s
.Printf(_T("File %d: %s (%s)\n"),
888 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
892 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
895 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
899 // restore system option
900 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons
);
903 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
905 wxGenericFileDialog
dialog(this,
906 _T("Testing save file dialog"),
909 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
910 wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
912 dialog
.SetFilterIndex(1);
914 if (dialog
.ShowModal() == wxID_OK
)
916 wxLogMessage(_T("%s, filter %d"),
917 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
920 #endif // USE_FILEDLG_GENERIC
923 void MyFrame::DoDirChoose(int style
)
925 // pass some initial dir to wxDirDialog
927 wxGetHomeDir(&dirHome
);
929 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
931 if (dialog
.ShowModal() == wxID_OK
)
933 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
937 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
939 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_DIR_MUST_EXIST
);
942 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
944 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_DIR_MUST_EXIST
);
946 #endif // wxUSE_DIRDLG
948 #if USE_DIRDLG_GENERIC
949 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
951 // pass some initial dir to wxDirDialog
953 wxGetHomeDir(&dirHome
);
955 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
957 if (dialog
.ShowModal() == wxID_OK
)
959 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
963 #endif // USE_DIRDLG_GENERIC
965 #if USE_MODAL_PRESENTATION
966 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
968 MyModalDialog
dlg(this);
972 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
974 bool show
= GetMenuBar()->IsChecked(event
.GetId());
980 m_dialog
= new MyModelessDialog(this);
983 m_dialog
->Show(true);
987 // If m_dialog is NULL, then possibly the system
988 // didn't report the checked menu item status correctly.
989 // It should be true just after the menu item was selected,
990 // if there was no modeless dialog yet.
992 wxASSERT( m_dialog
!= NULL
);
998 void MyFrame::DlgCenteredScreen(wxCommandEvent
& WXUNUSED(event
))
1000 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on screen"),
1001 wxDefaultPosition
, wxSize(200, 100));
1002 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1003 dlg
.CentreOnScreen();
1007 void MyFrame::DlgCenteredParent(wxCommandEvent
& WXUNUSED(event
))
1009 wxDialog
dlg(this, wxID_ANY
, _T("Dialog centered on parent"),
1010 wxDefaultPosition
, wxSize(200, 100));
1011 (new wxButton(&dlg
, wxID_OK
, _T("Close")))->Centre();
1012 dlg
.CentreOnParent();
1016 #endif // USE_MODAL_PRESENTATION
1018 #if wxUSE_STARTUP_TIPS
1019 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
1021 static size_t s_index
= (size_t)-1;
1023 if ( s_index
== (size_t)-1 )
1027 // this is completely bogus, we don't know how many lines are there
1028 // in the file, but who cares, it's a demo only...
1029 s_index
= rand() % 5;
1032 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
1034 bool showAtStartup
= wxShowTip(this, tipProvider
);
1036 if ( showAtStartup
)
1038 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1039 wxOK
| wxICON_INFORMATION
, this);
1042 s_index
= tipProvider
->GetCurrentTip();
1045 #endif // wxUSE_STARTUP_TIPS
1047 #if USE_SETTINGS_DIALOG
1048 void MyFrame::OnPropertySheet(wxCommandEvent
& event
)
1050 SettingsDialog
dialog(this, event
.GetId());
1053 #endif // USE_SETTINGS_DIALOG
1055 void MyFrame::OnRequestUserAttention(wxCommandEvent
& WXUNUSED(event
))
1057 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1061 RequestUserAttention(wxUSER_ATTENTION_ERROR
);
1064 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
1069 #if wxUSE_PROGRESSDLG
1071 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
1073 static const int max
= 100;
1075 wxProgressDialog
dialog(_T("Progress dialog example"),
1076 _T("An informative message"),
1082 // wxPD_AUTO_HIDE | -- try this as well
1084 wxPD_ESTIMATED_TIME
|
1086 | wxPD_SMOOTH
// - makes indeterminate mode bar on WinXP very small
1090 for ( int i
= 0; i
<= max
; i
++ )
1096 // test both modes of wxProgressDialog behaviour: start in
1097 // indeterminate mode but switch to the determinate one later
1098 const bool determinate
= i
> max
/2;
1102 msg
= _T("That's all, folks!");
1104 else if ( !determinate
)
1106 msg
= _T("Testing indeterminate mode");
1108 else if ( determinate
)
1110 msg
= _T("Now in standard determinate mode");
1113 // will be set to true if "Skip" button was pressed
1117 cont
= dialog
.Update(i
, msg
, &skip
);
1121 cont
= dialog
.Pulse(msg
, &skip
);
1124 // each skip will move progress about quarter forward
1130 if ( wxMessageBox(_T("Do you really want to cancel?"),
1131 _T("Progress dialog question"), // caption
1132 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
1142 wxLogStatus(wxT("Progress dialog aborted!"));
1146 wxLogStatus(wxT("Countdown from %d finished"), max
);
1150 #endif // wxUSE_PROGRESSDLG
1154 static void InitAboutInfoMinimal(wxAboutDialogInfo
& info
)
1156 info
.SetName(_T("Dialogs Sample"));
1157 info
.SetVersion(wxVERSION_NUM_DOT_STRING_T
);
1158 info
.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1159 info
.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1160 info
.AddDeveloper(_T("Vadim Zeitlin"));
1163 static void InitAboutInfoWebsite(wxAboutDialogInfo
& info
)
1165 InitAboutInfoMinimal(info
);
1167 info
.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1170 static void InitAboutInfoAll(wxAboutDialogInfo
& info
)
1172 InitAboutInfoMinimal(info
);
1174 // we can add a second developer
1175 info
.AddDeveloper(_T("A.N. Other"));
1177 // or we can add several persons at once like this
1178 static const wxChar
*docwriters
[] =
1180 _T("First D. Writer"),
1184 info
.SetDocWriters(wxArrayString(WXSIZEOF(docwriters
), docwriters
));
1185 info
.SetLicence(wxString::FromAscii(
1186 " wxWindows Library Licence, Version 3.1\n"
1187 " ======================================\n"
1189 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1191 " Everyone is permitted to copy and distribute verbatim copies\n"
1192 " of this licence document, but changing it is not allowed.\n"
1194 " WXWINDOWS LIBRARY LICENCE\n"
1195 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1197 " ...and so on and so forth...\n"
1200 info
.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1203 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1205 wxAboutDialogInfo info
;
1206 InitAboutInfoMinimal(info
);
1211 void MyFrame::ShowFancyAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1213 wxAboutDialogInfo info
;
1214 InitAboutInfoWebsite(info
);
1219 void MyFrame::ShowFullAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1221 wxAboutDialogInfo info
;
1222 InitAboutInfoAll(info
);
1227 // a trivial example of a custom dialog class
1228 class MyAboutDialog
: public wxGenericAboutDialog
1231 MyAboutDialog(const wxAboutDialogInfo
& info
)
1236 // add some custom controls
1237 virtual void DoAddCustomControls()
1239 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1240 AddText(_T("Some custom text"));
1241 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1245 void MyFrame::ShowCustomAboutDialog(wxCommandEvent
& WXUNUSED(event
))
1247 wxAboutDialogInfo info
;
1248 InitAboutInfoAll(info
);
1250 MyAboutDialog
dlg(info
);
1254 #endif // wxUSE_ABOUTDLG
1258 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
1260 wxWindowDisabler disableAll
;
1262 wxBusyInfo
info(_T("Working, please wait..."), this);
1264 for ( int i
= 0; i
< 18; i
++ )
1274 #endif // wxUSE_BUSYINFO
1276 #if wxUSE_FINDREPLDLG
1278 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1282 delete m_dlgReplace
;
1283 m_dlgReplace
= NULL
;
1287 m_dlgReplace
= new wxFindReplaceDialog
1291 _T("Find and replace dialog"),
1295 m_dlgReplace
->Show(true);
1299 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1308 m_dlgFind
= new wxFindReplaceDialog
1317 m_dlgFind
->Show(true);
1321 static wxString
DecodeFindDialogEventFlags(int flags
)
1324 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1325 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1326 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1327 << _T("case sensitive");
1332 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1334 wxEventType type
= event
.GetEventType();
1336 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1338 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1339 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1340 event
.GetFindString().c_str(),
1341 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1343 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1344 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1346 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1347 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1348 event
.GetFindString().c_str(),
1349 event
.GetReplaceString().c_str(),
1350 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1352 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1354 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1358 if ( dlg
== m_dlgFind
)
1361 idMenu
= DIALOGS_FIND
;
1364 else if ( dlg
== m_dlgReplace
)
1366 txt
= _T("Replace");
1367 idMenu
= DIALOGS_REPLACE
;
1368 m_dlgReplace
= NULL
;
1372 txt
= _T("Unknown");
1375 wxFAIL_MSG( _T("unexpected event") );
1378 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1380 if ( idMenu
!= wxID_ANY
)
1382 GetMenuBar()->Check(idMenu
, false);
1389 wxLogError(wxT("Unknown find dialog event!"));
1393 #endif // wxUSE_FINDREPLDLG
1395 // ----------------------------------------------------------------------------
1397 // ----------------------------------------------------------------------------
1399 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1402 dc
.SetFont(wxGetApp().m_canvasFont
);
1403 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1404 dc
.SetBackgroundMode(wxTRANSPARENT
);
1406 _T("wxWidgets common dialogs")
1407 #if !defined(__SMARTPHONE__)
1408 _T(" test application")
1413 #if USE_MODAL_PRESENTATION
1415 // ----------------------------------------------------------------------------
1417 // ----------------------------------------------------------------------------
1419 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1420 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1422 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1424 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1425 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1428 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1429 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1433 sizerTop
->SetSizeHints(this);
1434 sizerTop
->Fit(this);
1437 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1439 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1440 wxOK
| wxICON_INFORMATION
, this);
1443 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1445 if ( event
.CanVeto() )
1447 wxMessageBox(_T("Use the menu item to close this dialog"),
1448 _T("Modeless dialog"),
1449 wxOK
| wxICON_INFORMATION
, this);
1455 // ----------------------------------------------------------------------------
1457 // ----------------------------------------------------------------------------
1459 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1460 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1462 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1464 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1465 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1466 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1468 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1469 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1470 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1471 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1472 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1476 sizerTop
->SetSizeHints(this);
1477 sizerTop
->Fit(this);
1479 m_btnModal
->SetFocus();
1480 m_btnModal
->SetDefault();
1483 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1485 if ( event
.GetEventObject() == m_btnDelete
)
1490 m_btnDelete
->Disable();
1492 else if ( event
.GetEventObject() == m_btnModal
)
1495 wxGetTextFromUser(_T("Dummy prompt"),
1496 _T("Modal dialog called from dialog"),
1497 wxEmptyString
, this);
1499 wxMessageBox(_T("Modal dialog called from dialog"));
1500 #endif // wxUSE_TEXTDLG
1502 else if ( event
.GetEventObject() == m_btnModeless
)
1504 (new MyModelessDialog(this))->Show();
1512 #endif // USE_MODAL_PRESENTATION
1514 #if USE_SETTINGS_DIALOG
1515 // ----------------------------------------------------------------------------
1517 // ----------------------------------------------------------------------------
1519 IMPLEMENT_CLASS(SettingsDialog
, wxPropertySheetDialog
)
1521 BEGIN_EVENT_TABLE(SettingsDialog
, wxPropertySheetDialog
)
1524 SettingsDialog::SettingsDialog(wxWindow
* win
, int dialogType
)
1526 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
1531 bool useToolBook
= (dialogType
== DIALOGS_PROPERTY_SHEET_TOOLBOOK
|| dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
);
1532 int resizeBorder
= wxRESIZE_BORDER
;
1540 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
1541 if (dialogType
== DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK
)
1542 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
1544 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
1546 SetSheetStyle(sheetStyle
);
1547 SetSheetInnerBorder(0);
1548 SetSheetOuterBorder(0);
1550 // create a dummy image list with a few icons
1551 const wxSize
imageSize(32, 32);
1553 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
1555 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
1557 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
1559 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
1561 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
1566 Create(win
, wxID_ANY
, _("Preferences"), wxDefaultPosition
, wxDefaultSize
,
1567 wxDEFAULT_DIALOG_STYLE
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
1570 // If using a toolbook, also follow Mac style and don't create buttons
1572 CreateButtons(wxOK
| wxCANCEL
|
1573 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, wxHELP
)
1576 wxBookCtrlBase
* notebook
= GetBookCtrl();
1577 notebook
->SetImageList(m_imageList
);
1579 wxPanel
* generalSettings
= CreateGeneralSettingsPage(notebook
);
1580 wxPanel
* aestheticSettings
= CreateAestheticSettingsPage(notebook
);
1582 notebook
->AddPage(generalSettings
, _("General"), true, tabImage1
);
1583 notebook
->AddPage(aestheticSettings
, _("Aesthetics"), false, tabImage2
);
1588 SettingsDialog::~SettingsDialog()
1593 wxPanel
* SettingsDialog::CreateGeneralSettingsPage(wxWindow
* parent
)
1595 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1597 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1598 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1602 wxBoxSizer
* itemSizer3
= new wxBoxSizer( wxHORIZONTAL
);
1603 wxCheckBox
* checkBox3
= new wxCheckBox(panel
, ID_LOAD_LAST_PROJECT
, _("&Load last project on startup"), wxDefaultPosition
, wxDefaultSize
);
1604 itemSizer3
->Add(checkBox3
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1605 item0
->Add(itemSizer3
, 0, wxGROW
|wxALL
, 0);
1609 wxString autoSaveLabel
= _("&Auto-save every");
1610 wxString minsLabel
= _("mins");
1612 wxBoxSizer
* itemSizer12
= new wxBoxSizer( wxHORIZONTAL
);
1613 wxCheckBox
* checkBox12
= new wxCheckBox(panel
, ID_AUTO_SAVE
, autoSaveLabel
, wxDefaultPosition
, wxDefaultSize
);
1616 wxSpinCtrl
* spinCtrl12
= new wxSpinCtrl(panel
, ID_AUTO_SAVE_MINS
, wxEmptyString
,
1617 wxDefaultPosition
, wxSize(40, wxDefaultCoord
), wxSP_ARROW_KEYS
, 1, 60, 1);
1620 itemSizer12
->Add(checkBox12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1622 itemSizer12
->Add(spinCtrl12
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1624 itemSizer12
->Add(new wxStaticText(panel
, wxID_STATIC
, minsLabel
), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1625 item0
->Add(itemSizer12
, 0, wxGROW
|wxALL
, 0);
1629 wxBoxSizer
* itemSizer8
= new wxBoxSizer( wxHORIZONTAL
);
1630 wxCheckBox
* checkBox6
= new wxCheckBox(panel
, ID_SHOW_TOOLTIPS
, _("Show &tooltips"), wxDefaultPosition
, wxDefaultSize
);
1631 itemSizer8
->Add(checkBox6
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1632 item0
->Add(itemSizer8
, 0, wxGROW
|wxALL
, 0);
1634 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1636 panel
->SetSizer(topSizer
);
1637 topSizer
->Fit(panel
);
1642 wxPanel
* SettingsDialog::CreateAestheticSettingsPage(wxWindow
* parent
)
1644 wxPanel
* panel
= new wxPanel(parent
, wxID_ANY
);
1646 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
1647 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
1649 //// PROJECT OR GLOBAL
1650 wxString globalOrProjectChoices
[2];
1651 globalOrProjectChoices
[0] = _("&New projects");
1652 globalOrProjectChoices
[1] = _("&This project");
1654 wxRadioBox
* projectOrGlobal
= new wxRadioBox(panel
, ID_APPLY_SETTINGS_TO
, _("&Apply settings to:"),
1655 wxDefaultPosition
, wxDefaultSize
, 2, globalOrProjectChoices
);
1656 item0
->Add(projectOrGlobal
, 0, wxGROW
|wxALL
, 5);
1658 projectOrGlobal
->SetSelection(0);
1660 //// BACKGROUND STYLE
1661 wxArrayString backgroundStyleChoices
;
1662 backgroundStyleChoices
.Add(wxT("Colour"));
1663 backgroundStyleChoices
.Add(wxT("Image"));
1664 wxStaticBox
* staticBox3
= new wxStaticBox(panel
, wxID_ANY
, _("Background style:"));
1666 wxBoxSizer
* styleSizer
= new wxStaticBoxSizer( staticBox3
, wxVERTICAL
);
1667 item0
->Add(styleSizer
, 0, wxGROW
|wxALL
, 5);
1669 wxBoxSizer
* itemSizer2
= new wxBoxSizer( wxHORIZONTAL
);
1671 wxChoice
* choice2
= new wxChoice(panel
, ID_BACKGROUND_STYLE
, wxDefaultPosition
, wxDefaultSize
, backgroundStyleChoices
);
1673 itemSizer2
->Add(new wxStaticText(panel
, wxID_ANY
, _("&Window:")), 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1674 itemSizer2
->Add(5, 5, 1, wxALL
, 0);
1675 itemSizer2
->Add(choice2
, 0, wxALL
|wxALIGN_CENTER_VERTICAL
, 5);
1677 styleSizer
->Add(itemSizer2
, 0, wxGROW
|wxALL
, 5);
1680 //// FONT SIZE SELECTION
1682 wxStaticBox
* staticBox1
= new wxStaticBox(panel
, wxID_ANY
, _("Tile font size:"));
1683 wxBoxSizer
* itemSizer5
= new wxStaticBoxSizer( staticBox1
, wxHORIZONTAL
);
1685 wxSpinCtrl
* spinCtrl
= new wxSpinCtrl(panel
, ID_FONT_SIZE
, wxEmptyString
, wxDefaultPosition
,
1686 wxSize(80, wxDefaultCoord
));
1687 itemSizer5
->Add(spinCtrl
, 0, wxALL
|wxALIGN_CENTER_HORIZONTAL
|wxALIGN_CENTER_VERTICAL
, 5);
1689 item0
->Add(itemSizer5
, 0, wxGROW
|wxLEFT
|wxRIGHT
, 5);
1692 topSizer
->Add( item0
, 1, wxGROW
|wxALIGN_CENTRE
|wxALL
, 5 );
1693 topSizer
->AddSpacer(5);
1695 panel
->SetSizer(topSizer
);
1696 topSizer
->Fit(panel
);
1701 #endif // USE_SETTINGS_DIALOG