]> git.saurik.com Git - wxWidgets.git/blob - samples/dialogs/dialogs.cpp
adding x server license terms for polygon methods
[wxWidgets.git] / samples / dialogs / dialogs.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dialogs.cpp
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart, Vadim Zeitlin, ABX
5 // Created: 04/01/98
6 // RCS-ID: $Id$
7 // Copyright: (c) Julian Smart
8 // (c) 2004 ABX
9 // (c) Vadim Zeitlin
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif
23
24 #include "../sample.xpm"
25
26 #include "wx/apptrait.h"
27 #include "wx/datetime.h"
28 #include "wx/image.h"
29 #include "wx/bookctrl.h"
30 #include "wx/artprov.h"
31 #include "wx/imaglist.h"
32 #include "wx/minifram.h"
33 #include "wx/sysopt.h"
34 #include "wx/notifmsg.h"
35 #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 void OnCheckBox(wxCommandEvent& event) { m_btn->Enable(event.IsChecked()); }
1336 wxString GetInfo() const
1337 {
1338 return wxString::Format("checkbox value = %d", (int) m_cb->GetValue());
1339 }
1340 private:
1341 wxButton *m_btn;
1342 wxCheckBox *m_cb;
1343 };
1344
1345 MyExtraPanel::MyExtraPanel(wxWindow *parent)
1346 : wxPanel(parent)
1347 {
1348 m_btn = new wxButton(this, -1, wxT("Custom Button"));
1349 m_btn->Enable(false);
1350 m_cb = new wxCheckBox(this, -1, wxT("Enable Custom Button"));
1351 m_cb->Connect(wxID_ANY, wxEVT_CHECKBOX,
1352 wxCommandEventHandler(MyExtraPanel::OnCheckBox), NULL, this);
1353 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1354 sizerTop->Add(m_cb, wxSizerFlags().Centre().Border());
1355 sizerTop->AddStretchSpacer();
1356 sizerTop->Add(m_btn, wxSizerFlags().Right().Border());
1357 SetSizerAndFit(sizerTop);
1358 }
1359
1360 // a static method can be used instead of a function with most of compilers
1361 static wxWindow* createMyExtraPanel(wxWindow *parent)
1362 {
1363 return new MyExtraPanel(parent);
1364 }
1365
1366 void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
1367 {
1368 wxFileDialog dialog
1369 (
1370 this,
1371 wxT("Testing open file dialog"),
1372 wxEmptyString,
1373 wxEmptyString,
1374 #ifdef __WXMOTIF__
1375 wxT("C++ files (*.cpp)|*.cpp")
1376 #else
1377 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1378 #endif
1379 );
1380
1381 dialog.SetExtraControlCreator(&createMyExtraPanel);
1382 dialog.CentreOnParent();
1383 dialog.SetDirectory(wxGetHomeDir());
1384
1385 if (dialog.ShowModal() == wxID_OK)
1386 {
1387 wxString info;
1388 wxWindow * const extra = dialog.GetExtraControl();
1389 info.Printf(wxT("Full file name: %s\n")
1390 wxT("Path: %s\n")
1391 wxT("Name: %s\n")
1392 wxT("Custom window: %s"),
1393 dialog.GetPath().c_str(),
1394 dialog.GetDirectory().c_str(),
1395 dialog.GetFilename().c_str(),
1396 extra ? static_cast<MyExtraPanel*>(extra)->GetInfo()
1397 : wxString("None"));
1398 wxMessageDialog dialog2(this, info, wxT("Selected file"));
1399 dialog2.ShowModal();
1400 }
1401 }
1402
1403 // this shows how to take advantage of specifying a default extension in the
1404 // call to wxFileSelector: it is remembered after each new call and the next
1405 // one will use it by default
1406 void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
1407 {
1408 static wxString s_extDef;
1409 wxString path = wxFileSelector(
1410 wxT("Select the file to load"),
1411 wxEmptyString, wxEmptyString,
1412 s_extDef,
1413 wxString::Format
1414 (
1415 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1416 wxFileSelectorDefaultWildcardStr,
1417 wxFileSelectorDefaultWildcardStr
1418 ),
1419 wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW,
1420 this
1421 );
1422
1423 if ( !path )
1424 return;
1425
1426 // it is just a sample, would use wxSplitPath in real program
1427 s_extDef = path.AfterLast(wxT('.'));
1428
1429 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
1430 path, s_extDef);
1431 }
1432
1433 void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
1434 {
1435 wxString wildcards =
1436 #ifdef __WXMOTIF__
1437 wxT("C++ files (*.cpp)|*.cpp");
1438 #else
1439 wxString::Format
1440 (
1441 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1442 wxFileSelectorDefaultWildcardStr,
1443 wxFileSelectorDefaultWildcardStr
1444 );
1445 #endif
1446 wxFileDialog dialog(this, wxT("Testing open multiple file dialog"),
1447 wxEmptyString, wxEmptyString, wildcards,
1448 wxFD_OPEN|wxFD_MULTIPLE);
1449
1450 if (dialog.ShowModal() == wxID_OK)
1451 {
1452 wxArrayString paths, filenames;
1453
1454 dialog.GetPaths(paths);
1455 dialog.GetFilenames(filenames);
1456
1457 wxString msg, s;
1458 size_t count = paths.GetCount();
1459 for ( size_t n = 0; n < count; n++ )
1460 {
1461 s.Printf(wxT("File %d: %s (%s)\n"),
1462 (int)n, paths[n].c_str(), filenames[n].c_str());
1463
1464 msg += s;
1465 }
1466 s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex());
1467 msg += s;
1468
1469 wxMessageDialog dialog2(this, msg, wxT("Selected files"));
1470 dialog2.ShowModal();
1471 }
1472 }
1473
1474 void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
1475 {
1476 wxFileDialog dialog(this,
1477 wxT("Testing save file dialog"),
1478 wxEmptyString,
1479 wxT("myletter.doc"),
1480 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1481 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1482
1483 dialog.SetFilterIndex(1);
1484
1485 if (dialog.ShowModal() == wxID_OK)
1486 {
1487 wxLogMessage(wxT("%s, filter %d"),
1488 dialog.GetPath().c_str(), dialog.GetFilterIndex());
1489 }
1490 }
1491 #endif // wxUSE_FILEDLG
1492
1493 #if USE_FILEDLG_GENERIC
1494 void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
1495 {
1496 wxGenericFileDialog dialog
1497 (
1498 this,
1499 wxT("Testing open file dialog"),
1500 wxEmptyString,
1501 wxEmptyString,
1502 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
1503 );
1504
1505 dialog.SetExtraControlCreator(&createMyExtraPanel);
1506 dialog.SetDirectory(wxGetHomeDir());
1507
1508 if (dialog.ShowModal() == wxID_OK)
1509 {
1510 wxString info;
1511 info.Printf(wxT("Full file name: %s\n")
1512 wxT("Path: %s\n")
1513 wxT("Name: %s"),
1514 dialog.GetPath().c_str(),
1515 dialog.GetDirectory().c_str(),
1516 dialog.GetFilename().c_str());
1517 wxMessageDialog dialog2(this, info, wxT("Selected file"));
1518 dialog2.ShowModal();
1519 }
1520 }
1521
1522 void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
1523 {
1524 // On PocketPC you can disable OK-only dialogs policy using system option
1525 int buttons = wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1526 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1527
1528 wxString wildcards = wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1529 wxGenericFileDialog dialog(this, wxT("Testing open multiple file dialog"),
1530 wxEmptyString, wxEmptyString, wildcards,
1531 wxFD_MULTIPLE);
1532
1533 if (dialog.ShowModal() == wxID_OK)
1534 {
1535 wxArrayString paths, filenames;
1536
1537 dialog.GetPaths(paths);
1538 dialog.GetFilenames(filenames);
1539
1540 wxString msg, s;
1541 size_t count = paths.GetCount();
1542 for ( size_t n = 0; n < count; n++ )
1543 {
1544 s.Printf(wxT("File %d: %s (%s)\n"),
1545 (int)n, paths[n].c_str(), filenames[n].c_str());
1546
1547 msg += s;
1548 }
1549 s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex());
1550 msg += s;
1551
1552 wxMessageDialog dialog2(this, msg, wxT("Selected files"));
1553 dialog2.ShowModal();
1554 }
1555
1556 // restore system option
1557 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons);
1558 }
1559
1560 void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
1561 {
1562 wxGenericFileDialog dialog(this,
1563 wxT("Testing save file dialog"),
1564 wxEmptyString,
1565 wxT("myletter.doc"),
1566 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1567 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1568
1569 dialog.SetFilterIndex(1);
1570
1571 if (dialog.ShowModal() == wxID_OK)
1572 {
1573 wxLogMessage(wxT("%s, filter %d"),
1574 dialog.GetPath().c_str(), dialog.GetFilterIndex());
1575 }
1576 }
1577 #endif // USE_FILEDLG_GENERIC
1578
1579 #if wxUSE_DIRDLG
1580 void MyFrame::DoDirChoose(int style)
1581 {
1582 // pass some initial dir to wxDirDialog
1583 wxString dirHome;
1584 wxGetHomeDir(&dirHome);
1585
1586 wxDirDialog dialog(this, wxT("Testing directory picker"), dirHome, style);
1587
1588 if (dialog.ShowModal() == wxID_OK)
1589 {
1590 wxLogMessage(wxT("Selected path: %s"), dialog.GetPath().c_str());
1591 }
1592 }
1593
1594 void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
1595 {
1596 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
1597 }
1598
1599 void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
1600 {
1601 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST);
1602 }
1603 #endif // wxUSE_DIRDLG
1604
1605 #if USE_DIRDLG_GENERIC
1606 void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
1607 {
1608 // pass some initial dir to wxDirDialog
1609 wxString dirHome;
1610 wxGetHomeDir(&dirHome);
1611
1612 wxGenericDirDialog dialog(this, wxT("Testing generic directory picker"), dirHome);
1613
1614 if (dialog.ShowModal() == wxID_OK)
1615 {
1616 wxMessageDialog dialog2(this, dialog.GetPath(), wxT("Selected path"));
1617 dialog2.ShowModal();
1618 }
1619 }
1620 #endif // USE_DIRDLG_GENERIC
1621
1622 #if USE_MODAL_PRESENTATION
1623 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
1624 {
1625 MyModalDialog dlg(this);
1626 dlg.ShowModal();
1627 }
1628 #endif // USE_MODAL_PRESENTATION
1629
1630 void MyFrame::ModelessDlg(wxCommandEvent& event)
1631 {
1632 bool show = GetMenuBar()->IsChecked(event.GetId());
1633
1634 if ( show )
1635 {
1636 if ( !m_dialog )
1637 {
1638 m_dialog = new MyModelessDialog(this);
1639 }
1640
1641 m_dialog->Show(true);
1642 }
1643 else // hide
1644 {
1645 // If m_dialog is NULL, then possibly the system
1646 // didn't report the checked menu item status correctly.
1647 // It should be true just after the menu item was selected,
1648 // if there was no modeless dialog yet.
1649
1650 wxASSERT( m_dialog != NULL );
1651 if (m_dialog)
1652 m_dialog->Hide();
1653 }
1654 }
1655
1656 void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event))
1657 {
1658 wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on screen"),
1659 wxDefaultPosition, wxSize(200, 100));
1660 (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
1661 dlg.CentreOnScreen();
1662 dlg.ShowModal();
1663 }
1664
1665 void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event))
1666 {
1667 wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on parent"),
1668 wxDefaultPosition, wxSize(200, 100));
1669 (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
1670 dlg.CentreOnParent();
1671 dlg.ShowModal();
1672 }
1673
1674 #if wxUSE_MINIFRAME
1675 void MyFrame::MiniFrame(wxCommandEvent& WXUNUSED(event))
1676 {
1677 wxFrame *frame = new wxMiniFrame(this, wxID_ANY, wxT("Mini frame"),
1678 wxDefaultPosition, wxSize(300, 100),
1679 wxCAPTION | wxCLOSE_BOX);
1680 new wxStaticText(frame,
1681 wxID_ANY,
1682 wxT("Mini frames have slightly different appearance"),
1683 wxPoint(5, 5));
1684 new wxStaticText(frame,
1685 wxID_ANY,
1686 wxT("from the normal frames but that's the only difference."),
1687 wxPoint(5, 25));
1688
1689 frame->CentreOnParent();
1690 frame->Show();
1691 }
1692 #endif // wxUSE_MINIFRAME
1693
1694 void MyFrame::DlgOnTop(wxCommandEvent& WXUNUSED(event))
1695 {
1696 wxDialog dlg(this, wxID_ANY, wxT("Dialog staying on top of other windows"),
1697 wxDefaultPosition, wxSize(300, 100),
1698 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP);
1699 (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
1700 dlg.ShowModal();
1701 }
1702
1703 #if wxUSE_STARTUP_TIPS
1704 void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
1705 {
1706 static size_t s_index = (size_t)-1;
1707
1708 if ( s_index == (size_t)-1 )
1709 {
1710 srand(time(NULL));
1711
1712 // this is completely bogus, we don't know how many lines are there
1713 // in the file, but who cares, it's a demo only...
1714 s_index = rand() % 5;
1715 }
1716
1717 wxTipProvider *tipProvider = wxCreateFileTipProvider(wxT("tips.txt"), s_index);
1718
1719 bool showAtStartup = wxShowTip(this, tipProvider);
1720
1721 if ( showAtStartup )
1722 {
1723 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
1724 wxOK | wxICON_INFORMATION, this);
1725 }
1726
1727 s_index = tipProvider->GetCurrentTip();
1728 delete tipProvider;
1729 }
1730 #endif // wxUSE_STARTUP_TIPS
1731
1732 #if USE_SETTINGS_DIALOG
1733 void MyFrame::OnPropertySheet(wxCommandEvent& event)
1734 {
1735 SettingsDialog dialog(this, event.GetId());
1736 dialog.ShowModal();
1737 }
1738 #endif // USE_SETTINGS_DIALOG
1739
1740 void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
1741 {
1742 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
1743
1744 wxSleep(3);
1745
1746 RequestUserAttention(wxUSER_ATTENTION_ERROR);
1747 }
1748
1749 #if wxUSE_NOTIFICATION_MESSAGE
1750
1751 void MyFrame::OnNotifMsgAuto(wxCommandEvent& WXUNUSED(event))
1752 {
1753 // Notice that the notification remains shown even after the
1754 // wxNotificationMessage object itself is destroyed so we can show simple
1755 // notifications using temporary objects.
1756 if ( !wxNotificationMessage
1757 (
1758 "Automatic Notification",
1759 "Nothing important has happened\n"
1760 "this notification will disappear soon."
1761 ).Show() )
1762 {
1763 wxLogStatus("Failed to show notification message");
1764 }
1765
1766 // But it doesn't have to be a temporary, of course.
1767 wxNotificationMessage n("Dummy Warning", "Example of a warning notification.");
1768 n.SetFlags(wxICON_ERROR);
1769 n.Show(5); // Just for testing, use 5 second delay.
1770 }
1771
1772 void MyFrame::OnNotifMsgShow(wxCommandEvent& WXUNUSED(event))
1773 {
1774 if ( !m_notifMsg )
1775 {
1776 m_notifMsg = new wxNotificationMessage
1777 (
1778 "wxWidgets Manual Notification",
1779 "You can hide this notification from the menu",
1780 this
1781 );
1782 }
1783
1784 if ( !m_notifMsg->Show(wxNotificationMessage::Timeout_Never) )
1785 {
1786 wxLogStatus("Failed to show manual notification message");
1787 }
1788 }
1789
1790 void MyFrame::OnNotifMsgHide(wxCommandEvent& WXUNUSED(event))
1791 {
1792 if ( m_notifMsg && !m_notifMsg->Close() )
1793 {
1794 wxLogStatus("Failed to hide manual notification message");
1795 }
1796 }
1797
1798 #endif // wxUSE_NOTIFICATION_MESSAGE
1799
1800 #if wxUSE_RICHTOOLTIP
1801
1802 #include "wx/richtooltip.h"
1803
1804 #include "tip.xpm"
1805
1806 class RichTipDialog : public wxDialog
1807 {
1808 public:
1809 RichTipDialog(wxWindow* parent)
1810 : wxDialog(parent, wxID_ANY, "wxRichToolTip Test",
1811 wxDefaultPosition, wxDefaultSize,
1812 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
1813 {
1814 // Create the controls.
1815 m_textTitle = new wxTextCtrl(this, wxID_ANY, "Tooltip title");
1816 m_textBody = new wxTextCtrl(this, wxID_ANY, "Main tooltip text\n"
1817 "possibly on several\n"
1818 "lines.",
1819 wxDefaultPosition, wxDefaultSize,
1820 wxTE_MULTILINE);
1821 wxButton* btnShowText = new wxButton(this, wxID_ANY, "Show for &text");
1822 wxButton* btnShowBtn = new wxButton(this, wxID_ANY, "Show for &button");
1823
1824 const wxString icons[] =
1825 {
1826 "&None",
1827 "&Information",
1828 "&Warning",
1829 "&Error",
1830 "&Custom"
1831 };
1832 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == Icon_Max, IconMismatch );
1833 m_icons = new wxRadioBox(this, wxID_ANY, "&Icon choice:",
1834 wxDefaultPosition, wxDefaultSize,
1835 WXSIZEOF(icons), icons,
1836 1, wxRA_SPECIFY_ROWS);
1837 m_icons->SetSelection(Icon_Info);
1838
1839 const wxString tipKinds[] =
1840 {
1841 "&None", "Top left", "Top", "Top right",
1842 "Bottom left", "Bottom", "Bottom right", "&Auto"
1843 };
1844 m_tipKinds = new wxRadioBox(this, wxID_ANY, "Tip &kind:",
1845 wxDefaultPosition, wxDefaultSize,
1846 WXSIZEOF(tipKinds), tipKinds,
1847 4, wxRA_SPECIFY_COLS);
1848 m_tipKinds->SetSelection(wxTipKind_Auto);
1849
1850 const wxString bgStyles[] =
1851 {
1852 "&Default", "&Solid", "&Gradient",
1853 };
1854 wxCOMPILE_TIME_ASSERT( WXSIZEOF(bgStyles) == Bg_Max, BgMismatch );
1855 m_bgStyles = new wxRadioBox(this, wxID_ANY, "Background style:",
1856 wxDefaultPosition, wxDefaultSize,
1857 WXSIZEOF(bgStyles), bgStyles,
1858 1, wxRA_SPECIFY_ROWS);
1859
1860 const wxString timeouts[] = { "&None", "&Default (no delay)", "&3 seconds" };
1861 wxCOMPILE_TIME_ASSERT( WXSIZEOF(timeouts) == Timeout_Max, TmMismatch );
1862 m_timeouts = new wxRadioBox(this, wxID_ANY, "Timeout:",
1863 wxDefaultPosition, wxDefaultSize,
1864 WXSIZEOF(timeouts), timeouts,
1865 1, wxRA_SPECIFY_ROWS);
1866 m_timeouts->SetSelection(Timeout_Default);
1867 m_timeDelay = new wxCheckBox(this, wxID_ANY, "Delay show" );
1868
1869 // Lay them out.
1870 m_textBody->SetMinSize(wxSize(300, 200));
1871
1872 wxBoxSizer* const sizer = new wxBoxSizer(wxVERTICAL);
1873 sizer->Add(m_textTitle, wxSizerFlags().Expand().Border());
1874 sizer->Add(m_textBody, wxSizerFlags(1).Expand().Border());
1875 sizer->Add(m_icons, wxSizerFlags().Expand().Border());
1876 sizer->Add(m_tipKinds, wxSizerFlags().Centre().Border());
1877 sizer->Add(m_bgStyles, wxSizerFlags().Centre().Border());
1878 sizer->Add(m_timeouts, wxSizerFlags().Centre().Border());
1879 sizer->Add(m_timeDelay, wxSizerFlags().Centre().Border());
1880 wxBoxSizer* const sizerBtns = new wxBoxSizer(wxHORIZONTAL);
1881 sizerBtns->Add(btnShowText, wxSizerFlags().Border(wxRIGHT));
1882 sizerBtns->Add(btnShowBtn, wxSizerFlags().Border(wxLEFT));
1883 sizer->Add(sizerBtns, wxSizerFlags().Centre().Border());
1884 sizer->Add(CreateStdDialogButtonSizer(wxOK),
1885 wxSizerFlags().Expand().Border());
1886 SetSizerAndFit(sizer);
1887
1888
1889 // And connect the event handlers.
1890 btnShowText->Connect
1891 (
1892 wxEVT_BUTTON,
1893 wxCommandEventHandler(RichTipDialog::OnShowTipForText),
1894 NULL,
1895 this
1896 );
1897
1898 btnShowBtn->Connect
1899 (
1900 wxEVT_BUTTON,
1901 wxCommandEventHandler(RichTipDialog::OnShowTipForBtn),
1902 NULL,
1903 this
1904 );
1905 }
1906
1907 private:
1908 enum
1909 {
1910 Icon_None,
1911 Icon_Info,
1912 Icon_Warning,
1913 Icon_Error,
1914 Icon_Custom,
1915 Icon_Max
1916 };
1917
1918 enum
1919 {
1920 Bg_Default,
1921 Bg_Solid,
1922 Bg_Gradient,
1923 Bg_Max
1924 };
1925
1926 enum
1927 {
1928 Timeout_None,
1929 Timeout_Default,
1930 Timeout_3sec,
1931 Timeout_Max
1932 };
1933
1934
1935 void OnShowTipForText(wxCommandEvent& WXUNUSED(event))
1936 {
1937 DoShowTip(m_textTitle);
1938 }
1939
1940 void OnShowTipForBtn(wxCommandEvent& WXUNUSED(event))
1941 {
1942 DoShowTip(FindWindow(wxID_OK));
1943 }
1944
1945 void DoShowTip(wxWindow* win)
1946 {
1947 wxRichToolTip tip(m_textTitle->GetValue(), m_textBody->GetValue());
1948 const int iconSel = m_icons->GetSelection();
1949 if ( iconSel == Icon_Custom )
1950 {
1951 tip.SetIcon(tip_xpm);
1952 }
1953 else // Use a standard icon.
1954 {
1955 static const int stdIcons[] =
1956 {
1957 wxICON_NONE,
1958 wxICON_INFORMATION,
1959 wxICON_WARNING,
1960 wxICON_ERROR,
1961 };
1962
1963 tip.SetIcon(stdIcons[iconSel]);
1964 }
1965
1966 switch ( m_bgStyles->GetSelection() )
1967 {
1968 case Bg_Default:
1969 break;
1970
1971 case Bg_Solid:
1972 tip.SetBackgroundColour(*wxLIGHT_GREY);
1973 break;
1974
1975 case Bg_Gradient:
1976 tip.SetBackgroundColour(*wxWHITE, wxColour(0xe4, 0xe5, 0xf0));
1977 break;
1978 }
1979
1980 int delay = m_timeDelay->IsChecked() ? 500 : 0;
1981
1982 switch ( m_timeouts->GetSelection() )
1983 {
1984 case Timeout_None:
1985 // Don't call SetTimeout unnecessarily
1986 // or msw will show generic impl
1987 if ( delay )
1988 tip.SetTimeout(0, delay);
1989 break;
1990
1991 case Timeout_Default:
1992 break;
1993
1994 case Timeout_3sec:
1995 tip.SetTimeout(3000, delay);
1996 break;
1997 }
1998
1999 tip.SetTipKind(static_cast<wxTipKind>(m_tipKinds->GetSelection()));
2000
2001 tip.ShowFor(win);
2002 }
2003
2004 wxTextCtrl* m_textTitle;
2005 wxTextCtrl* m_textBody;
2006 wxRadioBox* m_icons;
2007 wxRadioBox* m_tipKinds;
2008 wxRadioBox* m_bgStyles;
2009 wxRadioBox* m_timeouts;
2010 wxCheckBox* m_timeDelay;
2011 };
2012
2013 void MyFrame::OnRichTipDialog(wxCommandEvent& WXUNUSED(event))
2014 {
2015 RichTipDialog dialog(this);
2016 dialog.ShowModal();
2017 }
2018
2019 #endif // wxUSE_RICHTOOLTIP
2020
2021 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
2022 {
2023 StdButtonSizerDialog dialog(this);
2024 dialog.ShowModal();
2025 }
2026
2027 // TestDefaultAction
2028
2029 #define ID_CATCH_LISTBOX_DCLICK 100
2030 #define ID_LISTBOX 101
2031 #define ID_DISABLE_OK 102
2032 #define ID_DISABLE_CANCEL 103
2033
2034 BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog)
2035 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK, TestDefaultActionDialog::OnCatchListBoxDClick)
2036 EVT_CHECKBOX(ID_DISABLE_OK, TestDefaultActionDialog::OnDisableOK)
2037 EVT_CHECKBOX(ID_DISABLE_CANCEL, TestDefaultActionDialog::OnDisableCancel)
2038 EVT_LISTBOX_DCLICK(ID_LISTBOX, TestDefaultActionDialog::OnListBoxDClick)
2039 EVT_TEXT_ENTER(wxID_ANY, TestDefaultActionDialog::OnTextEnter)
2040 END_EVENT_TABLE()
2041
2042 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
2043 wxDialog( parent, -1, "Test default action" )
2044 {
2045 m_catchListBoxDClick = false;
2046
2047 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
2048
2049 wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 5, 5 );
2050
2051 #if wxUSE_LISTBOX
2052 wxListBox *listbox = new wxListBox( this, ID_LISTBOX );
2053 listbox->Append( "String 1" );
2054 listbox->Append( "String 2" );
2055 listbox->Append( "String 3" );
2056 listbox->Append( "String 4" );
2057 grid_sizer->Add( listbox );
2058 #endif // wxUSE_LISTBOX
2059
2060 grid_sizer->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL );
2061
2062 grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL );
2063 grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
2064
2065 grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL );
2066 grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
2067
2068 grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_OK, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL );
2069 grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_CANCEL, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL );
2070
2071 main_sizer->Add( grid_sizer, 0, wxALL, 10 );
2072
2073 wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL );
2074 if (button_sizer)
2075 main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 );
2076
2077 SetSizerAndFit( main_sizer );
2078 }
2079
2080 void TestDefaultActionDialog::OnDisableOK(wxCommandEvent& event)
2081 {
2082 FindWindow(wxID_OK)->Enable(!event.IsChecked());
2083 }
2084
2085 void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent& event)
2086 {
2087 FindWindow(wxID_CANCEL)->Enable(!event.IsChecked());
2088 }
2089
2090 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
2091 {
2092 event.Skip( !m_catchListBoxDClick );
2093 }
2094
2095 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(event))
2096 {
2097 m_catchListBoxDClick = !m_catchListBoxDClick;
2098 }
2099
2100 void TestDefaultActionDialog::OnTextEnter(wxCommandEvent& event)
2101 {
2102 wxLogMessage("Text \"%s\" entered.", event.GetString());
2103 }
2104
2105 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event))
2106 {
2107 TestDefaultActionDialog dialog( this );
2108 dialog.ShowModal();
2109 }
2110
2111 void MyFrame::OnModalHook(wxCommandEvent& event)
2112 {
2113 class TestModalHook : public wxModalDialogHook
2114 {
2115 protected:
2116 virtual int Enter(wxDialog* dialog)
2117 {
2118 wxLogStatus("Showing %s modal dialog",
2119 dialog->GetClassInfo()->GetClassName());
2120 return wxID_NONE;
2121 }
2122
2123 virtual void Exit(wxDialog* dialog)
2124 {
2125 wxLogStatus("Leaving %s modal dialog",
2126 dialog->GetClassInfo()->GetClassName());
2127 }
2128 };
2129
2130 static TestModalHook s_hook;
2131 if ( event.IsChecked() )
2132 s_hook.Register();
2133 else
2134 s_hook.Unregister();
2135 }
2136
2137 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
2138 {
2139 Close(true);
2140 }
2141
2142 #if wxUSE_PROGRESSDLG
2143
2144 void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
2145 {
2146 static const int max = 100;
2147
2148 wxProgressDialog dialog("Progress dialog example",
2149 // "Reserve" enough space for the multiline
2150 // messages below, we'll change it anyhow
2151 // immediately in the loop below
2152 wxString(' ', 100) + "\n\n\n\n",
2153 max, // range
2154 this, // parent
2155 wxPD_CAN_ABORT |
2156 wxPD_CAN_SKIP |
2157 wxPD_APP_MODAL |
2158 //wxPD_AUTO_HIDE | // -- try this as well
2159 wxPD_ELAPSED_TIME |
2160 wxPD_ESTIMATED_TIME |
2161 wxPD_REMAINING_TIME |
2162 wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
2163 );
2164
2165 bool cont = true;
2166 for ( int i = 0; i <= max; i++ )
2167 {
2168 wxString msg;
2169
2170 // test both modes of wxProgressDialog behaviour: start in
2171 // indeterminate mode but switch to the determinate one later
2172 const bool determinate = i > max/2;
2173
2174 if ( i == max )
2175 {
2176 msg = "That's all, folks!\n"
2177 "\n"
2178 "Nothing to see here any more.";
2179 }
2180 else if ( !determinate )
2181 {
2182 msg = "Testing indeterminate mode\n"
2183 "\n"
2184 "This mode allows you to show to the user\n"
2185 "that something is going on even if you don't know\n"
2186 "when exactly will you finish.";
2187 }
2188 else if ( determinate )
2189 {
2190 msg = "Now in standard determinate mode\n"
2191 "\n"
2192 "This is the standard usage mode in which you\n"
2193 "update the dialog after performing each new step of work.\n"
2194 "It requires knowing the total number of steps in advance.";
2195 }
2196
2197 // will be set to true if "Skip" button was pressed
2198 bool skip = false;
2199 if ( determinate )
2200 {
2201 cont = dialog.Update(i, msg, &skip);
2202 }
2203 else
2204 {
2205 cont = dialog.Pulse(msg, &skip);
2206 }
2207
2208 // each skip will move progress about quarter forward
2209 if ( skip )
2210 {
2211 i += max/4;
2212
2213 if ( i >= 100 )
2214 i = 99;
2215 }
2216
2217 if ( !cont )
2218 {
2219 if ( wxMessageBox(wxT("Do you really want to cancel?"),
2220 wxT("Progress dialog question"), // caption
2221 wxYES_NO | wxICON_QUESTION) == wxYES )
2222 break;
2223
2224 cont = true;
2225 dialog.Resume();
2226 }
2227
2228 wxMilliSleep(200);
2229 }
2230
2231 if ( !cont )
2232 {
2233 wxLogStatus(wxT("Progress dialog aborted!"));
2234 }
2235 else
2236 {
2237 wxLogStatus(wxT("Countdown from %d finished"), max);
2238 }
2239 }
2240
2241 #endif // wxUSE_PROGRESSDLG
2242
2243 #if wxUSE_ABOUTDLG
2244
2245 static void InitAboutInfoMinimal(wxAboutDialogInfo& info)
2246 {
2247 info.SetName(wxT("Dialogs Sample"));
2248 info.SetVersion(wxVERSION_NUM_DOT_STRING,
2249 wxString::Format
2250 (
2251 "%s version %s",
2252 wxMINOR_VERSION % 2 ? "Development" : "Stable",
2253 wxVERSION_NUM_DOT_STRING
2254 ));
2255 info.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
2256 info.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
2257 info.AddDeveloper(wxT("Vadim Zeitlin"));
2258 }
2259
2260 static void InitAboutInfoWebsite(wxAboutDialogInfo& info)
2261 {
2262 InitAboutInfoMinimal(info);
2263
2264 info.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
2265 }
2266
2267 static void InitAboutInfoAll(wxAboutDialogInfo& info)
2268 {
2269 InitAboutInfoWebsite(info);
2270
2271 // we can add a second developer
2272 info.AddDeveloper(wxT("A.N. Other"));
2273
2274 // or we can add several persons at once like this
2275 static const wxChar *docwriters[] =
2276 {
2277 wxT("First D. Writer"),
2278 wxT("Second One"),
2279 };
2280
2281 info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters));
2282 info.SetLicence(wxString::FromAscii(
2283 " wxWindows Library Licence, Version 3.1\n"
2284 " ======================================\n"
2285 "\n"
2286 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
2287 "\n"
2288 " Everyone is permitted to copy and distribute verbatim copies\n"
2289 " of this licence document, but changing it is not allowed.\n"
2290 "\n"
2291 " WXWINDOWS LIBRARY LICENCE\n"
2292 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
2293 "\n"
2294 " ...and so on and so forth...\n"
2295 ));
2296
2297 info.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
2298 }
2299
2300 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
2301 {
2302 wxAboutDialogInfo info;
2303 InitAboutInfoMinimal(info);
2304
2305 wxAboutBox(info, this);
2306 }
2307
2308 void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event))
2309 {
2310 wxAboutDialogInfo info;
2311 InitAboutInfoWebsite(info);
2312
2313 wxAboutBox(info, this);
2314 }
2315
2316 void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event))
2317 {
2318 wxAboutDialogInfo info;
2319 InitAboutInfoAll(info);
2320
2321 wxAboutBox(info, this);
2322 }
2323
2324 // a trivial example of a custom dialog class
2325 class MyAboutDialog : public wxGenericAboutDialog
2326 {
2327 public:
2328 MyAboutDialog(const wxAboutDialogInfo& info, wxWindow* parent)
2329 {
2330 Create(info, parent);
2331 }
2332
2333 // add some custom controls
2334 virtual void DoAddCustomControls()
2335 {
2336 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2337 AddText(wxT("Some custom text"));
2338 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
2339 }
2340 };
2341
2342 void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event))
2343 {
2344 wxAboutDialogInfo info;
2345 InitAboutInfoAll(info);
2346
2347 MyAboutDialog dlg(info, this);
2348 dlg.ShowModal();
2349 }
2350
2351 #endif // wxUSE_ABOUTDLG
2352
2353 #if wxUSE_BUSYINFO
2354
2355 void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
2356 {
2357 wxWindowDisabler disableAll;
2358
2359 wxBusyInfo info(wxT("Working, please wait..."), this);
2360
2361 for ( int i = 0; i < 18; i++ )
2362 {
2363 wxMilliSleep(100);
2364 wxTheApp->Yield();
2365 }
2366
2367 wxSleep(2);
2368 //wxWakeUpIdle();
2369 }
2370
2371 #endif // wxUSE_BUSYINFO
2372
2373 #if wxUSE_FINDREPLDLG
2374
2375 void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
2376 {
2377 if ( m_dlgReplace )
2378 {
2379 wxDELETE(m_dlgReplace);
2380 }
2381 else
2382 {
2383 m_dlgReplace = new wxFindReplaceDialog
2384 (
2385 this,
2386 &m_findData,
2387 wxT("Find and replace dialog"),
2388 wxFR_REPLACEDIALOG
2389 );
2390
2391 m_dlgReplace->Show(true);
2392 }
2393 }
2394
2395 void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
2396 {
2397 if ( m_dlgFind )
2398 {
2399 wxDELETE(m_dlgFind);
2400 }
2401 else
2402 {
2403 m_dlgFind = new wxFindReplaceDialog
2404 (
2405 this,
2406 &m_findData,
2407 wxT("Find dialog"),
2408 // just for testing
2409 wxFR_NOWHOLEWORD
2410 );
2411
2412 m_dlgFind->Show(true);
2413 }
2414 }
2415
2416 static wxString DecodeFindDialogEventFlags(int flags)
2417 {
2418 wxString str;
2419 str << (flags & wxFR_DOWN ? wxT("down") : wxT("up")) << wxT(", ")
2420 << (flags & wxFR_WHOLEWORD ? wxT("whole words only, ") : wxT(""))
2421 << (flags & wxFR_MATCHCASE ? wxT("") : wxT("not "))
2422 << wxT("case sensitive");
2423
2424 return str;
2425 }
2426
2427 void MyFrame::OnFindDialog(wxFindDialogEvent& event)
2428 {
2429 wxEventType type = event.GetEventType();
2430
2431 if ( type == wxEVT_FIND || type == wxEVT_FIND_NEXT )
2432 {
2433 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
2434 type == wxEVT_FIND_NEXT ? wxT("next ") : wxT(""),
2435 event.GetFindString().c_str(),
2436 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
2437 }
2438 else if ( type == wxEVT_FIND_REPLACE ||
2439 type == wxEVT_FIND_REPLACE_ALL )
2440 {
2441 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
2442 type == wxEVT_FIND_REPLACE_ALL ? wxT("all ") : wxT(""),
2443 event.GetFindString().c_str(),
2444 event.GetReplaceString().c_str(),
2445 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
2446 }
2447 else if ( type == wxEVT_FIND_CLOSE )
2448 {
2449 wxFindReplaceDialog *dlg = event.GetDialog();
2450
2451 int idMenu;
2452 const wxChar *txt;
2453 if ( dlg == m_dlgFind )
2454 {
2455 txt = wxT("Find");
2456 idMenu = DIALOGS_FIND;
2457 m_dlgFind = NULL;
2458 }
2459 else if ( dlg == m_dlgReplace )
2460 {
2461 txt = wxT("Replace");
2462 idMenu = DIALOGS_REPLACE;
2463 m_dlgReplace = NULL;
2464 }
2465 else
2466 {
2467 txt = wxT("Unknown");
2468 idMenu = wxID_ANY;
2469
2470 wxFAIL_MSG( wxT("unexpected event") );
2471 }
2472
2473 wxLogMessage(wxT("%s dialog is being closed."), txt);
2474
2475 if ( idMenu != wxID_ANY )
2476 {
2477 GetMenuBar()->Check(idMenu, false);
2478 }
2479
2480 dlg->Destroy();
2481 }
2482 else
2483 {
2484 wxLogError(wxT("Unknown find dialog event!"));
2485 }
2486 }
2487
2488 #endif // wxUSE_FINDREPLDLG
2489
2490 // ----------------------------------------------------------------------------
2491 // MyCanvas
2492 // ----------------------------------------------------------------------------
2493
2494 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
2495 {
2496 wxPaintDC dc(this);
2497 dc.SetBackgroundMode(wxTRANSPARENT);
2498 dc.DrawText(
2499 wxT("wxWidgets common dialogs")
2500 #if !defined(__SMARTPHONE__)
2501 wxT(" test application")
2502 #endif
2503 , 10, 10);
2504 }
2505
2506 #if USE_MODAL_PRESENTATION
2507
2508 // ----------------------------------------------------------------------------
2509 // MyModelessDialog
2510 // ----------------------------------------------------------------------------
2511
2512 MyModelessDialog::MyModelessDialog(wxWindow *parent)
2513 : wxDialog(parent, wxID_ANY, wxString(wxT("Modeless dialog")))
2514 {
2515 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
2516
2517 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, wxT("Press me"));
2518 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, wxT("Should be disabled"));
2519 check->Disable();
2520
2521 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
2522 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
2523
2524 SetSizerAndFit(sizerTop);
2525 }
2526
2527 void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
2528 {
2529 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
2530 wxOK | wxICON_INFORMATION, this);
2531 }
2532
2533 void MyModelessDialog::OnClose(wxCloseEvent& event)
2534 {
2535 if ( event.CanVeto() )
2536 {
2537 wxMessageBox(wxT("Use the menu item to close this dialog"),
2538 wxT("Modeless dialog"),
2539 wxOK | wxICON_INFORMATION, this);
2540
2541 event.Veto();
2542 }
2543 }
2544
2545 // ----------------------------------------------------------------------------
2546 // MyModalDialog
2547 // ----------------------------------------------------------------------------
2548
2549 MyModalDialog::MyModalDialog(wxWindow *parent)
2550 : wxDialog(parent, wxID_ANY, wxString(wxT("Modal dialog")))
2551 {
2552 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
2553
2554 m_btnModal = new wxButton(this, wxID_ANY, wxT("&Modal dialog..."));
2555 m_btnModeless = new wxButton(this, wxID_ANY, wxT("Mode&less dialog"));
2556 m_btnDelete = new wxButton(this, wxID_ANY, wxT("&Delete button"));
2557
2558 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
2559 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
2560 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
2561 sizerTop->Add(new wxButton(this, wxID_CLOSE), 0, wxALIGN_CENTER | wxALL, 5);
2562
2563 SetSizerAndFit(sizerTop);
2564
2565 SetEscapeId(wxID_CLOSE);
2566
2567 m_btnModal->SetFocus();
2568 m_btnModal->SetDefault();
2569 }
2570
2571 void MyModalDialog::OnButton(wxCommandEvent& event)
2572 {
2573 if ( event.GetEventObject() == m_btnDelete )
2574 {
2575 wxDELETE(m_btnModal);
2576 m_btnDelete->Disable();
2577 }
2578 else if ( event.GetEventObject() == m_btnModal )
2579 {
2580 #if wxUSE_TEXTDLG
2581 wxGetTextFromUser(wxT("Dummy prompt"),
2582 wxT("Modal dialog called from dialog"),
2583 wxEmptyString, this);
2584 #else
2585 wxMessageBox(wxT("Modal dialog called from dialog"));
2586 #endif // wxUSE_TEXTDLG
2587 }
2588 else if ( event.GetEventObject() == m_btnModeless )
2589 {
2590 (new MyModelessDialog(this))->Show();
2591 }
2592 else
2593 {
2594 event.Skip();
2595 }
2596 }
2597
2598 #endif // USE_MODAL_PRESENTATION
2599
2600 // ----------------------------------------------------------------------------
2601 // StdButtonSizerDialog
2602 // ----------------------------------------------------------------------------
2603
2604 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent)
2605 : wxDialog(parent, wxID_ANY, wxString(wxT("StdButtonSizer dialog")),
2606 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
2607 m_buttonsSizer(NULL)
2608 {
2609 wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL);
2610
2611 wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL);
2612 wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL);
2613
2614 m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button"));
2615
2616 wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button"));
2617
2618 m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2619 m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes"));
2620
2621 wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL);
2622
2623 m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button"));
2624
2625 wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button"));
2626
2627 m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2628 m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close"));
2629
2630 wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL);
2631
2632 m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No"));
2633 m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help"));
2634 m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply"));
2635
2636 m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default"));
2637
2638 sizer1->Add(m_radiobtnOk, 0, wxALL, 5);
2639 sizer1->Add(m_radiobtnYes, 0, wxALL, 5);
2640
2641 sizer->Add(sizerInside1, 0, 0, 0);
2642 sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5);
2643 sizerInside1->Add(sizer1, 0, wxALL, 5);
2644 sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2645
2646 sizer2->Add(m_radiobtnCancel, 0, wxALL, 5);
2647 sizer2->Add(m_radiobtnClose, 0, wxALL, 5);
2648
2649 sizer->Add(sizerInside2, 0, 0, 0);
2650 sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5);
2651 sizerInside2->Add(sizer2, 0, wxALL, 5);
2652 sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2653
2654 sizerTop->Add(sizer, 0, wxALL, 5);
2655
2656 sizer3->Add(m_chkboxNo, 0, wxALL, 5);
2657 sizer3->Add(m_chkboxHelp, 0, wxALL, 5);
2658 sizer3->Add(m_chkboxApply, 0, wxALL, 5);
2659
2660 sizerTop->Add(sizer3, 0, wxALL, 5);
2661
2662 sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10);
2663
2664 EnableDisableControls();
2665
2666 SetSizerAndFit(sizerTop);
2667
2668 wxCommandEvent ev;
2669 OnEvent(ev);
2670 }
2671
2672 void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event))
2673 {
2674 if (m_buttonsSizer)
2675 {
2676 m_buttonsSizer->DeleteWindows();
2677 GetSizer()->Remove(m_buttonsSizer);
2678 }
2679
2680 EnableDisableControls();
2681
2682 long flags = 0;
2683 unsigned long numButtons = 0;
2684
2685 if (m_chkboxAffirmativeButton->IsChecked())
2686 {
2687 if (m_radiobtnOk->GetValue())
2688 {
2689 flags |= wxOK;
2690 numButtons ++;
2691 }
2692 else if (m_radiobtnYes->GetValue())
2693 {
2694 flags |= wxYES;
2695 numButtons ++;
2696 }
2697 }
2698
2699 if (m_chkboxDismissButton->IsChecked())
2700 {
2701 if (m_radiobtnCancel->GetValue())
2702 {
2703 flags |= wxCANCEL;
2704 numButtons ++;
2705 }
2706
2707 else if (m_radiobtnClose->GetValue())
2708 {
2709 flags |= wxCLOSE;
2710 numButtons ++;
2711 }
2712
2713 }
2714
2715 if (m_chkboxApply->IsChecked())
2716 {
2717 flags |= wxAPPLY;
2718 numButtons ++;
2719 }
2720
2721 if (m_chkboxNo->IsChecked())
2722 {
2723 flags |= wxNO;
2724 numButtons ++;
2725 }
2726
2727 if (m_chkboxHelp->IsChecked())
2728 {
2729 flags |= wxHELP;
2730 numButtons ++;
2731 }
2732
2733 if (m_chkboxNoDefault->IsChecked())
2734 {
2735 flags |= wxNO_DEFAULT;
2736 }
2737
2738 m_buttonsSizer = CreateStdDialogButtonSizer(flags);
2739 GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5);
2740
2741 Layout();
2742 GetSizer()->SetSizeHints(this);
2743 }
2744
2745 void StdButtonSizerDialog::EnableDisableControls()
2746 {
2747 const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked();
2748
2749 m_radiobtnOk->Enable(affButtonEnabled);
2750 m_radiobtnYes->Enable(affButtonEnabled);
2751
2752 const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked();
2753
2754 m_radiobtnCancel->Enable(dismissButtonEnabled);
2755 m_radiobtnClose->Enable(dismissButtonEnabled);
2756 }
2757
2758 #if USE_SETTINGS_DIALOG
2759 // ----------------------------------------------------------------------------
2760 // SettingsDialog
2761 // ----------------------------------------------------------------------------
2762
2763 IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
2764
2765 BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
2766 END_EVENT_TABLE()
2767
2768 SettingsDialog::SettingsDialog(wxWindow* win, int dialogType)
2769 {
2770 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
2771
2772 int tabImage1 = -1;
2773 int tabImage2 = -1;
2774
2775 bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK);
2776 int resizeBorder = wxRESIZE_BORDER;
2777
2778 if (useToolBook)
2779 {
2780 resizeBorder = 0;
2781 tabImage1 = 0;
2782 tabImage2 = 1;
2783
2784 int sheetStyle = wxPROPSHEET_SHRINKTOFIT;
2785 if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK)
2786 sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK;
2787 else
2788 sheetStyle |= wxPROPSHEET_TOOLBOOK;
2789
2790 SetSheetStyle(sheetStyle);
2791 SetSheetInnerBorder(0);
2792 SetSheetOuterBorder(0);
2793
2794 // create a dummy image list with a few icons
2795 const wxSize imageSize(32, 32);
2796
2797 m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
2798 m_imageList->
2799 Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
2800 m_imageList->
2801 Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize));
2802 m_imageList->
2803 Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize));
2804 m_imageList->
2805 Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize));
2806 }
2807 else
2808 m_imageList = NULL;
2809
2810 Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
2811 wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder)
2812 );
2813
2814 // If using a toolbook, also follow Mac style and don't create buttons
2815 if (!useToolBook)
2816 CreateButtons(wxOK | wxCANCEL |
2817 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP)
2818 );
2819
2820 wxBookCtrlBase* notebook = GetBookCtrl();
2821 notebook->SetImageList(m_imageList);
2822
2823 wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
2824 wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
2825
2826 notebook->AddPage(generalSettings, _("General"), true, tabImage1);
2827 notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2);
2828
2829 LayoutDialog();
2830 }
2831
2832 SettingsDialog::~SettingsDialog()
2833 {
2834 delete m_imageList;
2835 }
2836
2837 wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
2838 {
2839 wxPanel* panel = new wxPanel(parent, wxID_ANY);
2840
2841 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
2842 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
2843
2844 //// LOAD LAST FILE
2845
2846 wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
2847 wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize);
2848 itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2849 item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
2850
2851 //// AUTOSAVE
2852
2853 wxString autoSaveLabel = _("&Auto-save every");
2854 wxString minsLabel = _("mins");
2855
2856 wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
2857 wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
2858
2859 #if wxUSE_SPINCTRL
2860 wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
2861 wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1);
2862 #endif
2863
2864 itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2865 #if wxUSE_SPINCTRL
2866 itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2867 #endif
2868 itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2869 item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
2870
2871 //// TOOLTIPS
2872
2873 wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
2874 wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize);
2875 itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2876 item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
2877
2878 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
2879
2880 panel->SetSizerAndFit(topSizer);
2881
2882 return panel;
2883 }
2884
2885 wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
2886 {
2887 wxPanel* panel = new wxPanel(parent, wxID_ANY);
2888
2889 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
2890 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
2891
2892 //// PROJECT OR GLOBAL
2893 wxString globalOrProjectChoices[2];
2894 globalOrProjectChoices[0] = _("&New projects");
2895 globalOrProjectChoices[1] = _("&This project");
2896
2897 wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"),
2898 wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
2899 item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
2900
2901 projectOrGlobal->SetSelection(0);
2902
2903 //// BACKGROUND STYLE
2904 wxArrayString backgroundStyleChoices;
2905 backgroundStyleChoices.Add(wxT("Colour"));
2906 backgroundStyleChoices.Add(wxT("Image"));
2907 wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:"));
2908
2909 wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
2910 item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
2911
2912 wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
2913
2914 wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
2915
2916 itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2917 itemSizer2->Add(5, 5, 1, wxALL, 0);
2918 itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2919
2920 styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
2921
2922 #if wxUSE_SPINCTRL
2923 //// FONT SIZE SELECTION
2924
2925 wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:"));
2926 wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
2927
2928 wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition,
2929 wxSize(80, wxDefaultCoord));
2930 itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
2931
2932 item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
2933 #endif
2934
2935 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
2936 topSizer->AddSpacer(5);
2937
2938 panel->SetSizerAndFit(topSizer);
2939
2940 return panel;
2941 }
2942
2943 #endif // USE_SETTINGS_DIALOG
2944
2945 #if wxUSE_MSGDLG
2946 // ----------------------------------------------------------------------------
2947 // TestMessageBoxDialog
2948 // ----------------------------------------------------------------------------
2949
2950 /* static */
2951 const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] =
2952 {
2953 { wxYES, "&Yes" },
2954 { wxNO, "&No" },
2955 { wxOK, "&Ok" },
2956 { wxCANCEL, "&Cancel" },
2957 { wxHELP, "&Help" },
2958 };
2959
2960 BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog)
2961 EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply)
2962 EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose)
2963 END_EVENT_TABLE()
2964
2965 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent)
2966 : wxDialog(parent, wxID_ANY, "Message Box Test Dialog",
2967 wxDefaultPosition, wxDefaultSize,
2968 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
2969 {
2970 }
2971
2972 bool TestMessageBoxDialog::Create()
2973 {
2974 wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
2975
2976 // this sizer allows to configure the messages shown in the message box
2977 wxSizer * const
2978 sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages");
2979 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Title:"));
2980 m_textTitle = new wxTextCtrl(this, wxID_ANY, "Test Message Box");
2981 sizerMsgs->Add(m_textTitle, wxSizerFlags().Expand().Border(wxBOTTOM));
2982
2983 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:"));
2984 m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!",
2985 wxDefaultPosition, wxDefaultSize,
2986 wxTE_MULTILINE);
2987 sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM));
2988
2989 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:"));
2990 m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "",
2991 wxDefaultPosition, wxDefaultSize,
2992 wxTE_MULTILINE);
2993 sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand());
2994
2995 sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
2996
2997 // if a derived class provides more message configurations, add these.
2998 AddAdditionalTextOptions(sizerTop);
2999
3000 // this one is for configuring the buttons
3001 wxSizer * const
3002 sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons");
3003
3004 wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5);
3005 sizerBtns->AddGrowableCol(1);
3006
3007 sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)"));
3008 sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label"));
3009
3010 for ( int n = 0; n < Btn_Max; n++ )
3011 {
3012 m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name);
3013 sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left());
3014
3015 m_labels[n] = new wxTextCtrl(this, wxID_ANY);
3016 sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand());
3017
3018 m_labels[n]->Connect(wxEVT_UPDATE_UI,
3019 wxUpdateUIEventHandler(
3020 TestMessageBoxDialog::OnUpdateLabelUI),
3021 NULL,
3022 this);
3023 }
3024
3025 sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand());
3026 sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border());
3027
3028
3029 // icon choice
3030 const wxString icons[] =
3031 {
3032 "&Not specified",
3033 "E&xplicitly none",
3034 "&Information icon",
3035 "&Question icon",
3036 "&Warning icon",
3037 "&Error icon",
3038 "A&uth needed icon"
3039 };
3040
3041 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == MsgDlgIcon_Max, IconMismatch );
3042
3043 m_icons = new wxRadioBox(this, wxID_ANY, "&Icon style",
3044 wxDefaultPosition, wxDefaultSize,
3045 WXSIZEOF(icons), icons,
3046 2, wxRA_SPECIFY_ROWS);
3047 // Make the 'Information' icon the default one:
3048 m_icons->SetSelection(MsgDlgIcon_Info);
3049 sizerTop->Add(m_icons, wxSizerFlags().Expand().Border());
3050
3051
3052 // miscellaneous other stuff
3053 wxSizer * const
3054 sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags");
3055
3056 m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default");
3057 m_chkNoDefault->Connect(wxEVT_UPDATE_UI,
3058 wxUpdateUIEventHandler(
3059 TestMessageBoxDialog::OnUpdateNoDefaultUI),
3060 NULL,
3061 this);
3062 sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border());
3063
3064 m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent");
3065 sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border());
3066
3067 // add any additional flag from subclasses
3068 AddAdditionalFlags(sizerFlags);
3069
3070 sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border());
3071
3072 // finally buttons to show the resulting message box and close this dialog
3073 sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE),
3074 wxSizerFlags().Right().Border());
3075
3076 SetSizerAndFit(sizerTop);
3077
3078 m_buttons[Btn_Ok]->SetValue(true);
3079
3080 return true;
3081 }
3082
3083 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event)
3084 {
3085 for ( int n = 0; n < Btn_Max; n++ )
3086 {
3087 if ( event.GetEventObject() == m_labels[n] )
3088 {
3089 event.Enable( m_buttons[n]->IsChecked() );
3090 return;
3091 }
3092 }
3093
3094 wxFAIL_MSG( "called for unknown label" );
3095 }
3096
3097 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event)
3098 {
3099 event.Enable( m_buttons[Btn_No]->IsChecked() );
3100 }
3101
3102 long TestMessageBoxDialog::GetStyle()
3103 {
3104 long style = 0;
3105
3106 for ( int n = 0; n < Btn_Max; n++ )
3107 {
3108 if ( m_buttons[n]->IsChecked() )
3109 style |= ms_btnInfo[n].flag;
3110 }
3111
3112 switch ( m_icons->GetSelection() )
3113 {
3114 case MsgDlgIcon_Max:
3115 wxFAIL_MSG( "unexpected selection" );
3116
3117 case MsgDlgIcon_No:
3118 break;
3119
3120 case MsgDlgIcon_None:
3121 style |= wxICON_NONE;
3122 break;
3123
3124 case MsgDlgIcon_Info:
3125 style |= wxICON_INFORMATION;
3126 break;
3127
3128 case MsgDlgIcon_Question:
3129 style |= wxICON_QUESTION;
3130 break;
3131
3132 case MsgDlgIcon_Warning:
3133 style |= wxICON_WARNING;
3134 break;
3135
3136 case MsgDlgIcon_Error:
3137 style |= wxICON_ERROR;
3138 break;
3139
3140 case MsgDlgIcon_AuthNeeded:
3141 style |= wxICON_AUTH_NEEDED;
3142 break;
3143 }
3144
3145 if ( m_chkCentre->IsChecked() )
3146 style |= wxCENTRE;
3147
3148 if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() )
3149 style |= wxNO_DEFAULT;
3150
3151 return style;
3152 }
3153
3154 void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase &dlg)
3155 {
3156 long style = dlg.GetMessageDialogStyle();
3157
3158 if ( !m_textExtMsg->IsEmpty() )
3159 dlg.SetExtendedMessage(m_textExtMsg->GetValue());
3160
3161 if ( style & wxYES_NO )
3162 {
3163 if ( style & wxCANCEL )
3164 {
3165 dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(),
3166 m_labels[Btn_No]->GetValue(),
3167 m_labels[Btn_Cancel]->GetValue());
3168 }
3169 else
3170 {
3171 dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(),
3172 m_labels[Btn_No]->GetValue());
3173 }
3174 }
3175 else
3176 {
3177 if ( style & wxCANCEL )
3178 {
3179 dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(),
3180 m_labels[Btn_Cancel]->GetValue());
3181 }
3182 else
3183 {
3184 dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue());
3185 }
3186 }
3187
3188 if ( style & wxHELP )
3189 {
3190 dlg.SetHelpLabel(m_labels[Btn_Help]->GetValue());
3191 }
3192 }
3193
3194 void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
3195 {
3196 wxMessageDialog dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3197 PrepareMessageDialog(dlg);
3198
3199 wxString btnName;
3200 switch ( dlg.ShowModal() )
3201 {
3202 case wxID_OK:
3203 btnName = "OK";
3204 break;
3205
3206 case wxID_CANCEL:
3207 // Avoid the extra message box if the dialog was cancelled.
3208 return;
3209
3210 case wxID_YES:
3211 btnName = "Yes";
3212 break;
3213
3214 case wxID_NO:
3215 btnName = "No";
3216 break;
3217
3218 case wxID_HELP:
3219 btnName = "Help";
3220 break;
3221
3222 default:
3223 btnName = "Unknown";
3224 }
3225
3226 wxLogMessage("Dialog was closed with the \"%s\" button.", btnName);
3227 }
3228
3229 void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event))
3230 {
3231 EndModal(wxID_CANCEL);
3232 }
3233 #endif // wxUSE_MSGDLG
3234
3235 #if wxUSE_RICHMSGDLG
3236 // ----------------------------------------------------------------------------
3237 // TestRichMessageDialog
3238 // ----------------------------------------------------------------------------
3239
3240 BEGIN_EVENT_TABLE(TestRichMessageDialog, TestMessageBoxDialog)
3241 EVT_BUTTON(wxID_APPLY, TestRichMessageDialog::OnApply)
3242 END_EVENT_TABLE()
3243
3244 TestRichMessageDialog::TestRichMessageDialog(wxWindow *parent)
3245 : TestMessageBoxDialog(parent)
3246 {
3247 SetTitle("Rich Message Dialog Test Dialog");
3248 }
3249
3250 void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer *sizer)
3251 {
3252 wxSizer * const sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this,
3253 "&Additional Elements");
3254
3255 // add a option to show a check box.
3256 wxFlexGridSizer * const sizerCheckBox = new wxFlexGridSizer(2, 5, 5);
3257 sizerCheckBox->AddGrowableCol(1);
3258 sizerCheckBox->Add(new wxStaticText(this, wxID_ANY, "&Check box:"));
3259 m_textCheckBox = new wxTextCtrl(this, wxID_ANY);
3260 sizerCheckBox->Add(m_textCheckBox, wxSizerFlags(1).Expand().Border(wxBOTTOM));
3261 sizerMsgs->Add(sizerCheckBox, wxSizerFlags(1).Expand());
3262
3263 // add option to show a detailed text.
3264 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Detailed message:"));
3265 m_textDetailed = new wxTextCtrl(this, wxID_ANY, "",
3266 wxDefaultPosition, wxDefaultSize,
3267 wxTE_MULTILINE);
3268 sizerMsgs->Add(m_textDetailed, wxSizerFlags(1).Expand());
3269
3270 sizer->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
3271 }
3272
3273 void TestRichMessageDialog::AddAdditionalFlags(wxSizer *sizer)
3274 {
3275 // add checkbox to set the initial state for the checkbox shown
3276 // in the dialog.
3277 m_initialValueCheckBox =
3278 new wxCheckBox(this, wxID_ANY, "Checkbox initially checked");
3279 sizer->Add(m_initialValueCheckBox, wxSizerFlags(1).Border());
3280 }
3281
3282 void TestRichMessageDialog::OnApply(wxCommandEvent& WXUNUSED(event))
3283 {
3284 wxRichMessageDialog dlg(this, GetMessage(), GetBoxTitle(), GetStyle());
3285 PrepareMessageDialog(dlg);
3286
3287 dlg.ShowCheckBox(m_textCheckBox->GetValue(),
3288 m_initialValueCheckBox->GetValue());
3289 dlg.ShowDetailedText(m_textDetailed->GetValue());
3290
3291 dlg.ShowModal();
3292 }
3293
3294 #endif // wxUSE_RICHMSGDLG
3295
3296 #if wxUSE_LOG
3297
3298 // ----------------------------------------------------------------------------
3299 // custom log target
3300 // ----------------------------------------------------------------------------
3301
3302 class MyLogGui : public wxLogGui
3303 {
3304 private:
3305 virtual void DoShowSingleLogMessage(const wxString& message,
3306 const wxString& title,
3307 int style)
3308 {
3309 wxMessageDialog dlg(NULL, message, title,
3310 wxOK | wxCANCEL | wxCANCEL_DEFAULT | style);
3311 dlg.SetOKCancelLabels(wxID_COPY, wxID_OK);
3312 dlg.SetExtendedMessage("Note that this is a custom log dialog.");
3313 dlg.ShowModal();
3314 }
3315 };
3316
3317 wxLog *MyAppTraits::CreateLogTarget()
3318 {
3319 return new MyLogGui;
3320 }
3321
3322 #endif // wxUSE_LOG