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/colordlg.h" 
  33 #include "wx/filedlg.h" 
  34 #include "wx/dirdlg.h" 
  35 #include "wx/fontdlg.h" 
  36 #include "wx/choicdlg.h" 
  37 #include "wx/tipdlg.h" 
  38 #include "wx/progdlg.h" 
  39 #include "wx/fdrepdlg.h" 
  40 #include "wx/busyinfo.h" 
  43 #define wxTEST_GENERIC_DIALOGS_IN_MSW 0 
  45 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW 
  46 #include "wx/generic/colrdlgg.h" 
  47 #include "wx/generic/fontdlgg.h" 
  50 #define wxUSE_DIRDLGG 0 
  52 #if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG 
  53 #include "wx/generic/dirdlgg.h" 
  60 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
) 
  61     EVT_PAINT(MyCanvas::OnPaint
) 
  64 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
) 
  65     EVT_MENU(DIALOGS_CHOOSE_COLOUR
,                 MyFrame::ChooseColour
) 
  66     EVT_MENU(DIALOGS_CHOOSE_FONT
,                   MyFrame::ChooseFont
) 
  67     EVT_MENU(DIALOGS_LOG_DIALOG
,                    MyFrame::LogDialog
) 
  68     EVT_MENU(DIALOGS_MESSAGE_BOX
,                   MyFrame::MessageBox
) 
  69     EVT_MENU(DIALOGS_TEXT_ENTRY
,                    MyFrame::TextEntry
) 
  70     EVT_MENU(DIALOGS_PASSWORD_ENTRY
,                MyFrame::PasswordEntry
) 
  71     EVT_MENU(DIALOGS_NUM_ENTRY
,                     MyFrame::NumericEntry
) 
  72     EVT_MENU(DIALOGS_SINGLE_CHOICE
,                 MyFrame::SingleChoice
) 
  73     EVT_MENU(DIALOGS_MULTI_CHOICE
,                  MyFrame::MultiChoice
) 
  74     EVT_MENU(DIALOGS_FILE_OPEN
,                     MyFrame::FileOpen
) 
  75     EVT_MENU(DIALOGS_FILE_OPEN2
,                    MyFrame::FileOpen2
) 
  76     EVT_MENU(DIALOGS_FILES_OPEN
,                    MyFrame::FilesOpen
) 
  77     EVT_MENU(DIALOGS_FILE_SAVE
,                     MyFrame::FileSave
) 
  78     EVT_MENU(DIALOGS_DIR_CHOOSE
,                    MyFrame::DirChoose
) 
  79     EVT_MENU(DIALOGS_DIRNEW_CHOOSE
,                 MyFrame::DirChooseNew
) 
  80 #if defined(__WXMSW__) || defined(__WXMAC__) 
  81     EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
,            MyFrame::GenericDirChoose
) 
  82 #endif // wxMSW || wxMAC 
  83     EVT_MENU(DIALOGS_MODAL
,                         MyFrame::ModalDlg
) 
  84     EVT_MENU(DIALOGS_MODELESS
,                      MyFrame::ModelessDlg
) 
  85     EVT_MENU(DIALOGS_TIP
,                           MyFrame::ShowTip
) 
  86 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW 
  87     EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
,         MyFrame::ChooseColourGeneric
) 
  88     EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
,           MyFrame::ChooseFontGeneric
) 
  92     EVT_MENU(DIALOGS_PROGRESS
,                      MyFrame::ShowProgress
) 
  93 #endif // wxUSE_PROGRESSDLG 
  96     EVT_MENU(DIALOGS_BUSYINFO
,                      MyFrame::ShowBusyInfo
) 
  97 #endif // wxUSE_BUSYINFO 
 100     EVT_MENU(DIALOGS_FIND
,                          MyFrame::ShowFindDialog
) 
 101     EVT_MENU(DIALOGS_REPLACE
,                       MyFrame::ShowReplaceDialog
) 
 103     EVT_FIND(-1, MyFrame::OnFindDialog
) 
 104     EVT_FIND_NEXT(-1, MyFrame::OnFindDialog
) 
 105     EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog
) 
 106     EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog
) 
 107     EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog
) 
 108 #endif // wxUSE_FINDREPLDLG 
 109     EVT_MENU(wxID_EXIT
,                             MyFrame::OnExit
) 
 112 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
) 
 113     EVT_BUTTON(-1, MyModalDialog::OnButton
) 
 116 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
) 
 117     EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
) 
 119     EVT_CLOSE(MyModelessDialog::OnClose
) 
 122 MyCanvas 
