[comp.sys.mac.programmer] Updating dialogs

dan@lclark.UUCP (Dan Revel) (01/06/89)

What's the best way to update a non-modal dialog after changing one of
its dialog items?  Here's my problem: I want to display differing icons
in response to user radio button selections, right now I call DrawDialog(...)
to redraw the whole window but that causes everything to flicker and I would
rather just redraw the icon I have changed.  I tried just using InvalRect on
the rect returned by GetDItem but to no update event is generated...

Here's a synopsis of the code I have now:

	GetDItem(...);
	SetDItem(...);
	DrawDialog(...);

(BTW: I'm using MPW Pascal although I don't think it matters in this case)

Thanks for your help!

Dan

-- 
dan@lclark
tektronix!reed!lclark!dan			Dylsexics untie! (-|

sec@berlin.acss.umn.edu (Stephen E. Collins) (01/06/89)

In article <373@lclark.UUCP>, dan@lclark.UUCP (Dan Revel) writes:
> What's the best way to update a non-modal dialog after changing one of
> its dialog items?   ...
>                                              I tried just using InvalRect on
> the rect returned by GetDItem but to no update event is generated.

I'll bet you forgot to do a SetPort to your dialog window before you
called InvalRect.

+-----------------------------------------------------------------------+
| Stephen E. Collins                             | sec@ux.acss.umn.edu /
| ACSS Microcomputer & Workstation Systems Group | sec@UMNACVX.BITNET /
| 125 Shepherd Labs                  +-----------+-------------------/
| University of Minnesota            | Cum hanc intellegas, Latinam /
| Minneapolis, MN  55455             | sententiolam potes legere!  /
+------------------------------------+----------------------------+

beard@ux1.lbl.gov (Patrick C Beard) (01/06/89)

In article <373@lclark.UUCP> dan@lclark.UUCP (Dan Revel) writes:
>What's the best way to update a non-modal dialog after changing one of
>its dialog items?
>Here's a synopsis of the code I have now:
>	GetDItem(...);
>	SetDItem(...);
>	DrawDialog(...);
To speed things up (I'm assuming you know what you are doing with your
Get/SetDItem  calls) you should try using UpdtDialog(), IM IV-60, which
allows you to specify the Dialog and a region to update.  Just get the
rectangle of the item, call RectRgn() to generate the region, and just
that item will get redrawn.  

Now, a better way to do it might be to try a user item that calls a routine
that does the PlotIcon itself, and keep an array of icons the index of
which is updated when the radio button is hit.  For the fastest performance
do the PlotIcon immediately, and let the user item handle updates.  For
more info about user items, consult the Dialog Manager chapter.
>
>Thanks for your help!
You are welcome!
>Dan
Patrick Beard
Lawrence Berkeley Laboratory

tim@hoptoad.uucp (Tim Maroney) (01/06/89)

In article <373@lclark.UUCP> dan@lclark.UUCP (Dan Revel) writes:
>What's the best way to update a non-modal dialog after changing one of
>its dialog items?  Here's my problem: I want to display differing icons
>in response to user radio button selections, right now I call DrawDialog(...)
>to redraw the whole window but that causes everything to flicker and I would
>rather just redraw the icon I have changed.  I tried just using InvalRect on
>the rect returned by GetDItem but to no update event is generated...

You also need to make sure that the current GrafPort at the time of the
InvalRect is the dialog GrafPort.  If you do this, an update event will
be returned on the dialog by GetNextEvent, and when you call DialogSelect
the item will be redrawn.  My guess is you just forget to set the GrafPort
before doing the InvalRect.  It would also be a good idea to do an
EraseRect before or after doing the InvalRect, or you may find your
new icon superimposed over the old one (or maybe not, but it shouldn't
hurt to be safe).
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"There's a real world out there, with real people.  Go out and play there for
 a while and give the Usenet sandbox a rest.  It will lower your stress
 levels and make the world a happier place for us all." -- Gene Spafford