[comp.sys.mac.programmer] QuickDraw before ModalDialog

CAH0@bunny.gte.com (Chuck Hoffman) (05/10/91)

Running 6.0.7, using THINK C.  I have my "About" information in a dialog 
box used with ModalDialog.  I first do some QuickDraw in the box (copybits 
from the ICN#, and a dark border around the Okay button) before invoking 
ModalDialog.  If Pyro! 4.0 gets the screen, then gives it up again, my 
QuickDraw stuff seems to go away.  I'm not able to detect any events while 
ModalDialog is running, and wouldn't have a way to redraw the box during 
ModalDialog anyway.  Am I destined always to lose the QuickDraw stuff?  
Should I InvalRect the box?  Is there a better way?


Chuck Hoffman, GTE Laboratories, Inc.    |  I'm not sure why we're here,
cah0@bunny.gte.com                       |  but I am sure that while we're
Telephone (U.S.A.) 617-466-2131          |  here, we're supposed to help
GTE VoiceNet: 679-2131                   |  each other.
GTE Telemail: C.HOFFMAN                  |

davids@mondo.engin.umich.edu (David Snearline) (05/10/91)

In article <11147@bunny.GTE.COM> CAH0@bunny.gte.com (Chuck Hoffman) writes:
>Running 6.0.7, using THINK C.  I have my "About" information in a dialog 
>box used with ModalDialog.  I first do some QuickDraw in the box (copybits 
>from the ICN#, and a dark border around the Okay button) before invoking 
>ModalDialog.  If Pyro! 4.0 gets the screen, then gives it up again, my 
>QuickDraw stuff seems to go away.  I'm not able to detect any events while 
>ModalDialog is running, and wouldn't have a way to redraw the box during 
>ModalDialog anyway.  Am I destined always to lose the QuickDraw stuff?  
>Should I InvalRect the box?  Is there a better way?

I suggest that you call ModalDialog with a filterProc as described in
Inside Mac I p. 415.  If you are receiving an update event, draw your
extra items.  If you get an update event, draw your items and then return
false for your function so that ModalDialog handles the event.

An alternative approach is to declare a disabled userItem for the ICN#
and the border, and set the procedure pointer with SetDItem.

--- David ---

--
David Snearline
CAEN Network Operations
University of Michigan Engineering

glenn@gla-aux.uucp (Glenn L. Austin) (05/10/91)

CAH0@bunny.gte.com (Chuck Hoffman) writes:
>Running 6.0.7, using THINK C.  I have my "About" information in a dialog 
>box used with ModalDialog.  I first do some QuickDraw in the box (copybits 
>from the ICN#, and a dark border around the Okay button) before invoking 
>ModalDialog.  If Pyro! 4.0 gets the screen, then gives it up again, my 
>QuickDraw stuff seems to go away.  I'm not able to detect any events while 
>ModalDialog is running, and wouldn't have a way to redraw the box during 
>ModalDialog anyway.  Am I destined always to lose the QuickDraw stuff?  
>Should I InvalRect the box?  Is there a better way?

The reason why is that, when using dialog boxes, the contents are updated
via the DrawDialog mechanism.  So, if you want the drawings to get redrawn,
you MUST allocate a user item which covers the area to be drawn.  This is
so that, when an update occurs on the dialog, the intersection of the
updateRgn and any dialog items designates which items will be redrawn.  If
there is no user item behind your graphics, then there is no way to determine
that they should be redrawn.

Probably the first userItem people should do is the "default button" outline.
To save some time for those who haven't done one before, here's the code in
C:

pascal void DrawDefaultItem(DialogPtr theDialog, short itemNo)
{
  GrafPtr  oldPort;
  PenState oldPen;
  short    item;
  Handle   h;
  Rect     box;

  GetPort(&oldPort);			/* get the current grafport */
  SetPort(theDialog);			/* necessary on the Plus */

  GetPenState(&oldPen);			/* save the old pen settings */

  PenNormal();				/* reset the pen state */

					/* get the item's rectangle */
  GetDItem(theDialog, itemNo, &item, &h, &box);

  PenSize(3,3);				/* set the pen to 3 x 3 */
  InsetRect(&box, -4, -4);		/* inset outside of the item */
					/* WARNING!!!  Drawing outside */
					/* of the item's rectangle can */
					/* be clipped by QuickDraw! */
					/* It is better to create the item */
					/* with the correct size in the */
					/* first place!  Also, then it */
					/* will get called if a portion of */
					/* the expanded area was within */
					/* the updateRgn! */
  FrameRoundRect(&box, 16, 16);

  SetPenState(&oldPen);			/* restore the pen state */

  SetPort(oldPort);			/* and the old port */
}

I use code very similar to this, including the PenState and GetPort/SetPort
calls all the time.  I found the SetPort necessary on my old Plus...

-- 
===============================================================================
| Glenn L. Austin - Mac Wizard and Auto Racing Driver                         |
| Usenet:  glenn@gla-aux.uucp                                                 |
|  "Turn too soon, run out of room.  Turn too late, much better fate."        |