Hacker’s Corner: Dynamic ⎕PW in Dyalog APL
Vector 13:4, page 111
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 111
With Dyalog APL/W, I found it quite inconvenient that I have to reset the ⎕PW every time the development session window changes or I change the size of my session font.
So here is the function I came up with that I use to reset ⎕PW which I saved in my session.
{r}←SetPW;old;chars;sbw;ww;cw;ver;dll;GSM
⍝ Set ⎕PW according to APL font size and Screen dimensions
⍝ Shy result is the width set.
⍝ Uses Windows System function GetSystemMetrics to get the
⍝ width of a vertical scroll bar
⍝ This function, if placed in the Session namespace,
⍝ can be automatically run whenever the session window is
⍝ resized by setting the folowing event:-
⍝ '⎕se.tb'⎕WS'Event' 'Configure' '⍎⎕se.SetPW'
⍝ Save environment and initialise to units of pixels
old←'⎕se'⎕WG'coord' ⍝ Save current coord system
'⎕se'⎕WS'coord' 'pixel' ⍝ Set new Coord system
⍝ Build call to Windows function GetSystemMetrics (GSM)
ver←¯3↑⊃'.'⎕WG'AplVersion' ⍝ Get Version of Windows
bit16←ver≡'3.x' ⍝ True if 16 bit Windows
dll←⊃bit16⌽'32.C32' '.P16' ⍝ user 16 or 32 bit dll
'GSM'⎕NA'I User',dll,'|GetSystemMetrics I'
⍝ Get widths in pixels of:-
sbw←GSM 2 ⍝ Scroll Bar
ww←2⊃'⎕se'⎕WG'size' ⍝ Session Window
cw←2⊃'⎕se'⎕WG⊂'Textsize' '⎕' ⍝ Quad Character
⍝ Calculate the available width in characters
chars←⌊(ww-sbw)÷cw ⍝ Available window width
⍝ Reset the environment
r←30⌈chars ⍝ Minimum ⎕PW value is 30
⎕PW←r ⍝ Set new Page Width
'⎕se'⎕WS'coord'old ⍝ Reset old coord system
The next job was to set this as the callback function to be triggered on resizing the screen width. However:
does not work. According to Dyadic, it is not possible to set the CONFIGURE event on the session. However you can set it on the session toolbar:
and that does the trick.