#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>

static void _set_params(int keepAspRatio,int hideAxes,int hideLegends,int hidetexts, DWORD& dwEmbedParamsAdd, DWORD& dwEmbedParamsRemove)
{
		dwEmbedParamsAdd = 0;
		dwEmbedParamsRemove = 0; 
	    if(keepAspRatio)dwEmbedParamsAdd |= EMBEDGRAPH_KEEP_ASPECT_RATIO;
	    else dwEmbedParamsRemove  |= EMBEDGRAPH_KEEP_ASPECT_RATIO;
	    
	    if(hideAxes)dwEmbedParamsAdd |= EMBEDGRAPH_HIDE_AXES ;
	    else dwEmbedParamsRemove  |= EMBEDGRAPH_HIDE_AXES ;
	    
	    if(hideLegends)dwEmbedParamsAdd |= EMBEDGRAPH_HIDE_LEGENDS;
	    else dwEmbedParamsRemove  |=EMBEDGRAPH_HIDE_LEGENDS;
	
	    if(hidetexts)dwEmbedParamsAdd |= EMBEDGRAPH_HIDE_TEXT_OBJS ;
	    else dwEmbedParamsRemove  |= EMBEDGRAPH_HIDE_TEXT_OBJS ;
	      
}


void updateEmbedGraphs(Range& rng, const int& keepaspect, const int& axes, const int& legends, const int& texts)
{
	Worksheet wks;
	int r1,r2,c1,c2;
	int nRange = rng.GetNumData();
	
	for(int ii = 0;ii < nRange; ii++)
	{
		rng.GetRange(ii, r1, c1, r2, c2, wks);
		if(!wks)
			XF_THROW(XFERR_INVALID_ARG); 
		///---Sim 12-18-2007 FIX_WHOLE_SHEET_RANGE
		if ( r2 < 0 )
			r2 = wks.GetNumRows() - 1;
		if ( c2 < 0 )
			c2 = wks.GetNumCols() - 1;
		///---END FIX_WHOLE_SHEET_RANGE
		for(int nC = c1; nC <= c2; nC++)
		{
			for(int nR=r1; nR <= r2; nR++)
			{
				//wks.GetEmbeddingParams(nR, nC, dwEmbedParams);
				//SetParams(keepaspect, axes, legends, texts, dwEmbedParams);
				DWORD dwEmbedParamsAdd= 0;
				DWORD dwEmbedParamsRemove= 0;
				_set_params(keepaspect, axes, legends, texts, dwEmbedParamsAdd, dwEmbedParamsRemove);
				if(dwEmbedParamsAdd)
					wks.SetEmbeddingParams(nR, nC, dwEmbedParamsAdd, TRUE);
				if(dwEmbedParamsRemove)
					wks.SetEmbeddingParams(nR, nC, dwEmbedParamsRemove, FALSE);
			}
		}
	}
}

//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 updateEmbedGraphs_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return updateEmbedGraphs_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false; 

}

int updateEmbedGraphs_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false;
}
//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 updateEmbedGraphs_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 updateEmbedGraphs_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