*myCanvas 
= (MyCanvas 
*) NULL
; 
 124 // `Main program' equivalent, creating windows and returning main app frame 
 128     wxInitAllImageHandlers(); 
 131 #if defined(__WXGTK__) && defined(wxUSE_UNICODE) 
 132   wxConvCurrent 
= &wxConvLibc
; 
 135   m_canvasTextColour 
= wxColour(_T("BLACK")); 
 136   m_canvasFont 
= *wxNORMAL_FONT
; 
 138   // Create the main frame window 
 139   MyFrame 
*frame 
= new MyFrame((wxFrame 
*) NULL
, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300)); 
 142   wxMenu 
*file_menu 
= new wxMenu
; 
 144   file_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour")); 
 146 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW 
 147   file_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("Choose colour (&generic)")); 
 150   file_menu
->AppendSeparator(); 
 151   file_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font")); 
 153 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW 
 154   file_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose f&ont (generic)")); 
 157   file_menu
->AppendSeparator(); 
 158   file_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L")); 
 159   file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M")); 
 160   file_menu
->Append(DIALOGS_TEXT_ENTRY
,  _T("Text &entry\tCtrl-E")); 
 161   file_menu
->Append(DIALOGS_PASSWORD_ENTRY
,  _T("&Password entry\tCtrl-P")); 
 162   file_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N")); 
 163   file_menu
->Append(DIALOGS_SINGLE_CHOICE
,  _T("&Single choice\tCtrl-C")); 
 164   file_menu
->Append(DIALOGS_MULTI_CHOICE
,  _T("M&ultiple choice\tCtrl-U")); 
 165   file_menu
->AppendSeparator(); 
 166   file_menu
->Append(DIALOGS_TIP
,  _T("&Tip of the day\tCtrl-T")); 
 167   file_menu
->AppendSeparator(); 
 168   file_menu
->Append(DIALOGS_FILE_OPEN
,  _T("&Open file\tCtrl-O")); 
 169   file_menu
->Append(DIALOGS_FILE_OPEN2
,  _T("&Second open file\tCtrl-2")); 
 170   file_menu
->Append(DIALOGS_FILES_OPEN
,  _T("Open &files\tCtrl-Q")); 
 171   file_menu
->Append(DIALOGS_FILE_SAVE
,  _T("Sa&ve file\tCtrl-S")); 
 172   file_menu
->Append(DIALOGS_DIR_CHOOSE
,  _T("&Choose a directory\tCtrl-D")); 
 173   file_menu
->Append(DIALOGS_DIRNEW_CHOOSE
,  _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D")); 
 174 #if defined(__WXMSW__) || defined(__WXMAC__) 
 175   file_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
,  _T("&Choose a directory (generic implementation)")); 
 176 #endif // wxMSW || wxMAC 
 177   file_menu
->AppendSeparator(); 
 179 #if wxUSE_PROGRESSDLG 
 180   file_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G")); 
 181 #endif // wxUSE_PROGRESSDLG 
 183   file_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B")); 
 184 #endif // wxUSE_BUSYINFO 
 185 #if wxUSE_FINDREPLDLG 
 186   file_menu
->Append(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"), _T(""), TRUE
); 
 187   file_menu
->Append(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE
); 
 188 #endif // wxUSE_FINDREPLDLG 
 189   file_menu
->AppendSeparator(); 
 191   file_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W")); 
 192   file_menu
->Append(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE
); 
 193   file_menu
->AppendSeparator(); 
 195   file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X")); 
 196   wxMenuBar 
