1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
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 #include "wx/fdrepdlg.h"
36 #include "wx/busyinfo.h"
38 #define wxTEST_GENERIC_DIALOGS_IN_MSW 0
40 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
41 #include "wx/generic/colrdlgg.h"
42 #include "wx/generic/fontdlgg.h"
45 #define wxUSE_DIRDLGG 0
47 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
48 #include "wx/generic/dirdlgg.h"
55 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
56 EVT_PAINT(MyCanvas::OnPaint
)
59 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
60 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
61 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
62 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
63 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
64 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
65 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
66 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
67 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
68 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
69 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
70 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
71 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
72 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
73 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
74 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
75 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
76 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
77 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
78 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
79 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
80 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
84 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
85 #endif // wxUSE_PROGRESSDLG
88 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
89 #endif // wxUSE_BUSYINFO
92 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
93 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
95 EVT_FIND(-1, MyFrame::OnFindDialog
)
96 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
)
97 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
)
98 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
)
99 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
)
100 #endif // wxUSE_FINDREPLDLG
101 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
104 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
105 EVT_BUTTON(-1, MyModalDialog::OnButton
)
108 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
109 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
111 EVT_CLOSE(MyModelessDialog::OnClose
)
114 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
116 // `Main program' equivalent, creating windows and returning main app frame
119 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
120 wxConvCurrent
= &wxConvLibc
;
123 m_canvasTextColour
= wxColour("BLACK");
124 m_canvasFont
= *wxNORMAL_FONT
;
126 // Create the main frame window
127 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300));
130 wxMenu
*file_menu
= new wxMenu
;
132 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, "&Choose colour");
134 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
135 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, "Choose colour (&generic)");
138 file_menu
->AppendSeparator();
139 file_menu
->Append(DIALOGS_CHOOSE_FONT
, "Choose &font");
141 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
142 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, "Choose f&ont (generic)");
145 file_menu
->AppendSeparator();
146 file_menu
->Append(DIALOGS_LOG_DIALOG
, "&Log dialog\tCtrl-L");
147 file_menu
->Append(DIALOGS_MESSAGE_BOX
, "&Message box\tCtrl-M");
148 file_menu
->Append(DIALOGS_TEXT_ENTRY
, "Text &entry\tCtrl-E");
149 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, "&Password entry\tCtrl-P");
150 file_menu
->Append(DIALOGS_NUM_ENTRY
, "&Numeric entry\tCtrl-N");
151 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, "&Single choice\tCtrl-C");
152 file_menu
->Append(DIALOGS_MULTI_CHOICE
, "M&ultiple choice\tCtrl-U");
153 file_menu
->AppendSeparator();
154 file_menu
->Append(DIALOGS_TIP
, "&Tip of the day\tCtrl-T");
155 file_menu
->AppendSeparator();
156 file_menu
->Append(DIALOGS_FILE_OPEN
, "&Open file\tCtrl-O");
157 file_menu
->Append(DIALOGS_FILE_OPEN2
, "&Second open file\tCtrl-2");
158 file_menu
->Append(DIALOGS_FILES_OPEN
, "Open &files\tCtrl-Q");
159 file_menu
->Append(DIALOGS_FILE_SAVE
, "Sa&ve file\tCtrl-S");
160 file_menu
->Append(DIALOGS_DIR_CHOOSE
, "&Choose a directory\tCtrl-D");
161 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, "&Choose a directory (generic implementation)");
162 #if wxUSE_PROGRESSDLG
163 file_menu
->Append(DIALOGS_PROGRESS
, "Pro&gress dialog\tCtrl-G");
164 #endif // wxUSE_PROGRESSDLG
166 file_menu
->Append(DIALOGS_BUSYINFO
, "&Busy info dialog\tCtrl-B");
167 #endif // wxUSE_BUSYINFO
168 #if wxUSE_FINDREPLDLG
169 file_menu
->Append(DIALOGS_FIND
, "&Find dialog\tCtrl-F", "", TRUE
);
170 file_menu
->Append(DIALOGS_REPLACE
, "Find and &replace dialog\tShift-Ctrl-F", "", TRUE
);
171 #endif // wxUSE_FINDREPLDLG
172 file_menu
->AppendSeparator();
173 file_menu
->Append(DIALOGS_MODAL
, "Mo&dal dialog\tCtrl-W");
174 file_menu
->Append(DIALOGS_MODELESS
, "Modeless &dialog\tCtrl-Z", "", TRUE
);
175 file_menu
->AppendSeparator();
176 file_menu
->Append(wxID_EXIT
, "E&xit\tAlt-X");
177 wxMenuBar
*menu_bar
= new wxMenuBar
;
178 menu_bar
->Append(file_menu
, "&File");
179 frame
->SetMenuBar(menu_bar
);
181 myCanvas
= new MyCanvas(frame
);
182 myCanvas
->SetBackgroundColour(*wxWHITE
);
184 frame
->Centre(wxBOTH
);
194 // My frame constructor
195 MyFrame::MyFrame(wxWindow
*parent
,
196 const wxString
& title
,
199 : wxFrame(parent
, -1, title
, pos
, size
)
201 m_dialog
= (MyModelessDialog
*)NULL
;
203 #if wxUSE_FINDREPLDLG
211 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
213 wxColour col
= myCanvas
->GetBackgroundColour();
217 data
.SetChooseFull(TRUE
);
218 for (int i
= 0; i
< 16; i
++)
220 wxColour
colour(i
*16, i
*16, i
*16);
221 data
.SetCustomColour(i
, colour
);
224 wxColourDialog
dialog(this, &data
);
225 dialog
.SetTitle("Choose the background colour");
226 if (dialog
.ShowModal() == wxID_OK
)
228 wxColourData retData
= dialog
.GetColourData();
229 col
= retData
.GetColour();
230 myCanvas
->SetBackgroundColour(col
);
236 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
239 data
.SetInitialFont(wxGetApp().m_canvasFont
);
240 data
.SetColour(wxGetApp().m_canvasTextColour
);
242 wxFontDialog
*dialog
= new wxFontDialog(this, &data
);
243 if (dialog
->ShowModal() == wxID_OK
)
245 wxFontData retData
= dialog
->GetFontData();
246 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
247 wxGetApp().m_canvasTextColour
= retData
.GetColour();
253 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
254 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
257 data
.SetChooseFull(TRUE
);
258 for (int i
= 0; i
< 16; i
++)
260 wxColour
colour(i
*16, i
*16, i
*16);
261 data
.SetCustomColour(i
, colour
);
264 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
265 if (dialog
->ShowModal() == wxID_OK
)
267 wxColourData retData
= dialog
->GetColourData();
268 wxColour col
= retData
.GetColour();
269 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
270 myCanvas
->SetBackgroundColour(col
);
277 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
280 data
.SetInitialFont(wxGetApp().m_canvasFont
);
281 data
.SetColour(wxGetApp().m_canvasTextColour
);
283 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
284 if (dialog
->ShowModal() == wxID_OK
)
286 wxFontData retData
= dialog
->GetFontData();
287 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
288 wxGetApp().m_canvasTextColour
= retData
.GetColour();
293 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
295 void MyFrame::LogDialog(wxCommandEvent
& event
)
297 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
298 // being flushed -- test it
301 wxLogMessage(wxT("This is some message - everything is ok so far."));
302 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
303 wxLogWarning(wxT("And then something went wrong!"));
305 // and if ~wxBusyCursor doesn't do it, then call it manually
309 wxLogError(wxT("Intermediary error handler decided to abort."));
310 wxLogError(wxT("The top level caller detected an unrecoverable error."));
312 wxLog::FlushActive();
314 wxLogMessage(wxT("And this is the same dialog but with only one message."));
317 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
319 wxMessageDialog
dialog( NULL
, "This is a message box\nA long, long string to test out the message box properly",
320 "Message box text", wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
325 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
327 long res
= wxGetNumberFromUser( "This is some text, actually a lot of text.\n"
328 "Even two rows of text.",
329 "Enter a number:", "Numeric input test",
336 msg
= "Invalid number entered or dialog cancelled.";
341 msg
.Printf(_T("You've entered %lu"), res
);
342 icon
= wxICON_INFORMATION
;
345 wxMessageBox(msg
, "Numeric test result", wxOK
| icon
, this);
348 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
350 wxString pwd
= wxGetPasswordFromUser("Enter password:",
351 "Password entry dialog",
356 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
357 "Got password", wxOK
| wxICON_INFORMATION
, this);
361 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
363 wxTextEntryDialog
dialog(this,
364 "This is a small sample\n"
365 "A long, long string to test out the text entrybox",
366 "Please enter a string",
370 if (dialog
.ShowModal() == wxID_OK
)
372 wxMessageDialog
dialog2(this, dialog
.GetValue(), "Got string");
377 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
379 const wxString choices
[] = { "One", "Two", "Three", "Four", "Five" } ;
381 wxSingleChoiceDialog
dialog(this,
382 "This is a small sample\n"
383 "A single-choice convenience dialog",
384 "Please select a value",
385 WXSIZEOF(choices
), choices
);
387 dialog
.SetSelection(2);
389 if (dialog
.ShowModal() == wxID_OK
)
391 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), "Got string");
396 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
398 const wxString choices
[] =
400 "One", "Two", "Three", "Four", "Five",
401 "Six", "Seven", "Eight", "Nine", "Ten",
402 "Eleven", "Twelve", "Seventeen",
405 wxArrayInt selections
;
406 size_t count
= wxGetMultipleChoices(selections
,
407 "This is a small sample\n"
408 "A multi-choice convenience dialog",
409 "Please select a value",
410 WXSIZEOF(choices
), choices
,
415 msg
.Printf(wxT("You selected %u items:\n"), count
);
416 for ( size_t n
= 0; n
< count
; n
++ )
418 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"), n
, selections
[n
],
419 choices
[selections
[n
]].c_str());
423 //else: cancelled or nothing selected
426 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
431 _T("Testing open file dialog"),
434 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
437 if (dialog
.ShowModal() == wxID_OK
)
440 info
.Printf(_T("Full file name: %s\n")
443 dialog
.GetPath().c_str(),
444 dialog
.GetDirectory().c_str(),
445 dialog
.GetFilename().c_str());
446 wxMessageDialog
dialog2(this, info
, "Selected file");
451 // this shows how to take advantage of specifying a default extension in the
452 // call to wxFileSelector: it is remembered after each new call and the next
453 // one will use it by default
454 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
456 static wxString s_extDef
;
457 wxString path
= wxFileSelector(
458 _T("Select the file to load"),
461 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
469 // it is just a sample, would use wxSplitPath in real program
470 s_extDef
= path
.AfterLast(_T('.'));
472 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
473 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
476 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
478 wxFileDialog
dialog(this, "Testing open multiple file dialog",
479 "", "", wxFileSelectorDefaultWildcardStr
,
482 if (dialog
.ShowModal() == wxID_OK
)
484 wxArrayString paths
, filenames
;
486 dialog
.GetPaths(paths
);
487 dialog
.GetFilenames(filenames
);
490 size_t count
= paths
.GetCount();
491 for ( size_t n
= 0; n
< count
; n
++ )
493 s
.Printf(_T("File %d: %s (%s)\n"),
494 n
, paths
[n
].c_str(), filenames
[n
].c_str());
499 wxMessageDialog
dialog2(this, msg
, "Selected files");
504 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
506 wxFileDialog
dialog(this, "Testing save file dialog", "", "myletter.txt",
507 "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
508 wxSAVE
|wxOVERWRITE_PROMPT
);
510 if (dialog
.ShowModal() == wxID_OK
)
513 wxSprintf(buf
, _T("%s, filter %d"), (const wxChar
*)dialog
.GetPath(), dialog
.GetFilterIndex());
514 wxMessageDialog
dialog2(this, wxString(buf
), "Selected path");
519 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
521 // pass some initial dir to wxDirDialog
523 wxGetHomeDir(&dirHome
);
525 wxDirDialog
dialog(this, "Testing directory picker", dirHome
);
527 if (dialog
.ShowModal() == wxID_OK
)
529 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
534 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
536 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
537 // pass some initial dir to wxDirDialog
539 wxGetHomeDir(&dirHome
);
541 wxGenericDirDialog
dialog(this, "Testing generic directory picker", dirHome
);
543 if (dialog
.ShowModal() == wxID_OK
)
545 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
549 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
550 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
554 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
556 MyModalDialog
dlg(this);
560 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
562 bool show
= GetMenuBar()->IsChecked(event
.GetId());
568 m_dialog
= new MyModelessDialog(this);
571 m_dialog
->Show(TRUE
);
579 void MyFrame::ShowTip(wxCommandEvent
& event
)
581 #if wxUSE_STARTUP_TIPS
582 static size_t s_index
= (size_t)-1;
584 if ( s_index
== (size_t)-1 )
588 // this is completely bogus, we don't know how many lines are there
589 // in the file, but who cares, it's a demo only...
590 s_index
= rand() % 5;
593 wxTipProvider
*tipProvider
= wxCreateFileTipProvider("tips.txt", s_index
);
595 bool showAtStartup
= wxShowTip(this, tipProvider
);
599 wxMessageBox("Will show tips on startup", "Tips dialog",
600 wxOK
| wxICON_INFORMATION
, this);
603 s_index
= tipProvider
->GetCurrentTip();
608 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
613 #if wxUSE_PROGRESSDLG
615 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
617 static const int max
= 10;
619 wxProgressDialog
dialog("Progress dialog example",
620 "An informative message",
626 wxPD_ESTIMATED_TIME
|
627 wxPD_REMAINING_TIME
);
630 for ( int i
= 0; i
<= max
&& cont
; i
++ )
635 cont
= dialog
.Update(i
, "That's all, folks!");
637 else if ( i
== max
/ 2 )
639 cont
= dialog
.Update(i
, "Only a half left (very long message)!");
643 cont
= dialog
.Update(i
);
649 wxLogStatus(wxT("Progress dialog aborted!"));
653 wxLogStatus(wxT("Countdown from %d finished"), max
);
657 #endif // wxUSE_PROGRESSDLG
661 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
663 wxWindowDisabler disableAll
;
665 wxBusyInfo
info("Working, please wait...", this);
667 for ( int i
= 0; i
< 30; i
++ )
674 #endif // wxUSE_BUSYINFO
676 #if wxUSE_FINDREPLDLG
678 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
687 m_dlgReplace
= new wxFindReplaceDialog
691 "Find and replace dialog",
695 m_dlgReplace
->Show(TRUE
);
699 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
708 m_dlgFind
= new wxFindReplaceDialog
717 m_dlgFind
->Show(TRUE
);
721 static wxString
DecodeFindDialogEventFlags(int flags
)
724 str
<< (flags
& wxFR_DOWN
? "down" : "up") << ", "
725 << (flags
& wxFR_WHOLEWORD
? "whole words only, " : "")
726 << (flags
& wxFR_MATCHCASE
? "" : "not ")
732 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
734 wxEventType type
= event
.GetEventType();
736 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
738 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
739 type
== wxEVT_COMMAND_FIND_NEXT
? "next " : "",
740 event
.GetFindString().c_str(),
741 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
743 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
744 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
746 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
747 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? "all " : "",
748 event
.GetFindString().c_str(),
749 event
.GetReplaceString().c_str(),
750 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
752 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
754 wxFindReplaceDialog
*dlg
= event
.GetDialog();
757 if ( dlg
== m_dlgFind
)
762 else if ( dlg
== m_dlgReplace
)
771 wxFAIL_MSG( _T("unexecpted event") );
774 wxLogMessage(wxT("%s dialog is being closed."), txt
),
780 wxLogError(wxT("Unknown find dialog event!"));
784 #endif // wxUSE_FINDREPLDLG
786 // ----------------------------------------------------------------------------
788 // ----------------------------------------------------------------------------
790 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
793 dc
.SetFont(wxGetApp().m_canvasFont
);
794 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
795 dc
.SetBackgroundMode(wxTRANSPARENT
);
796 dc
.DrawText("wxWindows common dialogs test application", 10, 10);
799 // ----------------------------------------------------------------------------
801 // ----------------------------------------------------------------------------
803 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
804 : wxDialog(parent
, -1, wxString("Modeless dialog"))
806 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
808 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, "Press me");
809 wxCheckBox
*check
= new wxCheckBox(this, -1, "Should be disabled");
812 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
813 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
818 sizerTop
->SetSizeHints(this);
822 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
824 wxMessageBox("Button pressed in modeless dialog", "Info",
825 wxOK
| wxICON_INFORMATION
, this);
828 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
830 if ( event
.CanVeto() )
832 wxMessageBox("Use the menu item to close this dialog",
834 wxOK
| wxICON_INFORMATION
, this);
840 // ----------------------------------------------------------------------------
842 // ----------------------------------------------------------------------------
844 MyModalDialog::MyModalDialog(wxWindow
*parent
)
845 : wxDialog(parent
, -1, wxString("Modal dialog"))
847 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
849 m_btnFocused
= new wxButton(this, -1, "Default button");
850 m_btnDelete
= new wxButton(this, -1, "&Delete button");
851 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, "&Close");
852 sizerTop
->Add(m_btnFocused
, 0, wxALIGN_CENTER
| wxALL
, 5);
853 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
854 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
859 sizerTop
->SetSizeHints(this);
862 m_btnFocused
->SetFocus();
863 m_btnFocused
->SetDefault();
866 void MyModalDialog::OnButton(wxCommandEvent
& event
)
868 if ( event
.GetEventObject() == m_btnDelete
)
873 m_btnDelete
->Disable();
875 else if ( event
.GetEventObject() == m_btnFocused
)
877 wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog",