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