Пример #1
0
short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply))
{
    AEDescList docList;
    AEKeyword keywd;
    DescType returnedType;
    Size actualSize;
    long itemsInList;
    OSErr err;
    short i;
    err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
    if (err != noErr)
        return err;

    err = AECountItems(&docList, &itemsInList);
    if (err != noErr)
        return err;

    ProcessSerialNumber PSN ;
    PSN.highLongOfPSN = 0 ;
    PSN.lowLongOfPSN = kCurrentProcess ;
    SetFrontProcess( &PSN ) ;

    for (i = 1; i <= itemsInList; i++) {
        wxString fName ;

        FSRef theRef ;
        AEGetNthPtr(&docList, i, typeFSRef, &keywd, &returnedType,
        (Ptr) & theRef, sizeof(theRef), &actualSize);
        fName = wxMacFSRefToPath( &theRef ) ;

        MacPrintFile(fName);
    }
    return noErr;
}
Пример #2
0
AliasHandle	ChooseFile()
{
	NavReplyRecord reply;
	
	OSStatus err = NavChooseFile(NULL, &reply, NULL, NULL, NULL, NULL, NULL, NULL);
	if (err == noErr && reply.validRecord) {
		long count;
		err = AECountItems(&(reply.selection), &count);
		if (err == noErr)
		{
			AEKeyword   theKeyword;
			DescType    actualType;
			Size        actualSize;
			FSSpec		fspec;
				
			// Get a pointer to selected file
			err = AEGetNthPtr(&(reply.selection), 1,
								typeFSS, &theKeyword,
								&actualType, &fspec,
								sizeof(FSSpec),
								&actualSize);
			if (err == noErr) {
				AliasHandle ah;
				RequireNoErrString(NewAlias(NULL, &fspec, &ah), "NewAlias failed");
				return ah;
			}
		}
	}
	return NULL;
}
Пример #3
0
/*----------------------------------------------------------------------------
	HandleCount 
	
----------------------------------------------------------------------------*/
void AEGenericClass::HandleCount(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
{
	ConstAETokenDesc	tokenDesc(token);
	long 			numberOfObjects = 0;
	DescType		objectClass;
	OSErr		err = noErr;	

	if (!reply->dataHandle)
		return;
	
	// Get the class of object that we will count
	err = GetObjectClassFromAppleEvent(appleEvent, &objectClass);
	ThrowIfOSErr(err);
	
	err = CheckForUnusedParameters(appleEvent);
	ThrowIfOSErr(err);

	if (AEListUtils::TokenContainsTokenList(token))
	{
		err = AECountItems(token, &numberOfObjects);
		ThrowIfOSErr(err);
		
	}
	else
	{
		CountObjects(objectClass, tokenDesc.GetDispatchClass(), token, &numberOfObjects);
	}

	err = AEPutParamPtr(reply, keyAEResult, 
								 typeLongInteger, 
								 (Ptr)&numberOfObjects, 
								 sizeof(long));
	ThrowIfOSErr(err);
}
Пример #4
0
short AELoadCart(AppleEvent* aev, AppleEvent* reply, long refCon)
{
short err;
FSSpec cart;
AEDescList docList;
AEKeyword keyWd;
DescType typ;
long items,siz;

	err = AEGetParamDesc(aev,keyDirectObject,typeAEList,&docList);
	if(err==0) {
		err = AECountItems(&docList,&items);
		for(short i=1;i<=items;i++) {
			err = AEGetNthPtr(&docList,i,typeFSS,&keyWd,&typ,(Ptr)&cart,sizeof(FSSpec),&siz);
			if(err==0) {
				if(CheckFileType(&cart,'Cart')) {
					LoadCartridgeFile(&cart);
					AEDisposeDesc(&docList);
					return 0;
				}
			}
		}
		AEDisposeDesc(&docList);
	}
	
	return err;
}
Пример #5
0
pascal OSErr AEOpenFiles(AppleEvent *theAppleEvent, AppleEvent *theReply,
                         long Refcon)
{
    AEDescList docList;
    AEKeyword keywd;
    DescType returnedType;
    Size actualSize;
    long itemsInList;
    FSSpec theSpec;
    CInfoPBRec pb;
    Str255 name;
    short i;
    
    if (AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList) !=
        noErr) return;
    if (AECountItems (&docList, &itemsInList) != noErr) return;
    
    SetSelection (TEXTREC->teLength, TEXTREC->teLength);
    for (i = 1; i <= itemsInList; i++) {
        AEGetNthPtr (&docList, i, typeFSS, &keywd, &returnedType, 
            (Ptr) &theSpec, sizeof(theSpec), &actualSize);
        
        GetFullPath(&theSpec, name);
        P2CStr(name); // was: pstrterm(name);
        if (xlload ((char *)name + 1, 1, 0) == 0) xlabort ("load error");
    }
    macputs ("> ");
    PrepareForInput ();
}
Пример #6
0
static	OSStatus	OpenDocuments( AEDescList docList )
{
	long				index;
	FSRef				fsRef;
	long				count			= 0;
	OSStatus			status			= AECountItems( &docList, &count );
	require_noerr( status, CantGetCount );

	for( index = 1; index <= count; index++ )
	{
		if ( (status = AEGetNthPtr( &docList, index, typeFSRef, NULL, NULL, &fsRef, sizeof(FSRef), NULL) ) == noErr )
		{
				/* convert the FSRef into a Core Foundation URL */
			CFURLRef parentURLRef = CFURLCreateFromFSRef(NULL, &fsRef);
			if (NULL != parentURLRef)
			{
				GetMovieFromCFURLRef(&parentURLRef, &mCurrentMovie);
			}
		}
	}
	
CantGetName:
CantCreateWindow:
CantGetCount:
	return( status );
}
Пример #7
0
void	OpenFiles()
{
	NavReplyRecord		reply;
	OSErr				err;
	long				i, n;
	FSSpec				spec;
	AEKeyword			keyWd;
	DescType			typeCd;
	Size				actSz;
	NavDialogOptions	navDialogOptions;
	
	NavGetDefaultDialogOptions( &navDialogOptions );
	navDialogOptions.dialogOptionFlags	|= ( kNavDontResolveAliases + kNavSupportPackages );
	
	err	= NavChooseFile( NULL, &reply, &navDialogOptions, NULL, NULL, NULL, NULL, NULL );
	if ( err != noErr )	goto Bail;
	if ( !reply.validRecord ) { err = userCanceledErr; goto Bail; }

	err = AECountItems( &reply.selection, &n );
	if ( err != noErr )	goto Bail;

	for ( i = 1 ; i <= n; i++ )
	{
		err = AEGetNthPtr( &reply.selection, i, typeFSS, &keyWd, &typeCd, (Ptr) &spec, sizeof(spec), (actSz = sizeof(spec), &actSz) );
		if ( err != noErr ) goto Bail;
		
		//XXX	Do Something with spec
		SysBeep( 0 );
	}

Bail:
	return;
}
Пример #8
0
/*----------------------------------------------------------------------------
	GetDataFromList 

	
----------------------------------------------------------------------------*/
void AEGenericClass::GetDataFromList(const AEDesc *srcList, AEDesc *desiredTypes, AEDesc *dstList)
{
	OSErr		err;
	long			itemNum;
	long			numItems;
	DescType		keyword;
	StAEDesc		srcItem;
	StAEDesc		dstItem;
		
	err = AECountItems((AEDescList*)srcList, &numItems);
	ThrowIfOSErr(err);
		
	for (itemNum = 1; itemNum <= numItems; itemNum++)
	{
		err = AEGetNthDesc(srcList, itemNum, typeWildCard, &keyword, &srcItem);
		ThrowIfOSErr(err);
		
		if (AEListUtils::TokenContainsTokenList(&srcItem) == false)
		{
			GetDataFromObject(&srcItem, desiredTypes, &dstItem);  // Get data from single item
		}
		else
		{
			ThrowIfOSErr(AECreateList(nil, 0, false, &dstItem));
			GetDataFromList(&srcItem, desiredTypes, &dstItem);
		}
		err = AEPutDesc(dstList, itemNum, &dstItem);
		ThrowIfOSErr(err);
	}
}
Пример #9
0
/*----------------------------------------------------------------------------
	SetDataForList 

	Given a token that contains a list of cWindow tokens,
	walk the list recursively to set the data for each token in the list
	
----------------------------------------------------------------------------*/
void AEGenericClass::SetDataForList(const AEDesc *token, AEDesc *data)
{
	OSErr 			err;
		
	if (AEListUtils::TokenContainsTokenList(token) == false)
	{
		SetDataForObject(token, data);
	}
	else
	{
		long			numItems;
		long			itemNum;
		err = AECountItems((AEDescList*)token, &numItems);
		ThrowIfOSErr(err);
		
		for (itemNum = 1; itemNum <= numItems; itemNum++)
		{
			StAEDesc	  	tempToken;
			AEKeyword	keyword;
			
		 	err = AEGetNthDesc((AEDescList*)token, itemNum, typeWildCard, &keyword, &tempToken);
			ThrowIfOSErr(err);
			
			if (AEListUtils::TokenContainsTokenList(&tempToken) == false)
			{
				SetDataForObject(&tempToken, data);  		// Set data from single item
			}
			else
			{
				SetDataForList(&tempToken, data); 	// Recurse sublist
			}
		}
	}
}
OSStatus	LLFilePicker::doNavChooseDialog(ELoadFilter filter)
{
	OSStatus		error = noErr;
	NavDialogRef	navRef = NULL;
	NavReplyRecord	navReply;

	// if local file browsing is turned off, return without opening dialog
	if ( check_local_file_access_enabled() == false )
	{
		return FALSE;
	}

	memset(&navReply, 0, sizeof(navReply));
	
	// NOTE: we are passing the address of a local variable here.  
	//   This is fine, because the object this call creates will exist for less than the lifetime of this function.
	//   (It is destroyed by NavDialogDispose() below.)
	error = NavCreateChooseFileDialog(&mNavOptions, NULL, NULL, NULL, navOpenFilterProc, (void*)(&filter), &navRef);

	gViewerWindow->getWindow()->beforeDialog();

	if (error == noErr)
		error = NavDialogRun(navRef);

	gViewerWindow->getWindow()->afterDialog();

	if (error == noErr)
		error = NavDialogGetReply(navRef, &navReply);

	if (navRef)
		NavDialogDispose(navRef);

	if (error == noErr && navReply.validRecord)
	{
		SInt32	count = 0;
		SInt32	index;
		
		// AE indexes are 1 based...
		error = AECountItems(&navReply.selection, &count);
		for (index = 1; index <= count; index++)
		{
			FSRef		fsRef;
			AEKeyword	theAEKeyword;
			DescType	typeCode;
			Size		actualSize = 0;
			char		path[MAX_PATH];	/*Flawfinder: ignore*/
			
			memset(&fsRef, 0, sizeof(fsRef));
			error = AEGetNthPtr(&navReply.selection, index, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize);
			
			if (error == noErr)
				error = FSRefMakePath(&fsRef, (UInt8*) path, sizeof(path));
			
			if (error == noErr)
				mFiles.push_back(std::string(path));
		}
	}
	
	return error;
}
Пример #11
0
static pascal OSErr OpenDocumentsAE( const AppleEvent * theAppleEvent,
	AppleEvent * reply, SInt32 handlerRefcon) {
    AEDescList  docList;
    FSRef       theFSRef;
    long        index;
    long        count = 0;
    OSErr       err;
    char	buffer[2048];

 fprintf( logfile, "OPEN event received.\n" ); fflush( logfile );
    if ( localsplash )
	start_splash_screen();

    err = AEGetParamDesc(theAppleEvent, keyDirectObject,
                         typeAEList, &docList);
    err = AECountItems(&docList, &count);
    for(index = 1; index <= count; index++) {
        err = AEGetNthPtr(&docList, index, typeFSRef,
                        NULL, NULL, &theFSRef,
                        sizeof(theFSRef), NULL);// 4
	err = FSRefMakePath(&theFSRef,(unsigned char *) buffer,sizeof(buffer));
	ViewPostScriptFont(buffer,0);
 fprintf( logfile, " file: %s\n", buffer );
    }
    system( "DYLD_LIBRARY_PATH=\"\"; osascript -e 'tell application \"X11\" to activate'" );
    AEDisposeDesc(&docList);
 fprintf( logfile, " event processed %d.\n", err ); fflush( logfile );

return( err );
}
Пример #12
0
/* This function extracts a single FSRef from a NavReplyRecord. */
static OSErr ExtractSingleItem(const NavReplyRecord *reply, FSRef *item)
{
    FSSpec fss;
    SInt32 itemCount;
    DescType junkType;
    AEKeyword junkKeyword;
    Size junkSize;
    OSErr osErr;

    osErr = AECountItems(&reply->selection, &itemCount);
    if( itemCount != 1 )	/* we only work with one object at a time */
        osErr = paramErr;
    if( osErr == noErr )
        osErr = AEGetNthPtr(&reply->selection, 1, typeFSS, &junkKeyword, &junkType, &fss, sizeof(fss), &junkSize);
    if( osErr == noErr )
    {
        mycheck(junkType == typeFSS);
        mycheck(junkSize == sizeof(FSSpec));

        /* We call FSMakeFSSpec because sometimes Nav is braindead		*/
        /* and gives us an invalid FSSpec (where the name is empty).	*/
        /* While FSpMakeFSRef seems to handle that (and the file system	*/
        /* engineers assure me that that will keep working (at least	*/
        /* on traditional Mac OS) because of the potential for breaking	*/
        /* existing applications), I'm still wary of doing this so		*/
        /* I regularise the FSSpec by feeding it through FSMakeFSSpec.	*/

        if( fss.name[0] == 0 )
            osErr = FSMakeFSSpec(fss.vRefNum, fss.parID, fss.name, &fss);
        if( osErr == noErr )
            osErr = FSpMakeFSRef(&fss, item);
    }

    return osErr;
}
Пример #13
0
OSErr IACdrivefilelist (tyFScallback handlespecroutine) {
	
	/*
	the opendoc and printdoc required events take a list of filespecs as a 
	parameter. we factor out the common code, and make it a little easier for an
	application to handle these events.
	
	you supply a callback routine that handles a single filespec, you could
	print it or open it, depending on which of the required events is being
	invoked.
	*/

	AEDesc desc;
	long ctfiles;
	DescType actualtype;
	long actualsize;
	AEKeyword actualkeyword;
	FSSpec fs;
	long i;
	OSErr ec;
						
	ec = AEGetKeyDesc (IACglobals.event, keyDirectObject, typeAEList, &desc);
	
	IACglobals.errorcode = ec;
	
	if (ec != noErr) 
		return (ec);
		
	ec = AECountItems (&desc, &ctfiles);
	
	IACglobals.errorcode = ec;
	
	if (ec != noErr) 
		return (ec);
				
	for (i = 1; i <= ctfiles; i ++) {
	
		ec = AEGetNthPtr (
			&desc, i, typeFSS, &actualkeyword, &actualtype, 
			
			(Ptr) &fs, sizeof (fs), &actualsize);
							
		IACglobals.errorcode = ec;
	
		if (ec != noErr) {
		
			AEDisposeDesc (&desc);
			
			return (ec);
			}
			
		if (!(*handlespecroutine) (&fs))
			return (-1);
		} /*for*/
		
	return (noErr);
	} /*IACdrivefilelist*/
