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