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