home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / ncsa_tel / contribu / byu_tel2.hqx / vs / rsmac.c next >
Text File  |  1990-04-23  |  41KB  |  1,731 lines

  1. #ifndef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. /*
  5.  *
  6.  *      Virtual Screen Kernel Macintosh Real Screen Interface
  7.  *                          (rsmac.c)
  8.  *
  9.  *   National Center for Supercomputing Applications
  10.  *      by Gaige B. Paulsen
  11.  *
  12.  *    This file contains the macintosh real screen calls for the NCSA
  13.  *  Virtual Screen Kernel.
  14.  *
  15.  *      RSbell(w)                   - Ring window w's bell
  16.  *      RScursoff(w)                - Turn the cursor off in w
  17.  *      RScurson(w,x,y)             - Turn the cursor on in w at x,y
  18.  *      RSdraw(w,x,y,a,len,ptr)     - Draw @x,y in w string@ptr for length len
  19.  *      RSdelchars(w,x,y,n)         - Delete n chars in w from x,y
  20.  *      RSdellines(w,t,b,n)         - Delete n lines in region t->b in w
  21.  *      RSerase(w,x1,y1,x2,y2)      - Erase from x1,y1 to x2,y2 in w
  22.  *      RSinitall()                 - Initialize the world if necessary
  23.  *      RSinslines(w,t,b,n)         - Insert n lines in region t->b in w
  24.  *      RSinsstring(w,x,y,a,len,ptr)- Insert len chars @x,y in w attrib a
  25.  *      RSsendstring(w,ptr,len)     - Send string @ptr length len from window w
  26.  *        RSbufinfo( w, total,current)- Tells you the total/current lines in buffer
  27.  *        RSdrawsep( w, y1,draw)        - Tells you to draw the line at y1 (0 is erase)
  28.  *        RSmargininfo( w, total, current)    - Tells you total/current columns in VS
  29.  *
  30.  *
  31.  *  Macintosh only Routines:
  32.  *    NI    RSregnconv( *)                - Convert region to rect coords
  33.  *  NI  RSsetwind(w)                - Set the port and vars to window w
  34.  *  NI  RSsetattr(a)                - Set font/text style to a
  35.  *    NI    RSsetConst(w)
  36.  *    ML    RSattatch(w,wind)            - Attach the RS (w) to window wind
  37.  *    ML    RSdetatch(w)                - Ready window for go-away
  38.  *    ML    RSselect(w,pt,shift)        - Handle selection RS (w) point (pt) and (shift) if held down
  39.  *    ML    RSzoom(window,code,shifted)    - Zoom Box handling
  40.  *    ML    RSsize( window, where)        - Resize handling
  41.  *    IN    RSgetwindow(w)                - Get the WindowPtr for RS (w)
  42.  *    IN    RSfindvwind(wind)            - Find the (RS/VS) # of wind
  43.  *    IN    RSfindscroll( control, n)    - Find which VS the control is in and which control it is
  44.  *      RSupdate(wind)                - Handle updates on WIND, return 0 if not an RS
  45.  *        RSactivate(w)                - Handle activate events 
  46.  *        RSdeactivate(w)                - Handle deactivate events 
  47.  *        RSGetTextSel(w,table)        - Returns handle to text selection of window w, table->tabs
  48.  *        RSchangefont(w,fnum,fsiz,r)    - Set (w) to font fnum, size fsiz, resize window if (r)
  49.  *        RSgetfont(w, &fnum, &fsiz)    - Get the font size and number into fnum and fsiz
  50.  *        RSnewwindow( wDims, sb, wid, lines
  51.  *            name,wrap,fnum,fsiz,
  52.  *            showit, goaway)            - Returns VS # of newly created text window -
  53.  *                                      wDims (dimension),sb(scrollback),wid(width 80/132),
  54.  *                                    lines (# of lines, 24 <> 66),
  55.  *                                      name(window), wrap(0/1),fnum,fsiz, showit(vis),goaway(0,1)
  56.  *        RSkillwindow( w)            - Destroys, deallocates, kills window (w)
  57.  *        RSclick(window,where,shift,
  58.  *                option)                - Handle clicks in window (returns false if not RS window)
  59.  *        RShide(w)                    - Hide RS (w)
  60.  *        RSshow(w)                    - Show RS (w)
  61.  *        RScprompt(w, FilterProc)    - Prompt for colors...FilterProc is for Modal Dialog
  62.  *        RSsetcolor(w,n,r,g,b)        - Set one of the 4 colors of RS (w) to R,G,B
  63.  *        RSgetcolor(w,n,r,g,b)        - Get one of the 4 colors of RS (w) into R,G,B
  64.  *        RSmouseintext(w,myPoint)    - Returns true if Mouse is in text part of current RS window
  65.  *        RSskip(w,on)                - Activate/deactivate drawing in an RS
  66.  *        
  67.  *        IN - Informational
  68.  *        ML - Mid Level
  69.  *        NI - Necessary Internal
  70.  *           - Suggested calls
  71.  *
  72.  *      Version Date    Notes
  73.  *      ------- ------  ---------------------------------------------------
  74.  *      0.01    861102  Initial coding -GBP
  75.  *      0.25    861106  Added code from screen.c -GBP
  76.  *      0.50    861113  First compiled edition -GBP
  77.  *        2.1        871130    NCSA Telnet 2.1 -GBP
  78.  *        2.2     880715    NCSA Telnet 2.2 -GBP
  79.  */
  80.  
  81.  
  82. #define __ALLNU__
  83. #include <Events.h>
  84. #include <Controls.h>
  85. #include <OSUtils.h>
  86. #include <Dialogs.h>
  87. #include <Quickdraw.h>
  88. #include <Palette.h>
  89. #include <Windows.h>
  90. #include <Menus.h>
  91. #include <Fonts.h>
  92. #include <stdio.h>
  93.  
  94. #include "vskeys.h"
  95. #include "vsdata.h"
  96.  
  97. #ifdef MPW
  98. #include "::main:mpw.h"
  99. #include "Picker.h"
  100. #endif
  101.  
  102. #define NCSA_TELNET
  103.  
  104. #ifdef NCSA_TELNET
  105. #include "wind.h"
  106. #endif
  107.  
  108. /*
  109. *  Capable of shifting the text to the right some # of pixels
  110. */
  111. #define CVO 0
  112. #define CHO -3
  113.  
  114. #define Fheight RSlocal[w].fheight
  115. #define    Fascent    RSlocal[w].fascent
  116. #define Fwidth RSlocal[w].fwidth
  117. #define    FONT RSlocal[w].fnum
  118. #define FSIZE RSlocal[w].fsiz
  119. #define Fright RSlocal[w].width
  120. #define MAXWINDOWWIDTH (width)*Fwidth+16-CHO
  121. #define MAXWINDOWHEIGHT (lines)*Fheight+16
  122.  
  123. #define putln(x)
  124.  
  125. extern unsigned char tempspot[];
  126.  
  127. extern int HasColor;    /* BYU mod */
  128.  
  129. struct RSdata {
  130.     Rect        textrect;    /* Where the text is in the window */
  131.     Rect        cursor;        /* Cursor rectangle */
  132.     GrafPtr        window;        /* Window pointer */
  133.     PaletteHandle    pal;    /* My Palette */
  134.     int            selected;
  135.     long        last,
  136.                 anchor;
  137.     int            topline,
  138.                 leftmarg;
  139.     int            rheight,    /* Real window dimensions */
  140.                             /* adjusted to not include CHO boundary - TK 12/88 */
  141.                 rwidth;
  142.     int            height,
  143.                 width;        /* Window Dimensions rounded to the nearest character */
  144.     char        color[6];    /* color scheme for this machine's sessions */
  145.     RGBColor    RGBs[4];    /* RGB Colors for window */
  146.     ControlHandle
  147.         left,        /* The CH for the left margin */
  148.         scroll;        /* The CH for the scroll bar */
  149.     int
  150.         min,        /* Minimum control value */
  151.         max,        /* Maximum control value */
  152.         current,    /* current control value */
  153.         lmin,        /* Minimum control value */
  154.         lmax,        /* Maximum control value */
  155.         lcurrent;    /* current control value */
  156.     int
  157.         fascent,    /* Font Ascent */
  158.         fnum,        /* Font Number */
  159.         fsiz,        /* Font Size */
  160.         fheight,    /* Font Height/character */
  161.         fwidth,        /* Font Width /character */
  162.         monospaced;    /* Font is monospaced */
  163.     int
  164.         skip;        /* TRUE if we are skipping the output */
  165.  
  166.     };
  167.  
  168. typedef struct RSdata RSdata;
  169.  
  170. extern int scrn,numwindows,del;
  171. #ifdef NCSA_TELNET
  172. extern WindRec *screens;
  173. #endif NCSA_TELNET
  174. extern char *VSgetline();
  175. pascal void ScrollProc();
  176.  
  177. #define MAXRS 20
  178. CTabHandle RSctab;
  179. RSdata *RSlocal;
  180. Rect    noConst,
  181.         screenRect,
  182.         RScur;                /* cursor rectangle */
  183. Region **RSuRgn;            /* update region */
  184. char **NewHandle();
  185. int RSw=-1,         /* last window used */
  186.     RSa=0;          /* last attrib used */
  187. int RScolor=1;        /* true if try to use color stuff */
  188. int RScolors[]=
  189.     { 33,            /* black */
  190.       30,            /* white */
  191.       205,            /* red */
  192.       341,            /* green */
  193.       409,            /* blue */
  194.       273,            /* cyan */
  195.       137,            /* magenta */
  196.       69            /* yellow */
  197.       };
  198.  
  199. RSinitall()
  200. {
  201.     int i;
  202.     extern SysEnvRec theWorld;
  203.  
  204.     RSlocal = (RSdata *) malloc(MAXRS*sizeof(RSdata));
  205.     for(i=0;i<MAXRS;RSlocal[i++].window=0L) {
  206.         RSlocal[i].color[0]=0;            /* Foreground */
  207.         RSlocal[i].color[1]=1;            /* Background */
  208.         RSlocal[i].color[2]=2;            /* Blink Fore */
  209.         RSlocal[i].color[3]=3;            /* Blink Back */
  210.         RSlocal[i].cursor.top = 0;
  211.         RSlocal[i].cursor.bottom = 0;
  212.         RSlocal[i].cursor.left = 0;
  213.         RSlocal[i].cursor.right = 0;
  214.         }
  215.     RSuRgn=NewRgn();
  216.     RScur.left = 0;
  217.     RScur.top = 0;
  218.     RScur.bottom = 0;
  219.     RScur.right = 0;
  220.     RSctab = (CTabHandle)NewHandle( (long)(sizeof(ColorTable)+ 8*sizeof(CSpecArray)) );
  221.     RScolor = theWorld.hasColorQD;
  222. }
  223.  
  224. RSsetConst(w)
  225. int w;
  226. {
  227.     SetRect( &noConst, 0,0, RSlocal[w].width, RSlocal[w].height);
  228. }
  229.  
  230. RSbell(w)
  231. int w;
  232. {
  233.     RSsetwind(w);
  234.     if (FrontWindow()!=RSlocal[w].window) {
  235.         InvertRect(&RSlocal[w].window->portRect);
  236.         SysBeep(8);
  237.         InvertRect(&RSlocal[w].window->portRect);
  238.         }
  239.     else SysBeep(8);
  240. }
  241.  
  242. RScursoff(w)
  243. int w;
  244. {
  245.     if (RSlocal[w].skip) return(0);
  246.     RSsetwind(w);
  247.     InvertRect(&RSlocal[w].cursor);
  248. }
  249.  
  250. RScurson(w,x,y)
  251. int w,x,y;
  252. {
  253.     if (RSlocal[w].skip) return(0);
  254.     RSsetwind(w);
  255.     RSlocal[w].cursor.left = x * Fwidth;
  256.     RSlocal[w].cursor.top  = y * Fheight;
  257.     RSlocal[w].cursor.right  = RSlocal[w].cursor.left + Fwidth;
  258.     RSlocal[w].cursor.bottom = RSlocal[w].cursor.top  + Fheight;
  259.     InvertRect(&RSlocal[w].cursor);
  260. }
  261.  
  262. RSdraw(w,x,y,a,len,ptr)
  263. int w,x,y,a,len;
  264. char *ptr;
  265. {
  266.     Rect rect;
  267.     int i,ys;
  268.  
  269.     if (RSlocal[w].skip) return(0);
  270.     RSsetwind(w);
  271.     RSsetattr(0);
  272.     SetRect(&rect, (x)*Fwidth, (y)*Fheight, (x+len)*Fwidth, (y+1)*Fheight );
  273.     if (RSa!=a) RSsetattr(a);
  274. #ifdef OLDM
  275.     if (!RScolor)
  276. #endif OLDM
  277.         EraseRect(&rect);
  278.     MoveTo( x*Fwidth, (ys=y*Fheight+Fascent));
  279.     if (RSlocal[w].monospaced)
  280.         DrawText(ptr,0,len);
  281.     else
  282.         while (len--) {
  283.             DrawChar(*ptr++);
  284.             MoveTo( (++x)*Fwidth, ys);
  285.             }
  286.     if (RSlocal[w].selected)
  287.         RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &rect);
  288. }
  289.  
  290. RSdelcols(w,n)
  291. int w,n;
  292. {
  293.     Rect rect;
  294.  
  295.     if (RSlocal[w].skip) return(0);
  296.     RSsetwind(w);
  297.     SetRect(&rect, 0, 0, Fright, RSlocal[w].height );
  298.     ScrollRect(&rect, -n*Fwidth, 0, RSuRgn);
  299.     InvalRgn(RSuRgn);
  300.     ValidRect(&rect);
  301.     SetRect(&rect, RSlocal[w].width-(n*Fwidth), 0, RSlocal[w].width, RSlocal[w].height );
  302.     if (RSlocal[w].selected)
  303.         RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &rect);
  304. }
  305.  
  306. RSdelchars(w,x,y,n)
  307. int w,x,y,n;
  308. {
  309.     Rect rect;
  310.  
  311.     if (RSlocal[w].skip) return(0);
  312.     RSsetwind(w);
  313.     RSsetattr(0);
  314.     SetRect(&rect, (x)*Fwidth, y*Fheight, Fright, (y+1)*Fheight );
  315.     if ( (x+n)*Fwidth > Fright)
  316.         EraseRect( &rect);
  317.     else {
  318.         ScrollRect(&rect, -Fwidth*n, 0, RSuRgn);
  319.         InvalRgn(RSuRgn);
  320.            ValidRect(&rect);
  321.         if (RSlocal[w].selected) {
  322.             HLock(RSuRgn);
  323.             RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &((*RSuRgn)->rgnBBox));
  324.             HUnlock(RSuRgn);
  325.             }
  326.         }
  327. }
  328.  
  329. RSdellines(w,t,b,n,scrolled)
  330. int w,t,b,n,scrolled;
  331. {
  332.     Rect rect;
  333.  
  334.     if (RSlocal[w].skip) return(0);
  335.     RSsetwind(w);
  336.     RSsetConst(w);
  337.     RSsetattr(0);
  338.     if (scrolled) {
  339.         if (RSlocal[w].selected && scrolled<0) {
  340.             RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &noConst);
  341.             RSlocal[w].selected=0;
  342.             }
  343.         else {
  344.             RSlocal[w].last-=65536;            /* Subtract one from each of the */
  345.             RSlocal[w].anchor-=65536;        /* Selection components */
  346.             }
  347.         }
  348.  
  349.     rect.left = 0;
  350.     rect.right = Fright;
  351.     rect.top = (t) * Fheight;
  352.     rect.bottom = ((b+1)*Fheight);
  353.     OffsetRgn(((WindowPeek)RSlocal[w].window)->updateRgn,0,-Fheight*n);
  354.     ScrollRect(&rect, 0, -Fheight*n, RSuRgn);
  355.     RSsetattr(VSIw->attrib);
  356.     InvalRgn(RSuRgn);
  357.  
  358.     SetRect(&rect,0,(b-n+1)*Fheight-1,Fright,(b+1)*Fheight+1);
  359.     ValidRect(&rect);
  360.  
  361. }
  362.  
  363. RSerase(w,x1,y1,x2,y2)
  364. int w,x1,y1,x2,y2;
  365. {
  366.     Rect rect;
  367.  
  368.     if (RSlocal[w].skip) return(0);
  369.     RSsetwind(w);
  370.     RSsetattr(0);
  371.     SetRect(&rect, x1*Fwidth, y1*Fheight, (x2+1)*Fwidth-1, (y2+1)*Fheight+1);
  372.     if (rect.left <= 0)                        /* little buffer strip on left */
  373.         rect.left = CHO;
  374.     if (rect.right >= RSlocal[w].width-1)
  375.         rect.right = RSlocal[w].rwidth-2;    /* clear to edge of window, including edge strip */
  376.     if (rect.bottom >= RSlocal[w].height-2)
  377.         rect.bottom = RSlocal[w].rheight+1;    /* clear to bottom edge also */
  378.  
  379.     EraseRect(&rect);
  380.     if (RSlocal[w].selected)
  381.         RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &rect);
  382.  
  383. }
  384.  
  385. RSinslines(w,t,b,n,scrolled)
  386. int w,t,b,n,scrolled;
  387. {
  388.     Rect rect;
  389.  
  390.     if (RSlocal[w].skip) return(0);
  391.     RSsetwind(w);
  392.     RSsetConst(w);
  393.     RSsetattr(0);
  394.     if (RSlocal[w].selected && (scrolled <0)) {
  395.         RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &noConst);
  396.         RSlocal[w].selected=0;
  397.         }
  398.  
  399.     rect.left = 0;
  400.     rect.right = Fright;
  401.     rect.top = (t) * Fheight;
  402.     rect.bottom = ((b+1)*Fheight);
  403.     OffsetRgn(((WindowPeek)RSlocal[w].window)->updateRgn,0,Fheight*n);
  404.     ScrollRect(&rect, 0, Fheight*n, RSuRgn);
  405.     InvalRgn(RSuRgn);
  406.  
  407.     SetRect(&rect,0,(t)*Fheight-1,Fright,(t+n)*Fheight+1);
  408.     ValidRect(&rect);
  409. }
  410.  
  411. RSinscols(w,n)
  412. int w,n;
  413. {
  414.     Rect rect;
  415.  
  416.     if (RSlocal[w].skip) return(0);
  417.     RSsetwind(w);
  418.     SetRect(&rect, 0, 0, Fright, RSlocal[w].height );
  419.     ScrollRect(&rect, n*Fwidth, 0, RSuRgn);
  420.     InvalRgn(RSuRgn);
  421.     ValidRect(&rect);
  422.     SetRect(&rect, 0, 0, (n+1)*Fwidth-1, RSlocal[w].height );
  423.     if (RSlocal[w].selected)
  424.         RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &rect);
  425.  
  426. }
  427.  
  428. RSinsstring(w,x,y,a,len,ptr)
  429. int w,x,y,a,len;
  430. char *ptr;
  431. {
  432.     Rect rect;
  433.  
  434.     if (RSlocal[w].skip) return(0);
  435.     RSsetwind(w);
  436.     SetRect(&rect, (x)*Fwidth, y*Fheight, Fright, (y+1)*Fheight );
  437.     ScrollRect(&rect, len*Fwidth, 0, RSuRgn);
  438.     if (RSa!=a) RSsetattr(a);
  439.     InvalRgn(RSuRgn);
  440.     ValidRect(&rect);
  441.     SetRect(&rect, (x)*Fwidth, y*Fheight, (x+len)*Fwidth, (y+1)*Fheight );
  442.     EraseRect(&rect);
  443.     MoveTo( (x)*Fwidth, y*Fheight+Fascent);
  444.     DrawText(ptr,0,len);
  445.     if (RSlocal[w].selected)
  446.         RSinvText(w, RSlocal[w].anchor, RSlocal[w].last, &rect);
  447.  
  448. }
  449.  
  450. RSsendstring(w,ptr,len)
  451. int w, len;
  452. char *ptr;
  453. {
  454.     int temp;
  455.  
  456. #ifdef NCSA_TELNET
  457.     temp=findbyVS(w);
  458.     if (temp<0) return;
  459.     netwrite(screens[temp].port,ptr,len);
  460. #else
  461.     while (len--)  putu(*ptr++);
  462. #endif
  463. }
  464.  
  465. RSmargininfo( w, total, current)
  466. int w, total, current;
  467. {
  468.  
  469.     RSlocal[w].leftmarg= current;            /* Adjust local vars */
  470.  
  471.     if (RSlocal[w].lcurrent != current)
  472.         SetCtlValue( RSlocal[w].left, (RSlocal[w].lcurrent=current) );
  473.     if (RSlocal[w].lmax !=total )
  474.         SetCtlMax( RSlocal[w].left, (RSlocal[w].lmax= total) );
  475. }
  476.  
  477. RSbufinfo( w, total, current,bottom)
  478. int w, total, current;
  479. {
  480.     RSlocal[w].topline= current;            /* Adjust local vars */
  481.  
  482.     if (RSlocal[w].min != -total) {
  483.         SetCtlMin( RSlocal[w].scroll, (RSlocal[w].min = -total) );
  484.         SetCtlValue( RSlocal[w].scroll, (RSlocal[w].current=current) );
  485.         }
  486.         
  487.     if (RSlocal[w].current != current)
  488.         SetCtlValue( RSlocal[w].scroll, (RSlocal[w].current=current) );
  489.         
  490.     if (RSlocal[w].max !=( (VSgetlines(w)-1) -(bottom-current))) {
  491.         SetCtlMax( RSlocal[w].scroll, (RSlocal[w].max= (VSgetlines(w)-1)- (bottom-current)) );
  492.         SetCtlValue( RSlocal[w].scroll, (RSlocal[w].current=current) );
  493.         }
  494. }
  495.  
  496. GrafPtr RSgetwindow(w)
  497. int w;
  498. {
  499.     return(RSlocal[w].window);
  500. }
  501.  
  502. /****************************************************************************/
  503. /*  Given a window record number, do a SetPort() to the window associated with
  504. *   that window record.
  505. */
  506. int RSsetwind(w)
  507. int w;
  508. {
  509.     if ((w<0) || (w>20)) return(-3);
  510.     
  511.     if (RSw!=w) {                                /* if last window used is different */
  512.         if (RSlocal[w].window==0L) return(-4);
  513.         RSw=w;RSa=-1;                            /* remember this one now, reset attributes */
  514.         SetPort(RSlocal[w].window);
  515.         return(1);
  516.         }
  517.         
  518.     SetPort(RSlocal[w].window);
  519.     return(0);
  520. }
  521.  
  522. RSsetattr(a)
  523. int a;
  524. {
  525.     if (VSisgrph(a))
  526.         TextFont(74);
  527.         else TextFont(RSlocal[RSw].fnum);
  528.     TextSize(RSlocal[RSw].fsiz);
  529.     TextFace((a & 1) + (a & 0x08) /2);
  530.  
  531.     if (RScolor) {
  532.         if (VSisrev(a))
  533.             TextMode( notSrcCopy);
  534.         else
  535.             TextMode( srcCopy);
  536.         }
  537.     else {
  538.         if (VSisrev(a)) {
  539.             BackPat(qd.black);                                        /* Reverses current attributes regard */
  540.             PenPat(qd.white);                                        /* less of the color, etc.... */
  541.             } else {
  542.             BackPat(qd.white);
  543.             PenPat(qd.black);
  544.             }
  545.         }
  546.  
  547.     if (VSisblnk(a) ) {
  548.         if (RScolor) {
  549.             PmForeColor(2);
  550.             PmBackColor(3);
  551.         } else {
  552.             ForeColor( (long) RScolors[ RSlocal[RSw].color[2]]);        /* Blink foreground */
  553.             BackColor( (long) RScolors[ RSlocal[RSw].color[3]]);        /* Blink Background */
  554.             }
  555.         }
  556.     else {
  557.         if (RScolor) {
  558.             PmForeColor(0);
  559.             PmBackColor(1);
  560.         } else {
  561.             ForeColor( (long) RScolors[ RSlocal[RSw].color[0]]);        /* normal foreground */
  562.             BackColor( (long) RScolors[ RSlocal[RSw].color[1]]);        /* normal Background */
  563.             }
  564.         }
  565.     RSa=a;
  566. }
  567.  
  568. RSattatch(w,wind)
  569. int w;
  570. GrafPtr wind;
  571. {
  572.     RSlocal[w].window=wind;
  573.     RSlocal[w].selected=0;
  574.     SetPort(wind);
  575.     TextFont(FONT);
  576.     TextSize(FSIZE);
  577.     if (!RScolor)
  578.         TextMode(srcXor);            /* Xor mode*/
  579.     else
  580.         TextMode(srcCopy);
  581.     RSw=-1;    /*make sure we don't write in wrong place */
  582. }
  583.  
  584. RSdetatch(w)
  585. int w;
  586. {
  587.     RSlocal[w].window=0L;
  588.     RSw=-1;    /*make sure we don't write in wrong place */
  589. }
  590.  
  591. int RSfindvwind(wind)
  592. GrafPtr wind;
  593. {
  594.     int i=0;
  595.  
  596.     while((RSlocal[i].window!=wind) && (i<20)) i++;
  597.     if((RSlocal[i].window==0L) || (i>=20)) return(-4);
  598.         else return(i);
  599. }
  600.  
  601. int RSfindscroll( control, n)                /* Find screen index by control*/
  602. ControlHandle control;
  603. int *n;
  604. {
  605.     *n=0;
  606.  
  607.     while((*n<MAXRS) && (control!=RSlocal[*n].scroll)) (*n)++;
  608.     if (*n<MAXRS) return(1);
  609.  
  610.     *n=0;
  611.     while((*n<MAXRS) && (control!=RSlocal[*n].left)) (*n)++;
  612.     if (*n<MAXRS) return(2);
  613.  
  614.     return(-1);
  615. }
  616.  
  617. RSregnconv(regn,x1,y1,x2,y2,fh,fw)
  618. Region **regn;
  619. int *x1,*x2,*y1,*y2,fw,fh;
  620. {
  621.  
  622.     HLock(regn);
  623.     *y1=((*regn)->rgnBBox.top)/fh;
  624.     *y2=(((*regn)->rgnBBox.bottom)+fh-1)/fh;
  625.     *x1=((*regn)->rgnBBox.left)/fw;
  626.     *x2=(((*regn)->rgnBBox.right)+fw-1)/fw;
  627.     HUnlock(regn);
  628.     if (*x1<0) *x1=0;
  629.     if (*y1<0) *y1=0;
  630.     if (*x2<0) *x2=0;
  631.     if (*y2<0) *y2=0;
  632. #ifdef WHONEEDSIT
  633.     if (*x1>VSIw->maxwidth) *x1=VSIw->maxwidth;
  634.     if (*x2>VSIw->maxwidth) *x2=VSIw->maxwidth;
  635.     if (*y1>VSIw->lines) *y1=VSIw->lines;
  636.     if (*y2>VSIw->lines) *y2=VSIw->lines;
  637. #endif WHONEEDSIT
  638. }
  639.  
  640. RSupdate(wind)
  641. GrafPtr wind;
  642. {
  643.     int w,x1,x2,y1,y2;
  644.     int temp;
  645.     Rect growRect, rect;
  646.  
  647.     w=RSfindvwind(wind);
  648.     if (RSsetwind(w)<0) return(-1);
  649.     BeginUpdate(wind);
  650.  
  651.     /*    EraseRect( &wind->portRect); */
  652.         RSregnconv(wind->visRgn,&x1,&y1,&x2,&y2, Fheight, Fwidth);
  653.         VSredraw(w,x1,y1,x2,y2);
  654.  
  655.     /* We must reset, less we risk looking UGLY as sin... */
  656.     BackPat(qd.white);
  657.     PenPat(qd.black);
  658.     if (RScolor) {
  659.         PmForeColor(0);
  660.         PmBackColor(1);
  661.     } else {
  662.         ForeColor( (long) RScolors[ RSlocal[w].color[0]]);        /* normal foreground */
  663.         BackColor( (long) RScolors[ RSlocal[w].color[1]]);        /* normal Background */
  664.         }
  665.  
  666.     RSa=-1;
  667.  
  668.     PenMode(patOr);
  669.     DrawGrowIcon(wind);
  670.     PenMode(patCopy);
  671.     DrawControls(wind);
  672.     
  673. /*     if ( RSlocal[w].left)
  674.         || RSlocal[w].scroll ) {
  675.         }
  676. */
  677.  
  678. #ifdef NOHORIZ
  679.     SetRect(&growRect,Fright,RSlocal[RSw].height,Fright+15,RSlocal[RSw].height+15);
  680.     ClipRect(&growRect);
  681.     SetRect(&growRect,0,0,32767,32767);
  682.     ClipRect(&growRect);
  683. #endif NOHORIZ
  684.  
  685.     EndUpdate(wind);
  686.     return(0);
  687. }
  688.  
  689. #ifdef FASTERCOMMENTED
  690. RSupdprint(wind)
  691. WindowPeek wind;
  692. {
  693.     int x,y,z,w;
  694.     char tbuf[50];
  695.  
  696.     RSregnconv(wind->updateRgn,&x,&y,&z,&w);
  697.     sprintf(tbuf,"RSregnconv: %d,%d,%d,%d",x,y,z,w);
  698.     putln(tbuf);
  699. }
  700. #endif
  701.  
  702. RSinvText(w, curr,last,constrain)
  703. int w;
  704. Point curr,last;
  705. Rect *constrain;
  706. {
  707.     Rect temp,temp2;
  708.     char tbuf[100];
  709.     Point lb,ub;
  710.  
  711.     RSsetwind(w);
  712.  
  713.     curr.v -=RSlocal[w].topline;        /* Adjust the coords */
  714.     curr.h -=RSlocal[w].leftmarg;
  715.  
  716.     last.v -=RSlocal[w].topline;        /* For both spots.... */
  717.     last.h -=RSlocal[w].leftmarg;
  718.  
  719.     if (curr.v==last.v) {
  720.         if (curr.h<last.h)  {ub= curr;lb=last;} else {ub=last;lb=curr;}
  721.         SetRect(&temp,((ub.h+1)*Fwidth),(ub.v*Fheight),
  722.                       ((lb.h+1)*Fwidth), ((lb.v+1) *Fheight));
  723.         SectRect(&temp,constrain,&temp2);
  724.         HiliteMode();
  725.         InvertRect(&temp2);
  726.         }
  727.     else if (curr.v!=last.v) {
  728.         if (curr.v<last.v)  ub= curr; else ub=last;
  729.         if (curr.v>last.v)  lb= curr; else lb=last;
  730.         SetRect(&temp,((ub.h+1)*Fwidth),(ub.v*Fheight),
  731.                       Fright, ((ub.v+1) *Fheight));
  732.         SectRect(&temp,constrain,&temp2);
  733.         HiliteMode();
  734.         InvertRect(&temp2);
  735.         SetRect(&temp, 0, (lb.v*Fheight),
  736.                       ((lb.h+1)*Fwidth), ((lb.v+1) *Fheight));
  737.         SectRect(&temp,constrain,&temp2);
  738.         HiliteMode();
  739.         InvertRect(&temp2);
  740.         if (lb.v-ub.v>1) {
  741.             SetRect(&temp,0,(ub.v+1)*Fheight,Fright,(lb.v*Fheight));
  742.             SectRect(&temp,constrain,&temp2);
  743.             HiliteMode();
  744.             InvertRect(&temp2);
  745.             }
  746.         }
  747. }
  748.  
  749. long getlocalmouse(wind)
  750. GrafPtr wind;
  751. {
  752.     Point temp;
  753.     char tbuf[50];
  754.  
  755.     SetPort(wind);
  756.     GetMouse(&temp);
  757.     return( * ((long *) &temp));
  758. }
  759.  
  760. #define    Fwidthhalf    Fwidth/2
  761. long normalize(in, w)
  762. Point in;
  763. int  w;
  764. {
  765.     char tbuf[100];
  766.  
  767.  
  768.     if (in.v<0) {in.v=0; VSscrolback( w,1);}
  769.     if (in.v>RSlocal[ w].height) {in.v=RSlocal[ w].height; VSscrolforward( w,1);}
  770.     in.v=in.v/Fheight;
  771.  
  772.     if (in.h<0) {in.h=-1; VSscrolleft( w,1);}
  773.     if (in.h>RSlocal[ w].width) {in.h=RSlocal[ w].width; VSscrolright( w,1);}
  774.     in.h=(in.h+Fwidthhalf)/Fwidth-1;
  775.  
  776.     in.v += RSlocal[ w].topline;
  777.     in.h += RSlocal[ w].leftmarg;
  778.     return( * ((long *) &in));
  779. }
  780.  
  781. RSselect( w, pt, shift)
  782. int  w;
  783. short shift;
  784. long *pt;
  785. {
  786.     GrafPtr tempwndo;
  787.     long curr;
  788.     char temp[50];
  789.  
  790.     RSsetConst( w);
  791.  
  792.     tempwndo = RSlocal[ w].window;
  793.     if (RSlocal[ w].selected) {
  794.         if (!shift) {
  795.                 RSinvText( w, RSlocal[ w].anchor,
  796.                                  RSlocal[ w].last, &noConst);
  797.                 curr=RSlocal[ w].last=RSlocal[ w].anchor=normalize(*pt, w);
  798.                 RSlocal[ w].selected=1;
  799.                 }
  800.         }
  801.         else {
  802.             curr=RSlocal[ w].anchor=RSlocal[ w].last=normalize(*pt, w);
  803.             RSlocal[ w].selected=1;
  804.             }
  805.     while(StillDown()) {
  806.         while(((curr=normalize(getlocalmouse(tempwndo), w))==RSlocal[ w].last)
  807.                 && StillDown());
  808.         RSinvText( w,curr,RSlocal[ w].last, &noConst);
  809.         RSlocal[ w].last=curr;
  810.         }
  811.  
  812.     if (RSlocal[ w].anchor==curr ||
  813.         RSlocal[ w].anchor==RSlocal[ w].last ) RSlocal[ w].selected=0;
  814.     if (RSlocal[ w].selected) {
  815.         sprintf(temp, "(%d,%d) - (%d,%d) is selected", RSlocal[ w].anchor,RSlocal[ w].last);
  816.         putln(temp);
  817.         }
  818. }
  819.  
  820. RSactivate(w)
  821. int w;
  822. {
  823.     int temp;
  824.  
  825.     RSsetConst(w);
  826.  
  827.     DrawGrowIcon(RSlocal[w].window);
  828.     if (RSlocal[w].scroll !=0L) HiliteControl( RSlocal[w].scroll, 0);
  829.  
  830.     if (RSlocal[w].left   !=0L) HiliteControl( RSlocal[w].left  , 0);
  831.  
  832. }
  833.  
  834. RSdeactivate(w)
  835. int w;
  836. {
  837.     int temp;
  838.  
  839.     RSsetConst(w);
  840.     DrawGrowIcon(RSlocal[w].window); 
  841.     if (RSlocal[w].scroll !=0L) HiliteControl( RSlocal[w].scroll, 255);
  842.  
  843.     if (RSlocal[w].left   !=0L) HiliteControl( RSlocal[w].left  , 255);
  844.  
  845. }
  846.  
  847. char **RSGetTextSel(w, table)
  848. int w, table;
  849. {
  850.     char **charh, *charp, *t;
  851.     int maxwid,i;
  852.     long realsiz, VSgettext();
  853.     char tempc[100];
  854.     Point Anchor,Last;
  855.  
  856.     putln("In the routine");
  857.     if (!RSlocal[w].selected) return(0L);    /* No Selection */
  858.     maxwid= VSmaxwidth( w);
  859.     Anchor = *((Point *) &RSlocal[w].anchor);
  860.     Last   = *((Point *) &RSlocal[w].last);
  861.     realsiz= Anchor.v - Last.v;
  862.     if (realsiz<0) realsiz = - realsiz;
  863.     realsiz ++;                                /* lines 2,3 selected can be 2 lines */
  864.     realsiz *= (maxwid+2);
  865.     sprintf(tempc,"Size of block=%d",realsiz);
  866.     putln(tempc);
  867.     charh=NewHandle( realsiz);
  868.     if (charh==0L)
  869.         return((char *) -1L);                /* Boo Boo return */
  870.     HLock(charh);
  871.     charp=*charh;
  872.  
  873.     realsiz=VSgettext(w, Anchor.h ,Anchor.v, Last.h ,Last.v , charp, realsiz, "\015", table);
  874.  
  875.     putln("unlocking");
  876.     HUnlock(charh);
  877.     SetHandleSize(charh,realsiz);
  878.     sprintf(tempc,"Size of clip=%d",realsiz);
  879.     putln(tempc);
  880.     return(charh);
  881. }
  882.  
  883. RSsetsize( w,v,h)
  884. int  w,v,h;
  885. {
  886.     Rect eraseit;
  887.     int screen;
  888.  
  889.  
  890.     RSlocal[ w].height=( (v-16+CVO) /Fheight) *Fheight;
  891.     RSlocal[ w].width=( (h-16+CHO) /Fwidth) *Fwidth;
  892.     RSlocal[ w].rheight=v-16;
  893.     RSlocal[ w].rwidth=h-16;
  894.  
  895. /*
  896. *  Get rid of the scroll bars which were in the old size.
  897. *  Hiding them causes the region to be updated later.
  898. */
  899.     if (RSlocal[ w].scroll != NULL )
  900.         HideControl(RSlocal[ w].scroll);
  901.     if (RSlocal[ w].left != NULL ) 
  902.         HideControl(RSlocal[ w].left);
  903.  
  904.     DrawGrowIcon(RSlocal[w].window);            /* Draw in the necessary bugger */
  905.     
  906.     if (RSlocal[ w].scroll != NULL ) {
  907.         SizeControl(RSlocal[ w].scroll, 16, (v-13));
  908.         MoveControl(RSlocal[ w].scroll, (h-15)+CHO, -1+CVO);
  909.         ShowControl(RSlocal[ w].scroll);
  910.         }
  911.     if (RSlocal[ w].left != NULL ) {
  912.         SizeControl(RSlocal[ w].left, (h-13), 16);
  913.         MoveControl(RSlocal[ w].left, -1+CHO,  (v-15)+CVO);
  914.         ShowControl(RSlocal[ w].left);
  915.         }
  916.     SetRect(&RSlocal[w].textrect, 0,0, RSlocal[w].rwidth, RSlocal[w].rheight);
  917.  
  918. }
  919.  
  920.  
  921. RSdrawsep( w, y1,draw)
  922. int w,y1, draw;
  923. {
  924. #ifdef SEPLINE
  925.     RSsetwind(w);
  926.  
  927.     PenPat(gray);
  928.     if ( draw)
  929.         PenMode(srcCopy);
  930.     else
  931.         PenMode(srcXor);
  932.  
  933.     MoveTo(0,y1*Fheight);
  934.     Line( RSlocal[w].width-1, 0);
  935.  
  936.     PenMode(srcOr);
  937.  
  938.     RSsetattr(0);
  939. #endif SEPLINE
  940. }
  941.  
  942. int RSchangefont( w, fnum, fsiz, resizwind)
  943. int w, fnum, fsiz, resizwind;
  944. {
  945.     FontInfo finforec;
  946.     Rect pRect;
  947.     int t, tw, h,v,x1,x2,y1,y2,width,lines;
  948.     int srw,srh;
  949.     WStateData *wstate;
  950.     WindowPeek wpeek;
  951.  
  952.     RSsetwind(w);
  953.  
  954.     srw=RSlocal[w].rwidth;
  955.     srh=RSlocal[w].rheight;
  956.  
  957.     if (fnum) {
  958.         TextFont( fnum);
  959.         RSlocal[w].fnum=fnum;
  960.         }
  961.     if (fsiz) {
  962.         TextSize( fsiz);
  963.         RSlocal[w].fsiz=fsiz;
  964.         }
  965.     GetFontInfo( &finforec);
  966.     RSlocal[w].fwidth=finforec.widMax;
  967.     RSlocal[w].fascent=finforec.ascent;
  968.     RSlocal[w].fheight=finforec.ascent+finforec.descent+finforec.leading /* +1 */;
  969.     RSlocal[w].monospaced= (CharWidth('W')==CharWidth('i'));
  970.     RSlocal[w].fwidth= CharWidth('W');
  971.  
  972.     width=VSmaxwidth(w)+1;
  973.     lines=VSgetlines(w);
  974.  
  975.     if (!resizwind) {
  976.         RSlocal[ w].height=( (RSlocal[ w].rheight) /Fheight) *Fheight;
  977.         RSlocal[ w].width =( (RSlocal[ w].rwidth + CHO) /Fwidth ) *Fwidth - CHO;
  978.         }
  979.     else {
  980.         VSgetrgn(  w, &x1,&y1,&x2,&y2);
  981.         RSlocal[ w].rwidth  = RSlocal[ w].width = (x2 - x1 +1) *Fwidth - CHO;
  982.         RSlocal[ w].rheight = RSlocal[ w].height= (y2 - y1 +1) *Fheight;
  983.         }
  984.  
  985.     if ( RSlocal[ w].rwidth  > MAXWINDOWWIDTH-16-CHO)
  986.           RSlocal[ w].rwidth  = MAXWINDOWWIDTH-16-CHO;
  987.  
  988.     if ( RSlocal[ w].rheight > MAXWINDOWHEIGHT-16)
  989.           RSlocal[ w].rheight = MAXWINDOWHEIGHT-16;
  990.     
  991.  
  992.     if ( (srw !=RSlocal[w].rwidth) || (srh !=RSlocal[w].rheight) ) {
  993.         SizeWindow( RSlocal[w].window, RSlocal[ w].rwidth +16,
  994.                                        RSlocal[ w].rheight+16, FALSE); /*  TRUE if done right */
  995.         /* DrawGrowIcon(RSlocal[w].window);  need? */
  996.         RSsetsize(  w, RSlocal[ w].rheight+16, RSlocal[ w].rwidth+16);
  997.         }
  998.  
  999.     wpeek= (WindowPeek)RSlocal[w].window;
  1000.  
  1001.     HLock( wpeek->dataHandle);
  1002.     wstate= *wpeek->dataHandle;
  1003.  
  1004.     movmem( &wstate->stdState, &pRect, 8);
  1005.     pRect.right=pRect.left+MAXWINDOWWIDTH;
  1006.     if (pRect.right>screenRect.right)
  1007.         pRect.right=screenRect.right;
  1008.  
  1009.     pRect.bottom=pRect.top+MAXWINDOWHEIGHT;
  1010.     movmem( &pRect, &wstate->stdState, 8);
  1011.  
  1012.     VSgetrgn(  w, &x1,&y1,&x2,&y2);
  1013.     VSsetrgn(  w,  x1, y1, (int)(x1+ (RSlocal[ w].rwidth )/Fwidth -1),
  1014.                            (int)(y1+ (RSlocal[ w].rheight)/Fheight-1));
  1015.     VSgetrgn(  w, &x1,&y1,&x2,&y2);        /* Get new region */
  1016.     
  1017. /*  wrong call    VSredraw(  w,0,0,(x2-x1)*Fwidth,(y2-y1)*Fheight);  */
  1018.     DrawGrowIcon(RSlocal[w].window);
  1019.     VSredraw( w, 0,0, (x2-x1+1), (y2-y1+1));
  1020.     ValidRect( &RSlocal[w].window->portRect);
  1021.  
  1022. }
  1023.  
  1024. RSgetfont( w, pfnum, pfsiz)
  1025. int w;
  1026. int *pfnum, *pfsiz;
  1027. {
  1028. /*
  1029. *  Bug fix.  RSsetwind's error conditions are all < 0.  There is a success condition == 1.
  1030. *  TK 12/17/88
  1031. */
  1032.     if (0 > RSsetwind(w)) return -1;
  1033.  
  1034.     *pfnum=RSlocal[w].fnum;
  1035.     *pfsiz=RSlocal[w].fsiz;
  1036.     
  1037.     return(0);
  1038. }
  1039.  
  1040. int RSnewwindow( wDims, scrollback, width, lines, name, wrapon, fnum, fsiz, showit, goaway)
  1041. Rect *wDims;
  1042. int wrapon,
  1043.     goaway,
  1044.     showit,
  1045.     scrollback,
  1046.     fnum,
  1047.     fsiz,
  1048.     lines,
  1049.     width;
  1050. char *name;
  1051. {
  1052.     GrafPort gp;
  1053.     int w;
  1054.  
  1055.     Rect pRect;
  1056.     int t,cur,new,wheight,wwidth;
  1057.     long VSwhereis();
  1058.     WStateData *wstate;
  1059.     WindowPeek wpeek;
  1060.     FontInfo finforec;
  1061.  
  1062.     w=VSnewscreen( scrollback,(scrollback!=0), width, 1);
  1063.  
  1064.     if (w<0) {
  1065.         putln( "Couldn't open Virtual Screen");
  1066.         return(-1);
  1067.         }
  1068.  
  1069.         RSlocal[w].fnum=fnum;
  1070.         RSlocal[w].fsiz=fsiz;
  1071.  
  1072.     OpenPort( &gp);
  1073.         TextFont( fnum);
  1074.         TextSize( fsiz);
  1075.         GetFontInfo( &finforec);
  1076.         RSlocal[w].fwidth=finforec.widMax;
  1077.         RSlocal[w].fascent=finforec.ascent;
  1078.         RSlocal[w].fheight=finforec.ascent+finforec.descent+finforec.leading;
  1079.         RSlocal[w].monospaced= (CharWidth('W')==CharWidth('i'));
  1080.         RSlocal[w].fwidth= CharWidth('W');
  1081.     ClosePort( &gp);
  1082.  
  1083.     if ( (wDims->right -wDims->left) > MAXWINDOWWIDTH)
  1084.         wDims->right = wDims->left + MAXWINDOWWIDTH;
  1085.  
  1086.     if ( (wDims->bottom -wDims->top) > MAXWINDOWHEIGHT)
  1087.         wDims->bottom = wDims->top + MAXWINDOWHEIGHT;
  1088.  
  1089.     wwidth = wDims->right  - wDims->left;
  1090.     wheight= wDims->bottom - wDims->top;
  1091.  
  1092.     if (!RScolor)
  1093.         RSlocal[w].window=NewWindow(0L, wDims, name, showit?TRUE:FALSE, 8, -1L,
  1094.                                                     goaway?TRUE:FALSE, (long)w);
  1095.     else {
  1096.         RGBColor mrgb;
  1097.  
  1098.         RSlocal[w].window=NewCWindow(0L, wDims, name, showit?TRUE:FALSE, 8, -1L,
  1099.                                                     goaway?TRUE:FALSE, (long)w);
  1100.                     /* the screen is not there until we can see it..... */
  1101.         HLock( RSctab);
  1102.         (*RSctab)->ctSize = 4;
  1103.         RSlocal[w].RGBs[0].red  =(*RSctab)->ctTable[0].rgb.red        =     0;
  1104.         RSlocal[w].RGBs[0].green=(*RSctab)->ctTable[0].rgb.green    =     0;
  1105.         RSlocal[w].RGBs[0].blue =(*RSctab)->ctTable[0].rgb.blue        =     0;
  1106.         RSlocal[w].RGBs[1].red  =(*RSctab)->ctTable[1].rgb.red        = 65535;
  1107.         RSlocal[w].RGBs[1].green=(*RSctab)->ctTable[1].rgb.green    = 65535;
  1108.         RSlocal[w].RGBs[1].blue =(*RSctab)->ctTable[1].rgb.blue        = 65535;
  1109.         RSlocal[w].RGBs[2].red  =(*RSctab)->ctTable[2].rgb.red        =     0;
  1110.         RSlocal[w].RGBs[2].green=(*RSctab)->ctTable[2].rgb.green    = 61183;
  1111.         RSlocal[w].RGBs[2].blue =(*RSctab)->ctTable[2].rgb.blue        = 11060;
  1112.         RSlocal[w].RGBs[3].red  =(*RSctab)->ctTable[3].rgb.red        = 61183;
  1113.         RSlocal[w].RGBs[3].green=(*RSctab)->ctTable[3].rgb.green    =  2079;
  1114.         RSlocal[w].RGBs[3].blue =(*RSctab)->ctTable[3].rgb.blue        =  4938;
  1115.         HUnlock(RSctab);
  1116.  
  1117.         RSlocal[w].pal = NewPalette( 4, RSctab, pmCourteous, 0);
  1118.         SetPalette( RSlocal[w].window, RSlocal[w].pal, TRUE);
  1119.         }
  1120.  
  1121.     if (RSlocal[w].window==0L) {
  1122.         printf("Couldn't open Real Window");
  1123.         return(-2);
  1124.         }
  1125.  
  1126.     SetPort( RSlocal[w].window);
  1127.     SetOrigin(CHO,CVO);            /* Cheap way to correct left margin problem */
  1128.  
  1129.     wpeek = (WindowPeek)RSlocal[w].window;
  1130.  
  1131.     HLock( wpeek->dataHandle);
  1132.     wstate = *wpeek->dataHandle;
  1133.  
  1134.     movmem( wDims, &wstate->userState, 8);
  1135.     pRect.top=wDims->top;
  1136.     pRect.left=wDims->left;
  1137.     pRect.right=pRect.left+MAXWINDOWWIDTH;
  1138.     if (pRect.right>screenRect.right)
  1139.         pRect.right=screenRect.right;
  1140.  
  1141.     pRect.bottom=pRect.top+MAXWINDOWHEIGHT;
  1142.     movmem( &pRect, &wstate->stdState, 8);
  1143.  
  1144.     pRect.top     =              -1+CVO;
  1145.     pRect.bottom = wheight- 14 + CVO;
  1146.     pRect.left     = wwidth - 15 + CHO;
  1147.     pRect.right     = wwidth + CHO;
  1148.  
  1149.     RSlocal[w].scroll=NewControl( RSlocal[w].window, &pRect, "", FALSE,
  1150.                                     0,0,0,16,1L);
  1151.     if (RSlocal[w].scroll==0L) {
  1152.         printf("Couldn't Make Vertical Scroll Bar");
  1153.         return(-3);
  1154.         }
  1155.  
  1156.     pRect.top     = wheight-15+CVO;
  1157.     pRect.bottom = wheight   +CVO;
  1158.     pRect.left     =          -1+CHO;
  1159.     pRect.right     = wwidth -14+CHO;
  1160.  
  1161.     RSlocal[w].left=NewControl( RSlocal[w].window, &pRect, "", FALSE,
  1162.                                     0,0,0,16,1L);
  1163.  
  1164.     if (RSlocal[w].left==0L) {
  1165.         printf("Couldn't Make Horizontal Scroll Bar");
  1166.         return(-3);
  1167.         }
  1168.  
  1169.     RSlocal[w].skip= 0;
  1170.  
  1171.     RSlocal[w].max = 0;
  1172.     RSlocal[w].min = 0;
  1173.     RSlocal[w].current = 0;
  1174.     RSlocal[w].lmax =0;
  1175.     RSlocal[w].lmin =0;
  1176.     RSlocal[w].lcurrent =0;
  1177.     RSlocal[w].selected =0;
  1178.  
  1179.     RSsetsize( w, wheight, wwidth);
  1180.     VSsetlines(w, lines);
  1181.     VSsetrgn(w, 0,0,((wwidth -16 + CHO)/Fwidth -1),((wheight-16 + CVO)/Fheight -1) );
  1182.  
  1183.     TextFont(FONT);                /* monaco */
  1184.     TextSize(FSIZE);                /* 9 point*/
  1185.     if (!RScolor)
  1186.         TextMode(srcXor);            /* Xor mode*/
  1187.     else
  1188.         TextMode(srcCopy);
  1189.  
  1190.     if (wrapon)
  1191.         VSwrite( w, "\033[?7h",5);
  1192.  
  1193.     return(w);
  1194. }
  1195.  
  1196. RSkillwindow(w)
  1197. int w;
  1198. {
  1199.     int i;
  1200.  
  1201.     if (!VSdetatch( w )){        /* Detatch the virtual screen */
  1202.         KillControls(  RSlocal[w].window);  /* Get rid of those little slidy things */
  1203.         DisposeWindow( RSlocal[w].window);    /* Get rid of the actual window */
  1204.         RSdetatch( w);        /* Detatch from the table */
  1205.         }
  1206.  
  1207. }
  1208.  
  1209.  
  1210. RSzoom( window, code, shifted)
  1211. GrafPtr window;
  1212. int shifted,    /* (myEvent.modifiers & shiftKey) */
  1213.     code;
  1214. {
  1215.     int w,t;
  1216.     int h,v,x1,x2,y1,y2;
  1217.  
  1218.     SetPort( window);
  1219.     /* EraseRect( &window->portRect); */
  1220.     ZoomWindow( window, code, shifted );
  1221.  
  1222.     h=window->portRect.right- window->portRect.left;
  1223.     v=window->portRect.bottom-window->portRect.top;
  1224.  
  1225.     w=RSfindvwind( window);
  1226.  
  1227.     RSsetsize(  w,v,h);
  1228.  
  1229.     VSgetrgn(  w, &x1,&y1,&x2,&y2);
  1230.     VSsetrgn(  w,  x1, y1, (x1+ (h-16+CHO)/Fwidth -1),
  1231.                                           (y1 + (v-16+CVO)/Fheight -1));
  1232.     VSgetrgn(  w, &x1,&y1,&x2,&y2);        /* Get new region */
  1233.     
  1234. /*     VSredraw(  w,0,0,(x2-x1)*Fwidth,(y2-y1)*Fheight);   wrong call parms*/
  1235. /*    DrawGrowIcon( window); */
  1236.     VSredraw(  w,0,0,x2-x1+1,y2-y1+1); 
  1237.     ValidRect( &window->portRect);
  1238. }
  1239.  
  1240. /*
  1241. *  This routine is called when the user presses the grow icon, or when the size of
  1242. *  the window needs to be adjusted (where==NULL, modifiers==0).
  1243. *  It limits the size of the window to a legal range.
  1244. */
  1245.  
  1246. RSsize( window, where, modifiers)
  1247. GrafPtr window;
  1248. long *where;
  1249. int modifiers;
  1250. {
  1251.     Rect SizRect;
  1252.     long size;
  1253.     int  w,width,lines;
  1254.     int  t,tw, h,v,x1,x2,y1,y2,th;
  1255.  
  1256.     if (( w=RSfindvwind(window)) <0)
  1257.         return(-1);
  1258.  
  1259.     if (modifiers & cmdKey ) return(0);        /* don't allow command-grow */
  1260.     
  1261.     SetPort(window);
  1262.  
  1263.     width=VSmaxwidth(w)+1;
  1264.     lines=VSgetlines(w);
  1265.     tw=MAXWINDOWWIDTH;
  1266. #ifdef LIMIT_WIDTH
  1267.     if (tw>screenRect.right) tw=screenRect.right - window->portRect.left - CHO;
  1268. #endif    LIMIT_WIDTH
  1269.     if (modifiers & 2048 ) th = screenRect.bottom;
  1270.             else th =MAXWINDOWHEIGHT+1;
  1271.     SetRect( &SizRect, 48, 48, tw+1 , th);
  1272.     
  1273.     if (where) {                            /* grow icon actions */
  1274.     
  1275.         size=GrowWindow( window, where, &SizRect);
  1276.         if (size !=0L) {
  1277.             SizeWindow( window, size & 0xffff,(size>>16) & 0xffff, FALSE);
  1278.             h=window->portRect.right- window->portRect.left;
  1279.             v=window->portRect.bottom-window->portRect.top;
  1280.             }
  1281.         else
  1282.             return;                            /* user skipped growing */
  1283.         }
  1284.     else {                                    /* just resize the window */
  1285.         h=window->portRect.right- window->portRect.left;    /* same width */
  1286.         v = (Fheight)*VSgetlines(w) + 16;                        /* new height */
  1287.         SizeWindow( window, h,v, FALSE);                    /* change it */
  1288.         
  1289.         }
  1290.  
  1291.     RSsetsize(  w,v,h);
  1292.     VSgetrgn(  w, &x1,&y1,&x2,&y2);
  1293.     VSsetrgn(  w,  x1, y1, (x1+ (h-16+CHO)/Fwidth -1),
  1294.                                         (y1 + (v-16)/Fheight-1));
  1295.     VSgetrgn(  w, &x1,&y1,&x2,&y2);        /* Get new region */
  1296.     if (modifiers & 2048)             /* option key down means we are resizing the window */
  1297.         VSsetlines( w, y2 - y1+1);        /* Make more lines if user really wants em */
  1298.     VSredraw( w, 0,0, (x2-x1+1), (y2-y1+1));
  1299.     ValidRect( &window->portRect);
  1300.         
  1301. }
  1302.  
  1303. RSclick( window, where, shifted, optioned)
  1304. GrafPtr window;
  1305. long *where;
  1306. int shifted;
  1307. int optioned;
  1308. {
  1309.     ControlHandle ctrlh;
  1310.     int  w,screen,part,part2,x1,x2,y1,y2;
  1311.  
  1312.     if (( w=RSfindvwind(window)) <0)
  1313.         return(-1);
  1314.  
  1315.     SetPort(window);
  1316.  
  1317.     GlobalToLocal( where);
  1318.     if ( (part=FindControl( where, window, &ctrlh)) !=0)
  1319.         switch(part) {
  1320.             case inThumb:
  1321.                 part2=TrackControl(ctrlh, where, 0L);
  1322.                 if (part2 == inThumb) {
  1323.                     part=GetCtlValue(ctrlh);
  1324.                     if (ctrlh==RSlocal[ w].scroll) {
  1325.                         VSgetrgn( w, &x1,&y1,&x2,&y2);    /* Get region */
  1326.                         VSsetrgn( w,x1,part,x2,part+ (y2-y1));
  1327.                         }
  1328.                     else { /* ctrlh must be .left */
  1329.                         VSgetrgn( w, &x1,&y1,&x2,&y2);    /* Get region */
  1330.                         VSsetrgn( w, part, y1, part+(x2-x1), y2);
  1331.                         }
  1332.                     }
  1333.                 break;
  1334.             case inUpButton:
  1335.             case inDownButton:
  1336.             case inPageUp:
  1337.             case inPageDown:
  1338.                 part2 = TrackControl( ctrlh, where, ScrollProc);
  1339.                 break;
  1340.             default:
  1341.                 break;
  1342.             }
  1343.     else {
  1344.         if (optioned) {
  1345.             Point x;
  1346.             (*(long *)&x)=normalize( *where, w);
  1347.             VSpossend( w,x.h,x.v,screens[scrn].echo);
  1348.             }
  1349.         else
  1350.             RSselect(  w, where, shifted);
  1351.         }
  1352. }
  1353.  
  1354. pascal void ScrollProc( control, part)
  1355. short part;
  1356. ControlHandle control;
  1357. {
  1358.     int  w,kind,x1,y2,x2,y1;
  1359.     Point Loc;
  1360.  
  1361.     kind = RSfindscroll( control, & w);
  1362.     VSgetrgn( w, &x1,&y1,&x2,&y2);
  1363.  
  1364.     if (kind ==2) {
  1365.         switch (part) {
  1366.             case inUpButton:                            /* Up is left */
  1367.                 VSscrolleft(  w,1);
  1368.                 break;
  1369.             case inDownButton:                            /* Down is right */
  1370.                 VSscrolright(  w,1);
  1371.                 break;
  1372.             case inPageUp:
  1373.                 VSscrolleft(  w,x2-x1);
  1374.                 break;
  1375.             case inPageDown:
  1376.                 VSscrolright(  w,x2-x1);
  1377.                 break;
  1378.             default:
  1379.                 break;
  1380.             }
  1381.         }
  1382.     else if (kind==1) {
  1383.         switch (part) {
  1384.             case inUpButton:
  1385.                 VSscrolback(  w,1);
  1386.                 break;
  1387.             case inDownButton:
  1388.                 VSscrolforward(  w,1);
  1389.                 break;
  1390.             case inPageUp:
  1391.                 VSscrolback(  w,y2-y1);
  1392.                 break;
  1393.             case inPageDown:
  1394.                 VSscrolforward(  w,y2-y1);
  1395.                 break;
  1396.             default:
  1397.                 break;
  1398.             }
  1399.         }
  1400. }
  1401.  
  1402. RShide( w)
  1403. int w;
  1404. {
  1405.     if (RSsetwind(w)<0) {
  1406.         return(-1);
  1407.         }
  1408.  
  1409.     HideWindow(RSlocal[w].window);
  1410. }
  1411.  
  1412. RSshow( w)
  1413. int w;
  1414. {
  1415.     if (RSsetwind(w)<0) {
  1416.         return(-1);
  1417.         }
  1418.  
  1419.     ShowWindow(RSlocal[w].window);
  1420. }
  1421. #ifdef NCSA_TELNET
  1422.  
  1423.  
  1424. int RScpromptnum=0, RScfontsize=0;
  1425. Str255 RScfontname;
  1426.  
  1427. #ifdef PROMPTFONT
  1428. pascal void RSdrawsize( wind, item)
  1429. GrafPtr wind;
  1430. int item;
  1431. {
  1432.     short itemType;
  1433.     Rect ibox;
  1434.     char **itemh;
  1435.     RGBColor rgb;
  1436.     char temp[50];
  1437.  
  1438.     GetDItem( wind, item, &itemType, &itemh, &ibox);
  1439.  
  1440.     EraseRect( &ibox);
  1441.  
  1442.     MoveTo( ibox.left, ibox.top+12);
  1443.     sprintf(temp, "%d",RScfontsize);
  1444.     DrawString( temp);
  1445.     FrameRect( &ibox);
  1446.     MoveTo( ibox.right, ibox.top+1);
  1447.     LineTo( ibox.right, ibox.bottom);
  1448.     LineTo( ibox.left , ibox.bottom);
  1449. }
  1450.  
  1451. pascal void RSdrawfont( wind, item)
  1452. GrafPtr wind;
  1453. int item;
  1454. {
  1455.     int itemType;
  1456.     Rect ibox;
  1457.     char **itemh;
  1458.     RGBColor rgb;
  1459.  
  1460.     GetDItem( wind, item, &itemType, &itemh, &ibox);
  1461.  
  1462.     EraseRect( &ibox);
  1463.  
  1464.     MoveTo( ibox.left, ibox.top+12);
  1465.     DrawString( &RScfontname);
  1466.     FrameRect( &ibox);
  1467.     MoveTo( ibox.right, ibox.top+1);
  1468.     LineTo( ibox.right, ibox.bottom);
  1469.     LineTo( ibox.left , ibox.bottom);
  1470. }
  1471. #endif PROMPTFONT
  1472.  
  1473. pascal void RScboxdraw( wind, item)
  1474. GrafPtr wind;
  1475. short item;
  1476. {
  1477.     short itemType;
  1478.     Rect ibox;
  1479.     char **itemh;
  1480.  
  1481.     GetDItem( wind, item, &itemType, &itemh, &ibox);
  1482.     InsetRect( &ibox, -2, -2);
  1483.     FrameRect( &ibox);
  1484. }
  1485.  
  1486. pascal void RScdraw( wind, item)
  1487. GrafPtr wind;
  1488. short item;
  1489. {
  1490.     short itemType;
  1491.     Rect ibox;
  1492.     char **itemh;
  1493.     RGBColor rgb;
  1494.  
  1495.     GetDItem( wind, item, &itemType, &itemh, &ibox);
  1496.  
  1497.     GetForeColor( &rgb);
  1498.     RGBForeColor( &RSlocal[RScpromptnum].RGBs[item-3]);
  1499.     PaintRect( &ibox);
  1500.     RGBForeColor( &rgb);
  1501.  
  1502. }
  1503.  
  1504. RScprompt( w, FilterProc)
  1505. int *FilterProc;
  1506. {
  1507.     short itemType;
  1508.     short item,x, size,num;
  1509.     long sresult=1, fresult=1, result;
  1510.     char sizetemp[10];
  1511.  
  1512.     static char *cprompt="\pChoose a color:";
  1513.  
  1514.     Rect ibox,sizebox,fontbox,fnambox,snambox;
  1515.     char **itemh;
  1516.     RGBColor rgb,rgb2;
  1517.     DialogPtr dlog;
  1518.     Point pt;
  1519.     MenuHandle fontMH, sizeMH;
  1520.     GrafPtr OldPort;
  1521.  
  1522.     pt.h=0;
  1523.     pt.v=0;
  1524.  
  1525.  
  1526.     RScpromptnum=w;
  1527. #ifdef PROMPTFONT
  1528.  
  1529.     RScfontsize=RSlocal[w].fsiz;
  1530.     GetFontName( RSlocal[w].fnum, &RScfontname);
  1531. #endif PROMPTFONT
  1532.  
  1533.     dlog=GetNewDialog( 1001, (Ptr) 0L,(Ptr) -1L);
  1534.  
  1535.     SetPort( dlog);
  1536. #ifdef PROMPTFONT
  1537.     fontMH=NewMenu( 63, "\PFontPopUp");
  1538.     AddResMenu( fontMH, 'FONT');
  1539.  
  1540.     sizeMH=NewMenu( 64, "\PSizePopUp");
  1541.     AppendMenu(sizeMH, "\P7;9;10;12;18;24;36");
  1542.  
  1543.     InsertMenu( fontMH, -1);
  1544.  
  1545.     InsertMenu( sizeMH, -1);
  1546. #endif PROMPTFONT
  1547.  
  1548.     GetDItem( dlog, 3, &itemType, &itemh, &ibox);
  1549.     SetDItem( dlog, 3, itemType, RScdraw, &ibox);
  1550.  
  1551.     GetDItem( dlog, 4, &itemType, &itemh, &ibox);
  1552.     SetDItem( dlog, 4, itemType, RScdraw, &ibox);
  1553.  
  1554.     GetDItem( dlog, 5, &itemType, &itemh, &ibox);
  1555.     SetDItem( dlog, 5, itemType, RScdraw, &ibox);
  1556.  
  1557.     GetDItem( dlog, 6, &itemType, &itemh, &ibox);
  1558.     SetDItem( dlog, 6, itemType, RScdraw, &ibox);
  1559.  
  1560.     GetDItem( dlog, 11, &itemType, &itemh, &ibox);
  1561.     SetDItem( dlog, 11, itemType, RScboxdraw, &ibox);
  1562.  
  1563.     GetDItem( dlog, 12, &itemType, &itemh, &ibox);
  1564.     SetDItem( dlog, 12, itemType, RScboxdraw, &ibox);
  1565.  
  1566.     GetDItem( dlog, 13, &itemType, &itemh, &ibox);
  1567.     SetDItem( dlog, 13, itemType, RScboxdraw, &ibox);
  1568.  
  1569.     GetDItem( dlog, 14, &itemType, &itemh, &ibox);
  1570.     SetDItem( dlog, 14, itemType, RScboxdraw, &ibox);
  1571. #ifdef PROMPTFONT
  1572.     GetDItem( dlog, 11, &itemType, &itemh, &fnambox);
  1573.  
  1574.     GetDItem( dlog, 12, &itemType, &itemh, &fontbox);
  1575.     SetDItem( dlog, 12, itemType, RSdrawfont, &fontbox);
  1576.     LocalToGlobal(&fontbox);
  1577.  
  1578.     GetDItem( dlog, 13, &itemType, &itemh, &snambox);
  1579.  
  1580.     GetDItem( dlog, 14, &itemType, &itemh, &sizebox);
  1581.     SetDItem( dlog, 14, itemType, RSdrawsize, &sizebox);
  1582.     LocalToGlobal(&sizebox);
  1583. #endif PROMPTFONT
  1584.  
  1585.     item =0;
  1586.     while (item !=1 && item !=2) {
  1587.         ModalDialog( FilterProc, &item);
  1588.         switch (item) {
  1589.             case 3:
  1590.                 x=GetColor( pt, cprompt, &RSlocal[w].RGBs[0], &rgb2);
  1591.                 if (x)
  1592.                     RSlocal[w].RGBs[0]=rgb2;
  1593.                 break;
  1594.  
  1595.             case 4:
  1596.                 x=GetColor( pt, cprompt, &RSlocal[w].RGBs[1], &rgb2);
  1597.                 if (x)
  1598.                     RSlocal[w].RGBs[1]=rgb2;
  1599.                 break;
  1600.  
  1601.             case 5:
  1602.                 x=GetColor( pt, cprompt, &RSlocal[w].RGBs[2], &rgb2);
  1603.                 if (x)
  1604.                     RSlocal[w].RGBs[2]=rgb2;
  1605.                 break;
  1606.  
  1607.             case 6:
  1608.                 x=GetColor( pt, cprompt, &RSlocal[w].RGBs[3], &rgb2);
  1609.                 if (x)
  1610.                     RSlocal[w].RGBs[3]=rgb2;
  1611.                 break;
  1612.  
  1613. #ifdef PROMPTFONT
  1614.             case 12:
  1615.                 InvertRect( &fnambox);
  1616.                 result = PopUpMenuSelect(fontMH, fontbox.top, fontbox.left, (short) fresult);
  1617.                 result = result & 0xffff;
  1618.                 InvertRect( &fnambox);
  1619.  
  1620.                 if (result >0) {
  1621.                     GetItem( fontMH, (short)result, &RScfontname);
  1622.                     RSdrawfont( dlog, 12);
  1623.                     fresult = result;
  1624.                     }
  1625.                 break;
  1626.             case 14:
  1627.                 InvertRect( &snambox);
  1628.                 result = PopUpMenuSelect(sizeMH, sizebox.top, sizebox.left, (short) sresult);
  1629.                 result = result & 0xffff;
  1630.                 InvertRect( &snambox);
  1631.  
  1632.                 if (result >0) {
  1633.                     GetItem( sizeMH, (short)result, &sizetemp);
  1634.                     sscanf( sizetemp, "%d", &RScfontsize);
  1635.                     RSdrawsize( dlog, 14);
  1636.                     sresult = result;
  1637.                     }
  1638.                 break;
  1639. #endif PROMPTFONT
  1640.  
  1641.             }
  1642.         }
  1643.  
  1644.     DisposDialog(dlog);
  1645.  
  1646.     SetPort(RSlocal[w].window);
  1647.     InvalRect(&RSlocal[w].window->portRect);
  1648.  
  1649.     if ( item ==2)
  1650.         return(-1);
  1651.     else
  1652.         for (x=0;x<4;x++)
  1653.             SetEntryColor( RSlocal[w].pal, x, &RSlocal[w].RGBs[x]);
  1654.      /* do something if it changes */;
  1655.  
  1656. #ifdef PROMPTFONT
  1657.     GetFNum( &RScfontname ,&num);
  1658.     size= RScfontsize;
  1659.     DeleteMenu( fontMH);
  1660.     DeleteMenu( sizeMH);
  1661.  
  1662.     RSchangefont( w, num, size, 1);
  1663. #endif PROMPTFONT
  1664.  
  1665.     return(0);
  1666.  
  1667. }
  1668.  
  1669. RSsetcolor( w, n, r,g,b)
  1670. int w,n;
  1671. unsigned int r, g, b;
  1672. {
  1673.     if ( !HasColor || (RSsetwind(w) < 0)) {        /* BYU mod */
  1674.         return(-1);
  1675.         }
  1676.  
  1677.     RSlocal[w].RGBs[n].red = r;
  1678.     RSlocal[w].RGBs[n].green = g;
  1679.     RSlocal[w].RGBs[n].blue = b;
  1680.     SetEntryColor( RSlocal[w].pal, n, &RSlocal[w].RGBs[n]);
  1681.  
  1682.     SetPort(RSlocal[w].window);
  1683.     InvalRect(&RSlocal[w].window->portRect);
  1684.  
  1685.     return(0);
  1686. }
  1687.  
  1688. RSgetcolor( w, n, r,g,b)
  1689. int w,n;
  1690. unsigned int *r, *g, *b;
  1691. {
  1692.     *r = RSlocal[w].RGBs[n].red;
  1693.     *g = RSlocal[w].RGBs[n].green;
  1694.     *b = RSlocal[w].RGBs[n].blue;
  1695. }
  1696.  
  1697. HiliteMode()
  1698. {
  1699.     char *p = (char *) 0x938;
  1700.     
  1701.     *p=*p &0x7f;
  1702. }
  1703.  
  1704. RSmouseintext( w, myPoint)                /* Point is in global coords */
  1705. long myPoint;
  1706. {
  1707.     return ( PtInRect( &myPoint, &RSlocal[w].textrect )); 
  1708. }
  1709.  
  1710. RSskip(w, on)
  1711. int w,on;
  1712. {
  1713.     RSlocal[w].skip=on;
  1714. }
  1715.  
  1716. /**********************************************************************************/
  1717. /*  Make sure at least this much memory is available before allocating more memory
  1718. *   for me.  Returns true or false whether that much is available.
  1719. */
  1720. RSokmem(amount)
  1721.     int amount;
  1722.     {
  1723.     char *p,*malloc();
  1724.     
  1725.     if (NULL == (p = malloc(amount)))
  1726.         return(0);
  1727.         
  1728.     free(p);
  1729.     return(1);
  1730. }
  1731.