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