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