Example #1
0
 JSObject *CJSRuntime::AcquireObject(IUEEntries iType, void *index)
 {
     JSObject *retVal = NULL;
     if (iType != IUE_COUNT && static_cast<size_t>(iType) < objectList.size())
     {
         retVal = FindAssociatedObject(iType, index);
         if (retVal == NULL)
         {
             retVal = MakeNewObject(iType);
             if (retVal != NULL)
             {
                 objectList[iType][index] = retVal;
                 JS_SetPrivate(jsContext, retVal, index);
             }
         }
     }
     return retVal;
 }
Example #2
0
/*----------------------------------------------------------------------------
	HandleMake 

	
----------------------------------------------------------------------------*/
void AEGenericClass::HandleMake(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
{
	DescType		insertionPos	= typeNull;
	OSErr		err 			= noErr;

	StAEDesc		insertionLoc;
	StAEDesc		objectSpec;

	// For Create Element, the object specifier is contained in  
	// a typeInsertionLoc record instead of in a direct parameter. 
	// We coerce the insertionLoc record into an AERecord so we can extract the fields.	 
	// Notice that this is a REQUIRED parameter, but we give it a default behavior
	// by creating a new element at beginning of the first document
	
	err = ::AEGetParamDesc(appleEvent, 				// Extract as a AERecord
								  keyAEInsertHere, 
								  typeAERecord, 
								  &insertionLoc);
	if (err == errAEDescNotFound)
	{
		insertionPos	= kAEBeginning;
		err			= noErr;
	}
	else if (err == noErr)
	{
		// Get the enumerated insertion location (at end, in front, before, after, replace.)
		
		OSType		typeCode;
		Size			actualSize;
		err = ::AEGetKeyPtr(&insertionLoc, 
								  	keyAEPosition, 			// insertion location
									typeEnumeration, 
									&typeCode, 
									(Ptr)&insertionPos,
						   			sizeof(insertionPos), 
						   			&actualSize);

		// Extract and resolve the object specifier from the insertion location record.
		// In a case like "make new rectangle before rectangle 1 of document 1",
		// the ospec will resolve to "rectangle 1 of document 1"
				 
		err = ::AEGetKeyDesc(&insertionLoc, 
									keyAEObject, 
									typeWildCard, 
									&objectSpec);
	}

	// if there was a object specifier in the insertion location (eg, "before rectangle 1 of document 1"),
	//   then we call AEResolve() to get a token for it,
	// Otherwise, is was something like "at end" or "at beginning", which is also OK, 
	//   then deal with it correctly later.
	if (objectSpec.descriptorType == typeNull) 
	{
		::AEDisposeDesc(token);			// destroy it's old representation, token will now be null descriptor
	}
	else
	{
		err = ::AEResolve(&objectSpec, 
							 kAEIDoMinimum, 
							 token);			// token will contain info about the object to insert before, after, etc.
		ThrowIfOSErr(err);
	}
		
	// Extract the optional parameters from the AppleEvent
	
	// ----- [with data ....] -----
	
	StAEDesc		withData;
	const AEDesc*	withDataPtr = nil;
	
	err = ::AEGetParamDesc(appleEvent, 
								  keyAEData,
								  typeWildCard,
								  &withData);
	if (err == errAEDescNotFound)
		err = noErr;
	else
	{
		ThrowIfOSErr(err);
		withDataPtr = &withData;
	}

	// ----- [with properties {property: value, ...}] -----
	StAEDesc		withProperties;
	const AEDesc*	withPropertiesPtr = nil;
	err = AEGetParamDesc(appleEvent, 
								  keyAEPropData, 
								  typeWildCard, 
								  &withProperties);
								  
	if (err == errAEDescNotFound)
		err = noErr;
	else
	{
		ThrowIfOSErr(err);
		withPropertiesPtr = &withProperties;
	}
	
	// Finally, use the token and other parameters to create & initialize the object
	MakeNewObject(insertionPos, token, withDataPtr, withPropertiesPtr, reply);
}
Example #3
0
void CGenPropertyPage::OnAddItem(CDialog & dlg) 
{

  // load dialog with default values
  InitDialog (&dlg);

  // display dialog, exit if cancelled
  if (dlg.DoModal () != IDOK)
    return;

  // create the object's lookup name (label converted to lower case, or generated)
 CObject * pItem;
 CString strObjectName;

  strObjectName = GetObjectName (&dlg);
  if (strObjectName.IsEmpty ())
    strObjectName.Format ("*%s%s",       // e.g. *trigger100
                            (LPCTSTR) m_strObjectType,
                            (LPCTSTR) App.GetUniqueString ());
  else
    strObjectName.MakeLower();

  // if already there (presumably not possible with un-named objects),
  // then abort the add
  if (m_ObjectMap->Lookup (strObjectName, pItem))
    {
    CString strMsg;

    strMsg = TFormat ("The %s named \"%s\" is already in the %s list",
                  (LPCTSTR) m_strObjectType,
                  (LPCTSTR) GetObjectName (&dlg),
                  (LPCTSTR) m_strObjectType);
    ::UMessageBox (strMsg);
    return;
    }

  // add new object to map
  m_ObjectMap->SetAt (strObjectName, pItem = MakeNewObject ());

  // unload from dialog into object's properties
  UnloadDialog (&dlg, pItem);

  // They can no longer cancel the property sheet, the document has changed
  CancelToClose ();
  if (!CheckIfTemporary (pItem))
    m_doc->SetModifiedFlag (TRUE);

  // create a CString for lookup purposes
  CString * pstrObjectName = new CString (strObjectName);

  // add this item to the list view
  add_item (pItem, pstrObjectName, 0, TRUE);

  SetInternalName (pItem, strObjectName);  // set name so we can delete one-shot items

  // resort the list
  t_gen_sort_param sort_param (m_ObjectMap, m_last_col, m_reverse, m_CompareObjects);
  m_ctlList->SortItems (CompareFunc, (LPARAM) &sort_param); 

  // redraw the list
  if (GetFilterFlag ())
    LoadList ();       // full reload because it may have changed filter requirements

// get dispatch id from the script and put it into the item

  if (m_doc->m_ScriptEngine)
    {
    CString strMessage;
    SetDispatchID (pItem, m_doc->GetProcedureDispid (GetScriptName (pItem),
                                                     m_strObjectType, 
                                                     GetLabel (pItem),
                                                     strMessage));
    if (!strMessage.IsEmpty ())
      ::UMessageBox (strMessage, MB_ICONINFORMATION);
    }
  
}    // end of CGenPropertyPage::OnAddItem