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