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