Specifications
Developer Technical Support May 1992
Apple IIGS
#75: BeginUpdate Anomaly 3 of 4
But I Have to Do…
If you absolutely must do some of the things previously discussed, there is a way to accomplish it.
It is not simple, but it can be done.
Assuming that BeginUpdate has been called, and an application is in its update procedure:
1. Create a new region and copy the visRgn into it. Doing this allows the application
to restore the visRgn to just the area to be updated that BeginUpdate calculated.
This needs to be done for any other windows which obscure a part the the window
being updated. Again, these are not windows that an application would open
directly. CopyPixels may open a window, since it is a dynamic segment and may
need to get loaded from a disk that is off-line.
2. Create a new region, then swap its handle with the updateRgn handle. This
protects the real visRgn and lets an application call InvalRect and InvalRgn
at any time if necessary. It also means the application doesn’t need to worry about
the system making these calls either. The updateRgn is also an empty region
after the swap, so any contributions to it constitute a valid update event that needs to
be handled.
3. Do the update part of the update procedure. In this part, if the application has any
calls to CopyPixels, or any other QuickDraw Auxiliary dynamic segment
functions, after the call is completed, copy the saved visRgn back to the visRgn
of the grafPort. The closing of the dynamic segment alert window recalculates
the visRgn, and copying it undoes this effect. Do not do the same for the
updateRgn. Leave the updateRgn alone. We are accumulating an actual
updateRgn, and the closing of the alert window for the dynamic segment may
have contributed to this region.
There are two methods for leaving the update procedure. Although the second method works
whether or not an application uses TaskMaster, if an application does not use TaskMaster,
then the first method is simpler.
The procedure without using TaskMaster (i.e., you made the BeginUpdate call, and you will
make the EndUpdate call) is as follows:
A. Dispose of the region created in Step 1. This region was only needed to restore the
partial visRgn that BeginUpdate calculated after a window was opened.
B. Swap the updateRgn handle with the region handle created in Step 2.
C. Make the EndUpdate call.
D. If the region created in Step 2 is not empty, copy this region into the updateRgn
for the window with CopyRgn. You can’t just do an InvalRgn with it because
InvalRgn globalizes the region and the region is already global. You want to
copy the region since this generates a valid update event. You can use CopyRgn
instead of UnionRgn because the update region is empty.
E. Dispose of the region created in Step 2.
With TaskMaster, things are a little messier. Since TaskMaster makes the EndUpdate call,
you have less control over the situation. It is important to do the EndUpdate before generating
the update event. Posting the update event has to happen outside the update procedure, since you
have to leave the update procedure for TaskMaster to do the EndUpdate. So it follows that
you do Steps A and B, post an application event to handle the rest externally, and when the
application event is handled, do Steps D and E.