*menu_bar 
= new wxMenuBar
; 
 197   menu_bar
->Append(file_menu
, _T("&File")); 
 198   frame
->SetMenuBar(menu_bar
); 
 200   myCanvas 
= new MyCanvas(frame
); 
 201   myCanvas
->SetBackgroundColour(*wxWHITE
); 
 203   frame
->Centre(wxBOTH
); 
 213 // My frame constructor 
 214 MyFrame::MyFrame(wxWindow 
*parent
, 
 215                  const wxString
& title
, 
 218        : wxFrame(parent
, -1, title
, pos
, size
) 
 220     m_dialog 
= (MyModelessDialog 
*)NULL
; 
 222 #if wxUSE_FINDREPLDLG 
 230 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) ) 
 232     wxColour col 
= myCanvas
->GetBackgroundColour(); 
 236     data
.SetChooseFull(TRUE
); 
 237     for (int i 
= 0; i 
< 16; i
++) 
 239         wxColour 
colour(i
*16, i
*16, i
*16); 
 240         data
.SetCustomColour(i
, colour
); 
 243     wxColourDialog 
dialog(this, &data
); 
 244     dialog
.SetTitle(_T("Choose the background colour")); 
 245     if (dialog
.ShowModal() == wxID_OK
) 
 247         wxColourData retData 
= dialog
.GetColourData(); 
 248         col 
= retData
.GetColour(); 
 249         myCanvas
->SetBackgroundColour(col
); 
 250         myCanvas
->ClearBackground(); 
 255 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) ) 
 258     data
.SetInitialFont(wxGetApp().m_canvasFont
); 
 259     data
.SetColour(wxGetApp().m_canvasTextColour
); 
 261     // you might also do this: 
 263     //  wxFontDialog dialog; 
 264     //  if ( !dialog.Create(this, data) { ... error ... } 
 266     wxFontDialog 
dialog(this, data
); 
 268     if (dialog
.ShowModal() == wxID_OK
) 
 270         wxFontData retData 
= dialog
.GetFontData(); 
 271         wxGetApp().m_canvasFont 
= retData
.GetChosenFont(); 
 272         wxGetApp().m_canvasTextColour 
= retData
.GetColour(); 
 275     //else: cancelled by the user, don't change the font 
 278 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW 
 279 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
)) 
 282       data
.SetChooseFull(TRUE
); 
 283       for (int i 
= 0; i 
< 16; i
++) 
 285         wxColour 
colour(i
*16, i
*16, i
*16); 
 286         data
.SetCustomColour(i
, colour
); 
 289       wxGenericColourDialog 
*dialog 
= new wxGenericColourDialog(this, &data
); 
 290       if (dialog
->ShowModal() == wxID_OK
) 
 292         wxColourData retData 
= dialog
->GetColourData(); 
 293         wxColour col 
= retData
.GetColour(); 
 294 //        wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID); 
 295         myCanvas
->SetBackgroundColour(col
); 
 296         myCanvas
->ClearBackground(); 
 302 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) ) 
 305       data
.SetInitialFont(wxGetApp().m_canvasFont
); 
 306       data
.SetColour(wxGetApp().m_canvasTextColour
); 
 308       wxGenericFontDialog 
*dialog 
= new wxGenericFontDialog(this, &data
); 
 309       if (dialog
->ShowModal() == wxID_OK
) 
 311         wxFontData retData 
= dialog
->GetFontData(); 
 312         wxGetApp().m_canvasFont 
= retData
.GetChosenFont(); 
 313         wxGetApp().m_canvasTextColour 
