]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/dirctrlg.cpp
Warning fixes found under hardest mode of OpenWatcom. Seems clean in Borland, MinGW...
[wxWidgets.git] / src / generic / dirctrlg.cpp
index e6f1686a90739ccdb1ad0b354c2a5b5a5ac7205c..7f1c89e741a1a0af41a94c16800a1f6ac5b0c897 100644 (file)
 #endif // __OS2__
 
 #if defined(__WXMAC__)
-#  ifdef __DARWIN__
-#    include "MoreFilesX.h"
-#  else
-#    include "MoreFilesExtras.h"
-#  endif
+# include "MoreFilesX.h"
 #endif
 
 #ifdef __BORLANDC__
@@ -113,7 +109,7 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
     // No logical drives; return "\"
     paths.Add(wxT("\\"));
     names.Add(wxT("\\"));
-    return 1;
+    icon_ids.Add(wxFileIconsTable::computer);
 #elif defined(__WIN32__)
     wxChar driveBuffer[256];
     size_t n = (size_t) GetLogicalDriveStrings(255, driveBuffer);
@@ -202,87 +198,36 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
 #endif // __WIN32__/!__WIN32__
 
 #elif defined(__WXMAC__)
-#ifdef __DARWIN__
-    FSRef     **theVolRefs;
-    ItemCount   theVolCount;
-    char        thePath[FILENAME_MAX];
-
-    if (FSGetMountedVolumes(&theVolRefs, &theVolCount) == noErr) {
-        ItemCount index;
-        ::HLock( (Handle)theVolRefs ) ;
-        for (index = 0; index < theVolCount; ++index) {
-            // get the POSIX path associated with the FSRef
-            if ( FSRefMakePath(&((*theVolRefs)[index]),
-                                 (UInt8 *)thePath, sizeof(thePath)) != noErr ) {
-                continue;
-            }
-            // add path separator at end if necessary
-            wxString path( thePath , wxConvLocal) ;
-            if (path.Last() != wxFILE_SEP_PATH) {
-                path += wxFILE_SEP_PATH;
-            }
-            // get Mac volume name for display
-            FSVolumeRefNum vRefNum ;
-            HFSUniStr255 volumeName ;
 
-            if ( FSGetVRefNum(&((*theVolRefs)[index]), &vRefNum) != noErr ) {
-                continue;
-            }
-            if ( FSGetVInfo(vRefNum, &volumeName, NULL, NULL) != noErr ) {
-                continue;
-            }
-            // get C string from Unicode HFS name
-            //   see: http://developer.apple.com/carbon/tipsandtricks.html
-            CFStringRef cfstr = CFStringCreateWithCharacters( kCFAllocatorDefault,
-                                                              volumeName.unicode,
-                                                              volumeName.length );
-            // Do something with str
-            char *cstr = NewPtr(CFStringGetLength(cfstr) + 1);
-            if (( cstr == NULL ) ||
-                !CFStringGetCString(cfstr, cstr, CFStringGetLength(cfstr) + 1,
-                                    kCFStringEncodingMacRoman))
+    ItemCount volumeIndex = 1;
+    OSErr err = noErr ;
+    
+    while( noErr == err )
+    {
+        HFSUniStr255 volumeName ;
+        FSRef fsRef ;
+        FSVolumeInfo volumeInfo ;
+               err = FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoFlags , &volumeInfo , &volumeName, &fsRef);
+               if( noErr == err )
+               {
+                   wxString path = wxMacFSRefToPath( &fsRef ) ;
+            wxString name = wxMacHFSUniStrToString( &volumeName ) ;
+            
+            if ( (volumeInfo.flags & kFSVolFlagSoftwareLockedMask) || (volumeInfo.flags & kFSVolFlagHardwareLockedMask) )
             {
-                CFRelease( cstr );
-                continue;
+                icon_ids.Add(wxFileIconsTable::cdrom);
             }
-            wxString name( cstr , wxConvLocal );
-            DisposePtr( cstr );
-            CFRelease( cfstr );
-
-            GetVolParmsInfoBuffer volParmsInfo;
-            UInt32 actualSize;
-            if ( FSGetVolParms(vRefNum, sizeof(volParmsInfo), &volParmsInfo, &actualSize) != noErr ) {
-                continue;
+            else
+            {
+                icon_ids.Add(wxFileIconsTable::drive);
             }
-
+            // todo other removable
+            
             paths.Add(path);
             names.Add(name);
-
-            if ( VolIsEjectable(&volParmsInfo) )
-                icon_ids.Add(wxFileIconsTable::cdrom);
-            else
-                icon_ids.Add(wxFileIconsTable::drive);
-        }
-        ::HUnlock( (Handle)theVolRefs );
-        ::DisposeHandle( (Handle)theVolRefs );
-    }
-#else // !__DARWIN__
-    FSSpec volume;
-    short index = 1;
-    while(1)
-    {
-        short actualCount = 0 ;
-        if (OnLine(&volume, 1, &actualCount, &index ) != noErr || actualCount==0)
-        {
-            break;
-        }
-
-        wxString name = wxMacFSSpec2MacFilename( &volume );
-        paths.Add(name + wxFILE_SEP_PATH);
-        names.Add(name);
-        icon_ids.Add(wxFileIconsTable::drive);
+            volumeIndex++ ;
+               }
     }
-#endif // __DARWIN__
 
 #elif defined(__UNIX__)
     paths.Add(wxT("/"));
@@ -291,6 +236,8 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
 #else
     #error "Unsupported platform in wxGenericDirCtrl!"
 #endif
+    wxASSERT_MSG( (paths.GetCount() == names.GetCount()), wxT("The number of paths and their human readable names should be equal in number."));
+    wxASSERT_MSG( (paths.GetCount() == icon_ids.GetCount()), wxT("Wrong number of icons for available drives."));
     return paths.GetCount();
 }
 
