X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8e13c1ec4e6e8d2c5852df39c6be5db4fd279227..655c20fcd5a554a986b93651d8b0bec2afde8573:/src/generic/filedlgg.cpp diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index c372fb9fac..2f493b2e32 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -13,7 +13,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #if wxUSE_FILEDLG @@ -23,27 +23,32 @@ #error wxGenericFileDialog currently only supports Unix, win32 and DOS #endif -#include "wx/checkbox.h" -#include "wx/textctrl.h" -#include "wx/choice.h" -#include "wx/checkbox.h" -#include "wx/stattext.h" -#include "wx/debug.h" -#include "wx/log.h" +#ifndef WX_PRECOMP + #ifdef __WXMSW__ + #include "wx/msw/wrapwin.h" + #endif + #include "wx/hash.h" + #include "wx/intl.h" + #include "wx/settings.h" + #include "wx/log.h" + #include "wx/msgdlg.h" + #include "wx/bmpbuttn.h" + #include "wx/checkbox.h" + #include "wx/choice.h" + #include "wx/stattext.h" + #include "wx/textctrl.h" + #include "wx/sizer.h" + #include "wx/filedlg.h" // wxFD_OPEN, wxFD_SAVE... +#endif + #include "wx/longlong.h" -#include "wx/intl.h" -#include "wx/msgdlg.h" -#include "wx/sizer.h" -#include "wx/bmpbuttn.h" #include "wx/tokenzr.h" #include "wx/config.h" #include "wx/imaglist.h" #include "wx/dir.h" #include "wx/artprov.h" -#include "wx/settings.h" #include "wx/filefn.h" #include "wx/file.h" // for wxS_IXXX constants only -#include "wx/filedlg.h" // wxOPEN, wxSAVE... #include "wx/generic/filedlgg.h" #include "wx/generic/dirctrlg.h" // for wxFileIconsTable @@ -52,8 +57,8 @@ #endif #ifndef __WXWINCE__ -#include -#include + #include + #include #endif #ifdef __UNIX__ @@ -65,7 +70,6 @@ #endif #ifdef __WINDOWS__ - #include "wx/msw/wrapwin.h" #include "wx/msw/mslu.h" #endif @@ -353,7 +357,7 @@ wxString wxFileData::GetHint() const else if (IsDrive()) s += _(""); else // plain file - s += wxString::Format(_("%ld bytes"), + s += wxString::Format(wxPLURAL("%ld byte", "%ld bytes", m_size), wxLongLong(m_size).ToString().c_str()); s += wxT(' '); @@ -731,7 +735,7 @@ void wxFileCtrl::GoToParentDir() { if (!IsTopMostDir(m_dirName)) { - size_t len = m_dirName.Len(); + size_t len = m_dirName.length(); if (wxEndsWithPathSeparator(m_dirName)) m_dirName.Remove( len-1, 1 ); wxString fname( wxFileNameFromPath(m_dirName) ); @@ -819,8 +823,8 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) wxASSERT( fd ); if ((event.GetLabel().empty()) || - (event.GetLabel() == _(".")) || - (event.GetLabel() == _("..")) || + (event.GetLabel() == wxT(".")) || + (event.GetLabel() == wxT("..")) || (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND)) { wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); @@ -971,10 +975,12 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, const wxString& wildCard, long style, const wxPoint& pos, + const wxSize& sz, + const wxString& name, bool bypassGenericImpl ) : wxFileDialogBase() { Init(); - Create( parent, message, defaultDir, defaultFile, wildCard, style, pos, bypassGenericImpl ); + Create( parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name, bypassGenericImpl ); } bool wxGenericFileDialog::Create( wxWindow *parent, @@ -984,12 +990,14 @@ bool wxGenericFileDialog::Create( wxWindow *parent, const wxString& wildCard, long style, const wxPoint& pos, + const wxSize& sz, + const wxString& name, bool bypassGenericImpl ) { m_bypassGenericImpl = bypassGenericImpl; if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile, - wildCard, style, pos)) + wildCard, style, pos, sz, name)) { return false; } @@ -997,11 +1005,8 @@ bool wxGenericFileDialog::Create( wxWindow *parent, if (m_bypassGenericImpl) return true; - if (!wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize, - wxDEFAULT_DIALOG_STYLE -#if !(defined(__PDA__) || defined(__SMARTPHONE__)) - | wxRESIZE_BORDER -#endif + if (!wxDialog::Create( parent, wxID_ANY, message, pos, sz, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | style, name )) { return false; @@ -1017,11 +1022,6 @@ bool wxGenericFileDialog::Create( wxWindow *parent, &ms_lastShowHidden); } - if (m_dialogStyle == 0) - m_dialogStyle = wxOPEN; - if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN)) - m_dialogStyle |= wxOPEN; - if ((m_dir.empty()) || (m_dir == wxT("."))) { m_dir = wxGetCwd(); @@ -1029,7 +1029,7 @@ bool wxGenericFileDialog::Create( wxWindow *parent, m_dir = wxFILE_SEP_PATH; } - size_t len = m_dir.Len(); + size_t len = m_dir.length(); if ((len > 1) && (wxEndsWithPathSeparator(m_dir))) m_dir.Remove( len-1, 1 ); @@ -1102,7 +1102,7 @@ bool wxGenericFileDialog::Create( wxWindow *parent, mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 ); long style2 = ms_lastViewStyle; - if ( !(m_dialogStyle & wxMULTIPLE) ) + if ( !HasFdFlag(wxFD_MULTIPLE) ) style2 |= wxLC_SINGLE_SEL; #ifdef __WXWINCE__ @@ -1116,48 +1116,50 @@ bool wxGenericFileDialog::Create( wxWindow *parent, wxDefaultPosition, wxSize(540,200), style2); + m_text = new wxTextCtrl(this, ID_TEXT, m_fileName, + wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER); + m_choice = new wxChoice(this, ID_CHOICE); + if (is_pda) { // PDAs have a different screen layout - mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 ); + mainsizer->Add(m_list, wxSizerFlags(1).Expand().HorzBorder()); - wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); - m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); - textsizer->Add( m_text, 1, wxCENTER | wxALL, 5 ); - mainsizer->Add( textsizer, 0, wxEXPAND ); + wxBoxSizer *textsizer = new wxBoxSizer(wxHORIZONTAL); + textsizer->Add(m_text, wxSizerFlags(1).Centre().Border()); + mainsizer->Add(textsizer, wxSizerFlags().Expand()); m_check = NULL; - m_choice = new wxChoice( this, ID_CHOICE ); - textsizer->Add( m_choice, 1, wxCENTER|wxALL, 5 ); + textsizer->Add(m_choice, wxSizerFlags(1).Centre().Border()); - wxSizer *bsizer = CreateButtonSizer( wxOK|wxCANCEL , false, 5 ); - if(bsizer->GetChildren().GetCount() > 0 ) - { - mainsizer->Add( bsizer, 0, wxEXPAND | wxALL, 5 ); - } - else - { - delete bsizer; - } + wxSizer *bsizer = CreateButtonSizer(wxOK | wxCANCEL); + if ( bsizer ) + mainsizer->Add(bsizer, wxSizerFlags().Expand().Border()); } - else + else // !is_pda { - mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 ); - - wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); - m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); - textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); - textsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); - mainsizer->Add( textsizer, 0, wxEXPAND ); - - wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); - m_choice = new wxChoice( this, ID_CHOICE ); - choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 ); - m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") ); - m_check->SetValue( ms_lastShowHidden ); - choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 ); - choicesizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 10 ); - mainsizer->Add( choicesizer, 0, wxEXPAND ); + mainsizer->Add(m_list, wxSizerFlags(1).Expand().DoubleHorzBorder()); + + wxBoxSizer *textsizer = new wxBoxSizer(wxHORIZONTAL); + textsizer->Add(m_text, wxSizerFlags(1).Centre(). + DoubleBorder(wxLEFT | wxRIGHT | wxTOP)); + textsizer->Add(new wxButton(this, wxID_OK), wxSizerFlags().Centre(). + DoubleBorder(wxLEFT | wxRIGHT | wxTOP)); + mainsizer->Add(textsizer, wxSizerFlags().Expand()); + + wxSizerFlags flagsCentre; + flagsCentre.Centre().DoubleBorder(); + + wxBoxSizer *choicesizer = new wxBoxSizer(wxHORIZONTAL); + choicesizer->Add(m_choice, wxSizerFlags(flagsCentre).Proportion(1)); + + m_check = new wxCheckBox(this, ID_CHECK, _("Show &hidden files")); + m_check->SetValue(ms_lastShowHidden); + + choicesizer->Add(m_check, flagsCentre); + choicesizer->Add(new wxButton(this, wxID_CANCEL), flagsCentre); + mainsizer->Add(choicesizer, wxSizerFlags().Expand()); } SetWildcard(wildCard); @@ -1332,13 +1334,21 @@ void wxGenericFileDialog::OnSelected( wxListEvent &event ) // No double-click on most WinCE devices, so do action immediately. HandleAction( filename ); #else - if (filename == wxT("..")) return; + if (filename == wxT("..")) + { + inSelected = false; + return; + } wxString dir = m_list->GetDir(); if (!IsTopMostDir(dir)) dir += wxFILE_SEP_PATH; dir += filename; - if (wxDirExists(dir)) return; + if (wxDirExists(dir)) + { + inSelected = false; + return; + } ignoreChanges = true; m_text->SetValue( filename ); @@ -1396,7 +1406,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn ) } #endif // __UNIX__ - if (!(m_dialogStyle & wxSAVE)) + if (!HasFdFlag(wxFD_SAVE)) { if ((filename.Find(wxT('*')) != wxNOT_FOUND) || (filename.Find(wxT('?')) != wxNOT_FOUND)) @@ -1441,14 +1451,13 @@ void wxGenericFileDialog::HandleAction( const wxString &fn ) // VZ: the logic of testing for !wxFileExists() only for the open file // dialog is not entirely clear to me, why don't we allow saving to a // file without extension as well? - if ( !(m_dialogStyle & wxOPEN) || !wxFileExists(filename) ) + if ( !HasFdFlag(wxFD_OPEN) || !wxFileExists(filename) ) { filename = AppendExtension(filename, m_filterExtension); } // check that the file [doesn't] exist if necessary - if ( (m_dialogStyle & wxSAVE) && - (m_dialogStyle & wxOVERWRITE_PROMPT) && + if ( HasFdFlag(wxFD_SAVE) && HasFdFlag(wxFD_OVERWRITE_PROMPT) && wxFileExists( filename ) ) { wxString msg; @@ -1457,8 +1466,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn ) if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES) return; } - else if ( (m_dialogStyle & wxOPEN) && - (m_dialogStyle & wxFILE_MUST_EXIST) && + else if ( HasFdFlag(wxFD_OPEN) && HasFdFlag(wxFD_FILE_MUST_EXIST) && !wxFileExists(filename) ) { wxMessageBox(_("Please choose an existing file."), _("Error"), @@ -1468,7 +1476,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn ) SetPath( filename ); // change to the directory where the user went if asked - if ( m_dialogStyle & wxCHANGE_DIR ) + if ( HasFdFlag(wxFD_CHANGE_DIR) ) { wxString cwd; wxSplitPath(filename, &cwd, NULL, NULL); @@ -1623,10 +1631,10 @@ void wxGenericFileDialog::UpdateControls() #endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) } -#ifdef USE_GENERIC_FILEDIALOG +#ifdef wxUSE_GENERIC_FILEDIALOG IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog) -#endif // USE_GENERIC_FILEDIALOG +#endif // wxUSE_GENERIC_FILEDIALOG #endif // wxUSE_FILEDLG