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

//put additional include files here
#include <..\originlab\theme_utils.h>
//#include <event_utils.h>
//put your own support static functions here

///Jake 06/25/07 v8.0648 ADD_ERROR_CHECKING
static bool _check_error(TreeNode trGetN, string& strErrMsg)
{
	DataRange cellRange;
	TreeNode trCell = trGetN.cell;
	okxf_resolve_tree_construct_range(&trCell, &cellRange);
	if(!cellRange)
	{
		strErrMsg = XFERR_INVALID_RANGE;
		return true;
	}
	int nRangNum = cellRange.GetNumData();
	if(!nRangNum)
	{
		strErrMsg = XFERR_INVALID_RANGE;
		return true;
	}
	return false;
}
///end 06/25/07 ADD_ERROR_CHECKING


void insertNotes(const string& str, Range& cell)
{
	///Jake 06/25/07 v8.0648 ADD_ERROR_CHECKING
	int nRangNum = cell.GetNumData();
	if(!nRangNum)
		XF_THROW(XFERR_INVALID_RANGE);
	///end ADD_ERROR_CHECKING
	
	Worksheet wks;
	int r1,r2,c1,c2;
	cell.GetRange(0, r1, c1, r2, c2, wks);
	if(!wks)
		XF_THROW(XFERR_INVALID_ARG)
	
	for(int nC = c1; nC<= c2; nC++)
	{
		Note npg;
		npg.Create();
		npg.Text = str;
		/// TD 10-10-2007 QA80-10510 UNDO_SUPPORT_FOR_ATTACHMENTS_IN_WKS_CELL
		//wks.EmbedNote(r1, nC, npg);
		wks.EmbedNote(r1, nC, npg, EMBEDGRAPH_DO_UNDO);
		/// end UNDO_SUPPORT_FOR_ATTACHMENTS_IN_WKS_CELL
	}
	
	//wks_set_cell_heights(wks, c1, c1, 200, true);
	//wks_set_cell_heights(wks, r1, r1, 600, 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 insertNotes_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	
	if(nGetNDialog > 0 && (dwCntrl & LTXF_FROM_GUI_MENU))
		nRet = XFEVT_PROCEED_NO_DLG;
	
}
