X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/67fade3398f9c35a8e042749ed340c898f7e7bdd..1fd1922a49351a377bc6ef8f7e00f150112ee096:/src/msw/volume.cpp diff --git a/src/msw/volume.cpp b/src/msw/volume.cpp index 11fcf168e5..2d7fe331b9 100644 --- a/src/msw/volume.cpp +++ b/src/msw/volume.cpp @@ -27,9 +27,11 @@ #pragma hdrstop #endif +#if wxUSE_FSVOLUME + #ifndef WX_PRECOMP -#include -#include + #include "wx/icon.h" + #include "wx/intl.h" #endif // WX_PRECOMP #include "wx/dir.h" @@ -42,6 +44,38 @@ // Win32 headers #include +#ifndef SHGFI_ATTRIBUTES + #define SHGFI_ATTRIBUTES 2048 +#endif + +#ifndef SFGAO_READONLY + #define SFGAO_READONLY 0x00040000L +#endif + +#ifndef SFGAO_REMOVABLE + #define SFGAO_REMOVABLE 0x02000000L +#endif + +#ifndef SHGFI_DISPLAYNAME + #define SHGFI_DISPLAYNAME 512 +#endif + +#ifndef SHGFI_ICON + #define SHGFI_ICON 256 +#endif + +#ifndef SHGFI_SMALLICON + #define SHGFI_SMALLICON 1 +#endif + +#ifndef SHGFI_SHELLICONSIZE + #define SHGFI_SHELLICONSIZE 4 +#endif + +#ifndef SHGFI_OPENICON + #define SHGFI_OPENICON 2 +#endif + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Dynamic library function defs. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -65,6 +99,15 @@ struct FileInfo : public wxObject { FileInfo(unsigned flag=0, wxFSVolumeKind type=wxFS_VOL_OTHER) : m_flags(flag), m_type(type) {} + + FileInfo(const FileInfo& other) { *this = other; } + FileInfo& operator=(const FileInfo& other) + { + m_flags = other.m_flags; + m_type = other.m_type; + return *this; + } + unsigned m_flags; wxFSVolumeKind m_type; }; @@ -74,7 +117,10 @@ static FileInfoMap s_fileInfo(25); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Other initialization. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -WX_DEFINE_OBJARRAY(wxIconArray); +#if wxUSE_GUI +// already in wx/iconbndl.h +// WX_DEFINE_OBJARRAY(wxIconArray); +#endif //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Local helper functions. @@ -89,7 +135,7 @@ WX_DEFINE_OBJARRAY(wxIconArray); // - Other flags are 'best guess' from type of drive. The system will // not report the file attributes with any degree of accuracy. //============================================================================= -unsigned GetBasicFlags(const char* filename) +static unsigned GetBasicFlags(const wxChar* filename) { unsigned flags = wxFS_VOL_MOUNTED; @@ -162,7 +208,8 @@ unsigned GetBasicFlags(const char* filename) // Purpose: Add a file to the list if it meets the filter requirement. // Notes: - See GetBasicFlags for remarks about the Mounted flag. //============================================================================= -bool FilteredAdd(wxArrayString& list, const char* filename, unsigned flagsSet, unsigned flagsUnset) +static bool FilteredAdd(wxArrayString& list, const wxChar* filename, + unsigned flagsSet, unsigned flagsUnset) { bool accept = TRUE; unsigned flags = GetBasicFlags(filename); @@ -198,7 +245,8 @@ bool FilteredAdd(wxArrayString& list, const char* filename, unsigned flagsSet, u // all items while determining which are connected and not. So this // function will find either all items or connected items. //============================================================================= -void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc, unsigned flagsSet, unsigned flagsUnset) +static void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc, + unsigned flagsSet, unsigned flagsUnset) { HANDLE hEnum; int rc; @@ -217,8 +265,8 @@ void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc, unsigned flagsSe //---------------------------------------------------------------------- if (rc = s_pWNetOpenEnum(scope, RESOURCETYPE_DISK, 0, pResSrc, &hEnum), rc == NO_ERROR) { - unsigned long count = 1; - unsigned long size = 256; + DWORD count = 1; + DWORD size = 256; NETRESOURCE* pRes = (NETRESOURCE*)malloc(size); memset(pRes, 0, sizeof(NETRESOURCE)); while (rc = s_pWNetEnumResource(hEnum, &count, pRes, &size), rc == NO_ERROR || rc == ERROR_MORE_DATA) @@ -272,7 +320,7 @@ void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc, unsigned flagsSe //============================================================================= static int CompareFcn(const wxString& first, const wxString& second) { - return stricmp(first.c_str(), second.c_str()); + return wxStricmp(first.c_str(), second.c_str()); } // CompareFcn //============================================================================= @@ -283,7 +331,8 @@ static int CompareFcn(const wxString& first, const wxString& second) // way manually. // - The resulting list is sorted alphabetically. //============================================================================= -bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc, unsigned flagsSet, unsigned flagsUnset) +static bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc, + unsigned flagsSet, unsigned flagsUnset) { // NN query depends on dynamically loaded library. if (!s_pWNetOpenEnum || !s_pWNetEnumResource || !s_pWNetCloseEnum) @@ -323,7 +372,9 @@ bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc, unsigned flagsSe wxString all(list[iList]); wxString mount(mounted[iMounted]); - while (compare = stricmp(list[iList], mounted[iMounted]), compare > 0 && iList >= 0) + while (compare = + wxStricmp(list[iList].c_str(), mounted[iMounted].c_str()), + compare > 0 && iList >= 0) { iList--; all = list[iList]; @@ -410,8 +461,7 @@ wxArrayString wxFSVolume::GetVolumes(int flagsSet, int flagsUnset) wxArrayString nn; if (BuildRemoteList(nn, 0, flagsSet, flagsUnset)) { - int idx; - for (idx = 0; idx < nn.GetCount(); idx++) + for (size_t idx = 0; idx < nn.GetCount(); idx++) list.Add(nn[idx]); } } @@ -466,12 +516,12 @@ bool wxFSVolume::Create(const wxString& name) long rc = SHGetFileInfo(m_volName, 0, &fi, sizeof(fi), SHGFI_DISPLAYNAME); if (!rc) { - wxLogError(_("Cannot read typename from '%s'!"), m_volName); + wxLogError(_("Cannot read typename from '%s'!"), m_volName.c_str()); return m_isOk; } m_dispName = fi.szDisplayName; -#ifdef wxUSE_GUI +#if wxUSE_GUI m_icons.Alloc(wxFS_VOL_ICO_MAX); int idx; @@ -529,7 +579,7 @@ int wxFSVolume::GetFlags() const return itr->second.m_flags; } // GetFlags -#ifdef wxUSE_GUI +#if wxUSE_GUI //============================================================================= // Function: GetIcon @@ -537,14 +587,11 @@ int wxFSVolume::GetFlags() const //============================================================================= wxIcon wxFSVolume::GetIcon(wxFSIconType type) const { - wxASSERT(type < m_icons.GetCount()); - - if (type >= m_icons.GetCount()) - { - wxLogError(_("Invalid request for icon type!")); - wxIcon null; - return null; - } + wxCHECK_MSG(type < (int)m_icons.GetCount(), wxNullIcon, + _T("Invalid request for icon type!")); + wxCHECK_MSG( type >= 0 && (size_t)type < m_icons.GetCount(), + wxIcon(), + _T("invalid icon index") ); // Load on demand. if (m_icons[type].IsNull()) @@ -567,13 +614,17 @@ wxIcon wxFSVolume::GetIcon(wxFSIconType type) const case wxFS_VOL_ICO_SEL_LARGE: flags = SHGFI_ICON | SHGFI_SHELLICONSIZE | SHGFI_OPENICON; break; + + case wxFS_VOL_ICO_MAX: + wxFAIL_MSG(_T("wxFS_VOL_ICO_MAX is not valid icon type")); + break; } SHFILEINFO fi; long rc = SHGetFileInfo(m_volName, 0, &fi, sizeof(fi), flags); m_icons[type].SetHICON((WXHICON)fi.hIcon); if (!rc || !fi.hIcon) - wxLogError(_("Cannot load icon from '%s'."), m_volName); + wxLogError(_("Cannot load icon from '%s'."), m_volName.c_str()); } return m_icons[type]; @@ -581,3 +632,5 @@ wxIcon wxFSVolume::GetIcon(wxFSIconType type) const #endif // wxUSE_GUI +#endif // wxUSE_FSVOLUME +