NB. split.ijs - splitter control
NB. see TEST section at the bottom for an example
NB. http://www.jsoftware.com/pipermail/general/2003-October/014971.html
NB. 07/14/2003 Oleg Kobchenko
NB. 07/15/2006 Oleg Kobchenko - j601, componentized

require'gl2'

coclass 'psplit'
coinsert'jgl2'

wfopen=: ;:^:(0=L.)
crot=: [:  ,  _2 |.\  ]
irot=: [: ,./ _2 ]\"1 ]

create=: 3 : 0
  HZ=:'h'={: ID=: 0{::y
  LC=:  wfopen    1{::y
  RC=:  wfopen    2{::y
  nm=. >coname''
  pn=. >{:<;._2 wd'qp'
  (pn,'_',ID,'_paint__COCREATOR')   =: ('paint_',  nm,'_')~
  (pn,'_',ID,'_mbldown__COCREATOR') =: ('mbldown_',nm,'_')~
  (pn,'_',ID,'_mblup__COCREATOR')   =: ('mblup_',  nm,'_')~
  CAPT=: ''
)

destroy=: codestroy

FG=: 3#127
BG=: 210 200 190

paint=: 3 : 0
  glclear''
  glcursor HZ { IDC_SIZEWE,IDC_SIZENS
  glpen 0,0 [ glbrush glrgb BG
  glrect 0 0 , glqwh''
  glpen 1,0 [ glrgb FG
  wh=. <. , (|.^:HZ 0.25 0.75,:0.4 0.6) * glqwh''
  gllines (irot^:HZ 0 2  0 3 ,:1 2 1 3) { wh
)

mbldown=: 3 : 0
  glsel ID      NB. is it really necessary?
  glcapture 5+HZ
  CAPT=: HZ{".sysdata__COCREATOR
)

mblup=: 3 : 0
  if. 0=#CAPT do. return. end.
  glcapture 0
  move (HZ{".sysdata__COCREATOR) - CAPT
  CAPT=: ''
)

move=: 3 : 0
     LC setp crot^:HZ 0 0, y, 0
  (<ID) setp crot^:HZ y,0  0  0
     RC setp crot^:HZ y,0,-y, 0
)

setp=: 4 : 0"0 1
  pos=. ".wd'qchildxywhx ',>x
  wd'setxywhx ',(>x),' ',":pos+y
)

NB. =========================================================

TEST=: 0 : 0
pc test;
xywh 6 6 44 61;cc ok button bottommove;cn "OK";
xywh 6 69 44 14;cc b1 button topmove bottommove;
xywh 6 86 44 14;cc b2 button topmove bottommove;
xywh 51 6 3 94;cc splitv isigraph bottommove;
xywh 55 6 111 28;cc b3 button rightmove;
xywh 169 6 31 28;cc b4 button leftmove rightmove;
xywh 54 35 146 3;cc splith isigraph rightmove;
xywh 55 39 145 62;cc cancel button rightmove bottommove;cn "Cancel";
pas 6 6;pcenter;
rem form end;
)

test_run=: 3 : 0
  wd TEST
  LC=: ;:'ok b1 b2'
  RC=: ;:'cancel b3'
  spv=: 'psplit' conew~ 'splitv';'ok b1 b2';'b3 splith cancel'
  sph=: 'psplit' conew~ 'splith';'b3 b4'   ;'cancel'
  wd 'pshow;'
)

test_close=: 3 : 0
  destroy__spv''
  destroy__sph''
  wd'pclose'
)

test_run''