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