home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / mac / programm / 18241 < prev    next >
Encoding:
Text File  |  1992-11-10  |  4.5 KB  |  105 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!think.com!ames!data.nas.nasa.gov!taligent!kip-16.taligent.com!user
  3. From: keith@taligent.com (Keith Rollin)
  4. Subject: Re: Spurious invalidation
  5. Message-ID: <keith-101192141340@kip-16.taligent.com>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: usenet@taligent.com (More Bytes Than You Can Read)
  8. Organization: Taligent
  9. References: <1992Nov6.170232.21241@alw.nih.gov> <absurd-061192133636@seuss.apple.com> <1992Nov7.172136.7170@athena.mit.edu>,<1992Nov7.221521.21889@samba.oit.unc.edu> <1992Nov10.155449.14655@alw.nih.gov>
  10. Date: Tue, 10 Nov 1992 22:22:10 GMT
  11. Lines: 92
  12.  
  13. In article <1992Nov10.155449.14655@alw.nih.gov>, fixer@faxcsl.dcrt.nih.gov
  14. (Chris Spiral Catfish Tate) wrote:
  15. > Thanks to everyone who responded, either on the net or via email.
  16. > In summary, what's happening is that indeed, SetCTitle() is *both* redrawing
  17. > the control with its new title *and* causing an update event in the dialog.
  18. > I'm not quite clear on why it has to generate the update event, but that's
  19. > beside the point.
  20.  
  21. I looked into this when working on "Macintosh Programming Secrets." What
  22. happens when you call SetCTitle is the following:
  23.  
  24.     _HideControl
  25.     change the title of the control
  26.     _ShowControl
  27.  
  28. _HideControl calls _EraseControl and then invalidates the area under the
  29. control's bounds. This is correct behaviour for _HideControl. When
  30. _ShowControl is called, the control is redrawn, but the area is still
  31. marked invalid in the window's update region. The second drawing of the
  32. control is the dialog manager responding to the update.
  33.  
  34. > If you're absolutely sure you don't have to update anything else when the
  35. > control changes its title, you can also call ValidRect() on its rectangle
  36. > immediately following the call to SetCTitle(), and the update will be
  37. > "cancelled."
  38.  
  39. Right. Here's the section for MPS that deals with this issue. Note that it
  40. assumes that, if a dialog item is not a static or edit text item, that it
  41. is a control. This is not a valid assumption in all cases (as in the
  42. original poster's, who had user items in his dialog).
  43.  
  44. /*******************************************************************************
  45.  
  46.     SetDialogItemTitle
  47.  
  48.     Change the text associated with a particular dialog item. This is a little
  49.     tricky since there are two ways to change the text. If you are dealing
  50.     with an EditText or StatText (static text) item, you must call SetIText.
  51.     If you are dealing with a dialog item that is backed up by a Control
  52.     Manager control (like a simple button, radio button, or checkbox), you
  53.     must call SetCTitle.
  54.  
  55.     We determine what kind of dialog item we are dealing with by calling
  56.     GetDItem. Returned in the ╥kind╙ parameter is a number that identifies
  57.     what sort of item we are handling. First, we strip off the upper bit,
  58.     which identifies the item as being enabled or disabled. Once that bit is
  59.     removed, we can examine the kind of the item and act accordingly.
  60.  
  61.     Notice the special handling we give to controls when we call SetCTitle.
  62.     This is to take care of ╥excessive flashing╙ as Online Companion puts it.
  63.     When you call SetCTitle, the control manager first calls HideControl to
  64.     remove the control with its old text from the screen. It then changes the
  65.     control╒s title in the ControlRecord, and reshows the control by calling
  66.     ShowControl. At this point, the control is properly shown on the screen
  67.     with its correct, new title.
  68.  
  69.     However, there╒s a little time bomb lurking in the works. When HideControl
  70.     was called, the Control Manager called InvalRect on the area the control
  71.     occupied. Even though ShowControl was later called on the same area and
  72.     everything is drawn correctly, that rectangle is still marked as invalid
  73.     and is incorporated into the update region for the dialog. The event loop
  74.     at the heart of ModalDialog will then get an update event for that area
  75.     and redraw the button _again_! This can cause the button to flicker and
  76.     flash more than we would like. We already know that that area is
  77.     adequately drawn, so we tell the Event Manager to hoof it by validating it
  78.     with a call to ValidRect.
  79.  
  80. *******************************************************************************/
  81. void    SetDialogItemTitle(DialogPtr dlg, short item, Str255 *newTitle)
  82. {
  83.     short    iKind;
  84.     Handle    iHandle;
  85.     Rect    iRect;
  86.  
  87.     GetDItem(dlg, item, &iKind, &iHandle, &iRect);
  88.     iKind &= ~itemDisable;                // Strip off the enable/disable bit
  89.     if ((iKind == statText) || (iKind == editText)) {
  90.         SetIText(iHandle, *newTitle);
  91.     } else {
  92.         SetCTitle((ControlHandle) iHandle, *newTitle);
  93.         SetPort(dlg);
  94.         ValidRect(&iRect);
  95.     }
  96. }
  97.  
  98.  
  99. -----
  100. Keith Rollin
  101. Phantom Programmer
  102. Taligent, Inc.
  103.