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