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