diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/Wish.pbproj/project.pbxproj | 28 | ||||
-rw-r--r-- | macosx/tkMacOSXDialog.c | 3 | ||||
-rw-r--r-- | macosx/tkMacOSXHLEvents.c | 95 | ||||
-rw-r--r-- | macosx/tkMacOSXUtil.c | 330 | ||||
-rw-r--r-- | macosx/tkMacOSXUtil.h | 65 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 3 |
6 files changed, 65 insertions, 459 deletions
diff --git a/macosx/Wish.pbproj/project.pbxproj b/macosx/Wish.pbproj/project.pbxproj index 43bc086..932be57 100644 --- a/macosx/Wish.pbproj/project.pbxproj +++ b/macosx/Wish.pbproj/project.pbxproj @@ -380,7 +380,6 @@ F5375541016C376E01DC9062, F5375542016C376E01DC9062, F5375543016C376E01DC9062, - F5375544016C376E01DC9062, F5375545016C376E01DC9062, ); isa = PBXGroup; @@ -423,12 +422,6 @@ path = tkMacOSXPort.h; refType = 2; }; - F5375544016C376E01DC9062 = { - fileEncoding = 5; - isa = PBXFileReference; - path = tkMacOSXUtil.h; - refType = 2; - }; F5375545016C376E01DC9062 = { fileEncoding = 5; isa = PBXFileReference; @@ -464,7 +457,6 @@ F5375561016C376E01DC9062, F5375562016C376E01DC9062, F5375563016C376E01DC9062, - F5375564016C376E01DC9062, F5375565016C376E01DC9062, F5375567016C376E01DC9062, F5375568016C376E01DC9062, @@ -635,12 +627,6 @@ path = tkMacOSXTest.c; refType = 4; }; - F5375564016C376E01DC9062 = { - fileEncoding = 5; - isa = PBXFileReference; - path = tkMacOSXUtil.c; - refType = 4; - }; F5375565016C376E01DC9062 = { fileEncoding = 5; isa = PBXFileReference; @@ -1617,7 +1603,6 @@ MacOS X Port by Jim Ingham <jingham@apple.com> & Ian Reid, Copyright  F53755FF016C397D01DC9062, F5375600016C397D01DC9062, F5375601016C397D01DC9062, - F5375602016C397D01DC9062, F5375603016C397D01DC9062, F537566E016C3A1F01DC9062, F537566F016C3A1F01DC9062, @@ -1749,7 +1734,6 @@ MacOS X Port by Jim Ingham <jingham@apple.com> & Ian Reid, Copyright  F5375664016C39A101DC9062, F5375665016C39A101DC9062, F5375666016C39A101DC9062, - F5375667016C39A101DC9062, F5375668016C39A101DC9062, F537566A016C39A101DC9062, F537566B016C39A101DC9062, @@ -1990,12 +1974,6 @@ MacOS X Port by Jim Ingham <jingham@apple.com> & Ian Reid, Copyright  settings = { }; }; - F5375602016C397D01DC9062 = { - fileRef = F5375544016C376E01DC9062; - isa = PBXBuildFile; - settings = { - }; - }; F5375603016C397D01DC9062 = { fileRef = F5375545016C376E01DC9062; isa = PBXBuildFile; @@ -2572,12 +2550,6 @@ MacOS X Port by Jim Ingham <jingham@apple.com> & Ian Reid, Copyright  settings = { }; }; - F5375667016C39A101DC9062 = { - fileRef = F5375564016C376E01DC9062; - isa = PBXBuildFile; - settings = { - }; - }; F5375668016C39A101DC9062 = { fileRef = F5375565016C376E01DC9062; isa = PBXBuildFile; diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 6232e64..8da90f6 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -9,13 +9,12 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.3 2003/02/24 19:27:08 wolfsuit Exp $ + * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4 2003/02/25 16:09:23 das Exp $ */ #include <Carbon/Carbon.h> #include "tkPort.h" #include "tkInt.h" -#include "tkMacOSXUtil.h" #include "tkMacOSXInt.h" #include "tkFileFilter.h" diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 41b707f..7c7566c 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -10,10 +10,10 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.3 2002/09/12 17:34:16 das Exp $ + * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.4 2003/02/25 16:09:25 das Exp $ */ -#include "tkMacOSXUtil.h" +#include "tkMacOSXPort.h" #include "tkMacOSXInt.h" #include <Carbon/Carbon.h> @@ -44,6 +44,7 @@ static OSErr PrefsHandler (const AppleEvent * event, AppleEvent * reply, long ha static int MissedAnyParameters _ANSI_ARGS_((const AppleEvent *theEvent)); static int ReallyKillMe _ANSI_ARGS_((Tcl_Event *eventPtr, int flags)); +static OSErr FSRefToDString _ANSI_ARGS_((const FSRef *fsref, Tcl_DString *ds)); /* *---------------------------------------------------------------------- @@ -100,7 +101,7 @@ TkMacOSXInitAppleEvents( if (interp != NULL) { ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler); - err = AEInstallEventHandler('misc', 'dosc', + err = AEInstallEventHandler(kAEMiscStandards, kAEDoScript, ScriptHandlerUPP, (long) interp, false); } } @@ -201,7 +202,7 @@ OdocHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon) { Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; AEDescList fileSpecList; - FSSpec file; + FSRef file; OSErr err; DescType type; Size actual; @@ -246,23 +247,17 @@ OdocHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon) Tcl_DStringInit(&command); Tcl_DStringAppend(&command, "::tk::mac::OpenDocument", -1); for (index = 1; index <= count; index++) { - int length; - Handle fullPath; - - err = AEGetNthPtr(&fileSpecList, index, typeFSS, - &keyword, &type, (Ptr) &file, sizeof(FSSpec), &actual); + err = AEGetNthPtr(&fileSpecList, index, typeFSRef, + &keyword, &type, (Ptr) &file, sizeof(FSRef), &actual); if ( err != noErr ) { continue; } - err = FSpPathFromLocation(&file, &length, &fullPath); - HLock(fullPath); - Tcl_ExternalToUtfDString(NULL, *fullPath, length, &pathName); - HUnlock(fullPath); - DisposeHandle(fullPath); - - Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName)); - Tcl_DStringFree(&pathName); + err = FSRefToDString(&file, &pathName); + if (err == noErr) { + Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName)); + Tcl_DStringFree(&pathName); + } } Tcl_GlobalEval(interp, Tcl_DStringValue(&command)); @@ -319,7 +314,7 @@ ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon) strlen(errString)); theErr = -1771; } else { - if (theDesc.descriptorType == (DescType)'TEXT') { + if (theDesc.descriptorType == (DescType)typeChar) { Tcl_DString encodedText; short i; Size size; @@ -343,23 +338,30 @@ ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon) &encodedText); tclErr = Tcl_GlobalEval(interp, Tcl_DStringValue(&encodedText)); Tcl_DStringFree(&encodedText); - } else if (theDesc.descriptorType == (DescType)'alis') { + } else if (theDesc.descriptorType == (DescType)typeAlias) { Boolean dummy; - FSSpec theFSS; - Handle fullPath; - int length; - AliasHandle aliasHandle; - - AEGetDescData (&theDesc,&aliasHandle,sizeof(aliasHandle ) ); + FSRef file; + AliasPtr alias; + Size theSize; + + theSize = AEGetDescDataSize(&theDesc); + alias = (AliasPtr) ckalloc(theSize); + if (alias) { + AEGetDescData (&theDesc, alias, theSize); - theErr = ResolveAlias(NULL, aliasHandle, - &theFSS, &dummy); + theErr = FSResolveAlias(NULL, &alias, + &file, &dummy); + ckfree((char*)alias); + } else { + theErr = memFullErr; + } if (theErr == noErr) { - FSpPathFromLocation(&theFSS, &length, &fullPath); - HLock(fullPath); - Tcl_EvalFile(interp, *fullPath); - HUnlock(fullPath); - DisposeHandle(fullPath); + Tcl_DString scriptName; + theErr = FSRefToDString(&file, &scriptName); + if (theErr == noErr) { + Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName)); + Tcl_DStringFree(&scriptName); + } } else { sprintf(errString, "AEDoScriptHandler: file not found"); AEPutParamPtr(reply, keyErrorString, typeChar, @@ -457,3 +459,32 @@ MissedAnyParameters( return (err != errAEDescNotFound); } + +/* + *---------------------------------------------------------------------- + * + * FSRefToDString -- + * + * Get a POSIX path from an FSRef. + * + * Results: + * In the parameter ds. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static OSErr +FSRefToDString(const FSRef *fsref, Tcl_DString *ds) +{ + UInt8 fileName[PATH_MAX+1]; + OSErr err; + + err = FSRefMakePath(fsref, fileName, sizeof(fileName)); + if (err == noErr) { + Tcl_UtfToExternalDString(NULL, fileName, -1, ds); + } + return err; +} diff --git a/macosx/tkMacOSXUtil.c b/macosx/tkMacOSXUtil.c deleted file mode 100644 index 1e4e856..0000000 --- a/macosx/tkMacOSXUtil.c +++ /dev/null @@ -1,330 +0,0 @@ -#include <Carbon/Carbon.h> - -#include "tkMacOSXUtil.h" - -#define DIR_SEP_CHAR ':' - -/*****************************************************************************/ -pascal OSErr FSMakeFSSpecCompat(short vRefNum, - long dirID, - ConstStr255Param fileName, - FSSpec *spec) -{ - OSErr result; - - { - /* Let the file system create the FSSpec if it can since it does the job */ - /* much more efficiently than I can. */ - result = FSMakeFSSpec(vRefNum, dirID, fileName, spec); - /* Fix a bug in Macintosh PC Exchange's MakeFSSpec code where 0 is */ - /* returned in the parID field when making an FSSpec to the volume's */ - /* root directory by passing a full pathname in MakeFSSpec's */ - /* fileName parameter. Fixed in Mac OS 8.1 */ - if ( (result == noErr) && (spec->parID == 0) ) - spec->parID = fsRtParID; - } - return ( result ); -} - - -/*****************************************************************************/ -pascal OSErr GetCatInfoNoName(short vRefNum, - long dirID, - ConstStr255Param name, - CInfoPBPtr pb) -{ - Str31 tempName; - OSErr error; - - /* Protection against File Sharing problem */ - if ( (name == NULL) || (name[0] == 0) ) - { - tempName[0] = 0; - pb->dirInfo.ioNamePtr = tempName; - pb->dirInfo.ioFDirIndex = -1; /* use ioDirID */ - } - else - { - pb->dirInfo.ioNamePtr = (StringPtr)name; - pb->dirInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */ - } - pb->dirInfo.ioVRefNum = vRefNum; - pb->dirInfo.ioDrDirID = dirID; - error = PBGetCatInfoSync(pb); - pb->dirInfo.ioNamePtr = NULL; - return ( error ); -} -/*****************************************************************************/ -pascal OSErr GetDirectoryID(short vRefNum, - long dirID, - ConstStr255Param name, - long *theDirID, - Boolean *isDirectory) -{ - CInfoPBRec pb; - OSErr error; - error = GetCatInfoNoName(vRefNum, dirID, name, &pb); - if ( error == noErr ) - { - *isDirectory = (pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0; - if ( *isDirectory ) - { - *theDirID = pb.dirInfo.ioDrDirID; - } - else - { - *theDirID = pb.hFileInfo.ioFlParID; - } - } - - return ( error ); -} - -/*****************************************************************************/ -pascal OSErr FSpGetDirectoryID(const FSSpec *spec, - long *theDirID, - Boolean *isDirectory) -{ - return ( GetDirectoryID(spec->vRefNum, spec->parID, spec->name, - theDirID, isDirectory) ); -} - -/* - *---------------------------------------------------------------------- - * - * FSpPathFromLocation -- - * - * This function obtains a full path name for a given macintosh - * FSSpec. Unlike the More Files function FSpGetFullPath, this - * function will return a C string in the Handle. It also will - * create paths for FSSpec that do not yet exist. - * - * Results: - * OSErr code. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -OSErr -FSpPathFromLocation( - FSSpec *spec, /* The location we want a path for. */ - int *length, /* Length of the resulting path. */ - Handle *fullPath) /* Handle to path. */ -{ - OSErr err; - FSSpec tempSpec; - CInfoPBRec pb; - - *fullPath = NULL; - - /* - * Make a copy of the input FSSpec that can be modified. - */ - BlockMoveData(spec, &tempSpec, sizeof(FSSpec)); - - if (tempSpec.parID == fsRtParID) { - /* - * The object is a volume. Add a colon to make it a full - * pathname. Allocate a handle for it and we are done. - */ - tempSpec.name[0] += 2; - tempSpec.name[tempSpec.name[0] - 1] = DIR_SEP_CHAR; - tempSpec.name[tempSpec.name[0]] = '\0'; - - err = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); - } else { - /* - * The object isn't a volume. Is the object a file or a directory? - */ - pb.dirInfo.ioNamePtr = tempSpec.name; - pb.dirInfo.ioVRefNum = tempSpec.vRefNum; - pb.dirInfo.ioDrDirID = tempSpec.parID; - pb.dirInfo.ioFDirIndex = 0; - err = PBGetCatInfoSync(&pb); - - if ((err == noErr) || (err == fnfErr)) { - /* - * If the file doesn't currently exist we start over. If the - * directory exists everything will work just fine. Otherwise we - * will just fail later. If the object is a directory, append a - * colon so full pathname ends with colon, but only if the name is - * not empty. NavServices returns FSSpec's with the parent ID set, - * but the name empty... - */ - if (err == fnfErr) { - BlockMoveData(spec, &tempSpec, sizeof(FSSpec)); - } else if ( (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) { - if (tempSpec.name[0] > 0) { - tempSpec.name[0] += 1; - tempSpec.name[tempSpec.name[0]] = DIR_SEP_CHAR; - } - } - - /* - * Create a new Handle for the object - make it a C string. - */ - tempSpec.name[0] += 1; - tempSpec.name[tempSpec.name[0]] = '\0'; - err = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); - if (err == noErr) { - /* - * Get the ancestor directory names - loop until we have an - * error or find the root directory. - */ - pb.dirInfo.ioNamePtr = tempSpec.name; - pb.dirInfo.ioVRefNum = tempSpec.vRefNum; - pb.dirInfo.ioDrParID = tempSpec.parID; - do { - pb.dirInfo.ioFDirIndex = -1; - pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; - err = PBGetCatInfoSync(&pb); - if (err == noErr) { - /* - * Append colon to directory name and add - * directory name to beginning of fullPath. - */ - ++tempSpec.name[0]; - tempSpec.name[tempSpec.name[0]] = DIR_SEP_CHAR; - - (void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1], - tempSpec.name[0]); - fprintf(stderr,"mem\n"); - err = MemError(); - } - } while ( (err == noErr) && - (pb.dirInfo.ioDrDirID != fsRtDirID) ); - } - } - } - - /* - * On error Dispose the handle, set it to NULL & return the err. - * Otherwise, set the length & return. - */ - if (err == noErr) { - *length = GetHandleSize(*fullPath) - 1; - } else { - if ( *fullPath != NULL ) { - DisposeHandle(*fullPath); - } - *fullPath = NULL; - *length = 0; - } - - return err; -} - -/* - *---------------------------------------------------------------------- - * - * FSpLocationFromPath -- - * - * This function obtains an FSSpec for a given macintosh path. - * Unlike the More Files function FSpLocationFromFullPath, this - * function will also accept partial paths and resolve any aliases - * along the path. - * - * Results: - * OSErr code. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -OSErr -FSpLocationFromPath( - int length, /* Length of path. */ - const char *path, /* The path to convert. */ - FSSpecPtr fileSpecPtr) /* On return the spec for the path. */ -{ - Str255 fileName; - OSErr err; - short vRefNum; - long dirID; - int pos, cur; - Boolean isDirectory; - Boolean wasAlias; - - /* - * Check to see if this is a full path. If partial - * we assume that path starts with the current working - * directory. (Ie. volume & dir = 0) - */ - vRefNum = 0; - dirID = 0; - cur = 0; - if (length == 0) { - return fnfErr; - } - if (path[cur] == DIR_SEP_CHAR) { - cur++; - if (cur >= length) { - /* - * If path = ":", just return current directory. - */ - FSMakeFSSpecCompat(0, 0, NULL, fileSpecPtr); - return noErr; - } - } else { - while (path[cur] != DIR_SEP_CHAR && cur < length) { - cur++; - } - if (cur > 255) { - return bdNamErr; - } - if (cur < length) { - /* - * This is a full path - */ - cur++; - strncpy((char *) fileName + 1, path, cur); - fileName[0] = cur; - err = FSMakeFSSpecCompat(0, 0, fileName, fileSpecPtr); - if (err != noErr) return err; - FSpGetDirectoryID(fileSpecPtr, &dirID, &isDirectory); - vRefNum = fileSpecPtr->vRefNum; - } else { - cur = 0; - } - } - - isDirectory = 1; - while (cur < length) { - if (!isDirectory) { - return dirNFErr; - } - pos = cur; - while (path[pos] != DIR_SEP_CHAR && pos < length) { - pos++; - } - if (pos == cur) { - /* Move up one dir */ - /* cur++; */ - fileName[1] = DIR_SEP_CHAR; - fileName[2] = DIR_SEP_CHAR; - fileName[0] = 2; - } else if (pos - cur > 255) { - return bdNamErr; - } else { - strncpy((char *) fileName + 1, &path[cur], pos - cur); - fileName[0] = pos - cur; - } - err = FSMakeFSSpecCompat(vRefNum, dirID, fileName, fileSpecPtr); - if (err != noErr) return err; - err = ResolveAliasFile(fileSpecPtr, true, &isDirectory, &wasAlias); - if (err != noErr) return err; - FSpGetDirectoryID(fileSpecPtr, &dirID, &isDirectory); - vRefNum = fileSpecPtr->vRefNum; - cur = pos; - if (path[cur] == DIR_SEP_CHAR) { - cur++; - } - } - - return noErr; -} diff --git a/macosx/tkMacOSXUtil.h b/macosx/tkMacOSXUtil.h deleted file mode 100644 index e38f8a5..0000000 --- a/macosx/tkMacOSXUtil.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * tkMacOSXUtil.h -- - * - * Declarations of utility functions from the MoreFiles package. - * - * FIXME: We should be able to replace all these with FSRef calls - * much more simply. - * - * Copyright 2001, Apple Computer, Inc. - * - * The following terms apply to all files originating from Apple - * Computer, Inc. ("Apple") and associated with the software - * unless explicitly disclaimed in individual files. - * - * - * Apple hereby grants permission to use, copy, modify, - * distribute, and license this software and its documentation - * for any purpose, provided that existing copyright notices are - * retained in all copies and that this notice is included - * verbatim in any distributions. No written agreement, license, - * or royalty fee is required for any of the authorized - * uses. Modifications to this software may be copyrighted by - * their authors and need not follow the licensing terms - * described here, provided that the new terms are clearly - * indicated on the first page of each file where they apply. - * - * - * IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE - * SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, - * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF - * THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, - * EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. APPLE, THE AUTHORS AND - * DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS - * SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE - * AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE - * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * GOVERNMENT USE: If you are acquiring this software on behalf - * of the U.S. government, the Government shall have only - * "Restricted Rights" in the software and related documentation - * as defined in the Federal Acquisition Regulations (FARs) in - * Clause 52.227.19 (c) (2). If you are acquiring the software - * on behalf of the Department of Defense, the software shall be - * classified as "Commercial Computer Software" and the - * Government shall have only "Restricted Rights" as defined in - * Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the - * foregoing, the authors grant the U.S. Government and others - * acting in its behalf permission to use and distribute the - * software in accordance with the terms specified in this - * license. - */ - -#ifndef TK_MAC_UTIL_H -#define TK_MAC_UTIL_H - -#include <Carbon/Carbon.h> - -OSErr FSpPathFromLocation(FSSpec *spec, int *length, Handle *fullPath); -OSErr FSpLocationFromPath(int length, const char *path, FSSpecPtr fileSpecPtr); -OSErr FSpGetDirectoryID(const FSSpec *spec, long *theDirID, Boolean *isDirectory); - -#endif diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 7264f19..bad9c47 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXWm.c,v 1.6 2003/02/09 07:51:04 hobbs Exp $ + * RCS: @(#) $Id: tkMacOSXWm.c,v 1.7 2003/02/25 16:09:29 das Exp $ */ #include <Carbon/Carbon.h> @@ -23,7 +23,6 @@ #include "tkScrollbar.h" #include "tkMacOSXWm.h" #include "tkMacOSXEvent.h" -#include "tkMacOSXUtil.h" /* * This is a list of all of the toplevels that have been mapped so far. It is |