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