-/////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
// Name: filedlgg.cpp
// Purpose: wxGenericFileDialog
// Author: Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "filedlgg.h"
#endif
#if wxUSE_FILEDLG
// NOTE : it probably also supports MAC, untested
-#if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__)
+#if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__) && !defined(__OS2__)
#error wxGenericFileDialog currently only supports Unix, win32 and DOS
#endif
#endif
#endif
+#ifdef __WINDOWS__
+ #include "wx/msw/wrapwin.h"
+ #include "wx/msw/mslu.h"
+#endif
+
#ifdef __WATCOMC__
#include <direct.h>
#endif
// ----------------------------------------------------------------------------
static
-int wxFileDataNameCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long data)
{
wxFileData *fd1 = (wxFileData*)data1;
wxFileData *fd2 = (wxFileData*)data2;
}
static
-int wxFileDataSizeCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataSizeCompare( long data1, long data2, long data)
{
wxFileData *fd1 = (wxFileData*)data1;
wxFileData *fd2 = (wxFileData*)data2;
}
static
-int wxFileDataTypeCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataTypeCompare( long data1, long data2, long data)
{
wxFileData *fd1 = (wxFileData*)data1;
wxFileData *fd2 = (wxFileData*)data2;
}
static
-int wxFileDataTimeCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataTimeCompare( long data1, long data2, long data)
{
wxFileData *fd1 = (wxFileData*)data1;
wxFileData *fd2 = (wxFileData*)data2;
return fd1->GetDateTime().IsLaterThan(fd2->GetDateTime()) ? int(data) : -int(data);
}
-#ifdef __UNIX__
+#if defined(__UNIX__) && !defined(__OS2__)
#define IsTopMostDir(dir) (dir == wxT("/"))
#endif
-#if defined(__DOS__) || defined(__WINDOWS__)
+#if defined(__DOS__) || defined(__WINDOWS__) || defined (__OS2__)
#define IsTopMostDir(dir) (dir.IsEmpty())
#endif
// 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;
ReadData();
}
+void wxFileData::Copy( 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();
+}
+
void wxFileData::ReadData()
{
if (IsDrive())
return;
}
-#if defined(__DOS__) || defined(__WINDOWS__)
+#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
// c:\.. is a drive don't stat it
if ((m_fileName == wxT("..")) && (m_filePath.length() <= 5))
{
wxStructStat buff;
-#if defined(__UNIX__) && (!defined( __EMX__ ) && !defined(__VMS))
+#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()
// try to get a better icon
if (m_image == wxFileIconsTable::file)
{
- if (IsExe())
+ if (m_fileName.Find(wxT('.'), TRUE) != wxNOT_FOUND)
+ {
+ m_image = wxTheFileIconsTable->GetIconID( m_fileName.AfterLast(wxT('.')));
+ } else 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;
if (IsLink())
{
- wxColour *dg = wxTheColourDatabase->FindColour( _T("MEDIUM GREY") );
- item.SetTextColour(*dg);
+ wxColour dg = wxTheColourDatabase->Find( _T("MEDIUM GREY") );
+ if ( dg.Ok() )
+ item.SetTextColour(dg);
}
item.m_data = (long)this;
}
BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
+ EVT_LIST_DELETE_ALL_ITEMS(-1, wxFileCtrl::OnListDeleteAllItems)
EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
EVT_LIST_COL_CLICK(-1, wxFileCtrl::OnListColClick)
END_EVENT_TABLE()
wxBusyCursor bcur; // this may take a while...
- FreeAllItemsData();
DeleteAllItems();
- wxFileData *fd = (wxFileData *) NULL;
wxListItem item;
item.m_itemId = 0;
item.m_col = 0;
-#if defined(__WINDOWS__) || defined(__DOS__) || defined(__WXMAC__) || defined(__WXPM__)
+#if defined(__WINDOWS__) || defined(__DOS__) || defined(__WXMAC__) || defined(__OS2__)
if ( IsTopMostDir(m_dirName) )
{
wxArrayString names, paths;
for (n=0; n<count; n++)
{
- fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]);
- Add(fd, item);
+ 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
if ( !IsTopMostDir(m_dirName) )
{
wxString p(wxPathOnly(m_dirName));
-#ifdef __UNIX__
+#if defined(__UNIX__) && !defined(__OS2__)
if (p.IsEmpty()) p = wxT("/");
#endif // __UNIX__
- fd = new wxFileData(p, wxT(".."), wxFileData::is_dir, wxFileIconsTable::folder);
- Add(fd, item);
+ 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__)
+#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
if (dirname.length() == 2 && dirname[1u] == wxT(':'))
dirname << wxT('\\');
-#endif // defined(__DOS__) || defined(__WINDOWS__)
+#endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
wxDir dir(dirname);
if ( dir.IsOpened() )
cont = dir.GetFirst(&f, wxEmptyString, wxDIR_DIRS | hiddenFlag);
while (cont)
{
- fd = new wxFileData(dirPrefix + f, f, wxFileData::is_dir, wxFileIconsTable::folder);
- Add(fd, item);
+ 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);
}
wxDIR_FILES | hiddenFlag);
while (cont)
{
- fd = new wxFileData(dirPrefix + f, f, wxFileData::is_file, wxFileIconsTable::file);
- Add(fd, item);
+ 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);
}
}
EnsureVisible( id );
EditLabel( id );
}
+ else
+ delete fd;
}
void wxFileCtrl::GoToParentDir()
m_dirName.Remove( len-1, 1 );
wxString fname( wxFileNameFromPath(m_dirName) );
m_dirName = wxPathOnly( m_dirName );
-#if defined(__DOS__) || defined(__WINDOWS__)
+#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
if (!m_dirName.IsEmpty())
{
if (m_dirName.Last() == wxT('.'))
EnsureVisible( 0 );
}
-void wxFileCtrl::FreeItemData(const wxListItem& item)
+void wxFileCtrl::FreeItemData(wxListItem& item)
{
- wxFileData *fd = (wxFileData*)item.m_data;
- delete fd;
+ if ( item.m_data )
+ {
+ wxFileData *fd = (wxFileData*)item.m_data;
+ delete fd;
+
+ item.m_data = 0;
+ }
}
void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
FreeItemData(event.m_item);
}
+void wxFileCtrl::OnListDeleteAllItems( wxListEvent &event )
+{
+ FreeAllItemsData();
+}
+
void wxFileCtrl::FreeAllItemsData()
{
wxListItem item;
wxFileCtrl::~wxFileCtrl()
{
- FreeAllItemsData();
}
//-----------------------------------------------------------------------------
wxArrayString wildDescriptions, wildFilters;
if ( !ParseWildcard(m_wildCard, wildDescriptions, wildFilters) )
{
- wxFAIL_MSG( wxT("Wrong file type descripition") );
+ wxFAIL_MSG( wxT("Wrong file type description") );
}
// layout
// PDAs have a different screen layout
mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 );
- wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
- m_choice = new wxChoice( this, ID_CHOICE );
- choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 5 );
- mainsizer->Add( choicesizer, 0, wxEXPAND );
-
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER );
textsizer->Add( m_text, 1, wxCENTER | wxALL, 5 );
mainsizer->Add( textsizer, 0, wxEXPAND );
- m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") );
- m_check->SetValue( ms_lastShowHidden );
- textsizer->Add( m_check, 0, wxCENTER|wxALL, 5 );
+ m_check = NULL;
+ m_choice = new wxChoice( this, ID_CHOICE );
+ textsizer->Add( m_choice, 1, wxCENTER|wxALL, 5 );
buttonsizer = new wxBoxSizer( wxHORIZONTAL );
buttonsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxCENTER | wxALL, 5 );
return wxDialog::ShowModal();
}
+bool wxGenericFileDialog::Show( bool show )
+{
+ if (show)
+ {
+ m_list->GoToDir(m_dir);
+ UpdateControls();
+ m_text->SetValue(m_fileName);
+ }
+
+ return wxDialog::Show( show );
+}
+
void wxGenericFileDialog::DoSetFilterIndex(int filterindex)
{
wxString *str = (wxString*) m_choice->GetClientData( filterindex );
wxFileExists( filename ) )
{
wxString msg;
- msg.Printf( _("File '%s' already exists, do you really want to "
- "overwrite it?"), filename.c_str() );
+ msg.Printf( _("File '%s' already exists, do you really want to overwrite it?"), filename.c_str() );
if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
return;
wxString cwd;
wxSplitPath(filename, &cwd, NULL, NULL);
- if ( cwd != wxGetWorkingDirectory() )
+ if ( cwd != wxGetCwd() )
{
wxSetWorkingDirectory(cwd);
}
bool enable = !IsTopMostDir(dir);
m_upDirButton->Enable(enable);
-#if defined(__DOS__) || defined(__WINDOWS__)
+#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
m_newDirButton->Enable(enable);
-#endif // defined(__DOS__) || defined(__WINDOWS__)
+#endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
}
#ifdef USE_GENERIC_FILEDIALOG