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