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