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