X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..55f9f0cbc8dcf45f8d484b2f931c5c254d4404d1:/samples/dialogs/dialogs.cpp diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 6ef90dcc7a..5d36625f14 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem +// Copyright: (c) Julian Smart // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// @@ -71,6 +71,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) + EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew) #if defined(__WXMSW__) || defined(__WXMAC__) EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) #endif // wxMSW || wxMAC @@ -122,7 +123,7 @@ bool MyApp::OnInit() wxConvCurrent = &wxConvLibc; #endif - m_canvasTextColour = wxColour("BLACK"); + m_canvasTextColour = wxColour(_T("BLACK")); m_canvasFont = *wxNORMAL_FONT; // Create the main frame window @@ -142,8 +143,8 @@ bool MyApp::OnInit() #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose f&ont (generic)")); - #endif + file_menu->AppendSeparator(); file_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L")); file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); @@ -160,9 +161,12 @@ bool MyApp::OnInit() file_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); file_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); file_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D")); + file_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D")); #if defined(__WXMSW__) || defined(__WXMAC__) file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic implementation)")); #endif // wxMSW || wxMAC + file_menu->AppendSeparator(); + #if wxUSE_PROGRESSDLG file_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G")); #endif // wxUSE_PROGRESSDLG @@ -170,13 +174,15 @@ bool MyApp::OnInit() file_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B")); #endif // wxUSE_BUSYINFO #if wxUSE_FINDREPLDLG - file_menu->Append(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"), "", TRUE); - file_menu->Append(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"), "", TRUE); + file_menu->Append(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"), _T(""), TRUE); + file_menu->Append(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE); #endif // wxUSE_FINDREPLDLG file_menu->AppendSeparator(); + file_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W")); - file_menu->Append(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"), "", TRUE); + file_menu->Append(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE); file_menu->AppendSeparator(); + file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X")); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, _T("&File")); @@ -226,7 +232,7 @@ void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) } wxColourDialog dialog(this, &data); - dialog.SetTitle("Choose the background colour"); + dialog.SetTitle(_T("Choose the background colour")); if (dialog.ShowModal() == wxID_OK) { wxColourData retData = dialog.GetColourData(); @@ -375,7 +381,7 @@ void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) { wxString pwd = wxGetPasswordFromUser(_T("Enter password:"), _T("Password entry dialog"), - "", + _T(""), this); if ( !!pwd ) { @@ -438,10 +444,11 @@ void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) if ( count ) { wxString msg; - msg.Printf(wxT("You selected %u items:\n"), count); + msg.Printf(wxT("You selected %u items:\n"), (unsigned)count); for ( size_t n = 0; n < count; n++ ) { - msg += wxString::Format(wxT("\t%u: %u (%s)\n"), n, selections[n], + msg += wxString::Format(wxT("\t%u: %u (%s)\n"), + (unsigned)n, (unsigned)selections[n], choices[selections[n]].c_str()); } wxLogMessage(msg); @@ -457,7 +464,11 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) _T("Testing open file dialog"), _T(""), _T(""), +#ifdef __WXMOTIF__ + _T("C++ files (*.cpp)|*.cpp") +#else _T("C++ files (*.h;*.cpp)|*.h;*.cpp") +#endif ); dialog.SetDirectory(wxGetHomeDir()); @@ -519,7 +530,7 @@ void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) for ( size_t n = 0; n < count; n++ ) { s.Printf(_T("File %d: %s (%s)\n"), - n, paths[n].c_str(), filenames[n].c_str()); + (int)n, paths[n].c_str(), filenames[n].c_str()); msg += s; } @@ -547,13 +558,13 @@ void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) } } -void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) +void MyFrame::DoDirChoose(int style) { // pass some initial dir to wxDirDialog wxString dirHome; wxGetHomeDir(&dirHome); - wxDirDialog dialog(this, _T("Testing directory picker"), dirHome); + wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style); if (dialog.ShowModal() == wxID_OK) { @@ -561,6 +572,16 @@ void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) } } +void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) +{ + DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON); +} + +void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) ) +{ + DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON); +} + #if defined(__WXMSW__) || defined(__WXMAC__) void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) @@ -707,7 +728,7 @@ void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) { wxWindowDisabler disableAll; - wxBusyInfo info("Working, please wait...", this); + wxBusyInfo info(_T("Working, please wait..."), this); for ( int i = 0; i < 18; i++ ) { @@ -850,7 +871,7 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) dc.SetFont(wxGetApp().m_canvasFont); dc.SetTextForeground(wxGetApp().m_canvasTextColour); dc.SetBackgroundMode(wxTRANSPARENT); - dc.DrawText("wxWindows common dialogs test application", 10, 10); + dc.DrawText(_T("wxWindows common dialogs test application"), 10, 10); } // ---------------------------------------------------------------------------- @@ -858,7 +879,7 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) // ---------------------------------------------------------------------------- MyModelessDialog::MyModelessDialog(wxWindow *parent) - : wxDialog(parent, -1, wxString("Modeless dialog")) + : wxDialog(parent, -1, wxString(_T("Modeless dialog"))) { wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); @@ -903,10 +924,13 @@ MyModalDialog::MyModalDialog(wxWindow *parent) { wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); - m_btnFocused = new wxButton(this, -1, _T("Default button")); + m_btnModal = new wxButton(this, -1, _T("&Modal dialog...")); + m_btnModeless = new wxButton(this, -1, _T("Mode&less dialog")); m_btnDelete = new wxButton(this, -1, _T("&Delete button")); + wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close")); - sizerTop->Add(m_btnFocused, 0, wxALIGN_CENTER | wxALL, 5); + sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); + sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); @@ -916,25 +940,29 @@ MyModalDialog::MyModalDialog(wxWindow *parent) sizerTop->SetSizeHints(this); sizerTop->Fit(this); - m_btnFocused->SetFocus(); - m_btnFocused->SetDefault(); + m_btnModal->SetFocus(); + m_btnModal->SetDefault(); } void MyModalDialog::OnButton(wxCommandEvent& event) { if ( event.GetEventObject() == m_btnDelete ) { - delete m_btnFocused; - m_btnFocused = NULL; + delete m_btnModal; + m_btnModal = NULL; m_btnDelete->Disable(); } - else if ( event.GetEventObject() == m_btnFocused ) + else if ( event.GetEventObject() == m_btnModal ) { wxGetTextFromUser(_T("Dummy prompt"), _T("Modal dialog called from dialog"), _T(""), this); } + else if ( event.GetEventObject() == m_btnModeless ) + { + (new MyModelessDialog(this))->Show(); + } else { event.Skip();