NB. built from project: ~Source\classes\grid\sview\sview
NB. sview utils

script_z_ '~system\classes\grid\jsgrid.ijs'

coclass 'jsview'


default=: 4 : 0
nc=. 4!:0 <x.
if. _1=nc do. ".x.,'=: y.'
elseif. _2=nc do. 'invalid name: ',":,x.
end.
empty''
)

pdefine=: 3 : 0
if. 0 e. $y. do. empty''
else.
  names=. {."1 y.
  (names)=: {:"1 y.
  names
end.
)

tolist=: }.@;@:((10{a.)&,@,@":&.>)
create=: jsview_run

centerxywh=: ''
gridid=: 'grid'
scrollid=: 'scrollbarv'
font1=: font0=: PROFONT
ifowner=: 0
pname=: 'View'
rowheight=: 20
colwidth=: 50
JSVIEW=: 0 : 0
pc jsview;
xywh 0 0 150 10;cc grid isigraph ws_border ws_clipchildren rightmove bottommove;
xywh 150 0 9 10;cc scrollbarv scrollbarv leftmove rightmove bottommove;
pas 0 0;pcenter;
rem form end;
)
jsview_run=: 3 : 0
pdefine y.
'dataraw' default data
len=. #data
'coltypes' default len$10
'coltitle' default ":each i.len

wd 'pc jsview',ifowner#' owner'
wd 'pn "',pname,'"'

'px py'=. 48 % LOGPIXELSY
wd 'psel jsview'   

tol=. 1
rmx=. 100
rws=. px * rowheight * 1 + #data  
h=. rws <. rmx
w=. py * +/colwidth
wd 'xywh 0 0 ',":tol + w,h
wd 'cc grid isigraph ws_border ws_clipchildren rightmove bottommove'
if. rmx < rws do.
  wd 'xywh ',":(tol+w),0,9,h
  wd 'cc scrollbarv scrollbarv leftmove rightmove bottommove'
end.
wd 'pas 0 0;pcenter;'
if. #centerxywh do.
  wdcenter centerxywh
else.
wdfit ''
end.
grid=: '' conew 'jsgrid'
init__grid''
wd 'setfocus grid'
wd 'pshow;'
)

destroy=: 3 : 0
destroy__grid''
codestroy''
)
jsview_gethilite=: 3 : 0
0 pick hilite__grid { dataraw__grid
)
jsview_close=: 3 : 0
wd 'pclose'
destroy''
)
jsview_ok_button=: 3 : 0
hl=. jsview_gethilite''
wd 'pclose'
try. jsview_result__COCREATOR hl catch. end.
destroy''
)
jsview_cancel_button=: jsview_cancel=: jsview_close
jsview_enter=: jsview_ok_button
formselect=: 3 : 'wd''psel '',formhwnd'
jsview_grid_size=: 3 : 'size__grid 1'
jsview_grid_mbldown=: 3 : 'mbldown__grid sysdata'
jsview_grid_mbldbl=: 3 : 'mbldbl__grid sysdata'
jsview_grid_mblup=: 3 : 'mblup__grid sysdata'
jsview_grid_mmove=: 3 : 'mmove__grid sysdata'
jsview_grid_char=: 3 : 'char__grid sysdata;sysmodifiers'
jsview_scrollbarv_button=: 3 : 0
scrollbarv__grid scrollbarv
wd'setfocus grid'
)