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

  1. /**
  2.  *
  3.  *
  4.  *    OpenSReqWindow(1.0)    ARP Programmers Manual   OpenSReqWindow(1.0)
  5.  *
  6.  *
  7.  *
  8.  *    NAME
  9.  *   OpenSReqWindow -- Open a simple requester window
  10.  *
  11.  *    SYNOPSIS
  12.  *   WindowPtr = OpenSReqWindow(SimpleRequester, hsize, vsize,
  13.  *    D0        A0               D0?    D1?
  14.  *                              idcmpflags, flags)
  15.  *
  16.  *    FUNCTION
  17.  *   This function allocates a NewWindow structure, opens a window,
  18.  *   and RectFills a background color, given an initialized Simple-
  19.  *   Requester structure and a width and height. Also, window flags
  20.  *   and IDCMP flags have to be passed. It then deallocates
  21.  *   the NewWindow structure. Notice that it only uses fields in the
  22.  *   SimpleRequester structure that it needs, so this function can
  23.  *   also be used for other than requester windows. Any error
  24.  *   conditions are returned in the SimpleRequester structure.
  25.  *
  26.  *    INPUTS
  27.  *   SimpleRequester -- A pointer to an initialized SimpleRequester
  28.  *                      structure.
  29.  *         hsize           -- The width of the window
  30.  *   vsize           -- The height of the window
  31.  *   idcmpflags      -- The IDCMP flags
  32.  *   flags           -- The window flags
  33.  *
  34.  *    RESULT
  35.  *   WindowPtr       -- NULL if an error was detected. In that case the
  36.  *                      error value may be obtained from the
  37.  *                      SimpleRequester structure. Otherwise a pointer
  38.  *                      to the Window will be returned.
  39.  *
  40.  *    ADDITIONAL CONSIDERATIONS
  41.  *   This routine assumes Intuition and Graphics are already open.
  42.  *   See also the related higher level routines SimpleMsgWin() and
  43.  *   UpdateMsgWin().
  44.  *
  45.  *    BUGS
  46.  *   None reported sofar.
  47.  *
  48.  *    AUTHOR
  49.  *   W.G.J. Langeveld (WGL)
  50.  *
  51.  *
  52. **/
  53. #include <exec/types.h>
  54. #include <exec/io.h>
  55. #include <exec/memory.h>
  56. #include <libraries/dos.h>
  57. #include <intuition/intuition.h>
  58. #include <intuition/intuitionbase.h>
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #include <functions.h>
  63. #include <simpreq.h>
  64. #include "simpdefs.h"
  65.  
  66. extern struct IntuitionBase *IntuitionBase;
  67. extern struct GfxBase *GfxBase;
  68.  
  69. /**
  70.  *
  71.  *   This routine opens the SimpleRequester window
  72.  *
  73. **/
  74. struct Window *OpenSReqWindow ( struct SimpleRequester *s, int hsize, int vsize, ULONG idcmpflags, ULONG flags )
  75. {
  76.     struct NewWindow *nw;
  77.     struct Window     *w;
  78.     ULONG              pen;
  79.     
  80.     s->sr_ErrorCode = SR_SUCCESS;
  81.     /*
  82.      *   Set up a NewWindow structure.
  83.      */
  84.     nw = AllocMem((long) sizeof(struct NewWindow), MEMF_CLEAR);
  85.     if (nw == NULL) 
  86.     {
  87.         s->sr_ErrorCode = SR_OUTOFMEMORY;
  88.         return(NULL);
  89.     }
  90.     
  91.     nw->LeftEdge    = s->sr_x;
  92.     nw->TopEdge     = s->sr_y;
  93.     nw->Width       = hsize;
  94.     nw->Height      = vsize;
  95.     
  96.     if (s->sr_PenList) 
  97.     {
  98.         nw->BlockPen    = s->sr_PenList->reqp_BlockPen;
  99.         nw->DetailPen   = s->sr_PenList->reqp_DetailPen;
  100.     }
  101.     else
  102.     {
  103.         nw->BlockPen    = DEFWINBPEN;
  104.         nw->DetailPen   = DEFWINDPEN;
  105.     }
  106.     
  107.     nw->IDCMPFlags  = idcmpflags;
  108.     nw->Flags       = flags;
  109.     nw->MinWidth    = nw->MaxWidth  = nw->Width;
  110.     nw->MinHeight   = nw->MaxHeight = nw->Height;
  111.     nw->Type        = WBENCHSCREEN;
  112.     /*
  113.      *   Modify the NewWindow structure if Custom Screen
  114.      */
  115.     if (s->sr_Screen) 
  116.     {
  117.         nw->Type   = s->sr_Screen->Flags & SCREENTYPE;
  118.         nw->Screen = s->sr_Screen;
  119.     }
  120.     /*
  121.      *   Open the window and free the NewWindow structure
  122.      */
  123.     w = OpenWindow(nw);
  124.     
  125.     FreeMem(nw, (long) sizeof(struct NewWindow));
  126.     
  127.     if (w == NULL) 
  128.     {
  129.         s->sr_ErrorCode = SR_NOWINDOW;
  130.         return(NULL);
  131.     }
  132.     
  133.     /*
  134.      *   Color in the background
  135.      */
  136.     if (s->sr_PenList) 
  137.     {
  138.         pen = s->sr_PenList->reqp_BackPen;
  139.     }
  140.     else
  141.     {
  142.         pen = DEFBACKPEN;
  143.     }
  144.     
  145.     BlankSReqWin(w, pen);
  146.     
  147.     return(w);
  148. }
  149.  
  150. void BlankSReqWin ( struct Window *w, ULONG pen)
  151. {
  152.     struct RastPort *rp;
  153.     WORD             sp = 0;
  154.     register long    x1,
  155.                      x2,
  156.                      y1,
  157.                      y2;
  158.     
  159.     if (w == NULL)
  160.         return;
  161.     
  162.     rp = w->RPort;
  163.     
  164.     SetAPen(rp, (long) pen);
  165.     SetDrMd(rp, JAM2);
  166.     
  167.     if (w->BorderTop > 4 && pen)
  168.         sp = 1;
  169.     
  170.     x1 = (long) (            w->BorderLeft   + (sp << 1) - 2);
  171.     y1 = (long) (            w->BorderTop    +  sp       - 1);
  172.     x2 = (long) (w->Width  - w->BorderRight  - (sp << 1) + 1);
  173.     y2 = (long) (w->Height - w->BorderBottom -  sp          );
  174.     
  175.     if (IntuitionBase->LibNode.lib_Version >= 36) 
  176.     {
  177.         y1 += 1;
  178.         x2 -= 2;
  179.         x1 += 2;
  180.         y2 -= 1;
  181.     }
  182.     
  183.     if ((x2 >= x1) && (y2 >= y1))
  184.         RectFill(rp, x1, y1, x2, y2);
  185.     return;
  186. }
  187.