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("wxWindows 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
231 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
233 wxColour col
= myCanvas
->GetBackgroundColour();
237 data
.SetChooseFull(TRUE
);
238 for (int i
= 0; i
< 16; i
++)
240 wxColour
colour(i
*16, i
*16, i
*16);
241 data
.SetCustomColour(i
, colour
);
244 wxColourDialog
dialog(this, &data
);
245 dialog
.SetTitle(_T("Choose the background colour"));
246 if (dialog
.ShowModal() == wxID_OK
)
248 wxColourData retData
= dialog
.GetColourData();
249 col
= retData
.GetColour();
250 myCanvas
->SetBackgroundColour(col
);
251 myCanvas
->ClearBackground();
256 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
259 data
.SetInitialFont(wxGetApp().m_canvasFont
);
260 data
.SetColour(wxGetApp().m_canvasTextColour
);
262 // you might also do this:
264 // wxFontDialog dialog;
265 // if ( !dialog.Create(this, data) { ... error ... }
267 wxFontDialog
dialog(this, data
);
269 if (dialog
.ShowModal() == wxID_OK
)
271 wxFontData retData
= dialog
.GetFontData();
272 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
273 wxGetApp().m_canvasTextColour
= retData
.GetColour();
276 //else: cancelled by the user, don't change the font
279 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
280 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
283 data
.SetChooseFull(TRUE
);
284 for (int i
= 0; i
< 16; i
++)
286 wxColour
colour(i
*16, i
*16, i
*16);
287 data
.SetCustomColour(i
, colour
);
290 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
291 if (dialog
->ShowModal() == wxID_OK
)
293 wxColourData retData
= dialog
->GetColourData();
294 wxColour col
= retData
.GetColour();
295 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
296 myCanvas
->SetBackgroundColour(col
);
297 myCanvas
->ClearBackground();
303 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
306 data
.SetInitialFont(wxGetApp().m_canvasFont
);
307 data
.SetColour(wxGetApp().m_canvasTextColour
);
309 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
310 if (dialog
->ShowModal() == wxID_OK
)
312 wxFontData retData
= dialog
->GetFontData();
313 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
314 wxGetApp().m_canvasTextColour
= retData
.GetColour();
319 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
321 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
323 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
324 // being flushed -- test it
327 wxLogMessage(wxT("This is some message - everything is ok so far."));
328 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
329 wxLogWarning(wxT("And then something went wrong!"));
331 // and if ~wxBusyCursor doesn't do it, then call it manually
335 wxLogError(wxT("Intermediary error handler decided to abort."));
336 wxLogError(wxT("The top level caller detected an unrecoverable error."));
338 wxLog::FlushActive();
340 wxLogMessage(wxT("And this is the same dialog but with only one message."));
343 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
345 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
346 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
348 switch ( dialog
.ShowModal() )
351 wxLogStatus(wxT("You pressed \"Yes\""));
355 wxLogStatus(wxT("You pressed \"No\""));
359 wxLogStatus(wxT("You pressed \"Cancel\""));
363 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
367 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
369 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
370 _T("Even two rows of text."),
371 _T("Enter a number:"), _T("Numeric input test"),
378 msg
= _T("Invalid number entered or dialog cancelled.");
383 msg
.Printf(_T("You've entered %lu"), res
);
384 icon
= wxICON_INFORMATION
;
387 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
390 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
392 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
393 _T("Password entry dialog"),
398 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
399 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
403 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
405 wxTextEntryDialog
dialog(this,
406 _T("This is a small sample\n")
407 _T("A long, long string to test out the text entrybox"),
408 _T("Please enter a string"),
412 if (dialog
.ShowModal() == wxID_OK
)
414 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
419 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
421 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
423 wxSingleChoiceDialog
dialog(this,
424 _T("This is a small sample\n")
425 _T("A single-choice convenience dialog"),
426 _T("Please select a value"),
427 WXSIZEOF(choices
), choices
);
429 dialog
.SetSelection(2);
431 if (dialog
.ShowModal() == wxID_OK
)
433 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
438 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
440 const wxString choices
[] =
442 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
443 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
444 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
447 wxArrayInt selections
;
448 size_t count
= wxGetMultipleChoices(selections
,
449 _T("This is a small sample\n")
450 _T("A multi-choice convenience dialog"),
451 _T("Please select a value"),
452 WXSIZEOF(choices
), choices
,
457 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
458 for ( size_t n
= 0; n
< count
; n
++ )
460 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
461 (unsigned)n
, (unsigned)selections
[n
],
462 choices
[selections
[n
]].c_str());
466 //else: cancelled or nothing selected
469 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
474 _T("Testing open file dialog"),
478 _T("C++ files (*.cpp)|*.cpp")
480 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
484 dialog
.SetDirectory(wxGetHomeDir());
486 if (dialog
.ShowModal() == wxID_OK
)
489 info
.Printf(_T("Full file name: %s\n")
492 dialog
.GetPath().c_str(),
493 dialog
.GetDirectory().c_str(),
494 dialog
.GetFilename().c_str());
495 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
500 // this shows how to take advantage of specifying a default extension in the
501 // call to wxFileSelector: it is remembered after each new call and the next
502 // one will use it by default
503 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
505 static wxString s_extDef
;
506 wxString path
= wxFileSelector(
507 _T("Select the file to load"),
510 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
518 // it is just a sample, would use wxSplitPath in real program
519 s_extDef
= path
.AfterLast(_T('.'));
521 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
522 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
525 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
529 _T("C++ files (*.cpp)|*.cpp");
531 _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
533 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
534 _T(""), _T(""), wildcards
,
537 if (dialog
.ShowModal() == wxID_OK
)
539 wxArrayString paths
, filenames
;
541 dialog
.GetPaths(paths
);
542 dialog
.GetFilenames(filenames
);
545 size_t count
= paths
.GetCount();
546 for ( size_t n
= 0; n
< count
; n
++ )
548 s
.Printf(_T("File %d: %s (%s)\n"),
549 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
553 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
556 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
561 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
563 wxFileDialog
dialog(this,
564 _T("Testing save file dialog"),
567 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
568 wxSAVE
|wxOVERWRITE_PROMPT
);
570 dialog
.SetFilterIndex(1);
572 if (dialog
.ShowModal() == wxID_OK
)
574 wxLogMessage(_T("%s, filter %d"),
575 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
579 void MyFrame::DoDirChoose(int style
)
581 // pass some initial dir to wxDirDialog
583 wxGetHomeDir(&dirHome
);
585 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
587 if (dialog
.ShowModal() == wxID_OK
)
589 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
593 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
595 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
598 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
600 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
603 #if defined(__WXMSW__) || defined(__WXMAC__)
605 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
607 #if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG
608 // pass some initial dir to wxDirDialog
610 wxGetHomeDir(&dirHome
);
612 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
614 if (dialog
.ShowModal() == wxID_OK
)
616 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
620 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
621 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
625 #endif // wxMSW || wxMAC
627 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
629 MyModalDialog
dlg(this);
633 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
635 bool show
= GetMenuBar()->IsChecked(event
.GetId());
641 m_dialog
= new MyModelessDialog(this);
644 m_dialog
->Show(TRUE
);
652 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
654 #if wxUSE_STARTUP_TIPS
655 static size_t s_index
= (size_t)-1;
657 if ( s_index
== (size_t)-1 )
661 // this is completely bogus, we don't know how many lines are there
662 // in the file, but who cares, it's a demo only...
663 s_index
= rand() % 5;
666 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
668 bool showAtStartup
= wxShowTip(this, tipProvider
);
672 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
673 wxOK
| wxICON_INFORMATION
, this);
676 s_index
= tipProvider
->GetCurrentTip();
681 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
686 #if wxUSE_PROGRESSDLG
688 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
690 static const int max
= 10;
692 wxProgressDialog
dialog(_T("Progress dialog example"),
693 _T("An informative message"),
698 // wxPD_AUTO_HIDE | -- try this as well
700 wxPD_ESTIMATED_TIME
|
701 wxPD_REMAINING_TIME
);
704 for ( int i
= 0; i
<= max
; i
++ )
709 cont
= dialog
.Update(i
, _T("That's all, folks!"));
711 else if ( i
== max
/ 2 )
713 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
717 cont
= dialog
.Update(i
);
722 if ( wxMessageBox(_T("Do you really want to cancel?"),
723 _T("Progress dialog question"), // caption
724 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
733 wxLogStatus(wxT("Progress dialog aborted!"));
737 wxLogStatus(wxT("Countdown from %d finished"), max
);
741 #endif // wxUSE_PROGRESSDLG
745 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
747 wxWindowDisabler disableAll
;
749 wxBusyInfo
info(_T("Working, please wait..."), this);
751 for ( int i
= 0; i
< 18; i
++ )
761 #endif // wxUSE_BUSYINFO
763 #if wxUSE_FINDREPLDLG
765 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
774 m_dlgReplace
= new wxFindReplaceDialog
778 _T("Find and replace dialog"),
782 m_dlgReplace
->Show(TRUE
);
786 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
795 m_dlgFind
= new wxFindReplaceDialog
804 m_dlgFind
->Show(TRUE
);
808 static wxString
DecodeFindDialogEventFlags(int flags
)
811 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
812 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
813 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
814 << _T("case sensitive");
819 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
821 wxEventType type
= event
.GetEventType();
823 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
825 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
826 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
827 event
.GetFindString().c_str(),
828 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
830 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
831 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
833 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
834 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
835 event
.GetFindString().c_str(),
836 event
.GetReplaceString().c_str(),
837 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
839 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
841 wxFindReplaceDialog
*dlg
= event
.GetDialog();
845 if ( dlg
== m_dlgFind
)
848 idMenu
= DIALOGS_FIND
;
851 else if ( dlg
== m_dlgReplace
)
854 idMenu
= DIALOGS_REPLACE
;
862 wxFAIL_MSG( _T("unexpected event") );
865 wxLogMessage(wxT("%s dialog is being closed."), txt
);
869 GetMenuBar()->Check(idMenu
, FALSE
);
876 wxLogError(wxT("Unknown find dialog event!"));
880 #endif // wxUSE_FINDREPLDLG
882 // ----------------------------------------------------------------------------
884 // ----------------------------------------------------------------------------
886 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
889 dc
.SetFont(wxGetApp().m_canvasFont
);
890 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
891 dc
.SetBackgroundMode(wxTRANSPARENT
);
892 dc
.DrawText(_T("wxWindows common dialogs test application"), 10, 10);
895 // ----------------------------------------------------------------------------
897 // ----------------------------------------------------------------------------
899 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
900 : wxDialog(parent
, -1, wxString(_T("Modeless dialog")))
902 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
904 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
905 wxCheckBox
*check
= new wxCheckBox(this, -1, _T("Should be disabled"));
908 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
909 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
914 sizerTop
->SetSizeHints(this);
918 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
920 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
921 wxOK
| wxICON_INFORMATION
, this);
924 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
926 if ( event
.CanVeto() )
928 wxMessageBox(_T("Use the menu item to close this dialog"),
929 _T("Modeless dialog"),
930 wxOK
| wxICON_INFORMATION
, this);
936 // ----------------------------------------------------------------------------
938 // ----------------------------------------------------------------------------
940 MyModalDialog::MyModalDialog(wxWindow
*parent
)
941 : wxDialog(parent
, -1, wxString(_T("Modal dialog")))
943 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
945 m_btnModal
= new wxButton(this, -1, _T("&Modal dialog..."));
946 m_btnModeless
= new wxButton(this, -1, _T("Mode&less dialog"));
947 m_btnDelete
= new wxButton(this, -1, _T("&Delete button"));
949 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
950 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
951 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
952 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
953 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
958 sizerTop
->SetSizeHints(this);
961 m_btnModal
->SetFocus();
962 m_btnModal
->SetDefault();
965 void MyModalDialog::OnButton(wxCommandEvent
& event
)
967 if ( event
.GetEventObject() == m_btnDelete
)
972 m_btnDelete
->Disable();
974 else if ( event
.GetEventObject() == m_btnModal
)
976 wxGetTextFromUser(_T("Dummy prompt"),
977 _T("Modal dialog called from dialog"),
980 else if ( event
.GetEventObject() == m_btnModeless
)
982 (new MyModelessDialog(this))->Show();