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