#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	type_fill,
	type_font,
};

//--- modification log
// CPY 6/14/07 Greg found this XF does not work at all, so I have rewritten
// 1. change color control string from "ColorList" to "Color"
// 2. code rewritten as it is very simple and no need to keep original
// Jasmine 08/06/07 MAKE_CELL_COLOR_UNDOABLE
// CPY 2/6/08 UNDO_SHOULD_BE_OPTIONAL


void wcellcolor(const Range& irng, const int& color, const int& type, const int& undo)
{
		
	if(!irng)
		XF_THROW(CER_INVALID_RANGE);
	/// Max 6/15/07 MOVE_OFFSET_TO_BEFORE_EXECUTE
	/*
	//-------  CPY 6/14/07
	int nVal = color;
	if(nVal >=1 && nVal <=24)// 24 is not defined in oc_const.h yet, will need to add this later
		nVal--; // convert from LT color to OC color
	//-------
	*/
	int nVal = okutil_ocolor_LT_color_convert(color, false); // false = LT color to OCOLOR
	/// END MOVE_OFFSET_TO_BEFORE_EXECUTE
	Tree tr;
	if(type == type_font)
		tr.Root.CommonStyle.Color.nVal = nVal;
	else
		tr.Root.CommonStyle.Fill.FillColor.nVal = nVal;
	
	//------ Folger 01/18/08 QA70-10946 SUPPORT_MULTIPLE_SHEETS_OPERATION_WITH_SHEET_RANGE_LIST_CLASS
	//int nErr = irng.UpdateThemeIDs(tr.Root);
	//if(nErr != 0)
		//XF_THROW(XF_OC_METHOD_ERR)
	////---- CPY 2/6/08 UNDO_SHOULD_BE_OPTIONAL
	////irng.ApplyFormat(tr, TRUE, TRUE, TRUE);///Jasmine 08/06/07 MAKE_CELL_COLOR_UNDOABLE
	//irng.ApplyFormat(tr, TRUE, TRUE, undo);
	////----
	SheetRangesList rngList(irng);
	int nNumSheet = rngList.GetNumSheets();
	
	for ( int ii=0; ii<nNumSheet; ++ii )
	{
		DataRange drSub;
		if ( rngList.GetWksSubRange(ii, drSub) )
		{
			int nErr = irng.UpdateThemeIDs(tr.Root);
			if(nErr != 0)
				XF_THROW(XF_OC_METHOD_ERR)
			drSub.ApplyFormat(tr, TRUE, TRUE, undo);
		}
	}
	//-------
	
	
}

//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 wcellcolor_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return wcellcolor_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	
	string strRange = trGetN.irng.strVal;
	if(strRange.IsEmpty())
		strErrMsg = CER_FFT_GET_INPUT_FAIL;
	else
	{
		DataRange dr;
		///Folger 05/22/07 FIX_BUG_ON_VERIFY_RANGE
		//dr.Add("Range1", strRange);
		TreeNode tr = trGetN.irng;
		okxf_resolve_tree_construct_range(&tr, &dr);
		///End FIX_BUG_ON_VERIFY_RANGE
		if(!dr || 1 > dr.GetNumRanges())
			strErrMsg = CER_INVALID_RANGE;
	}
	return false;

}

int wcellcolor_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 wcellcolor_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	//dwCntrl is combination of bits
			
}
//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 wcellcolor_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
