[comp.sys.mac.programmer] How do I implement a toolbox window like MacPaint 2.0?

philf@lindy.Stanford.EDU (Phil Fernandez) (07/08/89)

I'd like to implement a "toolbox" window like those displayed by
MacPaint 2.0, Freehand, Hypercard, etc.  I.e., I little pseudo-window
that sets pen modes, etc.  I don't particularly want it to be a
tear-off window like Hypercard -- I'll just activate via a menu
choice, and deactivate it via a little close box or a menu choice.

My question is, how do I implement this beast?  It's clearly not a
"real" window -- clicking in it doesn't deactivate my active
application window.  Yet it's not confined to my application window
boundary.

Can anyone give me insights into the "right" way to do this?

Thanks...please mail directly to me:

philf@lindy.stanford.edu
...sun!lindy.stanford.edu!philf

phil

kari@xanadu.COM (Kari Dubbelman) (07/10/89)

Seeing that you have at least two open questions that I can answer...

You have hit upon two of the (more) weak spots in the Mac toolbox.
Most other things at this programming level exist and work well.
Inside Mac tells how to do these things. You cannot program the Mac
without IM volumes I, IV, and (if you have color) V.  Period. You
probably also need IM-II and the TechNotes stack would not hurt.

But to answer the button question, there is no built-in way to do it
and this is a serious oversight in the Mac toolbox. IM (I-407)
recommends you do something like this (with int16 a portable 16-bit
integer; Warning - shooting-from-the-hip programming below)

void
highlightbutton(dialog,itemNumber)
DialogPtr dialog;
int16 itemNumber;
{
Rect displayRect;
int16 itemType;
Handle itemHandle;

	GetDItem(dialog,itemNumber,&itemType,&itemHandle,&displayRect);
	SetPort(dialog);	/* Possibly unneccesary */
	PenNormal();		/* Probably unnecessary */
	PenSize(3,3);
	InsetRect(displayRect,-4,-4);
	FrameRoundRect(displayRect,16,16);
}

but this causes minor problems in modeless dialog boxes - this routine
has to be called in the window update routine also, otherwise covering
windows will cause (pieces of) the highlighting to disappear when
removed.  (Modal dialogs work OK).

Second question, about a floating tool selection window:

There is a system for doing exactly this, based on a variable called
GhostWindow (I-287). I have not tried this myself, but concensus among
developers I've listened to seems to be not to use this "feature"
since it causes more problems than it solves. Just be careful so as
not to deactivate any other window if you get a hit in the tool
selection window. You may benefit from making this window have a
built-in PICT handle for its contents - Draw the window in MacPaint,
cut it with the lasso, cut it to the clipboard, go into MacDraw, Paste
it out of there and save the picture as a PICT file. Then go into
ResEdit and grab the PICT resource from the MacDraw save file and put
into your programs resource file. Install it as the Window PICT and
you have your icons. Highlight areas with InvertRect as appropriate.
(Haven't tested this either... Caveat Implementor as the Romans used
to say)

	-Kari