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