home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff386.lzh / XLispStat / src3.lzh / Mac / maciviewwindow2.c < prev    next >
C/C++ Source or Header  |  1990-07-30  |  18KB  |  722 lines

  1. #ifdef MPWC
  2. #include <Windows.h>
  3. #include <Menus.h>
  4. #include <ToolUtils.h>
  5. #include <Events.h>
  6. #include <Controls.h>
  7. #include <Fonts.h>
  8. #include <Script.h>
  9. #else
  10. #include <WindowMgr.h>
  11. #include <MenuMgr.h>
  12. #include <ToolboxUtil.h>
  13. #include <EventMgr.h>
  14. #include <ControlMgr.h>
  15. #include <FontMgr.h>
  16. #include <Color.h>
  17. #endif MPWC
  18.  
  19. #include "StGWWindow.h"
  20. #include "macgraphwindow.h"
  21.  
  22. /**************************************************************************/
  23. /**                                                                      **/
  24. /**                    Action Installation Functions                     **/
  25. /**                                                                      **/
  26. /**************************************************************************/
  27.  
  28. StGWSetFreeMem(gwinfo, FreeMem)
  29.     StGWWinInfo *gwinfo;
  30.     int (*FreeMem)();
  31. {
  32.   if (gwinfo == nil) return;
  33.   else gwinfo->FreeMem =  FreeMem;
  34. }
  35.  
  36. StGWIdleOn(gwinfo)
  37.     StGWWinInfo *gwinfo;
  38. {
  39.   
  40.   if (gwinfo == nil) return(FALSE);
  41.   else return(gwinfo->idleOn);
  42. }
  43.  
  44. StGWSetIdleOn(gwinfo, on)
  45.     StGWWinInfo *gwinfo;
  46.     int on;
  47. {
  48.   if (gwinfo != nil) gwinfo->idleOn = on;
  49. }
  50.  
  51. /**************************************************************************/
  52. /**                                                                      **/
  53. /**                      Window Management Functions                     **/
  54. /**                                                                      **/
  55. /**************************************************************************/
  56.  
  57. StGWShowWindow(gwinfo)
  58.     StGWWinInfo *gwinfo;
  59. {
  60.   WindowPtr w;
  61.   
  62.   if (gwinfo == nil || (w = gwinfo->window) == nil) return;
  63.   else {
  64.     MyShowWindow(w);
  65.     if (! gwinfo->initialized) StGWInitialDraw(gwinfo);
  66.   }
  67. }
  68.  
  69. StGWRemove(gwinfo)
  70.     StGWWinInfo *gwinfo;
  71. {
  72.   WindowPtr w;
  73.   
  74.   if (gwinfo == nil || (w = gwinfo->window) == nil) return;
  75.   else SkelRmveWind(w);
  76. }
  77.  
  78. StGWWhileButtonDown(gwinfo, action, motionOnly)
  79.     StGWWinInfo *gwinfo;
  80.     int (*action)(), motionOnly;
  81. {
  82.   Point pt;
  83.   GrafPtr savePort;
  84.   WindowPtr w;
  85.   
  86.   if (gwinfo == nil || (w = gwinfo->window) == nil) return;
  87.   
  88.   GetPort(&savePort);
  89.   SetPort(w);
  90.   while (StillDown()) {
  91.     SetPort(w);
  92.     mac_do_cursor(gwinfo);
  93.     GetMouse(&pt);
  94.     if (gwinfo->mouse_x != pt.h || gwinfo->mouse_y != pt.v || ! motionOnly) {
  95.       gwinfo->mouse_x = pt.h; gwinfo->mouse_y = pt.v;
  96.       if (action != nil) (*action)(w, pt.h, pt.v);
  97.     }
  98.   }
  99.   SetPort(savePort);
  100. }
  101.  
  102. static TitleBarHeight(w)
  103.     WindowPtr w;
  104. {
  105.   Rect r;
  106.   Point pt;
  107.   WindowPeek wind = (WindowPeek) w;
  108.   GrafPtr savePort;
  109.   
  110.   GetPort(&savePort);
  111.   SetPort(w);
  112.   SetPt(&pt, 0, 0);
  113.   LocalToGlobal(&pt);
  114.   r = (*(wind->strucRgn))->rgnBBox;
  115.   SetPort(savePort);
  116.   return(pt.v - r.top);
  117. }
  118.  
  119. StWSetLocation(w, left, top, frame)
  120.     WindowPtr w;
  121.     int left, top, frame;
  122. {
  123.   int adjust;
  124.   
  125.   if (w == nil) return;
  126.   adjust = (frame) ? MBarHeight + TitleBarHeight(w) : MBarHeight;
  127.   MoveWindow(w, left, top + adjust, FALSE);
  128. }
  129.  
  130. StWGetLocation(w, left, top, frame)
  131.     WindowPtr w;
  132.     int *left, *top, frame;
  133. {
  134.   GrafPtr savePort;
  135.   Point pt;
  136.   int adjust;
  137.   
  138.   if (w == nil) return;
  139.   else {
  140.     adjust = (frame) ? MBarHeight + TitleBarHeight(w) : MBarHeight;
  141.     GetPort(&savePort);
  142.     SetPort(w);
  143.     pt.h = w->portRect.left;
  144.     pt.v = w->portRect.top;
  145.     LocalToGlobal(&pt);
  146.     if (left != nil) *left = pt.h;
  147.     if (top != nil) *top = pt.v - adjust;
  148.     SetPort(savePort);
  149.   }
  150. }
  151.  
  152. StGWSetSize(gwinfo, width, height, frame)
  153.     StGWWinInfo *gwinfo;
  154.     int width, height;
  155. {
  156.   WindowPtr w;
  157.   if (gwinfo == nil || (w = gwinfo->window) == nil) return;
  158.   else StWSetSize(w, width, height, frame);
  159. }
  160.  
  161. StWSetSize(w, width, height, frame)
  162.     WindowPtr w;
  163.     int width, height;
  164. {
  165.   GrafPtr savePort;
  166.   
  167.   if (w == nil) return;
  168.   GetPort(&savePort);
  169.   SetPort(w);
  170.   SizeWindow(w, width, height - ((frame) ? TitleBarHeight(w) : 0), TRUE);
  171.   InvalRect(&w->portRect);
  172.   mac_update_action(TRUE);
  173.   SetPort(savePort);
  174. }
  175.  
  176. StWGetSize(w, width, height, frame)
  177.     WindowPtr w;
  178.     int *width, *height;
  179. {
  180.   
  181.   if (w == nil) return;
  182.   else {
  183.     if (width != nil) *width = w->portRect.right - w->portRect.left;
  184.     if (height != nil) *height = w->portRect.bottom - w->portRect.top 
  185.                                + ((frame) ? TitleBarHeight(w) : 0);
  186.   }
  187. }
  188.  
  189. /**************************************************************************/
  190. /**                                                                      **/
  191. /**             Window State Access and Mutation Functions               **/
  192. /**                                                                      **/
  193. /**************************************************************************/
  194.  
  195. SetHardwareState(gwinfo)
  196.     StGWWinInfo *gwinfo;
  197. {
  198.   GrafPtr savePort;
  199.   WindowPtr w;
  200.   
  201.   if (gwinfo == nil || (w = gwinfo->window) == nil) return;
  202.  
  203.   GetPort(&savePort);
  204.   SetPort(w);
  205.   
  206.   set_fore_color(gwinfo);
  207.   set_back_color(gwinfo);
  208.   if (gwinfo->drawMode == 0) w->pnMode = patCopy;
  209.   else w->pnMode = patXor;
  210.   if (gwinfo->drawMode == 0) {
  211.     w->txMode = srcOr;
  212.     gwinfo->symbolMode = srcCopy;
  213.   }
  214.   else {
  215.     w->txMode = srcXor;
  216.     gwinfo->symbolMode = srcXor;
  217.   }
  218.   
  219.   /* set line type */
  220.   if (gwinfo->lineType != 0 && gwinfo->drawColor != gwinfo->backColor)
  221.     PenPat(gray);
  222.   else PenPat(black);
  223.   
  224.   /* set pen size */
  225.   PenSize(gwinfo->lineWidth, gwinfo->lineWidth);
  226.   
  227.   adjust_graph_workport(gwinfo);
  228.   SetPort(savePort);
  229. }
  230.  
  231. static get_state(gwinfo, which)
  232.     StGWWinInfo *gwinfo;
  233.     int which;
  234. {
  235.   if (gwinfo == nil) return(0);
  236.   switch (which) {
  237.   case 'W': return(gwinfo->canvasWidth);
  238.   case 'H': return(gwinfo->canvasHeight);
  239.   case 'L': return(gwinfo->lineType);
  240.   case 'M': return(gwinfo->drawMode);
  241.   case 'D': return(gwinfo->drawColor);
  242.   case 'B': return(gwinfo->backColor);
  243.   case 'C': return(gwinfo->use_color);
  244.   }
  245. }
  246.  
  247. StGWCanvasWidth(gwinfo) StGWWinInfo *gwinfo; { return (get_state(gwinfo, 'W')); }
  248. StGWCanvasHeight(gwinfo) StGWWinInfo *gwinfo;{ return (get_state(gwinfo, 'H')); }
  249. StGWLineType(gwinfo) StGWWinInfo *gwinfo;    { return (get_state(gwinfo, 'L')); }
  250. StGWDrawMode(gwinfo) StGWWinInfo *gwinfo;    { return (get_state(gwinfo, 'M')); }
  251.  
  252. ColorCode StGWDrawColor(gwinfo) 
  253.     StGWWinInfo *gwinfo;
  254. {
  255.   return ((ColorCode) get_state(gwinfo, 'D'));
  256. }
  257.  
  258. ColorCode StGWBackColor(gwinfo)
  259.     StGWWinInfo *gwinfo;
  260. {
  261.   return ((ColorCode) get_state(gwinfo, 'B'));
  262. }
  263.  
  264. StGWUseColor(gwinfo) StGWWinInfo *gwinfo; { return (get_state(gwinfo, 'C')); }
  265.  
  266. StGWGetLineWidth(gwinfo, width)
  267.     StGWWinInfo *gwinfo;
  268.     int *width;
  269. {
  270.   if (gwinfo == nil) return;
  271.   if (width != nil) *width = gwinfo->lineWidth;
  272. }
  273.  
  274. static set_state(gwinfo, which, value)
  275.     StGWWinInfo *gwinfo;
  276.     int which, value;
  277. {
  278.   int changed;
  279.   
  280.   if (gwinfo == nil) return;
  281.   switch (which) {
  282.   case 'L': if ((changed = (value != gwinfo->lineType))) gwinfo->lineType = value;  break;
  283.   case 'M': if ((changed = (value != gwinfo->drawMode))) gwinfo->drawMode = value;  break;
  284.   case 'D': if ((changed = (value != gwinfo->drawColor))) gwinfo->drawColor = value; break;
  285.   case 'B': if ((changed = (value != gwinfo->backColor))) gwinfo->backColor = value; break;
  286.   case 'C': if ((changed = (value != gwinfo->use_color))) 
  287.               gwinfo->use_color = (StScreenHasColor()) ? value : FALSE;
  288.             break;
  289.   }
  290.   if (changed) SetHardwareState(gwinfo);
  291.   if (changed && which == 'B') DrawGWGrowBox(gwinfo);
  292. }
  293.  
  294. StGWSetLineType(gwinfo, type)
  295.     StGWWinInfo *gwinfo;
  296.     int type;
  297. {
  298.   set_state(gwinfo, 'L', type);
  299. }
  300.  
  301. StGWSetDrawMode(gwinfo, mode)
  302.     StGWWinInfo *gwinfo;
  303.     int mode;
  304. {
  305.   set_state(gwinfo, 'M', mode);
  306. }
  307.  
  308. StGWSetDrawColor(gwinfo, color)
  309.     StGWWinInfo *gwinfo;
  310.     ColorCode color;
  311. {
  312.   set_state(gwinfo, 'D', (ColorCode) color);
  313. }
  314.  
  315. StGWSetBackColor(gwinfo, color)
  316.     StGWWinInfo *gwinfo;
  317.     ColorCode color;
  318. {
  319.   set_state(gwinfo, 'B', (ColorCode) color);
  320. }
  321.  
  322. StGWSetUseColor(gwinfo, use)
  323.     StGWWinInfo *gwinfo;
  324.     int use;
  325. {
  326.   set_state(gwinfo, 'C', use);
  327. }
  328.  
  329. StGWSetLineWidth(gwinfo, width)
  330.     StGWWinInfo *gwinfo;
  331.     int width;
  332. {
  333.   int changed;
  334.   
  335.   if (gwinfo == nil) return;
  336.   changed = (width != gwinfo->lineWidth);
  337.   if (changed) {
  338.     gwinfo->lineWidth = width;
  339.     SetHardwareState(gwinfo);
  340.   }
  341. }
  342.  
  343. StGWReverseColors(gwinfo)
  344.     StGWWinInfo *gwinfo;
  345. {
  346.   ColorCode backColor, drawColor;
  347.   char *object;
  348.   
  349.   object = (char *) StGWGetObject(gwinfo);
  350.  
  351.   backColor = StGWBackColor(gwinfo);
  352.   drawColor = StGWDrawColor(gwinfo);
  353.   if (backColor != drawColor) {
  354.     StGWSetBackColor(gwinfo, drawColor);
  355.     StGWSetDrawColor(gwinfo, backColor);
  356.     StGWObRedraw(object);
  357.   }
  358. }
  359.  
  360. StGWGetViewRect(gwinfo, left, top, width, height)
  361.     StGWWinInfo *gwinfo;
  362.     int *left, *top, *width, *height;
  363. {
  364.   WindowPtr w;
  365.   
  366.   if (gwinfo != nil && (w = gwinfo->window) != nil) {
  367.     if (left != nil) *left = w->portRect.left;
  368.     if (top != nil) *top = w->portRect.top;
  369.     if (width != nil) *width = w->portRect.right - w->portRect.left - 15;
  370.     if (height != nil) *height = w->portRect.bottom - w->portRect.top;
  371.     if (height != nil && StGWHasHscroll(gwinfo)) *height -= 15;
  372.   }
  373.   else {
  374.     if (left != nil) *left = 0;
  375.     if (top != nil) *top = 0;
  376.     if (width != nil) *width = 1;
  377.     if (height != nil) *height = 1;
  378.   }
  379. }
  380.  
  381. /**************************************************************************/
  382. /**                                                                      **/
  383. /**                       Window Scrolling Functions                     **/
  384. /**                                                                      **/
  385. /**************************************************************************/
  386.  
  387. static set_has_scroll(gwinfo, which, has, size)
  388.     StGWWinInfo *gwinfo;
  389.     int which, has, size;
  390. {
  391.   WindowPtr w;
  392.   GrafPtr savePort;
  393.   int view_size, value, old_has;
  394.   ControlHandle ctl;
  395.   char *object;
  396.   
  397.   if (gwinfo == nil || (w = gwinfo->window) == nil) return;
  398.  
  399.   GetPort(&savePort);
  400.   SetPort(w);
  401.   
  402.   if (has && size <= 0) StPerror("size must be positive");
  403.   object = (char *) StGWGetObject(gwinfo);
  404.  
  405.   ClipRect(&w->portRect);
  406.  
  407.   ctl = (which == 'H') ? gwinfo->hscroll : gwinfo->vscroll;
  408.    
  409.   old_has = (which == 'H') ? gwinfo->hasHscroll : gwinfo->hasVscroll;
  410.   if (which == 'H') gwinfo->hasHscroll = has;
  411.   else gwinfo->hasVscroll = has;
  412.     
  413.   if (has) {
  414.     if (w == FrontWindow()) HiliteControl(ctl, 0);
  415.     else HiliteControl(ctl, 255);
  416.     if (which == 'H') {
  417.       if (! old_has) gwinfo->canvasHeight -= 15;
  418.       if (gwinfo->hasVscroll) {
  419.         StGWGetViewRect(gwinfo, nil, nil, nil, &view_size);
  420.         value = (gwinfo->canvasHeight - view_size > 0)
  421.               ? gwinfo->canvasHeight - view_size : 0;
  422.         SetCtlMax(gwinfo->vscroll, value);
  423.       }
  424.       gwinfo->canvasWidth = size;
  425.       StGWGetViewRect(gwinfo, nil, nil, &view_size, nil);
  426.     }
  427.     else {
  428.       gwinfo->canvasHeight = size;
  429.       StGWGetViewRect(gwinfo, nil, nil, nil, &view_size);
  430.     }
  431.     value = (size - view_size > 0) ? size - view_size : 0;
  432.     SetCtlMax(ctl, value);
  433.     ShowControl(ctl);
  434.   }
  435.   else {
  436.     if (which == 'H') {
  437.       StGWGetViewRect(gwinfo, nil, nil, &gwinfo->canvasWidth, nil);
  438.       if (old_has) gwinfo->canvasHeight += 15;
  439.       StGWSetScroll(gwinfo, 0, gwinfo->view_v, TRUE);
  440.     }
  441.     else {
  442.       StGWGetViewRect(gwinfo, nil, nil, nil, &gwinfo->canvasHeight);
  443.       StGWSetScroll(gwinfo, gwinfo->view_h, 0, TRUE);
  444.     }
  445.     HideControl(ctl);
  446.     SetCtlMax(ctl, 0);
  447.   }
  448.   InvalRect(&w->portRect);
  449.   reset_clip_rect(gwinfo);
  450.   SetPort(savePort);
  451.  
  452.   StGWObResize(object);
  453. }
  454.  
  455. StGWSetHasHscroll(gwinfo, has, size)
  456.     StGWWinInfo *gwinfo;
  457.     int has, size;
  458. {
  459.   set_has_scroll(gwinfo, 'H', has, size);
  460. }
  461.  
  462. StGWSetHasVscroll(gwinfo, has, size)
  463.     StGWWinInfo *gwinfo;
  464.     int has, size;
  465. {
  466.   set_has_scroll(gwinfo, 'V', has, size);
  467. }
  468.  
  469. StGWHasHscroll(gwinfo)
  470.     StGWWinInfo *gwinfo;
  471. {
  472.   if (gwinfo == nil) return(FALSE);
  473.   else return(gwinfo->hasHscroll);
  474. }
  475.  
  476. StGWHasVscroll(gwinfo)
  477.     StGWWinInfo *gwinfo;
  478. {
  479.   if (gwinfo == nil) return(FALSE);
  480.   else return(gwinfo->hasVscroll);
  481. }
  482.  
  483. StGWSetScroll(gwinfo, h, v, move)
  484.     StGWWinInfo *gwinfo;
  485.     int h, v, move;
  486. {
  487.   WindowPtr w;
  488.   GrafPtr savePort;
  489.   Rect r;
  490.   
  491.   if (gwinfo == nil || (w = gwinfo->window) == nil) return;
  492.   gwinfo->view_h = (gwinfo->hasHscroll) ? h : 0;
  493.   gwinfo->view_v = (gwinfo->hasVscroll) ? v : 0;
  494.     
  495.   GetPort(&savePort);
  496.   SetPort(w);
  497.   ClipRect(&w->portRect);
  498.   SetCtlValue(gwinfo->hscroll, h);
  499.   SetCtlValue(gwinfo->vscroll, v);
  500.   gwinfo->view_h = GetCtlValue(gwinfo->hscroll);
  501.   gwinfo->view_v = GetCtlValue(gwinfo->vscroll);
  502.   SetOrigin(gwinfo->view_h, gwinfo->view_v);
  503.   reset_clip_rect(gwinfo);
  504.   if (move) {
  505.     r = scroll_bar_bounds(w, 'H');
  506.     MoveControl(gwinfo->hscroll, r.left, r.top);
  507.     r = scroll_bar_bounds(w, 'V');
  508.     MoveControl(gwinfo->vscroll, r.left, r.top);
  509.   }
  510.   SetPort(savePort);
  511. }
  512.  
  513. StGWGetScroll(gwinfo, h, v)
  514.     StGWWinInfo *gwinfo;
  515.     int *h, *v;
  516. {
  517.   
  518.   if (gwinfo != nil) {
  519.     if (h != nil) *h = gwinfo->view_h;
  520.     if (v != nil) *v = gwinfo->view_v;
  521.   }
  522. }
  523.  
  524. StGWSetHscrollIncs(gwinfo, inc, pageInc)
  525.     StGWWinInfo *gwinfo;
  526.     int inc, pageInc;
  527. {
  528.   if (gwinfo == nil) return;
  529.   gwinfo->h_scroll_inc[0] = inc;
  530.   gwinfo->h_scroll_inc[1] = pageInc;
  531. }
  532.  
  533. StGWGetHscrollIncs(gwinfo, inc, pageInc)
  534.     StGWWinInfo *gwinfo;
  535.     int *inc, *pageInc;
  536. {
  537.   if (gwinfo == nil) return;
  538.   if (inc != 0) *inc = gwinfo->h_scroll_inc[0];
  539.   if (pageInc != 0) *pageInc = gwinfo->h_scroll_inc[1];
  540. }
  541.  
  542. StGWSetVscrollIncs(gwinfo, inc, pageInc)
  543.     StGWWinInfo *gwinfo;
  544.     int inc, pageInc;
  545. {
  546.   if (gwinfo == nil) return;
  547.   gwinfo->v_scroll_inc[0] = inc;
  548.   gwinfo->v_scroll_inc[1] = pageInc;
  549. }
  550.  
  551. StGWGetVscrollIncs(gwinfo, inc, pageInc)
  552.     StGWWinInfo *gwinfo;
  553.     int *inc, *pageInc;
  554. {
  555.   if (gwinfo == nil) return;
  556.   if (inc != 0) *inc = gwinfo->v_scroll_inc[0];
  557.   if (pageInc != 0) *pageInc = gwinfo->v_scroll_inc[1];
  558. }
  559.  
  560. /**************************************************************************/
  561. /**                                                                      **/
  562. /**                    Graph Window RefCon Functions                     **/
  563. /**                                                                      **/
  564. /**************************************************************************/
  565.  
  566. StGWSetRefCon(gwinfo, x)
  567.     StGWWinInfo *gwinfo;
  568.     long x;
  569. {
  570.   if (gwinfo == nil) return;
  571.   else gwinfo->RefCon = x;
  572. }
  573.  
  574. long StGWGetRefCon(gwinfo)
  575.     StGWWinInfo *gwinfo;
  576. {
  577.   if (gwinfo == nil) return(nil);
  578.   else return(gwinfo->RefCon);
  579. }
  580.  
  581. StGWSetObject(gwinfo, x)
  582.     StGWWinInfo *gwinfo;
  583.     long x;
  584. {
  585.   if (gwinfo == nil) return;
  586.   else gwinfo->Object = x;
  587. }
  588.  
  589. long IViewWindowGetObject(w)
  590.     WindowPtr w;
  591. {
  592.   StGWWinInfo *gwinfo = (StGWWinInfo *) GetWRefCon(w);
  593.   if (gwinfo == nil) return(nil);
  594.   else return(gwinfo->Object);
  595. }
  596.  
  597. long StGWGetObject(gwinfo)
  598.     StGWWinInfo *gwinfo;
  599. {
  600.   return((gwinfo != nil) ? gwinfo->Object : nil);
  601. }
  602.        
  603. StGWInitialDraw(gwinfo)
  604.     StGWWinInfo *gwinfo;
  605. {
  606.   WindowPtr w;
  607.   
  608.   if (gwinfo != nil && (w = gwinfo->window) != nil) { 
  609.     graph_update_action(gwinfo, TRUE);
  610.     /*ValidRect(&w->portRect);*//* causes problems with new initial draw */
  611.   }
  612. }
  613.  
  614. /**************************************************************************/
  615. /**                                                                      **/
  616. /**                    Graph Window Color Functions                      **/
  617. /**                                                                      **/
  618. /**************************************************************************/
  619.  
  620. #define NumBasicColors 8
  621. #define NumRGBColors 100
  622. # define MULTIPLIER 62535
  623.  
  624. static int NumColors;
  625.  
  626. typedef struct {
  627.   union {
  628.     long old;
  629.     RGBColor rgb;
  630.   } value;
  631.   long refcon;
  632. } ctab_entry;
  633.  
  634. static ctab_entry *ctable;
  635.  
  636. init_mac_colors()
  637. {
  638.   NumColors = NumBasicColors;
  639.   if (StScreenHasColor()) NumColors += NumRGBColors;
  640.   ctable = (ctab_entry *) StCalloc(NumColors, sizeof(ctab_entry));
  641.   
  642.   ctable[0].value.old = whiteColor;
  643.   ctable[1].value.old = blackColor;
  644.   ctable[2].value.old = redColor;
  645.   ctable[3].value.old = greenColor;
  646.   ctable[4].value.old = blueColor;
  647.   ctable[5].value.old = cyanColor;
  648.   ctable[6].value.old = magentaColor;
  649.   ctable[7].value.old = yellowColor;
  650. }
  651.  
  652. StGWMakeColor(red, green, blue, refcon)
  653.     double red, green, blue;
  654.     long refcon;
  655. {
  656.   int index;
  657.   
  658.   for (index = NumBasicColors; 
  659.        index < NumColors && StGWGetColRefCon(index) != nil; 
  660.        index++);
  661.   if (index >= NumColors) return(-1);
  662.   else {
  663.     StGWSetColRefCon(index, refcon);
  664.     ctable[index].value.rgb.red = MULTIPLIER * red;
  665.     ctable[index].value.rgb.green = MULTIPLIER * green;
  666.     ctable[index].value.rgb.blue = MULTIPLIER * blue;
  667.     return(index);
  668.   }
  669. }
  670.  
  671. StGWFreeColor(index)
  672.     unsigned int index;
  673. {
  674.   if (index < NumColors && index >= NumBasicColors)
  675.     StGWSetColRefCon(index, nil);
  676.   else StPerror("can't free standard color");
  677. }
  678.  
  679. StGWSetColRefCon(index, rc)
  680.     unsigned int index;
  681.     long rc;
  682. {
  683.   if (index < NumColors) ctable[index].refcon = rc;
  684. }
  685.  
  686. long StGWGetColRefCon(index)
  687.     unsigned int index;
  688. {    
  689.   if (index < NumColors) return(ctable[index].refcon);
  690.   else return(nil);
  691. }
  692.  
  693. static long get_color(index)
  694.     unsigned int index;
  695. {
  696.   if (index < NumBasicColors) return(ctable[index].value.old);
  697.   else return(ctable[1].value.old);
  698. }
  699.  
  700. static RGBColor *get_rgb_color(index)
  701.     unsigned int index;
  702. {
  703.   if (index < NumColors) return(&ctable[index].value.rgb);
  704.   else StPerror("bad rgb color");
  705. }
  706.  
  707. set_fore_color(gwinfo)
  708.     StGWWinInfo *gwinfo;
  709. {
  710.   if (gwinfo->drawColor < NumBasicColors)
  711.     ForeColor(get_color(gwinfo->drawColor));
  712.   else RGBForeColor(get_rgb_color(gwinfo->drawColor));
  713. }
  714.  
  715. set_back_color(gwinfo)
  716.     StGWWinInfo *gwinfo;
  717. {
  718.   if (gwinfo->backColor < NumBasicColors)
  719.     BackColor(get_color(gwinfo->backColor));
  720.   else RGBForeColor(get_rgb_color(gwinfo->backColor));
  721. }
  722.