Build fix.
[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
31 #if wxUSE_COLOURDLG
32 #include "wx/colordlg.h"
33 #endif // wxUSE_COLOURDLG
34
35 #if wxUSE_CHOICEDLG
36 #include "wx/choicdlg.h"
37 #endif // wxUSE_CHOICEDLG
38
39 #if wxUSE_STARTUP_TIPS
40 #include "wx/tipdlg.h"
41 #endif // wxUSE_STARTUP_TIPS
42
43 #if wxUSE_PROGRESSDLG
44 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
45 #include "wx/datetime.h" // wxDateTime
46 #endif
47
48 #include "wx/progdlg.h"
49 #endif // wxUSE_PROGRESSDLG
50
51 #if wxUSE_BUSYINFO
52 #include "wx/busyinfo.h"
53 #endif // wxUSE_BUSYINFO
54
55 #if wxUSE_NUMBERDLG
56 #include "wx/numdlg.h"
57 #endif // wxUSE_NUMBERDLG
58
59 #if wxUSE_FILEDLG
60 #include "wx/filedlg.h"
61 #endif // wxUSE_FILEDLG
62
63 #if wxUSE_DIRDLG
64 #include "wx/dirdlg.h"
65 #endif // wxUSE_DIRDLG
66
67 #if wxUSE_FONTDLG
68 #include "wx/fontdlg.h"
69 #endif // wxUSE_FONTDLG
70
71 #if wxUSE_FINDREPLDLG
72 #include "wx/fdrepdlg.h"
73 #endif // wxUSE_FINDREPLDLG
74
75 #if wxUSE_SPINCTRL
76 #include "wx/spinctrl.h"
77 #endif
78
79 #include "wx/propdlg.h"
80
81 #include "dialogs.h"
82
83 #if USE_COLOURDLG_GENERIC
84 #include "wx/generic/colrdlgg.h"
85 #endif // USE_COLOURDLG_GENERIC
86
87 #if USE_DIRDLG_GENERIC
88 #include "wx/generic/dirdlgg.h"
89 #endif // USE_DIRDLG_GENERIC
90
91 #if USE_FILEDLG_GENERIC
92 #include "wx/generic/filedlgg.h"
93 #endif // USE_FILEDLG_GENERIC
94
95 #if USE_FONTDLG_GENERIC
96 #include "wx/generic/fontdlgg.h"
97 #endif // USE_FONTDLG_GENERIC
98
99 IMPLEMENT_APP(MyApp)
100
101 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
102 EVT_PAINT(MyCanvas::OnPaint)
103 END_EVENT_TABLE()
104
105
106
107 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
108 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
109
110 #if wxUSE_COLOURDLG
111 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
112 #endif // wxUSE_COLOURDLG
113
114 #if wxUSE_FONTDLG
115 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
116 #endif // wxUSE_FONTDLG
117
118 #if wxUSE_LOG_DIALOG
119 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
120 #endif // wxUSE_LOG_DIALOG
121
122 #if wxUSE_TEXTDLG
123 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
124 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
125 #endif // wxUSE_TEXTDLG
126
127 #if wxUSE_NUMBERDLG
128 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
129 #endif // wxUSE_NUMBERDLG
130
131 #if wxUSE_CHOICEDLG
132 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
133 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
134 #endif // wxUSE_CHOICEDLG
135
136 #if wxUSE_FILEDLG
137 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
138 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
139 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
140 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
141 #endif // wxUSE_FILEDLG
142
143 #if USE_FILEDLG_GENERIC
144 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric)
145 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric)
146 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric)
147 #endif // USE_FILEDLG_GENERIC
148
149 #if wxUSE_DIRDLG
150 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
151 EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
152 #endif // wxUSE_DIRDLG
153
154 #if USE_MODAL_PRESENTATION
155 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
156 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
157 #endif // USE_MODAL
158
159 #if wxUSE_STARTUP_TIPS
160 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
161 #endif // wxUSE_STARTUP_TIPS
162
163 #if USE_FONTDLG_GENERIC
164 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
165 #endif // USE_FONTDLG_GENERIC
166
167 #if USE_DIRDLG_GENERIC
168 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
169 #endif // wxMSW || wxMAC
170
171 #if USE_COLOURDLG_GENERIC
172 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
173 #endif // USE_COLOURDLG_GENERIC
174
175 #if wxUSE_PROGRESSDLG
176 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
177 #endif // wxUSE_PROGRESSDLG
178
179 #if wxUSE_BUSYINFO
180 EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
181 #endif // wxUSE_BUSYINFO
182
183 #if wxUSE_FINDREPLDLG
184 EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
185 EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
186
187 EVT_FIND(wxID_ANY, MyFrame::OnFindDialog)
188 EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog)
189 EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog)
190 EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog)
191 EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
192 #endif // wxUSE_FINDREPLDLG
193
194 #if USE_SETTINGS_DIALOG
195 EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet)
196 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheetToolBook)
197 #endif
198
199 EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
200
201 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
202 END_EVENT_TABLE()
203
204 #if USE_MODAL_PRESENTATION
205
206 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
207 EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
208 END_EVENT_TABLE()
209
210 BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
211 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
212 EVT_CLOSE(MyModelessDialog::OnClose)
213 END_EVENT_TABLE()
214
215 #endif // USE_MODAL_PRESENTATION
216
217 MyCanvas *myCanvas = (MyCanvas *) NULL;
218
219 // `Main program' equivalent, creating windows and returning main app frame
220 bool MyApp::OnInit()
221 {
222 #if wxUSE_IMAGE
223 wxInitAllImageHandlers();
224 #endif
225
226 m_canvasTextColour = wxColour(_T("BLACK"));
227 m_canvasFont = *wxNORMAL_FONT;
228
229 // Create the main frame window
230 MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example"));
231
232 // Make a menubar
233 wxMenu *file_menu = new wxMenu;
234
235 file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
236
237
238 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
239
240 wxMenu *choices_menu = new wxMenu;
241
242 #if wxUSE_COLOURDLG
243 choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour"));
244 #endif // wxUSE_COLOURDLG
245
246 #if wxUSE_FONTDLG
247 choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
248 #endif // wxUSE_FONTDLG
249
250 #if wxUSE_CHOICEDLG
251 choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C"));
252 choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U"));
253 #endif // wxUSE_CHOICEDLG
254
255 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
256 choices_menu->AppendSeparator();
257 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
258
259 #if USE_COLOURDLG_GENERIC
260 choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)"));
261 #endif // USE_COLOURDLG_GENERIC
262
263 #if USE_FONTDLG_GENERIC
264 choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)"));
265 #endif // USE_FONTDLG_GENERIC
266
267 file_menu->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu);
268 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
269
270
271 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
272
273 wxMenu *entry_menu = new wxMenu;
274
275 #if wxUSE_TEXTDLG
276 entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E"));
277 entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P"));
278 #endif // wxUSE_TEXTDLG
279
280 #if wxUSE_NUMBERDLG
281 entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N"));
282 #endif // wxUSE_NUMBERDLG
283
284 file_menu->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu);
285
286 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
287
288
289 #if wxUSE_FILEDLG
290
291 wxMenu *filedlg_menu = new wxMenu;
292 filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O"));
293 filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2"));
294 filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
295 filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
296
297 #if USE_FILEDLG_GENERIC
298 filedlg_menu->AppendSeparator();
299 filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)"));
300 filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)"));
301 filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)"));
302 #endif // USE_FILEDLG_GENERIC
303
304 file_menu->Append(wxID_ANY,_T("&File operations"),filedlg_menu);
305
306 #endif // wxUSE_FILEDLG
307
308 #if wxUSE_DIRDLG
309 wxMenu *dir_menu = new wxMenu;
310
311 dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D"));
312 dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
313 file_menu->Append(wxID_ANY,_T("&Directory operations"),dir_menu);
314
315 #if USE_DIRDLG_GENERIC
316 dir_menu->AppendSeparator();
317 dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)"));
318 #endif // USE_DIRDLG_GENERIC
319
320 #endif // wxUSE_DIRDLG
321
322
323 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
324
325 wxMenu *info_menu = new wxMenu;
326
327 #if wxUSE_STARTUP_TIPS
328 info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T"));
329 #endif // wxUSE_STARTUP_TIPS
330
331 #if wxUSE_PROGRESSDLG
332 info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G"));
333 #endif // wxUSE_PROGRESSDLG
334
335 #if wxUSE_BUSYINFO
336 info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B"));
337 #endif // wxUSE_BUSYINFO
338
339 #if wxUSE_LOG_DIALOG
340 info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L"));
341 #endif // wxUSE_LOG_DIALOG
342
343 file_menu->Append(wxID_ANY,_T("&Informative dialogs"),info_menu);
344
345 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
346
347
348 #if wxUSE_FINDREPLDLG
349 wxMenu *find_menu = new wxMenu;
350 find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"));
351 find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"));
352 file_menu->Append(wxID_ANY,_T("&Searching"),find_menu);
353 #endif // wxUSE_FINDREPLDLG
354
355 #if USE_MODAL_PRESENTATION
356 wxMenu *modal_menu = new wxMenu;
357 modal_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W"));
358 modal_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"));
359 file_menu->Append(wxID_ANY,_T("&Modal/Modeless"),modal_menu);
360 #endif // USE_MODAL_PRESENTATION
361
362 #if USE_SETTINGS_DIALOG
363 file_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Property Sheet Dialog\tCtrl-P"));
364 file_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, _T("Property Sheet Dialog using &ToolBook"));
365 #endif
366
367 file_menu->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R"));
368
369 file_menu->AppendSeparator();
370 file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
371
372 wxMenuBar *menu_bar = new wxMenuBar;
373 menu_bar->Append(file_menu, _T("&File"));
374 frame->SetMenuBar(menu_bar);
375
376 myCanvas = new MyCanvas(frame);
377 myCanvas->SetBackgroundColour(*wxWHITE);
378
379 frame->Centre(wxBOTH);
380
381 // Show the frame
382 frame->Show(true);
383
384 SetTopWindow(frame);
385
386 return true;
387 }
388
389 // My frame constructor
390 MyFrame::MyFrame(wxWindow *parent,
391 const wxString& title)
392 : wxFrame(parent, wxID_ANY, title)
393 {
394 SetIcon(sample_xpm);
395
396 #if USE_MODAL_PRESENTATION
397 m_dialog = (MyModelessDialog *)NULL;
398 #endif // USE_MODAL_PRESENTATION
399
400 #if wxUSE_FINDREPLDLG
401 m_dlgFind =
402 m_dlgReplace = NULL;
403 #endif
404
405 #if wxUSE_COLOURDLG
406 m_clrData.SetChooseFull(true);
407 for (int i = 0; i < 16; i++)
408 {
409 m_clrData.SetCustomColour(
410 i,
411 wxColour(
412 (unsigned char)(i*16),
413 (unsigned char)(i*16),
414 (unsigned char)(i*16)
415 )
416 );
417 }
418 #endif // wxUSE_COLOURDLG
419 }
420
421 #if wxUSE_COLOURDLG
422 void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
423 {
424 m_clrData.SetColour(myCanvas->GetBackgroundColour());
425
426 wxColourDialog dialog(this, &m_clrData);
427 dialog.SetTitle(_T("Choose the background colour"));
428 if (dialog.ShowModal() == wxID_OK)
429 {
430 m_clrData = dialog.GetColourData();
431 myCanvas->SetBackgroundColour(m_clrData.GetColour());
432 myCanvas->ClearBackground();
433 myCanvas->Refresh();
434 }
435 }
436 #endif // wxUSE_COLOURDLG
437
438 #if USE_COLOURDLG_GENERIC
439 void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
440 {
441 m_clrData.SetColour(myCanvas->GetBackgroundColour());
442
443 //FIXME:TODO:This has no effect...
444 m_clrData.SetChooseFull(true);
445
446 for (int i = 0; i < 16; i++)
447 {
448 wxColour colour(
449 (unsigned char)(i*16),
450 (unsigned char)(i*16),
451 (unsigned char)(i*16)
452 );
453 m_clrData.SetCustomColour(i, colour);
454 }
455
456 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);
457 if (dialog->ShowModal() == wxID_OK)
458 {
459 m_clrData = dialog->GetColourData();
460 myCanvas->SetBackgroundColour(m_clrData.GetColour());
461 myCanvas->ClearBackground();
462 myCanvas->Refresh();
463 }
464 dialog->Destroy();
465 }
466 #endif // USE_COLOURDLG_GENERIC
467
468 #if wxUSE_FONTDLG
469 void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
470 {
471 wxFontData data;
472 data.SetInitialFont(wxGetApp().m_canvasFont);
473 data.SetColour(wxGetApp().m_canvasTextColour);
474
475 // you might also do this:
476 //
477 // wxFontDialog dialog;
478 // if ( !dialog.Create(this, data) { ... error ... }
479 //
480 wxFontDialog dialog(this, data);
481
482 if (dialog.ShowModal() == wxID_OK)
483 {
484 wxFontData retData = dialog.GetFontData();
485 wxGetApp().m_canvasFont = retData.GetChosenFont();
486 wxGetApp().m_canvasTextColour = retData.GetColour();
487 myCanvas->Refresh();
488 }
489 //else: cancelled by the user, don't change the font
490 }
491 #endif // wxUSE_FONTDLG
492
493 #if USE_FONTDLG_GENERIC
494 void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
495 {
496 wxFontData data;
497 data.SetInitialFont(wxGetApp().m_canvasFont);
498 data.SetColour(wxGetApp().m_canvasTextColour);
499
500 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data);
501 if (dialog->ShowModal() == wxID_OK)
502 {
503 wxFontData retData = dialog->GetFontData();
504 wxGetApp().m_canvasFont = retData.GetChosenFont();
505 wxGetApp().m_canvasTextColour = retData.GetColour();
506 myCanvas->Refresh();
507 }
508 dialog->Destroy();
509 }
510 #endif // USE_FONTDLG_GENERIC
511
512 #if wxUSE_LOG_DIALOG
513 void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
514 {
515 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
516 // being flushed -- test it
517 {
518 wxBusyCursor bc;
519 wxLogMessage(wxT("This is some message - everything is ok so far."));
520 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
521 wxLogWarning(wxT("And then something went wrong!"));
522
523 // and if ~wxBusyCursor doesn't do it, then call it manually
524 wxYield();
525 }
526
527 wxLogError(wxT("Intermediary error handler decided to abort."));
528 wxLogError(wxT("The top level caller detected an unrecoverable error."));
529
530 wxLog::FlushActive();
531
532 wxLogMessage(wxT("And this is the same dialog but with only one message."));
533 }
534 #endif // wxUSE_LOG_DIALOG
535
536 void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
537 {
538 wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"),
539 _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION);
540
541 switch ( dialog.ShowModal() )
542 {
543 case wxID_YES:
544 wxLogStatus(wxT("You pressed \"Yes\""));
545 break;
546
547 case wxID_NO:
548 wxLogStatus(wxT("You pressed \"No\""));
549 break;
550
551 case wxID_CANCEL:
552 wxLogStatus(wxT("You pressed \"Cancel\""));
553 break;
554
555 default:
556 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
557 }
558 }
559
560 #if wxUSE_NUMBERDLG
561 void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
562 {
563 long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
564 _T("Even two rows of text."),
565 _T("Enter a number:"), _T("Numeric input test"),
566 50, 0, 100, this );
567
568 wxString msg;
569 int icon;
570 if ( res == -1 )
571 {
572 msg = _T("Invalid number entered or dialog cancelled.");
573 icon = wxICON_HAND;
574 }
575 else
576 {
577 msg.Printf(_T("You've entered %lu"), res );
578 icon = wxICON_INFORMATION;
579 }
580
581 wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this);
582 }
583 #endif // wxUSE_NUMBERDLG
584
585 #if wxUSE_TEXTDLG
586 void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
587 {
588 wxString pwd = wxGetPasswordFromUser(_T("Enter password:"),
589 _T("Password entry dialog"),
590 wxEmptyString,
591 this);
592 if ( !pwd.empty() )
593 {
594 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
595 _T("Got password"), wxOK | wxICON_INFORMATION, this);
596 }
597 }
598
599 void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
600 {
601 wxTextEntryDialog dialog(this,
602 _T("This is a small sample\n")
603 _T("A long, long string to test out the text entrybox"),
604 _T("Please enter a string"),
605 _T("Default value"),
606 wxOK | wxCANCEL);
607
608 if (dialog.ShowModal() == wxID_OK)
609 {
610 wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this);
611 }
612 }
613 #endif // wxUSE_TEXTDLG
614
615 #if wxUSE_CHOICEDLG
616 void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
617 {
618 const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
619
620 wxSingleChoiceDialog dialog(this,
621 _T("This is a small sample\n")
622 _T("A single-choice convenience dialog"),
623 _T("Please select a value"),
624 WXSIZEOF(choices), choices);
625
626 dialog.SetSelection(2);
627
628 if (dialog.ShowModal() == wxID_OK)
629 {
630 wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string"));
631 dialog2.ShowModal();
632 }
633 }
634
635 void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
636 {
637 const wxString choices[] =
638 {
639 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
640 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
641 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
642 };
643
644 wxArrayInt selections;
645 size_t count = wxGetMultipleChoices(selections,
646 _T("This is a small sample\n")
647 _T("A multi-choice convenience dialog"),
648 _T("Please select a value"),
649 WXSIZEOF(choices), choices,
650 this);
651 if ( count )
652 {
653 wxString msg;
654 msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
655 for ( size_t n = 0; n < count; n++ )
656 {
657 msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
658 (unsigned)n, (unsigned)selections[n],
659 choices[selections[n]].c_str());
660 }
661 wxLogMessage(msg);
662 }
663 //else: cancelled or nothing selected
664 }
665 #endif // wxUSE_CHOICEDLG
666
667 #if wxUSE_FILEDLG
668 void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
669 {
670 wxFileDialog dialog
671 (
672 this,
673 _T("Testing open file dialog"),
674 wxEmptyString,
675 wxEmptyString,
676 #ifdef __WXMOTIF__
677 _T("C++ files (*.cpp)|*.cpp")
678 #else
679 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
680 #endif
681 );
682
683 dialog.SetDirectory(wxGetHomeDir());
684 dialog.CentreOnParent();
685
686 if (dialog.ShowModal() == wxID_OK)
687 {
688 wxString info;
689 info.Printf(_T("Full file name: %s\n")
690 _T("Path: %s\n")
691 _T("Name: %s"),
692 dialog.GetPath().c_str(),
693 dialog.GetDirectory().c_str(),
694 dialog.GetFilename().c_str());
695 wxMessageDialog dialog2(this, info, _T("Selected file"));
696 dialog2.ShowModal();
697 }
698 }
699
700 // this shows how to take advantage of specifying a default extension in the
701 // call to wxFileSelector: it is remembered after each new call and the next
702 // one will use it by default
703 void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
704 {
705 static wxString s_extDef;
706 wxString path = wxFileSelector(
707 _T("Select the file to load"),
708 wxEmptyString, wxEmptyString,
709 s_extDef,
710 wxString::Format
711 (
712 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
713 wxFileSelectorDefaultWildcardStr,
714 wxFileSelectorDefaultWildcardStr
715 ),
716 wxCHANGE_DIR,
717 this
718 );
719
720 if ( !path )
721 return;
722
723 // it is just a sample, would use wxSplitPath in real program
724 s_extDef = path.AfterLast(_T('.'));
725
726 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
727 (const wxChar*) path, (const wxChar*) s_extDef);
728 }
729
730 void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
731 {
732 wxString wildcards =
733 #ifdef __WXMOTIF__
734 _T("C++ files (*.cpp)|*.cpp");
735 #else
736 wxString::Format
737 (
738 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
739 wxFileSelectorDefaultWildcardStr,
740 wxFileSelectorDefaultWildcardStr
741 );
742 #endif
743 wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
744 wxEmptyString, wxEmptyString, wildcards,
745 wxMULTIPLE);
746
747 if (dialog.ShowModal() == wxID_OK)
748 {
749 wxArrayString paths, filenames;
750
751 dialog.GetPaths(paths);
752 dialog.GetFilenames(filenames);
753
754 wxString msg, s;
755 size_t count = paths.GetCount();
756 for ( size_t n = 0; n < count; n++ )
757 {
758 s.Printf(_T("File %d: %s (%s)\n"),
759 (int)n, paths[n].c_str(), filenames[n].c_str());
760
761 msg += s;
762 }
763 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
764 msg += s;
765
766 wxMessageDialog dialog2(this, msg, _T("Selected files"));
767 dialog2.ShowModal();
768 }
769 }
770
771 void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
772 {
773 wxFileDialog dialog(this,
774 _T("Testing save file dialog"),
775 wxEmptyString,
776 _T("myletter.doc"),
777 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
778 wxSAVE|wxOVERWRITE_PROMPT);
779
780 dialog.SetFilterIndex(1);
781
782 if (dialog.ShowModal() == wxID_OK)
783 {
784 wxLogMessage(_T("%s, filter %d"),
785 dialog.GetPath().c_str(), dialog.GetFilterIndex());
786 }
787 }
788 #endif // wxUSE_FILEDLG
789
790 #if USE_FILEDLG_GENERIC
791 void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
792 {
793 wxGenericFileDialog dialog
794 (
795 this,
796 _T("Testing open file dialog"),
797 wxEmptyString,
798 wxEmptyString,
799 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
800 );
801
802 dialog.SetDirectory(wxGetHomeDir());
803
804 if (dialog.ShowModal() == wxID_OK)
805 {
806 wxString info;
807 info.Printf(_T("Full file name: %s\n")
808 _T("Path: %s\n")
809 _T("Name: %s"),
810 dialog.GetPath().c_str(),
811 dialog.GetDirectory().c_str(),
812 dialog.GetFilename().c_str());
813 wxMessageDialog dialog2(this, info, _T("Selected file"));
814 dialog2.ShowModal();
815 }
816 }
817
818 void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
819 {
820 wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
821 wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
822 wxEmptyString, wxEmptyString, wildcards,
823 wxMULTIPLE);
824
825 if (dialog.ShowModal() == wxID_OK)
826 {
827 wxArrayString paths, filenames;
828
829 dialog.GetPaths(paths);
830 dialog.GetFilenames(filenames);
831
832 wxString msg, s;
833 size_t count = paths.GetCount();
834 for ( size_t n = 0; n < count; n++ )
835 {
836 s.Printf(_T("File %d: %s (%s)\n"),
837 (int)n, paths[n].c_str(), filenames[n].c_str());
838
839 msg += s;
840 }
841 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
842 msg += s;
843
844 wxMessageDialog dialog2(this, msg, _T("Selected files"));
845 dialog2.ShowModal();
846 }
847 }
848
849 void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
850 {
851 wxGenericFileDialog dialog(this,
852 _T("Testing save file dialog"),
853 wxEmptyString,
854 _T("myletter.doc"),
855 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
856 wxSAVE|wxOVERWRITE_PROMPT);
857
858 dialog.SetFilterIndex(1);
859
860 if (dialog.ShowModal() == wxID_OK)
861 {
862 wxLogMessage(_T("%s, filter %d"),
863 dialog.GetPath().c_str(), dialog.GetFilterIndex());
864 }
865 }
866 #endif // USE_FILEDLG_GENERIC
867
868 #if wxUSE_DIRDLG
869 void MyFrame::DoDirChoose(int style)
870 {
871 // pass some initial dir to wxDirDialog
872 wxString dirHome;
873 wxGetHomeDir(&dirHome);
874
875 wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
876
877 if (dialog.ShowModal() == wxID_OK)
878 {
879 wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
880 }
881 }
882
883 void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
884 {
885 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON);
886 }
887
888 void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
889 {
890 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON);
891 }
892 #endif // wxUSE_DIRDLG
893
894 #if USE_DIRDLG_GENERIC
895 void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
896 {
897 // pass some initial dir to wxDirDialog
898 wxString dirHome;
899 wxGetHomeDir(&dirHome);
900
901 wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
902
903 if (dialog.ShowModal() == wxID_OK)
904 {
905 wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
906 dialog2.ShowModal();
907 }
908 }
909 #endif // USE_DIRDLG_GENERIC
910
911 #if USE_MODAL_PRESENTATION
912 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
913 {
914 MyModalDialog dlg(this);
915 dlg.ShowModal();
916 }
917
918 void MyFrame::ModelessDlg(wxCommandEvent& event)
919 {
920 bool show = GetMenuBar()->IsChecked(event.GetId());
921
922 if ( show )
923 {
924 if ( !m_dialog )
925 {
926 m_dialog = new MyModelessDialog(this);
927 }
928
929 m_dialog->Show(true);
930 }
931 else // hide
932 {
933 // If m_dialog is NULL, then possibly the system
934 // didn't report the checked menu item status correctly.
935 // It should be true just after the menu item was selected,
936 // if there was no modeless dialog yet.
937
938 wxASSERT( m_dialog != NULL );
939 if (m_dialog)
940 m_dialog->Hide();
941 }
942 }
943 #endif // USE_MODAL_PRESENTATION
944
945 #if wxUSE_STARTUP_TIPS
946 void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
947 {
948 static size_t s_index = (size_t)-1;
949
950 if ( s_index == (size_t)-1 )
951 {
952 srand(time(NULL));
953
954 // this is completely bogus, we don't know how many lines are there
955 // in the file, but who cares, it's a demo only...
956 s_index = rand() % 5;
957 }
958
959 wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
960
961 bool showAtStartup = wxShowTip(this, tipProvider);
962
963 if ( showAtStartup )
964 {
965 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
966 wxOK | wxICON_INFORMATION, this);
967 }
968
969 s_index = tipProvider->GetCurrentTip();
970 delete tipProvider;
971 }
972 #endif // wxUSE_STARTUP_TIPS
973
974 #if USE_SETTINGS_DIALOG
975 void MyFrame::OnPropertySheet(wxCommandEvent& WXUNUSED(event))
976 {
977 SettingsDialog dialog(this);
978 dialog.ShowModal();
979 }
980
981 void MyFrame::OnPropertySheetToolBook(wxCommandEvent& WXUNUSED(event))
982 {
983 SettingsDialog dialog(this, true);
984 dialog.ShowModal();
985 }
986 #endif // USE_SETTINGS_DIALOG
987
988 void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
989 {
990 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
991
992 wxSleep(3);
993
994 RequestUserAttention(wxUSER_ATTENTION_ERROR);
995 }
996
997 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
998 {
999 Close(true);
1000 }
1001
1002 #if wxUSE_PROGRESSDLG
1003
1004 void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
1005 {
1006 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1007 // check the performance
1008 int countrandomnumbers = 0, count = 0;
1009 wxTimeSpan tsTest(0,0,0,250);
1010 wxDateTime DT2, DT1 = wxDateTime::UNow();
1011 srand(0);
1012 while(1)
1013 {
1014 rand();
1015 ++countrandomnumbers;
1016 if ( countrandomnumbers == 1000 )
1017 {
1018 srand(0);
1019 countrandomnumbers = 0;
1020 ++count;
1021 DT2 = wxDateTime::UNow();
1022 wxTimeSpan ts = DT2.Subtract( DT1 );
1023 if ( ts.IsLongerThan( tsTest ) )
1024 {
1025 break;
1026 }
1027 }
1028 }
1029 const int max = 40 * count;
1030 #else
1031 static const int max = 10;
1032 #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG
1033
1034 wxProgressDialog dialog(_T("Progress dialog example"),
1035 _T("An informative message"),
1036 max, // range
1037 this, // parent
1038 wxPD_CAN_ABORT |
1039 wxPD_CAN_SKIP |
1040 wxPD_APP_MODAL |
1041 // wxPD_AUTO_HIDE | -- try this as well
1042 wxPD_ELAPSED_TIME |
1043 wxPD_ESTIMATED_TIME |
1044 wxPD_REMAINING_TIME |
1045 wxPD_SMOOTH);
1046
1047 bool cont = true;
1048 bool skip = false;
1049 // each skip will move progress about quarter forward
1050 for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false )
1051 {
1052 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1053 // do (almost) the same operations as we did for the performance test
1054 srand(0);
1055 for ( int j = 0; j < 1000; j++ )
1056 {
1057 rand();
1058 if ( j == 999 )
1059 {
1060 DT2 = wxDateTime::UNow();
1061 wxTimeSpan ts = DT2.Subtract( DT1 );
1062 if ( ts.IsLongerThan( tsTest ) )
1063 {
1064 // nothing to do
1065 }
1066 }
1067 }
1068 #else
1069 wxSleep(1);
1070 #endif
1071
1072 wxString msg;
1073
1074 if ( i == max )
1075 {
1076 msg = _T("That's all, folks!");
1077 }
1078 else if ( i > max / 2 )
1079 {
1080 msg = _T("Only a half left (very long message)!");
1081 }
1082
1083 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1084 if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
1085 {
1086 cont = dialog.Update(i, msg, &skip);
1087 }
1088 #else
1089 cont = dialog.Update(i, msg, &skip);
1090 #endif
1091
1092 if ( !cont )
1093 {
1094 if ( wxMessageBox(_T("Do you really want to cancel?"),
1095 _T("Progress dialog question"), // caption
1096 wxYES_NO | wxICON_QUESTION) == wxYES )
1097 break;
1098
1099 cont = true;
1100 dialog.Resume();
1101 }
1102 }
1103
1104 if ( !cont )
1105 {
1106 wxLogStatus(wxT("Progress dialog aborted!"));
1107 }
1108 else
1109 {
1110 wxLogStatus(wxT("Countdown from %d finished"), max);
1111 }
1112 }
1113
1114 #endif // wxUSE_PROGRESSDLG
1115
1116 #if wxUSE_BUSYINFO
1117
1118 void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
1119 {
1120 wxWindowDisabler disableAll;
1121
1122 wxBusyInfo info(_T("Working, please wait..."), this);
1123
1124 for ( int i = 0; i < 18; i++ )
1125 {
1126 //wxUsleep(100);
1127 wxTheApp->Yield();
1128 }
1129
1130 wxSleep(2);
1131 //wxWakeUpIdle();
1132 }
1133
1134 #endif // wxUSE_BUSYINFO
1135
1136 #if wxUSE_FINDREPLDLG
1137
1138 void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
1139 {
1140 if ( m_dlgReplace )
1141 {
1142 delete m_dlgReplace;
1143 m_dlgReplace = NULL;
1144 }
1145 else
1146 {
1147 m_dlgReplace = new wxFindReplaceDialog
1148 (
1149 this,
1150 &m_findData,
1151 _T("Find and replace dialog"),
1152 wxFR_REPLACEDIALOG
1153 );
1154
1155 m_dlgReplace->Show(true);
1156 }
1157 }
1158
1159 void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
1160 {
1161 if ( m_dlgFind )
1162 {
1163 delete m_dlgFind;
1164 m_dlgFind = NULL;
1165 }
1166 else
1167 {
1168 m_dlgFind = new wxFindReplaceDialog
1169 (
1170 this,
1171 &m_findData,
1172 _T("Find dialog"),
1173 // just for testing
1174 wxFR_NOWHOLEWORD
1175 );
1176
1177 m_dlgFind->Show(true);
1178 }
1179 }
1180
1181 static wxString DecodeFindDialogEventFlags(int flags)
1182 {
1183 wxString str;
1184 str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
1185 << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
1186 << (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
1187 << _T("case sensitive");
1188
1189 return str;
1190 }
1191
1192 void MyFrame::OnFindDialog(wxFindDialogEvent& event)
1193 {
1194 wxEventType type = event.GetEventType();
1195
1196 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
1197 {
1198 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1199 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
1200 event.GetFindString().c_str(),
1201 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1202 }
1203 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
1204 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
1205 {
1206 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1207 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
1208 event.GetFindString().c_str(),
1209 event.GetReplaceString().c_str(),
1210 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1211 }
1212 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
1213 {
1214 wxFindReplaceDialog *dlg = event.GetDialog();
1215
1216 int idMenu;
1217 const wxChar *txt;
1218 if ( dlg == m_dlgFind )
1219 {
1220 txt = _T("Find");
1221 idMenu = DIALOGS_FIND;
1222 m_dlgFind = NULL;
1223 }
1224 else if ( dlg == m_dlgReplace )
1225 {
1226 txt = _T("Replace");
1227 idMenu = DIALOGS_REPLACE;
1228 m_dlgReplace = NULL;
1229 }
1230 else
1231 {
1232 txt = _T("Unknown");
1233 idMenu = wxID_ANY;
1234
1235 wxFAIL_MSG( _T("unexpected event") );
1236 }
1237
1238 wxLogMessage(wxT("%s dialog is being closed."), txt);
1239
1240 if ( idMenu != wxID_ANY )
1241 {
1242 GetMenuBar()->Check(idMenu, false);
1243 }
1244
1245 dlg->Destroy();
1246 }
1247 else
1248 {
1249 wxLogError(wxT("Unknown find dialog event!"));
1250 }
1251 }
1252
1253 #endif // wxUSE_FINDREPLDLG
1254
1255 // ----------------------------------------------------------------------------
1256 // MyCanvas
1257 // ----------------------------------------------------------------------------
1258
1259 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
1260 {
1261 wxPaintDC dc(this);
1262 dc.SetFont(wxGetApp().m_canvasFont);
1263 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
1264 dc.SetBackgroundMode(wxTRANSPARENT);
1265 dc.DrawText(
1266 _T("wxWidgets common dialogs")
1267 #if !defined(__SMARTPHONE__)
1268 _T(" test application")
1269 #endif
1270 , 10, 10);
1271 }
1272
1273 #if USE_MODAL_PRESENTATION
1274
1275 // ----------------------------------------------------------------------------
1276 // MyModelessDialog
1277 // ----------------------------------------------------------------------------
1278
1279 MyModelessDialog::MyModelessDialog(wxWindow *parent)
1280 : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog")))
1281 {
1282 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
1283
1284 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
1285 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled"));
1286 check->Disable();
1287
1288 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
1289 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
1290
1291 SetSizer(sizerTop);
1292
1293 sizerTop->SetSizeHints(this);
1294 sizerTop->Fit(this);
1295 }
1296
1297 void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
1298 {
1299 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1300 wxOK | wxICON_INFORMATION, this);
1301 }
1302
1303 void MyModelessDialog::OnClose(wxCloseEvent& event)
1304 {
1305 if ( event.CanVeto() )
1306 {
1307 wxMessageBox(_T("Use the menu item to close this dialog"),
1308 _T("Modeless dialog"),
1309 wxOK | wxICON_INFORMATION, this);
1310
1311 event.Veto();
1312 }
1313 }
1314
1315 // ----------------------------------------------------------------------------
1316 // MyModalDialog
1317 // ----------------------------------------------------------------------------
1318
1319 MyModalDialog::MyModalDialog(wxWindow *parent)
1320 : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog")))
1321 {
1322 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1323
1324 m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog..."));
1325 m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog"));
1326 m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button"));
1327
1328 wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
1329 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
1330 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
1331 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
1332 sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
1333
1334 SetSizer(sizerTop);
1335
1336 sizerTop->SetSizeHints(this);
1337 sizerTop->Fit(this);
1338
1339 m_btnModal->SetFocus();
1340 m_btnModal->SetDefault();
1341 }
1342
1343 void MyModalDialog::OnButton(wxCommandEvent& event)
1344 {
1345 if ( event.GetEventObject() == m_btnDelete )
1346 {
1347 delete m_btnModal;
1348 m_btnModal = NULL;
1349
1350 m_btnDelete->Disable();
1351 }
1352 else if ( event.GetEventObject() == m_btnModal )
1353 {
1354 #if wxUSE_TEXTDLG
1355 wxGetTextFromUser(_T("Dummy prompt"),
1356 _T("Modal dialog called from dialog"),
1357 wxEmptyString, this);
1358 #else
1359 wxMessageBox(_T("Modal dialog called from dialog"));
1360 #endif // wxUSE_TEXTDLG
1361 }
1362 else if ( event.GetEventObject() == m_btnModeless )
1363 {
1364 (new MyModelessDialog(this))->Show();
1365 }
1366 else
1367 {
1368 event.Skip();
1369 }
1370 }
1371
1372 #endif // USE_MODAL_PRESENTATION
1373
1374 #if USE_SETTINGS_DIALOG
1375 // ----------------------------------------------------------------------------
1376 // SettingsDialog
1377 // ----------------------------------------------------------------------------
1378
1379 IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
1380
1381 BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
1382 END_EVENT_TABLE()
1383
1384 SettingsDialog::SettingsDialog(wxWindow* win, bool useToolBook)
1385 {
1386 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
1387
1388 int tabImage1 = -1;
1389 int tabImage2 = -1;
1390
1391 if (useToolBook)
1392 {
1393 tabImage1 = 0;
1394 tabImage2 = 1;
1395 SetSheetStyle(wxPROPSHEET_TOOLBOOK|wxPROPSHEET_SHRINKTOFIT);
1396
1397 // create a dummy image list with a few icons
1398 const wxSize imageSize(32, 32);
1399
1400 m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
1401 m_imageList->
1402 Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
1403 m_imageList->
1404 Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize));
1405 m_imageList->
1406 Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize));
1407 m_imageList->
1408 Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize));
1409 }
1410 else
1411 m_imageList = NULL;
1412
1413 Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
1414 wxDEFAULT_DIALOG_STYLE
1415 #ifndef __WXWINCE__
1416 |wxRESIZE_BORDER
1417 #endif
1418 );
1419
1420 // If using a toolbook, also follow Mac style and don't create buttons
1421 if (!useToolBook)
1422 CreateButtons(wxOK|wxCANCEL
1423 #ifndef __POCKETPC__
1424 |wxHELP
1425 #endif
1426 );
1427
1428 wxBookCtrlBase* notebook = GetBookCtrl();
1429 notebook->SetImageList(m_imageList);
1430
1431 wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
1432 wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
1433
1434 notebook->AddPage(generalSettings, _("General"), true, tabImage1);
1435 notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2);
1436
1437 LayoutDialog();
1438 }
1439
1440 SettingsDialog::~SettingsDialog()
1441 {
1442 delete m_imageList;
1443 }
1444
1445 wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
1446 {
1447 wxPanel* panel = new wxPanel(parent, wxID_ANY);
1448
1449 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
1450 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1451
1452 //// LOAD LAST FILE
1453
1454 wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
1455 wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize);
1456 itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1457 item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
1458
1459 //// AUTOSAVE
1460
1461 wxString autoSaveLabel = _("&Auto-save every");
1462 wxString minsLabel = _("mins");
1463
1464 wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
1465 wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
1466
1467 #if wxUSE_SPINCTRL
1468 wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
1469 wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1);
1470 #endif
1471
1472 itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1473 #if wxUSE_SPINCTRL
1474 itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1475 #endif
1476 itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1477 item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
1478
1479 //// TOOLTIPS
1480
1481 wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
1482 wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize);
1483 itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1484 item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
1485
1486 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
1487
1488 panel->SetSizer(topSizer);
1489 topSizer->Fit(panel);
1490
1491 return panel;
1492 }
1493
1494 wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
1495 {
1496 wxPanel* panel = new wxPanel(parent, wxID_ANY);
1497
1498 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
1499 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1500
1501 //// PROJECT OR GLOBAL
1502 wxString globalOrProjectChoices[2];
1503 globalOrProjectChoices[0] = _("&New projects");
1504 globalOrProjectChoices[1] = _("&This project");
1505
1506 wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"),
1507 wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
1508 item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
1509
1510 projectOrGlobal->SetSelection(0);
1511
1512 //// BACKGROUND STYLE
1513 wxArrayString backgroundStyleChoices;
1514 backgroundStyleChoices.Add(wxT("Colour"));
1515 backgroundStyleChoices.Add(wxT("Image"));
1516 wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:"));
1517
1518 wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
1519 item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
1520
1521 wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
1522
1523 wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
1524
1525 itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1526 itemSizer2->Add(5, 5, 1, wxALL, 0);
1527 itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1528
1529 styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
1530
1531 #if wxUSE_SPINCTRL
1532 //// FONT SIZE SELECTION
1533
1534 wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:"));
1535 wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
1536
1537 wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition,
1538 wxSize(80, wxDefaultCoord));
1539 itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
1540
1541 item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
1542 #endif
1543
1544 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
1545 topSizer->AddSpacer(5);
1546
1547 panel->SetSizer(topSizer);
1548 topSizer->Fit(panel);
1549
1550 return panel;
1551 }
1552
1553 #endif // USE_SETTINGS_DIALOG