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