NB. built from project: ~Source\classes\grid\vgrid\vgrid

script_z_ '~system\main\dll.ijs'
script_z_ '~system\classes\grid\jzgrid.ijs'


coclass 'jvgrid'
require 'jzgrid'
coextend 'jzgrid'
colwidth=: 50
rowheight=: 19
coltypes=: 15
dataname=: 'data__COCREATOR'

j=. 'dataname coltypes colwidth'
j=. j,' filltype font0 font1 gridid highlighter'
CNAMES=: j,' scrollvid'
gridlinesh=: 1
gridlinesv=: 1

gridlinesh=: 0
gridlinesv=: 0

stretch=: [ $ ] , ($ ,: @ {:)
fitcols=: 4 : 0
r=. <. j=. y. * x. % +/y.
r + ((+/r) + /:\: 1|j) <<. 0.5++/j
)
screenrows=: 3 : 0
<. ({: glqwh '') % {. gridhs
)

resetatts=: 3 : 0
a=. resetatts_jzgrid_ f. ''
a=. 3 }."1 a
a=. (3 {."1 a) ,. a
)

char=: 3 : 0

if. DEBUG do.
  smoutput y.;a.i.y.
end.

select. d=. a. i. 0 { y.

case. 13 do. select_result__COCREATOR hilite
case. 166 do. scroll _1
case. 168 do. scroll 1
case. 161 do. scroll -{. screenrc''
case. 162 do. scroll {. screenrc''
case. 163 do. scroll #data
case. 164 do. scroll -#data

end.
)

mbldown=: 3 : 0
gridfocus''
'colx rowx col row val type'=. mouse y.
captureval=: val

if. row > #data do. return. end.

shape=. $data

select. type

case. 0 do.
    hilite=: row
    setselhilite''
  paintx''

case. 1 do.
  if. sizeenable do.
    glcursor IDC_SIZEWE
    glcapture 5    
    capture=: 1
    captureindex=: col - 1
    capturesize=: (colx - 1) { gridws
  end.
end.

mark=: (hilite+1), 0

)
mblup=: 3 : 0
if. 0 = capture do. return. end.
glcapture 0
t=. capture
capture=: 0
n=. {. 0 ". y.
d=. 0 >. n + capturesize - captureval

'tw th'=. glqwh ''
left=. (captureindex{.gridws),d
right=. (tw - +/left) fitcols (#left)}.gridws
setwidths colwidth=: left,right

paintx ''
)
mbldbl=: 3 : 0
'colx rowx col row val type'=. mouse y.
if. rowx do.
  select_result__COCREATOR hilite
end.
)
size=: 3 : 0
old=. sizewh
sizewh=: glqwh''
  setwidths ({.sizewh) fitcols colwidth
  setscrollbar''
  fit''
)

scroll=: 0&$: : (4 : 0)

old=. hilite
hilite=: (<:#data) <. 0 >. hilite + y.

if. x. >: hilite=old do. scrollit'' end.
mark=: (hilite+1), 0
)
scrollit=: 3 : 0
old=. scrollr

rws=. _1 + screenrows''
if. hilite < scrollr do.
  scrollr=: hilite
elseif. hilite >: scrollr+rws do.
  scrollr=: hilite-rws
end.

setselhilite''
if. scrollr ~: old do.
  glgridscroll scrollr, 0
  setscrollbarv ''
end.

paintx ''
)

create=: 3 : 0
create_jzgrid_ f. y.
atts=: resetatts''
hilite=: 0
fixc=: fixr=: 0
highlight=: ''
highlighter=: 1
sizeenable=: 1
fixeddata=: 1
)
destroy=: destroy_jzgrid_ f.
definedata=: 3 : 0
data=: dataname~
cls=. {:$data
colwidth=: cls stretch colwidth
coltypes=: cls stretch coltypes
datandx=: i.#data
)
refreshdata=: 3 : 0
if. #y. do.
  definedata''
  hilite=: y.
else.
  pos=. hilite { data
  definedata''
  hilite=: (#data) | data i. pos
end.
setdata''
scrollit''
)
setdata=: 3 : 0
definedata''
'r c'=. shape=. $data
setgrid 'maxr maxc'=: shape
setheights maxr$rowheight
setwidths ({.sizewh) fitcols colwidth
setseldata''
setscrollbars''
)
setseldata=: 3 : 0
shape=. $data
(0 0,shape) settext data
setselhilite''
)
setselhilite=: 3 : 0
shape=. $data
if. 0 e. shape do. return. end.
if. hilite >: #data do. hilite=: 0 end.

typ=. shape $ coltypes
typ=. (highlighter+hilite{typ) hilite} typ
(0 0,shape) settype typ
)