= retData
.GetColour(); 
 318 #endif // wxTEST_GENERIC_DIALOGS_IN_MSW 
 320 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
)) 
 322     // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages 
 323     // being flushed -- test it 
 326         wxLogMessage(wxT("This is some message - everything is ok so far.")); 
 327         wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); 
 328         wxLogWarning(wxT("And then something went wrong!")); 
 330         // and if ~wxBusyCursor doesn't do it, then call it manually 
 334     wxLogError(wxT("Intermediary error handler decided to abort.")); 
 335     wxLogError(wxT("The top level caller detected an unrecoverable error.")); 
 337     wxLog::FlushActive(); 
 339     wxLogMessage(wxT("And this is the same dialog but with only one message.")); 
 342 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) ) 
 344   wxMessageDialog 
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"), 
 345       _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
); 
 347   switch ( dialog
.ShowModal() ) 
 350           wxLogStatus(wxT("You pressed \"Yes\"")); 
 354           wxLogStatus(wxT("You pressed \"No\"")); 
 358           wxLogStatus(wxT("You pressed \"Cancel\"")); 
 362           wxLogError(wxT("Unexpected wxMessageDialog return code!")); 
 366 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) ) 
 368     long res 
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n") 
 369                                     _T("Even two rows of text."), 
 370                                     _T("Enter a number:"), _T("Numeric input test"), 
 377         msg 
= _T("Invalid number entered or dialog cancelled."); 
 382         msg
.Printf(_T("You've entered %lu"), res 
); 
 383         icon 
= wxICON_INFORMATION
; 
 386     wxMessageBox(msg
, _T("Numeric test result"), wxOK 
| icon
, this); 
 389 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
)) 
 391     wxString pwd 
= wxGetPasswordFromUser(_T("Enter password:"), 
 392                                          _T("Password entry dialog"), 
 397         wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()), 
 398                      _T("Got password"), wxOK 
| wxICON_INFORMATION
, this); 
 402 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
)) 
 404   wxTextEntryDialog 
dialog(this, 
 405                            _T("This is a small sample\n") 
 406                            _T("A long, long string to test out the text entrybox"), 
 407                            _T("Please enter a string"), 
 411   if (dialog
.ShowModal() == wxID_OK
) 
 413     wxMessageDialog 
dialog2(this, dialog
.GetValue(), _T("Got string")); 
 418 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) ) 
 420     const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ; 
 422     wxSingleChoiceDialog 
dialog(this, 
 423                                 _T("This is a small sample\n") 
 424                                 _T("A single-choice convenience dialog"), 
 425                                 _T("Please select a value"), 
 426                                 WXSIZEOF(choices
), choices
); 
 428     dialog
.SetSelection(2); 
 430     if (dialog
.ShowModal() == wxID_OK
) 
 432         wxMessageDialog 
dialog2(this, dialog
.GetStringSelection(), _T("Got string")); 
 437 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) ) 
 439     const wxString choices
[] = 
 441         _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"), 
 442         _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"), 
 443         _T("Eleven"), _T("Twelve"), _T("Seventeen"), 
 446     wxArrayInt selections
; 
 447     size_t count 
= wxGetMultipleChoices(selections
, 
 448                                         _T("This is a small sample\n") 
 449                                         _T("A multi-choice convenience dialog"), 
 450                                         _T("Please select a value"), 
 451                                         WXSIZEOF(choices
), choices
, 
 456         msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
); 
 457         for ( size_t n 
= 0; n 
< count
; n
++ ) 
 459             msg 
+= wxString::Format(wxT("\t%u: %u (%s)\n"), 
 460                                     (unsigned)n
, (unsigned)selections
[n
], 
 461                                     choices
[selections
[n
]].c_str()); 
 465     //else: cancelled or nothing selected 
 468 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) ) 
 473                     _T("Testing open file dialog"), 
 477                     _T("C++ files (*.cpp)|*.cpp") 
 479                     _T("C++ files (*.h;*.cpp)|*.h;*.cpp") 
 483     dialog
.SetDirectory(wxGetHomeDir()); 
 485     if (dialog
.ShowModal() == wxID_OK
) 
 488         info
.Printf(_T("Full file name: %s\n") 
 491                     dialog
.GetPath().c_str(), 
 492                     dialog
.GetDirectory().c_str(), 
 493                     dialog
.GetFilename().c_str()); 
 494         wxMessageDialog 
dialog2(this, info
, _T("Selected file")); 
 499 // this shows how to take advantage of specifying a default extension in the 
 500 // call to wxFileSelector: it is remembered after each new call and the next 
 501 // one will use it by default 
 502 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) ) 
 504     static wxString s_extDef
