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