]>
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/apptrait.h" | |
26 | #include "wx/datetime.h" | |
27 | #include "wx/image.h" | |
28 | #include "wx/bookctrl.h" | |
29 | #include "wx/artprov.h" | |
30 | #include "wx/imaglist.h" | |
31 | #include "wx/minifram.h" | |
32 | #include "wx/sysopt.h" | |
33 | #include "wx/notifmsg.h" | |
34 | ||
35 | #if wxUSE_COLOURDLG | |
36 | #include "wx/colordlg.h" | |
37 | #endif // wxUSE_COLOURDLG | |
38 | ||
39 | #if wxUSE_CHOICEDLG | |
40 | #include "wx/choicdlg.h" | |
41 | #endif // wxUSE_CHOICEDLG | |
42 | ||
43 | #include "wx/rearrangectrl.h" | |
44 | ||
45 | #if wxUSE_STARTUP_TIPS | |
46 | #include "wx/tipdlg.h" | |
47 | #endif // wxUSE_STARTUP_TIPS | |
48 | ||
49 | #if wxUSE_PROGRESSDLG | |
50 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
51 | #include "wx/datetime.h" // wxDateTime | |
52 | #endif | |
53 | ||
54 | #include "wx/progdlg.h" | |
55 | #endif // wxUSE_PROGRESSDLG | |
56 | ||
57 | #if wxUSE_ABOUTDLG | |
58 | #include "wx/aboutdlg.h" | |
59 | ||
60 | // these headers are only needed for custom about dialog | |
61 | #include "wx/statline.h" | |
62 | #include "wx/generic/aboutdlgg.h" | |
63 | #endif // wxUSE_ABOUTDLG | |
64 | ||
65 | #if wxUSE_BUSYINFO | |
66 | #include "wx/busyinfo.h" | |
67 | #endif // wxUSE_BUSYINFO | |
68 | ||
69 | #if wxUSE_NUMBERDLG | |
70 | #include "wx/numdlg.h" | |
71 | #endif // wxUSE_NUMBERDLG | |
72 | ||
73 | #if wxUSE_FILEDLG | |
74 | #include "wx/filedlg.h" | |
75 | #endif // wxUSE_FILEDLG | |
76 | ||
77 | #if wxUSE_DIRDLG | |
78 | #include "wx/dirdlg.h" | |
79 | #endif // wxUSE_DIRDLG | |
80 | ||
81 | #if wxUSE_FONTDLG | |
82 | #include "wx/fontdlg.h" | |
83 | #endif // wxUSE_FONTDLG | |
84 | ||
85 | #if wxUSE_FINDREPLDLG | |
86 | #include "wx/fdrepdlg.h" | |
87 | #endif // wxUSE_FINDREPLDLG | |
88 | ||
89 | #include "wx/spinctrl.h" | |
90 | #include "wx/propdlg.h" | |
91 | ||
92 | #include "dialogs.h" | |
93 | ||
94 | #if USE_COLOURDLG_GENERIC | |
95 | #include "wx/generic/colrdlgg.h" | |
96 | #endif // USE_COLOURDLG_GENERIC | |
97 | ||
98 | #if USE_DIRDLG_GENERIC | |
99 | #include "wx/generic/dirdlgg.h" | |
100 | #endif // USE_DIRDLG_GENERIC | |
101 | ||
102 | #if USE_FILEDLG_GENERIC | |
103 | #include "wx/generic/filedlgg.h" | |
104 | #endif // USE_FILEDLG_GENERIC | |
105 | ||
106 | #if USE_FONTDLG_GENERIC | |
107 | #include "wx/generic/fontdlgg.h" | |
108 | #endif // USE_FONTDLG_GENERIC | |
109 | ||
110 | IMPLEMENT_APP(MyApp) | |
111 | ||
112 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) | |
113 | EVT_PAINT(MyCanvas::OnPaint) | |
114 | END_EVENT_TABLE() | |
115 | ||
116 | ||
117 | ||
118 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
119 | #if wxUSE_MSGDLG | |
120 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) | |
121 | EVT_MENU(DIALOGS_MESSAGE_DIALOG, MyFrame::MessageBoxDialog) | |
122 | EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo) | |
123 | #endif // wxUSE_MSGDLG | |
124 | #if wxUSE_COLOURDLG | |
125 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) | |
126 | EVT_MENU(DIALOGS_GET_COLOUR, MyFrame::GetColour) | |
127 | #endif // wxUSE_COLOURDLG | |
128 | ||
129 | #if wxUSE_FONTDLG | |
130 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) | |
131 | #endif // wxUSE_FONTDLG | |
132 | ||
133 | #if wxUSE_LOG_DIALOG | |
134 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) | |
135 | #endif // wxUSE_LOG_DIALOG | |
136 | ||
137 | #if wxUSE_TEXTDLG | |
138 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) | |
139 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
140 | #endif // wxUSE_TEXTDLG | |
141 | ||
142 | #if wxUSE_NUMBERDLG | |
143 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) | |
144 | #endif // wxUSE_NUMBERDLG | |
145 | ||
146 | #if wxUSE_CHOICEDLG | |
147 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) | |
148 | EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice) | |
149 | #endif // wxUSE_CHOICEDLG | |
150 | ||
151 | EVT_MENU(DIALOGS_REARRANGE, MyFrame::Rearrange) | |
152 | ||
153 | #if wxUSE_FILEDLG | |
154 | EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) | |
155 | EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) | |
156 | EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) | |
157 | EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) | |
158 | #endif // wxUSE_FILEDLG | |
159 | ||
160 | #if USE_FILEDLG_GENERIC | |
161 | EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric) | |
162 | EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric) | |
163 | EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric) | |
164 | #endif // USE_FILEDLG_GENERIC | |
165 | ||
166 | #if wxUSE_DIRDLG | |
167 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) | |
168 | EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew) | |
169 | #endif // wxUSE_DIRDLG | |
170 | ||
171 | #if USE_MODAL_PRESENTATION | |
172 | EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg) | |
173 | #endif // USE_MODAL_PRESENTATION | |
174 | EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg) | |
175 | EVT_MENU(DIALOGS_CENTRE_SCREEN, MyFrame::DlgCenteredScreen) | |
176 | EVT_MENU(DIALOGS_CENTRE_PARENT, MyFrame::DlgCenteredParent) | |
177 | EVT_MENU(DIALOGS_MINIFRAME, MyFrame::MiniFrame) | |
178 | EVT_MENU(DIALOGS_ONTOP, MyFrame::DlgOnTop) | |
179 | ||
180 | #if wxUSE_STARTUP_TIPS | |
181 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) | |
182 | #endif // wxUSE_STARTUP_TIPS | |
183 | ||
184 | #if USE_FONTDLG_GENERIC | |
185 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) | |
186 | #endif // USE_FONTDLG_GENERIC | |
187 | ||
188 | #if USE_DIRDLG_GENERIC | |
189 | EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) | |
190 | #endif // wxMSW || wxMAC | |
191 | ||
192 | #if USE_COLOURDLG_GENERIC | |
193 | EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) | |
194 | #endif // USE_COLOURDLG_GENERIC | |
195 | ||
196 | #if wxUSE_PROGRESSDLG | |
197 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
198 | #endif // wxUSE_PROGRESSDLG | |
199 | ||
200 | #if wxUSE_ABOUTDLG | |
201 | EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog) | |
202 | EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog) | |
203 | EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog) | |
204 | EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog) | |
205 | #endif // wxUSE_ABOUTDLG | |
206 | ||
207 | #if wxUSE_BUSYINFO | |
208 | EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo) | |
209 | #endif // wxUSE_BUSYINFO | |
210 | ||
211 | #if wxUSE_FINDREPLDLG | |
212 | EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog) | |
213 | EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog) | |
214 | ||
215 | EVT_FIND(wxID_ANY, MyFrame::OnFindDialog) | |
216 | EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog) | |
217 | EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog) | |
218 | EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog) | |
219 | EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog) | |
220 | #endif // wxUSE_FINDREPLDLG | |
221 | ||
222 | #if USE_SETTINGS_DIALOG | |
223 | EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet) | |
224 | EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheet) | |
225 | EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet) | |
226 | #endif // USE_SETTINGS_DIALOG | |
227 | ||
228 | EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog) | |
229 | EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION, MyFrame::OnTestDefaultActionDialog) | |
230 | ||
231 | EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) | |
232 | #if wxUSE_NOTIFICATION_MESSAGE | |
233 | EVT_MENU(DIALOGS_NOTIFY_AUTO, MyFrame::OnNotifMsgAuto) | |
234 | EVT_MENU(DIALOGS_NOTIFY_SHOW, MyFrame::OnNotifMsgShow) | |
235 | EVT_MENU(DIALOGS_NOTIFY_HIDE, MyFrame::OnNotifMsgHide) | |
236 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
237 | ||
238 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) | |
239 | END_EVENT_TABLE() | |
240 | ||
241 | #if USE_MODAL_PRESENTATION | |
242 | ||
243 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) | |
244 | EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton) | |
245 | END_EVENT_TABLE() | |
246 | ||
247 | BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog) | |
248 | EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton) | |
249 | EVT_CLOSE(MyModelessDialog::OnClose) | |
250 | END_EVENT_TABLE() | |
251 | ||
252 | #endif // USE_MODAL_PRESENTATION | |
253 | ||
254 | BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog) | |
255 | EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent) | |
256 | EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent) | |
257 | END_EVENT_TABLE() | |
258 | ||
259 | MyCanvas *myCanvas = (MyCanvas *) NULL; | |
260 | ||
261 | // `Main program' equivalent, creating windows and returning main app frame | |
262 | bool MyApp::OnInit() | |
263 | { | |
264 | if ( !wxApp::OnInit() ) | |
265 | return false; | |
266 | ||
267 | #if wxUSE_IMAGE | |
268 | wxInitAllImageHandlers(); | |
269 | #endif | |
270 | ||
271 | m_canvasTextColour = *wxBLACK; | |
272 | m_canvasFont = *wxNORMAL_FONT; | |
273 | ||
274 | // Create the main frame window | |
275 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example")); | |
276 | ||
277 | // Make a menubar | |
278 | wxMenu *menuDlg = new wxMenu; | |
279 | ||
280 | menuDlg->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); | |
281 | menuDlg->Append(DIALOGS_MESSAGE_DIALOG, _T("Message dialog\tShift-Ctrl-M")); | |
282 | ||
283 | ||
284 | #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
285 | ||
286 | wxMenu *choices_menu = new wxMenu; | |
287 | ||
288 | #if wxUSE_COLOURDLG | |
289 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose bg colour")); | |
290 | choices_menu->Append(DIALOGS_GET_COLOUR, _T("&Choose fg colour")); | |
291 | #endif // wxUSE_COLOURDLG | |
292 | ||
293 | #if wxUSE_FONTDLG | |
294 | choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font")); | |
295 | #endif // wxUSE_FONTDLG | |
296 | ||
297 | #if wxUSE_CHOICEDLG | |
298 | choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C")); | |
299 | choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U")); | |
300 | #endif // wxUSE_CHOICEDLG | |
301 | ||
302 | choices_menu->Append(DIALOGS_REARRANGE, _T("&Rearrange dialog\tCtrl-R")); | |
303 | ||
304 | #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
305 | choices_menu->AppendSeparator(); | |
306 | #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
307 | ||
308 | #if USE_COLOURDLG_GENERIC | |
309 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)")); | |
310 | #endif // USE_COLOURDLG_GENERIC | |
311 | ||
312 | #if USE_FONTDLG_GENERIC | |
313 | choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)")); | |
314 | #endif // USE_FONTDLG_GENERIC | |
315 | ||
316 | menuDlg->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu); | |
317 | #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
318 | ||
319 | ||
320 | #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG | |
321 | ||
322 | wxMenu *entry_menu = new wxMenu; | |
323 | ||
324 | #if wxUSE_TEXTDLG | |
325 | entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E")); | |
326 | entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P")); | |
327 | #endif // wxUSE_TEXTDLG | |
328 | ||
329 | #if wxUSE_NUMBERDLG | |
330 | entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N")); | |
331 | #endif // wxUSE_NUMBERDLG | |
332 | ||
333 | menuDlg->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu); | |
334 | ||
335 | #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG | |
336 | ||
337 | ||
338 | #if wxUSE_FILEDLG | |
339 | ||
340 | wxMenu *filedlg_menu = new wxMenu; | |
341 | filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O")); | |
342 | filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2")); | |
343 | filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); | |
344 | filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); | |
345 | ||
346 | #if USE_FILEDLG_GENERIC | |
347 | filedlg_menu->AppendSeparator(); | |
348 | filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)")); | |
349 | filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)")); | |
350 | filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)")); | |
351 | #endif // USE_FILEDLG_GENERIC | |
352 | ||
353 | menuDlg->Append(wxID_ANY,_T("&File operations"),filedlg_menu); | |
354 | ||
355 | #endif // wxUSE_FILEDLG | |
356 | ||
357 | #if wxUSE_DIRDLG | |
358 | wxMenu *dir_menu = new wxMenu; | |
359 | ||
360 | dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D")); | |
361 | dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D")); | |
362 | menuDlg->Append(wxID_ANY,_T("&Directory operations"),dir_menu); | |
363 | ||
364 | #if USE_DIRDLG_GENERIC | |
365 | dir_menu->AppendSeparator(); | |
366 | dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)")); | |
367 | #endif // USE_DIRDLG_GENERIC | |
368 | ||
369 | #endif // wxUSE_DIRDLG | |
370 | ||
371 | ||
372 | #if wxUSE_STARTUP_TIPS || \ | |
373 | wxUSE_PROGRESSDLG || \ | |
374 | wxUSE_BUSYINFO || \ | |
375 | wxUSE_LOG_DIALOG || \ | |
376 | wxUSE_MSGDLG | |
377 | ||
378 | wxMenu *info_menu = new wxMenu; | |
379 | ||
380 | #if wxUSE_STARTUP_TIPS | |
381 | info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T")); | |
382 | #endif // wxUSE_STARTUP_TIPS | |
383 | ||
384 | #if wxUSE_PROGRESSDLG | |
385 | info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G")); | |
386 | #endif // wxUSE_PROGRESSDLG | |
387 | ||
388 | #if wxUSE_BUSYINFO | |
389 | info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B")); | |
390 | #endif // wxUSE_BUSYINFO | |
391 | ||
392 | #if wxUSE_LOG_DIALOG | |
393 | info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L")); | |
394 | #endif // wxUSE_LOG_DIALOG | |
395 | ||
396 | #if wxUSE_MSGDLG | |
397 | info_menu->Append(DIALOGS_MESSAGE_BOX_WXINFO, | |
398 | _T("&wxWidgets information\tCtrl-I")); | |
399 | #endif // wxUSE_MSGDLG | |
400 | ||
401 | menuDlg->Append(wxID_ANY,_T("&Informative dialogs"),info_menu); | |
402 | ||
403 | #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG | |
404 | ||
405 | ||
406 | #if wxUSE_FINDREPLDLG | |
407 | wxMenu *find_menu = new wxMenu; | |
408 | find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F")); | |
409 | find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F")); | |
410 | menuDlg->Append(wxID_ANY,_T("&Searching"),find_menu); | |
411 | #endif // wxUSE_FINDREPLDLG | |
412 | ||
413 | wxMenu *dialogs_menu = new wxMenu; | |
414 | #if USE_MODAL_PRESENTATION | |
415 | dialogs_menu->Append(DIALOGS_MODAL, _T("&Modal dialog\tCtrl-W")); | |
416 | #endif // USE_MODAL_PRESENTATION | |
417 | dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Mode&less dialog\tCtrl-Z")); | |
418 | dialogs_menu->Append(DIALOGS_CENTRE_SCREEN, _T("Centered on &screen\tShift-Ctrl-1")); | |
419 | dialogs_menu->Append(DIALOGS_CENTRE_PARENT, _T("Centered on &parent\tShift-Ctrl-2")); | |
420 | dialogs_menu->Append(DIALOGS_MINIFRAME, _T("&Mini frame")); | |
421 | dialogs_menu->Append(DIALOGS_ONTOP, _T("Dialog staying on &top")); | |
422 | menuDlg->Append(wxID_ANY, _T("&Generic dialogs"), dialogs_menu); | |
423 | ||
424 | #if USE_SETTINGS_DIALOG | |
425 | wxMenu *sheet_menu = new wxMenu; | |
426 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Standard property sheet\tShift-Ctrl-P")); | |
427 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, _T("&Toolbook sheet\tShift-Ctrl-T")); | |
428 | ||
429 | if (wxPlatformIs(wxPORT_MAC)) | |
430 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U")); | |
431 | /* | |
432 | #ifdef __WXMAC__ | |
433 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U")); | |
434 | #endif | |
435 | */ | |
436 | menuDlg->Append(wxID_ANY, _T("&Property sheets"), sheet_menu); | |
437 | #endif // USE_SETTINGS_DIALOG | |
438 | ||
439 | wxMenu *menuNotif = new wxMenu; | |
440 | menuNotif->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-Shift-R")); | |
441 | #if wxUSE_NOTIFICATION_MESSAGE | |
442 | menuNotif->Append(DIALOGS_NOTIFY_AUTO, "&Automatically hidden notification"); | |
443 | menuNotif->Append(DIALOGS_NOTIFY_SHOW, "&Show manual notification"); | |
444 | menuNotif->Append(DIALOGS_NOTIFY_HIDE, "&Hide manual notification"); | |
445 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
446 | menuDlg->AppendSubMenu(menuNotif, "&User notifications"); | |
447 | ||
448 | menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, _T("&Standard Buttons Sizer Dialog")); | |
449 | menuDlg->Append(DIALOGS_TEST_DEFAULT_ACTION, _T("&Test dialog default action")); | |
450 | ||
451 | menuDlg->AppendSeparator(); | |
452 | menuDlg->Append(wxID_EXIT, _T("E&xit\tAlt-X")); | |
453 | ||
454 | #if wxUSE_ABOUTDLG | |
455 | wxMenu *menuHelp = new wxMenu; | |
456 | menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)...\tF1")); | |
457 | menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, _T("About (&fancy)...\tShift-F1")); | |
458 | menuHelp->Append(DIALOGS_ABOUTDLG_FULL, _T("About (f&ull)...\tCtrl-F1")); | |
459 | menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, _T("About (&custom)...\tCtrl-Shift-F1")); | |
460 | #endif // wxUSE_ABOUTDLG | |
461 | ||
462 | wxMenuBar *menubar = new wxMenuBar; | |
463 | menubar->Append(menuDlg, _T("&Dialogs")); | |
464 | #if wxUSE_ABOUTDLG | |
465 | menubar->Append(menuHelp, _T("&Help")); | |
466 | #endif // wxUSE_ABOUTDLG | |
467 | ||
468 | frame->SetMenuBar(menubar); | |
469 | ||
470 | myCanvas = new MyCanvas(frame); | |
471 | myCanvas->SetBackgroundColour(*wxWHITE); | |
472 | ||
473 | frame->Centre(wxBOTH); | |
474 | ||
475 | // Show the frame | |
476 | frame->Show(true); | |
477 | ||
478 | SetTopWindow(frame); | |
479 | ||
480 | return true; | |
481 | } | |
482 | ||
483 | // My frame constructor | |
484 | MyFrame::MyFrame(wxWindow *parent, | |
485 | const wxString& title) | |
486 | : wxFrame(parent, wxID_ANY, title) | |
487 | { | |
488 | SetIcon(sample_xpm); | |
489 | ||
490 | #if USE_MODAL_PRESENTATION | |
491 | m_dialog = (MyModelessDialog *)NULL; | |
492 | #endif // USE_MODAL_PRESENTATION | |
493 | ||
494 | #if wxUSE_FINDREPLDLG | |
495 | m_dlgFind = | |
496 | m_dlgReplace = NULL; | |
497 | #endif | |
498 | ||
499 | #if wxUSE_COLOURDLG | |
500 | m_clrData.SetChooseFull(true); | |
501 | for (int i = 0; i < wxColourData::NUM_CUSTOM; i++) | |
502 | { | |
503 | unsigned char n = i*16; | |
504 | m_clrData.SetCustomColour(i, wxColour(n, n, n)); | |
505 | } | |
506 | #endif // wxUSE_COLOURDLG | |
507 | ||
508 | #if wxUSE_NOTIFICATION_MESSAGE | |
509 | m_notifMsg = NULL; | |
510 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
511 | ||
512 | #if wxUSE_STATUSBAR | |
513 | CreateStatusBar(); | |
514 | #endif // wxUSE_STATUSBAR | |
515 | } | |
516 | ||
517 | MyFrame::~MyFrame() | |
518 | { | |
519 | #if wxUSE_NOTIFICATION_MESSAGE | |
520 | delete m_notifMsg; | |
521 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
522 | } | |
523 | ||
524 | #if wxUSE_COLOURDLG | |
525 | ||
526 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event)) | |
527 | { | |
528 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
529 | ||
530 | wxColourDialog dialog(this, &m_clrData); | |
531 | dialog.SetTitle(_("Please choose the background colour")); | |
532 | if ( dialog.ShowModal() == wxID_OK ) | |
533 | { | |
534 | m_clrData = dialog.GetColourData(); | |
535 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
536 | myCanvas->ClearBackground(); | |
537 | myCanvas->Refresh(); | |
538 | } | |
539 | } | |
540 | ||
541 | void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event)) | |
542 | { | |
543 | wxColour clr = wxGetColourFromUser | |
544 | ( | |
545 | this, | |
546 | wxGetApp().m_canvasTextColour, | |
547 | "Please choose the foreground colour" | |
548 | ); | |
549 | if ( clr.IsOk() ) | |
550 | { | |
551 | wxGetApp().m_canvasTextColour = clr; | |
552 | myCanvas->Refresh(); | |
553 | } | |
554 | //else: dialog cancelled by user | |
555 | } | |
556 | ||
557 | #endif // wxUSE_COLOURDLG | |
558 | ||
559 | ||
560 | #if USE_COLOURDLG_GENERIC | |
561 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) | |
562 | { | |
563 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
564 | ||
565 | //FIXME:TODO:This has no effect... | |
566 | m_clrData.SetChooseFull(true); | |
567 | ||
568 | for (int i = 0; i < 16; i++) | |
569 | { | |
570 | wxColour colour( | |
571 | (unsigned char)(i*16), | |
572 | (unsigned char)(i*16), | |
573 | (unsigned char)(i*16) | |
574 | ); | |
575 | m_clrData.SetCustomColour(i, colour); | |
576 | } | |
577 | ||
578 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData); | |
579 | if (dialog->ShowModal() == wxID_OK) | |
580 | { | |
581 | m_clrData = dialog->GetColourData(); | |
582 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
583 | myCanvas->ClearBackground(); | |
584 | myCanvas->Refresh(); | |
585 | } | |
586 | dialog->Destroy(); | |
587 | } | |
588 | #endif // USE_COLOURDLG_GENERIC | |
589 | ||
590 | #if wxUSE_FONTDLG | |
591 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) | |
592 | { | |
593 | wxFontData data; | |
594 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
595 | data.SetColour(wxGetApp().m_canvasTextColour); | |
596 | ||
597 | // you might also do this: | |
598 | // | |
599 | // wxFontDialog dialog; | |
600 | // if ( !dialog.Create(this, data) { ... error ... } | |
601 | // | |
602 | wxFontDialog dialog(this, data); | |
603 | ||
604 | if (dialog.ShowModal() == wxID_OK) | |
605 | { | |
606 | wxFontData retData = dialog.GetFontData(); | |
607 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
608 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
609 | myCanvas->Refresh(); | |
610 | } | |
611 | //else: cancelled by the user, don't change the font | |
612 | } | |
613 | #endif // wxUSE_FONTDLG | |
614 | ||
615 | #if USE_FONTDLG_GENERIC | |
616 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) | |
617 | { | |
618 | wxFontData data; | |
619 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
620 | data.SetColour(wxGetApp().m_canvasTextColour); | |
621 | ||
622 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data); | |
623 | if (dialog->ShowModal() == wxID_OK) | |
624 | { | |
625 | wxFontData retData = dialog->GetFontData(); | |
626 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
627 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
628 | myCanvas->Refresh(); | |
629 | } | |
630 | dialog->Destroy(); | |
631 | } | |
632 | #endif // USE_FONTDLG_GENERIC | |
633 | ||
634 | #if wxUSE_LOG_DIALOG | |
635 | void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event)) | |
636 | { | |
637 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages | |
638 | // being flushed -- test it | |
639 | { | |
640 | wxBusyCursor bc; | |
641 | wxLogMessage(wxT("This is some message - everything is ok so far.")); | |
642 | wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); | |
643 | wxLogWarning(wxT("And then something went wrong!")); | |
644 | ||
645 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
646 | wxYield(); | |
647 | } | |
648 | ||
649 | wxLogError(wxT("Intermediary error handler decided to abort.")); | |
650 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
651 | ||
652 | wxLog::FlushActive(); | |
653 | ||
654 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); | |
655 | } | |
656 | #endif // wxUSE_LOG_DIALOG | |
657 | ||
658 | #if wxUSE_MSGDLG | |
659 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event)) | |
660 | { | |
661 | wxMessageDialog dialog(this, | |
662 | "This is a message box\n" | |
663 | "This is a long, long string to test out if the message box " | |
664 | "is laid out properly.", | |
665 | "Message box text", | |
666 | wxCENTER | | |
667 | wxNO_DEFAULT | wxYES_NO | wxCANCEL | | |
668 | wxICON_INFORMATION); | |
669 | ||
670 | wxString extmsg; | |
671 | if ( dialog.SetYesNoCancelLabels | |
672 | ( | |
673 | "Answer &Yes", | |
674 | "Answer &No", | |
675 | "Refuse to answer" | |
676 | ) ) | |
677 | { | |
678 | extmsg = "This platform supports custom button labels,\n" | |
679 | "so you should see the descriptive labels below."; | |
680 | } | |
681 | else | |
682 | { | |
683 | extmsg = "Custom button labels are not supported on this platform,\n" | |
684 | "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used."; | |
685 | } | |
686 | dialog.SetExtendedMessage(extmsg); | |
687 | ||
688 | switch ( dialog.ShowModal() ) | |
689 | { | |
690 | case wxID_YES: | |
691 | wxLogStatus(wxT("You pressed \"Yes\"")); | |
692 | break; | |
693 | ||
694 | case wxID_NO: | |
695 | wxLogStatus(wxT("You pressed \"No\"")); | |
696 | break; | |
697 | ||
698 | case wxID_CANCEL: | |
699 | wxLogStatus(wxT("You pressed \"Cancel\"")); | |
700 | break; | |
701 | ||
702 | default: | |
703 | wxLogError(wxT("Unexpected wxMessageDialog return code!")); | |
704 | } | |
705 | } | |
706 | ||
707 | void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event)) | |
708 | { | |
709 | TestMessageBoxDialog dlg(this); | |
710 | dlg.ShowModal(); | |
711 | } | |
712 | ||
713 | void MyFrame::MessageBoxInfo(wxCommandEvent& WXUNUSED(event)) | |
714 | { | |
715 | ::wxInfoMessageBox(this); | |
716 | } | |
717 | #endif // wxUSE_MSGDLG | |
718 | ||
719 | #if wxUSE_NUMBERDLG | |
720 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event)) | |
721 | { | |
722 | long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n") | |
723 | _T("Even two rows of text."), | |
724 | _T("Enter a number:"), _T("Numeric input test"), | |
725 | 50, 0, 100, this ); | |
726 | ||
727 | wxString msg; | |
728 | int icon; | |
729 | if ( res == -1 ) | |
730 | { | |
731 | msg = _T("Invalid number entered or dialog cancelled."); | |
732 | icon = wxICON_HAND; | |
733 | } | |
734 | else | |
735 | { | |
736 | msg.Printf(_T("You've entered %lu"), res ); | |
737 | icon = wxICON_INFORMATION; | |
738 | } | |
739 | ||
740 | wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this); | |
741 | } | |
742 | #endif // wxUSE_NUMBERDLG | |
743 | ||
744 | #if wxUSE_TEXTDLG | |
745 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) | |
746 | { | |
747 | wxString pwd = wxGetPasswordFromUser(_T("Enter password:"), | |
748 | _T("Password entry dialog"), | |
749 | wxEmptyString, | |
750 | this); | |
751 | if ( !pwd.empty() ) | |
752 | { | |
753 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), | |
754 | _T("Got password"), wxOK | wxICON_INFORMATION, this); | |
755 | } | |
756 | } | |
757 | ||
758 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
759 | { | |
760 | wxTextEntryDialog dialog(this, | |
761 | _T("This is a small sample\n") | |
762 | _T("A long, long string to test out the text entrybox"), | |
763 | _T("Please enter a string"), | |
764 | _T("Default value"), | |
765 | wxOK | wxCANCEL); | |
766 | ||
767 | if (dialog.ShowModal() == wxID_OK) | |
768 | { | |
769 | wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this); | |
770 | } | |
771 | } | |
772 | #endif // wxUSE_TEXTDLG | |
773 | ||
774 | #if wxUSE_CHOICEDLG | |
775 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) | |
776 | { | |
777 | const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ; | |
778 | ||
779 | wxSingleChoiceDialog dialog(this, | |
780 | _T("This is a small sample\n") | |
781 | _T("A single-choice convenience dialog"), | |
782 | _T("Please select a value"), | |
783 | WXSIZEOF(choices), choices); | |
784 | ||
785 | dialog.SetSelection(2); | |
786 | ||
787 | if (dialog.ShowModal() == wxID_OK) | |
788 | { | |
789 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string")); | |
790 | dialog2.ShowModal(); | |
791 | } | |
792 | } | |
793 | ||
794 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) | |
795 | { | |
796 | const wxString choices[] = | |
797 | { | |
798 | _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"), | |
799 | _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"), | |
800 | _T("Eleven"), _T("Twelve"), _T("Seventeen"), | |
801 | }; | |
802 | ||
803 | wxArrayInt selections; | |
804 | size_t count = wxGetMultipleChoices(selections, | |
805 | _T("This is a small sample\n") | |
806 | _T("A multi-choice convenience dialog"), | |
807 | _T("Please select a value"), | |
808 | WXSIZEOF(choices), choices, | |
809 | this); | |
810 | if ( count ) | |
811 | { | |
812 | wxString msg; | |
813 | msg.Printf(wxT("You selected %u items:\n"), (unsigned)count); | |
814 | for ( size_t n = 0; n < count; n++ ) | |
815 | { | |
816 | msg += wxString::Format(wxT("\t%u: %u (%s)\n"), | |
817 | (unsigned)n, (unsigned)selections[n], | |
818 | choices[selections[n]].c_str()); | |
819 | } | |
820 | wxLogMessage(msg); | |
821 | } | |
822 | //else: cancelled or nothing selected | |
823 | } | |
824 | #endif // wxUSE_CHOICEDLG | |
825 | ||
826 | // custom rearrange dialog: it adds the possibility to rename an item to the | |
827 | // base class functionality | |
828 | class MyRearrangeDialog : public wxRearrangeDialog | |
829 | { | |
830 | public: | |
831 | MyRearrangeDialog(wxWindow *parent, | |
832 | wxArrayInt& order, | |
833 | wxArrayString& labels, | |
834 | wxArrayString& labelsOrig) | |
835 | : wxRearrangeDialog | |
836 | ( | |
837 | parent, | |
838 | "Configure the columns shown:", | |
839 | "wxRearrangeDialog example", | |
840 | order, | |
841 | labels | |
842 | ), | |
843 | m_order(order), | |
844 | m_labels(labels), | |
845 | m_labelsOrig(labelsOrig) | |
846 | { | |
847 | m_sel = wxNOT_FOUND; | |
848 | ||
849 | wxPanel * const panel = new wxPanel(this); | |
850 | wxSizer * const sizer = new wxBoxSizer(wxHORIZONTAL); | |
851 | ||
852 | m_labelOrig = new wxStaticText(panel, wxID_ANY, ""); | |
853 | sizer->Add(m_labelOrig, wxSizerFlags().Centre().Border(wxRIGHT)); | |
854 | ||
855 | m_text = new wxTextCtrl(panel, wxID_ANY, "", | |
856 | wxDefaultPosition, wxDefaultSize, | |
857 | wxTE_PROCESS_ENTER); | |
858 | sizer->Add(m_text, wxSizerFlags().Centre().Border(wxRIGHT)); | |
859 | ||
860 | sizer->Add(new wxButton(panel, wxID_APPLY, "&Rename"), | |
861 | wxSizerFlags().Centre()); | |
862 | ||
863 | panel->SetSizer(sizer); | |
864 | ||
865 | // call this first to ensure that the controls have a reasonable best | |
866 | // size before they're added | |
867 | DoUpdateExtraControls(GetList()->GetSelection()); | |
868 | ||
869 | AddExtraControls(panel); | |
870 | ||
871 | ||
872 | // another customization not directly supported by the dialog: add a | |
873 | // custom button | |
874 | wxWindow * const btnOk = FindWindow(wxID_OK); | |
875 | wxCHECK_RET( btnOk, "no Ok button?" ); | |
876 | ||
877 | wxSizer * const sizerBtns = btnOk->GetContainingSizer(); | |
878 | wxCHECK_RET( sizerBtns, "no buttons sizer?" ); | |
879 | ||
880 | sizerBtns->Add(new wxButton(this, wxID_RESET, "&Reset all"), | |
881 | wxSizerFlags().Border(wxLEFT)); | |
882 | } | |
883 | ||
884 | // call this instead of ShowModal() to update order and labels array in | |
885 | // case the dialog was not cancelled | |
886 | bool Rearrange() | |
887 | { | |
888 | switch ( ShowModal() ) | |
889 | { | |
890 | case wxID_CANCEL: | |
891 | return false; | |
892 | ||
893 | case wxID_OK: | |
894 | m_order = GetOrder(); | |
895 | break; | |
896 | ||
897 | case wxID_RESET: | |
898 | // order already reset | |
899 | break; | |
900 | } | |
901 | ||
902 | return true; | |
903 | } | |
904 | ||
905 | private: | |
906 | void OnSelChange(wxCommandEvent& event) | |
907 | { | |
908 | DoUpdateExtraControls(event.GetInt()); | |
909 | } | |
910 | ||
911 | void OnUpdateUIRename(wxUpdateUIEvent& event) | |
912 | { | |
913 | event.Enable( CanRename() ); | |
914 | } | |
915 | ||
916 | void OnRename(wxCommandEvent& WXUNUSED(event)) | |
917 | { | |
918 | if ( !CanRename() ) | |
919 | return; | |
920 | ||
921 | m_labels[m_sel] = m_text->GetValue(); | |
922 | GetList()->SetString(m_sel, m_labels[m_sel]); | |
923 | } | |
924 | ||
925 | void OnReset(wxCommandEvent& WXUNUSED(event)) | |
926 | { | |
927 | // in a real program we should probably ask if the user really wants to | |
928 | // do this but here we just go ahead and reset all columns labels and | |
929 | // their order without confirmation | |
930 | const unsigned count = m_order.size(); | |
931 | for ( unsigned n = 0; n < count; n++ ) | |
932 | { | |
933 | m_order[n] = n; | |
934 | m_labels[n] = m_labelsOrig[n]; | |
935 | } | |
936 | ||
937 | EndModal(wxID_RESET); | |
938 | } | |
939 | ||
940 | bool CanRename() const | |
941 | { | |
942 | // only allow renaming if the user modified the currently selected item | |
943 | // text (which presupposes that we do have a current item) | |
944 | return m_sel != wxNOT_FOUND && m_text->GetValue() != m_labels[m_sel]; | |
945 | } | |
946 | ||
947 | void DoUpdateExtraControls(int sel) | |
948 | { | |
949 | m_sel = sel; | |
950 | ||
951 | if ( m_sel == wxNOT_FOUND ) | |
952 | { | |
953 | m_labelOrig->SetLabel("<no selection>"); | |
954 | m_text->Clear(); | |
955 | m_text->Disable(); | |
956 | } | |
957 | else // have valid item | |
958 | { | |
959 | m_labelOrig->SetLabelText(m_labelsOrig[m_sel]); | |
960 | m_text->Enable(); | |
961 | m_text->SetValue(m_labels[m_sel]); | |
962 | } | |
963 | } | |
964 | ||
965 | wxArrayInt& m_order; | |
966 | wxArrayString& m_labels, | |
967 | m_labelsOrig; | |
968 | ||
969 | int m_sel; | |
970 | wxStaticText *m_labelOrig; | |
971 | wxTextCtrl *m_text; | |
972 | ||
973 | DECLARE_EVENT_TABLE() | |
974 | DECLARE_NO_COPY_CLASS(MyRearrangeDialog) | |
975 | }; | |
976 | ||
977 | BEGIN_EVENT_TABLE(MyRearrangeDialog, wxRearrangeDialog) | |
978 | EVT_LISTBOX(wxID_ANY, MyRearrangeDialog::OnSelChange) | |
979 | ||
980 | EVT_UPDATE_UI(wxID_APPLY, MyRearrangeDialog::OnUpdateUIRename) | |
981 | ||
982 | EVT_TEXT_ENTER(wxID_ANY, MyRearrangeDialog::OnRename) | |
983 | EVT_BUTTON(wxID_APPLY, MyRearrangeDialog::OnRename) | |
984 | EVT_BUTTON(wxID_RESET, MyRearrangeDialog::OnReset) | |
985 | END_EVENT_TABLE() | |
986 | ||
987 | void MyFrame::Rearrange(wxCommandEvent& WXUNUSED(event)) | |
988 | { | |
989 | // the arrays are static so that we preserve the items order between calls | |
990 | // to this function | |
991 | static wxArrayInt s_order; | |
992 | static wxArrayString s_labels, | |
993 | s_labelsOrig; | |
994 | ||
995 | // initialize them on the first call | |
996 | if ( s_labelsOrig.empty() ) | |
997 | { | |
998 | static const struct ItemInfo | |
999 | { | |
1000 | const char *label; | |
1001 | const char *labelOrig; | |
1002 | int order; | |
1003 | } items[] = | |
1004 | { | |
1005 | { "File name", "Name", 0 }, | |
1006 | { "File type", "Ext", 1 }, | |
1007 | { "Size", "Size", 2 }, | |
1008 | { "Creation time", "Ctime", ~3 }, // negated so hidden | |
1009 | { "Last accessed", "Atime", ~4 }, | |
1010 | { "Last modified", "Mtime", 5 }, | |
1011 | }; | |
1012 | ||
1013 | s_order.reserve(WXSIZEOF(items)); | |
1014 | s_labels.reserve(WXSIZEOF(items)); | |
1015 | s_labelsOrig.reserve(WXSIZEOF(items)); | |
1016 | for ( unsigned n = 0; n < WXSIZEOF(items); n++ ) | |
1017 | { | |
1018 | const ItemInfo& item = items[n]; | |
1019 | s_order.push_back(item.order); | |
1020 | s_labels.push_back(item.label); | |
1021 | s_labelsOrig.push_back(item.labelOrig); | |
1022 | } | |
1023 | } | |
1024 | ||
1025 | MyRearrangeDialog dlg(this, s_order, s_labels, s_labelsOrig); | |
1026 | if ( !dlg.Rearrange() ) | |
1027 | return; | |
1028 | ||
1029 | wxString columns; | |
1030 | for ( unsigned n = 0; n < s_order.size(); n++ ) | |
1031 | { | |
1032 | columns += wxString::Format("\n %u: ", n); | |
1033 | int idx = s_order[n]; | |
1034 | if ( idx < 0 ) | |
1035 | { | |
1036 | columns += "[hidden] "; | |
1037 | idx = ~idx; | |
1038 | } | |
1039 | ||
1040 | columns += s_labels[idx]; | |
1041 | if ( s_labels[idx] != s_labelsOrig[idx] ) | |
1042 | { | |
1043 | columns += wxString::Format(" (original label: \"%s\")", | |
1044 | s_labelsOrig[idx]); | |
1045 | } | |
1046 | } | |
1047 | ||
1048 | wxLogMessage("The columns order now is:%s", columns); | |
1049 | } | |
1050 | ||
1051 | #if wxUSE_FILEDLG | |
1052 | ||
1053 | // panel with custom controls for file dialog | |
1054 | class MyExtraPanel : public wxPanel | |
1055 | { | |
1056 | public: | |
1057 | MyExtraPanel(wxWindow *parent); | |
1058 | void OnCheckBox(wxCommandEvent& event) { m_btn->Enable(event.IsChecked()); } | |
1059 | wxString GetInfo() const | |
1060 | { | |
1061 | return wxString::Format("checkbox value = %d", (int) m_cb->GetValue()); | |
1062 | } | |
1063 | private: | |
1064 | wxButton *m_btn; | |
1065 | wxCheckBox *m_cb; | |
1066 | }; | |
1067 | ||
1068 | MyExtraPanel::MyExtraPanel(wxWindow *parent) | |
1069 | : wxPanel(parent) | |
1070 | { | |
1071 | m_btn = new wxButton(this, -1, _T("Custom Button")); | |
1072 | m_btn->Enable(false); | |
1073 | m_cb = new wxCheckBox(this, -1, _T("Enable Custom Button")); | |
1074 | m_cb->Connect(wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, | |
1075 | wxCommandEventHandler(MyExtraPanel::OnCheckBox), NULL, this); | |
1076 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
1077 | sizerTop->Add(m_cb, wxSizerFlags().Centre().Border()); | |
1078 | sizerTop->AddStretchSpacer(); | |
1079 | sizerTop->Add(m_btn, wxSizerFlags().Right().Border()); | |
1080 | SetSizerAndFit(sizerTop); | |
1081 | } | |
1082 | ||
1083 | // a static method can be used instead of a function with most of compilers | |
1084 | static wxWindow* createMyExtraPanel(wxWindow *parent) | |
1085 | { | |
1086 | return new MyExtraPanel(parent); | |
1087 | } | |
1088 | ||
1089 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) | |
1090 | { | |
1091 | wxFileDialog dialog | |
1092 | ( | |
1093 | this, | |
1094 | _T("Testing open file dialog"), | |
1095 | wxEmptyString, | |
1096 | wxEmptyString, | |
1097 | #ifdef __WXMOTIF__ | |
1098 | _T("C++ files (*.cpp)|*.cpp") | |
1099 | #else | |
1100 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") | |
1101 | #endif | |
1102 | ); | |
1103 | ||
1104 | dialog.SetExtraControlCreator(&createMyExtraPanel); | |
1105 | dialog.CentreOnParent(); | |
1106 | dialog.SetDirectory(wxGetHomeDir()); | |
1107 | ||
1108 | if (dialog.ShowModal() == wxID_OK) | |
1109 | { | |
1110 | wxString info; | |
1111 | wxWindow * const extra = dialog.GetExtraControl(); | |
1112 | info.Printf(_T("Full file name: %s\n") | |
1113 | _T("Path: %s\n") | |
1114 | _T("Name: %s\n") | |
1115 | _T("Custom window: %s"), | |
1116 | dialog.GetPath().c_str(), | |
1117 | dialog.GetDirectory().c_str(), | |
1118 | dialog.GetFilename().c_str(), | |
1119 | extra ? static_cast<MyExtraPanel*>(extra)->GetInfo() | |
1120 | : wxString("None")); | |
1121 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
1122 | dialog2.ShowModal(); | |
1123 | } | |
1124 | } | |
1125 | ||
1126 | // this shows how to take advantage of specifying a default extension in the | |
1127 | // call to wxFileSelector: it is remembered after each new call and the next | |
1128 | // one will use it by default | |
1129 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
1130 | { | |
1131 | static wxString s_extDef; | |
1132 | wxString path = wxFileSelector( | |
1133 | _T("Select the file to load"), | |
1134 | wxEmptyString, wxEmptyString, | |
1135 | s_extDef, | |
1136 | wxString::Format | |
1137 | ( | |
1138 | _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"), | |
1139 | wxFileSelectorDefaultWildcardStr, | |
1140 | wxFileSelectorDefaultWildcardStr | |
1141 | ), | |
1142 | wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW, | |
1143 | this | |
1144 | ); | |
1145 | ||
1146 | if ( !path ) | |
1147 | return; | |
1148 | ||
1149 | // it is just a sample, would use wxSplitPath in real program | |
1150 | s_extDef = path.AfterLast(_T('.')); | |
1151 | ||
1152 | wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), | |
1153 | path, s_extDef); | |
1154 | } | |
1155 | ||
1156 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) | |
1157 | { | |
1158 | wxString wildcards = | |
1159 | #ifdef __WXMOTIF__ | |
1160 | _T("C++ files (*.cpp)|*.cpp"); | |
1161 | #else | |
1162 | wxString::Format | |
1163 | ( | |
1164 | _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"), | |
1165 | wxFileSelectorDefaultWildcardStr, | |
1166 | wxFileSelectorDefaultWildcardStr | |
1167 | ); | |
1168 | #endif | |
1169 | wxFileDialog dialog(this, _T("Testing open multiple file dialog"), | |
1170 | wxEmptyString, wxEmptyString, wildcards, | |
1171 | wxFD_OPEN|wxFD_MULTIPLE); | |
1172 | ||
1173 | if (dialog.ShowModal() == wxID_OK) | |
1174 | { | |
1175 | wxArrayString paths, filenames; | |
1176 | ||
1177 | dialog.GetPaths(paths); | |
1178 | dialog.GetFilenames(filenames); | |
1179 | ||
1180 | wxString msg, s; | |
1181 | size_t count = paths.GetCount(); | |
1182 | for ( size_t n = 0; n < count; n++ ) | |
1183 | { | |
1184 | s.Printf(_T("File %d: %s (%s)\n"), | |
1185 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
1186 | ||
1187 | msg += s; | |
1188 | } | |
1189 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
1190 | msg += s; | |
1191 | ||
1192 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
1193 | dialog2.ShowModal(); | |
1194 | } | |
1195 | } | |
1196 | ||
1197 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) | |
1198 | { | |
1199 | wxFileDialog dialog(this, | |
1200 | _T("Testing save file dialog"), | |
1201 | wxEmptyString, | |
1202 | _T("myletter.doc"), | |
1203 | _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"), | |
1204 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); | |
1205 | ||
1206 | dialog.SetFilterIndex(1); | |
1207 | ||
1208 | if (dialog.ShowModal() == wxID_OK) | |
1209 | { | |
1210 | wxLogMessage(_T("%s, filter %d"), | |
1211 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
1212 | } | |
1213 | } | |
1214 | #endif // wxUSE_FILEDLG | |
1215 | ||
1216 | #if USE_FILEDLG_GENERIC | |
1217 | void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
1218 | { | |
1219 | wxGenericFileDialog dialog | |
1220 | ( | |
1221 | this, | |
1222 | _T("Testing open file dialog"), | |
1223 | wxEmptyString, | |
1224 | wxEmptyString, | |
1225 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") | |
1226 | ); | |
1227 | ||
1228 | dialog.SetExtraControlCreator(&createMyExtraPanel); | |
1229 | dialog.SetDirectory(wxGetHomeDir()); | |
1230 | ||
1231 | if (dialog.ShowModal() == wxID_OK) | |
1232 | { | |
1233 | wxString info; | |
1234 | info.Printf(_T("Full file name: %s\n") | |
1235 | _T("Path: %s\n") | |
1236 | _T("Name: %s"), | |
1237 | dialog.GetPath().c_str(), | |
1238 | dialog.GetDirectory().c_str(), | |
1239 | dialog.GetFilename().c_str()); | |
1240 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
1241 | dialog2.ShowModal(); | |
1242 | } | |
1243 | } | |
1244 | ||
1245 | void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
1246 | { | |
1247 | // On PocketPC you can disable OK-only dialogs policy using system option | |
1248 | int buttons = wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel")); | |
1249 | wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1); | |
1250 | ||
1251 | wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h"); | |
1252 | wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"), | |
1253 | wxEmptyString, wxEmptyString, wildcards, | |
1254 | wxFD_MULTIPLE); | |
1255 | ||
1256 | if (dialog.ShowModal() == wxID_OK) | |
1257 | { | |
1258 | wxArrayString paths, filenames; | |
1259 | ||
1260 | dialog.GetPaths(paths); | |
1261 | dialog.GetFilenames(filenames); | |
1262 | ||
1263 | wxString msg, s; | |
1264 | size_t count = paths.GetCount(); | |
1265 | for ( size_t n = 0; n < count; n++ ) | |
1266 | { | |
1267 | s.Printf(_T("File %d: %s (%s)\n"), | |
1268 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
1269 | ||
1270 | msg += s; | |
1271 | } | |
1272 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
1273 | msg += s; | |
1274 | ||
1275 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
1276 | dialog2.ShowModal(); | |
1277 | } | |
1278 | ||
1279 | // restore system option | |
1280 | wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons); | |
1281 | } | |
1282 | ||
1283 | void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) ) | |
1284 | { | |
1285 | wxGenericFileDialog dialog(this, | |
1286 | _T("Testing save file dialog"), | |
1287 | wxEmptyString, | |
1288 | _T("myletter.doc"), | |
1289 | _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"), | |
1290 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); | |
1291 | ||
1292 | dialog.SetFilterIndex(1); | |
1293 | ||
1294 | if (dialog.ShowModal() == wxID_OK) | |
1295 | { | |
1296 | wxLogMessage(_T("%s, filter %d"), | |
1297 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
1298 | } | |
1299 | } | |
1300 | #endif // USE_FILEDLG_GENERIC | |
1301 | ||
1302 | #if wxUSE_DIRDLG | |
1303 | void MyFrame::DoDirChoose(int style) | |
1304 | { | |
1305 | // pass some initial dir to wxDirDialog | |
1306 | wxString dirHome; | |
1307 | wxGetHomeDir(&dirHome); | |
1308 | ||
1309 | wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style); | |
1310 | ||
1311 | if (dialog.ShowModal() == wxID_OK) | |
1312 | { | |
1313 | wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str()); | |
1314 | } | |
1315 | } | |
1316 | ||
1317 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) | |
1318 | { | |
1319 | DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); | |
1320 | } | |
1321 | ||
1322 | void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) ) | |
1323 | { | |
1324 | DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST); | |
1325 | } | |
1326 | #endif // wxUSE_DIRDLG | |
1327 | ||
1328 | #if USE_DIRDLG_GENERIC | |
1329 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) | |
1330 | { | |
1331 | // pass some initial dir to wxDirDialog | |
1332 | wxString dirHome; | |
1333 | wxGetHomeDir(&dirHome); | |
1334 | ||
1335 | wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome); | |
1336 | ||
1337 | if (dialog.ShowModal() == wxID_OK) | |
1338 | { | |
1339 | wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path")); | |
1340 | dialog2.ShowModal(); | |
1341 | } | |
1342 | } | |
1343 | #endif // USE_DIRDLG_GENERIC | |
1344 | ||
1345 | #if USE_MODAL_PRESENTATION | |
1346 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) | |
1347 | { | |
1348 | MyModalDialog dlg(this); | |
1349 | dlg.ShowModal(); | |
1350 | } | |
1351 | #endif // USE_MODAL_PRESENTATION | |
1352 | ||
1353 | void MyFrame::ModelessDlg(wxCommandEvent& event) | |
1354 | { | |
1355 | bool show = GetMenuBar()->IsChecked(event.GetId()); | |
1356 | ||
1357 | if ( show ) | |
1358 | { | |
1359 | if ( !m_dialog ) | |
1360 | { | |
1361 | m_dialog = new MyModelessDialog(this); | |
1362 | } | |
1363 | ||
1364 | m_dialog->Show(true); | |
1365 | } | |
1366 | else // hide | |
1367 | { | |
1368 | // If m_dialog is NULL, then possibly the system | |
1369 | // didn't report the checked menu item status correctly. | |
1370 | // It should be true just after the menu item was selected, | |
1371 | // if there was no modeless dialog yet. | |
1372 | ||
1373 | wxASSERT( m_dialog != NULL ); | |
1374 | if (m_dialog) | |
1375 | m_dialog->Hide(); | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event)) | |
1380 | { | |
1381 | wxDialog dlg(this, wxID_ANY, _T("Dialog centered on screen"), | |
1382 | wxDefaultPosition, wxSize(200, 100)); | |
1383 | (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre(); | |
1384 | dlg.CentreOnScreen(); | |
1385 | dlg.ShowModal(); | |
1386 | } | |
1387 | ||
1388 | void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event)) | |
1389 | { | |
1390 | wxDialog dlg(this, wxID_ANY, _T("Dialog centered on parent"), | |
1391 | wxDefaultPosition, wxSize(200, 100)); | |
1392 | (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre(); | |
1393 | dlg.CentreOnParent(); | |
1394 | dlg.ShowModal(); | |
1395 | } | |
1396 | ||
1397 | void MyFrame::MiniFrame(wxCommandEvent& WXUNUSED(event)) | |
1398 | { | |
1399 | wxFrame *frame = new wxMiniFrame(this, wxID_ANY, _T("Mini frame"), | |
1400 | wxDefaultPosition, wxSize(300, 100), | |
1401 | wxCAPTION | wxCLOSE_BOX); | |
1402 | new wxStaticText(frame, | |
1403 | wxID_ANY, | |
1404 | _T("Mini frames have slightly different appearance"), | |
1405 | wxPoint(5, 5)); | |
1406 | new wxStaticText(frame, | |
1407 | wxID_ANY, | |
1408 | _T("from the normal frames but that's the only difference."), | |
1409 | wxPoint(5, 25)); | |
1410 | ||
1411 | frame->CentreOnParent(); | |
1412 | frame->Show(); | |
1413 | } | |
1414 | ||
1415 | void MyFrame::DlgOnTop(wxCommandEvent& WXUNUSED(event)) | |
1416 | { | |
1417 | wxDialog dlg(this, wxID_ANY, _T("Dialog staying on top of other windows"), | |
1418 | wxDefaultPosition, wxSize(300, 100), | |
1419 | wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP); | |
1420 | (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre(); | |
1421 | dlg.ShowModal(); | |
1422 | } | |
1423 | ||
1424 | #if wxUSE_STARTUP_TIPS | |
1425 | void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event)) | |
1426 | { | |
1427 | static size_t s_index = (size_t)-1; | |
1428 | ||
1429 | if ( s_index == (size_t)-1 ) | |
1430 | { | |
1431 | srand(time(NULL)); | |
1432 | ||
1433 | // this is completely bogus, we don't know how many lines are there | |
1434 | // in the file, but who cares, it's a demo only... | |
1435 | s_index = rand() % 5; | |
1436 | } | |
1437 | ||
1438 | wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index); | |
1439 | ||
1440 | bool showAtStartup = wxShowTip(this, tipProvider); | |
1441 | ||
1442 | if ( showAtStartup ) | |
1443 | { | |
1444 | wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"), | |
1445 | wxOK | wxICON_INFORMATION, this); | |
1446 | } | |
1447 | ||
1448 | s_index = tipProvider->GetCurrentTip(); | |
1449 | delete tipProvider; | |
1450 | } | |
1451 | #endif // wxUSE_STARTUP_TIPS | |
1452 | ||
1453 | #if USE_SETTINGS_DIALOG | |
1454 | void MyFrame::OnPropertySheet(wxCommandEvent& event) | |
1455 | { | |
1456 | SettingsDialog dialog(this, event.GetId()); | |
1457 | dialog.ShowModal(); | |
1458 | } | |
1459 | #endif // USE_SETTINGS_DIALOG | |
1460 | ||
1461 | void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) | |
1462 | { | |
1463 | wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window")); | |
1464 | ||
1465 | wxSleep(3); | |
1466 | ||
1467 | RequestUserAttention(wxUSER_ATTENTION_ERROR); | |
1468 | } | |
1469 | ||
1470 | #if wxUSE_NOTIFICATION_MESSAGE | |
1471 | ||
1472 | void MyFrame::OnNotifMsgAuto(wxCommandEvent& WXUNUSED(event)) | |
1473 | { | |
1474 | if ( !wxNotificationMessage | |
1475 | ( | |
1476 | "Automatic Notification", | |
1477 | "Nothing important has happened\n" | |
1478 | "this notification will disappear soon." | |
1479 | ).Show() ) | |
1480 | { | |
1481 | wxLogStatus("Failed to show notification message"); | |
1482 | } | |
1483 | } | |
1484 | ||
1485 | void MyFrame::OnNotifMsgShow(wxCommandEvent& WXUNUSED(event)) | |
1486 | { | |
1487 | if ( !m_notifMsg ) | |
1488 | { | |
1489 | m_notifMsg = new wxNotificationMessage | |
1490 | ( | |
1491 | "wxWidgets Manual Notification", | |
1492 | "You can hide this notification from the menu", | |
1493 | this | |
1494 | ); | |
1495 | } | |
1496 | ||
1497 | if ( !m_notifMsg->Show(wxNotificationMessage::Timeout_Never) ) | |
1498 | { | |
1499 | wxLogStatus("Failed to show manual notification message"); | |
1500 | } | |
1501 | } | |
1502 | ||
1503 | void MyFrame::OnNotifMsgHide(wxCommandEvent& WXUNUSED(event)) | |
1504 | { | |
1505 | if ( m_notifMsg ) | |
1506 | { | |
1507 | if ( !m_notifMsg->Close() ) | |
1508 | wxLogStatus("Failed to hide manual notification message"); | |
1509 | } | |
1510 | } | |
1511 | ||
1512 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
1513 | ||
1514 | void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event)) | |
1515 | { | |
1516 | StdButtonSizerDialog dialog(this); | |
1517 | dialog.ShowModal(); | |
1518 | } | |
1519 | ||
1520 | // TestDefaultAction | |
1521 | ||
1522 | #define ID_CATCH_LISTBOX_DCLICK 100 | |
1523 | #define ID_LISTBOX 101 | |
1524 | ||
1525 | BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog) | |
1526 | EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK, TestDefaultActionDialog::OnCatchListBoxDClick) | |
1527 | EVT_LISTBOX_DCLICK(ID_LISTBOX, TestDefaultActionDialog::OnListBoxDClick) | |
1528 | END_EVENT_TABLE() | |
1529 | ||
1530 | TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) : | |
1531 | wxDialog( parent, -1, "Test default action" ) | |
1532 | { | |
1533 | m_catchListBoxDClick = false; | |
1534 | ||
1535 | wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); | |
1536 | ||
1537 | wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 5, 5 ); | |
1538 | ||
1539 | wxListBox *listbox = new wxListBox( this, ID_LISTBOX ); | |
1540 | listbox->Append( "String 1" ); | |
1541 | listbox->Append( "String 2" ); | |
1542 | listbox->Append( "String 3" ); | |
1543 | listbox->Append( "String 4" ); | |
1544 | grid_sizer->Add( listbox ); | |
1545 | ||
1546 | grid_sizer->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL ); | |
1547 | ||
1548 | grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL ); | |
1549 | grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL ); | |
1550 | ||
1551 | grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL ); | |
1552 | grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL ); | |
1553 | ||
1554 | main_sizer->Add( grid_sizer, 0, wxALL, 10 ); | |
1555 | ||
1556 | wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL ); | |
1557 | if (button_sizer) | |
1558 | main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 ); | |
1559 | ||
1560 | SetSizerAndFit( main_sizer ); | |
1561 | } | |
1562 | ||
1563 | void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event) | |
1564 | { | |
1565 | event.Skip( !m_catchListBoxDClick ); | |
1566 | } | |
1567 | ||
1568 | void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(event)) | |
1569 | { | |
1570 | m_catchListBoxDClick = !m_catchListBoxDClick; | |
1571 | } | |
1572 | ||
1573 | void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event)) | |
1574 | { | |
1575 | TestDefaultActionDialog dialog( this ); | |
1576 | dialog.ShowModal(); | |
1577 | } | |
1578 | ||
1579 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) | |
1580 | { | |
1581 | Close(true); | |
1582 | } | |
1583 | ||
1584 | #if wxUSE_PROGRESSDLG | |
1585 | ||
1586 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
1587 | { | |
1588 | static const int max = 100; | |
1589 | ||
1590 | wxProgressDialog dialog(_T("Progress dialog example"), | |
1591 | _T("An informative message"), | |
1592 | max, // range | |
1593 | this, // parent | |
1594 | wxPD_CAN_ABORT | | |
1595 | wxPD_CAN_SKIP | | |
1596 | wxPD_APP_MODAL | | |
1597 | // wxPD_AUTO_HIDE | -- try this as well | |
1598 | wxPD_ELAPSED_TIME | | |
1599 | wxPD_ESTIMATED_TIME | | |
1600 | wxPD_REMAINING_TIME | |
1601 | | wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small | |
1602 | ); | |
1603 | ||
1604 | bool cont = true; | |
1605 | for ( int i = 0; i <= max; i++ ) | |
1606 | { | |
1607 | wxMilliSleep(200); | |
1608 | ||
1609 | wxString msg; | |
1610 | ||
1611 | // test both modes of wxProgressDialog behaviour: start in | |
1612 | // indeterminate mode but switch to the determinate one later | |
1613 | const bool determinate = i > max/2; | |
1614 | ||
1615 | if ( i == max ) | |
1616 | { | |
1617 | msg = _T("That's all, folks!"); | |
1618 | } | |
1619 | else if ( !determinate ) | |
1620 | { | |
1621 | msg = _T("Testing indeterminate mode"); | |
1622 | } | |
1623 | else if ( determinate ) | |
1624 | { | |
1625 | msg = _T("Now in standard determinate mode"); | |
1626 | } | |
1627 | ||
1628 | // will be set to true if "Skip" button was pressed | |
1629 | bool skip = false; | |
1630 | if ( determinate ) | |
1631 | { | |
1632 | cont = dialog.Update(i, msg, &skip); | |
1633 | } | |
1634 | else | |
1635 | { | |
1636 | cont = dialog.Pulse(msg, &skip); | |
1637 | } | |
1638 | ||
1639 | // each skip will move progress about quarter forward | |
1640 | if ( skip ) | |
1641 | i += max/4; | |
1642 | ||
1643 | if ( !cont ) | |
1644 | { | |
1645 | if ( wxMessageBox(_T("Do you really want to cancel?"), | |
1646 | _T("Progress dialog question"), // caption | |
1647 | wxYES_NO | wxICON_QUESTION) == wxYES ) | |
1648 | break; | |
1649 | ||
1650 | cont = true; | |
1651 | dialog.Resume(); | |
1652 | } | |
1653 | } | |
1654 | ||
1655 | if ( !cont ) | |
1656 | { | |
1657 | wxLogStatus(wxT("Progress dialog aborted!")); | |
1658 | } | |
1659 | else | |
1660 | { | |
1661 | wxLogStatus(wxT("Countdown from %d finished"), max); | |
1662 | } | |
1663 | } | |
1664 | ||
1665 | #endif // wxUSE_PROGRESSDLG | |
1666 | ||
1667 | #if wxUSE_ABOUTDLG | |
1668 | ||
1669 | static void InitAboutInfoMinimal(wxAboutDialogInfo& info) | |
1670 | { | |
1671 | info.SetName(_T("Dialogs Sample")); | |
1672 | info.SetVersion(wxVERSION_NUM_DOT_STRING_T); | |
1673 | info.SetDescription(_T("This sample shows different wxWidgets dialogs")); | |
1674 | info.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team")); | |
1675 | info.AddDeveloper(_T("Vadim Zeitlin")); | |
1676 | } | |
1677 | ||
1678 | static void InitAboutInfoWebsite(wxAboutDialogInfo& info) | |
1679 | { | |
1680 | InitAboutInfoMinimal(info); | |
1681 | ||
1682 | info.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site")); | |
1683 | } | |
1684 | ||
1685 | static void InitAboutInfoAll(wxAboutDialogInfo& info) | |
1686 | { | |
1687 | InitAboutInfoWebsite(info); | |
1688 | ||
1689 | // we can add a second developer | |
1690 | info.AddDeveloper(_T("A.N. Other")); | |
1691 | ||
1692 | // or we can add several persons at once like this | |
1693 | static const wxChar *docwriters[] = | |
1694 | { | |
1695 | _T("First D. Writer"), | |
1696 | _T("Second One"), | |
1697 | }; | |
1698 | ||
1699 | info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters)); | |
1700 | info.SetLicence(wxString::FromAscii( | |
1701 | " wxWindows Library Licence, Version 3.1\n" | |
1702 | " ======================================\n" | |
1703 | "\n" | |
1704 | " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n" | |
1705 | "\n" | |
1706 | " Everyone is permitted to copy and distribute verbatim copies\n" | |
1707 | " of this licence document, but changing it is not allowed.\n" | |
1708 | "\n" | |
1709 | " WXWINDOWS LIBRARY LICENCE\n" | |
1710 | " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n" | |
1711 | "\n" | |
1712 | " ...and so on and so forth...\n" | |
1713 | )); | |
1714 | ||
1715 | info.AddTranslator(_T("Wun Ngo Wen (Martian)")); | |
1716 | } | |
1717 | ||
1718 | void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1719 | { | |
1720 | wxAboutDialogInfo info; | |
1721 | InitAboutInfoMinimal(info); | |
1722 | ||
1723 | wxAboutBox(info); | |
1724 | } | |
1725 | ||
1726 | void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1727 | { | |
1728 | wxAboutDialogInfo info; | |
1729 | InitAboutInfoWebsite(info); | |
1730 | ||
1731 | wxAboutBox(info); | |
1732 | } | |
1733 | ||
1734 | void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1735 | { | |
1736 | wxAboutDialogInfo info; | |
1737 | InitAboutInfoAll(info); | |
1738 | ||
1739 | wxAboutBox(info); | |
1740 | } | |
1741 | ||
1742 | // a trivial example of a custom dialog class | |
1743 | class MyAboutDialog : public wxGenericAboutDialog | |
1744 | { | |
1745 | public: | |
1746 | MyAboutDialog(const wxAboutDialogInfo& info) | |
1747 | { | |
1748 | Create(info); | |
1749 | } | |
1750 | ||
1751 | // add some custom controls | |
1752 | virtual void DoAddCustomControls() | |
1753 | { | |
1754 | AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); | |
1755 | AddText(_T("Some custom text")); | |
1756 | AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); | |
1757 | } | |
1758 | }; | |
1759 | ||
1760 | void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1761 | { | |
1762 | wxAboutDialogInfo info; | |
1763 | InitAboutInfoAll(info); | |
1764 | ||
1765 | MyAboutDialog dlg(info); | |
1766 | dlg.ShowModal(); | |
1767 | } | |
1768 | ||
1769 | #endif // wxUSE_ABOUTDLG | |
1770 | ||
1771 | #if wxUSE_BUSYINFO | |
1772 | ||
1773 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
1774 | { | |
1775 | wxWindowDisabler disableAll; | |
1776 | ||
1777 | wxBusyInfo info(_T("Working, please wait..."), this); | |
1778 | ||
1779 | for ( int i = 0; i < 18; i++ ) | |
1780 | { | |
1781 | //wxUsleep(100); | |
1782 | wxTheApp->Yield(); | |
1783 | } | |
1784 | ||
1785 | wxSleep(2); | |
1786 | //wxWakeUpIdle(); | |
1787 | } | |
1788 | ||
1789 | #endif // wxUSE_BUSYINFO | |
1790 | ||
1791 | #if wxUSE_FINDREPLDLG | |
1792 | ||
1793 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
1794 | { | |
1795 | if ( m_dlgReplace ) | |
1796 | { | |
1797 | delete m_dlgReplace; | |
1798 | m_dlgReplace = NULL; | |
1799 | } | |
1800 | else | |
1801 | { | |
1802 | m_dlgReplace = new wxFindReplaceDialog | |
1803 | ( | |
1804 | this, | |
1805 | &m_findData, | |
1806 | _T("Find and replace dialog"), | |
1807 | wxFR_REPLACEDIALOG | |
1808 | ); | |
1809 | ||
1810 | m_dlgReplace->Show(true); | |
1811 | } | |
1812 | } | |
1813 | ||
1814 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
1815 | { | |
1816 | if ( m_dlgFind ) | |
1817 | { | |
1818 | delete m_dlgFind; | |
1819 | m_dlgFind = NULL; | |
1820 | } | |
1821 | else | |
1822 | { | |
1823 | m_dlgFind = new wxFindReplaceDialog | |
1824 | ( | |
1825 | this, | |
1826 | &m_findData, | |
1827 | _T("Find dialog"), | |
1828 | // just for testing | |
1829 | wxFR_NOWHOLEWORD | |
1830 | ); | |
1831 | ||
1832 | m_dlgFind->Show(true); | |
1833 | } | |
1834 | } | |
1835 | ||
1836 | static wxString DecodeFindDialogEventFlags(int flags) | |
1837 | { | |
1838 | wxString str; | |
1839 | str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ") | |
1840 | << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T("")) | |
1841 | << (flags & wxFR_MATCHCASE ? _T("") : _T("not ")) | |
1842 | << _T("case sensitive"); | |
1843 | ||
1844 | return str; | |
1845 | } | |
1846 | ||
1847 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
1848 | { | |
1849 | wxEventType type = event.GetEventType(); | |
1850 | ||
1851 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
1852 | { | |
1853 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), | |
1854 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), | |
1855 | event.GetFindString().c_str(), | |
1856 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1857 | } | |
1858 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
1859 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
1860 | { | |
1861 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), | |
1862 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""), | |
1863 | event.GetFindString().c_str(), | |
1864 | event.GetReplaceString().c_str(), | |
1865 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1866 | } | |
1867 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
1868 | { | |
1869 | wxFindReplaceDialog *dlg = event.GetDialog(); | |
1870 | ||
1871 | int idMenu; | |
1872 | const wxChar *txt; | |
1873 | if ( dlg == m_dlgFind ) | |
1874 | { | |
1875 | txt = _T("Find"); | |
1876 | idMenu = DIALOGS_FIND; | |
1877 | m_dlgFind = NULL; | |
1878 | } | |
1879 | else if ( dlg == m_dlgReplace ) | |
1880 | { | |
1881 | txt = _T("Replace"); | |
1882 | idMenu = DIALOGS_REPLACE; | |
1883 | m_dlgReplace = NULL; | |
1884 | } | |
1885 | else | |
1886 | { | |
1887 | txt = _T("Unknown"); | |
1888 | idMenu = wxID_ANY; | |
1889 | ||
1890 | wxFAIL_MSG( _T("unexpected event") ); | |
1891 | } | |
1892 | ||
1893 | wxLogMessage(wxT("%s dialog is being closed."), txt); | |
1894 | ||
1895 | if ( idMenu != wxID_ANY ) | |
1896 | { | |
1897 | GetMenuBar()->Check(idMenu, false); | |
1898 | } | |
1899 | ||
1900 | dlg->Destroy(); | |
1901 | } | |
1902 | else | |
1903 | { | |
1904 | wxLogError(wxT("Unknown find dialog event!")); | |
1905 | } | |
1906 | } | |
1907 | ||
1908 | #endif // wxUSE_FINDREPLDLG | |
1909 | ||
1910 | // ---------------------------------------------------------------------------- | |
1911 | // MyCanvas | |
1912 | // ---------------------------------------------------------------------------- | |
1913 | ||
1914 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) | |
1915 | { | |
1916 | wxPaintDC dc(this); | |
1917 | dc.SetFont(wxGetApp().m_canvasFont); | |
1918 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
1919 | dc.SetBackgroundMode(wxTRANSPARENT); | |
1920 | dc.DrawText( | |
1921 | _T("wxWidgets common dialogs") | |
1922 | #if !defined(__SMARTPHONE__) | |
1923 | _T(" test application") | |
1924 | #endif | |
1925 | , 10, 10); | |
1926 | } | |
1927 | ||
1928 | #if USE_MODAL_PRESENTATION | |
1929 | ||
1930 | // ---------------------------------------------------------------------------- | |
1931 | // MyModelessDialog | |
1932 | // ---------------------------------------------------------------------------- | |
1933 | ||
1934 | MyModelessDialog::MyModelessDialog(wxWindow *parent) | |
1935 | : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog"))) | |
1936 | { | |
1937 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
1938 | ||
1939 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me")); | |
1940 | wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled")); | |
1941 | check->Disable(); | |
1942 | ||
1943 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
1944 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
1945 | ||
1946 | SetSizerAndFit(sizerTop); | |
1947 | } | |
1948 | ||
1949 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) | |
1950 | { | |
1951 | wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"), | |
1952 | wxOK | wxICON_INFORMATION, this); | |
1953 | } | |
1954 | ||
1955 | void MyModelessDialog::OnClose(wxCloseEvent& event) | |
1956 | { | |
1957 | if ( event.CanVeto() ) | |
1958 | { | |
1959 | wxMessageBox(_T("Use the menu item to close this dialog"), | |
1960 | _T("Modeless dialog"), | |
1961 | wxOK | wxICON_INFORMATION, this); | |
1962 | ||
1963 | event.Veto(); | |
1964 | } | |
1965 | } | |
1966 | ||
1967 | // ---------------------------------------------------------------------------- | |
1968 | // MyModalDialog | |
1969 | // ---------------------------------------------------------------------------- | |
1970 | ||
1971 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
1972 | : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog"))) | |
1973 | { | |
1974 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
1975 | ||
1976 | m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog...")); | |
1977 | m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog")); | |
1978 | m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button")); | |
1979 | ||
1980 | wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close")); | |
1981 | sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); | |
1982 | sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); | |
1983 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); | |
1984 | sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); | |
1985 | ||
1986 | SetSizerAndFit(sizerTop); | |
1987 | ||
1988 | m_btnModal->SetFocus(); | |
1989 | m_btnModal->SetDefault(); | |
1990 | } | |
1991 | ||
1992 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
1993 | { | |
1994 | if ( event.GetEventObject() == m_btnDelete ) | |
1995 | { | |
1996 | delete m_btnModal; | |
1997 | m_btnModal = NULL; | |
1998 | ||
1999 | m_btnDelete->Disable(); | |
2000 | } | |
2001 | else if ( event.GetEventObject() == m_btnModal ) | |
2002 | { | |
2003 | #if wxUSE_TEXTDLG | |
2004 | wxGetTextFromUser(_T("Dummy prompt"), | |
2005 | _T("Modal dialog called from dialog"), | |
2006 | wxEmptyString, this); | |
2007 | #else | |
2008 | wxMessageBox(_T("Modal dialog called from dialog")); | |
2009 | #endif // wxUSE_TEXTDLG | |
2010 | } | |
2011 | else if ( event.GetEventObject() == m_btnModeless ) | |
2012 | { | |
2013 | (new MyModelessDialog(this))->Show(); | |
2014 | } | |
2015 | else | |
2016 | { | |
2017 | event.Skip(); | |
2018 | } | |
2019 | } | |
2020 | ||
2021 | #endif // USE_MODAL_PRESENTATION | |
2022 | ||
2023 | // ---------------------------------------------------------------------------- | |
2024 | // StdButtonSizerDialog | |
2025 | // ---------------------------------------------------------------------------- | |
2026 | ||
2027 | StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent) | |
2028 | : wxDialog(parent, wxID_ANY, wxString(_T("StdButtonSizer dialog")), | |
2029 | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER), | |
2030 | m_buttonsSizer(NULL) | |
2031 | { | |
2032 | wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL); | |
2033 | ||
2034 | wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL); | |
2035 | wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL); | |
2036 | ||
2037 | m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button")); | |
2038 | ||
2039 | wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button")); | |
2040 | ||
2041 | m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
2042 | m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes")); | |
2043 | ||
2044 | wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL); | |
2045 | ||
2046 | m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button")); | |
2047 | ||
2048 | wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button")); | |
2049 | ||
2050 | m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
2051 | m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close")); | |
2052 | ||
2053 | wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL); | |
2054 | ||
2055 | m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No")); | |
2056 | m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help")); | |
2057 | m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply")); | |
2058 | ||
2059 | m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default")); | |
2060 | ||
2061 | sizer1->Add(m_radiobtnOk, 0, wxALL, 5); | |
2062 | sizer1->Add(m_radiobtnYes, 0, wxALL, 5); | |
2063 | ||
2064 | sizer->Add(sizerInside1, 0, 0, 0); | |
2065 | sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5); | |
2066 | sizerInside1->Add(sizer1, 0, wxALL, 5); | |
2067 | sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
2068 | ||
2069 | sizer2->Add(m_radiobtnCancel, 0, wxALL, 5); | |
2070 | sizer2->Add(m_radiobtnClose, 0, wxALL, 5); | |
2071 | ||
2072 | sizer->Add(sizerInside2, 0, 0, 0); | |
2073 | sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5); | |
2074 | sizerInside2->Add(sizer2, 0, wxALL, 5); | |
2075 | sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
2076 | ||
2077 | sizerTop->Add(sizer, 0, wxALL, 5); | |
2078 | ||
2079 | sizer3->Add(m_chkboxNo, 0, wxALL, 5); | |
2080 | sizer3->Add(m_chkboxHelp, 0, wxALL, 5); | |
2081 | sizer3->Add(m_chkboxApply, 0, wxALL, 5); | |
2082 | ||
2083 | sizerTop->Add(sizer3, 0, wxALL, 5); | |
2084 | ||
2085 | sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10); | |
2086 | ||
2087 | EnableDisableControls(); | |
2088 | ||
2089 | SetSizerAndFit(sizerTop); | |
2090 | ||
2091 | wxCommandEvent ev; | |
2092 | OnEvent(ev); | |
2093 | } | |
2094 | ||
2095 | void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event)) | |
2096 | { | |
2097 | if (m_buttonsSizer) | |
2098 | { | |
2099 | m_buttonsSizer->DeleteWindows(); | |
2100 | GetSizer()->Remove(m_buttonsSizer); | |
2101 | } | |
2102 | ||
2103 | EnableDisableControls(); | |
2104 | ||
2105 | long flags = 0; | |
2106 | unsigned long numButtons = 0; | |
2107 | ||
2108 | if (m_chkboxAffirmativeButton->IsChecked()) | |
2109 | { | |
2110 | if (m_radiobtnOk->GetValue()) | |
2111 | { | |
2112 | flags |= wxOK; | |
2113 | numButtons ++; | |
2114 | } | |
2115 | else if (m_radiobtnYes->GetValue()) | |
2116 | { | |
2117 | flags |= wxYES; | |
2118 | numButtons ++; | |
2119 | } | |
2120 | } | |
2121 | ||
2122 | if (m_chkboxDismissButton->IsChecked()) | |
2123 | { | |
2124 | if (m_radiobtnCancel->GetValue()) | |
2125 | { | |
2126 | flags |= wxCANCEL; | |
2127 | numButtons ++; | |
2128 | } | |
2129 | ||
2130 | else if (m_radiobtnClose->GetValue()) | |
2131 | { | |
2132 | flags |= wxCLOSE; | |
2133 | numButtons ++; | |
2134 | } | |
2135 | ||
2136 | } | |
2137 | ||
2138 | if (m_chkboxApply->IsChecked()) | |
2139 | { | |
2140 | flags |= wxAPPLY; | |
2141 | numButtons ++; | |
2142 | } | |
2143 | ||
2144 | if (m_chkboxNo->IsChecked()) | |
2145 | { | |
2146 | flags |= wxNO; | |
2147 | numButtons ++; | |
2148 | } | |
2149 | ||
2150 | if (m_chkboxHelp->IsChecked()) | |
2151 | { | |
2152 | flags |= wxHELP; | |
2153 | numButtons ++; | |
2154 | } | |
2155 | ||
2156 | if (m_chkboxNoDefault->IsChecked()) | |
2157 | { | |
2158 | flags |= wxNO_DEFAULT; | |
2159 | } | |
2160 | ||
2161 | m_buttonsSizer = CreateStdDialogButtonSizer(flags); | |
2162 | GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5); | |
2163 | ||
2164 | Layout(); | |
2165 | GetSizer()->SetSizeHints(this); | |
2166 | } | |
2167 | ||
2168 | void StdButtonSizerDialog::EnableDisableControls() | |
2169 | { | |
2170 | const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked(); | |
2171 | ||
2172 | m_radiobtnOk->Enable(affButtonEnabled); | |
2173 | m_radiobtnYes->Enable(affButtonEnabled); | |
2174 | ||
2175 | const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked(); | |
2176 | ||
2177 | m_radiobtnCancel->Enable(dismissButtonEnabled); | |
2178 | m_radiobtnClose->Enable(dismissButtonEnabled); | |
2179 | } | |
2180 | ||
2181 | #if USE_SETTINGS_DIALOG | |
2182 | // ---------------------------------------------------------------------------- | |
2183 | // SettingsDialog | |
2184 | // ---------------------------------------------------------------------------- | |
2185 | ||
2186 | IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog) | |
2187 | ||
2188 | BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog) | |
2189 | END_EVENT_TABLE() | |
2190 | ||
2191 | SettingsDialog::SettingsDialog(wxWindow* win, int dialogType) | |
2192 | { | |
2193 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); | |
2194 | ||
2195 | int tabImage1 = -1; | |
2196 | int tabImage2 = -1; | |
2197 | ||
2198 | bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK); | |
2199 | int resizeBorder = wxRESIZE_BORDER; | |
2200 | ||
2201 | if (useToolBook) | |
2202 | { | |
2203 | resizeBorder = 0; | |
2204 | tabImage1 = 0; | |
2205 | tabImage2 = 1; | |
2206 | ||
2207 | int sheetStyle = wxPROPSHEET_SHRINKTOFIT; | |
2208 | if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK) | |
2209 | sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK; | |
2210 | else | |
2211 | sheetStyle |= wxPROPSHEET_TOOLBOOK; | |
2212 | ||
2213 | SetSheetStyle(sheetStyle); | |
2214 | SetSheetInnerBorder(0); | |
2215 | SetSheetOuterBorder(0); | |
2216 | ||
2217 | // create a dummy image list with a few icons | |
2218 | const wxSize imageSize(32, 32); | |
2219 | ||
2220 | m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); | |
2221 | m_imageList-> | |
2222 | Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); | |
2223 | m_imageList-> | |
2224 | Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); | |
2225 | m_imageList-> | |
2226 | Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); | |
2227 | m_imageList-> | |
2228 | Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); | |
2229 | } | |
2230 | else | |
2231 | m_imageList = NULL; | |
2232 | ||
2233 | Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize, | |
2234 | wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder) | |
2235 | ); | |
2236 | ||
2237 | // If using a toolbook, also follow Mac style and don't create buttons | |
2238 | if (!useToolBook) | |
2239 | CreateButtons(wxOK | wxCANCEL | | |
2240 | (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP) | |
2241 | ); | |
2242 | ||
2243 | wxBookCtrlBase* notebook = GetBookCtrl(); | |
2244 | notebook->SetImageList(m_imageList); | |
2245 | ||
2246 | wxPanel* generalSettings = CreateGeneralSettingsPage(notebook); | |
2247 | wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook); | |
2248 | ||
2249 | notebook->AddPage(generalSettings, _("General"), true, tabImage1); | |
2250 | notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2); | |
2251 | ||
2252 | LayoutDialog(); | |
2253 | } | |
2254 | ||
2255 | SettingsDialog::~SettingsDialog() | |
2256 | { | |
2257 | delete m_imageList; | |
2258 | } | |
2259 | ||
2260 | wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent) | |
2261 | { | |
2262 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
2263 | ||
2264 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
2265 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
2266 | ||
2267 | //// LOAD LAST FILE | |
2268 | ||
2269 | wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL ); | |
2270 | wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize); | |
2271 | itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2272 | item0->Add(itemSizer3, 0, wxGROW|wxALL, 0); | |
2273 | ||
2274 | //// AUTOSAVE | |
2275 | ||
2276 | wxString autoSaveLabel = _("&Auto-save every"); | |
2277 | wxString minsLabel = _("mins"); | |
2278 | ||
2279 | wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL ); | |
2280 | wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize); | |
2281 | ||
2282 | #if wxUSE_SPINCTRL | |
2283 | wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString, | |
2284 | wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1); | |
2285 | #endif | |
2286 | ||
2287 | itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2288 | #if wxUSE_SPINCTRL | |
2289 | itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2290 | #endif | |
2291 | itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2292 | item0->Add(itemSizer12, 0, wxGROW|wxALL, 0); | |
2293 | ||
2294 | //// TOOLTIPS | |
2295 | ||
2296 | wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL ); | |
2297 | wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize); | |
2298 | itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2299 | item0->Add(itemSizer8, 0, wxGROW|wxALL, 0); | |
2300 | ||
2301 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
2302 | ||
2303 | panel->SetSizerAndFit(topSizer); | |
2304 | ||
2305 | return panel; | |
2306 | } | |
2307 | ||
2308 | wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent) | |
2309 | { | |
2310 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
2311 | ||
2312 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
2313 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
2314 | ||
2315 | //// PROJECT OR GLOBAL | |
2316 | wxString globalOrProjectChoices[2]; | |
2317 | globalOrProjectChoices[0] = _("&New projects"); | |
2318 | globalOrProjectChoices[1] = _("&This project"); | |
2319 | ||
2320 | wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"), | |
2321 | wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices); | |
2322 | item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5); | |
2323 | ||
2324 | projectOrGlobal->SetSelection(0); | |
2325 | ||
2326 | //// BACKGROUND STYLE | |
2327 | wxArrayString backgroundStyleChoices; | |
2328 | backgroundStyleChoices.Add(wxT("Colour")); | |
2329 | backgroundStyleChoices.Add(wxT("Image")); | |
2330 | wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:")); | |
2331 | ||
2332 | wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL ); | |
2333 | item0->Add(styleSizer, 0, wxGROW|wxALL, 5); | |
2334 | ||
2335 | wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
2336 | ||
2337 | wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices); | |
2338 | ||
2339 | itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2340 | itemSizer2->Add(5, 5, 1, wxALL, 0); | |
2341 | itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2342 | ||
2343 | styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5); | |
2344 | ||
2345 | #if wxUSE_SPINCTRL | |
2346 | //// FONT SIZE SELECTION | |
2347 | ||
2348 | wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:")); | |
2349 | wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL ); | |
2350 | ||
2351 | wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition, | |
2352 | wxSize(80, wxDefaultCoord)); | |
2353 | itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); | |
2354 | ||
2355 | item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5); | |
2356 | #endif | |
2357 | ||
2358 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
2359 | topSizer->AddSpacer(5); | |
2360 | ||
2361 | panel->SetSizerAndFit(topSizer); | |
2362 | ||
2363 | return panel; | |
2364 | } | |
2365 | ||
2366 | // ---------------------------------------------------------------------------- | |
2367 | // TestMessageBoxDialog | |
2368 | // ---------------------------------------------------------------------------- | |
2369 | ||
2370 | /* static */ | |
2371 | const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] = | |
2372 | { | |
2373 | { wxYES, "&Yes" }, | |
2374 | { wxNO, "&No" }, | |
2375 | { wxOK, "&Ok" }, | |
2376 | { wxCANCEL, "&Cancel" }, | |
2377 | }; | |
2378 | ||
2379 | BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog) | |
2380 | EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply) | |
2381 | EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose) | |
2382 | END_EVENT_TABLE() | |
2383 | ||
2384 | TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent) | |
2385 | : wxDialog(parent, wxID_ANY, "Message Box Test Dialog", | |
2386 | wxDefaultPosition, wxDefaultSize, | |
2387 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) | |
2388 | { | |
2389 | wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL); | |
2390 | ||
2391 | // this sizer allows to configure the messages shown in the message box | |
2392 | wxSizer * const | |
2393 | sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages"); | |
2394 | sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:")); | |
2395 | m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!", | |
2396 | wxDefaultPosition, wxDefaultSize, | |
2397 | wxTE_MULTILINE); | |
2398 | sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM)); | |
2399 | ||
2400 | sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:")); | |
2401 | m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "", | |
2402 | wxDefaultPosition, wxDefaultSize, | |
2403 | wxTE_MULTILINE); | |
2404 | sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand()); | |
2405 | ||
2406 | sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border()); | |
2407 | ||
2408 | ||
2409 | // this one is for configuring the buttons | |
2410 | wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5); | |
2411 | sizerBtns->AddGrowableCol(1); | |
2412 | ||
2413 | sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)")); | |
2414 | sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label")); | |
2415 | ||
2416 | for ( int n = 0; n < Btn_Max; n++ ) | |
2417 | { | |
2418 | m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name); | |
2419 | sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left()); | |
2420 | ||
2421 | m_labels[n] = new wxTextCtrl(this, wxID_ANY); | |
2422 | sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand()); | |
2423 | ||
2424 | m_labels[n]->Connect(wxEVT_UPDATE_UI, | |
2425 | wxUpdateUIEventHandler( | |
2426 | TestMessageBoxDialog::OnUpdateLabelUI), | |
2427 | NULL, | |
2428 | this); | |
2429 | } | |
2430 | ||
2431 | wxSizer * const | |
2432 | sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons"); | |
2433 | sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand()); | |
2434 | sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border()); | |
2435 | ||
2436 | ||
2437 | // icon choice | |
2438 | const wxString icons[] = { | |
2439 | "&Information", "&Question", "&Warning", "&Error" | |
2440 | }; | |
2441 | ||
2442 | m_icons = new wxRadioBox(this, wxID_ANY, "&Icon:", | |
2443 | wxDefaultPosition, wxDefaultSize, | |
2444 | WXSIZEOF(icons), icons); | |
2445 | sizerTop->Add(m_icons, wxSizerFlags().Expand().Border()); | |
2446 | ||
2447 | ||
2448 | // miscellaneous other stuff | |
2449 | wxSizer * const | |
2450 | sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags"); | |
2451 | ||
2452 | m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default"); | |
2453 | m_chkNoDefault->Connect(wxEVT_UPDATE_UI, | |
2454 | wxUpdateUIEventHandler( | |
2455 | TestMessageBoxDialog::OnUpdateNoDefaultUI), | |
2456 | NULL, | |
2457 | this); | |
2458 | sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border()); | |
2459 | ||
2460 | m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent"); | |
2461 | sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border()); | |
2462 | ||
2463 | sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border()); | |
2464 | ||
2465 | // finally buttons to show the resulting message box and close this dialog | |
2466 | sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE), | |
2467 | wxSizerFlags().Right().Border()); | |
2468 | ||
2469 | SetSizerAndFit(sizerTop); | |
2470 | ||
2471 | m_buttons[Btn_Ok]->SetValue(true); | |
2472 | } | |
2473 | ||
2474 | void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event) | |
2475 | { | |
2476 | for ( int n = 0; n < Btn_Max; n++ ) | |
2477 | { | |
2478 | if ( event.GetEventObject() == m_labels[n] ) | |
2479 | { | |
2480 | event.Enable( m_buttons[n]->IsChecked() ); | |
2481 | return; | |
2482 | } | |
2483 | } | |
2484 | ||
2485 | wxFAIL_MSG( "called for unknown label" ); | |
2486 | } | |
2487 | ||
2488 | void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event) | |
2489 | { | |
2490 | event.Enable( m_buttons[Btn_No]->IsChecked() ); | |
2491 | } | |
2492 | ||
2493 | void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) | |
2494 | { | |
2495 | long style = 0; | |
2496 | ||
2497 | for ( int n = 0; n < Btn_Max; n++ ) | |
2498 | { | |
2499 | if ( m_buttons[n]->IsChecked() ) | |
2500 | style |= ms_btnInfo[n].flag; | |
2501 | } | |
2502 | ||
2503 | switch ( m_icons->GetSelection() ) | |
2504 | { | |
2505 | case 0: style |= wxICON_INFORMATION; break; | |
2506 | case 1: style |= wxICON_QUESTION; break; | |
2507 | case 2: style |= wxICON_WARNING; break; | |
2508 | case 3: style |= wxICON_ERROR; break; | |
2509 | } | |
2510 | ||
2511 | if ( m_chkCentre->IsChecked() ) | |
2512 | style |= wxCENTRE; | |
2513 | ||
2514 | if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() ) | |
2515 | style |= wxNO_DEFAULT; | |
2516 | ||
2517 | ||
2518 | wxMessageDialog dlg(this, m_textMsg->GetValue(), "Test Message Box", | |
2519 | style); | |
2520 | if ( !m_textExtMsg->IsEmpty() ) | |
2521 | dlg.SetExtendedMessage(m_textExtMsg->GetValue()); | |
2522 | ||
2523 | if ( style & wxYES_NO ) | |
2524 | { | |
2525 | if ( style & wxCANCEL ) | |
2526 | { | |
2527 | dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(), | |
2528 | m_labels[Btn_No]->GetValue(), | |
2529 | m_labels[Btn_Cancel]->GetValue()); | |
2530 | } | |
2531 | else | |
2532 | { | |
2533 | dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(), | |
2534 | m_labels[Btn_No]->GetValue()); | |
2535 | } | |
2536 | } | |
2537 | else | |
2538 | { | |
2539 | if ( style & wxCANCEL ) | |
2540 | { | |
2541 | dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(), | |
2542 | m_labels[Btn_Cancel]->GetValue()); | |
2543 | } | |
2544 | else | |
2545 | { | |
2546 | dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue()); | |
2547 | } | |
2548 | } | |
2549 | ||
2550 | dlg.ShowModal(); | |
2551 | } | |
2552 | ||
2553 | void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event)) | |
2554 | { | |
2555 | EndModal(wxID_CANCEL); | |
2556 | } | |
2557 | ||
2558 | #endif // USE_SETTINGS_DIALOG | |
2559 | ||
2560 | #if wxUSE_LOG | |
2561 | ||
2562 | // ---------------------------------------------------------------------------- | |
2563 | // custom log target | |
2564 | // ---------------------------------------------------------------------------- | |
2565 | ||
2566 | class MyLogGui : public wxLogGui | |
2567 | { | |
2568 | private: | |
2569 | virtual void DoShowSingleLogMessage(const wxString& message, | |
2570 | const wxString& title, | |
2571 | int style) | |
2572 | { | |
2573 | wxMessageDialog dlg(NULL, message, title, | |
2574 | wxOK | wxCANCEL | wxCANCEL_DEFAULT | style); | |
2575 | dlg.SetOKCancelLabels(wxID_COPY, wxID_OK); | |
2576 | dlg.SetExtendedMessage("Note that this is a custom log dialog."); | |
2577 | dlg.ShowModal(); | |
2578 | } | |
2579 | }; | |
2580 | ||
2581 | wxLog *MyAppTraits::CreateLogTarget() | |
2582 | { | |
2583 | return new MyLogGui; | |
2584 | } | |
2585 | ||
2586 | #endif // wxUSE_LOG |