NB. Utilities for OCX controls
NB.
NB. utilities:
NB.
NB. ocxinfo        return all OCX info (events, methods, properties, constants)
NB.                e.g. ocxinfo 'GraphLib.Graph'
NB.
NB. ocxconstants   return OCX constants
NB. ocxevent       return OCX events
NB. ocxmethod      return OCX methods
NB. ocxproperty    return OCX properties
NB.
NB. ocxdialog      run OCX property dialog

NB. ==============================================
NB. ocxfmt        format J array for OCX control
NB.
NB. adverbs for building ocxset verbs:
NB. ocxchar       character
NB. ocxnum        numeric
NB. ocxindex      numeric indexed
NB. ocxclist      character list
NB. ocxnlist      numeric list
NB. ocxilist      numeric indexed list
NB. ocxdata       data (J array)
NB.
NB. e.g.
NB.   wde 'oleset cmd data'  =  'cmd' ocxchar 'data'
NB.
NB. the parameters for ocxset are typically:
NB.
NB.   'cmd data'   =  'cmd' ocxchar 'data'
NB.   'cmd 123'    =  'cmd' ocxnum 123
NB.   'cmd(3) 12'  =  'cmd' ocxindex 3 12
NB.   'cmd one cmd two'      =  'cmd' ocxclist 'one';'two'
NB.   'cmd 10 cmd 11'        =  'cmd' ocxnlist 10 11
NB.   'cmd(0) 10 cmd(1) 11'  =  'cmd' ocxilist 10 11
NB.   'cmd 1',TAB,'2',TAB,'3',CRLF  =  'cmd' ocxchar 1 2 3

NB. ocxinfo
NB. return information about OCX events, methods,
NB. properties and constants
NB. e.g. ocxinfo 'GraphLib.Graph'
ocxinfo=: 3 : 0
wd 'pc ocxinfo'
wd 'cc x0 ocx:',y.
dat=. wd 'oleinfo x0'
wd 'pclose'
(-. (13 10{a.) E. dat) # dat
)

NB. ocxinfo1
NB. return given entries from OCX info
ocxinfo1=: 4 : 0
dat=. <;._2 ocxinfo y.
f=. x."_ -: (#x.)&{.
(#x.) }. each dat #~ f &> dat
)

ocxconstants=: 'NB. constants: ' & ocxinfo1
ocxevent=: 'NB. event: ' & ocxinfo1
ocxmethod=: 'NB. method: ' & ocxinfo1
ocxproperty=: 'NB. property: ' & ocxinfo1

NB. ocxdialog
NB. run OCX property dialog
NB. e.g. ocxdialog 'GraphLib.Graph'
ocxdialog=: 3 : 0
wd 'pc ocxinfo'
wd 'cc x0 ocx:',y.
wd 'oledlg x0'
wd 'pclose'
)

NB. ocxset        wrapper
NB.
NB. ocx_... supporting utilities
NB.
NB. note ocx commands are not case-sensitive

NB. ocxfmt
NB. format data of rank 0 1 or 2
NB. columns are separated by TAB, rows by CR.
NB. result is enclosed in EAV pair.
ocxfmt=: 3 : 0
t=. 3!:0 y.
if. 2=t
do. y=. y.
elseif. 32<:t
do.
  y=. ,&TAB @ ": &.>y.
  y=. ;,&CRLF@}: &.><@;"1 y
elseif. 1
do.
  y=. ;,&CRLF @ ": &.><"1 y.
  y=. '-' (I. y='_') } y
  y=. TAB (I. y=' ') } y
end.
EAV,y,EAV
)

ocx_ss=:    '-'&(I. @(=&'_')@]})
ocx_char=:  EAV&,@(,&EAV)
ocx_num=:   ocx_ss f. @":@".@":
j=.         ('('&,@(,&')')@":@{.,' '&,@":@{:)	
ocx_index=: j f. &.> @ (_2&(<\))	
ocx_nlist=: ]`(<@(ocx_ss f.)@":"0)@.(32&>@(3!:0))
ocx_clist=: ocx_char &.> @ ocx_nlist
ocx_ilist=: <"1@(('('&,.)@(,"1&') ')@":@,.@i.@# ,. ])@":@,.

ocxset=:  2 : 'wd@((''oleset '',x.,'' '',y.,'' '')&,)@(,&'';'')'

ocxchar=:  ocxset (@ocx_char)              NB. character
ocxnum=:   ocxset (@ocx_num)               NB. numeric
ocxindex=: ocxset (&.>) (@ocx_index) (;@)  NB. index
ocxclist=: ocxset (&.>) (@ocx_clist) (;@)  NB. character list
ocxnlist=: ocxset (&.>) (@ocx_nlist) (;@)  NB. numeric list
ocxilist=: ocxset (&.>) (@ocx_ilist) (;@)  NB. numeric index
ocxdata=:  ocxset (@ocxfmt)                NB. data
