home *** CD-ROM | disk | FTP | other *** search
- /*
- os2disp.c
-
- % OS/2 VIO text mode device interface functions.
-
- 11/11/88 by Ted.
-
- OWL
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 1/14/89 ted Removed redundant disp clips.
- 1/18/89 Ted changed call to PlotText for simplified interface.
- 4/09/89 ted converted for static digdata.
- 4/22/89 ted added digpriv's.
- 9/11/89 gam added some casts for Version 1.1
- */
-
- #include "os2priv.h"
-
- #ifdef OAK_OS2 /* Only compile this for OS2 */
-
- #define MAXPLOTLEN 132 /* the maximum length string PlotText can do */
-
- static void DIGPRIV vio_setfuncs(_arg1(dig_struct *));
- static void DIGPRIV vio_cellcolor(_arg2(opixval, byte *));
-
- static dig_dControl_func (vio_dControl);
- static dig_pPlotText_func (vio_PlotText);
- static dig_pDrawCursor_func (vio_DrawCursor);
- static dig_pClear_func (vio_Clear);
- static dig_pScrollBoxVt_func (vio_ScrollBoxVt);
- static dig_pScrollBoxHz_func (vio_ScrollBoxHz);
- static void vio_ReadCharAttrbuf(_arg6(ptd_struct *, opcoord, opcoord, char *, byte *, int));
- static unsigned os2_dDummy(_arg1(void));
-
- static void DIGPRIV vio_scrollvt(_arg2(opbox *, opcoord));
- static void DIGPRIV vio_scrollhz(_arg2(opbox *, opcoord));
-
- /* -------------------------------------------------------------------------- */
-
- boolean os2_ModeText(digp)
- dig_struct *digp;
- {
- if (!os2_OpenDIG(digp, NULL)) {
- return(FALSE);
- }
- vio_setfuncs(digp);
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV vio_setfuncs(digp)
- dig_struct *digp;
-
- {
- digp->CloseDIG = os2_CloseDIG;
- digp->dControl = vio_dControl;
-
- digp->pPlotText = vio_PlotText;
- digp->pDrawCursor = vio_DrawCursor;
- digp->pClear = vio_Clear;
- digp->pScrollBoxVt = vio_ScrollBoxVt;
- digp->pScrollBoxHz = vio_ScrollBoxHz;
-
- /* in hardware cursor text modes, no pixmap funcs are needed */
- digp->pDrawPixmap = (dig_pDrawPixmap_func ((*))) os2_dDummy;
- digp->pReadPixmap = (dig_pReadPixmap_func ((*))) os2_dDummy;
- digp->pControl = (dig_pControl_func ((*))) os2_dDummy;
-
- digp->vtscroll = TRUE;
- digp->hzscroll = TRUE;
- digp->textfree = FALSE;
- digp->evcheck = TRUE;
- digp->type = 0;
- digp->version = 0;
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV vio_cellcolor(color, cell)
- opixval color;
- byte *cell;
- /*
- Return a 16 bit value which can be repeated to clear a region to the
- given color.
- */
- {
- cell[0] = ' ';
- /* put color val in bgcolor slot, and invert it for fgcolor slot */
- cell[1] = (byte)color & 0x07;
- cell[1] = (cell[1] ^ 0x07) | (cell[1] << 4);
- }
- /* -------------------------------------------------------------------------- */
-
- static int vio_dControl(msg, indata, outdata)
- dig_dcmsg msg;
- VOID *indata;
- VOID *outdata;
- {
- setattr_struct *pvs;
-
- switch (msg) {
- case DC_GETINFO:
- *((dispinfo_struct **)(outdata)) = &os2data->info;
- break;
- case DC_INITMODE:
- os2_initmode();
- break;
- case DC_RESTOREMODE:
- VioSetCurPos(os2data->oldcursy, os2data->oldcursx, os2data->hvio);
- os2_vsetcursortype(CURSOR_NORMAL);
- break;
- case DC_SETATTRCOLS:
- pvs = (setattr_struct *)indata;
-
- os2data->attrmap[pvs->attr] = ((byte) (pvs->fg)) & 0x0F;
- os2data->attrmap[pvs->attr] |= ((byte) (pvs->bg)) << 4;
- break;
- case DC_GETATTRFG:
- *((opixval *) outdata) = (opixval)
- (os2data->attrmap[*((byte *)indata)] & 0x0F);
- break;
- case DC_GETATTRBG:
- *((opixval *) outdata) = (opixval)
- (os2data->attrmap[*((byte *)indata)] >> 4);
- break;
- case DC_SETCOLMAP:
- break;
- case DC_OPENFONT:
- memmove((VOID *)(ofont_type)outdata, (VOID *)&os2data->info.def_font,
- sizeof(struct ofont_struct));
- memmove((VOID *)(&((ofont_type)outdata)->req), (VOID *)indata,
- sizeof(fontreq_struct));
- break;
- case DC_READCHARATTR:
- { ptarg_struct *pta = (ptarg_struct *)indata;
- vio_ReadCharAttrbuf(pta->ptd, pta->x, pta->y,
- pta->charbuf, pta->attrbuf, pta->slen);
- }
- break;
- #ifdef OAK_FAMILYAPI
- case DC_CACHE:
- if (os2data->h->ismouse) {
- if (os2data->dosbox) {
- OREGS regs;
- regs.x.ax = BMOU_HIDE;
- oakint86(BIOS_MOUSEINT, ®s);
- }
- else {
- os2_dohide();
- }
- }
- break;
- case DC_FLUSH:
- if (os2data->h->ismouse) {
- if (os2data->dosbox) {
- OREGS regs;
- regs.x.ax = BMOU_SHOW;
- oakint86(BIOS_MOUSEINT, ®s);
- }
- else {
- os2_doshow();
- }
- }
- break;
- #else
- case DC_CACHE:
- if (os2data->h->ismouse) {
- os2_dohide();
- }
- break;
- case DC_FLUSH:
- if (os2data->h->ismouse) {
- os2_doshow();
- }
- break;
- #endif
- }
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_PlotText(ptd, x, y, charbuf, rchar, rattr, slen)
- ptd_struct *ptd;
- opcoord x;
- opcoord y;
- char *charbuf;
- char rchar;
- byte rattr;
- int slen;
- {
- win_type win;
- opbox clipbox;
- int delta;
- byte tbuf[2*MAXPLOTLEN];
-
- win = ptd->win;
-
- opbox_copy(&clipbox, ptd->relboxp);
- opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
- x += win_GetXmin(win);
- y += win_GetYmin(win);
-
- delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
- if (slen <= 0) {
- return;
- }
- if (charbuf != NULL) charbuf += delta;
-
- y -= 1; /* Move y up to top of char box for vio cell address */
-
- rattr = os2data->attrmap[rattr];
-
- /* Index into buf for clipping. */
- if (charbuf != NULL) {
- /* Draw the string, interleaving chars with rattr */
- VioWrtCharStrAtt(charbuf, slen, y, x, &rattr, os2data->hvio);
- }
- else { /* no charbuf */
- /* Draw a string of rchar/rattr pairs */
- tbuf[0] = rchar;
- tbuf[1] = rattr;
- VioWrtNCell(tbuf, slen, y, x, os2data->hvio);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_DrawCursor(ptd, ctype)
- ptd_struct *ptd;
- cursortype ctype;
- {
- win_type win;
- opbox clipbox;
- int row, col;
- ofont_type font;
- opcoord x;
- opcoord y;
- int slen;
-
- win = ptd->win;
- font = win_GetFont(win);
-
- opbox_copy(&clipbox, ptd->relboxp);
- opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
- x = win_GetXmin(win) + win_GetCursx(win);
- y = win_GetYmin(win) + win_GetCursy(win);
-
- col = opcoord_GetXCol(x + ofont_GetWidth(font) - 1, font); /* round in */
- row = opcoord_GetYRow(y - 1, font);
- x = col * ofont_GetWidth(font);
- y = (row + 1) * ofont_GetHeight(font);
-
- slen = 1;
- opbox_clipstring(&clipbox, &x, &y, &slen, font);
- if (slen <= 0) {
- return;
- }
- if (ctype != CURSOR_NONE) {
- VioSetCurPos(row, col, os2data->hvio);
- }
- if (os2data->curctype != ctype) {
- os2_vsetcursortype(ctype);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_Clear(ptd, color)
- ptd_struct *ptd;
- opixval color;
- {
- win_type win;
- opbox scrbox;
- byte cell[2];
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- vio_cellcolor(color, cell);
-
- VioScrollUp(scrbox.ymin, scrbox.xmin,
- scrbox.ymax-1, scrbox.xmax-1,
- opbox_GetHeight(&scrbox), cell, os2data->hvio);
- }
- /* -------------------------------------------------------------------------- */
-
- void vio_ScrollBoxVt(ptd, nrows)
- ptd_struct *ptd;
- opcoord nrows;
- {
- win_type win;
- opbox scrbox;
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- vio_scrollvt(&scrbox, nrows);
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_ScrollBoxHz(ptd, ncols)
- ptd_struct *ptd;
- opcoord ncols;
- {
- win_type win;
- opbox scrbox;
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- vio_scrollhz(&scrbox, ncols);
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_ReadCharAttrbuf(ptd, x, y, charbuf, attrbuf, slen)
- ptd_struct *ptd;
- opcoord x;
- opcoord y;
- char *charbuf;
- byte *attrbuf;
- int slen;
- {
- win_type win;
- opbox clipbox;
- int delta;
- byte tbuf[2*MAXPLOTLEN];
-
- win = ptd->win;
-
- opbox_copy(&clipbox, ptd->relboxp);
- opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
- x += win_GetXmin(win);
- y += win_GetYmin(win);
-
- delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
- if (slen <= 0) {
- return;
- }
- if (charbuf != NULL) charbuf += delta;
- if (attrbuf != NULL) attrbuf += delta;
-
- if (attrbuf == NULL || charbuf == NULL) {
- return;
- }
-
- /* Read the string in from display in char/attr form */
- if (slen > MAXPLOTLEN) slen = MAXPLOTLEN;
- slen *= 2;
- VioReadCellStr(tbuf, (PUSHORT)&slen, (USHORT)y-1, (USHORT)x, os2data->hvio);
- slen /= 2;
-
- /* Separate chars and attrs */
- for (delta = 0; slen > 0; slen--) {
- *charbuf++ = (char)tbuf[delta++];
- *attrbuf++ = tbuf[delta++];
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static unsigned os2_dDummy(void)
- {
- return(0);
- }
- /* -------------------------------------------------------------------------- */
- /* -------------------------------------------------------------------------- */
- static byte blank[2] = {0x20, 0x07};
-
- static void DIGPRIV vio_scrollvt(scrboxp, nrows)
- opbox *scrboxp;
- opcoord nrows;
- {
- if (nrows > 0) {
- if (nrows >= opbox_GetHeight(scrboxp)) return; /* quit if scroll all */
- VioScrollUp(scrboxp->ymin, scrboxp->xmin,
- scrboxp->ymax-1, scrboxp->xmax-1,
- nrows, blank, os2data->hvio);
- }
- else if (nrows < 0) {
- nrows = -nrows;
- if (nrows >= opbox_GetHeight(scrboxp)) return; /* quit if scroll all */
- VioScrollDn(scrboxp->ymin, scrboxp->xmin,
- scrboxp->ymax-1, scrboxp->xmax-1,
- nrows, blank, os2data->hvio);
- }
- else return;
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV vio_scrollhz(scrboxp, ncols)
- opbox *scrboxp;
- opcoord ncols;
- {
- if (ncols > 0) {
- if (ncols >= opbox_GetWidth(scrboxp)) return; /* quit if scroll all */
- VioScrollLf(scrboxp->ymin, scrboxp->xmin,
- scrboxp->ymax-1, scrboxp->xmax-1,
- ncols, blank, os2data->hvio);
- }
- else if (ncols < 0) {
- ncols = -ncols;
- if (ncols >= opbox_GetWidth(scrboxp)) return; /* quit if scroll all */
- VioScrollRt(scrboxp->ymin, scrboxp->xmin,
- scrboxp->ymax-1, scrboxp->xmax-1,
- ncols, blank, os2data->hvio);
- }
- else return; /* quit if no scroll */
- }
- /* -------------------------------------------------------------------------- */
-
- #else /* ifndef OAK_OS2 */
- /* A dummy so compilers won't freak if everything else is ifdef'ed out. */
- int os2textdummy(void);
- int os2textdummy() { return(0); }
- #endif
-
-