FSRef transition
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28878 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f81f59012d
commit
a2b772607a
@ -155,15 +155,7 @@ bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
|
||||
|
||||
// filefn.h
|
||||
WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
|
||||
WXDLLEXPORT void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) ;
|
||||
WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec ) ;
|
||||
# ifndef __DARWIN__
|
||||
// Mac file names are POSIX (Unix style) under Darwin, so these are not needed
|
||||
WXDLLEXPORT wxString wxMacFSSpec2UnixFilename( const FSSpec *spec ) ;
|
||||
WXDLLEXPORT void wxUnixFilename2FSSpec( const char *path , FSSpec *spec ) ;
|
||||
WXDLLEXPORT wxString wxMac2UnixFilename( const char *s) ;
|
||||
WXDLLEXPORT wxString wxUnix2MacFilename( const char *s);
|
||||
# endif
|
||||
WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec ) ;
|
||||
|
||||
// utils.h
|
||||
WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
|
||||
@ -564,11 +556,11 @@ void wxMacWakeUp() ;
|
||||
|
||||
ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) ;
|
||||
|
||||
#ifdef TARGET_API_MAC_OSX
|
||||
#define kDefaultPathStyle kCFURLPOSIXPathStyle
|
||||
#else
|
||||
#define kDefaultPathStyle kCFURLHFSPathStyle
|
||||
#endif
|
||||
// filefn.cpp
|
||||
|
||||
wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ;
|
||||
OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ;
|
||||
wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ;
|
||||
|
||||
#endif
|
||||
// _WX_PRIVATE_H_
|
||||
|
@ -228,7 +228,7 @@ bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode)
|
||||
// otherwise we only create the new file and fail if it already exists
|
||||
#if defined(__WXMAC__) && !defined(__UNIX__) && !wxUSE_UNICODE
|
||||
// Dominic Mazzoni [dmazzoni+@cs.cmu.edu] reports that open is still broken on the mac, so we replace
|
||||
// int fd = open(wxUnix2MacFilename( szFileName ), O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access);
|
||||
// int fd = open( szFileName , O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access);
|
||||
int fd = creat( szFileName , accessMode);
|
||||
#else
|
||||
#ifdef __WXWINCE__
|
||||
|
@ -997,19 +997,23 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
||||
bool ret = file.Commit();
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
if ( ret )
|
||||
{
|
||||
FSSpec spec ;
|
||||
|
||||
wxMacFilename2FSSpec( m_strLocalFile , &spec ) ;
|
||||
FInfo finfo ;
|
||||
if ( FSpGetFInfo( &spec , &finfo ) == noErr )
|
||||
{
|
||||
finfo.fdType = 'TEXT' ;
|
||||
finfo.fdCreator = 'ttxt' ;
|
||||
FSpSetFInfo( &spec , &finfo ) ;
|
||||
}
|
||||
}
|
||||
if ( ret )
|
||||
{
|
||||
FSRef fsRef ;
|
||||
FSCatalogInfo catInfo;
|
||||
FileInfo *finfo ;
|
||||
|
||||
if ( wxMacPathToFSRef( m_strLocalFile , &fsRef ) == noErr )
|
||||
{
|
||||
if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
|
||||
{
|
||||
finfo = (FileInfo*)&catInfo.finderInfo;
|
||||
finfo->fileType = 'TEXT' ;
|
||||
finfo->fileCreator = 'ttxt' ;
|
||||
FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // __WXMAC__
|
||||
|
||||
#ifdef __UNIX__
|
||||
|
@ -164,14 +164,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef __WXMAC__
|
||||
# ifdef __DARWIN__
|
||||
# include "MoreFilesX.h"
|
||||
# else
|
||||
# include "MoreFiles.h"
|
||||
# include "MoreFilesExtras.h"
|
||||
# include "FullPath.h"
|
||||
# include "FSpCompat.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -915,220 +908,72 @@ wxString wxPathOnly (const wxString& path)
|
||||
// Also, convert to lower case, since case is significant in UNIX.
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
|
||||
|
||||
#if TARGET_API_MAC_OSX
|
||||
#define kDefaultPathStyle kCFURLPOSIXPathStyle
|
||||
#else
|
||||
#define kDefaultPathStyle kCFURLHFSPathStyle
|
||||
#endif
|
||||
|
||||
wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent )
|
||||
{
|
||||
#ifdef __DARWIN__
|
||||
int i;
|
||||
int j;
|
||||
OSErr theErr;
|
||||
OSStatus theStatus = noErr;
|
||||
Boolean isDirectory = FALSE;
|
||||
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, fsRef);
|
||||
if ( additionalPathComponent )
|
||||
{
|
||||
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());
|
||||
CFURLRef parentURLRef = fullURLRef ;
|
||||
fullURLRef = CFURLCreateCopyAppendingPathComponent(NULL, parentURLRef,
|
||||
additionalPathComponent,false);
|
||||
CFRelease( parentURLRef ) ;
|
||||
}
|
||||
|
||||
strcpy(thePath, "");
|
||||
|
||||
// GD: Separate file name from path and make a FSRef to the parent
|
||||
// directory. This is necessary since FSRefs cannot reference files
|
||||
// that have not yet been created.
|
||||
// Based on example code from Apple Technical Note TN2022
|
||||
// http://developer.apple.com/technotes/tn/tn2022.html
|
||||
|
||||
// check whether we are converting a directory
|
||||
isDirectory = ((spec->name)[spec->name[0]] == ':');
|
||||
// count length of file name
|
||||
for (i = spec->name[0] - (isDirectory ? 1 : 0); ((spec->name[i] != ':') && (i > 0)); i--);
|
||||
// copy file name
|
||||
// prepend path separator since it will later be appended to the path
|
||||
theFileName[0] = wxFILE_SEP_PATH;
|
||||
for (j = i + 1; j <= spec->name[0] - (isDirectory ? 1 : 0); j++) {
|
||||
theFileName[j - i] = spec->name[j];
|
||||
}
|
||||
theFileName[j - i] = '\0';
|
||||
// copy path if any
|
||||
for (j = 1; j <= i; j++) {
|
||||
theParentPath[++theParentPath[0]] = spec->name[j];
|
||||
}
|
||||
theErr = FSMakeFSSpec(spec->vRefNum, spec->parID, theParentPath, &theParentSpec);
|
||||
if (theErr == noErr) {
|
||||
// convert the FSSpec to an FSRef
|
||||
theErr = FSpMakeFSRef(&theParentSpec, &theParentRef);
|
||||
}
|
||||
if (theErr == noErr) {
|
||||
// get the POSIX path associated with the FSRef
|
||||
theStatus = FSRefMakePath(&theParentRef,
|
||||
(UInt8 *)thePath, sizeof(thePath));
|
||||
}
|
||||
if (theStatus == noErr) {
|
||||
// append file name to path
|
||||
// includes previously prepended path separator
|
||||
strcat(thePath, theFileName);
|
||||
}
|
||||
|
||||
// create path string for return value
|
||||
wxString result( thePath , wxConvLocal) ;
|
||||
#else
|
||||
Handle myPath ;
|
||||
short length ;
|
||||
|
||||
// get length of path and allocate handle
|
||||
FSpGetFullPath( spec , &length , &myPath ) ;
|
||||
::SetHandleSize( myPath , length + 1 ) ;
|
||||
::HLock( myPath ) ;
|
||||
(*myPath)[length] = 0 ;
|
||||
if ((length > 0) && ((*myPath)[length-1] == ':'))
|
||||
(*myPath)[length-1] = 0 ;
|
||||
|
||||
// create path string for return value
|
||||
wxString result( *myPath , wxConvLocal) ;
|
||||
|
||||
// free allocated handle
|
||||
::HUnlock( myPath ) ;
|
||||
::DisposeHandle( myPath ) ;
|
||||
#endif
|
||||
|
||||
return result ;
|
||||
CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, kDefaultPathStyle);
|
||||
CFRelease( fullURLRef ) ;
|
||||
return wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());
|
||||
}
|
||||
#ifndef __DARWIN__
|
||||
// Mac file names are POSIX (Unix style) under Darwin
|
||||
// therefore the conversion functions below are not needed
|
||||
|
||||
static wxChar sMacFileNameConversion[ 1000 ] ;
|
||||
static char scMacFileNameConversion[ 1000 ] ;
|
||||
|
||||
#endif
|
||||
void wxMacFilename2FSSpec( const char *path , FSSpec *spec )
|
||||
OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef )
|
||||
{
|
||||
OSStatus err = noErr ;
|
||||
#ifdef __DARWIN__
|
||||
FSRef theRef;
|
||||
|
||||
// get the FSRef associated with the POSIX path
|
||||
err = FSPathMakeRef((const UInt8 *) path, &theRef, NULL);
|
||||
// convert the FSRef to an FSSpec
|
||||
err = FSGetCatalogInfo(&theRef, kFSCatInfoNone, NULL, NULL, spec, NULL);
|
||||
#else
|
||||
if ( strchr( path , ':' ) == NULL )
|
||||
{
|
||||
// try whether it is a volume / or a mounted volume
|
||||
strncpy( scMacFileNameConversion , path , 1000 ) ;
|
||||
scMacFileNameConversion[998] = 0 ;
|
||||
strcat( scMacFileNameConversion , ":" ) ;
|
||||
err = FSpLocationFromFullPath( strlen(scMacFileNameConversion) , scMacFileNameConversion , spec ) ;
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, wxMacCFStringHolder(path ,wxLocale::GetSystemEncoding() ) , kDefaultPathStyle, false);
|
||||
if ( NULL != url )
|
||||
{
|
||||
if ( CFURLGetFSRef(url, fsRef) == false )
|
||||
err = fnfErr ;
|
||||
CFRelease( url ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = FSpLocationFromFullPath( strlen(path) , path , spec ) ;
|
||||
err = fnfErr ;
|
||||
}
|
||||
#endif
|
||||
return err ;
|
||||
}
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec )
|
||||
wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname )
|
||||
{
|
||||
return wxMacFilename2FSSpec( wxConvFile.cWC2MB(path) , spec ) ;
|
||||
CFStringRef cfname = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
||||
uniname->unicode,
|
||||
uniname->length );
|
||||
return wxMacCFStringHolder(cfname).AsString() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __DARWIN__
|
||||
|
||||
wxString wxMac2UnixFilename (const wxChar *str)
|
||||
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
|
||||
{
|
||||
wxChar *s = sMacFileNameConversion ;
|
||||
wxStrcpy( s , str ) ;
|
||||
if (s)
|
||||
FSRef fsRef ;
|
||||
if ( FSpMakeFSRef( spec , &fsRef) == noErr )
|
||||
{
|
||||
memmove( s+1 , s ,wxStrlen( s ) + 1 * sizeof(wxChar)) ;
|
||||
if ( *s == ':' )
|
||||
*s = '.' ;
|
||||
else
|
||||
*s = '/' ;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (*s == ':')
|
||||
*s = '/';
|
||||
else
|
||||
*s = wxTolower(*s); // Case INDEPENDENT
|
||||
s++;
|
||||
}
|
||||
return wxMacFSRefToPath( &fsRef ) ;
|
||||
}
|
||||
return wxString(sMacFileNameConversion) ;
|
||||
return wxEmptyString ;
|
||||
}
|
||||
|
||||
wxString wxUnix2MacFilename (const wxChar *str)
|
||||
void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec )
|
||||
{
|
||||
wxChar *s = sMacFileNameConversion ;
|
||||
wxStrcpy( s , str ) ;
|
||||
if (s)
|
||||
{
|
||||
if ( *s == '.' )
|
||||
{
|
||||
// relative path , since it goes on with slash which is translated to a :
|
||||
memmove( s , s+1 ,wxStrlen( s ) * sizeof(wxChar)) ;
|
||||
}
|
||||
else if ( *s == '/' )
|
||||
{
|
||||
// absolute path -> on mac just start with the drive name
|
||||
memmove( s , s+1 ,wxStrlen( s ) * sizeof(wxChar) ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxASSERT_MSG( 1 , wxT("unkown path beginning") ) ;
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (*s == '/' || *s == '\\')
|
||||
{
|
||||
// convert any back-directory situations
|
||||
if ( *(s+1) == '.' && *(s+2) == '.' && ( (*(s+3) == '/' || *(s+3) == '\\') ) )
|
||||
{
|
||||
*s = ':';
|
||||
memmove( s+1 , s+3 ,(wxStrlen( s+3 ) + 1)*sizeof(wxChar) ) ;
|
||||
}
|
||||
else
|
||||
*s = ':';
|
||||
}
|
||||
s++ ;
|
||||
}
|
||||
}
|
||||
return wxString(sMacFileNameConversion) ;
|
||||
OSStatus err = noErr ;
|
||||
FSRef fsRef ;
|
||||
wxMacPathToFSRef( path , &fsRef ) ;
|
||||
err = FSRefMakeFSSpec( &fsRef , spec ) ;
|
||||
}
|
||||
|
||||
wxString wxMacFSSpec2UnixFilename( const FSSpec *spec )
|
||||
{
|
||||
return wxMac2UnixFilename( wxMacFSSpec2MacFilename( spec) ) ;
|
||||
}
|
||||
|
||||
void wxUnixFilename2FSSpec( const wxChar *path , FSSpec *spec )
|
||||
{
|
||||
wxString var = wxUnix2MacFilename( path ) ;
|
||||
wxMacFilename2FSSpec( var , spec ) ;
|
||||
}
|
||||
#endif // ! __DARWIN__
|
||||
|
||||
#endif // __WXMAC__
|
||||
|
||||
void
|
||||
@ -1577,28 +1422,15 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
ok = _getcwd(cbuf, sz) != NULL;
|
||||
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
FSSpec cwdSpec ;
|
||||
FCBPBRec pb;
|
||||
OSErr error;
|
||||
Str255 fileName ;
|
||||
pb.ioNamePtr = (StringPtr) &fileName;
|
||||
pb.ioVRefNum = 0;
|
||||
pb.ioRefNum = LMGetCurApRefNum();
|
||||
pb.ioFCBIndx = 0;
|
||||
error = PBGetFCBInfoSync(&pb);
|
||||
if ( error == noErr )
|
||||
char lbuf[1024] ;
|
||||
if ( getcwd( lbuf , sizeof( lbuf ) ) )
|
||||
{
|
||||
cwdSpec.vRefNum = pb.ioFCBVRefNum;
|
||||
cwdSpec.parID = pb.ioFCBParID;
|
||||
cwdSpec.name[0] = 0 ;
|
||||
wxString res = wxMacFSSpec2MacFilename( &cwdSpec ) ;
|
||||
wxStrcpy( buf , res ) ;
|
||||
wxString res( lbuf , *wxConvCurrent ) ;
|
||||
wxStrcpy( buf , res ) ;
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
ok = false ;
|
||||
#elif defined(__OS2__)
|
||||
APIRET rc;
|
||||
ULONG ulDriveNum = 0;
|
||||
|
@ -2031,31 +2031,44 @@ static void MacEnsureDefaultExtensionsLoaded()
|
||||
gMacDefaultExtensionsInited = true ;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxFileName::MacSetTypeAndCreator( wxUint32 type , wxUint32 creator )
|
||||
{
|
||||
FInfo fndrInfo ;
|
||||
FSSpec spec ;
|
||||
wxMacFilename2FSSpec(GetFullPath(),&spec) ;
|
||||
OSErr err = FSpGetFInfo( &spec , &fndrInfo ) ;
|
||||
wxCHECK( err == noErr , false ) ;
|
||||
FSRef fsRef ;
|
||||
FSCatalogInfo catInfo;
|
||||
FileInfo *finfo ;
|
||||
|
||||
fndrInfo.fdType = type ;
|
||||
fndrInfo.fdCreator = creator ;
|
||||
FSpSetFInfo( &spec , &fndrInfo ) ;
|
||||
return true ;
|
||||
if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr )
|
||||
{
|
||||
if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
|
||||
{
|
||||
finfo = (FileInfo*)&catInfo.finderInfo;
|
||||
finfo->fileType = type ;
|
||||
finfo->fileCreator = creator ;
|
||||
FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool wxFileName::MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator )
|
||||
{
|
||||
FInfo fndrInfo ;
|
||||
FSSpec spec ;
|
||||
wxMacFilename2FSSpec(GetFullPath(),&spec) ;
|
||||
OSErr err = FSpGetFInfo( &spec , &fndrInfo ) ;
|
||||
wxCHECK( err == noErr , false ) ;
|
||||
FSRef fsRef ;
|
||||
FSCatalogInfo catInfo;
|
||||
FileInfo *finfo ;
|
||||
|
||||
*type = fndrInfo.fdType ;
|
||||
*creator = fndrInfo.fdCreator ;
|
||||
return true ;
|
||||
if ( wxMacPathToFSRef( GetFullPath() , &fsRef ) == noErr )
|
||||
{
|
||||
if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
|
||||
{
|
||||
finfo = (FileInfo*)&catInfo.finderInfo;
|
||||
*type = finfo->fileType ;
|
||||
*creator = finfo->fileCreator ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool wxFileName::MacSetDefaultTypeAndCreator()
|
||||
|
@ -85,11 +85,7 @@
|
||||
#endif // __OS2__
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
# ifdef __DARWIN__
|
||||
# include "MoreFilesX.h"
|
||||
# else
|
||||
# include "MoreFilesExtras.h"
|
||||
# endif
|
||||
# include "MoreFilesX.h"
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
@ -202,87 +198,36 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
|
||||
#endif // __WIN32__/!__WIN32__
|
||||
|
||||
#elif defined(__WXMAC__)
|
||||
#ifdef __DARWIN__
|
||||
FSRef **theVolRefs;
|
||||
ItemCount theVolCount;
|
||||
char thePath[FILENAME_MAX];
|
||||
|
||||
if (FSGetMountedVolumes(&theVolRefs, &theVolCount) == noErr) {
|
||||
ItemCount index;
|
||||
::HLock( (Handle)theVolRefs ) ;
|
||||
for (index = 0; index < theVolCount; ++index) {
|
||||
// get the POSIX path associated with the FSRef
|
||||
if ( FSRefMakePath(&((*theVolRefs)[index]),
|
||||
(UInt8 *)thePath, sizeof(thePath)) != noErr ) {
|
||||
continue;
|
||||
}
|
||||
// add path separator at end if necessary
|
||||
wxString path( thePath , wxConvLocal) ;
|
||||
if (path.Last() != wxFILE_SEP_PATH) {
|
||||
path += wxFILE_SEP_PATH;
|
||||
}
|
||||
// get Mac volume name for display
|
||||
FSVolumeRefNum vRefNum ;
|
||||
HFSUniStr255 volumeName ;
|
||||
|
||||
if ( FSGetVRefNum(&((*theVolRefs)[index]), &vRefNum) != noErr ) {
|
||||
continue;
|
||||
}
|
||||
if ( FSGetVInfo(vRefNum, &volumeName, NULL, NULL) != noErr ) {
|
||||
continue;
|
||||
}
|
||||
// get C string from Unicode HFS name
|
||||
// see: http://developer.apple.com/carbon/tipsandtricks.html
|
||||
CFStringRef cfstr = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
||||
volumeName.unicode,
|
||||
volumeName.length );
|
||||
// Do something with str
|
||||
char *cstr = NewPtr(CFStringGetLength(cfstr) + 1);
|
||||
if (( cstr == NULL ) ||
|
||||
!CFStringGetCString(cfstr, cstr, CFStringGetLength(cfstr) + 1,
|
||||
kCFStringEncodingMacRoman))
|
||||
ItemCount volumeIndex = 1;
|
||||
OSErr err = noErr ;
|
||||
|
||||
while( noErr == err )
|
||||
{
|
||||
HFSUniStr255 volumeName ;
|
||||
FSRef fsRef ;
|
||||
FSVolumeInfo volumeInfo ;
|
||||
err = FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoFlags , &volumeInfo , &volumeName, &fsRef);
|
||||
if( noErr == err )
|
||||
{
|
||||
wxString path = wxMacFSRefToPath( &fsRef ) ;
|
||||
wxString name = wxMacHFSUniStrToString( &volumeName ) ;
|
||||
|
||||
if ( (volumeInfo.flags & kFSVolFlagSoftwareLockedMask) || (volumeInfo.flags & kFSVolFlagHardwareLockedMask) )
|
||||
{
|
||||
CFRelease( cfstr );
|
||||
continue;
|
||||
icon_ids.Add(wxFileIconsTable::cdrom);
|
||||
}
|
||||
wxString name( cstr , wxConvLocal );
|
||||
DisposePtr( cstr );
|
||||
CFRelease( cfstr );
|
||||
|
||||
GetVolParmsInfoBuffer volParmsInfo;
|
||||
UInt32 actualSize;
|
||||
if ( FSGetVolParms(vRefNum, sizeof(volParmsInfo), &volParmsInfo, &actualSize) != noErr ) {
|
||||
continue;
|
||||
else
|
||||
{
|
||||
icon_ids.Add(wxFileIconsTable::drive);
|
||||
}
|
||||
|
||||
// todo other removable
|
||||
|
||||
paths.Add(path);
|
||||
names.Add(name);
|
||||
|
||||
if ( VolIsEjectable(&volParmsInfo) )
|
||||
icon_ids.Add(wxFileIconsTable::cdrom);
|
||||
else
|
||||
icon_ids.Add(wxFileIconsTable::drive);
|
||||
}
|
||||
::HUnlock( (Handle)theVolRefs );
|
||||
::DisposeHandle( (Handle)theVolRefs );
|
||||
volumeIndex++ ;
|
||||
}
|
||||
}
|
||||
#else // !__DARWIN__
|
||||
FSSpec volume;
|
||||
short index = 1;
|
||||
while(1)
|
||||
{
|
||||
short actualCount = 0 ;
|
||||
if (OnLine(&volume, 1, &actualCount, &index ) != noErr || actualCount==0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wxString name = wxMacFSSpec2MacFilename( &volume );
|
||||
paths.Add(name + wxFILE_SEP_PATH);
|
||||
names.Add(name);
|
||||
icon_ids.Add(wxFileIconsTable::drive);
|
||||
}
|
||||
#endif // __DARWIN__
|
||||
|
||||
#elif defined(__UNIX__)
|
||||
paths.Add(wxT("/"));
|
||||
|
@ -165,7 +165,6 @@ short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
|
||||
DescType returnedType;
|
||||
Size actualSize;
|
||||
long itemsInList;
|
||||
FSSpec theSpec;
|
||||
OSErr err;
|
||||
short i;
|
||||
err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
|
||||
@ -181,10 +180,15 @@ short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
|
||||
PSN.lowLongOfPSN = kCurrentProcess ;
|
||||
SetFrontProcess( &PSN ) ;
|
||||
|
||||
for (i = 1; i <= itemsInList; i++) {
|
||||
AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
|
||||
(Ptr) & theSpec, sizeof(theSpec), &actualSize);
|
||||
wxString fName = wxMacFSSpec2MacFilename(&theSpec);
|
||||
for (i = 1; i <= itemsInList; i++)
|
||||
{
|
||||
wxString fName ;
|
||||
|
||||
FSRef theRef ;
|
||||
AEGetNthPtr(&docList, i, typeFSRef, &keywd, &returnedType,
|
||||
(Ptr) & theRef, sizeof(theRef), &actualSize);
|
||||
fName = wxMacFSRefToPath( &theRef ) ;
|
||||
|
||||
MacOpenFile(fName);
|
||||
}
|
||||
return noErr;
|
||||
@ -199,7 +203,6 @@ short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply)
|
||||
DescType returnedType;
|
||||
Size actualSize;
|
||||
long itemsInList;
|
||||
FSSpec theSpec;
|
||||
OSErr err;
|
||||
short i;
|
||||
err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
|
||||
@ -216,9 +219,13 @@ short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply)
|
||||
SetFrontProcess( &PSN ) ;
|
||||
|
||||
for (i = 1; i <= itemsInList; i++) {
|
||||
AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
|
||||
(Ptr) & theSpec, sizeof(theSpec), &actualSize);
|
||||
wxString fName = wxMacFSSpec2MacFilename(&theSpec);
|
||||
wxString fName ;
|
||||
|
||||
FSRef theRef ;
|
||||
AEGetNthPtr(&docList, i, typeFSRef, &keywd, &returnedType,
|
||||
(Ptr) & theRef, sizeof(theRef), &actualSize);
|
||||
fName = wxMacFSRefToPath( &theRef ) ;
|
||||
|
||||
MacPrintFile(fName);
|
||||
}
|
||||
return noErr;
|
||||
|
@ -98,47 +98,20 @@ int wxDirDialog::ShowModal()
|
||||
|
||||
if (mNavReply.validRecord) { // User chose a folder
|
||||
|
||||
FSSpec folderInfo;
|
||||
FSSpec outFileSpec ;
|
||||
FSRef folderInfo;
|
||||
AEDesc specDesc ;
|
||||
|
||||
OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
|
||||
OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSRef, &specDesc);
|
||||
if ( err != noErr ) {
|
||||
m_path = wxT("") ;
|
||||
return wxID_CANCEL ;
|
||||
}
|
||||
folderInfo = **(FSSpec**) specDesc.dataHandle;
|
||||
folderInfo = **(FSRef**) specDesc.dataHandle;
|
||||
if (specDesc.dataHandle != nil) {
|
||||
::AEDisposeDesc(&specDesc);
|
||||
}
|
||||
|
||||
// mNavReply.GetFileSpec(folderInfo);
|
||||
|
||||
// The FSSpec from NavChooseFolder is NOT the file spec
|
||||
// for the folder. The parID field is actually the DirID
|
||||
// of the folder itself, not the folder's parent, and
|
||||
// the name field is empty. We must call PBGetCatInfo
|
||||
// to get the parent DirID and folder name
|
||||
|
||||
Str255 name;
|
||||
CInfoPBRec thePB; // Directory Info Parameter Block
|
||||
thePB.dirInfo.ioCompletion = nil;
|
||||
thePB.dirInfo.ioVRefNum = folderInfo.vRefNum; // Volume is right
|
||||
thePB.dirInfo.ioDrDirID = folderInfo.parID; // Folder's DirID
|
||||
thePB.dirInfo.ioNamePtr = name;
|
||||
thePB.dirInfo.ioFDirIndex = -1; // Lookup using Volume and DirID
|
||||
|
||||
err = ::PBGetCatInfoSync(&thePB);
|
||||
if ( err != noErr ) {
|
||||
m_path = wxT("") ;
|
||||
return wxID_CANCEL ;
|
||||
}
|
||||
// Create cannonical FSSpec
|
||||
::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
|
||||
name, &outFileSpec);
|
||||
|
||||
// outFolderDirID = thePB.dirInfo.ioDrDirID;
|
||||
m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
|
||||
m_path = wxMacFSRefToPath( &folderInfo ) ;
|
||||
return wxID_OK ;
|
||||
}
|
||||
return wxID_CANCEL;
|
||||
|
@ -40,14 +40,10 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "wx/filename.h"
|
||||
#include "wx/mac/private.h"
|
||||
|
||||
#ifdef __DARWIN__
|
||||
# include "MoreFilesX.h"
|
||||
#else
|
||||
# include "MoreFiles.h"
|
||||
# include "MoreFilesExtras.h"
|
||||
#endif
|
||||
#include "MoreFilesX.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
@ -73,7 +69,8 @@ class wxDirData
|
||||
public:
|
||||
wxDirData(const wxString& dirname);
|
||||
~wxDirData();
|
||||
|
||||
|
||||
void Close() ;
|
||||
void SetFileSpec(const wxString& filespec) { m_filespec = filespec; }
|
||||
void SetFlags(int flags) { m_flags = flags; }
|
||||
|
||||
@ -83,11 +80,7 @@ public:
|
||||
const wxString& GetName() const { return m_dirname; }
|
||||
|
||||
private:
|
||||
CInfoPBRec m_CPB ;
|
||||
wxInt16 m_index ;
|
||||
long m_dirId ;
|
||||
Str255 m_name ;
|
||||
Boolean m_isDir ;
|
||||
FSIterator m_iterator ;
|
||||
|
||||
wxString m_dirname;
|
||||
wxString m_filespec;
|
||||
@ -106,8 +99,6 @@ private:
|
||||
wxDirData::wxDirData(const wxString& dirname)
|
||||
: m_dirname(dirname)
|
||||
{
|
||||
OSErr err;
|
||||
|
||||
// throw away the trailing slashes
|
||||
size_t n = m_dirname.length();
|
||||
wxCHECK_RET( n, _T("empty dir name in wxDir") );
|
||||
@ -116,96 +107,88 @@ wxDirData::wxDirData(const wxString& dirname)
|
||||
;
|
||||
|
||||
m_dirname.Truncate(n + 1);
|
||||
|
||||
#ifdef __DARWIN__
|
||||
FSRef theRef;
|
||||
|
||||
// get the FSRef associated with the POSIX path
|
||||
err = FSPathMakeRef((const UInt8 *) m_dirname.c_str(), &theRef, NULL);
|
||||
FSGetVRefNum(&theRef, &(m_CPB.hFileInfo.ioVRefNum));
|
||||
|
||||
err = FSGetNodeID( &theRef , &m_dirId , &m_isDir ) ;
|
||||
#else
|
||||
FSSpec fsspec ;
|
||||
|
||||
wxMacFilename2FSSpec( m_dirname , &fsspec ) ;
|
||||
m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ;
|
||||
|
||||
err = FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ;
|
||||
#endif
|
||||
wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ;
|
||||
|
||||
m_CPB.hFileInfo.ioNamePtr = m_name ;
|
||||
m_index = 0 ;
|
||||
m_iterator = NULL ;
|
||||
}
|
||||
|
||||
wxDirData::~wxDirData()
|
||||
{
|
||||
Close() ;
|
||||
}
|
||||
|
||||
void wxDirData::Close()
|
||||
{
|
||||
if ( m_iterator )
|
||||
{
|
||||
FSCloseIterator( m_iterator ) ;
|
||||
m_iterator = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void wxDirData::Rewind()
|
||||
{
|
||||
m_index = 0 ;
|
||||
Close() ;
|
||||
}
|
||||
|
||||
bool wxDirData::Read(wxString *filename)
|
||||
{
|
||||
if ( !m_isDir )
|
||||
return FALSE ;
|
||||
|
||||
{
|
||||
wxString result;
|
||||
|
||||
short err = noErr ;
|
||||
|
||||
while ( err == noErr )
|
||||
OSStatus err = noErr ;
|
||||
if ( NULL == m_iterator )
|
||||
{
|
||||
m_index++ ;
|
||||
m_CPB.dirInfo.ioFDirIndex = m_index;
|
||||
m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */
|
||||
err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB);
|
||||
if ( err != noErr )
|
||||
break ;
|
||||
FSRef dirRef;
|
||||
err = wxMacPathToFSRef( m_dirname , &dirRef ) ;
|
||||
if ( err == noErr )
|
||||
{
|
||||
err = FSOpenIterator(&dirRef, kFSIterateFlat, &m_iterator);
|
||||
}
|
||||
if ( err )
|
||||
{
|
||||
Close() ;
|
||||
return FALSE ;
|
||||
}
|
||||
}
|
||||
|
||||
wxString name ;
|
||||
|
||||
while( noErr == err )
|
||||
{
|
||||
HFSUniStr255 uniname ;
|
||||
FSRef fileRef;
|
||||
FSCatalogInfo catalogInfo;
|
||||
UInt32 fetched = 0;
|
||||
|
||||
err = FSGetCatalogInfoBulk( m_iterator, 1, &fetched, NULL, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo , &catalogInfo , &fileRef, NULL, &uniname );
|
||||
if ( errFSNoMoreItems == err )
|
||||
return false ;
|
||||
|
||||
wxASSERT( noErr == err ) ;
|
||||
|
||||
// its hidden but we don't want it
|
||||
if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) )
|
||||
continue ;
|
||||
#ifdef __DARWIN__
|
||||
// under X, names that start with '.' are hidden
|
||||
if ( ( m_name[1] == '.' ) && !(m_flags & wxDIR_HIDDEN) )
|
||||
if ( noErr != err )
|
||||
break ;
|
||||
|
||||
name = wxMacHFSUniStrToString( &uniname ) ;
|
||||
|
||||
if ( ( name == wxT(".") || name == wxT("..") ) && !(m_flags & wxDIR_DOTDOT) )
|
||||
continue;
|
||||
#endif
|
||||
#if TARGET_CARBON
|
||||
// under X thats the way the mounting points look like
|
||||
if ( ( m_CPB.dirInfo.ioDrDirID == 0 ) && ( m_flags & wxDIR_DIRS) )
|
||||
break ;
|
||||
#endif
|
||||
// we have a directory
|
||||
if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) )
|
||||
break ;
|
||||
|
||||
// its a file but we don't want it
|
||||
if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) )
|
||||
|
||||
if ( ( name[0U] == '.' ) && !(m_flags & wxDIR_HIDDEN ) )
|
||||
continue ;
|
||||
|
||||
if ( (((FileInfo*)&catalogInfo.finderInfo)->finderFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN ) )
|
||||
continue ;
|
||||
|
||||
wxString file = wxMacMakeStringFromPascal( m_name ) ;
|
||||
// its a dir and we want it
|
||||
if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) && (m_flags & wxDIR_DIRS) )
|
||||
break ;
|
||||
|
||||
// its a file but we don't want it
|
||||
if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0 && !(m_flags & wxDIR_FILES ) )
|
||||
continue ;
|
||||
|
||||
if ( m_filespec.IsEmpty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") )
|
||||
{
|
||||
}
|
||||
else if ( m_filespec.Length() > 1 && m_filespec.Left(1) == wxT("*") )
|
||||
{
|
||||
if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() )
|
||||
{
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == wxT("*") )
|
||||
{
|
||||
if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() )
|
||||
{
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
else if ( file.Upper() != m_filespec.Upper() )
|
||||
else if ( !wxMatchWild(m_filespec, name , FALSE) )
|
||||
{
|
||||
continue ;
|
||||
}
|
||||
@ -217,8 +200,7 @@ bool wxDirData::Read(wxString *filename)
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
*filename = wxMacMakeStringFromPascal( m_name ) ;
|
||||
|
||||
*filename = name ;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
|
||||
OSErr err = noErr;
|
||||
CInfoPBRec cat;
|
||||
|
||||
wxMacFilename2FSSpec( dataPtr , &theFlavor.fileSpec ) ;
|
||||
wxMacFilename2FSSpec( wxString( dataPtr , *wxConvCurrent ) , &theFlavor.fileSpec ) ;
|
||||
|
||||
cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
|
||||
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
|
||||
|
@ -36,12 +36,7 @@ IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
|
||||
|
||||
#include <Navigation.h>
|
||||
|
||||
#ifdef __DARWIN__
|
||||
# include "MoreFilesX.h"
|
||||
#else
|
||||
# include "MoreFiles.h"
|
||||
# include "MoreFilesExtras.h"
|
||||
#endif
|
||||
#include "MoreFilesX.h"
|
||||
|
||||
extern bool gUseNavServices ;
|
||||
|
||||
@ -58,11 +53,7 @@ struct OpenUserDataRec {
|
||||
wxArrayString extensions ;
|
||||
wxArrayLong filtermactypes ;
|
||||
wxString defaultLocation;
|
||||
#if TARGET_CARBON
|
||||
CFArrayRef menuitems ;
|
||||
#else
|
||||
NavMenuItemSpecArrayHandle menuitems ;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct OpenUserDataRec
|
||||
@ -73,11 +64,7 @@ static pascal void NavEventProc(
|
||||
NavCBRecPtr ioParams,
|
||||
NavCallBackUserData ioUserData);
|
||||
|
||||
#if TARGET_CARBON
|
||||
static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
|
||||
#else
|
||||
static NavEventUPP sStandardNavEventFilter = NewNavEventProc(NavEventProc);
|
||||
#endif
|
||||
static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
|
||||
|
||||
static pascal void
|
||||
NavEventProc(
|
||||
@ -87,14 +74,9 @@ NavEventProc(
|
||||
{
|
||||
OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ;
|
||||
if (inSelector == kNavCBEvent) {
|
||||
#if TARGET_CARBON
|
||||
#else
|
||||
wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event);
|
||||
#endif
|
||||
}
|
||||
else if ( inSelector == kNavCBStart )
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
if (data && !(data->defaultLocation).IsEmpty())
|
||||
{
|
||||
// Set default location for the modern Navigation APIs
|
||||
@ -112,22 +94,13 @@ NavEventProc(
|
||||
menuItem.menuType = data->currentfilter;
|
||||
wxMacStringToPascal( data->name[data->currentfilter] , (StringPtr)(menuItem.menuItemName) ) ;
|
||||
::NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &menuItem);
|
||||
|
||||
#else
|
||||
if ( data->menuitems )
|
||||
NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &(*data->menuitems)[data->currentfilter]);
|
||||
#endif
|
||||
}
|
||||
else if ( inSelector == kNavCBPopupMenuSelect )
|
||||
{
|
||||
NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ;
|
||||
#if TARGET_CARBON
|
||||
const size_t numFilters = data->extensions.GetCount();
|
||||
|
||||
if ( menu->menuType < numFilters )
|
||||
#else
|
||||
if ( menu->menuCreator == 'WXNG' )
|
||||
#endif
|
||||
{
|
||||
data->currentfilter = menu->menuType ;
|
||||
if ( data->saveMode )
|
||||
@ -137,27 +110,15 @@ NavEventProc(
|
||||
extension.MakeLower() ;
|
||||
wxString sfilename ;
|
||||
|
||||
#if TARGET_CARBON
|
||||
wxMacCFStringHolder cfString( NavDialogGetSaveFileName( ioParams->context ) , false );
|
||||
sfilename = cfString.AsString() ;
|
||||
#else
|
||||
Str255 filename ;
|
||||
// get the current filename
|
||||
NavCustomControl(ioParams->context, kNavCtlGetEditFileName, &filename);
|
||||
sfilename = wxMacMakeStringFromPascal( filename ) ;
|
||||
#endif
|
||||
|
||||
int pos = sfilename.Find('.', true) ;
|
||||
if ( pos != wxNOT_FOUND )
|
||||
{
|
||||
sfilename = sfilename.Left(pos+1)+extension ;
|
||||
#if TARGET_CARBON
|
||||
cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ;
|
||||
NavDialogSetSaveFileName( ioParams->context , cfString ) ;
|
||||
#else
|
||||
wxMacStringToPascal( sfilename , filename ) ;
|
||||
NavCustomControl(ioParams->context, kNavCtlSetEditFileName, &filename);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -268,7 +229,7 @@ static Boolean CheckFile( const wxString &filename , OSType type , OpenUserDataR
|
||||
return true ;
|
||||
}
|
||||
|
||||
#ifndef __DARWIN__
|
||||
#if !TARGET_API_MAC_OSX
|
||||
static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr)
|
||||
{
|
||||
OpenUserDataRecPtr data = (OpenUserDataRecPtr) dataPtr ;
|
||||
@ -328,28 +289,13 @@ pascal Boolean CrossPlatformFilterCallback (
|
||||
wxString file = wxMacMakeStringFromPascal( spec.name ) ;
|
||||
display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
|
||||
}
|
||||
#if TARGET_CARBON
|
||||
else if ( theItem->descriptorType == typeFSRef )
|
||||
{
|
||||
FSRef fsref ;
|
||||
memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ;
|
||||
|
||||
|
||||
|
||||
CFURLRef fullURLRef;
|
||||
fullURLRef = ::CFURLCreateFromFSRef(NULL, &fsref);
|
||||
#ifdef __UNIX__
|
||||
CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
|
||||
#else
|
||||
CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
|
||||
#endif
|
||||
CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
|
||||
::CFRelease( fullURLRef ) ;
|
||||
wxString file = wxMacCFStringHolder(cfString).AsString(wxFont::GetDefaultEncoding());
|
||||
|
||||
wxString file = wxMacFSRefToPath( &fsref ) ;
|
||||
display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,7 +304,6 @@ pascal Boolean CrossPlatformFilterCallback (
|
||||
|
||||
int wxFileDialog::ShowModal()
|
||||
{
|
||||
#if TARGET_CARBON
|
||||
OSErr err;
|
||||
NavDialogCreationOptions dialogCreateOptions;
|
||||
// set default options
|
||||
@ -474,30 +419,10 @@ int wxFileDialog::ShowModal()
|
||||
|
||||
CFURLRef fullURLRef = 0 ;
|
||||
if (m_dialogStyle & wxSAVE)
|
||||
{
|
||||
CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
|
||||
|
||||
if (parentURLRef)
|
||||
{
|
||||
fullURLRef =
|
||||
::CFURLCreateCopyAppendingPathComponent(NULL,
|
||||
parentURLRef,
|
||||
navReply.saveFileName,
|
||||
false);
|
||||
::CFRelease(parentURLRef);
|
||||
}
|
||||
}
|
||||
thePath = wxMacFSRefToPath( &theFSRef , navReply.saveFileName ) ;
|
||||
else
|
||||
{
|
||||
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());
|
||||
thePath = wxMacFSRefToPath( &theFSRef ) ;
|
||||
|
||||
if (!thePath)
|
||||
{
|
||||
::NavDisposeReply(&navReply);
|
||||
@ -516,163 +441,5 @@ int wxFileDialog::ShowModal()
|
||||
::NavDisposeReply(&navReply);
|
||||
|
||||
return (err == noErr) ? wxID_OK : wxID_CANCEL;
|
||||
#else // TARGET_CARBON
|
||||
|
||||
NavDialogOptions mNavOptions;
|
||||
NavObjectFilterUPP mNavFilterUPP = NULL;
|
||||
NavPreviewUPP mNavPreviewUPP = NULL ;
|
||||
NavReplyRecord mNavReply;
|
||||
AEDesc mDefaultLocation ;
|
||||
bool mSelectDefault = false ;
|
||||
OSStatus err = noErr ;
|
||||
// setup dialog
|
||||
|
||||
mNavFilterUPP = nil;
|
||||
mNavPreviewUPP = nil;
|
||||
mSelectDefault = false;
|
||||
mDefaultLocation.descriptorType = typeNull;
|
||||
mDefaultLocation.dataHandle = nil;
|
||||
|
||||
NavGetDefaultDialogOptions(&mNavOptions);
|
||||
wxMacStringToPascal( m_message , (StringPtr)mNavOptions.message ) ;
|
||||
wxMacStringToPascal( m_fileName , (StringPtr)mNavOptions.savedFileName ) ;
|
||||
|
||||
// Set default location, the location
|
||||
// that's displayed when the dialog
|
||||
// first appears
|
||||
|
||||
FSSpec location ;
|
||||
wxMacFilename2FSSpec( m_dir , &location ) ;
|
||||
|
||||
err = ::AECreateDesc(typeFSS, &location, sizeof(FSSpec), &mDefaultLocation );
|
||||
|
||||
if ( mDefaultLocation.dataHandle )
|
||||
{
|
||||
if (mSelectDefault)
|
||||
{
|
||||
mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
|
||||
} else {
|
||||
mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
|
||||
}
|
||||
}
|
||||
|
||||
memset( &mNavReply , 0 , sizeof( mNavReply ) ) ;
|
||||
mNavReply.validRecord = false;
|
||||
mNavReply.replacing = false;
|
||||
mNavReply.isStationery = false;
|
||||
mNavReply.translationNeeded = false;
|
||||
mNavReply.selection.descriptorType = typeNull;
|
||||
mNavReply.selection.dataHandle = nil;
|
||||
mNavReply.keyScript = smSystemScript;
|
||||
mNavReply.fileTranslation = nil;
|
||||
mNavReply.version = kNavReplyRecordVersion ;
|
||||
|
||||
// zero all data
|
||||
|
||||
m_path = wxEmptyString ;
|
||||
m_fileName = wxEmptyString ;
|
||||
m_paths.Empty();
|
||||
m_fileNames.Empty();
|
||||
|
||||
OpenUserDataRec myData;
|
||||
MakeUserDataRec( &myData , m_wildCard ) ;
|
||||
myData.currentfilter = m_filterIndex ;
|
||||
if ( myData.extensions.GetCount() > 0 )
|
||||
{
|
||||
mNavOptions.popupExtension = (NavMenuItemSpecArrayHandle) NewHandle( sizeof( NavMenuItemSpec ) * myData.extensions.GetCount() ) ;
|
||||
myData.menuitems = mNavOptions.popupExtension ;
|
||||
for ( size_t i = 0 ; i < myData.extensions.GetCount() ; ++i )
|
||||
{
|
||||
(*mNavOptions.popupExtension)[i].version = kNavMenuItemSpecVersion ;
|
||||
(*mNavOptions.popupExtension)[i].menuCreator = 'WXNG' ;
|
||||
// TODO : according to the new docs -1 to 10 are reserved for the OS
|
||||
(*mNavOptions.popupExtension)[i].menuType = i ;
|
||||
wxMacStringToPascal( myData.name[i] , (StringPtr)(*mNavOptions.popupExtension)[i].menuItemName ) ;
|
||||
}
|
||||
}
|
||||
if ( m_dialogStyle & wxSAVE )
|
||||
{
|
||||
myData.saveMode = true ;
|
||||
|
||||
mNavOptions.dialogOptionFlags |= kNavDontAutoTranslate ;
|
||||
mNavOptions.dialogOptionFlags |= kNavDontAddTranslateItems ;
|
||||
|
||||
err = ::NavPutFile(
|
||||
&mDefaultLocation,
|
||||
&mNavReply,
|
||||
&mNavOptions,
|
||||
sStandardNavEventFilter ,
|
||||
NULL,
|
||||
kNavGenericSignature,
|
||||
&myData); // User Data
|
||||
m_filterIndex = myData.currentfilter ;
|
||||
}
|
||||
else
|
||||
{
|
||||
myData.saveMode = false ;
|
||||
|
||||
mNavFilterUPP = NewNavObjectFilterUPP( CrossPlatformFilterCallback ) ;
|
||||
if ( m_dialogStyle & wxMULTIPLE )
|
||||
mNavOptions.dialogOptionFlags |= kNavAllowMultipleFiles ;
|
||||
else
|
||||
mNavOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles ;
|
||||
|
||||
err = ::NavGetFile(
|
||||
&mDefaultLocation,
|
||||
&mNavReply,
|
||||
&mNavOptions,
|
||||
sStandardNavEventFilter ,
|
||||
mNavPreviewUPP,
|
||||
mNavFilterUPP,
|
||||
NULL ,
|
||||
&myData);
|
||||
m_filterIndex = myData.currentfilter ;
|
||||
}
|
||||
|
||||
DisposeNavObjectFilterUPP(mNavFilterUPP);
|
||||
if ( mDefaultLocation.dataHandle != nil )
|
||||
{
|
||||
::AEDisposeDesc(&mDefaultLocation);
|
||||
}
|
||||
|
||||
if ( (err != noErr) && (err != userCanceledErr) ) {
|
||||
return wxID_CANCEL ;
|
||||
}
|
||||
|
||||
if (mNavReply.validRecord)
|
||||
{
|
||||
FSSpec outFileSpec ;
|
||||
AEDesc specDesc ;
|
||||
AEKeyword keyWord ;
|
||||
|
||||
long count ;
|
||||
::AECountItems( &mNavReply.selection , &count ) ;
|
||||
for ( long i = 1 ; i <= count ; ++i )
|
||||
{
|
||||
OSErr err = ::AEGetNthDesc( &mNavReply.selection , i , typeFSS, &keyWord , &specDesc);
|
||||
if ( err != noErr )
|
||||
{
|
||||
m_path = wxT("") ;
|
||||
return wxID_CANCEL ;
|
||||
}
|
||||
outFileSpec = **(FSSpec**) specDesc.dataHandle;
|
||||
if (specDesc.dataHandle != nil) {
|
||||
::AEDisposeDesc(&specDesc);
|
||||
}
|
||||
m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
|
||||
|
||||
m_paths.Add( m_path ) ;
|
||||
m_fileName = wxFileNameFromPath(m_path);
|
||||
m_fileNames.Add(m_fileName);
|
||||
}
|
||||
// set these to the first hit
|
||||
m_path = m_paths[ 0 ] ;
|
||||
m_fileName = wxFileNameFromPath(m_path);
|
||||
m_dir = wxPathOnly(m_path);
|
||||
NavDisposeReply( &mNavReply ) ;
|
||||
return wxID_OK ;
|
||||
}
|
||||
return wxID_CANCEL;
|
||||
#endif // TARGET_CARBON
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
//
|
||||
|
||||
#ifdef __WXMAC__
|
||||
#include "wx/mac/private.h"
|
||||
#include "wx/mac/uma.h"
|
||||
#include <Movies.h>
|
||||
#include <Gestalt.h>
|
||||
#endif
|
||||
@ -375,42 +375,57 @@ bool wxSound::DoPlay(unsigned flags) const
|
||||
if (!wxInitQT())
|
||||
return false;
|
||||
|
||||
short movieResFile;
|
||||
FSSpec sfFile;
|
||||
|
||||
#ifdef __WXMAC__
|
||||
wxMacFilename2FSSpec( m_sndname , &sfFile ) ;
|
||||
#else
|
||||
int nError;
|
||||
if ((nError = NativePathNameToFSSpec ((char*) m_sndname.c_str(), &sfFile, 0)) != noErr)
|
||||
OSErr err = noErr ;
|
||||
#if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 )
|
||||
if ( UMAGetSystemVersion() >= 0x1030 )
|
||||
{
|
||||
wxLogSysError(wxString::Format(wxT("File:%s does not exist\nError:%i"),
|
||||
m_sndname.c_str(), nError));
|
||||
return false;
|
||||
Handle dataRef = NULL;
|
||||
OSType dataRefType;
|
||||
|
||||
err = QTNewDataReferenceFromFullPathCFString(wxMacCFStringHolder(m_sndname,wxLocale::GetSystemEncoding()),
|
||||
kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType);
|
||||
|
||||
if (NULL != dataRef)
|
||||
{
|
||||
err = NewMovieFromDataRef( &movie, newMovieDontAskUnresolvedDataRefs , NULL, dataRef, dataRefType );
|
||||
DisposeHandle(dataRef);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
if (OpenMovieFile (&sfFile, &movieResFile, fsRdPerm) != noErr)
|
||||
{
|
||||
wxLogSysError(wxT("Quicktime couldn't open the file"));
|
||||
return false;
|
||||
short movieResFile;
|
||||
FSSpec sfFile;
|
||||
#ifdef __WXMAC__
|
||||
wxMacFilename2FSSpec( m_sndname , &sfFile ) ;
|
||||
#else
|
||||
int nError;
|
||||
if ((nError = NativePathNameToFSSpec ((char*) m_sndname.c_str(), &sfFile, 0)) != noErr)
|
||||
{
|
||||
wxLogSysError(wxString::Format(wxT("File:%s does not exist\nError:%i"),
|
||||
m_sndname.c_str(), nError));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
if (OpenMovieFile (&sfFile, &movieResFile, fsRdPerm) != noErr)
|
||||
{
|
||||
wxLogSysError(wxT("Quicktime couldn't open the file"));
|
||||
return false;
|
||||
}
|
||||
short movieResID = 0;
|
||||
Str255 movieName;
|
||||
|
||||
err = NewMovieFromFile (
|
||||
&movie,
|
||||
movieResFile,
|
||||
&movieResID,
|
||||
movieName,
|
||||
newMovieActive,
|
||||
NULL); //wasChanged
|
||||
|
||||
CloseMovieFile (movieResFile);
|
||||
}
|
||||
|
||||
|
||||
short movieResID = 0;
|
||||
Str255 movieName;
|
||||
OSErr err;
|
||||
|
||||
err = NewMovieFromFile (
|
||||
&movie,
|
||||
movieResFile,
|
||||
&movieResID,
|
||||
movieName,
|
||||
newMovieActive,
|
||||
NULL); //wasChanged
|
||||
|
||||
CloseMovieFile (movieResFile);
|
||||
|
||||
|
||||
if (err != noErr)
|
||||
{
|
||||
wxLogSysError(
|
||||
|
@ -33,12 +33,7 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __DARWIN__
|
||||
# include "MoreFilesX.h"
|
||||
#else
|
||||
# include "MoreFiles.h"
|
||||
# include "MoreFilesExtras.h"
|
||||
#endif
|
||||
#include "MoreFilesX.h"
|
||||
|
||||
#ifndef __DARWIN__
|
||||
#include <Threads.h>
|
||||
@ -524,18 +519,12 @@ wxString wxMacFindFolder( short vol,
|
||||
OSType folderType,
|
||||
Boolean createFolder)
|
||||
{
|
||||
short vRefNum ;
|
||||
long dirID ;
|
||||
FSRef fsRef ;
|
||||
wxString strDir ;
|
||||
|
||||
if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)
|
||||
{
|
||||
FSSpec file ;
|
||||
if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
|
||||
{
|
||||
strDir = wxMacFSSpec2MacFilename( &file ) + wxFILE_SEP_PATH ;
|
||||
}
|
||||
}
|
||||
if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
|
||||
strDir = wxMacFSRefToPath( &fsRef ) ;
|
||||
|
||||
return strDir ;
|
||||
}
|
||||
|
||||
@ -667,20 +656,28 @@ bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
|
||||
|
||||
p = p + wxT(":") ;
|
||||
|
||||
Str255 volumeName ;
|
||||
XVolumeParam pb ;
|
||||
|
||||
wxMacStringToPascal( p , volumeName ) ;
|
||||
OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ;
|
||||
if ( err == noErr ) {
|
||||
if ( pTotal ) {
|
||||
(*pTotal) = wxLongLong( pb.ioVTotalBytes ) ;
|
||||
}
|
||||
if ( pFree ) {
|
||||
(*pFree) = wxLongLong( pb.ioVFreeBytes ) ;
|
||||
}
|
||||
OSErr err = noErr ;
|
||||
|
||||
FSRef fsRef ;
|
||||
err = wxMacPathToFSRef( p , &fsRef ) ;
|
||||
if ( noErr == err )
|
||||
{
|
||||
FSVolumeRefNum vRefNum ;
|
||||
err = FSGetVRefNum( &fsRef , &vRefNum ) ;
|
||||
if ( noErr == err )
|
||||
{
|
||||
UInt64 freeBytes , totalBytes ;
|
||||
err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ) ;
|
||||
if ( noErr == err )
|
||||
{
|
||||
if ( pTotal )
|
||||
*pTotal = wxLongLong( totalBytes ) ;
|
||||
if ( pFree )
|
||||
*pFree = wxLongLong( freeBytes ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return err == noErr ;
|
||||
}
|
||||
#endif // !__DARWIN__
|
||||
|
@ -30,106 +30,27 @@ extern "C" {
|
||||
#include <string.h>
|
||||
|
||||
#ifndef __DARWIN__
|
||||
#define wxEXECUTE_WIN_MESSAGE 10000
|
||||
|
||||
#include "wx/mac/private.h"
|
||||
|
||||
/*
|
||||
Below FinderLaunch function comes from:
|
||||
http://developer.apple.com/technotes/tn/tn1002.html#fndrask
|
||||
*/
|
||||
/* FinderLaunch converts a list of nTargets FSSpec records
|
||||
pointed to by the targetList parameter and converts the
|
||||
list to an Apple Event. It then sends that event to the
|
||||
Finder. The array of FSSpec records pointed to by the
|
||||
targetList parameter may contain references to files,
|
||||
folders, or applications. The net effect of this command
|
||||
is equivalent to the user selecting an icon in one of the
|
||||
Finder's windows and then choosing the open command from
|
||||
the Finder's file menu. */
|
||||
static OSErr FinderLaunch(long nTargets, FSSpec *targetList) {
|
||||
OSErr err;
|
||||
AppleEvent theAEvent, theReply;
|
||||
AEAddressDesc fndrAddress;
|
||||
AEDescList targetListDesc;
|
||||
OSType fndrCreator;
|
||||
Boolean wasChanged;
|
||||
AliasHandle targetAlias;
|
||||
long index;
|
||||
|
||||
/* set up locals */
|
||||
AECreateDesc(typeNull, NULL, 0, &theAEvent);
|
||||
AECreateDesc(typeNull, NULL, 0, &fndrAddress);
|
||||
AECreateDesc(typeNull, NULL, 0, &theReply);
|
||||
AECreateDesc(typeNull, NULL, 0, &targetListDesc);
|
||||
targetAlias = NULL;
|
||||
fndrCreator = 'MACS';
|
||||
|
||||
/* verify parameters */
|
||||
if ((nTargets == 0) || (targetList == NULL)) {
|
||||
err = paramErr;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* create an open documents event targeting the
|
||||
finder */
|
||||
err = AECreateDesc(typeApplSignature, (Ptr) &fndrCreator,
|
||||
sizeof(fndrCreator), &fndrAddress);
|
||||
if (err != noErr) goto bail;
|
||||
err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
|
||||
&fndrAddress, kAutoGenerateReturnID,
|
||||
kAnyTransactionID, &theAEvent);
|
||||
if (err != noErr) goto bail;
|
||||
|
||||
/* create the list of files to open */
|
||||
err = AECreateList(NULL, 0, false, &targetListDesc);
|
||||
if (err != noErr) goto bail;
|
||||
for ( index=0; index < nTargets; index++) {
|
||||
if (targetAlias == NULL)
|
||||
err = NewAlias(NULL, (targetList + index),
|
||||
&targetAlias);
|
||||
else err = UpdateAlias(NULL, (targetList + index),
|
||||
targetAlias, &wasChanged);
|
||||
if (err != noErr) goto bail;
|
||||
HLock((Handle) targetAlias);
|
||||
err = AEPutPtr(&targetListDesc, (index + 1),
|
||||
typeAlias, *targetAlias,
|
||||
GetHandleSize((Handle) targetAlias));
|
||||
HUnlock((Handle) targetAlias);
|
||||
if (err != noErr) goto bail;
|
||||
}
|
||||
|
||||
/* add the file list to the Apple Event */
|
||||
err = AEPutParamDesc(&theAEvent, keyDirectObject,
|
||||
&targetListDesc);
|
||||
if (err != noErr) goto bail;
|
||||
|
||||
/* send the event to the Finder */
|
||||
err = AESend(&theAEvent, &theReply, kAENoReply,
|
||||
kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
|
||||
|
||||
/* clean up and leave */
|
||||
bail:
|
||||
if (targetAlias != NULL) DisposeHandle((Handle) targetAlias);
|
||||
AEDisposeDesc(&targetListDesc);
|
||||
AEDisposeDesc(&theAEvent);
|
||||
AEDisposeDesc(&fndrAddress);
|
||||
AEDisposeDesc(&theReply);
|
||||
return err;
|
||||
}
|
||||
#include "LaunchServices.h"
|
||||
|
||||
long wxExecute(const wxString& command, int flags, wxProcess *WXUNUSED(handler))
|
||||
{
|
||||
wxASSERT_MSG( flags == wxEXEC_ASYNC,
|
||||
wxT("wxExecute: Only wxEXEC_ASYNC is supported") );
|
||||
|
||||
FSSpec fsSpec;
|
||||
wxMacFilename2FSSpec(command, &fsSpec);
|
||||
FSRef fsRef ;
|
||||
OSErr err = noErr ;
|
||||
err = wxMacPathToFSRef( command , &fsRef ) ;
|
||||
if ( noErr == err )
|
||||
{
|
||||
err = LSOpenFSRef( &fsRef , NULL ) ;
|
||||
}
|
||||
|
||||
// 0 means execution failed. Returning non-zero is a PID, but not
|
||||
// on Mac where PIDs are 64 bits and won't fit in a long, so we
|
||||
// return a dummy value for now.
|
||||
return ( FinderLaunch(1 /*one file*/, &fsSpec) == noErr ) ? -1 : 0;
|
||||
return ( err == noErr ) ? -1 : 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user