]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxPATH_NORM_SHORTCUT
authorJulian Smart <julian@anthemion.co.uk>
Sat, 20 Dec 2003 13:59:13 +0000 (13:59 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sat, 20 Dec 2003 13:59:13 +0000 (13:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24939 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/filename.tex
include/wx/filename.h
src/common/filename.cpp

index c1f63e73ce8d07cc2ed20192c0e60116a3f4a88f..9980383392e5689d79502562b9a040e61892497f 100644 (file)
@@ -84,6 +84,8 @@ All:
 - check if file exists in wxFileConfig::DeleteFile() (Christian Sturmlechner)
 - when wxUSE_STL == 1 wxHashTable will not be implemented using wxHashMap
   (as in 2.5.0).
+- Added some extra convenience functions to wxRect such as
+  GetBottomRight (Hajo Kirchhoff)
 
 All (GUI):
 
@@ -114,6 +116,7 @@ wxMSW:
 - MDI child frames are not always resizeable any more (Andrei Fortuna)
 - fixed enumerating of entries/groups under '/' in wxRegConfig
 - added wxSYS_ICONTITLE_FONT (Andreas Pflug)
+- added wxPATH_NORM_SHORTCUT to wxFileName
 
 wxGTK:
 
index b294adbd7260d1599de9d2ae0644b844f91e0415..d739dcd8dc8aed020b46a4eeae51ea9a58fb0b7a 100644 (file)
@@ -652,6 +652,7 @@ any or-combination of the following constants:
 \twocolitem{{\bf wxPATH\_NORM\_CASE}}{if filesystem is case insensitive, transform to tolower case}
 \twocolitem{{\bf wxPATH\_NORM\_ABSOLUTE}}{make the path absolute}
 \twocolitem{{\bf wxPATH\_NORM\_LONG}}{make the path the long form}
+\twocolitem{{\bf wxPATH\_NORM\_SHORTCUT}}{resolve if it is a shortcut (Windows only)}
 \twocolitem{{\bf wxPATH\_NORM\_ALL}}{all of previous flags except \texttt{wxPATH\_NORM\_CASE}}
 \end{twocollist}
 }
index 14aed5347d906440519d8a4a14855aeb8a570a79..774f65aaf0b9ae3ce272a19d6b47acb2dd2a6486 100644 (file)
@@ -72,7 +72,8 @@ enum wxPathNormalize
     wxPATH_NORM_CASE     = 0x0008,  // if case insensitive => tolower
     wxPATH_NORM_ABSOLUTE = 0x0010,  // make the path absolute
     wxPATH_NORM_LONG =     0x0020,  // make the path the long form
-    wxPATH_NORM_ALL      = 0x003f & ~wxPATH_NORM_CASE
+    wxPATH_NORM_SHORTCUT = 0x0040,  // resolve the shortcut, if it is a shortcut
+    wxPATH_NORM_ALL      = 0x00ff & ~wxPATH_NORM_CASE
 };
 
 // what exactly should GetPath() return?
@@ -283,6 +284,12 @@ public:
         { return Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
                            wxPATH_NORM_TILDE, cwd, format); }
 
+#ifdef __WIN32__
+        // if the path is a shortcut, return the target and optionally,
+        // the arguments
+    bool GetShortcutTarget(const wxString& shortcutPath, wxString& targetFilename, wxString* arguments = NULL);
+#endif
+
     // Comparison
 
         // compares with the rules of the given platforms format
index 07840e53728785cf418321b007f6b00eb774a7db..c5f7f9a8a3d0faa16cd9a39e309ebd27fc8fd3f4 100644 (file)
@@ -945,6 +945,23 @@ bool wxFileName::Normalize(int flags,
 
         m_dirs.Add(dir);
     }
+    
+#ifdef __WIN32__
+    if ( (flags & wxPATH_NORM_SHORTCUT) )
+    {
+        wxString filename;
+        if (GetShortcutTarget(GetFullPath(format), filename))
+        {
+            // Repeat this since we may now have a new path
+            if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
+            {
+                filename.MakeLower();
+            }
+            m_relative = false;
+            Assign(filename);
+        }
+    }
+#endif
 
     if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
     {
@@ -969,6 +986,71 @@ bool wxFileName::Normalize(int flags,
     return true;
 }
 
+// ----------------------------------------------------------------------------
+// get the shortcut target
+// ----------------------------------------------------------------------------
+
+#if defined(__WIN32__) && !defined(__WXWINCE__)
+#include <shlobj.h>
+#endif
+
+#ifdef __WIN32__
+bool wxFileName::GetShortcutTarget(const wxString& shortcutPath, wxString& targetFilename, wxString* arguments)
+{
+#ifdef __WXWINCE__
+    // Not tested on WinCE, so don't compile yet
+    return shortcutPath;
+#else
+    wxString path, file, ext;
+    wxSplitPath(shortcutPath, & path, & file, & ext);
+    
+       HRESULT hres;   
+       IShellLink* psl;
+    bool success = FALSE;
+
+    // Assume it's not a shortcut if it doesn't end with lnk
+    if (ext.Lower() != wxT("lnk"))
+        return FALSE;
+    
+       // create a ShellLink object
+       hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+                               IID_IShellLink, (LPVOID*) &psl);
+       
+       if (SUCCEEDED(hres))
+       {
+               IPersistFile* ppf;
+               hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
+               if (SUCCEEDED(hres))
+               {
+                       WORD wsz[MAX_PATH];
+
+                       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, shortcutPath.mb_str(), -1, wsz,
+                MAX_PATH);
+                       
+                       hres = ppf->Load(wsz, 0);                       
+                       if (SUCCEEDED(hres))
+                       {
+                wxChar buf[2048];
+                               psl->GetPath(buf, 2048, NULL, SLGP_UNCPRIORITY);
+                               targetFilename = wxString(buf);
+                success = (shortcutPath != targetFilename);
+
+                               psl->GetArguments(buf, 2048);
+                wxString args(buf);
+                if (!args.IsEmpty() && arguments)
+                {
+                    *arguments = args;
+                }                
+                       }
+               }
+       }
+       psl->Release();
+       return success;
+#endif
+}
+#endif
+
+
 // ----------------------------------------------------------------------------
 // absolute/relative paths
 // ----------------------------------------------------------------------------