// modification log
//CPY 12/6/06 QA70-12736 LT_NEED_MORE_CNTRL_ON_ALLOWING_OC_FUNCS
//CPY 10/1/08 QA70-12321 ADD_LT_WAY_TO_FORCE_XF_COMPILE
//Kenny 6/9/2009 ADD_SUPPORT_TO_COMPILE_AND_INIT_VERTICAL_CURSOR
//Kenny 6/11/2009 FORCE_COMPILE_OC_SOURCE_CODE_FOR_VERTICAL_CURSOR
//CPY 7/19/09 SCROLLBAR_MSG_DUMP_TO_SCRIPT_WIN_SHOULD_BE_PREVENTED
//CPY QA70-14088 FFT_FILTER_PREVIEW_RESCALE_TRIANGLE_LEAD_TO_INFINITE_REFRESH
//CPY 9/30/09 QA70-14403 PREVIEW_GRAPH_SHOULD_NEVER_RESCALE_ON_CHANGE
///Sophy 11/6/2009 QA80-14598-P1 FORCE_XF_COMPILE_WHEN_CLICK_ATTACH_GROBJ_AFTER_LOAD_GRAPPH
/// Folger 01/12/09 QA81-14832 QUICKFIT_ROI_OBJECTS_SHOULD_BE_REMOVED_AFTER_OPEN_NLFIT_FROM_CONTEXT_MENU
/// CPY 1/22/10 QA81-15020 CLOSE_BUTTON_USE_SIMPLER_LT_BASED_CODE
///Sophy 2/22/2010 QA81-14930 IMPROVE_CODE_FOR_ROI_TOOLS
///Jasmine 03/09/10 NEW_DLG_FOR_IMAGE_PROFILE
///Kyle 06/04/2010 ADD_READ_OUT_FOR_HV_PROFILE
/// TD ML ORG-288 06-29-2010 PREVENT_REENTRY_IN_ImageProfile_ReadOut
/// Folger 11/01/2010 ORG-27 NEW_DIGITIZER_GADGET
[ZoomRectMove]
	//%1 = layer index to rescale;
	page -s; // clear selection first
	_graphname$=%H; // in order for this to work in a dialog, cannot assume active window name
	_layer_index=page.active;
	plot -V;
	queue {
		win -o _graphname$ {
			layer -o $(_layer_index+1) {
				x1=v1;y1=v2;x2=v3;y2=v4;
			}
		}
	}
//---- CPY QA70-14088 FFT_FILTER_PREVIEW_RESCALE_TRIANGLE_LEAD_TO_INFINITE_REFRESH
// old code removed, can find from VSS
////////////////////////////////////////////////
////////////////////////////////////////////////
/////////////Axis Scroller Triangle Begin  /////
[XScaleTriangleObjOnMove]
	page -s;
	_graphname$=%H; // in order for this to work in a dialog, cannot assume active window name
	_was_layer=page.active;
	_was_new_x = this.x;
	_was_X1=%1;
	//using queue lost this and also need to temp disable script so it will not repeat on-move
	queue {
		//type "%H, but %(_graphname$)";
		win -o _graphname$ {
			layer -o $(_was_layer) {
				if(_was_X1>0) {
					X1=_was_new_x;
					Xmin.Script=0;Xmin.x = X1;Xmin.Script=2;
				}
				else {
					X2=_was_new_x;
					Xmax.Script=0;Xmax.x = X2;Xmax.Script=2;				
				}
				del -v _was*;
			}
		}
	}
	
[XScaleMax]
	run.Section(,XScaleTriangleObjOnMove,0);
	
[XSCaleMin]
	run.Section(,XScaleTriangleObjOnMove,1);

/////////////Axis Scroller Triangle end    /////
////////////////////////////////////////////////
////////////////////////////////////////////////
//---- end FFT_FILTER_PREVIEW_RESCALE_TRIANGLE_LEAD_TO_INFINITE_REFRESH

