NB. provides jselect form
NB. built from project: ~Source\classes\select\select
NB. provides jselect form
NB.
NB. methods:
NB.   create
NB.   destroy
NB.
NB. on exit calls select_result in creator locale
NB.
NB. y. is a boxed list:
NB.
NB.   0  boxed list of choices
NB.   1  title
NB.   2  options
NB.   3  return verb (default select_result__COCREATOR)
NB.
NB. options is a numeric list (each defaults to 0):
NB.
NB.   0  initial selection
NB.   1  1 = sorted
NB.   2  1 = multiple selection
NB.   3  1 = extended selection (requires multiple selection)
NB.   4  1 = leave open on exit


coclass 'jselect'

SELECTFONT=: FIXFONT

PTOP=: 1
CLOSE=: ''
SORT=: ''
RESULT=: 'select_result__COCREATOR'

delstring=: 4 : ';(x.E.r) <@((#x.)&}.) ;.1 r=. x.,y.'
tolist=: }.@;@:((10{a.)&,@,@":&.>)
todelim=: ; @: ((EAV&,) @ (,&EAV) @ , @ ": &.>)

NB. =========================================================
NB.*create v create select form
create=: jselect_run

NB. =========================================================
NB.*destroy v destroy select form
destroy=: 3 : 0
wd 'pclose'
codestroy''
)

NB. =========================================================
JSELECT0=: 0 : 0
pc jselect owner;
xywh 4 5 72 100;cc lb listbox ws_vscroll rightmove bottommove;
xywh 86 6 34 11;cc ok button bs_defpushbutton leftmove rightmove;cn "OK";
xywh 86 20 34 11;cc cancel button leftmove rightmove;cn "Cancel";
pas 4 0;pcenter;
rem form end;
)

NB. =========================================================
JSELECT1=: 0 : 0
pc jselect nomin owner closeok;
xywh 0 0 130 66;cc lb listbox ws_vscroll rightmove bottommove;
pas 0 0;pcenter;ptop;
rem form end;
)

NB. =========================================================
NB. x. arguments as for jselect_form
jselect_run=: 3 : 0

y=. y.

if. 1 = L. y do. y=. <y end.

'sel title opt return'=. 4 {. y
title=. title, (0=#title)#'Select'
if. #return do.
  if. -. 1 e. ('_' = {:return),'__' E. return do.
    return=. return,'__COCREATOR'
  end.
  RESULT=: return
end.

opt=. 5 {. opt,0
if. 1{opt do.
  SORT=: /: sel
  sel=. SORT { sel
else.
  SORT=: i.#sel
end.
CLOSE=: 0 = 4{opt

wp=. JSELECT0
sty=. ; (2 3 { opt) # ' lbs_multiplesel';' lbs_extendedsel'
if. # sty do.
  ndx=. 8 + 1 i.~ 'listbox' E. wp
  wp=. (ndx{.wp), sty, ndx}.wp
end.
wd wp
formhwnd=: wd 'qhwndp'
wd 'setfont lb ',SELECTFONT
wd 'set lb ',todelim sel
wd 'setselect lb ',":0{opt
wd 'ptop ',":PTOP
wd 'pshow'
)

NB. =========================================================
jselect_lb_button=: jselectdo bind 1

NB. =========================================================
jselect_tctrl_fkey=: 3 : 0
wd 'ptop ',":PTOP=: -. PTOP
)

NB. =========================================================
NB. close enables and selects our owner
jselect_close=: 3 : 0
CLOSE=: 1
jselectdo 1
)

NB. =========================================================
jselect_cancel=: 3 : 0
CLOSE=: 1
jselectdo 0
)

NB. =========================================================
jselect_enter=: jselect_close
jselect_ok_button=: jselect_close
jselect_cancel_button=: jselect_cancel

NB. =========================================================
NB. jselectdo 0 = cancel, 1 = success
NB. calls select_result
jselectdo=: 3 : 0
res=. y. ; SORT i. ". lb_select
if. CLOSE do. destroy'' end.
try. RESULT~ res catch. end.
)

