]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialogs.cpp | |
3 | // Purpose: Common dialogs demo | |
5b05ce47 | 4 | // Author: Julian Smart, Vadim Zeitlin, ABX |
457814b5 JS |
5 | // Created: 04/01/98 |
6 | // RCS-ID: $Id$ | |
6aa89a22 | 7 | // Copyright: (c) Julian Smart |
5b05ce47 VZ |
8 | // (c) 2004 ABX |
9 | // (c) Vadim Zeitlin | |
c50f1fb9 | 10 | // Licence: wxWindows license |
457814b5 JS |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
457814b5 JS |
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 | ||
0f5d8ecf JS |
24 | #include "../sample.xpm" |
25 | ||
9ad2fe62 | 26 | #include "wx/apptrait.h" |
fb8a56b7 | 27 | #include "wx/datetime.h" |
f517634c | 28 | #include "wx/image.h" |
5378558e | 29 | #include "wx/bookctrl.h" |
cc8bc5aa | 30 | #include "wx/artprov.h" |
2b923807 | 31 | #include "wx/imaglist.h" |
1baa0a9d | 32 | #include "wx/minifram.h" |
684883e3 | 33 | #include "wx/sysopt.h" |
e36a1739 | 34 | #include "wx/notifmsg.h" |
457814b5 | 35 | |
13188def WS |
36 | #if wxUSE_COLOURDLG |
37 | #include "wx/colordlg.h" | |
38 | #endif // wxUSE_COLOURDLG | |
dfad0599 | 39 | |
13188def WS |
40 | #if wxUSE_CHOICEDLG |
41 | #include "wx/choicdlg.h" | |
42 | #endif // wxUSE_CHOICEDLG | |
457814b5 | 43 | |
5a5f305a VZ |
44 | #include "wx/rearrangectrl.h" |
45 | ||
13188def WS |
46 | #if wxUSE_STARTUP_TIPS |
47 | #include "wx/tipdlg.h" | |
48 | #endif // wxUSE_STARTUP_TIPS | |
d7d17624 | 49 | |
13188def | 50 | #if wxUSE_PROGRESSDLG |
9b16ffef | 51 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
b20edf8b | 52 | #include "wx/datetime.h" // wxDateTime |
9b16ffef VZ |
53 | #endif |
54 | ||
13188def WS |
55 | #include "wx/progdlg.h" |
56 | #endif // wxUSE_PROGRESSDLG | |
57 | ||
ca7adbf8 VZ |
58 | #if wxUSE_ABOUTDLG |
59 | #include "wx/aboutdlg.h" | |
453c9e3b VZ |
60 | |
61 | // these headers are only needed for custom about dialog | |
62 | #include "wx/statline.h" | |
63 | #include "wx/generic/aboutdlgg.h" | |
ca7adbf8 VZ |
64 | #endif // wxUSE_ABOUTDLG |
65 | ||
13188def WS |
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 | |
4ad3c82f | 89 | |
a92b5dfe VZ |
90 | #if wxUSE_INFOBAR |
91 | #include "wx/infobar.h" | |
92 | #endif // wxUSE_INFOBAR | |
93 | ||
0f5d8ecf JS |
94 | #include "wx/spinctrl.h" |
95 | #include "wx/propdlg.h" | |
96 | ||
457814b5 JS |
97 | #include "dialogs.h" |
98 | ||
13188def WS |
99 | #if USE_COLOURDLG_GENERIC |
100 | #include "wx/generic/colrdlgg.h" | |
101 | #endif // USE_COLOURDLG_GENERIC | |
102 | ||
13188def WS |
103 | #if USE_DIRDLG_GENERIC |
104 | #include "wx/generic/dirdlgg.h" | |
105 | #endif // USE_DIRDLG_GENERIC | |
106 | ||
695fe764 WS |
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 | ||
457814b5 JS |
115 | IMPLEMENT_APP(MyApp) |
116 | ||
4c45f240 VZ |
117 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
118 | EVT_PAINT(MyCanvas::OnPaint) | |
119 | END_EVENT_TABLE() | |
120 | ||
13188def WS |
121 | |
122 | ||
4c45f240 | 123 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
8cf304f8 | 124 | #if wxUSE_MSGDLG |
13188def | 125 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) |
86c3808c | 126 | EVT_MENU(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, MyFrame::MessageBoxWindowModal) |
44b25eac | 127 | EVT_MENU(DIALOGS_MESSAGE_DIALOG, MyFrame::MessageBoxDialog) |
8cf304f8 VZ |
128 | EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo) |
129 | #endif // wxUSE_MSGDLG | |
13188def | 130 | #if wxUSE_COLOURDLG |
4c45f240 | 131 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) |
e6ef9ea4 | 132 | EVT_MENU(DIALOGS_GET_COLOUR, MyFrame::GetColour) |
13188def WS |
133 | #endif // wxUSE_COLOURDLG |
134 | ||
135 | #if wxUSE_FONTDLG | |
4c45f240 | 136 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) |
13188def WS |
137 | #endif // wxUSE_FONTDLG |
138 | ||
139 | #if wxUSE_LOG_DIALOG | |
4c45f240 | 140 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) |
13188def | 141 | #endif // wxUSE_LOG_DIALOG |
a92b5dfe VZ |
142 | #if wxUSE_INFOBAR |
143 | EVT_MENU(DIALOGS_INFOBAR_SIMPLE, MyFrame::InfoBarSimple) | |
144 | EVT_MENU(DIALOGS_INFOBAR_ADVANCED, MyFrame::InfoBarAdvanced) | |
145 | #endif // wxUSE_INFOBAR | |
13188def WS |
146 | |
147 | #if wxUSE_TEXTDLG | |
4c45f240 VZ |
148 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) |
149 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
13188def WS |
150 | #endif // wxUSE_TEXTDLG |
151 | ||
152 | #if wxUSE_NUMBERDLG | |
4c45f240 | 153 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) |
13188def WS |
154 | #endif // wxUSE_NUMBERDLG |
155 | ||
156 | #if wxUSE_CHOICEDLG | |
4c45f240 | 157 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) |
d6c9c1b7 | 158 | EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice) |
13188def WS |
159 | #endif // wxUSE_CHOICEDLG |
160 | ||
81496fea | 161 | #if wxUSE_REARRANGECTRL |
5a5f305a | 162 | EVT_MENU(DIALOGS_REARRANGE, MyFrame::Rearrange) |
81496fea | 163 | #endif // wxUSE_REARRANGECTRL |
5a5f305a | 164 | |
13188def | 165 | #if wxUSE_FILEDLG |
4c45f240 | 166 | EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) |
35b45b33 | 167 | EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) |
4c45f240 VZ |
168 | EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) |
169 | EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) | |
13188def WS |
170 | #endif // wxUSE_FILEDLG |
171 | ||
695fe764 WS |
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 | ||
13188def | 178 | #if wxUSE_DIRDLG |
4c45f240 | 179 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) |
f09c8393 | 180 | EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew) |
13188def WS |
181 | #endif // wxUSE_DIRDLG |
182 | ||
183 | #if USE_MODAL_PRESENTATION | |
f6bcfd97 | 184 | EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg) |
1baa0a9d | 185 | #endif // USE_MODAL_PRESENTATION |
4c45f240 | 186 | EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg) |
cae50e6b VZ |
187 | EVT_MENU(DIALOGS_CENTRE_SCREEN, MyFrame::DlgCenteredScreen) |
188 | EVT_MENU(DIALOGS_CENTRE_PARENT, MyFrame::DlgCenteredParent) | |
81496fea | 189 | #if wxUSE_MINIFRAME |
1baa0a9d | 190 | EVT_MENU(DIALOGS_MINIFRAME, MyFrame::MiniFrame) |
81496fea | 191 | #endif // wxUSE_MINIFRAME |
8e5dbcdd | 192 | EVT_MENU(DIALOGS_ONTOP, MyFrame::DlgOnTop) |
13188def WS |
193 | |
194 | #if wxUSE_STARTUP_TIPS | |
4c45f240 | 195 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) |
13188def WS |
196 | #endif // wxUSE_STARTUP_TIPS |
197 | ||
198 | #if USE_FONTDLG_GENERIC | |
4c45f240 | 199 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) |
13188def WS |
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 | |
a62b0bcc | 209 | |
abceee76 VZ |
210 | #if wxUSE_PROGRESSDLG |
211 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
761989ff | 212 | #endif // wxUSE_PROGRESSDLG |
a62b0bcc | 213 | |
ca7adbf8 VZ |
214 | #if wxUSE_ABOUTDLG |
215 | EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog) | |
216 | EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog) | |
453c9e3b VZ |
217 | EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog) |
218 | EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog) | |
ca7adbf8 VZ |
219 | #endif // wxUSE_ABOUTDLG |
220 | ||
a62b0bcc VZ |
221 | #if wxUSE_BUSYINFO |
222 | EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo) | |
223 | #endif // wxUSE_BUSYINFO | |
224 | ||
761989ff VZ |
225 | #if wxUSE_FINDREPLDLG |
226 | EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog) | |
227 | EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog) | |
228 | ||
13188def WS |
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) | |
761989ff | 234 | #endif // wxUSE_FINDREPLDLG |
13188def | 235 | |
532d575b | 236 | #if USE_SETTINGS_DIALOG |
0f5d8ecf | 237 | EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet) |
64d3ed17 JS |
238 | EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheet) |
239 | EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet) | |
e36a1739 | 240 | #endif // USE_SETTINGS_DIALOG |
532d575b | 241 | |
8e1dac82 | 242 | EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog) |
a625c5b6 | 243 | EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION, MyFrame::OnTestDefaultActionDialog) |
e36a1739 | 244 | |
0f5d8ecf | 245 | EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) |
e36a1739 VZ |
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 | |
9b16ffef | 251 | |
4c45f240 | 252 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) |
4c45f240 | 253 | END_EVENT_TABLE() |
abceee76 | 254 | |
13188def | 255 | #if USE_MODAL_PRESENTATION |
f6bcfd97 | 256 | |
13188def WS |
257 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) |
258 | EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton) | |
259 | END_EVENT_TABLE() | |
5d987909 | 260 | |
13188def WS |
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 | |
abceee76 | 267 | |
8e1dac82 VZ |
268 | BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog) |
269 | EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent) | |
270 | EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent) | |
271 | END_EVENT_TABLE() | |
272 | ||
457814b5 | 273 | // `Main program' equivalent, creating windows and returning main app frame |
4c45f240 | 274 | bool MyApp::OnInit() |
457814b5 | 275 | { |
45e6e6f8 VZ |
276 | if ( !wxApp::OnInit() ) |
277 | return false; | |
278 | ||
f517634c | 279 | #if wxUSE_IMAGE |
013e1fee | 280 | wxInitAllImageHandlers(); |
f517634c | 281 | #endif |
013e1fee | 282 | |
13188def | 283 | // Create the main frame window |
5b05ce47 | 284 | MyFrame *frame = new MyFrame(wxT("wxWidgets dialogs example")); |
457814b5 | 285 | |
13188def | 286 | // Make a menubar |
ca7adbf8 | 287 | wxMenu *menuDlg = new wxMenu; |
dabbc6a5 | 288 | |
9a83f860 | 289 | menuDlg->Append(DIALOGS_MESSAGE_BOX, wxT("&Message box\tCtrl-M")); |
86c3808c | 290 | menuDlg->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, wxT("Window-Modal Message box ")); |
9a83f860 | 291 | menuDlg->Append(DIALOGS_MESSAGE_DIALOG, wxT("Message dialog\tShift-Ctrl-M")); |
457814b5 | 292 | |
457814b5 | 293 | |
33bcca32 | 294 | #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG |
f09c8393 | 295 | |
33bcca32 | 296 | wxMenu *choices_menu = new wxMenu; |
f09c8393 | 297 | |
33bcca32 | 298 | #if wxUSE_COLOURDLG |
9a83f860 VZ |
299 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR, wxT("&Choose bg colour")); |
300 | choices_menu->Append(DIALOGS_GET_COLOUR, wxT("&Choose fg colour")); | |
33bcca32 | 301 | #endif // wxUSE_COLOURDLG |
f09c8393 | 302 | |
33bcca32 | 303 | #if wxUSE_FONTDLG |
9a83f860 | 304 | choices_menu->Append(DIALOGS_CHOOSE_FONT, wxT("Choose &font")); |
33bcca32 | 305 | #endif // wxUSE_FONTDLG |
457814b5 | 306 | |
33bcca32 | 307 | #if wxUSE_CHOICEDLG |
9a83f860 VZ |
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")); | |
33bcca32 | 310 | #endif // wxUSE_CHOICEDLG |
695fe764 | 311 | |
81496fea | 312 | #if wxUSE_REARRANGECTRL |
9a83f860 | 313 | choices_menu->Append(DIALOGS_REARRANGE, wxT("&Rearrange dialog\tCtrl-R")); |
81496fea | 314 | #endif // wxUSE_REARRANGECTRL |
5a5f305a | 315 | |
33bcca32 VZ |
316 | #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC |
317 | choices_menu->AppendSeparator(); | |
318 | #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
695fe764 | 319 | |
33bcca32 | 320 | #if USE_COLOURDLG_GENERIC |
9a83f860 | 321 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, wxT("&Choose colour (generic)")); |
33bcca32 | 322 | #endif // USE_COLOURDLG_GENERIC |
695fe764 | 323 | |
33bcca32 | 324 | #if USE_FONTDLG_GENERIC |
9a83f860 | 325 | choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, wxT("Choose &font (generic)")); |
33bcca32 | 326 | #endif // USE_FONTDLG_GENERIC |
d93c719a | 327 | |
9a83f860 | 328 | menuDlg->Append(wxID_ANY,wxT("&Choices and selectors"),choices_menu); |
33bcca32 | 329 | #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG |
457814b5 | 330 | |
457814b5 | 331 | |
33bcca32 | 332 | #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG |
13188def | 333 | |
33bcca32 | 334 | wxMenu *entry_menu = new wxMenu; |
13188def | 335 | |
33bcca32 | 336 | #if wxUSE_TEXTDLG |
9a83f860 VZ |
337 | entry_menu->Append(DIALOGS_TEXT_ENTRY, wxT("Text &entry\tCtrl-E")); |
338 | entry_menu->Append(DIALOGS_PASSWORD_ENTRY, wxT("&Password entry\tCtrl-P")); | |
33bcca32 | 339 | #endif // wxUSE_TEXTDLG |
13188def | 340 | |
33bcca32 | 341 | #if wxUSE_NUMBERDLG |
9a83f860 | 342 | entry_menu->Append(DIALOGS_NUM_ENTRY, wxT("&Numeric entry\tCtrl-N")); |
33bcca32 | 343 | #endif // wxUSE_NUMBERDLG |
13188def | 344 | |
9a83f860 | 345 | menuDlg->Append(wxID_ANY,wxT("&Entry dialogs"),entry_menu); |
13188def | 346 | |
33bcca32 | 347 | #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG |
13188def WS |
348 | |
349 | ||
33bcca32 | 350 | #if wxUSE_FILEDLG |
13188def | 351 | |
33bcca32 | 352 | wxMenu *filedlg_menu = new wxMenu; |
9a83f860 VZ |
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")); | |
695fe764 | 357 | |
8ce68f7f VZ |
358 | #if USE_FILEDLG_GENERIC |
359 | filedlg_menu->AppendSeparator(); | |
9a83f860 VZ |
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)")); | |
8ce68f7f | 363 | #endif // USE_FILEDLG_GENERIC |
695fe764 | 364 | |
9a83f860 | 365 | menuDlg->Append(wxID_ANY,wxT("&File operations"),filedlg_menu); |
13188def | 366 | |
33bcca32 | 367 | #endif // wxUSE_FILEDLG |
13188def | 368 | |
33bcca32 VZ |
369 | #if wxUSE_DIRDLG |
370 | wxMenu *dir_menu = new wxMenu; | |
13188def | 371 | |
9a83f860 VZ |
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); | |
13188def | 375 | |
33bcca32 VZ |
376 | #if USE_DIRDLG_GENERIC |
377 | dir_menu->AppendSeparator(); | |
9a83f860 | 378 | dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, wxT("&Choose a directory (generic)")); |
33bcca32 | 379 | #endif // USE_DIRDLG_GENERIC |
13188def | 380 | |
33bcca32 | 381 | #endif // wxUSE_DIRDLG |
13188def WS |
382 | |
383 | ||
8cf304f8 VZ |
384 | #if wxUSE_STARTUP_TIPS || \ |
385 | wxUSE_PROGRESSDLG || \ | |
386 | wxUSE_BUSYINFO || \ | |
387 | wxUSE_LOG_DIALOG || \ | |
388 | wxUSE_MSGDLG | |
13188def | 389 | |
33bcca32 | 390 | wxMenu *info_menu = new wxMenu; |
13188def | 391 | |
33bcca32 | 392 | #if wxUSE_STARTUP_TIPS |
9a83f860 | 393 | info_menu->Append(DIALOGS_TIP, wxT("&Tip of the day\tCtrl-T")); |
33bcca32 | 394 | #endif // wxUSE_STARTUP_TIPS |
13188def | 395 | |
33bcca32 | 396 | #if wxUSE_PROGRESSDLG |
9a83f860 | 397 | info_menu->Append(DIALOGS_PROGRESS, wxT("Pro&gress dialog\tCtrl-G")); |
33bcca32 | 398 | #endif // wxUSE_PROGRESSDLG |
13188def | 399 | |
33bcca32 | 400 | #if wxUSE_BUSYINFO |
9a83f860 | 401 | info_menu->Append(DIALOGS_BUSYINFO, wxT("&Busy info dialog\tCtrl-B")); |
33bcca32 | 402 | #endif // wxUSE_BUSYINFO |
13188def | 403 | |
33bcca32 | 404 | #if wxUSE_LOG_DIALOG |
9a83f860 | 405 | info_menu->Append(DIALOGS_LOG_DIALOG, wxT("&Log dialog\tCtrl-L")); |
33bcca32 | 406 | #endif // wxUSE_LOG_DIALOG |
13188def | 407 | |
a92b5dfe VZ |
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 | ||
8cf304f8 VZ |
413 | #if wxUSE_MSGDLG |
414 | info_menu->Append(DIALOGS_MESSAGE_BOX_WXINFO, | |
a92b5dfe | 415 | wxT("&wxWidgets information\tCtrl-W")); |
8cf304f8 VZ |
416 | #endif // wxUSE_MSGDLG |
417 | ||
9a83f860 | 418 | menuDlg->Append(wxID_ANY,wxT("&Informative dialogs"),info_menu); |
13188def | 419 | |
33bcca32 | 420 | #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG |
13188def WS |
421 | |
422 | ||
33bcca32 VZ |
423 | #if wxUSE_FINDREPLDLG |
424 | wxMenu *find_menu = new wxMenu; | |
9a83f860 VZ |
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); | |
33bcca32 | 428 | #endif // wxUSE_FINDREPLDLG |
13188def | 429 | |
cae50e6b | 430 | wxMenu *dialogs_menu = new wxMenu; |
1baa0a9d | 431 | #if USE_MODAL_PRESENTATION |
a92b5dfe | 432 | dialogs_menu->Append(DIALOGS_MODAL, wxT("&Modal dialog\tShift-Ctrl-W")); |
1baa0a9d | 433 | #endif // USE_MODAL_PRESENTATION |
a92b5dfe | 434 | dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, wxT("Mode&less dialog\tShift-Ctrl-Z")); |
9a83f860 VZ |
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")); | |
81496fea | 437 | #if wxUSE_MINIFRAME |
9a83f860 | 438 | dialogs_menu->Append(DIALOGS_MINIFRAME, wxT("&Mini frame")); |
81496fea | 439 | #endif // wxUSE_MINIFRAME |
9a83f860 VZ |
440 | dialogs_menu->Append(DIALOGS_ONTOP, wxT("Dialog staying on &top")); |
441 | menuDlg->Append(wxID_ANY, wxT("&Generic dialogs"), dialogs_menu); | |
13188def | 442 | |
532d575b | 443 | #if USE_SETTINGS_DIALOG |
b40bb73e | 444 | wxMenu *sheet_menu = new wxMenu; |
9a83f860 VZ |
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")); | |
e031f1df | 447 | |
5c351979 | 448 | if (wxPlatformIs(wxPORT_MAC)) |
9a83f860 | 449 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U")); |
230c9077 | 450 | /* |
b887dc7b | 451 | #ifdef __WXMAC__ |
9a83f860 | 452 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U")); |
b887dc7b | 453 | #endif |
230c9077 | 454 | */ |
9a83f860 | 455 | menuDlg->Append(wxID_ANY, wxT("&Property sheets"), sheet_menu); |
b40bb73e | 456 | #endif // USE_SETTINGS_DIALOG |
532d575b | 457 | |
e36a1739 | 458 | wxMenu *menuNotif = new wxMenu; |
9a83f860 | 459 | menuNotif->Append(DIALOGS_REQUEST, wxT("&Request user attention\tCtrl-Shift-R")); |
e36a1739 VZ |
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"); | |
8e1dac82 | 466 | |
9a83f860 VZ |
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")); | |
ca7adbf8 VZ |
469 | |
470 | menuDlg->AppendSeparator(); | |
9a83f860 | 471 | menuDlg->Append(wxID_EXIT, wxT("E&xit\tAlt-X")); |
9b16ffef | 472 | |
ca7adbf8 VZ |
473 | #if wxUSE_ABOUTDLG |
474 | wxMenu *menuHelp = new wxMenu; | |
9a83f860 VZ |
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")); | |
ca7adbf8 | 479 | #endif // wxUSE_ABOUTDLG |
13188def | 480 | |
ca7adbf8 | 481 | wxMenuBar *menubar = new wxMenuBar; |
9a83f860 | 482 | menubar->Append(menuDlg, wxT("&Dialogs")); |
ca7adbf8 | 483 | #if wxUSE_ABOUTDLG |
9a83f860 | 484 | menubar->Append(menuHelp, wxT("&Help")); |
ca7adbf8 VZ |
485 | #endif // wxUSE_ABOUTDLG |
486 | ||
487 | frame->SetMenuBar(menubar); | |
13188def | 488 | |
13188def | 489 | frame->Centre(wxBOTH); |
13188def WS |
490 | frame->Show(true); |
491 | ||
13188def | 492 | return true; |
457814b5 JS |
493 | } |
494 | ||
495 | // My frame constructor | |
5b05ce47 VZ |
496 | MyFrame::MyFrame(const wxString& title) |
497 | : wxFrame(NULL, wxID_ANY, title) | |
4c45f240 | 498 | { |
0f5d8ecf | 499 | SetIcon(sample_xpm); |
532d575b | 500 | |
13188def | 501 | #if USE_MODAL_PRESENTATION |
4c45f240 | 502 | m_dialog = (MyModelessDialog *)NULL; |
13188def | 503 | #endif // USE_MODAL_PRESENTATION |
f1e1ed3b | 504 | |
043dcdaa | 505 | #if wxUSE_FINDREPLDLG |
14fca738 VZ |
506 | m_dlgFind = |
507 | m_dlgReplace = NULL; | |
043dcdaa | 508 | #endif |
dabbc6a5 DS |
509 | |
510 | #if wxUSE_COLOURDLG | |
d33dd9ef | 511 | m_clrData.SetChooseFull(true); |
e6ef9ea4 | 512 | for (int i = 0; i < wxColourData::NUM_CUSTOM; i++) |
d33dd9ef | 513 | { |
e6ef9ea4 VZ |
514 | unsigned char n = i*16; |
515 | m_clrData.SetCustomColour(i, wxColour(n, n, n)); | |
d33dd9ef | 516 | } |
13188def | 517 | #endif // wxUSE_COLOURDLG |
f9d0e439 | 518 | |
e36a1739 VZ |
519 | #if wxUSE_NOTIFICATION_MESSAGE |
520 | m_notifMsg = NULL; | |
521 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
522 | ||
f9d0e439 VZ |
523 | #if wxUSE_STATUSBAR |
524 | CreateStatusBar(); | |
525 | #endif // wxUSE_STATUSBAR | |
87a18679 VZ |
526 | |
527 | m_canvas = new MyCanvas(this); | |
a92b5dfe VZ |
528 | |
529 | #if wxUSE_INFOBAR | |
374ae80f | 530 | // an info bar can be created very simply and used without any extra effort |
a92b5dfe | 531 | m_infoBarSimple = new wxInfoBar(this); |
374ae80f | 532 | |
c0945eb2 | 533 | // or it can also be customized by |
374ae80f | 534 | m_infoBarAdvanced = new wxInfoBar(this); |
c0945eb2 VZ |
535 | |
536 | // ... adding extra buttons (but more than two will usually be too many) | |
374ae80f | 537 | m_infoBarAdvanced->AddButton(wxID_UNDO); |
e6b2aae1 VZ |
538 | m_infoBarAdvanced->AddButton(wxID_REDO); |
539 | ||
c0945eb2 VZ |
540 | m_infoBarAdvanced->Connect(wxID_REDO, wxEVT_COMMAND_BUTTON_CLICKED, |
541 | wxCommandEventHandler(MyFrame::OnInfoBarRedo), | |
542 | NULL, | |
543 | this); | |
544 | ||
e6b2aae1 VZ |
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); | |
374ae80f | 549 | |
c0945eb2 | 550 | // ... changing the colours and/or fonts |
374ae80f | 551 | m_infoBarAdvanced->SetOwnBackgroundColour(0xc8ffff); |
c0945eb2 VZ |
552 | m_infoBarAdvanced->SetFont(GetFont().Bold().Larger()); |
553 | ||
554 | // ... and changing the effect (only does anything under MSW currently) | |
374ae80f VZ |
555 | m_infoBarAdvanced->SetShowHideEffects(wxSHOW_EFFECT_EXPAND, |
556 | wxSHOW_EFFECT_EXPAND); | |
557 | m_infoBarAdvanced->SetEffectDuration(1500); | |
a92b5dfe | 558 | |
c0945eb2 | 559 | |
a92b5dfe VZ |
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()); | |
374ae80f | 564 | sizer->Add(m_infoBarAdvanced, wxSizerFlags().Expand()); |
a92b5dfe | 565 | SetSizer(sizer); |
15ea6e20 VZ |
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()); | |
a92b5dfe | 572 | #endif // wxUSE_INFOBAR |
4c45f240 | 573 | } |
457814b5 | 574 | |
e36a1739 VZ |
575 | MyFrame::~MyFrame() |
576 | { | |
577 | #if wxUSE_NOTIFICATION_MESSAGE | |
578 | delete m_notifMsg; | |
579 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
580 | } | |
581 | ||
13188def | 582 | #if wxUSE_COLOURDLG |
e6ef9ea4 VZ |
583 | |
584 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event)) | |
457814b5 | 585 | { |
87a18679 | 586 | m_clrData.SetColour(m_canvas->GetBackgroundColour()); |
d93c719a | 587 | |
d33dd9ef | 588 | wxColourDialog dialog(this, &m_clrData); |
e6ef9ea4 VZ |
589 | dialog.SetTitle(_("Please choose the background colour")); |
590 | if ( dialog.ShowModal() == wxID_OK ) | |
f6bcfd97 | 591 | { |
d33dd9ef | 592 | m_clrData = dialog.GetColourData(); |
87a18679 VZ |
593 | m_canvas->SetBackgroundColour(m_clrData.GetColour()); |
594 | m_canvas->ClearBackground(); | |
595 | m_canvas->Refresh(); | |
f6bcfd97 | 596 | } |
457814b5 | 597 | } |
e6ef9ea4 VZ |
598 | |
599 | void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event)) | |
600 | { | |
601 | wxColour clr = wxGetColourFromUser | |
602 | ( | |
603 | this, | |
3406ebd4 | 604 | m_canvas->GetForegroundColour(), |
e6ef9ea4 VZ |
605 | "Please choose the foreground colour" |
606 | ); | |
607 | if ( clr.IsOk() ) | |
608 | { | |
3406ebd4 | 609 | m_canvas->SetForegroundColour(clr); |
87a18679 | 610 | m_canvas->Refresh(); |
e6ef9ea4 VZ |
611 | } |
612 | //else: dialog cancelled by user | |
613 | } | |
614 | ||
13188def | 615 | #endif // wxUSE_COLOURDLG |
457814b5 | 616 | |
e6ef9ea4 | 617 | |
1e72e3cc RN |
618 | #if USE_COLOURDLG_GENERIC |
619 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) | |
620 | { | |
87a18679 | 621 | m_clrData.SetColour(m_canvas->GetBackgroundColour()); |
1e72e3cc RN |
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(); | |
87a18679 VZ |
640 | m_canvas->SetBackgroundColour(m_clrData.GetColour()); |
641 | m_canvas->ClearBackground(); | |
642 | m_canvas->Refresh(); | |
1e72e3cc RN |
643 | } |
644 | dialog->Destroy(); | |
645 | } | |
646 | #endif // USE_COLOURDLG_GENERIC | |
647 | ||
13188def | 648 | #if wxUSE_FONTDLG |
d355d3fe | 649 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 650 | { |
dbc65e27 | 651 | wxFontData data; |
3406ebd4 VZ |
652 | data.SetInitialFont(m_canvas->GetFont()); |
653 | data.SetColour(m_canvas->GetForegroundColour()); | |
d93c719a | 654 | |
dbc65e27 VZ |
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(); | |
3406ebd4 VZ |
665 | m_canvas->SetFont(retData.GetChosenFont()); |
666 | m_canvas->SetForegroundColour(retData.GetColour()); | |
87a18679 | 667 | m_canvas->Refresh(); |
dbc65e27 VZ |
668 | } |
669 | //else: cancelled by the user, don't change the font | |
457814b5 | 670 | } |
13188def | 671 | #endif // wxUSE_FONTDLG |
457814b5 | 672 | |
13188def | 673 | #if USE_FONTDLG_GENERIC |
d355d3fe | 674 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 675 | { |
13188def | 676 | wxFontData data; |
3406ebd4 VZ |
677 | data.SetInitialFont(m_canvas->GetFont()); |
678 | data.SetColour(m_canvas->GetForegroundColour()); | |
457814b5 | 679 | |
ca3e85cf | 680 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data); |
13188def WS |
681 | if (dialog->ShowModal() == wxID_OK) |
682 | { | |
457814b5 | 683 | wxFontData retData = dialog->GetFontData(); |
3406ebd4 VZ |
684 | m_canvas->SetFont(retData.GetChosenFont()); |
685 | m_canvas->SetForegroundColour(retData.GetColour()); | |
87a18679 | 686 | m_canvas->Refresh(); |
13188def WS |
687 | } |
688 | dialog->Destroy(); | |
457814b5 | 689 | } |
13188def | 690 | #endif // USE_FONTDLG_GENERIC |
d93c719a | 691 | |
b4954d19 | 692 | #if wxUSE_LOG_DIALOG |
87728739 | 693 | void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event)) |
d93c719a | 694 | { |
2c8e4738 VZ |
695 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages |
696 | // being flushed -- test it | |
697 | { | |
698 | wxBusyCursor bc; | |
4693b20c MB |
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!")); | |
9fe52545 VZ |
702 | |
703 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
704 | wxYield(); | |
2c8e4738 VZ |
705 | } |
706 | ||
4693b20c MB |
707 | wxLogError(wxT("Intermediary error handler decided to abort.")); |
708 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
5888ef1e | 709 | |
7923c649 VZ |
710 | wxLog::FlushActive(); |
711 | ||
4693b20c | 712 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); |
d93c719a | 713 | } |
b4954d19 | 714 | #endif // wxUSE_LOG_DIALOG |
457814b5 | 715 | |
a92b5dfe VZ |
716 | #if wxUSE_INFOBAR |
717 | ||
718 | void 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 | ||
727 | void MyFrame::InfoBarAdvanced(wxCommandEvent& WXUNUSED(event)) | |
728 | { | |
374ae80f | 729 | m_infoBarAdvanced->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING); |
a92b5dfe VZ |
730 | } |
731 | ||
c0945eb2 VZ |
732 | void MyFrame::OnInfoBarRedo(wxCommandEvent& WXUNUSED(event)) |
733 | { | |
734 | m_infoBarAdvanced->ShowMessage("Still no, sorry again.", wxICON_ERROR); | |
735 | } | |
736 | ||
a92b5dfe VZ |
737 | #endif // wxUSE_INFOBAR |
738 | ||
739 | ||
8cf304f8 | 740 | #if wxUSE_MSGDLG |
44b25eac | 741 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 742 | { |
1d89da8a | 743 | wxMessageDialog dialog(this, |
4223fc75 | 744 | "This is a message box\n" |
0a29d575 | 745 | "This is a long, long string to test out if the message box " |
ebaa7e48 | 746 | "is laid out properly.", |
4223fc75 | 747 | "Message box text", |
f3fe2d4e | 748 | wxCENTER | |
44b25eac VZ |
749 | wxNO_DEFAULT | wxYES_NO | wxCANCEL | |
750 | wxICON_INFORMATION); | |
86c3808c | 751 | |
4223fc75 VZ |
752 | wxString extmsg; |
753 | if ( dialog.SetYesNoCancelLabels | |
86c3808c SC |
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 | ||
789 | void 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 | |
4223fc75 VZ |
802 | ( |
803 | "Answer &Yes", | |
804 | "Answer &No", | |
805 | "Refuse to answer" | |
806 | ) ) | |
2afb9e16 | 807 | { |
4223fc75 | 808 | extmsg = "This platform supports custom button labels,\n" |
5150a29a | 809 | "so you should see the descriptive labels below."; |
2afb9e16 VZ |
810 | } |
811 | else | |
812 | { | |
4223fc75 VZ |
813 | extmsg = "Custom button labels are not supported on this platform,\n" |
814 | "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used."; | |
2afb9e16 | 815 | } |
86c3808c SC |
816 | dialog->SetExtendedMessage(extmsg); |
817 | dialog->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed), NULL, this ); | |
818 | dialog->ShowWindowModal(); | |
819 | } | |
457814b5 | 820 | |
86c3808c SC |
821 | void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent& event) |
822 | { | |
823 | wxDialog* dialog = event.GetDialog(); | |
824 | switch ( dialog->GetReturnCode() ) | |
13188def WS |
825 | { |
826 | case wxID_YES: | |
827 | wxLogStatus(wxT("You pressed \"Yes\"")); | |
828 | break; | |
49b957be | 829 | |
13188def WS |
830 | case wxID_NO: |
831 | wxLogStatus(wxT("You pressed \"No\"")); | |
832 | break; | |
49b957be | 833 | |
13188def WS |
834 | case wxID_CANCEL: |
835 | wxLogStatus(wxT("You pressed \"Cancel\"")); | |
836 | break; | |
49b957be | 837 | |
13188def WS |
838 | default: |
839 | wxLogError(wxT("Unexpected wxMessageDialog return code!")); | |
840 | } | |
86c3808c | 841 | delete dialog; |
457814b5 JS |
842 | } |
843 | ||
44b25eac VZ |
844 | void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event)) |
845 | { | |
846 | TestMessageBoxDialog dlg(this); | |
847 | dlg.ShowModal(); | |
848 | } | |
849 | ||
8cf304f8 VZ |
850 | void MyFrame::MessageBoxInfo(wxCommandEvent& WXUNUSED(event)) |
851 | { | |
852 | ::wxInfoMessageBox(this); | |
853 | } | |
854 | #endif // wxUSE_MSGDLG | |
855 | ||
13188def | 856 | #if wxUSE_NUMBERDLG |
8cf304f8 | 857 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event)) |
c49245f8 | 858 | { |
9a83f860 VZ |
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"), | |
e65cc56a | 862 | 50, 0, 100, this ); |
c49245f8 VZ |
863 | |
864 | wxString msg; | |
865 | int icon; | |
866 | if ( res == -1 ) | |
867 | { | |
9a83f860 | 868 | msg = wxT("Invalid number entered or dialog cancelled."); |
c49245f8 VZ |
869 | icon = wxICON_HAND; |
870 | } | |
871 | else | |
d93c719a | 872 | { |
9a83f860 | 873 | msg.Printf(wxT("You've entered %lu"), res ); |
c49245f8 VZ |
874 | icon = wxICON_INFORMATION; |
875 | } | |
876 | ||
9a83f860 | 877 | wxMessageBox(msg, wxT("Numeric test result"), wxOK | icon, this); |
c49245f8 | 878 | } |
13188def | 879 | #endif // wxUSE_NUMBERDLG |
c49245f8 | 880 | |
13188def | 881 | #if wxUSE_TEXTDLG |
a294c6d5 | 882 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 883 | { |
9a83f860 VZ |
884 | wxString pwd = wxGetPasswordFromUser(wxT("Enter password:"), |
885 | wxT("Password entry dialog"), | |
dabbc6a5 | 886 | wxEmptyString, |
a294c6d5 | 887 | this); |
ecda9475 | 888 | if ( !pwd.empty() ) |
a294c6d5 | 889 | { |
4693b20c | 890 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), |
9a83f860 | 891 | wxT("Got password"), wxOK | wxICON_INFORMATION, this); |
a294c6d5 VZ |
892 | } |
893 | } | |
894 | ||
895 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
896 | { | |
13188def | 897 | wxTextEntryDialog dialog(this, |
9a83f860 VZ |
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"), | |
13188def | 902 | wxOK | wxCANCEL); |
457814b5 | 903 | |
13188def WS |
904 | if (dialog.ShowModal() == wxID_OK) |
905 | { | |
9a83f860 | 906 | wxMessageBox(dialog.GetValue(), wxT("Got string"), wxOK | wxICON_INFORMATION, this); |
13188def | 907 | } |
457814b5 | 908 | } |
13188def | 909 | #endif // wxUSE_TEXTDLG |
457814b5 | 910 | |
13188def | 911 | #if wxUSE_CHOICEDLG |
d355d3fe | 912 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 913 | { |
9a83f860 | 914 | const wxString choices[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ; |
457814b5 | 915 | |
5f95bb70 | 916 | wxSingleChoiceDialog dialog(this, |
9a83f860 VZ |
917 | wxT("This is a small sample\n") |
918 | wxT("A single-choice convenience dialog"), | |
919 | wxT("Please select a value"), | |
5f95bb70 | 920 | WXSIZEOF(choices), choices); |
457814b5 | 921 | |
ef77f91e JS |
922 | dialog.SetSelection(2); |
923 | ||
924 | if (dialog.ShowModal() == wxID_OK) | |
925 | { | |
9a83f860 | 926 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), wxT("Got string")); |
ef77f91e JS |
927 | dialog2.ShowModal(); |
928 | } | |
457814b5 JS |
929 | } |
930 | ||
d6c9c1b7 VZ |
931 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) |
932 | { | |
5f95bb70 VZ |
933 | const wxString choices[] = |
934 | { | |
9a83f860 VZ |
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"), | |
5f95bb70 | 938 | }; |
d6c9c1b7 VZ |
939 | |
940 | wxArrayInt selections; | |
e5cfb314 | 941 | const int count = wxGetSelectedChoices(selections, |
9a83f860 VZ |
942 | wxT("This is a small sample\n") |
943 | wxT("A multi-choice convenience dialog"), | |
944 | wxT("Please select a value"), | |
5f95bb70 | 945 | WXSIZEOF(choices), choices, |
d6c9c1b7 | 946 | this); |
e5cfb314 | 947 | if ( count >= 0 ) |
d6c9c1b7 | 948 | { |
3d49ce44 | 949 | wxString msg; |
e5cfb314 | 950 | if ( count == 0 ) |
d6c9c1b7 | 951 | { |
e5cfb314 VZ |
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 | } | |
d6c9c1b7 | 963 | } |
3d49ce44 | 964 | wxLogMessage(msg); |
d6c9c1b7 | 965 | } |
e5cfb314 | 966 | //else: cancelled |
d6c9c1b7 | 967 | } |
13188def | 968 | #endif // wxUSE_CHOICEDLG |
d6c9c1b7 | 969 | |
81496fea | 970 | #if wxUSE_REARRANGECTRL |
5a5f305a VZ |
971 | // custom rearrange dialog: it adds the possibility to rename an item to the |
972 | // base class functionality | |
973 | class MyRearrangeDialog : public wxRearrangeDialog | |
974 | { | |
975 | public: | |
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); | |
e9bef302 VZ |
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)); | |
5a5f305a VZ |
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 | { | |
e9bef302 VZ |
1033 | switch ( ShowModal() ) |
1034 | { | |
1035 | case wxID_CANCEL: | |
1036 | return false; | |
5a5f305a | 1037 | |
e9bef302 VZ |
1038 | case wxID_OK: |
1039 | m_order = GetOrder(); | |
1040 | break; | |
1041 | ||
1042 | case wxID_RESET: | |
1043 | // order already reset | |
1044 | break; | |
1045 | } | |
5a5f305a VZ |
1046 | |
1047 | return true; | |
1048 | } | |
1049 | ||
1050 | private: | |
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 | ||
e9bef302 VZ |
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 | ||
5a5f305a VZ |
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() | |
c0c133e1 | 1119 | wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog); |
5a5f305a VZ |
1120 | }; |
1121 | ||
1122 | BEGIN_EVENT_TABLE(MyRearrangeDialog, wxRearrangeDialog) | |
1123 | EVT_LISTBOX(wxID_ANY, MyRearrangeDialog::OnSelChange) | |
e9bef302 | 1124 | |
5a5f305a | 1125 | EVT_UPDATE_UI(wxID_APPLY, MyRearrangeDialog::OnUpdateUIRename) |
e9bef302 | 1126 | |
5a5f305a | 1127 | EVT_TEXT_ENTER(wxID_ANY, MyRearrangeDialog::OnRename) |
e9bef302 VZ |
1128 | EVT_BUTTON(wxID_APPLY, MyRearrangeDialog::OnRename) |
1129 | EVT_BUTTON(wxID_RESET, MyRearrangeDialog::OnReset) | |
5a5f305a VZ |
1130 | END_EVENT_TABLE() |
1131 | ||
1132 | void 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 | } | |
81496fea | 1195 | #endif // wxUSE_REARRANGECTRL |
5a5f305a | 1196 | |
13188def | 1197 | #if wxUSE_FILEDLG |
8ce68f7f VZ |
1198 | |
1199 | // panel with custom controls for file dialog | |
1200 | class MyExtraPanel : public wxPanel | |
1201 | { | |
1202 | public: | |
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 | } | |
1209 | private: | |
1210 | wxButton *m_btn; | |
1211 | wxCheckBox *m_cb; | |
1212 | }; | |
1213 | ||
1214 | MyExtraPanel::MyExtraPanel(wxWindow *parent) | |
1215 | : wxPanel(parent) | |
1216 | { | |
9a83f860 | 1217 | m_btn = new wxButton(this, -1, wxT("Custom Button")); |
8ce68f7f | 1218 | m_btn->Enable(false); |
9a83f860 | 1219 | m_cb = new wxCheckBox(this, -1, wxT("Enable Custom Button")); |
8ce68f7f VZ |
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 | |
1230 | static wxWindow* createMyExtraPanel(wxWindow *parent) | |
1231 | { | |
1232 | return new MyExtraPanel(parent); | |
1233 | } | |
1234 | ||
d355d3fe | 1235 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 1236 | { |
fbf4eacb VZ |
1237 | wxFileDialog dialog |
1238 | ( | |
1239 | this, | |
9a83f860 | 1240 | wxT("Testing open file dialog"), |
dabbc6a5 DS |
1241 | wxEmptyString, |
1242 | wxEmptyString, | |
a4e64fb5 | 1243 | #ifdef __WXMOTIF__ |
9a83f860 | 1244 | wxT("C++ files (*.cpp)|*.cpp") |
a4e64fb5 | 1245 | #else |
9a83f860 | 1246 | wxT("C++ files (*.cpp;*.h)|*.cpp;*.h") |
a4e64fb5 | 1247 | #endif |
fbf4eacb | 1248 | ); |
457814b5 | 1249 | |
8ce68f7f | 1250 | dialog.SetExtraControlCreator(&createMyExtraPanel); |
3b6c3fc8 | 1251 | dialog.CentreOnParent(); |
cd7afaff | 1252 | dialog.SetDirectory(wxGetHomeDir()); |
5b636c67 | 1253 | |
c50f1fb9 VZ |
1254 | if (dialog.ShowModal() == wxID_OK) |
1255 | { | |
5919d76b | 1256 | wxString info; |
cece89a4 | 1257 | wxWindow * const extra = dialog.GetExtraControl(); |
9a83f860 VZ |
1258 | info.Printf(wxT("Full file name: %s\n") |
1259 | wxT("Path: %s\n") | |
1260 | wxT("Name: %s\n") | |
1261 | wxT("Custom window: %s"), | |
5919d76b VZ |
1262 | dialog.GetPath().c_str(), |
1263 | dialog.GetDirectory().c_str(), | |
8ce68f7f | 1264 | dialog.GetFilename().c_str(), |
cece89a4 VZ |
1265 | extra ? static_cast<MyExtraPanel*>(extra)->GetInfo() |
1266 | : wxString("None")); | |
9a83f860 | 1267 | wxMessageDialog dialog2(this, info, wxT("Selected file")); |
c50f1fb9 VZ |
1268 | dialog2.ShowModal(); |
1269 | } | |
457814b5 JS |
1270 | } |
1271 | ||
35b45b33 VZ |
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 | |
1275 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
1276 | { | |
1277 | static wxString s_extDef; | |
1278 | wxString path = wxFileSelector( | |
9a83f860 | 1279 | wxT("Select the file to load"), |
dabbc6a5 | 1280 | wxEmptyString, wxEmptyString, |
35b45b33 | 1281 | s_extDef, |
3601f639 VZ |
1282 | wxString::Format |
1283 | ( | |
9a83f860 | 1284 | wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"), |
3601f639 VZ |
1285 | wxFileSelectorDefaultWildcardStr, |
1286 | wxFileSelectorDefaultWildcardStr | |
1287 | ), | |
9f057af5 | 1288 | wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW, |
35b45b33 VZ |
1289 | this |
1290 | ); | |
1291 | ||
1292 | if ( !path ) | |
1293 | return; | |
1294 | ||
1295 | // it is just a sample, would use wxSplitPath in real program | |
9a83f860 | 1296 | s_extDef = path.AfterLast(wxT('.')); |
35b45b33 | 1297 | |
9a83f860 | 1298 | wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"), |
a342cb00 | 1299 | path, s_extDef); |
35b45b33 VZ |
1300 | } |
1301 | ||
c61f4f6d VZ |
1302 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) |
1303 | { | |
dabbc6a5 | 1304 | wxString wildcards = |
f0f43012 | 1305 | #ifdef __WXMOTIF__ |
9a83f860 | 1306 | wxT("C++ files (*.cpp)|*.cpp"); |
f0f43012 | 1307 | #else |
3601f639 VZ |
1308 | wxString::Format |
1309 | ( | |
9a83f860 | 1310 | wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"), |
3601f639 VZ |
1311 | wxFileSelectorDefaultWildcardStr, |
1312 | wxFileSelectorDefaultWildcardStr | |
1313 | ); | |
f0f43012 | 1314 | #endif |
9a83f860 | 1315 | wxFileDialog dialog(this, wxT("Testing open multiple file dialog"), |
dabbc6a5 | 1316 | wxEmptyString, wxEmptyString, wildcards, |
ff3e84ff | 1317 | wxFD_OPEN|wxFD_MULTIPLE); |
c61f4f6d VZ |
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 | { | |
9a83f860 | 1330 | s.Printf(wxT("File %d: %s (%s)\n"), |
fba1b53b | 1331 | (int)n, paths[n].c_str(), filenames[n].c_str()); |
c61f4f6d VZ |
1332 | |
1333 | msg += s; | |
1334 | } | |
9a83f860 | 1335 | s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex()); |
f0f43012 | 1336 | msg += s; |
c61f4f6d | 1337 | |
9a83f860 | 1338 | wxMessageDialog dialog2(this, msg, wxT("Selected files")); |
c61f4f6d VZ |
1339 | dialog2.ShowModal(); |
1340 | } | |
1341 | } | |
1342 | ||
d355d3fe | 1343 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 1344 | { |
2f1cd905 | 1345 | wxFileDialog dialog(this, |
9a83f860 | 1346 | wxT("Testing save file dialog"), |
dabbc6a5 | 1347 | wxEmptyString, |
9a83f860 VZ |
1348 | wxT("myletter.doc"), |
1349 | wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"), | |
ff3e84ff | 1350 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
c50f1fb9 | 1351 | |
2b5f62a0 VZ |
1352 | dialog.SetFilterIndex(1); |
1353 | ||
c50f1fb9 VZ |
1354 | if (dialog.ShowModal() == wxID_OK) |
1355 | { | |
9a83f860 | 1356 | wxLogMessage(wxT("%s, filter %d"), |
2b5f62a0 | 1357 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); |
c50f1fb9 | 1358 | } |
457814b5 | 1359 | } |
13188def | 1360 | #endif // wxUSE_FILEDLG |
457814b5 | 1361 | |
695fe764 WS |
1362 | #if USE_FILEDLG_GENERIC |
1363 | void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
1364 | { | |
1365 | wxGenericFileDialog dialog | |
1366 | ( | |
1367 | this, | |
9a83f860 | 1368 | wxT("Testing open file dialog"), |
695fe764 WS |
1369 | wxEmptyString, |
1370 | wxEmptyString, | |
9a83f860 | 1371 | wxT("C++ files (*.cpp;*.h)|*.cpp;*.h") |
695fe764 WS |
1372 | ); |
1373 | ||
8ce68f7f | 1374 | dialog.SetExtraControlCreator(&createMyExtraPanel); |
695fe764 WS |
1375 | dialog.SetDirectory(wxGetHomeDir()); |
1376 | ||
1377 | if (dialog.ShowModal() == wxID_OK) | |
1378 | { | |
1379 | wxString info; | |
9a83f860 VZ |
1380 | info.Printf(wxT("Full file name: %s\n") |
1381 | wxT("Path: %s\n") | |
1382 | wxT("Name: %s"), | |
695fe764 WS |
1383 | dialog.GetPath().c_str(), |
1384 | dialog.GetDirectory().c_str(), | |
1385 | dialog.GetFilename().c_str()); | |
9a83f860 | 1386 | wxMessageDialog dialog2(this, info, wxT("Selected file")); |
695fe764 WS |
1387 | dialog2.ShowModal(); |
1388 | } | |
1389 | } | |
1390 | ||
1391 | void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
1392 | { | |
684883e3 WS |
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 | ||
9a83f860 VZ |
1397 | wxString wildcards = wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h"); |
1398 | wxGenericFileDialog dialog(this, wxT("Testing open multiple file dialog"), | |
695fe764 | 1399 | wxEmptyString, wxEmptyString, wildcards, |
e031f1df | 1400 | wxFD_MULTIPLE); |
695fe764 WS |
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 | { | |
9a83f860 | 1413 | s.Printf(wxT("File %d: %s (%s)\n"), |
695fe764 WS |
1414 | (int)n, paths[n].c_str(), filenames[n].c_str()); |
1415 | ||
1416 | msg += s; | |
1417 | } | |
9a83f860 | 1418 | s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex()); |
695fe764 WS |
1419 | msg += s; |
1420 | ||
9a83f860 | 1421 | wxMessageDialog dialog2(this, msg, wxT("Selected files")); |
695fe764 WS |
1422 | dialog2.ShowModal(); |
1423 | } | |
684883e3 WS |
1424 | |
1425 | // restore system option | |
1426 | wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons); | |
695fe764 WS |
1427 | } |
1428 | ||
1429 | void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) ) | |
1430 | { | |
1431 | wxGenericFileDialog dialog(this, | |
9a83f860 | 1432 | wxT("Testing save file dialog"), |
695fe764 | 1433 | wxEmptyString, |
9a83f860 VZ |
1434 | wxT("myletter.doc"), |
1435 | wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"), | |
e031f1df | 1436 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
695fe764 WS |
1437 | |
1438 | dialog.SetFilterIndex(1); | |
1439 | ||
1440 | if (dialog.ShowModal() == wxID_OK) | |
1441 | { | |
9a83f860 | 1442 | wxLogMessage(wxT("%s, filter %d"), |
695fe764 WS |
1443 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); |
1444 | } | |
1445 | } | |
1446 | #endif // USE_FILEDLG_GENERIC | |
1447 | ||
13188def | 1448 | #if wxUSE_DIRDLG |
f09c8393 | 1449 | void MyFrame::DoDirChoose(int style) |
457814b5 | 1450 | { |
3f2711d5 VZ |
1451 | // pass some initial dir to wxDirDialog |
1452 | wxString dirHome; | |
1453 | wxGetHomeDir(&dirHome); | |
1454 | ||
9a83f860 | 1455 | wxDirDialog dialog(this, wxT("Testing directory picker"), dirHome, style); |
c50f1fb9 VZ |
1456 | |
1457 | if (dialog.ShowModal() == wxID_OK) | |
1458 | { | |
9a83f860 | 1459 | wxLogMessage(wxT("Selected path: %s"), dialog.GetPath().c_str()); |
c50f1fb9 VZ |
1460 | } |
1461 | } | |
1462 | ||
f09c8393 VZ |
1463 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) |
1464 | { | |
ff3e84ff | 1465 | DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); |
f09c8393 VZ |
1466 | } |
1467 | ||
1468 | void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) ) | |
1469 | { | |
ff3e84ff | 1470 | DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST); |
f09c8393 | 1471 | } |
13188def | 1472 | #endif // wxUSE_DIRDLG |
f09c8393 | 1473 | |
13188def | 1474 | #if USE_DIRDLG_GENERIC |
51a58d8b JS |
1475 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) |
1476 | { | |
1477 | // pass some initial dir to wxDirDialog | |
1478 | wxString dirHome; | |
1479 | wxGetHomeDir(&dirHome); | |
1480 | ||
9a83f860 | 1481 | wxGenericDirDialog dialog(this, wxT("Testing generic directory picker"), dirHome); |
51a58d8b JS |
1482 | |
1483 | if (dialog.ShowModal() == wxID_OK) | |
1484 | { | |
9a83f860 | 1485 | wxMessageDialog dialog2(this, dialog.GetPath(), wxT("Selected path")); |
51a58d8b JS |
1486 | dialog2.ShowModal(); |
1487 | } | |
1488 | } | |
13188def | 1489 | #endif // USE_DIRDLG_GENERIC |
51a58d8b | 1490 | |
13188def | 1491 | #if USE_MODAL_PRESENTATION |
f6bcfd97 BP |
1492 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) |
1493 | { | |
1494 | MyModalDialog dlg(this); | |
1495 | dlg.ShowModal(); | |
1496 | } | |
1baa0a9d | 1497 | #endif // USE_MODAL_PRESENTATION |
f6bcfd97 | 1498 | |
4c45f240 VZ |
1499 | void MyFrame::ModelessDlg(wxCommandEvent& event) |
1500 | { | |
2f82899b | 1501 | bool show = GetMenuBar()->IsChecked(event.GetId()); |
4c45f240 VZ |
1502 | |
1503 | if ( show ) | |
1504 | { | |
1505 | if ( !m_dialog ) | |
1506 | { | |
1507 | m_dialog = new MyModelessDialog(this); | |
1508 | } | |
1509 | ||
13188def | 1510 | m_dialog->Show(true); |
4c45f240 VZ |
1511 | } |
1512 | else // hide | |
1513 | { | |
26a12ab3 JS |
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(); | |
4c45f240 VZ |
1522 | } |
1523 | } | |
cae50e6b VZ |
1524 | |
1525 | void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event)) | |
1526 | { | |
9a83f860 | 1527 | wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on screen"), |
cae50e6b | 1528 | wxDefaultPosition, wxSize(200, 100)); |
9a83f860 | 1529 | (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre(); |
cae50e6b VZ |
1530 | dlg.CentreOnScreen(); |
1531 | dlg.ShowModal(); | |
1532 | } | |
1533 | ||
1534 | void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event)) | |
1535 | { | |
9a83f860 | 1536 | wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on parent"), |
cae50e6b | 1537 | wxDefaultPosition, wxSize(200, 100)); |
9a83f860 | 1538 | (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre(); |
cae50e6b VZ |
1539 | dlg.CentreOnParent(); |
1540 | dlg.ShowModal(); | |
1541 | } | |
1542 | ||
81496fea | 1543 | #if wxUSE_MINIFRAME |
1baa0a9d VZ |
1544 | void MyFrame::MiniFrame(wxCommandEvent& WXUNUSED(event)) |
1545 | { | |
9a83f860 | 1546 | wxFrame *frame = new wxMiniFrame(this, wxID_ANY, wxT("Mini frame"), |
1baa0a9d VZ |
1547 | wxDefaultPosition, wxSize(300, 100), |
1548 | wxCAPTION | wxCLOSE_BOX); | |
1549 | new wxStaticText(frame, | |
1550 | wxID_ANY, | |
9a83f860 | 1551 | wxT("Mini frames have slightly different appearance"), |
1baa0a9d VZ |
1552 | wxPoint(5, 5)); |
1553 | new wxStaticText(frame, | |
1554 | wxID_ANY, | |
9a83f860 | 1555 | wxT("from the normal frames but that's the only difference."), |
1baa0a9d VZ |
1556 | wxPoint(5, 25)); |
1557 | ||
1558 | frame->CentreOnParent(); | |
1559 | frame->Show(); | |
1560 | } | |
81496fea | 1561 | #endif // wxUSE_MINIFRAME |
4c45f240 | 1562 | |
8e5dbcdd VZ |
1563 | void MyFrame::DlgOnTop(wxCommandEvent& WXUNUSED(event)) |
1564 | { | |
9a83f860 | 1565 | wxDialog dlg(this, wxID_ANY, wxT("Dialog staying on top of other windows"), |
8e5dbcdd VZ |
1566 | wxDefaultPosition, wxSize(300, 100), |
1567 | wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP); | |
9a83f860 | 1568 | (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre(); |
8e5dbcdd VZ |
1569 | dlg.ShowModal(); |
1570 | } | |
1571 | ||
13188def | 1572 | #if wxUSE_STARTUP_TIPS |
87728739 | 1573 | void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event)) |
c50f1fb9 VZ |
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 | ||
9a83f860 | 1586 | wxTipProvider *tipProvider = wxCreateFileTipProvider(wxT("tips.txt"), s_index); |
c50f1fb9 VZ |
1587 | |
1588 | bool showAtStartup = wxShowTip(this, tipProvider); | |
1589 | ||
1590 | if ( showAtStartup ) | |
1591 | { | |
9a83f860 | 1592 | wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"), |
c50f1fb9 VZ |
1593 | wxOK | wxICON_INFORMATION, this); |
1594 | } | |
457814b5 | 1595 | |
c50f1fb9 VZ |
1596 | s_index = tipProvider->GetCurrentTip(); |
1597 | delete tipProvider; | |
457814b5 | 1598 | } |
13188def | 1599 | #endif // wxUSE_STARTUP_TIPS |
457814b5 | 1600 | |
532d575b | 1601 | #if USE_SETTINGS_DIALOG |
64d3ed17 | 1602 | void MyFrame::OnPropertySheet(wxCommandEvent& event) |
0f5d8ecf | 1603 | { |
64d3ed17 | 1604 | SettingsDialog dialog(this, event.GetId()); |
cc8bc5aa JS |
1605 | dialog.ShowModal(); |
1606 | } | |
532d575b | 1607 | #endif // USE_SETTINGS_DIALOG |
0f5d8ecf | 1608 | |
9b16ffef VZ |
1609 | void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) |
1610 | { | |
9a83f860 | 1611 | wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window")); |
9b16ffef VZ |
1612 | |
1613 | wxSleep(3); | |
1614 | ||
1615 | RequestUserAttention(wxUSER_ATTENTION_ERROR); | |
1616 | } | |
1617 | ||
e36a1739 VZ |
1618 | #if wxUSE_NOTIFICATION_MESSAGE |
1619 | ||
1620 | void 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 | ||
1633 | void 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 | ||
1651 | void MyFrame::OnNotifMsgHide(wxCommandEvent& WXUNUSED(event)) | |
1652 | { | |
af588446 | 1653 | if ( m_notifMsg && !m_notifMsg->Close() ) |
e36a1739 | 1654 | { |
af588446 | 1655 | wxLogStatus("Failed to hide manual notification message"); |
e36a1739 VZ |
1656 | } |
1657 | } | |
1658 | ||
1659 | #endif // wxUSE_NOTIFICATION_MESSAGE | |
1660 | ||
8e1dac82 VZ |
1661 | void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event)) |
1662 | { | |
1663 | StdButtonSizerDialog dialog(this); | |
1664 | dialog.ShowModal(); | |
1665 | } | |
1666 | ||
a625c5b6 RR |
1667 | // TestDefaultAction |
1668 | ||
1669 | #define ID_CATCH_LISTBOX_DCLICK 100 | |
1670 | #define ID_LISTBOX 101 | |
1671 | ||
1672 | BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog) | |
1673 | EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK, TestDefaultActionDialog::OnCatchListBoxDClick) | |
1674 | EVT_LISTBOX_DCLICK(ID_LISTBOX, TestDefaultActionDialog::OnListBoxDClick) | |
1675 | END_EVENT_TABLE() | |
1676 | ||
1677 | TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) : | |
1678 | wxDialog( parent, -1, "Test default action" ) | |
1679 | { | |
1680 | m_catchListBoxDClick = false; | |
1681 | ||
1682 | wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); | |
44b25eac | 1683 | |
a625c5b6 | 1684 | wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 5, 5 ); |
44b25eac | 1685 | |
81496fea | 1686 | #if wxUSE_LISTBOX |
a625c5b6 RR |
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 ); | |
81496fea | 1693 | #endif // wxUSE_LISTBOX |
44b25eac | 1694 | |
a625c5b6 | 1695 | grid_sizer->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL ); |
44b25eac | 1696 | |
a625c5b6 RR |
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 ); | |
44b25eac | 1699 | |
a625c5b6 RR |
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 ); | |
44b25eac | 1702 | |
a625c5b6 | 1703 | main_sizer->Add( grid_sizer, 0, wxALL, 10 ); |
44b25eac | 1704 | |
a625c5b6 RR |
1705 | wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL ); |
1706 | if (button_sizer) | |
1707 | main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 ); | |
44b25eac | 1708 | |
8ce68f7f | 1709 | SetSizerAndFit( main_sizer ); |
a625c5b6 | 1710 | } |
44b25eac | 1711 | |
a625c5b6 RR |
1712 | void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event) |
1713 | { | |
1714 | event.Skip( !m_catchListBoxDClick ); | |
1715 | } | |
1716 | ||
1717 | void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(event)) | |
1718 | { | |
1719 | m_catchListBoxDClick = !m_catchListBoxDClick; | |
1720 | } | |
1721 | ||
1722 | void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event)) | |
1723 | { | |
1724 | TestDefaultActionDialog dialog( this ); | |
1725 | dialog.ShowModal(); | |
1726 | } | |
1727 | ||
d355d3fe | 1728 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 1729 | { |
13188def | 1730 | Close(true); |
457814b5 JS |
1731 | } |
1732 | ||
abceee76 VZ |
1733 | #if wxUSE_PROGRESSDLG |
1734 | ||
1735 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
1736 | { | |
b2c782f2 | 1737 | static const int max = 100; |
abceee76 | 1738 | |
9a83f860 VZ |
1739 | wxProgressDialog dialog(wxT("Progress dialog example"), |
1740 | wxT("An informative message"), | |
abceee76 VZ |
1741 | max, // range |
1742 | this, // parent | |
1743 | wxPD_CAN_ABORT | | |
ecda9475 | 1744 | wxPD_CAN_SKIP | |
abceee76 | 1745 | wxPD_APP_MODAL | |
df26c4c6 | 1746 | // wxPD_AUTO_HIDE | -- try this as well |
abceee76 VZ |
1747 | wxPD_ELAPSED_TIME | |
1748 | wxPD_ESTIMATED_TIME | | |
f4aa7ec3 | 1749 | wxPD_REMAINING_TIME |
b2c782f2 | 1750 | | wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small |
f4aa7ec3 | 1751 | ); |
abceee76 | 1752 | |
13188def | 1753 | bool cont = true; |
b2c782f2 | 1754 | for ( int i = 0; i <= max; i++ ) |
abceee76 | 1755 | { |
b2c782f2 | 1756 | wxMilliSleep(200); |
ecda9475 WS |
1757 | |
1758 | wxString msg; | |
1759 | ||
b2c782f2 VZ |
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; | |
f4aa7ec3 | 1763 | |
abceee76 VZ |
1764 | if ( i == max ) |
1765 | { | |
9a83f860 | 1766 | msg = wxT("That's all, folks!"); |
abceee76 | 1767 | } |
b2c782f2 | 1768 | else if ( !determinate ) |
f4aa7ec3 | 1769 | { |
9a83f860 | 1770 | msg = wxT("Testing indeterminate mode"); |
f4aa7ec3 | 1771 | } |
b2c782f2 | 1772 | else if ( determinate ) |
abceee76 | 1773 | { |
9a83f860 | 1774 | msg = wxT("Now in standard determinate mode"); |
abceee76 | 1775 | } |
ecda9475 | 1776 | |
b2c782f2 VZ |
1777 | // will be set to true if "Skip" button was pressed |
1778 | bool skip = false; | |
1779 | if ( determinate ) | |
abceee76 | 1780 | { |
ecda9475 | 1781 | cont = dialog.Update(i, msg, &skip); |
abceee76 | 1782 | } |
f4aa7ec3 VZ |
1783 | else |
1784 | { | |
f4aa7ec3 | 1785 | cont = dialog.Pulse(msg, &skip); |
f4aa7ec3 | 1786 | } |
ecda9475 | 1787 | |
b2c782f2 VZ |
1788 | // each skip will move progress about quarter forward |
1789 | if ( skip ) | |
1790 | i += max/4; | |
1791 | ||
d8ddee9c VZ |
1792 | if ( !cont ) |
1793 | { | |
9a83f860 VZ |
1794 | if ( wxMessageBox(wxT("Do you really want to cancel?"), |
1795 | wxT("Progress dialog question"), // caption | |
78a189c9 | 1796 | wxYES_NO | wxICON_QUESTION) == wxYES ) |
d8ddee9c VZ |
1797 | break; |
1798 | ||
9b16ffef | 1799 | cont = true; |
d8ddee9c VZ |
1800 | dialog.Resume(); |
1801 | } | |
abceee76 VZ |
1802 | } |
1803 | ||
1804 | if ( !cont ) | |
1805 | { | |
4693b20c | 1806 | wxLogStatus(wxT("Progress dialog aborted!")); |
abceee76 VZ |
1807 | } |
1808 | else | |
1809 | { | |
4693b20c | 1810 | wxLogStatus(wxT("Countdown from %d finished"), max); |
abceee76 VZ |
1811 | } |
1812 | } | |
1813 | ||
1814 | #endif // wxUSE_PROGRESSDLG | |
1815 | ||
ca7adbf8 VZ |
1816 | #if wxUSE_ABOUTDLG |
1817 | ||
453c9e3b | 1818 | static void InitAboutInfoMinimal(wxAboutDialogInfo& info) |
ca7adbf8 | 1819 | { |
9a83f860 | 1820 | info.SetName(wxT("Dialogs Sample")); |
704006b3 VZ |
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 | )); | |
9a83f860 VZ |
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")); | |
ca7adbf8 VZ |
1831 | } |
1832 | ||
453c9e3b VZ |
1833 | static void InitAboutInfoWebsite(wxAboutDialogInfo& info) |
1834 | { | |
1835 | InitAboutInfoMinimal(info); | |
1836 | ||
9a83f860 | 1837 | info.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site")); |
453c9e3b VZ |
1838 | } |
1839 | ||
1840 | static void InitAboutInfoAll(wxAboutDialogInfo& info) | |
1841 | { | |
20fe9c5a | 1842 | InitAboutInfoWebsite(info); |
453c9e3b VZ |
1843 | |
1844 | // we can add a second developer | |
9a83f860 | 1845 | info.AddDeveloper(wxT("A.N. Other")); |
453c9e3b VZ |
1846 | |
1847 | // or we can add several persons at once like this | |
1848 | static const wxChar *docwriters[] = | |
1849 | { | |
9a83f860 VZ |
1850 | wxT("First D. Writer"), |
1851 | wxT("Second One"), | |
453c9e3b VZ |
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 | )); | |
fb4f85bf | 1869 | |
9a83f860 | 1870 | info.AddTranslator(wxT("Wun Ngo Wen (Martian)")); |
453c9e3b VZ |
1871 | } |
1872 | ||
ca7adbf8 VZ |
1873 | void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event)) |
1874 | { | |
1875 | wxAboutDialogInfo info; | |
453c9e3b | 1876 | InitAboutInfoMinimal(info); |
ca7adbf8 | 1877 | |
c173e541 | 1878 | wxAboutBox(info, this); |
ca7adbf8 VZ |
1879 | } |
1880 | ||
1881 | void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event)) | |
1882 | { | |
1883 | wxAboutDialogInfo info; | |
453c9e3b | 1884 | InitAboutInfoWebsite(info); |
ca7adbf8 | 1885 | |
c173e541 | 1886 | wxAboutBox(info, this); |
ca7adbf8 VZ |
1887 | } |
1888 | ||
453c9e3b VZ |
1889 | void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event)) |
1890 | { | |
1891 | wxAboutDialogInfo info; | |
1892 | InitAboutInfoAll(info); | |
1893 | ||
c173e541 | 1894 | wxAboutBox(info, this); |
453c9e3b VZ |
1895 | } |
1896 | ||
1dcfc333 VZ |
1897 | // a trivial example of a custom dialog class |
1898 | class MyAboutDialog : public wxGenericAboutDialog | |
453c9e3b | 1899 | { |
1dcfc333 | 1900 | public: |
c173e541 | 1901 | MyAboutDialog(const wxAboutDialogInfo& info, wxWindow* parent) |
453c9e3b | 1902 | { |
c173e541 | 1903 | Create(info, parent); |
1dcfc333 | 1904 | } |
453c9e3b | 1905 | |
1dcfc333 VZ |
1906 | // add some custom controls |
1907 | virtual void DoAddCustomControls() | |
1908 | { | |
1909 | AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); | |
9a83f860 | 1910 | AddText(wxT("Some custom text")); |
1dcfc333 VZ |
1911 | AddControl(new wxStaticLine(this), wxSizerFlags().Expand()); |
1912 | } | |
1913 | }; | |
453c9e3b | 1914 | |
1dcfc333 VZ |
1915 | void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event)) |
1916 | { | |
453c9e3b VZ |
1917 | wxAboutDialogInfo info; |
1918 | InitAboutInfoAll(info); | |
1919 | ||
c173e541 | 1920 | MyAboutDialog dlg(info, this); |
453c9e3b VZ |
1921 | dlg.ShowModal(); |
1922 | } | |
1923 | ||
ca7adbf8 VZ |
1924 | #endif // wxUSE_ABOUTDLG |
1925 | ||
a62b0bcc VZ |
1926 | #if wxUSE_BUSYINFO |
1927 | ||
1928 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
1929 | { | |
21977bac VZ |
1930 | wxWindowDisabler disableAll; |
1931 | ||
9a83f860 | 1932 | wxBusyInfo info(wxT("Working, please wait..."), this); |
a62b0bcc | 1933 | |
5b636c67 | 1934 | for ( int i = 0; i < 18; i++ ) |
a62b0bcc | 1935 | { |
f2335ba5 | 1936 | wxMilliSleep(100); |
a62b0bcc VZ |
1937 | wxTheApp->Yield(); |
1938 | } | |
5b636c67 VZ |
1939 | |
1940 | wxSleep(2); | |
1941 | //wxWakeUpIdle(); | |
a62b0bcc VZ |
1942 | } |
1943 | ||
1944 | #endif // wxUSE_BUSYINFO | |
1945 | ||
761989ff VZ |
1946 | #if wxUSE_FINDREPLDLG |
1947 | ||
1948 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
1949 | { | |
14fca738 VZ |
1950 | if ( m_dlgReplace ) |
1951 | { | |
1952 | delete m_dlgReplace; | |
1953 | m_dlgReplace = NULL; | |
1954 | } | |
1955 | else | |
1956 | { | |
1957 | m_dlgReplace = new wxFindReplaceDialog | |
1958 | ( | |
1959 | this, | |
1960 | &m_findData, | |
9a83f860 | 1961 | wxT("Find and replace dialog"), |
14fca738 VZ |
1962 | wxFR_REPLACEDIALOG |
1963 | ); | |
1964 | ||
13188def | 1965 | m_dlgReplace->Show(true); |
14fca738 | 1966 | } |
761989ff VZ |
1967 | } |
1968 | ||
1969 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
1970 | { | |
14fca738 VZ |
1971 | if ( m_dlgFind ) |
1972 | { | |
1973 | delete m_dlgFind; | |
1974 | m_dlgFind = NULL; | |
1975 | } | |
1976 | else | |
1977 | { | |
1978 | m_dlgFind = new wxFindReplaceDialog | |
1979 | ( | |
1980 | this, | |
1981 | &m_findData, | |
9a83f860 | 1982 | wxT("Find dialog"), |
14fca738 VZ |
1983 | // just for testing |
1984 | wxFR_NOWHOLEWORD | |
1985 | ); | |
1986 | ||
13188def | 1987 | m_dlgFind->Show(true); |
14fca738 | 1988 | } |
761989ff VZ |
1989 | } |
1990 | ||
1991 | static wxString DecodeFindDialogEventFlags(int flags) | |
1992 | { | |
1993 | wxString str; | |
9a83f860 VZ |
1994 | str << (flags & wxFR_DOWN ? wxT("down") : wxT("up")) << wxT(", ") |
1995 | << (flags & wxFR_WHOLEWORD ? wxT("whole words only, ") : wxT("")) | |
1996 | << (flags & wxFR_MATCHCASE ? wxT("") : wxT("not ")) | |
1997 | << wxT("case sensitive"); | |
761989ff VZ |
1998 | |
1999 | return str; | |
2000 | } | |
2001 | ||
2002 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
2003 | { | |
2004 | wxEventType type = event.GetEventType(); | |
2005 | ||
2006 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
2007 | { | |
4693b20c | 2008 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), |
eba33006 | 2009 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), |
761989ff VZ |
2010 | event.GetFindString().c_str(), |
2011 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
2012 | } | |
2013 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
2014 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
2015 | { | |
4693b20c | 2016 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), |
9a83f860 | 2017 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? wxT("all ") : wxT(""), |
761989ff VZ |
2018 | event.GetFindString().c_str(), |
2019 | event.GetReplaceString().c_str(), | |
2020 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
2021 | } | |
2022 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
2023 | { | |
14fca738 VZ |
2024 | wxFindReplaceDialog *dlg = event.GetDialog(); |
2025 | ||
df26c4c6 | 2026 | int idMenu; |
14fca738 VZ |
2027 | const wxChar *txt; |
2028 | if ( dlg == m_dlgFind ) | |
2029 | { | |
9a83f860 | 2030 | txt = wxT("Find"); |
df26c4c6 | 2031 | idMenu = DIALOGS_FIND; |
14fca738 VZ |
2032 | m_dlgFind = NULL; |
2033 | } | |
2034 | else if ( dlg == m_dlgReplace ) | |
2035 | { | |
9a83f860 | 2036 | txt = wxT("Replace"); |
df26c4c6 | 2037 | idMenu = DIALOGS_REPLACE; |
14fca738 VZ |
2038 | m_dlgReplace = NULL; |
2039 | } | |
2040 | else | |
2041 | { | |
9a83f860 | 2042 | txt = wxT("Unknown"); |
13188def | 2043 | idMenu = wxID_ANY; |
14fca738 | 2044 | |
9a83f860 | 2045 | wxFAIL_MSG( wxT("unexpected event") ); |
14fca738 VZ |
2046 | } |
2047 | ||
df26c4c6 VZ |
2048 | wxLogMessage(wxT("%s dialog is being closed."), txt); |
2049 | ||
13188def | 2050 | if ( idMenu != wxID_ANY ) |
df26c4c6 | 2051 | { |
13188def | 2052 | GetMenuBar()->Check(idMenu, false); |
df26c4c6 | 2053 | } |
761989ff | 2054 | |
14fca738 | 2055 | dlg->Destroy(); |
761989ff VZ |
2056 | } |
2057 | else | |
2058 | { | |
4693b20c | 2059 | wxLogError(wxT("Unknown find dialog event!")); |
761989ff VZ |
2060 | } |
2061 | } | |
2062 | ||
2063 | #endif // wxUSE_FINDREPLDLG | |
2064 | ||
abceee76 VZ |
2065 | // ---------------------------------------------------------------------------- |
2066 | // MyCanvas | |
2067 | // ---------------------------------------------------------------------------- | |
2068 | ||
d355d3fe | 2069 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
457814b5 | 2070 | { |
c50f1fb9 | 2071 | wxPaintDC dc(this); |
457814b5 | 2072 | dc.SetBackgroundMode(wxTRANSPARENT); |
dc96b1b6 | 2073 | dc.DrawText( |
9a83f860 | 2074 | wxT("wxWidgets common dialogs") |
dc96b1b6 | 2075 | #if !defined(__SMARTPHONE__) |
9a83f860 | 2076 | wxT(" test application") |
dc96b1b6 WS |
2077 | #endif |
2078 | , 10, 10); | |
457814b5 JS |
2079 | } |
2080 | ||
b4954d19 WS |
2081 | #if USE_MODAL_PRESENTATION |
2082 | ||
4c45f240 VZ |
2083 | // ---------------------------------------------------------------------------- |
2084 | // MyModelessDialog | |
2085 | // ---------------------------------------------------------------------------- | |
457814b5 | 2086 | |
4c45f240 | 2087 | MyModelessDialog::MyModelessDialog(wxWindow *parent) |
9a83f860 | 2088 | : wxDialog(parent, wxID_ANY, wxString(wxT("Modeless dialog"))) |
4c45f240 | 2089 | { |
cbc66a27 VZ |
2090 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
2091 | ||
9a83f860 VZ |
2092 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, wxT("Press me")); |
2093 | wxCheckBox *check = new wxCheckBox(this, wxID_ANY, wxT("Should be disabled")); | |
cbc66a27 VZ |
2094 | check->Disable(); |
2095 | ||
2096 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
2097 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
2098 | ||
8ce68f7f | 2099 | SetSizerAndFit(sizerTop); |
4c45f240 | 2100 | } |
abceee76 | 2101 | |
5d987909 VZ |
2102 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) |
2103 | { | |
9a83f860 | 2104 | wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"), |
5d987909 VZ |
2105 | wxOK | wxICON_INFORMATION, this); |
2106 | } | |
2107 | ||
abceee76 VZ |
2108 | void MyModelessDialog::OnClose(wxCloseEvent& event) |
2109 | { | |
2110 | if ( event.CanVeto() ) | |
2111 | { | |
9a83f860 VZ |
2112 | wxMessageBox(wxT("Use the menu item to close this dialog"), |
2113 | wxT("Modeless dialog"), | |
abceee76 VZ |
2114 | wxOK | wxICON_INFORMATION, this); |
2115 | ||
2116 | event.Veto(); | |
2117 | } | |
2118 | } | |
2119 | ||
f6bcfd97 BP |
2120 | // ---------------------------------------------------------------------------- |
2121 | // MyModalDialog | |
2122 | // ---------------------------------------------------------------------------- | |
2123 | ||
2124 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
9a83f860 | 2125 | : wxDialog(parent, wxID_ANY, wxString(wxT("Modal dialog"))) |
f6bcfd97 BP |
2126 | { |
2127 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
2128 | ||
9a83f860 VZ |
2129 | m_btnModal = new wxButton(this, wxID_ANY, wxT("&Modal dialog...")); |
2130 | m_btnModeless = new wxButton(this, wxID_ANY, wxT("Mode&less dialog")); | |
2131 | m_btnDelete = new wxButton(this, wxID_ANY, wxT("&Delete button")); | |
5315ebfa | 2132 | |
5315ebfa VZ |
2133 | sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); |
2134 | sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); | |
f6bcfd97 | 2135 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); |
5a58a134 | 2136 | sizerTop->Add(new wxButton(this, wxID_CLOSE), 0, wxALIGN_CENTER | wxALL, 5); |
f6bcfd97 | 2137 | |
8ce68f7f | 2138 | SetSizerAndFit(sizerTop); |
f6bcfd97 | 2139 | |
5a58a134 VZ |
2140 | SetEscapeId(wxID_CLOSE); |
2141 | ||
5315ebfa VZ |
2142 | m_btnModal->SetFocus(); |
2143 | m_btnModal->SetDefault(); | |
f6bcfd97 BP |
2144 | } |
2145 | ||
2146 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
2147 | { | |
2148 | if ( event.GetEventObject() == m_btnDelete ) | |
2149 | { | |
5315ebfa VZ |
2150 | delete m_btnModal; |
2151 | m_btnModal = NULL; | |
f6bcfd97 BP |
2152 | |
2153 | m_btnDelete->Disable(); | |
2154 | } | |
5315ebfa | 2155 | else if ( event.GetEventObject() == m_btnModal ) |
f6bcfd97 | 2156 | { |
13188def | 2157 | #if wxUSE_TEXTDLG |
9a83f860 VZ |
2158 | wxGetTextFromUser(wxT("Dummy prompt"), |
2159 | wxT("Modal dialog called from dialog"), | |
dabbc6a5 | 2160 | wxEmptyString, this); |
13188def | 2161 | #else |
9a83f860 | 2162 | wxMessageBox(wxT("Modal dialog called from dialog")); |
13188def | 2163 | #endif // wxUSE_TEXTDLG |
f6bcfd97 | 2164 | } |
5315ebfa VZ |
2165 | else if ( event.GetEventObject() == m_btnModeless ) |
2166 | { | |
2167 | (new MyModelessDialog(this))->Show(); | |
2168 | } | |
f6bcfd97 BP |
2169 | else |
2170 | { | |
2171 | event.Skip(); | |
2172 | } | |
2173 | } | |
b4954d19 WS |
2174 | |
2175 | #endif // USE_MODAL_PRESENTATION | |
2176 | ||
8e1dac82 VZ |
2177 | // ---------------------------------------------------------------------------- |
2178 | // StdButtonSizerDialog | |
2179 | // ---------------------------------------------------------------------------- | |
2180 | ||
2181 | StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent) | |
9a83f860 | 2182 | : wxDialog(parent, wxID_ANY, wxString(wxT("StdButtonSizer dialog")), |
8e1dac82 VZ |
2183 | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER), |
2184 | m_buttonsSizer(NULL) | |
2185 | { | |
2186 | wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL); | |
2187 | ||
2188 | wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL); | |
2189 | wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL); | |
2190 | ||
2191 | m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button")); | |
2192 | ||
2193 | wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button")); | |
2194 | ||
2195 | m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
2196 | m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes")); | |
2197 | ||
2198 | wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL); | |
2199 | ||
2200 | m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button")); | |
2201 | ||
2202 | wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button")); | |
2203 | ||
2204 | m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
2205 | m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close")); | |
2206 | ||
2207 | wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL); | |
2208 | ||
2209 | m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No")); | |
2210 | m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help")); | |
2211 | m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply")); | |
2212 | ||
2213 | m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default")); | |
2214 | ||
2215 | sizer1->Add(m_radiobtnOk, 0, wxALL, 5); | |
2216 | sizer1->Add(m_radiobtnYes, 0, wxALL, 5); | |
2217 | ||
2218 | sizer->Add(sizerInside1, 0, 0, 0); | |
2219 | sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5); | |
2220 | sizerInside1->Add(sizer1, 0, wxALL, 5); | |
2221 | sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
2222 | ||
2223 | sizer2->Add(m_radiobtnCancel, 0, wxALL, 5); | |
2224 | sizer2->Add(m_radiobtnClose, 0, wxALL, 5); | |
2225 | ||
2226 | sizer->Add(sizerInside2, 0, 0, 0); | |
2227 | sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5); | |
2228 | sizerInside2->Add(sizer2, 0, wxALL, 5); | |
2229 | sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
2230 | ||
2231 | sizerTop->Add(sizer, 0, wxALL, 5); | |
2232 | ||
2233 | sizer3->Add(m_chkboxNo, 0, wxALL, 5); | |
2234 | sizer3->Add(m_chkboxHelp, 0, wxALL, 5); | |
2235 | sizer3->Add(m_chkboxApply, 0, wxALL, 5); | |
2236 | ||
2237 | sizerTop->Add(sizer3, 0, wxALL, 5); | |
2238 | ||
2239 | sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10); | |
2240 | ||
2241 | EnableDisableControls(); | |
2242 | ||
8ce68f7f | 2243 | SetSizerAndFit(sizerTop); |
8e1dac82 | 2244 | |
8e1dac82 VZ |
2245 | wxCommandEvent ev; |
2246 | OnEvent(ev); | |
2247 | } | |
2248 | ||
2249 | void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event)) | |
2250 | { | |
2251 | if (m_buttonsSizer) | |
2252 | { | |
2253 | m_buttonsSizer->DeleteWindows(); | |
2254 | GetSizer()->Remove(m_buttonsSizer); | |
2255 | } | |
2256 | ||
2257 | EnableDisableControls(); | |
2258 | ||
2259 | long flags = 0; | |
2260 | unsigned long numButtons = 0; | |
2261 | ||
2262 | if (m_chkboxAffirmativeButton->IsChecked()) | |
2263 | { | |
2264 | if (m_radiobtnOk->GetValue()) | |
2265 | { | |
2266 | flags |= wxOK; | |
2267 | numButtons ++; | |
2268 | } | |
2269 | else if (m_radiobtnYes->GetValue()) | |
2270 | { | |
2271 | flags |= wxYES; | |
2272 | numButtons ++; | |
2273 | } | |
2274 | } | |
2275 | ||
2276 | if (m_chkboxDismissButton->IsChecked()) | |
2277 | { | |
2278 | if (m_radiobtnCancel->GetValue()) | |
2279 | { | |
2280 | flags |= wxCANCEL; | |
2281 | numButtons ++; | |
2282 | } | |
2283 | ||
2284 | else if (m_radiobtnClose->GetValue()) | |
2285 | { | |
2286 | flags |= wxCLOSE; | |
2287 | numButtons ++; | |
2288 | } | |
2289 | ||
2290 | } | |
2291 | ||
2292 | if (m_chkboxApply->IsChecked()) | |
2293 | { | |
2294 | flags |= wxAPPLY; | |
2295 | numButtons ++; | |
2296 | } | |
2297 | ||
2298 | if (m_chkboxNo->IsChecked()) | |
2299 | { | |
2300 | flags |= wxNO; | |
2301 | numButtons ++; | |
2302 | } | |
2303 | ||
2304 | if (m_chkboxHelp->IsChecked()) | |
2305 | { | |
2306 | flags |= wxHELP; | |
2307 | numButtons ++; | |
2308 | } | |
2309 | ||
2310 | if (m_chkboxNoDefault->IsChecked()) | |
2311 | { | |
2312 | flags |= wxNO_DEFAULT; | |
2313 | } | |
2314 | ||
2315 | m_buttonsSizer = CreateStdDialogButtonSizer(flags); | |
2316 | GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5); | |
2317 | ||
2318 | Layout(); | |
2319 | GetSizer()->SetSizeHints(this); | |
2320 | } | |
2321 | ||
2322 | void StdButtonSizerDialog::EnableDisableControls() | |
2323 | { | |
2324 | const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked(); | |
2325 | ||
2326 | m_radiobtnOk->Enable(affButtonEnabled); | |
2327 | m_radiobtnYes->Enable(affButtonEnabled); | |
2328 | ||
2329 | const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked(); | |
2330 | ||
2331 | m_radiobtnCancel->Enable(dismissButtonEnabled); | |
2332 | m_radiobtnClose->Enable(dismissButtonEnabled); | |
2333 | } | |
2334 | ||
532d575b | 2335 | #if USE_SETTINGS_DIALOG |
0f5d8ecf JS |
2336 | // ---------------------------------------------------------------------------- |
2337 | // SettingsDialog | |
2338 | // ---------------------------------------------------------------------------- | |
2339 | ||
2340 | IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog) | |
2341 | ||
2342 | BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog) | |
2343 | END_EVENT_TABLE() | |
2344 | ||
64d3ed17 | 2345 | SettingsDialog::SettingsDialog(wxWindow* win, int dialogType) |
0f5d8ecf | 2346 | { |
0f4991f4 | 2347 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); |
0f5d8ecf | 2348 | |
cc8bc5aa JS |
2349 | int tabImage1 = -1; |
2350 | int tabImage2 = -1; | |
e031f1df | 2351 | |
64d3ed17 | 2352 | bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK); |
77631b1d | 2353 | int resizeBorder = wxRESIZE_BORDER; |
684883e3 | 2354 | |
cc8bc5aa JS |
2355 | if (useToolBook) |
2356 | { | |
77631b1d | 2357 | resizeBorder = 0; |
cc8bc5aa JS |
2358 | tabImage1 = 0; |
2359 | tabImage2 = 1; | |
e031f1df | 2360 | |
64d3ed17 JS |
2361 | int sheetStyle = wxPROPSHEET_SHRINKTOFIT; |
2362 | if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK) | |
2363 | sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK; | |
2364 | else | |
2365 | sheetStyle |= wxPROPSHEET_TOOLBOOK; | |
e031f1df | 2366 | |
64d3ed17 | 2367 | SetSheetStyle(sheetStyle); |
77631b1d JS |
2368 | SetSheetInnerBorder(0); |
2369 | SetSheetOuterBorder(0); | |
cc8bc5aa JS |
2370 | |
2371 | // create a dummy image list with a few icons | |
2372 | const wxSize imageSize(32, 32); | |
2373 | ||
2374 | m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); | |
2375 | m_imageList-> | |
2376 | Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); | |
2377 | m_imageList-> | |
2378 | Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); | |
2379 | m_imageList-> | |
2380 | Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); | |
2381 | m_imageList-> | |
2382 | Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); | |
2383 | } | |
2384 | else | |
2385 | m_imageList = NULL; | |
2386 | ||
532d575b | 2387 | Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize, |
654ffe9f | 2388 | wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder) |
3103e8a9 | 2389 | ); |
cc8bc5aa | 2390 | |
684883e3 | 2391 | // If using a toolbook, also follow Mac style and don't create buttons |
cc8bc5aa | 2392 | if (!useToolBook) |
654ffe9f VZ |
2393 | CreateButtons(wxOK | wxCANCEL | |
2394 | (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP) | |
897b24cf | 2395 | ); |
0f5d8ecf JS |
2396 | |
2397 | wxBookCtrlBase* notebook = GetBookCtrl(); | |
cc8bc5aa | 2398 | notebook->SetImageList(m_imageList); |
0f5d8ecf JS |
2399 | |
2400 | wxPanel* generalSettings = CreateGeneralSettingsPage(notebook); | |
2401 | wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook); | |
2402 | ||
cc8bc5aa JS |
2403 | notebook->AddPage(generalSettings, _("General"), true, tabImage1); |
2404 | notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2); | |
0f5d8ecf JS |
2405 | |
2406 | LayoutDialog(); | |
2407 | } | |
2408 | ||
cc8bc5aa JS |
2409 | SettingsDialog::~SettingsDialog() |
2410 | { | |
2411 | delete m_imageList; | |
2412 | } | |
2413 | ||
0f5d8ecf JS |
2414 | wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent) |
2415 | { | |
2416 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
2417 | ||
2418 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
2419 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
2420 | ||
2421 | //// LOAD LAST FILE | |
2422 | ||
2423 | wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL ); | |
2424 | wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize); | |
2425 | itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2426 | item0->Add(itemSizer3, 0, wxGROW|wxALL, 0); | |
2427 | ||
2428 | //// AUTOSAVE | |
2429 | ||
2430 | wxString autoSaveLabel = _("&Auto-save every"); | |
2431 | wxString minsLabel = _("mins"); | |
2432 | ||
2433 | wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL ); | |
2434 | wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize); | |
62675ef3 JS |
2435 | |
2436 | #if wxUSE_SPINCTRL | |
0f5d8ecf | 2437 | wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString, |
532d575b | 2438 | wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1); |
62675ef3 | 2439 | #endif |
532d575b | 2440 | |
0f5d8ecf | 2441 | itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
62675ef3 | 2442 | #if wxUSE_SPINCTRL |
0f5d8ecf | 2443 | itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
62675ef3 | 2444 | #endif |
0f5d8ecf JS |
2445 | itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
2446 | item0->Add(itemSizer12, 0, wxGROW|wxALL, 0); | |
2447 | ||
2448 | //// TOOLTIPS | |
532d575b | 2449 | |
0f5d8ecf JS |
2450 | wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL ); |
2451 | wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize); | |
2452 | itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2453 | item0->Add(itemSizer8, 0, wxGROW|wxALL, 0); | |
2454 | ||
2455 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
2456 | ||
8ce68f7f | 2457 | panel->SetSizerAndFit(topSizer); |
532d575b | 2458 | |
0f5d8ecf JS |
2459 | return panel; |
2460 | } | |
2461 | ||
2462 | wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent) | |
2463 | { | |
2464 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
2465 | ||
2466 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
2467 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
2468 | ||
2469 | //// PROJECT OR GLOBAL | |
2470 | wxString globalOrProjectChoices[2]; | |
2471 | globalOrProjectChoices[0] = _("&New projects"); | |
2472 | globalOrProjectChoices[1] = _("&This project"); | |
2473 | ||
2474 | wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"), | |
2475 | wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices); | |
2476 | item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5); | |
2477 | ||
2478 | projectOrGlobal->SetSelection(0); | |
2479 | ||
2480 | //// BACKGROUND STYLE | |
2481 | wxArrayString backgroundStyleChoices; | |
2482 | backgroundStyleChoices.Add(wxT("Colour")); | |
2483 | backgroundStyleChoices.Add(wxT("Image")); | |
532d575b | 2484 | wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:")); |
0f5d8ecf JS |
2485 | |
2486 | wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL ); | |
2487 | item0->Add(styleSizer, 0, wxGROW|wxALL, 5); | |
2488 | ||
2489 | wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
2490 | ||
2491 | wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices); | |
2492 | ||
2493 | itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2494 | itemSizer2->Add(5, 5, 1, wxALL, 0); | |
2495 | itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2496 | ||
2497 | styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5); | |
2498 | ||
62675ef3 | 2499 | #if wxUSE_SPINCTRL |
0f5d8ecf JS |
2500 | //// FONT SIZE SELECTION |
2501 | ||
532d575b | 2502 | wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:")); |
0f5d8ecf JS |
2503 | wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL ); |
2504 | ||
2505 | wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition, | |
532d575b | 2506 | wxSize(80, wxDefaultCoord)); |
0f5d8ecf JS |
2507 | itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); |
2508 | ||
2509 | item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5); | |
62675ef3 | 2510 | #endif |
0f5d8ecf JS |
2511 | |
2512 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
0f4991f4 | 2513 | topSizer->AddSpacer(5); |
0f5d8ecf | 2514 | |
8ce68f7f | 2515 | panel->SetSizerAndFit(topSizer); |
532d575b | 2516 | |
0f5d8ecf JS |
2517 | return panel; |
2518 | } | |
2519 | ||
44b25eac VZ |
2520 | // ---------------------------------------------------------------------------- |
2521 | // TestMessageBoxDialog | |
2522 | // ---------------------------------------------------------------------------- | |
2523 | ||
b3ca7c85 VZ |
2524 | /* static */ |
2525 | const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] = | |
44b25eac VZ |
2526 | { |
2527 | { wxYES, "&Yes" }, | |
2528 | { wxNO, "&No" }, | |
2529 | { wxOK, "&Ok" }, | |
2530 | { wxCANCEL, "&Cancel" }, | |
2531 | }; | |
2532 | ||
2533 | BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog) | |
2534 | EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply) | |
2535 | EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose) | |
2536 | END_EVENT_TABLE() | |
2537 | ||
2538 | TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent) | |
2539 | : wxDialog(parent, wxID_ANY, "Message Box Test Dialog", | |
2540 | wxDefaultPosition, wxDefaultSize, | |
2541 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) | |
2542 | { | |
2543 | wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL); | |
2544 | ||
2545 | // this sizer allows to configure the messages shown in the message box | |
2546 | wxSizer * const | |
2547 | sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages"); | |
2548 | sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:")); | |
4e2dc789 | 2549 | m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!", |
44b25eac VZ |
2550 | wxDefaultPosition, wxDefaultSize, |
2551 | wxTE_MULTILINE); | |
2552 | sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM)); | |
2553 | ||
2554 | sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:")); | |
2555 | m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "", | |
2556 | wxDefaultPosition, wxDefaultSize, | |
2557 | wxTE_MULTILINE); | |
2558 | sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand()); | |
2559 | ||
2560 | sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border()); | |
2561 | ||
2562 | ||
2563 | // this one is for configuring the buttons | |
f68376d9 SC |
2564 | wxSizer * const |
2565 | sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons"); | |
2566 | ||
44b25eac VZ |
2567 | wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5); |
2568 | sizerBtns->AddGrowableCol(1); | |
2569 | ||
2570 | sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)")); | |
2571 | sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label")); | |
2572 | ||
2573 | for ( int n = 0; n < Btn_Max; n++ ) | |
2574 | { | |
2575 | m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name); | |
2576 | sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left()); | |
2577 | ||
2578 | m_labels[n] = new wxTextCtrl(this, wxID_ANY); | |
2579 | sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand()); | |
2580 | ||
2581 | m_labels[n]->Connect(wxEVT_UPDATE_UI, | |
2582 | wxUpdateUIEventHandler( | |
2583 | TestMessageBoxDialog::OnUpdateLabelUI), | |
2584 | NULL, | |
2585 | this); | |
2586 | } | |
2587 | ||
44b25eac VZ |
2588 | sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand()); |
2589 | sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border()); | |
2590 | ||
2591 | ||
2592 | // icon choice | |
8783d72f VZ |
2593 | const wxString icons[] = |
2594 | { | |
2595 | "&Not specified", | |
2596 | "E&xplicitly none", | |
2597 | "&Information icon", | |
2598 | "&Question icon", | |
2599 | "&Warning icon", | |
2600 | "&Error icon" | |
44b25eac VZ |
2601 | }; |
2602 | ||
e1cf09d9 | 2603 | wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == MsgDlgIcon_Max, IconMismatch ); |
e1cf09d9 | 2604 | |
8783d72f | 2605 | m_icons = new wxRadioBox(this, wxID_ANY, "&Icon style", |
44b25eac | 2606 | wxDefaultPosition, wxDefaultSize, |
8783d72f VZ |
2607 | WXSIZEOF(icons), icons, |
2608 | 2, wxRA_SPECIFY_ROWS); | |
7e3204b4 | 2609 | // Make the 'Information' icon the default one: |
8783d72f | 2610 | m_icons->SetSelection(MsgDlgIcon_Info); |
44b25eac VZ |
2611 | sizerTop->Add(m_icons, wxSizerFlags().Expand().Border()); |
2612 | ||
2613 | ||
4e2dc789 VZ |
2614 | // miscellaneous other stuff |
2615 | wxSizer * const | |
2616 | sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags"); | |
2617 | ||
2618 | m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default"); | |
2619 | m_chkNoDefault->Connect(wxEVT_UPDATE_UI, | |
2620 | wxUpdateUIEventHandler( | |
2621 | TestMessageBoxDialog::OnUpdateNoDefaultUI), | |
2622 | NULL, | |
2623 | this); | |
2624 | sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border()); | |
2625 | ||
2626 | m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent"); | |
2627 | sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border()); | |
2628 | ||
2629 | sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border()); | |
2630 | ||
44b25eac VZ |
2631 | // finally buttons to show the resulting message box and close this dialog |
2632 | sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE), | |
2633 | wxSizerFlags().Right().Border()); | |
2634 | ||
2635 | SetSizerAndFit(sizerTop); | |
4e2dc789 VZ |
2636 | |
2637 | m_buttons[Btn_Ok]->SetValue(true); | |
44b25eac VZ |
2638 | } |
2639 | ||
2640 | void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event) | |
2641 | { | |
2642 | for ( int n = 0; n < Btn_Max; n++ ) | |
2643 | { | |
2644 | if ( event.GetEventObject() == m_labels[n] ) | |
2645 | { | |
2646 | event.Enable( m_buttons[n]->IsChecked() ); | |
2647 | return; | |
2648 | } | |
2649 | } | |
2650 | ||
2651 | wxFAIL_MSG( "called for unknown label" ); | |
2652 | } | |
2653 | ||
4e2dc789 VZ |
2654 | void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event) |
2655 | { | |
2656 | event.Enable( m_buttons[Btn_No]->IsChecked() ); | |
2657 | } | |
2658 | ||
44b25eac VZ |
2659 | void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) |
2660 | { | |
2661 | long style = 0; | |
2662 | ||
2663 | for ( int n = 0; n < Btn_Max; n++ ) | |
2664 | { | |
2665 | if ( m_buttons[n]->IsChecked() ) | |
2666 | style |= ms_btnInfo[n].flag; | |
2667 | } | |
2668 | ||
2669 | switch ( m_icons->GetSelection() ) | |
2670 | { | |
8783d72f VZ |
2671 | case MsgDlgIcon_Max: |
2672 | wxFAIL_MSG( "unexpected selection" ); | |
2673 | ||
2674 | case MsgDlgIcon_No: | |
2675 | break; | |
2676 | ||
2677 | case MsgDlgIcon_None: | |
2678 | style |= wxICON_NONE; | |
2679 | break; | |
2680 | ||
2681 | case MsgDlgIcon_Info: | |
2682 | style |= wxICON_INFORMATION; | |
2683 | break; | |
2684 | ||
2685 | case MsgDlgIcon_Question: | |
2686 | style |= wxICON_QUESTION; | |
2687 | break; | |
2688 | ||
2689 | case MsgDlgIcon_Warning: | |
2690 | style |= wxICON_WARNING; | |
2691 | break; | |
2692 | ||
2693 | case MsgDlgIcon_Error: | |
2694 | style |= wxICON_ERROR; | |
2695 | break; | |
44b25eac VZ |
2696 | } |
2697 | ||
4e2dc789 VZ |
2698 | if ( m_chkCentre->IsChecked() ) |
2699 | style |= wxCENTRE; | |
2700 | ||
2701 | if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() ) | |
2702 | style |= wxNO_DEFAULT; | |
2703 | ||
2704 | ||
44b25eac VZ |
2705 | wxMessageDialog dlg(this, m_textMsg->GetValue(), "Test Message Box", |
2706 | style); | |
2707 | if ( !m_textExtMsg->IsEmpty() ) | |
2708 | dlg.SetExtendedMessage(m_textExtMsg->GetValue()); | |
2709 | ||
2710 | if ( style & wxYES_NO ) | |
2711 | { | |
2712 | if ( style & wxCANCEL ) | |
2713 | { | |
2714 | dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(), | |
2715 | m_labels[Btn_No]->GetValue(), | |
2716 | m_labels[Btn_Cancel]->GetValue()); | |
2717 | } | |
2718 | else | |
2719 | { | |
2720 | dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(), | |
2721 | m_labels[Btn_No]->GetValue()); | |
2722 | } | |
2723 | } | |
2724 | else | |
2725 | { | |
2726 | if ( style & wxCANCEL ) | |
2727 | { | |
2728 | dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(), | |
2729 | m_labels[Btn_Cancel]->GetValue()); | |
2730 | } | |
2731 | else | |
2732 | { | |
2733 | dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue()); | |
2734 | } | |
2735 | } | |
2736 | ||
2737 | dlg.ShowModal(); | |
2738 | } | |
2739 | ||
2740 | void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event)) | |
2741 | { | |
2742 | EndModal(wxID_CANCEL); | |
2743 | } | |
2744 | ||
532d575b | 2745 | #endif // USE_SETTINGS_DIALOG |
9ad2fe62 VZ |
2746 | |
2747 | #if wxUSE_LOG | |
2748 | ||
2749 | // ---------------------------------------------------------------------------- | |
2750 | // custom log target | |
2751 | // ---------------------------------------------------------------------------- | |
2752 | ||
2753 | class MyLogGui : public wxLogGui | |
2754 | { | |
2755 | private: | |
2756 | virtual void DoShowSingleLogMessage(const wxString& message, | |
2757 | const wxString& title, | |
2758 | int style) | |
2759 | { | |
f0afc953 VZ |
2760 | wxMessageDialog dlg(NULL, message, title, |
2761 | wxOK | wxCANCEL | wxCANCEL_DEFAULT | style); | |
2762 | dlg.SetOKCancelLabels(wxID_COPY, wxID_OK); | |
9ad2fe62 VZ |
2763 | dlg.SetExtendedMessage("Note that this is a custom log dialog."); |
2764 | dlg.ShowModal(); | |
2765 | } | |
2766 | }; | |
2767 | ||
2768 | wxLog *MyAppTraits::CreateLogTarget() | |
2769 | { | |
2770 | return new MyLogGui; | |
2771 | } | |
2772 | ||
2773 | #endif // wxUSE_LOG |