#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	end_quit,
	end_hold,
	end_loop,
};
//put additional include files here
////////////////////////////////////////////////////
// Modification Log ////////////////////////////////
// CPY 8/14/09 QA70-14151-P2 SLIDE_SHOW_THEME_NOT_UPDATING_GUI
///Sophy 3/25/2010 QA80-15232 SLIDE_SHOW_DISPLAY_ON_SAME_MONITOR_AS_ORIGIN_APP_WIN_SUPPORT
// Kyle 09/07/2010 ORG-994-P1 SLIDE_SHOW_CHECK_TIMER_PERIOD
////////////////////////////////////////////////////

///Kyle 09/07/2010 ORG-994-P1 SLIDE_SHOW_CHECK_TIMER_PERIOD
static bool _check_input(TreeNode& trGetN, string* pstrErrMsg = NULL)
{
	if( trGetN.timer.nVal && trGetN.period.dVal <= 0 )
	{
		if( pstrErrMsg )
		{
			*pstrErrMsg = CER_MUST_LARGE_THAN_0;
			*pstrErrMsg += ":" + _L("Timer Period");
		}
		return false;
	}

	return true;
}
///End SLIDE_SHOW_CHECK_TIMER_PERIOD


void pef_slideshow(const int& end, const int& order, const int& timer, const double& period, const int& recursive, const int& embed, const int& info, const string& hint1, const string& hint2, const string& hinttimer, const string& hint3, const string& hint4)
{
	
	vector<string> vsPageSNs;
	    Folder fld = Project.ActiveFolder();
	///Kyle 03/16/2010 QA80-15208 SLIDESHOW_AND_PPTSLIDE_SUPPORT_EMBEDDED_GRAPHS
	//if(get_graph_names(fld, vsPageSNs, recursive, GGNSKIP_HIDDEN_SLIDE, order) < 1)
	if(get_graph_names(fld, vsPageSNs, recursive, GGNSKIP_HIDDEN_SLIDE, order, embed) < 1)
	///End SLIDESHOW_AND_PPTSLIDE_SUPPORT_EMBEDDED_GRAPHS
	{
		/// Iris 10/21/2010 ORG-1303 CLEANUP_XFS_ERROR_CODE
		//warning_msg_box(_L("There is no graph in the folder to show"), false);
		//return;// nothing to do, no graphs at all
		XF_THROW(XF_NO_GRAPH);
		///End CLEANUP_XFS_ERROR_CODE
	}
	
	///Kyle 09/07/2010 ORG-994-P1 SLIDE_SHOW_CHECK_TIMER_PERIOD
	if( timer && period <= 0 )
		XF_THROW_EX(CER_MUST_LARGE_THAN_0,  _L("Timer Period"));
	///End SLIDE_SHOW_CHECK_TIMER_PERIOD
	
	int nTimer = timer? period*1000 : 0;
	DWORD dwCntrl = end;// lowest bits are same
	switch(info)
	{
	case 1:
		dwCntrl |= SLIDE_SHOW_INFOLINE_TOP;
		break;
	case 2:
		dwCntrl |= SLIDE_SHOW_INFOLINE_BOTTOM;
		break;
	}
	///Sophy 3/25/2010 QA80-15232 SLIDE_SHOW_DISPLAY_ON_SAME_MONITOR_AS_ORIGIN_APP_WIN_SUPPORT
	//Project.StartSlideShow(vsPageSNs, nTimer, dwCntrl);
	Project.StartSlideShow(vsPageSNs, nTimer, dwCntrl | SLIDE_SHOW_FOLLOW_ORIGIN);
	///end SLIDE_SHOW_DISPLAY_ON_SAME_MONITOR_AS_ORIGIN_APP_WIN_SUPPORT
	
}

//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 pef_slideshow_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return pef_slideshow_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	string strEventNodeName = lpcszNodeName;
	//---- CPY 8/14/09 QA70-14151-P2 SLIDE_SHOW_THEME_NOT_UPDATING_GUI
	//if(GETNE_ON_INIT == nEventID || (nEventID > 0 && strEventNodeName == "timer"))
	if(GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID || (nEventID > 0 && strEventNodeName == "timer"))
	//-----
	{
		trGetN.period.Show = trGetN.timer.nVal;
		trGetN.hinttimer.Show = trGetN.timer.nVal;
	}
	
	bOKEnable = _check_input(trGetN, &strErrMsg);		///Kyle 09/07/2010 ORG-994-P1 SLIDE_SHOW_CHECK_TIMER_PERIOD
	
	return false;

}

int pef_slideshow_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 pef_slideshow_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	
	///Kyle 09/07/2010 ORG-994-P1 SLIDE_SHOW_CHECK_TIMER_PERIOD
	if( is_xf_startup(nGetNDialog, dwCntrl) )
	{
		if ( (dwCntrl&LTXF_THEME_USED) && nGetNDialog <= 0 )
		{
			if(!_check_input(trGetN))
				nRet = XFEVT_PROCEED_WITH_DLG;
		}
	}
	///End SLIDE_SHOW_CHECK_TIMER_PERIOD
}
//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 pef_slideshow_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
