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