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; }
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
// DestoryWacomContext // // This function will instruct the Tablet Driver to delete a context that your // application created. Please be nice and destroy all contexts you create // before your application quits. // // parameters: UInt32 contextID - The ID returned to you when you created the // context. // // returns: a contextID and noErr on success, else an AE error code ////////////////////////////////////////////////////////////////////////////// OSErr DestoryWacomContext(UInt32 contextID) { AEDesc driverTarget,nullDesc,keyData,tObjSpecifier; AppleEvent aeSend; OSErr err; err = GetTabletDriverTarget(&driverTarget); if(err) { return err; } err = AECreateAppleEvent(kAECoreSuite, kAEDelete, &driverTarget, kAutoGenerateReturnID, kAnyTransactionID, &aeSend); // Now tell the AE what to destroy //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 we want to destroy sizeof(contextID), &keyData ); err = CreateObjSpecifier(cContext, // We want to destroy a context &nullDesc, // This is the last item in the chain formUniqueID, // 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 err = AEPutParamDesc( &aeSend, keyDirectObject, &tObjSpecifier); // 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);
/******************************************************************************** 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
/******************************************************************************** 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
/******************************************************************************** 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
/******************************************************************************** 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
/******************************************************************************** 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
static VALUE rbosa_element_new_os (VALUE self, VALUE desired_class, VALUE container, VALUE key_form, VALUE key_data) { OSErr error; AEDesc obj_specifier; error = CreateObjSpecifier (RVAL2FOURCHAR (desired_class), rbosa_element_aedesc (container), RVAL2FOURCHAR (key_form), rbosa_element_aedesc (key_data), false, &obj_specifier); if (error != noErr) rb_raise (rb_eArgError, "Cannot create Apple Event object specifier for desired class '%s' : %s (%d)", RVAL2CSTR (desired_class), error_code_to_string (error), error); return rbosa_element_make (self, &obj_specifier, Qnil); }
//******************************************************************************** // 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
//******************************************************************************** // 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
/* *---------------------------------------------------------------------- * * GetFinderFont -- * * Gets the "views" font of the Macintosh Finder * * Results: * Standard Tcl result, and sets finderID to the font family * id for the current finder font. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int GetFinderFont(int *finderID) { OSErr err = noErr; OSType finderPrefs, viewFont = 'vfnt'; DescType returnType; Size returnSize; long result, sys8Mask = 0x0800; static AppleEvent outgoingAevt = {typeNull, NULL}; AppleEvent returnAevt; AEAddressDesc fndrAddress; AEDesc nullContainer = {typeNull, NULL}, tempDesc = {typeNull, NULL}, tempDesc2 = {typeNull, NULL}, finalDesc = {typeNull, NULL}; const OSType finderSignature = 'MACS'; if (outgoingAevt.descriptorType == typeNull) { if ((Gestalt(gestaltSystemVersion, &result) != noErr) || (result >= sys8Mask)) { finderPrefs = 'pfrp'; } else { finderPrefs = 'pvwp'; } AECreateDesc(typeApplSignature, &finderSignature, sizeof(finderSignature), &fndrAddress); err = AECreateAppleEvent(kAECoreSuite, kAEGetData, &fndrAddress, kAutoGenerateReturnID, kAnyTransactionID, &outgoingAevt); AEDisposeDesc(&fndrAddress); /* * The structure is: * the property view font ('vfnt') * of the property view preferences ('pvwp') * of the Null Container (i.e. the Finder itself). */ AECreateDesc(typeType, &finderPrefs, sizeof(finderPrefs), &tempDesc); err = CreateObjSpecifier(typeType, &nullContainer, formPropertyID, &tempDesc, true, &tempDesc2); AECreateDesc(typeType, &viewFont, sizeof(viewFont), &tempDesc); err = CreateObjSpecifier(typeType, &tempDesc2, formPropertyID, &tempDesc, true, &finalDesc); AEPutKeyDesc(&outgoingAevt, keyDirectObject, &finalDesc); AEDisposeDesc(&finalDesc); } err = AESend(&outgoingAevt, &returnAevt, kAEWaitReply, kAEHighPriority, kAEDefaultTimeout, NULL, NULL); if (err == noErr) { err = AEGetKeyPtr(&returnAevt, keyDirectObject, typeInteger, &returnType, (void *) finderID, sizeof(int), &returnSize); if (err == noErr) { return TCL_OK; } } return TCL_ERROR; }
// 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;
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;
// 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);
// CreateWacomContextForTablet // // This function will instruct the Tablet Driver to create a context for your // application that you can then modify. For example, you can modify your // context to change the tablet mapping or to diconnect the tablet from the // cursor. // // parameters: UInt32 tabletIdx - Tablet Number you want to a context for // UInt32 *contextID - On return, the ID used to modify / delete // your context. // // returns: a contextID and noErr on success, else an AE error code ////////////////////////////////////////////////////////////////////////////// OSErr CreateWacomContextForTablet(UInt32 tabletIdx, UInt32 *contextID) { AEDesc driverTarget,nullDesc,keyData,tObjSpecifier; DescType objectToMake = cContext; UInt32 outContextID; DescType outType; Size outSize; AppleEvent aeSend; AppleEvent aeReply; OSErr err; err = GetTabletDriverTarget(&driverTarget); if(err) { return err; } err = AECreateAppleEvent(kAECoreSuite, kAECreateElement, &driverTarget, kAutoGenerateReturnID, kAnyTransactionID, &aeSend); // Now tell the AE what to create err = AEPutParamPtr( &aeSend, keyAEObjectClass, typeType, &objectToMake, sizeof(DescType)); // Now tell the AE where to create a context //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, &tabletIdx, // This is the tablet number we want the context for sizeof(tabletIdx), &keyData ); err = CreateObjSpecifier(cWTDTablet, // We want info from a tablet &nullDesc, // This is the last item in the chain formAbsolutePosition, // use indexing to determine which tablet to get data from &keyData, // This is the Tablet Number descriptor created above TRUE, // delete the nullDesc, and KeyData descriptor for us &tObjSpecifier); // The created descriptor which says that we want data from tablet number X err = AEPutParamDesc( &aeSend, keyAEInsertHere, &tObjSpecifier); // Finally send the event err = AESend(&aeSend, // The complete AE we created above &aeReply, // The reply event that contains the Context ID. kAEWaitReply, kAEHighPriority, kDefaultTimeOut, NULL, NULL); AEDisposeDesc(&tObjSpecifier); AEDisposeDesc(&aeSend); // Get the Context ID out of the reply err = AEGetParamPtr(&aeReply, keyDirectObject, typeUInt32, &outType, &outContextID, // Put the answer into this variable sizeof(long), &outSize); if(!err) { if(contextID) { *contextID = outContextID; } } AEDisposeDesc(&aeReply);