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/numdlg.h"
33 #include "wx/colordlg.h"
34 #include "wx/filedlg.h"
35 #include "wx/dirdlg.h"
36 #include "wx/fontdlg.h"
37 #include "wx/choicdlg.h"
38 #include "wx/tipdlg.h"
39 #include "wx/progdlg.h"
40 #include "wx/fdrepdlg.h"
41 #include "wx/busyinfo.h"
44 #define wxTEST_GENERIC_DIALOGS_IN_MSW 0
46 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
47 #include "wx/generic/colrdlgg.h"
48 #include "wx/generic/fontdlgg.h"
51 #define wxUSE_DIRDLGG 0
53 #if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG
54 #include "wx/generic/dirdlgg.h"
61 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
62 EVT_PAINT(MyCanvas::OnPaint
)
65 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
66 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
67 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
68 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
69 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
70 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
71 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
72 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
73 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
74 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
75 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
76 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
77 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
78 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
79 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
80 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
81 #if defined(__WXMSW__) || defined(__WXMAC__)
82 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
83 #endif // wxMSW || wxMAC
84 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
85 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
86 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
87 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
88 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
89 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
93 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
94 #endif // wxUSE_PROGRESSDLG
97 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
98 #endif // wxUSE_BUSYINFO
100 #if wxUSE_FINDREPLDLG
101 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
102 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
104 EVT_FIND(-1, MyFrame::OnFindDialog
)
105 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
)
106 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
)
107 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
)
108 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
)
109 #endif // wxUSE_FINDREPLDLG
110 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
113 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
114 EVT_BUTTON(-1, MyModalDialog::OnButton
)
117 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
118 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
120 EVT_CLOSE(MyModelessDialog::OnClose
)
123 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
125 // `Main program' equivalent, creating windows and returning main app frame
129 wxInitAllImageHandlers();
132 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
133 wxConvCurrent
= &wxConvLibc
;
136 m_canvasTextColour
= wxColour(_T("BLACK"));
137 m_canvasFont
= *wxNORMAL_FONT
;
139 // Create the main frame window
140 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"), wxPoint(20, 20), wxSize(400, 300));
143 wxMenu
*file_menu
= new wxMenu
;
145 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
147 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
148 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("Choose colour (&generic)"));
151 file_menu
->AppendSeparator();
152 file_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
154 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
155 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose f&ont (generic)"));
158 file_menu
->AppendSeparator();
159 file_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
160 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
161 file_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
162 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
163 file_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
164 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
165 file_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
166 file_menu
->AppendSeparator();
167 file_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
168 file_menu
->AppendSeparator();
169 file_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
170 file_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
171 file_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
172 file_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
173 file_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
174 file_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
175 #if defined(__WXMSW__) || defined(__WXMAC__)
176 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic implementation)"));
177 #endif // wxMSW || wxMAC
178 file_menu
->AppendSeparator();
180 #if wxUSE_PROGRESSDLG
181 file_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
182 #endif // wxUSE_PROGRESSDLG
184 file_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
185 #endif // wxUSE_BUSYINFO
186 #if wxUSE_FINDREPLDLG
187 file_menu
->Append(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"), _T(""), TRUE
);
188 file_menu
->Append(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE
);
189 #endif // wxUSE_FINDREPLDLG
190 file_menu
->AppendSeparator();
192 file_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
193 file_menu
->Append(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE
);
194 file_menu
->AppendSeparator();
196 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
197 wxMenuBar
*menu_bar
= new wxMenuBar
;
198 menu_bar
->Append(file_menu
, _T("&File"));
199 frame
->SetMenuBar(menu_bar
);
201 myCanvas
= new MyCanvas(frame
);
202 myCanvas
->SetBackgroundColour(*wxWHITE
);
204 frame
->Centre(wxBOTH
);
214 // My frame constructor
215 MyFrame::MyFrame(wxWindow
*parent
,
216 const wxString
& title
,
219 : wxFrame(parent
, -1, title
, pos
, size
)
221 m_dialog
= (MyModelessDialog
*)NULL
;
223 #if wxUSE_FINDREPLDLG
228 m_clrData
.SetChooseFull(true);
229 for (int i
= 0; i
< 16; i
++)
231 m_clrData
.SetCustomColour(i
, wxColour(i
*16, i
*16, i
*16));
237 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
239 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
241 wxColourDialog
dialog(this, &m_clrData
);
242 dialog
.SetTitle(_T("Choose the background colour"));
243 if (dialog
.ShowModal() == wxID_OK
)
245 m_clrData
= dialog
.GetColourData();
246 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
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("wxWidgets 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();