]> git.saurik.com Git - wxWidgets.git/blame - samples/dialogs/dialogs.cpp
TrueType support for Canvas.
[wxWidgets.git] / samples / dialogs / dialogs.cpp
CommitLineData
457814b5
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialogs.cpp
3// Purpose: Common dialogs demo
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c50f1fb9 9// Licence: wxWindows license
457814b5
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
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
329e86bf
RR
28#include "wx/colordlg.h"
29#include "wx/filedlg.h"
30#include "wx/dirdlg.h"
31#include "wx/fontdlg.h"
32#include "wx/choicdlg.h"
33#include "wx/tipdlg.h"
abceee76 34#include "wx/progdlg.h"
457814b5 35
51a58d8b
JS
36// New wxGenericDirCtrl
37#include "wx/dirctrl.h"
38
dfad0599
JS
39#define wxTEST_GENERIC_DIALOGS_IN_MSW 0
40
41#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
457814b5
JS
42#include <wx/generic/colrdlgg.h>
43#include <wx/generic/fontdlgg.h>
44#endif
45
46#include "dialogs.h"
47
48IMPLEMENT_APP(MyApp)
49
4c45f240
VZ
50BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
51 EVT_PAINT(MyCanvas::OnPaint)
52END_EVENT_TABLE()
53
54BEGIN_EVENT_TABLE(MyFrame, wxFrame)
55 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
56 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
57 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
58 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
59 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
60 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
61 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
62 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
63 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
35b45b33 64 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
4c45f240
VZ
65 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
66 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
67 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
51a58d8b 68 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
f6bcfd97 69 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
4c45f240
VZ
70 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
71 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
72#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
73 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
74 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
abceee76
VZ
75#endif
76#if wxUSE_PROGRESSDLG
77 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
4c45f240
VZ
78#endif
79 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
80
81 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyFrame::OnButton)
82END_EVENT_TABLE()
abceee76 83
f6bcfd97
BP
84BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
85 EVT_BUTTON(-1, MyModalDialog::OnButton)
86END_EVENT_TABLE()
87
abceee76
VZ
88BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
89 EVT_CLOSE(MyModelessDialog::OnClose)
90END_EVENT_TABLE()
91
c67daf87 92MyCanvas *myCanvas = (MyCanvas *) NULL;
457814b5 93
457814b5 94// `Main program' equivalent, creating windows and returning main app frame
4c45f240 95bool MyApp::OnInit()
457814b5 96{
e5ea3f7a 97#if defined(__WXGTK__) && defined(wxUSE_UNICODE)
dcf924a3 98 wxConvCurrent = &wxConvLibc;
e5ea3f7a
RR
99#endif
100
457814b5 101 m_canvasTextColour = wxColour("BLACK");
66bd6b93 102 m_canvasFont = *wxNORMAL_FONT;
457814b5
JS
103
104 // Create the main frame window
8487f887 105 MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300));
457814b5
JS
106
107 // Make a menubar
108 wxMenu *file_menu = new wxMenu;
109
110 file_menu->Append(DIALOGS_CHOOSE_COLOUR, "&Choose colour");
111
dfad0599 112#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
457814b5
JS
113 file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, "Choose colour (&generic)");
114#endif
115
116 file_menu->AppendSeparator();
117 file_menu->Append(DIALOGS_CHOOSE_FONT, "Choose &font");
118
dfad0599 119#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
457814b5
JS
120 file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, "Choose f&ont (generic)");
121
122#endif
123 file_menu->AppendSeparator();
d93c719a 124 file_menu->Append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L");
c61f4f6d
VZ
125 file_menu->Append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M");
126 file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E");
a294c6d5 127 file_menu->Append(DIALOGS_PASSWORD_ENTRY, "&Password entry\tCtrl-P");
c49245f8 128 file_menu->Append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N");
4c45f240 129 file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-C");
457814b5 130 file_menu->AppendSeparator();
c61f4f6d 131 file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T");
c50f1fb9 132 file_menu->AppendSeparator();
c61f4f6d 133 file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O");
35b45b33 134 file_menu->Append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2");
a294c6d5 135 file_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tCtrl-Q");
4c45f240 136 file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S");
c61f4f6d 137 file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D");
51a58d8b 138 file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, "&Choose a directory (generic implementation)");
abceee76
VZ
139#if wxUSE_PROGRESSDLG
140 file_menu->Append(DIALOGS_PROGRESS, "Pro&gress dialog\tCtrl-G");
141#endif // wxUSE_PROGRESSDLG
f6bcfd97
BP
142 file_menu->AppendSeparator();
143 file_menu->Append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-F");
4c45f240
VZ
144 file_menu->Append(DIALOGS_MODELESS, "Modeless &dialog\tCtrl-Z", "", TRUE);
145 file_menu->AppendSeparator();
c61f4f6d 146 file_menu->Append(wxID_EXIT, "E&xit\tAlt-X");
457814b5
JS
147 wxMenuBar *menu_bar = new wxMenuBar;
148 menu_bar->Append(file_menu, "&File");
149 frame->SetMenuBar(menu_bar);
150
151 myCanvas = new MyCanvas(frame);
152 myCanvas->SetBackgroundColour(*wxWHITE);
153
154 frame->Centre(wxBOTH);
d93c719a 155
457814b5
JS
156 // Show the frame
157 frame->Show(TRUE);
158
159 SetTopWindow(frame);
160
161 return TRUE;
162}
163
164// My frame constructor
4c45f240
VZ
165MyFrame::MyFrame(wxWindow *parent,
166 const wxString& title,
167 const wxPoint& pos,
168 const wxSize& size)
169 : wxFrame(parent, -1, title, pos, size)
170{
171 m_dialog = (MyModelessDialog *)NULL;
172}
457814b5 173
d355d3fe 174void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
457814b5 175{
f6bcfd97
BP
176 wxColourData data;
177 data.SetChooseFull(TRUE);
178 for (int i = 0; i < 16; i++)
179 {
457814b5
JS
180 wxColour colour(i*16, i*16, i*16);
181 data.SetCustomColour(i, colour);
f6bcfd97 182 }
d93c719a 183
f6bcfd97
BP
184 wxColourDialog *dialog = new wxColourDialog(this, &data);
185 dialog->SetTitle("Choose the background colour");
186 if (dialog->ShowModal() == wxID_OK)
187 {
457814b5
JS
188 wxColourData retData = dialog->GetColourData();
189 wxColour col = retData.GetColour();
457814b5
JS
190 myCanvas->SetBackgroundColour(col);
191 myCanvas->Clear();
192 myCanvas->Refresh();
f6bcfd97
BP
193 }
194 dialog->Destroy();
457814b5
JS
195}
196
d355d3fe 197void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
457814b5
JS
198{
199 wxFontData data;
200 data.SetInitialFont(wxGetApp().m_canvasFont);
201 data.SetColour(wxGetApp().m_canvasTextColour);
d93c719a 202
457814b5
JS
203 wxFontDialog *dialog = new wxFontDialog(this, &data);
204 if (dialog->ShowModal() == wxID_OK)
205 {
206 wxFontData retData = dialog->GetFontData();
207 wxGetApp().m_canvasFont = retData.GetChosenFont();
208 wxGetApp().m_canvasTextColour = retData.GetColour();
209 myCanvas->Refresh();
210 }
5919d76b 211 dialog->Destroy();
457814b5
JS
212}
213
dfad0599 214#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
d355d3fe 215void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
457814b5
JS
216{
217 wxColourData data;
218 data.SetChooseFull(TRUE);
219 for (int i = 0; i < 16; i++)
220 {
221 wxColour colour(i*16, i*16, i*16);
222 data.SetCustomColour(i, colour);
223 }
d93c719a 224
457814b5
JS
225 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data);
226 if (dialog->ShowModal() == wxID_OK)
227 {
228 wxColourData retData = dialog->GetColourData();
229 wxColour col = retData.GetColour();
230// wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
231 myCanvas->SetBackgroundColour(col);
232 myCanvas->Clear();
233 myCanvas->Refresh();
234 }
5919d76b 235 dialog->Destroy();
457814b5
JS
236}
237
d355d3fe 238void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
457814b5
JS
239{
240 wxFontData data;
241 data.SetInitialFont(wxGetApp().m_canvasFont);
242 data.SetColour(wxGetApp().m_canvasTextColour);
243
244 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data);
245 if (dialog->ShowModal() == wxID_OK)
246 {
247 wxFontData retData = dialog->GetFontData();
248 wxGetApp().m_canvasFont = retData.GetChosenFont();
249 wxGetApp().m_canvasTextColour = retData.GetColour();
250 myCanvas->Refresh();
251 }
5919d76b 252 dialog->Destroy();
457814b5 253}
d93c719a
VZ
254#endif // wxTEST_GENERIC_DIALOGS_IN_MSW
255
256void MyFrame::LogDialog(wxCommandEvent& event)
257{
2c8e4738
VZ
258 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
259 // being flushed -- test it
260 {
261 wxBusyCursor bc;
262 wxLogMessage("This is some message - everything is ok so far.");
263 wxLogMessage("Another message...\n... this one is on multiple lines");
264 wxLogWarning("And then something went wrong!");
265 }
266
d93c719a 267 wxLogError("Intermediary error handler decided to abort.");
5888ef1e
VZ
268 wxLogError("The top level caller detected an unrecoverable error.");
269
7923c649
VZ
270 wxLog::FlushActive();
271
c86423f9 272 wxLogMessage("And this is the same dialog but with only one message.");
d93c719a 273}
457814b5 274
d355d3fe 275void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
457814b5 276{
f6bcfd97 277 wxMessageDialog dialog( NULL, "This is a message box\nA long, long string to test out the message box properly",
c50f1fb9 278 "Message box text", wxYES_NO|wxCANCEL|wxICON_INFORMATION);
457814b5
JS
279
280 dialog.ShowModal();
281}
282
c49245f8
VZ
283void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
284{
e65cc56a
RR
285 long res = wxGetNumberFromUser( "This is some text, actually a lot of text.\n"
286 "Even two rows of text.",
d93c719a 287 "Enter a number:", "Numeric input test",
e65cc56a 288 50, 0, 100, this );
c49245f8
VZ
289
290 wxString msg;
291 int icon;
292 if ( res == -1 )
293 {
294 msg = "Invalid number entered or dialog cancelled.";
295 icon = wxICON_HAND;
296 }
297 else
d93c719a
VZ
298 {
299 msg.Printf(_T("You've entered %lu"), res );
c49245f8
VZ
300 icon = wxICON_INFORMATION;
301 }
302
303 wxMessageBox(msg, "Numeric test result", wxOK | icon, this);
304}
305
a294c6d5 306void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
457814b5 307{
a294c6d5 308 wxString pwd = wxGetPasswordFromUser("Enter password:",
3ca6a5f0 309 "Password entry dialog",
a294c6d5
VZ
310 "",
311 this);
312 if ( !!pwd )
313 {
314 wxMessageBox(wxString::Format("Your password is '%s'", pwd.c_str()),
315 "Got password", wxOK | wxICON_INFORMATION, this);
316 }
317}
318
319void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
320{
321 wxTextEntryDialog dialog(this,
322 "This is a small sample\n"
323 "A long, long string to test out the text entrybox",
324 "Please enter a string",
325 "Default value",
326 wxOK | wxCANCEL);
457814b5
JS
327
328 if (dialog.ShowModal() == wxID_OK)
329 {
c50f1fb9
VZ
330 wxMessageDialog dialog2(this, dialog.GetValue(), "Got string");
331 dialog2.ShowModal();
457814b5
JS
332 }
333}
334
d355d3fe 335void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
457814b5 336{
ef77f91e
JS
337 const wxString choices[] = { "One", "Two", "Three", "Four", "Five" } ;
338 int n = 5;
457814b5 339
ef77f91e
JS
340 wxSingleChoiceDialog dialog(this, "This is a small sample\nA single-choice convenience dialog",
341 "Please select a value", n, (const wxString *)choices);
457814b5 342
ef77f91e
JS
343 dialog.SetSelection(2);
344
345 if (dialog.ShowModal() == wxID_OK)
346 {
347 wxMessageDialog dialog2(this, dialog.GetStringSelection(), "Got string");
348 dialog2.ShowModal();
349 }
457814b5
JS
350}
351
d355d3fe 352void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
457814b5 353{
c50f1fb9 354 wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
457814b5 355
c50f1fb9
VZ
356 if (dialog.ShowModal() == wxID_OK)
357 {
5919d76b 358 wxString info;
13393ab6
RR
359 info.Printf(_T("Full file name: %s\n")
360 _T("Path: %s\n")
361 _T("Name: %s"),
5919d76b
VZ
362 dialog.GetPath().c_str(),
363 dialog.GetDirectory().c_str(),
364 dialog.GetFilename().c_str());
c50f1fb9
VZ
365 wxMessageDialog dialog2(this, info, "Selected file");
366 dialog2.ShowModal();
367 }
457814b5
JS
368}
369
35b45b33
VZ
370// this shows how to take advantage of specifying a default extension in the
371// call to wxFileSelector: it is remembered after each new call and the next
372// one will use it by default
373void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
374{
375 static wxString s_extDef;
376 wxString path = wxFileSelector(
377 _T("Select the file to load"),
378 _T(""), _T(""),
379 s_extDef,
380 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
381 0,
382 this
383 );
384
385 if ( !path )
386 return;
387
388 // it is just a sample, would use wxSplitPath in real program
389 s_extDef = path.AfterLast(_T('.'));
390
391 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
392 path, s_extDef);
393}
394
c61f4f6d
VZ
395void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
396{
397 wxFileDialog dialog(this, "Testing open multiple file dialog",
470caaf9
VZ
398 "", "", wxFileSelectorDefaultWildcardStr,
399 wxMULTIPLE);
c61f4f6d
VZ
400
401 if (dialog.ShowModal() == wxID_OK)
402 {
403 wxArrayString paths, filenames;
404
405 dialog.GetPaths(paths);
406 dialog.GetFilenames(filenames);
407
408 wxString msg, s;
409 size_t count = paths.GetCount();
410 for ( size_t n = 0; n < count; n++ )
411 {
412 s.Printf(_T("File %d: %s (%s)\n"),
413 n, paths[n].c_str(), filenames[n].c_str());
414
415 msg += s;
416 }
417
418 wxMessageDialog dialog2(this, msg, "Selected files");
419 dialog2.ShowModal();
420 }
421}
422
d355d3fe 423void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
457814b5 424{
ed58dbea 425 wxFileDialog dialog(this, "Testing save file dialog", "", "myletter.txt",
c50f1fb9
VZ
426 "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
427 wxSAVE|wxOVERWRITE_PROMPT);
428
429 if (dialog.ShowModal() == wxID_OK)
430 {
431 wxChar buf[400];
432 wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex());
433 wxMessageDialog dialog2(this, wxString(buf), "Selected path");
434 dialog2.ShowModal();
435 }
457814b5
JS
436}
437
d355d3fe 438void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
457814b5 439{
3f2711d5
VZ
440 // pass some initial dir to wxDirDialog
441 wxString dirHome;
442 wxGetHomeDir(&dirHome);
443
444 wxDirDialog dialog(this, "Testing directory picker", dirHome);
c50f1fb9
VZ
445
446 if (dialog.ShowModal() == wxID_OK)
447 {
448 wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
449 dialog2.ShowModal();
450 }
451}
452
51a58d8b
JS
453void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
454{
455 // pass some initial dir to wxDirDialog
456 wxString dirHome;
457 wxGetHomeDir(&dirHome);
458
459 wxGenericDirDialog dialog(this, "Testing generic directory picker", dirHome);
460
461 if (dialog.ShowModal() == wxID_OK)
462 {
463 wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
464 dialog2.ShowModal();
465 }
466}
467
f6bcfd97
BP
468void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
469{
470 MyModalDialog dlg(this);
471 dlg.ShowModal();
472}
473
4c45f240
VZ
474void MyFrame::ModelessDlg(wxCommandEvent& event)
475{
2f82899b 476 bool show = GetMenuBar()->IsChecked(event.GetId());
4c45f240
VZ
477
478 if ( show )
479 {
480 if ( !m_dialog )
481 {
482 m_dialog = new MyModelessDialog(this);
483 }
484
485 m_dialog->Show(TRUE);
486 }
487 else // hide
488 {
489 m_dialog->Hide();
490 }
491}
492
493void MyFrame::OnButton(wxCommandEvent& WXUNUSED(event))
494{
495 wxMessageBox("Button pressed in modeless dialog", "Info",
496 wxOK | wxICON_INFORMATION, this);
497}
498
c50f1fb9
VZ
499void MyFrame::ShowTip(wxCommandEvent& event)
500{
78bd7ed3 501#if wxUSE_STARTUP_TIPS
c50f1fb9
VZ
502 static size_t s_index = (size_t)-1;
503
504 if ( s_index == (size_t)-1 )
505 {
506 srand(time(NULL));
507
508 // this is completely bogus, we don't know how many lines are there
509 // in the file, but who cares, it's a demo only...
510 s_index = rand() % 5;
511 }
512
513 wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", s_index);
514
515 bool showAtStartup = wxShowTip(this, tipProvider);
516
517 if ( showAtStartup )
518 {
519 wxMessageBox("Will show tips on startup", "Tips dialog",
520 wxOK | wxICON_INFORMATION, this);
521 }
457814b5 522
c50f1fb9
VZ
523 s_index = tipProvider->GetCurrentTip();
524 delete tipProvider;
78bd7ed3 525#endif
457814b5
JS
526}
527
d355d3fe 528void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
457814b5 529{
c50f1fb9 530 Close(TRUE);
457814b5
JS
531}
532
abceee76
VZ
533#if wxUSE_PROGRESSDLG
534
535void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
536{
537 static const int max = 10;
538
539 wxProgressDialog dialog("Progress dialog example",
540 "An informative message",
541 max, // range
542 this, // parent
543 wxPD_CAN_ABORT |
544 wxPD_APP_MODAL |
545 wxPD_ELAPSED_TIME |
546 wxPD_ESTIMATED_TIME |
547 wxPD_REMAINING_TIME);
548
549 bool cont = TRUE;
550 for ( int i = 0; i <= max && cont; i++ )
551 {
552 wxSleep(1);
553 if ( i == max )
554 {
555 cont = dialog.Update(i, "That's all, folks!");
556 }
557 else if ( i == max / 2 )
558 {
559 cont = dialog.Update(i, "Only a half left (very long message)!");
560 }
561 else
562 {
563 cont = dialog.Update(i);
564 }
565 }
566
567 if ( !cont )
568 {
569 wxLogStatus("Progress dialog aborted!");
570 }
571 else
572 {
573 wxLogStatus("Countdown from %d finished", max);
574 }
575}
576
577#endif // wxUSE_PROGRESSDLG
578
579// ----------------------------------------------------------------------------
580// MyCanvas
581// ----------------------------------------------------------------------------
582
d355d3fe 583void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
457814b5 584{
c50f1fb9 585 wxPaintDC dc(this);
457814b5
JS
586 dc.SetFont(wxGetApp().m_canvasFont);
587 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
588 dc.SetBackgroundMode(wxTRANSPARENT);
589 dc.DrawText("wxWindows common dialogs test application", 10, 10);
590}
591
4c45f240
VZ
592// ----------------------------------------------------------------------------
593// MyModelessDialog
594// ----------------------------------------------------------------------------
457814b5 595
4c45f240
VZ
596MyModelessDialog::MyModelessDialog(wxWindow *parent)
597 : wxDialog(parent, -1, wxString("Modeless dialog"))
598{
cbc66a27
VZ
599 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
600
601 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me");
602 wxCheckBox *check = new wxCheckBox(this, -1, "Should be disabled");
603 check->Disable();
604
605 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
606 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
607
608 SetAutoLayout(TRUE);
609 SetSizer(sizerTop);
610
611 sizerTop->SetSizeHints(this);
612 sizerTop->Fit(this);
4c45f240 613}
abceee76
VZ
614
615void MyModelessDialog::OnClose(wxCloseEvent& event)
616{
617 if ( event.CanVeto() )
618 {
619 wxMessageBox("Use the menu item to close this dialog",
620 "Modeless dialog",
621 wxOK | wxICON_INFORMATION, this);
622
623 event.Veto();
624 }
625}
626
f6bcfd97
BP
627// ----------------------------------------------------------------------------
628// MyModalDialog
629// ----------------------------------------------------------------------------
630
631MyModalDialog::MyModalDialog(wxWindow *parent)
632 : wxDialog(parent, -1, wxString("Modal dialog"))
633{
634 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
635
636 m_btnFocused = new wxButton(this, -1, "Default button");
637 m_btnDelete = new wxButton(this, -1, "&Delete button");
638 sizerTop->Add(m_btnFocused, 0, wxALIGN_CENTER | wxALL, 5);
639 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
640
641 SetAutoLayout(TRUE);
642 SetSizer(sizerTop);
643
644 sizerTop->SetSizeHints(this);
645 sizerTop->Fit(this);
646
647 m_btnFocused->SetFocus();
648 m_btnFocused->SetDefault();
649}
650
651void MyModalDialog::OnButton(wxCommandEvent& event)
652{
653 if ( event.GetEventObject() == m_btnDelete )
654 {
655 delete m_btnFocused;
656 m_btnFocused = NULL;
657
658 m_btnDelete->Disable();
659 }
660 else if ( event.GetEventObject() == m_btnFocused )
661 {
662 wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog",
663 "", this);
664 }
665 else
666 {
667 event.Skip();
668 }
669}