make wxRearrangeDialog more customizable and add an example of customizing it to...
[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/apptrait.h"
26 #include "wx/datetime.h"
27 #include "wx/image.h"
28 #include "wx/bookctrl.h"
29 #include "wx/artprov.h"
30 #include "wx/imaglist.h"
31 #include "wx/minifram.h"
32 #include "wx/sysopt.h"
33 #include "wx/notifmsg.h"
34
35 #if wxUSE_COLOURDLG
36 #include "wx/colordlg.h"
37 #endif // wxUSE_COLOURDLG
38
39 #if wxUSE_CHOICEDLG
40 #include "wx/choicdlg.h"
41 #endif // wxUSE_CHOICEDLG
42
43 #include "wx/rearrangectrl.h"
44
45 #if wxUSE_STARTUP_TIPS
46 #include "wx/tipdlg.h"
47 #endif // wxUSE_STARTUP_TIPS
48
49 #if wxUSE_PROGRESSDLG
50 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
51 #include "wx/datetime.h" // wxDateTime
52 #endif
53
54 #include "wx/progdlg.h"
55 #endif // wxUSE_PROGRESSDLG
56
57 #if wxUSE_ABOUTDLG
58 #include "wx/aboutdlg.h"
59
60 // these headers are only needed for custom about dialog
61 #include "wx/statline.h"
62 #include "wx/generic/aboutdlgg.h"
63 #endif // wxUSE_ABOUTDLG
64
65 #if wxUSE_BUSYINFO
66 #include "wx/busyinfo.h"
67 #endif // wxUSE_BUSYINFO
68
69 #if wxUSE_NUMBERDLG
70 #include "wx/numdlg.h"
71 #endif // wxUSE_NUMBERDLG
72
73 #if wxUSE_FILEDLG
74 #include "wx/filedlg.h"
75 #endif // wxUSE_FILEDLG
76
77 #if wxUSE_DIRDLG
78 #include "wx/dirdlg.h"
79 #endif // wxUSE_DIRDLG
80
81 #if wxUSE_FONTDLG
82 #include "wx/fontdlg.h"
83 #endif // wxUSE_FONTDLG
84
85 #if wxUSE_FINDREPLDLG
86 #include "wx/fdrepdlg.h"
87 #endif // wxUSE_FINDREPLDLG
88
89 #include "wx/spinctrl.h"
90 #include "wx/propdlg.h"
91
92 #include "dialogs.h"
93
94 #if USE_COLOURDLG_GENERIC
95 #include "wx/generic/colrdlgg.h"
96 #endif // USE_COLOURDLG_GENERIC
97
98 #if USE_DIRDLG_GENERIC
99 #include "wx/generic/dirdlgg.h"
100 #endif // USE_DIRDLG_GENERIC
101
102 #if USE_FILEDLG_GENERIC
103 #include "wx/generic/filedlgg.h"
104 #endif // USE_FILEDLG_GENERIC
105
106 #if USE_FONTDLG_GENERIC
107 #include "wx/generic/fontdlgg.h"
108 #endif // USE_FONTDLG_GENERIC
109
110 IMPLEMENT_APP(MyApp)
111
112 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
113 EVT_PAINT(MyCanvas::OnPaint)
114 END_EVENT_TABLE()
115
116
117
118 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
119 #if wxUSE_MSGDLG
120 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
121 EVT_MENU(DIALOGS_MESSAGE_DIALOG, MyFrame::MessageBoxDialog)
122 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo)
123 #endif // wxUSE_MSGDLG
124 #if wxUSE_COLOURDLG
125 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
126 EVT_MENU(DIALOGS_GET_COLOUR, MyFrame::GetColour)
127 #endif // wxUSE_COLOURDLG
128
129 #if wxUSE_FONTDLG
130 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
131 #endif // wxUSE_FONTDLG
132
133 #if wxUSE_LOG_DIALOG
134 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
135 #endif // wxUSE_LOG_DIALOG
136
137 #if wxUSE_TEXTDLG
138 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
139 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
140 #endif // wxUSE_TEXTDLG
141
142 #if wxUSE_NUMBERDLG
143 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
144 #endif // wxUSE_NUMBERDLG
145
146 #if wxUSE_CHOICEDLG
147 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
148 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
149 #endif // wxUSE_CHOICEDLG
150
151 EVT_MENU(DIALOGS_REARRANGE, MyFrame::Rearrange)
152
153 #if wxUSE_FILEDLG
154 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
155 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
156 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
157 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
158 #endif // wxUSE_FILEDLG
159
160 #if USE_FILEDLG_GENERIC
161 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric)
162 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric)
163 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric)
164 #endif // USE_FILEDLG_GENERIC
165
166 #if wxUSE_DIRDLG
167 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
168 EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
169 #endif // wxUSE_DIRDLG
170
171 #if USE_MODAL_PRESENTATION
172 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
173 #endif // USE_MODAL_PRESENTATION
174 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
175 EVT_MENU(DIALOGS_CENTRE_SCREEN, MyFrame::DlgCenteredScreen)
176 EVT_MENU(DIALOGS_CENTRE_PARENT, MyFrame::DlgCenteredParent)
177 EVT_MENU(DIALOGS_MINIFRAME, MyFrame::MiniFrame)
178 EVT_MENU(DIALOGS_ONTOP, MyFrame::DlgOnTop)
179
180 #if wxUSE_STARTUP_TIPS
181 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
182 #endif // wxUSE_STARTUP_TIPS
183
184 #if USE_FONTDLG_GENERIC
185 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
186 #endif // USE_FONTDLG_GENERIC
187
188 #if USE_DIRDLG_GENERIC
189 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
190 #endif // wxMSW || wxMAC
191
192 #if USE_COLOURDLG_GENERIC
193 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
194 #endif // USE_COLOURDLG_GENERIC
195
196 #if wxUSE_PROGRESSDLG
197 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
198 #endif // wxUSE_PROGRESSDLG
199
200 #if wxUSE_ABOUTDLG
201 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog)
202 EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog)
203 EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog)
204 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog)
205 #endif // wxUSE_ABOUTDLG
206
207 #if wxUSE_BUSYINFO
208 EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
209 #endif // wxUSE_BUSYINFO
210
211 #if wxUSE_FINDREPLDLG
212 EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
213 EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
214
215 EVT_FIND(wxID_ANY, MyFrame::OnFindDialog)
216 EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog)
217 EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog)
218 EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog)
219 EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
220 #endif // wxUSE_FINDREPLDLG
221
222 #if USE_SETTINGS_DIALOG
223 EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet)
224 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheet)
225 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet)
226 #endif // USE_SETTINGS_DIALOG
227
228 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog)
229 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION, MyFrame::OnTestDefaultActionDialog)
230
231 EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
232 #if wxUSE_NOTIFICATION_MESSAGE
233 EVT_MENU(DIALOGS_NOTIFY_AUTO, MyFrame::OnNotifMsgAuto)
234 EVT_MENU(DIALOGS_NOTIFY_SHOW, MyFrame::OnNotifMsgShow)
235 EVT_MENU(DIALOGS_NOTIFY_HIDE, MyFrame::OnNotifMsgHide)
236 #endif // wxUSE_NOTIFICATION_MESSAGE
237
238 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
239 END_EVENT_TABLE()
240
241 #if USE_MODAL_PRESENTATION
242
243 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
244 EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
245 END_EVENT_TABLE()
246
247 BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
248 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
249 EVT_CLOSE(MyModelessDialog::OnClose)
250 END_EVENT_TABLE()
251
252 #endif // USE_MODAL_PRESENTATION
253
254 BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog)
255 EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent)
256 EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent)
257 END_EVENT_TABLE()
258
259 MyCanvas *myCanvas = (MyCanvas *) NULL;
260
261 // `Main program' equivalent, creating windows and returning main app frame
262 bool MyApp::OnInit()
263 {
264 if ( !wxApp::OnInit() )
265 return false;
266
267 #if wxUSE_IMAGE
268 wxInitAllImageHandlers();
269 #endif
270
271 m_canvasTextColour = *wxBLACK;
272 m_canvasFont = *wxNORMAL_FONT;
273
274 // Create the main frame window
275 MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example"));
276
277 // Make a menubar
278 wxMenu *menuDlg = new wxMenu;
279
280 menuDlg->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
281 menuDlg->Append(DIALOGS_MESSAGE_DIALOG, _T("Message dialog\tShift-Ctrl-M"));
282
283
284 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
285
286 wxMenu *choices_menu = new wxMenu;
287
288 #if wxUSE_COLOURDLG
289 choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose bg colour"));
290 choices_menu->Append(DIALOGS_GET_COLOUR, _T("&Choose fg colour"));
291 #endif // wxUSE_COLOURDLG
292
293 #if wxUSE_FONTDLG
294 choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
295 #endif // wxUSE_FONTDLG
296
297 #if wxUSE_CHOICEDLG
298 choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C"));
299 choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U"));
300 #endif // wxUSE_CHOICEDLG
301
302 choices_menu->Append(DIALOGS_REARRANGE, _T("&Rearrange dialog\tCtrl-R"));
303
304 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
305 choices_menu->AppendSeparator();
306 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
307
308 #if USE_COLOURDLG_GENERIC
309 choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)"));
310 #endif // USE_COLOURDLG_GENERIC
311
312 #if USE_FONTDLG_GENERIC
313 choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)"));
314 #endif // USE_FONTDLG_GENERIC
315
316 menuDlg->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu);
317 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
318
319
320 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
321
322 wxMenu *entry_menu = new wxMenu;
323
324 #if wxUSE_TEXTDLG
325 entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E"));
326 entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P"));
327 #endif // wxUSE_TEXTDLG
328
329 #if wxUSE_NUMBERDLG
330 entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N"));
331 #endif // wxUSE_NUMBERDLG
332
333 menuDlg->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu);
334
335 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
336
337
338 #if wxUSE_FILEDLG
339
340 wxMenu *filedlg_menu = new wxMenu;
341 filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O"));
342 filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2"));
343 filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
344 filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
345
346 #if USE_FILEDLG_GENERIC
347 filedlg_menu->AppendSeparator();
348 filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)"));
349 filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)"));
350 filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)"));
351 #endif // USE_FILEDLG_GENERIC
352
353 menuDlg->Append(wxID_ANY,_T("&File operations"),filedlg_menu);
354
355 #endif // wxUSE_FILEDLG
356
357 #if wxUSE_DIRDLG
358 wxMenu *dir_menu = new wxMenu;
359
360 dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D"));
361 dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
362 menuDlg->Append(wxID_ANY,_T("&Directory operations"),dir_menu);
363
364 #if USE_DIRDLG_GENERIC
365 dir_menu->AppendSeparator();
366 dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)"));
367 #endif // USE_DIRDLG_GENERIC
368
369 #endif // wxUSE_DIRDLG
370
371
372 #if wxUSE_STARTUP_TIPS || \
373 wxUSE_PROGRESSDLG || \
374 wxUSE_BUSYINFO || \
375 wxUSE_LOG_DIALOG || \
376 wxUSE_MSGDLG
377
378 wxMenu *info_menu = new wxMenu;
379
380 #if wxUSE_STARTUP_TIPS
381 info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T"));
382 #endif // wxUSE_STARTUP_TIPS
383
384 #if wxUSE_PROGRESSDLG
385 info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G"));
386 #endif // wxUSE_PROGRESSDLG
387
388 #if wxUSE_BUSYINFO
389 info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B"));
390 #endif // wxUSE_BUSYINFO
391
392 #if wxUSE_LOG_DIALOG
393 info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L"));
394 #endif // wxUSE_LOG_DIALOG
395
396 #if wxUSE_MSGDLG
397 info_menu->Append(DIALOGS_MESSAGE_BOX_WXINFO,
398 _T("&wxWidgets information\tCtrl-I"));
399 #endif // wxUSE_MSGDLG
400
401 menuDlg->Append(wxID_ANY,_T("&Informative dialogs"),info_menu);
402
403 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
404
405
406 #if wxUSE_FINDREPLDLG
407 wxMenu *find_menu = new wxMenu;
408 find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"));
409 find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"));
410 menuDlg->Append(wxID_ANY,_T("&Searching"),find_menu);
411 #endif // wxUSE_FINDREPLDLG
412
413 wxMenu *dialogs_menu = new wxMenu;
414 #if USE_MODAL_PRESENTATION
415 dialogs_menu->Append(DIALOGS_MODAL, _T("&Modal dialog\tCtrl-W"));
416 #endif // USE_MODAL_PRESENTATION
417 dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Mode&less dialog\tCtrl-Z"));
418 dialogs_menu->Append(DIALOGS_CENTRE_SCREEN, _T("Centered on &screen\tShift-Ctrl-1"));
419 dialogs_menu->Append(DIALOGS_CENTRE_PARENT, _T("Centered on &parent\tShift-Ctrl-2"));
420 dialogs_menu->Append(DIALOGS_MINIFRAME, _T("&Mini frame"));
421 dialogs_menu->Append(DIALOGS_ONTOP, _T("Dialog staying on &top"));
422 menuDlg->Append(wxID_ANY, _T("&Generic dialogs"), dialogs_menu);
423
424 #if USE_SETTINGS_DIALOG
425 wxMenu *sheet_menu = new wxMenu;
426 sheet_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Standard property sheet\tShift-Ctrl-P"));
427 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, _T("&Toolbook sheet\tShift-Ctrl-T"));
428
429 if (wxPlatformIs(wxPORT_MAC))
430 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
431 /*
432 #ifdef __WXMAC__
433 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
434 #endif
435 */
436 menuDlg->Append(wxID_ANY, _T("&Property sheets"), sheet_menu);
437 #endif // USE_SETTINGS_DIALOG
438
439 wxMenu *menuNotif = new wxMenu;
440 menuNotif->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-Shift-R"));
441 #if wxUSE_NOTIFICATION_MESSAGE
442 menuNotif->Append(DIALOGS_NOTIFY_AUTO, "&Automatically hidden notification");
443 menuNotif->Append(DIALOGS_NOTIFY_SHOW, "&Show manual notification");
444 menuNotif->Append(DIALOGS_NOTIFY_HIDE, "&Hide manual notification");
445 #endif // wxUSE_NOTIFICATION_MESSAGE
446 menuDlg->AppendSubMenu(menuNotif, "&User notifications");
447
448 menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, _T("&Standard Buttons Sizer Dialog"));
449 menuDlg->Append(DIALOGS_TEST_DEFAULT_ACTION, _T("&Test dialog default action"));
450
451 menuDlg->AppendSeparator();
452 menuDlg->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
453
454 #if wxUSE_ABOUTDLG
455 wxMenu *menuHelp = new wxMenu;
456 menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)...\tF1"));
457 menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, _T("About (&fancy)...\tShift-F1"));
458 menuHelp->Append(DIALOGS_ABOUTDLG_FULL, _T("About (f&ull)...\tCtrl-F1"));
459 menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, _T("About (&custom)...\tCtrl-Shift-F1"));
460 #endif // wxUSE_ABOUTDLG
461
462 wxMenuBar *menubar = new wxMenuBar;
463 menubar->Append(menuDlg, _T("&Dialogs"));
464 #if wxUSE_ABOUTDLG
465 menubar->Append(menuHelp, _T("&Help"));
466 #endif // wxUSE_ABOUTDLG
467
468 frame->SetMenuBar(menubar);
469
470 myCanvas = new MyCanvas(frame);
471 myCanvas->SetBackgroundColour(*wxWHITE);
472
473 frame->Centre(wxBOTH);
474
475 // Show the frame
476 frame->Show(true);
477
478 SetTopWindow(frame);
479
480 return true;
481 }
482
483 // My frame constructor
484 MyFrame::MyFrame(wxWindow *parent,
485 const wxString& title)
486 : wxFrame(parent, wxID_ANY, title)
487 {
488 SetIcon(sample_xpm);
489
490 #if USE_MODAL_PRESENTATION
491 m_dialog = (MyModelessDialog *)NULL;
492 #endif // USE_MODAL_PRESENTATION
493
494 #if wxUSE_FINDREPLDLG
495 m_dlgFind =
496 m_dlgReplace = NULL;
497 #endif
498
499 #if wxUSE_COLOURDLG
500 m_clrData.SetChooseFull(true);
501 for (int i = 0; i < wxColourData::NUM_CUSTOM; i++)
502 {
503 unsigned char n = i*16;
504 m_clrData.SetCustomColour(i, wxColour(n, n, n));
505 }
506 #endif // wxUSE_COLOURDLG
507
508 #if wxUSE_NOTIFICATION_MESSAGE
509 m_notifMsg = NULL;
510 #endif // wxUSE_NOTIFICATION_MESSAGE
511
512 #if wxUSE_STATUSBAR
513 CreateStatusBar();
514 #endif // wxUSE_STATUSBAR
515 }
516
517 MyFrame::~MyFrame()
518 {
519 #if wxUSE_NOTIFICATION_MESSAGE
520 delete m_notifMsg;
521 #endif // wxUSE_NOTIFICATION_MESSAGE
522 }
523
524 #if wxUSE_COLOURDLG
525
526 void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event))
527 {
528 m_clrData.SetColour(myCanvas->GetBackgroundColour());
529
530 wxColourDialog dialog(this, &m_clrData);
531 dialog.SetTitle(_("Please choose the background colour"));
532 if ( dialog.ShowModal() == wxID_OK )
533 {
534 m_clrData = dialog.GetColourData();
535 myCanvas->SetBackgroundColour(m_clrData.GetColour());
536 myCanvas->ClearBackground();
537 myCanvas->Refresh();
538 }
539 }
540
541 void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
542 {
543 wxColour clr = wxGetColourFromUser
544 (
545 this,
546 wxGetApp().m_canvasTextColour,
547 "Please choose the foreground colour"
548 );
549 if ( clr.IsOk() )
550 {
551 wxGetApp().m_canvasTextColour = clr;
552 myCanvas->Refresh();
553 }
554 //else: dialog cancelled by user
555 }
556
557 #endif // wxUSE_COLOURDLG
558
559
560 #if USE_COLOURDLG_GENERIC
561 void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
562 {
563 m_clrData.SetColour(myCanvas->GetBackgroundColour());
564
565 //FIXME:TODO:This has no effect...
566 m_clrData.SetChooseFull(true);
567
568 for (int i = 0; i < 16; i++)
569 {
570 wxColour colour(
571 (unsigned char)(i*16),
572 (unsigned char)(i*16),
573 (unsigned char)(i*16)
574 );
575 m_clrData.SetCustomColour(i, colour);
576 }
577
578 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);
579 if (dialog->ShowModal() == wxID_OK)
580 {
581 m_clrData = dialog->GetColourData();
582 myCanvas->SetBackgroundColour(m_clrData.GetColour());
583 myCanvas->ClearBackground();
584 myCanvas->Refresh();
585 }
586 dialog->Destroy();
587 }
588 #endif // USE_COLOURDLG_GENERIC
589
590 #if wxUSE_FONTDLG
591 void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
592 {
593 wxFontData data;
594 data.SetInitialFont(wxGetApp().m_canvasFont);
595 data.SetColour(wxGetApp().m_canvasTextColour);
596
597 // you might also do this:
598 //
599 // wxFontDialog dialog;
600 // if ( !dialog.Create(this, data) { ... error ... }
601 //
602 wxFontDialog dialog(this, data);
603
604 if (dialog.ShowModal() == wxID_OK)
605 {
606 wxFontData retData = dialog.GetFontData();
607 wxGetApp().m_canvasFont = retData.GetChosenFont();
608 wxGetApp().m_canvasTextColour = retData.GetColour();
609 myCanvas->Refresh();
610 }
611 //else: cancelled by the user, don't change the font
612 }
613 #endif // wxUSE_FONTDLG
614
615 #if USE_FONTDLG_GENERIC
616 void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
617 {
618 wxFontData data;
619 data.SetInitialFont(wxGetApp().m_canvasFont);
620 data.SetColour(wxGetApp().m_canvasTextColour);
621
622 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data);
623 if (dialog->ShowModal() == wxID_OK)
624 {
625 wxFontData retData = dialog->GetFontData();
626 wxGetApp().m_canvasFont = retData.GetChosenFont();
627 wxGetApp().m_canvasTextColour = retData.GetColour();
628 myCanvas->Refresh();
629 }
630 dialog->Destroy();
631 }
632 #endif // USE_FONTDLG_GENERIC
633
634 #if wxUSE_LOG_DIALOG
635 void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
636 {
637 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
638 // being flushed -- test it
639 {
640 wxBusyCursor bc;
641 wxLogMessage(wxT("This is some message - everything is ok so far."));
642 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
643 wxLogWarning(wxT("And then something went wrong!"));
644
645 // and if ~wxBusyCursor doesn't do it, then call it manually
646 wxYield();
647 }
648
649 wxLogError(wxT("Intermediary error handler decided to abort."));
650 wxLogError(wxT("The top level caller detected an unrecoverable error."));
651
652 wxLog::FlushActive();
653
654 wxLogMessage(wxT("And this is the same dialog but with only one message."));
655 }
656 #endif // wxUSE_LOG_DIALOG
657
658 #if wxUSE_MSGDLG
659 void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event))
660 {
661 wxMessageDialog dialog(this,
662 "This is a message box\n"
663 "This is a long, long string to test out if the message box "
664 "is laid out properly.",
665 "Message box text",
666 wxCENTER |
667 wxNO_DEFAULT | wxYES_NO | wxCANCEL |
668 wxICON_INFORMATION);
669
670 wxString extmsg;
671 if ( dialog.SetYesNoCancelLabels
672 (
673 "Answer &Yes",
674 "Answer &No",
675 "Refuse to answer"
676 ) )
677 {
678 extmsg = "This platform supports custom button labels,\n"
679 "so you should see the descriptive labels below.";
680 }
681 else
682 {
683 extmsg = "Custom button labels are not supported on this platform,\n"
684 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
685 }
686 dialog.SetExtendedMessage(extmsg);
687
688 switch ( dialog.ShowModal() )
689 {
690 case wxID_YES:
691 wxLogStatus(wxT("You pressed \"Yes\""));
692 break;
693
694 case wxID_NO:
695 wxLogStatus(wxT("You pressed \"No\""));
696 break;
697
698 case wxID_CANCEL:
699 wxLogStatus(wxT("You pressed \"Cancel\""));
700 break;
701
702 default:
703 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
704 }
705 }
706
707 void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event))
708 {
709 TestMessageBoxDialog dlg(this);
710 dlg.ShowModal();
711 }
712
713 void MyFrame::MessageBoxInfo(wxCommandEvent& WXUNUSED(event))
714 {
715 ::wxInfoMessageBox(this);
716 }
717 #endif // wxUSE_MSGDLG
718
719 #if wxUSE_NUMBERDLG
720 void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event))
721 {
722 long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
723 _T("Even two rows of text."),
724 _T("Enter a number:"), _T("Numeric input test"),
725 50, 0, 100, this );
726
727 wxString msg;
728 int icon;
729 if ( res == -1 )
730 {
731 msg = _T("Invalid number entered or dialog cancelled.");
732 icon = wxICON_HAND;
733 }
734 else
735 {
736 msg.Printf(_T("You've entered %lu"), res );
737 icon = wxICON_INFORMATION;
738 }
739
740 wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this);
741 }
742 #endif // wxUSE_NUMBERDLG
743
744 #if wxUSE_TEXTDLG
745 void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
746 {
747 wxString pwd = wxGetPasswordFromUser(_T("Enter password:"),
748 _T("Password entry dialog"),
749 wxEmptyString,
750 this);
751 if ( !pwd.empty() )
752 {
753 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
754 _T("Got password"), wxOK | wxICON_INFORMATION, this);
755 }
756 }
757
758 void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
759 {
760 wxTextEntryDialog dialog(this,
761 _T("This is a small sample\n")
762 _T("A long, long string to test out the text entrybox"),
763 _T("Please enter a string"),
764 _T("Default value"),
765 wxOK | wxCANCEL);
766
767 if (dialog.ShowModal() == wxID_OK)
768 {
769 wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this);
770 }
771 }
772 #endif // wxUSE_TEXTDLG
773
774 #if wxUSE_CHOICEDLG
775 void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
776 {
777 const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
778
779 wxSingleChoiceDialog dialog(this,
780 _T("This is a small sample\n")
781 _T("A single-choice convenience dialog"),
782 _T("Please select a value"),
783 WXSIZEOF(choices), choices);
784
785 dialog.SetSelection(2);
786
787 if (dialog.ShowModal() == wxID_OK)
788 {
789 wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string"));
790 dialog2.ShowModal();
791 }
792 }
793
794 void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
795 {
796 const wxString choices[] =
797 {
798 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
799 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
800 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
801 };
802
803 wxArrayInt selections;
804 size_t count = wxGetMultipleChoices(selections,
805 _T("This is a small sample\n")
806 _T("A multi-choice convenience dialog"),
807 _T("Please select a value"),
808 WXSIZEOF(choices), choices,
809 this);
810 if ( count )
811 {
812 wxString msg;
813 msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
814 for ( size_t n = 0; n < count; n++ )
815 {
816 msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
817 (unsigned)n, (unsigned)selections[n],
818 choices[selections[n]].c_str());
819 }
820 wxLogMessage(msg);
821 }
822 //else: cancelled or nothing selected
823 }
824 #endif // wxUSE_CHOICEDLG
825
826 // custom rearrange dialog: it adds the possibility to rename an item to the
827 // base class functionality
828 class MyRearrangeDialog : public wxRearrangeDialog
829 {
830 public:
831 MyRearrangeDialog(wxWindow *parent,
832 wxArrayInt& order,
833 wxArrayString& labels,
834 wxArrayString& labelsOrig)
835 : wxRearrangeDialog
836 (
837 parent,
838 "Configure the columns shown:",
839 "wxRearrangeDialog example",
840 order,
841 labels
842 ),
843 m_order(order),
844 m_labels(labels),
845 m_labelsOrig(labelsOrig)
846 {
847 m_sel = wxNOT_FOUND;
848
849 wxPanel * const panel = new wxPanel(this);
850 wxSizer * const sizer = new wxBoxSizer(wxHORIZONTAL);
851
852 m_labelOrig = new wxStaticText(panel, wxID_ANY, "");
853 sizer->Add(m_labelOrig, wxSizerFlags().Centre().Border(wxRIGHT));
854
855 m_text = new wxTextCtrl(panel, wxID_ANY, "",
856 wxDefaultPosition, wxDefaultSize,
857 wxTE_PROCESS_ENTER);
858 sizer->Add(m_text, wxSizerFlags().Centre().Border(wxRIGHT));
859
860 sizer->Add(new wxButton(panel, wxID_APPLY, "&Rename"),
861 wxSizerFlags().Centre());
862
863 panel->SetSizer(sizer);
864
865 // call this first to ensure that the controls have a reasonable best
866 // size before they're added
867 DoUpdateExtraControls(GetList()->GetSelection());
868
869 AddExtraControls(panel);
870 }
871
872 // call this instead of ShowModal() to update order and labels array in
873 // case the dialog was not cancelled
874 bool Rearrange()
875 {
876 if ( ShowModal() == wxID_CANCEL )
877 return false;
878
879 m_order = GetOrder();
880
881 return true;
882 }
883
884 private:
885 void OnSelChange(wxCommandEvent& event)
886 {
887 DoUpdateExtraControls(event.GetInt());
888 }
889
890 void OnUpdateUIRename(wxUpdateUIEvent& event)
891 {
892 event.Enable( CanRename() );
893 }
894
895 void OnRename(wxCommandEvent& WXUNUSED(event))
896 {
897 if ( !CanRename() )
898 return;
899
900 m_labels[m_sel] = m_text->GetValue();
901 GetList()->SetString(m_sel, m_labels[m_sel]);
902 }
903
904 bool CanRename() const
905 {
906 // only allow renaming if the user modified the currently selected item
907 // text (which presupposes that we do have a current item)
908 return m_sel != wxNOT_FOUND && m_text->GetValue() != m_labels[m_sel];
909 }
910
911 void DoUpdateExtraControls(int sel)
912 {
913 m_sel = sel;
914
915 if ( m_sel == wxNOT_FOUND )
916 {
917 m_labelOrig->SetLabel("<no selection>");
918 m_text->Clear();
919 m_text->Disable();
920 }
921 else // have valid item
922 {
923 m_labelOrig->SetLabelText(m_labelsOrig[m_sel]);
924 m_text->Enable();
925 m_text->SetValue(m_labels[m_sel]);
926 }
927 }
928
929 wxArrayInt& m_order;
930 wxArrayString& m_labels,
931 m_labelsOrig;
932
933 int m_sel;
934 wxStaticText *m_labelOrig;
935 wxTextCtrl *m_text;
936
937 DECLARE_EVENT_TABLE()
938 DECLARE_NO_COPY_CLASS(MyRearrangeDialog)
939 };
940
941 BEGIN_EVENT_TABLE(MyRearrangeDialog, wxRearrangeDialog)
942 EVT_LISTBOX(wxID_ANY, MyRearrangeDialog::OnSelChange)
943 EVT_UPDATE_UI(wxID_APPLY, MyRearrangeDialog::OnUpdateUIRename)
944 EVT_BUTTON(wxID_APPLY, MyRearrangeDialog::OnRename)
945 EVT_TEXT_ENTER(wxID_ANY, MyRearrangeDialog::OnRename)
946 END_EVENT_TABLE()
947
948 void MyFrame::Rearrange(wxCommandEvent& WXUNUSED(event))
949 {
950 // the arrays are static so that we preserve the items order between calls
951 // to this function
952 static wxArrayInt s_order;
953 static wxArrayString s_labels,
954 s_labelsOrig;
955
956 // initialize them on the first call
957 if ( s_labelsOrig.empty() )
958 {
959 static const struct ItemInfo
960 {
961 const char *label;
962 const char *labelOrig;
963 int order;
964 } items[] =
965 {
966 { "File name", "Name", 0 },
967 { "File type", "Ext", 1 },
968 { "Size", "Size", 2 },
969 { "Creation time", "Ctime", ~3 }, // negated so hidden
970 { "Last accessed", "Atime", ~4 },
971 { "Last modified", "Mtime", 5 },
972 };
973
974 s_order.reserve(WXSIZEOF(items));
975 s_labels.reserve(WXSIZEOF(items));
976 s_labelsOrig.reserve(WXSIZEOF(items));
977 for ( unsigned n = 0; n < WXSIZEOF(items); n++ )
978 {
979 const ItemInfo& item = items[n];
980 s_order.push_back(item.order);
981 s_labels.push_back(item.label);
982 s_labelsOrig.push_back(item.labelOrig);
983 }
984 }
985
986 MyRearrangeDialog dlg(this, s_order, s_labels, s_labelsOrig);
987 if ( !dlg.Rearrange() )
988 return;
989
990 wxString columns;
991 for ( unsigned n = 0; n < s_order.size(); n++ )
992 {
993 columns += wxString::Format("\n %u: ", n);
994 int idx = s_order[n];
995 if ( idx < 0 )
996 {
997 columns += "[hidden] ";
998 idx = ~idx;
999 }
1000
1001 columns += s_labels[idx];
1002 if ( s_labels[idx] != s_labelsOrig[idx] )
1003 {
1004 columns += wxString::Format(" (original label: \"%s\")",
1005 s_labelsOrig[idx]);
1006 }
1007 }
1008
1009 wxLogMessage("The columns order now is:%s", columns);
1010 }
1011
1012 #if wxUSE_FILEDLG
1013
1014 // panel with custom controls for file dialog
1015 class MyExtraPanel : public wxPanel
1016 {
1017 public:
1018 MyExtraPanel(wxWindow *parent);
1019 void OnCheckBox(wxCommandEvent& event) { m_btn->Enable(event.IsChecked()); }
1020 wxString GetInfo() const
1021 {
1022 return wxString::Format("checkbox value = %d", (int) m_cb->GetValue());
1023 }
1024 private:
1025 wxButton *m_btn;
1026 wxCheckBox *m_cb;
1027 };
1028
1029 MyExtraPanel::MyExtraPanel(wxWindow *parent)
1030 : wxPanel(parent)
1031 {
1032 m_btn = new wxButton(this, -1, _T("Custom Button"));
1033 m_btn->Enable(false);
1034 m_cb = new wxCheckBox(this, -1, _T("Enable Custom Button"));
1035 m_cb->Connect(wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,
1036 wxCommandEventHandler(MyExtraPanel::OnCheckBox), NULL, this);
1037 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1038 sizerTop->Add(m_cb, wxSizerFlags().Centre().Border());
1039 sizerTop->AddStretchSpacer();
1040 sizerTop->Add(m_btn, wxSizerFlags().Right().Border());
1041 SetSizerAndFit(sizerTop);
1042 }
1043
1044 // a static method can be used instead of a function with most of compilers
1045 static wxWindow* createMyExtraPanel(wxWindow *parent)
1046 {
1047 return new MyExtraPanel(parent);
1048 }
1049
1050 void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
1051 {
1052 wxFileDialog dialog
1053 (
1054 this,
1055 _T("Testing open file dialog"),
1056 wxEmptyString,
1057 wxEmptyString,
1058 #ifdef __WXMOTIF__
1059 _T("C++ files (*.cpp)|*.cpp")
1060 #else
1061 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
1062 #endif
1063 );
1064
1065 dialog.SetExtraControlCreator(&createMyExtraPanel);
1066 dialog.CentreOnParent();
1067 dialog.SetDirectory(wxGetHomeDir());
1068
1069 if (dialog.ShowModal() == wxID_OK)
1070 {
1071 wxString info;
1072 wxWindow * const extra = dialog.GetExtraControl();
1073 info.Printf(_T("Full file name: %s\n")
1074 _T("Path: %s\n")
1075 _T("Name: %s\n")
1076 _T("Custom window: %s"),
1077 dialog.GetPath().c_str(),
1078 dialog.GetDirectory().c_str(),
1079 dialog.GetFilename().c_str(),
1080 extra ? static_cast<MyExtraPanel*>(extra)->GetInfo()
1081 : wxString("None"));
1082 wxMessageDialog dialog2(this, info, _T("Selected file"));
1083 dialog2.ShowModal();
1084 }
1085 }
1086
1087 // this shows how to take advantage of specifying a default extension in the
1088 // call to wxFileSelector: it is remembered after each new call and the next
1089 // one will use it by default
1090 void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
1091 {
1092 static wxString s_extDef;
1093 wxString path = wxFileSelector(
1094 _T("Select the file to load"),
1095 wxEmptyString, wxEmptyString,
1096 s_extDef,
1097 wxString::Format
1098 (
1099 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
1100 wxFileSelectorDefaultWildcardStr,
1101 wxFileSelectorDefaultWildcardStr
1102 ),
1103 wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW,
1104 this
1105 );
1106
1107 if ( !path )
1108 return;
1109
1110 // it is just a sample, would use wxSplitPath in real program
1111 s_extDef = path.AfterLast(_T('.'));
1112
1113 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
1114 path, s_extDef);
1115 }
1116
1117 void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
1118 {
1119 wxString wildcards =
1120 #ifdef __WXMOTIF__
1121 _T("C++ files (*.cpp)|*.cpp");
1122 #else
1123 wxString::Format
1124 (
1125 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
1126 wxFileSelectorDefaultWildcardStr,
1127 wxFileSelectorDefaultWildcardStr
1128 );
1129 #endif
1130 wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
1131 wxEmptyString, wxEmptyString, wildcards,
1132 wxFD_OPEN|wxFD_MULTIPLE);
1133
1134 if (dialog.ShowModal() == wxID_OK)
1135 {
1136 wxArrayString paths, filenames;
1137
1138 dialog.GetPaths(paths);
1139 dialog.GetFilenames(filenames);
1140
1141 wxString msg, s;
1142 size_t count = paths.GetCount();
1143 for ( size_t n = 0; n < count; n++ )
1144 {
1145 s.Printf(_T("File %d: %s (%s)\n"),
1146 (int)n, paths[n].c_str(), filenames[n].c_str());
1147
1148 msg += s;
1149 }
1150 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
1151 msg += s;
1152
1153 wxMessageDialog dialog2(this, msg, _T("Selected files"));
1154 dialog2.ShowModal();
1155 }
1156 }
1157
1158 void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
1159 {
1160 wxFileDialog dialog(this,
1161 _T("Testing save file dialog"),
1162 wxEmptyString,
1163 _T("myletter.doc"),
1164 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1165 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1166
1167 dialog.SetFilterIndex(1);
1168
1169 if (dialog.ShowModal() == wxID_OK)
1170 {
1171 wxLogMessage(_T("%s, filter %d"),
1172 dialog.GetPath().c_str(), dialog.GetFilterIndex());
1173 }
1174 }
1175 #endif // wxUSE_FILEDLG
1176
1177 #if USE_FILEDLG_GENERIC
1178 void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
1179 {
1180 wxGenericFileDialog dialog
1181 (
1182 this,
1183 _T("Testing open file dialog"),
1184 wxEmptyString,
1185 wxEmptyString,
1186 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
1187 );
1188
1189 dialog.SetExtraControlCreator(&createMyExtraPanel);
1190 dialog.SetDirectory(wxGetHomeDir());
1191
1192 if (dialog.ShowModal() == wxID_OK)
1193 {
1194 wxString info;
1195 info.Printf(_T("Full file name: %s\n")
1196 _T("Path: %s\n")
1197 _T("Name: %s"),
1198 dialog.GetPath().c_str(),
1199 dialog.GetDirectory().c_str(),
1200 dialog.GetFilename().c_str());
1201 wxMessageDialog dialog2(this, info, _T("Selected file"));
1202 dialog2.ShowModal();
1203 }
1204 }
1205
1206 void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
1207 {
1208 // On PocketPC you can disable OK-only dialogs policy using system option
1209 int buttons = wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1210 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1211
1212 wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1213 wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
1214 wxEmptyString, wxEmptyString, wildcards,
1215 wxFD_MULTIPLE);
1216
1217 if (dialog.ShowModal() == wxID_OK)
1218 {
1219 wxArrayString paths, filenames;
1220
1221 dialog.GetPaths(paths);
1222 dialog.GetFilenames(filenames);
1223
1224 wxString msg, s;
1225 size_t count = paths.GetCount();
1226 for ( size_t n = 0; n < count; n++ )
1227 {
1228 s.Printf(_T("File %d: %s (%s)\n"),
1229 (int)n, paths[n].c_str(), filenames[n].c_str());
1230
1231 msg += s;
1232 }
1233 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
1234 msg += s;
1235
1236 wxMessageDialog dialog2(this, msg, _T("Selected files"));
1237 dialog2.ShowModal();
1238 }
1239
1240 // restore system option
1241 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons);
1242 }
1243
1244 void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
1245 {
1246 wxGenericFileDialog dialog(this,
1247 _T("Testing save file dialog"),
1248 wxEmptyString,
1249 _T("myletter.doc"),
1250 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
1251 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1252
1253 dialog.SetFilterIndex(1);
1254
1255 if (dialog.ShowModal() == wxID_OK)
1256 {
1257 wxLogMessage(_T("%s, filter %d"),
1258 dialog.GetPath().c_str(), dialog.GetFilterIndex());
1259 }
1260 }
1261 #endif // USE_FILEDLG_GENERIC
1262
1263 #if wxUSE_DIRDLG
1264 void MyFrame::DoDirChoose(int style)
1265 {
1266 // pass some initial dir to wxDirDialog
1267 wxString dirHome;
1268 wxGetHomeDir(&dirHome);
1269
1270 wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
1271
1272 if (dialog.ShowModal() == wxID_OK)
1273 {
1274 wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
1275 }
1276 }
1277
1278 void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
1279 {
1280 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
1281 }
1282
1283 void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
1284 {
1285 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST);
1286 }
1287 #endif // wxUSE_DIRDLG
1288
1289 #if USE_DIRDLG_GENERIC
1290 void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
1291 {
1292 // pass some initial dir to wxDirDialog
1293 wxString dirHome;
1294 wxGetHomeDir(&dirHome);
1295
1296 wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
1297
1298 if (dialog.ShowModal() == wxID_OK)
1299 {
1300 wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
1301 dialog2.ShowModal();
1302 }
1303 }
1304 #endif // USE_DIRDLG_GENERIC
1305
1306 #if USE_MODAL_PRESENTATION
1307 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
1308 {
1309 MyModalDialog dlg(this);
1310 dlg.ShowModal();
1311 }
1312 #endif // USE_MODAL_PRESENTATION
1313
1314 void MyFrame::ModelessDlg(wxCommandEvent& event)
1315 {
1316 bool show = GetMenuBar()->IsChecked(event.GetId());
1317
1318 if ( show )
1319 {
1320 if ( !m_dialog )
1321 {
1322 m_dialog = new MyModelessDialog(this);
1323 }
1324
1325 m_dialog->Show(true);
1326 }
1327 else // hide
1328 {
1329 // If m_dialog is NULL, then possibly the system
1330 // didn't report the checked menu item status correctly.
1331 // It should be true just after the menu item was selected,
1332 // if there was no modeless dialog yet.
1333
1334 wxASSERT( m_dialog != NULL );
1335 if (m_dialog)
1336 m_dialog->Hide();
1337 }
1338 }
1339
1340 void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event))
1341 {
1342 wxDialog dlg(this, wxID_ANY, _T("Dialog centered on screen"),
1343 wxDefaultPosition, wxSize(200, 100));
1344 (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre();
1345 dlg.CentreOnScreen();
1346 dlg.ShowModal();
1347 }
1348
1349 void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event))
1350 {
1351 wxDialog dlg(this, wxID_ANY, _T("Dialog centered on parent"),
1352 wxDefaultPosition, wxSize(200, 100));
1353 (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre();
1354 dlg.CentreOnParent();
1355 dlg.ShowModal();
1356 }
1357
1358 void MyFrame::MiniFrame(wxCommandEvent& WXUNUSED(event))
1359 {
1360 wxFrame *frame = new wxMiniFrame(this, wxID_ANY, _T("Mini frame"),
1361 wxDefaultPosition, wxSize(300, 100),
1362 wxCAPTION | wxCLOSE_BOX);
1363 new wxStaticText(frame,
1364 wxID_ANY,
1365 _T("Mini frames have slightly different appearance"),
1366 wxPoint(5, 5));
1367 new wxStaticText(frame,
1368 wxID_ANY,
1369 _T("from the normal frames but that's the only difference."),
1370 wxPoint(5, 25));
1371
1372 frame->CentreOnParent();
1373 frame->Show();
1374 }
1375
1376 void MyFrame::DlgOnTop(wxCommandEvent& WXUNUSED(event))
1377 {
1378 wxDialog dlg(this, wxID_ANY, _T("Dialog staying on top of other windows"),
1379 wxDefaultPosition, wxSize(300, 100),
1380 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP);
1381 (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre();
1382 dlg.ShowModal();
1383 }
1384
1385 #if wxUSE_STARTUP_TIPS
1386 void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
1387 {
1388 static size_t s_index = (size_t)-1;
1389
1390 if ( s_index == (size_t)-1 )
1391 {
1392 srand(time(NULL));
1393
1394 // this is completely bogus, we don't know how many lines are there
1395 // in the file, but who cares, it's a demo only...
1396 s_index = rand() % 5;
1397 }
1398
1399 wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
1400
1401 bool showAtStartup = wxShowTip(this, tipProvider);
1402
1403 if ( showAtStartup )
1404 {
1405 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
1406 wxOK | wxICON_INFORMATION, this);
1407 }
1408
1409 s_index = tipProvider->GetCurrentTip();
1410 delete tipProvider;
1411 }
1412 #endif // wxUSE_STARTUP_TIPS
1413
1414 #if USE_SETTINGS_DIALOG
1415 void MyFrame::OnPropertySheet(wxCommandEvent& event)
1416 {
1417 SettingsDialog dialog(this, event.GetId());
1418 dialog.ShowModal();
1419 }
1420 #endif // USE_SETTINGS_DIALOG
1421
1422 void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
1423 {
1424 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1425
1426 wxSleep(3);
1427
1428 RequestUserAttention(wxUSER_ATTENTION_ERROR);
1429 }
1430
1431 #if wxUSE_NOTIFICATION_MESSAGE
1432
1433 void MyFrame::OnNotifMsgAuto(wxCommandEvent& WXUNUSED(event))
1434 {
1435 if ( !wxNotificationMessage
1436 (
1437 "Automatic Notification",
1438 "Nothing important has happened\n"
1439 "this notification will disappear soon."
1440 ).Show() )
1441 {
1442 wxLogStatus("Failed to show notification message");
1443 }
1444 }
1445
1446 void MyFrame::OnNotifMsgShow(wxCommandEvent& WXUNUSED(event))
1447 {
1448 if ( !m_notifMsg )
1449 {
1450 m_notifMsg = new wxNotificationMessage
1451 (
1452 "wxWidgets Manual Notification",
1453 "You can hide this notification from the menu",
1454 this
1455 );
1456 }
1457
1458 if ( !m_notifMsg->Show(wxNotificationMessage::Timeout_Never) )
1459 {
1460 wxLogStatus("Failed to show manual notification message");
1461 }
1462 }
1463
1464 void MyFrame::OnNotifMsgHide(wxCommandEvent& WXUNUSED(event))
1465 {
1466 if ( m_notifMsg )
1467 {
1468 if ( !m_notifMsg->Close() )
1469 wxLogStatus("Failed to hide manual notification message");
1470 }
1471 }
1472
1473 #endif // wxUSE_NOTIFICATION_MESSAGE
1474
1475 void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
1476 {
1477 StdButtonSizerDialog dialog(this);
1478 dialog.ShowModal();
1479 }
1480
1481 // TestDefaultAction
1482
1483 #define ID_CATCH_LISTBOX_DCLICK 100
1484 #define ID_LISTBOX 101
1485
1486 BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog)
1487 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK, TestDefaultActionDialog::OnCatchListBoxDClick)
1488 EVT_LISTBOX_DCLICK(ID_LISTBOX, TestDefaultActionDialog::OnListBoxDClick)
1489 END_EVENT_TABLE()
1490
1491 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
1492 wxDialog( parent, -1, "Test default action" )
1493 {
1494 m_catchListBoxDClick = false;
1495
1496 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1497
1498 wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 5, 5 );
1499
1500 wxListBox *listbox = new wxListBox( this, ID_LISTBOX );
1501 listbox->Append( "String 1" );
1502 listbox->Append( "String 2" );
1503 listbox->Append( "String 3" );
1504 listbox->Append( "String 4" );
1505 grid_sizer->Add( listbox );
1506
1507 grid_sizer->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL );
1508
1509 grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL );
1510 grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
1511
1512 grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL );
1513 grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
1514
1515 main_sizer->Add( grid_sizer, 0, wxALL, 10 );
1516
1517 wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL );
1518 if (button_sizer)
1519 main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 );
1520
1521 SetSizerAndFit( main_sizer );
1522 }
1523
1524 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
1525 {
1526 event.Skip( !m_catchListBoxDClick );
1527 }
1528
1529 void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(event))
1530 {
1531 m_catchListBoxDClick = !m_catchListBoxDClick;
1532 }
1533
1534 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event))
1535 {
1536 TestDefaultActionDialog dialog( this );
1537 dialog.ShowModal();
1538 }
1539
1540 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
1541 {
1542 Close(true);
1543 }
1544
1545 #if wxUSE_PROGRESSDLG
1546
1547 void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
1548 {
1549 static const int max = 100;
1550
1551 wxProgressDialog dialog(_T("Progress dialog example"),
1552 _T("An informative message"),
1553 max, // range
1554 this, // parent
1555 wxPD_CAN_ABORT |
1556 wxPD_CAN_SKIP |
1557 wxPD_APP_MODAL |
1558 // wxPD_AUTO_HIDE | -- try this as well
1559 wxPD_ELAPSED_TIME |
1560 wxPD_ESTIMATED_TIME |
1561 wxPD_REMAINING_TIME
1562 | wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
1563 );
1564
1565 bool cont = true;
1566 for ( int i = 0; i <= max; i++ )
1567 {
1568 wxMilliSleep(200);
1569
1570 wxString msg;
1571
1572 // test both modes of wxProgressDialog behaviour: start in
1573 // indeterminate mode but switch to the determinate one later
1574 const bool determinate = i > max/2;
1575
1576 if ( i == max )
1577 {
1578 msg = _T("That's all, folks!");
1579 }
1580 else if ( !determinate )
1581 {
1582 msg = _T("Testing indeterminate mode");
1583 }
1584 else if ( determinate )
1585 {
1586 msg = _T("Now in standard determinate mode");
1587 }
1588
1589 // will be set to true if "Skip" button was pressed
1590 bool skip = false;
1591 if ( determinate )
1592 {
1593 cont = dialog.Update(i, msg, &skip);
1594 }
1595 else
1596 {
1597 cont = dialog.Pulse(msg, &skip);
1598 }
1599
1600 // each skip will move progress about quarter forward
1601 if ( skip )
1602 i += max/4;
1603
1604 if ( !cont )
1605 {
1606 if ( wxMessageBox(_T("Do you really want to cancel?"),
1607 _T("Progress dialog question"), // caption
1608 wxYES_NO | wxICON_QUESTION) == wxYES )
1609 break;
1610
1611 cont = true;
1612 dialog.Resume();
1613 }
1614 }
1615
1616 if ( !cont )
1617 {
1618 wxLogStatus(wxT("Progress dialog aborted!"));
1619 }
1620 else
1621 {
1622 wxLogStatus(wxT("Countdown from %d finished"), max);
1623 }
1624 }
1625
1626 #endif // wxUSE_PROGRESSDLG
1627
1628 #if wxUSE_ABOUTDLG
1629
1630 static void InitAboutInfoMinimal(wxAboutDialogInfo& info)
1631 {
1632 info.SetName(_T("Dialogs Sample"));
1633 info.SetVersion(wxVERSION_NUM_DOT_STRING_T);
1634 info.SetDescription(_T("This sample shows different wxWidgets dialogs"));
1635 info.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
1636 info.AddDeveloper(_T("Vadim Zeitlin"));
1637 }
1638
1639 static void InitAboutInfoWebsite(wxAboutDialogInfo& info)
1640 {
1641 InitAboutInfoMinimal(info);
1642
1643 info.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1644 }
1645
1646 static void InitAboutInfoAll(wxAboutDialogInfo& info)
1647 {
1648 InitAboutInfoWebsite(info);
1649
1650 // we can add a second developer
1651 info.AddDeveloper(_T("A.N. Other"));
1652
1653 // or we can add several persons at once like this
1654 static const wxChar *docwriters[] =
1655 {
1656 _T("First D. Writer"),
1657 _T("Second One"),
1658 };
1659
1660 info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters));
1661 info.SetLicence(wxString::FromAscii(
1662 " wxWindows Library Licence, Version 3.1\n"
1663 " ======================================\n"
1664 "\n"
1665 " Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1666 "\n"
1667 " Everyone is permitted to copy and distribute verbatim copies\n"
1668 " of this licence document, but changing it is not allowed.\n"
1669 "\n"
1670 " WXWINDOWS LIBRARY LICENCE\n"
1671 " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1672 "\n"
1673 " ...and so on and so forth...\n"
1674 ));
1675
1676 info.AddTranslator(_T("Wun Ngo Wen (Martian)"));
1677 }
1678
1679 void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
1680 {
1681 wxAboutDialogInfo info;
1682 InitAboutInfoMinimal(info);
1683
1684 wxAboutBox(info);
1685 }
1686
1687 void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event))
1688 {
1689 wxAboutDialogInfo info;
1690 InitAboutInfoWebsite(info);
1691
1692 wxAboutBox(info);
1693 }
1694
1695 void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event))
1696 {
1697 wxAboutDialogInfo info;
1698 InitAboutInfoAll(info);
1699
1700 wxAboutBox(info);
1701 }
1702
1703 // a trivial example of a custom dialog class
1704 class MyAboutDialog : public wxGenericAboutDialog
1705 {
1706 public:
1707 MyAboutDialog(const wxAboutDialogInfo& info)
1708 {
1709 Create(info);
1710 }
1711
1712 // add some custom controls
1713 virtual void DoAddCustomControls()
1714 {
1715 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1716 AddText(_T("Some custom text"));
1717 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1718 }
1719 };
1720
1721 void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event))
1722 {
1723 wxAboutDialogInfo info;
1724 InitAboutInfoAll(info);
1725
1726 MyAboutDialog dlg(info);
1727 dlg.ShowModal();
1728 }
1729
1730 #endif // wxUSE_ABOUTDLG
1731
1732 #if wxUSE_BUSYINFO
1733
1734 void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
1735 {
1736 wxWindowDisabler disableAll;
1737
1738 wxBusyInfo info(_T("Working, please wait..."), this);
1739
1740 for ( int i = 0; i < 18; i++ )
1741 {
1742 //wxUsleep(100);
1743 wxTheApp->Yield();
1744 }
1745
1746 wxSleep(2);
1747 //wxWakeUpIdle();
1748 }
1749
1750 #endif // wxUSE_BUSYINFO
1751
1752 #if wxUSE_FINDREPLDLG
1753
1754 void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
1755 {
1756 if ( m_dlgReplace )
1757 {
1758 delete m_dlgReplace;
1759 m_dlgReplace = NULL;
1760 }
1761 else
1762 {
1763 m_dlgReplace = new wxFindReplaceDialog
1764 (
1765 this,
1766 &m_findData,
1767 _T("Find and replace dialog"),
1768 wxFR_REPLACEDIALOG
1769 );
1770
1771 m_dlgReplace->Show(true);
1772 }
1773 }
1774
1775 void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
1776 {
1777 if ( m_dlgFind )
1778 {
1779 delete m_dlgFind;
1780 m_dlgFind = NULL;
1781 }
1782 else
1783 {
1784 m_dlgFind = new wxFindReplaceDialog
1785 (
1786 this,
1787 &m_findData,
1788 _T("Find dialog"),
1789 // just for testing
1790 wxFR_NOWHOLEWORD
1791 );
1792
1793 m_dlgFind->Show(true);
1794 }
1795 }
1796
1797 static wxString DecodeFindDialogEventFlags(int flags)
1798 {
1799 wxString str;
1800 str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
1801 << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
1802 << (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
1803 << _T("case sensitive");
1804
1805 return str;
1806 }
1807
1808 void MyFrame::OnFindDialog(wxFindDialogEvent& event)
1809 {
1810 wxEventType type = event.GetEventType();
1811
1812 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
1813 {
1814 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1815 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
1816 event.GetFindString().c_str(),
1817 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1818 }
1819 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
1820 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
1821 {
1822 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1823 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
1824 event.GetFindString().c_str(),
1825 event.GetReplaceString().c_str(),
1826 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1827 }
1828 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
1829 {
1830 wxFindReplaceDialog *dlg = event.GetDialog();
1831
1832 int idMenu;
1833 const wxChar *txt;
1834 if ( dlg == m_dlgFind )
1835 {
1836 txt = _T("Find");
1837 idMenu = DIALOGS_FIND;
1838 m_dlgFind = NULL;
1839 }
1840 else if ( dlg == m_dlgReplace )
1841 {
1842 txt = _T("Replace");
1843 idMenu = DIALOGS_REPLACE;
1844 m_dlgReplace = NULL;
1845 }
1846 else
1847 {
1848 txt = _T("Unknown");
1849 idMenu = wxID_ANY;
1850
1851 wxFAIL_MSG( _T("unexpected event") );
1852 }
1853
1854 wxLogMessage(wxT("%s dialog is being closed."), txt);
1855
1856 if ( idMenu != wxID_ANY )
1857 {
1858 GetMenuBar()->Check(idMenu, false);
1859 }
1860
1861 dlg->Destroy();
1862 }
1863 else
1864 {
1865 wxLogError(wxT("Unknown find dialog event!"));
1866 }
1867 }
1868
1869 #endif // wxUSE_FINDREPLDLG
1870
1871 // ----------------------------------------------------------------------------
1872 // MyCanvas
1873 // ----------------------------------------------------------------------------
1874
1875 void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
1876 {
1877 wxPaintDC dc(this);
1878 dc.SetFont(wxGetApp().m_canvasFont);
1879 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
1880 dc.SetBackgroundMode(wxTRANSPARENT);
1881 dc.DrawText(
1882 _T("wxWidgets common dialogs")
1883 #if !defined(__SMARTPHONE__)
1884 _T(" test application")
1885 #endif
1886 , 10, 10);
1887 }
1888
1889 #if USE_MODAL_PRESENTATION
1890
1891 // ----------------------------------------------------------------------------
1892 // MyModelessDialog
1893 // ----------------------------------------------------------------------------
1894
1895 MyModelessDialog::MyModelessDialog(wxWindow *parent)
1896 : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog")))
1897 {
1898 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
1899
1900 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
1901 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled"));
1902 check->Disable();
1903
1904 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
1905 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
1906
1907 SetSizerAndFit(sizerTop);
1908 }
1909
1910 void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
1911 {
1912 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1913 wxOK | wxICON_INFORMATION, this);
1914 }
1915
1916 void MyModelessDialog::OnClose(wxCloseEvent& event)
1917 {
1918 if ( event.CanVeto() )
1919 {
1920 wxMessageBox(_T("Use the menu item to close this dialog"),
1921 _T("Modeless dialog"),
1922 wxOK | wxICON_INFORMATION, this);
1923
1924 event.Veto();
1925 }
1926 }
1927
1928 // ----------------------------------------------------------------------------
1929 // MyModalDialog
1930 // ----------------------------------------------------------------------------
1931
1932 MyModalDialog::MyModalDialog(wxWindow *parent)
1933 : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog")))
1934 {
1935 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1936
1937 m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog..."));
1938 m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog"));
1939 m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button"));
1940
1941 wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
1942 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
1943 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
1944 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
1945 sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
1946
1947 SetSizerAndFit(sizerTop);
1948
1949 m_btnModal->SetFocus();
1950 m_btnModal->SetDefault();
1951 }
1952
1953 void MyModalDialog::OnButton(wxCommandEvent& event)
1954 {
1955 if ( event.GetEventObject() == m_btnDelete )
1956 {
1957 delete m_btnModal;
1958 m_btnModal = NULL;
1959
1960 m_btnDelete->Disable();
1961 }
1962 else if ( event.GetEventObject() == m_btnModal )
1963 {
1964 #if wxUSE_TEXTDLG
1965 wxGetTextFromUser(_T("Dummy prompt"),
1966 _T("Modal dialog called from dialog"),
1967 wxEmptyString, this);
1968 #else
1969 wxMessageBox(_T("Modal dialog called from dialog"));
1970 #endif // wxUSE_TEXTDLG
1971 }
1972 else if ( event.GetEventObject() == m_btnModeless )
1973 {
1974 (new MyModelessDialog(this))->Show();
1975 }
1976 else
1977 {
1978 event.Skip();
1979 }
1980 }
1981
1982 #endif // USE_MODAL_PRESENTATION
1983
1984 // ----------------------------------------------------------------------------
1985 // StdButtonSizerDialog
1986 // ----------------------------------------------------------------------------
1987
1988 StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent)
1989 : wxDialog(parent, wxID_ANY, wxString(_T("StdButtonSizer dialog")),
1990 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
1991 m_buttonsSizer(NULL)
1992 {
1993 wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL);
1994
1995 wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL);
1996 wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL);
1997
1998 m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button"));
1999
2000 wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button"));
2001
2002 m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2003 m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes"));
2004
2005 wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL);
2006
2007 m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button"));
2008
2009 wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button"));
2010
2011 m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2012 m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close"));
2013
2014 wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL);
2015
2016 m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No"));
2017 m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help"));
2018 m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply"));
2019
2020 m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default"));
2021
2022 sizer1->Add(m_radiobtnOk, 0, wxALL, 5);
2023 sizer1->Add(m_radiobtnYes, 0, wxALL, 5);
2024
2025 sizer->Add(sizerInside1, 0, 0, 0);
2026 sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5);
2027 sizerInside1->Add(sizer1, 0, wxALL, 5);
2028 sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2029
2030 sizer2->Add(m_radiobtnCancel, 0, wxALL, 5);
2031 sizer2->Add(m_radiobtnClose, 0, wxALL, 5);
2032
2033 sizer->Add(sizerInside2, 0, 0, 0);
2034 sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5);
2035 sizerInside2->Add(sizer2, 0, wxALL, 5);
2036 sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2037
2038 sizerTop->Add(sizer, 0, wxALL, 5);
2039
2040 sizer3->Add(m_chkboxNo, 0, wxALL, 5);
2041 sizer3->Add(m_chkboxHelp, 0, wxALL, 5);
2042 sizer3->Add(m_chkboxApply, 0, wxALL, 5);
2043
2044 sizerTop->Add(sizer3, 0, wxALL, 5);
2045
2046 sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10);
2047
2048 EnableDisableControls();
2049
2050 SetSizerAndFit(sizerTop);
2051
2052 wxCommandEvent ev;
2053 OnEvent(ev);
2054 }
2055
2056 void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event))
2057 {
2058 if (m_buttonsSizer)
2059 {
2060 m_buttonsSizer->DeleteWindows();
2061 GetSizer()->Remove(m_buttonsSizer);
2062 }
2063
2064 EnableDisableControls();
2065
2066 long flags = 0;
2067 unsigned long numButtons = 0;
2068
2069 if (m_chkboxAffirmativeButton->IsChecked())
2070 {
2071 if (m_radiobtnOk->GetValue())
2072 {
2073 flags |= wxOK;
2074 numButtons ++;
2075 }
2076 else if (m_radiobtnYes->GetValue())
2077 {
2078 flags |= wxYES;
2079 numButtons ++;
2080 }
2081 }
2082
2083 if (m_chkboxDismissButton->IsChecked())
2084 {
2085 if (m_radiobtnCancel->GetValue())
2086 {
2087 flags |= wxCANCEL;
2088 numButtons ++;
2089 }
2090
2091 else if (m_radiobtnClose->GetValue())
2092 {
2093 flags |= wxCLOSE;
2094 numButtons ++;
2095 }
2096
2097 }
2098
2099 if (m_chkboxApply->IsChecked())
2100 {
2101 flags |= wxAPPLY;
2102 numButtons ++;
2103 }
2104
2105 if (m_chkboxNo->IsChecked())
2106 {
2107 flags |= wxNO;
2108 numButtons ++;
2109 }
2110
2111 if (m_chkboxHelp->IsChecked())
2112 {
2113 flags |= wxHELP;
2114 numButtons ++;
2115 }
2116
2117 if (m_chkboxNoDefault->IsChecked())
2118 {
2119 flags |= wxNO_DEFAULT;
2120 }
2121
2122 m_buttonsSizer = CreateStdDialogButtonSizer(flags);
2123 GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5);
2124
2125 Layout();
2126 GetSizer()->SetSizeHints(this);
2127 }
2128
2129 void StdButtonSizerDialog::EnableDisableControls()
2130 {
2131 const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked();
2132
2133 m_radiobtnOk->Enable(affButtonEnabled);
2134 m_radiobtnYes->Enable(affButtonEnabled);
2135
2136 const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked();
2137
2138 m_radiobtnCancel->Enable(dismissButtonEnabled);
2139 m_radiobtnClose->Enable(dismissButtonEnabled);
2140 }
2141
2142 #if USE_SETTINGS_DIALOG
2143 // ----------------------------------------------------------------------------
2144 // SettingsDialog
2145 // ----------------------------------------------------------------------------
2146
2147 IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
2148
2149 BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
2150 END_EVENT_TABLE()
2151
2152 SettingsDialog::SettingsDialog(wxWindow* win, int dialogType)
2153 {
2154 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
2155
2156 int tabImage1 = -1;
2157 int tabImage2 = -1;
2158
2159 bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK);
2160 int resizeBorder = wxRESIZE_BORDER;
2161
2162 if (useToolBook)
2163 {
2164 resizeBorder = 0;
2165 tabImage1 = 0;
2166 tabImage2 = 1;
2167
2168 int sheetStyle = wxPROPSHEET_SHRINKTOFIT;
2169 if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK)
2170 sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK;
2171 else
2172 sheetStyle |= wxPROPSHEET_TOOLBOOK;
2173
2174 SetSheetStyle(sheetStyle);
2175 SetSheetInnerBorder(0);
2176 SetSheetOuterBorder(0);
2177
2178 // create a dummy image list with a few icons
2179 const wxSize imageSize(32, 32);
2180
2181 m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
2182 m_imageList->
2183 Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
2184 m_imageList->
2185 Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize));
2186 m_imageList->
2187 Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize));
2188 m_imageList->
2189 Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize));
2190 }
2191 else
2192 m_imageList = NULL;
2193
2194 Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
2195 wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder)
2196 );
2197
2198 // If using a toolbook, also follow Mac style and don't create buttons
2199 if (!useToolBook)
2200 CreateButtons(wxOK | wxCANCEL |
2201 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP)
2202 );
2203
2204 wxBookCtrlBase* notebook = GetBookCtrl();
2205 notebook->SetImageList(m_imageList);
2206
2207 wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
2208 wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
2209
2210 notebook->AddPage(generalSettings, _("General"), true, tabImage1);
2211 notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2);
2212
2213 LayoutDialog();
2214 }
2215
2216 SettingsDialog::~SettingsDialog()
2217 {
2218 delete m_imageList;
2219 }
2220
2221 wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
2222 {
2223 wxPanel* panel = new wxPanel(parent, wxID_ANY);
2224
2225 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
2226 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
2227
2228 //// LOAD LAST FILE
2229
2230 wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
2231 wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize);
2232 itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2233 item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
2234
2235 //// AUTOSAVE
2236
2237 wxString autoSaveLabel = _("&Auto-save every");
2238 wxString minsLabel = _("mins");
2239
2240 wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
2241 wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
2242
2243 #if wxUSE_SPINCTRL
2244 wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
2245 wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1);
2246 #endif
2247
2248 itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2249 #if wxUSE_SPINCTRL
2250 itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2251 #endif
2252 itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2253 item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
2254
2255 //// TOOLTIPS
2256
2257 wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
2258 wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize);
2259 itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2260 item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
2261
2262 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
2263
2264 panel->SetSizerAndFit(topSizer);
2265
2266 return panel;
2267 }
2268
2269 wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
2270 {
2271 wxPanel* panel = new wxPanel(parent, wxID_ANY);
2272
2273 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
2274 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
2275
2276 //// PROJECT OR GLOBAL
2277 wxString globalOrProjectChoices[2];
2278 globalOrProjectChoices[0] = _("&New projects");
2279 globalOrProjectChoices[1] = _("&This project");
2280
2281 wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"),
2282 wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
2283 item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
2284
2285 projectOrGlobal->SetSelection(0);
2286
2287 //// BACKGROUND STYLE
2288 wxArrayString backgroundStyleChoices;
2289 backgroundStyleChoices.Add(wxT("Colour"));
2290 backgroundStyleChoices.Add(wxT("Image"));
2291 wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:"));
2292
2293 wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
2294 item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
2295
2296 wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
2297
2298 wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
2299
2300 itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2301 itemSizer2->Add(5, 5, 1, wxALL, 0);
2302 itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2303
2304 styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
2305
2306 #if wxUSE_SPINCTRL
2307 //// FONT SIZE SELECTION
2308
2309 wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:"));
2310 wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
2311
2312 wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition,
2313 wxSize(80, wxDefaultCoord));
2314 itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
2315
2316 item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
2317 #endif
2318
2319 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
2320 topSizer->AddSpacer(5);
2321
2322 panel->SetSizerAndFit(topSizer);
2323
2324 return panel;
2325 }
2326
2327 // ----------------------------------------------------------------------------
2328 // TestMessageBoxDialog
2329 // ----------------------------------------------------------------------------
2330
2331 /* static */
2332 const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] =
2333 {
2334 { wxYES, "&Yes" },
2335 { wxNO, "&No" },
2336 { wxOK, "&Ok" },
2337 { wxCANCEL, "&Cancel" },
2338 };
2339
2340 BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog)
2341 EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply)
2342 EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose)
2343 END_EVENT_TABLE()
2344
2345 TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent)
2346 : wxDialog(parent, wxID_ANY, "Message Box Test Dialog",
2347 wxDefaultPosition, wxDefaultSize,
2348 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
2349 {
2350 wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
2351
2352 // this sizer allows to configure the messages shown in the message box
2353 wxSizer * const
2354 sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages");
2355 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:"));
2356 m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!",
2357 wxDefaultPosition, wxDefaultSize,
2358 wxTE_MULTILINE);
2359 sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM));
2360
2361 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:"));
2362 m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "",
2363 wxDefaultPosition, wxDefaultSize,
2364 wxTE_MULTILINE);
2365 sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand());
2366
2367 sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
2368
2369
2370 // this one is for configuring the buttons
2371 wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5);
2372 sizerBtns->AddGrowableCol(1);
2373
2374 sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)"));
2375 sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label"));
2376
2377 for ( int n = 0; n < Btn_Max; n++ )
2378 {
2379 m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name);
2380 sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left());
2381
2382 m_labels[n] = new wxTextCtrl(this, wxID_ANY);
2383 sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand());
2384
2385 m_labels[n]->Connect(wxEVT_UPDATE_UI,
2386 wxUpdateUIEventHandler(
2387 TestMessageBoxDialog::OnUpdateLabelUI),
2388 NULL,
2389 this);
2390 }
2391
2392 wxSizer * const
2393 sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons");
2394 sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand());
2395 sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border());
2396
2397
2398 // icon choice
2399 const wxString icons[] = {
2400 "&Information", "&Question", "&Warning", "&Error"
2401 };
2402
2403 m_icons = new wxRadioBox(this, wxID_ANY, "&Icon:",
2404 wxDefaultPosition, wxDefaultSize,
2405 WXSIZEOF(icons), icons);
2406 sizerTop->Add(m_icons, wxSizerFlags().Expand().Border());
2407
2408
2409 // miscellaneous other stuff
2410 wxSizer * const
2411 sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags");
2412
2413 m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default");
2414 m_chkNoDefault->Connect(wxEVT_UPDATE_UI,
2415 wxUpdateUIEventHandler(
2416 TestMessageBoxDialog::OnUpdateNoDefaultUI),
2417 NULL,
2418 this);
2419 sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border());
2420
2421 m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent");
2422 sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border());
2423
2424 sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border());
2425
2426 // finally buttons to show the resulting message box and close this dialog
2427 sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE),
2428 wxSizerFlags().Right().Border());
2429
2430 SetSizerAndFit(sizerTop);
2431
2432 m_buttons[Btn_Ok]->SetValue(true);
2433 }
2434
2435 void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event)
2436 {
2437 for ( int n = 0; n < Btn_Max; n++ )
2438 {
2439 if ( event.GetEventObject() == m_labels[n] )
2440 {
2441 event.Enable( m_buttons[n]->IsChecked() );
2442 return;
2443 }
2444 }
2445
2446 wxFAIL_MSG( "called for unknown label" );
2447 }
2448
2449 void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event)
2450 {
2451 event.Enable( m_buttons[Btn_No]->IsChecked() );
2452 }
2453
2454 void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
2455 {
2456 long style = 0;
2457
2458 for ( int n = 0; n < Btn_Max; n++ )
2459 {
2460 if ( m_buttons[n]->IsChecked() )
2461 style |= ms_btnInfo[n].flag;
2462 }
2463
2464 switch ( m_icons->GetSelection() )
2465 {
2466 case 0: style |= wxICON_INFORMATION; break;
2467 case 1: style |= wxICON_QUESTION; break;
2468 case 2: style |= wxICON_WARNING; break;
2469 case 3: style |= wxICON_ERROR; break;
2470 }
2471
2472 if ( m_chkCentre->IsChecked() )
2473 style |= wxCENTRE;
2474
2475 if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() )
2476 style |= wxNO_DEFAULT;
2477
2478
2479 wxMessageDialog dlg(this, m_textMsg->GetValue(), "Test Message Box",
2480 style);
2481 if ( !m_textExtMsg->IsEmpty() )
2482 dlg.SetExtendedMessage(m_textExtMsg->GetValue());
2483
2484 if ( style & wxYES_NO )
2485 {
2486 if ( style & wxCANCEL )
2487 {
2488 dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(),
2489 m_labels[Btn_No]->GetValue(),
2490 m_labels[Btn_Cancel]->GetValue());
2491 }
2492 else
2493 {
2494 dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(),
2495 m_labels[Btn_No]->GetValue());
2496 }
2497 }
2498 else
2499 {
2500 if ( style & wxCANCEL )
2501 {
2502 dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(),
2503 m_labels[Btn_Cancel]->GetValue());
2504 }
2505 else
2506 {
2507 dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue());
2508 }
2509 }
2510
2511 dlg.ShowModal();
2512 }
2513
2514 void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event))
2515 {
2516 EndModal(wxID_CANCEL);
2517 }
2518
2519 #endif // USE_SETTINGS_DIALOG
2520
2521 #if wxUSE_LOG
2522
2523 // ----------------------------------------------------------------------------
2524 // custom log target
2525 // ----------------------------------------------------------------------------
2526
2527 class MyLogGui : public wxLogGui
2528 {
2529 private:
2530 virtual void DoShowSingleLogMessage(const wxString& message,
2531 const wxString& title,
2532 int style)
2533 {
2534 wxMessageDialog dlg(NULL, message, title,
2535 wxOK | wxCANCEL | wxCANCEL_DEFAULT | style);
2536 dlg.SetOKCancelLabels(wxID_COPY, wxID_OK);
2537 dlg.SetExtendedMessage("Note that this is a custom log dialog.");
2538 dlg.ShowModal();
2539 }
2540 };
2541
2542 wxLog *MyAppTraits::CreateLogTarget()
2543 {
2544 return new MyLogGui;
2545 }
2546
2547 #endif // wxUSE_LOG