1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustementd for conditional building
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"
31 #include "wx/colordlg.h"
32 #endif // wxUSE_COLOURDLG
35 #include "wx/choicdlg.h"
36 #endif // wxUSE_CHOICEDLG
38 #if wxUSE_STARTUP_TIPS
39 #include "wx/tipdlg.h"
40 #endif // wxUSE_STARTUP_TIPS
43 #include "wx/progdlg.h"
44 #endif // wxUSE_PROGRESSDLG
47 #include "wx/busyinfo.h"
48 #endif // wxUSE_BUSYINFO
51 #include "wx/numdlg.h"
52 #endif // wxUSE_NUMBERDLG
55 #include "wx/filedlg.h"
56 #endif // wxUSE_FILEDLG
59 #include "wx/dirdlg.h"
60 #endif // wxUSE_DIRDLG
63 #include "wx/fontdlg.h"
64 #endif // wxUSE_FONTDLG
67 #include "wx/fdrepdlg.h"
68 #endif // wxUSE_FINDREPLDLG
72 #if USE_COLOURDLG_GENERIC
73 #include "wx/generic/colrdlgg.h"
74 #endif // USE_COLOURDLG_GENERIC
76 #if USE_FONTDLG_GENERIC
77 #include "wx/generic/fontdlgg.h"
78 #endif // USE_FONTDLG_GENERIC
80 #if USE_DIRDLG_GENERIC
81 #include "wx/generic/dirdlgg.h"
82 #endif // USE_DIRDLG_GENERIC
86 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
87 EVT_PAINT(MyCanvas::OnPaint
)
92 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
93 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
96 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
97 #endif // wxUSE_COLOURDLG
100 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
101 #endif // wxUSE_FONTDLG
104 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
105 #endif // wxUSE_LOG_DIALOG
108 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
109 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
110 #endif // wxUSE_TEXTDLG
113 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
114 #endif // wxUSE_NUMBERDLG
117 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
118 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
119 #endif // wxUSE_CHOICEDLG
122 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
123 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
124 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
125 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
126 #endif // wxUSE_FILEDLG
129 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
130 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
131 #endif // wxUSE_DIRDLG
133 #if USE_MODAL_PRESENTATION
134 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
135 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
138 #if wxUSE_STARTUP_TIPS
139 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
140 #endif // wxUSE_STARTUP_TIPS
142 #if USE_FONTDLG_GENERIC
143 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
144 #endif // USE_FONTDLG_GENERIC
146 #if USE_DIRDLG_GENERIC
147 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
148 #endif // wxMSW || wxMAC
150 #if USE_COLOURDLG_GENERIC
151 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
152 #endif // USE_COLOURDLG_GENERIC
154 #if wxUSE_PROGRESSDLG
155 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
156 #endif // wxUSE_PROGRESSDLG
159 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
160 #endif // wxUSE_BUSYINFO
162 #if wxUSE_FINDREPLDLG
163 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
164 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
166 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
167 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
168 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
169 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
170 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
171 #endif // wxUSE_FINDREPLDLG
173 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
176 #if USE_MODAL_PRESENTATION
178 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
179 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
182 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
183 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
184 EVT_CLOSE(MyModelessDialog::OnClose
)
187 #endif // USE_MODAL_PRESENTATION
189 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
191 // `Main program' equivalent, creating windows and returning main app frame
195 wxInitAllImageHandlers();
198 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
199 wxConvCurrent
= &wxConvLibc
;
202 m_canvasTextColour
= wxColour(_T("BLACK"));
203 m_canvasFont
= *wxNORMAL_FONT
;
205 // Create the main frame window
206 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
209 wxMenu
*file_menu
= new wxMenu
;
211 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
214 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
216 wxMenu
*choices_menu
= new wxMenu
;
219 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
220 #endif // wxUSE_COLOURDLG
222 #if USE_COLOURDLG_GENERIC
223 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
224 #endif // USE_COLOURDLG_GENERIC
227 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
228 #endif // wxUSE_FONTDLG
230 #if USE_FONTDLG_GENERIC
231 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
232 #endif // USE_FONTDLG_GENERIC
235 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
236 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
237 #endif // wxUSE_CHOICEDLG
239 file_menu
->Append(wxID_ANY
,_T("Choices and selectors"),choices_menu
);
241 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
244 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
246 wxMenu
*entry_menu
= new wxMenu
;
249 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
250 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
251 #endif // wxUSE_TEXTDLG
254 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
255 #endif // wxUSE_NUMBERDLG
257 file_menu
->Append(wxID_ANY
,_T("Entry dialogs"),entry_menu
);
264 wxMenu
*filedlg_menu
= new wxMenu
;
265 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
266 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
267 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
268 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
269 file_menu
->Append(wxID_ANY
,_T("File operations"),filedlg_menu
);
271 #endif // wxUSE_FILEDLG
274 wxMenu
*dir_menu
= new wxMenu
;
276 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
278 #if USE_DIRDLG_GENERIC
279 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
280 #endif // USE_DIRDLG_GENERIC
282 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
283 file_menu
->Append(wxID_ANY
,_T("Directory operations"),dir_menu
);
285 #endif // wxUSE_DIRDLG
288 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
290 wxMenu
*info_menu
= new wxMenu
;
292 #if wxUSE_STARTUP_TIPS
293 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
294 #endif // wxUSE_STARTUP_TIPS
296 #if wxUSE_PROGRESSDLG
297 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
298 #endif // wxUSE_PROGRESSDLG
301 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
302 #endif // wxUSE_BUSYINFO
305 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
306 #endif // wxUSE_LOG_DIALOG
308 file_menu
->Append(wxID_ANY
,_T("Informative dialogs"),info_menu
);
310 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
313 #if wxUSE_FINDREPLDLG
314 wxMenu
*find_menu
= new wxMenu
;
315 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
316 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
317 file_menu
->Append(wxID_ANY
,_T("Searching"),find_menu
);
318 #endif // wxUSE_FINDREPLDLG
320 #if USE_MODAL_PRESENTATION
321 wxMenu
*modal_menu
= new wxMenu
;
322 modal_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
323 modal_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"));
324 file_menu
->Append(wxID_ANY
,_T("Modal/Modeless"),modal_menu
);
325 #endif // USE_MODAL_PRESENTATION
327 file_menu
->AppendSeparator();
328 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
330 wxMenuBar
*menu_bar
= new wxMenuBar
;
331 menu_bar
->Append(file_menu
, _T("&File"));
332 frame
->SetMenuBar(menu_bar
);
334 myCanvas
= new MyCanvas(frame
);
335 myCanvas
->SetBackgroundColour(*wxWHITE
);
337 frame
->Centre(wxBOTH
);
347 // My frame constructor
348 MyFrame::MyFrame(wxWindow
*parent
,
349 const wxString
& title
)
350 : wxFrame(parent
, wxID_ANY
, title
)
352 #if USE_MODAL_PRESENTATION
353 m_dialog
= (MyModelessDialog
*)NULL
;
354 #endif // USE_MODAL_PRESENTATION
356 #if wxUSE_FINDREPLDLG
362 m_clrData
.SetChooseFull(true);
363 for (int i
= 0; i
< 16; i
++)
365 m_clrData
.SetCustomColour(i
, wxColour(i
*16, i
*16, i
*16));
367 #endif // wxUSE_COLOURDLG
373 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
375 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
377 wxColourDialog
dialog(this, &m_clrData
);
378 dialog
.SetTitle(_T("Choose the background colour"));
379 if (dialog
.ShowModal() == wxID_OK
)
381 m_clrData
= dialog
.GetColourData();
382 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
383 myCanvas
->ClearBackground();
387 #endif // wxUSE_COLOURDLG
390 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
393 data
.SetInitialFont(wxGetApp().m_canvasFont
);
394 data
.SetColour(wxGetApp().m_canvasTextColour
);
396 // you might also do this:
398 // wxFontDialog dialog;
399 // if ( !dialog.Create(this, data) { ... error ... }
401 wxFontDialog
dialog(this, data
);
403 if (dialog
.ShowModal() == wxID_OK
)
405 wxFontData retData
= dialog
.GetFontData();
406 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
407 wxGetApp().m_canvasTextColour
= retData
.GetColour();
410 //else: cancelled by the user, don't change the font
412 #endif // wxUSE_FONTDLG
414 #if USE_COLOURDLG_GENERIC
415 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
418 data
.SetChooseFull(true);
419 for (int i
= 0; i
< 16; i
++)
421 wxColour
colour(i
*16, i
*16, i
*16);
422 data
.SetCustomColour(i
, colour
);
425 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
426 if (dialog
->ShowModal() == wxID_OK
)
428 wxColourData retData
= dialog
->GetColourData();
429 wxColour col
= retData
.GetColour();
430 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
431 myCanvas
->SetBackgroundColour(col
);
432 myCanvas
->ClearBackground();
437 #endif // USE_COLOURDLG_GENERIC
439 #if USE_FONTDLG_GENERIC
440 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
443 data
.SetInitialFont(wxGetApp().m_canvasFont
);
444 data
.SetColour(wxGetApp().m_canvasTextColour
);
446 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
447 if (dialog
->ShowModal() == wxID_OK
)
449 wxFontData retData
= dialog
->GetFontData();
450 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
451 wxGetApp().m_canvasTextColour
= retData
.GetColour();
456 #endif // USE_FONTDLG_GENERIC
458 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
460 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
461 // being flushed -- test it
464 wxLogMessage(wxT("This is some message - everything is ok so far."));
465 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
466 wxLogWarning(wxT("And then something went wrong!"));
468 // and if ~wxBusyCursor doesn't do it, then call it manually
472 wxLogError(wxT("Intermediary error handler decided to abort."));
473 wxLogError(wxT("The top level caller detected an unrecoverable error."));
475 wxLog::FlushActive();
477 wxLogMessage(wxT("And this is the same dialog but with only one message."));
480 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
482 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
483 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
485 switch ( dialog
.ShowModal() )
488 wxLogStatus(wxT("You pressed \"Yes\""));
492 wxLogStatus(wxT("You pressed \"No\""));
496 wxLogStatus(wxT("You pressed \"Cancel\""));
500 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
505 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
507 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
508 _T("Even two rows of text."),
509 _T("Enter a number:"), _T("Numeric input test"),
516 msg
= _T("Invalid number entered or dialog cancelled.");
521 msg
.Printf(_T("You've entered %lu"), res
);
522 icon
= wxICON_INFORMATION
;
525 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
527 #endif // wxUSE_NUMBERDLG
530 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
532 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
533 _T("Password entry dialog"),
538 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
539 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
543 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
545 wxTextEntryDialog
dialog(this,
546 _T("This is a small sample\n")
547 _T("A long, long string to test out the text entrybox"),
548 _T("Please enter a string"),
552 if (dialog
.ShowModal() == wxID_OK
)
554 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
558 #endif // wxUSE_TEXTDLG
561 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
563 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
565 wxSingleChoiceDialog
dialog(this,
566 _T("This is a small sample\n")
567 _T("A single-choice convenience dialog"),
568 _T("Please select a value"),
569 WXSIZEOF(choices
), choices
);
571 dialog
.SetSelection(2);
573 if (dialog
.ShowModal() == wxID_OK
)
575 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
580 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
582 const wxString choices
[] =
584 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
585 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
586 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
589 wxArrayInt selections
;
590 size_t count
= wxGetMultipleChoices(selections
,
591 _T("This is a small sample\n")
592 _T("A multi-choice convenience dialog"),
593 _T("Please select a value"),
594 WXSIZEOF(choices
), choices
,
599 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
600 for ( size_t n
= 0; n
< count
; n
++ )
602 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
603 (unsigned)n
, (unsigned)selections
[n
],
604 choices
[selections
[n
]].c_str());
608 //else: cancelled or nothing selected
610 #endif // wxUSE_CHOICEDLG
613 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
618 _T("Testing open file dialog"),
622 _T("C++ files (*.cpp)|*.cpp")
624 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
628 dialog
.SetDirectory(wxGetHomeDir());
630 if (dialog
.ShowModal() == wxID_OK
)
633 info
.Printf(_T("Full file name: %s\n")
636 dialog
.GetPath().c_str(),
637 dialog
.GetDirectory().c_str(),
638 dialog
.GetFilename().c_str());
639 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
644 // this shows how to take advantage of specifying a default extension in the
645 // call to wxFileSelector: it is remembered after each new call and the next
646 // one will use it by default
647 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
649 static wxString s_extDef
;
650 wxString path
= wxFileSelector(
651 _T("Select the file to load"),
652 wxEmptyString
, wxEmptyString
,
654 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
662 // it is just a sample, would use wxSplitPath in real program
663 s_extDef
= path
.AfterLast(_T('.'));
665 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
666 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
669 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
673 _T("C++ files (*.cpp)|*.cpp");
675 _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
677 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
678 wxEmptyString
, wxEmptyString
, wildcards
,
681 if (dialog
.ShowModal() == wxID_OK
)
683 wxArrayString paths
, filenames
;
685 dialog
.GetPaths(paths
);
686 dialog
.GetFilenames(filenames
);
689 size_t count
= paths
.GetCount();
690 for ( size_t n
= 0; n
< count
; n
++ )
692 s
.Printf(_T("File %d: %s (%s)\n"),
693 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
697 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
700 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
705 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
707 wxFileDialog
dialog(this,
708 _T("Testing save file dialog"),
711 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
712 wxSAVE
|wxOVERWRITE_PROMPT
);
714 dialog
.SetFilterIndex(1);
716 if (dialog
.ShowModal() == wxID_OK
)
718 wxLogMessage(_T("%s, filter %d"),
719 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
722 #endif // wxUSE_FILEDLG
725 void MyFrame::DoDirChoose(int style
)
727 // pass some initial dir to wxDirDialog
729 wxGetHomeDir(&dirHome
);
731 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
733 if (dialog
.ShowModal() == wxID_OK
)
735 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
739 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
741 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
744 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
746 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
748 #endif // wxUSE_DIRDLG
750 #if USE_DIRDLG_GENERIC
751 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
753 // pass some initial dir to wxDirDialog
755 wxGetHomeDir(&dirHome
);
757 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
759 if (dialog
.ShowModal() == wxID_OK
)
761 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
765 #endif // USE_DIRDLG_GENERIC
767 #if USE_MODAL_PRESENTATION
768 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
770 MyModalDialog
dlg(this);
774 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
776 bool show
= GetMenuBar()->IsChecked(event
.GetId());
782 m_dialog
= new MyModelessDialog(this);
785 m_dialog
->Show(true);
792 #endif // USE_MODAL_PRESENTATION
794 #if wxUSE_STARTUP_TIPS
795 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
797 static size_t s_index
= (size_t)-1;
799 if ( s_index
== (size_t)-1 )
803 // this is completely bogus, we don't know how many lines are there
804 // in the file, but who cares, it's a demo only...
805 s_index
= rand() % 5;
808 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
810 bool showAtStartup
= wxShowTip(this, tipProvider
);
814 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
815 wxOK
| wxICON_INFORMATION
, this);
818 s_index
= tipProvider
->GetCurrentTip();
821 #endif // wxUSE_STARTUP_TIPS
823 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
828 #if wxUSE_PROGRESSDLG
830 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
832 static const int max
= 10;
834 wxProgressDialog
dialog(_T("Progress dialog example"),
835 _T("An informative message"),
840 // wxPD_AUTO_HIDE | -- try this as well
842 wxPD_ESTIMATED_TIME
|
843 wxPD_REMAINING_TIME
);
846 for ( int i
= 0; i
<= max
; i
++ )
851 cont
= dialog
.Update(i
, _T("That's all, folks!"));
853 else if ( i
== max
/ 2 )
855 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
859 cont
= dialog
.Update(i
);
864 if ( wxMessageBox(_T("Do you really want to cancel?"),
865 _T("Progress dialog question"), // caption
866 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
875 wxLogStatus(wxT("Progress dialog aborted!"));
879 wxLogStatus(wxT("Countdown from %d finished"), max
);
883 #endif // wxUSE_PROGRESSDLG
887 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
889 wxWindowDisabler disableAll
;
891 wxBusyInfo
info(_T("Working, please wait..."), this);
893 for ( int i
= 0; i
< 18; i
++ )
903 #endif // wxUSE_BUSYINFO
905 #if wxUSE_FINDREPLDLG
907 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
916 m_dlgReplace
= new wxFindReplaceDialog
920 _T("Find and replace dialog"),
924 m_dlgReplace
->Show(true);
928 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
937 m_dlgFind
= new wxFindReplaceDialog
946 m_dlgFind
->Show(true);
950 static wxString
DecodeFindDialogEventFlags(int flags
)
953 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
954 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
955 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
956 << _T("case sensitive");
961 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
963 wxEventType type
= event
.GetEventType();
965 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
967 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
968 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
969 event
.GetFindString().c_str(),
970 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
972 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
973 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
975 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
976 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
977 event
.GetFindString().c_str(),
978 event
.GetReplaceString().c_str(),
979 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
981 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
983 wxFindReplaceDialog
*dlg
= event
.GetDialog();
987 if ( dlg
== m_dlgFind
)
990 idMenu
= DIALOGS_FIND
;
993 else if ( dlg
== m_dlgReplace
)
996 idMenu
= DIALOGS_REPLACE
;
1001 txt
= _T("Unknown");
1004 wxFAIL_MSG( _T("unexpected event") );
1007 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1009 if ( idMenu
!= wxID_ANY
)
1011 GetMenuBar()->Check(idMenu
, false);
1018 wxLogError(wxT("Unknown find dialog event!"));
1022 #endif // wxUSE_FINDREPLDLG
1024 // ----------------------------------------------------------------------------
1026 // ----------------------------------------------------------------------------
1028 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1031 dc
.SetFont(wxGetApp().m_canvasFont
);
1032 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1033 dc
.SetBackgroundMode(wxTRANSPARENT
);
1034 dc
.DrawText(_T("wxWidgets common dialogs test application"), 10, 10);
1037 // ----------------------------------------------------------------------------
1039 // ----------------------------------------------------------------------------
1041 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1042 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1044 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1046 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1047 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1050 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1051 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1055 sizerTop
->SetSizeHints(this);
1056 sizerTop
->Fit(this);
1059 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1061 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1062 wxOK
| wxICON_INFORMATION
, this);
1065 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1067 if ( event
.CanVeto() )
1069 wxMessageBox(_T("Use the menu item to close this dialog"),
1070 _T("Modeless dialog"),
1071 wxOK
| wxICON_INFORMATION
, this);
1077 // ----------------------------------------------------------------------------
1079 // ----------------------------------------------------------------------------
1081 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1082 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1084 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1086 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1087 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1088 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1090 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1091 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1092 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1093 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1094 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1098 sizerTop
->SetSizeHints(this);
1099 sizerTop
->Fit(this);
1101 m_btnModal
->SetFocus();
1102 m_btnModal
->SetDefault();
1105 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1107 if ( event
.GetEventObject() == m_btnDelete
)
1112 m_btnDelete
->Disable();
1114 else if ( event
.GetEventObject() == m_btnModal
)
1117 wxGetTextFromUser(_T("Dummy prompt"),
1118 _T("Modal dialog called from dialog"),
1119 wxEmptyString
, this);
1121 wxMessageBox(_T("Modal dialog called from dialog"));
1122 #endif // wxUSE_TEXTDLG
1124 else if ( event
.GetEventObject() == m_btnModeless
)
1126 (new MyModelessDialog(this))->Show();