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 wxInitAllImageHandlers();
128 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
129 wxConvCurrent
= &wxConvLibc
;
132 m_canvasTextColour
= wxColour(_T("BLACK"));
133 m_canvasFont
= *wxNORMAL_FONT
;
135 // Create the main frame window
136 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300));
139 wxMenu
*file_menu
= new wxMenu
;
141 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
143 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
144 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("Choose colour (&generic)"));
147 file_menu
->AppendSeparator();
148 file_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
150 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
151 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose f&ont (generic)"));
154 file_menu
->AppendSeparator();
155 file_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
156 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
157 file_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
158 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
159 file_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
160 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
161 file_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
162 file_menu
->AppendSeparator();
163 file_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
164 file_menu
->AppendSeparator();
165 file_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
166 file_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
167 file_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
168 file_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
169 file_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
170 file_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
171 #if defined(__WXMSW__) || defined(__WXMAC__)
172 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic implementation)"));
173 #endif // wxMSW || wxMAC
174 file_menu
->AppendSeparator();
176 #if wxUSE_PROGRESSDLG
177 file_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
178 #endif // wxUSE_PROGRESSDLG
180 file_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
181 #endif // wxUSE_BUSYINFO
182 #if wxUSE_FINDREPLDLG
183 file_menu
->Append(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"), _T(""), TRUE
);
184 file_menu
->Append(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE
);
185 #endif // wxUSE_FINDREPLDLG
186 file_menu
->AppendSeparator();
188 file_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
189 file_menu
->Append(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE
);
190 file_menu
->AppendSeparator();
192 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
193 wxMenuBar
*menu_bar
= new wxMenuBar
;
194 menu_bar
->Append(file_menu
, _T("&File"));
195 frame
->SetMenuBar(menu_bar
);
197 myCanvas
= new MyCanvas(frame
);
198 myCanvas
->SetBackgroundColour(*wxWHITE
);
200 frame
->Centre(wxBOTH
);
210 // My frame constructor
211 MyFrame
::MyFrame(wxWindow
*parent
,
212 const wxString
& title
,
215 : wxFrame(parent
, -1, title
, pos
, size
)
217 m_dialog
= (MyModelessDialog
*)NULL
;
219 #if wxUSE_FINDREPLDLG
227 void MyFrame
::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
229 wxColour col
= myCanvas
->GetBackgroundColour();
233 data
.SetChooseFull(TRUE
);
234 for (int i
= 0; i
< 16; i
++)
236 wxColour
colour(i
*16, i
*16, i
*16);
237 data
.SetCustomColour(i
, colour
);
240 wxColourDialog
dialog(this, &data
);
241 dialog
.SetTitle(_T("Choose the background colour"));
242 if (dialog
.ShowModal() == wxID_OK
)
244 wxColourData retData
= dialog
.GetColourData();
245 col
= retData
.GetColour();
246 myCanvas
->SetBackgroundColour(col
);
247 myCanvas
->ClearBackground();
252 void MyFrame
::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
255 data
.SetInitialFont(wxGetApp().m_canvasFont
);
256 data
.SetColour(wxGetApp().m_canvasTextColour
);
258 // you might also do this:
260 // wxFontDialog dialog;
261 // if ( !dialog.Create(this, data) { ... error ... }
263 wxFontDialog
dialog(this, data
);
265 if (dialog
.ShowModal() == wxID_OK
)
267 wxFontData retData
= dialog
.GetFontData();
268 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
269 wxGetApp().m_canvasTextColour
= retData
.GetColour();
272 //else: cancelled by the user, don't change the font
275 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
276 void MyFrame
::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
279 data
.SetChooseFull(TRUE
);
280 for (int i
= 0; i
< 16; i
++)
282 wxColour
colour(i
*16, i
*16, i
*16);
283 data
.SetCustomColour(i
, colour
);
286 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
287 if (dialog
->ShowModal() == wxID_OK
)
289 wxColourData retData
= dialog
->GetColourData();
290 wxColour col
= retData
.GetColour();
291 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
292 myCanvas
->SetBackgroundColour(col
);
293 myCanvas
->ClearBackground();
299 void MyFrame
::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
302 data
.SetInitialFont(wxGetApp().m_canvasFont
);
303 data
.SetColour(wxGetApp().m_canvasTextColour
);
305 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
306 if (dialog
->ShowModal() == wxID_OK
)
308 wxFontData retData
= dialog
->GetFontData();
309 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
310 wxGetApp().m_canvasTextColour
= retData
.GetColour();
315 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
317 void MyFrame
::LogDialog(wxCommandEvent
& WXUNUSED(event
))
319 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
320 // being flushed -- test it
323 wxLogMessage(wxT("This is some message - everything is ok so far."));
324 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
325 wxLogWarning(wxT("And then something went wrong!"));
327 // and if ~wxBusyCursor doesn't do it, then call it manually
331 wxLogError(wxT("Intermediary error handler decided to abort."));
332 wxLogError(wxT("The top level caller detected an unrecoverable error."));
334 wxLog
::FlushActive();
336 wxLogMessage(wxT("And this is the same dialog but with only one message."));
339 void MyFrame
::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
341 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
342 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
344 switch ( dialog
.ShowModal() )
347 wxLogStatus(wxT("You pressed \"Yes\""));
351 wxLogStatus(wxT("You pressed \"No\""));
355 wxLogStatus(wxT("You pressed \"Cancel\""));
359 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
363 void MyFrame
::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
365 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
366 _T("Even two rows of text."),
367 _T("Enter a number:"), _T("Numeric input test"),
374 msg
= _T("Invalid number entered or dialog cancelled.");
379 msg
.Printf(_T("You've entered %lu"), res
);
380 icon
= wxICON_INFORMATION
;
383 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
386 void MyFrame
::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
388 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
389 _T("Password entry dialog"),
394 wxMessageBox(wxString
::Format(wxT("Your password is '%s'"), pwd
.c_str()),
395 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
399 void MyFrame
::TextEntry(wxCommandEvent
& WXUNUSED(event
))
401 wxTextEntryDialog
dialog(this,
402 _T("This is a small sample\n")
403 _T("A long, long string to test out the text entrybox"),
404 _T("Please enter a string"),
408 if (dialog
.ShowModal() == wxID_OK
)
410 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
415 void MyFrame
::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
417 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
419 wxSingleChoiceDialog
dialog(this,
420 _T("This is a small sample\n")
421 _T("A single-choice convenience dialog"),
422 _T("Please select a value"),
423 WXSIZEOF(choices
), choices
);
425 dialog
.SetSelection(2);
427 if (dialog
.ShowModal() == wxID_OK
)
429 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
434 void MyFrame
::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
436 const wxString choices
[] =
438 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
439 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
440 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
443 wxArrayInt selections
;
444 size_t count
= wxGetMultipleChoices(selections
,
445 _T("This is a small sample\n")
446 _T("A multi-choice convenience dialog"),
447 _T("Please select a value"),
448 WXSIZEOF(choices
), choices
,
453 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
454 for ( size_t n
= 0; n
< count
; n
++ )
456 msg
+= wxString
::Format(wxT("\t%u: %u (%s)\n"),
457 (unsigned)n
, (unsigned)selections
[n
],
458 choices
[selections
[n
]].c_str());
462 //else: cancelled or nothing selected
465 void MyFrame
::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
470 _T("Testing open file dialog"),
474 _T("C++ files (*.cpp)|*.cpp")
476 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
480 dialog
.SetDirectory(wxGetHomeDir());
482 if (dialog
.ShowModal() == wxID_OK
)
485 info
.Printf(_T("Full file name: %s\n")
488 dialog
.GetPath().c_str(),
489 dialog
.GetDirectory().c_str(),
490 dialog
.GetFilename().c_str());
491 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
496 // this shows how to take advantage of specifying a default extension in the
497 // call to wxFileSelector: it is remembered after each new call and the next
498 // one will use it by default
499 void MyFrame
::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
501 static wxString s_extDef
;
502 wxString path
= wxFileSelector(
503 _T("Select the file to load"),
506 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
514 // it is just a sample, would use wxSplitPath in real program
515 s_extDef
= path
.AfterLast(_T('.'));
517 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
518 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
521 void MyFrame
::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
525 _T("C++ files (*.cpp)|*.cpp");
527 _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
529 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
530 _T(""), _T(""), wildcards
,
533 if (dialog
.ShowModal() == wxID_OK
)
535 wxArrayString paths
, filenames
;
537 dialog
.GetPaths(paths
);
538 dialog
.GetFilenames(filenames
);
541 size_t count
= paths
.GetCount();
542 for ( size_t n
= 0; n
< count
; n
++ )
544 s
.Printf(_T("File %d: %s (%s)\n"),
545 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
549 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
552 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
557 void MyFrame
::FileSave(wxCommandEvent
& WXUNUSED(event
) )
559 wxFileDialog
dialog(this,
560 _T("Testing save file dialog"),
563 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
564 wxSAVE
|wxOVERWRITE_PROMPT
);
566 dialog
.SetFilterIndex(1);
568 if (dialog
.ShowModal() == wxID_OK
)
570 wxLogMessage(_T("%s, filter %d"),
571 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
575 void MyFrame
::DoDirChoose(int style
)
577 // pass some initial dir to wxDirDialog
579 wxGetHomeDir(&dirHome
);
581 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
583 if (dialog
.ShowModal() == wxID_OK
)
585 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
589 void MyFrame
::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
591 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
594 void MyFrame
::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
596 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
599 #if defined(__WXMSW__) || defined(__WXMAC__)
601 void MyFrame
::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
603 #if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG
604 // pass some initial dir to wxDirDialog
606 wxGetHomeDir(&dirHome
);
608 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
610 if (dialog
.ShowModal() == wxID_OK
)
612 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
616 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
617 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
621 #endif // wxMSW || wxMAC
623 void MyFrame
::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
625 MyModalDialog
dlg(this);
629 void MyFrame
::ModelessDlg(wxCommandEvent
& event
)
631 bool show
= GetMenuBar()->IsChecked(event
.GetId());
637 m_dialog
= new MyModelessDialog(this);
640 m_dialog
->Show(TRUE
);
648 void MyFrame
::ShowTip(wxCommandEvent
& WXUNUSED(event
))
650 #if wxUSE_STARTUP_TIPS
651 static size_t s_index
= (size_t)-1;
653 if ( s_index
== (size_t)-1 )
657 // this is completely bogus, we don't know how many lines are there
658 // in the file, but who cares, it's a demo only...
659 s_index
= rand() % 5;
662 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
664 bool showAtStartup
= wxShowTip(this, tipProvider
);
668 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
669 wxOK
| wxICON_INFORMATION
, this);
672 s_index
= tipProvider
->GetCurrentTip();
677 void MyFrame
::OnExit(wxCommandEvent
& WXUNUSED(event
) )
682 #if wxUSE_PROGRESSDLG
684 void MyFrame
::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
686 static const int max
= 10;
688 wxProgressDialog
dialog(_T("Progress dialog example"),
689 _T("An informative message"),
694 // wxPD_AUTO_HIDE | -- try this as well
696 wxPD_ESTIMATED_TIME
|
697 wxPD_REMAINING_TIME
);
700 for ( int i
= 0; i
<= max
; i
++ )
705 cont
= dialog
.Update(i
, _T("That's all, folks!"));
707 else if ( i
== max
/ 2 )
709 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
713 cont
= dialog
.Update(i
);
718 if ( wxMessageBox(_T("Do you really want to cancel?"),
719 _T("Progress dialog question"), // caption
720 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
729 wxLogStatus(wxT("Progress dialog aborted!"));
733 wxLogStatus(wxT("Countdown from %d finished"), max
);
737 #endif // wxUSE_PROGRESSDLG
741 void MyFrame
::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
743 wxWindowDisabler disableAll
;
745 wxBusyInfo
info(_T("Working, please wait..."), this);
747 for ( int i
= 0; i
< 18; i
++ )
757 #endif // wxUSE_BUSYINFO
759 #if wxUSE_FINDREPLDLG
761 void MyFrame
::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
770 m_dlgReplace
= new wxFindReplaceDialog
774 _T("Find and replace dialog"),
778 m_dlgReplace
->Show(TRUE
);
782 void MyFrame
::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
791 m_dlgFind
= new wxFindReplaceDialog
800 m_dlgFind
->Show(TRUE
);
804 static wxString
DecodeFindDialogEventFlags(int flags
)
807 str
<< (flags
& wxFR_DOWN ?
_T("down") : _T("up")) << _T(", ")
808 << (flags
& wxFR_WHOLEWORD ?
_T("whole words only, ") : _T(""))
809 << (flags
& wxFR_MATCHCASE ?
_T("") : _T("not "))
810 << _T("case sensitive");
815 void MyFrame
::OnFindDialog(wxFindDialogEvent
& event
)
817 wxEventType type
= event
.GetEventType();
819 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
821 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
822 type
== wxEVT_COMMAND_FIND_NEXT ?
wxT("next ") : wxT(""),
823 event
.GetFindString().c_str(),
824 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
826 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
827 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
829 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
830 type
== wxEVT_COMMAND_FIND_REPLACE_ALL ?
_T("all ") : wxT(""),
831 event
.GetFindString().c_str(),
832 event
.GetReplaceString().c_str(),
833 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
835 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
837 wxFindReplaceDialog
*dlg
= event
.GetDialog();
841 if ( dlg
== m_dlgFind
)
844 idMenu
= DIALOGS_FIND
;
847 else if ( dlg
== m_dlgReplace
)
850 idMenu
= DIALOGS_REPLACE
;
858 wxFAIL_MSG( _T("unexpected event") );
861 wxLogMessage(wxT("%s dialog is being closed."), txt
);
865 GetMenuBar()->Check(idMenu
, FALSE
);
872 wxLogError(wxT("Unknown find dialog event!"));
876 #endif // wxUSE_FINDREPLDLG
878 // ----------------------------------------------------------------------------
880 // ----------------------------------------------------------------------------
882 void MyCanvas
::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
885 dc
.SetFont(wxGetApp().m_canvasFont
);
886 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
887 dc
.SetBackgroundMode(wxTRANSPARENT
);
888 dc
.DrawText(_T("wxWindows common dialogs test application"), 10, 10);
891 // ----------------------------------------------------------------------------
893 // ----------------------------------------------------------------------------
895 MyModelessDialog
::MyModelessDialog(wxWindow
*parent
)
896 : wxDialog(parent
, -1, wxString(_T("Modeless dialog")))
898 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
900 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
901 wxCheckBox
*check
= new wxCheckBox(this, -1, _T("Should be disabled"));
904 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
905 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
910 sizerTop
->SetSizeHints(this);
914 void MyModelessDialog
::OnButton(wxCommandEvent
& WXUNUSED(event
))
916 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
917 wxOK
| wxICON_INFORMATION
, this);
920 void MyModelessDialog
::OnClose(wxCloseEvent
& event
)
922 if ( event
.CanVeto() )
924 wxMessageBox(_T("Use the menu item to close this dialog"),
925 _T("Modeless dialog"),
926 wxOK
| wxICON_INFORMATION
, this);
932 // ----------------------------------------------------------------------------
934 // ----------------------------------------------------------------------------
936 MyModalDialog
::MyModalDialog(wxWindow
*parent
)
937 : wxDialog(parent
, -1, wxString(_T("Modal dialog")))
939 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
941 m_btnModal
= new wxButton(this, -1, _T("&Modal dialog..."));
942 m_btnModeless
= new wxButton(this, -1, _T("Mode&less dialog"));
943 m_btnDelete
= new wxButton(this, -1, _T("&Delete button"));
945 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
946 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
947 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
948 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
949 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
954 sizerTop
->SetSizeHints(this);
957 m_btnModal
->SetFocus();
958 m_btnModal
->SetDefault();
961 void MyModalDialog
::OnButton(wxCommandEvent
& event
)
963 if ( event
.GetEventObject() == m_btnDelete
)
968 m_btnDelete
->Disable();
970 else if ( event
.GetEventObject() == m_btnModal
)
972 wxGetTextFromUser(_T("Dummy prompt"),
973 _T("Modal dialog called from dialog"),
976 else if ( event
.GetEventObject() == m_btnModeless
)
978 (new MyModelessDialog(this))->Show();