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