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