- wxStat( m_filePath, &buff );
-#endif
-#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 (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND)
- {
- m_image = wxTheFileIconsTable->GetIconID( m_fileName.AfterLast(wxT('.')));
- } else if (IsExe())
- {
- m_image = wxFileIconsTable::executable;
- }
- }
-
- m_size = (long)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;
-}
-
-//-----------------------------------------------------------------------------
-// wxFileCtrl
-//-----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl)
-
-BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
- EVT_LIST_DELETE_ITEM(wxID_ANY, wxFileCtrl::OnListDeleteItem)
- EVT_LIST_DELETE_ALL_ITEMS(wxID_ANY, wxFileCtrl::OnListDeleteAllItems)
- EVT_LIST_END_LABEL_EDIT(wxID_ANY, wxFileCtrl::OnListEndLabelEdit)
- EVT_LIST_COL_CLICK(wxID_ANY, wxFileCtrl::OnListColClick)
-END_EVENT_TABLE()
-
-
-wxFileCtrl::wxFileCtrl()
-{
- m_showHidden = false;
- m_sort_foward = 1;
- m_sort_field = wxFileData::FileList_Name;
-}
-
-wxFileCtrl::wxFileCtrl(wxWindow *win,
- wxWindowID id,
- const wxString& wild,
- bool showHidden,
- const wxPoint& pos,
- const wxSize& size,
- long style,
- const wxValidator &validator,
- const wxString &name)
- : wxListCtrl(win, id, pos, size, style, validator, name),
- m_wild(wild)
-{
- wxImageList *imageList = wxTheFileIconsTable->GetSmallImageList();
-
- SetImageList( imageList, wxIMAGE_LIST_SMALL );
-
- m_showHidden = showHidden;
-
- m_sort_foward = 1;
- m_sort_field = wxFileData::FileList_Name;
-
- m_dirName = wxT("*");
-
- if (style & wxLC_REPORT)
- ChangeToReportMode();
-}
-
-void wxFileCtrl::ChangeToListMode()
-{
- ClearAll();
- SetSingleStyle( wxLC_LIST );
- UpdateFiles();
-}
-
-void wxFileCtrl::ChangeToReportMode()
-{
- ClearAll();
- SetSingleStyle( wxLC_REPORT );
-
- // do this since WIN32 does mm/dd/yy UNIX does mm/dd/yyyy
- // don't hardcode since mm/dd is dd/mm elsewhere
- int w, h;
- wxDateTime dt(22, wxDateTime::Dec, 2002, 22, 22, 22);
- wxString txt = dt.FormatDate() + wxT("22") + dt.Format(wxT("%I:%M:%S %p"));
- GetTextExtent(txt, &w, &h);
-
- InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT, w );
- InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, w/2 );
- InsertColumn( 2, _("Type"), wxLIST_FORMAT_LEFT, w/2 );
- InsertColumn( 3, _("Modified"), wxLIST_FORMAT_LEFT, w );
-#if defined(__UNIX__)
- GetTextExtent(wxT("Permissions 2"), &w, &h);
- InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, w );
-#elif defined(__WIN32__)
- GetTextExtent(wxT("Attributes 2"), &w, &h);
- InsertColumn( 4, _("Attributes"), wxLIST_FORMAT_LEFT, w );
-#endif
-
- UpdateFiles();
-}
-
-void wxFileCtrl::ChangeToSmallIconMode()
-{
- ClearAll();
- SetSingleStyle( wxLC_SMALL_ICON );
- UpdateFiles();
-}
-
-void wxFileCtrl::ShowHidden( bool show )
-{
- m_showHidden = show;
- UpdateFiles();
-}
-
-long wxFileCtrl::Add( wxFileData *fd, wxListItem &item )
-{
- long ret = -1;
- item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE;
- fd->MakeItem( item );
- long my_style = GetWindowStyleFlag();
- if (my_style & wxLC_REPORT)
- {
- ret = InsertItem( item );
- for (int i = 1; i < wxFileData::FileList_Max; i++)
- SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) );
- }
- else if ((my_style & wxLC_LIST) || (my_style & wxLC_SMALL_ICON))
- {
- ret = InsertItem( item );
- }
- return ret;
-}
-
-void wxFileCtrl::UpdateItem(const wxListItem &item)
-{
- wxFileData *fd = (wxFileData*)GetItemData(item);
- wxCHECK_RET(fd, wxT("invalid filedata"));
-
- fd->ReadData();
-
- SetItemText(item, fd->GetFileName());
- SetItemImage(item, fd->GetImageId());
-
- if (GetWindowStyleFlag() & wxLC_REPORT)
- {
- for (int i = 1; i < wxFileData::FileList_Max; i++)
- SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) );
- }
-}
-
-void wxFileCtrl::UpdateFiles()
-{
- // don't do anything before ShowModal() call which sets m_dirName
- if ( m_dirName == wxT("*") )
- return;
-
- wxBusyCursor bcur; // this may take a while...
-
- DeleteAllItems();
-
- wxListItem item;
- item.m_itemId = 0;
- item.m_col = 0;
-
-#if defined(__WINDOWS__) || defined(__DOS__) || defined(__WXMAC__) || defined(__OS2__)
- if ( IsTopMostDir(m_dirName) )
- {
- wxArrayString names, paths;
- wxArrayInt icons;
- size_t n, count = wxGetAvailableDrives(paths, names, icons);
-
- for (n=0; n<count; n++)
- {
- wxFileData *fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]);
- if (Add(fd, item) != -1)
- item.m_itemId++;
- else
- delete fd;
- }
- }
- else
-#endif // defined(__DOS__) || defined(__WINDOWS__)
- {
- // Real directory...
- if ( !IsTopMostDir(m_dirName) )
- {
- wxString p(wxPathOnly(m_dirName));
-#if defined(__UNIX__) && !defined(__OS2__)
- if (p.empty()) p = wxT("/");
-#endif // __UNIX__
- wxFileData *fd = new wxFileData(p, wxT(".."), wxFileData::is_dir, wxFileIconsTable::folder);
- if (Add(fd, item) != -1)
- item.m_itemId++;
- else
- delete fd;
- }
-
- wxString dirname(m_dirName);
-#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
- if (dirname.length() == 2 && dirname[1u] == wxT(':'))
- dirname << wxT('\\');
-#endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
- wxDir dir(dirname);
-
- if ( dir.IsOpened() )
- {
- wxString dirPrefix(dirname);
- if (dirPrefix.Last() != wxFILE_SEP_PATH)
- dirPrefix += wxFILE_SEP_PATH;
-
- int hiddenFlag = m_showHidden ? wxDIR_HIDDEN : 0;
-
- bool cont;
- wxString f;
-
- // Get the directories first (not matched against wildcards):
- cont = dir.GetFirst(&f, wxEmptyString, wxDIR_DIRS | hiddenFlag);
- while (cont)
- {
- wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_dir, wxFileIconsTable::folder);
- if (Add(fd, item) != -1)
- item.m_itemId++;
- else
- delete fd;
-
- cont = dir.GetNext(&f);
- }
-
- // Tokenize the wildcard string, so we can handle more than 1
- // search pattern in a wildcard.
- wxStringTokenizer tokenWild(m_wild, wxT(";"));
- while ( tokenWild.HasMoreTokens() )
- {
- cont = dir.GetFirst(&f, tokenWild.GetNextToken(),
- wxDIR_FILES | hiddenFlag);
- while (cont)
- {
- wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_file, wxFileIconsTable::file);
- if (Add(fd, item) != -1)
- item.m_itemId++;
- else
- delete fd;
-
- cont = dir.GetNext(&f);
- }
- }
- }
- }
-
- SortItems(m_sort_field, m_sort_foward);
-}
-
-void wxFileCtrl::SetWild( const wxString &wild )
-{
- if (wild.Find(wxT('|')) != wxNOT_FOUND)
- return;
-
- m_wild = wild;
- UpdateFiles();
-}
-
-void wxFileCtrl::MakeDir()
-{
- wxString new_name( _("NewName") );
- wxString path( m_dirName );
- path += wxFILE_SEP_PATH;
- path += new_name;
- if (wxFileExists(path))
- {
- // try NewName0, NewName1 etc.
- int i = 0;
- do {
- new_name = _("NewName");
- wxString num;
- num.Printf( wxT("%d"), i );
- new_name += num;
-
- path = m_dirName;
- path += wxFILE_SEP_PATH;
- path += new_name;
- i++;
- } while (wxFileExists(path));
- }
-
- wxLogNull log;
- if (!wxMkdir(path))
- {
- wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- return;
- }
-
- wxFileData *fd = new wxFileData( path, new_name, wxFileData::is_dir, wxFileIconsTable::folder );
- wxListItem item;
- item.m_itemId = 0;
- item.m_col = 0;
- long id = Add( fd, item );
-
- if (id != -1)
- {
- SortItems(m_sort_field, m_sort_foward);
- id = FindItem( 0, (long)fd );
- EnsureVisible( id );
- EditLabel( id );
- }
- else
- delete fd;
-}
-
-void wxFileCtrl::GoToParentDir()
-{
- if (!IsTopMostDir(m_dirName))
- {
- size_t len = m_dirName.Len();
- if (wxEndsWithPathSeparator(m_dirName))
- m_dirName.Remove( len-1, 1 );
- wxString fname( wxFileNameFromPath(m_dirName) );
- m_dirName = wxPathOnly( m_dirName );
-#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
- if (!m_dirName.empty())
- {
- if (m_dirName.Last() == wxT('.'))
- m_dirName = wxEmptyString;
- }
-#elif defined(__UNIX__)
- if (m_dirName.empty())
- m_dirName = wxT("/");