Inside Mac XCMD
Volume Number: 6
Issue Number: 3
Column Tag: XCMD Corner
Related Info: Control Manager Event Manager Resource Manager
Inside Macintosh
By Donald Koscheka, Ernst & Young, MacTutor Contributing Editor
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
“Inside Macintosh” poses a paradox for the Hypercard developer. Hypertalk
greatly reduces the stresses and strains of developing a Macintosh application but a
quick flip through the pages of Inside Macintosh reveals a wealth of features and
capabilities that aren’t available to the script writer. This column attempts to
remedy this situation but has focussed in on I/O routines, in part because I/O is
where Hypercard is weakest.
The paradox of XCMD programming is that some of the easiest problems are the
most difficult to solve. We’ll take as one example, adding a custom control to
Hypercard. Before I go into too much detail, I need to warn you. Much of what this
column discusses is stuff that ought to be in Hypercard in the first place. I have to
believe that some future release will address these issues. Even so, bear with me;
there’s still a lot to learn and sometimes going back to the basics can be quite
illuminating.
Here is the problem: You want to add a custom control to a Hypercard window,
perhaps a horizontal scroll bar. Sounds simple enough so you whip up a little xcmd
that calls the toolbox utility “NewControl”. To your bemusement, the control draws
correctly but it doesn’t work! Worse yet, the button erases on updates. You dump
Hypercard’s window record to discover something even more horrifying - your
control is the only object in the control list; Hypercard doesn’t trifle with the control
manager.
It turns out that adding a control to the Hypercard window isn’t enough. You
need to add a mechanism to track control events by intercepting the event trap
( currently GetNextEvent). Although the accompanying code focuses on the control
manager, you can modify this technique to manage windows, lists and key events (some
of these will be featured in future columns).
By patching GetNextEvent, you can peek at events before Hypercard sees them.
You decide whether to pass an event on to Hypercard or to “consume the event”.
Listing 1, Control XFCN.c, creates a control and installs the event patch (if it
isn’t already installed). Listing 2 contains the patch which is stored as resource type
“EXEC”. Control XFCN installs this patch into the system heap so that we can begin