]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dialogs.cpp | |
3 | // Purpose: Common dialogs demo | |
4 | // Author: Julian Smart | |
5 | // Modified by: ABX (2004) - adjustements for conditional building + new menu | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx/wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/wx.h" | |
21 | #endif | |
22 | ||
23 | #include "../sample.xpm" | |
24 | ||
25 | #include "wx/datetime.h" | |
26 | #include "wx/image.h" | |
27 | #include "wx/bookctrl.h" | |
28 | #include "wx/artprov.h" | |
29 | #include "wx/imaglist.h" | |
30 | #include "wx/minifram.h" | |
31 | #include "wx/sysopt.h" | |
32 | ||
33 | #if wxUSE_COLOURDLG | |
34 | #include "wx/colordlg.h" | |
35 | #endif // wxUSE_COLOURDLG | |
36 | ||
37 | #if wxUSE_CHOICEDLG | |
38 | #include "wx/choicdlg.h" | |
39 | #endif // wxUSE_CHOICEDLG | |
40 | ||
41 | #if wxUSE_STARTUP_TIPS | |
42 | #include "wx/tipdlg.h" | |
43 | #endif // wxUSE_STARTUP_TIPS | |
44 | ||
45 | #if wxUSE_PROGRESSDLG | |
46 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
47 | #include "wx/datetime.h" // wxDateTime | |
48 | #endif | |
49 | ||
50 | #include "wx/progdlg.h" | |
51 | #endif // wxUSE_PROGRESSDLG | |
52 | ||
53 | #if wxUSE_ABOUTDLG | |
54 | #include "wx/aboutdlg.h" | |
55 | ||
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 | |
60 | ||
61 | #if wxUSE_BUSYINFO | |
62 | #include "wx/busyinfo.h" | |
63 | #endif // wxUSE_BUSYINFO | |
64 | ||
65 | #if wxUSE_NUMBERDLG | |
66 | #include "wx/numdlg.h" | |
67 | #endif // wxUSE_NUMBERDLG | |
68 | ||
69 | #if wxUSE_FILEDLG | |
70 | #include "wx/filedlg.h" | |
71 | #endif // wxUSE_FILEDLG | |
72 | ||
73 | #if wxUSE_DIRDLG | |
74 | #include "wx/dirdlg.h" | |
75 | #endif // wxUSE_DIRDLG | |
76 | ||
77 | #if wxUSE_FONTDLG | |
78 | #include "wx/fontdlg.h" | |
79 | #endif // wxUSE_FONTDLG | |
80 | ||
81 | #if wxUSE_FINDREPLDLG | |
82 | #include "wx/fdrepdlg.h" | |
83 | #endif // wxUSE_FINDREPLDLG | |
84 | ||
85 | #if wxUSE_SPINCTRL | |
86 | #include "wx/spinctrl.h" | |
87 | #endif | |
88 | ||
89 | #include "wx/propdlg.h" | |
90 | ||
91 | #include "dialogs.h" | |
92 | ||
93 | #if USE_COLOURDLG_GENERIC | |
94 | #include "wx/generic/colrdlgg.h" | |
95 | #endif // USE_COLOURDLG_GENERIC | |
96 | ||
97 | #if USE_DIRDLG_GENERIC | |
98 | #include "wx/generic/dirdlgg.h" | |
99 | #endif // USE_DIRDLG_GENERIC | |
100 | ||
101 | #if USE_FILEDLG_GENERIC | |
102 | #include "wx/generic/filedlgg.h" | |
103 | #endif // USE_FILEDLG_GENERIC | |
104 | ||
105 | #if USE_FONTDLG_GENERIC | |
106 | #include "wx/generic/fontdlgg.h" | |
107 | #endif // USE_FONTDLG_GENERIC | |
108 | ||
109 | IMPLEMENT_APP(MyApp) | |
110 | ||
111 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) | |
112 | EVT_PAINT(MyCanvas::OnPaint) | |
113 | END_EVENT_TABLE() | |
114 | ||
115 | ||
116 | ||
117 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
118 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) | |
119 | ||
120 | #if wxUSE_COLOURDLG | |
121 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) | |
122 | #endif // wxUSE_COLOURDLG | |
123 | ||
124 | #if wxUSE_FONTDLG | |
125 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) | |
126 | #endif // wxUSE_FONTDLG | |
127 | ||
128 | #if wxUSE_LOG_DIALOG | |
129 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) | |
130 | #endif // wxUSE_LOG_DIALOG | |
131 | ||
132 | #if wxUSE_TEXTDLG | |
133 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) | |
134 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
135 | #endif // wxUSE_TEXTDLG | |
136 | ||
137 | #if wxUSE_NUMBERDLG | |
138 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) | |
139 | #endif // wxUSE_NUMBERDLG | |
140 | ||
141 | #if wxUSE_CHOICEDLG | |
142 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) | |
143 | EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice) | |
144 | #endif // wxUSE_CHOICEDLG | |
145 | ||
146 | #if wxUSE_FILEDLG | |
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 | |
152 | ||
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 | |
158 | ||
159 | #if wxUSE_DIRDLG | |
160 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) | |
161 | EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew) | |
162 | #endif // wxUSE_DIRDLG | |
163 | ||
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 | ||
172 | #if wxUSE_STARTUP_TIPS | |
173 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) | |
174 | #endif // wxUSE_STARTUP_TIPS | |
175 | ||
176 | #if USE_FONTDLG_GENERIC | |
177 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) | |
178 | #endif // USE_FONTDLG_GENERIC | |
179 | ||
180 | #if USE_DIRDLG_GENERIC | |
181 | EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) | |
182 | #endif // wxMSW || wxMAC | |
183 | ||
184 | #if USE_COLOURDLG_GENERIC | |
185 | EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) | |
186 | #endif // USE_COLOURDLG_GENERIC | |
187 | ||
188 | #if wxUSE_PROGRESSDLG | |
189 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
190 | #endif // wxUSE_PROGRESSDLG | |
191 | ||
192 | #if wxUSE_ABOUTDLG | |
193 | EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog) | |
194 | EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog) | |
195 | EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog) | |
196 | EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog) | |
197 | #endif // wxUSE_ABOUTDLG | |
198 | ||
199 | #if wxUSE_BUSYINFO | |
200 | EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo) | |
201 | #endif // wxUSE_BUSYINFO | |
202 | ||
203 | #if wxUSE_FINDREPLDLG | |
204 | EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog) | |
205 | EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog) | |
206 | ||
207 | EVT_FIND(wxID_ANY, MyFrame::OnFindDialog) | |
208 | EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog) | |
209 | EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog) | |
210 | EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog) | |
211 | EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog) | |
212 | #endif // wxUSE_FINDREPLDLG | |
213 | ||
214 | #if USE_SETTINGS_DIALOG | |
215 | EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet) | |
216 | EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheet) | |
217 | EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet) | |
218 | #endif | |
219 | ||
220 | EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog) | |
221 | EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) | |
222 | ||
223 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) | |
224 | END_EVENT_TABLE() | |
225 | ||
226 | #if USE_MODAL_PRESENTATION | |
227 | ||
228 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) | |
229 | EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton) | |
230 | END_EVENT_TABLE() | |
231 | ||
232 | BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog) | |
233 | EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton) | |
234 | EVT_CLOSE(MyModelessDialog::OnClose) | |
235 | END_EVENT_TABLE() | |
236 | ||
237 | #endif // USE_MODAL_PRESENTATION | |
238 | ||
239 | BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog) | |
240 | EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent) | |
241 | EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent) | |
242 | END_EVENT_TABLE() | |
243 | ||
244 | MyCanvas *myCanvas = (MyCanvas *) NULL; | |
245 | ||
246 | // `Main program' equivalent, creating windows and returning main app frame | |
247 | bool MyApp::OnInit() | |
248 | { | |
249 | if ( !wxApp::OnInit() ) | |
250 | return false; | |
251 | ||
252 | #if wxUSE_IMAGE | |
253 | wxInitAllImageHandlers(); | |
254 | #endif | |
255 | ||
256 | m_canvasTextColour = *wxBLACK; | |
257 | m_canvasFont = *wxNORMAL_FONT; | |
258 | ||
259 | // Create the main frame window | |
260 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example")); | |
261 | ||
262 | // Make a menubar | |
263 | wxMenu *menuDlg = new wxMenu; | |
264 | ||
265 | menuDlg->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); | |
266 | ||
267 | ||
268 | #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
269 | ||
270 | wxMenu *choices_menu = new wxMenu; | |
271 | ||
272 | #if wxUSE_COLOURDLG | |
273 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour")); | |
274 | #endif // wxUSE_COLOURDLG | |
275 | ||
276 | #if wxUSE_FONTDLG | |
277 | choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font")); | |
278 | #endif // wxUSE_FONTDLG | |
279 | ||
280 | #if wxUSE_CHOICEDLG | |
281 | choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C")); | |
282 | choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U")); | |
283 | #endif // wxUSE_CHOICEDLG | |
284 | ||
285 | #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
286 | choices_menu->AppendSeparator(); | |
287 | #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
288 | ||
289 | #if USE_COLOURDLG_GENERIC | |
290 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)")); | |
291 | #endif // USE_COLOURDLG_GENERIC | |
292 | ||
293 | #if USE_FONTDLG_GENERIC | |
294 | choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)")); | |
295 | #endif // USE_FONTDLG_GENERIC | |
296 | ||
297 | menuDlg->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu); | |
298 | #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
299 | ||
300 | ||
301 | #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG | |
302 | ||
303 | wxMenu *entry_menu = new wxMenu; | |
304 | ||
305 | #if wxUSE_TEXTDLG | |
306 | entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E")); | |
307 | entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P")); | |
308 | #endif // wxUSE_TEXTDLG | |
309 | ||
310 | #if wxUSE_NUMBERDLG | |
311 | entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N")); | |
312 | #endif // wxUSE_NUMBERDLG | |
313 | ||
314 | menuDlg->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu); | |
315 | ||
316 | #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG | |
317 | ||
318 | ||
319 | #if wxUSE_FILEDLG | |
320 | ||
321 | wxMenu *filedlg_menu = new wxMenu; | |
322 | filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O")); | |
323 | filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2")); | |
324 | filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); | |
325 | filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); | |
326 | ||
327 | #if USE_FILEDLG_GENERIC | |
328 | filedlg_menu->AppendSeparator(); | |
329 | filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)")); | |
330 | filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)")); | |
331 | filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)")); | |
332 | #endif // USE_FILEDLG_GENERIC | |
333 | ||
334 | menuDlg->Append(wxID_ANY,_T("&File operations"),filedlg_menu); | |
335 | ||
336 | #endif // wxUSE_FILEDLG | |
337 | ||
338 | #if wxUSE_DIRDLG | |
339 | wxMenu *dir_menu = new wxMenu; | |
340 | ||
341 | dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D")); | |
342 | dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D")); | |
343 | menuDlg->Append(wxID_ANY,_T("&Directory operations"),dir_menu); | |
344 | ||
345 | #if USE_DIRDLG_GENERIC | |
346 | dir_menu->AppendSeparator(); | |
347 | dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)")); | |
348 | #endif // USE_DIRDLG_GENERIC | |
349 | ||
350 | #endif // wxUSE_DIRDLG | |
351 | ||
352 | ||
353 | #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG | |
354 | ||
355 | wxMenu *info_menu = new wxMenu; | |
356 | ||
357 | #if wxUSE_STARTUP_TIPS | |
358 | info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T")); | |
359 | #endif // wxUSE_STARTUP_TIPS | |
360 | ||
361 | #if wxUSE_PROGRESSDLG | |
362 | info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G")); | |
363 | #endif // wxUSE_PROGRESSDLG | |
364 | ||
365 | #if wxUSE_BUSYINFO | |
366 | info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B")); | |
367 | #endif // wxUSE_BUSYINFO | |
368 | ||
369 | #if wxUSE_LOG_DIALOG | |
370 | info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L")); | |
371 | #endif // wxUSE_LOG_DIALOG | |
372 | ||
373 | menuDlg->Append(wxID_ANY,_T("&Informative dialogs"),info_menu); | |
374 | ||
375 | #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG | |
376 | ||
377 | ||
378 | #if wxUSE_FINDREPLDLG | |
379 | wxMenu *find_menu = new wxMenu; | |
380 | find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F")); | |
381 | find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F")); | |
382 | menuDlg->Append(wxID_ANY,_T("&Searching"),find_menu); | |
383 | #endif // wxUSE_FINDREPLDLG | |
384 | ||
385 | wxMenu *dialogs_menu = new wxMenu; | |
386 | #if USE_MODAL_PRESENTATION | |
387 | dialogs_menu->Append(DIALOGS_MODAL, _T("&Modal dialog\tCtrl-W")); | |
388 | #endif // USE_MODAL_PRESENTATION | |
389 | dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Mode&less dialog\tCtrl-Z")); | |
390 | dialogs_menu->Append(DIALOGS_CENTRE_SCREEN, _T("Centered on &screen\tShift-Ctrl-1")); | |
391 | dialogs_menu->Append(DIALOGS_CENTRE_PARENT, _T("Centered on &parent\tShift-Ctrl-2")); | |
392 | dialogs_menu->Append(DIALOGS_MINIFRAME, _T("&Mini frame")); | |
393 | menuDlg->Append(wxID_ANY, _T("&Generic dialogs"), dialogs_menu); | |
394 | ||
395 | #if USE_SETTINGS_DIALOG | |
396 | wxMenu *sheet_menu = new wxMenu; | |
397 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Standard property sheet\tShift-Ctrl-P")); | |
398 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, _T("&Toolbook sheet\tShift-Ctrl-T")); | |
399 | ||
400 | if (wxPlatformIs(wxPORT_MAC)) | |
401 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U")); | |
402 | /* | |
403 | #ifdef __WXMAC__ | |
404 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U")); | |
405 | #endif | |
406 | */ | |
407 | menuDlg->Append(wxID_ANY, _T("&Property sheets"), sheet_menu); | |
408 | #endif // USE_SETTINGS_DIALOG | |
409 | ||
410 | menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, _T("&Standard Buttons Sizer Dialog")); | |
411 | ||
412 | menuDlg->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R")); | |
413 | ||
414 | menuDlg->AppendSeparator(); | |
415 | menuDlg->Append(wxID_EXIT, _T("E&xit\tAlt-X")); | |
416 | ||
417 | #if wxUSE_ABOUTDLG | |
418 | wxMenu *menuHelp = new wxMenu; | |
419 | menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)...\tF1")); | |
420 | menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, _T("About (&fancy)...\tShift-F1")); | |
421 | menuHelp->Append(DIALOGS_ABOUTDLG_FULL, _T("About (f&ull)...\tCtrl-F1")); | |
422 | menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, _T("About (&custom)...\tCtrl-Shift-F1")); | |
423 | #endif // wxUSE_ABOUTDLG | |
424 | ||
425 | wxMenuBar *menubar = new wxMenuBar; | |
426 | menubar->Append(menuDlg, _T("&Dialogs")); | |
427 | #if wxUSE_ABOUTDLG | |
428 | menubar->Append(menuHelp, _T("&Help")); | |
429 | #endif // wxUSE_ABOUTDLG | |
430 | ||
431 | frame->SetMenuBar(menubar); | |
432 | ||
433 | myCanvas = new MyCanvas(frame); | |
434 | myCanvas->SetBackgroundColour(*wxWHITE); | |
435 | ||
436 | frame->Centre(wxBOTH); | |
437 | ||
438 | // Show the frame | |
439 | frame->Show(true); | |
440 | ||
441 | SetTopWindow(frame); | |
442 | ||
443 | return true; | |
444 | } | |
445 | ||
446 | // My frame constructor | |
447 | MyFrame::MyFrame(wxWindow *parent, | |
448 | const wxString& title) | |
449 | : wxFrame(parent, wxID_ANY, title) | |
450 | { | |
451 | SetIcon(sample_xpm); | |
452 | ||
453 | #if USE_MODAL_PRESENTATION | |
454 | m_dialog = (MyModelessDialog *)NULL; | |
455 | #endif // USE_MODAL_PRESENTATION | |
456 | ||
457 | #if wxUSE_FINDREPLDLG | |
458 | m_dlgFind = | |
459 | m_dlgReplace = NULL; | |
460 | #endif | |
461 | ||
462 | #if wxUSE_COLOURDLG | |
463 | m_clrData.SetChooseFull(true); | |
464 | for (int i = 0; i < 16; i++) | |
465 | { | |
466 | m_clrData.SetCustomColour( | |
467 | i, | |
468 | wxColour( | |
469 | (unsigned char)(i*16), | |
470 | (unsigned char)(i*16), | |
471 | (unsigned char)(i*16) | |
472 | ) | |
473 | ); | |
474 | } | |
475 | #endif // wxUSE_COLOURDLG | |
476 | ||
477 | #if wxUSE_STATUSBAR | |
478 | CreateStatusBar(); | |
479 | #endif // wxUSE_STATUSBAR | |
480 | } | |
481 | ||
482 | #if wxUSE_COLOURDLG | |
483 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) | |
484 | { | |
485 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
486 | ||
487 | wxColourDialog dialog(this, &m_clrData); | |
488 | dialog.SetTitle(_T("Choose the background colour")); | |
489 | if (dialog.ShowModal() == wxID_OK) | |
490 | { | |
491 | m_clrData = dialog.GetColourData(); | |
492 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
493 | myCanvas->ClearBackground(); | |
494 | myCanvas->Refresh(); | |
495 | } | |
496 | } | |
497 | #endif // wxUSE_COLOURDLG | |
498 | ||
499 | #if USE_COLOURDLG_GENERIC | |
500 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) | |
501 | { | |
502 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
503 | ||
504 | //FIXME:TODO:This has no effect... | |
505 | m_clrData.SetChooseFull(true); | |
506 | ||
507 | for (int i = 0; i < 16; i++) | |
508 | { | |
509 | wxColour colour( | |
510 | (unsigned char)(i*16), | |
511 | (unsigned char)(i*16), | |
512 | (unsigned char)(i*16) | |
513 | ); | |
514 | m_clrData.SetCustomColour(i, colour); | |
515 | } | |
516 | ||
517 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData); | |
518 | if (dialog->ShowModal() == wxID_OK) | |
519 | { | |
520 | m_clrData = dialog->GetColourData(); | |
521 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
522 | myCanvas->ClearBackground(); | |
523 | myCanvas->Refresh(); | |
524 | } | |
525 | dialog->Destroy(); | |
526 | } | |
527 | #endif // USE_COLOURDLG_GENERIC | |
528 | ||
529 | #if wxUSE_FONTDLG | |
530 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) | |
531 | { | |
532 | wxFontData data; | |
533 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
534 | data.SetColour(wxGetApp().m_canvasTextColour); | |
535 | ||
536 | // you might also do this: | |
537 | // | |
538 | // wxFontDialog dialog; | |
539 | // if ( !dialog.Create(this, data) { ... error ... } | |
540 | // | |
541 | wxFontDialog dialog(this, data); | |
542 | ||
543 | if (dialog.ShowModal() == wxID_OK) | |
544 | { | |
545 | wxFontData retData = dialog.GetFontData(); | |
546 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
547 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
548 | myCanvas->Refresh(); | |
549 | } | |
550 | //else: cancelled by the user, don't change the font | |
551 | } | |
552 | #endif // wxUSE_FONTDLG | |
553 | ||
554 | #if USE_FONTDLG_GENERIC | |
555 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) | |
556 | { | |
557 | wxFontData data; | |
558 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
559 | data.SetColour(wxGetApp().m_canvasTextColour); | |
560 | ||
561 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data); | |
562 | if (dialog->ShowModal() == wxID_OK) | |
563 | { | |
564 | wxFontData retData = dialog->GetFontData(); | |
565 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
566 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
567 | myCanvas->Refresh(); | |
568 | } | |
569 | dialog->Destroy(); | |
570 | } | |
571 | #endif // USE_FONTDLG_GENERIC | |
572 | ||
573 | #if wxUSE_LOG_DIALOG | |
574 | void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event)) | |
575 | { | |
576 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages | |
577 | // being flushed -- test it | |
578 | { | |
579 | wxBusyCursor bc; | |
580 | wxLogMessage(wxT("This is some message - everything is ok so far.")); | |
581 | wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); | |
582 | wxLogWarning(wxT("And then something went wrong!")); | |
583 | ||
584 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
585 | wxYield(); | |
586 | } | |
587 | ||
588 | wxLogError(wxT("Intermediary error handler decided to abort.")); | |
589 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
590 | ||
591 | wxLog::FlushActive(); | |
592 | ||
593 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); | |
594 | } | |
595 | #endif // wxUSE_LOG_DIALOG | |
596 | ||
597 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) | |
598 | { | |
599 | wxMessageDialog dialog(NULL, | |
600 | _T("This is a message box\nA long, long string to test out the message box properly"), | |
601 | _T("Message box text"), | |
602 | wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_INFORMATION); | |
603 | ||
604 | if ( dialog.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) ) | |
605 | { | |
606 | dialog.SetExtendedMessage(_T("This platform supports custom button labels")); | |
607 | } | |
608 | else | |
609 | { | |
610 | dialog.SetExtendedMessage(_T("Custom button labels are not supported.")); | |
611 | } | |
612 | ||
613 | switch ( dialog.ShowModal() ) | |
614 | { | |
615 | case wxID_YES: | |
616 | wxLogStatus(wxT("You pressed \"Yes\"")); | |
617 | break; | |
618 | ||
619 | case wxID_NO: | |
620 | wxLogStatus(wxT("You pressed \"No\"")); | |
621 | break; | |
622 | ||
623 | case wxID_CANCEL: | |
624 | wxLogStatus(wxT("You pressed \"Cancel\"")); | |
625 | break; | |
626 | ||
627 | default: | |
628 | wxLogError(wxT("Unexpected wxMessageDialog return code!")); | |
629 | } | |
630 | } | |
631 | ||
632 | #if wxUSE_NUMBERDLG | |
633 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) ) | |
634 | { | |
635 | long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n") | |
636 | _T("Even two rows of text."), | |
637 | _T("Enter a number:"), _T("Numeric input test"), | |
638 | 50, 0, 100, this ); | |
639 | ||
640 | wxString msg; | |
641 | int icon; | |
642 | if ( res == -1 ) | |
643 | { | |
644 | msg = _T("Invalid number entered or dialog cancelled."); | |
645 | icon = wxICON_HAND; | |
646 | } | |
647 | else | |
648 | { | |
649 | msg.Printf(_T("You've entered %lu"), res ); | |
650 | icon = wxICON_INFORMATION; | |
651 | } | |
652 | ||
653 | wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this); | |
654 | } | |
655 | #endif // wxUSE_NUMBERDLG | |
656 | ||
657 | #if wxUSE_TEXTDLG | |
658 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) | |
659 | { | |
660 | wxString pwd = wxGetPasswordFromUser(_T("Enter password:"), | |
661 | _T("Password entry dialog"), | |
662 | wxEmptyString, | |
663 | this); | |
664 | if ( !pwd.empty() ) | |
665 | { | |
666 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), | |
667 | _T("Got password"), wxOK | wxICON_INFORMATION, this); | |
668 | } | |
669 | } | |
670 | ||
671 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
672 | { | |
673 | wxTextEntryDialog dialog(this, | |
674 | _T("This is a small sample\n") | |
675 | _T("A long, long string to test out the text entrybox"), | |
676 | _T("Please enter a string"), | |
677 | _T("Default value"), | |
678 | wxOK | wxCANCEL); | |
679 | ||
680 | if (dialog.ShowModal() == wxID_OK) | |
681 | { | |
682 | wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this); | |
683 | } | |
684 | } | |
685 | #endif // wxUSE_TEXTDLG | |
686 | ||
687 | #if wxUSE_CHOICEDLG | |
688 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) | |
689 | { | |
690 | const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ; | |
691 | ||
692 | wxSingleChoiceDialog dialog(this, | |
693 | _T("This is a small sample\n") | |
694 | _T("A single-choice convenience dialog"), | |
695 | _T("Please select a value"), | |
696 | WXSIZEOF(choices), choices); | |
697 | ||
698 | dialog.SetSelection(2); | |
699 | ||
700 | if (dialog.ShowModal() == wxID_OK) | |
701 | { | |
702 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string")); | |
703 | dialog2.ShowModal(); | |
704 | } | |
705 | } | |
706 | ||
707 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) | |
708 | { | |
709 | const wxString choices[] = | |
710 | { | |
711 | _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"), | |
712 | _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"), | |
713 | _T("Eleven"), _T("Twelve"), _T("Seventeen"), | |
714 | }; | |
715 | ||
716 | wxArrayInt selections; | |
717 | size_t count = wxGetMultipleChoices(selections, | |
718 | _T("This is a small sample\n") | |
719 | _T("A multi-choice convenience dialog"), | |
720 | _T("Please select a value"), | |
721 | WXSIZEOF(choices), choices, | |
722 | this); | |
723 | if ( count ) | |
724 | { | |
725 | wxString msg; | |
726 | msg.Printf(wxT("You selected %u items:\n"), (unsigned)count); | |
727 | for ( size_t n = 0; n < count; n++ ) | |
728 | { | |
729 | msg += wxString::Format(wxT("\t%u: %u (%s)\n"), | |
730 | (unsigned)n, (unsigned)selections[n], | |
731 | choices[selections[n]].c_str()); | |
732 | } | |
733 | wxLogMessage(msg); | |
734 | } | |
735 | //else: cancelled or nothing selected | |
736 | } | |
737 | #endif // wxUSE_CHOICEDLG | |
738 | ||
739 | #if wxUSE_FILEDLG | |
740 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) | |
741 | { | |
742 | wxFileDialog dialog | |
743 | ( | |
744 | this, | |
745 | _T("Testing open file dialog"), | |
746 | wxEmptyString, | |
747 | wxEmptyString, | |
748 | #ifdef __WXMOTIF__ | |
749 | _T("C++ files (*.cpp)|*.cpp") | |
750 | #else | |
751 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") | |
752 | #endif | |
753 | ); | |
754 | ||
755 | dialog.CentreOnParent(); | |
756 | dialog.SetDirectory(wxGetHomeDir()); | |
757 | ||
758 | if (dialog.ShowModal() == wxID_OK) | |
759 | { | |
760 | wxString info; | |
761 | info.Printf(_T("Full file name: %s\n") | |
762 | _T("Path: %s\n") | |
763 | _T("Name: %s"), | |
764 | dialog.GetPath().c_str(), | |
765 | dialog.GetDirectory().c_str(), | |
766 | dialog.GetFilename().c_str()); | |
767 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
768 | dialog2.ShowModal(); | |
769 | } | |
770 | } | |
771 | ||
772 | // this shows how to take advantage of specifying a default extension in the | |
773 | // call to wxFileSelector: it is remembered after each new call and the next | |
774 | // one will use it by default | |
775 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
776 | { | |
777 | static wxString s_extDef; | |
778 | wxString path = wxFileSelector( | |
779 | _T("Select the file to load"), | |
780 | wxEmptyString, wxEmptyString, | |
781 | s_extDef, | |
782 | wxString::Format | |
783 | ( | |
784 | _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"), | |
785 | wxFileSelectorDefaultWildcardStr, | |
786 | wxFileSelectorDefaultWildcardStr | |
787 | ), | |
788 | wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW, | |
789 | this | |
790 | ); | |
791 | ||
792 | if ( !path ) | |
793 | return; | |
794 | ||
795 | // it is just a sample, would use wxSplitPath in real program | |
796 | s_extDef = path.AfterLast(_T('.')); | |
797 | ||
798 | wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), | |
799 | path, s_extDef); | |
800 | } | |
801 | ||
802 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) | |
803 | { | |
804 | wxString wildcards = | |
805 | #ifdef __WXMOTIF__ | |
806 | _T("C++ files (*.cpp)|*.cpp"); | |
807 | #else | |
808 | wxString::Format | |
809 | ( | |
810 | _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"), | |
811 | wxFileSelectorDefaultWildcardStr, | |
812 | wxFileSelectorDefaultWildcardStr | |
813 | ); | |
814 | #endif | |
815 | wxFileDialog dialog(this, _T("Testing open multiple file dialog"), | |
816 | wxEmptyString, wxEmptyString, wildcards, | |
817 | wxFD_OPEN|wxFD_MULTIPLE); | |
818 | ||
819 | if (dialog.ShowModal() == wxID_OK) | |
820 | { | |
821 | wxArrayString paths, filenames; | |
822 | ||
823 | dialog.GetPaths(paths); | |
824 | dialog.GetFilenames(filenames); | |
825 | ||
826 | wxString msg, s; | |
827 | size_t count = paths.GetCount(); | |
828 | for ( size_t n = 0; n < count; n++ ) | |
829 | { | |
830 | s.Printf(_T("File %d: %s (%s)\n"), | |
831 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
832 | ||
833 | msg += s; | |
834 | } | |
835 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
836 | msg += s; | |
837 | ||
838 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
839 | dialog2.ShowModal(); | |
840 | } | |
841 | } | |
842 | ||
843 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) | |
844 | { | |
845 | wxFileDialog dialog(this, | |
846 | _T("Testing save file dialog"), | |
847 | wxEmptyString, | |
848 | _T("myletter.doc"), | |
849 | _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"), | |
850 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); | |
851 | ||
852 | dialog.SetFilterIndex(1); | |
853 | ||
854 | if (dialog.ShowModal() == wxID_OK) | |
855 | { | |
856 | wxLogMessage(_T("%s, filter %d"), | |
857 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
858 | } | |
859 | } | |
860 | #endif // wxUSE_FILEDLG | |
861 | ||
862 | #if USE_FILEDLG_GENERIC | |
863 | void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
864 | { | |
865 | wxGenericFileDialog dialog | |
866 | ( | |
867 | this, | |
868 | _T("Testing open file dialog"), | |
869 | wxEmptyString, | |
870 | wxEmptyString, | |
871 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") | |
872 | ); | |
873 | ||
874 | dialog.SetDirectory(wxGetHomeDir()); | |
875 | ||
876 | if (dialog.ShowModal() == wxID_OK) | |
877 | { | |
878 | wxString info; | |
879 | info.Printf(_T("Full file name: %s\n") | |
880 | _T("Path: %s\n") | |
881 | _T("Name: %s"), | |
882 | dialog.GetPath().c_str(), | |
883 | dialog.GetDirectory().c_str(), | |
884 | dialog.GetFilename().c_str()); | |
885 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
886 | dialog2.ShowModal(); | |
887 | } | |
888 | } | |
889 | ||
890 | void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
891 | { | |
892 | // On PocketPC you can disable OK-only dialogs policy using system option | |
893 | int buttons = wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")); | |
894 | wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1); | |
895 | ||
896 | wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h"); | |
897 | wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"), | |
898 | wxEmptyString, wxEmptyString, wildcards, | |
899 | wxFD_MULTIPLE); | |
900 | ||
901 | if (dialog.ShowModal() == wxID_OK) | |
902 | { | |
903 | wxArrayString paths, filenames; | |
904 | ||
905 | dialog.GetPaths(paths); | |
906 | dialog.GetFilenames(filenames); | |
907 | ||
908 | wxString msg, s; | |
909 | size_t count = paths.GetCount(); | |
910 | for ( size_t n = 0; n < count; n++ ) | |
911 | { | |
912 | s.Printf(_T("File %d: %s (%s)\n"), | |
913 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
914 | ||
915 | msg += s; | |
916 | } | |
917 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
918 | msg += s; | |
919 | ||
920 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
921 | dialog2.ShowModal(); | |
922 | } | |
923 | ||
924 | // restore system option | |
925 | wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons); | |
926 | } | |
927 | ||
928 | void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) ) | |
929 | { | |
930 | wxGenericFileDialog dialog(this, | |
931 | _T("Testing save file dialog"), | |
932 | wxEmptyString, | |
933 | _T("myletter.doc"), | |
934 | _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"), | |
935 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); | |
936 | ||
937 | dialog.SetFilterIndex(1); | |
938 | ||
939 | if (dialog.ShowModal() == wxID_OK) | |
940 | { | |
941 | wxLogMessage(_T("%s, filter %d"), | |
942 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
943 | } | |
944 | } | |
945 | #endif // USE_FILEDLG_GENERIC | |
946 | ||
947 | #if wxUSE_DIRDLG | |
948 | void MyFrame::DoDirChoose(int style) | |
949 | { | |
950 | // pass some initial dir to wxDirDialog | |
951 | wxString dirHome; | |
952 | wxGetHomeDir(&dirHome); | |
953 | ||
954 | wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style); | |
955 | ||
956 | if (dialog.ShowModal() == wxID_OK) | |
957 | { | |
958 | wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str()); | |
959 | } | |
960 | } | |
961 | ||
962 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) | |
963 | { | |
964 | DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); | |
965 | } | |
966 | ||
967 | void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) ) | |
968 | { | |
969 | DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST); | |
970 | } | |
971 | #endif // wxUSE_DIRDLG | |
972 | ||
973 | #if USE_DIRDLG_GENERIC | |
974 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) | |
975 | { | |
976 | // pass some initial dir to wxDirDialog | |
977 | wxString dirHome; | |
978 | wxGetHomeDir(&dirHome); | |
979 | ||
980 | wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome); | |
981 | ||
982 | if (dialog.ShowModal() == wxID_OK) | |
983 | { | |
984 | wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path")); | |
985 | dialog2.ShowModal(); | |
986 | } | |
987 | } | |
988 | #endif // USE_DIRDLG_GENERIC | |
989 | ||
990 | #if USE_MODAL_PRESENTATION | |
991 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) | |
992 | { | |
993 | MyModalDialog dlg(this); | |
994 | dlg.ShowModal(); | |
995 | } | |
996 | #endif // USE_MODAL_PRESENTATION | |
997 | ||
998 | void MyFrame::ModelessDlg(wxCommandEvent& event) | |
999 | { | |
1000 | bool show = GetMenuBar()->IsChecked(event.GetId()); | |
1001 | ||
1002 | if ( show ) | |
1003 | { | |
1004 | if ( !m_dialog ) | |
1005 | { | |
1006 | m_dialog = new MyModelessDialog(this); | |
1007 | } | |
1008 | ||
1009 | m_dialog->Show(true); | |
1010 | } | |
1011 | else // hide | |
1012 | { | |
1013 | // If m_dialog is NULL, then possibly the system | |
1014 | // didn't report the checked menu item status correctly. | |
1015 | // It should be true just after the menu item was selected, | |
1016 | // if there was no modeless dialog yet. | |
1017 | ||
1018 | wxASSERT( m_dialog != NULL ); | |
1019 | if (m_dialog) | |
1020 | m_dialog->Hide(); | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event)) | |
1025 | { | |
1026 | wxDialog dlg(this, wxID_ANY, _T("Dialog centered on screen"), | |
1027 | wxDefaultPosition, wxSize(200, 100)); | |
1028 | (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre(); | |
1029 | dlg.CentreOnScreen(); | |
1030 | dlg.ShowModal(); | |
1031 | } | |
1032 | ||
1033 | void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event)) | |
1034 | { | |
1035 | wxDialog dlg(this, wxID_ANY, _T("Dialog centered on parent"), | |
1036 | wxDefaultPosition, wxSize(200, 100)); | |
1037 | (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre(); | |
1038 | dlg.CentreOnParent(); | |
1039 | dlg.ShowModal(); | |
1040 | } | |
1041 | ||
1042 | void MyFrame::MiniFrame(wxCommandEvent& WXUNUSED(event)) | |
1043 | { | |
1044 | wxFrame *frame = new wxMiniFrame(this, wxID_ANY, _T("Mini frame"), | |
1045 | wxDefaultPosition, wxSize(300, 100), | |
1046 | wxCAPTION | wxCLOSE_BOX); | |
1047 | new wxStaticText(frame, | |
1048 | wxID_ANY, | |
1049 | _T("Mini frames have slightly different appearance"), | |
1050 | wxPoint(5, 5)); | |
1051 | new wxStaticText(frame, | |
1052 | wxID_ANY, | |
1053 | _T("from the normal frames but that's the only difference."), | |
1054 | wxPoint(5, 25)); | |
1055 | ||
1056 | frame->CentreOnParent(); | |
1057 | frame->Show(); | |
1058 | } | |
1059 | ||
1060 | #if wxUSE_STARTUP_TIPS | |
1061 | void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event)) | |
1062 | { | |
1063 | static size_t s_index = (size_t)-1; | |
1064 | ||
1065 | if ( s_index == (size_t)-1 ) | |
1066 | { | |
1067 | srand(time(NULL)); | |
1068 | ||
1069 | // this is completely bogus, we don't know how many lines are there | |
1070 | // in the file, but who cares, it's a demo only... | |
1071 | s_index = rand() % 5; | |
1072 | } | |
1073 | ||
1074 | wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index); | |
1075 | ||
1076 | bool showAtStartup = wxShowTip(this, tipProvider); | |
1077 | ||
1078 | if ( showAtStartup ) | |
1079 | { | |
1080 | wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"), | |
1081 | wxOK | wxICON_INFORMATION, this); | |
1082 | } | |
1083 | ||
1084 | s_index = tipProvider->GetCurrentTip(); | |
1085 | delete tipProvider; | |
1086 | } | |
1087 | #endif // wxUSE_STARTUP_TIPS | |
1088 | ||
1089 | #if USE_SETTINGS_DIALOG | |
1090 | void MyFrame::OnPropertySheet(wxCommandEvent& event) | |
1091 | { | |
1092 | SettingsDialog dialog(this, event.GetId()); | |
1093 | dialog.ShowModal(); | |
1094 | } | |
1095 | #endif // USE_SETTINGS_DIALOG | |
1096 | ||
1097 | void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) | |
1098 | { | |
1099 | wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window")); | |
1100 | ||
1101 | wxSleep(3); | |
1102 | ||
1103 | RequestUserAttention(wxUSER_ATTENTION_ERROR); | |
1104 | } | |
1105 | ||
1106 | void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event)) | |
1107 | { | |
1108 | StdButtonSizerDialog dialog(this); | |
1109 | dialog.ShowModal(); | |
1110 | } | |
1111 | ||
1112 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) | |
1113 | { | |
1114 | Close(true); | |
1115 | } | |
1116 | ||
1117 | #if wxUSE_PROGRESSDLG | |
1118 | ||
1119 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
1120 | { | |
1121 | static const int max = 100; | |
1122 | ||
1123 | wxProgressDialog dialog(_T("Progress dialog example"), | |
1124 | _T("An informative message"), | |
1125 | max, // range | |
1126 | this, // parent | |
1127 | wxPD_CAN_ABORT | | |
1128 | wxPD_CAN_SKIP | | |
1129 | wxPD_APP_MODAL | | |
1130 | // wxPD_AUTO_HIDE | -- try this as well | |
1131 | wxPD_ELAPSED_TIME | | |
1132 | wxPD_ESTIMATED_TIME | | |
1133 | wxPD_REMAINING_TIME | |
1134 | | wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small | |
1135 | ); | |
1136 | ||
1137 | bool cont = true; | |
1138 | for ( int i = 0; i <= max; i++ ) | |
1139 | { | |
1140 | wxMilliSleep(200); | |
1141 | ||
1142 | wxString msg; | |
1143 | ||
1144 | // test both modes of wxProgressDialog behaviour: start in | |
1145 | // indeterminate mode but switch to the determinate one later | |
1146 | const bool determinate = i > max/2; | |
1147 | ||
1148 | if ( i == max ) | |
1149 | { | |
1150 | msg = _T("That's all, folks!"); | |
1151 | } | |
1152 | else if ( !determinate ) | |
1153 | { | |
1154 | msg = _T("Testing indeterminate mode"); | |
1155 | } | |
1156 | else if ( determinate ) | |
1157 | { | |
1158 | msg = _T("Now in standard determinate mode"); | |
1159 | } | |
1160 | ||
1161 | // will be set to true if "Skip" button was pressed | |
1162 | bool skip = false; | |
1163 | if ( determinate ) | |
1164 | { | |
1165 | cont = dialog.Update(i, msg, &skip); | |
1166 | } | |
1167 | else | |
1168 | { | |
1169 | cont = dialog.Pulse(msg, &skip); | |
1170 | } | |
1171 | ||
1172 | // each skip will move progress about quarter forward | |
1173 | if ( skip ) | |
1174 | i += max/4; | |
1175 | ||
1176 | if ( !cont ) | |
1177 | { | |
1178 | if ( wxMessageBox(_T("Do you really want to cancel?"), | |
1179 | _T("Progress dialog question"), // caption | |
1180 | wxYES_NO | wxICON_QUESTION) == wxYES ) | |
1181 | break; | |
1182 | ||
1183 | cont = true; | |
1184 | dialog.Resume(); | |
1185 | } | |
1186 | } | |
1187 | ||
1188 | if ( !cont ) | |
1189 | { | |
1190 | wxLogStatus(wxT("Progress dialog aborted!")); | |
1191 | } | |
1192 | else | |
1193 | { | |
1194 | wxLogStatus(wxT("Countdown from %d finished"), max); | |
1195 | } | |
1196 | } | |
1197 | ||
1198 | #endif // wxUSE_PROGRESSDLG | |
1199 | ||
1200 | #if wxUSE_ABOUTDLG | |
1201 | ||
1202 | static void InitAboutInfoMinimal(wxAboutDialogInfo& info) | |
1203 | { | |
1204 | info.SetName(_T("Dialogs Sample")); | |
1205 | info.SetVersion(wxVERSION_NUM_DOT_STRING_T); | |
1206 | info.SetDescription(_T("This sample shows different wxWidgets dialogs")); | |
1207 | info.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team")); | |
1208 | info.AddDeveloper(_T("Vadim Zeitlin")); | |
1209 | } | |
1210 | ||
1211 | static void InitAboutInfoWebsite(wxAboutDialogInfo& info) | |
1212 | { | |
1213 | InitAboutInfoMinimal(info); | |
1214 | ||
1215 | info.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site")); | |
1216 | } | |
1217 | ||
1218 | static void InitAboutInfoAll(wxAboutDialogInfo& info) | |
1219 | { | |
1220 | InitAboutInfoMinimal(info); | |
1221 | ||
1222 | // we can add a second developer | |
1223 | info.AddDeveloper(_T("A.N. Other")); | |
1224 | ||
1225 | // or we can add several persons at once like this | |
1226 | static const wxChar *docwriters[] = | |
1227 | { | |
1228 | _T("First D. Writer"), | |
1229 | _T("Second One"), | |
1230 | }; | |
1231 | ||
1232 | info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters)); | |
1233 | info.SetLicence(wxString::FromAscii( | |
1234 | " wxWindows Library Licence, Version 3.1\n" | |
1235 | " ======================================\n" | |
1236 | "\n" | |
1237 | " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n" | |
1238 | "\n" | |
1239 | " Everyone is permitted to copy and distribute verbatim copies\n" | |
1240 | " of this licence document, but changing it is not allowed.\n" | |
1241 | "\n" | |
1242 | " WXWINDOWS LIBRARY LICENCE\n" | |
1243 | " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n" | |
1244 | "\n" | |
1245 | " ...and so on and so forth...\n" | |
1246 | )); | |
1247 | ||
1248 | info.AddTranslator(_T("Wun Ngo Wen (Martian)")); | |
1249 | } | |
1250 | ||
1251 | void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1252 | { | |
1253 | wxAboutDialogInfo info; | |
1254 | InitAboutInfoMinimal(info); | |
1255 | ||
1256 | wxAboutBox(info); | |
1257 | } | |
1258 | ||
1259 | void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1260 | { | |
1261 | wxAboutDialogInfo info; | |
1262 | InitAboutInfoWebsite(info); | |
1263 | ||
1264 | wxAboutBox(info); | |
1265 | } | |
1266 | ||
1267 | void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1268 | { | |
1269 | wxAboutDialogInfo info; | |
1270 | InitAboutInfoAll(info); | |
1271 | ||
1272 | wxAboutBox(info); | |
1273 | } | |
1274 | ||
1275 | // a trivial example of a custom dialog class | |
1276 | class MyAboutDialog : public wxGenericAboutDialog | |
1277 | { | |
1278 | public: | |
1279 | MyAboutDialog(const wxAboutDialogInfo& info) | |
1280 | { | |
1281 | Create(info); | |
1282 | } | |
1283 | ||
1284 | // add some custom controls | |
1285 | virtual void DoAddCustomControls() | |
1286 | { | |
1287 | AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); | |
1288 | AddText(_T("Some custom text")); | |
1289 | AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); | |
1290 | } | |
1291 | }; | |
1292 | ||
1293 | void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1294 | { | |
1295 | wxAboutDialogInfo info; | |
1296 | InitAboutInfoAll(info); | |
1297 | ||
1298 | MyAboutDialog dlg(info); | |
1299 | dlg.ShowModal(); | |
1300 | } | |
1301 | ||
1302 | #endif // wxUSE_ABOUTDLG | |
1303 | ||
1304 | #if wxUSE_BUSYINFO | |
1305 | ||
1306 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
1307 | { | |
1308 | wxWindowDisabler disableAll; | |
1309 | ||
1310 | wxBusyInfo info(_T("Working, please wait..."), this); | |
1311 | ||
1312 | for ( int i = 0; i < 18; i++ ) | |
1313 | { | |
1314 | //wxUsleep(100); | |
1315 | wxTheApp->Yield(); | |
1316 | } | |
1317 | ||
1318 | wxSleep(2); | |
1319 | //wxWakeUpIdle(); | |
1320 | } | |
1321 | ||
1322 | #endif // wxUSE_BUSYINFO | |
1323 | ||
1324 | #if wxUSE_FINDREPLDLG | |
1325 | ||
1326 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
1327 | { | |
1328 | if ( m_dlgReplace ) | |
1329 | { | |
1330 | delete m_dlgReplace; | |
1331 | m_dlgReplace = NULL; | |
1332 | } | |
1333 | else | |
1334 | { | |
1335 | m_dlgReplace = new wxFindReplaceDialog | |
1336 | ( | |
1337 | this, | |
1338 | &m_findData, | |
1339 | _T("Find and replace dialog"), | |
1340 | wxFR_REPLACEDIALOG | |
1341 | ); | |
1342 | ||
1343 | m_dlgReplace->Show(true); | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
1348 | { | |
1349 | if ( m_dlgFind ) | |
1350 | { | |
1351 | delete m_dlgFind; | |
1352 | m_dlgFind = NULL; | |
1353 | } | |
1354 | else | |
1355 | { | |
1356 | m_dlgFind = new wxFindReplaceDialog | |
1357 | ( | |
1358 | this, | |
1359 | &m_findData, | |
1360 | _T("Find dialog"), | |
1361 | // just for testing | |
1362 | wxFR_NOWHOLEWORD | |
1363 | ); | |
1364 | ||
1365 | m_dlgFind->Show(true); | |
1366 | } | |
1367 | } | |
1368 | ||
1369 | static wxString DecodeFindDialogEventFlags(int flags) | |
1370 | { | |
1371 | wxString str; | |
1372 | str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ") | |
1373 | << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T("")) | |
1374 | << (flags & wxFR_MATCHCASE ? _T("") : _T("not ")) | |
1375 | << _T("case sensitive"); | |
1376 | ||
1377 | return str; | |
1378 | } | |
1379 | ||
1380 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
1381 | { | |
1382 | wxEventType type = event.GetEventType(); | |
1383 | ||
1384 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
1385 | { | |
1386 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), | |
1387 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), | |
1388 | event.GetFindString().c_str(), | |
1389 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1390 | } | |
1391 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
1392 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
1393 | { | |
1394 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), | |
1395 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""), | |
1396 | event.GetFindString().c_str(), | |
1397 | event.GetReplaceString().c_str(), | |
1398 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1399 | } | |
1400 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
1401 | { | |
1402 | wxFindReplaceDialog *dlg = event.GetDialog(); | |
1403 | ||
1404 | int idMenu; | |
1405 | const wxChar *txt; | |
1406 | if ( dlg == m_dlgFind ) | |
1407 | { | |
1408 | txt = _T("Find"); | |
1409 | idMenu = DIALOGS_FIND; | |
1410 | m_dlgFind = NULL; | |
1411 | } | |
1412 | else if ( dlg == m_dlgReplace ) | |
1413 | { | |
1414 | txt = _T("Replace"); | |
1415 | idMenu = DIALOGS_REPLACE; | |
1416 | m_dlgReplace = NULL; | |
1417 | } | |
1418 | else | |
1419 | { | |
1420 | txt = _T("Unknown"); | |
1421 | idMenu = wxID_ANY; | |
1422 | ||
1423 | wxFAIL_MSG( _T("unexpected event") ); | |
1424 | } | |
1425 | ||
1426 | wxLogMessage(wxT("%s dialog is being closed."), txt); | |
1427 | ||
1428 | if ( idMenu != wxID_ANY ) | |
1429 | { | |
1430 | GetMenuBar()->Check(idMenu, false); | |
1431 | } | |
1432 | ||
1433 | dlg->Destroy(); | |
1434 | } | |
1435 | else | |
1436 | { | |
1437 | wxLogError(wxT("Unknown find dialog event!")); | |
1438 | } | |
1439 | } | |
1440 | ||
1441 | #endif // wxUSE_FINDREPLDLG | |
1442 | ||
1443 | // ---------------------------------------------------------------------------- | |
1444 | // MyCanvas | |
1445 | // ---------------------------------------------------------------------------- | |
1446 | ||
1447 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) | |
1448 | { | |
1449 | wxPaintDC dc(this); | |
1450 | dc.SetFont(wxGetApp().m_canvasFont); | |
1451 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
1452 | dc.SetBackgroundMode(wxTRANSPARENT); | |
1453 | dc.DrawText( | |
1454 | _T("wxWidgets common dialogs") | |
1455 | #if !defined(__SMARTPHONE__) | |
1456 | _T(" test application") | |
1457 | #endif | |
1458 | , 10, 10); | |
1459 | } | |
1460 | ||
1461 | #if USE_MODAL_PRESENTATION | |
1462 | ||
1463 | // ---------------------------------------------------------------------------- | |
1464 | // MyModelessDialog | |
1465 | // ---------------------------------------------------------------------------- | |
1466 | ||
1467 | MyModelessDialog::MyModelessDialog(wxWindow *parent) | |
1468 | : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog"))) | |
1469 | { | |
1470 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
1471 | ||
1472 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me")); | |
1473 | wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled")); | |
1474 | check->Disable(); | |
1475 | ||
1476 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
1477 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
1478 | ||
1479 | SetSizer(sizerTop); | |
1480 | ||
1481 | sizerTop->SetSizeHints(this); | |
1482 | sizerTop->Fit(this); | |
1483 | } | |
1484 | ||
1485 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) | |
1486 | { | |
1487 | wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"), | |
1488 | wxOK | wxICON_INFORMATION, this); | |
1489 | } | |
1490 | ||
1491 | void MyModelessDialog::OnClose(wxCloseEvent& event) | |
1492 | { | |
1493 | if ( event.CanVeto() ) | |
1494 | { | |
1495 | wxMessageBox(_T("Use the menu item to close this dialog"), | |
1496 | _T("Modeless dialog"), | |
1497 | wxOK | wxICON_INFORMATION, this); | |
1498 | ||
1499 | event.Veto(); | |
1500 | } | |
1501 | } | |
1502 | ||
1503 | // ---------------------------------------------------------------------------- | |
1504 | // MyModalDialog | |
1505 | // ---------------------------------------------------------------------------- | |
1506 | ||
1507 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
1508 | : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog"))) | |
1509 | { | |
1510 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
1511 | ||
1512 | m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog...")); | |
1513 | m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog")); | |
1514 | m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button")); | |
1515 | ||
1516 | wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close")); | |
1517 | sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); | |
1518 | sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); | |
1519 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); | |
1520 | sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); | |
1521 | ||
1522 | SetSizer(sizerTop); | |
1523 | ||
1524 | sizerTop->SetSizeHints(this); | |
1525 | sizerTop->Fit(this); | |
1526 | ||
1527 | m_btnModal->SetFocus(); | |
1528 | m_btnModal->SetDefault(); | |
1529 | } | |
1530 | ||
1531 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
1532 | { | |
1533 | if ( event.GetEventObject() == m_btnDelete ) | |
1534 | { | |
1535 | delete m_btnModal; | |
1536 | m_btnModal = NULL; | |
1537 | ||
1538 | m_btnDelete->Disable(); | |
1539 | } | |
1540 | else if ( event.GetEventObject() == m_btnModal ) | |
1541 | { | |
1542 | #if wxUSE_TEXTDLG | |
1543 | wxGetTextFromUser(_T("Dummy prompt"), | |
1544 | _T("Modal dialog called from dialog"), | |
1545 | wxEmptyString, this); | |
1546 | #else | |
1547 | wxMessageBox(_T("Modal dialog called from dialog")); | |
1548 | #endif // wxUSE_TEXTDLG | |
1549 | } | |
1550 | else if ( event.GetEventObject() == m_btnModeless ) | |
1551 | { | |
1552 | (new MyModelessDialog(this))->Show(); | |
1553 | } | |
1554 | else | |
1555 | { | |
1556 | event.Skip(); | |
1557 | } | |
1558 | } | |
1559 | ||
1560 | #endif // USE_MODAL_PRESENTATION | |
1561 | ||
1562 | // ---------------------------------------------------------------------------- | |
1563 | // StdButtonSizerDialog | |
1564 | // ---------------------------------------------------------------------------- | |
1565 | ||
1566 | StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent) | |
1567 | : wxDialog(parent, wxID_ANY, wxString(_T("StdButtonSizer dialog")), | |
1568 | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER), | |
1569 | m_buttonsSizer(NULL) | |
1570 | { | |
1571 | wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL); | |
1572 | ||
1573 | wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL); | |
1574 | wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL); | |
1575 | ||
1576 | m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button")); | |
1577 | ||
1578 | wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button")); | |
1579 | ||
1580 | m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
1581 | m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes")); | |
1582 | ||
1583 | wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL); | |
1584 | ||
1585 | m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button")); | |
1586 | ||
1587 | wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button")); | |
1588 | ||
1589 | m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
1590 | m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close")); | |
1591 | ||
1592 | wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL); | |
1593 | ||
1594 | m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No")); | |
1595 | m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help")); | |
1596 | m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply")); | |
1597 | ||
1598 | m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default")); | |
1599 | ||
1600 | sizer1->Add(m_radiobtnOk, 0, wxALL, 5); | |
1601 | sizer1->Add(m_radiobtnYes, 0, wxALL, 5); | |
1602 | ||
1603 | sizer->Add(sizerInside1, 0, 0, 0); | |
1604 | sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5); | |
1605 | sizerInside1->Add(sizer1, 0, wxALL, 5); | |
1606 | sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
1607 | ||
1608 | sizer2->Add(m_radiobtnCancel, 0, wxALL, 5); | |
1609 | sizer2->Add(m_radiobtnClose, 0, wxALL, 5); | |
1610 | ||
1611 | sizer->Add(sizerInside2, 0, 0, 0); | |
1612 | sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5); | |
1613 | sizerInside2->Add(sizer2, 0, wxALL, 5); | |
1614 | sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
1615 | ||
1616 | sizerTop->Add(sizer, 0, wxALL, 5); | |
1617 | ||
1618 | sizer3->Add(m_chkboxNo, 0, wxALL, 5); | |
1619 | sizer3->Add(m_chkboxHelp, 0, wxALL, 5); | |
1620 | sizer3->Add(m_chkboxApply, 0, wxALL, 5); | |
1621 | ||
1622 | sizerTop->Add(sizer3, 0, wxALL, 5); | |
1623 | ||
1624 | sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10); | |
1625 | ||
1626 | EnableDisableControls(); | |
1627 | ||
1628 | SetSizer(sizerTop); | |
1629 | ||
1630 | sizerTop->SetSizeHints(this); | |
1631 | wxCommandEvent ev; | |
1632 | OnEvent(ev); | |
1633 | } | |
1634 | ||
1635 | void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event)) | |
1636 | { | |
1637 | if (m_buttonsSizer) | |
1638 | { | |
1639 | m_buttonsSizer->DeleteWindows(); | |
1640 | GetSizer()->Remove(m_buttonsSizer); | |
1641 | } | |
1642 | ||
1643 | EnableDisableControls(); | |
1644 | ||
1645 | long flags = 0; | |
1646 | unsigned long numButtons = 0; | |
1647 | ||
1648 | if (m_chkboxAffirmativeButton->IsChecked()) | |
1649 | { | |
1650 | if (m_radiobtnOk->GetValue()) | |
1651 | { | |
1652 | flags |= wxOK; | |
1653 | numButtons ++; | |
1654 | } | |
1655 | else if (m_radiobtnYes->GetValue()) | |
1656 | { | |
1657 | flags |= wxYES; | |
1658 | numButtons ++; | |
1659 | } | |
1660 | } | |
1661 | ||
1662 | if (m_chkboxDismissButton->IsChecked()) | |
1663 | { | |
1664 | if (m_radiobtnCancel->GetValue()) | |
1665 | { | |
1666 | flags |= wxCANCEL; | |
1667 | numButtons ++; | |
1668 | } | |
1669 | ||
1670 | else if (m_radiobtnClose->GetValue()) | |
1671 | { | |
1672 | flags |= wxCLOSE; | |
1673 | numButtons ++; | |
1674 | } | |
1675 | ||
1676 | } | |
1677 | ||
1678 | if (m_chkboxApply->IsChecked()) | |
1679 | { | |
1680 | flags |= wxAPPLY; | |
1681 | numButtons ++; | |
1682 | } | |
1683 | ||
1684 | if (m_chkboxNo->IsChecked()) | |
1685 | { | |
1686 | flags |= wxNO; | |
1687 | numButtons ++; | |
1688 | } | |
1689 | ||
1690 | if (m_chkboxHelp->IsChecked()) | |
1691 | { | |
1692 | flags |= wxHELP; | |
1693 | numButtons ++; | |
1694 | } | |
1695 | ||
1696 | if (m_chkboxNoDefault->IsChecked()) | |
1697 | { | |
1698 | flags |= wxNO_DEFAULT; | |
1699 | } | |
1700 | ||
1701 | m_buttonsSizer = CreateStdDialogButtonSizer(flags); | |
1702 | GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5); | |
1703 | ||
1704 | Layout(); | |
1705 | GetSizer()->SetSizeHints(this); | |
1706 | } | |
1707 | ||
1708 | void StdButtonSizerDialog::EnableDisableControls() | |
1709 | { | |
1710 | const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked(); | |
1711 | ||
1712 | m_radiobtnOk->Enable(affButtonEnabled); | |
1713 | m_radiobtnYes->Enable(affButtonEnabled); | |
1714 | ||
1715 | const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked(); | |
1716 | ||
1717 | m_radiobtnCancel->Enable(dismissButtonEnabled); | |
1718 | m_radiobtnClose->Enable(dismissButtonEnabled); | |
1719 | } | |
1720 | ||
1721 | #if USE_SETTINGS_DIALOG | |
1722 | // ---------------------------------------------------------------------------- | |
1723 | // SettingsDialog | |
1724 | // ---------------------------------------------------------------------------- | |
1725 | ||
1726 | IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog) | |
1727 | ||
1728 | BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog) | |
1729 | END_EVENT_TABLE() | |
1730 | ||
1731 | SettingsDialog::SettingsDialog(wxWindow* win, int dialogType) | |
1732 | { | |
1733 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); | |
1734 | ||
1735 | int tabImage1 = -1; | |
1736 | int tabImage2 = -1; | |
1737 | ||
1738 | bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK); | |
1739 | int resizeBorder = wxRESIZE_BORDER; | |
1740 | ||
1741 | if (useToolBook) | |
1742 | { | |
1743 | resizeBorder = 0; | |
1744 | tabImage1 = 0; | |
1745 | tabImage2 = 1; | |
1746 | ||
1747 | int sheetStyle = wxPROPSHEET_SHRINKTOFIT; | |
1748 | if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK) | |
1749 | sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK; | |
1750 | else | |
1751 | sheetStyle |= wxPROPSHEET_TOOLBOOK; | |
1752 | ||
1753 | SetSheetStyle(sheetStyle); | |
1754 | SetSheetInnerBorder(0); | |
1755 | SetSheetOuterBorder(0); | |
1756 | ||
1757 | // create a dummy image list with a few icons | |
1758 | const wxSize imageSize(32, 32); | |
1759 | ||
1760 | m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); | |
1761 | m_imageList-> | |
1762 | Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); | |
1763 | m_imageList-> | |
1764 | Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); | |
1765 | m_imageList-> | |
1766 | Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); | |
1767 | m_imageList-> | |
1768 | Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); | |
1769 | } | |
1770 | else | |
1771 | m_imageList = NULL; | |
1772 | ||
1773 | Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize, | |
1774 | wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder) | |
1775 | ); | |
1776 | ||
1777 | // If using a toolbook, also follow Mac style and don't create buttons | |
1778 | if (!useToolBook) | |
1779 | CreateButtons(wxOK | wxCANCEL | | |
1780 | (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP) | |
1781 | ); | |
1782 | ||
1783 | wxBookCtrlBase* notebook = GetBookCtrl(); | |
1784 | notebook->SetImageList(m_imageList); | |
1785 | ||
1786 | wxPanel* generalSettings = CreateGeneralSettingsPage(notebook); | |
1787 | wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook); | |
1788 | ||
1789 | notebook->AddPage(generalSettings, _("General"), true, tabImage1); | |
1790 | notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2); | |
1791 | ||
1792 | LayoutDialog(); | |
1793 | } | |
1794 | ||
1795 | SettingsDialog::~SettingsDialog() | |
1796 | { | |
1797 | delete m_imageList; | |
1798 | } | |
1799 | ||
1800 | wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent) | |
1801 | { | |
1802 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
1803 | ||
1804 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
1805 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
1806 | ||
1807 | //// LOAD LAST FILE | |
1808 | ||
1809 | wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL ); | |
1810 | wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize); | |
1811 | itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1812 | item0->Add(itemSizer3, 0, wxGROW|wxALL, 0); | |
1813 | ||
1814 | //// AUTOSAVE | |
1815 | ||
1816 | wxString autoSaveLabel = _("&Auto-save every"); | |
1817 | wxString minsLabel = _("mins"); | |
1818 | ||
1819 | wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL ); | |
1820 | wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize); | |
1821 | ||
1822 | #if wxUSE_SPINCTRL | |
1823 | wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString, | |
1824 | wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1); | |
1825 | #endif | |
1826 | ||
1827 | itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1828 | #if wxUSE_SPINCTRL | |
1829 | itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1830 | #endif | |
1831 | itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1832 | item0->Add(itemSizer12, 0, wxGROW|wxALL, 0); | |
1833 | ||
1834 | //// TOOLTIPS | |
1835 | ||
1836 | wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL ); | |
1837 | wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize); | |
1838 | itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1839 | item0->Add(itemSizer8, 0, wxGROW|wxALL, 0); | |
1840 | ||
1841 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
1842 | ||
1843 | panel->SetSizer(topSizer); | |
1844 | topSizer->Fit(panel); | |
1845 | ||
1846 | return panel; | |
1847 | } | |
1848 | ||
1849 | wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent) | |
1850 | { | |
1851 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
1852 | ||
1853 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
1854 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
1855 | ||
1856 | //// PROJECT OR GLOBAL | |
1857 | wxString globalOrProjectChoices[2]; | |
1858 | globalOrProjectChoices[0] = _("&New projects"); | |
1859 | globalOrProjectChoices[1] = _("&This project"); | |
1860 | ||
1861 | wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"), | |
1862 | wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices); | |
1863 | item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5); | |
1864 | ||
1865 | projectOrGlobal->SetSelection(0); | |
1866 | ||
1867 | //// BACKGROUND STYLE | |
1868 | wxArrayString backgroundStyleChoices; | |
1869 | backgroundStyleChoices.Add(wxT("Colour")); | |
1870 | backgroundStyleChoices.Add(wxT("Image")); | |
1871 | wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:")); | |
1872 | ||
1873 | wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL ); | |
1874 | item0->Add(styleSizer, 0, wxGROW|wxALL, 5); | |
1875 | ||
1876 | wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
1877 | ||
1878 | wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices); | |
1879 | ||
1880 | itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1881 | itemSizer2->Add(5, 5, 1, wxALL, 0); | |
1882 | itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1883 | ||
1884 | styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5); | |
1885 | ||
1886 | #if wxUSE_SPINCTRL | |
1887 | //// FONT SIZE SELECTION | |
1888 | ||
1889 | wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:")); | |
1890 | wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL ); | |
1891 | ||
1892 | wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition, | |
1893 | wxSize(80, wxDefaultCoord)); | |
1894 | itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); | |
1895 | ||
1896 | item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5); | |
1897 | #endif | |
1898 | ||
1899 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
1900 | topSizer->AddSpacer(5); | |
1901 | ||
1902 | panel->SetSizer(topSizer); | |
1903 | topSizer->Fit(panel); | |
1904 | ||
1905 | return panel; | |
1906 | } | |
1907 | ||
1908 | #endif // USE_SETTINGS_DIALOG |