-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;