home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / screens.c < prev    next >
C/C++ Source or Header  |  1998-06-26  |  9KB  |  564 lines

  1. /**    Screens.c
  2.   *
  3.   *    Implement the basic screen functions for rexxarplib.library.
  4.   *
  5.   *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  6.   *   ============
  7.   *
  8.   *    CURRENT VERSION:
  9.   *
  10.   *    This version has been converted to SAS C 6.5 format. It has been modified
  11.   *    for modern definition sequences for ANSI compilation. This no longer works
  12.   *    with OS versions prior to 2.04.
  13.   *
  14.   *    rxf_sopen to a public screen will exit through a closescreen with the old
  15.   *    code. This code ends that behavior.
  16.   *
  17.   *    rxf_sopen would produce random color choices either if the color string was
  18.   *    too short. Also the screen title pens were defaulted not matching Workbench
  19.   *    defaults.
  20.   *
  21.   *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  22.   *   ============
  23.   *
  24.   **/
  25.  
  26. #include <functions.h>
  27. #include "ralprotos.h"
  28. #include <exec/types.h>
  29. #include <exec/exec.h>
  30. #include <intuition/intuition.h>
  31. #include <intuition/intuitionbase.h>
  32. #include <libraries/MyARP.h>
  33. #include <proto/rexxsyslib.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <ctype.h>
  37. #include "rexxarplib.h"
  38. #include <simpreq.h>
  39.  
  40. /**
  41.  *
  42.  *   Function to bring a screen to the front
  43.  *
  44. **/
  45. char *rxf_showtitle( long *err, int n, char *args[] )
  46. {
  47.     struct Screen *ps;
  48.     long onoff;
  49.     
  50.     *err = 0;
  51.     
  52.     ps = NULL;
  53.     if (n == 2) 
  54.     {
  55.         ps = LockScreen(args[0]);
  56.         onoff = atol(args[1]);
  57.         
  58.         if (ps) 
  59.         {
  60.             ShowTitle(ps, onoff);
  61.             UnlockScreen(args[0], ps);
  62.             return(CAS("1"));
  63.         }
  64.     }
  65.     
  66.     return(CAS("0"));
  67. }
  68.  
  69. /**
  70.  *
  71.  *   Function to bring a screen to the front
  72.  *
  73. **/
  74. char *rxf_stofront( long *err, int n, char *args[] )
  75. {
  76.     struct Screen *ps;
  77.     
  78.     *err = 0;
  79.     
  80.     ps = NULL;
  81.     if (n >= 1) 
  82.     {
  83.         ps = LockScreen(args[0]);
  84.         if (ps) 
  85.         {
  86.             ScreenToFront(ps);
  87.             UnlockScreen(args[0], ps);
  88.         }
  89.         else
  90.         {
  91.             return(CAS("0"));
  92.         }
  93.     }
  94.     else
  95.     {
  96.         WBenchToFront();
  97.     }
  98.     
  99.     return(CAS("1"));
  100. }
  101.  
  102. /**
  103.  *
  104.  *   Function to move a screen to the back
  105.  *
  106. **/
  107. char *rxf_stoback( long *err, int n, char *args[] )
  108. {
  109.     struct Screen *ps;
  110.     
  111.     *err = 0;
  112.     
  113.     ps = NULL;
  114.     if (n >= 1) 
  115.     {
  116.         ps = LockScreen(args[0]);
  117.         if (ps) 
  118.         {
  119.             ScreenToBack(ps);
  120.             UnlockScreen(args[0], ps);
  121.         }
  122.         else
  123.         {
  124.             return(CAS("0"));
  125.         }
  126.     }
  127.     else
  128.     {
  129.         WBenchToBack();
  130.     }
  131.     
  132.     return(CAS("1"));
  133. }
  134.  
  135. /**
  136.  *
  137.  *   Function to get the number of rows on a screen
  138.  *
  139. **/
  140. char *rxf_srows( long *err, int n, char *args[] )
  141. {
  142.     struct Screen *ps;
  143.     int rows = -1;
  144.     char bf[11];
  145.     
  146.     *err = 0;
  147.     
  148.     if (n >= 1) 
  149.     {
  150.         ps = LockScreen(args[0]);
  151.         if (ps) 
  152.         {
  153.             rows = ps->Height;
  154.             UnlockScreen(args[0], ps);
  155.         }
  156.     }
  157.     else
  158.     {
  159.         rows = GetWBRows();
  160.         if (GetWBLace() > 0)
  161.             rows <<= 1;
  162.     }
  163.     
  164.     return( CAS(ltoa(bf, (long) rows)) );
  165. }
  166.  
  167.  
  168. /**
  169.  *
  170.  *   Function to get the number of columns on a screen
  171.  *
  172. **/
  173. char *rxf_scols( long *err, int n, char *args[] )
  174. {
  175.     struct Screen *ps;
  176.     char bf[11];
  177.     int cols = -1;
  178.     
  179.     *err = 0;
  180.     
  181.     if (n >= 1) 
  182.     {
  183.         ps = LockScreen(args[0]);
  184.         if (ps) 
  185.         {
  186.             cols = ps->Width;
  187.             UnlockScreen(args[0], ps);
  188.         }
  189.     }
  190.     else
  191.     {
  192.         cols = GetWBCols();
  193.     }
  194.     
  195.     return( CAS(ltoa(bf, (long) cols)) );
  196. }
  197.  
  198.  
  199. /**
  200.  *
  201.  *   Function to get the interlace status of a screen
  202.  *
  203. **/
  204. char *rxf_slace( long *err, int n, char *args[] )
  205. {
  206.     struct Screen *ps;
  207.     char bf[11];
  208.     int lace = -1;
  209.     
  210.     *err = 0;
  211.     
  212.     if (n >= 1) 
  213.     {
  214.         ps = LockScreen(args[0]);
  215.         if (ps)
  216.         {
  217.             if (ps->ViewPort.Modes & LACE)
  218.                 lace = 1;
  219.             else
  220.                 lace = 0;
  221.             UnlockScreen(args[0], ps);
  222.         }
  223.     }
  224.     else
  225.     {
  226.         lace = GetWBLace();
  227.     }
  228.     
  229.     return( CAS(ltoa(bf, (long) lace)) );
  230. }
  231.  
  232. /**
  233.  *
  234.  *   Function to get the colors of the screen
  235.  *
  236. **/
  237. char *rxf_scolor( long *err, int n, char *args[] )
  238. {
  239.     struct Screen *ps;
  240.     char bf[11], s[30];
  241.     int ncol, maxcol;
  242.     short colors;
  243.     
  244.     *err = 17;
  245.     
  246.     if (n != 2 && n != 5)
  247.         return(CAS("-1"));
  248.     
  249.     *err = 12;
  250.     
  251.     ps = LockScreen(args[0]);
  252.     if (ps) 
  253.     {
  254.         ncol = atoi(args[1]);
  255.         maxcol = 1 << (ps->BitMap.Depth);
  256.         if (maxcol > 32)
  257.             maxcol = 32;
  258.         if (ncol < maxcol) 
  259.         {
  260.             *err = 0;
  261.             if ((colors = GetRGB4((&(ps->ViewPort))->ColorMap,
  262.             (long) ncol)) != -1) 
  263.             {
  264.                 strcpy(s, ltoa(bf, (long) ((colors >> 8) & 0xF)));
  265.                 strcat(s, " ");
  266.                 strcat(s, ltoa(bf, (long) ((colors >> 4) & 0xF)));
  267.                 strcat(s, " ");
  268.                 strcat(s, ltoa(bf, (long) ( colors       & 0xF)));
  269.             }
  270.             if (n == 5) 
  271.             {
  272.                 SetRGB4(&(ps->ViewPort), (long) ncol, atol(args[2]),
  273.                 atol(args[3]), atol(args[4]));
  274.             }
  275.         }
  276.         UnlockScreen(args[0], ps);
  277.     }
  278.     else
  279.     {
  280.         return(CAS("-1"));
  281.     }
  282.     
  283.     return( CAS(s) );
  284. }
  285.  
  286.  
  287.  
  288. /**
  289.  *
  290.  *   Function to move a screen
  291.  *
  292. **/
  293. char *rxf_smove( long *err, int n, char *args[] )
  294. {
  295.     struct Screen *ps;
  296.     int dx = 0, dy = 0;
  297.     char s[30];
  298.     
  299.     *err = 17;
  300.     
  301.     if (n < 1)
  302.         return( CAS("0") );
  303.     
  304.     *err = 12;
  305.     
  306.     ps = LockScreen(args[0]);
  307.     if (ps) 
  308.     {
  309.         *err = 0;
  310.         if ((n >= 2) && args[1])
  311.             dx = atoi(args[1]);
  312.         if ((n >= 3) && args[2])
  313.             dy = atoi(args[2]);
  314.         
  315.         if (dx || dy)
  316.             MoveScreen(ps, (LONG) dx, (LONG) dy);
  317.         
  318.         ltoa(s, (long) ps->LeftEdge);
  319.         strcat(s, " ");
  320.         ltoa(&s[strlen(s)], (long) ps->TopEdge);
  321.         
  322.         UnlockScreen(args[0], ps);
  323.     }
  324.     else
  325.     {
  326.         return(CAS("0"));
  327.     }
  328.     
  329.     return(CAS(s));
  330. }
  331.  
  332.  
  333.  
  334. /**
  335.  *
  336.  *   Open a public screen
  337.  *
  338. **/
  339. #include "newlook.h"
  340.  
  341. #define NSSIZE ((long) sizeof(struct ExtNewScreen))
  342.     
  343. static UWORD std_pens[10] =
  344. {
  345.     1, 2, 1, 2, 1, 3, 1, 0, 2, 0xffff
  346. };
  347.  
  348. char *rxf_sopen( long *err, int n, char *args[] )
  349. {
  350.     struct ExtNewScreen *ns = NULL;
  351.     struct Screen *ps = NULL;
  352.     char *tp = NULL;
  353.     int result = 0;
  354.     struct TagItem tags[3];
  355.     UWORD p_pens[10];
  356.     int i, j, oscanflag = 0, autosflag = 0;
  357.     
  358.     *err = 18;
  359.     if (!args[4])
  360.         goto cleanup;
  361.     
  362.     ps = LockScreen(args[4]);
  363.     if (ps) 
  364.     {
  365.         UnlockScreen(args[4], ps);
  366.         ps = NULL;    /* Added June 1998, JDow */
  367.         goto cleanup;    /* Screen already exists! */
  368.     }
  369.     
  370.     *err = 12;
  371.     ns = (struct ExtNewScreen *) AllocMem(NSSIZE, MEMF_PUBLIC | MEMF_CLEAR);
  372.     if (!ns)
  373.         goto cleanup;
  374.     
  375.     if ((n >= 1) && args[0])
  376.         ns->TopEdge  = atoi(args[0]);
  377.     if ((n >= 2) && args[1])
  378.         ns->Depth    = atoi(args[1]);
  379.     if ((n >= 3) && args[2]) 
  380.     {
  381.         if (strstr(args[2], "HIRES"))
  382.             ns->ViewModes |= HIRES;
  383.         if (strstr(args[2], "LACE"))
  384.             ns->ViewModes |= LACE;
  385.         if (strstr(args[2], "HAM"))
  386.             ns->ViewModes |= HAM;
  387.         if (strstr(args[2], "SCREENBEHIND"))
  388.             ns->Type |= SCREENBEHIND;
  389.         if (strstr(args[2], "OVERSCAN"))
  390.             oscanflag = 1;
  391.         if (strstr(args[2], "AUTOSCROLL"))
  392.             autosflag = 1;
  393.     }
  394.     if ((n >= 7) && args[6])
  395.         ns->Width = atoi(args[6]);
  396.     if ((n >= 8) && args[7])
  397.         ns->Height = atoi(args[7]);
  398.     if ((n >= 9) && args[8])
  399.         ns->LeftEdge = atoi(args[8]);
  400.     
  401.     if (ns->Width <= 0) 
  402.     {
  403.         ns->Width = GetWBCols();
  404.         if ((ns->ViewModes & HIRES) == 0)
  405.             ns->Width >>= 1;
  406.     }
  407.     
  408.     if (ns->Height <= 0) 
  409.     {
  410.         ns->Height = GetWBRows();
  411.         if (ns->ViewModes & LACE)
  412.             ns->Height <<= 1;
  413.     }
  414.     
  415.     if ((n >= 3) && args[2]) 
  416.     {
  417.         if (strstr(args[2], "TRUNCATE"))
  418.             ns->Height -= ns->TopEdge;
  419.     }
  420.     
  421.     if (ns->Depth == 0)
  422.         ns->Depth   = 2;
  423.     
  424.     ns->DetailPen = 0;
  425.     ns->BlockPen  = 1;
  426.     ns->Font      = Topaz80Equiv();
  427.     
  428.     ns->Type = PUBLICSCREEN | NS_EXTENDED;
  429.     ns->Extension = tags;
  430.     
  431.     i = 0;
  432.     tags[i].ti_Tag = SA_PubName;       tags[i].ti_Data = (ULONG) args[4];
  433.     i++;
  434.     if (autosflag) 
  435.     {
  436.         tags[i].ti_Tag = SA_AutoScroll; tags[i].ti_Data = (ULONG) 1L;
  437.         i++;
  438.     }
  439.     if (oscanflag) 
  440.     {
  441.         tags[i].ti_Tag = SA_Overscan;   tags[i].ti_Data = (ULONG) 1L;
  442.         i++;
  443.     }
  444.     if (ns->Depth > 1) 
  445.     {
  446.         for (j = 0; j < 10; j++)
  447.             p_pens[j] = std_pens[j];
  448.         if ((n >= 6) && args[5]) 
  449.         {
  450.             for (j = 0;  (args[5][j] != '\0') && (j < 9); j++) 
  451.             {
  452.                 p_pens[j] = ((unsigned char) args[5][j] - '0') & 0x1F;
  453.  
  454.                 if (j == 0)    // Screen Title Detail (text) Pen
  455.                     ns->DetailPen = p_pens[j];
  456.                 if (j == 1)    // Screen Title Block (background) Pen
  457.                     ns->BlockPen = p_pens[j];
  458.             }
  459.             p_pens[j] = 0xffff;
  460.         }
  461.         tags[i].ti_Tag = SA_Pens;       tags[i].ti_Data = (ULONG) p_pens;
  462.         i++;
  463.     }
  464.     tags[i].ti_Tag = TAG_END;          tags[i].ti_Data = (ULONG) 0L;
  465.     
  466.     if ((n >= 4) && args[3]) 
  467.     {
  468.         tp = mymalloc(strlen(args[3]) + 1);
  469.         if (!tp)
  470.             goto cleanup;
  471.         strcpy(tp, args[3]);
  472.         ns->DefaultTitle = (UBYTE *) tp;
  473.     }
  474.     
  475.     ps = OpenScreen( (struct NewScreen *) ns);
  476.     if (!ps)
  477.         goto cleanup;
  478.     
  479.     result = PubScreenStatus(ps, 0L);
  480.     
  481.     cleanup:
  482.     if (ns)
  483.         FreeMem(ns, NSSIZE);
  484.     
  485.     if (result & 1) 
  486.     {
  487.         *err = 0;
  488.         return(CAS("1"));
  489.     }
  490.     
  491.     if (ps)
  492.         CloseScreen(ps);
  493.  
  494.     if (tp)
  495.         myfree(tp);
  496.     
  497.     return(CAS("0"));
  498. }
  499.  
  500.  
  501. /**
  502.  *
  503.  *   Close a public screen
  504.  *
  505. **/
  506. char *rxf_sclose( long *err, int n, char *args[] )
  507. {
  508.     struct Screen *ps = NULL;
  509.     char *tp = NULL;
  510.     long sts;
  511.     
  512.     *err = 18;
  513.     if (!args[0])
  514.         goto cleanup;
  515.     
  516.     *err = 12;
  517.     
  518.     ps = LockScreen(args[0]);
  519.     if (ps) 
  520.     {
  521.         UnlockScreen(args[0], ps);
  522.         sts = PubScreenStatus(ps, PSNF_PRIVATE);
  523.  
  524.         if (sts & 1L)
  525.         {
  526.             tp = (char *) ps->DefaultTitle;
  527.             CloseScreen(ps);
  528.             if (tp)
  529.                 myfree(tp);
  530.             *err = 0;
  531.         }
  532.     }
  533.     
  534.     cleanup:
  535.     if (*err)
  536.         return(CAS("0"));
  537.     
  538.     return(CAS("1"));
  539. }
  540.  
  541. /**
  542.  *
  543.  *   Encapsulation of (un)locking screens
  544.  *
  545. **/
  546. struct Screen *LockScreen( char *name )
  547. {
  548.     struct Screen *ps = NULL;
  549.     
  550.     if (name == NULL)
  551.         return(NULL);
  552.     
  553.     ps = LockPubScreen(name);
  554.     
  555.     return(ps);
  556. }
  557.  
  558. struct Screen *UnlockScreen( char *name, struct Screen *ps )
  559. {
  560.     if (name && ps) 
  561.         UnlockPubScreen(NULL, ps);
  562.     return(NULL);
  563. }
  564.