X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/551adc4b47dabeb4c7f39df9922bdcb5d0d03c68..4aaef122cbbd5bbe0e70b824e320458e2329dd13:/src/generic/filedlgg.cpp diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index f0f9ad244c..214a64ddab 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -22,8 +22,8 @@ #if wxUSE_FILEDLG -#ifndef __UNIX__ -#error wxFileDialog currently only supports unix +#if !defined(__UNIX__) && !defined(__DOS__) +#error wxFileDialog currently only supports Unix and DOS #endif #include "wx/checkbox.h" @@ -52,15 +52,25 @@ #include #include -#include -#include -#ifndef __VMS -# include + +#ifdef __UNIX__ + #include + #include + #ifndef __VMS + # include + #endif +#endif + +#ifdef __WATCOMC__ + #include #endif + # include #include +#ifndef __DOS__ #include "wx/generic/home.xpm" +#endif #include "wx/generic/listview.xpm" #include "wx/generic/repview.xpm" #include "wx/generic/new_dir.xpm" @@ -203,6 +213,10 @@ wxFileIconsTable::wxFileIconsTable() : +#if wxUSE_MIMETYPE +// VS: we don't need this function w/o wxMimeTypesManager because we'll only have +// one icon and we won't resize it + static wxBitmap CreateAntialiasedBitmap(const wxImage& img) { wxImage small(16, 16); @@ -251,7 +265,6 @@ static wxBitmap CreateAntialiasedBitmap(const wxImage& img) return small.ConvertToBitmap(); } - // finds empty borders and return non-empty area of image: static wxImage CutEmptyBorders(const wxImage& img) { @@ -295,11 +308,13 @@ static wxImage CutEmptyBorders(const wxImage& img) return img.GetSubImage(wxRect(left, top, right - left + 1, bottom - top + 1)); } +#endif // wxUSE_MIMETYPE int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime) { +#if wxUSE_MIMETYPE if (!extension.IsEmpty()) { wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable.Get(extension); @@ -331,6 +346,14 @@ int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime) } m_HashTable.Put(extension, new wxFileIconEntry(id)); return id; + +#else // !wxUSE_MIMETYPE + + if (extension == wxT("exe")) + return FI_EXECUTABLE; + else + return FI_UNKNOWN; +#endif // wxUSE_MIMETYPE/!wxUSE_MIMETYPE } @@ -365,7 +388,7 @@ wxFileData::wxFileData( const wxString &name, const wxString &fname ) struct stat buff; stat( m_fileName.fn_str(), &buff ); -#if !defined( __EMX__ ) && !defined(__VMS) +#if defined(__UNIX__) && (!defined( __EMX__ ) && !defined(__VMS)) struct stat lbuff; lstat( m_fileName.fn_str(), &lbuff ); m_isLink = S_ISLNK( lbuff.st_mode ); @@ -543,7 +566,11 @@ END_EVENT_TABLE() wxFileCtrl::wxFileCtrl() { +#if defined(__UNIX__) m_dirName = wxT("/"); +#elif defined(__DOS__) + m_dirName = wxT("C:\\"); +#endif m_showHidden = FALSE; } @@ -596,8 +623,14 @@ long wxFileCtrl::Add( wxFileData *fd, wxListItem &item ) long my_style = GetWindowStyleFlag(); if (my_style & wxLC_REPORT) { +#ifdef __UNIX__ + const int noEntries = 5; +#else + const int noEntries = 4; +#endif ret = InsertItem( item ); - for (int i = 1; i < 5; i++) SetItem( item.m_itemId, i, fd->GetEntry( i) ); + for (int i = 1; i < noEntries; i++) + SetItem( item.m_itemId, i, fd->GetEntry( i) ); } else if (my_style & wxLC_LIST) { @@ -624,7 +657,9 @@ void wxFileCtrl::Update() InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, 60 ); InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT, 65 ); InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT, 50 ); +#ifdef __UNIX__ InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, 120 ); +#endif } wxFileData *fd = (wxFileData *) NULL; wxListItem item; @@ -640,7 +675,11 @@ void wxFileCtrl::Update() item.m_itemId++; } +#if defined(__UNIX__) wxString res = m_dirName + wxT("/*"); +#elif defined(__DOS__) + wxString res = m_dirName + wxT("\\*.*"); +#endif wxString f( wxFindFirstFile( res.GetData(), wxDIR ) ); while (!f.IsEmpty()) { @@ -660,7 +699,7 @@ void wxFileCtrl::Update() wxStringTokenizer tokenWild( m_wild, ";" ); while ( tokenWild.HasMoreTokens() ) { - res = m_dirName + wxT("/") + tokenWild.GetNextToken(); + res = m_dirName + wxFILE_SEP_PATH + tokenWild.GetNextToken(); f = wxFindFirstFile( res.GetData(), wxFILE ); while (!f.IsEmpty()) { @@ -696,7 +735,7 @@ void wxFileCtrl::MakeDir() { wxString new_name( wxT("NewName") ); wxString path( m_dirName ); - path += wxT("/"); + path += wxFILE_SEP_PATH; path += new_name; if (wxFileExists(path)) { @@ -709,7 +748,7 @@ void wxFileCtrl::MakeDir() new_name += num; path = m_dirName; - path += wxT("/"); + path += wxFILE_SEP_PATH; path += new_name; i++; } while (wxFileExists(path)); @@ -742,6 +781,9 @@ void wxFileCtrl::GoToParentDir() { if (m_dirName != wxT("/")) { + size_t len = m_dirName.Len(); + if (m_dirName[len-1] == wxFILE_SEP_PATH) + m_dirName.Remove( len-1, 1 ); wxString fname( wxFileNameFromPath(m_dirName) ); m_dirName = wxPathOnly( m_dirName ); if (m_dirName.IsEmpty()) m_dirName = wxT("/"); @@ -808,7 +850,7 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) if ((event.GetLabel().IsEmpty()) || (event.GetLabel() == _(".")) || (event.GetLabel() == _("..")) || - (event.GetLabel().First( wxT("/") ) != wxNOT_FOUND)) + (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND)) { wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); @@ -817,7 +859,7 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) } wxString new_name( wxPathOnly( fd->GetFullName() ) ); - new_name += wxT("/"); + new_name += wxFILE_SEP_PATH; new_name += event.GetLabel(); wxLogNull log; @@ -902,13 +944,17 @@ wxFileDialog::wxFileDialog(wxWindow *parent, m_dialogStyle |= wxOPEN; m_dir = defaultDir; - if ((m_dir.IsEmpty()) || (m_dir == wxT("."))) + if ((m_dir.empty()) || (m_dir == wxT("."))) { - char buf[200]; - m_dir = getcwd( buf, sizeof(buf) ); + m_dir = wxGetCwd(); } - m_path = defaultDir; - m_path += wxT("/"); + + size_t len = m_dir.Len(); + if ((len > 1) && (m_dir[len-1] == wxFILE_SEP_PATH)) + m_dir.Remove( len-1, 1 ); + + m_path = m_dir; + m_path += wxFILE_SEP_PATH; m_path += defaultFile; m_fileName = defaultFile; m_wildCard = wildCard; @@ -966,6 +1012,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, #endif buttonsizer->Add( but, 0, wxALL, 5 ); +#ifndef __DOS__ // VS: Home directory is senseless in MS-DOS... but = new wxBitmapButton( this, ID_PARENT_DIR, wxBitmap(home_xpm) ); #if wxUSE_TOOLTIPS but->SetToolTip( _("Go to home directory") ); @@ -973,6 +1020,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, buttonsizer->Add( but, 0, wxALL, 5); buttonsizer->Add( 20, 20 ); +#endif //!__DOS__ but = new wxBitmapButton( this, ID_NEW_DIR, wxBitmap(new_dir_xpm) ); #if wxUSE_TOOLTIPS @@ -990,10 +1038,10 @@ wxFileDialog::wxFileDialog(wxWindow *parent, if (m_dialogStyle & wxMULTIPLE) m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, firstWild, wxDefaultPosition, - wxSize(440,180), s_lastViewStyle | wxSUNKEN_BORDER ); + wxSize(540,200), s_lastViewStyle | wxSUNKEN_BORDER ); else m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, firstWild, wxDefaultPosition, - wxSize(440,180), s_lastViewStyle | wxSUNKEN_BORDER | wxLC_SINGLE_SEL ); + wxSize(540,200), s_lastViewStyle | wxSUNKEN_BORDER | wxLC_SINGLE_SEL ); m_list -> ShowHidden(s_lastShowHidden); mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 ); @@ -1089,7 +1137,7 @@ void wxFileDialog::OnSelected( wxListEvent &event ) wxString dir; m_list->GetDir( dir ); - if (dir != wxT("/")) dir += wxT("/"); + if (dir != wxT("/")) dir += wxFILE_SEP_PATH; dir += filename; if (wxDirExists(dir)) return; @@ -1113,6 +1161,7 @@ void wxFileDialog::HandleAction( const wxString &fn ) return; } +#ifdef __UNIX__ if (filename == wxT("~")) { m_list->GoToHomeDir(); @@ -1130,11 +1179,12 @@ void wxFileDialog::HandleAction( const wxString &fn ) tmp += filename; filename = tmp; } +#endif // __UNIX__ if ((filename.Find(wxT('*')) != wxNOT_FOUND) || (filename.Find(wxT('?')) != wxNOT_FOUND)) { - if (filename.Find(wxT('/')) != wxNOT_FOUND) + if (filename.Find(wxFILE_SEP_PATH) != wxNOT_FOUND) { wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR ); return; @@ -1143,7 +1193,7 @@ void wxFileDialog::HandleAction( const wxString &fn ) return; } - if (dir != wxT("/")) dir += wxT("/"); + if (dir != wxT("/")) dir += wxFILE_SEP_PATH; if (filename[0u] != wxT('/')) { dir += filename; @@ -1162,7 +1212,7 @@ void wxFileDialog::HandleAction( const wxString &fn ) if ( (m_dialogStyle & wxSAVE) && (m_dialogStyle & wxOVERWRITE_PROMPT) ) { if (filename.Find( wxT('.') ) == wxNOT_FOUND || - filename.AfterLast( wxT('.') ).Find( wxT('/') ) != wxNOT_FOUND) + filename.AfterLast( wxT('.') ).Find( wxFILE_SEP_PATH ) != wxNOT_FOUND) filename << m_filterExtension; if (wxFileExists( filename )) { @@ -1178,7 +1228,7 @@ void wxFileDialog::HandleAction( const wxString &fn ) { if ( !wxFileExists( filename ) ) if (filename.Find( wxT('.') ) == wxNOT_FOUND || - filename.AfterLast( wxT('.') ).Find( wxT('/') ) != wxNOT_FOUND) + filename.AfterLast( wxT('.') ).Find( wxFILE_SEP_PATH ) != wxNOT_FOUND) filename << m_filterExtension; if ( m_dialogStyle & wxFILE_MUST_EXIST ) @@ -1280,7 +1330,7 @@ void wxFileDialog::GetPaths( wxArrayString& paths ) const wxString dir; m_list->GetDir( dir ); - if (dir != wxT("/")) dir += wxT("/"); + if (dir != wxT("/")) dir += wxFILE_SEP_PATH; wxListItem item; item.m_mask = wxLIST_MASK_TEXT;