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