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