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