]> git.saurik.com Git - wxWidgets.git/blame - src/msw/volume.cpp
Implement setFont on the iOS port of wxStaticText.
[wxWidgets.git] / src / msw / volume.cpp
CommitLineData
7183fd72
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/volume.cpp
3// Purpose: wxFSVolume - encapsulates system volume information
4// Author: George Policello
5// Modified by:
6// Created: 28 Jan 02
7183fd72 7// Copyright: (c) 2002 George Policello
65571936 8// Licence: wxWindows licence
7183fd72
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
7183fd72
VZ
19#include "wx/wxprec.h"
20
21#ifdef __BORLANDC__
22 #pragma hdrstop
23#endif
24
05815ab3
VZ
25#if wxUSE_FSVOLUME
26
7212d155
PC
27#include "wx/volume.h"
28
7183fd72 29#ifndef WX_PRECOMP
df5168c4
MB
30 #if wxUSE_GUI
31 #include "wx/icon.h"
32 #endif
05815ab3 33 #include "wx/intl.h"
86e4f8ad 34 #include "wx/log.h"
df69528b 35 #include "wx/hashmap.h"
a368dde5 36 #include "wx/filefn.h"
7183fd72
VZ
37#endif // WX_PRECOMP
38
39#include "wx/dir.h"
7183fd72
VZ
40#include "wx/dynlib.h"
41#include "wx/arrimpl.cpp"
42
8ba51e73
VZ
43// some compilers require including <windows.h> before <shellapi.h> so do it
44// even if this is not necessary with most of them
45#include "wx/msw/wrapwin.h"
eaeeb91e 46#include <shellapi.h>
a6c7a0f8 47#include <shlobj.h>
7212d155 48#include "wx/msw/missing.h"
eaeeb91e 49
ec67cff1 50#if wxUSE_BASE
7cfdeaad 51
7183fd72
VZ
52//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53// Dynamic library function defs.
54//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
64c288fa 56#if wxUSE_DYNLIB_CLASS
7183fd72 57static wxDynamicLibrary s_mprLib;
64c288fa 58#endif
7183fd72
VZ
59
60typedef DWORD (WINAPI* WNetOpenEnumPtr)(DWORD, DWORD, DWORD, LPNETRESOURCE, LPHANDLE);
61typedef DWORD (WINAPI* WNetEnumResourcePtr)(HANDLE, LPDWORD, LPVOID, LPDWORD);
62typedef DWORD (WINAPI* WNetCloseEnumPtr)(HANDLE);
63
64static WNetOpenEnumPtr s_pWNetOpenEnum;
65static WNetEnumResourcePtr s_pWNetEnumResource;
66static WNetCloseEnumPtr s_pWNetCloseEnum;
67
68//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
69// Globals/Statics
70//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
71static long s_cancelSearch = FALSE;
72
17ebae65 73struct FileInfo
7183fd72
VZ
74{
75 FileInfo(unsigned flag=0, wxFSVolumeKind type=wxFS_VOL_OTHER) :
76 m_flags(flag), m_type(type) {}
51fdd3da
VZ
77
78 FileInfo(const FileInfo& other) { *this = other; }
79 FileInfo& operator=(const FileInfo& other)
80 {
81 m_flags = other.m_flags;
82 m_type = other.m_type;
83 return *this;
84 }
85
7183fd72
VZ
86 unsigned m_flags;
87 wxFSVolumeKind m_type;
88};
89WX_DECLARE_STRING_HASH_MAP(FileInfo, FileInfoMap);
17ebae65
MB
90// Cygwin bug (?) destructor for global s_fileInfo is called twice...
91static FileInfoMap& GetFileInfoMap()
92{
93 static FileInfoMap s_fileInfo(25);
94
95 return s_fileInfo;
96}
97#define s_fileInfo (GetFileInfoMap())
7183fd72 98
7183fd72
VZ
99//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100// Local helper functions.
101//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
102
103//=============================================================================
104// Function: GetBasicFlags
105// Purpose: Set basic flags, primarily wxFS_VOL_REMOTE and wxFS_VOL_REMOVABLE.
106// Notes: - Local and mapped drives are mounted by definition. We have no
107// way to determine mounted status of network drives, so assume that
108// all drives are mounted, and let the caller decide otherwise.
109// - Other flags are 'best guess' from type of drive. The system will
110// not report the file attributes with any degree of accuracy.
111//=============================================================================
4d90b8de 112static unsigned GetBasicFlags(const wxChar* filename)
7183fd72
VZ
113{
114 unsigned flags = wxFS_VOL_MOUNTED;
115
116 //----------------------------------
117 // 'Best Guess' based on drive type.
118 //----------------------------------
119 wxFSVolumeKind type;
120 switch(GetDriveType(filename))
121 {
122 case DRIVE_FIXED:
123 type = wxFS_VOL_DISK;
124 break;
125
126 case DRIVE_REMOVABLE:
127 flags |= wxFS_VOL_REMOVABLE;
128 type = wxFS_VOL_FLOPPY;
129 break;
130
131 case DRIVE_CDROM:
132 flags |= wxFS_VOL_REMOVABLE | wxFS_VOL_READONLY;
133 type = wxFS_VOL_CDROM;
134 break;
135
136 case DRIVE_REMOTE:
137 flags |= wxFS_VOL_REMOTE;
138 type = wxFS_VOL_NETWORK;
139 break;
140
141 case DRIVE_NO_ROOT_DIR:
142 flags &= ~wxFS_VOL_MOUNTED;
143 type = wxFS_VOL_OTHER;
144 break;
145
146 default:
147 type = wxFS_VOL_OTHER;
148 break;
149 }
150
151 //-----------------------------------------------------------------------
90e572f1 152 // The following most likely will not modify anything not set above,
7183fd72
VZ
153 // and will not work at all for network shares or empty CD ROM drives.
154 // But it is a good check if the Win API ever gets better about reporting
155 // this information.
156 //-----------------------------------------------------------------------
157 SHFILEINFO fi;
ab63e6ae 158 long rc = SHGetFileInfo(filename, 0, &fi, sizeof(fi), SHGFI_ATTRIBUTES);
7183fd72
VZ
159 if (!rc)
160 {
ab63e6ae
VZ
161 // this error is not fatal, so don't show a message to the user about
162 // it, otherwise it would appear every time a generic directory picker
163 // dialog is used and there is a connected network drive
9a83f860 164 wxLogLastError(wxT("SHGetFileInfo"));
7183fd72
VZ
165 }
166 else
167 {
168 if (fi.dwAttributes & SFGAO_READONLY)
169 flags |= wxFS_VOL_READONLY;
170 if (fi.dwAttributes & SFGAO_REMOVABLE)
171 flags |= wxFS_VOL_REMOVABLE;
172 }
173
174 //------------------
175 // Flags are cached.
176 //------------------
177 s_fileInfo[filename] = FileInfo(flags, type);
178
179 return flags;
180} // GetBasicFlags
181
182//=============================================================================
183// Function: FilteredAdd
184// Purpose: Add a file to the list if it meets the filter requirement.
185// Notes: - See GetBasicFlags for remarks about the Mounted flag.
186//=============================================================================
27d2dbbc 187static bool FilteredAdd(wxArrayString& list, const wxChar* filename,
4d90b8de 188 unsigned flagsSet, unsigned flagsUnset)
7183fd72 189{
27d2dbbc 190 bool accept = true;
7183fd72
VZ
191 unsigned flags = GetBasicFlags(filename);
192
193 if (flagsSet & wxFS_VOL_MOUNTED && !(flags & wxFS_VOL_MOUNTED))
27d2dbbc 194 accept = false;
7183fd72 195 else if (flagsUnset & wxFS_VOL_MOUNTED && (flags & wxFS_VOL_MOUNTED))
27d2dbbc 196 accept = false;
7183fd72 197 else if (flagsSet & wxFS_VOL_REMOVABLE && !(flags & wxFS_VOL_REMOVABLE))
27d2dbbc 198 accept = false;
7183fd72 199 else if (flagsUnset & wxFS_VOL_REMOVABLE && (flags & wxFS_VOL_REMOVABLE))
27d2dbbc 200 accept = false;
7183fd72 201 else if (flagsSet & wxFS_VOL_READONLY && !(flags & wxFS_VOL_READONLY))
27d2dbbc 202 accept = false;
7183fd72 203 else if (flagsUnset & wxFS_VOL_READONLY && (flags & wxFS_VOL_READONLY))
27d2dbbc 204 accept = false;
7183fd72 205 else if (flagsSet & wxFS_VOL_REMOTE && !(flags & wxFS_VOL_REMOTE))
27d2dbbc 206 accept = false;
7183fd72 207 else if (flagsUnset & wxFS_VOL_REMOTE && (flags & wxFS_VOL_REMOTE))
27d2dbbc 208 accept = false;
7183fd72
VZ
209
210 // Add to the list if passed the filter.
211 if (accept)
212 list.Add(filename);
213
214 return accept;
215} // FilteredAdd
216
217//=============================================================================
218// Function: BuildListFromNN
219// Purpose: Append or remove items from the list
220// Notes: - There is no way to find all disconnected NN items, or even to find
221// all items while determining which are connected and not. So this
222// function will find either all items or connected items.
223//=============================================================================
27d2dbbc 224static void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc,
4d90b8de 225 unsigned flagsSet, unsigned flagsUnset)
7183fd72
VZ
226{
227 HANDLE hEnum;
228 int rc;
229
230 //-----------------------------------------------
231 // Scope may be all drives or all mounted drives.
232 //-----------------------------------------------
233 unsigned scope = RESOURCE_GLOBALNET;
234 if (flagsSet & wxFS_VOL_MOUNTED)
235 scope = RESOURCE_CONNECTED;
236
237 //----------------------------------------------------------------------
238 // Enumerate all items, adding only non-containers (ie. network shares).
239 // Containers cause a recursive call to this function for their own
240 // enumeration.
241 //----------------------------------------------------------------------
242 if (rc = s_pWNetOpenEnum(scope, RESOURCETYPE_DISK, 0, pResSrc, &hEnum), rc == NO_ERROR)
243 {
4aebbc59
MB
244 DWORD count = 1;
245 DWORD size = 256;
7183fd72
VZ
246 NETRESOURCE* pRes = (NETRESOURCE*)malloc(size);
247 memset(pRes, 0, sizeof(NETRESOURCE));
248 while (rc = s_pWNetEnumResource(hEnum, &count, pRes, &size), rc == NO_ERROR || rc == ERROR_MORE_DATA)
249 {
250 if (s_cancelSearch)
251 break;
252
253 if (rc == ERROR_MORE_DATA)
254 {
255 pRes = (NETRESOURCE*)realloc(pRes, size);
256 count = 1;
257 }
258 else if (count == 1)
259 {
260 // Enumerate the container.
261 if (pRes->dwUsage & RESOURCEUSAGE_CONTAINER)
262 {
263 BuildListFromNN(list, pRes, flagsSet, flagsUnset);
264 }
265
266 // Add the network share.
267 else
268 {
269 wxString filename(pRes->lpRemoteName);
270
1d243ee0
VZ
271 // if the drive is unavailable, FilteredAdd() can hang for
272 // a long time and, moreover, its failure appears to be not
273 // cached so this will happen every time we use it, so try
274 // a much quicker wxDirExists() test (which still hangs but
275 // for much shorter time) for locally mapped drives first
276 // to try to avoid this
277 if ( pRes->lpLocalName &&
278 *pRes->lpLocalName &&
279 !wxDirExists(pRes->lpLocalName) )
280 continue;
281
df69528b 282 if (!filename.empty())
7183fd72
VZ
283 {
284 if (filename.Last() != '\\')
285 filename.Append('\\');
286
287 // The filter function will not know mounted from unmounted, and neither do we unless
288 // we are iterating using RESOURCE_CONNECTED, in which case they all are mounted.
289 // Volumes on disconnected servers, however, will correctly show as unmounted.
b2b6da49 290 FilteredAdd(list, filename.t_str(), flagsSet, flagsUnset&~wxFS_VOL_MOUNTED);
7183fd72
VZ
291 if (scope == RESOURCE_GLOBALNET)
292 s_fileInfo[filename].m_flags &= ~wxFS_VOL_MOUNTED;
293 }
294 }
295 }
296 else if (count == 0)
297 break;
298 }
299 free(pRes);
300 s_pWNetCloseEnum(hEnum);
301 }
302} // BuildListFromNN
303
304//=============================================================================
305// Function: CompareFcn
306// Purpose: Used to sort the NN list alphabetically, case insensitive.
307//=============================================================================
99f161bd 308static int CompareFcn(const wxString& first, const wxString& second)
7183fd72 309{
99f161bd 310 return wxStricmp(first.c_str(), second.c_str());
7183fd72
VZ
311} // CompareFcn
312
313//=============================================================================
314// Function: BuildRemoteList
315// Purpose: Append Network Neighborhood items to the list.
316// Notes: - Mounted gets transalated into Connected. FilteredAdd is told
317// to ignore the Mounted flag since we need to handle it in a weird
318// way manually.
319// - The resulting list is sorted alphabetically.
320//=============================================================================
27d2dbbc 321static bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc,
4d90b8de 322 unsigned flagsSet, unsigned flagsUnset)
7183fd72
VZ
323{
324 // NN query depends on dynamically loaded library.
325 if (!s_pWNetOpenEnum || !s_pWNetEnumResource || !s_pWNetCloseEnum)
326 {
327 wxLogError(_("Failed to load mpr.dll."));
27d2dbbc 328 return false;
7183fd72
VZ
329 }
330
331 // Don't waste time doing the work if the flags conflict.
332 if (flagsSet & wxFS_VOL_MOUNTED && flagsUnset & wxFS_VOL_MOUNTED)
27d2dbbc 333 return false;
7183fd72
VZ
334
335 //----------------------------------------------
336 // Generate the list according to the flags set.
337 //----------------------------------------------
338 BuildListFromNN(list, pResSrc, flagsSet, flagsUnset);
339 list.Sort(CompareFcn);
340
341 //-------------------------------------------------------------------------
342 // If mounted only is requested, then we only need one simple pass.
343 // Otherwise, we need to build a list of all NN volumes and then apply the
344 // list of mounted drives to it.
345 //-------------------------------------------------------------------------
346 if (!(flagsSet & wxFS_VOL_MOUNTED))
347 {
348 // generate.
349 wxArrayString mounted;
350 BuildListFromNN(mounted, pResSrc, flagsSet | wxFS_VOL_MOUNTED, flagsUnset & ~wxFS_VOL_MOUNTED);
351 mounted.Sort(CompareFcn);
352
353 // apply list from bottom to top to preserve indexes if removing items.
4a559093
WS
354 ssize_t iList = list.GetCount()-1;
355 for (ssize_t iMounted = mounted.GetCount()-1; iMounted >= 0 && iList >= 0; iMounted--)
7183fd72
VZ
356 {
357 int compare;
358 wxString all(list[iList]);
359 wxString mount(mounted[iMounted]);
360
27d2dbbc 361 while (compare =
4d90b8de
VS
362 wxStricmp(list[iList].c_str(), mounted[iMounted].c_str()),
363 compare > 0 && iList >= 0)
7183fd72
VZ
364 {
365 iList--;
366 all = list[iList];
367 }
368
369
370 if (compare == 0)
371 {
372 // Found the element. Remove it or mark it mounted.
373 if (flagsUnset & wxFS_VOL_MOUNTED)
ba8c1601 374 list.RemoveAt(iList);
7183fd72
VZ
375 else
376 s_fileInfo[list[iList]].m_flags |= wxFS_VOL_MOUNTED;
377
378 }
379
380 iList--;
381 }
382 }
383
27d2dbbc 384 return true;
7183fd72
VZ
385} // BuildRemoteList
386
387//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
388// wxFSVolume
389//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
390
391//=============================================================================
392// Function: GetVolumes
393// Purpose: Generate and return a list of all volumes (drives) available.
394// Notes:
395//=============================================================================
e2478fde 396wxArrayString wxFSVolumeBase::GetVolumes(int flagsSet, int flagsUnset)
7183fd72 397{
27d2dbbc 398 ::InterlockedExchange(&s_cancelSearch, FALSE); // reset
7183fd72 399
64c288fa 400#if wxUSE_DYNLIB_CLASS
9a83f860 401 if (!s_mprLib.IsLoaded() && s_mprLib.Load(wxT("mpr.dll")))
7183fd72
VZ
402 {
403#ifdef UNICODE
9a83f860
VZ
404 s_pWNetOpenEnum = (WNetOpenEnumPtr)s_mprLib.GetSymbol(wxT("WNetOpenEnumW"));
405 s_pWNetEnumResource = (WNetEnumResourcePtr)s_mprLib.GetSymbol(wxT("WNetEnumResourceW"));
7183fd72 406#else
9a83f860
VZ
407 s_pWNetOpenEnum = (WNetOpenEnumPtr)s_mprLib.GetSymbol(wxT("WNetOpenEnumA"));
408 s_pWNetEnumResource = (WNetEnumResourcePtr)s_mprLib.GetSymbol(wxT("WNetEnumResourceA"));
7183fd72 409#endif
9a83f860 410 s_pWNetCloseEnum = (WNetCloseEnumPtr)s_mprLib.GetSymbol(wxT("WNetCloseEnum"));
7183fd72 411 }
64c288fa 412#endif
7183fd72
VZ
413
414 wxArrayString list;
415
416 //-------------------------------
417 // Local and mapped drives first.
418 //-------------------------------
419 // Allocate the required space for the API call.
95dc6a2b 420 const DWORD chars = GetLogicalDriveStrings(0, NULL);
7183fd72
VZ
421 TCHAR* buf = new TCHAR[chars+1];
422
423 // Get the list of drives.
999836aa 424 GetLogicalDriveStrings(chars, buf);
7183fd72
VZ
425
426 // Parse the list into an array, applying appropriate filters.
427 TCHAR *pVol;
428 pVol = buf;
429 while (*pVol)
430 {
431 FilteredAdd(list, pVol, flagsSet, flagsUnset);
67fade33 432 pVol = pVol + wxStrlen(pVol) + 1;
7183fd72
VZ
433 }
434
435 // Cleanup.
436 delete[] buf;
437
438 //---------------------------
439 // Network Neighborhood next.
440 //---------------------------
441
442 // not exclude remote and not removable
443 if (!(flagsUnset & wxFS_VOL_REMOTE) &&
444 !(flagsSet & wxFS_VOL_REMOVABLE)
445 )
446 {
447 // The returned list will be sorted alphabetically. We don't pass
448 // our in since we don't want to change to order of the local drives.
449 wxArrayString nn;
450 if (BuildRemoteList(nn, 0, flagsSet, flagsUnset))
451 {
89c98653 452 for (size_t idx = 0; idx < nn.GetCount(); idx++)
7183fd72
VZ
453 list.Add(nn[idx]);
454 }
455 }
456
457 return list;
458} // GetVolumes
459
460//=============================================================================
461// Function: CancelSearch
462// Purpose: Instruct an active search to stop.
463// Notes: - This will only sensibly be called by a thread other than the one
464// performing the search. This is the only thread-safe function
465// provided by the class.
466//=============================================================================
e2478fde 467void wxFSVolumeBase::CancelSearch()
7183fd72 468{
27d2dbbc 469 ::InterlockedExchange(&s_cancelSearch, TRUE);
7183fd72
VZ
470} // CancelSearch
471
472//=============================================================================
473// Function: constructor
474// Purpose: default constructor
475//=============================================================================
e2478fde 476wxFSVolumeBase::wxFSVolumeBase()
7183fd72 477{
27d2dbbc 478 m_isOk = false;
7183fd72
VZ
479} // wxVolume
480
481//=============================================================================
482// Function: constructor
483// Purpose: constructor that calls Create
484//=============================================================================
e2478fde 485wxFSVolumeBase::wxFSVolumeBase(const wxString& name)
7183fd72
VZ
486{
487 Create(name);
488} // wxVolume
489
490//=============================================================================
491// Function: Create
492// Purpose: Finds, logs in, etc. to the request volume.
493//=============================================================================
e2478fde 494bool wxFSVolumeBase::Create(const wxString& name)
7183fd72
VZ
495{
496 // assume fail.
27d2dbbc 497 m_isOk = false;
7183fd72
VZ
498
499 // supplied.
500 m_volName = name;
501
502 // Display name.
503 SHFILEINFO fi;
b2b6da49 504 long rc = SHGetFileInfo(m_volName.t_str(), 0, &fi, sizeof(fi), SHGFI_DISPLAYNAME);
7183fd72
VZ
505 if (!rc)
506 {
4d90b8de 507 wxLogError(_("Cannot read typename from '%s'!"), m_volName.c_str());
daa35097 508 return false;
7183fd72
VZ
509 }
510 m_dispName = fi.szDisplayName;
511
7183fd72 512 // all tests passed.
daa35097
VZ
513 m_isOk = true;
514 return true;
7183fd72
VZ
515} // Create
516
517//=============================================================================
518// Function: IsOk
27d2dbbc 519// Purpose: returns true if the volume is legal.
7183fd72
VZ
520// Notes: For fixed disks, it must exist. For removable disks, it must also
521// be present. For Network Shares, it must also be logged in, etc.
522//=============================================================================
e2478fde 523bool wxFSVolumeBase::IsOk() const
7183fd72
VZ
524{
525 return m_isOk;
526} // IsOk
527
528//=============================================================================
529// Function: GetKind
530// Purpose: Return the type of the volume.
531//=============================================================================
e2478fde 532wxFSVolumeKind wxFSVolumeBase::GetKind() const
7183fd72
VZ
533{
534 if (!m_isOk)
535 return wxFS_VOL_OTHER;
536
537 FileInfoMap::iterator itr = s_fileInfo.find(m_volName);
538 if (itr == s_fileInfo.end())
539 return wxFS_VOL_OTHER;
540
541 return itr->second.m_type;
542}
543
544//=============================================================================
545// Function: GetFlags
546// Purpose: Return the caches flags for this volume.
547// Notes: - Returns -1 if no flags were cached.
548//=============================================================================
e2478fde 549int wxFSVolumeBase::GetFlags() const
7183fd72
VZ
550{
551 if (!m_isOk)
552 return -1;
553
554 FileInfoMap::iterator itr = s_fileInfo.find(m_volName);
555 if (itr == s_fileInfo.end())
556 return -1;
557
558 return itr->second.m_flags;
559} // GetFlags
560
ec67cff1 561#endif // wxUSE_BASE
e2478fde
VZ
562
563// ============================================================================
564// wxFSVolume
565// ============================================================================
566
0e7fa3a6 567#if wxUSE_GUI
7183fd72 568
e2478fde
VZ
569void wxFSVolume::InitIcons()
570{
571 m_icons.Alloc(wxFS_VOL_ICO_MAX);
572 wxIcon null;
573 for (int idx = 0; idx < wxFS_VOL_ICO_MAX; idx++)
574 m_icons.Add(null);
575}
576
7183fd72
VZ
577//=============================================================================
578// Function: GetIcon
579// Purpose: return the requested icon.
580//=============================================================================
e2478fde 581
7183fd72
VZ
582wxIcon wxFSVolume::GetIcon(wxFSIconType type) const
583{
e2478fde 584 wxCHECK_MSG( type >= 0 && (size_t)type < m_icons.GetCount(), wxNullIcon,
9a83f860 585 wxT("wxFSIconType::GetIcon(): invalid icon index") );
7183fd72 586
95fbc738 587#ifdef __WXMSW__
7183fd72
VZ
588 // Load on demand.
589 if (m_icons[type].IsNull())
590 {
e2478fde 591 UINT flags = SHGFI_ICON;
7183fd72
VZ
592 switch (type)
593 {
594 case wxFS_VOL_ICO_SMALL:
e2478fde 595 flags |= SHGFI_SMALLICON;
7183fd72
VZ
596 break;
597
598 case wxFS_VOL_ICO_LARGE:
e2478fde 599 flags |= SHGFI_SHELLICONSIZE;
7183fd72
VZ
600 break;
601
602 case wxFS_VOL_ICO_SEL_SMALL:
e2478fde 603 flags |= SHGFI_SMALLICON | SHGFI_OPENICON;
7183fd72
VZ
604 break;
605
606 case wxFS_VOL_ICO_SEL_LARGE:
e2478fde 607 flags |= SHGFI_SHELLICONSIZE | SHGFI_OPENICON;
7183fd72 608 break;
27d2dbbc 609
4d90b8de 610 case wxFS_VOL_ICO_MAX:
9a83f860 611 wxFAIL_MSG(wxT("wxFS_VOL_ICO_MAX is not valid icon type"));
4d90b8de 612 break;
7183fd72
VZ
613 }
614
615 SHFILEINFO fi;
017dc06b 616 long rc = SHGetFileInfo(m_volName.t_str(), 0, &fi, sizeof(fi), flags);
7183fd72
VZ
617 m_icons[type].SetHICON((WXHICON)fi.hIcon);
618 if (!rc || !fi.hIcon)
43b2d5e7 619 {
4d90b8de 620 wxLogError(_("Cannot load icon from '%s'."), m_volName.c_str());
43b2d5e7 621 }
7183fd72
VZ
622 }
623
624 return m_icons[type];
95fbc738
VZ
625#else
626 wxFAIL_MSG(wxS("Can't convert HICON to wxIcon in this port."));
627 return wxNullIcon;
628#endif
7183fd72
VZ
629} // GetIcon
630
631#endif // wxUSE_GUI
632
05815ab3 633#endif // wxUSE_FSVOLUME