Beispiel #1
0
pascal OSErr MoreFEGetCommentCFString(const FSRefPtr pFSRefPtr, CFStringRef* pCommentStr,const AEIdleUPP pIdleProcUPP)
{
  AppleEvent tAppleEvent = {typeNull,NULL};  //  If you always init AEDescs, it's always safe to dispose of them.
  AEDesc tAEDesc = {typeNull,NULL};
  OSErr anErr = noErr;

  if (NULL == pIdleProcUPP)  // the idle proc is required
    return paramErr;


  anErr = MoreAEOCreateObjSpecifierFromFSRef(pFSRefPtr,&tAEDesc);

  if (noErr == anErr)
  {
    AEBuildError  tAEBuildError;

    anErr = AEBuildAppleEvent(
              kAECoreSuite,kAEGetData,
          typeApplSignature,&gFinderSignature,sizeof(OSType),
              kAutoGenerateReturnID,kAnyTransactionID,
              &tAppleEvent,&tAEBuildError,
              "'----':obj {form:prop,want:type(prop),seld:type(comt),from:(@)}",&tAEDesc);

        // always dispose of AEDescs when you are finished with them
        (void) MoreAEDisposeDesc(&tAEDesc);

    if (noErr == anErr)
    {
#if 0  // Set this true to printf the Apple Event before you send it.
      Handle strHdl;
      anErr = AEPrintDescToHandle(&tAppleEvent,&strHdl);
      if (noErr == anErr)
      {
        char  nul  = '\0';
        PtrAndHand(&nul,strHdl,1);
        printf("\n-MoreFEGetCommentCFString: tAppleEvent=%s.",*strHdl); fflush(stdout);
        DisposeHandle(strHdl);
      }
#endif
      //  Send the event.
      anErr = MoreAESendEventReturnAEDesc(pIdleProcUPP,&tAppleEvent,typeUnicodeText,&tAEDesc);
      // always dispose of AEDescs when you are finished with them
      (void) MoreAEDisposeDesc(&tAppleEvent);
      if (noErr == anErr)
      {
        anErr = MoreAEGetCFStringFromDescriptor(&tAEDesc,pCommentStr);
        // always dispose of AEDescs when you are finished with them
        (void) MoreAEDisposeDesc(&tAEDesc);
      }
    }
  }
  return anErr;
}  // end MoreFEGetCommentCFString
Beispiel #2
0
pascal OSErr MoreFEGetComment(const FSRef *pFSRefPtr, const FSSpecPtr pFSSpecPtr,Str255 pCommentStr,const AEIdleUPP pIdleProcUPP)
{
  AppleEvent tAppleEvent = {typeNull,NULL};  //  If you always init AEDescs, it's always safe to dispose of them.
  AEDesc tAEDesc = {typeNull,NULL};
  OSErr anErr = noErr;

  if (NULL == pIdleProcUPP)  // the idle proc is required
  {
	fprintf(stderr, "No proc pointer\n");
    return paramErr;
  }
  anErr = MoreAEOCreateObjSpecifierFromFSRef(pFSRefPtr,&tAEDesc);
  if (anErr)
  {
	fprintf(stderr, "Error creating objspecifier from fsspec\n");
    return paramErr;
  }
  if (noErr == anErr)
  {
    AEBuildError  tAEBuildError;

    anErr = AEBuildAppleEvent(
              kAECoreSuite,kAEGetData,
          typeApplSignature,&gFinderSignature,sizeof(OSType),
              kAutoGenerateReturnID,kAnyTransactionID,
              &tAppleEvent,&tAEBuildError,
              "'----':obj {form:prop,want:type(prop),seld:type(comt),from:(@)}",&tAEDesc);

        // always dispose of AEDescs when you are finished with them
        (void) MoreAEDisposeDesc(&tAEDesc);

    if (noErr == anErr)
    {
      //  Send the event.
      anErr = MoreAESendEventReturnPString(pIdleProcUPP,&tAppleEvent,pCommentStr);
	  if (anErr)
	  {
		fprintf(stderr, "Error sending event to get pascal string\n");
	  }
      // always dispose of AEDescs when you are finished with them
      (void) MoreAEDisposeDesc(&tAppleEvent);
    }
	else
	{
		fprintf(stderr, "Error building Apple Event\n");
	}
  }
  return anErr;
}  // end MoreFEGetComment
Beispiel #3
0
pascal OSStatus MoreAESendEventReturnData(const AEIdleUPP pIdleProcUPP, const AppleEvent *pAppleEvent, DescType pDesiredType, DescType *pActualType, void *pDataPtr, Size pMaximumSize, Size *pActualSize) {
	OSStatus anError = noErr;

	// No idle function is an error, since we are expected to return a value
	if (pIdleProcUPP == NULL)
		anError = paramErr;
	else {
		AppleEvent theReply = {
			typeNull, NULL
		};
		AESendMode sendMode = kAEWaitReply;

		anError = AESend(pAppleEvent, &theReply, sendMode, kAENormalPriority, kNoTimeOut, pIdleProcUPP, NULL);
		// [ Don't dispose of the event, it's not ours ]
		if (noErr == anError) {
			anError = MoreAEGetHandlerError(&theReply);

			if (!anError && theReply.descriptorType != typeNull) {
				anError = AEGetParamPtr(&theReply, keyDirectObject, pDesiredType,
				                        pActualType, pDataPtr, pMaximumSize, pActualSize);
			}
			MoreAEDisposeDesc(&theReply);
		}
	}
	return anError;
}
Beispiel #4
0
pascal OSErr MoreFESetComment(const FSSpecPtr pFSSpecPtr, const Str255 pCommentStr, const AEIdleUPP pIdleProcUPP){
	AppleEvent tAppleEvent = {
		typeNull, nil
	};                                              // If you always init AEDescs, it's always safe to dispose of them.
	AEBuildError tAEBuildError;
	AEDesc tAEDesc = {
		typeNull, nil
	};
	OSErr anErr = noErr;

	anErr = MoreAEOCreateObjSpecifierFromFSSpec(pFSSpecPtr, &tAEDesc);
	if (noErr == anErr) {
		char *dataPtr = NewPtr(pCommentStr[ 0 ]);

		CopyPascalStringToC(pCommentStr, dataPtr);
		anErr = AEBuildAppleEvent(
		        kAECoreSuite, kAESetData,
		        typeApplSignature, &gFinderSignature, sizeof( OSType ),
		        kAutoGenerateReturnID, kAnyTransactionID,
		        &tAppleEvent, &tAEBuildError,
		        "'----':obj {form:prop,want:type(prop),seld:type(comt),from:(@)},data:'TEXT'(@)",
		        &tAEDesc, dataPtr);

		DisposePtr(dataPtr);

		if (noErr == anErr) {
			// Send the event. In this case we don't care about the reply
			anErr = MoreAESendEventNoReturnValue(pIdleProcUPP, &tAppleEvent);
			(void) MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them
		}
	}
	return anErr;
}
Beispiel #5
0
pascal OSErr MoreAEGetCFStringFromDescriptor(const AEDesc* pAEDesc, CFStringRef* pCFStringRef)
{
  AEDesc    uniAEDesc = {typeNull, NULL};
  OSErr    anErr;

  if (NULL == pCFStringRef)
    return paramErr;

  anErr = AECoerceDesc(pAEDesc, typeUnicodeText, &uniAEDesc);
  if (noErr == anErr)
  {
    if (typeUnicodeText == uniAEDesc.descriptorType)
    {
          Size bufSize = AEGetDescDataSize(&uniAEDesc);
          Ptr buf = NewPtr(bufSize);

          if ((noErr == (anErr = MemError())) && (NULL != buf))
          {
              anErr = AEGetDescData(&uniAEDesc, buf, bufSize);
              if (noErr == anErr)
                  *pCFStringRef = CFStringCreateWithCharacters(kCFAllocatorDefault, (UniChar*) buf, bufSize / (Size) sizeof(UniChar));

              DisposePtr(buf);
          }
    }
    MoreAEDisposeDesc(&uniAEDesc);
  }
  return (anErr);
}//end MoreAEGetCFStringFromDescriptor
Beispiel #6
0
/********************************************************************************
	Given selection type, create an new object descriptor for a selection,
	contained by containerObj.
	
	pSelectionAEDesc	input:	Selection type to use for object.
	pContainerAEDesc	input:	Pointer to container object for object being created.
	pSelectionObject		input:	Pointer to null AEDesc.
						output:	A property object.
	
	RESULT CODES
	____________
	noErr				    0	No error	
	paramErr			  -50	Error in parameter list
	memFullErr			 -108	Not enough room in heap zone	
	errAECoercionFail 	-1700	Data could not be coerced to the requested 
								Apple event data type	
	errAEWrongDataType	-1703	Wrong Apple event data type	
	errAENotAEDesc		-1704	Not a valid descriptor record	
	errAEBadListItem	-1705	Operation involving a list item failed	
*/
pascal	OSErr	MoreAEOCreateSelectionObject( const DescType pSelectionAEDesc,
											  AEDesc *pContainerAEDesc,
											  AEDesc *pSelectionObject )
{
	OSErr	anErr = noErr;
	
	AEDesc	selectionDesc = {typeNull,NULL};
	
	anErr = AECreateDesc( typeAbsoluteOrdinal, &pSelectionAEDesc, sizeof( pSelectionAEDesc ), &selectionDesc );
	if ( noErr == anErr )
	{
		anErr = CreateObjSpecifier( cObject, pContainerAEDesc, formAbsolutePosition,
									&selectionDesc, false, pSelectionObject );
		MoreAEDisposeDesc( &selectionDesc );
	}			
	return anErr;
}//end MoreAEOCreateSelectionObject
Beispiel #7
0
/********************************************************************************
	Given a ProcessSerialNumber, create an new object descriptor for the PSN,
	contained by containerObj.
	
	pPSN			input:	ProcessSerialNumber to use for object.
	pContainerAEDesc	input:	Pointer to container object for object being created.
	pPSNObjDesc		input:	Pointer to null AEDesc.
					output:	A ProcessSerialNumber object.
	
	RESULT CODES
	____________
	noErr				    0	No error	
	paramErr			  -50	Error in parameter list
	memFullErr			 -108	Not enough room in heap zone	
	errAECoercionFail 	-1700	Data could not be coerced to the requested 
								Apple event data type	
	errAEWrongDataType	-1703	Wrong Apple event data type	
	errAENotAEDesc		-1704	Not a valid descriptor record	
	errAEBadListItem	-1705	Operation involving a list item failed	
*/
pascal	OSErr	MoreAEOCreateProcessObject( const ProcessSerialNumber *pPSN,
											AEDesc *pContainerAEDesc,
											AEDesc *pPSNObjDesc )
{
	OSErr	anErr = noErr;
	AEDesc	psnDesc;
	
	anErr = AECreateDesc( typeProcessSerialNumber, pPSN, sizeof( ProcessSerialNumber ), &psnDesc );
	if ( noErr == anErr )
	{
		anErr = CreateObjSpecifier( cProperty, pContainerAEDesc, formPropertyID,
									&psnDesc, false, pPSNObjDesc );
		MoreAEDisposeDesc( &psnDesc );
	}
	
	return anErr;
}//end MoreAEOCreateProcessObject
Beispiel #8
0
/********************************************************************************
	Given a property type, create an new object descriptor for that property,
	contained by containerObj.
	
	pPropertyType		input:	Property type to use for object.
	pContainerAEDesc	input:	Pointer to container object for object being created.
	propertyObjPtr	input:	Pointer to null AEDesc.
					output:	A property object.
	
	RESULT CODES
	____________
	noErr				    0	No error	
	paramErr			  -50	Error in parameter list
	memFullErr			 -108	Not enough room in heap zone	
	errAECoercionFail 	-1700	Data could not be coerced to the requested 
								Apple event data type	
	errAEWrongDataType	-1703	Wrong Apple event data type	
	errAENotAEDesc		-1704	Not a valid descriptor record	
	errAEBadListItem	-1705	Operation involving a list item failed	
*/
pascal	OSErr	MoreAEOCreatePropertyObject( const DescType pPropertyType,
											 AEDesc *pContainerAEDesc,
											 AEDesc *propertyObjPtr )
{
	OSErr	anErr = noErr;
	AEDesc	propDesc;
	
	anErr = AECreateDesc( typeType, &pPropertyType, sizeof( pPropertyType ), &propDesc );
	if ( noErr == anErr )
	{
		anErr = CreateObjSpecifier( cProperty, pContainerAEDesc, formPropertyID,
									&propDesc, false, propertyObjPtr );
		MoreAEDisposeDesc( &propDesc );
	}
	
	return anErr;
}//end MoreAEOCreatePropertyObject
Beispiel #9
0
/********************************************************************************
	Given an AliasHandle, return an object descriptor containing an alias,
	contained by containerObj.
	
	pAliasHdl		input:	Handle to an alias record.
	pContainerAEDesc	input:	Pointer to container object for object being created.
	pAliasObjectAEDesc	input:	Pointer to null AEDesc.
					output:	an alias object.
	
	RESULT CODES
	____________
	noErr				    0	No error	
	paramErr			  -50	Error in parameter list
	memFullErr			 -108	Not enough room in heap zone	
	errAECoercionFail 	-1700	Data could not be coerced to the requested 
								Apple event data type	
	errAEWrongDataType	-1703	Wrong Apple event data type	
	errAENotAEDesc		-1704	Not a valid descriptor record	
	errAEBadListItem	-1705	Operation involving a list item failed	
*/
pascal	OSErr	MoreAEOCreateAliasObject( const AliasHandle pAliasHdl,
										  AEDesc *pContainerAEDesc,
										  AEDesc *pAliasObjectAEDesc )
{
	OSErr	anErr = noErr;
	AEDesc	aliasDesc;

	anErr = MoreAEOCreateAliasDesc( pAliasHdl, &aliasDesc );
	if ( noErr == anErr )
	{
		anErr = CreateObjSpecifier( typeAlias, pContainerAEDesc, formAbsolutePosition,
									&aliasDesc, false, pAliasObjectAEDesc );
		MoreAEDisposeDesc( &aliasDesc );
	}
	
	return anErr;
}//end MoreAEOCreateAliasObject
Beispiel #10
0
/********************************************************************************
	Given an FSRef, return an object descriptor containing an alias,
	contained by containerObj.
	
	pFSRef				input:	Pointer to the FSRef to use.
	pContainerAEDesc	input:	Pointer to container object for object being created.
	pAliasObjectAEDesc		input:	Pointer to null AEDesc.
						output:	an alias object.
	
	RESULT CODES
	____________
	noErr				    0	No error	
	paramErr			  -50	The value of target or alias parameter, or of
								both, is NIL, or the alias record is corrupt
	memFullErr			 -108	Not enough room in heap zone	
	errAECoercionFail 	-1700	Data could not be coerced to the requested 
								Apple event data type	
	errAEWrongDataType	-1703	Wrong Apple event data type	
	errAENotAEDesc		-1704	Not a valid descriptor record	
	errAEBadListItem	-1705	Operation involving a list item failed	
*/
pascal	OSErr	MoreAEOCreateAliasObjectFromFSRef( const FSRefPtr pFSRef,
													AEDesc *pContainerAEDesc,
													AEDesc *pAliasObjectAEDesc )
{
	OSErr		anErr = noErr;
	AEDesc		aliasDesc = {typeNull,NULL};

	anErr = MoreAEOCreateAliasDescFromFSRef( pFSRef, &aliasDesc );
	if ( noErr == anErr )
	{
		anErr = CreateObjSpecifier( typeAlias, pContainerAEDesc, formAbsolutePosition,
									&aliasDesc, false, pAliasObjectAEDesc );
		MoreAEDisposeDesc( &aliasDesc );
	}
	
	return anErr;
}//end MoreAEOCreateAliasObjectFromFSRef
Beispiel #11
0
pascal	OSErr	MoreAESendEventNoReturnValue (const AEIdleUPP pIdleProcUPP, const AppleEvent* pAppleEvent )
{
	OSErr		anErr = noErr;
	AppleEvent	theReply = {typeNull,nil};
	AESendMode	sendMode;

	if (nil == pIdleProcUPP)
		sendMode = kAENoReply;
	else
		sendMode = kAEWaitReply;

	anErr = AESend( pAppleEvent, &theReply, sendMode, kAENormalPriority, kNoTimeOut, pIdleProcUPP, nil );
	if ((noErr == anErr) && (kAEWaitReply == sendMode))
		anErr = MoreAEGetHandlerError(&theReply);

	MoreAEDisposeDesc( &theReply );
	
	return anErr;
}
Beispiel #12
0
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef, AEDesc *pObjSpecifier){
	OSErr anErr = paramErr;

	if (nil != pCFURLRef) {
		Boolean isDirectory = CFURLHasDirectoryPath(pCFURLRef);
		CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef, kCFURLHFSPathStyle);
		AEDesc containerDesc = {
			typeNull, NULL
		};
		AEDesc nameDesc = {
			typeNull, NULL
		};
		UniCharPtr buf = nil;

		if (nil != tCFStringRef) {
			Size bufSize = ( CFStringGetLength(tCFStringRef) + ( isDirectory ? 1 : 0 ) ) * sizeof( UniChar );

			buf = (UniCharPtr) NewPtr(bufSize);

			if ( ( anErr = MemError() ) == noErr) {
				CFStringGetCharacters(tCFStringRef, CFRangeMake(0, bufSize / 2), buf);
				if (isDirectory) ( buf )[ ( bufSize - 1 ) / 2 ] = (UniChar) 0x003A;
			}
		} else
			anErr = coreFoundationUnknownErr;

		if (anErr == noErr)
			anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize( (Ptr) buf), &nameDesc);
		if (anErr == noErr)
			if (isDirectory) {
				anErr = CreateObjSpecifier(cFolder, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
			} else {
				anErr = CreateObjSpecifier(cFile, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
			}

		MoreAEDisposeDesc(&nameDesc);

		if (buf)
			DisposePtr( (Ptr) buf);
	}
	return anErr;
}
Beispiel #13
0
//********************************************************************************
// A simple wrapper around CreateObjSpecifier which creates
// an object specifier using formName and the name in pKeyData.
pascal OSStatus MoreAEOCreateObjSpecifierFormName(DescType pDesiredClass, const AEDesc *pContainer, 
											ConstStr255Param pKeyData, Boolean pDisposeInputs, 
											AEDesc *pObjSpecifier)
{
	OSStatus anErr;
	AEDesc   keyDesc;

	assert(pContainer != NULL);
	assert(pKeyData != NULL);
	assert(pObjSpecifier != NULL);
	
	MoreAENullDesc(&keyDesc);
	
	anErr = AECreateDesc(typeText, &pKeyData[1], pKeyData[0], &keyDesc);
	if (noErr == anErr) {
		anErr = CreateObjSpecifier(pDesiredClass, (AEDesc *) pContainer, formName, &keyDesc, pDisposeInputs, pObjSpecifier);
	}
	MoreAEDisposeDesc(&keyDesc);
	return anErr;
}//end MoreAEOCreateObjSpecifierFormName
Beispiel #14
0
//********************************************************************************
// A simple wrapper around CreateObjSpecifier which creates
// an object specifier using formAbsolutePosition, a key of
// typeLongInteger (rather than typeAbsoluteOrdinal) and the
// position index in pKeyData.
pascal OSStatus MoreAEOCreateObjSpecifierFormAbsPos(DescType pDesiredClass, const AEDesc *pContainer, 
											SInt32 pKeyData, SInt32 pDisposeInputs, 
											AEDesc *pObjSpecifier)
{
	OSStatus anErr;
	AEDesc   keyDesc;

	assert(pContainer != NULL);
	assert(pObjSpecifier != NULL);

	MoreAENullDesc(&keyDesc);
	
	anErr = AECreateDesc(typeLongInteger, &pKeyData, sizeof(SInt32), &keyDesc);
	if (noErr == anErr) {
		anErr = CreateObjSpecifier(pDesiredClass, (AEDesc *) pContainer, formAbsolutePosition, &keyDesc, pDisposeInputs, pObjSpecifier);
	}
	
	MoreAEDisposeDesc(&keyDesc);
	
	return anErr;
}//end MoreAEOCreateObjSpecifierFormAbsPos
Beispiel #15
0
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef,AEDesc *pObjSpecifier)
{
	OSErr 		anErr = paramErr;

	if (NULL != pCFURLRef)
	{
		CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef,kCFURLHFSPathStyle);

		anErr = coreFoundationUnknownErr;
		if (NULL != tCFStringRef)
		{
			Boolean 		isDirectory = CFURLHasDirectoryPath(pCFURLRef);
			AEDesc 			containerDesc = {typeNull, NULL};
			AEDesc 			nameDesc = {typeNull, NULL};
				Size			bufSize = (CFStringGetLength(tCFStringRef) + (isDirectory ? 1 : 0)) * sizeof(UniChar);
				UniCharPtr		buf = (UniCharPtr) NewPtr(bufSize);

				if ((anErr = MemError()) == noErr)
				{
					CFStringGetCharacters(tCFStringRef, CFRangeMake(0,bufSize/2), buf);
					if (isDirectory) (buf)[(bufSize-1)/2] = (UniChar) 0x003A;				
				}
			
			if (anErr == noErr)
				anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize((Ptr) buf), &nameDesc);
			if (anErr == noErr)
				{
					if (isDirectory)	// we use cObject here since this might be a package (and we have no way to tell)
						anErr = CreateObjSpecifier(cObject, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
					else
						anErr = CreateObjSpecifier(cFile, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
				}
			MoreAEDisposeDesc(&nameDesc);

			if (buf)
				DisposePtr((Ptr)buf);
		}
	}
	return anErr;
}//end MoreAEOCreateObjSpecifierFromCFURLRef