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