Пример #14
0
CFMutableArrayRef CFMutableArrayCreatePOSIXPathsWithEvent(
								  const AppleEvent *ev, AEKeyword theKey, OSErr *errPtr)
{
	CFMutableArrayRef outArray = NULL;
	DescType typeCode;
	Size dataSize;
    AEDescList  aeList = {typeNull, NULL};
	
	*errPtr = AESizeOfParam(ev, theKey, &typeCode, &dataSize);
	if ((*errPtr != noErr) || (typeCode == typeNull)){
		goto bail;
	}
	
	*errPtr = AEGetParamDesc(ev, theKey, typeAEList, &aeList);
	if (*errPtr != noErr) goto bail;
	
    long count = 0;
	*errPtr = AECountItems(&aeList, &count);
	if (*errPtr != noErr) goto bail;
	
	outArray = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks);
	
	for(long index = 1; index <= count; index++) {
		void *value_ptr = NULL;
		Size data_size;
		*errPtr = AEGetNthPtr(&aeList, index, typeFileURL,
						  NULL, NULL, value_ptr,
						  0, &data_size);
		if (*errPtr == noErr) {
			value_ptr = malloc(data_size);
			*errPtr = AEGetNthPtr(&aeList, index, typeFileURL,
							  NULL, NULL, value_ptr,
							  data_size, NULL);
		}
		if (*errPtr != noErr) {
			fputs("Fail to AEGetNthPtr in CFMutableArrayCreatePOSIXPathsWithEvent", stderr);
			goto bail;
		}
		CFURLRef file_url = CFURLCreateAbsoluteURLWithBytes(
															NULL,
															(const UInt8 *)value_ptr,
															data_size,
															kCFStringEncodingUTF8,
															NULL,
															false);
		CFStringRef path = CFURLCopyFileSystemPath(file_url, kCFURLPOSIXPathStyle);
		CFArrayAppendValue(outArray, path);		
		CFRelease(file_url);
		CFRelease(path);
		free(value_ptr);
    }
