DECLARE CONSTANT FLD_DefaultSpread AS QUANTITY 40012
DECLARE CONSTANT FLD_DefaultSpreadLabel AS QUANTITY 71
DECLARE CONSTANT n_BtnExpandAdvOpt 			AS  QUANTITY	40000
DECLARE VARIABLE n_FormExpanded				AS 	QUANTITY

DECLARE CONSTANT n_BtnLot1		 			AS  QUANTITY	40020
DECLARE CONSTANT n_BtnLot2		 			AS  QUANTITY	40021
DECLARE CONSTANT n_BtnLot3		 			AS  QUANTITY	40022
DECLARE CONSTANT n_BtnLot4		 			AS  QUANTITY	40023
DECLARE CONSTANT n_BtnLot5		 			AS  QUANTITY	40024
DECLARE CONSTANT n_BtnLot6		 			AS  QUANTITY	40025

DECLARE CONSTANT n_FldLotSize		 		AS  QUANTITY	40010

#data pool objects
DECLARE CONSTANT Datapool_Instrument	AS QUANTITY 1
DECLARE CONSTANT Datapool_QuickLots		AS QUANTITY 4

DECLARE VARIABLE s_CurrentInstrument		AS TEXT 	100

#########################################################
PROCEDURE OnInitForm DO
{
	[n_FormExpanded] := 0;
	
	CALL UpdateQuickLots;	
}

# =================================================================================
PROCEDURE ToggleOrder DO
{
	ShowHideCtrl(FLD_DefaultSpread, 0);
	ShowHideCtrl(FLD_DefaultSpreadLabel, 0);
}

# =================================================================================
PROCEDURE ToggleQuote DO
{
	ShowHideCtrl(FLD_DefaultSpread, 1);
	ShowHideCtrl(FLD_DefaultSpreadLabel, 1);
}


PROCEDURE OnSpin
        DECLARE PARAMETER nControlID	AS QUANTITY
        DECLARE PARAMETER sBuddyValue	AS TEXT
        DECLARE PARAMETER nType			AS QUANTITY DO
{
	DECLARE VARIABLE sCurValue AS TEXT 30
	# nType 0 - UpTick, 1 - DownTick-
	
	# The TICK_FORMAT will be sent as initial string vlue from the back-end
	# The formant is    "min1|tick1|max1|min2|tick2|max2|...minN|tickN|maxN|"
	#
	# where,
	#		N is number of tick entries,
	#		A is integer from one to N
	#
	#		minA, tickA , and maxA  are floaing values and in the order defines 
	#			minimum value, tick size, and maximun value of a tick entry  
	
	DECLARE VARIABLE 	sTickString AS TEXT 300
	
	IF ( ([nControlID] = FLD_DefaultSpread) ) DO
	{
		[sTickString] := GetInitialValueString("TICK_FORMAT");
		SetValueOnTick([nControlID], [sTickString], [sBuddyValue], [nType]);
	}
}

