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