-#if defined(__DOS__) || defined(__WINDOWS__) || defined (__OS2__)
-#define IsTopMostDir(dir) (dir.IsEmpty())
-#endif
-
-#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
-// defined in src/generic/dirctrlg.cpp
-extern bool wxIsDriveAvailable(const wxString& dirName);
-#endif
-
-// defined in src/generic/dirctrlg.cpp
-extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids);
-
-//-----------------------------------------------------------------------------
-// wxFileData
-//-----------------------------------------------------------------------------
-
-wxFileData::wxFileData( const wxFileData& fileData )
-{
- m_fileName = fileData.GetFileName();
- m_filePath = fileData.GetFilePath();
- m_size = fileData.GetSize();
- m_dateTime = fileData.GetDateTime();
- m_permissions = fileData.GetPermissions();
- m_type = fileData.GetType();
- m_image = GetImageId();
-}
-
-wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id )
-{
- m_fileName = fileName;
- m_filePath = filePath;
- m_type = type;
- m_image = image_id;
-
- ReadData();
-}
-
-void wxFileData::ReadData()
-{
- if (IsDrive())
- {
- m_size = 0;
- return;
- }
-
-#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
- // c:\.. is a drive don't stat it
- if ((m_fileName == wxT("..")) && (m_filePath.length() <= 5))
- {
- m_type = is_drive;
- m_size = 0;
- return;
- }
-#endif // __DOS__ || __WINDOWS__
-
- wxStructStat buff;
-
-#if defined(__UNIX__) && (!defined( __OS2__ ) && !defined(__VMS))
- lstat( m_filePath.fn_str(), &buff );
- m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0;
-#else // no lstat()
- wxStat( m_filePath, &buff );
-#endif
-
- m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0;
- m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0;
-
- // try to get a better icon
- if (m_image == wxFileIconsTable::file)
- {
- if (IsExe())
- m_image = wxFileIconsTable::executable;
- else if (m_fileName.Find(wxT('.'), TRUE) != wxNOT_FOUND)
- m_image = wxTheFileIconsTable->GetIconID(m_fileName.AfterLast(wxT('.')));
- }
-
- m_size = buff.st_size;
-
- m_dateTime = buff.st_mtime;
-
-#if defined(__UNIX__)
- m_permissions.Printf(_T("%c%c%c%c%c%c%c%c%c"),
- buff.st_mode & wxS_IRUSR ? _T('r') : _T('-'),
- buff.st_mode & wxS_IWUSR ? _T('w') : _T('-'),
- buff.st_mode & wxS_IXUSR ? _T('x') : _T('-'),
- buff.st_mode & wxS_IRGRP ? _T('r') : _T('-'),
- buff.st_mode & wxS_IWGRP ? _T('w') : _T('-'),
- buff.st_mode & wxS_IXGRP ? _T('x') : _T('-'),
- buff.st_mode & wxS_IROTH ? _T('r') : _T('-'),
- buff.st_mode & wxS_IWOTH ? _T('w') : _T('-'),
- buff.st_mode & wxS_IXOTH ? _T('x') : _T('-'));
-#elif defined(__WIN32__)
- DWORD attribs = GetFileAttributes(m_filePath);
- if (attribs != (DWORD)-1)
- {
- m_permissions.Printf(_T("%c%c%c%c"),
- attribs & FILE_ATTRIBUTE_ARCHIVE ? _T('A') : _T(' '),
- attribs & FILE_ATTRIBUTE_READONLY ? _T('R') : _T(' '),
- attribs & FILE_ATTRIBUTE_HIDDEN ? _T('H') : _T(' '),
- attribs & FILE_ATTRIBUTE_SYSTEM ? _T('S') : _T(' '));
- }
-#endif
-}
-
-wxString wxFileData::GetFileType() const
-{
- if (IsDir())
- return _("<DIR>");
- else if (IsLink())
- return _("<LINK>");
- else if (IsDrive())
- return _("<DRIVE>");
- else if (m_fileName.Find(wxT('.'), TRUE) != wxNOT_FOUND)
- return m_fileName.AfterLast(wxT('.'));
-
- return wxEmptyString;
-}
-
-wxString wxFileData::GetModificationTime() const
-{
- // want time as 01:02 so they line up nicely, no %r in WIN32
- return m_dateTime.FormatDate() + wxT(" ") + m_dateTime.Format(wxT("%I:%M:%S %p"));
-}
-
-wxString wxFileData::GetHint() const
-{
- wxString s = m_filePath;
- s += wxT(" ");
-
- if (IsDir())
- s += _("<DIR>");
- else if (IsLink())
- s += _("<LINK>");
- else if (IsDrive())
- s += _("<DRIVE>");
- else // plain file
- s += wxString::Format( _("%ld bytes"), m_size );
-
- s += wxT(' ');
-
- if ( !IsDrive() )
- {
- s << GetModificationTime()
- << wxT(" ")
- << m_permissions;
- }
-
- return s;
-};
-
-wxString wxFileData::GetEntry( fileListFieldType num ) const
-{
- wxString s;
- switch ( num )
- {
- case FileList_Name:
- s = m_fileName;
- break;
-
- case FileList_Size:
- if (!IsDir() && !IsLink() && !IsDrive())
- s.Printf(_T("%ld"), m_size);
- break;
-
- case FileList_Type:
- s = GetFileType();
- break;
-
- case FileList_Time:
- if (!IsDrive())
- s = GetModificationTime();
- break;
-
-#if defined(__UNIX__) || defined(__WIN32__)
- case FileList_Perm:
- s = m_permissions;
- break;
-#endif // defined(__UNIX__) || defined(__WIN32__)
-
- default:
- wxFAIL_MSG( _T("unexpected field in wxFileData::GetEntry()") );
- }
-
- return s;
-}
-
-void wxFileData::SetNewName( const wxString &filePath, const wxString &fileName )
-{
- m_fileName = fileName;
- m_filePath = filePath;
-}
-
-void wxFileData::MakeItem( wxListItem &item )
-{
- item.m_text = m_fileName;
- item.ClearAttributes();
- if (IsExe())
- item.SetTextColour(*wxRED);
- if (IsDir())
- item.SetTextColour(*wxBLUE);
-
- item.m_image = m_image;
-
- if (IsLink())
- {
- wxColour dg = wxTheColourDatabase->Find( _T("MEDIUM GREY") );
- if ( dg.Ok() )
- item.SetTextColour(dg);
- }
- item.m_data = (long)this;
-}
-