PROCEDURE OnPress
        DECLARE PARAMETER nButtonID as QUANTITY
        DECLARE PARAMETER sButtonName as TEXT DO
{
	IF ( [nButtonID] = n_BtnExpandAdvOpt ) THEN
	{
		IF ( [n_FormExpanded] = 0 ) THEN
		{
			[n_FormExpanded] := 1;
			ChangeControlName(n_BtnExpandAdvOpt, "<<");
		}
		ELSE
		{
			[n_FormExpanded] := 0;
			ChangeControlName(n_BtnExpandAdvOpt, ">>");
		}
		
		DECLARE VARIABLE nID 				AS QUANTITY
		DECLARE VARIABLE sWndID				AS TEXT 20
		DECLARE VARIABLE sLayoutCtrlID		AS TEXT 20				
		DECLARE VARIABLE sBtnID				AS TEXT 20
		DECLARE VARIABLE sExpandState		AS TEXT 20
		
		[nID] 			:= GetWndID();
		[sBtnID]		:= IntToString( n_BtnExpandAdvOpt );		
		[sWndID] 		:= IntToString( [nID] );
		[sLayoutCtrlID] := IntToString( GetCtrlIDByName("OrderEntry") );
		[sExpandState]  := IntToString( [n_FormExpanded] );
		
		ExecExtSrciptProc("OnExpandButtonClicked", [sWndID], [sLayoutCtrlID], [sBtnID], [sExpandState]);	
	} ELSE IF ( ( [nButtonID] >= n_BtnLot1 ) AND ( [nButtonID] <= n_BtnLot6) ) DO
	{
		DECLARE VARIABLE nQuickVal 	AS	QUANTITY
		DECLARE VARIABLE nLotSize 	AS	QUANTITY
		[nQuickVal] := StringToInt( GetFieldValue1([nButtonID]) );

		IF ( [s_CurrentInstrument] != "" ) THEN
		{
			DECLARE VARIABLE sLotSize 	AS TEXT		30
		
			[sLotSize] := "";
			[sLotSize] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], 3);		
		
			[nLotSize] := StringToInt([sLotSize]);
		}
		ELSE
		{
			[nLotSize] := 1;
		}
	
		
		DECLARE VARIABLE nCumLotSize	AS	QUANTITY
		[nCumLotSize] := ( [nQuickVal] * [nLotSize] );
		
		DECLARE VARIABLE sSize 					AS TEXT		30
		[sSize] := IntToString([nCumLotSize]);
				
		DECLARE VARIABLE nID 				AS QUANTITY
		DECLARE VARIABLE sWndID				AS TEXT 20
		DECLARE VARIABLE sLayoutCtrlID		AS TEXT 20
		
		[nID] 			:= GetWndID();
		[sWndID] 		:= IntToString( [nID] );
		[sLayoutCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_OrderEntry") );
		
		ExecExtSrciptProc("SetSize", [sWndID], [sLayoutCtrlID], [sSize]);
		
		[sLayoutCtrlID] := IntToString( GetCtrlIDByName("OrderEntry_DebtOrderEntry") );
		ExecExtSrciptProc("SetSize", [sWndID], [sLayoutCtrlID], [sSize]);
	}
}

PROCEDURE SetPreferenceOptions DO 
{
	CALL OnPress n_BtnExpandAdvOpt, "" ; 
}

#########################################################
PROCEDURE UpdateQuickLots DO
{
	DECLARE VARIABLE	sObjKey 		AS TEXT		30	
	DECLARE VARIABLE	sQuickLotVal 	AS TEXT		30
	DECLARE VARIABLE	nVal		 	AS QUANTITY
	
	[sObjKey] := GetObjPoolItemKey(Datapool_QuickLots, 0);
	[nVal]			:= 0;
	
	WHILE ( [nVal] < 6 ) DO
	{
		[sQuickLotVal]  := GetObjPoolItemVal(Datapool_QuickLots, [sObjKey], [nVal]);
		ChangeControlName( (n_BtnLot1 + [nVal]), [sQuickLotVal] );
		
		[nVal] := ( [nVal] + 1 );
	}	
}

###############################################################################
PROCEDURE OnNotifySelectInstrument 
	DECLARE PARAMETER sInstrument AS TEXT 
	DECLARE PARAMETER sSymbol  	  AS TEXT DO
{
	[s_CurrentInstrument] := [sInstrument];
	
	IF ( [sInstrument] != "" ) THEN
	{
		DECLARE VARIABLE sLotSize 	AS TEXT		30
		
		[sLotSize] := "";
		[sLotSize] := GetObjPoolItemVal(Datapool_Instrument, [s_CurrentInstrument], 3);		
		
		SetFieldValue1(n_FldLotSize, [sLotSize]);
	}
	ELSE
	{
		SetFieldValue1(n_FldLotSize, "");
	}
}

##########################################################
PROCEDURE SetBkgColor
		 DECLARE PARAMETER sRVal AS TEXT
		 DECLARE PARAMETER sGVal AS TEXT 
		 DECLARE PARAMETER sBVal AS TEXT DO
{
	SLogLine("SetBkgColor - Advanced Options");
	
	DECLARE VARIABLE nRed	AS QUANTITY
	DECLARE VARIABLE nGreen	AS QUANTITY
	DECLARE VARIABLE nBlue	AS QUANTITY
	
	[nRed]   := StringToInt([sRVal]);
	[nGreen] := StringToInt([sGVal]);
	[nBlue]  := StringToInt([sBVal]);
	
	IF ( [nRed] != 236 ) DO
	{
		SetBackColor([nRed], [nGreen], [nBlue], 1);
	}	
	
}
##########################################################
PROCEDURE RemoveSingleClick
                 DECLARE PARAMETER sRVal AS TEXT DO
{
        IF ( [sRVal] = "0" ) THEN
        {
                SetCheck(40011,1);

                SLogLine("Remove Single Click 1");
        }
        ELSE
{

                SetCheck(40011,0);
                SLogLine("Remove Single Click 0");
        }

}
