]>
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 | |
526954c5 | 10 | // Licence: wxWindows licence |
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 | { |
3cb332c1 | 499 | SetIcon(wxICON(sample)); |
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 | { | |
5276b0a5 | 1952 | wxDELETE(m_dlgReplace); |
14fca738 VZ |
1953 | } |
1954 | else | |
1955 | { | |
1956 | m_dlgReplace = new wxFindReplaceDialog | |
1957 | ( | |
1958 | this, | |
1959 | &m_findData, | |
9a83f860 | 1960 | wxT("Find and replace dialog"), |
14fca738 VZ |
1961 | wxFR_REPLACEDIALOG |
1962 | ); | |
1963 | ||
13188def | 1964 | m_dlgReplace->Show(true); |
14fca738 | 1965 | } |
761989ff VZ |
1966 | } |
1967 | ||
1968 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
1969 | { | |
14fca738 VZ |
1970 | if ( m_dlgFind ) |
1971 | { | |
5276b0a5 | 1972 | wxDELETE(m_dlgFind); |
14fca738 VZ |
1973 | } |
1974 | else | |
1975 | { | |
1976 | m_dlgFind = new wxFindReplaceDialog | |
1977 | ( | |
1978 | this, | |
1979 | &m_findData, | |
9a83f860 | 1980 | wxT("Find dialog"), |
14fca738 VZ |
1981 | // just for testing |
1982 | wxFR_NOWHOLEWORD | |
1983 | ); | |
1984 | ||
13188def | 1985 | m_dlgFind->Show(true); |
14fca738 | 1986 | } |
761989ff VZ |
1987 | } |
1988 | ||
1989 | static wxString DecodeFindDialogEventFlags(int flags) | |
1990 | { | |
1991 | wxString str; | |
9a83f860 VZ |
1992 | str << (flags & wxFR_DOWN ? wxT("down") : wxT("up")) << wxT(", ") |
1993 | << (flags & wxFR_WHOLEWORD ? wxT("whole words only, ") : wxT("")) | |
1994 | << (flags & wxFR_MATCHCASE ? wxT("") : wxT("not ")) | |
1995 | << wxT("case sensitive"); | |
761989ff VZ |
1996 | |
1997 | return str; | |
1998 | } | |
1999 | ||
2000 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
2001 | { | |
2002 | wxEventType type = event.GetEventType(); | |
2003 | ||
2004 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
2005 | { | |
4693b20c | 2006 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), |
eba33006 | 2007 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), |
761989ff VZ |
2008 | event.GetFindString().c_str(), |
2009 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
2010 | } | |
2011 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
2012 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
2013 | { | |
4693b20c | 2014 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), |
9a83f860 | 2015 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? wxT("all ") : wxT(""), |
761989ff VZ |
2016 | event.GetFindString().c_str(), |
2017 | event.GetReplaceString().c_str(), | |
2018 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
2019 | } | |
2020 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
2021 | { | |
14fca738 VZ |
2022 | wxFindReplaceDialog *dlg = event.GetDialog(); |
2023 | ||
df26c4c6 | 2024 | int idMenu; |
14fca738 VZ |
2025 | const wxChar *txt; |
2026 | if ( dlg == m_dlgFind ) | |
2027 | { | |
9a83f860 | 2028 | txt = wxT("Find"); |
df26c4c6 | 2029 | idMenu = DIALOGS_FIND; |
14fca738 VZ |
2030 | m_dlgFind = NULL; |
2031 | } | |
2032 | else if ( dlg == m_dlgReplace ) | |
2033 | { | |
9a83f860 | 2034 | txt = wxT("Replace"); |
df26c4c6 | 2035 | idMenu = DIALOGS_REPLACE; |
14fca738 VZ |
2036 | m_dlgReplace = NULL; |
2037 | } | |
2038 | else | |
2039 | { | |
9a83f860 | 2040 | txt = wxT("Unknown"); |
13188def | 2041 | idMenu = wxID_ANY; |
14fca738 | 2042 | |
9a83f860 | 2043 | wxFAIL_MSG( wxT("unexpected event") ); |
14fca738 VZ |
2044 | } |
2045 | ||
df26c4c6 VZ |
2046 | wxLogMessage(wxT("%s dialog is being closed."), txt); |
2047 | ||
13188def | 2048 | if ( idMenu != wxID_ANY ) |
df26c4c6 | 2049 | { |
13188def | 2050 | GetMenuBar()->Check(idMenu, false); |
df26c4c6 | 2051 | } |
761989ff | 2052 | |
14fca738 | 2053 | dlg->Destroy(); |
761989ff VZ |
2054 | } |
2055 | else | |
2056 | { | |
4693b20c | 2057 | wxLogError(wxT("Unknown find dialog event!")); |
761989ff VZ |
2058 | } |
2059 | } | |
2060 | ||
2061 | #endif // wxUSE_FINDREPLDLG | |
2062 | ||
abceee76 VZ |
2063 | // ---------------------------------------------------------------------------- |
2064 | // MyCanvas | |
2065 | // ---------------------------------------------------------------------------- | |
2066 | ||
d355d3fe | 2067 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
457814b5 | 2068 | { |
c50f1fb9 | 2069 | wxPaintDC dc(this); |
457814b5 | 2070 | dc.SetBackgroundMode(wxTRANSPARENT); |
dc96b1b6 | 2071 | dc.DrawText( |
9a83f860 | 2072 | wxT("wxWidgets common dialogs") |
dc96b1b6 | 2073 | #if !defined(__SMARTPHONE__) |
9a83f860 | 2074 | wxT(" test application") |
dc96b1b6 WS |
2075 | #endif |
2076 | , 10, 10); | |
457814b5 JS |
2077 | } |
2078 | ||
b4954d19 WS |
2079 | #if USE_MODAL_PRESENTATION |
2080 | ||
4c45f240 VZ |
2081 | // ---------------------------------------------------------------------------- |
2082 | // MyModelessDialog | |
2083 | // ---------------------------------------------------------------------------- | |
457814b5 | 2084 | |
4c45f240 | 2085 | MyModelessDialog::MyModelessDialog(wxWindow *parent) |
9a83f860 | 2086 | : wxDialog(parent, wxID_ANY, wxString(wxT("Modeless dialog"))) |
4c45f240 | 2087 | { |
cbc66a27 VZ |
2088 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
2089 | ||
9a83f860 VZ |
2090 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, wxT("Press me")); |
2091 | wxCheckBox *check = new wxCheckBox(this, wxID_ANY, wxT("Should be disabled")); | |
cbc66a27 VZ |
2092 | check->Disable(); |
2093 | ||
2094 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
2095 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
2096 | ||
8ce68f7f | 2097 | SetSizerAndFit(sizerTop); |
4c45f240 | 2098 | } |
abceee76 | 2099 | |
5d987909 VZ |
2100 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) |
2101 | { | |
9a83f860 | 2102 | wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"), |
5d987909 VZ |
2103 | wxOK | wxICON_INFORMATION, this); |
2104 | } | |
2105 | ||
abceee76 VZ |
2106 | void MyModelessDialog::OnClose(wxCloseEvent& event) |
2107 | { | |
2108 | if ( event.CanVeto() ) | |
2109 | { | |
9a83f860 VZ |
2110 | wxMessageBox(wxT("Use the menu item to close this dialog"), |
2111 | wxT("Modeless dialog"), | |
abceee76 VZ |
2112 | wxOK | wxICON_INFORMATION, this); |
2113 | ||
2114 | event.Veto(); | |
2115 | } | |
2116 | } | |
2117 | ||
f6bcfd97 BP |
2118 | // ---------------------------------------------------------------------------- |
2119 | // MyModalDialog | |
2120 | // ---------------------------------------------------------------------------- | |
2121 | ||
2122 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
9a83f860 | 2123 | : wxDialog(parent, wxID_ANY, wxString(wxT("Modal dialog"))) |
f6bcfd97 BP |
2124 | { |
2125 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
2126 | ||
9a83f860 VZ |
2127 | m_btnModal = new wxButton(this, wxID_ANY, wxT("&Modal dialog...")); |
2128 | m_btnModeless = new wxButton(this, wxID_ANY, wxT("Mode&less dialog")); | |
2129 | m_btnDelete = new wxButton(this, wxID_ANY, wxT("&Delete button")); | |
5315ebfa | 2130 | |
5315ebfa VZ |
2131 | sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); |
2132 | sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); | |
f6bcfd97 | 2133 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); |
5a58a134 | 2134 | sizerTop->Add(new wxButton(this, wxID_CLOSE), 0, wxALIGN_CENTER | wxALL, 5); |
f6bcfd97 | 2135 | |
8ce68f7f | 2136 | SetSizerAndFit(sizerTop); |
f6bcfd97 | 2137 | |
5a58a134 VZ |
2138 | SetEscapeId(wxID_CLOSE); |
2139 | ||
5315ebfa VZ |
2140 | m_btnModal->SetFocus(); |
2141 | m_btnModal->SetDefault(); | |
f6bcfd97 BP |
2142 | } |
2143 | ||
2144 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
2145 | { | |
2146 | if ( event.GetEventObject() == m_btnDelete ) | |
2147 | { | |
5276b0a5 | 2148 | wxDELETE(m_btnModal); |
f6bcfd97 BP |
2149 | m_btnDelete->Disable(); |
2150 | } | |
5315ebfa | 2151 | else if ( event.GetEventObject() == m_btnModal ) |
f6bcfd97 | 2152 | { |
13188def | 2153 | #if wxUSE_TEXTDLG |
9a83f860 VZ |
2154 | wxGetTextFromUser(wxT("Dummy prompt"), |
2155 | wxT("Modal dialog called from dialog"), | |
dabbc6a5 | 2156 | wxEmptyString, this); |
13188def | 2157 | #else |
9a83f860 | 2158 | wxMessageBox(wxT("Modal dialog called from dialog")); |
13188def | 2159 | #endif // wxUSE_TEXTDLG |
f6bcfd97 | 2160 | } |
5315ebfa VZ |
2161 | else if ( event.GetEventObject() == m_btnModeless ) |
2162 | { | |
2163 | (new MyModelessDialog(this))->Show(); | |
2164 | } | |
f6bcfd97 BP |
2165 | else |
2166 | { | |
2167 | event.Skip(); | |
2168 | } | |
2169 | } | |
b4954d19 WS |
2170 | |
2171 | #endif // USE_MODAL_PRESENTATION | |
2172 | ||
8e1dac82 VZ |
2173 | // ---------------------------------------------------------------------------- |
2174 | // StdButtonSizerDialog | |
2175 | // ---------------------------------------------------------------------------- | |
2176 | ||
2177 | StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent) | |
9a83f860 | 2178 | : wxDialog(parent, wxID_ANY, wxString(wxT("StdButtonSizer dialog")), |
8e1dac82 VZ |
2179 | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER), |
2180 | m_buttonsSizer(NULL) | |
2181 | { | |
2182 | wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL); | |
2183 | ||
2184 | wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL); | |
2185 | wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL); | |
2186 | ||
2187 | m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button")); | |
2188 | ||
2189 | wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button")); | |
2190 | ||
2191 | m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
2192 | m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes")); | |
2193 | ||
2194 | wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL); | |
2195 | ||
2196 | m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button")); | |
2197 | ||
2198 | wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button")); | |
2199 | ||
2200 | m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | |
2201 | m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close")); | |
2202 | ||
2203 | wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL); | |
2204 | ||
2205 | m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No")); | |
2206 | m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help")); | |
2207 | m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply")); | |
2208 | ||
2209 | m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default")); | |
2210 | ||
2211 | sizer1->Add(m_radiobtnOk, 0, wxALL, 5); | |
2212 | sizer1->Add(m_radiobtnYes, 0, wxALL, 5); | |
2213 | ||
2214 | sizer->Add(sizerInside1, 0, 0, 0); | |
2215 | sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5); | |
2216 | sizerInside1->Add(sizer1, 0, wxALL, 5); | |
2217 | sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
2218 | ||
2219 | sizer2->Add(m_radiobtnCancel, 0, wxALL, 5); | |
2220 | sizer2->Add(m_radiobtnClose, 0, wxALL, 5); | |
2221 | ||
2222 | sizer->Add(sizerInside2, 0, 0, 0); | |
2223 | sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5); | |
2224 | sizerInside2->Add(sizer2, 0, wxALL, 5); | |
2225 | sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label | |
2226 | ||
2227 | sizerTop->Add(sizer, 0, wxALL, 5); | |
2228 | ||
2229 | sizer3->Add(m_chkboxNo, 0, wxALL, 5); | |
2230 | sizer3->Add(m_chkboxHelp, 0, wxALL, 5); | |
2231 | sizer3->Add(m_chkboxApply, 0, wxALL, 5); | |
2232 | ||
2233 | sizerTop->Add(sizer3, 0, wxALL, 5); | |
2234 | ||
2235 | sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10); | |
2236 | ||
2237 | EnableDisableControls(); | |
2238 | ||
8ce68f7f | 2239 | SetSizerAndFit(sizerTop); |
8e1dac82 | 2240 | |
8e1dac82 VZ |
2241 | wxCommandEvent ev; |
2242 | OnEvent(ev); | |
2243 | } | |
2244 | ||
2245 | void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event)) | |
2246 | { | |
2247 | if (m_buttonsSizer) | |
2248 | { | |
2249 | m_buttonsSizer->DeleteWindows(); | |
2250 | GetSizer()->Remove(m_buttonsSizer); | |
2251 | } | |
2252 | ||
2253 | EnableDisableControls(); | |
2254 | ||
2255 | long flags = 0; | |
2256 | unsigned long numButtons = 0; | |
2257 | ||
2258 | if (m_chkboxAffirmativeButton->IsChecked()) | |
2259 | { | |
2260 | if (m_radiobtnOk->GetValue()) | |
2261 | { | |
2262 | flags |= wxOK; | |
2263 | numButtons ++; | |
2264 | } | |
2265 | else if (m_radiobtnYes->GetValue()) | |
2266 | { | |
2267 | flags |= wxYES; | |
2268 | numButtons ++; | |
2269 | } | |
2270 | } | |
2271 | ||
2272 | if (m_chkboxDismissButton->IsChecked()) | |
2273 | { | |
2274 | if (m_radiobtnCancel->GetValue()) | |
2275 | { | |
2276 | flags |= wxCANCEL; | |
2277 | numButtons ++; | |
2278 | } | |
2279 | ||
2280 | else if (m_radiobtnClose->GetValue()) | |
2281 | { | |
2282 | flags |= wxCLOSE; | |
2283 | numButtons ++; | |
2284 | } | |
2285 | ||
2286 | } | |
2287 | ||
2288 | if (m_chkboxApply->IsChecked()) | |
2289 | { | |
2290 | flags |= wxAPPLY; | |
2291 | numButtons ++; | |
2292 | } | |
2293 | ||
2294 | if (m_chkboxNo->IsChecked()) | |
2295 | { | |
2296 | flags |= wxNO; | |
2297 | numButtons ++; | |
2298 | } | |
2299 | ||
2300 | if (m_chkboxHelp->IsChecked()) | |
2301 | { | |
2302 | flags |= wxHELP; | |
2303 | numButtons ++; | |
2304 | } | |
2305 | ||
2306 | if (m_chkboxNoDefault->IsChecked()) | |
2307 | { | |
2308 | flags |= wxNO_DEFAULT; | |
2309 | } | |
2310 | ||
2311 | m_buttonsSizer = CreateStdDialogButtonSizer(flags); | |
2312 | GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5); | |
2313 | ||
2314 | Layout(); | |
2315 | GetSizer()->SetSizeHints(this); | |
2316 | } | |
2317 | ||
2318 | void StdButtonSizerDialog::EnableDisableControls() | |
2319 | { | |
2320 | const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked(); | |
2321 | ||
2322 | m_radiobtnOk->Enable(affButtonEnabled); | |
2323 | m_radiobtnYes->Enable(affButtonEnabled); | |
2324 | ||
2325 | const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked(); | |
2326 | ||
2327 | m_radiobtnCancel->Enable(dismissButtonEnabled); | |
2328 | m_radiobtnClose->Enable(dismissButtonEnabled); | |
2329 | } | |
2330 | ||
532d575b | 2331 | #if USE_SETTINGS_DIALOG |
0f5d8ecf JS |
2332 | // ---------------------------------------------------------------------------- |
2333 | // SettingsDialog | |
2334 | // ---------------------------------------------------------------------------- | |
2335 | ||
2336 | IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog) | |
2337 | ||
2338 | BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog) | |
2339 | END_EVENT_TABLE() | |
2340 | ||
64d3ed17 | 2341 | SettingsDialog::SettingsDialog(wxWindow* win, int dialogType) |
0f5d8ecf | 2342 | { |
0f4991f4 | 2343 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); |
0f5d8ecf | 2344 | |
cc8bc5aa JS |
2345 | int tabImage1 = -1; |
2346 | int tabImage2 = -1; | |
e031f1df | 2347 | |
64d3ed17 | 2348 | bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK); |
77631b1d | 2349 | int resizeBorder = wxRESIZE_BORDER; |
684883e3 | 2350 | |
cc8bc5aa JS |
2351 | if (useToolBook) |
2352 | { | |
77631b1d | 2353 | resizeBorder = 0; |
cc8bc5aa JS |
2354 | tabImage1 = 0; |
2355 | tabImage2 = 1; | |
e031f1df | 2356 | |
64d3ed17 JS |
2357 | int sheetStyle = wxPROPSHEET_SHRINKTOFIT; |
2358 | if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK) | |
2359 | sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK; | |
2360 | else | |
2361 | sheetStyle |= wxPROPSHEET_TOOLBOOK; | |
e031f1df | 2362 | |
64d3ed17 | 2363 | SetSheetStyle(sheetStyle); |
77631b1d JS |
2364 | SetSheetInnerBorder(0); |
2365 | SetSheetOuterBorder(0); | |
cc8bc5aa JS |
2366 | |
2367 | // create a dummy image list with a few icons | |
2368 | const wxSize imageSize(32, 32); | |
2369 | ||
2370 | m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); | |
2371 | m_imageList-> | |
2372 | Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); | |
2373 | m_imageList-> | |
2374 | Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); | |
2375 | m_imageList-> | |
2376 | Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); | |
2377 | m_imageList-> | |
2378 | Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); | |
2379 | } | |
2380 | else | |
2381 | m_imageList = NULL; | |
2382 | ||
532d575b | 2383 | Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize, |
654ffe9f | 2384 | wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder) |
3103e8a9 | 2385 | ); |
cc8bc5aa | 2386 | |
684883e3 | 2387 | // If using a toolbook, also follow Mac style and don't create buttons |
cc8bc5aa | 2388 | if (!useToolBook) |
654ffe9f VZ |
2389 | CreateButtons(wxOK | wxCANCEL | |
2390 | (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP) | |
897b24cf | 2391 | ); |
0f5d8ecf JS |
2392 | |
2393 | wxBookCtrlBase* notebook = GetBookCtrl(); | |
cc8bc5aa | 2394 | notebook->SetImageList(m_imageList); |
0f5d8ecf JS |
2395 | |
2396 | wxPanel* generalSettings = CreateGeneralSettingsPage(notebook); | |
2397 | wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook); | |
2398 | ||
cc8bc5aa JS |
2399 | notebook->AddPage(generalSettings, _("General"), true, tabImage1); |
2400 | notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2); | |
0f5d8ecf JS |
2401 | |
2402 | LayoutDialog(); | |
2403 | } | |
2404 | ||
cc8bc5aa JS |
2405 | SettingsDialog::~SettingsDialog() |
2406 | { | |
2407 | delete m_imageList; | |
2408 | } | |
2409 | ||
0f5d8ecf JS |
2410 | wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent) |
2411 | { | |
2412 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
2413 | ||
2414 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
2415 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
2416 | ||
2417 | //// LOAD LAST FILE | |
2418 | ||
2419 | wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL ); | |
2420 | wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize); | |
2421 | itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2422 | item0->Add(itemSizer3, 0, wxGROW|wxALL, 0); | |
2423 | ||
2424 | //// AUTOSAVE | |
2425 | ||
2426 | wxString autoSaveLabel = _("&Auto-save every"); | |
2427 | wxString minsLabel = _("mins"); | |
2428 | ||
2429 | wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL ); | |
2430 | wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize); | |
62675ef3 JS |
2431 | |
2432 | #if wxUSE_SPINCTRL | |
0f5d8ecf | 2433 | wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString, |
532d575b | 2434 | wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1); |
62675ef3 | 2435 | #endif |
532d575b | 2436 | |
0f5d8ecf | 2437 | itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
62675ef3 | 2438 | #if wxUSE_SPINCTRL |
0f5d8ecf | 2439 | itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
62675ef3 | 2440 | #endif |
0f5d8ecf JS |
2441 | itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
2442 | item0->Add(itemSizer12, 0, wxGROW|wxALL, 0); | |
2443 | ||
2444 | //// TOOLTIPS | |
532d575b | 2445 | |
0f5d8ecf JS |
2446 | wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL ); |
2447 | wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize); | |
2448 | itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2449 | item0->Add(itemSizer8, 0, wxGROW|wxALL, 0); | |
2450 | ||
2451 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
2452 | ||
8ce68f7f | 2453 | panel->SetSizerAndFit(topSizer); |
532d575b | 2454 | |
0f5d8ecf JS |
2455 | return panel; |
2456 | } | |
2457 | ||
2458 | wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent) | |
2459 | { | |
2460 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
2461 | ||
2462 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
2463 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
2464 | ||
2465 | //// PROJECT OR GLOBAL | |
2466 | wxString globalOrProjectChoices[2]; | |
2467 | globalOrProjectChoices[0] = _("&New projects"); | |
2468 | globalOrProjectChoices[1] = _("&This project"); | |
2469 | ||
2470 | wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"), | |
2471 | wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices); | |
2472 | item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5); | |
2473 | ||
2474 | projectOrGlobal->SetSelection(0); | |
2475 | ||
2476 | //// BACKGROUND STYLE | |
2477 | wxArrayString backgroundStyleChoices; | |
2478 | backgroundStyleChoices.Add(wxT("Colour")); | |
2479 | backgroundStyleChoices.Add(wxT("Image")); | |
532d575b | 2480 | wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:")); |
0f5d8ecf JS |
2481 | |
2482 | wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL ); | |
2483 | item0->Add(styleSizer, 0, wxGROW|wxALL, 5); | |
2484 | ||
2485 | wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
2486 | ||
2487 | wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices); | |
2488 | ||
2489 | itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2490 | itemSizer2->Add(5, 5, 1, wxALL, 0); | |
2491 | itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
2492 | ||
2493 | styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5); | |
2494 | ||
62675ef3 | 2495 | #if wxUSE_SPINCTRL |
0f5d8ecf JS |
2496 | //// FONT SIZE SELECTION |
2497 | ||
532d575b | 2498 | wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:")); |
0f5d8ecf JS |
2499 | wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL ); |
2500 | ||
2501 | wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition, | |
532d575b | 2502 | wxSize(80, wxDefaultCoord)); |
0f5d8ecf JS |
2503 | itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); |
2504 | ||
2505 | item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5); | |
62675ef3 | 2506 | #endif |
0f5d8ecf JS |
2507 | |
2508 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
0f4991f4 | 2509 | topSizer->AddSpacer(5); |
0f5d8ecf | 2510 | |
8ce68f7f | 2511 | panel->SetSizerAndFit(topSizer); |
532d575b | 2512 | |
0f5d8ecf JS |
2513 | return panel; |
2514 | } | |
2515 | ||
44b25eac VZ |
2516 | // ---------------------------------------------------------------------------- |
2517 | // TestMessageBoxDialog | |
2518 | // ---------------------------------------------------------------------------- | |
2519 | ||
b3ca7c85 VZ |
2520 | /* static */ |
2521 | const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] = | |
44b25eac VZ |
2522 | { |
2523 | { wxYES, "&Yes" }, | |
2524 | { wxNO, "&No" }, | |
2525 | { wxOK, "&Ok" }, | |
2526 | { wxCANCEL, "&Cancel" }, | |
2527 | }; | |
2528 | ||
2529 | BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog) | |
2530 | EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply) | |
2531 | EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose) | |
2532 | END_EVENT_TABLE() | |
2533 | ||
2534 | TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent) | |
2535 | : wxDialog(parent, wxID_ANY, "Message Box Test Dialog", | |
2536 | wxDefaultPosition, wxDefaultSize, | |
2537 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) | |
2538 | { | |
2539 | wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL); | |
2540 | ||
2541 | // this sizer allows to configure the messages shown in the message box | |
2542 | wxSizer * const | |
2543 | sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages"); | |
2544 | sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:")); | |
4e2dc789 | 2545 | m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!", |
44b25eac VZ |
2546 | wxDefaultPosition, wxDefaultSize, |
2547 | wxTE_MULTILINE); | |
2548 | sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM)); | |
2549 | ||
2550 | sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:")); | |
2551 | m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "", | |
2552 | wxDefaultPosition, wxDefaultSize, | |
2553 | wxTE_MULTILINE); | |
2554 | sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand()); | |
2555 | ||
2556 | sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border()); | |
2557 | ||
2558 | ||
2559 | // this one is for configuring the buttons | |
f68376d9 SC |
2560 | wxSizer * const |
2561 | sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons"); | |
2562 | ||
44b25eac VZ |
2563 | wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5); |
2564 | sizerBtns->AddGrowableCol(1); | |
2565 | ||
2566 | sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)")); | |
2567 | sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label")); | |
2568 | ||
2569 | for ( int n = 0; n < Btn_Max; n++ ) | |
2570 | { | |
2571 | m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name); | |
2572 | sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left()); | |
2573 | ||
2574 | m_labels[n] = new wxTextCtrl(this, wxID_ANY); | |
2575 | sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand()); | |
2576 | ||
2577 | m_labels[n]->Connect(wxEVT_UPDATE_UI, | |
2578 | wxUpdateUIEventHandler( | |
2579 | TestMessageBoxDialog::OnUpdateLabelUI), | |
2580 | NULL, | |
2581 | this); | |
2582 | } | |
2583 | ||
44b25eac VZ |
2584 | sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand()); |
2585 | sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border()); | |
2586 | ||
2587 | ||
2588 | // icon choice | |
8783d72f VZ |
2589 | const wxString icons[] = |
2590 | { | |
2591 | "&Not specified", | |
2592 | "E&xplicitly none", | |
2593 | "&Information icon", | |
2594 | "&Question icon", | |
2595 | "&Warning icon", | |
2596 | "&Error icon" | |
44b25eac VZ |
2597 | }; |
2598 | ||
e1cf09d9 | 2599 | wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == MsgDlgIcon_Max, IconMismatch ); |
e1cf09d9 | 2600 | |
8783d72f | 2601 | m_icons = new wxRadioBox(this, wxID_ANY, "&Icon style", |
44b25eac | 2602 | wxDefaultPosition, wxDefaultSize, |
8783d72f VZ |
2603 | WXSIZEOF(icons), icons, |
2604 | 2, wxRA_SPECIFY_ROWS); | |
7e3204b4 | 2605 | // Make the 'Information' icon the default one: |
8783d72f | 2606 | m_icons->SetSelection(MsgDlgIcon_Info); |
44b25eac VZ |
2607 | sizerTop->Add(m_icons, wxSizerFlags().Expand().Border()); |
2608 | ||
2609 | ||
4e2dc789 VZ |
2610 | // miscellaneous other stuff |
2611 | wxSizer * const | |
2612 | sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags"); | |
2613 | ||
2614 | m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default"); | |
2615 | m_chkNoDefault->Connect(wxEVT_UPDATE_UI, | |
2616 | wxUpdateUIEventHandler( | |
2617 | TestMessageBoxDialog::OnUpdateNoDefaultUI), | |
2618 | NULL, | |
2619 | this); | |
2620 | sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border()); | |
2621 | ||
2622 | m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent"); | |
2623 | sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border()); | |
2624 | ||
2625 | sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border()); | |
2626 | ||
44b25eac VZ |
2627 | // finally buttons to show the resulting message box and close this dialog |
2628 | sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE), | |
2629 | wxSizerFlags().Right().Border()); | |
2630 | ||
2631 | SetSizerAndFit(sizerTop); | |
4e2dc789 VZ |
2632 | |
2633 | m_buttons[Btn_Ok]->SetValue(true); | |
44b25eac VZ |
2634 | } |
2635 | ||
2636 | void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event) | |
2637 | { | |
2638 | for ( int n = 0; n < Btn_Max; n++ ) | |
2639 | { | |
2640 | if ( event.GetEventObject() == m_labels[n] ) | |
2641 | { | |
2642 | event.Enable( m_buttons[n]->IsChecked() ); | |
2643 | return; | |
2644 | } | |
2645 | } | |
2646 | ||
2647 | wxFAIL_MSG( "called for unknown label" ); | |
2648 | } | |
2649 | ||
4e2dc789 VZ |
2650 | void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event) |
2651 | { | |
2652 | event.Enable( m_buttons[Btn_No]->IsChecked() ); | |
2653 | } | |
2654 | ||
44b25eac VZ |
2655 | void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) |
2656 | { | |
2657 | long style = 0; | |
2658 | ||
2659 | for ( int n = 0; n < Btn_Max; n++ ) | |
2660 | { | |
2661 | if ( m_buttons[n]->IsChecked() ) | |
2662 | style |= ms_btnInfo[n].flag; | |
2663 | } | |
2664 | ||
2665 | switch ( m_icons->GetSelection() ) | |
2666 | { | |
8783d72f VZ |
2667 | case MsgDlgIcon_Max: |
2668 | wxFAIL_MSG( "unexpected selection" ); | |
2669 | ||
2670 | case MsgDlgIcon_No: | |
2671 | break; | |
2672 | ||
2673 | case MsgDlgIcon_None: | |
2674 | style |= wxICON_NONE; | |
2675 | break; | |
2676 | ||
2677 | case MsgDlgIcon_Info: | |
2678 | style |= wxICON_INFORMATION; | |
2679 | break; | |
2680 | ||
2681 | case MsgDlgIcon_Question: | |
2682 | style |= wxICON_QUESTION; | |
2683 | break; | |
2684 | ||
2685 | case MsgDlgIcon_Warning: | |
2686 | style |= wxICON_WARNING; | |
2687 | break; | |
2688 | ||
2689 | case MsgDlgIcon_Error: | |
2690 | style |= wxICON_ERROR; | |
2691 | break; | |
44b25eac VZ |
2692 | } |
2693 | ||
4e2dc789 VZ |
2694 | if ( m_chkCentre->IsChecked() ) |
2695 | style |= wxCENTRE; | |
2696 | ||
2697 | if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() ) | |
2698 | style |= wxNO_DEFAULT; | |
2699 | ||
2700 | ||
44b25eac VZ |
2701 | wxMessageDialog dlg(this, m_textMsg->GetValue(), "Test Message Box", |
2702 | style); | |
2703 | if ( !m_textExtMsg->IsEmpty() ) | |
2704 | dlg.SetExtendedMessage(m_textExtMsg->GetValue()); | |
2705 | ||
2706 | if ( style & wxYES_NO ) | |
2707 | { | |
2708 | if ( style & wxCANCEL ) | |
2709 | { | |
2710 | dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(), | |
2711 | m_labels[Btn_No]->GetValue(), | |
2712 | m_labels[Btn_Cancel]->GetValue()); | |
2713 | } | |
2714 | else | |
2715 | { | |
2716 | dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(), | |
2717 | m_labels[Btn_No]->GetValue()); | |
2718 | } | |
2719 | } | |
2720 | else | |
2721 | { | |
2722 | if ( style & wxCANCEL ) | |
2723 | { | |
2724 | dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(), | |
2725 | m_labels[Btn_Cancel]->GetValue()); | |
2726 | } | |
2727 | else | |
2728 | { | |
2729 | dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue()); | |
2730 | } | |
2731 | } | |
2732 | ||
2733 | dlg.ShowModal(); | |
2734 | } | |
2735 | ||
2736 | void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event)) | |
2737 | { | |
2738 | EndModal(wxID_CANCEL); | |
2739 | } | |
2740 | ||
532d575b | 2741 | #endif // USE_SETTINGS_DIALOG |
9ad2fe62 VZ |
2742 | |
2743 | #if wxUSE_LOG | |
2744 | ||
2745 | // ---------------------------------------------------------------------------- | |
2746 | // custom log target | |
2747 | // ---------------------------------------------------------------------------- | |
2748 | ||
2749 | class MyLogGui : public wxLogGui | |
2750 | { | |
2751 | private: | |
2752 | virtual void DoShowSingleLogMessage(const wxString& message, | |
2753 | const wxString& title, | |
2754 | int style) | |
2755 | { | |
f0afc953 VZ |
2756 | wxMessageDialog dlg(NULL, message, title, |
2757 | wxOK | wxCANCEL | wxCANCEL_DEFAULT | style); | |
2758 | dlg.SetOKCancelLabels(wxID_COPY, wxID_OK); | |
9ad2fe62 VZ |
2759 | dlg.SetExtendedMessage("Note that this is a custom log dialog."); |
2760 | dlg.ShowModal(); | |
2761 | } | |
2762 | }; | |
2763 | ||
2764 | wxLog *MyAppTraits::CreateLogTarget() | |
2765 | { | |
2766 | return new MyLogGui; | |
2767 | } | |
2768 | ||
2769 | #endif // wxUSE_LOG |