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