This is the verb that provides the mechanism described above. When a Windows event occurs, the system typically invokes the following sentence (but does not show it in the session):
wdhandler ''
To demonstrate this, try defining a new wdhandler
as follows:
wdhandler=: wdinfo bind 'my new handler'
Now any action you take on the form will invoke this new definition. Typically, you would not want to redefine wdhandler
, but the fact that you can do so gives you complete control over the way events are handled. To erase your definition and recover the old definition (which is in locale z
), enter:
erase 'wdhandler'
How does the standard wdhandler
work? It first queries the event that has been signaled, using wd'q'
, and assigns the result to a global variable wdq
:
wdq +------------+---------------------------------+ |syshandler |mywin_handler | +------------+---------------------------------+ |sysevent |mywin_pressme_button | +------------+---------------------------------+ |sysdefault |mywin_default | +------------+---------------------------------+ |sysparent |mywin | +------------+---------------------------------+ |syschild |pressme | +------------+---------------------------------+ |systype |button | +------------+---------------------------------+ |syslocale | | +------------+---------------------------------+ |syshwndp |1388 | +------------+---------------------------------+ |sysfocus |pressme | +------------+---------------------------------+ |syslastfocus|pressme | +------------+---------------------------------+ |sysinfo |1 552 146 200 200 192 173 800 600| +------------+---------------------------------+
Note that wd'q'
only returns information about the last event that occurred. Re-running it will provide new information only if another event has occurred, otherwise it will give a domain error.
The result wdq
is a boxed array describing the event and the current state of the form. The first column contain various identifiers, and the second column corresponding values. Note that the first three rows correspond to the three levels of event handler discussed above. wdhandler
checks whether any of these event handlers exist, then
sysfocus
will be defined with the value pressme
As another example, click on the form to give it focus, then press the Esc key. Click on the J session window, and look at the variable wdq
:
wdq +------------+---------------------------------+ |syshandler |mywin_handler | +------------+---------------------------------+ |sysevent |mywin_cancel | +------------+---------------------------------+ |sysdefault |mywin_default | +------------+---------------------------------+ ...
This shows that the second-level event handler for the Esc key is named mywin_cancel
. Define a verb of this name to close the form:
mywin_cancel=: wd bind 'pclose'
Now click on the form to give it focus, press the Esc key, and the form will close.