home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PMWIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-01  |  5.4 KB  |  199 lines

  1. /*
  2.     pmwin.c    3/11/88
  3.  
  4.     % Pixel map window object.
  5.     Implements a display-only graphics window on the display.
  6.     By Ted.
  7.  
  8.     OWL 1.2
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      8/09/88 jmd    revised to use new object stuff
  15.      8/15/88 jmd    OPEN now takes a winopen_struct (not anymore)
  16.      9/11/88 ted    separated saving operations into a subclass grwin_Class
  17.      9/12/88 jmd    Added in and out data to objects
  18.     11/20/88 jmd    Added ID to obj struct
  19.     12/13/88 ted    Extracted REQ message handlers
  20.  
  21.      8/12/89 jdc    Added INIT and WHO message
  22.      8/13/89 jmd    Added test for NULL pmap in INPOS message
  23.      8/31/89 jmd    Moved SetCharSize to OPEN msg
  24.  
  25.     11/06/89 jmd    removed DoRaw macros
  26.     11/10/89 jmd    added GRAB support
  27.      3/28/90 jmd    ansi-fied
  28.      6/06/90 ted    Added SHADOW case with planemask emsgdata for plane shadows.
  29.      6/12/90 jmd    Fixed shadow clearframe
  30.      6/17/90 ted    Got planemask from shadow attr foreground pixval.
  31.      6/17/90 ted    Moved x and y offsets to pmwin_xd, added and initted 'win' var.
  32.     10/04/90 jmd    added some casts for UNIX compiler happiness
  33. */
  34.  
  35. #include "oakhead.h"
  36. #include "disppriv.h"
  37. #include "pmwinobj.h"
  38. #include "pmwinod.h"
  39.  
  40. OGLOBAL objreq_fptr pmwinreq_mousefptr =  objreq_Null;
  41.  
  42. /* -------------------------------------------------------------------------- */
  43.  
  44. int pmwin_Class(VOID *objdata, int msg, VOID *indata, VOID *outdata)
  45. /* 
  46.     pmap window object dispatch function
  47.     A pmap window displays a pixel map. It must be opened and then
  48.     pmwin_SetPmap must be called to make it point to the pixel map it is
  49.     supposed to display. Handy functions called pmwin_Open() & pmwin_PixOpen()
  50.     are available to take care of this if the window is to be the same size
  51.     as the pmap.
  52. */
  53. {
  54.     pmwin_od    *pmwd;
  55.     pmap_type    pmap;
  56.     win_type win;
  57.  
  58.     if (msg != OBJM_GETDATASIZE) {    /* pmwd isn't valid yet in GETDATASIZE msg */
  59.         pmwd = (pmwin_od *) objdata;
  60.         win = pmwinod_GetSelf(pmwd);
  61.     }
  62.     switch(msg) {
  63.     case OBJM_GETDATASIZE:
  64.         ((ogds_struct *) outdata)->odsize = sizeof(pmwin_od);
  65.         ((ogds_struct *) outdata)->xdsize = sizeof(pmwin_xd);
  66.         ((ogds_struct *) outdata)->id = ID_PMWIN;
  67.         break;
  68.  
  69.     case OBJM_WHO:
  70.         /* Identify ourselves */
  71.         if (*((int *) indata) == ID_PMWIN) {
  72.             return(TRUE);
  73.         }
  74.         return(win_Class(&(pmwd->wd), msg, indata, outdata));
  75.  
  76.     case OBJM_OPEN:
  77.     {
  78.         int ret;
  79.  
  80.         pmwin_getxd(win)->pmap = NULL;    /* (Don't use SetPmap because it calls border) */
  81.         pmwin_setxyoffs(win, 0, 0);        /* offsets for scrolling pmap within window */
  82.  
  83.         /* Send OPEN to win superclass */
  84.         ret = win_Class(&(pmwd->wd), msg, indata, outdata);
  85.  
  86.         /* Override win default: allow any pix size for pmwin's */
  87.         win_SetCharSize(win, FALSE);
  88.  
  89.         return(ret);
  90.     }
  91.  
  92.     case WINM_GRAB:
  93.     {
  94.         ptd_struct    *ptd;
  95.         ptd_struct    inptd;
  96.         opbox        inbox;
  97.         opbox        relbox;
  98.  
  99.         /* grab an image from the display */
  100.         ptd = (ptd_struct *)indata;
  101.         if (ptd_SetInner(ptd, &inptd, &inbox)) {
  102.             opbox_copy(&relbox, inptd.relboxp);
  103.             opbox_trans(&relbox, pmwin_GetXoffs(win), pmwin_GetYoffs(win));
  104.  
  105.             if ((pmap = pmwin_GetPmap(win)) != NULL) {
  106.                 ptd_ReadPixmap(&inptd, pmap, &relbox);
  107.             }
  108.         }
  109.         break;
  110.     }
  111.  
  112.     case WINM_SHADOW:
  113.     case WINM_PAINT:
  114.     {
  115.         ptd_struct    *ptd;
  116.         ptd_struct    inptd;
  117.         opbox        inbox;
  118.         opbox        relbox;
  119.         int            hgt, wid;
  120.         byte        attr;
  121.         opixval        planemask;
  122.  
  123.         ptd = (ptd_struct *)indata;
  124.  
  125.         if (ptd_SetInner(ptd, &inptd, &inbox)) {
  126.  
  127.             /* initialize emsgdata */
  128.             inptd.emsgdata = NULL;
  129.  
  130.             if ((pmap = pmwin_GetPmap(win)) != NULL) {
  131.                 hgt = pmap_GetHeight(pmap);
  132.                 wid = pmap_GetWidth(pmap);
  133.             }
  134.             else {
  135.                 hgt = 0;
  136.                 wid = 0;
  137.             }
  138.             opbox_copy(&relbox, inptd.relboxp);
  139.             opbox_trans(&relbox, pmwin_GetXoffs(win), pmwin_GetYoffs(win));
  140.  
  141.             /* Clear the region outside the pmap, use shadow attr if appropriate */
  142.             attr = (msg == WINM_SHADOW) ? 
  143.                     win_GetShadowAttr(ptd->win) : win_GetAttr(ptd->win);
  144.  
  145.             ptd_ClearFrame(&inptd, -pmwin_GetXoffs(win), -pmwin_GetYoffs(win),
  146.                             wid, hgt, disp_GetAttrBgColor(attr));
  147.  
  148.             if (pmap != NULL) {
  149.                 if (msg == WINM_SHADOW && disp_GetInfo()->nplanes > 1) {
  150.  
  151.                     planemask = disp_GetAttrFgColor(attr);
  152.  
  153.                     /* Send shadow val to ptd_DrawPixmap as planemask parameter */
  154.                     inptd.emsgdata = (VOID *) &planemask;
  155.                     /* Make ptd emsgdata non-NULL so win_Class won't draw shadow */
  156.                     ptd->emsgdata = (VOID *) &planemask;
  157.                 }
  158.                 ptd_DrawPixmap(&inptd, pmap, &relbox);
  159.             }
  160.         }
  161.         /* No break; fall through to win superclass */
  162.     }
  163.     case OBJM_INIT:
  164.     default:
  165.         /* pass other messages to win superclass */
  166.         return(win_Class(&(pmwd->wd), msg, indata, outdata));
  167.  
  168.     case WINM_GETINPOS:
  169.     {
  170.         inposdata_struct *ipd;
  171.  
  172.         ipd = (inposdata_struct *)outdata;
  173.         pmap = pmwin_GetPmap(win);
  174.  
  175.         /* make sure pmap is valid (we could be in the middle of being 
  176.                                     loaded from a screen file)
  177.         */
  178.         if (pmap == NULL) {
  179.             return(win_Class(&(pmwd->wd), msg, indata, outdata));
  180.         }
  181.  
  182.         ipd->inbox.xmin = -pmwin_GetXoffs(win);
  183.         ipd->inbox.xmax = -pmwin_GetXoffs(win) + pmap_GetWidth(pmap);
  184.         ipd->inbox.ymin = -pmwin_GetYoffs(win);
  185.         ipd->inbox.ymax = -pmwin_GetYoffs(win) + pmap_GetHeight(pmap);
  186.         break;
  187.     }
  188.     case WINM_SCROLLREQ:
  189.         return((*pmwinreq_mousefptr)(pmwd, msg, indata, outdata));
  190.  
  191.     case WINM_STARTCUR:    /* no text cursor in this window class */
  192.     case WINM_STOPCUR:
  193.         break;
  194.     }
  195.     return(TRUE);
  196. }
  197. /* -------------------------------------------------------------------------- */
  198.  
  199.