#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	type_ai,
	type_bmp,
	type_cgm,
	type_dxf,
	type_emf,
	type_eps,
	type_gif,
	type_jpg,
	type_pcx,
	type_pdf,
	type_png,
	type_psd,
	type_tga,
	type_tif,
	type_wmf,
};
enum{
	export_active,
	export_book,
	export_folder,
	export_recursive,
	export_project,
	export_specified,
};
enum{
	overwrite_rename,
	overwrite_replace,
	overwrite_skip,
	overwrite_ask,
};
//put additional include files here
#include <image_utils.h>
#include <okocUtils.h>
#include <..\OriginLab\PathTrack.h>

#include <..\Originlab\ODlg8.h> ///---Sim 08-16-2007 ADD_MORE_OPTIONS_ON_OVER_WRITE
#include <control.h>
#include <ocGDI.h> //------- CPY 10/6/06 EMF_PREVIEW
//#include <..\Originlab\theme_utils.h>
/// Hong 11/07/07 v8.0742 FIX_EXP_GRAPH_FAIL_COMPILE
#ifdef _FOR_SMART_LOADING_ONLY
#include <..\originlab\AxisScrollbar.h>
#include <..\originlab\grobj_utils.h>
#endif //_FOR_SMART_LOADING_ONLY
/// end FIX_EXP_GRAPH_FAIL_COMPILE
#include <..\Originlab\GraphicalExport.h>

//#define _TEST_SPEED
#ifdef _TEST_SPEED
#include <profiler.h> //CPY 4/23/07 
#endif // _TEST_SPEED

/**
 *	Modification Log:
 	/// Hong 04/13/09 QA80-13280 EXP_SINGLE_WKS_TO_MILTI_PAGES_PDF
 	/// Hong 06/16/09 FIX_DPI_SETTING_IS_LOST_AFTER_CLICK_OK
 	/// Hong 07/21/09 QA80-13280-P4 WKS_EXPORT_MULTIPAGE_PDF_PAGE_BREAKS
 	/// Hong 09/18/09 FIX_FAIL_DESTROY_STATIC_OBJECT_IF_CLOSE_EXPPDFW_LEAD_EXPGRAPH_FAIL_TO_OPEN
*/


//static CGraphicalExportWksEx 	s_wksExport;



void expPDFw(const int& type, const int& export, const string& pages, const string& filename, const string& path, const int& overwrite, const int& sysopts, const TreeNode& tr, const int& keepsize, const TreeNode& tr1, const TreeNode& tr2, const TreeNode& tr3)
{
	/// Hong 04/13/09 QA80-13280 EXP_SINGLE_WKS_TO_MILTI_PAGES_PDF
	//InvokeExpGraph(type, export, pages, filename, path, overwrite, sysopts, tr, keepsize, tr1, tr2);
	InvokeExpGraph(type, export, pages, filename, path, overwrite, sysopts, tr, keepsize, tr1, tr2, NULL, true);
	/// end EXP_SINGLE_WKS_TO_MILTI_PAGES_PDF
}

//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 expPDFw_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return expPDFw_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	/// Hong 06/16/09 FIX_DPI_SETTING_IS_LOST_AFTER_CLICK_OK
	if ( GETNE_ON_OK == nEventID )
		return true;
	/// end FIX_DPI_SETTING_IS_LOST_AFTER_CLICK_OK
	
	///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
	TreeNode			trNode;
	trNode = tree_get_node_by_tagname(trGetN, lpcszNodeName, true);
	DWORD				dwUpdateGraph;
	/// Hong 07/21/09 QA80-13280-P4 WKS_EXPORT_MULTIPAGE_PDF_PAGE_BREAKS
	//InvokeOnChange(trGetN, trNode, dwUpdateGraph, dwEnables, strErrMsg);
	InvokeOnChange(trGetN, trNode, dwUpdateGraph, dwEnables, strErrMsg, true);
	/// end WKS_EXPORT_MULTIPAGE_PDF_PAGE_BREAKS
	
	return true;	

}

int expPDFw_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	/// Hong 04/13/09 QA80-13280 EXP_SINGLE_WKS_TO_MILTI_PAGES_PDF
	//int		nRet = InvokeMakeTree(tr, lpcszVarName, false);
	int		nRet = InvokeMakeTree(tr, lpcszVarName, false, true);
	/// end EXP_SINGLE_WKS_TO_MILTI_PAGES_PDF
	return nRet;
}
//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 expPDFw_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	/// Hong 04/13/09 QA80-13280 EXP_SINGLE_WKS_TO_MILTI_PAGES_PDF
	//InvokeBeforeExecute(trGetN, nGetNDialog, nRet, dwCntrl);
	InvokeBeforeExecute(trGetN, nGetNDialog, nRet, dwCntrl, true);
	/// end EXP_SINGLE_WKS_TO_MILTI_PAGES_PDF
}
//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 expPDFw_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	/// Hong 09/18/09 FIX_FAIL_DESTROY_STATIC_OBJECT_IF_CLOSE_EXPPDFW_LEAD_EXPGRAPH_FAIL_TO_OPEN
	if ( GETNE_ON_DESTORY == nEventID )
	{
		InvokeOnDestroy();
		return true;
	}
	/// end FIX_FAIL_DESTROY_STATIC_OBJECT_IF_CLOSE_EXPPDFW_LEAD_EXPGRAPH_FAIL_TO_OPEN
	
	return false;
}
