Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #LRNG_SRV)

* Global Vars
Define Field(#ret_code) Type(*char) Length(2)
Define Field(#lr_wkSep) Type(*char) Length(1)

* List Definitions
Define Field(#line) Type(*char) Length(1000) Input_Atr(LC)
Def_List Name(#formData) Fields(#line) Counter(#listentry) Type(*Working) Entrys(*MAX)

* Properties
Define_Com Class(#prim_alph) Name(#sPath)
Define_Pty Name(layoutPath) Get(*auto #sPath) Set(*auto #sPath)

Define_Com Class(#PRIM_ALPH) Name(#errorString)

Mthroutine Name(loadLayout)
* Maps
Define_Map For(*input) Class(#PRIM_ALPH) Name(#layout)

* Coms
Define_Com Class(#PRIM_ALPH) Name(#fullPath)
Define_Com Class(#PRIM_ALPH) Name(#data)


#fullPath := #com_owner.layoutPath + #layout
Use Builtin(TRANSFORM_FILE) With_Args(#formData #fullPath 'T') To_Get(#ret_code)

If (#ret_code *EQ ER)

#LRNGERRORHANDLER.AddError Message(#COM_OWNER.Name + ' Layout (001) : Layout "' + #fullPath + '"  could not be loaded. Check the layout file name and layout path.')

Endif


Endroutine


Mthroutine Name(inflate)
* Parent Parms
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parent) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#intopopover) Mandatory('')
* Index parms
Define_Map For(*INPUT) Class(#PRIM_NMBR) Name(#index) Mandatory(0)
* Just parms
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm01) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm02) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm03) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm04) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm05) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm06) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm07) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm08) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm09) Mandatory('')
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#parm10) Mandatory('')

* Define Coms
Define_Com Class(#PRIM_ALPH) Name(#currentLevel)
Define_Com Class(#PRIM_ALPH) Name(#currentField)
Define_Com Class(#PRIM_ALPH) Name(#subForm)
Define_Com Class(#PRIM_ALPH) Name(#overrideParent)
Define_Com Class(#PRIM_ALPH) Name(#lrprops)

* Set Seperator
Use Builtin(HextoBin) With_Args(FF) To_Get(#lr_wkSep)


#COM_OWNER.AppTraceOn

#COM_OWNER.AppTrace Text(#COM_OWNER.Name + 'Parent is ' + #parent)
#COM_OWNER.AppTrace Text(#COM_OWNER.Name + 'Popover is ' + #intopopover)


* Check if Parent or Popover
If (#intopopover *NE *BLANK)
If (#parent *EQ *blank)
#parent := #intopopover + '.popover'
#lrprops += #lr_wkSep + #parent + '.type:FORM'
Else
#LRNGERRORHANDLER.AddError Message(#COM_OWNER.Name + ' Layout Error (002) : Both Parent and IntoPopover cannot be used on inflate')
Goto Label(end)
Endif
Else
If (#parent *EQ *blank)
#parent := '/Form'
Endif

Endif

* We will Find Either a <FORM> <GRID> or <FIELD> as we move thru the list mark the level
Selectlist Named(#formData)

* Ignore blank lines and comments
Continue If((#line *EQ *blank) *Or ((#line.PositionOf( '/*' ) *EQ 1)))

* Check for valid Level marker

If ((#line.Contains( '<' )) *And (#line.Contains( '>' )))

If ((#line.UpperCase.contains( 'FORM' )) *Or (#line.UpperCase.contains( 'GRID' )) *Or (#line.UpperCase.contains( 'FIELD' )))
Else
#LRNGERRORHANDLER.AddError Message(#COM_OWNER.Name + ' Layout Error (003) : Invalid level marker specified ' + #line)
Continue
Endif

Endif

* Check for Level Change set current Level
* Should find <FORM> first
If (#line.UpperCase.contains( '<FORM>' ))
#currentLevel := 'FORM'
Continue
Endif
If (#line.UpperCase.contains( '<FORM NAME=' ))
* Sub Form Creation
#currentLevel := 'FORM'
#subForm := #line.Substring( (#line.PositionOf( '"' ) + 1) (#line.LastPositionOf( '"' ) - (#line.PositionOf( '"' ) + 1)) )
If (#index *EQ 0)
#parent := #parent + '.fields.' + #subForm
Endif
If (#index *GT 0)
#parent := #parent + '.fields.' + #subForm + '_' + #index.asstring
Endif
#lrprops += #lr_wkSep + #parent + '.type:FORM'

Continue
Endif
* Then <GRID>
If (#line.UpperCase = '<GRID>')
#currentLevel := 'GRID'
Continue
Endif
* And Lastly Fields
If (#line.UpperCase.Contains( '<FIELD' ))
* Since its a field also set the current Field
#currentLevel := 'FIELD'
#currentField := #line.Substring( (#line.uppercase.PositionOf( 'NAME="' ) + 6) ((#line.PositionOf( '"' (#line.uppercase.PositionOf( 'NAME="' ) + 6) )) - (#line.uppercase.PositionOf( 'NAME="' ) + 6)) )


#overrideParent := *null
If (#line.UpperCase.Contains( 'PARENT' ))
#overrideParent := #line.Substring( (#line.uppercase.PositionOf( 'PARENT="' ) + 8) ((#line.PositionOf( '"' (#line.uppercase.PositionOf( 'PARENT="' ) + 8) )) - (#line.uppercase.PositionOf( 'PARENT="' ) + 8)) ) + '.fields.'

Endif
If (#line.UpperCase.Contains( 'ITEMOF' ))
#overrideParent := #line.Substring( (#line.uppercase.PositionOf( 'ITEMOF="' ) + 8) ((#line.PositionOf( '"' (#line.uppercase.PositionOf( 'ITEMOF="' ) + 8) )) - (#line.uppercase.PositionOf( 'ITEMOF="' ) + 8)) ) + '.'

Endif
Continue
Endif

* Check the is line is something=avalue
If (#line.Contains( '=' ).IsFalse)
#LRNGERRORHANDLER.AddError Message(#COM_OWNER.Name + ' Layout Error (006) : Property Missing "=" ' + #line)
Continue

Endif

#COM_OWNER.AppTrace Text('Parent currently id ' + #parent)


* Process The current level instructions
Case Of_Field(#currentLevel)

When Value_Is(= 'FORM')

#lrprops += #lr_wkSep + (#parent + '.' + #line.Substring( 1 (#line.PositionOf( '=' ) - 1) )) + ':' + ((#line.Substring( (#line.PositionOf( '=' ) + 1) )).ReplaceAll( '%index%' #index.asstring ).ReplaceAll( '%parm01%' #parm01 ).ReplaceAll( '%parm02%' #parm02 ).ReplaceAll( '%parm03%' #parm03 ).ReplaceAll( '%parm04%' #parm04 ).ReplaceAll( '%parm05%' #parm05 ).ReplaceAll( '%parm06%' #parm06 ).ReplaceAll( '%parm07%' #parm07 ).ReplaceAll( '%parm08%' #parm08 ).ReplaceAll( '%parm09%' #parm09 ).ReplaceAll( '%parm10%' #parm10 ))


When Value_Is(= 'GRID')

#lrprops += #lr_wkSep + (#parent + '.GRID.' + #line.Substring( 1 (#line.PositionOf( '=' ) - 1) )) + ':' + ((#line.Substring( (#line.PositionOf( '=' ) + 1) )).ReplaceAll( '%index%' #index.asstring ).ReplaceAll( '%parm01%' #parm01 ).ReplaceAll( '%parm02%' #parm02 ).ReplaceAll( '%parm03%' #parm03 ).ReplaceAll( '%parm04%' #parm04 ).ReplaceAll( '%parm05%' #parm05 ).ReplaceAll( '%parm06%' #parm06 ).ReplaceAll( '%parm07%' #parm07 ).ReplaceAll( '%parm08%' #parm08 ).ReplaceAll( '%parm09%' #parm09 ).ReplaceAll( '%parm10%' #parm10 ))

When Value_Is(= 'FIELD')

If (#overrideParent.IsNull)

#lrprops += #lr_wkSep + (#parent + '.fields.' + #currentField + '.' + #line.Substring( 1 (#line.PositionOf( '=' ) - 1) )) + ':' + ((#line.Substring( (#line.PositionOf( '=' ) + 1) )).ReplaceAll( '%index%' #index.asstring ).ReplaceAll( '%parm01%' #parm01 ).ReplaceAll( '%parm02%' #parm02 ).ReplaceAll( '%parm03%' #parm03 ).ReplaceAll( '%parm04%' #parm04 ).ReplaceAll( '%parm05%' #parm05 ).ReplaceAll( '%parm06%' #parm06 ).ReplaceAll( '%parm07%' #parm07 ).ReplaceAll( '%parm08%' #parm08 ).ReplaceAll( '%parm09%' #parm09 ).ReplaceAll( '%parm10%' #parm10 ))
Else

#lrprops += #lr_wkSep + (#overrideParent + #currentField + '.' + #line.Substring( 1 (#line.PositionOf( '=' ) - 1) )) + ':' + ((#line.Substring( (#line.PositionOf( '=' ) + 1) )).ReplaceAll( '%index%' #index.asstring ).ReplaceAll( '%parm01%' #parm01 ).ReplaceAll( '%parm02%' #parm02 ).ReplaceAll( '%parm03%' #parm03 ).ReplaceAll( '%parm04%' #parm04 ).ReplaceAll( '%parm05%' #parm05 ).ReplaceAll( '%parm06%' #parm06 ).ReplaceAll( '%parm07%' #parm07 ).ReplaceAll( '%parm08%' #parm08 ).ReplaceAll( '%parm09%' #parm09 ).ReplaceAll( '%parm10%' #parm10 ))

Endif



Endcase

Endselect

#COM_OWNER.AppTraceOff


END: If (#LRNGERRORHANDLER.ErrorCount *LE *zero)
#COM_OWNER.SetfromStrings Separatorused(#lr_wkSep) Propertystrings(#lrprops)

Else
#COM_OWNER.Set Property('/Form.fields') To(*null)
#COM_OWNER.Set Property('/Form.padding') To(*null)
#COM_OWNER.Set Property('/Form.backcolor') To(*null)
#COM_OWNER.Set Property('/Form.font') To(*null)

#COM_OWNER.Set Property('/Form.grid.col%1.width') To(FIT)
#COM_OWNER.Set Property('/Form.grid.row%1.height') To(FIT)

#LRNGERRORHANDLER.SendErrors
Endif

Endroutine


End_Com