@@ -323,6 +270,7 @@ bool wxIsDriveAvailable(const wxString& dirName)
 int setdrive(int drive)
 {
 #ifdef __WXWINCE__
+    wxUnusedVar(drive);
     return 0;
 #elif defined(__GNUWIN32__) && \
     (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
@@ -355,6 +303,7 @@ int setdrive(int drive)
 bool wxIsDriveAvailable(const wxString& dirName)
 {
 #ifdef __WXWINCE__
+    wxUnusedVar(dirName);
     return false;
 #else
 #ifdef __WIN32__
@@ -403,9 +352,9 @@ bool wxIsDriveAvailable(const wxString& dirName)
 
 // Function which is called by quick sort. We want to override the default wxArrayString behaviour,
 // and sort regardless of case.
-static int wxCMPFUNC_CONV wxDirCtrlStringCompareFunction(wxString* strFirst, wxString* strSecond)
+static int wxCMPFUNC_CONV wxDirCtrlStringCompareFunction(const wxString& strFirst, const wxString& strSecond)
 {
-    return strFirst->CmpNoCase(*strSecond);
+    return strFirst.CmpNoCase(strSecond);
 }
 
 //-----------------------------------------------------------------------------
@@ -574,7 +523,8 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
     else
         filterStyle |= wxBORDER_SUNKEN;
 
-    m_treeCtrl = new wxTreeCtrl(this, wxID_TREECTRL, pos, size, treeStyle);
+    m_treeCtrl = new wxTreeCtrl(this, wxID_TREECTRL,
+                                wxPoint(0,0), GetClientSize(), treeStyle);
 
     if (!filter.IsEmpty() && (style & wxDIRCTRL_SHOW_FILTERS))
         m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL, wxDefaultPosition, wxDefaultSize, filterStyle);
@@ -1136,7 +1086,7 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter)
 bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description)
 {
     wxArrayString filters, descriptions;
-    int count = wxParseWildcard(filterStr, filters, descriptions);
+    int count = wxParseCommonDialogsFilter(filterStr, descriptions, filters);
     if (count > 0 && n < count)
     {
         filter = filters[n];
@@ -1153,7 +1103,7 @@ bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxStrin
 // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
 int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions)
 {
-    return wxParseWildcard(filterStr, descriptions, filters );
+    return wxParseCommonDialogsFilter(filterStr, descriptions, filters );
 }
 #endif // WXWIN_COMPATIBILITY_2_4
 
@@ -1171,15 +1121,15 @@ void wxGenericDirCtrl::DoResize()
             // correct control height to always be returned, rather
             // than the drop-down list height which is sometimes returned.
             wxSize oldSize = m_filterListCtrl->GetSize();
-            m_filterListCtrl->SetSize(wxDefaultPosition.x,
-                                      wxDefaultPosition.y,
+            m_filterListCtrl->SetSize(wxDefaultCoord,
+                                      wxDefaultCoord,
                                       oldSize.x+10,
-                                      wxDefaultSize.y,
+                                      wxDefaultCoord,
                                       wxSIZE_USE_EXISTING);
-            m_filterListCtrl->SetSize(wxDefaultPosition.x,
-                                      wxDefaultPosition.y,
+            m_filterListCtrl->SetSize(wxDefaultCoord,
+                                      wxDefaultCoord,
                                       oldSize.x,
-                                      wxDefaultSize.y,
+                                      wxDefaultCoord,
                                       wxSIZE_USE_EXISTING);
 #endif
             filterSz = m_filterListCtrl->GetSize();
@@ -1265,7 +1215,7 @@ void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilt
 {
     Clear();
     wxArrayString descriptions, filters;
-    size_t n = (size_t) wxParseWildcard(filter, filters, descriptions);
+    size_t n = (size_t) wxParseCommonDialogsFilter(filter, filters, descriptions);
 
     if (n > 0 && defaultFilter < (int) n)
     {
@@ -1508,7 +1458,9 @@ void wxFileIconsTable::Create()
     m_smallImageList = new wxImageList(16, 16);
 
     // folder:
-    m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FOLDER, wxART_CMN_DIALOG));
+    m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FOLDER,
+                                                   wxART_CMN_DIALOG,
+                                                   wxSize(16, 16)));
     // folder_open
     m_smallImageList->Add(wxIcon(file_icons_tbl_folder_open_xpm));
     // computer
@@ -1522,11 +1474,15 @@ void wxFileIconsTable::Create()
     // removeable
     m_smallImageList->Add(wxIcon(file_icons_tbl_removeable_xpm));
     // file
-    m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_CMN_DIALOG));
+    m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE,
+                                                   wxART_CMN_DIALOG,
+                                                   wxSize(16, 16)));
     // executable
     if (GetIconID(wxEmptyString, _T("application/x-executable")) == file)
     {
-        m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE, wxART_CMN_DIALOG));
+        m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE,
+                                                       wxART_CMN_DIALOG,
+                                                       wxSize(16, 16)));
         delete m_HashTable->Get(_T("exe"));
         m_HashTable->Delete(_T("exe"));
         m_HashTable->Put(_T("exe"), new wxFileIconEntry(executable));
@@ -1718,6 +1674,7 @@ int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
 
 #else // !wxUSE_MIMETYPE
 
+    wxUnusedVar(mime);
     if (extension == wxT("exe"))
         return executable;
     else