NB. built from project: ~Source\classes\view\view
NB. util - view

script_z_ '~system\packages\print\print.ijs'

coclass 'jview'

MAXSIZE=: (IFUNIX +. IFWINNT) { 30000 200000

getfontsz=: 13 : '{.1{._1 -.~ _1 ". y.'
3 : 0''
if. 0 ~: 4!:0 <'VIEWFONT' do.
  VIEWFONT=: FIXFONT
end.
if. 0 ~: 4!:0 <'SMPRINT_j_' do.
  VIEWPRINT=: ''
else.
  VIEWPRINT=: SMPRINT_j_
end.
0
)

VIEWFONTSIZE=: getfontsz VIEWFONT
VIEWFONTSCALE=: 1
cifmt1=: 3 : 0
neg=. 0 > y.
dat=. 0 ": | y.
len=. #dat
msk=. (-len) {. (|. len$1j1 1 1) , 3$1
dat=. msk # !. ',' dat
(neg # '-'), dat
)
flat=: 3 : 0
dat=. ": y.
dat=. 1 1}. _1 _1}. ": <dat
}: (,|."1 [ 1,.-. *./\"1 |."1 dat=' ')#,dat,.LF
)
setfontsz=: 4 : 0
b=. ~: /\ y.='"'
nam=. b#y.
txt=. ;:(-.b)#y.
ndx=. 1 i.~ ([: *./ e.&'0123456789.') &> txt
nam, }: ; ,&' ' &.> (<": x.) ndx } txt
)
create=: jview_run
destroy=: codestroy
JVIEW=: 0 : 0
pc jview;
xywh 2 2 132 10;cc h0 static;
xywh 0 13 350 250;cc e0 editm ws_border ws_vscroll es_readonly rightmove bottommove;
xywh 140 2 24 10;cc Top checkbox leftmove rightmove;
xywh 166 2 29 10;cc Wrap checkbox leftmove rightmove;
xywh 196 1 38 12;cc Print button leftmove rightmove;
pas 0 0;pcenter;
rem form end;
)
jview_form=: 3 : 0

VIEWMAX=: 0

ed=. ' ws_border ws_vscroll es_readonly rightmove bottommove'
wd 'pc jview'
wd 'xywh 2 2 132 10;cc h0 static;'
wd 'xywh 0 13 350 250;cc e0 editm',ed,' ws_hscroll'
wd 'xywh 0 13 350 250;cc e1 editm',ed

if. y. do.
  wd 'xywh 221 2 34 10;cc Top checkbox leftmove rightmove;'
  wd 'xywh 258 2 39 10;cc Wrap checkbox leftmove rightmove;'
  wd 'xywh 301 1 48 12;cc Print button leftmove rightmove;'
else.
  wd 'xywh 269 2 34 10;cc Top checkbox leftmove rightmove;'
  wd 'xywh 304 2 39 10;cc Wrap checkbox leftmove rightmove;'
end.

wd 'setfont e0 ',VIEWFONT
wd 'setfont e1 ',VIEWFONT
wd 'pas 0 0;pcenter;'

formhwnd=: wd 'qhwndp'

)
jview_run=: 3 : 0

y=. boxopen y.
defprint=. (0<#VIEWPRINT) *. 0=(IFWINCE)

y=. y, (#y) }. '';'';'';0;defprint;0
'name hdr txt'=. ": each 3 {. y
'wrap print ptop'=. 3 {. 3 }. y

if. 2 <: #$txt do. txt=. flat txt end.

txt=. (1{a.) (I.  EAV=txt) }txt
if. MAXSIZE <: #txt do.
  msg=. 'Text size of ',(cifmt1 #txt),' characters is too large to view.'
  msg=. msg,LF,LF,'Truncated to ',(cifmt1 MAXSIZE),' characters.'
  txt=. (MAXSIZE {. txt),LF,'...'
  wdinfo name;msg
end.

jview_form print

wd 'pn *',name
wd 'set h0 *',hdr
wd 'set Wrap ',": wrap
wd 'set Top ',": ptop
wd 'ptop ',": ptop

try.
  if. wrap=0 do.
    wd 'set e0 *',txt
    wd 'setshow e1 0;setshow e0 1'
  else.
    wd 'set e1 *',txt
    wd 'setshow e1 1;setshow e0 0'
  end.
catch.
  msg=. LF,LF,({.~ i.&':') wd 'qer'
  wdinfo 'jview';'Unable to view text',msg
  wd 'psel jview;pclose'
  destroy''
  return.
end.

wdfit''
wd 'pshow'
)
jview_Print_button=: 3 : 0
txt=. ('1'={.Wrap) pick e0;e1
try. '' VIEWPRINT~ txt
catch. wdinfo 'Print';'Print failed.',LF,LF,'Check the printer is installed'
end.
)
jview_Top_button=: 3 : 0
wd 'ptop ',Top
)
jview_Wrap_button=: 3 : 0
if. Wrap='1' do.
  wd 'set e1 *',e0
  wd 'setselect e1 ',e0_select
  wd 'setshow e1 1;setshow e0 0'
else.
  wd 'set e0 *',e1
  wd 'setselect e0 ',e1_select
  wd 'setshow e0 1;setshow e1 0'
end.
)
jview_close=: 3 : 0
wd 'pclose'
f=. 'view_result__COCREATOR'
if. 0 = 4!:0 :: _1: < f do.
  try. f~'' catch. end.
end.
destroy''
)
jview_cancel=: jview_close
jview_mctrl_fkey=: 3 : 0
VIEWMAX=: -. VIEWMAX
if. VIEWMAX do.
  wd 'pshow sw_showmaximized'
else.
  wd 'pshow sw_shownormal'
end.
)
jview_maximize=: 3 : 0
VIEWMAX=: 0
jview_mctrl_fkey''
)
jview_scale=: 3 : 0
VIEWFONTSCALE=: VIEWFONTSCALE * 1.2 ^ y.
font=. (<. 0.5 + VIEWFONTSIZE * VIEWFONTSCALE) setfontsz VIEWFONT
wd 'setfont e0 ',font
wd 'setfont e1 ',font

)
jview_bctrl_fkey=: jview_scale bind 1
jview_bctrlshift_fkey=: jview_scale bind _1