////////////////////////////////////////////////
//////// Axis Scrollbar Begin //////////////////
[AxisScrollBarEvents]
	// assume nEvent already declared
	int nX = %1;
	if(nEvent == 7 || nEvent == 500) //OE_SELECT, WIN_OPEN
	{
		if(exist(graph_scrollbar_events,20)==0)
		{
			run.LoadOC(OriginLab\AxisScrollbar.c, 16);
			if(exist(graph_scrollbar_events,20)==0)
				return 1;
		}
	}
	string strName$ = this.Name$;
	int ii = 1;
	run -oc {
		ii=graph_scrollbar_events(nEvent, strName$, nX);
	}
	return ii;
//---- end SCROLLBAR_MSG_DUMP_TO_SCRIPT_WIN_SHOULD_BE_PREVENTED

//----- CPY 1/5/07 OGS_BASED_AXIS_SCROLLER_RECT	
// this assume proper LT codes in graph_controls.ogs
// scrollbar rect will be called xScrollbar if bHorizontal, or yScrollbar if bHorizontal=false
// and it has a rect inside called xScrollThumb or yScrollThumb
[XScroll]
	int nEvent = %1;
	if(nEvent > 0)
		run.Section(,AxisScrollBarEvents,1);		
	
	
[YScroll]
	int nEvent = %1;
	if(nEvent > 0)
	if(nEvent > 0)
		run.Section(,AxisScrollBarEvents,0);
	
//////// Axis Scrollbar end //////////////////
////////////////////////////////////////////////
	
//----------- CPY 10/1/08 QA70-12321 ADD_LT_WAY_TO_FORCE_XF_COMPILE	
[GraphTool]
	//type "%1 %2";
	int nEvent = %1;
	if(exist(%2_events,20) == 0)
	{
		//if(nEvent==2 || nEvent == 4)// end of move or size
		if( nEvent==1 || nEvent==2 || nEvent == 4 || nEvent == 505 )// Sandy 2009-2-27 add event == 1 for button up ///Sophy 12/9/2009 add nEvent == 505, when graph rescale, also need to force result updated.
			%2 -hn;
		///Sophy 2/4/2010 QA80-15080 VERSION_CHECKING_FOR_ROI_COMPATIBILITY
		else if ( nEvent == 500 ) //page open
			%2 -hn;
		///end VERSION_CHECKING_FOR_ROI_COMPATIBILITY
		else
			return 0;
	}
	
	///Sophy 2/22/2010 QA81-14930 IMPROVE_CODE_FOR_ROI_TOOLS
	if ( nEvent == 506 ) //OE_UPDATE, since for ROI tool no need to handle this event, so to skip initilization of ROI object for saving time.
		return 0;
	///end IMPROVE_CODE_FOR_ROI_TOOLS
	
	%2_events(this.name$,%1, 0x00010000);		/// GROBJEVENTS_FROM_EVENT_FUNCTION

//----------- end ADD_LT_WAY_TO_FORCE_XF_COMPILE

///Sophy 1/5/2010 QA80-14904-S1 CLEAN_CODE_FOR_ROI_TOOLS
[GraphToolEvent]
	if ( exist(%1_events, 20) == 0 ) //event function not exist, compile it first
		%1 -hn;
	
	///Sophy 2/22/2010 QA81-14930 IMPROVE_CODE_FOR_ROI_TOOLS
	int nEvent = %3;
	if ( nEvent == 506 ) //OE_UPDATE, since for ROI tool no need to handle this event, so to skip initilization of ROI object for saving time.
		return 0;
	///end IMPROVE_CODE_FOR_ROI_TOOLS
	%1_events(%2, %3, %4);
	
