#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	type_short,
	type_byte,
};
//put additional include files here
#include <GetNBox.h>
#include <image_utils.h>
#include <..\Originlab\matdata_utils.h>
//put your own support static functions here

/*------------------------------------------------------------------------------*
 * Modification Log:															*
 *	Folger 02/03/09 QA80-13032 SUPPORT_COPY_LAYER_SCALE_FOR_COPY_IMAGE_DATA		*
 *------------------------------------------------------------------------------*/
 

void img2m(const Image& img, MatrixObject& om, const int& type)
{
	
	
	vector<int> vType = {FSI_SHORT, FSI_BYTE};
	// since imgi might be same as mo, so we better make a copy of Lbmp first
	Image imgTemp;
	///------ Folger 02/03/09 QA80-13032 SUPPORT_COPY_LAYER_SCALE_FOR_COPY_IMAGE_DATA
	if ( !(om.HasImage() && (DWORD)om.GetLeadBitmap() == (DWORD)img.GetLBmp()) )
		imgTemp.Init(img);
	else
	///------ End SUPPORT_COPY_LAYER_SCALE_FOR_COPY_IMAGE_DATA
		imgTemp.SetLBmp(img.GetLBmp(), true);	
	int nGray = (type == type_short? 16 :8);	
	
	if(!om.SetInternalDataType(vType[type], OCD_RESET_VIEW))
		XF_THROW(MATOBJ_FAILED_LT_BMP);	
	///------ Folger 02/03/09 QA80-13032 SUPPORT_COPY_LAYER_SCALE_FOR_COPY_IMAGE_DATA
	//imgTemp.CopyTo(om, true, nGray);
	imgTemp.CopyTo(om, true, nGray, IMAGE_COPY_SCALE);	
	///------ End SUPPORT_COPY_LAYER_SCALE_FOR_COPY_IMAGE_DATA
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int img2m_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return img2m_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	///Kyle 09/24/08 SET_NO_NEED_TO_LOCALIZE
	if ( GETNE_ON_INIT == nEventID )
	{
		trGetN.type.SetAttribute(STR_OCNTRL_OPTNS, OCNTRLPARAM1_NOT_LOCALIZED);
	}
	///End SET_NO_NEED_TO_LOCALIZE
	
	return false;

}

int img2m_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	
	return -1;  // to indicate no need for any tree var
	
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void img2m_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int img2m_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
