home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19924 < prev    next >
Encoding:
Text File  |  1992-12-16  |  3.0 KB  |  72 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!friedman
  3. From: friedman@netcom.com (Greg Friedman)
  4. Subject: Re: Dialogs and Scrolling
  5. Message-ID: <1992Dec16.204039.26189@netcom.com>
  6. Organization: Netcom Online Communications Services (408-241-9760 login: guest)
  7. References: <1992Dec16.171910.8575@aio.jsc.nasa.gov>
  8. Date: Wed, 16 Dec 1992 20:40:39 GMT
  9. Lines: 61
  10.  
  11. In article <1992Dec16.171910.8575@aio.jsc.nasa.gov> mark@cheers.jsc.nasa.gov (Mark Manning) writes:
  12. >
  13. >   Question: I want to place a PICT picture onto the screen and
  14. >             then scroll it left and right.  On top of this PICT
  15. >             are editable fields.  Is this possible and if so
  16. >             could you post a snippet on how to do this?  I keep
  17. >             crashing my system when I try to do this. :(
  18.  
  19. If I understand correctly, you have a dialog on the screen and are
  20. attempting to scroll the contents of the dialog.  I have done
  21. something similar in the past, though my dlog did not contain a PICT.
  22. I don't think a pict item should make a difference. This code assumes
  23. that you are scrolling in response to a hit on the upButton in a scroll
  24. bar.  If you aren't scrolling in response to a scroll bar hit, or
  25. your dlog doesn't contain controls, than omit the control related code:
  26.  
  27.   SetCtlValue(vScrollHndl,(**vScrollHndl).contrlValue - 1);
  28.   ShiftControls(whichWindow,((-1) * kVScrollVal));
  29.                 
  30.   clipRect.right = clipRect.right - 15;
  31.   clipRect.bottom = clipRect.bottom - (15);
  32.   clipRect.top = clipRect.top + headerHeight;
  33.   ClipRect(&clipRect);
  34.   ScrollRect(&clipRect,0,kVScrollVal,((WindowPeek)whichWindow)->visRgn);
  35.   SetOrigin  (((GrafPtr)whichWindow)->portRect.left,
  36.       ((GrafPtr)whichWindow)->portRect.top - kVScrollVal);
  37.   clipRect = ((GrafPtr)whichWindow) ->portRect;
  38.   clipRect.right = clipRect.right - 15;
  39.   clipRect.top = clipRect.top + headerHeight;
  40.   clipRect.bottom = clipRect.top + kVScrollVal;
  41.   ClipRect(&clipRect);
  42.   DrawDialog((DialogPtr)whichWindow);
  43.   ValidRect(&((GrafPtr)whichWindow) ->portRect);
  44.  
  45. I didn't scroll the entire contents of the dlog.  I omitted a header,
  46. whose height was defined in headerHeight.  Be sure to set the origin
  47. of the dlog. Otherwise dlog items will be drawn in the wrong places
  48. when the dialog is drawn.  Also, be sure to validate the dlog rect
  49. after your call to draw dlog.  In case you have controls in the window,
  50. you'll have to shift them yourself.  Here's the function ShiftControls
  51. that I call from the above code.
  52.  
  53. void
  54. ShiftControls(    WindowPtr    whichWindow,
  55.   short    shiftVal)
  56. {
  57.  ControlHandle    whichControl;
  58.     
  59.     /*set whichControl to the window's first control*/
  60.     whichControl = ((WindowPeek)whichWindow)->controlList;
  61.     
  62.     /* now loop through all of the controls and shift them by shiftVal*/
  63.     do{
  64.   (**whichControl).contrlRect.top = (**whichControl).contrlRect.top + shiftVal;
  65.   (**whichControl).contrlRect.bottom = (**whichControl).contrlRect.bottom + 
  66.      shiftVal;
  67.   whichControl = (**whichControl).nextControl;
  68.  } while (whichControl);
  69. }
  70.  
  71. Hope this helps.
  72.