1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
29 #include "wx/msw/wince/time.h"
32 #include "wx/colordlg.h"
33 #include "wx/filedlg.h"
34 #include "wx/dirdlg.h"
35 #include "wx/fontdlg.h"
36 #include "wx/choicdlg.h"
37 #include "wx/tipdlg.h"
38 #include "wx/progdlg.h"
39 #include "wx/fdrepdlg.h"
40 #include "wx/busyinfo.h"
42 #define wxTEST_GENERIC_DIALOGS_IN_MSW 0
44 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
45 #include "wx/generic/colrdlgg.h"
46 #include "wx/generic/fontdlgg.h"
49 #define wxUSE_DIRDLGG 0
51 #if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG
52 #include "wx/generic/dirdlgg.h"
59 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
60 EVT_PAINT(MyCanvas::OnPaint
)
63 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
64 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
65 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
66 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
67 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
68 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
69 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
70 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
71 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
72 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
73 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
74 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
75 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
76 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
77 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
78 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
79 #if defined(__WXMSW__) || defined(__WXMAC__)
80 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
81 #endif // wxMSW || wxMAC
82 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
83 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
84 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
85 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
86 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
87 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
91 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
92 #endif // wxUSE_PROGRESSDLG
95 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
96 #endif // wxUSE_BUSYINFO
99 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
100 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
102 EVT_FIND(-1, MyFrame::OnFindDialog
)
103 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
)
104 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
)
105 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
)
106 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
)
107 #endif // wxUSE_FINDREPLDLG
108 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
111 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
112 EVT_BUTTON(-1, MyModalDialog::OnButton
)
115 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
116 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
118 EVT_CLOSE(MyModelessDialog::OnClose
)
121 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
123 // `Main program' equivalent, creating windows and returning main app frame
126 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
127 wxConvCurrent
= &wxConvLibc
;
130 m_canvasTextColour
= wxColour(_T("BLACK"));
131 m_canvasFont
= *wxNORMAL_FONT
;
133 // Create the main frame window
134 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300));
137 wxMenu
*file_menu
= new wxMenu
;
139 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
141 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
142 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("Choose colour (&generic)"));
145 file_menu
->AppendSeparator();
146 file_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
148 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
149 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose f&ont (generic)"));
152 file_menu
->AppendSeparator();
153 file_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
154 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
155 file_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
156 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
157 file_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
158 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
159 file_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
160 file_menu
->AppendSeparator();
161 file_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
162 file_menu
->AppendSeparator();
163 file_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
164 file_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
165 file_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
166 file_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
167 file_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
168 file_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
169 #if defined(__WXMSW__) || defined(__WXMAC__)
170 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic implementation)"));
171 #endif // wxMSW || wxMAC
172 file_menu
->AppendSeparator();
174 #if wxUSE_PROGRESSDLG
175 file_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
176 #endif // wxUSE_PROGRESSDLG
178 file_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
179 #endif // wxUSE_BUSYINFO
180 #if wxUSE_FINDREPLDLG
181 file_menu
->Append(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"), _T(""), TRUE
);
182 file_menu
->Append(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE
);
183 #endif // wxUSE_FINDREPLDLG
184 file_menu
->AppendSeparator();
186 file_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
187 file_menu
->Append(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE
);
188 file_menu
->AppendSeparator();
190 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
191 wxMenuBar
*menu_bar
= new wxMenuBar
;
192 menu_bar
->Append(file_menu
, _T("&File"));
193 frame
->SetMenuBar(menu_bar
);
195 myCanvas
= new MyCanvas(frame
);
196 myCanvas
->SetBackgroundColour(*wxWHITE
);
198 frame
->Centre(wxBOTH
);
208 // My frame constructor
209 MyFrame::MyFrame(wxWindow
*parent
,
210 const wxString
& title
,
213 : wxFrame(parent
, -1, title
, pos
, size
)
215 m_dialog
= (MyModelessDialog
*)NULL
;
217 #if wxUSE_FINDREPLDLG
225 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
227 wxColour col
= myCanvas
->GetBackgroundColour();
231 data
.SetChooseFull(TRUE
);
232 for (int i
= 0; i
< 16; i
++)
234 wxColour
colour(i
*16, i
*16, i
*16);
235 data
.SetCustomColour(i
, colour
);
238 wxColourDialog
dialog(this, &data
);
239 dialog
.SetTitle(_T("Choose the background colour"));
240 if (dialog
.ShowModal() == wxID_OK
)
242 wxColourData retData
= dialog
.GetColourData();
243 col
= retData
.GetColour();
244 myCanvas
->SetBackgroundColour(col
);
245 myCanvas
->ClearBackground();
250 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
253 data
.SetInitialFont(wxGetApp().m_canvasFont
);
254 data
.SetColour(wxGetApp().m_canvasTextColour
);
256 // you might also do this:
258 // wxFontDialog dialog;
259 // if ( !dialog.Create(this, data) { ... error ... }
261 wxFontDialog
dialog(this, data
);
263 if (dialog
.ShowModal() == wxID_OK
)
265 wxFontData retData
= dialog
.GetFontData();
266 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
267 wxGetApp().m_canvasTextColour
= retData
.GetColour();
270 //else: cancelled by the user, don't change the font
273 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
274 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
277 data
.SetChooseFull(TRUE
);
278 for (int i
= 0; i
< 16; i
++)
280 wxColour
colour(i
*16, i
*16, i
*16);
281 data
.SetCustomColour(i
, colour
);
284 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
285 if (dialog
->ShowModal() == wxID_OK
)
287 wxColourData retData
= dialog
->GetColourData();
288 wxColour col
= retData
.GetColour();
289 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
290 myCanvas
->SetBackgroundColour(col
);
291 myCanvas
->ClearBackground();
297 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
300 data
.SetInitialFont(wxGetApp().m_canvasFont
);
301 data
.SetColour(wxGetApp().m_canvasTextColour
);
303 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
304 if (dialog
->ShowModal() == wxID_OK
)
306 wxFontData retData
= dialog
->GetFontData();
307 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
308 wxGetApp().m_canvasTextColour
= retData
.GetColour();
313 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
315 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
317 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
318 // being flushed -- test it
321 wxLogMessage(wxT("This is some message - everything is ok so far."));
322 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
323 wxLogWarning(wxT("And then something went wrong!"));
325 // and if ~wxBusyCursor doesn't do it, then call it manually
329 wxLogError(wxT("Intermediary error handler decided to abort."));
330 wxLogError(wxT("The top level caller detected an unrecoverable error."));
332 wxLog::FlushActive();
334 wxLogMessage(wxT("And this is the same dialog but with only one message."));
337 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
339 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
340 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
342 switch ( dialog
.ShowModal() )
345 wxLogStatus(wxT("You pressed \"Yes\""));
349 wxLogStatus(wxT("You pressed \"No\""));
353 wxLogStatus(wxT("You pressed \"Cancel\""));
357 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
361 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
363 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
364 _T("Even two rows of text."),
365 _T("Enter a number:"), _T("Numeric input test"),
372 msg
= _T("Invalid number entered or dialog cancelled.");
377 msg
.Printf(_T("You've entered %lu"), res
);
378 icon
= wxICON_INFORMATION
;
381 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
384 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
386 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
387 _T("Password entry dialog"),
392 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
393 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
397 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
399 wxTextEntryDialog
dialog(this,
400 _T("This is a small sample\n")
401 _T("A long, long string to test out the text entrybox"),
402 _T("Please enter a string"),
406 if (dialog
.ShowModal() == wxID_OK
)
408 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
413 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
415 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
417 wxSingleChoiceDialog
dialog(this,
418 _T("This is a small sample\n")
419 _T("A single-choice convenience dialog"),
420 _T("Please select a value"),
421 WXSIZEOF(choices
), choices
);
423 dialog
.SetSelection(2);
425 if (dialog
.ShowModal() == wxID_OK
)
427 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
432 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
434 const wxString choices
[] =
436 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
437 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
438 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
441 wxArrayInt selections
;
442 size_t count
= wxGetMultipleChoices(selections
,
443 _T("This is a small sample\n")
444 _T("A multi-choice convenience dialog"),
445 _T("Please select a value"),
446 WXSIZEOF(choices
), choices
,
451 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
452 for ( size_t n
= 0; n
< count
; n
++ )
454 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
455 (unsigned)n
, (unsigned)selections
[n
],
456 choices
[selections
[n
]].c_str());
460 //else: cancelled or nothing selected
463 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
468 _T("Testing open file dialog"),
472 _T("C++ files (*.cpp)|*.cpp")
474 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
478 dialog
.SetDirectory(wxGetHomeDir());
480 if (dialog
.ShowModal() == wxID_OK
)
483 info
.Printf(_T("Full file name: %s\n")
486 dialog
.GetPath().c_str(),
487 dialog
.GetDirectory().c_str(),
488 dialog
.GetFilename().c_str());
489 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
494 // this shows how to take advantage of specifying a default extension in the
495 // call to wxFileSelector: it is remembered after each new call and the next
496 // one will use it by default
497 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
499 static wxString s_extDef
;
500 wxString path
= wxFileSelector(
501 _T("Select the file to load"),
504 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
512 // it is just a sample, would use wxSplitPath in real program
513 s_extDef
= path
.AfterLast(_T('.'));
515 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
516 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
519 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
521 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
522 _T(""), _T(""), wxFileSelectorDefaultWildcardStr
,
525 if (dialog
.ShowModal() == wxID_OK
)
527 wxArrayString paths
, filenames
;
529 dialog
.GetPaths(paths
);
530 dialog
.GetFilenames(filenames
);
533 size_t count
= paths
.GetCount();
534 for ( size_t n
= 0; n
< count
; n
++ )
536 s
.Printf(_T("File %d: %s (%s)\n"),
537 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
542 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
547 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
549 wxFileDialog
dialog(this,
550 _T("Testing save file dialog"),
553 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
554 wxSAVE
|wxOVERWRITE_PROMPT
);
556 dialog
.SetFilterIndex(1);
558 if (dialog
.ShowModal() == wxID_OK
)
560 wxLogMessage(_T("%s, filter %d"),
561 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
565 void MyFrame::DoDirChoose(int style
)
567 // pass some initial dir to wxDirDialog
569 wxGetHomeDir(&dirHome
);
571 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
573 if (dialog
.ShowModal() == wxID_OK
)
575 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
579 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
581 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
584 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
586 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
589 #if defined(__WXMSW__) || defined(__WXMAC__)
591 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
593 #if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG
594 // pass some initial dir to wxDirDialog
596 wxGetHomeDir(&dirHome
);
598 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
600 if (dialog
.ShowModal() == wxID_OK
)
602 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
606 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
607 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
611 #endif // wxMSW || wxMAC
613 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
615 MyModalDialog
dlg(this);
619 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
621 bool show
= GetMenuBar()->IsChecked(event
.GetId());
627 m_dialog
= new MyModelessDialog(this);
630 m_dialog
->Show(TRUE
);
638 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
640 #if wxUSE_STARTUP_TIPS
641 static size_t s_index
= (size_t)-1;
643 if ( s_index
== (size_t)-1 )
647 // this is completely bogus, we don't know how many lines are there
648 // in the file, but who cares, it's a demo only...
649 s_index
= rand() % 5;
652 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
654 bool showAtStartup
= wxShowTip(this, tipProvider
);
658 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
659 wxOK
| wxICON_INFORMATION
, this);
662 s_index
= tipProvider
->GetCurrentTip();
667 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
672 #if wxUSE_PROGRESSDLG
674 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
676 static const int max
= 10;
678 wxProgressDialog
dialog(_T("Progress dialog example"),
679 _T("An informative message"),
684 // wxPD_AUTO_HIDE | -- try this as well
686 wxPD_ESTIMATED_TIME
|
687 wxPD_REMAINING_TIME
);
690 for ( int i
= 0; i
<= max
; i
++ )
695 cont
= dialog
.Update(i
, _T("That's all, folks!"));
697 else if ( i
== max
/ 2 )
699 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
703 cont
= dialog
.Update(i
);
708 if ( wxMessageBox(_T("Do you really want to cancel?"),
709 _T("Progress dialog question"), // caption
710 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
719 wxLogStatus(wxT("Progress dialog aborted!"));
723 wxLogStatus(wxT("Countdown from %d finished"), max
);
727 #endif // wxUSE_PROGRESSDLG
731 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
733 wxWindowDisabler disableAll
;
735 wxBusyInfo
info(_T("Working, please wait..."), this);
737 for ( int i
= 0; i
< 18; i
++ )
747 #endif // wxUSE_BUSYINFO
749 #if wxUSE_FINDREPLDLG
751 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
760 m_dlgReplace
= new wxFindReplaceDialog
764 _T("Find and replace dialog"),
768 m_dlgReplace
->Show(TRUE
);
772 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
781 m_dlgFind
= new wxFindReplaceDialog
790 m_dlgFind
->Show(TRUE
);
794 static wxString
DecodeFindDialogEventFlags(int flags
)
797 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
798 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
799 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
800 << _T("case sensitive");
805 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
807 wxEventType type
= event
.GetEventType();
809 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
811 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
812 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
813 event
.GetFindString().c_str(),
814 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
816 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
817 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
819 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
820 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
821 event
.GetFindString().c_str(),
822 event
.GetReplaceString().c_str(),
823 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
825 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
827 wxFindReplaceDialog
*dlg
= event
.GetDialog();
831 if ( dlg
== m_dlgFind
)
834 idMenu
= DIALOGS_FIND
;
837 else if ( dlg
== m_dlgReplace
)
840 idMenu
= DIALOGS_REPLACE
;
848 wxFAIL_MSG( _T("unexpected event") );
851 wxLogMessage(wxT("%s dialog is being closed."), txt
);
855 GetMenuBar()->Check(idMenu
, FALSE
);
862 wxLogError(wxT("Unknown find dialog event!"));
866 #endif // wxUSE_FINDREPLDLG
868 // ----------------------------------------------------------------------------
870 // ----------------------------------------------------------------------------
872 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
875 dc
.SetFont(wxGetApp().m_canvasFont
);
876 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
877 dc
.SetBackgroundMode(wxTRANSPARENT
);
878 dc
.DrawText(_T("wxWindows common dialogs test application"), 10, 10);
881 // ----------------------------------------------------------------------------
883 // ----------------------------------------------------------------------------
885 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
886 : wxDialog(parent
, -1, wxString(_T("Modeless dialog")))
888 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
890 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
891 wxCheckBox
*check
= new wxCheckBox(this, -1, _T("Should be disabled"));
894 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
895 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
900 sizerTop
->SetSizeHints(this);
904 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
906 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
907 wxOK
| wxICON_INFORMATION
, this);
910 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
912 if ( event
.CanVeto() )
914 wxMessageBox(_T("Use the menu item to close this dialog"),
915 _T("Modeless dialog"),
916 wxOK
| wxICON_INFORMATION
, this);
922 // ----------------------------------------------------------------------------
924 // ----------------------------------------------------------------------------
926 MyModalDialog::MyModalDialog(wxWindow
*parent
)
927 : wxDialog(parent
, -1, wxString(_T("Modal dialog")))
929 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
931 m_btnModal
= new wxButton(this, -1, _T("&Modal dialog..."));
932 m_btnModeless
= new wxButton(this, -1, _T("Mode&less dialog"));
933 m_btnDelete
= new wxButton(this, -1, _T("&Delete button"));
935 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
936 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
937 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
938 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
939 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
944 sizerTop
->SetSizeHints(this);
947 m_btnModal
->SetFocus();
948 m_btnModal
->SetDefault();
951 void MyModalDialog::OnButton(wxCommandEvent
& event
)
953 if ( event
.GetEventObject() == m_btnDelete
)
958 m_btnDelete
->Disable();
960 else if ( event
.GetEventObject() == m_btnModal
)
962 wxGetTextFromUser(_T("Dummy prompt"),
963 _T("Modal dialog called from dialog"),
966 else if ( event
.GetEventObject() == m_btnModeless
)
968 (new MyModelessDialog(this))->Show();