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