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

  1. /*
  2.     os2disp.c
  3.  
  4.     % OS/2 VIO text mode device interface functions.
  5.  
  6.     11/11/88  by Ted.
  7.  
  8.     OWL
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      1/14/89 ted    Removed redundant disp clips.
  15.      1/18/89 Ted    changed call to PlotText for simplified interface.
  16.      4/09/89 ted    converted for static digdata.
  17.      4/22/89 ted    added digpriv's.
  18.      9/11/89 gam    added some casts for Version 1.1
  19. */
  20.  
  21. #include "os2priv.h"
  22.  
  23. #ifdef OAK_OS2            /* Only compile this for OS2 */
  24.  
  25. #define MAXPLOTLEN    132        /* the maximum length string PlotText can do */
  26.  
  27. static void            DIGPRIV    vio_setfuncs(_arg1(dig_struct *));
  28. static void            DIGPRIV    vio_cellcolor(_arg2(opixval, byte *));
  29.  
  30. static dig_dControl_func    (vio_dControl);
  31. static dig_pPlotText_func    (vio_PlotText);
  32. static dig_pDrawCursor_func    (vio_DrawCursor);
  33. static dig_pClear_func        (vio_Clear);
  34. static dig_pScrollBoxVt_func (vio_ScrollBoxVt);
  35. static dig_pScrollBoxHz_func (vio_ScrollBoxHz);
  36. static void vio_ReadCharAttrbuf(_arg6(ptd_struct *, opcoord, opcoord, char *, byte *, int));
  37. static unsigned    os2_dDummy(_arg1(void));
  38.  
  39. static void DIGPRIV vio_scrollvt(_arg2(opbox *, opcoord));
  40. static void DIGPRIV vio_scrollhz(_arg2(opbox *, opcoord));
  41.  
  42. /* -------------------------------------------------------------------------- */
  43.  
  44. boolean os2_ModeText(digp)
  45.     dig_struct *digp;
  46. {
  47.     if (!os2_OpenDIG(digp, NULL)) {
  48.         return(FALSE);
  49.     }
  50.     vio_setfuncs(digp);
  51.     return(TRUE);
  52. }
  53. /* -------------------------------------------------------------------------- */
  54.  
  55. static void DIGPRIV vio_setfuncs(digp)
  56.     dig_struct *digp;
  57.  
  58. {
  59.     digp->CloseDIG = os2_CloseDIG;
  60.     digp->dControl      = vio_dControl;
  61.  
  62.     digp->pPlotText     = vio_PlotText;
  63.     digp->pDrawCursor   = vio_DrawCursor;
  64.     digp->pClear        = vio_Clear;
  65.     digp->pScrollBoxVt  = vio_ScrollBoxVt;
  66.     digp->pScrollBoxHz  = vio_ScrollBoxHz;
  67.  
  68.     /* in hardware cursor text modes, no pixmap funcs are needed */
  69.     digp->pDrawPixmap   = (dig_pDrawPixmap_func ((*))) os2_dDummy;
  70.     digp->pReadPixmap   = (dig_pReadPixmap_func ((*))) os2_dDummy;
  71.     digp->pControl      = (dig_pControl_func ((*))) os2_dDummy;
  72.  
  73.     digp->vtscroll = TRUE;
  74.     digp->hzscroll = TRUE;
  75.     digp->textfree = FALSE;
  76.     digp->evcheck  = TRUE;
  77.     digp->type = 0;
  78.     digp->version = 0;
  79. }
  80. /* -------------------------------------------------------------------------- */
  81.  
  82. static void DIGPRIV vio_cellcolor(color, cell)
  83.     opixval color;
  84.     byte *cell;
  85. /*
  86.     Return a 16 bit value which can be repeated to clear a region to the
  87.     given color.
  88. */
  89. {
  90.     cell[0] = ' ';
  91.     /* put color val in bgcolor slot, and invert it for fgcolor slot */
  92.     cell[1] = (byte)color & 0x07;
  93.     cell[1] = (cell[1] ^ 0x07) | (cell[1] << 4);
  94. }
  95. /* -------------------------------------------------------------------------- */
  96.  
  97. static int vio_dControl(msg, indata, outdata)
  98.     dig_dcmsg msg;
  99.     VOID *indata;
  100.     VOID *outdata;
  101. {
  102.     setattr_struct *pvs;
  103.  
  104.     switch (msg) {
  105.     case DC_GETINFO:
  106.         *((dispinfo_struct **)(outdata)) = &os2data->info;
  107.         break;
  108.     case DC_INITMODE:
  109.         os2_initmode();
  110.         break;
  111.     case DC_RESTOREMODE:
  112.         VioSetCurPos(os2data->oldcursy, os2data->oldcursx, os2data->hvio);
  113.         os2_vsetcursortype(CURSOR_NORMAL);
  114.         break;
  115.     case DC_SETATTRCOLS:
  116.         pvs = (setattr_struct *)indata;
  117.  
  118.         os2data->attrmap[pvs->attr] =  ((byte) (pvs->fg)) & 0x0F;
  119.         os2data->attrmap[pvs->attr] |= ((byte) (pvs->bg)) << 4;
  120.         break;
  121.     case DC_GETATTRFG:
  122.         *((opixval *) outdata) = (opixval)
  123.             (os2data->attrmap[*((byte *)indata)] & 0x0F);
  124.         break;
  125.     case DC_GETATTRBG:
  126.         *((opixval *) outdata) = (opixval)
  127.             (os2data->attrmap[*((byte *)indata)] >> 4);
  128.         break;
  129.     case DC_SETCOLMAP:
  130.         break;
  131.     case DC_OPENFONT:
  132.           memmove((VOID *)(ofont_type)outdata, (VOID *)&os2data->info.def_font,
  133.                 sizeof(struct ofont_struct));
  134.           memmove((VOID *)(&((ofont_type)outdata)->req), (VOID *)indata,
  135.                 sizeof(fontreq_struct));
  136.         break;
  137.     case DC_READCHARATTR:
  138.         {    ptarg_struct *pta = (ptarg_struct *)indata;
  139.             vio_ReadCharAttrbuf(pta->ptd, pta->x, pta->y,
  140.                                     pta->charbuf, pta->attrbuf, pta->slen);
  141.         }
  142.         break;
  143. #ifdef OAK_FAMILYAPI
  144.     case DC_CACHE:
  145.         if (os2data->h->ismouse) {
  146.             if (os2data->dosbox) {
  147.                 OREGS regs;
  148.                 regs.x.ax = BMOU_HIDE;
  149.                 oakint86(BIOS_MOUSEINT, ®s);
  150.             }
  151.             else {
  152.                 os2_dohide();
  153.             }
  154.         }
  155.         break;
  156.     case DC_FLUSH:
  157.         if (os2data->h->ismouse) {
  158.             if (os2data->dosbox) {
  159.                 OREGS regs;
  160.                 regs.x.ax = BMOU_SHOW;
  161.                 oakint86(BIOS_MOUSEINT, ®s);
  162.             }
  163.             else {
  164.                 os2_doshow();
  165.             }
  166.         }
  167.         break;
  168. #else
  169.     case DC_CACHE:
  170.         if (os2data->h->ismouse) {
  171.             os2_dohide();
  172.         }
  173.         break;
  174.     case DC_FLUSH:
  175.         if (os2data->h->ismouse) {
  176.                 os2_doshow();
  177.         }
  178.         break;
  179. #endif
  180.     }
  181.     return(TRUE);
  182. }
  183. /* -------------------------------------------------------------------------- */
  184.  
  185. static void vio_PlotText(ptd, x, y, charbuf, rchar, rattr, slen)
  186.     ptd_struct *ptd;
  187.     opcoord x;
  188.     opcoord y;
  189.     char *charbuf;
  190.     char rchar;
  191.     byte rattr;
  192.     int slen;
  193. {
  194.     win_type win;
  195.     opbox clipbox;
  196.     int delta;
  197.     byte tbuf[2*MAXPLOTLEN];
  198.  
  199.     win = ptd->win;
  200.  
  201.     opbox_copy(&clipbox, ptd->relboxp);
  202.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  203.     x += win_GetXmin(win);
  204.     y += win_GetYmin(win);
  205.  
  206.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  207.     if (slen <= 0) {
  208.         return;
  209.     }
  210.     if (charbuf != NULL) charbuf += delta;
  211.  
  212.     y -= 1;        /* Move y up to top of char box for vio cell address */
  213.  
  214.     rattr = os2data->attrmap[rattr];
  215.  
  216. /* Index into buf for clipping. */
  217.     if (charbuf != NULL) {
  218.     /* Draw the string, interleaving chars with rattr */
  219.         VioWrtCharStrAtt(charbuf, slen, y, x, &rattr, os2data->hvio);
  220.     }
  221.     else {    /* no charbuf */
  222.     /* Draw a string of rchar/rattr pairs */
  223.         tbuf[0] = rchar;
  224.         tbuf[1] = rattr;
  225.         VioWrtNCell(tbuf, slen, y, x, os2data->hvio);
  226.     }
  227. }
  228. /* -------------------------------------------------------------------------- */
  229.  
  230. static void vio_DrawCursor(ptd, ctype)
  231.     ptd_struct *ptd;
  232.     cursortype ctype;
  233. {
  234.     win_type win;
  235.     opbox clipbox;
  236.     int row, col;
  237.     ofont_type font;
  238.     opcoord x;
  239.     opcoord y;
  240.     int slen;
  241.  
  242.     win = ptd->win;
  243.     font = win_GetFont(win);
  244.  
  245.     opbox_copy(&clipbox, ptd->relboxp);
  246.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  247.     x = win_GetXmin(win) + win_GetCursx(win);
  248.     y = win_GetYmin(win) + win_GetCursy(win);
  249.  
  250.     col = opcoord_GetXCol(x + ofont_GetWidth(font) - 1, font);    /* round in */
  251.     row = opcoord_GetYRow(y - 1, font);
  252.     x = col * ofont_GetWidth(font);
  253.     y = (row + 1) * ofont_GetHeight(font);
  254.  
  255.     slen = 1;
  256.     opbox_clipstring(&clipbox, &x, &y, &slen, font);
  257.     if (slen <= 0) {
  258.         return;
  259.     }
  260.     if (ctype != CURSOR_NONE) {
  261.         VioSetCurPos(row, col, os2data->hvio);
  262.     }
  263.     if (os2data->curctype != ctype) {
  264.         os2_vsetcursortype(ctype);
  265.     }
  266. }
  267. /* -------------------------------------------------------------------------- */
  268.  
  269. static void vio_Clear(ptd, color)
  270.     ptd_struct *ptd;
  271.     opixval color;
  272. {
  273.     win_type win;
  274.     opbox scrbox;
  275.     byte cell[2];
  276.  
  277.     win = ptd->win;
  278.  
  279.     opbox_copy(&scrbox, ptd->relboxp);
  280.     opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
  281.  
  282.     vio_cellcolor(color, cell);
  283.  
  284.     VioScrollUp(scrbox.ymin, scrbox.xmin,
  285.                 scrbox.ymax-1, scrbox.xmax-1,
  286.                 opbox_GetHeight(&scrbox), cell, os2data->hvio);
  287. }
  288. /* -------------------------------------------------------------------------- */
  289.  
  290. void vio_ScrollBoxVt(ptd, nrows)
  291.     ptd_struct *ptd;
  292.     opcoord nrows;
  293. {
  294.     win_type win;
  295.     opbox scrbox;
  296.  
  297.     win = ptd->win;
  298.  
  299.     opbox_copy(&scrbox, ptd->relboxp);
  300.     opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
  301.  
  302.     vio_scrollvt(&scrbox, nrows);
  303. }
  304. /* -------------------------------------------------------------------------- */
  305.  
  306. static void vio_ScrollBoxHz(ptd, ncols)
  307.     ptd_struct *ptd;
  308.     opcoord ncols;
  309. {
  310.     win_type win;
  311.     opbox scrbox;
  312.  
  313.     win = ptd->win;
  314.  
  315.     opbox_copy(&scrbox, ptd->relboxp);
  316.     opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
  317.  
  318.     vio_scrollhz(&scrbox, ncols);
  319. }
  320. /* -------------------------------------------------------------------------- */
  321.  
  322. static void vio_ReadCharAttrbuf(ptd, x, y, charbuf, attrbuf, slen)
  323.     ptd_struct *ptd;
  324.     opcoord x;
  325.     opcoord y;
  326.     char *charbuf;
  327.     byte *attrbuf;
  328.     int slen;
  329. {
  330.     win_type win;
  331.     opbox clipbox;
  332.     int delta;
  333.     byte tbuf[2*MAXPLOTLEN];
  334.  
  335.     win = ptd->win;
  336.  
  337.     opbox_copy(&clipbox, ptd->relboxp);
  338.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  339.     x += win_GetXmin(win);
  340.     y += win_GetYmin(win);
  341.  
  342.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  343.     if (slen <= 0) {
  344.         return;
  345.     }
  346.     if (charbuf != NULL) charbuf += delta;
  347.     if (attrbuf != NULL) attrbuf += delta;
  348.  
  349.     if (attrbuf == NULL || charbuf == NULL) {
  350.         return;
  351.     }
  352.  
  353.     /* Read the string in from display in char/attr form */
  354.     if (slen > MAXPLOTLEN) slen = MAXPLOTLEN;
  355.     slen *= 2;
  356.     VioReadCellStr(tbuf, (PUSHORT)&slen, (USHORT)y-1, (USHORT)x, os2data->hvio);
  357.     slen /= 2;
  358.  
  359.     /* Separate chars and attrs */
  360.     for (delta = 0; slen > 0; slen--) {
  361.         *charbuf++ = (char)tbuf[delta++];
  362.         *attrbuf++ = tbuf[delta++];
  363.     }
  364. }
  365. /* -------------------------------------------------------------------------- */
  366.  
  367. static unsigned os2_dDummy(void)
  368. {
  369.     return(0);
  370. }
  371. /* -------------------------------------------------------------------------- */
  372. /* -------------------------------------------------------------------------- */
  373. static byte blank[2] = {0x20, 0x07};
  374.  
  375. static void DIGPRIV vio_scrollvt(scrboxp, nrows)
  376.     opbox *scrboxp;
  377.     opcoord nrows;
  378. {
  379.     if (nrows > 0) {
  380.         if (nrows >= opbox_GetHeight(scrboxp)) return;    /* quit if scroll all */
  381.         VioScrollUp(scrboxp->ymin, scrboxp->xmin,
  382.                     scrboxp->ymax-1, scrboxp->xmax-1,
  383.                     nrows, blank, os2data->hvio);
  384.     }
  385.     else if (nrows < 0) {
  386.         nrows = -nrows;
  387.         if (nrows >= opbox_GetHeight(scrboxp)) return;    /* quit if scroll all */
  388.         VioScrollDn(scrboxp->ymin, scrboxp->xmin,
  389.                     scrboxp->ymax-1, scrboxp->xmax-1,
  390.                     nrows, blank, os2data->hvio);
  391.     }
  392.     else return;
  393. }
  394. /* -------------------------------------------------------------------------- */
  395.  
  396. static void DIGPRIV vio_scrollhz(scrboxp, ncols)
  397.     opbox *scrboxp;
  398.     opcoord ncols;
  399. {
  400.     if (ncols > 0) {
  401.         if (ncols >= opbox_GetWidth(scrboxp)) return;    /* quit if scroll all */
  402.         VioScrollLf(scrboxp->ymin, scrboxp->xmin,
  403.                     scrboxp->ymax-1, scrboxp->xmax-1,
  404.                     ncols, blank, os2data->hvio);
  405.     }
  406.     else if (ncols < 0) {
  407.         ncols = -ncols;
  408.         if (ncols >= opbox_GetWidth(scrboxp)) return;    /* quit if scroll all */
  409.         VioScrollRt(scrboxp->ymin, scrboxp->xmin,
  410.                     scrboxp->ymax-1, scrboxp->xmax-1,
  411.                     ncols, blank, os2data->hvio);
  412.     }
  413.     else return;                                /* quit if no scroll */
  414. }
  415. /* -------------------------------------------------------------------------- */
  416.  
  417. #else    /* ifndef OAK_OS2 */
  418. /* A dummy so compilers won't freak if everything else is ifdef'ed out. */
  419.     int os2textdummy(void);
  420.     int os2textdummy() { return(0); }
  421. #endif
  422.  
  423.