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