]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialogs.cpp | |
3 | // Purpose: Common dialogs demo | |
4 | // Author: Julian Smart | |
695fe764 | 5 | // Modified by: ABX (2004) - adjustements for conditional building + new menu |
457814b5 JS |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
c50f1fb9 | 9 | // Licence: wxWindows license |
457814b5 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a7166b34 | 12 | #if defined(__GNUG__) && !defined(__APPLE__) |
457814b5 JS |
13 | #pragma implementation |
14 | #pragma interface | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx/wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #endif | |
27 | ||
fb8a56b7 | 28 | #include "wx/datetime.h" |
f517634c | 29 | #include "wx/image.h" |
457814b5 | 30 | |
13188def WS |
31 | #if wxUSE_COLOURDLG |
32 | #include "wx/colordlg.h" | |
33 | #endif // wxUSE_COLOURDLG | |
dfad0599 | 34 | |
13188def WS |
35 | #if wxUSE_CHOICEDLG |
36 | #include "wx/choicdlg.h" | |
37 | #endif // wxUSE_CHOICEDLG | |
457814b5 | 38 | |
13188def WS |
39 | #if wxUSE_STARTUP_TIPS |
40 | #include "wx/tipdlg.h" | |
41 | #endif // wxUSE_STARTUP_TIPS | |
d7d17624 | 42 | |
13188def | 43 | #if wxUSE_PROGRESSDLG |
9b16ffef VZ |
44 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
45 | #include <wx/datetime.h> // wxDateTime | |
46 | #endif | |
47 | ||
13188def WS |
48 | #include "wx/progdlg.h" |
49 | #endif // wxUSE_PROGRESSDLG | |
50 | ||
51 | #if wxUSE_BUSYINFO | |
52 | #include "wx/busyinfo.h" | |
53 | #endif // wxUSE_BUSYINFO | |
54 | ||
55 | #if wxUSE_NUMBERDLG | |
56 | #include "wx/numdlg.h" | |
57 | #endif // wxUSE_NUMBERDLG | |
58 | ||
59 | #if wxUSE_FILEDLG | |
60 | #include "wx/filedlg.h" | |
61 | #endif // wxUSE_FILEDLG | |
62 | ||
63 | #if wxUSE_DIRDLG | |
64 | #include "wx/dirdlg.h" | |
65 | #endif // wxUSE_DIRDLG | |
66 | ||
67 | #if wxUSE_FONTDLG | |
68 | #include "wx/fontdlg.h" | |
69 | #endif // wxUSE_FONTDLG | |
70 | ||
71 | #if wxUSE_FINDREPLDLG | |
72 | #include "wx/fdrepdlg.h" | |
73 | #endif // wxUSE_FINDREPLDLG | |
4ad3c82f | 74 | |
457814b5 JS |
75 | #include "dialogs.h" |
76 | ||
13188def WS |
77 | #if USE_COLOURDLG_GENERIC |
78 | #include "wx/generic/colrdlgg.h" | |
79 | #endif // USE_COLOURDLG_GENERIC | |
80 | ||
13188def WS |
81 | #if USE_DIRDLG_GENERIC |
82 | #include "wx/generic/dirdlgg.h" | |
83 | #endif // USE_DIRDLG_GENERIC | |
84 | ||
695fe764 WS |
85 | #if USE_FILEDLG_GENERIC |
86 | #include "wx/generic/filedlgg.h" | |
87 | #endif // USE_FILEDLG_GENERIC | |
88 | ||
89 | #if USE_FONTDLG_GENERIC | |
90 | #include "wx/generic/fontdlgg.h" | |
91 | #endif // USE_FONTDLG_GENERIC | |
92 | ||
457814b5 JS |
93 | IMPLEMENT_APP(MyApp) |
94 | ||
4c45f240 VZ |
95 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
96 | EVT_PAINT(MyCanvas::OnPaint) | |
97 | END_EVENT_TABLE() | |
98 | ||
13188def WS |
99 | |
100 | ||
4c45f240 | 101 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
13188def WS |
102 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) |
103 | ||
104 | #if wxUSE_COLOURDLG | |
4c45f240 | 105 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) |
13188def WS |
106 | #endif // wxUSE_COLOURDLG |
107 | ||
108 | #if wxUSE_FONTDLG | |
4c45f240 | 109 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) |
13188def WS |
110 | #endif // wxUSE_FONTDLG |
111 | ||
112 | #if wxUSE_LOG_DIALOG | |
4c45f240 | 113 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) |
13188def WS |
114 | #endif // wxUSE_LOG_DIALOG |
115 | ||
116 | #if wxUSE_TEXTDLG | |
4c45f240 VZ |
117 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) |
118 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
13188def WS |
119 | #endif // wxUSE_TEXTDLG |
120 | ||
121 | #if wxUSE_NUMBERDLG | |
4c45f240 | 122 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) |
13188def WS |
123 | #endif // wxUSE_NUMBERDLG |
124 | ||
125 | #if wxUSE_CHOICEDLG | |
4c45f240 | 126 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) |
d6c9c1b7 | 127 | EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice) |
13188def WS |
128 | #endif // wxUSE_CHOICEDLG |
129 | ||
130 | #if wxUSE_FILEDLG | |
4c45f240 | 131 | EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) |
35b45b33 | 132 | EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) |
4c45f240 VZ |
133 | EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) |
134 | EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) | |
13188def WS |
135 | #endif // wxUSE_FILEDLG |
136 | ||
695fe764 WS |
137 | #if USE_FILEDLG_GENERIC |
138 | EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric) | |
139 | EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric) | |
140 | EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric) | |
141 | #endif // USE_FILEDLG_GENERIC | |
142 | ||
13188def | 143 | #if wxUSE_DIRDLG |
4c45f240 | 144 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) |
f09c8393 | 145 | EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew) |
13188def WS |
146 | #endif // wxUSE_DIRDLG |
147 | ||
148 | #if USE_MODAL_PRESENTATION | |
f6bcfd97 | 149 | EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg) |
4c45f240 | 150 | EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg) |
13188def WS |
151 | #endif // USE_MODAL |
152 | ||
153 | #if wxUSE_STARTUP_TIPS | |
4c45f240 | 154 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) |
13188def WS |
155 | #endif // wxUSE_STARTUP_TIPS |
156 | ||
157 | #if USE_FONTDLG_GENERIC | |
4c45f240 | 158 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) |
13188def WS |
159 | #endif // USE_FONTDLG_GENERIC |
160 | ||
161 | #if USE_DIRDLG_GENERIC | |
162 | EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) | |
163 | #endif // wxMSW || wxMAC | |
164 | ||
165 | #if USE_COLOURDLG_GENERIC | |
166 | EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) | |
167 | #endif // USE_COLOURDLG_GENERIC | |
a62b0bcc | 168 | |
abceee76 VZ |
169 | #if wxUSE_PROGRESSDLG |
170 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
761989ff | 171 | #endif // wxUSE_PROGRESSDLG |
a62b0bcc VZ |
172 | |
173 | #if wxUSE_BUSYINFO | |
174 | EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo) | |
175 | #endif // wxUSE_BUSYINFO | |
176 | ||
761989ff VZ |
177 | #if wxUSE_FINDREPLDLG |
178 | EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog) | |
179 | EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog) | |
180 | ||
13188def WS |
181 | EVT_FIND(wxID_ANY, MyFrame::OnFindDialog) |
182 | EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog) | |
183 | EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog) | |
184 | EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog) | |
185 | EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog) | |
761989ff | 186 | #endif // wxUSE_FINDREPLDLG |
13188def | 187 | |
9b16ffef VZ |
188 | EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) |
189 | ||
4c45f240 | 190 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) |
4c45f240 | 191 | END_EVENT_TABLE() |
abceee76 | 192 | |
13188def | 193 | #if USE_MODAL_PRESENTATION |
f6bcfd97 | 194 | |
13188def WS |
195 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) |
196 | EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton) | |
197 | END_EVENT_TABLE() | |
5d987909 | 198 | |
13188def WS |
199 | BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog) |
200 | EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton) | |
201 | EVT_CLOSE(MyModelessDialog::OnClose) | |
202 | END_EVENT_TABLE() | |
203 | ||
204 | #endif // USE_MODAL_PRESENTATION | |
abceee76 | 205 | |
c67daf87 | 206 | MyCanvas *myCanvas = (MyCanvas *) NULL; |
457814b5 | 207 | |
457814b5 | 208 | // `Main program' equivalent, creating windows and returning main app frame |
4c45f240 | 209 | bool MyApp::OnInit() |
457814b5 | 210 | { |
f517634c | 211 | #if wxUSE_IMAGE |
013e1fee | 212 | wxInitAllImageHandlers(); |
f517634c | 213 | #endif |
013e1fee | 214 | |
13188def WS |
215 | m_canvasTextColour = wxColour(_T("BLACK")); |
216 | m_canvasFont = *wxNORMAL_FONT; | |
457814b5 | 217 | |
13188def WS |
218 | // Create the main frame window |
219 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example")); | |
457814b5 | 220 | |
13188def WS |
221 | // Make a menubar |
222 | wxMenu *file_menu = new wxMenu; | |
dabbc6a5 | 223 | |
13188def | 224 | file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); |
457814b5 | 225 | |
457814b5 | 226 | |
33bcca32 | 227 | #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG |
f09c8393 | 228 | |
33bcca32 | 229 | wxMenu *choices_menu = new wxMenu; |
f09c8393 | 230 | |
33bcca32 VZ |
231 | #if wxUSE_COLOURDLG |
232 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour")); | |
233 | #endif // wxUSE_COLOURDLG | |
f09c8393 | 234 | |
33bcca32 VZ |
235 | #if wxUSE_FONTDLG |
236 | choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font")); | |
237 | #endif // wxUSE_FONTDLG | |
457814b5 | 238 | |
33bcca32 VZ |
239 | #if wxUSE_CHOICEDLG |
240 | choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C")); | |
241 | choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U")); | |
242 | #endif // wxUSE_CHOICEDLG | |
695fe764 | 243 | |
33bcca32 VZ |
244 | #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC |
245 | choices_menu->AppendSeparator(); | |
246 | #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
695fe764 | 247 | |
33bcca32 VZ |
248 | #if USE_COLOURDLG_GENERIC |
249 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)")); | |
250 | #endif // USE_COLOURDLG_GENERIC | |
695fe764 | 251 | |
33bcca32 VZ |
252 | #if USE_FONTDLG_GENERIC |
253 | choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)")); | |
254 | #endif // USE_FONTDLG_GENERIC | |
d93c719a | 255 | |
33bcca32 VZ |
256 | file_menu->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu); |
257 | #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
457814b5 | 258 | |
457814b5 | 259 | |
33bcca32 | 260 | #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG |
13188def | 261 | |
33bcca32 | 262 | wxMenu *entry_menu = new wxMenu; |
13188def | 263 | |
33bcca32 VZ |
264 | #if wxUSE_TEXTDLG |
265 | entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E")); | |
266 | entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P")); | |
267 | #endif // wxUSE_TEXTDLG | |
13188def | 268 | |
33bcca32 VZ |
269 | #if wxUSE_NUMBERDLG |
270 | entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N")); | |
271 | #endif // wxUSE_NUMBERDLG | |
13188def | 272 | |
33bcca32 | 273 | file_menu->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu); |
13188def | 274 | |
33bcca32 | 275 | #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG |
13188def WS |
276 | |
277 | ||
33bcca32 | 278 | #if wxUSE_FILEDLG |
13188def | 279 | |
33bcca32 VZ |
280 | wxMenu *filedlg_menu = new wxMenu; |
281 | filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O")); | |
282 | filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2")); | |
283 | filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); | |
284 | filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); | |
695fe764 | 285 | |
33bcca32 VZ |
286 | #if USE_FILEDLG_GENERIC |
287 | filedlg_menu->AppendSeparator(); | |
288 | filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)")); | |
289 | filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)")); | |
290 | filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)")); | |
291 | #endif // USE_FILEDLG_GENERIC | |
695fe764 | 292 | |
33bcca32 | 293 | file_menu->Append(wxID_ANY,_T("&File operations"),filedlg_menu); |
13188def | 294 | |
33bcca32 | 295 | #endif // wxUSE_FILEDLG |
13188def | 296 | |
33bcca32 VZ |
297 | #if wxUSE_DIRDLG |
298 | wxMenu *dir_menu = new wxMenu; | |
13188def | 299 | |
33bcca32 VZ |
300 | dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D")); |
301 | dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D")); | |
302 | file_menu->Append(wxID_ANY,_T("&Directory operations"),dir_menu); | |
13188def | 303 | |
33bcca32 VZ |
304 | #if USE_DIRDLG_GENERIC |
305 | dir_menu->AppendSeparator(); | |
306 | dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)")); | |
307 | #endif // USE_DIRDLG_GENERIC | |
13188def | 308 | |
33bcca32 | 309 | #endif // wxUSE_DIRDLG |
13188def WS |
310 | |
311 | ||
33bcca32 | 312 | #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG |
13188def | 313 | |
33bcca32 | 314 | wxMenu *info_menu = new wxMenu; |
13188def | 315 | |
33bcca32 VZ |
316 | #if wxUSE_STARTUP_TIPS |
317 | info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T")); | |
318 | #endif // wxUSE_STARTUP_TIPS | |
13188def | 319 | |
33bcca32 VZ |
320 | #if wxUSE_PROGRESSDLG |
321 | info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G")); | |
322 | #endif // wxUSE_PROGRESSDLG | |
13188def | 323 | |
33bcca32 VZ |
324 | #if wxUSE_BUSYINFO |
325 | info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B")); | |
326 | #endif // wxUSE_BUSYINFO | |
13188def | 327 | |
33bcca32 VZ |
328 | #if wxUSE_LOG_DIALOG |
329 | info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L")); | |
330 | #endif // wxUSE_LOG_DIALOG | |
13188def | 331 | |
33bcca32 | 332 | file_menu->Append(wxID_ANY,_T("&Informative dialogs"),info_menu); |
13188def | 333 | |
33bcca32 | 334 | #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG |
13188def WS |
335 | |
336 | ||
33bcca32 VZ |
337 | #if wxUSE_FINDREPLDLG |
338 | wxMenu *find_menu = new wxMenu; | |
339 | find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F")); | |
340 | find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F")); | |
341 | file_menu->Append(wxID_ANY,_T("&Searching"),find_menu); | |
342 | #endif // wxUSE_FINDREPLDLG | |
13188def | 343 | |
33bcca32 VZ |
344 | #if USE_MODAL_PRESENTATION |
345 | wxMenu *modal_menu = new wxMenu; | |
346 | modal_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W")); | |
347 | modal_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z")); | |
348 | file_menu->Append(wxID_ANY,_T("&Modal/Modeless"),modal_menu); | |
349 | #endif // USE_MODAL_PRESENTATION | |
13188def | 350 | |
9b16ffef VZ |
351 | file_menu->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R")); |
352 | ||
13188def WS |
353 | file_menu->AppendSeparator(); |
354 | file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X")); | |
355 | ||
356 | wxMenuBar *menu_bar = new wxMenuBar; | |
357 | menu_bar->Append(file_menu, _T("&File")); | |
358 | frame->SetMenuBar(menu_bar); | |
359 | ||
360 | myCanvas = new MyCanvas(frame); | |
361 | myCanvas->SetBackgroundColour(*wxWHITE); | |
362 | ||
363 | frame->Centre(wxBOTH); | |
364 | ||
365 | // Show the frame | |
366 | frame->Show(true); | |
367 | ||
368 | SetTopWindow(frame); | |
369 | ||
370 | return true; | |
457814b5 JS |
371 | } |
372 | ||
373 | // My frame constructor | |
4c45f240 | 374 | MyFrame::MyFrame(wxWindow *parent, |
13188def WS |
375 | const wxString& title) |
376 | : wxFrame(parent, wxID_ANY, title) | |
4c45f240 | 377 | { |
13188def | 378 | #if USE_MODAL_PRESENTATION |
4c45f240 | 379 | m_dialog = (MyModelessDialog *)NULL; |
13188def | 380 | #endif // USE_MODAL_PRESENTATION |
f1e1ed3b | 381 | |
043dcdaa | 382 | #if wxUSE_FINDREPLDLG |
14fca738 VZ |
383 | m_dlgFind = |
384 | m_dlgReplace = NULL; | |
043dcdaa | 385 | #endif |
dabbc6a5 DS |
386 | |
387 | #if wxUSE_COLOURDLG | |
d33dd9ef VS |
388 | m_clrData.SetChooseFull(true); |
389 | for (int i = 0; i < 16; i++) | |
390 | { | |
8f6eaec9 WS |
391 | m_clrData.SetCustomColour( |
392 | i, | |
393 | wxColour( | |
394 | (unsigned char)(i*16), | |
395 | (unsigned char)(i*16), | |
396 | (unsigned char)(i*16) | |
397 | ) | |
398 | ); | |
d33dd9ef | 399 | } |
13188def | 400 | #endif // wxUSE_COLOURDLG |
dabbc6a5 | 401 | |
fb8a56b7 | 402 | #if wxUSE_STATUSBAR |
f1e1ed3b | 403 | CreateStatusBar(); |
fb8a56b7 | 404 | #endif // wxUSE_STATUSBAR |
4c45f240 | 405 | } |
457814b5 | 406 | |
13188def | 407 | #if wxUSE_COLOURDLG |
d355d3fe | 408 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 409 | { |
d33dd9ef | 410 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); |
d93c719a | 411 | |
d33dd9ef | 412 | wxColourDialog dialog(this, &m_clrData); |
9f84eccd | 413 | dialog.SetTitle(_T("Choose the background colour")); |
afbd36dd | 414 | if (dialog.ShowModal() == wxID_OK) |
f6bcfd97 | 415 | { |
d33dd9ef VS |
416 | m_clrData = dialog.GetColourData(); |
417 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
1d14c005 | 418 | myCanvas->ClearBackground(); |
457814b5 | 419 | myCanvas->Refresh(); |
f6bcfd97 | 420 | } |
457814b5 | 421 | } |
13188def | 422 | #endif // wxUSE_COLOURDLG |
457814b5 | 423 | |
1e72e3cc RN |
424 | #if USE_COLOURDLG_GENERIC |
425 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) | |
426 | { | |
427 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
428 | ||
429 | //FIXME:TODO:This has no effect... | |
430 | m_clrData.SetChooseFull(true); | |
431 | ||
432 | for (int i = 0; i < 16; i++) | |
433 | { | |
434 | wxColour colour( | |
435 | (unsigned char)(i*16), | |
436 | (unsigned char)(i*16), | |
437 | (unsigned char)(i*16) | |
438 | ); | |
439 | m_clrData.SetCustomColour(i, colour); | |
440 | } | |
441 | ||
442 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData); | |
443 | if (dialog->ShowModal() == wxID_OK) | |
444 | { | |
445 | m_clrData = dialog->GetColourData(); | |
446 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
447 | myCanvas->ClearBackground(); | |
448 | myCanvas->Refresh(); | |
449 | } | |
450 | dialog->Destroy(); | |
451 | } | |
452 | #endif // USE_COLOURDLG_GENERIC | |
453 | ||
13188def | 454 | #if wxUSE_FONTDLG |
d355d3fe | 455 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 456 | { |
dbc65e27 VZ |
457 | wxFontData data; |
458 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
459 | data.SetColour(wxGetApp().m_canvasTextColour); | |
d93c719a | 460 | |
dbc65e27 VZ |
461 | // you might also do this: |
462 | // | |
463 | // wxFontDialog dialog; | |
464 | // if ( !dialog.Create(this, data) { ... error ... } | |
465 | // | |
466 | wxFontDialog dialog(this, data); | |
467 | ||
468 | if (dialog.ShowModal() == wxID_OK) | |
469 | { | |
470 | wxFontData retData = dialog.GetFontData(); | |
457814b5 JS |
471 | wxGetApp().m_canvasFont = retData.GetChosenFont(); |
472 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
473 | myCanvas->Refresh(); | |
dbc65e27 VZ |
474 | } |
475 | //else: cancelled by the user, don't change the font | |
457814b5 | 476 | } |
13188def | 477 | #endif // wxUSE_FONTDLG |
457814b5 | 478 | |
13188def | 479 | #if USE_FONTDLG_GENERIC |
d355d3fe | 480 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 481 | { |
13188def WS |
482 | wxFontData data; |
483 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
484 | data.SetColour(wxGetApp().m_canvasTextColour); | |
457814b5 | 485 | |
13188def WS |
486 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data); |
487 | if (dialog->ShowModal() == wxID_OK) | |
488 | { | |
457814b5 JS |
489 | wxFontData retData = dialog->GetFontData(); |
490 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
491 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
492 | myCanvas->Refresh(); | |
13188def WS |
493 | } |
494 | dialog->Destroy(); | |
457814b5 | 495 | } |
13188def | 496 | #endif // USE_FONTDLG_GENERIC |
d93c719a | 497 | |
b4954d19 | 498 | #if wxUSE_LOG_DIALOG |
87728739 | 499 | void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event)) |
d93c719a | 500 | { |
2c8e4738 VZ |
501 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages |
502 | // being flushed -- test it | |
503 | { | |
504 | wxBusyCursor bc; | |
4693b20c MB |
505 | wxLogMessage(wxT("This is some message - everything is ok so far.")); |
506 | wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); | |
507 | wxLogWarning(wxT("And then something went wrong!")); | |
9fe52545 VZ |
508 | |
509 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
510 | wxYield(); | |
2c8e4738 VZ |
511 | } |
512 | ||
4693b20c MB |
513 | wxLogError(wxT("Intermediary error handler decided to abort.")); |
514 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
5888ef1e | 515 | |
7923c649 VZ |
516 | wxLog::FlushActive(); |
517 | ||
4693b20c | 518 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); |
d93c719a | 519 | } |
b4954d19 | 520 | #endif // wxUSE_LOG_DIALOG |
457814b5 | 521 | |
d355d3fe | 522 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 523 | { |
13188def WS |
524 | wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"), |
525 | _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION); | |
457814b5 | 526 | |
13188def WS |
527 | switch ( dialog.ShowModal() ) |
528 | { | |
529 | case wxID_YES: | |
530 | wxLogStatus(wxT("You pressed \"Yes\"")); | |
531 | break; | |
49b957be | 532 | |
13188def WS |
533 | case wxID_NO: |
534 | wxLogStatus(wxT("You pressed \"No\"")); | |
535 | break; | |
49b957be | 536 | |
13188def WS |
537 | case wxID_CANCEL: |
538 | wxLogStatus(wxT("You pressed \"Cancel\"")); | |
539 | break; | |
49b957be | 540 | |
13188def WS |
541 | default: |
542 | wxLogError(wxT("Unexpected wxMessageDialog return code!")); | |
543 | } | |
457814b5 JS |
544 | } |
545 | ||
13188def | 546 | #if wxUSE_NUMBERDLG |
c49245f8 VZ |
547 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) ) |
548 | { | |
78a189c9 VZ |
549 | long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n") |
550 | _T("Even two rows of text."), | |
551 | _T("Enter a number:"), _T("Numeric input test"), | |
e65cc56a | 552 | 50, 0, 100, this ); |
c49245f8 VZ |
553 | |
554 | wxString msg; | |
555 | int icon; | |
556 | if ( res == -1 ) | |
557 | { | |
78a189c9 | 558 | msg = _T("Invalid number entered or dialog cancelled."); |
c49245f8 VZ |
559 | icon = wxICON_HAND; |
560 | } | |
561 | else | |
d93c719a VZ |
562 | { |
563 | msg.Printf(_T("You've entered %lu"), res ); | |
c49245f8 VZ |
564 | icon = wxICON_INFORMATION; |
565 | } | |
566 | ||
78a189c9 | 567 | wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this); |
c49245f8 | 568 | } |
13188def | 569 | #endif // wxUSE_NUMBERDLG |
c49245f8 | 570 | |
13188def | 571 | #if wxUSE_TEXTDLG |
a294c6d5 | 572 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 573 | { |
2f1cd905 | 574 | wxString pwd = wxGetPasswordFromUser(_T("Enter password:"), |
78a189c9 | 575 | _T("Password entry dialog"), |
dabbc6a5 | 576 | wxEmptyString, |
a294c6d5 | 577 | this); |
ecda9475 | 578 | if ( !pwd.empty() ) |
a294c6d5 | 579 | { |
4693b20c | 580 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), |
78a189c9 | 581 | _T("Got password"), wxOK | wxICON_INFORMATION, this); |
a294c6d5 VZ |
582 | } |
583 | } | |
584 | ||
585 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
586 | { | |
13188def WS |
587 | wxTextEntryDialog dialog(this, |
588 | _T("This is a small sample\n") | |
589 | _T("A long, long string to test out the text entrybox"), | |
590 | _T("Please enter a string"), | |
591 | _T("Default value"), | |
592 | wxOK | wxCANCEL); | |
457814b5 | 593 | |
13188def WS |
594 | if (dialog.ShowModal() == wxID_OK) |
595 | { | |
b4954d19 | 596 | wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this); |
13188def | 597 | } |
457814b5 | 598 | } |
13188def | 599 | #endif // wxUSE_TEXTDLG |
457814b5 | 600 | |
13188def | 601 | #if wxUSE_CHOICEDLG |
d355d3fe | 602 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 603 | { |
78a189c9 | 604 | const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ; |
457814b5 | 605 | |
5f95bb70 | 606 | wxSingleChoiceDialog dialog(this, |
78a189c9 VZ |
607 | _T("This is a small sample\n") |
608 | _T("A single-choice convenience dialog"), | |
609 | _T("Please select a value"), | |
5f95bb70 | 610 | WXSIZEOF(choices), choices); |
457814b5 | 611 | |
ef77f91e JS |
612 | dialog.SetSelection(2); |
613 | ||
614 | if (dialog.ShowModal() == wxID_OK) | |
615 | { | |
78a189c9 | 616 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string")); |
ef77f91e JS |
617 | dialog2.ShowModal(); |
618 | } | |
457814b5 JS |
619 | } |
620 | ||
d6c9c1b7 VZ |
621 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) |
622 | { | |
5f95bb70 VZ |
623 | const wxString choices[] = |
624 | { | |
78a189c9 VZ |
625 | _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"), |
626 | _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"), | |
627 | _T("Eleven"), _T("Twelve"), _T("Seventeen"), | |
5f95bb70 | 628 | }; |
d6c9c1b7 VZ |
629 | |
630 | wxArrayInt selections; | |
631 | size_t count = wxGetMultipleChoices(selections, | |
78a189c9 VZ |
632 | _T("This is a small sample\n") |
633 | _T("A multi-choice convenience dialog"), | |
634 | _T("Please select a value"), | |
5f95bb70 | 635 | WXSIZEOF(choices), choices, |
d6c9c1b7 VZ |
636 | this); |
637 | if ( count ) | |
638 | { | |
3d49ce44 | 639 | wxString msg; |
fba1b53b | 640 | msg.Printf(wxT("You selected %u items:\n"), (unsigned)count); |
d6c9c1b7 VZ |
641 | for ( size_t n = 0; n < count; n++ ) |
642 | { | |
fba1b53b VZ |
643 | msg += wxString::Format(wxT("\t%u: %u (%s)\n"), |
644 | (unsigned)n, (unsigned)selections[n], | |
3d49ce44 | 645 | choices[selections[n]].c_str()); |
d6c9c1b7 | 646 | } |
3d49ce44 | 647 | wxLogMessage(msg); |
d6c9c1b7 VZ |
648 | } |
649 | //else: cancelled or nothing selected | |
650 | } | |
13188def | 651 | #endif // wxUSE_CHOICEDLG |
d6c9c1b7 | 652 | |
13188def | 653 | #if wxUSE_FILEDLG |
d355d3fe | 654 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 655 | { |
fbf4eacb VZ |
656 | wxFileDialog dialog |
657 | ( | |
658 | this, | |
659 | _T("Testing open file dialog"), | |
dabbc6a5 DS |
660 | wxEmptyString, |
661 | wxEmptyString, | |
a4e64fb5 MB |
662 | #ifdef __WXMOTIF__ |
663 | _T("C++ files (*.cpp)|*.cpp") | |
664 | #else | |
daf32463 | 665 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") |
a4e64fb5 | 666 | #endif |
fbf4eacb | 667 | ); |
457814b5 | 668 | |
5b636c67 VZ |
669 | dialog.SetDirectory(wxGetHomeDir()); |
670 | ||
c50f1fb9 VZ |
671 | if (dialog.ShowModal() == wxID_OK) |
672 | { | |
5919d76b | 673 | wxString info; |
13393ab6 RR |
674 | info.Printf(_T("Full file name: %s\n") |
675 | _T("Path: %s\n") | |
676 | _T("Name: %s"), | |
5919d76b VZ |
677 | dialog.GetPath().c_str(), |
678 | dialog.GetDirectory().c_str(), | |
679 | dialog.GetFilename().c_str()); | |
78a189c9 | 680 | wxMessageDialog dialog2(this, info, _T("Selected file")); |
c50f1fb9 VZ |
681 | dialog2.ShowModal(); |
682 | } | |
457814b5 JS |
683 | } |
684 | ||
35b45b33 VZ |
685 | // this shows how to take advantage of specifying a default extension in the |
686 | // call to wxFileSelector: it is remembered after each new call and the next | |
687 | // one will use it by default | |
688 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
689 | { | |
690 | static wxString s_extDef; | |
691 | wxString path = wxFileSelector( | |
692 | _T("Select the file to load"), | |
dabbc6a5 | 693 | wxEmptyString, wxEmptyString, |
35b45b33 VZ |
694 | s_extDef, |
695 | _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"), | |
fbf4eacb | 696 | wxCHANGE_DIR, |
35b45b33 VZ |
697 | this |
698 | ); | |
699 | ||
700 | if ( !path ) | |
701 | return; | |
702 | ||
703 | // it is just a sample, would use wxSplitPath in real program | |
704 | s_extDef = path.AfterLast(_T('.')); | |
705 | ||
706 | wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), | |
37d403aa | 707 | (const wxChar*) path, (const wxChar*) s_extDef); |
35b45b33 VZ |
708 | } |
709 | ||
c61f4f6d VZ |
710 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) |
711 | { | |
dabbc6a5 | 712 | wxString wildcards = |
f0f43012 JS |
713 | #ifdef __WXMOTIF__ |
714 | _T("C++ files (*.cpp)|*.cpp"); | |
715 | #else | |
daf32463 | 716 | _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h"); |
f0f43012 | 717 | #endif |
78a189c9 | 718 | wxFileDialog dialog(this, _T("Testing open multiple file dialog"), |
dabbc6a5 | 719 | wxEmptyString, wxEmptyString, wildcards, |
470caaf9 | 720 | wxMULTIPLE); |
c61f4f6d VZ |
721 | |
722 | if (dialog.ShowModal() == wxID_OK) | |
723 | { | |
724 | wxArrayString paths, filenames; | |
725 | ||
726 | dialog.GetPaths(paths); | |
727 | dialog.GetFilenames(filenames); | |
728 | ||
729 | wxString msg, s; | |
730 | size_t count = paths.GetCount(); | |
731 | for ( size_t n = 0; n < count; n++ ) | |
732 | { | |
733 | s.Printf(_T("File %d: %s (%s)\n"), | |
fba1b53b | 734 | (int)n, paths[n].c_str(), filenames[n].c_str()); |
c61f4f6d VZ |
735 | |
736 | msg += s; | |
737 | } | |
f0f43012 JS |
738 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); |
739 | msg += s; | |
c61f4f6d | 740 | |
78a189c9 | 741 | wxMessageDialog dialog2(this, msg, _T("Selected files")); |
c61f4f6d VZ |
742 | dialog2.ShowModal(); |
743 | } | |
744 | } | |
745 | ||
d355d3fe | 746 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 747 | { |
2f1cd905 VZ |
748 | wxFileDialog dialog(this, |
749 | _T("Testing save file dialog"), | |
dabbc6a5 | 750 | wxEmptyString, |
2b5f62a0 | 751 | _T("myletter.doc"), |
2f1cd905 VZ |
752 | _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), |
753 | wxSAVE|wxOVERWRITE_PROMPT); | |
c50f1fb9 | 754 | |
2b5f62a0 VZ |
755 | dialog.SetFilterIndex(1); |
756 | ||
c50f1fb9 VZ |
757 | if (dialog.ShowModal() == wxID_OK) |
758 | { | |
2b5f62a0 VZ |
759 | wxLogMessage(_T("%s, filter %d"), |
760 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
c50f1fb9 | 761 | } |
457814b5 | 762 | } |
13188def | 763 | #endif // wxUSE_FILEDLG |
457814b5 | 764 | |
695fe764 WS |
765 | #if USE_FILEDLG_GENERIC |
766 | void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
767 | { | |
768 | wxGenericFileDialog dialog | |
769 | ( | |
770 | this, | |
771 | _T("Testing open file dialog"), | |
772 | wxEmptyString, | |
773 | wxEmptyString, | |
daf32463 | 774 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") |
695fe764 WS |
775 | ); |
776 | ||
777 | dialog.SetDirectory(wxGetHomeDir()); | |
778 | ||
779 | if (dialog.ShowModal() == wxID_OK) | |
780 | { | |
781 | wxString info; | |
782 | info.Printf(_T("Full file name: %s\n") | |
783 | _T("Path: %s\n") | |
784 | _T("Name: %s"), | |
785 | dialog.GetPath().c_str(), | |
786 | dialog.GetDirectory().c_str(), | |
787 | dialog.GetFilename().c_str()); | |
788 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
789 | dialog2.ShowModal(); | |
790 | } | |
791 | } | |
792 | ||
793 | void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
794 | { | |
daf32463 | 795 | wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h"); |
695fe764 WS |
796 | wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"), |
797 | wxEmptyString, wxEmptyString, wildcards, | |
798 | wxMULTIPLE); | |
799 | ||
800 | if (dialog.ShowModal() == wxID_OK) | |
801 | { | |
802 | wxArrayString paths, filenames; | |
803 | ||
804 | dialog.GetPaths(paths); | |
805 | dialog.GetFilenames(filenames); | |
806 | ||
807 | wxString msg, s; | |
808 | size_t count = paths.GetCount(); | |
809 | for ( size_t n = 0; n < count; n++ ) | |
810 | { | |
811 | s.Printf(_T("File %d: %s (%s)\n"), | |
812 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
813 | ||
814 | msg += s; | |
815 | } | |
816 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
817 | msg += s; | |
818 | ||
819 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
820 | dialog2.ShowModal(); | |
821 | } | |
822 | } | |
823 | ||
824 | void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) ) | |
825 | { | |
826 | wxGenericFileDialog dialog(this, | |
827 | _T("Testing save file dialog"), | |
828 | wxEmptyString, | |
829 | _T("myletter.doc"), | |
830 | _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), | |
831 | wxSAVE|wxOVERWRITE_PROMPT); | |
832 | ||
833 | dialog.SetFilterIndex(1); | |
834 | ||
835 | if (dialog.ShowModal() == wxID_OK) | |
836 | { | |
837 | wxLogMessage(_T("%s, filter %d"), | |
838 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
839 | } | |
840 | } | |
841 | #endif // USE_FILEDLG_GENERIC | |
842 | ||
13188def | 843 | #if wxUSE_DIRDLG |
f09c8393 | 844 | void MyFrame::DoDirChoose(int style) |
457814b5 | 845 | { |
3f2711d5 VZ |
846 | // pass some initial dir to wxDirDialog |
847 | wxString dirHome; | |
848 | wxGetHomeDir(&dirHome); | |
849 | ||
f09c8393 | 850 | wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style); |
c50f1fb9 VZ |
851 | |
852 | if (dialog.ShowModal() == wxID_OK) | |
853 | { | |
2b5f62a0 | 854 | wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str()); |
c50f1fb9 VZ |
855 | } |
856 | } | |
857 | ||
f09c8393 VZ |
858 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) |
859 | { | |
860 | DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON); | |
861 | } | |
862 | ||
863 | void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) ) | |
864 | { | |
8768548b | 865 | DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON); |
f09c8393 | 866 | } |
13188def | 867 | #endif // wxUSE_DIRDLG |
f09c8393 | 868 | |
13188def | 869 | #if USE_DIRDLG_GENERIC |
51a58d8b JS |
870 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) |
871 | { | |
872 | // pass some initial dir to wxDirDialog | |
873 | wxString dirHome; | |
874 | wxGetHomeDir(&dirHome); | |
875 | ||
78a189c9 | 876 | wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome); |
51a58d8b JS |
877 | |
878 | if (dialog.ShowModal() == wxID_OK) | |
879 | { | |
78a189c9 | 880 | wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path")); |
51a58d8b JS |
881 | dialog2.ShowModal(); |
882 | } | |
883 | } | |
13188def | 884 | #endif // USE_DIRDLG_GENERIC |
51a58d8b | 885 | |
13188def | 886 | #if USE_MODAL_PRESENTATION |
f6bcfd97 BP |
887 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) |
888 | { | |
889 | MyModalDialog dlg(this); | |
890 | dlg.ShowModal(); | |
891 | } | |
892 | ||
4c45f240 VZ |
893 | void MyFrame::ModelessDlg(wxCommandEvent& event) |
894 | { | |
2f82899b | 895 | bool show = GetMenuBar()->IsChecked(event.GetId()); |
4c45f240 VZ |
896 | |
897 | if ( show ) | |
898 | { | |
899 | if ( !m_dialog ) | |
900 | { | |
901 | m_dialog = new MyModelessDialog(this); | |
902 | } | |
903 | ||
13188def | 904 | m_dialog->Show(true); |
4c45f240 VZ |
905 | } |
906 | else // hide | |
907 | { | |
908 | m_dialog->Hide(); | |
909 | } | |
910 | } | |
13188def | 911 | #endif // USE_MODAL_PRESENTATION |
4c45f240 | 912 | |
13188def | 913 | #if wxUSE_STARTUP_TIPS |
87728739 | 914 | void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event)) |
c50f1fb9 VZ |
915 | { |
916 | static size_t s_index = (size_t)-1; | |
917 | ||
918 | if ( s_index == (size_t)-1 ) | |
919 | { | |
920 | srand(time(NULL)); | |
921 | ||
922 | // this is completely bogus, we don't know how many lines are there | |
923 | // in the file, but who cares, it's a demo only... | |
924 | s_index = rand() % 5; | |
925 | } | |
926 | ||
2f1cd905 | 927 | wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index); |
c50f1fb9 VZ |
928 | |
929 | bool showAtStartup = wxShowTip(this, tipProvider); | |
930 | ||
931 | if ( showAtStartup ) | |
932 | { | |
2f1cd905 | 933 | wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"), |
c50f1fb9 VZ |
934 | wxOK | wxICON_INFORMATION, this); |
935 | } | |
457814b5 | 936 | |
c50f1fb9 VZ |
937 | s_index = tipProvider->GetCurrentTip(); |
938 | delete tipProvider; | |
457814b5 | 939 | } |
13188def | 940 | #endif // wxUSE_STARTUP_TIPS |
457814b5 | 941 | |
9b16ffef VZ |
942 | void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) |
943 | { | |
944 | wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window")); | |
945 | ||
946 | wxSleep(3); | |
947 | ||
948 | RequestUserAttention(wxUSER_ATTENTION_ERROR); | |
949 | } | |
950 | ||
d355d3fe | 951 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 952 | { |
13188def | 953 | Close(true); |
457814b5 JS |
954 | } |
955 | ||
abceee76 VZ |
956 | #if wxUSE_PROGRESSDLG |
957 | ||
958 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
959 | { | |
9b16ffef VZ |
960 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
961 | // check the performance | |
962 | int countrandomnumbers = 0, count = 0; | |
963 | wxTimeSpan tsTest(0,0,0,250); | |
964 | wxDateTime DT2, DT1 = wxDateTime::UNow(); | |
965 | srand(0); | |
966 | while(1) | |
967 | { | |
968 | rand(); | |
969 | ++countrandomnumbers; | |
970 | if ( countrandomnumbers == 1000 ) | |
971 | { | |
972 | srand(0); | |
973 | countrandomnumbers = 0; | |
974 | ++count; | |
975 | DT2 = wxDateTime::UNow(); | |
976 | wxTimeSpan ts = DT2.Subtract( DT1 ); | |
977 | if ( ts.IsLongerThan( tsTest ) ) | |
978 | { | |
979 | break; | |
980 | } | |
981 | } | |
982 | } | |
983 | const int max = 40 * count; | |
984 | #else | |
abceee76 | 985 | static const int max = 10; |
9b16ffef | 986 | #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG |
abceee76 | 987 | |
2f1cd905 | 988 | wxProgressDialog dialog(_T("Progress dialog example"), |
78a189c9 | 989 | _T("An informative message"), |
abceee76 VZ |
990 | max, // range |
991 | this, // parent | |
992 | wxPD_CAN_ABORT | | |
ecda9475 | 993 | wxPD_CAN_SKIP | |
abceee76 | 994 | wxPD_APP_MODAL | |
df26c4c6 | 995 | // wxPD_AUTO_HIDE | -- try this as well |
abceee76 VZ |
996 | wxPD_ELAPSED_TIME | |
997 | wxPD_ESTIMATED_TIME | | |
ecda9475 WS |
998 | wxPD_REMAINING_TIME | |
999 | wxPD_SMOOTH); | |
abceee76 | 1000 | |
13188def | 1001 | bool cont = true; |
ecda9475 WS |
1002 | bool skip = false; |
1003 | // each skip will move progress about quarter forward | |
1004 | for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false ) | |
abceee76 | 1005 | { |
9b16ffef VZ |
1006 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
1007 | // do (almost) the same operations as we did for the performance test | |
1008 | srand(0); | |
1009 | for ( int j = 0; j < 1000; j++ ) | |
1010 | { | |
1011 | rand(); | |
1012 | if ( j == 999 ) | |
1013 | { | |
1014 | DT2 = wxDateTime::UNow(); | |
1015 | wxTimeSpan ts = DT2.Subtract( DT1 ); | |
1016 | if ( ts.IsLongerThan( tsTest ) ) | |
1017 | { | |
1018 | // nothing to do | |
1019 | } | |
1020 | } | |
1021 | } | |
1022 | #else | |
abceee76 | 1023 | wxSleep(1); |
9b16ffef | 1024 | #endif |
ecda9475 WS |
1025 | |
1026 | wxString msg; | |
1027 | ||
abceee76 VZ |
1028 | if ( i == max ) |
1029 | { | |
ecda9475 | 1030 | msg = _T("That's all, folks!"); |
abceee76 | 1031 | } |
ecda9475 | 1032 | else if ( i > max / 2 ) |
abceee76 | 1033 | { |
ecda9475 | 1034 | msg = _T("Only a half left (very long message)!"); |
abceee76 | 1035 | } |
ecda9475 WS |
1036 | |
1037 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
1038 | if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster | |
abceee76 | 1039 | { |
ecda9475 | 1040 | cont = dialog.Update(i, msg, &skip); |
abceee76 | 1041 | } |
ecda9475 WS |
1042 | #else |
1043 | cont = dialog.Update(i, msg, &skip); | |
1044 | #endif | |
1045 | ||
d8ddee9c VZ |
1046 | if ( !cont ) |
1047 | { | |
78a189c9 VZ |
1048 | if ( wxMessageBox(_T("Do you really want to cancel?"), |
1049 | _T("Progress dialog question"), // caption | |
1050 | wxYES_NO | wxICON_QUESTION) == wxYES ) | |
d8ddee9c VZ |
1051 | break; |
1052 | ||
9b16ffef | 1053 | cont = true; |
d8ddee9c VZ |
1054 | dialog.Resume(); |
1055 | } | |
abceee76 VZ |
1056 | } |
1057 | ||
1058 | if ( !cont ) | |
1059 | { | |
4693b20c | 1060 | wxLogStatus(wxT("Progress dialog aborted!")); |
abceee76 VZ |
1061 | } |
1062 | else | |
1063 | { | |
4693b20c | 1064 | wxLogStatus(wxT("Countdown from %d finished"), max); |
abceee76 VZ |
1065 | } |
1066 | } | |
1067 | ||
1068 | #endif // wxUSE_PROGRESSDLG | |
1069 | ||
a62b0bcc VZ |
1070 | #if wxUSE_BUSYINFO |
1071 | ||
1072 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
1073 | { | |
21977bac VZ |
1074 | wxWindowDisabler disableAll; |
1075 | ||
9f84eccd | 1076 | wxBusyInfo info(_T("Working, please wait..."), this); |
a62b0bcc | 1077 | |
5b636c67 | 1078 | for ( int i = 0; i < 18; i++ ) |
a62b0bcc | 1079 | { |
5b636c67 | 1080 | //wxUsleep(100); |
a62b0bcc VZ |
1081 | wxTheApp->Yield(); |
1082 | } | |
5b636c67 VZ |
1083 | |
1084 | wxSleep(2); | |
1085 | //wxWakeUpIdle(); | |
a62b0bcc VZ |
1086 | } |
1087 | ||
1088 | #endif // wxUSE_BUSYINFO | |
1089 | ||
761989ff VZ |
1090 | #if wxUSE_FINDREPLDLG |
1091 | ||
1092 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
1093 | { | |
14fca738 VZ |
1094 | if ( m_dlgReplace ) |
1095 | { | |
1096 | delete m_dlgReplace; | |
1097 | m_dlgReplace = NULL; | |
1098 | } | |
1099 | else | |
1100 | { | |
1101 | m_dlgReplace = new wxFindReplaceDialog | |
1102 | ( | |
1103 | this, | |
1104 | &m_findData, | |
78a189c9 | 1105 | _T("Find and replace dialog"), |
14fca738 VZ |
1106 | wxFR_REPLACEDIALOG |
1107 | ); | |
1108 | ||
13188def | 1109 | m_dlgReplace->Show(true); |
14fca738 | 1110 | } |
761989ff VZ |
1111 | } |
1112 | ||
1113 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
1114 | { | |
14fca738 VZ |
1115 | if ( m_dlgFind ) |
1116 | { | |
1117 | delete m_dlgFind; | |
1118 | m_dlgFind = NULL; | |
1119 | } | |
1120 | else | |
1121 | { | |
1122 | m_dlgFind = new wxFindReplaceDialog | |
1123 | ( | |
1124 | this, | |
1125 | &m_findData, | |
78a189c9 | 1126 | _T("Find dialog"), |
14fca738 VZ |
1127 | // just for testing |
1128 | wxFR_NOWHOLEWORD | |
1129 | ); | |
1130 | ||
13188def | 1131 | m_dlgFind->Show(true); |
14fca738 | 1132 | } |
761989ff VZ |
1133 | } |
1134 | ||
1135 | static wxString DecodeFindDialogEventFlags(int flags) | |
1136 | { | |
1137 | wxString str; | |
78a189c9 | 1138 | str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ") |
2f1cd905 VZ |
1139 | << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T("")) |
1140 | << (flags & wxFR_MATCHCASE ? _T("") : _T("not ")) | |
78a189c9 | 1141 | << _T("case sensitive"); |
761989ff VZ |
1142 | |
1143 | return str; | |
1144 | } | |
1145 | ||
1146 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
1147 | { | |
1148 | wxEventType type = event.GetEventType(); | |
1149 | ||
1150 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
1151 | { | |
4693b20c | 1152 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), |
eba33006 | 1153 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), |
761989ff VZ |
1154 | event.GetFindString().c_str(), |
1155 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1156 | } | |
1157 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
1158 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
1159 | { | |
4693b20c | 1160 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), |
eba33006 | 1161 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""), |
761989ff VZ |
1162 | event.GetFindString().c_str(), |
1163 | event.GetReplaceString().c_str(), | |
1164 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1165 | } | |
1166 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
1167 | { | |
14fca738 VZ |
1168 | wxFindReplaceDialog *dlg = event.GetDialog(); |
1169 | ||
df26c4c6 | 1170 | int idMenu; |
14fca738 VZ |
1171 | const wxChar *txt; |
1172 | if ( dlg == m_dlgFind ) | |
1173 | { | |
1174 | txt = _T("Find"); | |
df26c4c6 | 1175 | idMenu = DIALOGS_FIND; |
14fca738 VZ |
1176 | m_dlgFind = NULL; |
1177 | } | |
1178 | else if ( dlg == m_dlgReplace ) | |
1179 | { | |
1180 | txt = _T("Replace"); | |
df26c4c6 | 1181 | idMenu = DIALOGS_REPLACE; |
14fca738 VZ |
1182 | m_dlgReplace = NULL; |
1183 | } | |
1184 | else | |
1185 | { | |
1186 | txt = _T("Unknown"); | |
13188def | 1187 | idMenu = wxID_ANY; |
14fca738 | 1188 | |
2f1cd905 | 1189 | wxFAIL_MSG( _T("unexpected event") ); |
14fca738 VZ |
1190 | } |
1191 | ||
df26c4c6 VZ |
1192 | wxLogMessage(wxT("%s dialog is being closed."), txt); |
1193 | ||
13188def | 1194 | if ( idMenu != wxID_ANY ) |
df26c4c6 | 1195 | { |
13188def | 1196 | GetMenuBar()->Check(idMenu, false); |
df26c4c6 | 1197 | } |
761989ff | 1198 | |
14fca738 | 1199 | dlg->Destroy(); |
761989ff VZ |
1200 | } |
1201 | else | |
1202 | { | |
4693b20c | 1203 | wxLogError(wxT("Unknown find dialog event!")); |
761989ff VZ |
1204 | } |
1205 | } | |
1206 | ||
1207 | #endif // wxUSE_FINDREPLDLG | |
1208 | ||
abceee76 VZ |
1209 | // ---------------------------------------------------------------------------- |
1210 | // MyCanvas | |
1211 | // ---------------------------------------------------------------------------- | |
1212 | ||
d355d3fe | 1213 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
457814b5 | 1214 | { |
c50f1fb9 | 1215 | wxPaintDC dc(this); |
457814b5 JS |
1216 | dc.SetFont(wxGetApp().m_canvasFont); |
1217 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
1218 | dc.SetBackgroundMode(wxTRANSPARENT); | |
dc96b1b6 WS |
1219 | dc.DrawText( |
1220 | _T("wxWidgets common dialogs") | |
1221 | #if !defined(__SMARTPHONE__) | |
1222 | _T(" test application") | |
1223 | #endif | |
1224 | , 10, 10); | |
457814b5 JS |
1225 | } |
1226 | ||
b4954d19 WS |
1227 | #if USE_MODAL_PRESENTATION |
1228 | ||
4c45f240 VZ |
1229 | // ---------------------------------------------------------------------------- |
1230 | // MyModelessDialog | |
1231 | // ---------------------------------------------------------------------------- | |
457814b5 | 1232 | |
4c45f240 | 1233 | MyModelessDialog::MyModelessDialog(wxWindow *parent) |
13188def | 1234 | : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog"))) |
4c45f240 | 1235 | { |
cbc66a27 VZ |
1236 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
1237 | ||
78a189c9 | 1238 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me")); |
13188def | 1239 | wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled")); |
cbc66a27 VZ |
1240 | check->Disable(); |
1241 | ||
1242 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
1243 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
1244 | ||
cbc66a27 VZ |
1245 | SetSizer(sizerTop); |
1246 | ||
1247 | sizerTop->SetSizeHints(this); | |
1248 | sizerTop->Fit(this); | |
4c45f240 | 1249 | } |
abceee76 | 1250 | |
5d987909 VZ |
1251 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) |
1252 | { | |
2f1cd905 | 1253 | wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"), |
5d987909 VZ |
1254 | wxOK | wxICON_INFORMATION, this); |
1255 | } | |
1256 | ||
abceee76 VZ |
1257 | void MyModelessDialog::OnClose(wxCloseEvent& event) |
1258 | { | |
1259 | if ( event.CanVeto() ) | |
1260 | { | |
2f1cd905 | 1261 | wxMessageBox(_T("Use the menu item to close this dialog"), |
78a189c9 | 1262 | _T("Modeless dialog"), |
abceee76 VZ |
1263 | wxOK | wxICON_INFORMATION, this); |
1264 | ||
1265 | event.Veto(); | |
1266 | } | |
1267 | } | |
1268 | ||
f6bcfd97 BP |
1269 | // ---------------------------------------------------------------------------- |
1270 | // MyModalDialog | |
1271 | // ---------------------------------------------------------------------------- | |
1272 | ||
1273 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
13188def | 1274 | : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog"))) |
f6bcfd97 BP |
1275 | { |
1276 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
1277 | ||
13188def WS |
1278 | m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog...")); |
1279 | m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog")); | |
1280 | m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button")); | |
5315ebfa | 1281 | |
78a189c9 | 1282 | wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close")); |
5315ebfa VZ |
1283 | sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); |
1284 | sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); | |
f6bcfd97 | 1285 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); |
9b70bb91 | 1286 | sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); |
f6bcfd97 | 1287 | |
f6bcfd97 BP |
1288 | SetSizer(sizerTop); |
1289 | ||
1290 | sizerTop->SetSizeHints(this); | |
1291 | sizerTop->Fit(this); | |
1292 | ||
5315ebfa VZ |
1293 | m_btnModal->SetFocus(); |
1294 | m_btnModal->SetDefault(); | |
f6bcfd97 BP |
1295 | } |
1296 | ||
1297 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
1298 | { | |
1299 | if ( event.GetEventObject() == m_btnDelete ) | |
1300 | { | |
5315ebfa VZ |
1301 | delete m_btnModal; |
1302 | m_btnModal = NULL; | |
f6bcfd97 BP |
1303 | |
1304 | m_btnDelete->Disable(); | |
1305 | } | |
5315ebfa | 1306 | else if ( event.GetEventObject() == m_btnModal ) |
f6bcfd97 | 1307 | { |
13188def | 1308 | #if wxUSE_TEXTDLG |
78a189c9 VZ |
1309 | wxGetTextFromUser(_T("Dummy prompt"), |
1310 | _T("Modal dialog called from dialog"), | |
dabbc6a5 | 1311 | wxEmptyString, this); |
13188def WS |
1312 | #else |
1313 | wxMessageBox(_T("Modal dialog called from dialog")); | |
1314 | #endif // wxUSE_TEXTDLG | |
f6bcfd97 | 1315 | } |
5315ebfa VZ |
1316 | else if ( event.GetEventObject() == m_btnModeless ) |
1317 | { | |
1318 | (new MyModelessDialog(this))->Show(); | |
1319 | } | |
f6bcfd97 BP |
1320 | else |
1321 | { | |
1322 | event.Skip(); | |
1323 | } | |
1324 | } | |
b4954d19 WS |
1325 | |
1326 | #endif // USE_MODAL_PRESENTATION | |
1327 |