///Sophy 1/25/2010 LT_COMMAND_TO_REMOVE_ALL_LINKED_OBJECTS
//[DestroyObjects]
	////%1 is the main object name
	//StringArray sa;
	//layer -o [%1]%2 { label -lr %3 sa; }
	//for ( int ii = 1; ii <= sa.GetSize(); ii++ )
	//{
		////;label -r %(sa.GetAt(ii)$); //this code fail to delay destroy object
		//run.section(, DelayDestroy, %1 %2 %(sa.GetAt(ii)$));
	//}
	//
	
///end LT_COMMAND_TO_REMOVE_ALL_LINKED_OBJECTS
[DelayDestroy]
	;label -rc %1;
///end CLEAN_CODE_FOR_ROI_TOOLS

//---- CPY 1/22/10 QA81-15020 CLOSE_BUTTON_USE_SIMPLER_LT_BASED_CODE
[OnROICloseButton]
	run.section(, DelayDestroy, %(this.name$));
//----


///------ Folger 01/12/09 QA81-14832 QUICKFIT_ROI_OBJECTS_SHOULD_BE_REMOVED_AFTER_OPEN_NLFIT_FROM_CONTEXT_MENU
[ShowObjects]
	StringArray sa;
	label -lr %1 sa;
	for ( int ii = 1; ii <= sa.GetSize(); ii++ )
	{
		%A=%(sa.GetAt(ii)$);
		%A.Show=%2;
	}
///------ End QUICKFIT_ROI_OBJECTS_SHOULD_BE_REMOVED_AFTER_OPEN_NLFIT_FROM_CONTEXT_MENU

///Kenny 6/9/2009 ADD_SUPPORT_TO_COMPILE_AND_INIT_VERTICAL_CURSOR
[VertCursor]
	// nEvent, nObjType(VCOT_LINE=0,VCOT_TEXT_LABEL=1,VCOT_TAG=2,VCOT_TAG_LABEL=3)
	/*string strObjType;
	int nObjType = %2;
	if(0 == nObjType)
		strObjType$ = "VCOT_LINE";
	else if(1 == nObjType)
		strObjType$ = "VCOT_TEXT_LABEL";
	else if(2 == nObjType)
		strObjType$ = "VCOT_TAG";
	else
		strObjType$ = "VCOT_TAG_LABEL";
	type "event = %1\t objType = %(strObjType$)\t name = %(this.name$)";*/

	int nEvent = %1;
	if (exist(CheckInitVerticalCursorAndExecEvent, 20) == 0)
	{
		//if( nEvent == 1 || nEvent == 2 || nEvent == 4)
		if( nEvent >=2 && nEvent <= 5 || 7 == nEvent)	// 2~5, for OE_MOVE,OE_MOVING,OE_RESIZE,OE_RESIZING,OE_SELECT
		{
			verticalcursor -hn;
			run.LoadOC(OriginLab\VerticalCursorDlg.c, 16);	///Kenny 6/11/2009 FORCE_COMPILE_OC_SOURCE_CODE_FOR_VERTICAL_CURSOR
		}
		else
			return 0;
	}
	CheckInitVerticalCursorAndExecEvent(%1, this.name$, %2);	// nEvent, strObjectName, nObjType
///End ADD_SUPPORT_TO_COMPILE_AND_INIT_VERTICAL_CURSOR