bail:
	AEDisposeDesc(&aeList);
	return outArray;
}
Пример #15
0
/* Handle the kAEOpenDocuments Apple events. This will register
 * an idle source callback for each filename in the event.
 */
static pascal OSErr
gui_unique_mac_open_documents (const AppleEvent *inAppleEvent,
                               AppleEvent       *outAppleEvent,
                               long              handlerRefcon)
{
  OSStatus    status;
  AEDescList  documents;
  gchar       path[MAXPATHLEN];

  status = AEGetParamDesc (inAppleEvent,
                           keyDirectObject, typeAEList,
                           &documents);
  if (status == noErr)
    {
      long count = 0;
      int  i;

      AECountItems (&documents, &count);

      for (i = 0; i < count; i++)
        {
          FSRef    ref;
          gchar    *callback_path;
          GSource  *source;
          GClosure *closure;

          status = AEGetNthPtr (&documents, i + 1, typeFSRef,
                                0, 0, &ref, sizeof (ref),
                                0);
          if (status != noErr)
            continue;

          FSRefMakePath (&ref, (UInt8 *) path, MAXPATHLEN);

          callback_path = g_strdup (path);

          closure = g_cclosure_new (G_CALLBACK (gui_unique_mac_idle_open),
                                    (gpointer) callback_path,
                                    (GClosureNotify) g_free);

          g_object_watch_closure (G_OBJECT (unique_gimp), closure);

          source = g_idle_source_new ();
          g_source_set_priority (source, G_PRIORITY_LOW);
          g_source_set_closure (source, closure);
          g_source_attach (source, NULL);
          g_source_unref (source);
        }
    }

    return status;
}
Пример #16
0
static long
__rbosa_elementlist_count (AEDescList *list)
{
    OSErr   error;
    long    count;

    error = AECountItems (list, &count);
    if (error != noErr)
        rb_raise (rb_eRuntimeError, "Cannot count items : %s (%d)", 
                  error_code_to_string (error), error);

    return count;
}
Пример #17
0
static PyObject *BuildTerminologyList(AEDesc *theDesc, DescType requiredType) {
	AEDesc item;
	long size, i;
	AEKeyword key;
	PyObject *itemObj, *result;
	OSErr err;
	
	result = PyList_New(0);
	if (!result) return NULL;
	if (theDesc->descriptorType == typeAEList) {
		err = AECountItems(theDesc, &size);
		if (err) {
			Py_DECREF(result);
			return AE_MacOSError(err);
		}
		for (i = 1; i <= size; i++) {			
			err = AEGetNthDesc(theDesc, i, requiredType, &key, &item);
			if (!err) {
				itemObj = AE_AEDesc_New(&item);
				if (!itemObj) {
					AEDisposeDesc(&item);
					Py_DECREF(result);
					return NULL;
				}
				err = PyList_Append(result, itemObj);
				if (err) {
					Py_DECREF(itemObj);
					Py_DECREF(result);
					return NULL;
				}
			} else if (err != errAECoercionFail) {
				Py_DECREF(result);
				return AE_MacOSError(err);
			}
		}
	} else {
		itemObj = AE_AEDesc_New(theDesc);
		if (!itemObj) {
			AEDisposeDesc(theDesc);
			Py_DECREF(result);
			return NULL;
		}
		err = PyList_Append(result, itemObj);
		if (err) {
			Py_DECREF(itemObj);
			Py_DECREF(result);
			return NULL;
		}
	}
	return result;
}
Пример #18
0
pascal OSErr AEOpenFiles(const AppleEvent * theAppleEvent,
                         AppleEvent * theReply, long Refcon)
{
    AEDescList docList;
    AEKeyword keywd;
    DescType returnedType;
    Size actualSize;
    long itemsInList;
    FSSpec theSpec;
    CInfoPBRec pb;
    Handle nameh;
    short namelen;
    OSErr err;
    short i;

    err =
        AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList,
                       &docList);
    if (err != noErr)
        return err;

    err = AECountItems(&docList, &itemsInList);
    if (err != noErr)
        return err;

    for (i = 1; i <= itemsInList; i++) {
        AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
                    (Ptr) & theSpec, sizeof(theSpec), &actualSize);

        if (noErr == FSpGetFullPath(&theSpec, &namelen, &nameh)) {
            HLock(nameh);
            char *str = new char[namelen + 1];
            memcpy(str, (char *) *nameh, namelen);
            str[namelen] = 0;
            HUnlock(nameh);
            DisposeHandle(nameh);

            AudacityProject *project = GetActiveProject();

            if (project == NULL || !project->GetTracks()->IsEmpty()) {
                project = CreateNewAudacityProject(gParentWindow);
            }
            project->OpenFile(str);

            delete[]str;
        }
    }

    return noErr;
}
Пример #19
0
static PyObject *AEDesc_AECountItems(AEDescObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	long theCount;

	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_err = AECountItems(&_self->ob_itself,
	                    &theCount);
	if (_err != noErr) return AE_MacOSError(_err);
	_res = Py_BuildValue("l",
	                     theCount);
	return _res;
}
Пример #20
0
PASCAL_RTN OSErr QTApp_HandleOpenDocumentAppleEvent (const AppleEvent *theMessage, AppleEvent *theReply, long theRefcon)			
{
#pragma unused(theReply, theRefcon)

	long			myIndex;
	long			myItemsInList;
	AEKeyword		myKeyWd;
	AEDescList 	 	myDocList;
	long			myActualSize;
	DescType		myTypeCode;
	FSSpec			myFSSpec;
	OSErr			myIgnoreErr = noErr;
	OSErr			myErr = noErr;
	
	// get the direct parameter and put it into myDocList
	myDocList.dataHandle = NULL;
	myErr = AEGetParamDesc(theMessage, keyDirectObject, typeAEList, &myDocList);
	
	// count the descriptor records in the list
	if (myErr == noErr)
		myErr = AECountItems(&myDocList, &myItemsInList);
	else
		myItemsInList = 0;
	
	// open each specified file
	for (myIndex = 1; myIndex <= myItemsInList; myIndex++)
		if (myErr == noErr) {
			myErr = AEGetNthPtr(&myDocList, myIndex, typeFSS, &myKeyWd, &myTypeCode, (Ptr)&myFSSpec, sizeof(myFSSpec), &myActualSize);
			if (myErr == noErr) {
				FInfo		myFinderInfo;
			
				// verify that the file type is MovieFileType; to do this, get the Finder information
				myErr = FSpGetFInfo(&myFSSpec, &myFinderInfo);	
				if (myErr == noErr) {
					if (myFinderInfo.fdType == MovieFileType)
						// we've got a movie file; just open it
						QTFrame_OpenMovieInWindow(NULL, &myFSSpec);
				}
			}
		}

	if (myDocList.dataHandle)
		myIgnoreErr = AEDisposeDesc(&myDocList);
	
	// make sure we open the document in the foreground		
	gAppInForeground = true;
	return(myErr);
}
Пример #21
0
void ObjectTraverse(const AEDescList *object)
{
	static int recurse=0;
	long count;
	AEKeyword keyword;
	DescType data_desc;
	MacSize data_size;
	char buffer[1024];
	OSStatus err;
	if (noErr == AECountItems(object, &count))
	{
		for (int i = 1; i <= count; i++)	// AERecord starts at index 1
		{
			err = AESizeOfNthItem(object, i, &data_desc, &data_size);
			if (noErr == err)
			{
				err = AEGetNthPtr(object, i, data_desc, &keyword, &data_desc, buffer, 1024, &data_size);
				if (logfile)
				{
					long r;
					for (r = 0; r < recurse; r++)
						fprintf(logfile,"  ");

					fprintf(logfile,"key:'%c%c%c%c' desc:'%c%c%c%c' size: %ld", FCC_TO_CHARS(keyword), FCC_TO_CHARS(data_desc), data_size);
					if (err == noErr) {
						if (data_size == 4) {
							int val = *((int*) buffer);
							if ((data_desc == typeSInt32) || (data_desc == typeUInt32))
								fprintf(logfile," value: %d", val);
							if ((data_desc == typeSInt32) || (data_desc == typeUInt32))
								fprintf(logfile," value:'%c%c%c%c'", FCC_TO_CHARS(val));
						}
					}
					fprintf(logfile,"\r");
				}
				if ((err == noErr) && ((data_desc == cObjectSpecifier) || (data_desc == cAEList) || (data_desc == typeAERecord))) {
					AEDesc obj2;
					err = AEGetNthDesc(object, i, data_desc, &keyword, &obj2);
					if (err == noErr) {
						recurse++;
						ObjectTraverse(&obj2);
						recurse--;
					}
				}
			}
		}
	}
}
Пример #22
0
OSErr getFloatArray(const AppleEvent *ev, AEKeyword theKey,  CFMutableArrayRef *outArray)
{
	OSErr err;
	DescType typeCode;
	Size dataSize;
    AEDescList aeList = {typeNull, NULL};
	
	err = AESizeOfParam(ev, theKey, &typeCode, &dataSize);
	if ((err != noErr) || (typeCode == typeNull)){
		fputs("Failed to AESizeOfParam in getFloatArray", stderr);
		goto bail;
	}
	
	err = AEGetParamDesc(ev, theKey, typeAEList, &aeList);
	if (err != noErr) {
		fputs("Failed to AEGetParamDesc in getFloatArray", stderr);
		goto bail;
	}
    long count = 0;
	err = AECountItems(&aeList, &count);
	if (err != noErr) {
		fputs("Failed to AECountItems in getFloatArray", stderr);
		goto bail;
	}
	*outArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
	
    for(long index = 1; index <= count; index++) {
		float value;
		err = AEGetNthPtr(&aeList, index, typeIEEE32BitFloatingPoint,
						  NULL, NULL, &value,
						  sizeof(value), NULL);
		if (err != noErr) {
			fputs("Fail to AEGetNthPtr in getFloatArray", stderr);
			goto bail;
		}
		CFNumberRef cfnum = CFNumberCreate(NULL, kCFNumberFloat32Type, &value);
		CFArrayAppendValue(*outArray, cfnum);
		CFRelease(cfnum);
    }
bail:
	AEDisposeDesc(&aeList);
#if useLog
	CFShow(*outArray);
	fputs("end of getFloatArray", stderr);
#endif	
	return err;
}
Пример #23
0
static void
MyNavEventCallBack(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *callBackUD)
{
    #pragma unused(callBackUD)
    
    NavDialogRef dialog;
    NavReplyRecord reply;
    AEDescList selection;
    AEKeyword keyword;
    DescType type;
    FSRef folder;
    Size size;
    long count;
    OSStatus err;
        
    assert(callBackParms != NULL);
            
    if (callBackSelector == kNavCBUserAction) {
    
        dialog = callBackParms->context;
        
        switch (callBackParms->userAction) {
            case kNavUserActionChoose:
            
                err = NavDialogGetReply(dialog, &reply);
                assert(err == noErr);
                
                selection = reply.selection;
                err = AECountItems(&selection, &count);
                assert(err == noErr && count == 1);     // only one folder should be selected.
                
                err = AEGetNthPtr(&selection, 1, typeFSRef, &keyword, &type, &folder, sizeof(folder), &size);
                assert(err == noErr);
                
                NavDialogDispose(dialog);
                MyBurnFolder(folder);
                break;
                
            case kNavUserActionCancel:
               
                NavDialogDispose(dialog);
                DisposeNavEventUPP(gNavEventUPP); 
                QuitApplicationEventLoop();
                break;
        }
    }
}
Пример #24
0
static pascal OSErr handle_open_doc_ae(const AppleEvent *theAppleEvent, AppleEvent *reply, SRefCon handlerRefcon)
{
  AEDescList docList;
  long index;
  long count = 0;
  int i;
  char *myFileName;
  Size actualSize;
  DescType returnedType;
  AEKeyword keywd;
  FSRef theRef;

  VS("LOADER: handle_open_doc_ae called.\n");

  OSErr err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
  if (err != noErr) return err;

  err = AECountItems(&docList, &count);
  if (err != noErr) return err;
  for (index = 1; index <= count; index++)
  {
     err = AEGetNthPtr(&docList, index, typeFSRef, &keywd, &returnedType, &theRef, sizeof(theRef), &actualSize);

     CFURLRef fullURLRef;
     fullURLRef = CFURLCreateFromFSRef(NULL, &theRef);
     CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, kCFURLPOSIXPathStyle);
     CFRelease(fullURLRef);
     CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString);
     CFRelease(cfString);
     CFStringNormalize(cfMutableString, kCFStringNormalizationFormC);
     int len = CFStringGetLength(cfMutableString);
     const int bufferSize = (len+1)*6;  // in theory up to six bytes per Unicode code point, for UTF-8.
     char* buffer = (char*)malloc(bufferSize);
     CFStringGetCString(cfMutableString, buffer, bufferSize, kCFStringEncodingUTF8);

     argv_pyi = (char**)realloc(argv_pyi,(argc_pyi+2)*sizeof(char*));
     argv_pyi[argc_pyi++] = strdup(buffer);
     argv_pyi[argc_pyi] = NULL;

     free(buffer);
  }

  err = AEDisposeDesc(&docList);


  return (err);
}
Пример #25
0
// Counts how many files are in the apple event
short CountFiles(AppleEvent *message)
{
	AEDesc		fileListDesc;
	long		numFiles;
	OSErr		err;
	
	/* extract the list of aliases into fileListDesc */
	err = AEGetKeyDesc(message, keyDirectObject, typeAEList, &fileListDesc);
	if (err!=noErr)
		return 0;
		
	/* count the list elements */
	err = AECountItems(&fileListDesc, &numFiles);

	AEDisposeDesc(&fileListDesc);
	
	return	err ? 0 : numFiles; 
}
Пример #26
0
// Extracts all the files from a Finder print or open apple event and call the routine specified
// on each of them
OSErr ForEachFileDo(const AppleEvent *message,AEFileProc theirProc)
{
	OSErr		err = noErr;
	AEDesc		fileListDesc;
	long		numFiles;
	DescType	actualType;
	long		actualSize;
	AEKeyword	actualKeyword;
	FSSpec		oneFile;
	long		index;
							
	/* extract the list of aliases into fileListDesc */
	err = AEGetKeyDesc(message, keyDirectObject, typeAEList, &fileListDesc);
	if (err!=noErr)
		return err;
		
	/* count the list elements */
	err = AECountItems(&fileListDesc, &numFiles);
	if (err != noErr)
	{
		AEDisposeDesc(&fileListDesc);
		return err;
	}
	
	/* get each from list and process it */		
	for (index = 1; index <= numFiles; index ++)
	{
		err = AEGetNthPtr(&fileListDesc, index, typeFSS, &actualKeyword,
							&actualType, (Ptr)&oneFile, sizeof(oneFile), &actualSize);
		if (err != noErr)
		{
			AEDisposeDesc(&fileListDesc);
			return err;
		}
		
		/* oneFile contains FSSpec of file in question */
		err=theirProc(&oneFile);
		if (err)
			break;
	}
	
	AEDisposeDesc(&fileListDesc);
	return err;
}
Пример #27
0
OSErr GHOST_SystemCarbon::sAEHandlerOpenDocs(const AppleEvent *event, AppleEvent *reply, SInt32 refCon)
{
	//GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) refCon;
	AEDescList docs;
	SInt32 ndocs;
	OSErr err;

	err = AEGetParamDesc(event, keyDirectObject, typeAEList, &docs);
	if (err != noErr) return err;

	err = AECountItems(&docs, &ndocs);
	if (err == noErr) {
		int i;
	
		for (i = 0; i < ndocs; i++) {
			FSSpec fss;
			AEKeyword kwd;
			DescType actType;
			Size actSize;
		
			err = AEGetNthPtr(&docs, i + 1, typeFSS, &kwd, &actType, &fss, sizeof(fss), &actSize);
			if (err != noErr)
				break;
		
			if (i == 0) {
				FSRef fsref;
				
				if (FSpMakeFSRef(&fss, &fsref) != noErr)
					break;
				if (FSRefMakePath(&fsref, (UInt8 *) g_firstFileBuf, sizeof(g_firstFileBuf)) != noErr)
					break;

				g_hasFirstFile = true;
			}
		}
	}
	
	AEDisposeDesc(&docs);
	
	return err;
}
Пример #28
0
static pascal OSErr odocHandler(const AppleEvent* inEvent, AppleEvent*
                                /*reply*/, long refCon)
{
    AEDescList documentList;
    OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
                               &documentList);
    if (err == noErr) {
        err = checkAppleEventForMissingParams(*inEvent);

        if (err == noErr) {
            long documentCount;
            err = AECountItems(&documentList, &documentCount);

            for (long documentIndex = 1; err == noErr && documentIndex <=
                 documentCount; documentIndex++) {
                // What kind of document is it?
                DescType returnedType;
                Size actualSize;
                err = AESizeOfNthItem(&documentList, documentIndex, &returnedType,
                                      &actualSize);
                if (err == noErr) {

                    // It is just a normal document file
                    AEKeyword keyword;
                    FSRef ref;
                    err = AEGetNthPtr(&documentList, documentIndex, typeFSRef,
                                      &keyword, &returnedType, (Ptr)&ref, sizeof(FSRef), &actualSize);

                    if (err == noErr) {
                        char buf[1024];
                        err = FSRefMakePath(&ref, reinterpret_cast<UInt8*>(buf), 1024);
                        if ( err == noErr )
                            reinterpret_cast<mainForm*>(refCon)->fileOpen(QString::fromUtf8(buf));
                    }
                }
            }
        }
        AEDisposeDesc(&documentList);
    }
    return err;
}
Пример #29
0
static OSErr mac_openlist(AEDesc docs)
{
    OSErr err;
    long ndocs, i;
    FSSpec fss;
    AEKeyword keywd;
    DescType type;
    Size size;

    err = AECountItems(&docs, &ndocs);
    if (err != noErr) return err;

    for (i = 0; i < ndocs; i++) {
	err = AEGetNthPtr(&docs, i + 1, typeFSS,
			  &keywd, &type, &fss, sizeof(fss), &size);
	if (err != noErr) return err;;
	err = mac_opensessionfrom(&fss);
	if (err != noErr) return err;
    }
    return noErr;
}
Пример #30
0
/*----------------------------------------------------------------------------
	GetPropertyFromList 

----------------------------------------------------------------------------*/
void AEGenericClass::GetPropertyFromList(				DescType			desiredClass,
												const AEDesc*		containerToken,
												DescType			containerClass,
												DescType			keyForm,
												const AEDesc*		keyData,
												AEDesc*			resultToken)
{
	OSErr		err		= noErr;
	long			itemNum;
	long			numItems;
	DescType		keyword;
	
	err = AECountItems((AEDescList*)containerToken, &numItems);
	ThrowIfOSErr(err);
		
	for (itemNum = 1; itemNum <= numItems; itemNum++)
	{
		StAEDesc		srcItem;
		StAEDesc		dstItem;
		
		err = AEGetNthDesc(containerToken, itemNum, typeWildCard, &keyword, &srcItem);
		ThrowIfOSErr(err);
		
		if (AEListUtils::TokenContainsTokenList(&srcItem) == false)
		{
			GetPropertyFromObject(desiredClass, &srcItem, containerClass, keyForm, keyData, &dstItem);
		}
		else
		{
			err = AECreateList(nil, 0, false, &dstItem);
			ThrowIfOSErr(err);
			
			GetPropertyFromList(desiredClass, &srcItem, containerClass, keyForm, keyData, &dstItem);
		}

		err = AEPutDesc(resultToken, itemNum, &dstItem);
		ThrowIfOSErr(err);
	}
	
}