\ fields 05.1.22 NAB

needs forms
needs core-ext

: FieldFocus ( fieldid -- )
  FrmGetActiveForm  2dup 2>r 
  FrmGetObjectIndex dup
  2r@ FrmGetObjectPtr ( idx ptr. )
\ Make the field active:
  0 rot rot  FldSetInsPtPosition
  2r> FrmSetFocus ;

: FieldReleaseFocus ( fieldid -- )
  GetObjectPtr FldReleaseFocus ;

: string>Field ( c-addr u fieldID -- Err )
  >r  swap >abs 
  r> GetObjectPtr 
  2dup FldGetTextLength 0 2over
  FldDelete  FldInsert ;

: Field>string ( c-addr fieldID -- len )
  swap >r GetObjectPtr
  2dup FldGetTextLength dup >r
  s>d 2swap FldGetTextPtr
  r> r> swap >r >abs  MemMove drop
  r> ;
