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