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