]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filefn.cpp
Various layout fixes and such
[wxWidgets.git] / src / common / filefn.cpp
index 329a52695c2d485a3d746b5635800029612715bf..e2270201730cb94c12673c4532c951838940b428 100644 (file)
@@ -51,7 +51,7 @@
 #endif
 
 #if defined(__WXMAC__)
-  #include  "wx/mac/private.h"  // includes mac headers
+    #include  "wx/mac/private.h"  // includes mac headers
 #endif
 
 #ifdef __WXWINCE__
@@ -751,17 +751,22 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin
 #endif
 
   // Handle User's home (ignore root homes!)
-  size_t len;
-  if ((val = wxGetUserHome (user)) != NULL &&
-      (len = wxStrlen(val)) > 2 &&
-      wxStrncmp(dest, val, len) == 0)
-    {
-      wxStrcpy(wxFileFunctionsBuffer, wxT("~"));
-      if (user != wxT(""))
-             wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user);
-      wxStrcat(wxFileFunctionsBuffer, dest + len);
-      wxStrcpy (dest, wxFileFunctionsBuffer);
-    }
+  val = wxGetUserHome (user);
+  if (!val)
+    return dest;
+
+  const size_t len = wxStrlen(val);
+  if (len <= 2)
+    return dest;
+
+  if (wxStrncmp(dest, val, len) == 0)
+  {
+    wxStrcpy(wxFileFunctionsBuffer, wxT("~"));
+    if (user != wxT(""))
+           wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user);
+    wxStrcat(wxFileFunctionsBuffer, dest + len);
+    wxStrcpy (dest, wxFileFunctionsBuffer);
+  }
 
   return dest;
 }
@@ -918,9 +923,28 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
     Str255    theParentPath = "\p";
     FSSpec      theParentSpec;
     FSRef       theParentRef;
+    FSRef       theRef ;
     char        theFileName[FILENAME_MAX];
     char        thePath[FILENAME_MAX];
 
+    // we loose the long filename by merely copying the spec->name
+    // so try the built-ins, which only work if the file exists, but still...
+    
+    theErr = FSpMakeFSRef(spec, &theRef);
+    if ( theErr == noErr )
+    {
+       CFURLRef fullURLRef;
+        fullURLRef = ::CFURLCreateFromFSRef(NULL, &theRef);
+#ifdef __UNIX__
+       CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
+#else
+       CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
+#endif
+       CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
+       ::CFRelease( fullURLRef ) ;
+       return wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());
+    }
+
     strcpy(thePath, "");
 
     // GD: Separate file name from path and make a FSRef to the parent
@@ -1095,7 +1119,7 @@ wxString wxMacFSSpec2UnixFilename( const FSSpec *spec )
     return wxMac2UnixFilename( wxMacFSSpec2MacFilename( spec) ) ;
 }
 
-void wxUnixFilename2FSSpec( const char *path , FSSpec *spec )
+void wxUnixFilename2FSSpec( const wxChar *path , FSSpec *spec )
 {
     wxString var = wxUnix2MacFilename( path ) ;
     wxMacFilename2FSSpec( var , spec ) ;
@@ -1303,7 +1327,9 @@ bool wxRemoveFile(const wxString& file)
 #if defined(__VISUALC__) \
  || defined(__BORLANDC__) \
  || defined(__WATCOMC__) \
- || defined(__GNUWIN32__)
+ || defined(__DMC__) \
+ || defined(__GNUWIN32__) \
+ || (defined(__MWERKS__) && defined(__MSL__))
   int res = wxRemove(file);
 #elif defined(__WXMAC__)
   int res = unlink(wxFNCONV(file));
@@ -1396,7 +1422,7 @@ bool wxPathExists(const wxChar *pszPathName)
 
 #ifdef __OS2__
     // OS/2 can't handle "d:", it wants either "d:\" or "d:."
-    if (strPath.length() == 2 && strPath[1] == _T(':'))
+    if (strPath.length() == 2 && strPath[1u] == _T(':'))
         strPath << _T('.');
 #endif
 
@@ -1591,7 +1617,7 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
         ok = getcwd(cbuf, sz) != NULL;
     #endif // platform
 
-    #if wxUSE_UNICODE && !defined(__WXMAC__)
+    #if wxUSE_UNICODE && !(defined(__WXMAC__) && !defined(__DARWIN__))
         // finally convert the result to Unicode if needed
         wxConvFile.MB2WC(buf, cbuf, sz);
     #endif // wxUSE_UNICODE