home *** CD-ROM | disk | FTP | other *** search
- /*
- cmwin.c 3/11/88
-
- % Character map window object.
- By Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 6/16/88 Ted revised to have inheritance and class factory functions.
- 8/09/88 jmd revised to use new object stuff
- 8/15/88 jmd OPEN now takes a winopen_struct
- 9/12/88 jmd Added in and out data to objects
- 11/20/88 jmd Added ID to obj struct
- 12/13/88 jmd Added cmap = NULL to cmwin_GetCmap (removes LC warning)
-
- 1/18/89 Ted changed call to PlotText for simplified interface.
- 6/24/89 jmd added shadow support
- 8/12/89 jmd improved shadow support
- 8/12/89 jdc Added INIT and WHO message
- 8/13/89 jmd Added test for NULL cmap in INPOS message
-
- Questions... *** Answers 7/05/89 ted.
- 1) why is cmwin made current during ISAVE message?
- Because the ISAVE message is only sent during disp_Init to the
- background window, and this allows the vid_win to display its cursor.
- 2) read loop in cmwin_Plot looks like it could be better.
- Since this is a rarely used feature I optimized for code size and
- simplicity.
- 3) Spaces plotting should be optimized.
- Go ahead.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "cmwinobj.h"
- #include "cmwinod.h"
-
- OGLOBAL objreq_fptr cmwinreq_mousefptr = objreq_Null;
-
- OSTATIC void OWLPRIV cmwin_PlotBox(_arg3(ptd_struct *, cmwin_od *, int));
- OSTATIC void OWLPRIV ptd_ReadCharAttrbuf(_arg6(ptd_struct *, opcoord, opcoord, char *, byte *, int));
-
- #define CMWIN_READBOX 0
- #define CMWIN_PLOTBOX 1
- #define CMWIN_SHADOW 2
- /* -------------------------------------------------------------------------- */
-
- int cmwin_Class(objdata, msg, indata, outdata)
- VOID *objdata; /* object instance data pointer */
- int msg; /* message */
- VOID *indata; /* message input data */
- VOID *outdata; /* message output data */
- /*
- cmap window object dispatch function
- */
- {
- cmwin_od *cmwd;
- win_type win;
- cmap_type cmap;
- ofont_type font;
- ptd_struct *ptd;
- ptd_struct inptd; /* for use in inner-coordinate computations */
- opbox inbox; /* ditto; gets hooked in by ptd_SetInner */
- winopendata_struct *wod;
- inposdata_struct *ipd;
-
- cmwd = (cmwin_od *) objdata;
- if (msg != OBJM_GETDATASIZE) { /* would be GP fault in this case */
- win = cmwinod_GetSelf(cmwd);
- }
- switch(msg) {
- case OBJM_GETDATASIZE:
- ((ogds_struct *) outdata)->odsize = sizeof(cmwin_od);
- ((ogds_struct *) outdata)->xdsize = sizeof(cmwin_xd);
- ((ogds_struct *) outdata)->id = ID_CMWIN;
- break;
-
- case OBJM_INIT:
- wod = (winopendata_struct *) indata;
-
- if (wod->font == NULL) {
- return(FALSE);
- }
-
- /* Allocate character map */
- if ((cmap = cmap_Open(opbox_GetHeight(wod->boxp)/ofont_GetHeight(wod->font),
- opbox_GetWidth(wod->boxp)/ofont_GetWidth(wod->font))) == NULL) {
-
- return(FALSE);
- }
- cmwin_SetCmap(win, cmap);
-
- return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
-
- case OBJM_OPEN:
- /* Initialize cmap data */
- cmwin_SetCmap(win, NULL);
- cmwin_SetRowoffs(win, 0); /* offsets for scrolling cmap within window */
- cmwin_SetColoffs(win, 0);
-
- /* send OPEN message to win superclass */
- return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
-
- case OBJM_CLOSE:
- /* close character map */
- if (cmwin_GetCmap(win) != NULL) {
- cmap_Close(cmwin_GetCmap(win));
- }
- /* No break, pass CLOSE msg to win superclass */
- default:
- /* pass other messages to win superclass */
- return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
-
- case OBJM_WHO:
- /* Identify ourselves */
- if (*((int *) indata) == ID_CMWIN) {
- return(TRUE);
- }
- return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
-
- case WINM_SHADOW:
- ptd = (ptd_struct *)indata;
-
- /* set ptd data to indicate that we've taken care of the shadow */
- ptd->emsgdata = (VOID *) 1;
-
- /* no break; fall through to PAINT */
-
- case WINM_PAINT:
- ptd = (ptd_struct *)indata;
- if (ptd_SetInner(ptd, &inptd, &inbox)) {
- cmwin_PlotBox(&inptd, cmwd, (msg == WINM_PAINT) ? CMWIN_PLOTBOX : CMWIN_SHADOW);
- }
- return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
-
- case WINM_ISAVE:
- ptd = (ptd_struct *)indata;
-
- /* This is background cmwin; make it current */
- win_MakeCurrent(ptd->win);
-
- /* Get the characters from the display into the cmap */
- if (ptd_SetInner(ptd, &inptd, &inbox)) {
- cmwin_PlotBox(ptd, cmwd, CMWIN_READBOX);
- }
- break;
-
- case WINM_GETINPOS:
- ipd = (inposdata_struct *) outdata;
- font = win_GetFont(ipd->win);
-
- /* make sure cmap is valid (we could be in the middle of being
- loaded from a screen file)
- */
- if (cmwin_GetCmap(win) == NULL) {
- return(win_DoRaw(&(cmwd->wd), msg, indata, outdata));
- }
-
- ipd->inbox.xmin = -cmwin_GetColoffs(win) * ofont_GetWidth(font);
- ipd->inbox.xmax = ipd->inbox.xmin +
- (cmap_GetWidth(cmwin_GetCmap(win)) * ofont_GetWidth(font));
- ipd->inbox.ymin = -cmwin_GetRowoffs(win) * ofont_GetHeight(font);
- ipd->inbox.ymax = ipd->inbox.ymin +
- (cmap_GetHeight(cmwin_GetCmap(win)) * ofont_GetHeight(font));
- break;
-
- case WINM_SCROLLREQ:
- return((*cmwinreq_mousefptr)(cmwd, msg, indata, outdata));
- }
-
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV cmwin_PlotBox(ptd, cmwd, plot)
- ptd_struct *ptd;
- cmwin_od *cmwd;
- int plot; /* flag to plot, shadow, or read */
- /*
- Plots a region of a cmap window to the display.
- */
- {
- win_type win;
- cmap_type cmap;
- ocbox relcbox;
- opcoord xpix, ypix;
- int row;
- char *charbuf;
- byte *attrbuf;
- opcoord fwidth, fheight;
- int cwidth;
- int i, last;
- byte lasta, attr;
- ofont_type font;
-
- win = cmwinod_GetSelf(cmwd);
- cmap = cmwin_GetCmap(win);
- font = win_GetFont(ptd->win);
- fheight = ofont_GetHeight(font);
- fwidth = ofont_GetWidth(font);
-
- opbox_charcoords(ptd->relboxp, font, &relcbox);
- ocbox_trans(&relcbox, cmwin_GetRowoffs(win), cmwin_GetColoffs(win));
-
- /* Clear out the parts of the box not occupied by cmap, if any */
- attr = (plot == CMWIN_SHADOW) ? win_GetShadowAttr(win) : win_GetAttr(win);
-
- ptd_ClearFrame(ptd, -cmwin_GetColoffs(win) * fwidth, -cmwin_GetRowoffs(win) * fheight,
- cmwin_GetCmap(win)->ncols * fwidth, cmwin_GetCmap(win)->nrows * fheight,
- disp_GetAttrBgColor(attr));
-
- /* Plot the text from the window */
- if (cmap_clipcbox(cmap, &relcbox)) {
-
- charbuf = cmap_charbuf(cmap, relcbox.toprow, relcbox.leftcol);
- attrbuf = cmap_charattrbuf(cmap, charbuf);
-
- ocbox_trans(&relcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
-
- ypix = (relcbox.toprow + 1) * fheight;
- xpix = (relcbox.leftcol) * fwidth;
- cwidth = ocbox_GetWidth(&relcbox);
-
- row = ocbox_GetHeight(&relcbox);
- if (plot == CMWIN_PLOTBOX) { /* plotting (for paint message) */
- for (;;) {
- last = 0;
- lasta = attrbuf[last];
- for (i = 0; i <= cwidth; i++) {
- if (i == cwidth) {
- ptd_PlotTextbuf(ptd, xpix + last*fwidth, ypix,
- charbuf+last, lasta, i-last);
- break;
- }
- if (attrbuf[i] != lasta) {
- ptd_PlotTextbuf(ptd, xpix + last*fwidth, ypix,
- charbuf+last, lasta, i-last);
- last = i;
- lasta = attrbuf[last];
- }
- }
- if (row <= 1) {
- break;
- }
-
- ypix += fheight;
- charbuf += cmap->ncols;
- attrbuf += cmap->ncols;
- row--;
- }
- }
- else if (plot == CMWIN_SHADOW) { /* plotting (for shadow message) */
- for (;row > 0; row--) {
- ptd_PlotTextbuf(ptd, xpix, ypix, charbuf,
- win_GetShadowAttr(win), cwidth);
-
- ypix += fheight;
- charbuf += cmap->ncols;
- attrbuf += cmap->ncols;
- }
- }
- else { /* reading (for isave message) */
- for (;;) {
- ptd_ReadCharAttrbuf(ptd, xpix, ypix, charbuf, attrbuf, cwidth);
- if (row <= 1) {
- break;
- }
-
- ypix += fheight;
- charbuf += cmap->ncols;
- attrbuf += cmap->ncols;
- row--;
- }
- }
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV ptd_ReadCharAttrbuf(ptd, x, y, charbuf, attrbuf, slen)
- ptd_struct *ptd;
- opcoord x;
- opcoord y;
- char *charbuf;
- byte *attrbuf;
- int slen;
- {
- ptarg_struct pta;
-
- pta.ptd = ptd;
- pta.x = x;
- pta.y = y;
- pta.charbuf = charbuf;
- pta.attrbuf = attrbuf;
- pta.slen = slen;
-
- disp_Control(DC_READCHARATTR, &pta, NULL);
- }
- /* -------------------------------------------------------------------------- */
-
-