home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Telnet 2.7b5 / source / tek / tekrgmac.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-01  |  12.2 KB  |  592 lines  |  [TEXT/CWIE]

  1. /*
  2. rgmac.c by Gaige B. Paulsen
  3.   spawned from rgp.c by Aaron Contorer for NCSA
  4. Copyright 1987, board of trustees, University of Illinois
  5.  
  6. Routines for Macintosh Window output.  
  7. */
  8.  
  9. #ifdef MPW
  10. #pragma segment TEKMAIN
  11. #endif
  12.  
  13.  
  14. #include "tekrgmac.proto.h"
  15. #include "maclook.proto.h"
  16. #include "vgtek.proto.h"
  17. #include "mydnr.proto.h"
  18. #include "rsinterf.proto.h"
  19. #include "netevent.proto.h"
  20. #include "rg0.proto.h"
  21. #include "rgmp.proto.h"
  22. #include "InternalEvents.h"
  23. #include "tekdefs.h"        /* NCSA: sb - all the TEK defines are now here */
  24.  
  25. //#define TEK_DEBUG1
  26. #ifdef    TEK_DEBUG1
  27.  
  28. #define    TEK_DEBUG_PRINT(x)    putln(x)
  29. char    TEK_DEBUG_STRING    [512];
  30. #else
  31. #define    TEK_DEBUG_PRINT(x)
  32. #endif
  33.  
  34. /*--------------------------------------------------------------------------*/
  35. /* Some variable definitions are needed before we give the code                */
  36. /*                                                                             */
  37. /*--------------------------------------------------------------------------*/
  38.  
  39. long    RGMlastclick;
  40. short    RGMcolor[]=
  41.     { 30,            /* black */
  42.       33,            /* white */
  43.       205,            /* red */
  44.       341,            /* green */
  45.       409,            /* blue */
  46.       273,            /* cyan */
  47.       137,            /* magenta */
  48.       69            /* yellow */
  49.       };
  50.  
  51. struct    RGMwindows *RGMwind[ MAXWIND ];
  52.  
  53. char    *RGMdevname(void)
  54. {
  55.     return("Macintosh Windows");
  56. }
  57.  
  58. short    RGMnewwin(void)
  59. {
  60.     short    i = 0;
  61.  
  62.     while ((i < MAXWIND) && (RGMwind[i] != nil)) i++;
  63.  
  64.     if (i >= MAXWIND) return(-1);
  65.  
  66.     RGMwind[i] = (struct RGMwindows *) myNewPtr(sizeof(struct RGMwindows));
  67.     if (RGMwind[i] == nil) {
  68.         return -1;
  69.         }
  70.  
  71.     RGMwind[i]->id = 'RGMW';
  72.  
  73.     RGMwind[i]->wind = GetNewWindow(256, NULL, kInFront);
  74.     if (RGMwind[i]->wind == 0L) {
  75.         DisposePtr((Ptr)RGMwind[i]);
  76.         RGMwind[i] = nil;
  77.         return -1;
  78.         }
  79.  
  80.     ((WindowPeek)RGMwind[i]->wind)->windowKind = WIN_TEK;
  81.     
  82.     RGMwind[i]->vg = -1;                /* BYU */
  83.     RGMwind[i]->vs = -1;                /* BYU */
  84.     RGMwind[i]->xorigin = 0;
  85.     RGMwind[i]->yorigin = 0;
  86.     RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  87.     RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  88.     RGMwind[i]->width   = 400;        /* BYU LSC - was 256 (size of old window resource */
  89.     RGMwind[i]->height  = 300;        /* BYU LSC - was 342 (size of old window resource */
  90.     RGMwind[i]->ingin   = 0;        /* BYU LSC */
  91.  
  92.     ValidRect(&RGMwind[i]->wind->portRect);  
  93.  
  94.     return(i);
  95. }
  96.  
  97. void    RGMinit(void)
  98. {
  99.     short    i;
  100.     for (i = 0; i < MAXWIND; i++)
  101.         RGMwind[i] = nil;
  102. }
  103.  
  104. short    RGMgin(short w)
  105. {
  106.     if (RGsetwind(w)) return(-1);
  107.  
  108.     setgraphcurs();
  109.     RGMwind[w]->ingin=1;
  110. }
  111.  
  112. short    RGMpencolor(short w, short color)
  113. {
  114.     if (RGsetwind(w) ) return(-1);
  115.     ForeColor((long) RGMcolor[color] );
  116. #ifdef    TEK_DEBUG_1
  117.     sprintf(TEK_DEBUG_STRING, "TEK: Setting pen color to %d", color);
  118.     putln(TEK_DEBUG_STRING);
  119. #endif
  120.  
  121. }
  122.  
  123. short    RGMclrscr(short w)
  124. {    
  125.     if (RGsetwind(w) ) return(-1);
  126.     PaintRect(&RGMwind[w]->wind->portRect);
  127.     TEK_DEBUG_PRINT("TEK: Clearing screen");                    
  128. }    
  129.  
  130. short    RGMclose(short w)
  131. {
  132.     if (RGsetwind(w) ) return(-1);
  133.  
  134.     DisposeWindow(RGMwind[w]->wind);
  135.     DisposePtr((Ptr)RGMwind[w]->name);
  136.     DisposePtr((Ptr)RGMwind[w]);
  137.     RGMwind[w] = nil;
  138. }
  139.  
  140. short    RGMpoint(short w, short x, short y)
  141. {
  142.     if (RGsetwind(w) ) return(-1);
  143.  
  144.     MoveTo(x,y);
  145.     LineTo(x,y);
  146.  
  147. short    RGMdrawline(short w, short x0, short y0, short x1, short y1)
  148. {
  149.     long    xl0, yl0, xl1, yl1;
  150.     
  151.     if (RGsetwind(w) )
  152.         return(-1);
  153.  
  154.     xl0 = ((long)x0 * RGMwind[w]->width) / INXMAX;
  155.     yl0 = (long)RGMwind[w]->height - (((long)y0 * RGMwind[w]->height) / INYMAX);
  156.     xl1 = ((long)x1 * RGMwind[w]->width) / INXMAX;
  157.     yl1 = (long)RGMwind[w]->height - (((long)y1 * RGMwind[w]->height) / INYMAX);
  158.  
  159.     MoveTo((short)xl0, (short)yl0);
  160.     LineTo((short)xl1, (short)yl1);
  161. }
  162.  
  163. void    RGMinfo(short w, short v, short a, short b, short c, short d)
  164. {
  165.     UNUSED_ARG(a)
  166.     UNUSED_ARG(b)
  167.     UNUSED_ARG(c)
  168.     UNUSED_ARG(d)
  169.     RGMwind[w]->vg=v;
  170. }
  171.  
  172. void    RGMpagedone(short w)
  173. {
  174.     UNUSED_ARG(w)
  175. }
  176.  
  177. void    RGMdataline(short w, short data, short count)
  178. {
  179.     UNUSED_ARG(w)
  180.     UNUSED_ARG(data)
  181.     UNUSED_ARG(count)
  182. }
  183.  
  184.  
  185. void    RGMcharmode(short w, short rotation, short size)
  186. {
  187.     UNUSED_ARG(w)
  188.     UNUSED_ARG(rotation)
  189.     UNUSED_ARG(size)
  190. }
  191.  
  192. void    RGMgmode(void)
  193. {}
  194.  
  195. void    RGMtmode(void)
  196. {}
  197.  
  198. void    RGMshowcur(void)
  199. {
  200. }
  201.  
  202. void    RGMlockcur(void)
  203. {
  204. }
  205.  
  206. void    RGMhidecur(void)
  207. {
  208. }
  209.  
  210. void    RGMbell(short w)
  211. {
  212.     UNUSED_ARG(w)
  213. }
  214.  
  215. void    RGMuncover(short w)
  216. {
  217.     UNUSED_ARG(w)
  218. }
  219.  
  220. short    RGMoutfunc(short (*f )())
  221. {
  222.     UNUSED_ARG(f)
  223.     return(0);    // Unused
  224. }
  225.  
  226. short    RGsetwind(short dnum)
  227. {
  228.     if (dnum<0 || dnum>=MAXWIND) return(-1);
  229.  
  230.     if (RGMwind[dnum] == nil) return -1;
  231.  
  232.     SetPort( RGMwind[dnum]->wind);
  233.     return(0);
  234. }
  235.  
  236. short    RGfindbyVG(short vg)
  237. {
  238.     short    i = 0;
  239.     
  240.     while (i < MAXWIND) {
  241.         if (RGMwind[i] != nil) {
  242.             if (RGMwind[i]->vg == vg)
  243.                 break;
  244.             }
  245.         i++;
  246.         }
  247.  
  248.     if (i >= MAXWIND) return(-1);
  249.     return(i);
  250. }
  251.  
  252. short    RGattach(short vg, short virt, char *name, short TEKtype)
  253. {
  254.     short            dnum;
  255.     unsigned long    time;
  256.     char            myname[256],ts[256];
  257.  
  258.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);
  259.  
  260.     RGMwind[dnum]->vs = virt;
  261.     RGMwind[dnum]->name = (unsigned char *) myNewPtr((long) 256);        /* BYU LSC */
  262.  
  263.     if (RGMwind[dnum]->name == 0L) return(-2);
  264.  
  265.     myname[0] = '•';
  266.     if (TEKtype)
  267.         strcpy(&myname[1], "[4105] ");
  268.     else
  269.         strcpy(&myname[1], "[4014] ");
  270.         
  271.     strncpy(&myname[strlen(myname)],name,120);
  272.  
  273.     GetDateTime(&time);
  274.     IUTimeString(time,FALSE,(StringPtr) ts);        /* BYU LSC - Put time in the temp string */
  275.     p2cstr((StringPtr)ts);                                            /* BYU LSC */
  276.  
  277.     strncat(myname,"  ",2);                /* BYU - was 4 - Space, please */
  278.     strncat(myname,ts,64);                /* BYU - Place the time string at the end */
  279.     strcpy((char *) RGMwind[dnum]->name,myname);    /* BYU LSC */
  280.  
  281.     if (RGMwind[dnum]->wind != (GrafPtr) 0) {    /* BYU LSC */
  282.         c2pstr(myname);                            /* BYU LSC */
  283.         SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);    /* BYU LSC */
  284.     }
  285.  
  286.     return(0);
  287. }
  288.  
  289.  
  290. short    RGdetach( short vg)
  291. {
  292.         short    dnum;            /* BYU */
  293.         char    myname[256];            /* BYU LSC */
  294.  
  295.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);        /* BYU */
  296.     if (dnum >= MAXWIND)  return(-1);                    /* BYU */
  297.  
  298.     if (RGMwind[dnum]->vs != -1) {                                     /* BYU */
  299.         if (RGMwind[dnum]->wind != (GrafPtr) 0) {                    /* BYU */
  300. #if 1
  301.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  302.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  303.             strncpy(myname, (char *) RGMwind[dnum]->name,256);    /* BYU LSC */
  304.             c2pstr(myname);                                        /* BYU LSC */
  305.             SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);                /* BYU LSC */
  306. #else
  307.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  308.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  309.             SetWTitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);    /* BYU LSC */
  310. #endif
  311.         }                            /* BYU */
  312.     }                                /* BYU */
  313.     return(0);                        /* BYU */
  314. }
  315.  
  316. short    RGfindbywind( GrafPtr wind)
  317. {
  318.     short    i = 0;
  319.  
  320.     while (i < MAXWIND) {
  321.         if (RGMwind[i] != nil) {
  322.             if (RGMwind[i]->wind == wind)
  323.                 break;
  324.             }
  325.         i++;
  326.         }
  327.  
  328.     if (i >= MAXWIND) return(-1);
  329.     return(i);
  330. }
  331.  
  332. short    RGupdate( GrafPtr wind)
  333. {
  334.     short    i = 0,
  335.             done;
  336.  
  337.     if ((i = RGfindbywind(wind)) < 0)
  338.         return(-1);
  339.  
  340.     SetPort(wind);
  341.     BeginUpdate(wind);
  342.  
  343.     VGstopred(RGMwind[i]->vg);
  344.     VGpage(RGMwind[i]->vg);
  345.     done = VGpred(RGMwind[i]->vg,RGMwind[i]->vg);
  346.  
  347.     EndUpdate(wind);
  348.     if (!done)
  349.         netputevent(USERCLASS,RG_REDRAW,RGMwind[i]->vg,0);
  350.     return(done);
  351. }
  352.  
  353. short    RGsupdate( short i)
  354. {
  355.     short    rg;
  356.  
  357.     rg = RGfindbyVG(i);
  358.  
  359.     if (rg < 0) return(0);
  360.     SetPort(RGMwind[rg]->wind);
  361.     if (!VGpred(RGMwind[rg]->vg,RGMwind[rg]->vg))
  362.     {
  363.         netputevent(USERCLASS,RG_REDRAW,i,0);
  364.     }
  365.     else
  366.         return(1);
  367.     return(0);
  368. }
  369.  
  370. short    RGgetVG(GrafPtr wind)
  371. {
  372.     short    i;
  373.  
  374.     i = RGfindbywind(wind);
  375.  
  376.     return(RGMwind[i]->vg);
  377. }
  378.  
  379. short    RGgetdnum(GrafPtr wind)
  380. {
  381.     return(RGfindbywind(wind));
  382. }
  383.  
  384. short    RGgetVS(short dnum)
  385. {
  386.     return(RGMwind[dnum]->vs);
  387. }
  388.  
  389. short    inSplash(Point *p1, Point *p2)
  390. {
  391.     if ((p1->h - p2->h > 3) || (p2->h - p1->h > 3))
  392.         return(0);
  393.     if ((p1->v - p2->v > 3) || (p2->v - p1->v > 3))
  394.         return(0);
  395.  
  396.     return(1);
  397. }
  398.  
  399. void VidSync( void)
  400. {
  401.     long    a;
  402.     a = TickCount();            /* BYU LSC */
  403.     while (a == TickCount())
  404.         /* loop*/;    /* BYU LSC */
  405. }
  406.  
  407. void RGmousedown
  408.   (
  409.     GrafPtr wind,
  410.     Point *wherein
  411.   )
  412. {
  413.     unsigned long    lx,ly;        /* NCSA: SB */
  414.     char            thispaceforent[6];
  415.     short            i;
  416.     Point            where;
  417.     char            dum[32];
  418.  
  419.     where = *wherein;
  420.     if ((i = RGfindbywind(wind)) < 0)
  421.         return;
  422.  
  423.     if (!RGMwind[i]->ingin)
  424.     {
  425.     Point    anchor,current,last;
  426. #if 0                            /* BYU LSC - was "#ifndef MPW" */
  427.     long    TickCount();
  428. #endif MPW
  429.     long    tc;
  430.     short    x0,y0,x1,y1;
  431.     Rect    rect;
  432.     
  433.         SetPort(wind);
  434.     
  435.         last  = where;
  436.         current = where;
  437.         anchor = where;
  438.     
  439.         PenPat(PATTERN(qd.gray));    
  440.         PenMode(patXor);
  441.     
  442.         SetRect(&rect,0,0,0,0);
  443.     
  444.         while (StillDown())
  445.         {
  446.             GetMouse(¤t);
  447.             if (inSplash(¤t,&anchor)) continue;
  448.             tc = TickCount();
  449.             while(TickCount() == tc)
  450.                 /* loop */;
  451.             VidSync();
  452.             FrameRect(&rect);
  453.     
  454.             if (anchor.v < current.v)
  455.             {
  456.                 rect.top = anchor.v;
  457.                 rect.bottom = current.v;
  458.             }
  459.             else
  460.             {
  461.                 rect.top = current.v;
  462.                 rect.bottom = anchor.v;
  463.             }
  464.     
  465.             if (anchor.h < current.h)
  466.             {
  467.                 rect.left = anchor.h;
  468.                 rect.right = current.h;
  469.             }
  470.             else
  471.             {
  472.                 rect.right = anchor.h;
  473.                 rect.left = current.h;
  474.             }
  475.     
  476.             FrameRect(&rect);
  477.             last = current;
  478.         }
  479.     
  480.         FrameRect(&rect);
  481.  
  482.         PenPat(PATTERN(qd.black));    
  483.         PenMode(patCopy);
  484.  
  485.         if (!inSplash(&anchor,¤t))
  486.         {
  487.             x0 = (short) ((long) rect.left * RGMwind[i]->xscale / RGMwind[i]->width );
  488.             y0 = (short) (RGMwind[i]->yscale -
  489.                     (long) rect.top * RGMwind[i]->yscale / RGMwind[i]->height);
  490.             x1 = (short) ((long) rect.right * RGMwind[i]->xscale / RGMwind[i]->width);
  491.             y1 = (short) (RGMwind[i]->yscale -
  492.                     (long) rect.bottom * RGMwind[i]->yscale / RGMwind[i]->height);
  493.             x1 = (x1 < x0+2) ? x0 + 4 : x1;
  494.             y0 = (y0 < y1+2) ? y1 + 4 : y0;
  495.  
  496.             VGzoom( i,
  497.                     x0 + RGMwind[i]->xorigin,
  498.                     y1 + RGMwind[i]->yorigin,
  499.                     x1 + RGMwind[i]->xorigin,
  500.                     y0 + RGMwind[i]->yorigin);
  501.  
  502.             VGpage(RGMwind[i]->vg);
  503.  
  504.             RGMwind[i]->xscale  = x1 - x0;
  505.             RGMwind[i]->yscale  = y0 - y1;
  506.             RGMwind[i]->xorigin = x0 + RGMwind[i]->xorigin;
  507.             RGMwind[i]->yorigin = y1 + RGMwind[i]->yorigin;
  508.  
  509.             while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  510.                 Stask();
  511.             RGMlastclick = 0L;
  512.         }
  513.         else
  514.         {
  515.             if (RGMlastclick && ((RGMlastclick + GetDblTime()) > TickCount()))
  516.             {
  517.                 RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  518.                 RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  519.                 RGMwind[i]->xorigin = 0;
  520.                 RGMwind[i]->yorigin = 0;
  521.  
  522.                 VGzoom(i,0,0,WINXMAX-1,WINYMAX-1);    /* BYU LSC - need the "W" here */
  523.                 VGpage( RGMwind[i]->vg);
  524.                 while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  525.                     Stask();
  526.                 RGMlastclick = 0L;
  527.             }
  528.             else RGMlastclick = TickCount();
  529.         }
  530.         return;
  531.     
  532.     }
  533.     
  534.     /* NCSA: SB */
  535.     /* NCSA: SB - These computations are being truncated and turned into signed ints. */
  536.     /* NCSA: SB - Just make sure everything is cast correctly, and were fine */
  537.     
  538.     lx = ((unsigned long)RGMwind[i]->xscale * (unsigned long)where.h)     /* NCSA: SB */
  539.             / (unsigned long)RGMwind[i]->width;                             /* NCSA: SB */
  540.     ly = (unsigned long)RGMwind[i]->yscale -                             /* NCSA: SB */
  541.         ((unsigned long)RGMwind[i]->yscale * (unsigned long)where.v) / (unsigned long)RGMwind[i]->height; /* NCSA: SB */
  542.  
  543.     VGgindata(RGMwind[i]->vg,(unsigned short) lx,(unsigned short)ly,' ',thispaceforent);    /* NCSA: SB */
  544.  
  545. #if 0                                                    /* BYU LSC - not needed */
  546. sprintf(dum,"GIN i: %d, vs: %d\015",i,RGMwind[i]->vs);    /* BYU 2.4.18 - changed \n to \015 */
  547. putln(dum);
  548. #endif                                                    /* BYU LSC - not needed */
  549.  
  550.     RSsendstring(RGMwind[i]->vs,thispaceforent,5);
  551.     sprintf(dum," \r\n");
  552.     RSsendstring(RGMwind[i]->vs,dum,3);
  553.     
  554.  
  555.     /*    RGMwind[i]->ingin = 0; */
  556.     unsetgraphcurs();
  557.     RGMlastclick = TickCount();
  558. }
  559.  
  560.  
  561. /*--------------------------------------------------------------------------*/
  562. /* NCSA: SB - RGMgrowme                                                        */
  563. /* This allows the TEK window to be grown like any other real window.        */
  564. /* The grow box is not shown on the screen, but it acts accordingly     - SMB    */
  565. /*--------------------------------------------------------------------------*/
  566. void    RGMgrowme(short myRGMnum,GrafPtr window, long *where, short modifiers)
  567. {
  568.     UNUSED_ARG(modifiers)
  569.     long size;
  570.     Rect SizRect;
  571.  
  572.     SetRect(&SizRect, 50, 50, 1500, 1500);            /* NCSA: SB - max size - arbitrary */
  573.  
  574.     if (where)
  575.     {        
  576.         size = GrowWindow(window, *(Point *) where, &SizRect);    
  577.         if (size != 0L)
  578.             {
  579.             SizeWindow(window, size & 0xffff, (size >> 16) & 0xffff, FALSE);
  580.             RGMwind[myRGMnum]->width   = window->portRect.right - window->portRect.left;        
  581.             RGMwind[myRGMnum]->height  = window->portRect.bottom - window->portRect.top;         
  582.             VGpage(RGMwind[myRGMnum]->vg);
  583.             InvalRect(&window->portRect);
  584.             RGupdate(window);
  585.             }
  586.         else
  587.             return;                            /* user skipped growing */
  588.     }
  589. }
  590.  
  591.