1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
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 #if defined(__WXMSW__) || defined(__WXMAC__)
75 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
76 #endif // wxMSW || wxMAC
77 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
78 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
79 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
80 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
81 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
82 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
86 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
87 #endif // wxUSE_PROGRESSDLG
90 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
91 #endif // wxUSE_BUSYINFO
94 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
95 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
97 EVT_FIND(-1, MyFrame::OnFindDialog
)
98 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
)
99 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
)
100 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
)
101 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
)
102 #endif // wxUSE_FINDREPLDLG
103 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
106 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
107 EVT_BUTTON(-1, MyModalDialog::OnButton
)
110 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
111 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
113 EVT_CLOSE(MyModelessDialog::OnClose
)
116 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
118 // `Main program' equivalent, creating windows and returning main app frame
121 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
122 wxConvCurrent
= &wxConvLibc
;
125 m_canvasTextColour
= wxColour(_T("BLACK"));
126 m_canvasFont
= *wxNORMAL_FONT
;
128 // Create the main frame window
129 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300));
132 wxMenu
*file_menu
= new wxMenu
;
134 file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
136 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
137 file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("Choose colour (&generic)"));
140 file_menu
->AppendSeparator();
141 file_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
143 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
144 file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose f&ont (generic)"));
147 file_menu
->AppendSeparator();
148 file_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
149 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
150 file_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
151 file_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
152 file_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
153 file_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
154 file_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
155 file_menu
->AppendSeparator();
156 file_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
157 file_menu
->AppendSeparator();
158 file_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
159 file_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
160 file_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
161 file_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
162 file_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
163 #if defined(__WXMSW__) || defined(__WXMAC__)
164 file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic implementation)"));
165 #endif // wxMSW || wxMAC
166 #if wxUSE_PROGRESSDLG
167 file_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
168 #endif // wxUSE_PROGRESSDLG
170 file_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
171 #endif // wxUSE_BUSYINFO
172 #if wxUSE_FINDREPLDLG
173 file_menu
->Append(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"), _T(""), TRUE
);
174 file_menu
->Append(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE
);
175 #endif // wxUSE_FINDREPLDLG
176 file_menu
->AppendSeparator();
177 file_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
178 file_menu
->Append(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE
);
179 file_menu
->AppendSeparator();
180 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
181 wxMenuBar
*menu_bar
= new wxMenuBar
;
182 menu_bar
->Append(file_menu
, _T("&File"));
183 frame
->SetMenuBar(menu_bar
);
185 myCanvas
= new MyCanvas(frame
);
186 myCanvas
->SetBackgroundColour(*wxWHITE
);
188 frame
->Centre(wxBOTH
);
198 // My frame constructor
199 MyFrame::MyFrame(wxWindow
*parent
,
200 const wxString
& title
,
203 : wxFrame(parent
, -1, title
, pos
, size
)
205 m_dialog
= (MyModelessDialog
*)NULL
;
207 #if wxUSE_FINDREPLDLG
215 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
217 wxColour col
= myCanvas
->GetBackgroundColour();
221 data
.SetChooseFull(TRUE
);
222 for (int i
= 0; i
< 16; i
++)
224 wxColour
colour(i
*16, i
*16, i
*16);
225 data
.SetCustomColour(i
, colour
);
228 wxColourDialog
dialog(this, &data
);
229 dialog
.SetTitle(_T("Choose the background colour"));
230 if (dialog
.ShowModal() == wxID_OK
)
232 wxColourData retData
= dialog
.GetColourData();
233 col
= retData
.GetColour();
234 myCanvas
->SetBackgroundColour(col
);
240 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
243 data
.SetInitialFont(wxGetApp().m_canvasFont
);
244 data
.SetColour(wxGetApp().m_canvasTextColour
);
246 // you might also do this:
248 // wxFontDialog dialog;
249 // if ( !dialog.Create(this, data) { ... error ... }
251 wxFontDialog
dialog(this, data
);
253 if (dialog
.ShowModal() == wxID_OK
)
255 wxFontData retData
= dialog
.GetFontData();
256 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
257 wxGetApp().m_canvasTextColour
= retData
.GetColour();
260 //else: cancelled by the user, don't change the font
263 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
264 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
267 data
.SetChooseFull(TRUE
);
268 for (int i
= 0; i
< 16; i
++)
270 wxColour
colour(i
*16, i
*16, i
*16);
271 data
.SetCustomColour(i
, colour
);
274 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
275 if (dialog
->ShowModal() == wxID_OK
)
277 wxColourData retData
= dialog
->GetColourData();
278 wxColour col
= retData
.GetColour();
279 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
280 myCanvas
->SetBackgroundColour(col
);
287 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
290 data
.SetInitialFont(wxGetApp().m_canvasFont
);
291 data
.SetColour(wxGetApp().m_canvasTextColour
);
293 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
294 if (dialog
->ShowModal() == wxID_OK
)
296 wxFontData retData
= dialog
->GetFontData();
297 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
298 wxGetApp().m_canvasTextColour
= retData
.GetColour();
303 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW
305 void MyFrame::LogDialog(wxCommandEvent
& event
)
307 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
308 // being flushed -- test it
311 wxLogMessage(wxT("This is some message - everything is ok so far."));
312 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
313 wxLogWarning(wxT("And then something went wrong!"));
315 // and if ~wxBusyCursor doesn't do it, then call it manually
319 wxLogError(wxT("Intermediary error handler decided to abort."));
320 wxLogError(wxT("The top level caller detected an unrecoverable error."));
322 wxLog::FlushActive();
324 wxLogMessage(wxT("And this is the same dialog but with only one message."));
327 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
329 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
330 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
332 switch ( dialog
.ShowModal() )
335 wxLogStatus(wxT("You pressed \"Yes\""));
339 wxLogStatus(wxT("You pressed \"No\""));
343 wxLogStatus(wxT("You pressed \"Cancel\""));
347 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
351 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
353 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
354 _T("Even two rows of text."),
355 _T("Enter a number:"), _T("Numeric input test"),
362 msg
= _T("Invalid number entered or dialog cancelled.");
367 msg
.Printf(_T("You've entered %lu"), res
);
368 icon
= wxICON_INFORMATION
;
371 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
374 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
376 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
377 _T("Password entry dialog"),
382 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
383 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
387 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
389 wxTextEntryDialog
dialog(this,
390 _T("This is a small sample\n")
391 _T("A long, long string to test out the text entrybox"),
392 _T("Please enter a string"),
396 if (dialog
.ShowModal() == wxID_OK
)
398 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
403 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
405 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
407 wxSingleChoiceDialog
dialog(this,
408 _T("This is a small sample\n")
409 _T("A single-choice convenience dialog"),
410 _T("Please select a value"),
411 WXSIZEOF(choices
), choices
);
413 dialog
.SetSelection(2);
415 if (dialog
.ShowModal() == wxID_OK
)
417 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
422 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
424 const wxString choices
[] =
426 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
427 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
428 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
431 wxArrayInt selections
;
432 size_t count
= wxGetMultipleChoices(selections
,
433 _T("This is a small sample\n")
434 _T("A multi-choice convenience dialog"),
435 _T("Please select a value"),
436 WXSIZEOF(choices
), choices
,
441 msg
.Printf(wxT("You selected %u items:\n"), count
);
442 for ( size_t n
= 0; n
< count
; n
++ )
444 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"), n
, selections
[n
],
445 choices
[selections
[n
]].c_str());
449 //else: cancelled or nothing selected
452 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
457 _T("Testing open file dialog"),
461 _T("C++ files (*.cpp)|*.cpp")
463 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
467 dialog
.SetDirectory(wxGetHomeDir());
469 if (dialog
.ShowModal() == wxID_OK
)
472 info
.Printf(_T("Full file name: %s\n")
475 dialog
.GetPath().c_str(),
476 dialog
.GetDirectory().c_str(),
477 dialog
.GetFilename().c_str());
478 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
483 // this shows how to take advantage of specifying a default extension in the
484 // call to wxFileSelector: it is remembered after each new call and the next
485 // one will use it by default
486 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
488 static wxString s_extDef
;
489 wxString path
= wxFileSelector(
490 _T("Select the file to load"),
493 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
501 // it is just a sample, would use wxSplitPath in real program
502 s_extDef
= path
.AfterLast(_T('.'));
504 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
505 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
508 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
510 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
511 _T(""), _T(""), wxFileSelectorDefaultWildcardStr
,
514 if (dialog
.ShowModal() == wxID_OK
)
516 wxArrayString paths
, filenames
;
518 dialog
.GetPaths(paths
);
519 dialog
.GetFilenames(filenames
);
522 size_t count
= paths
.GetCount();
523 for ( size_t n
= 0; n
< count
; n
++ )
525 s
.Printf(_T("File %d: %s (%s)\n"),
526 n
, paths
[n
].c_str(), filenames
[n
].c_str());
531 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
536 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
538 wxFileDialog
dialog(this,
539 _T("Testing save file dialog"),
542 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
543 wxSAVE
|wxOVERWRITE_PROMPT
);
545 dialog
.SetFilterIndex(1);
547 if (dialog
.ShowModal() == wxID_OK
)
549 wxLogMessage(_T("%s, filter %d"),
550 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
554 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
556 // pass some initial dir to wxDirDialog
558 wxGetHomeDir(&dirHome
);
560 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
);
562 if (dialog
.ShowModal() == wxID_OK
)
564 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
568 #if defined(__WXMSW__) || defined(__WXMAC__)
570 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
572 #if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
573 // pass some initial dir to wxDirDialog
575 wxGetHomeDir(&dirHome
);
577 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
579 if (dialog
.ShowModal() == wxID_OK
)
581 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
585 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
586 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
590 #endif // wxMSW || wxMAC
592 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
594 MyModalDialog
dlg(this);
598 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
600 bool show
= GetMenuBar()->IsChecked(event
.GetId());
606 m_dialog
= new MyModelessDialog(this);
609 m_dialog
->Show(TRUE
);
617 void MyFrame::ShowTip(wxCommandEvent
& event
)
619 #if wxUSE_STARTUP_TIPS
620 static size_t s_index
= (size_t)-1;
622 if ( s_index
== (size_t)-1 )
626 // this is completely bogus, we don't know how many lines are there
627 // in the file, but who cares, it's a demo only...
628 s_index
= rand() % 5;
631 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
633 bool showAtStartup
= wxShowTip(this, tipProvider
);
637 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
638 wxOK
| wxICON_INFORMATION
, this);
641 s_index
= tipProvider
->GetCurrentTip();
646 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
651 #if wxUSE_PROGRESSDLG
653 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
655 static const int max
= 10;
657 wxProgressDialog
dialog(_T("Progress dialog example"),
658 _T("An informative message"),
663 // wxPD_AUTO_HIDE | -- try this as well
665 wxPD_ESTIMATED_TIME
|
666 wxPD_REMAINING_TIME
);
669 for ( int i
= 0; i
<= max
; i
++ )
674 cont
= dialog
.Update(i
, _T("That's all, folks!"));
676 else if ( i
== max
/ 2 )
678 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
682 cont
= dialog
.Update(i
);
687 if ( wxMessageBox(_T("Do you really want to cancel?"),
688 _T("Progress dialog question"), // caption
689 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
698 wxLogStatus(wxT("Progress dialog aborted!"));
702 wxLogStatus(wxT("Countdown from %d finished"), max
);
706 #endif // wxUSE_PROGRESSDLG
710 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
712 wxWindowDisabler disableAll
;
714 wxBusyInfo
info(_T("Working, please wait..."), this);
716 for ( int i
= 0; i
< 18; i
++ )
726 #endif // wxUSE_BUSYINFO
728 #if wxUSE_FINDREPLDLG
730 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
739 m_dlgReplace
= new wxFindReplaceDialog
743 _T("Find and replace dialog"),
747 m_dlgReplace
->Show(TRUE
);
751 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
760 m_dlgFind
= new wxFindReplaceDialog
769 m_dlgFind
->Show(TRUE
);
773 static wxString
DecodeFindDialogEventFlags(int flags
)
776 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
777 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
778 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
779 << _T("case sensitive");
784 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
786 wxEventType type
= event
.GetEventType();
788 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
790 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
791 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
792 event
.GetFindString().c_str(),
793 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
795 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
796 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
798 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
799 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
800 event
.GetFindString().c_str(),
801 event
.GetReplaceString().c_str(),
802 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
804 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
806 wxFindReplaceDialog
*dlg
= event
.GetDialog();
810 if ( dlg
== m_dlgFind
)
813 idMenu
= DIALOGS_FIND
;
816 else if ( dlg
== m_dlgReplace
)
819 idMenu
= DIALOGS_REPLACE
;
827 wxFAIL_MSG( _T("unexpected event") );
830 wxLogMessage(wxT("%s dialog is being closed."), txt
);
834 GetMenuBar()->Check(idMenu
, FALSE
);
841 wxLogError(wxT("Unknown find dialog event!"));
845 #endif // wxUSE_FINDREPLDLG
847 // ----------------------------------------------------------------------------
849 // ----------------------------------------------------------------------------
851 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
854 dc
.SetFont(wxGetApp().m_canvasFont
);
855 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
856 dc
.SetBackgroundMode(wxTRANSPARENT
);
857 dc
.DrawText(_T("wxWindows common dialogs test application"), 10, 10);
860 // ----------------------------------------------------------------------------
862 // ----------------------------------------------------------------------------
864 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
865 : wxDialog(parent
, -1, wxString(_T("Modeless dialog")))
867 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
869 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
870 wxCheckBox
*check
= new wxCheckBox(this, -1, _T("Should be disabled"));
873 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
874 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
879 sizerTop
->SetSizeHints(this);
883 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
885 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
886 wxOK
| wxICON_INFORMATION
, this);
889 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
891 if ( event
.CanVeto() )
893 wxMessageBox(_T("Use the menu item to close this dialog"),
894 _T("Modeless dialog"),
895 wxOK
| wxICON_INFORMATION
, this);
901 // ----------------------------------------------------------------------------
903 // ----------------------------------------------------------------------------
905 MyModalDialog::MyModalDialog(wxWindow
*parent
)
906 : wxDialog(parent
, -1, wxString(_T("Modal dialog")))
908 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
910 m_btnFocused
= new wxButton(this, -1, _T("Default button"));
911 m_btnDelete
= new wxButton(this, -1, _T("&Delete button"));
912 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
913 sizerTop
->Add(m_btnFocused
, 0, wxALIGN_CENTER
| wxALL
, 5);
914 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
915 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
920 sizerTop
->SetSizeHints(this);
923 m_btnFocused
->SetFocus();
924 m_btnFocused
->SetDefault();
927 void MyModalDialog::OnButton(wxCommandEvent
& event
)
929 if ( event
.GetEventObject() == m_btnDelete
)
934 m_btnDelete
->Disable();
936 else if ( event
.GetEventObject() == m_btnFocused
)
938 wxGetTextFromUser(_T("Dummy prompt"),
939 _T("Modal dialog called from dialog"),