X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c50e42a1223f6da4a07f5c8472a3fe7bf682356a..412e0d47c05d69cb029e9dbd11b31ce24fb2377e:/src/generic/filedlgg.cpp
diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp
index de3170c035..fc92b7327a 100644
--- a/src/generic/filedlgg.cpp
+++ b/src/generic/filedlgg.cpp
@@ -1,5 +1,5 @@
//////////////////////////////////////////////////////////////////////////////
-// Name: filedlgg.cpp
+// Name: src/generic/filedlgg.cpp
// Purpose: wxGenericFileDialog
// Author: Robert Roebling
// Modified by:
@@ -9,10 +9,6 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "filedlgg.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
@@ -34,6 +30,7 @@
#include "wx/stattext.h"
#include "wx/debug.h"
#include "wx/log.h"
+#include "wx/longlong.h"
#include "wx/intl.h"
#include "wx/msgdlg.h"
#include "wx/sizer.h"
@@ -83,69 +80,89 @@
// ----------------------------------------------------------------------------
static
-int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long sortOrder)
{
- wxFileData *fd1 = (wxFileData*)data1;
- wxFileData *fd2 = (wxFileData*)data2;
- if (fd1->GetFileName() == wxT("..")) return -data;
- if (fd2->GetFileName() == wxT("..")) return data;
- if (fd1->IsDir() && !fd2->IsDir()) return -data;
- if (fd2->IsDir() && !fd1->IsDir()) return data;
- return data*wxStrcmp( fd1->GetFileName(), fd2->GetFileName() );
+ wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
+ wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
+
+ if (fd1->GetFileName() == wxT(".."))
+ return -sortOrder;
+ if (fd2->GetFileName() == wxT(".."))
+ return sortOrder;
+ if (fd1->IsDir() && !fd2->IsDir())
+ return -sortOrder;
+ if (fd2->IsDir() && !fd1->IsDir())
+ return sortOrder;
+
+ return sortOrder*wxStrcmp( fd1->GetFileName(), fd2->GetFileName() );
}
static
-int wxCALLBACK wxFileDataSizeCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataSizeCompare(long data1, long data2, long sortOrder)
{
- wxFileData *fd1 = (wxFileData*)data1;
- wxFileData *fd2 = (wxFileData*)data2;
- if (fd1->GetFileName() == wxT("..")) return -data;
- if (fd2->GetFileName() == wxT("..")) return data;
- if (fd1->IsDir() && !fd2->IsDir()) return -data;
- if (fd2->IsDir() && !fd1->IsDir()) return data;
- if (fd1->IsLink() && !fd2->IsLink()) return -data;
- if (fd2->IsLink() && !fd1->IsLink()) return data;
- return data*(fd1->GetSize() - fd2->GetSize());
+ wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
+ wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
+
+ if (fd1->GetFileName() == wxT(".."))
+ return -sortOrder;
+ if (fd2->GetFileName() == wxT(".."))
+ return sortOrder;
+ if (fd1->IsDir() && !fd2->IsDir())
+ return -sortOrder;
+ if (fd2->IsDir() && !fd1->IsDir())
+ return sortOrder;
+ if (fd1->IsLink() && !fd2->IsLink())
+ return -sortOrder;
+ if (fd2->IsLink() && !fd1->IsLink())
+ return sortOrder;
+
+ return fd1->GetSize() > fd2->GetSize() ? sortOrder : -sortOrder;
}
static
-int wxCALLBACK wxFileDataTypeCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataTypeCompare(long data1, long data2, long sortOrder)
{
- wxFileData *fd1 = (wxFileData*)data1;
- wxFileData *fd2 = (wxFileData*)data2;
- if (fd1->GetFileName() == wxT("..")) return -data;
- if (fd2->GetFileName() == wxT("..")) return data;
- if (fd1->IsDir() && !fd2->IsDir()) return -data;
- if (fd2->IsDir() && !fd1->IsDir()) return data;
- if (fd1->IsLink() && !fd2->IsLink()) return -data;
- if (fd2->IsLink() && !fd1->IsLink()) return data;
- return data*wxStrcmp( fd1->GetFileType(), fd2->GetFileType() );
+ wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
+ wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
+
+ if (fd1->GetFileName() == wxT(".."))
+ return -sortOrder;
+ if (fd2->GetFileName() == wxT(".."))
+ return sortOrder;
+ if (fd1->IsDir() && !fd2->IsDir())
+ return -sortOrder;
+ if (fd2->IsDir() && !fd1->IsDir())
+ return sortOrder;
+ if (fd1->IsLink() && !fd2->IsLink())
+ return -sortOrder;
+ if (fd2->IsLink() && !fd1->IsLink())
+ return sortOrder;
+
+ return sortOrder*wxStrcmp( fd1->GetFileType(), fd2->GetFileType() );
}
static
-int wxCALLBACK wxFileDataTimeCompare( long data1, long data2, long data)
+int wxCALLBACK wxFileDataTimeCompare(long data1, long data2, long sortOrder)
{
- wxFileData *fd1 = (wxFileData*)data1;
- wxFileData *fd2 = (wxFileData*)data2;
- if (fd1->GetFileName() == wxT("..")) return -data;
- if (fd2->GetFileName() == wxT("..")) return data;
- if (fd1->IsDir() && !fd2->IsDir()) return -data;
- if (fd2->IsDir() && !fd1->IsDir()) return data;
-
- return fd1->GetDateTime().IsLaterThan(fd2->GetDateTime()) ? int(data) : -int(data);
+ wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
+ wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
+
+ if (fd1->GetFileName() == wxT(".."))
+ return -sortOrder;
+ if (fd2->GetFileName() == wxT(".."))
+ return sortOrder;
+ if (fd1->IsDir() && !fd2->IsDir())
+ return -sortOrder;
+ if (fd2->IsDir() && !fd1->IsDir())
+ return sortOrder;
+
+ return fd1->GetDateTime().IsLaterThan(fd2->GetDateTime()) ? sortOrder : -sortOrder;
}
-#if defined(__UNIX__) && !defined(__OS2__)
-#define IsTopMostDir(dir) (dir == wxT("/"))
-#endif
-
#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);
+#define IsTopMostDir(dir) (dir.empty())
+#else
+#define IsTopMostDir(dir) (dir == wxT("/"))
#endif
// defined in src/generic/dirctrlg.cpp
@@ -157,6 +174,7 @@ extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, w
wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id )
{
+ Init();
m_fileName = fileName;
m_filePath = filePath;
m_type = type;
@@ -165,6 +183,13 @@ wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, file
ReadData();
}
+void wxFileData::Init()
+{
+ m_size = 0;
+ m_type = wxFileData::is_file;
+ m_image = wxFileIconsTable::file;
+}
+
void wxFileData::Copy( const wxFileData& fileData )
{
m_fileName = fileData.GetFileName();
@@ -173,7 +198,7 @@ void wxFileData::Copy( const wxFileData& fileData )
m_dateTime = fileData.GetDateTime();
m_permissions = fileData.GetPermissions();
m_type = fileData.GetType();
- m_image = GetImageId();
+ m_image = fileData.GetImageId();
}
void wxFileData::ReadData()
@@ -200,7 +225,13 @@ void wxFileData::ReadData()
lstat( m_filePath.fn_str(), &buff );
m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0;
#else // no lstat()
+ // only translate to file charset if we don't go by our
+ // wxStat implementation
+#ifndef wxNEED_WX_UNISTD_H
+ wxStat( m_filePath.fn_str() , &buff );
+#else
wxStat( m_filePath, &buff );
+#endif
#endif
m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0;
@@ -254,7 +285,7 @@ wxString wxFileData::GetFileType() const
return _("");
else if (IsDrive())
return _("");
- else if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND)
+ else if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND)
return m_fileName.AfterLast(wxT('.'));
return wxEmptyString;
@@ -278,7 +309,8 @@ wxString wxFileData::GetHint() const
else if (IsDrive())
s += _("");
else // plain file
- s += wxString::Format( _("%ld bytes"), m_size );
+ s += wxString::Format(_("%ld bytes"),
+ wxLongLong(m_size).ToString().c_str());
s += wxT(' ');
@@ -290,7 +322,7 @@ wxString wxFileData::GetHint() const
}
return s;
-};
+}
wxString wxFileData::GetEntry( fileListFieldType num ) const
{
@@ -303,7 +335,7 @@ wxString wxFileData::GetEntry( fileListFieldType num ) const
case FileList_Size:
if (!IsDir() && !IsLink() && !IsDrive())
- s.Printf(_T("%ld"), m_size);
+ s = wxLongLong(m_size).ToString();
break;
case FileList_Type:
@@ -311,7 +343,7 @@ wxString wxFileData::GetEntry( fileListFieldType num ) const
break;
case FileList_Time:
- if (!IsDrive())
+ if (!IsDrive())
s = GetModificationTime();
break;
@@ -351,7 +383,7 @@ void wxFileData::MakeItem( wxListItem &item )
if ( dg.Ok() )
item.SetTextColour(dg);
}
- item.m_data = (long)this;
+ item.m_data = wxPtrToUInt(this);
}
//-----------------------------------------------------------------------------
@@ -476,7 +508,7 @@ void wxFileCtrl::UpdateItem(const wxListItem &item)
fd->ReadData();
SetItemText(item, fd->GetFileName());
- SetItemImage(item, fd->GetImageId(), fd->GetImageId());
+ SetItemImage(item, fd->GetImageId());
if (GetWindowStyleFlag() & wxLC_REPORT)
{
@@ -501,20 +533,20 @@ void wxFileCtrl::UpdateFiles()
#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; nSetToolTip( _("View files as a list view") );
#endif
buttonsizer->Add( but, 0, wxALL, 5 );
but = new wxBitmapButton(this, ID_REPORT_MODE,
- wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_CMN_DIALOG));
+ wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_BUTTON));
#if wxUSE_TOOLTIPS
but->SetToolTip( _("View files as a detailed view") );
#endif
@@ -933,7 +996,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
buttonsizer->Add( 30, 5, 1 );
m_upDirButton = new wxBitmapButton(this, ID_UP_DIR,
- wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_CMN_DIALOG));
+ wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_BUTTON));
#if wxUSE_TOOLTIPS
m_upDirButton->SetToolTip( _("Go to parent directory") );
#endif
@@ -941,7 +1004,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
#ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS...
but = new wxBitmapButton(this, ID_PARENT_DIR,
- wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_CMN_DIALOG));
+ wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_BUTTON));
#if wxUSE_TOOLTIPS
but->SetToolTip( _("Go to home directory") );
#endif
@@ -951,7 +1014,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
#endif //!__DOS__
m_newDirButton = new wxBitmapButton(this, ID_NEW_DIR,
- wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_CMN_DIALOG));
+ wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_BUTTON));
#if wxUSE_TOOLTIPS
m_newDirButton->SetToolTip( _("Create new directory") );
#endif
@@ -974,7 +1037,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
style2 |= wxLC_SINGLE_SEL;
m_list = new wxFileCtrl( this, ID_LIST_CTRL,
- wildFilters[0], ms_lastShowHidden,
+ wxEmptyString, ms_lastShowHidden,
wxDefaultPosition, wxSize(540,200),
style2);
@@ -993,8 +1056,8 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
textsizer->Add( m_choice, 1, wxCENTER|wxALL, 5 );
buttonsizer = new wxBoxSizer( wxHORIZONTAL );
- buttonsizer->Add( new wxButton( this, wxID_OK, wxSTOCK_OK ), 0, wxCENTER | wxALL, 5 );
- buttonsizer->Add( new wxButton( this, wxID_CANCEL, wxSTOCK_CANCEL ), 0, wxCENTER | wxALL, 5 );
+ buttonsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxALL, 5 );
+ buttonsizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 5 );
mainsizer->Add( buttonsizer, 0, wxALIGN_RIGHT );
}
else
@@ -1004,7 +1067,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER );
textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
- textsizer->Add( new wxButton( this, wxID_OK, wxSTOCK_OK ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
+ textsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
mainsizer->Add( textsizer, 0, wxEXPAND );
wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
@@ -1013,15 +1076,11 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") );
m_check->SetValue( ms_lastShowHidden );
choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 );
- choicesizer->Add( new wxButton( this, wxID_CANCEL, wxSTOCK_CANCEL ), 0, wxCENTER | wxALL, 10 );
+ choicesizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 10 );
mainsizer->Add( choicesizer, 0, wxEXPAND );
}
- for (size_t n=0; nAppend( wildDescriptions[n], (void*) new wxString( wildFilters[n] ) );
- }
- SetFilterIndex( 0 );
+ SetWildcard(wildCard);
SetAutoLayout( true );
SetSizer( mainsizer );
@@ -1032,22 +1091,27 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
Centre( wxBOTH );
m_text->SetFocus();
+
+ return true;
}
wxGenericFileDialog::~wxGenericFileDialog()
{
- if (wxConfig::Get(false))
+ if (!m_bypassGenericImpl)
{
- wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"),
- ms_lastViewStyle);
- wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"),
- ms_lastShowHidden);
- }
+ if (wxConfig::Get(false))
+ {
+ wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"),
+ ms_lastViewStyle);
+ wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"),
+ ms_lastShowHidden);
+ }
- const int count = m_choice->GetCount();
- for ( int i = 0; i < count; i++ )
- {
- delete (wxString *)m_choice->GetClientData(i);
+ const int count = m_choice->GetCount();
+ for ( int i = 0; i < count; i++ )
+ {
+ delete (wxString *)m_choice->GetClientData(i);
+ }
}
}
@@ -1089,6 +1153,31 @@ void wxGenericFileDialog::DoSetFilterIndex(int filterindex)
}
}
+void wxGenericFileDialog::SetWildcard(const wxString& wildCard)
+{
+ wxFileDialogBase::SetWildcard(wildCard);
+
+ wxArrayString wildDescriptions, wildFilters;
+ const size_t count = wxParseCommonDialogsFilter(m_wildCard,
+ wildDescriptions,
+ wildFilters);
+ wxCHECK_RET( count, wxT("wxFileDialog: bad wildcard string") );
+
+ const size_t countOld = m_choice->GetCount();
+ size_t n;
+ for ( n = 0; n < countOld; n++ )
+ {
+ delete (wxString *)m_choice->GetClientData(n);
+ }
+
+ for ( n = 0; n < count; n++ )
+ {
+ m_choice->Append( wildDescriptions[n], new wxString( wildFilters[n] ) );
+ }
+
+ SetFilterIndex( 0 );
+}
+
void wxGenericFileDialog::SetFilterIndex( int filterindex )
{
m_choice->SetSelection( filterindex );
@@ -1159,7 +1248,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
{
wxString filename( fn );
wxString dir = m_list->GetDir();
- if (filename.IsEmpty()) return;
+ if (filename.empty()) return;
if (filename == wxT(".")) return;
// "some/place/" means they want to chdir not try to load "place"
@@ -1186,20 +1275,23 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
if (filename.BeforeFirst(wxT('/')) == wxT("~"))
{
- filename = wxGetUserHome() + filename.Remove(0, 1);
+ filename = wxString(wxGetUserHome()) + filename.Remove(0, 1);
}
#endif // __UNIX__
- if ((filename.Find(wxT('*')) != wxNOT_FOUND) ||
- (filename.Find(wxT('?')) != wxNOT_FOUND))
+ if (!(m_dialogStyle & wxSAVE))
{
- if (filename.Find(wxFILE_SEP_PATH) != wxNOT_FOUND)
+ if ((filename.Find(wxT('*')) != wxNOT_FOUND) ||
+ (filename.Find(wxT('?')) != wxNOT_FOUND))
{
- wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR );
+ if (filename.Find(wxFILE_SEP_PATH) != wxNOT_FOUND)
+ {
+ wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR );
+ return;
+ }
+ m_list->SetWild( filename );
return;
}
- m_list->SetWild( filename );
- return;
}
if (!IsTopMostDir(dir))
@@ -1394,9 +1486,8 @@ void wxGenericFileDialog::UpdateControls()
#ifdef USE_GENERIC_FILEDIALOG
-IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog);
+IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog)
#endif // USE_GENERIC_FILEDIALOG
#endif // wxUSE_FILEDLG
-