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