1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
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 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
75 #if defined(__WXMSW__) || defined(__WXMAC__)
76 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
77 #endif // wxMSW || wxMAC
78 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
79 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
80 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
81 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
82 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
83 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
87 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
88 #endif // wxUSE_PROGRESSDLG
91 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
92 #endif // wxUSE_BUSYINFO
95 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
96 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
98 EVT_FIND(-1, MyFrame::OnFindDialog
)
99 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
)
100 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
)
101 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
)
102 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
)
103 #endif // wxUSE_FINDREPLDLG
104 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
107 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
108 EVT_BUTTON(-1, MyModalDialog::OnButton
)
111 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
112 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
114 EVT_CLOSE(MyModelessDialog::OnClose
)
117 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
119 // `Main program' equivalent, creating windows and returning main app frame
122 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
123 wxConvCurrent
= &wxConvLibc
;
126 m_canvasTextColour
= wxColour(_T("BLACK"));
127 m_canvasFont
= *wxNORMAL_FONT
;
129 // Create the main frame window
130 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300));
133 wxMenu
*file_menu
= new wxMenu
;
135 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
137 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
138 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("Choose colour (&generic)"));
141 file_menu
->AppendSeparator();
142 file_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
144 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
145 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose f&ont (generic)"));
148 file_menu
->AppendSeparator();
149 file_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
150 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
151 file_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
152 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
153 file_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
154 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
155 file_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
156 file_menu
->AppendSeparator();
157 file_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
158 file_menu
->AppendSeparator();
159 file_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
160 file_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
161 file_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
162 file_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
163 file_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
164 file_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
165 #if defined(__WXMSW__) || defined(__WXMAC__)
166 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic implementation)"));
167 #endif // wxMSW || wxMAC
168 file_menu
->AppendSeparator();
170 #if wxUSE_PROGRESSDLG
171 file_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
172 #endif // wxUSE_PROGRESSDLG
174 file_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
175 #endif // wxUSE_BUSYINFO
176 #if wxUSE_FINDREPLDLG
177 file_menu
->Append(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"), _T(""), TRUE
);
178 file_menu
->Append(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE
);
179 #endif // wxUSE_FINDREPLDLG
180 file_menu
->AppendSeparator();
182 file_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
183 file_menu
->Append(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE
);
184 file_menu
->AppendSeparator();
186 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
187 wxMenuBar
*menu_bar
= new wxMenuBar
;
188 menu_bar
->Append(file_menu
, _T("&File"));
189 frame
->SetMenuBar(menu_bar
);
191 myCanvas
= new MyCanvas(frame
);
192 myCanvas
->SetBackgroundColour(*wxWHITE
);
194 frame
->Centre(wxBOTH
);
204 // My frame constructor
205 MyFrame::MyFrame(wxWindow
*parent
,
206 const wxString
& title
,
209 : wxFrame(parent
, -1, title
, pos
, size
)
211 m_dialog
= (MyModelessDialog
*)NULL
;
213 #if wxUSE_FINDREPLDLG
221 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
223 wxColour col
= myCanvas
->GetBackgroundColour();
227 data
.SetChooseFull(TRUE
);
228 for (int i
= 0; i
< 16; i
++)
230 wxColour
colour(i
*16, i
*16, i
*16);
231 data
.SetCustomColour(i
, colour
);
234 wxColourDialog
dialog(this, &data
);
235 dialog
.SetTitle(_T("Choose the background colour"));
236 if (dialog
.ShowModal() == wxID_OK
)
238 wxColourData retData
= dialog
.GetColourData();
239 col
= retData
.GetColour();
240 myCanvas
->SetBackgroundColour(col
);
246 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
249 data
.SetInitialFont(wxGetApp().m_canvasFont
);
250 data
.SetColour(wxGetApp().m_canvasTextColour
);
252 // you might also do this:
254 // wxFontDialog dialog;
255 // if ( !dialog.Create(this, data) { ... error ... }
257 wxFontDialog
dialog(this, data
);
259 if (dialog
.ShowModal() == wxID_OK
)
261 wxFontData retData
= dialog
.GetFontData();
262 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
263 wxGetApp().m_canvasTextColour
= retData
.GetColour();
266 //else: cancelled by the user, don't change the font
269 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
270 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
273 data
.SetChooseFull(TRUE
);
274 for (int i
= 0; i
< 16; i
++)
276 wxColour
colour(i
*16, i
*16, i
*16);
277 data
.SetCustomColour(i
, colour
);
280 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
281 if (dialog
->ShowModal() == wxID_OK
)
283 wxColourData retData
= dialog
->GetColourData();
284 wxColour col
= retData
.GetColour();
285 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
286 myCanvas
->SetBackgroundColour(col
);
293 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
296 data
.SetInitialFont(wxGetApp().m_canvasFont
);
297 data
.SetColour(wxGetApp().m_canvasTextColour
);
299 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
300 if (dialog
->ShowModal() == wxID_OK
)
302 wxFontData retData
= dialog
->GetFontData();
303 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
304 wxGetApp().m_canvasTextColour
= retData
.GetColour();
309 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
311 void MyFrame::LogDialog(wxCommandEvent
& event
)
313 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
314 // being flushed -- test it
317 wxLogMessage(wxT("This is some message - everything is ok so far."));
318 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
319 wxLogWarning(wxT("And then something went wrong!"));
321 // and if ~wxBusyCursor doesn't do it, then call it manually
325 wxLogError(wxT("Intermediary error handler decided to abort."));
326 wxLogError(wxT("The top level caller detected an unrecoverable error."));
328 wxLog::FlushActive();
330 wxLogMessage(wxT("And this is the same dialog but with only one message."));
333 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
335 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
336 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
338 switch ( dialog
.ShowModal() )
341 wxLogStatus(wxT("You pressed \"Yes\""));
345 wxLogStatus(wxT("You pressed \"No\""));
349 wxLogStatus(wxT("You pressed \"Cancel\""));
353 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
357 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
359 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
360 _T("Even two rows of text."),
361 _T("Enter a number:"), _T("Numeric input test"),
368 msg
= _T("Invalid number entered or dialog cancelled.");
373 msg
.Printf(_T("You've entered %lu"), res
);
374 icon
= wxICON_INFORMATION
;
377 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
380 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
382 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
383 _T("Password entry dialog"),
388 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
389 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
393 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
395 wxTextEntryDialog
dialog(this,
396 _T("This is a small sample\n")
397 _T("A long, long string to test out the text entrybox"),
398 _T("Please enter a string"),
402 if (dialog
.ShowModal() == wxID_OK
)
404 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
409 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
411 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
413 wxSingleChoiceDialog
dialog(this,
414 _T("This is a small sample\n")
415 _T("A single-choice convenience dialog"),
416 _T("Please select a value"),
417 WXSIZEOF(choices
), choices
);
419 dialog
.SetSelection(2);
421 if (dialog
.ShowModal() == wxID_OK
)
423 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
428 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
430 const wxString choices
[] =
432 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
433 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
434 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
437 wxArrayInt selections
;
438 size_t count
= wxGetMultipleChoices(selections
,
439 _T("This is a small sample\n")
440 _T("A multi-choice convenience dialog"),
441 _T("Please select a value"),
442 WXSIZEOF(choices
), choices
,
447 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
448 for ( size_t n
= 0; n
< count
; n
++ )
450 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
451 (unsigned)n
, (unsigned)selections
[n
],
452 choices
[selections
[n
]].c_str());
456 //else: cancelled or nothing selected
459 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
464 _T("Testing open file dialog"),
468 _T("C++ files (*.cpp)|*.cpp")
470 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
474 dialog
.SetDirectory(wxGetHomeDir());
476 if (dialog
.ShowModal() == wxID_OK
)
479 info
.Printf(_T("Full file name: %s\n")
482 dialog
.GetPath().c_str(),
483 dialog
.GetDirectory().c_str(),
484 dialog
.GetFilename().c_str());
485 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
490 // this shows how to take advantage of specifying a default extension in the
491 // call to wxFileSelector: it is remembered after each new call and the next
492 // one will use it by default
493 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
495 static wxString s_extDef
;
496 wxString path
= wxFileSelector(
497 _T("Select the file to load"),
500 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
508 // it is just a sample, would use wxSplitPath in real program
509 s_extDef
= path
.AfterLast(_T('.'));
511 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
512 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
515 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
517 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
518 _T(""), _T(""), wxFileSelectorDefaultWildcardStr
,
521 if (dialog
.ShowModal() == wxID_OK
)
523 wxArrayString paths
, filenames
;
525 dialog
.GetPaths(paths
);
526 dialog
.GetFilenames(filenames
);
529 size_t count
= paths
.GetCount();
530 for ( size_t n
= 0; n
< count
; n
++ )
532 s
.Printf(_T("File %d: %s (%s)\n"),
533 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
538 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
543 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
545 wxFileDialog
dialog(this,
546 _T("Testing save file dialog"),
549 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
550 wxSAVE
|wxOVERWRITE_PROMPT
);
552 dialog
.SetFilterIndex(1);
554 if (dialog
.ShowModal() == wxID_OK
)
556 wxLogMessage(_T("%s, filter %d"),
557 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
561 void MyFrame::DoDirChoose(int style
)
563 // pass some initial dir to wxDirDialog
565 wxGetHomeDir(&dirHome
);
567 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
569 if (dialog
.ShowModal() == wxID_OK
)
571 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
575 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
577 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
580 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
582 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
585 #if defined(__WXMSW__) || defined(__WXMAC__)
587 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
589 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
590 // pass some initial dir to wxDirDialog
592 wxGetHomeDir(&dirHome
);
594 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
596 if (dialog
.ShowModal() == wxID_OK
)
598 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
602 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
603 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
607 #endif // wxMSW || wxMAC
609 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
611 MyModalDialog
dlg(this);
615 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
617 bool show
= GetMenuBar()->IsChecked(event
.GetId());
623 m_dialog
= new MyModelessDialog(this);
626 m_dialog
->Show(TRUE
);
634 void MyFrame::ShowTip(wxCommandEvent
& event
)
636 #if wxUSE_STARTUP_TIPS
637 static size_t s_index
= (size_t)-1;
639 if ( s_index
== (size_t)-1 )
643 // this is completely bogus, we don't know how many lines are there
644 // in the file, but who cares, it's a demo only...
645 s_index
= rand() % 5;
648 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
650 bool showAtStartup
= wxShowTip(this, tipProvider
);
654 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
655 wxOK
| wxICON_INFORMATION
, this);
658 s_index
= tipProvider
->GetCurrentTip();
663 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
668 #if wxUSE_PROGRESSDLG
670 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
672 static const int max
= 10;
674 wxProgressDialog
dialog(_T("Progress dialog example"),
675 _T("An informative message"),
680 // wxPD_AUTO_HIDE | -- try this as well
682 wxPD_ESTIMATED_TIME
|
683 wxPD_REMAINING_TIME
);
686 for ( int i
= 0; i
<= max
; i
++ )
691 cont
= dialog
.Update(i
, _T("That's all, folks!"));
693 else if ( i
== max
/ 2 )
695 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
699 cont
= dialog
.Update(i
);
704 if ( wxMessageBox(_T("Do you really want to cancel?"),
705 _T("Progress dialog question"), // caption
706 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
715 wxLogStatus(wxT("Progress dialog aborted!"));
719 wxLogStatus(wxT("Countdown from %d finished"), max
);
723 #endif // wxUSE_PROGRESSDLG
727 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
729 wxWindowDisabler disableAll
;
731 wxBusyInfo
info(_T("Working, please wait..."), this);
733 for ( int i
= 0; i
< 18; i
++ )
743 #endif // wxUSE_BUSYINFO
745 #if wxUSE_FINDREPLDLG
747 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
756 m_dlgReplace
= new wxFindReplaceDialog
760 _T("Find and replace dialog"),
764 m_dlgReplace
->Show(TRUE
);
768 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
777 m_dlgFind
= new wxFindReplaceDialog
786 m_dlgFind
->Show(TRUE
);
790 static wxString
DecodeFindDialogEventFlags(int flags
)
793 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
794 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
795 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
796 << _T("case sensitive");
801 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
803 wxEventType type
= event
.GetEventType();
805 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
807 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
808 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
809 event
.GetFindString().c_str(),
810 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
812 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
813 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
815 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
816 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
817 event
.GetFindString().c_str(),
818 event
.GetReplaceString().c_str(),
819 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
821 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
823 wxFindReplaceDialog
*dlg
= event
.GetDialog();
827 if ( dlg
== m_dlgFind
)
830 idMenu
= DIALOGS_FIND
;
833 else if ( dlg
== m_dlgReplace
)
836 idMenu
= DIALOGS_REPLACE
;
844 wxFAIL_MSG( _T("unexpected event") );
847 wxLogMessage(wxT("%s dialog is being closed."), txt
);
851 GetMenuBar()->Check(idMenu
, FALSE
);
858 wxLogError(wxT("Unknown find dialog event!"));
862 #endif // wxUSE_FINDREPLDLG
864 // ----------------------------------------------------------------------------
866 // ----------------------------------------------------------------------------
868 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
871 dc
.SetFont(wxGetApp().m_canvasFont
);
872 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
873 dc
.SetBackgroundMode(wxTRANSPARENT
);
874 dc
.DrawText(_T("wxWindows common dialogs test application"), 10, 10);
877 // ----------------------------------------------------------------------------
879 // ----------------------------------------------------------------------------
881 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
882 : wxDialog(parent
, -1, wxString(_T("Modeless dialog")))
884 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
886 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
887 wxCheckBox
*check
= new wxCheckBox(this, -1, _T("Should be disabled"));
890 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
891 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
896 sizerTop
->SetSizeHints(this);
900 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
902 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
903 wxOK
| wxICON_INFORMATION
, this);
906 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
908 if ( event
.CanVeto() )
910 wxMessageBox(_T("Use the menu item to close this dialog"),
911 _T("Modeless dialog"),
912 wxOK
| wxICON_INFORMATION
, this);
918 // ----------------------------------------------------------------------------
920 // ----------------------------------------------------------------------------
922 MyModalDialog::MyModalDialog(wxWindow
*parent
)
923 : wxDialog(parent
, -1, wxString(_T("Modal dialog")))
925 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
927 m_btnModal
= new wxButton(this, -1, _T("&Modal dialog..."));
928 m_btnModeless
= new wxButton(this, -1, _T("Mode&less dialog"));
929 m_btnDelete
= new wxButton(this, -1, _T("&Delete button"));
931 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
932 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
933 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
934 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
935 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
940 sizerTop
->SetSizeHints(this);
943 m_btnModal
->SetFocus();
944 m_btnModal
->SetDefault();
947 void MyModalDialog::OnButton(wxCommandEvent
& event
)
949 if ( event
.GetEventObject() == m_btnDelete
)
954 m_btnDelete
->Disable();
956 else if ( event
.GetEventObject() == m_btnModal
)
958 wxGetTextFromUser(_T("Dummy prompt"),
959 _T("Modal dialog called from dialog"),
962 else if ( event
.GetEventObject() == m_btnModeless
)
964 (new MyModelessDialog(this))->Show();