#include "wx/filedlg.h"
#include "wx/intl.h"
#include "wx/tokenzr.h"
+#include "wx/filename.h"
#ifndef __DARWIN__
#include "PLStringFuncs.h"
{
sfilename = sfilename.Left(pos+1)+extension ;
#if TARGET_CARBON
- cfString = sfilename ;
+ cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ;
NavDialogSetSaveFileName( ioParams->context , cfString ) ;
#else
wxMacStringToPascal( sfilename , filename ) ;
}
}
-const wxChar * gfilters[] =
-{
- wxT("*.TXT") ,
- wxT("*.TIF") ,
- wxT("*.JPG") ,
-
- NULL
-} ;
-
-OSType gfiltersmac[] =
-{
- 'TEXT' ,
- 'TIFF' ,
- 'JPEG' ,
-
- '****'
-} ;
-
void MakeUserDataRec(OpenUserDataRec *myData , const wxString& filter )
{
const size_t extCount = myData->extensions.GetCount();
for ( size_t i = 0 ; i < extCount; i++ )
{
- int j ;
- for ( j = 0 ; gfilters[j] ; j++ )
+ wxUint32 fileType;
+ wxUint32 creator;
+ wxString extension = myData->extensions[i];
+
+ if (extension.GetChar(0) == '*')
+ extension = extension.Mid(1); // Remove leading *
+
+ if (extension.GetChar(0) == '.')
{
- if ( myData->extensions[i] == gfilters[j] )
- {
- myData->filtermactypes.Add( gfiltersmac[j] ) ;
- break ;
- }
+ extension = extension.Mid(1); // Remove leading .
}
- if( gfilters[j] == NULL )
+
+ if (wxFileName::MacFindDefaultTypeAndCreator( extension, &fileType, &creator ))
{
- myData->filtermactypes.Add( '****' ) ;
+ myData->filtermactypes.Add( (OSType)fileType );
}
+ else
+ {
+ myData->filtermactypes.Add( '****' ) ; // We'll fail safe if it's not recognized
+ }
}
}
}
{
FSRef fsref ;
memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ;
- wxString file ;
- const short maxpath = 1024 ;
- FSRefMakePath( &fsref , (UInt8*) file.GetWriteBuf(maxpath+1),maxpath) ;
- file.UngetWriteBuf() ;
+
+
+
+ CFURLRef fullURLRef;
+ fullURLRef = ::CFURLCreateFromFSRef(NULL, &fsref);
+#ifdef __UNIX__
+ CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
+#else
+ CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
+#endif
+ CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
+ wxString file = wxMacCFStringHolder(cfString).AsString(wxFont::GetDefaultEncoding());
+
display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
}
#endif
#else
CFStringRef titleRef = ::CFStringCreateWithCString(NULL,
m_message.c_str(),
- CFStringGetSystemEncoding());
+ m_font.GetEncoding() );
#endif
dialogCreateOptions.windowTitle = titleRef;
#if wxUSE_UNICODE
#else
CFStringRef defaultFileNameRef = ::CFStringCreateWithCString(NULL,
m_fileName.c_str(),
- CFStringGetSystemEncoding());
+ m_font.GetEncoding());
#endif
dialogCreateOptions.saveFileName = defaultFileNameRef;
NavDialogRef dialog;
myData.menuitems = dialogCreateOptions.popupExtension ;
for ( size_t i = 0 ; i < numfilters ; ++i )
{
- CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] ) ) ;
+ CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] , m_font.GetEncoding() ) ) ;
}
}
if (err != noErr)
break;
+ CFURLRef fullURLRef;
if (m_dialogStyle & wxSAVE)
{
CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
if (parentURLRef)
{
- CFURLRef fullURLRef =
+ fullURLRef =
::CFURLCreateCopyAppendingPathComponent(NULL,
parentURLRef,
navReply.saveFileName,
false);
::CFRelease(parentURLRef);
- if (fullURLRef)
- {
- CFStringRef cfString = ::CFURLCopyPath(fullURLRef);
- ::CFRelease(fullURLRef);
-
- if (cfString)
- {
- // unescape the URL for
- // "file name" instead of "file%20name"
- CFStringRef cfStringUnescaped =
- ::CFURLCreateStringByReplacingPercentEscapes(NULL,
- cfString,
- CFSTR(""));
- ::CFRelease(cfString);
-
- if (cfStringUnescaped)
- {
- Size len = CFStringGetLength( cfStringUnescaped ) ;
- wxChar* buf = thePath.GetWriteBuf( len ) ;
- //buf[0] = '\0';
-#if wxUSE_UNICODE
- CFStringGetCharacters(cfStringUnescaped , CFRangeMake( 0 , len ) , (UniChar*) buf ) ;
-#else
- CFStringGetCString( cfStringUnescaped , buf , len+1 , CFStringGetSystemEncoding() ) ;
-#endif
- buf[len] = 0 ;
- wxMacConvertNewlines10To13( buf ) ;
- thePath.UngetWriteBuf() ;
- ::CFRelease(cfStringUnescaped);
- }
- }
- }
- }
- if (!thePath)
- {
- ::NavDisposeReply(&navReply);
- return wxID_CANCEL;
}
}
else
{
- const short maxpath = 1024 ;
- ::FSRefMakePath( &theFSRef , (UInt8*) thePath.GetWriteBuf(maxpath+1),maxpath) ;
- thePath.UngetWriteBuf() ;
- if (err != noErr)
- break;
+ fullURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
+ }
+#ifdef __UNIX__
+ CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
+#else
+ CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
+#endif
+ CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
+ thePath = wxMacCFStringHolder(cfString).AsString(m_font.GetEncoding());
+ if (!thePath)
+ {
+ ::NavDisposeReply(&navReply);
+ return wxID_CANCEL;
}
m_path = thePath;
m_paths.Add(m_path);