//************************************************************************//
//                                                                       
//    < XtraRecipe.cpp >                                                
//    Create and Destroy XtraRecipe and extending of them classes.          
//    And override implementing interfaces to communicate with Lingo.               
//                                                                       
//    It is made by XtraRecipe                   
//    coding and discrption by Takehisa MASHIMO                           
//    copyright 2003 Takehisa MASHIMO All Rights Reserved.               
//                                                                       
//************************************************************************//

#define INITGUID 1

#include "XtraRecipe.h"	// XtraRecipeNX錾Ăwb_
#include "YourCode.h"	// YourCodẽ\bh`Ăwb_

#include <string.h>
#include <stdlib.h>
#include "xclassver.h"
#include "moatry.h"

#include "driservc.h"
#include "drivalue.h"

#include "mmivalue.h"
#include "mmillist.h"
#include "mmiplist.h"
#include "mmidate.h"
#include "mmiclr.h"

//============================================================================
// XNvg\bhݒ
//============================================================================

// bZ[We[u̍쐬
static char versionInfo[] = 
*XtraName*

static char msgTable[] = {	
*XtraHeadaInfo*
*MsgTable_MethodList*
*XtraFootaInfo*
	};

// \bhXg̍쐬
enum 
{
	m_new = 0,						//On܂
*enum_MethodList*
	m_XXXX							//XgI
};

//============================================================================
// XtraRecipepbP[WiXtra{́jݒ
//   XtraRecipeNX`
///============================================================================

// XtraRecipepbP[WXtraRecipeNXƎC^tFCX`
BEGIN_XTRA
	BEGIN_XTRA_DEFINES_CLASS(XtraRecipe, 1)
		CLASS_DEFINES_INTERFACE(XtraRecipe, IMoaRegister, 1)
		CLASS_DEFINES_INTERFACE(XtraRecipe, IMoaMmXScript, 1)
	END_XTRA_DEFINES_CLASS
END_XTRA

// XtraRecipeNXCX^X̐iAvP[VĂяoj
STDMETHODIMP_(MoaError) MoaCreate_XtraRecipe (XtraRecipe FAR * This)
{
	moa_try
		//QƃC^tFCXID擾
		ThrowErr (This->pCallback->QueryInterface(&IID_IMoaMmValue, (PPMoaVoid) &This->pValueInterface));
	moa_catch
	moa_catch_end
	moa_try_end
}

// XtraRecipeNXCX^X̍폜iAvP[VĂяoj
STDMETHODIMP_(void) MoaDestroy_XtraRecipe(XtraRecipe FAR * This)
{
	moa_try
		if (This->pValueInterface != NULL) ThrowErr (This->pValueInterface->Release());
	moa_catch
	moa_catch_end
	moa_try_end_void
}

//----------------------------------------------------------------------------
// XtraRecipepbP[W
//   XtraRecipeNX
//     IMoaRegisterC^tFCX
//   -> gNXXtraRecipe_IMoaRegister
//        \bh̃I[o[Ch
//----------------------------------------------------------------------------

// IMoaRegisterC^tFCX𐶐A폜
STD_INTERFACE_CREATE_DESTROY(XtraRecipe, IMoaRegister)

// XtraRecipeNXIMoaRegisterC^tFCX
BEGIN_DEFINE_CLASS_INTERFACE(XtraRecipe, IMoaRegister)
END_DEFINE_CLASS_INTERFACE

// Register()̃I[o[Ch
STDMETHODIMP XtraRecipe_IMoaRegister::Register( PIMoaCache pCache, PIMoaXtraEntryDict pXtraDict )
{	
	moa_try

		// WXgXtraCX^Xo^
		PIMoaRegistryEntryDict		pReg;
		ThrowErr(pCache->AddRegistryEntry( pXtraDict, &CLSID_XtraRecipe, &IID_IMoaMmXScript, &pReg));

		// bZ[We[uo^
		char versionStr[256];
		PMoaVoid pMemStr = NULL;
		sprintf(versionStr, versionInfo, VER_MAJORVERSION_STRING, VER_MINORVERSION_STRING, VER_BUGFIXVERSION_STRING, VER_BUILDNUM_STRING);
		pMemStr = pObj->pCalloc->NRAlloc(sizeof(msgTable) + sizeof(versionStr));
		ThrowNull(pMemStr);

		strcpy((char *)pMemStr, versionStr);
		strcat((char *)pMemStr, msgTable);

		ThrowErr(pReg->Put(kMoaDrDictType_MessageTable, pMemStr, 0, kMoaDrDictKey_MessageTable));

		// Mark xtra as safe for shockwave
		MoaBool		bItsSafe = TRUE;
		ThrowErr(pReg->Put(kMoaMmDictType_SafeForShockwave, &bItsSafe, sizeof(bItsSafe), kMoaMmDictKey_SafeForShockwave));

	moa_catch
	moa_catch_end
		if (pMemStr) pObj->pCalloc->NRFree(pMemStr);
	moa_try_end
}


//----------------------------------------------------------------------------
// XtraRecipepbP[W
//   XtraRecipeNX
//     IMoaMmXScriptC^tFCX̎
//   -> gNXXtraRecipe_IMoaMmXScript
//        \bh̃I[o[Ch
//----------------------------------------------------------------------------

// XtraRecipeNXIMoaMmXScriptC^tFCXp
BEGIN_DEFINE_CLASS_INTERFACE(XtraRecipe, IMoaMmXScript)
END_DEFINE_CLASS_INTERFACE

// IMoaMmXScript()̃RXgN^
XtraRecipe_IMoaMmXScript::XtraRecipe_IMoaMmXScript(MoaError FAR *)
{
	moa_try
	moa_catch
	moa_catch_end
	moa_try_end_void
}	

// IMoaMmXScript()̃fRXgN^
XtraRecipe_IMoaMmXScript::~XtraRecipe_IMoaMmXScript()
{
	moa_try
	moa_catch
	moa_catch_end
	moa_try_end_void
}

//Call()̃I[o[ChiXNvg\bhU蕪j
STDMETHODIMP XtraRecipe_IMoaMmXScript::Call (PMoaDrCallInfo callPtr)
{
	moa_try
		switch	( callPtr->methodSelector ) 
		{
			case m_new:
				{
				/* Setup any instance vars for you Xtra here. new() is
				called via Lingo when creating a new instance. */
				}
				break;

*overRide_MethodList*

		}
	moa_catch
	moa_catch_end
	moa_try_end
}

// ***************************************************************************** //
// LingoXNvg֐[`@
// ***************************************************************************** //