; 
 505     wxString path 
= wxFileSelector( 
 506                                     _T("Select the file to load"), 
 509                                     _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"), 
 517     // it is just a sample, would use wxSplitPath in real program 
 518     s_extDef 
= path
.AfterLast(_T('.')); 
 520     wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), 
 521                  (const wxChar
*) path
, (const wxChar
*) s_extDef
); 
 524 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) ) 
 528                     _T("C++ files (*.cpp)|*.cpp"); 
 530                     _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp"); 
 532     wxFileDialog 
dialog(this, _T("Testing open multiple file dialog"), 
 533                         _T(""), _T(""), wildcards
, 
 536     if (dialog
.ShowModal() == wxID_OK
) 
 538         wxArrayString paths
, filenames
; 
 540         dialog
.GetPaths(paths
); 
 541         dialog
.GetFilenames(filenames
); 
 544         size_t count 
= paths
.GetCount(); 
 545         for ( size_t n 
= 0; n 
< count
; n
++ ) 
 547             s
.Printf(_T("File %d: %s (%s)\n"), 
 548                      (int)n
, paths
[n
].c_str(), filenames
[n
].c_str()); 
 552         s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex()); 
 555         wxMessageDialog 
dialog2(this, msg
, _T("Selected files")); 
 560 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) ) 
 562     wxFileDialog 
dialog(this, 
 563                         _T("Testing save file dialog"), 
 566                         _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), 
 567                         wxSAVE
|wxOVERWRITE_PROMPT
); 
 569     dialog
.SetFilterIndex(1); 
 571     if (dialog
.ShowModal() == wxID_OK
) 
 573         wxLogMessage(_T("%s, filter %d"), 
 574                      dialog
.GetPath().c_str(), dialog
.GetFilterIndex()); 
 578 void MyFrame::DoDirChoose(int style
) 
 580     // pass some initial dir to wxDirDialog 
 582     wxGetHomeDir(&dirHome
); 
 584     wxDirDialog 
dialog(this, _T("Testing directory picker"), dirHome
, style
); 
 586     if (dialog
.ShowModal() == wxID_OK
) 
 588         wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str()); 
 592 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) ) 
 594     DoDirChoose(wxDD_DEFAULT_STYLE 
& ~wxDD_NEW_DIR_BUTTON
); 
 597 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) ) 
 599     DoDirChoose(wxDD_DEFAULT_STYLE 
| wxDD_NEW_DIR_BUTTON
); 
 602 #if defined(__WXMSW__) || defined(__WXMAC__) 
 604 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) ) 
 606 #if !(defined(__WXMSW__) || defined(__WXMAC__)) || wxUSE_DIRDLGG 
 607     // pass some initial dir to wxDirDialog 
 609     wxGetHomeDir(&dirHome
); 
 611     wxGenericDirDialog 
dialog(this, _T("Testing generic directory picker"), dirHome
); 
 613     if (dialog
.ShowModal() == wxID_OK
) 
 615         wxMessageDialog 
dialog2(this, dialog
.GetPath(), _T("Selected path")); 
 619     wxLogError(wxT("Sorry, generic dir dialog not available:\n") 
 620                wxT("set wxUSE_DIRDLGG to 1 and recompile")); 
 624 #endif // wxMSW || wxMAC 
 626 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
)) 
 628     MyModalDialog 
dlg(this); 
 632 void MyFrame::ModelessDlg(wxCommandEvent
& event
) 
 634     bool show 
= GetMenuBar()->IsChecked(event
.GetId()); 
 640             m_dialog 
= new MyModelessDialog(this); 
 643         m_dialog
->Show(TRUE
); 
 651 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
)) 
 653 #if wxUSE_STARTUP_TIPS 
 654     static size_t s_index 
= (size_t)-1; 
 656     if ( s_index 
== (size_t)-1 ) 
 660         // this is completely bogus, we don't know how many lines are there 
 661         // in the file, but who cares, it's a demo only... 
 662         s_index 
