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