home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Telnet 2.7b5 / source / Screens / rsinterf.c < prev    next >
Encoding:
Text File  |  1995-06-14  |  44.2 KB  |  613 lines  |  [TEXT/CWIE]

  1. /* rsinterf.c */
  2.  
  3. /* A split of RSmac.c to facilitate keeping my sanity --CCP */
  4.  
  5. #include "rsdefs.h"
  6. #include "vsdata.h"
  7. #include "wind.h"
  8. #include "rsmac.proto.h"
  9. #include "vsinterf.proto.h"
  10. #include "vsintern.proto.h"
  11. #include "rsinterf.proto.h"
  12. #include "menuseg.proto.h"
  13. #include "maclook.proto.h"
  14. #include "wdefpatch.proto.h"    /* 931112, ragge, NADA, KTH */
  15. #include "parse.proto.h"
  16. #include "network.proto.h"
  17. #include "DlogUtils.proto.h"
  18. #include "url.proto.h"
  19. #include "drag.proto.h"
  20. #include "configure.proto.h"
  21. #include "errors.proto.h"
  22.  
  23. static void calculateWindowPosition(WindRec *theScreen,Rect *whereAt, short colsHigh, short colsWide);
  24.  
  25. extern WindRec *screens;
  26.  
  27. extern short MaxRS;
  28. extern RSdata *RSlocal, *RScurrent;
  29. extern Rect    noConst;
  30. extern short RSw,         /* last window used */
  31.     RSa;          /* last attrib used */
  32. extern  short **topLeftCorners;
  33. extern short    NumberOfColorBoxes;
  34. extern short    BoxColorItems[8];
  35. extern RGBColor    BoxColorData[8];
  36.  
  37. long RScolors[8] =    //these are the old quickdraw  < 0)    /* Not found */
  38.         return (0);
  39.     
  40.     if (modifiers & cmdKey) return (0);
  41.     
  42.     screenIndexValid = (screenIndex = findbyVS(w)) != -1;
  43.  
  44.     changeVSSize = (modifiers & optionKey) == optionKey;
  45.  
  46. #define DONT_DEFAULT_CHANGE_VS_IF_NAWS                // JMB
  47.     // 931112, ragge, NADA, KTH 
  48.     // I think this is the way it should work, if there is naws available it
  49.     // should be used by default, and option toggles behaviour.
  50.     // Maybe it should be user configurable?
  51. #ifndef DONT_DEFAULT_CHANGE_VS_IF_NAWS
  52.     if(screenIndexValid && screens[screenIndex].naws) {
  53.         changeVSSize = (modifiers & optionKey) != optionKey;
  54.     }
  55. #endif
  56.  
  57.     SetPort(window);
  58.  
  59.     width = VSmaxwidth(w) + 1; //VSmaxwidth returns one less than number of columns
  60.     lines = VSgetlines(w);
  61.  
  62.  
  63.     if (changeVSSize) {
  64.         th = INFINITY;
  65.         tw = INFINITY-1;
  66.         }
  67.     else {
  68.         tw = RMAXWINDOWWIDTH;
  69.         th = RMAXWINDOWHEIGHT + 1;
  70.         }
  71.  
  72.     SetRect(&SizRect, 48, 48, tw + 1, th);
  73.     
  74.     if (where)                                            /* grow icon actions */
  75.         {                            
  76.         if (changeVSSize) { /* 931112, ragge, NADA, KTH */
  77.             setupForGrow(window, 1 - CHO, 1 - CVO, FWidth, FHeight);
  78.         }
  79.         size = GrowWindow(window, *(Point *) where, &SizRect);    /* BYU LSC */
  80.         if (changeVSSize) { /* 931112, ragge, NADA, KTH */
  81.             cleanupForGrow(window);
  82.         }
  83.  
  84.         if (size != 0L)
  85.           {
  86.             SizeWindow(window, size & 0xffff, (size >> 16) & 0xffff, FALSE);
  87.             h = window->portRect.right - window->portRect.left;
  88.             v = window->portRect.bottom - window->portRect.top;
  89.           }
  90.         else return(0);                            /* user skipped growing */
  91.       }
  92.     else
  93.       {                                    /* just resize the window */
  94.         h = window->portRect.right - window->portRect.left;    /* same width */
  95.         v = (FHeight) * (VSgetlines(w));                    /* new height */
  96.         SizeWindow(window, h, v, FALSE);                    /* change it */
  97.         }     
  98.  
  99.     RSsetsize(w, v, h); /* save new size settings and update scroll bars */
  100.  
  101.     
  102.   /* update the visible region of the virtual screen */
  103.  
  104.     VSgetrgn(w, &x1, &y1, &x2, &y2);
  105.     VSsetrgn(w, x1, y1, (short)((x1 + (h - 16 + CHO) / FWidth - 1)),
  106.         (short)((y1 + (v - 16) / FHeight - 1)));
  107.     VSgetrgn(w, &x1, &y1, &x2, &y2);        /* Get new region */
  108.  
  109.     if (changeVSSize) {
  110.         
  111.         switch (VSsetlines(w,y2 -y1 +1)) {
  112.  
  113.  
  114.         case (-4000): //can't even get enough memory to put VS back to original size
  115.             /* signal this to main program */
  116.             return(-4);
  117.             break;
  118.         
  119.         case (-3000): //no resize: unkown problems, but we put the VS back to original size
  120.             return(0);
  121.             break;
  122.         case (-2000): //no resize: Memory problems, but we put the VS back to original size
  123.             return(-2);
  124.             break;
  125.         default:    //Ok, we can resize; tell host
  126.             RScalcwsize(w,x2 - x1 +1);
  127.             if (screenIndexValid && screens[screenIndex].naws)
  128.                 SendNAWSinfo(&screens[screenIndex], (x2-x1+1), (y2-y1+1));
  129.             return (0);
  130.             break;
  131.         }
  132.     }
  133.  
  134.     VSredraw(w, 0, 0, x2 - x1 + 1, y2 - y1 + 1);        /* refresh the part which has been revealed, if any */
  135.     ValidRect(&window->portRect);                        /* window contents are now completely valid */
  136.  
  137.     return (0);
  138.   } /* RSsize */
  139.   
  140. void RSshow( short w)        /* reveals a hidden terminal window. */
  141. {
  142.     VSscrn *theVS;
  143.     if (RSsetwind(w) < 0)
  144.         return;
  145.     theVS = VSwhereis(w);
  146.     RSa = -1;
  147.     VSredraw(w, 0, 0, theVS->maxwidth, theVS->lines);
  148.     ShowWindow(RScurrent->window);
  149. }
  150.  
  151. Boolean RSsetcolor
  152.     (
  153.     short w, /* window number */
  154.     short n, /* color entry number */
  155.     RGBColor    Color
  156.     )
  157.   /* sets a new value for the specified color entry of a terminal window. */
  158.   {
  159.     if ( !(TelInfo->haveColorQuickDraw) || (RSsetwind(w) < 0) || (n > 5) || (n < 0))
  160.         return(FALSE);
  161.     
  162.     SetEntryColor(RScurrent->pal, n, &Color);
  163.     SetPort(RScurrent->window);
  164.     InvalRect(&RScurrent->window->portRect);
  165.     return(TRUE);
  166.   } /* RSsetcolor */
  167.   
  168.   void RSsendstring
  169.   (
  170.     short w, /* which terminal window */
  171.     char *ptr, /* pointer to data */
  172.     short len /* length of data */
  173.   )
  174.   /* sends some data to the host along the connection associated
  175.     with the specified window. */
  176.   {
  177.     short temp;
  178.  
  179.     temp = findbyVS(w);
  180.     if (temp < 0)
  181.         return;
  182.     netpush(screens[temp].port);                /* BYU 2.4.18 - for Diab systems? */        
  183.     netwrite(screens[temp].port, ptr, len);
  184.   } /* RSsendstring */
  185.  
  186.  
  187. short RSnewwindow
  188.   (
  189.     RectPtr     wDims,
  190.     short scrollback, /* number of lines to save off top */
  191.     short width, /* number of characters per text line (80 or 132) */
  192.     short lines, /* number of text lines */
  193.     StringPtr name, /* window name */
  194.     short wrapon, /* autowrap on by default */
  195.     short fnum, /* ID of font to use initially */
  196.     short fsiz, /* size of font to use initially */
  197.     short showit, /* window initially visible or not */
  198.     short goaway, /* NCSA 2.5 */
  199.     short forcesave,        /* NCSA 2.5: force screen save */
  200.       short screenNumber
  201.   )
  202.   /* creates a virtual screen and a window to display it in. */
  203.   {
  204.     GrafPort gp; /* temp port for getting text parameters */
  205.     short w;
  206.  
  207.     Rect        pRect;
  208.     short        wheight, wwidth;
  209.     WStateData    *wstate;
  210.     WindowPeek    wpeek;
  211.     CTabHandle    ourColorTableHdl;
  212.   /* create the virtual screen */
  213.     w = VSnewscreen(scrollback, (scrollback != 0), /* NCSA 2.5 */
  214.         lines, width, forcesave);    /* NCSA 2.5 */
  215.     if (w < 0) {        /* problems opening the virtual screen -- tell us about it */
  216.         return(-1);
  217.           }
  218.       
  219.     RScurrent = RSlocal + w;
  220.  
  221.     RScurrent->fnum = fnum;
  222.     RScurrent->fsiz = fsiz;
  223.  
  224.     OpenPort(&gp);
  225.     RSTextFont(fnum,fsiz,0);    /* BYU */
  226.     TextSize(fsiz);
  227.     RSfontmetrics();
  228.     ClosePort(&gp);
  229.      
  230.     if (wDims->bottom == 0)
  231.         calculateWindowPosition(&screens[screenNumber],wDims,lines,width);
  232.  
  233.     if ((wDims->right - wDims->left) > RMAXWINDOWWIDTH)
  234.         wDims->right = wDims->left + RMAXWINDOWWIDTH;
  235.     if ((wDims->bottom - wDims->top) > RMAXWINDOWHEIGHT)
  236.         wDims->bottom = wDims->top + RMAXWINDOWHEIGHT;
  237.     wwidth = wDims->right - wDims->left;
  238.     wheight = wDims->bottom - wDims->top;
  239.  
  240.     if (!RectInRgn(wDims,TelInfo->greyRegion)) //window would be offscreen
  241.         calculateWindowPosition(&screens[screenNumber],wDims,lines,width);
  242.  
  243.   /* create the window */
  244.     if (!TelInfo->haveColorQuickDraw) {
  245.         RScurrent->window = NewWindow(0L, wDims, name, showit, 8,kInFront, goaway, (long)w);
  246.         RScurrent->pal = NULL;
  247.         if (RScurrent->window == NULL) {
  248.             VSdestroy(w);
  249.             return(-2);
  250.             }
  251.         }
  252.     else
  253.       {
  254.         short i;
  255.         RGBColor scratchRGB;
  256.         
  257.         RScurrent->window = NewCWindow(0L, wDims, name, showit, (short)8,kInFront, goaway, (long)w);
  258.         if (RScurrent->window == NULL) {
  259.             VSdestroy(w);
  260.             return(-2);
  261.             }
  262.         //note: the ANSI colors are in the top 8 of the palette.  The four telnet colors (settable
  263.         //in telnet) are in the lower 4 of the palette.  These 4 are set later by a call from 
  264.         //CreateConnectionFromParams to RSsetColor (ick, but I am not going to add 4 more params to
  265.         //this ungodly function call (CCP 2.7)
  266.         ourColorTableHdl = (CTabHandle) myNewHandle((long) (sizeof(ColorTable) + 
  267.                                     PALSIZE * sizeof(CSpecArray)));
  268.         if (ourColorTableHdl == NULL) 
  269.         {
  270.             DisposeWindow(RScurrent->window);
  271.             VSdestroy(w);
  272.             return(-2);
  273.         }
  274.         HLock((Handle) ourColorTableHdl);
  275.             
  276.         (*ourColorTableHdl)->ctSize = PALSIZE-1;        // Number of entries minus 1
  277.         (*ourColorTableHdl)->ctFlags = 0;
  278.         
  279.         for (i=0; i <4; i++) //set the ctTable.value field to zero for our four
  280.             (*ourColorTableHdl)->ctTable[i].value = 0;
  281.         
  282.         if (TelInfo->AnsiColors==NULL) 
  283.             return(-2); //BUGG CHANGE THIS ONCE WE ARE WORKING
  284.         
  285.         for (i=0; i < MAXATTR*2; i++) //get the ANSI colors from the palette
  286.         {
  287.             GetEntryColor(TelInfo->AnsiColors, i, &scratchRGB);
  288.             (*ourColorTableHdl)->ctTable[i+4].rgb = scratchRGB;
  289.             (*ourColorTableHdl)->ctTable[i+4].value = 0;
  290.         }
  291.         
  292.         RScurrent->pal = NewPalette(PALSIZE, ourColorTableHdl, pmCourteous, 0);
  293.         DisposeHandle((Handle) ourColorTableHdl);
  294.         if (RScurrent->pal == NULL) 
  295.         {
  296.             DisposeWindow(RScurrent->window);
  297.             VSdestroy(w);
  298.             return(-2);
  299.         }
  300.         SetPalette(RScurrent->window, RScurrent->pal, TRUE); //copy the palette to the window
  301.     } 
  302.  
  303.     SetPort(RScurrent->window);
  304.     SetOrigin(CHO, CVO);            /* Cheap way to correct left margin problem */
  305.  
  306.     wpeek = (WindowPeek) RScurrent->window;
  307.  
  308.     HLock(wpeek->dataHandle);
  309.     wstate = (WStateData *) *wpeek->dataHandle;
  310.  
  311.  
  312.     BlockMove(&wstate->userState, wDims, 8);
  313.     pRect.top = wDims->top;
  314.     pRect.left = wDims->left;
  315.     pRect.right = pRect.left + RMAXWINDOWWIDTH;
  316.     if (pRect.right > TelInfo->screenRect.right)
  317.         pRect.right = TelInfo->screenRect.right;
  318.  
  319.     pRect.bottom = pRect.top + RMAXWINDOWHEIil;
  320.         }
  321.  
  322.     RSsetwind(w);
  323.  
  324.     curr = RSlocal[w].anchor;
  325.     last = RSlocal[w].last;
  326.  
  327.   /* normalize coordinates with respect to visible area of virtual screen */
  328.     curr.v -= RScurrent->topline;
  329.     curr.h -= RScurrent->leftmarg;
  330.     last.v -= RScurrent->topline;
  331.     last.h -= RScurrent->leftmarg;
  332.  
  333.     if (curr.v == last.v)
  334.       {
  335.       /* highlighted text all on one line */
  336.         if (curr.h < last.h) /* get bounds the right way round */
  337.           {
  338.             ub = curr;
  339.             lb = last;
  340.           }
  341.         else
  342.           {
  343.             ub = last;
  344.             lb = curr;
  345.           } /* if */
  346.         MYSETRECT /* set up rectangle bounding area to be highlighted */
  347.           (
  348.             temp,
  349.             (ub.h + 1) * RScurrent->fwidth,
  350.             ub.v * RScurrent->fheight,
  351.             (lb.h + 1) * RScurrent->fwidth,
  352.             (lb.v + 1) * RScurrent->fheight
  353.           );
  354.         SectRect(&temp, &noConst, &temp2); /* clip to constraint rectangle */
  355.         RectRgn(rgnH, &temp2);
  356.       }
  357.     else
  358.       {
  359.       /* highlighting across more than one line */
  360.         if (curr.v < last.v)
  361.             ub = curr;
  362.         else
  363.             ub = last;
  364.         if (curr.v > last.v)
  365.             lb = curr;
  366.         else
  367.             lb = last;
  368.         MYSETRECT /* bounds of first (possibly partial) line to be highlighted */
  369.           (
  370.             temp,
  371.             (ub.h + 1) * RScurrent->fwidth,
  372.             ub.v * RScurrent->fheight,
  373.             RScurrent->width,
  374.             (ub.v + 1) * RScurrent->fheight
  375.           );
  376.         SectRect(&temp, &noConst, &temp2); /* clip to constraint rectangle */
  377.         RectRgn(rgnH, &temp2);
  378.  
  379.         MYSETRECT /* bounds of last (possibly partial) line to be highlighted */
  380.           (
  381.             temp,
  382.             0,
  383.             lb.v * RScurrent->fheight,
  384.             (lb.h + 1) * RScurrent->fwidth,
  385.             (lb.v + 1) * RScurrent->fheight
  386.           );
  387.         SectRect(&temp, &noConst, &temp2); /* clip to constraint rectangle */
  388.         RectRgn(tempRgn, &temp2);
  389.         UnionRgn(tempRgn, rgnH, rgnH);
  390.  
  391.         if (lb.v - ub.v > 1) /* highlight extends across more than two lines */
  392.           {
  393.           /* highlight complete in-between lines */
  394.             SetRect
  395.               (
  396.                 &temp,
  397.                 0,
  398.                 (ub.v + 1) * RScurrent->fheight,
  399.                 RScurrent->width,
  400.                 lb.v * RScurrent->fheight
  401.               );
  402.             SectRect(&temp, &noConst, &temp2); /* clip to constraint rectangle */
  403.             RectRgn(tempRgn, &temp2);
  404.             UnionRgn(tempRgn, rgnH, rgnH);
  405.  
  406.           } /* if */
  407.       } /* if */
  408.  
  409.     DisposeRgn(tempRgn);
  410.     
  411.     return rgnH;
  412. }
  413.  
  414. short RSfindvwind
  415.   (
  416.     GrafPtr wind
  417.   )
  418.   /* returns the number of the virtual screen associated with
  419.     the specified window, or -4 if not found. */
  420.   {
  421.     short
  422.         i = 0;
  423.     while ((RSlocal[i].window != wind) && (i < MaxRS))
  424.         i++;
  425.     if ((RSlocal[i].window == 0L) || (i >= MaxRS))
  426.         return(-4);
  427.     else
  428.         return(i);
  429.   } /* RSfindvwind */
  430.  
  431. void RSdeactivate
  432.   (
  433.     short w
  434.   )
  435.  /* handles a deactivate event for the specified window. */
  436.   {
  437.     GrafPtr port;
  438.     GetPort(&port);
  439.     SetPort(RSlocal[w].window);
  440.  
  441.     RSsetConst(w);
  442.   /* update the appearance of the grow icon */
  443.     DrawGrowIcon(RSlocal[w].window); 
  444.   /* and deactivate the scroll bars */
  445.     BackColor(whiteColor);
  446.     if (RSlocal[w].scroll != 0L)
  447.         HideControl(RSlocal[w].scroll);
  448.     if (RSlocal[w].left != 0L)
  449.         HideControl(RSlocal[w].left);
  450.     if (TelInfo->haveColorQuickDraw)
  451.         PmBackColor(1);
  452.     else
  453.         BackColor(blackColor);
  454.      SetPort(port);
  455.   } /* RSdeactivate */
  456.  
  457. void    RScursblink( short w)        /* Blinks the cursor */
  458. {
  459.     GrafPtr    oldwindow;
  460.     long    now = TickCount();
  461.     
  462.     if (now > TelInfo->blinktime) {
  463.         if (VSvalids(w) != 0)            /* BYU 2.4.12 */
  464.             return;                        /* BYU 2.4.12 */
  465.         if (!VSIcursorvisible())        /* BYU 2.4.12 */
  466.             return;                        /* BYU 2.4.12 - cursor isn't visible */
  467.     
  468.         GetPort(&oldwindow);            /* BYU 2.4.11 */
  469.         TelInfo->blinktime = now + 40;    /* BYU 2.4.11 */
  470.         RSlocal[w].cursorstate ^= 1;     /* BYU 2.4.11 */
  471.         SetPort(RSlocal[w].window);        /* BYU 2.4.11 */
  472.         InvertRect(&RSlocal[w].cursor);    /* BYU 2.4.11 */
  473.         SetPort(oldwindow);                /* BYU 2.4.11 */
  474.     }
  475. } /* RScursblink */
  476.  
  477. void RScursblinkon                        /* BYU 2.4.18 */
  478.   (                                        /* BYU 2.4.18 */
  479.     short w                                /* BYU 2.4.18 */
  480.   )                                        /* BYU 2.4.18 */
  481.   /* Blinks the cursor */                /* BYU 2.4.18 */
  482.   {                                        /* BYU 2.4.18 */
  483.       if (!RSlocal[w].cursorstate) {        /* BYU 2.4.18 */
  484.         GrafPtr oldwindow;                /* BYU 2.4.18 */
  485.         GetPort(&oldwindow);            /* BYU 2.4.18 */
  486.         RSlocal[w].cursorstate = 1;     /* BYU 2.4.18 */
  487.         SetPort(RSlocal[w].window);        /* BYU 2.4.18 */
  488.         InvertRect(&RSlocal[w].cursor);    /* BYU 2.4.18 */
  489.         SetPort(oldwindow);                /* BYU 2.4.18 */
  490.     }                                    /* BYU 2.4.18 */
  491.   } /* RScursblink */                    /* BYU 2.4.18 */
  492.  
  493. void RScursblinkoff                        /* BYU 2.4.11 */
  494.   (                                        /* BYU 2.4.11 */
  495.     short w                                /* BYU 2.4.11 */
  496.   )                                        /* BYU 2.4.11 */
  497.   /* Blinks the cursor */                /* BYU 2.4.11 */
  498.   {                                        /* BYU 2.4.11 */
  499.       if (RSlocal[w].cursorstate) {        /* BYU 2.4.11 */
  500.         GrafPtr oldwindow;                /* BYU 2.4.11 */
  501.         GetPort(&oldwindow);            /* BYU 2.4.11 */
  502.         RSlocal[w].cursorstate = 0;     /* BYU 2.4.11 */
  503.         SetPort(RSlocal[w].window);        /* BYU 2.4.11 */
  504.         InvertRect(&RSlocal[w].cursor);    /* BYU 2.4.11 */
  505.         SetPort(oldwindow);                /* BYU 2.4.11 */
  506.     }                                    /* BYU 2.4.11 */
  507.   } /* RScursblink */                    /* BYU 2.4.11 */
  508.  
  509. void    RScprompt(short w)
  510.   /* puts up the dialog that lets the user examine and change the color
  511.     settings for the specified window. */
  512. {
  513.     short        scratchshort, ditem;
  514.     Point        ColorBoxPoint;
  515.     DialogPtr    dptr;
  516.     Boolean        UserLikesNewColor;
  517.     RGBColor    scratchRGBcolor;
  518.     
  519.     dptr = GetNewMySmallDialog(ColorDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  520.  
  521.     for (scratchshort = 0, NumberOfColorBoxes = 4; scratchshort < NumberOfColorBoxes; scratchshort++)
  522.     {
  523.         RGBColor tempColor;
  524.         tempColor = RSgetcolor(w,scratchshort);
  525.         BoxColorItems[scratchshort] = ColorNF + scratchshort;
  526.         BlockMove(&tempColor,&BoxColorData[scratchshort], sizeof(RGBColor));
  527.         UItemAssign( dptr, ColorNF + scratchshort, ColorBoxItemProcUPP);
  528.     }
  529.         
  530.     ColorBoxPoint.h = 0;            // Have the color picker center the box on the main
  531.     ColorBoxPoint.v = 0;            // screen
  532.     
  533.     ditem = 3;    
  534.     while (ditem > 2) {
  535.         ModalDialog(ColorBoxModalProcUPP, &ditem);
  536.         switch (ditem) {
  537.             case    ColorNF:    
  538.             case    ColorNB:    
  539.             case    ColorBF:    
  540.             case    ColorBB:    
  541.                 if (TelInfo->haveColorQuickDraw) {
  542.                     Str255 askColorString;
  543.                     GetIndString(askColorString,MISC_STRINGS,PICK_NEW_COLOR_STRING);
  544.                     UserLikesNewColor = GetColor(ColorBoxPoint, askColorString,
  545.                          &BoxColorData[ditem-ColorNF], &scratchRGBcolor);
  546.                     if (UserLikesNewColor)
  547.                         BoxColorData[ditem-ColorNF] = scratchRGBcolor;
  548.                     }
  549.                 break;
  550.                 
  551.             default:
  552.                 break;
  553.             
  554.             } // switch
  555.         } // while
  556.  
  557.     if (ditem == DLOGCancel) {
  558.         DisposeDialog(dptr);
  559.         return;
  560.         }
  561.         
  562.     for (scratchshort = 0; scratchshort < NumberOfColorBoxes; scratchshort++) 
  563.             RSsetcolor(w,scratchshort,BoxColorData[scratchshort]);
  564.     
  565.     /* force redrawing of entire window contents */
  566.     SetPort(RSlocal[w].window);
  567.     InvalRect(&RSlocal[w].window->portRect);
  568.  
  569.     DisposeDialog(dptr);
  570. } /* RScprompt */
  571.  
  572. /*------------------------------------------------------------------------------*/
  573. /* NCSA: SB - RScalcwsize                                                         */
  574. /*         This routine is used to switch between 80 and 132 column mode. All that    */    
  575. /*         is passed in is the RS window, and the new width.  This calculates the    */    
  576. /*         new window width, resizes the window, and updates everything.  - SMB    */
  577. /*------------------------------------------------------------------------------*/
  578. void RScalcwsize(short w, short width)
  579. {
  580.     short x1,x2,y1,y2;
  581.     short lines;
  582.     short resizeWidth, resizeHeight;
  583.     Rect ourContent;
  584.     
  585.     RSsetwind(w);
  586.     RScursoff(w);
  587.     VSsetcols(w,(short)(width-1));
  588.     VSgetrgn(w, &x1, &y1, &x2, &y2); /*get current visible region */
  589.     x2= width-1;
  590.     lines = VSgetlines(w);                /* NCSA: SB - trust me, you need this... */
  591.     RScurrent->rwidth =
  592.         RScurrent->width = (x2 - x1 + 1) * RScurrent->fwidth - CHO;
  593.     RScurrent->rheight =
  594.         RScurrent->height= (y2 - y1 + 1) * RScurrent->fheight; 
  595.  
  596.  
  597.     if (RScurrent->rwidth > RMAXWINDOWWIDTH - 16 - CHO)
  598.           RScurrent->rwidth = RMAXWINDOWWIDTH - 16 - CHO;
  599.     if (RScurrent->rheight > RMAXWINDOWHEIGHT - 16)
  600.           RScurrent->rheight = RMAXWINDOWHEIGHT - 16;
  601.  
  602.     ourContent = (*((WindowPeek)(RScurrent->window))->contRgn)->rgnBBox;    
  603.     RScheckmaxwind(&ourContent,RScurrent->rwidth +16,    
  604.                 RScurrent->rheight + 16, &resizeWidth, &resizeHeight);        
  605.     RScurrent->rwidth = resizeWidth - 16;
  606.     RScurrent->rheight = resizeHeight - 16;
  607.     SizeWindow
  608.       (
  609.         RScurrent->window,
  610.         RScurrent->rwidth + 16, RScurrent->rheight+16,
  611.         FALSE
  612.       ); 
  613.     RSsetsize(w