= rand() % 5; 
 665     wxTipProvider 
*tipProvider 
= wxCreateFileTipProvider(_T("tips.txt"), s_index
); 
 667     bool showAtStartup 
= wxShowTip(this, tipProvider
); 
 671         wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"), 
 672                      wxOK 
| wxICON_INFORMATION
, this); 
 675     s_index 
= tipProvider
->GetCurrentTip(); 
 680 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) ) 
 685 #if wxUSE_PROGRESSDLG 
 687 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) ) 
 689     static const int max 
= 10; 
 691     wxProgressDialog 
dialog(_T("Progress dialog example"), 
 692                             _T("An informative message"), 
 697                             // wxPD_AUTO_HIDE | -- try this as well 
 699                             wxPD_ESTIMATED_TIME 
| 
 700                             wxPD_REMAINING_TIME
); 
 703     for ( int i 
= 0; i 
<= max
; i
++ ) 
 708             cont 
= dialog
.Update(i
, _T("That's all, folks!")); 
 710         else if ( i 
== max 
/ 2 ) 
 712             cont 
= dialog
.Update(i
, _T("Only a half left (very long message)!")); 
 716             cont 
= dialog
.Update(i
); 
 721             if ( wxMessageBox(_T("Do you really want to cancel?"), 
 722                               _T("Progress dialog question"),  // caption 
 723                               wxYES_NO 
| wxICON_QUESTION
) == wxYES 
) 
 732         wxLogStatus(wxT("Progress dialog aborted!")); 
 736         wxLogStatus(wxT("Countdown from %d finished"), max
); 
 740 #endif // wxUSE_PROGRESSDLG 
 744 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
)) 
 746     wxWindowDisabler disableAll
; 
 748     wxBusyInfo 
info(_T("Working, please wait..."), this); 
 750     for ( int i 
= 0; i 
< 18; i
++ ) 
 760 #endif // wxUSE_BUSYINFO 
 762 #if wxUSE_FINDREPLDLG 
 764 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) ) 
 773         m_dlgReplace 
= new wxFindReplaceDialog
 
 777                             _T("Find and replace dialog"), 
 781         m_dlgReplace
->Show(TRUE
); 
 785 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) ) 
 794         m_dlgFind 
= new wxFindReplaceDialog
 
 803         m_dlgFind
->Show(TRUE
); 
 807 static wxString 
DecodeFindDialogEventFlags(int flags
) 
 810     str 
<< (flags 
& wxFR_DOWN 
? _T("down") : _T("up")) << _T(", ") 
 811         << (flags 
& wxFR_WHOLEWORD 
? _T("whole words only, ") : _T("")) 
 812         << (flags 
& wxFR_MATCHCASE 
? _T("") : _T("not ")) 
 813         << _T("case sensitive"); 
 818 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
) 
 820     wxEventType type 
= event
.GetEventType(); 
 822     if ( type 
== wxEVT_COMMAND_FIND 
|| type 
== wxEVT_COMMAND_FIND_NEXT 
) 
 824         wxLogMessage(wxT("Find %s'%s' (flags: %s)"), 
 825                      type 
== wxEVT_COMMAND_FIND_NEXT 
? wxT("next ") : wxT(""), 
 826                      event
.GetFindString().c_str(), 
 827                      DecodeFindDialogEventFlags(event
.GetFlags()).c_str()); 
 829     else if ( type 
== wxEVT_COMMAND_FIND_REPLACE 
|| 
 830                 type 
== wxEVT_COMMAND_FIND_REPLACE_ALL 
) 
 832         wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), 
 833                      type 
== wxEVT_COMMAND_FIND_REPLACE_ALL 
? _T("all ") : wxT(""), 
 834                      event
.GetFindString().c_str(), 
 835                      event
.GetReplaceString().c_str(), 
 836                      DecodeFindDialogEventFlags(event
.GetFlags()).c_str()); 
 838     else if ( type 
== wxEVT_COMMAND_FIND_CLOSE 
) 
 840         wxFindReplaceDialog 
