home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / CMWIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  8.4 KB  |  304 lines

  1. /*
  2.     cmwin.c    3/11/88
  3.  
  4.     % Character map window object.
  5.     By Ted.
  6.  
  7.     OWL 1.1
  8.     Copyright (c) 1988, by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.      6/16/88 Ted    revised to have inheritance and class factory functions.
  14.      8/09/88 jmd    revised to use new object stuff
  15.      8/15/88 jmd    OPEN now takes a winopen_struct
  16.      9/12/88 jmd    Added in and out data to objects
  17.     11/20/88 jmd    Added ID to obj struct
  18.     12/13/88 jmd    Added cmap = NULL to cmwin_GetCmap (removes LC warning)
  19.  
  20.      1/18/89 Ted    changed call to PlotText for simplified interface.
  21.      6/24/89 jmd    added shadow support
  22.      8/12/89 jmd    improved shadow support
  23.      8/12/89 jdc    Added INIT and WHO message
  24.      8/13/89 jmd    Added test for NULL cmap in INPOS message
  25.  
  26.     Questions...  *** Answers 7/05/89 ted.
  27.     1) why is cmwin made current during ISAVE message?
  28.         Because the ISAVE message is only sent during disp_Init to the
  29.         background window, and this allows the vid_win to display its cursor.
  30.     2) read loop in cmwin_Plot looks like it could be better.
  31.         Since this is a rarely used feature I optimized for code size and
  32.         simplicity.
  33.     3) Spaces plotting should be optimized.
  34.         Go ahead.
  35. */
  36.  
  37. #include "oakhead.h"
  38. #include "disppriv.h"
  39. #include "cmwinobj.h"
  40. #include "cmwinod.h"
  41.  
  42. OGLOBAL objreq_fptr cmwinreq_mousefptr =  objreq_Null;
  43.  
  44. OSTATIC void OWLPRIV cmwin_PlotBox(_arg3(ptd_struct *, cmwin_od *, int));
  45. OSTATIC void OWLPRIV ptd_ReadCharAttrbuf(_arg6(ptd_struct *, opcoord, opcoord, char *, byte *, int));
  46.  
  47. #define CMWIN_READBOX    0
  48. #define CMWIN_PLOTBOX    1
  49. #define CMWIN_SHADOW    2
  50. /* -------------------------------------------------------------------------- */
  51.  
  52. int cmwin_Class(objdata, msg, indata, outdata)
  53.     VOID *objdata;            /* object instance data pointer */
  54.     int msg;                /* message */
  55.     VOID *indata;            /* message input data */
  56.     VOID *outdata;            /* message output data */
  57. /* 
  58.     cmap window object dispatch function
  59. */
  60. {
  61.     cmwin_od     *cmwd;
  62.     win_type    win;
  63.     cmap_type     cmap;
  64.     ofont_type  font;
  65.     ptd_struct     *ptd;
  66.     ptd_struct  inptd;        /* for use in inner-coordinate computations */
  67.     opbox         inbox;        /* ditto; gets hooked in by ptd_SetInner */
  68.     winopendata_struct *wod;
  69.     inposdata_struct *ipd;
  70.  
  71.     cmwd = (cmwin_od *) objdata;
  72.     if (msg != OBJM_GETDATASIZE) {    /* would be GP fault in this case */
  73.         win = cmwinod_GetSelf(cmwd);
  74.     }
  75.     switch(msg) {
  76.     case OBJM_GETDATASIZE:
  77.         ((ogds_struct *) outdata)->odsize = sizeof(cmwin_od);
  78.         ((ogds_struct *) outdata)->xdsize = sizeof(cmwin_xd);
  79.         ((ogds_struct *) outdata)->id = ID_CMWIN;
  80.         break;
  81.  
  82.     case OBJM_INIT:
  83.         wod = (winopendata_struct *) indata;
  84.  
  85.         if (wod->font == NULL) {
  86.             return(FALSE);
  87.         }
  88.  
  89.         /* Allocate character map */
  90.         if ((cmap = cmap_Open(opbox_GetHeight(wod->boxp)/ofont_GetHeight(wod->font),
  91.             opbox_GetWidth(wod->boxp)/ofont_GetWidth(wod->font))) == NULL) {
  92.  
  93.             return(FALSE);
  94.         }
  95.         cmwin_SetCmap(win, cmap);
  96.  
  97.         return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
  98.  
  99.     case OBJM_OPEN:
  100.         /* Initialize cmap data */
  101.         cmwin_SetCmap(win, NULL);
  102.         cmwin_SetRowoffs(win, 0);    /* offsets for scrolling cmap within window */
  103.         cmwin_SetColoffs(win, 0);
  104.  
  105.         /* send OPEN message to win superclass */
  106.         return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
  107.  
  108.     case OBJM_CLOSE:
  109.         /* close character map */
  110.         if (cmwin_GetCmap(win) != NULL) {
  111.             cmap_Close(cmwin_GetCmap(win));
  112.         }
  113.         /* No break, pass CLOSE msg to win superclass */
  114.     default:
  115.         /* pass other messages to win superclass */
  116.         return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
  117.  
  118.     case OBJM_WHO:
  119.         /* Identify ourselves */
  120.         if (*((int *) indata) == ID_CMWIN) {
  121.             return(TRUE);
  122.         }
  123.         return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
  124.  
  125.     case WINM_SHADOW:
  126.         ptd = (ptd_struct *)indata;
  127.  
  128.         /* set ptd data to indicate that we've taken care of the shadow */
  129.         ptd->emsgdata = (VOID *) 1;
  130.  
  131.         /* no break; fall through to PAINT */
  132.  
  133.     case WINM_PAINT:
  134.         ptd = (ptd_struct *)indata;
  135.         if (ptd_SetInner(ptd, &inptd, &inbox)) {
  136.             cmwin_PlotBox(&inptd, cmwd, (msg == WINM_PAINT) ? CMWIN_PLOTBOX : CMWIN_SHADOW);
  137.         }
  138.         return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
  139.  
  140.     case WINM_ISAVE:
  141.         ptd = (ptd_struct *)indata;
  142.  
  143.     /* This is background cmwin; make it current */
  144.         win_MakeCurrent(ptd->win);
  145.  
  146.     /*  Get the characters from the display into the cmap */
  147.         if (ptd_SetInner(ptd, &inptd, &inbox)) {
  148.             cmwin_PlotBox(ptd, cmwd, CMWIN_READBOX);
  149.         }
  150.         break;
  151.  
  152.     case WINM_GETINPOS:
  153.         ipd = (inposdata_struct *) outdata;
  154.         font = win_GetFont(ipd->win);
  155.  
  156.         /* make sure cmap is valid (we could be in the middle of being 
  157.                                     loaded from a screen file)
  158.         */
  159.         if (cmwin_GetCmap(win) == NULL) {
  160.             return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
  161.         }
  162.  
  163.         ipd->inbox.xmin = -cmwin_GetColoffs(win) * ofont_GetWidth(font);
  164.         ipd->inbox.xmax = ipd->inbox.xmin + 
  165.                         (cmap_GetWidth(cmwin_GetCmap(win)) * ofont_GetWidth(font));
  166.         ipd->inbox.ymin = -cmwin_GetRowoffs(win) * ofont_GetHeight(font);
  167.         ipd->inbox.ymax = ipd->inbox.ymin + 
  168.                         (cmap_GetHeight(cmwin_GetCmap(win)) * ofont_GetHeight(font));
  169.         break;
  170.  
  171.     case WINM_SCROLLREQ:
  172.         return((*cmwinreq_mousefptr)(cmwd, msg, indata, outdata));
  173.     }
  174.  
  175.     return(TRUE);
  176. }
  177. /* -------------------------------------------------------------------------- */
  178.  
  179. static void OWLPRIV cmwin_PlotBox(ptd, cmwd, plot)
  180.     ptd_struct *ptd;
  181.     cmwin_od *cmwd;
  182.     int plot;    /* flag to plot, shadow,  or read */
  183. /*
  184.     Plots a region of a cmap window to the display.
  185. */
  186. {
  187.     win_type win;
  188.     cmap_type cmap;
  189.     ocbox     relcbox;
  190.     opcoord xpix, ypix;
  191.     int     row;
  192.     char   *charbuf;
  193.     byte   *attrbuf;
  194.     opcoord fwidth, fheight;
  195.     int     cwidth;
  196.     int     i, last;
  197.     byte     lasta, attr;
  198.     ofont_type font;
  199.  
  200.     win = cmwinod_GetSelf(cmwd);
  201.     cmap = cmwin_GetCmap(win);
  202.     font = win_GetFont(ptd->win);
  203.     fheight = ofont_GetHeight(font);
  204.     fwidth  = ofont_GetWidth(font);
  205.  
  206.     opbox_charcoords(ptd->relboxp, font, &relcbox);
  207.     ocbox_trans(&relcbox, cmwin_GetRowoffs(win), cmwin_GetColoffs(win));
  208.  
  209.     /* Clear out the parts of the box not occupied by cmap, if any */
  210.     attr = (plot == CMWIN_SHADOW) ? win_GetShadowAttr(win) : win_GetAttr(win);
  211.  
  212.     ptd_ClearFrame(ptd, -cmwin_GetColoffs(win) * fwidth, -cmwin_GetRowoffs(win) * fheight,
  213.                     cmwin_GetCmap(win)->ncols * fwidth, cmwin_GetCmap(win)->nrows * fheight,
  214.                     disp_GetAttrBgColor(attr));
  215.  
  216.     /* Plot the text from the window */
  217.     if (cmap_clipcbox(cmap, &relcbox)) {
  218.  
  219.         charbuf = cmap_charbuf(cmap, relcbox.toprow, relcbox.leftcol);
  220.         attrbuf = cmap_charattrbuf(cmap, charbuf);
  221.  
  222.         ocbox_trans(&relcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  223.  
  224.         ypix = (relcbox.toprow + 1) * fheight;
  225.         xpix = (relcbox.leftcol) * fwidth;
  226.         cwidth = ocbox_GetWidth(&relcbox);
  227.  
  228.         row = ocbox_GetHeight(&relcbox);
  229.         if (plot == CMWIN_PLOTBOX) {        /* plotting (for paint message) */
  230.             for (;;) {
  231.                 last = 0;
  232.                 lasta = attrbuf[last];
  233.                 for (i = 0; i <= cwidth; i++) {
  234.                     if (i == cwidth) {
  235.                         ptd_PlotTextbuf(ptd, xpix + last*fwidth, ypix,
  236.                                         charbuf+last, lasta, i-last);
  237.                         break;
  238.                     }
  239.                     if (attrbuf[i] != lasta) {
  240.                         ptd_PlotTextbuf(ptd, xpix + last*fwidth, ypix,
  241.                                         charbuf+last, lasta, i-last);
  242.                         last = i;
  243.                         lasta = attrbuf[last];
  244.                     }
  245.                 }
  246.                 if (row <= 1) {
  247.                     break;
  248.                 }
  249.  
  250.                 ypix += fheight;
  251.                 charbuf += cmap->ncols;
  252.                 attrbuf += cmap->ncols;
  253.                 row--;
  254.             }
  255.         }
  256.         else if (plot == CMWIN_SHADOW) {        /* plotting (for shadow message) */
  257.             for (;row > 0; row--) {
  258.                 ptd_PlotTextbuf(ptd, xpix, ypix, charbuf, 
  259.                         win_GetShadowAttr(win), cwidth);
  260.  
  261.                 ypix += fheight;
  262.                 charbuf += cmap->ncols;
  263.                 attrbuf += cmap->ncols;
  264.             }
  265.         }
  266.         else {        /* reading (for isave message) */
  267.             for (;;) {
  268.                 ptd_ReadCharAttrbuf(ptd, xpix, ypix, charbuf, attrbuf, cwidth);
  269.                 if (row <= 1) {
  270.                     break;
  271.                 }
  272.  
  273.                 ypix += fheight;
  274.                 charbuf += cmap->ncols;
  275.                 attrbuf += cmap->ncols;
  276.                 row--;
  277.             }
  278.         }
  279.     }
  280. }
  281. /* -------------------------------------------------------------------------- */
  282.  
  283. static void OWLPRIV ptd_ReadCharAttrbuf(ptd, x, y, charbuf, attrbuf, slen)
  284.     ptd_struct *ptd;
  285.     opcoord x;
  286.     opcoord y;
  287.     char *charbuf;
  288.     byte *attrbuf;
  289.     int slen;
  290. {
  291.     ptarg_struct pta;
  292.  
  293.     pta.ptd = ptd;
  294.     pta.x = x;
  295.     pta.y = y;
  296.     pta.charbuf = charbuf;
  297.     pta.attrbuf = attrbuf;
  298.     pta.slen = slen;
  299.  
  300.     disp_Control(DC_READCHARATTR, &pta, NULL);
  301. }
  302. /* -------------------------------------------------------------------------- */
  303.  
  304.