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