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