]> git.saurik.com Git - wxWidgets.git/blame - samples/dialogs/dialogs.cpp
tooltips work under Mac as well; no need for wxUSE_TOOLTIP (especially spellt incorre...
[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
0f5d8ecf
JS
28#include "../sample.xpm"
29
fb8a56b7 30#include "wx/datetime.h"
f517634c 31#include "wx/image.h"
457814b5 32
13188def
WS
33#if wxUSE_COLOURDLG
34 #include "wx/colordlg.h"
35#endif // wxUSE_COLOURDLG
dfad0599 36
13188def
WS
37#if wxUSE_CHOICEDLG
38 #include "wx/choicdlg.h"
39#endif // wxUSE_CHOICEDLG
457814b5 40
13188def
WS
41#if wxUSE_STARTUP_TIPS
42 #include "wx/tipdlg.h"
43#endif // wxUSE_STARTUP_TIPS
d7d17624 44
13188def 45#if wxUSE_PROGRESSDLG
9b16ffef
VZ
46#if wxUSE_STOPWATCH && wxUSE_LONGLONG
47 #include <wx/datetime.h> // wxDateTime
48#endif
49
13188def
WS
50 #include "wx/progdlg.h"
51#endif // wxUSE_PROGRESSDLG
52
53#if wxUSE_BUSYINFO
54 #include "wx/busyinfo.h"
55#endif // wxUSE_BUSYINFO
56
57#if wxUSE_NUMBERDLG
58 #include "wx/numdlg.h"
59#endif // wxUSE_NUMBERDLG
60
61#if wxUSE_FILEDLG
62 #include "wx/filedlg.h"
63#endif // wxUSE_FILEDLG
64
65#if wxUSE_DIRDLG
66 #include "wx/dirdlg.h"
67#endif // wxUSE_DIRDLG
68
69#if wxUSE_FONTDLG
70 #include "wx/fontdlg.h"
71#endif // wxUSE_FONTDLG
72
73#if wxUSE_FINDREPLDLG
74 #include "wx/fdrepdlg.h"
75#endif // wxUSE_FINDREPLDLG
4ad3c82f 76
62675ef3 77#if wxUSE_SPINCTRL
0f5d8ecf 78#include "wx/spinctrl.h"
62675ef3
JS
79#endif
80
0f5d8ecf
JS
81#include "wx/propdlg.h"
82
457814b5
JS
83#include "dialogs.h"
84
13188def
WS
85#if USE_COLOURDLG_GENERIC
86 #include "wx/generic/colrdlgg.h"
87#endif // USE_COLOURDLG_GENERIC
88
13188def
WS
89#if USE_DIRDLG_GENERIC
90 #include "wx/generic/dirdlgg.h"
91#endif // USE_DIRDLG_GENERIC
92
695fe764
WS
93#if USE_FILEDLG_GENERIC
94 #include "wx/generic/filedlgg.h"
95#endif // USE_FILEDLG_GENERIC
96
97#if USE_FONTDLG_GENERIC
98 #include "wx/generic/fontdlgg.h"
99#endif // USE_FONTDLG_GENERIC
100
457814b5
JS
101IMPLEMENT_APP(MyApp)
102
4c45f240
VZ
103BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
104 EVT_PAINT(MyCanvas::OnPaint)
105END_EVENT_TABLE()
106
13188def
WS
107
108
4c45f240 109BEGIN_EVENT_TABLE(MyFrame, wxFrame)
13188def
WS
110 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
111
112#if wxUSE_COLOURDLG
4c45f240 113 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
13188def
WS
114#endif // wxUSE_COLOURDLG
115
116#if wxUSE_FONTDLG
4c45f240 117 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
13188def
WS
118#endif // wxUSE_FONTDLG
119
120#if wxUSE_LOG_DIALOG
4c45f240 121 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
13188def
WS
122#endif // wxUSE_LOG_DIALOG
123
124#if wxUSE_TEXTDLG
4c45f240
VZ
125 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
126 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
13188def
WS
127#endif // wxUSE_TEXTDLG
128
129#if wxUSE_NUMBERDLG
4c45f240 130 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
13188def
WS
131#endif // wxUSE_NUMBERDLG
132
133#if wxUSE_CHOICEDLG
4c45f240 134 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
d6c9c1b7 135 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
13188def
WS
136#endif // wxUSE_CHOICEDLG
137
138#if wxUSE_FILEDLG
4c45f240 139 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
35b45b33 140 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
4c45f240
VZ
141 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
142 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
13188def
WS
143#endif // wxUSE_FILEDLG
144
695fe764
WS
145#if USE_FILEDLG_GENERIC
146 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric)
147 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric)
148 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric)
149#endif // USE_FILEDLG_GENERIC
150
13188def 151#if wxUSE_DIRDLG
4c45f240 152 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
f09c8393 153 EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
13188def
WS
154#endif // wxUSE_DIRDLG
155
156#if USE_MODAL_PRESENTATION
f6bcfd97 157 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
4c45f240 158 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
13188def
WS
159#endif // USE_MODAL
160
161#if wxUSE_STARTUP_TIPS
4c45f240 162 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
13188def
WS
163#endif // wxUSE_STARTUP_TIPS
164
165#if USE_FONTDLG_GENERIC
4c45f240 166 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
13188def
WS
167#endif // USE_FONTDLG_GENERIC
168
169#if USE_DIRDLG_GENERIC
170 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
171#endif // wxMSW || wxMAC
172
173#if USE_COLOURDLG_GENERIC
174 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
175#endif // USE_COLOURDLG_GENERIC
a62b0bcc 176
abceee76
VZ
177#if wxUSE_PROGRESSDLG
178 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
761989ff 179#endif // wxUSE_PROGRESSDLG
a62b0bcc
VZ
180
181#if wxUSE_BUSYINFO
182 EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
183#endif // wxUSE_BUSYINFO
184
761989ff
VZ
185#if wxUSE_FINDREPLDLG
186 EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
187 EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
188
13188def
WS
189 EVT_FIND(wxID_ANY, MyFrame::OnFindDialog)
190 EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog)
191 EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog)
192 EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog)
193 EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
761989ff 194#endif // wxUSE_FINDREPLDLG
13188def 195
532d575b 196#if USE_SETTINGS_DIALOG
0f5d8ecf 197 EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet)
532d575b
WS
198#endif
199
0f5d8ecf 200 EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
9b16ffef 201
4c45f240 202 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
4c45f240 203END_EVENT_TABLE()
abceee76 204
13188def 205#if USE_MODAL_PRESENTATION
f6bcfd97 206
13188def
WS
207 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
208 EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
209 END_EVENT_TABLE()
5d987909 210
13188def
WS
211 BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
212 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
213 EVT_CLOSE(MyModelessDialog::OnClose)
214 END_EVENT_TABLE()
215
216#endif // USE_MODAL_PRESENTATION
abceee76 217
c67daf87 218MyCanvas *myCanvas = (MyCanvas *) NULL;
457814b5 219
457814b5 220// `Main program' equivalent, creating windows and returning main app frame
4c45f240 221bool MyApp::OnInit()
457814b5 222{
f517634c 223#if wxUSE_IMAGE
013e1fee 224 wxInitAllImageHandlers();
f517634c 225#endif
013e1fee 226
13188def
WS
227 m_canvasTextColour = wxColour(_T("BLACK"));
228 m_canvasFont = *wxNORMAL_FONT;
457814b5 229
13188def
WS
230 // Create the main frame window
231 MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example"));
457814b5 232
13188def
WS
233 // Make a menubar
234 wxMenu *file_menu = new wxMenu;
dabbc6a5 235
13188def 236 file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
457814b5 237
457814b5 238
33bcca32 239#if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
f09c8393 240
33bcca32 241 wxMenu *choices_menu = new wxMenu;
f09c8393 242
33bcca32
VZ
243 #if wxUSE_COLOURDLG
244 choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour"));
245 #endif // wxUSE_COLOURDLG
f09c8393 246
33bcca32
VZ
247 #if wxUSE_FONTDLG
248 choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
249 #endif // wxUSE_FONTDLG
457814b5 250
33bcca32
VZ
251 #if wxUSE_CHOICEDLG
252 choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C"));
253 choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U"));
254 #endif // wxUSE_CHOICEDLG
695fe764 255
33bcca32
VZ
256 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
257 choices_menu->AppendSeparator();
258 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
695fe764 259
33bcca32
VZ
260 #if USE_COLOURDLG_GENERIC
261 choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)"));
262 #endif // USE_COLOURDLG_GENERIC
695fe764 263
33bcca32
VZ
264 #if USE_FONTDLG_GENERIC
265 choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)"));
266 #endif // USE_FONTDLG_GENERIC
d93c719a 267
33bcca32
VZ
268 file_menu->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu);
269#endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
457814b5 270
457814b5 271
33bcca32 272#if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
13188def 273
33bcca32 274 wxMenu *entry_menu = new wxMenu;
13188def 275
33bcca32
VZ
276 #if wxUSE_TEXTDLG
277 entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E"));
278 entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P"));
279 #endif // wxUSE_TEXTDLG
13188def 280
33bcca32
VZ
281 #if wxUSE_NUMBERDLG
282 entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N"));
283 #endif // wxUSE_NUMBERDLG
13188def 284
33bcca32 285 file_menu->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu);
13188def 286
33bcca32 287#endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
13188def
WS
288
289
33bcca32 290#if wxUSE_FILEDLG
13188def 291
33bcca32
VZ
292 wxMenu *filedlg_menu = new wxMenu;
293 filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O"));
294 filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2"));
295 filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
296 filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
695fe764 297
33bcca32
VZ
298 #if USE_FILEDLG_GENERIC
299 filedlg_menu->AppendSeparator();
300 filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)"));
301 filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)"));
302 filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)"));
303 #endif // USE_FILEDLG_GENERIC
695fe764 304
33bcca32 305 file_menu->Append(wxID_ANY,_T("&File operations"),filedlg_menu);
13188def 306
33bcca32 307#endif // wxUSE_FILEDLG
13188def 308
33bcca32
VZ
309#if wxUSE_DIRDLG
310 wxMenu *dir_menu = new wxMenu;
13188def 311
33bcca32
VZ
312 dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D"));
313 dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
314 file_menu->Append(wxID_ANY,_T("&Directory operations"),dir_menu);
13188def 315
33bcca32
VZ
316 #if USE_DIRDLG_GENERIC
317 dir_menu->AppendSeparator();
318 dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)"));
319 #endif // USE_DIRDLG_GENERIC
13188def 320
33bcca32 321#endif // wxUSE_DIRDLG
13188def
WS
322
323
33bcca32 324#if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
13188def 325
33bcca32 326 wxMenu *info_menu = new wxMenu;
13188def 327
33bcca32
VZ
328 #if wxUSE_STARTUP_TIPS
329 info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T"));
330 #endif // wxUSE_STARTUP_TIPS
13188def 331
33bcca32
VZ
332 #if wxUSE_PROGRESSDLG
333 info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G"));
334 #endif // wxUSE_PROGRESSDLG
13188def 335
33bcca32
VZ
336 #if wxUSE_BUSYINFO
337 info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B"));
338 #endif // wxUSE_BUSYINFO
13188def 339
33bcca32
VZ
340 #if wxUSE_LOG_DIALOG
341 info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L"));
342 #endif // wxUSE_LOG_DIALOG
13188def 343
33bcca32 344 file_menu->Append(wxID_ANY,_T("&Informative dialogs"),info_menu);
13188def 345
33bcca32 346#endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
13188def
WS
347
348
33bcca32
VZ
349#if wxUSE_FINDREPLDLG
350 wxMenu *find_menu = new wxMenu;
351 find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"));
352 find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"));
353 file_menu->Append(wxID_ANY,_T("&Searching"),find_menu);
354#endif // wxUSE_FINDREPLDLG
13188def 355
33bcca32
VZ
356#if USE_MODAL_PRESENTATION
357 wxMenu *modal_menu = new wxMenu;
358 modal_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W"));
359 modal_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"));
360 file_menu->Append(wxID_ANY,_T("&Modal/Modeless"),modal_menu);
361#endif // USE_MODAL_PRESENTATION
13188def 362
532d575b 363#if USE_SETTINGS_DIALOG
0f5d8ecf 364 file_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Property Sheet Dialog\tCtrl-P"));
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
VZ
683 dialog.SetDirectory(wxGetHomeDir());
684
c50f1fb9
VZ
685 if (dialog.ShowModal() == wxID_OK)
686 {
5919d76b 687 wxString info;
13393ab6
RR
688 info.Printf(_T("Full file name: %s\n")
689 _T("Path: %s\n")
690 _T("Name: %s"),
5919d76b
VZ
691 dialog.GetPath().c_str(),
692 dialog.GetDirectory().c_str(),
693 dialog.GetFilename().c_str());
78a189c9 694 wxMessageDialog dialog2(this, info, _T("Selected file"));
c50f1fb9
VZ
695 dialog2.ShowModal();
696 }
457814b5
JS
697}
698
35b45b33
VZ
699// this shows how to take advantage of specifying a default extension in the
700// call to wxFileSelector: it is remembered after each new call and the next
701// one will use it by default
702void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
703{
704 static wxString s_extDef;
705 wxString path = wxFileSelector(
706 _T("Select the file to load"),
dabbc6a5 707 wxEmptyString, wxEmptyString,
35b45b33 708 s_extDef,
3601f639
VZ
709 wxString::Format
710 (
711 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
712 wxFileSelectorDefaultWildcardStr,
713 wxFileSelectorDefaultWildcardStr
714 ),
fbf4eacb 715 wxCHANGE_DIR,
35b45b33
VZ
716 this
717 );
718
719 if ( !path )
720 return;
721
722 // it is just a sample, would use wxSplitPath in real program
723 s_extDef = path.AfterLast(_T('.'));
724
725 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
37d403aa 726 (const wxChar*) path, (const wxChar*) s_extDef);
35b45b33
VZ
727}
728
c61f4f6d
VZ
729void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
730{
dabbc6a5 731 wxString wildcards =
f0f43012
JS
732#ifdef __WXMOTIF__
733 _T("C++ files (*.cpp)|*.cpp");
734#else
3601f639
VZ
735 wxString::Format
736 (
737 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
738 wxFileSelectorDefaultWildcardStr,
739 wxFileSelectorDefaultWildcardStr
740 );
f0f43012 741#endif
78a189c9 742 wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
dabbc6a5 743 wxEmptyString, wxEmptyString, wildcards,
470caaf9 744 wxMULTIPLE);
c61f4f6d
VZ
745
746 if (dialog.ShowModal() == wxID_OK)
747 {
748 wxArrayString paths, filenames;
749
750 dialog.GetPaths(paths);
751 dialog.GetFilenames(filenames);
752
753 wxString msg, s;
754 size_t count = paths.GetCount();
755 for ( size_t n = 0; n < count; n++ )
756 {
757 s.Printf(_T("File %d: %s (%s)\n"),
fba1b53b 758 (int)n, paths[n].c_str(), filenames[n].c_str());
c61f4f6d
VZ
759
760 msg += s;
761 }
f0f43012
JS
762 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
763 msg += s;
c61f4f6d 764
78a189c9 765 wxMessageDialog dialog2(this, msg, _T("Selected files"));
c61f4f6d
VZ
766 dialog2.ShowModal();
767 }
768}
769
d355d3fe 770void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
457814b5 771{
2f1cd905
VZ
772 wxFileDialog dialog(this,
773 _T("Testing save file dialog"),
dabbc6a5 774 wxEmptyString,
2b5f62a0 775 _T("myletter.doc"),
2f1cd905
VZ
776 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
777 wxSAVE|wxOVERWRITE_PROMPT);
c50f1fb9 778
2b5f62a0
VZ
779 dialog.SetFilterIndex(1);
780
c50f1fb9
VZ
781 if (dialog.ShowModal() == wxID_OK)
782 {
2b5f62a0
VZ
783 wxLogMessage(_T("%s, filter %d"),
784 dialog.GetPath().c_str(), dialog.GetFilterIndex());
c50f1fb9 785 }
457814b5 786}
13188def 787#endif // wxUSE_FILEDLG
457814b5 788
695fe764
WS
789#if USE_FILEDLG_GENERIC
790void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
791{
792 wxGenericFileDialog dialog
793 (
794 this,
795 _T("Testing open file dialog"),
796 wxEmptyString,
797 wxEmptyString,
daf32463 798 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
695fe764
WS
799 );
800
801 dialog.SetDirectory(wxGetHomeDir());
802
803 if (dialog.ShowModal() == wxID_OK)
804 {
805 wxString info;
806 info.Printf(_T("Full file name: %s\n")
807 _T("Path: %s\n")
808 _T("Name: %s"),
809 dialog.GetPath().c_str(),
810 dialog.GetDirectory().c_str(),
811 dialog.GetFilename().c_str());
812 wxMessageDialog dialog2(this, info, _T("Selected file"));
813 dialog2.ShowModal();
814 }
815}
816
817void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
818{
daf32463 819 wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
695fe764
WS
820 wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
821 wxEmptyString, wxEmptyString, wildcards,
822 wxMULTIPLE);
823
824 if (dialog.ShowModal() == wxID_OK)
825 {
826 wxArrayString paths, filenames;
827
828 dialog.GetPaths(paths);
829 dialog.GetFilenames(filenames);
830
831 wxString msg, s;
832 size_t count = paths.GetCount();
833 for ( size_t n = 0; n < count; n++ )
834 {
835 s.Printf(_T("File %d: %s (%s)\n"),
836 (int)n, paths[n].c_str(), filenames[n].c_str());
837
838 msg += s;
839 }
840 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
841 msg += s;
842
843 wxMessageDialog dialog2(this, msg, _T("Selected files"));
844 dialog2.ShowModal();
845 }
846}
847
848void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
849{
850 wxGenericFileDialog dialog(this,
851 _T("Testing save file dialog"),
852 wxEmptyString,
853 _T("myletter.doc"),
854 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
855 wxSAVE|wxOVERWRITE_PROMPT);
856
857 dialog.SetFilterIndex(1);
858
859 if (dialog.ShowModal() == wxID_OK)
860 {
861 wxLogMessage(_T("%s, filter %d"),
862 dialog.GetPath().c_str(), dialog.GetFilterIndex());
863 }
864}
865#endif // USE_FILEDLG_GENERIC
866
13188def 867#if wxUSE_DIRDLG
f09c8393 868void MyFrame::DoDirChoose(int style)
457814b5 869{
3f2711d5
VZ
870 // pass some initial dir to wxDirDialog
871 wxString dirHome;
872 wxGetHomeDir(&dirHome);
873
f09c8393 874 wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
c50f1fb9
VZ
875
876 if (dialog.ShowModal() == wxID_OK)
877 {
2b5f62a0 878 wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
c50f1fb9
VZ
879 }
880}
881
f09c8393
VZ
882void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
883{
884 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON);
885}
886
887void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
888{
8768548b 889 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON);
f09c8393 890}
13188def 891#endif // wxUSE_DIRDLG
f09c8393 892
13188def 893#if USE_DIRDLG_GENERIC
51a58d8b
JS
894void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
895{
896 // pass some initial dir to wxDirDialog
897 wxString dirHome;
898 wxGetHomeDir(&dirHome);
899
78a189c9 900 wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
51a58d8b
JS
901
902 if (dialog.ShowModal() == wxID_OK)
903 {
78a189c9 904 wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
51a58d8b
JS
905 dialog2.ShowModal();
906 }
907}
13188def 908#endif // USE_DIRDLG_GENERIC
51a58d8b 909
13188def 910#if USE_MODAL_PRESENTATION
f6bcfd97
BP
911void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
912{
913 MyModalDialog dlg(this);
914 dlg.ShowModal();
915}
916
4c45f240
VZ
917void MyFrame::ModelessDlg(wxCommandEvent& event)
918{
2f82899b 919 bool show = GetMenuBar()->IsChecked(event.GetId());
4c45f240
VZ
920
921 if ( show )
922 {
923 if ( !m_dialog )
924 {
925 m_dialog = new MyModelessDialog(this);
926 }
927
13188def 928 m_dialog->Show(true);
4c45f240
VZ
929 }
930 else // hide
931 {
26a12ab3
JS
932 // If m_dialog is NULL, then possibly the system
933 // didn't report the checked menu item status correctly.
934 // It should be true just after the menu item was selected,
935 // if there was no modeless dialog yet.
936
937 wxASSERT( m_dialog != NULL );
938 if (m_dialog)
939 m_dialog->Hide();
4c45f240
VZ
940 }
941}
13188def 942#endif // USE_MODAL_PRESENTATION
4c45f240 943
13188def 944#if wxUSE_STARTUP_TIPS
87728739 945void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
c50f1fb9
VZ
946{
947 static size_t s_index = (size_t)-1;
948
949 if ( s_index == (size_t)-1 )
950 {
951 srand(time(NULL));
952
953 // this is completely bogus, we don't know how many lines are there
954 // in the file, but who cares, it's a demo only...
955 s_index = rand() % 5;
956 }
957
2f1cd905 958 wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
c50f1fb9
VZ
959
960 bool showAtStartup = wxShowTip(this, tipProvider);
961
962 if ( showAtStartup )
963 {
2f1cd905 964 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
c50f1fb9
VZ
965 wxOK | wxICON_INFORMATION, this);
966 }
457814b5 967
c50f1fb9
VZ
968 s_index = tipProvider->GetCurrentTip();
969 delete tipProvider;
457814b5 970}
13188def 971#endif // wxUSE_STARTUP_TIPS
457814b5 972
532d575b 973#if USE_SETTINGS_DIALOG
0f5d8ecf
JS
974void MyFrame::OnPropertySheet(wxCommandEvent& WXUNUSED(event))
975{
976 SettingsDialog dialog(this);
977 dialog.ShowModal();
978}
532d575b 979#endif // USE_SETTINGS_DIALOG
0f5d8ecf 980
9b16ffef
VZ
981void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
982{
983 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
984
985 wxSleep(3);
986
987 RequestUserAttention(wxUSER_ATTENTION_ERROR);
988}
989
d355d3fe 990void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
457814b5 991{
13188def 992 Close(true);
457814b5
JS
993}
994
abceee76
VZ
995#if wxUSE_PROGRESSDLG
996
997void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
998{
9b16ffef
VZ
999 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1000 // check the performance
1001 int countrandomnumbers = 0, count = 0;
1002 wxTimeSpan tsTest(0,0,0,250);
1003 wxDateTime DT2, DT1 = wxDateTime::UNow();
1004 srand(0);
1005 while(1)
1006 {
1007 rand();
1008 ++countrandomnumbers;
1009 if ( countrandomnumbers == 1000 )
1010 {
1011 srand(0);
1012 countrandomnumbers = 0;
1013 ++count;
1014 DT2 = wxDateTime::UNow();
1015 wxTimeSpan ts = DT2.Subtract( DT1 );
1016 if ( ts.IsLongerThan( tsTest ) )
1017 {
1018 break;
1019 }
1020 }
1021 }
1022 const int max = 40 * count;
1023 #else
abceee76 1024 static const int max = 10;
9b16ffef 1025 #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG
abceee76 1026
2f1cd905 1027 wxProgressDialog dialog(_T("Progress dialog example"),
78a189c9 1028 _T("An informative message"),
abceee76
VZ
1029 max, // range
1030 this, // parent
1031 wxPD_CAN_ABORT |
ecda9475 1032 wxPD_CAN_SKIP |
abceee76 1033 wxPD_APP_MODAL |
df26c4c6 1034 // wxPD_AUTO_HIDE | -- try this as well
abceee76
VZ
1035 wxPD_ELAPSED_TIME |
1036 wxPD_ESTIMATED_TIME |
ecda9475
WS
1037 wxPD_REMAINING_TIME |
1038 wxPD_SMOOTH);
abceee76 1039
13188def 1040 bool cont = true;
ecda9475
WS
1041 bool skip = false;
1042 // each skip will move progress about quarter forward
1043 for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false )
abceee76 1044 {
9b16ffef
VZ
1045 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
1046 // do (almost) the same operations as we did for the performance test
1047 srand(0);
1048 for ( int j = 0; j < 1000; j++ )
1049 {
1050 rand();
1051 if ( j == 999 )
1052 {
1053 DT2 = wxDateTime::UNow();
1054 wxTimeSpan ts = DT2.Subtract( DT1 );
1055 if ( ts.IsLongerThan( tsTest ) )
1056 {
1057 // nothing to do
1058 }
1059 }
1060 }
1061 #else
abceee76 1062 wxSleep(1);
9b16ffef 1063 #endif
ecda9475
WS
1064
1065 wxString msg;
1066
abceee76
VZ
1067 if ( i == max )
1068 {
ecda9475 1069 msg = _T("That's all, folks!");
abceee76 1070 }
ecda9475 1071 else if ( i > max / 2 )
abceee76 1072 {
ecda9475 1073 msg = _T("Only a half left (very long message)!");
abceee76 1074 }
ecda9475
WS
1075
1076#if wxUSE_STOPWATCH && wxUSE_LONGLONG
1077 if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
abceee76 1078 {
ecda9475 1079 cont = dialog.Update(i, msg, &skip);
abceee76 1080 }
ecda9475
WS
1081#else
1082 cont = dialog.Update(i, msg, &skip);
1083#endif
1084
d8ddee9c
VZ
1085 if ( !cont )
1086 {
78a189c9
VZ
1087 if ( wxMessageBox(_T("Do you really want to cancel?"),
1088 _T("Progress dialog question"), // caption
1089 wxYES_NO | wxICON_QUESTION) == wxYES )
d8ddee9c
VZ
1090 break;
1091
9b16ffef 1092 cont = true;
d8ddee9c
VZ
1093 dialog.Resume();
1094 }
abceee76
VZ
1095 }
1096
1097 if ( !cont )
1098 {
4693b20c 1099 wxLogStatus(wxT("Progress dialog aborted!"));
abceee76
VZ
1100 }
1101 else
1102 {
4693b20c 1103 wxLogStatus(wxT("Countdown from %d finished"), max);
abceee76
VZ
1104 }
1105}
1106
1107#endif // wxUSE_PROGRESSDLG
1108
a62b0bcc
VZ
1109#if wxUSE_BUSYINFO
1110
1111void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
1112{
21977bac
VZ
1113 wxWindowDisabler disableAll;
1114
9f84eccd 1115 wxBusyInfo info(_T("Working, please wait..."), this);
a62b0bcc 1116
5b636c67 1117 for ( int i = 0; i < 18; i++ )
a62b0bcc 1118 {
5b636c67 1119 //wxUsleep(100);
a62b0bcc
VZ
1120 wxTheApp->Yield();
1121 }
5b636c67
VZ
1122
1123 wxSleep(2);
1124 //wxWakeUpIdle();
a62b0bcc
VZ
1125}
1126
1127#endif // wxUSE_BUSYINFO
1128
761989ff
VZ
1129#if wxUSE_FINDREPLDLG
1130
1131void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
1132{
14fca738
VZ
1133 if ( m_dlgReplace )
1134 {
1135 delete m_dlgReplace;
1136 m_dlgReplace = NULL;
1137 }
1138 else
1139 {
1140 m_dlgReplace = new wxFindReplaceDialog
1141 (
1142 this,
1143 &m_findData,
78a189c9 1144 _T("Find and replace dialog"),
14fca738
VZ
1145 wxFR_REPLACEDIALOG
1146 );
1147
13188def 1148 m_dlgReplace->Show(true);
14fca738 1149 }
761989ff
VZ
1150}
1151
1152void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
1153{
14fca738
VZ
1154 if ( m_dlgFind )
1155 {
1156 delete m_dlgFind;
1157 m_dlgFind = NULL;
1158 }
1159 else
1160 {
1161 m_dlgFind = new wxFindReplaceDialog
1162 (
1163 this,
1164 &m_findData,
78a189c9 1165 _T("Find dialog"),
14fca738
VZ
1166 // just for testing
1167 wxFR_NOWHOLEWORD
1168 );
1169
13188def 1170 m_dlgFind->Show(true);
14fca738 1171 }
761989ff
VZ
1172}
1173
1174static wxString DecodeFindDialogEventFlags(int flags)
1175{
1176 wxString str;
78a189c9 1177 str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
2f1cd905
VZ
1178 << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
1179 << (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
78a189c9 1180 << _T("case sensitive");
761989ff
VZ
1181
1182 return str;
1183}
1184
1185void MyFrame::OnFindDialog(wxFindDialogEvent& event)
1186{
1187 wxEventType type = event.GetEventType();
1188
1189 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
1190 {
4693b20c 1191 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
eba33006 1192 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
761989ff
VZ
1193 event.GetFindString().c_str(),
1194 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1195 }
1196 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
1197 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
1198 {
4693b20c 1199 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
eba33006 1200 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
761989ff
VZ
1201 event.GetFindString().c_str(),
1202 event.GetReplaceString().c_str(),
1203 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1204 }
1205 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
1206 {
14fca738
VZ
1207 wxFindReplaceDialog *dlg = event.GetDialog();
1208
df26c4c6 1209 int idMenu;
14fca738
VZ
1210 const wxChar *txt;
1211 if ( dlg == m_dlgFind )
1212 {
1213 txt = _T("Find");
df26c4c6 1214 idMenu = DIALOGS_FIND;
14fca738
VZ
1215 m_dlgFind = NULL;
1216 }
1217 else if ( dlg == m_dlgReplace )
1218 {
1219 txt = _T("Replace");
df26c4c6 1220 idMenu = DIALOGS_REPLACE;
14fca738
VZ
1221 m_dlgReplace = NULL;
1222 }
1223 else
1224 {
1225 txt = _T("Unknown");
13188def 1226 idMenu = wxID_ANY;
14fca738 1227
2f1cd905 1228 wxFAIL_MSG( _T("unexpected event") );
14fca738
VZ
1229 }
1230
df26c4c6
VZ
1231 wxLogMessage(wxT("%s dialog is being closed."), txt);
1232
13188def 1233 if ( idMenu != wxID_ANY )
df26c4c6 1234 {
13188def 1235 GetMenuBar()->Check(idMenu, false);
df26c4c6 1236 }
761989ff 1237
14fca738 1238 dlg->Destroy();
761989ff
VZ
1239 }
1240 else
1241 {
4693b20c 1242 wxLogError(wxT("Unknown find dialog event!"));
761989ff
VZ
1243 }
1244}
1245
1246#endif // wxUSE_FINDREPLDLG
1247
abceee76
VZ
1248// ----------------------------------------------------------------------------
1249// MyCanvas
1250// ----------------------------------------------------------------------------
1251
d355d3fe 1252void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
457814b5 1253{
c50f1fb9 1254 wxPaintDC dc(this);
457814b5
JS
1255 dc.SetFont(wxGetApp().m_canvasFont);
1256 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
1257 dc.SetBackgroundMode(wxTRANSPARENT);
dc96b1b6
WS
1258 dc.DrawText(
1259 _T("wxWidgets common dialogs")
1260#if !defined(__SMARTPHONE__)
1261 _T(" test application")
1262#endif
1263 , 10, 10);
457814b5
JS
1264}
1265
b4954d19
WS
1266#if USE_MODAL_PRESENTATION
1267
4c45f240
VZ
1268// ----------------------------------------------------------------------------
1269// MyModelessDialog
1270// ----------------------------------------------------------------------------
457814b5 1271
4c45f240 1272MyModelessDialog::MyModelessDialog(wxWindow *parent)
13188def 1273 : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog")))
4c45f240 1274{
cbc66a27
VZ
1275 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
1276
78a189c9 1277 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
13188def 1278 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled"));
cbc66a27
VZ
1279 check->Disable();
1280
1281 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
1282 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
1283
cbc66a27
VZ
1284 SetSizer(sizerTop);
1285
1286 sizerTop->SetSizeHints(this);
1287 sizerTop->Fit(this);
4c45f240 1288}
abceee76 1289
5d987909
VZ
1290void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
1291{
2f1cd905 1292 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
5d987909
VZ
1293 wxOK | wxICON_INFORMATION, this);
1294}
1295
abceee76
VZ
1296void MyModelessDialog::OnClose(wxCloseEvent& event)
1297{
1298 if ( event.CanVeto() )
1299 {
2f1cd905 1300 wxMessageBox(_T("Use the menu item to close this dialog"),
78a189c9 1301 _T("Modeless dialog"),
abceee76
VZ
1302 wxOK | wxICON_INFORMATION, this);
1303
1304 event.Veto();
1305 }
1306}
1307
f6bcfd97
BP
1308// ----------------------------------------------------------------------------
1309// MyModalDialog
1310// ----------------------------------------------------------------------------
1311
1312MyModalDialog::MyModalDialog(wxWindow *parent)
13188def 1313 : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog")))
f6bcfd97
BP
1314{
1315 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1316
13188def
WS
1317 m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog..."));
1318 m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog"));
1319 m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button"));
5315ebfa 1320
78a189c9 1321 wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
5315ebfa
VZ
1322 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
1323 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97 1324 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
9b70bb91 1325 sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97 1326
f6bcfd97
BP
1327 SetSizer(sizerTop);
1328
1329 sizerTop->SetSizeHints(this);
1330 sizerTop->Fit(this);
1331
5315ebfa
VZ
1332 m_btnModal->SetFocus();
1333 m_btnModal->SetDefault();
f6bcfd97
BP
1334}
1335
1336void MyModalDialog::OnButton(wxCommandEvent& event)
1337{
1338 if ( event.GetEventObject() == m_btnDelete )
1339 {
5315ebfa
VZ
1340 delete m_btnModal;
1341 m_btnModal = NULL;
f6bcfd97
BP
1342
1343 m_btnDelete->Disable();
1344 }
5315ebfa 1345 else if ( event.GetEventObject() == m_btnModal )
f6bcfd97 1346 {
13188def 1347#if wxUSE_TEXTDLG
78a189c9
VZ
1348 wxGetTextFromUser(_T("Dummy prompt"),
1349 _T("Modal dialog called from dialog"),
dabbc6a5 1350 wxEmptyString, this);
13188def
WS
1351#else
1352 wxMessageBox(_T("Modal dialog called from dialog"));
1353#endif // wxUSE_TEXTDLG
f6bcfd97 1354 }
5315ebfa
VZ
1355 else if ( event.GetEventObject() == m_btnModeless )
1356 {
1357 (new MyModelessDialog(this))->Show();
1358 }
f6bcfd97
BP
1359 else
1360 {
1361 event.Skip();
1362 }
1363}
b4954d19
WS
1364
1365#endif // USE_MODAL_PRESENTATION
1366
532d575b 1367#if USE_SETTINGS_DIALOG
0f5d8ecf
JS
1368// ----------------------------------------------------------------------------
1369// SettingsDialog
1370// ----------------------------------------------------------------------------
1371
1372IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
1373
1374BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
1375END_EVENT_TABLE()
1376
1377SettingsDialog::SettingsDialog(wxWindow* win)
1378{
0f4991f4 1379 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
0f5d8ecf 1380
532d575b 1381 Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
3103e8a9
JS
1382 wxDEFAULT_DIALOG_STYLE
1383#ifndef __WXWINCE__
1384 |wxRESIZE_BORDER
532d575b 1385#endif
3103e8a9 1386 );
0f5d8ecf
JS
1387 CreateButtons(wxOK|wxCANCEL|wxHELP);
1388
1389 wxBookCtrlBase* notebook = GetBookCtrl();
1390
1391 wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
1392 wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
1393
1394 notebook->AddPage(generalSettings, _("General"));
1395 notebook->AddPage(aestheticSettings, _("Aesthetics"));
1396
1397 LayoutDialog();
1398}
1399
1400wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
1401{
1402 wxPanel* panel = new wxPanel(parent, wxID_ANY);
1403
1404 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
1405 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1406
1407 //// LOAD LAST FILE
1408
1409 wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
1410 wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize);
1411 itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1412 item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
1413
1414 //// AUTOSAVE
1415
1416 wxString autoSaveLabel = _("&Auto-save every");
1417 wxString minsLabel = _("mins");
1418
1419 wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
1420 wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
62675ef3
JS
1421
1422#if wxUSE_SPINCTRL
0f5d8ecf 1423 wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
532d575b 1424 wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1);
62675ef3 1425#endif
532d575b 1426
0f5d8ecf 1427 itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
62675ef3 1428#if wxUSE_SPINCTRL
0f5d8ecf 1429 itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
62675ef3 1430#endif
0f5d8ecf
JS
1431 itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1432 item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
1433
1434 //// TOOLTIPS
532d575b 1435
0f5d8ecf
JS
1436 wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
1437 wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize);
1438 itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1439 item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
1440
1441 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
1442
1443 panel->SetSizer(topSizer);
1444 topSizer->Fit(panel);
532d575b 1445
0f5d8ecf
JS
1446 return panel;
1447}
1448
1449wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
1450{
1451 wxPanel* panel = new wxPanel(parent, wxID_ANY);
1452
1453 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
1454 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1455
1456 //// PROJECT OR GLOBAL
1457 wxString globalOrProjectChoices[2];
1458 globalOrProjectChoices[0] = _("&New projects");
1459 globalOrProjectChoices[1] = _("&This project");
1460
1461 wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"),
1462 wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
1463 item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
1464
1465 projectOrGlobal->SetSelection(0);
1466
1467 //// BACKGROUND STYLE
1468 wxArrayString backgroundStyleChoices;
1469 backgroundStyleChoices.Add(wxT("Colour"));
1470 backgroundStyleChoices.Add(wxT("Image"));
532d575b 1471 wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:"));
0f5d8ecf
JS
1472
1473 wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
1474 item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
1475
1476 wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
1477
1478 wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
1479
1480 itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1481 itemSizer2->Add(5, 5, 1, wxALL, 0);
1482 itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1483
1484 styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
1485
62675ef3 1486#if wxUSE_SPINCTRL
0f5d8ecf
JS
1487 //// FONT SIZE SELECTION
1488
532d575b 1489 wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:"));
0f5d8ecf
JS
1490 wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
1491
1492 wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition,
532d575b 1493 wxSize(80, wxDefaultCoord));
0f5d8ecf
JS
1494 itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
1495
1496 item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
62675ef3 1497#endif
0f5d8ecf
JS
1498
1499 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
0f4991f4 1500 topSizer->AddSpacer(5);
0f5d8ecf
JS
1501
1502 panel->SetSizer(topSizer);
1503 topSizer->Fit(panel);
532d575b 1504
0f5d8ecf
JS
1505 return panel;
1506}
1507
532d575b 1508#endif // USE_SETTINGS_DIALOG