///Jasmine 03/09/10 NEW_DLG_FOR_IMAGE_PROFILE
[ImageProfile]
	/// TD ML ORG-288 06-29-2010 PREVENT_REENTRY_IN_ImageProfile_ReadOut
	if(1 != bInIPf)
	{
	/// end PREVENT_REENTRY_IN_ImageProfile_ReadOut 
	int nEvent = %1;
	if (exist(CheckInitImageProfileDlgAndExecEvent, 20) == 0)
	{
		if( nEvent >=2 && nEvent <= 5 || 7 == nEvent)	// OE_MOVE,OE_MOVING,OE_RESIZE,OE_RESIZING
		{
			imageprofile -hn;
			run.LoadOC(OriginLab\ImageProfile.c, 16);
		}
		else
			return 0;
	}
	//CheckInitImageProfileDlgAndExecEvent(%1, this.name$);	// nEvent, strObjectName
	bInIPf = 1;	/// TD ML ORG-288 06-29-2010 PREVENT_REENTRY_IN_ImageProfile_ReadOut
	CheckInitImageProfileDlgAndExecEvent(%1, this.Attach$, this.name$);	// nEvent, strLayerName, strObjectName
	/// TD ML ORG-288 06-29-2010 PREVENT_REENTRY_IN_ImageProfile_ReadOut
	bInIPf = 0;
	del -v bInIPf;
	 
	 }
	/// end PREVENT_REENTRY_IN_ImageProfile_ReadOut 
///End NEW_DLG_FOR_IMAGE_PROFILE

///Kyle 06/04/2010 ADD_READ_OUT_FOR_HV_PROFILE
[ImageProfile_ReadOut]
	/// TD ML ORG-288 06-29-2010 PREVENT_REENTRY_IN_ImageProfile_ReadOut
	if(1 != bInIPfR)
	{
	/// end PREVENT_REENTRY_IN_ImageProfile_ReadOut 
	int nEvent = %1;
	if (exist(OnHVProfileReadOutChange, 20) == 0)
	{
		if( nEvent >=2 && nEvent <= 5 || 7 == nEvent)	// OE_MOVE,OE_MOVING,OE_RESIZE,OE_RESIZING
		{
			imageprofile -hn;
			run.LoadOC(OriginLab\ImageProfile.c, 16);
		}
		else
			return 0;
	}
		
	bInIPfR = 1;	/// TD ML ORG-288 06-29-2010 PREVENT_REENTRY_IN_ImageProfile_ReadOut
	OnHVProfileReadOutChange(%1, this.Attach$, this.name$);	// nEvent, strLayerName, strObjectName
	/// TD ML ORG-288 06-29-2010 PREVENT_REENTRY_IN_ImageProfile_ReadOut
	bInIPfR = 0;
	del -v bInIPfR;
	 
	 }
	/// end PREVENT_REENTRY_IN_ImageProfile_ReadOut 

///End ADD_READ_OUT_FOR_HV_PROFILE

//------ CPY 11/07/08 QA70-12403 TOOLS_FOR_XF_PREVIEW_DLG_LIKE_SMOOTH
//------ CPY 2/6/09 Pointer tool is removed due to popular request, see also
//http://beta.originlab.com/forum/topic.asp?TOPIC_ID=2809
[XFPreviewTools]
	int nTool = %1;
	//nTool=;
	switch(nTool)
	{
	case 1:
		doTool 1;//zoom tool
		break;
	case 2:
		doTool 16;//unzoom tool
		break;
	//---- CPY 9/30/09 QA70-14403 PREVIEW_GRAPH_SHOULD_NEVER_RESCALE_ON_CHANGE
	case 3:
		layer -all ask;//same as toolbar code 
		break;
	//----
	}
//------ end TOOLS_FOR_XF_PREVIEW_DLG_LIKE_SMOOTH

///------ Folger 11/01/2010 ORG-27 NEW_DIGITIZER_GADGET
[Digitizer]	
	int nEvent = %1;
	if ( exist(digitizer_events, 20) == 0 )
	{
		if ( nEvent == 2 || nEvent == 6 || nEvent == 500 || nEvent == 502 )	/// OE_MOVE, OE_WIN_OPEN, OE_WIN_ACTIVATE
		{
			;digitizer -hn;run.LoadOC(OriginLab\Digitizer.cpp, 16);
		}
	}
	
	if ( nEvent == 2 || nEvent == 6 )		/// OE_MOVE, OE_DELETE
	{
		digitizer_events(nEvent, %2);
	}
///------ End NEW_DIGITIZER_GADGET
