]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filefn.cpp
renamed errcode to fix compilation with VC++ 8 (replaces patch 982303)
[wxWidgets.git] / src / common / filefn.cpp
index ba56ed4355e8e8b16407908cb83ddbe0e8998de7..bff8bd1bc717e56667ef029cfce3367b6ee45db0 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     29/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998 Julian Smart
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -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__
@@ -354,7 +354,7 @@ wxString wxPathList::FindValidPath (const wxString& file)
 wxString wxPathList::FindAbsoluteValidPath (const wxString& file)
 {
     wxString f = FindValidPath(file);
-    if ( wxIsAbsolutePath(f) )
+    if ( f.empty() || wxIsAbsolutePath(f) )
         return f;
 
     wxString buf;
@@ -923,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
@@ -1331,10 +1350,10 @@ bool wxMkdir(const wxString& dir, int perm)
     // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
     // for the GNU compiler
 #if (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WINE__) || defined(__WXMICROWIN__)
-  #ifndef MSVCRT
-    if ( mkdir(wxFNCONV(dirname), perm) != 0 )
-  #else
+  #if defined(MSVCRT)
     if ( mkdir(wxFNCONV(dirname)) != 0 )
+  #else
+    if ( mkdir(wxFNCONV(dirname), perm) != 0 )
   #endif
 #elif defined(__OS2__)
     if (::DosCreateDir((PSZ)dirname, NULL) != 0) // enhance for EAB's??
@@ -1817,6 +1836,116 @@ time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename)
 }
 
 
+// Parses the filterStr, returning the number of filters.
+// Returns 0 if none or if there's a problem.
+// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
+
+int WXDLLEXPORT wxParseCommonDialogsFilter(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters)
+{
+    descriptions.Clear();
+    filters.Clear();
+
+    wxString str(filterStr);
+
+    wxString description, filter;
+    int pos = 0;
+    while( pos != wxNOT_FOUND )
+    {
+        pos = str.Find(wxT('|'));
+        if ( pos == wxNOT_FOUND )
+        {
+            // if there are no '|'s at all in the string just take the entire
+            // string as filter and make description empty for later autocompletion
+            if ( filters.IsEmpty() )
+            {
+                descriptions.Add(wxEmptyString);
+                filters.Add(filterStr);
+            }
+            else
+            {
+                wxFAIL_MSG( _T("missing '|' in the wildcard string!") );
+            }
+
+            break;
+        }
+
+        description = str.Left(pos);
+        str = str.Mid(pos + 1);
+        pos = str.Find(wxT('|'));
+        if ( pos == wxNOT_FOUND )
+        {
+            filter = str;
+        }
+        else
+        {
+            filter = str.Left(pos);
+            str = str.Mid(pos + 1);
+        }
+
+        descriptions.Add(description);
+        filters.Add(filter);
+    }
+
+#if defined(__WXMOTIF__)
+    // split it so there is one wildcard per entry
+    for( size_t i = 0 ; i < descriptions.GetCount() ; i++ )
+    {
+        pos = filters[i].Find(wxT(';'));
+        if (pos != wxNOT_FOUND)
+        {
+            // first split only filters
+            descriptions.Insert(descriptions[i],i+1);
+            filters.Insert(filters[i].Mid(pos+1),i+1);
+            filters[i]=filters[i].Left(pos);
+
+            // autoreplace new filter in description with pattern:
+            //     C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
+            // cause split into:
+            //     C/C++ Files(*.cpp)|*.cpp
+            //     C/C++ Files(*.c;*.h)|*.c;*.h
+            // and next iteration cause another split into:
+            //     C/C++ Files(*.cpp)|*.cpp
+            //     C/C++ Files(*.c)|*.c
+            //     C/C++ Files(*.h)|*.h
+            for ( size_t k=i;k<i+2;k++ )
+            {
+                pos = descriptions[k].Find(filters[k]);
+                if (pos != wxNOT_FOUND)
+                {
+                    wxString before = descriptions[k].Left(pos);
+                    wxString after = descriptions[k].Mid(pos+filters[k].Len());
+                    pos = before.Find(_T('('),true);
+                    if (pos>before.Find(_T(')'),true))
+                    {
+                        before = before.Left(pos+1);
+                        before << filters[k];
+                        pos = after.Find(_T(')'));
+                        int pos1 = after.Find(_T('('));
+                        if (pos != wxNOT_FOUND && (pos<pos1 || pos1==wxNOT_FOUND))
+                        {
+                            before << after.Mid(pos);
+                            descriptions[k] = before;
+                        }
+                    }
+                }
+            }
+        }
+    }
+#endif
+
+    // autocompletion
+    for( size_t j = 0 ; j < descriptions.GetCount() ; j++ )
+    {
+        if ( descriptions[j] == wxEmptyString && filters[j] != wxEmptyString )
+        {
+            descriptions[j].Printf(_("Files (%s)"), filters[j].c_str());
+        }
+    }
+
+    return filters.GetCount();
+}
+
+
 //------------------------------------------------------------------------
 // wild character routines
 //------------------------------------------------------------------------