*dlg 
= event
.GetDialog(); 
 844         if ( dlg 
== m_dlgFind 
) 
 847             idMenu 
= DIALOGS_FIND
; 
 850         else if ( dlg 
== m_dlgReplace 
) 
 853             idMenu 
= DIALOGS_REPLACE
; 
 861             wxFAIL_MSG( _T("unexpected event") ); 
 864         wxLogMessage(wxT("%s dialog is being closed."), txt
); 
 868             GetMenuBar()->Check(idMenu
, FALSE
); 
 875         wxLogError(wxT("Unknown find dialog event!")); 
 879 #endif // wxUSE_FINDREPLDLG 
 881 // ---------------------------------------------------------------------------- 
 883 // ---------------------------------------------------------------------------- 
 885 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) ) 
 888     dc
.SetFont(wxGetApp().m_canvasFont
); 
 889     dc
.SetTextForeground(wxGetApp().m_canvasTextColour
); 
 890     dc
.SetBackgroundMode(wxTRANSPARENT
); 
 891     dc
.DrawText(_T("wxWindows common dialogs test application"), 10, 10); 
 894 // ---------------------------------------------------------------------------- 
 896 // ---------------------------------------------------------------------------- 
 898 MyModelessDialog::MyModelessDialog(wxWindow 
*parent
) 
 899                 : wxDialog(parent
, -1, wxString(_T("Modeless dialog"))) 
 901     wxBoxSizer 
*sizerTop 
= new wxBoxSizer(wxVERTICAL
); 
 903     wxButton 
*btn 
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me")); 
 904     wxCheckBox 
*check 
= new wxCheckBox(this, -1, _T("Should be disabled")); 
 907     sizerTop
->Add(btn
, 1, wxEXPAND 
| wxALL
, 5); 
 908     sizerTop
->Add(check
, 1, wxEXPAND 
| wxALL
, 5); 
 913     sizerTop
->SetSizeHints(this); 
 917 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
)) 
 919     wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"), 
 920                  wxOK 
| wxICON_INFORMATION
, this); 
 923 void MyModelessDialog::OnClose(wxCloseEvent
& event
) 
 925     if ( event
.CanVeto() ) 
 927         wxMessageBox(_T("Use the menu item to close this dialog"), 
 928                      _T("Modeless dialog"), 
 929                      wxOK 
| wxICON_INFORMATION
, this); 
 935 // ---------------------------------------------------------------------------- 
 937 // ---------------------------------------------------------------------------- 
 939 MyModalDialog::MyModalDialog(wxWindow 
*parent
) 
 940              : wxDialog(parent
, -1, wxString(_T("Modal dialog"))) 
 942     wxBoxSizer 
*sizerTop 
= new wxBoxSizer(wxHORIZONTAL
); 
 944     m_btnModal 
= new wxButton(this, -1, _T("&Modal dialog...")); 
 945     m_btnModeless 
= new wxButton(this, -1, _T("Mode&less dialog")); 
 946     m_btnDelete 
= new wxButton(this, -1, _T("&Delete button")); 
 948     wxButton 
*btnOk 
= new wxButton(this, wxID_CANCEL
, _T("&Close")); 
 949     sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER 
| wxALL
, 5); 
 950     sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER 
| wxALL
, 5); 
 951     sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER 
| wxALL
, 5); 
 952     sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER 
| wxALL
, 5); 
 957     sizerTop
->SetSizeHints(this); 
 960     m_btnModal
->SetFocus(); 
 961     m_btnModal
->SetDefault(); 
 964 void MyModalDialog::OnButton(wxCommandEvent
& event
) 
 966     if ( event
.GetEventObject() == m_btnDelete 
) 
 971         m_btnDelete
->Disable(); 
 973     else if ( event
.GetEventObject() == m_btnModal 
) 
 975         wxGetTextFromUser(_T("Dummy prompt"), 
 976                           _T("Modal dialog called from dialog"), 
 979     else if ( event
.GetEventObject() == m_btnModeless 
) 
 981         (new MyModelessDialog(this))->Show();