Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / July 2004



Tip: Looking for answers? Try searching our database.

Query re PPx example

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael McLaughlin - 26 Jul 2004 14:33 GMT
I am trying to duplicate some functionality in the PPX TextEditor
example -- specifically, that in MyTextDocument.cp (MTD).

MTD
inherits from Correspondent and CommandHandler<kHICommandClose>
contains a Window
overrides DoSpecificCommand and ClassName (inter alia)
is registered in the main app with the class name

The close handler is installed *on the Window* but handler code belongs
to MTD.  When the window is closed, it is MTD that handles the action.

Presumably this is all as it should be but

Two questions:

1) How does MTD get into the "containment hierarchy" of the Window?
Apple docs, including a picture, seem to contradict this.

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,
Setup, inheriting from Correspondent and CommandHandler (for my custom
OK and Close), overrode DoSpecificCommand and ClassName and registered
the name just as in TextEditor.  I tried installing both on the window
and on Setup directly.

In both cases, the custom command was not handled until it got to the
main app which inherits from CommandConverter.  In other words, Setup
does *not* seem to be in the containment hierarchy.

Can anyone tell what I am doing wrong here?  Obviously, this should all
be very standard and straightforward but it isn't.

TIA.

--
Mike McLaughlin
Gregory Dow - 27 Jul 2004 07:38 GMT
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.