示例#1
0
void AECoreClass::ExtractData(const AEDesc *source, AEDesc *data)
{
	OSErr		err = noErr;
	StAEDesc		temp;
	DescType		dispatchClass;
		
	if ((source->descriptorType == typeNull) || (source->dataHandle == nil))
		ThrowIfOSErr(errAENoSuchObject);
	
	// If it's an object specifier, resolve into a token
	// Otherwise, just copy it
	
	if (source->descriptorType == typeObjectSpecifier) 
	{
		err = AEResolve(source, kAEIDoMinimum, &temp);
	}
	else
	{
		err = AEDuplicateDesc(source, &temp);
	}
	ThrowIfOSErr(err);
	
	// Next, determine which object should handle it, if any. 
	// If it's a property token, get the dispatch class. 
	// Otherwise, just get the descriptorType. 
	
	if (temp.descriptorType == typeProperty)
	{
		ConstAETokenDesc	tokenDesc(&temp);
		dispatchClass = tokenDesc.GetDispatchClass();
	}
	else
		dispatchClass = temp.descriptorType;
	
	// If it's a property token, get the data it refers to,
	// otherwise duplicate it and return
		
	AEDispatchHandler*	handler = GetDispatchHandler(dispatchClass);
	if (handler)
	{
		/*
		case cApplication:
			// why?
			ThrowIfOSErr(errAEEventNotHandled);
			break;
		*/
		handler->GetDataFromListOrObject(&temp, nil, data);
	}
	else
	{
		err = AEDuplicateDesc(&temp, data);
		ThrowIfOSErr(err);
	}
}
示例#2
0
/*----------------------------------------------------------------------------
	GetPropertyFromObject 

----------------------------------------------------------------------------*/
void AEGenericClass::GetPropertyFromObject(			DescType			desiredType,
						  					const AEDesc*		containerToken,
								  			DescType			containerClass,
								  			DescType			keyForm,
								 			const AEDesc*		keyData,
								  			AEDesc*			resultToken)
{
	OSErr			err;	
	DescType			requestedProperty;

	err = AEDuplicateDesc(containerToken, resultToken);
	ThrowIfOSErr(err);
		
	requestedProperty = **(DescType**)(keyData->dataHandle);
	
	if (requestedProperty == kAEAll || requestedProperty == keyAEProperties)
		requestedProperty = pProperties;

	if (CanGetProperty(requestedProperty) || CanSetProperty(requestedProperty))
	{
		AETokenDesc		resultTokenDesc(resultToken);
		resultToken->descriptorType = desiredType;
		resultTokenDesc.SetPropertyCode(requestedProperty);
	}
	else
	{
		ThrowIfOSErr(errAEEventNotHandled);
	}
}
示例#3
0
/*----------------------------------------------------------------------------
	CompareObjectsCallback 
	
----------------------------------------------------------------------------*/
pascal OSErr AECoreClass::CompareObjectsCallback(	DescType			comparisonOperator, 	// operator to use
											const AEDesc *		object,				// left-hand side
											const AEDesc *		descriptorOrObject, 		// right-hand side
											Boolean *			result)
{
	OSErr	err = noErr;
	try
	{
		OSErr		err = noErr;
		StAEDesc		desc1;
		StAEDesc		desc2;

		// This first AEDesc is a token to a specific object, so we resolve it.
		AECoreClass::GetAECoreHandler()->ExtractData(object, &desc1);
			
		// A second AEDesc is either a token to another object or an AEDesc containing literal data.
		AECoreClass::GetAECoreHandler()->ExtractData(descriptorOrObject, &desc2);	

		// Make sure the data type extracted from the second AEDesc is the same as the
		// data specified by the first AEDesc.
		
		if (desc1.descriptorType != desc2.descriptorType) 
		{
			StAEDesc		temp;
			
			// Create a temporary duplicate of desc2 and coerce it to the
			// requested type. This could call a coercion handler you have
			// installed. If there are no errors, stuff the coerced value back into desc2
			err = AEDuplicateDesc(&desc2, &temp);
			ThrowIfOSErr(err);
			
			desc2.Clear();
			
			err = AECoerceDesc(&temp, desc1.descriptorType, &desc2);
			ThrowIfOSErr(err);
		}

		AEDispatchHandler*	handler = AECoreClass::GetDispatchHandlerForClass(desc1.descriptorType);
		if (handler)
			handler->CompareObjects(comparisonOperator, &desc1, &desc2, result);
		else
			*result = AEComparisons::TryPrimitiveComparison(comparisonOperator, &desc1, &desc2);
	}
	catch (OSErr catchErr)
	{
		err = catchErr;
	}
	catch (...)
	{
		err = paramErr;
	}
	
	return err;
}
示例#4
0
文件: ae.c 项目: AdminCNP/appscript
static PyObject *AEDesc_AEDuplicateDesc(AEDescObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	AEDesc result;

	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_err = AEDuplicateDesc(&_self->ob_itself,
	                       &result);
	if (_err != noErr) return AE_MacOSError(_err);
	_res = Py_BuildValue("O&",
	                     AE_AEDesc_New, &result);
	return _res;
}
示例#5
0
文件: rbosa.c 项目: bmorton/rubyosa
static VALUE
rbosa_element_dup (VALUE self, VALUE element)
{
    AEDesc *  desc;
    AEDesc    new_desc;
    OSErr     error;

    desc = rbosa_element_aedesc (element);
    error = AEDuplicateDesc (desc, &new_desc);
    if (error != noErr) 
        rb_raise (rb_eArgError, "Cannot duplicate element : %s (%d)", 
                  error_code_to_string (error), error);

    return rbosa_element_make (self, &new_desc, Qnil); 
}
示例#6
0
static PyObject *AEDesc_AEDuplicateDesc(AEDescObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	AEDesc result;
#ifndef AEDuplicateDesc
	PyMac_PRECHECK(AEDuplicateDesc);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_err = AEDuplicateDesc(&_self->ob_itself,
	                       &result);
	if (_err != noErr) return PyMac_Error(_err);
	_res = Py_BuildValue("O&",
	                     AEDescX_New, &result);
	return _res;
}
示例#7
0
static pascal OSErr
GenericCoercionHandler(const AEDesc *fromDesc, DescType toType, refcontype refcon, AEDesc *toDesc)
{	
	PyObject *handler = (PyObject *)refcon;
	AEDescObject *fromObject;
	PyObject *args, *res;
    PyGILState_STATE state;
	OSErr err = noErr;
	
	state = PyGILState_Ensure();
	if ((fromObject = (AEDescObject *)AEDesc_New((AEDesc *)fromDesc)) == NULL) {
		err = -1;
		goto cleanup;
	}
	if ((args = Py_BuildValue("OO&", fromObject, PyMac_BuildOSType, &toType)) == NULL) {
		Py_DECREF(fromObject);
		err = -1;
		goto cleanup;
	}
	res = PyEval_CallObject(handler, args);
	fromObject->ob_itself.descriptorType = 'null';
	fromObject->ob_itself.dataHandle = NULL;
	Py_DECREF(args);
	if (res == NULL) {
		PySys_WriteStderr("Exception in AE coercion handler function\n");
		PyErr_Print();
		err = errAECoercionFail;
		goto cleanup;
	}
	if (!AEDesc_Check(res)) {
		PySys_WriteStderr("AE coercion handler function did not return an AEDesc\n");
		Py_DECREF(res);
		err = errAECoercionFail;
		goto cleanup;
	}
	if (AEDuplicateDesc(&((AEDescObject *)res)->ob_itself, toDesc)) {
		Py_DECREF(res);
		err = -1;
		goto cleanup;
	}
	Py_DECREF(res);
cleanup:
	PyGILState_Release(state);
	return err;
}
示例#8
0
// CountTabletObjects
//
//	This function will return the number of particular items the Tablet Driver
// knows about. For examle, the number of tablets, the number of transducers
// for a customized application for a particular tablet...
//
// parameters: TAEObject *pTabletObject - Pointer to a TAEObject that
//														describes exactly which tablet object
//														you want to count.
//					 UInt32 *outCount - The number of pTabletObjects the driver knows
//											  about.
//
// returns: noErr on success, else an AE error code
//////////////////////////////////////////////////////////////////////////////
OSErr	CountTabletObjects(TAEObject *pTabletObject, UInt32 *outCount)
{
   AEDesc 			driverTarget,keyData,tObjSpecifier;
   AEDesc			lastDesc;
   AppleEvent		aeSend;
   AppleEvent		aeReply;
   DescType			outType;
   Size				outSize;
   UInt32			tmpIndex = 0;
   UInt32			tmpCount = 0;
   OSErr				err;


//   assert(outCount);
   if(!outCount)
   {
      return -1;
   }

   err = GetTabletDriverTarget(&driverTarget);
   if(err)
   {
      return err;
   }

   err = AECreateAppleEvent(kAECoreSuite,
                            kAECountElements,
                            &driverTarget,
                            kAutoGenerateReturnID,
                            kAnyTransactionID,
                            &aeSend);

   // Now tell the AE what to Count

   // We have to set up a chain here.
   // [Button ->] [Transducer ->] [Application ->] Tablet -> null
   // The thing is, Apple Events are built backwards. So...

   //Create  NULL AEDesc, this will signify the end of the AEDesc Chain
   AEInitializeDesc(&lastDesc);
   err = AECreateDesc( typeNull, NULL, NULL, &lastDesc );

   if (pTabletObject->objectType != cWTDDriver)
   {
      // set up the driver desc
      AEInitializeDesc(&keyData);
      tmpIndex = 1;
      err = AECreateDesc( typeUInt32,
                        &tmpIndex,	// This is the Tablet Driver Index. Always 1
                        sizeof(tmpIndex),
                        &keyData );
   
      err = CreateObjSpecifier(cWTDDriver,
                              &lastDesc,
                              formAbsolutePosition,
                              &keyData,
                              TRUE,
                              &tObjSpecifier);
      AEDuplicateDesc(&tObjSpecifier,&lastDesc);
		AEDisposeDesc(&tObjSpecifier);

      if (pTabletObject->objectType != cWTDTablet)
      {
         // set up the tablet desc
         AEInitializeDesc(&keyData);
         err = AECreateDesc( typeUInt32,
                           &pTabletObject->tabletIndex,
                           sizeof(UInt32),
                           &keyData );
   
         err = CreateObjSpecifier(cWTDTablet,
                                 &lastDesc,
                                 formAbsolutePosition,
                                 &keyData,
                                 TRUE,
                                 &tObjSpecifier);
         AEDuplicateDesc(&tObjSpecifier,&lastDesc);
			AEDisposeDesc(&tObjSpecifier);
   
         if (pTabletObject->objectType != cWTDCustomizedApp)
         {
            // set up the cutom app desc
            AEInitializeDesc(&keyData);
            err = AECreateDesc( typeUInt32,
                              &pTabletObject->applicationIndex,
                              sizeof(UInt32),
                              &keyData );
   
            err = CreateObjSpecifier(cWTDCustomizedApp,
                                    &lastDesc,
                                    formAbsolutePosition,
                                    &keyData,
                                    TRUE,
                                    &tObjSpecifier);
            AEDuplicateDesc(&tObjSpecifier,&lastDesc);
				AEDisposeDesc(&tObjSpecifier);

            if (pTabletObject->objectType == cWTDButton)
            {
               // set up the transducer desc
               AEInitializeDesc(&keyData);
               err = AECreateDesc( typeUInt32,
                                   &pTabletObject->transducerIndex,
                                   sizeof(UInt32),
                                   &keyData );

               err = CreateObjSpecifier(cWTDTransducer,
                                        &lastDesc,
                                        formAbsolutePosition,
                                        &keyData,
                                        TRUE,
                                        &tObjSpecifier);
               AEDuplicateDesc(&tObjSpecifier,&lastDesc);
					AEDisposeDesc(&tObjSpecifier);
            }
         }
      }
   }


   // Now we actually tell it to count the number of the tablet objects
   err = AEPutParamPtr( &aeSend,
                        keyAEObjectClass,
                        typeType,
                        &pTabletObject->objectType,	// This is the class of objects to count
                        sizeof(DescType) );
   err = AEPutParamDesc( &aeSend, keyDirectObject, &lastDesc);	// The Object chain

   // Finally send the event
   err = AESend(&aeSend,	// The complete AE we created above
                &aeReply,
                kAEWaitReply,
                kAEHighPriority,
                kDefaultTimeOut,
                NULL,
                NULL);

   if(!err)
   {
      // Get the answer from the Reply
      err = AEGetParamPtr(&aeReply,
                          keyDirectObject,
                          typeUInt32,
                          &outType,
                          &tmpCount,   // Put the answer into this variable
                          sizeof(long),
                          &outSize);
      if(noErr != err)
      {
         tmpCount = 0;
      }
      else
      {
         *outCount = tmpCount;
      }
   }

   AEDisposeDesc(&tObjSpecifier);
   AEDisposeDesc(&aeSend);
   AEDisposeDesc(&aeReply);

   return err;
示例#9
0

OSErr	SetData_ofSize_ofType_ofTabletObject_ForAttribute(void 		*inDataPtr,
																		  Size 		inDataSize,
																		  DescType 	dataType,
																		  TAEObject *pTabletObject,
																		  DescType 	attribute)
{
   AEDesc 			driverTarget,nullDesc,keyData,tObjSpecifier;
   AEDesc			lastDesc;
   AppleEvent		aeSend;
   UInt32			tmpIndex = 0;
   OSErr				err;


//   assert(inDataPtr);
   if(!inDataPtr)
   {
      return -1;
   }

   err = GetTabletDriverTarget(&driverTarget);
   if(err)
   {
      return err;
   }

   err = AECreateAppleEvent(kAECoreSuite,
                            kAESetData,
                            &driverTarget,
                            kAutoGenerateReturnID,
                            kAnyTransactionID,
                            &aeSend);

   // Now tell the AE what to set

   // We have to set up a chain here.
   // Attribute -> Button -> Transducer -> Application -> Tablet -> null
   // The thing is, Apple Events are built backwards. So...

   //Create  NULL AEDesc, this will signify the end of the AEDesc Chain
   AEInitializeDesc(&nullDesc);
   err = AECreateDesc( typeNull, NULL, NULL, &nullDesc );

   // set up the driver desc
   AEInitializeDesc(&keyData);
   tmpIndex = 1;
   err = AECreateDesc( typeUInt32,
                       &tmpIndex,	// This is the Tablet Driver Index. Always 1
                       sizeof(tmpIndex),
                       &keyData );

   err = CreateObjSpecifier(cWTDDriver,
                            &nullDesc,	
                            formAbsolutePosition,
                            &keyData,	
                            TRUE,
                            &tObjSpecifier);
	AEDuplicateDesc(&tObjSpecifier,&lastDesc);
   AEDisposeDesc(&tObjSpecifier);
   
   if (pTabletObject->objectType != cWTDDriver)
   {
      // set up the tablet desc
      AEInitializeDesc(&keyData);
      err = AECreateDesc( typeUInt32,
                          &pTabletObject->tabletIndex,
                          sizeof(UInt32),
                          &keyData );

      err = CreateObjSpecifier(cWTDTablet,
                               &lastDesc,
                               formAbsolutePosition,
                               &keyData,
                               TRUE,
                               &tObjSpecifier);
      AEDuplicateDesc(&tObjSpecifier,&lastDesc);
		AEDisposeDesc(&tObjSpecifier);

      if (pTabletObject->objectType != cWTDTablet)
      {
         // set up the cutom app desc
         AEInitializeDesc(&keyData);
         err = AECreateDesc( typeUInt32,
                             &pTabletObject->applicationIndex,
                             sizeof(UInt32),
                             &keyData );

         err = CreateObjSpecifier(cWTDCustomizedApp,
                                  &lastDesc,
                                  formAbsolutePosition,
                                  &keyData,
                                  TRUE,
                                  &tObjSpecifier);
         AEDuplicateDesc(&tObjSpecifier,&lastDesc);
			AEDisposeDesc(&tObjSpecifier);

         if (pTabletObject->objectType != cWTDCustomizedApp)
         {
            if (pTabletObject->objectType == cWTDButton)
            {
               // set up the transducer desc
               AEInitializeDesc(&keyData);
               err = AECreateDesc( typeUInt32,
                                 &pTabletObject->transducerIndex,
                                 sizeof(UInt32),
                                 &keyData );
   
               err = CreateObjSpecifier(cWTDTransducer,
                                       &lastDesc,
                                       formAbsolutePosition,
                                       &keyData,
                                       TRUE,
                                       &tObjSpecifier);
               AEDuplicateDesc(&tObjSpecifier,&lastDesc);
					AEDisposeDesc(&tObjSpecifier);
            }
   
            if (pTabletObject->objectType == cWTDTransducer)
            {
               // set up the transducer desc
               AEInitializeDesc(&keyData);
               err = AECreateDesc( typeUInt32,
                                 &pTabletObject->transducerIndex,
                                 sizeof(UInt32),
                                 &keyData );
   
               err = CreateObjSpecifier(cWTDTransducer,
                                       &lastDesc,
                                       formAbsolutePosition,
                                       &keyData,
                                       TRUE,
                                       &tObjSpecifier);
               AEDuplicateDesc(&tObjSpecifier,&lastDesc);
					AEDisposeDesc(&tObjSpecifier);
            }
            else // cWTDButton || cWTDMenuItem || cWTDButton
            {
               // set up the transducer desc
               AEInitializeDesc(&keyData);
               err = AECreateDesc( typeUInt32,
                                 &pTabletObject->auxIndex,
                                 sizeof(UInt32),
                                 &keyData );
   
               err = CreateObjSpecifier(pTabletObject->objectType,
                                       &lastDesc,
                                       formAbsolutePosition,
                                       &keyData,
                                       TRUE,
                                       &tObjSpecifier);
               AEDuplicateDesc(&tObjSpecifier,&lastDesc);
					AEDisposeDesc(&tObjSpecifier);
            }
         }
      }
   }

   AEInitializeDesc(&keyData);
   err = AECreateDesc( typeType,
                       &attribute,	// This is the Attribute we want to set
                       sizeof(DescType),
                       &keyData );

   err = CreateObjSpecifier(cProperty,	
                            &lastDesc,
                            formPropertyID,
                            &keyData,	
                            TRUE,
                            &tObjSpecifier);	

	// Add the data to set to the AE here.
   err = AEPutParamPtr ( &aeSend, keyAEData,
								 dataType, inDataPtr, inDataSize); 
   err = AEPutParamDesc( &aeSend, keyDirectObject,  &tObjSpecifier);	// The Object chain 
   
   // Finally send the event
   err = AESend(&aeSend,	// The complete AE we created above
                NULL,		// Don't need a reply
                kAEWaitReply,
                kAEHighPriority,
                kDefaultTimeOut,
                NULL,
                NULL);

   AEDisposeDesc(&tObjSpecifier);
   AEDisposeDesc(&aeSend);

   return err;
示例#10
0
// GetData_ofSize_ofType_ofContext_ForAttribute
//
//	This function will get an attribute of a context your app created. See
// Context Attributes near the bottom of the TabletAEDictionary.h header file.
//
// parameters: const void *inDataPtr - Location to store the attribute data.
//					Size inDataSize - Size of the data buffer pointed to above.
//					DescType dataType - Type of data bufferpointed to above.
//					UInt32 contextID - The context to get from.
//					DescType attribute - The attribute you want to get.
//
// returns: noErr on success, else an AE error code
//////////////////////////////////////////////////////////////////////////////
OSErr	GetData_ofSize_ofType_ofContext_ForAttribute(void 		*inDataPtr,
                                                   Size 		inDataSize,
                                                   DescType dataType,
                                                   UInt32 	contextID,
                                                   DescType attribute)
{
   AEDesc 			driverTarget,nullDesc,keyData,tObjSpecifier;
	AEDesc			lastDesc;
   AppleEvent		aeSend;
   AppleEvent		aeReply;
   DescType			outType;
   Size				outSize;
   OSErr				err;


//   assert(inDataPtr);
   if(!inDataPtr)
   {
      return -1;
   }

   err = GetTabletDriverTarget(&driverTarget);
   if(err)
   {
      return err;
   }

   err = AECreateAppleEvent(kAECoreSuite,
                            kAEGetData,
                            &driverTarget,
                            kAutoGenerateReturnID,
                            kAnyTransactionID,
                            &aeSend);

   // Now tell the AE what to get

   // We have to set up a chain here.
   // Attribute -> Context -> null
   // The thing is, Apple Events are built backwards. So...

   //Create  NULL AEDesc, this will signify the end of the AEDesc Chain
   AEInitializeDesc(&nullDesc);
   err = AECreateDesc( typeNull, NULL, NULL, &nullDesc );

   AEInitializeDesc(&keyData);
   err = AECreateDesc( typeUInt32,
                       &contextID,	// This is the context ID that we want to modify
                       sizeof(contextID),
                       &keyData );

   err = CreateObjSpecifier(cContext,				// We want to modifiy a context attribute
                            &nullDesc,				// This is the last item in the chain
                            formUniqueID,			// use id to determine which context to modify
                            &keyData,				// This is the Context ID descriptor created above
                            TRUE,					// delete the nullDesc, and KeyData descriptor for us
                            &tObjSpecifier);		// The created descriptor which says that we want to modify Context X
	AEDuplicateDesc(&tObjSpecifier, &lastDesc);
   AEDisposeDesc(&tObjSpecifier);
	
   AEInitializeDesc(&keyData);
   err = AECreateDesc( typeType,
                       &attribute,	// This is the Attribute we want to set
                       sizeof(DescType),
                       &keyData );

   err = CreateObjSpecifier(cProperty,				// We want to destroy a context
                            &lastDesc,				// This is the last item in the chain (the Context)
                            formPropertyID,		// use id to determine which context to destroy
                            &keyData,				// This is the Context ID descriptor created above
                            TRUE,					// delete the nullDesc, and KeyData descriptor for us
                            &tObjSpecifier);		// The created descriptor which says that we want to delete Context X
	
	// Add the data to set to the AE here.
   err = AEPutParamPtr ( &aeSend, keyAERequestedType,
								 typeType, &dataType, sizeof(DescType));
	// The Object chain (Attribute -> Context -> null)
	err = AEPutParamDesc( &aeSend, keyDirectObject,  &tObjSpecifier);

   // Finally send the event
   err = AESend(&aeSend,	// The complete AE we created above
                &aeReply,		
                kAEWaitReply,
                kAEHighPriority,
                kDefaultTimeOut,
                NULL,
                NULL);

   if(!err)
   {
      err = AEGetParamPtr(&aeReply,
                          keyDirectObject,
                          dataType,
                          &outType,
                          inDataPtr,   // Put the answer into this variable
                          inDataSize,
                          &outSize);
   }
   
   AEDisposeDesc(&tObjSpecifier);
   AEDisposeDesc(&aeSend);
   AEDisposeDesc(&aeReply);