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