COMPILE FUNCTION Comm_Dialog_Tool_Mode(Method, Parm1, Parm2, Parm3)

/*
	Commuter module for Dialog_Tool_Mode window.
	
	10/23/2007 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg, obj_Tool_Log
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Popup, Send_Message, SRP_Array

EQU CRLF$	TO \0D0A\

$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT APPCOLORS
$insert IR_INSERTS
$INSERT TOOL_EQUATES

ErrCode  = ''
ErrorMsg = ''
ErrTitle = 'Error in Comm_Dialog_Tool_Mode'

Result   = ''

Begin Case
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'OK'				; GOSUB OK
	CASE Method = 'Cancel'			; GOSUB Cancel
	CASE Method = 'Close'			; GOSUB Close
	CASE Method = 'Refresh'			; GOSUB Refresh
	CASE Method = 'LU_UserID'		; GOSUB LU_UserID
	CASE Method = 'UserIDLF'		; GOSUB UserIDLF
	CASE Method = 'LU_ChgToMode'	; GOSUB LU_ChgToMode
	Case Method = 'EnableOK'        ; GOSUB EnableOK
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
End Case

Return Result


* * * * * * *
Create:
* * * * * * *
obj_AppWindow('Create')

ToolID		= Parm1
ToolRec		= XLATE('TOOL', ToolID, '', 'X')
ToolDesc	= ToolRec<TOOL_TOOL_DESC$>
ToolProc	= ToolRec<TOOL_TOOL_PROC$>

CurrMode = XLATE('TOOL', ToolID, 'CURR_MODE', 'X')<1,1>

IF CurrMode EQ "" THEN
	obj_Tool_Log('InitialLog', ToolID)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END
	CurrMode = 'OUT'
END

* Window title in top bar

WinText = 'Tool Mode Change - ':ToolDesc
Set_Property(@WINDOW, 'TEXT', WinText)

UserName = Oconv(@USER4, '[XLATE_CONV,LSL_USERS*FIRST_LAST]')

Set_Property(@WINDOW:'.USER_ID', 'DEFPROP', @USER4)
Set_Property(@WINDOW:'.USER_NAME', 'DEFPROP', UserName)
Set_Property(@WINDOW:'.REASON', 'FOCUS', 1)
Set_Property(@WINDOW:'.TOOL_ID', 'DEFPROP', ToolID)
Set_Property(@WINDOW:'.CURR_MODE', 'DEFPROP', CurrMode)

ModeData = XLATE('SYSREPOSPOPUPS', 'LSL2**TOOL_MODE', '8', 'X')


Ctrls  = @WINDOW:'.NEW_MODE':@RM				; Props  = 'VISIBLE':@RM
Ctrls := @WINDOW:'.NEW_MODE_GROUP':@RM			; Props := 'VISIBLE':@RM
Ctrls := @WINDOW:'.CHG_TO_MODE':@RM				; Props := 'VISIBLE':@RM
Ctrls := @WINDOW:'.LU_CHG_TO_MODE':@RM			; Props := 'VISIBLE':@RM
Ctrls := @WINDOW:'.CHG_TO_MODE_LABEL'			; Props := 'VISIBLE'			



*IF ToolProc = 'G' THEN

	* GaN process
	
	Vals = '0':@RM:'0':@RM:'1':@RM:'1':@RM:'1'
	Set_Property(Ctrls,Props,Vals)
	
*END ELSE
/*
	* Si Process
	
	Vals = '1':@RM:'1':@RM:'0':@RM:'0':@RM:'0'
	Set_Property(Ctrls,Props,Vals)


	TextVals	= ''
	ValueVals	= ''

	FOR I = 1 TO COUNT(ModeData,@VM) + (ModeData NE '')
		ModeID = ModeData<1,I,1>
		ModeDesc = ModeData<1,I,2>
		IF ModeID NE CurrMode THEN
			TextVals := ModeDesc:@RM
			ValueVals := ModeID:@RM
		END
	NEXT I

	*TextVals[-1,1] = ''		;* Leave the hanging @RM -> These are concatenated  a few lines down
	ValueVals[-1,1] = ''
			
	Ctrls 	 = @WINDOW:'.NEW_MODE.LABELFORMODE1':@RM:@WINDOW:'.NEW_MODE.LABELFORMODE2':@RM:@WINDOW:'.NEW_MODE.LABELFORMODE3':@RM
	Ctrls 	:= @WINDOW:'.NEW_MODE.LABELFORMODE1':@RM:@WINDOW:'.NEW_MODE.LABELFORMODE2':@RM:@WINDOW:'.NEW_MODE.LABELFORMODE3'

	Props	= 'TEXT':@RM:'TEXT':@RM:'TEXT':@RM:'VALUE':@RM:'VALUE':@RM:'VALUE'
	Vals	= TextVals:ValueVals

	Set_Property(Ctrls,Props,Vals)

	DefVal = ValueVals[1,@RM]
	Set_Property(@WINDOW:'.NEW_MODE', 'VALUE', DefVal)
*/

*END	;* End of check for Process flag

RETURN



* * * * * * *
LU_UserID:
* * * * * * *

TypeOver = ''
TypeOver<PSELECT$>	= 1
TypeOver<PDISPLAY$>	= 'BY LAST_FIRST'

UserID = Popup(@WINDOW,TypeOver,'SHOW_USERS')

IF UserID NE '' THEN
	Set_Property(@WINDOW:'.USER_ID','DEFPROP',UserID)
END ELSE
	RETURN
END


* * * * * * *
UserIDLF:
* * * * * * *

UserID = Get_Property(@WINDOW:'.USER_ID','DEFPROP')

UserName = OCONV(UserID,'[XLATE_CONV,LSL_USERS*FIRST_LAST]')
Set_Property(@WINDOW:'.USER_NAME','DEFPROP',UserName)

RETURN


* * * * * * *
LU_ChgToMode:
* * * * * * *

ReturnCtrl = @WINDOW:'.':Parm1


NewMode = Popup(@WINDOW,'','TOOL_MODE')

IF NewMode = '' THEN RETURN

obj_AppWindow('LUValReturn',NewMode:@RM:ReturnCtrl)

RETURN




* * * * * * *
Refresh:
* * * * * * *

RETURN


* * * * * * *
Close:
* * * * * * *


* * * * * * *
Cancel:
* * * * * * *

End_Dialog(@WINDOW,'Cancel')

RETURN


* * * * * *
OK:
* * * * * *

UserID 		= Get_Property(@WINDOW:'.USER_ID', 'DEFPROP')
Reason		= Get_Property(@WINDOW:'.REASON', 'DEFPROP')	
ChgToMode	= Get_Property(@WINDOW:'.CHG_TO_MODE','DEFPROP')

Result  = UserID:@FM:Reason:@FM:ChgToMode



End_Dialog(@WINDOW,Result)

RETURN


* * * * * * *
EnableOK:
* * * * * * *

    ChgToMode	= Get_Property(@WINDOW:'.CHG_TO_MODE','DEFPROP')
    ValidModes  = Xlate('SYSREPOSPOPUPS', 'LSL2**TOOL_MODE', 'DISPLAY', 'X')
    ValidModes  = SRP_Array('Rotate', ValidModes, @VM, @SVM)
    ValidModes  = ValidModes<0, 1>
    Locate ChgToMode in ValidModes using @SVM setting vsPos then
        Enabled = True$
    end else
        Enabled = False$
    end
    Set_Property(@Window:'.OK_BUTTON', 'ENABLED', Enabled)

return



