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 #if defined(__WXMSW__) || defined(__WXMAC__)
75 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
76 #endif // wxMSW || wxMAC
77 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
78 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
79 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
80 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
81 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
82 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
86 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
87 #endif // wxUSE_PROGRESSDLG
90 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
91 #endif // wxUSE_BUSYINFO
94 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
95 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
97 EVT_FIND(-1, MyFrame::OnFindDialog
)
98 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
)
99 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
)
100 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
)
101 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
)
102 #endif // wxUSE_FINDREPLDLG
103 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
106 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
107 EVT_BUTTON(-1, MyModalDialog::OnButton
)
110 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
111 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
113 EVT_CLOSE(MyModelessDialog::OnClose
)
116 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
118 // `Main program' equivalent, creating windows and returning main app frame
121 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
122 wxConvCurrent
= &wxConvLibc
;
125 m_canvasTextColour
= wxColour("BLACK");
126 m_canvasFont
= *wxNORMAL_FONT
;
128 // Create the main frame window
129 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, (char *) "wxWindows dialogs example", wxPoint(20, 20), wxSize(400, 300));
132 wxMenu
*file_menu
= new wxMenu
;
134 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, "&Choose colour");
136 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
137 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, "Choose colour (&generic)");
140 file_menu
->AppendSeparator();
141 file_menu
->Append(DIALOGS_CHOOSE_FONT
, "Choose &font");
143 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
144 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, "Choose f&ont (generic)");
147 file_menu
->AppendSeparator();
148 file_menu
->Append(DIALOGS_LOG_DIALOG
, "&Log dialog\tCtrl-L");
149 file_menu
->Append(DIALOGS_MESSAGE_BOX
, "&Message box\tCtrl-M");
150 file_menu
->Append(DIALOGS_TEXT_ENTRY
, "Text &entry\tCtrl-E");
151 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, "&Password entry\tCtrl-P");
152 file_menu
->Append(DIALOGS_NUM_ENTRY
, "&Numeric entry\tCtrl-N");
153 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, "&Single choice\tCtrl-C");
154 file_menu
->Append(DIALOGS_MULTI_CHOICE
, "M&ultiple choice\tCtrl-U");
155 file_menu
->AppendSeparator();
156 file_menu
->Append(DIALOGS_TIP
, "&Tip of the day\tCtrl-T");
157 file_menu
->AppendSeparator();
158 file_menu
->Append(DIALOGS_FILE_OPEN
, "&Open file\tCtrl-O");
159 file_menu
->Append(DIALOGS_FILE_OPEN2
, "&Second open file\tCtrl-2");
160 file_menu
->Append(DIALOGS_FILES_OPEN
, "Open &files\tCtrl-Q");
161 file_menu
->Append(DIALOGS_FILE_SAVE
, "Sa&ve file\tCtrl-S");
162 file_menu
->Append(DIALOGS_DIR_CHOOSE
, "&Choose a directory\tCtrl-D");
163 #if defined(__WXMSW__) || defined(__WXMAC__)
164 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, "&Choose a directory (generic implementation)");
165 #endif // wxMSW || wxMAC
166 #if wxUSE_PROGRESSDLG
167 file_menu
->Append(DIALOGS_PROGRESS
, "Pro&gress dialog\tCtrl-G");
168 #endif // wxUSE_PROGRESSDLG
170 file_menu
->Append(DIALOGS_BUSYINFO
, "&Busy info dialog\tCtrl-B");
171 #endif // wxUSE_BUSYINFO
172 #if wxUSE_FINDREPLDLG
173 file_menu
->Append(DIALOGS_FIND
, "&Find dialog\tCtrl-F", "", TRUE
);
174 file_menu
->Append(DIALOGS_REPLACE
, "Find and &replace dialog\tShift-Ctrl-F", "", TRUE
);
175 #endif // wxUSE_FINDREPLDLG
176 file_menu
->AppendSeparator();
177 file_menu
->Append(DIALOGS_MODAL
, "Mo&dal dialog\tCtrl-W");
178 file_menu
->Append(DIALOGS_MODELESS
, "Modeless &dialog\tCtrl-Z", "", TRUE
);
179 file_menu
->AppendSeparator();
180 file_menu
->Append(wxID_EXIT
, "E&xit\tAlt-X");
181 wxMenuBar
*menu_bar
= new wxMenuBar
;
182 menu_bar
->Append(file_menu
, "&File");
183 frame
->SetMenuBar(menu_bar
);
185 myCanvas
= new MyCanvas(frame
);
186 myCanvas
->SetBackgroundColour(*wxWHITE
);
188 frame
->Centre(wxBOTH
);
198 // My frame constructor
199 MyFrame::MyFrame(wxWindow
*parent
,
200 const wxString
& title
,
203 : wxFrame(parent
, -1, title
, pos
, size
)
205 m_dialog
= (MyModelessDialog
*)NULL
;
207 #if wxUSE_FINDREPLDLG
215 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
217 wxColour col
= myCanvas
->GetBackgroundColour();
221 data
.SetChooseFull(TRUE
);
222 for (int i
= 0; i
< 16; i
++)
224 wxColour
colour(i
*16, i
*16, i
*16);
225 data
.SetCustomColour(i
, colour
);
228 wxColourDialog
dialog(this, &data
);
229 dialog
.SetTitle("Choose the background colour");
230 if (dialog
.ShowModal() == wxID_OK
)
232 wxColourData retData
= dialog
.GetColourData();
233 col
= retData
.GetColour();
234 myCanvas
->SetBackgroundColour(col
);
240 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
243 data
.SetInitialFont(wxGetApp().m_canvasFont
);
244 data
.SetColour(wxGetApp().m_canvasTextColour
);
246 wxFontDialog
*dialog
= new wxFontDialog(this, &data
);
247 if (dialog
->ShowModal() == wxID_OK
)
249 wxFontData retData
= dialog
->GetFontData();
250 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
251 wxGetApp().m_canvasTextColour
= retData
.GetColour();
257 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
258 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
261 data
.SetChooseFull(TRUE
);
262 for (int i
= 0; i
< 16; i
++)
264 wxColour
colour(i
*16, i
*16, i
*16);
265 data
.SetCustomColour(i
, colour
);
268 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
269 if (dialog
->ShowModal() == wxID_OK
)
271 wxColourData retData
= dialog
->GetColourData();
272 wxColour col
= retData
.GetColour();
273 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
274 myCanvas
->SetBackgroundColour(col
);
281 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
284 data
.SetInitialFont(wxGetApp().m_canvasFont
);
285 data
.SetColour(wxGetApp().m_canvasTextColour
);
287 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
288 if (dialog
->ShowModal() == wxID_OK
)
290 wxFontData retData
= dialog
->GetFontData();
291 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
292 wxGetApp().m_canvasTextColour
= retData
.GetColour();
297 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
299 void MyFrame::LogDialog(wxCommandEvent
& event
)
301 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
302 // being flushed -- test it
305 wxLogMessage(wxT("This is some message - everything is ok so far."));
306 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
307 wxLogWarning(wxT("And then something went wrong!"));
309 // and if ~wxBusyCursor doesn't do it, then call it manually
313 wxLogError(wxT("Intermediary error handler decided to abort."));
314 wxLogError(wxT("The top level caller detected an unrecoverable error."));
316 wxLog::FlushActive();
318 wxLogMessage(wxT("And this is the same dialog but with only one message."));
321 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
323 wxMessageDialog
dialog( NULL
, "This is a message box\nA long, long string to test out the message box properly",
324 "Message box text", wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
326 switch ( dialog
.ShowModal() )
329 wxLogStatus("You pressed \"Yes\"");
333 wxLogStatus("You pressed \"No\"");
337 wxLogStatus("You pressed \"Cancel\"");
341 wxLogError("Unexpected wxMessageDialog return code!");
345 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
347 long res
= wxGetNumberFromUser( "This is some text, actually a lot of text.\n"
348 "Even two rows of text.",
349 "Enter a number:", "Numeric input test",
356 msg
= "Invalid number entered or dialog cancelled.";
361 msg
.Printf(_T("You've entered %lu"), res
);
362 icon
= wxICON_INFORMATION
;
365 wxMessageBox(msg
, "Numeric test result", wxOK
| icon
, this);
368 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
370 wxString pwd
= wxGetPasswordFromUser("Enter password:",
371 "Password entry dialog",
376 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
377 "Got password", wxOK
| wxICON_INFORMATION
, this);
381 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
383 wxTextEntryDialog
dialog(this,
384 "This is a small sample\n"
385 "A long, long string to test out the text entrybox",
386 "Please enter a string",
390 if (dialog
.ShowModal() == wxID_OK
)
392 wxMessageDialog
dialog2(this, dialog
.GetValue(), "Got string");
397 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
399 const wxString choices
[] = { "One", "Two", "Three", "Four", "Five" } ;
401 wxSingleChoiceDialog
dialog(this,
402 "This is a small sample\n"
403 "A single-choice convenience dialog",
404 "Please select a value",
405 WXSIZEOF(choices
), choices
);
407 dialog
.SetSelection(2);
409 if (dialog
.ShowModal() == wxID_OK
)
411 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), "Got string");
416 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
418 const wxString choices
[] =
420 "One", "Two", "Three", "Four", "Five",
421 "Six", "Seven", "Eight", "Nine", "Ten",
422 "Eleven", "Twelve", "Seventeen",
425 wxArrayInt selections
;
426 size_t count
= wxGetMultipleChoices(selections
,
427 "This is a small sample\n"
428 "A multi-choice convenience dialog",
429 "Please select a value",
430 WXSIZEOF(choices
), choices
,
435 msg
.Printf(wxT("You selected %u items:\n"), count
);
436 for ( size_t n
= 0; n
< count
; n
++ )
438 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"), n
, selections
[n
],
439 choices
[selections
[n
]].c_str());
443 //else: cancelled or nothing selected
446 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
451 _T("Testing open file dialog"),
454 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
457 if (dialog
.ShowModal() == wxID_OK
)
460 info
.Printf(_T("Full file name: %s\n")
463 dialog
.GetPath().c_str(),
464 dialog
.GetDirectory().c_str(),
465 dialog
.GetFilename().c_str());
466 wxMessageDialog
dialog2(this, info
, "Selected file");
471 // this shows how to take advantage of specifying a default extension in the
472 // call to wxFileSelector: it is remembered after each new call and the next
473 // one will use it by default
474 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
476 static wxString s_extDef
;
477 wxString path
= wxFileSelector(
478 _T("Select the file to load"),
481 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
489 // it is just a sample, would use wxSplitPath in real program
490 s_extDef
= path
.AfterLast(_T('.'));
492 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
493 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
496 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
498 wxFileDialog
dialog(this, "Testing open multiple file dialog",
499 "", "", wxFileSelectorDefaultWildcardStr
,
502 if (dialog
.ShowModal() == wxID_OK
)
504 wxArrayString paths
, filenames
;
506 dialog
.GetPaths(paths
);
507 dialog
.GetFilenames(filenames
);
510 size_t count
= paths
.GetCount();
511 for ( size_t n
= 0; n
< count
; n
++ )
513 s
.Printf(_T("File %d: %s (%s)\n"),
514 n
, paths
[n
].c_str(), filenames
[n
].c_str());
519 wxMessageDialog
dialog2(this, msg
, "Selected files");
524 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
526 wxFileDialog
dialog(this, "Testing save file dialog", "", "myletter.txt",
527 "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
528 wxSAVE
|wxOVERWRITE_PROMPT
);
530 if (dialog
.ShowModal() == wxID_OK
)
533 wxSprintf(buf
, _T("%s, filter %d"), (const wxChar
*)dialog
.GetPath(), dialog
.GetFilterIndex());
534 wxMessageDialog
dialog2(this, wxString(buf
), "Selected path");
539 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
541 // pass some initial dir to wxDirDialog
543 wxGetHomeDir(&dirHome
);
545 wxDirDialog
dialog(this, "Testing directory picker", dirHome
);
547 if (dialog
.ShowModal() == wxID_OK
)
549 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
554 #if defined(__WXMSW__) || defined(__WXMAC__)
556 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
558 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
559 // pass some initial dir to wxDirDialog
561 wxGetHomeDir(&dirHome
);
563 wxGenericDirDialog
dialog(this, "Testing generic directory picker", dirHome
);
565 if (dialog
.ShowModal() == wxID_OK
)
567 wxMessageDialog
dialog2(this, dialog
.GetPath(), "Selected path");
571 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
572 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
576 #endif // wxMSW || wxMAC
578 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
580 MyModalDialog
dlg(this);
584 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
586 bool show
= GetMenuBar()->IsChecked(event
.GetId());
592 m_dialog
= new MyModelessDialog(this);
595 m_dialog
->Show(TRUE
);
603 void MyFrame::ShowTip(wxCommandEvent
& event
)
605 #if wxUSE_STARTUP_TIPS
606 static size_t s_index
= (size_t)-1;
608 if ( s_index
== (size_t)-1 )
612 // this is completely bogus, we don't know how many lines are there
613 // in the file, but who cares, it's a demo only...
614 s_index
= rand() % 5;
617 wxTipProvider
*tipProvider
= wxCreateFileTipProvider("tips.txt", s_index
);
619 bool showAtStartup
= wxShowTip(this, tipProvider
);
623 wxMessageBox("Will show tips on startup", "Tips dialog",
624 wxOK
| wxICON_INFORMATION
, this);
627 s_index
= tipProvider
->GetCurrentTip();
632 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
637 #if wxUSE_PROGRESSDLG
639 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
641 static const int max
= 10;
643 wxProgressDialog
dialog("Progress dialog example",
644 "An informative message",
650 wxPD_ESTIMATED_TIME
|
651 wxPD_REMAINING_TIME
);
654 for ( int i
= 0; i
<= max
&& cont
; i
++ )
659 cont
= dialog
.Update(i
, "That's all, folks!");
661 else if ( i
== max
/ 2 )
663 cont
= dialog
.Update(i
, "Only a half left (very long message)!");
667 cont
= dialog
.Update(i
);
673 wxLogStatus(wxT("Progress dialog aborted!"));
677 wxLogStatus(wxT("Countdown from %d finished"), max
);
681 #endif // wxUSE_PROGRESSDLG
685 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
687 wxWindowDisabler disableAll
;
689 wxBusyInfo
info("Working, please wait...", this);
691 for ( int i
= 0; i
< 30; i
++ )
698 #endif // wxUSE_BUSYINFO
700 #if wxUSE_FINDREPLDLG
702 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
711 m_dlgReplace
= new wxFindReplaceDialog
715 "Find and replace dialog",
719 m_dlgReplace
->Show(TRUE
);
723 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
732 m_dlgFind
= new wxFindReplaceDialog
741 m_dlgFind
->Show(TRUE
);
745 static wxString
DecodeFindDialogEventFlags(int flags
)
748 str
<< (flags
& wxFR_DOWN
? "down" : "up") << ", "
749 << (flags
& wxFR_WHOLEWORD
? "whole words only, " : "")
750 << (flags
& wxFR_MATCHCASE
? "" : "not ")
756 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
758 wxEventType type
= event
.GetEventType();
760 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
762 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
763 type
== wxEVT_COMMAND_FIND_NEXT
? "next " : "",
764 event
.GetFindString().c_str(),
765 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
767 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
768 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
770 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
771 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? "all " : "",
772 event
.GetFindString().c_str(),
773 event
.GetReplaceString().c_str(),
774 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
776 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
778 wxFindReplaceDialog
*dlg
= event
.GetDialog();
781 if ( dlg
== m_dlgFind
)
786 else if ( dlg
== m_dlgReplace
)
795 wxFAIL_MSG( _T("unexecpted event") );
798 wxLogMessage(wxT("%s dialog is being closed."), txt
),
804 wxLogError(wxT("Unknown find dialog event!"));
808 #endif // wxUSE_FINDREPLDLG
810 // ----------------------------------------------------------------------------
812 // ----------------------------------------------------------------------------
814 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
817 dc
.SetFont(wxGetApp().m_canvasFont
);
818 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
819 dc
.SetBackgroundMode(wxTRANSPARENT
);
820 dc
.DrawText("wxWindows common dialogs test application", 10, 10);
823 // ----------------------------------------------------------------------------
825 // ----------------------------------------------------------------------------
827 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
828 : wxDialog(parent
, -1, wxString("Modeless dialog"))
830 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
832 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, "Press me");
833 wxCheckBox
*check
= new wxCheckBox(this, -1, "Should be disabled");
836 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
837 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
842 sizerTop
->SetSizeHints(this);
846 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
848 wxMessageBox("Button pressed in modeless dialog", "Info",
849 wxOK
| wxICON_INFORMATION
, this);
852 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
854 if ( event
.CanVeto() )
856 wxMessageBox("Use the menu item to close this dialog",
858 wxOK
| wxICON_INFORMATION
, this);
864 // ----------------------------------------------------------------------------
866 // ----------------------------------------------------------------------------
868 MyModalDialog::MyModalDialog(wxWindow
*parent
)
869 : wxDialog(parent
, -1, wxString("Modal dialog"))
871 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
873 m_btnFocused
= new wxButton(this, -1, "Default button");
874 m_btnDelete
= new wxButton(this, -1, "&Delete button");
875 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, "&Close");
876 sizerTop
->Add(m_btnFocused
, 0, wxALIGN_CENTER
| wxALL
, 5);
877 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
878 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
883 sizerTop
->SetSizeHints(this);
886 m_btnFocused
->SetFocus();
887 m_btnFocused
->SetDefault();
890 void MyModalDialog::OnButton(wxCommandEvent
& event
)
892 if ( event
.GetEventObject() == m_btnDelete
)
897 m_btnDelete
->Disable();
899 else if ( event
.GetEventObject() == m_btnFocused
)
901 wxGetTextFromUser("Dummy prompt", "Modal dialog called from dialog",