home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / bigscroll ƒ / bigscroll.c next >
Encoding:
C/C++ Source or Header  |  1996-03-28  |  4.6 KB  |  210 lines

  1. #include "bigscroll.h"
  2. #include "bigscroll.proto.h"
  3.  
  4.  
  5. #define HACKY_COLOR_SAVE        \
  6.   {                    \
  7.     RGBColor save_fore, save_back;    \
  8.                         \
  9.     GetForeColor (&save_fore);        \
  10.     GetBackColor (&save_back);        \
  11.     ForeColor (blackColor);        \
  12.     BackColor (whiteColor);
  13.  
  14. #define HACKY_COLOR_RESTORE        \
  15.     RGBForeColor (&save_fore);        \
  16.     RGBBackColor (&save_back);        \
  17.   }
  18.  
  19. void
  20. getregions (ControlHandle c)
  21. {
  22.   Rect *r;
  23.   bigsrgns **h;
  24.   short height, width;
  25.  
  26.   HLock ((Handle) c);
  27.   h = (bigsrgns **) (*c)->contrlData;
  28.   r = &(*c)->contrlRect;
  29.   height = r->bottom - r->top;
  30.   width = r->right - r->left;
  31.   if (height > width)
  32.     {
  33.       OpenRgn ();
  34.       MoveTo (r->left, r->top + width / 2);
  35.       LineTo (r->right, r->top + width / 2);
  36.       LineTo (r->left + width / 2, r->top);
  37.       LineTo (r->left, r->top + width / 2);
  38.       CloseRgn ((*h)->upbutton);
  39.       OpenRgn ();
  40.       MoveTo (r->left, r->bottom - width / 2);
  41.       LineTo (r->right, r->bottom - width / 2);
  42.       LineTo (r->left + width / 2, r->bottom);
  43.       LineTo (r->left, r->bottom - width / 2);
  44.       CloseRgn ((*h)->downbutton);
  45.     }
  46.   else
  47.     {
  48.       OpenRgn ();
  49.       MoveTo (r->left + height / 2, r->top);
  50.       LineTo (r->left + height / 2, r->bottom);
  51.       LineTo (r->left, r->top + height / 2);
  52.       LineTo (r->left + height / 2, r->top);
  53.       CloseRgn ((*h)->upbutton);
  54.       OpenRgn ();
  55.       MoveTo (r->right - height / 2, r->bottom);
  56.       LineTo (r->right, r->top + height / 2);
  57.       LineTo (r->right - height / 2, r->top);
  58.       LineTo (r->right - height / 2, r->bottom);
  59.       CloseRgn ((*h)->downbutton);
  60.     }
  61.   (*h)->rect = (*c)->contrlRect;
  62.   HUnlock ((Handle) c);
  63. }
  64.  
  65. void
  66. draw1part (ControlHandle c, short part, RgnHandle rgn, short where, int val)
  67. {
  68.   RgnHandle tmprgn;
  69.   short height, width;
  70.  
  71.   if (part == where || part == 0)
  72.     {
  73.       HACKY_COLOR_SAVE
  74.       if ((*c)->contrlHilite == where)
  75.     {
  76.       PaintRgn (rgn);
  77.     }
  78.       else
  79.     EraseRgn (rgn);
  80.       FrameRgn (rgn);
  81.       if ((*c)->contrlHilite != 255 && (*c)->contrlValue != val)
  82.     {
  83.       tmprgn = NewRgn ();
  84.       CopyRgn (rgn, tmprgn);
  85.       height = (*tmprgn)->rgnBBox.bottom - (*tmprgn)->rgnBBox.top;
  86.       width = (*tmprgn)->rgnBBox.right - (*tmprgn)->rgnBBox.left;
  87.       InsetRgn (tmprgn, width / 6, height / 6);
  88.       DiffRgn (rgn, tmprgn, tmprgn);
  89.       PaintRgn (tmprgn);
  90.       DisposeRgn (tmprgn);
  91.     }
  92.       HACKY_COLOR_RESTORE
  93.     }
  94. }
  95.  
  96. void
  97. drawcontrol (long part, ControlHandle c)
  98. {
  99.   GrafPtr saveport;
  100.  
  101.   if (!EqualRect (&(*c)->contrlRect, &(*(bigsrgns **) (*c)->contrlData)->rect))
  102.     getregions (c);
  103.   GetPort (&saveport);
  104.   SetPort ((*c)->contrlOwner);
  105.   PenNormal ();
  106.   draw1part (c, part, (*(bigsrgns **) (*c)->contrlData)->upbutton, inUpButton,
  107.          (*c)->contrlMin);
  108.   draw1part (c, part, (*(bigsrgns **) (*c)->contrlData)->downbutton, inDownButton,
  109.          (*c)->contrlMax);
  110.   SetPort (saveport);
  111. }
  112.  
  113. long
  114. test (long param, ControlHandle c)
  115. {
  116.   Point p;
  117.  
  118. #if 1
  119.   if (param)
  120.     (*c)->contrlRfCon = param;
  121. #endif /* 0 */
  122.   p.v = HiWord (param);
  123.   p.h = LoWord (param);
  124.   if ((*c)->contrlHilite != 255)
  125.     if (PtInRgn (p, (*(bigsrgns **) (*c)->contrlData)->downbutton))
  126.       {
  127. /*-->*/ return (long) inDownButton;
  128.       }
  129.     else if (PtInRgn (p, (*(bigsrgns **) (*c)->contrlData)->upbutton))
  130. /*-->*/ return (long) inUpButton;
  131.   return 0L;
  132. }
  133.  
  134.  
  135. void
  136. calc (RgnHandle rgn, ControlHandle c)
  137. {
  138.   if (!EqualRect (&(*c)->contrlRect, &(*(bigsrgns **) (*c)->contrlData)->rect))
  139.     getregions (c);
  140.   UnionRgn ((*(bigsrgns **) (*c)->contrlData)->downbutton,
  141.         (*(bigsrgns **) (*c)->contrlData)->upbutton, rgn);
  142. }
  143.  
  144. void
  145. initbigs (ControlHandle c)
  146. {
  147.   bigsrgns **h;
  148.  
  149.   (*c)->contrlData = NewHandle (sizeof (bigsrgns));
  150.   h = (bigsrgns **) (*c)->contrlData;
  151.   (*h)->upbutton = NewRgn ();
  152.   (*h)->downbutton = NewRgn ();
  153.   getregions (c);
  154. }
  155.  
  156. void
  157. disposebigs (ControlHandle c)
  158. {
  159.   bigsrgns **h;
  160.  
  161.   h = (bigsrgns **) (*c)->contrlData;
  162.   DisposeRgn ((*h)->upbutton);
  163.   DisposeRgn ((*h)->downbutton);
  164.   DisposHandle ((*c)->contrlData);
  165. }
  166.  
  167. pascal long
  168. main (short varcode, ControlHandle c, short message, long param)
  169. {
  170.   long retval;
  171.  
  172.   retval = 0;
  173.   switch (message)
  174.     {
  175.     case drawCntl:
  176.       drawcontrol (param, c);
  177.       break;
  178.     case testCntl:
  179.       retval = test (param, c);
  180.       break;
  181.     case calcCRgns:
  182. #ifdef LIVEDANGEROUSLY
  183.       if (param & 0x80000000)
  184.     param &= 0x00FFFFFF
  185. #endif /* LIVEDANGEROUSLY */
  186. /* FALL THROUGH --> */
  187.     case calcCntlRgn:
  188.     calc ((RgnHandle) param, c);
  189.       break;
  190.     case initCntl:
  191.       initbigs (c);
  192.       break;
  193.     case dispCntl:
  194.       disposebigs (c);
  195.       break;
  196.  
  197.     case posCntl:
  198.     case thumbCntl:
  199.     case dragCntl:
  200.     case autoTrack:
  201.     case calcThumbRgn:
  202.       break;
  203.     default:
  204.       break;
  205.     }
  206.   return retval;
  207. }
  208.  
  209.  
  210.