> I am trying to duplicate some functionality in the PPX TextEditor
> example -- specifically, that in MyTextDocument.cp (MTD).
[quoted text clipped - 13 lines]
> 1) How does MTD get into the "containment hierarchy" of the Window?
> Apple docs, including a picture, seem to contradict this.
You need to distinguish between the Event Target and the Event Doer. The
two do not have to be the same object.
In this case, the Window is the Event Target, and the MTD is the Event
Doer. When the system sends the close event to the Window, the system
calls the last installed event handler. To the system, and event handler
is really just a function pointer.
In PPx, the function that the system calls for an event handler is
converted into a virtual function call for some Event Doer object.
So, the MTD is not in the containment hierarchy of the Window. The MTD
installs an event hander on the Window, and the PPx implementation of an
event handler callback function results in a call to a virtual function
of the MTD.
> 2) In trying to duplicate this functionality, I created a dialog, in IB,
> with OK and Cancel buttons having custom commands. I created a class,
[quoted text clipped - 6 lines]
> main app which inherits from CommandConverter. In other words, Setup
> does *not* seem to be in the containment hierarchy.
When you say "custom command", I assume you mean a command ID with a
four-character code that isn't one of Apple's reserved IDs.
When the button is clicked, it sends an event with a signature (class,
type) of (kEventClassCommand, kEventCommandProcess). If you don't have
any custom handlers for that kind of event installed (and you probably
don't), then the event percolates up to the PPx Application class, which
inherits from CommandConverter.
The purpose of CommandConverter is to respond to a (kEventClassCommand,
kEventCommandProcess) event by sending a different event, of kind
(eventClass_ProcessCommand, "specific command ID") to the user focus
target. In your case, "specific command ID' as the four-character code
of the button's command ID.
I can't tell from the description above how you have installed your
event handlers.
But, you need to have your Setup class install an event handler on
something that is in the user focus chain when the button is clicked.
What that "something" is depends on your application. If the button is
in a dialog window, then probably the window object. However, if your
button is in a floating window which doesn't have the focus, the
specific command event will be sent to the window (probably the active
document) that does have the focus.
If no obvious target comes to mind, you can always install the handler
on the application event target. This might be a problem if you have
multiple windows that contain buttons with the same command ID. Then,
you would need a way to determine which button was sending the command.
-- Greg