]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filename.cpp
made wxLocale::GetSystemLanguage and wxLocale::AddLanguage static;
[wxWidgets.git] / src / common / filename.cpp
index 9495f6f929b1ea4107c466226ab6d853c0ef7c93..5e4f6beaada7a7ec019096310e131be50c3d238d 100644 (file)
 #include "wx/config.h"          // for wxExpandEnvVars
 #include "wx/utils.h"
 
+// For GetShort/LongPathName
+#ifdef __WIN32__
+#include <windows.h>
+#include "wx/msw/winundef.h"
+#endif
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -316,6 +322,13 @@ bool wxFileName::Normalize(wxPathNormalize flags,
         m_ext.MakeLower();
     }
 
+#if defined(__WXMSW__) && defined(__WIN32__)
+    if (flags & wxPATH_NORM_LONG)
+    {
+        Assign(GetLongPath());
+    }
+#endif
+
     return TRUE;
 }
 
@@ -358,9 +371,15 @@ bool wxFileName::IsAbsolute( wxPathFormat format )
 {
     wxChar ch = m_dirs.IsEmpty() ? _T('\0') : m_dirs[0u][0u];
 
+    // Hack to cope with e.g. c:\thing - need something better
+    wxChar driveSep = _T('\0');
+    if (!m_dirs.IsEmpty() && m_dirs[0].Length() > 1)
+        driveSep = m_dirs[0u][1u];
+
     // the path is absolute if it starts with a path separator or, only for
     // Unix filenames, with "~" or "~user"
     return IsPathSeparator(ch, format) ||
+           driveSep == _T(':') ||
            (GetFormat(format) == wxPATH_UNIX && ch == _T('~') );
 }
 
@@ -469,6 +488,60 @@ wxString wxFileName::GetFullPath( wxPathFormat format ) const
     return GetPathWithSep() + GetFullName();
 }
 
+// Return the short form of the path (returns identity on non-Windows platforms)
+wxString wxFileName::GetShortPath() const
+{
+#if defined(__WXMSW__) && defined(__WIN32__)
+    wxString path(GetFullPath());
+    wxString pathOut;
+    DWORD sz = ::GetShortPathName(path, NULL, 0);
+    bool ok = sz != 0;
+    if ( ok )
+    {
+        ok = ::GetShortPathName
+               (
+                path,
+                pathOut.GetWriteBuf(sz),
+                sz
+               ) != 0;
+        pathOut.UngetWriteBuf();
+    }
+    if (ok)
+        return pathOut;
+    else
+        return path;
+#else
+    return GetFullPath();
+#endif
+}
+
+// Return the long form of the path (returns identity on non-Windows platforms)
+wxString wxFileName::GetLongPath() const
+{
+#if defined(__WXMSW__) && defined(__WIN32__)
+    wxString path(GetFullPath());
+    wxString pathOut;
+    DWORD sz = ::GetLongPathName(path, NULL, 0);
+    bool ok = sz != 0;
+    if ( ok )
+    {
+        ok = ::GetLongPathName
+               (
+                path,
+                pathOut.GetWriteBuf(sz),
+                sz
+               ) != 0;
+        pathOut.UngetWriteBuf();
+    }
+    if (ok)
+        return pathOut;
+    else
+        return path;
+#else
+    return GetFullPath();
+#endif
+}
+
 wxPathFormat wxFileName::GetFormat( wxPathFormat format )
 {
     if (format == wxPATH_NATIVE)