home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name wndsplay -- Display window on video page with border.
- *
- * Synopsis presult = wndsplay(pwin,pwhere,pbord);
- *
- * BWINDOW *presult Pointer to newly-displayed BWINDOW
- * structure, or NIL if failure.
- * BWINDOW *pwin Pointer to BWINDOW structure to
- * display.
- * WHERE *pwhere Pointer to WHERE structure denoting
- * device, display page, and coordinates
- * where window is to be displayed.
- * BORDER *pbord Pointer to BORDER structure denoting
- * type of border to put around window.
- *
- * Description This function displays a window on a given video device
- * and display page and adds a border.
- *
- * The window is made current (selected for I/O).
- *
- * The window's cursor is activated (although the cursor
- * may be invisible). The cursors of other windows on that
- * page are deactivated.
- *
- * An error occurs if pwin does not point to a valid window
- * structure. An error also occurs if the location where
- * the window is to be displayed is impossible, for example
- * if an unknown device is requested or if the dimensions
- * of the window exceed the screen's dimensions.
- *
- * Returns presult Pointer to newly-displayed BWINDOW
- * structure, or NIL if failure.
- * b_pcurwin Pointer to newly-displayed BWINDOW
- * structure, or unchanged if failure.
- * *pwin Several fields altered.
- * b_wnlist[][] Linked list altered.
- * b_pactnode[][] Window node with active cursor.
- * b_wnerr Possible values:
- * (No change) Success.
- * WN_BAD_WIN *pwin is invalid.
- * WN_ALREADY_SHOWN Already shown.
- * WN_BAD_DEV Unknown device or
- * window dimensions
- * overflow screen.
- * WN_NO_MEMORY Insufficient memory.
- * WN_BAD_NODE Internal error.
- * WN_BAD_PAGE Internal error.
- * WN_COVERED Internal error.
- * WN_ILL_DIM Internal error.
- * WN_NOT_SHOWN Internal error.
- * WN_NULL_PTR Internal error.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- * Version 3.02 March 23, 1987
- * Corrected handling of pwin->prev.pdata when redisplaying
- * window.
- * Preserved WNUNHIDE error codes from being obscured by
- * subsequent errors.
- *
- **/
-
- #include <bwindow.h>
-
- #if MSC300
- #include <malloc.h>
- #include <memory.h>
- #else
- #include <stdlib.h>
- #endif
-
- /* Internal function (see below)*/
- static REGION *bordim(REGION *,DIM *,BORDER *,WHERE *);
-
- BWINDOW *wndsplay(pwin,pwhere,pborder)
- BWINDOW *pwin;
- WHERE *pwhere;
- BORDER *pborder;
- {
- REGION occupied; /* Region occupied by window */
- /* and border. */
- int old_npage;
-
- if (wnvalwin(pwin) == NIL) /* Validate window structure. */
- {
- wnerror(WN_BAD_WIN);
- return NIL;
- }
-
- if ( pwin->where_shown.dev == MONO /* Confirm that window is */
- || pwin->where_shown.dev == COLOR) /* not currently shown. */
- {
- wnerror(WN_ALREADY_SHOWN);
- return NIL;
- }
-
- if (wnseldev(pwhere,&pwin->img.dim,&old_npage))
- /* Validate device, page, and */
- { /* dimensions and select device */
- wnerror(WN_BAD_DEV); /* and page. */
- return NIL;
- }
-
- /* Obtain overall dimensions */
- /* including the border. */
- bordim(&occupied,&pwin->img.dim,pborder,pwhere);
- utcopy(&pwin->where_prev,pwhere,WHERE);
- utcopy(&pwin->where_prev.corner,&occupied.ul,LOC);
-
- if (pwin->options.removable)
- { /* Removable window: */
- if (pwin->prev.pdata != NIL)
- { /* Already have a buffer for */
- /* previous screen contents. */
- if ( REGION_H(occupied) * REGION_H(occupied)
- > pwin->prev.dim.h * pwin->prev.dim.w )
- { /* Existing buffer too small, */
- free((char *) pwin->prev.pdata); /* so discard it. */
- pwin->prev.pdata = NIL;
- }
- }
- pwin->prev.dim.h = REGION_H(occupied);
- pwin->prev.dim.w = REGION_W(occupied);
- if (pwin->prev.pdata == NIL)
- { /* Allocate space for previous */
- /* screen contents. */
- if (wnmkimg(&pwin->prev) == NIL)
- return NIL;
- }
- }
- pwin->prev.dim.h = REGION_H(occupied);
- pwin->prev.dim.w = REGION_W(occupied);
-
- utcopy(&pwin->where_shown,pwhere, WHERE); /* Record where shown */
- utcopy(&pwin->bord, pborder,BORDER); /* and border. */
-
- /* Display the window by */
- /* 1) adding this window to linked list for this display page; */
- /* 2) marking it hidden; */
- /* 3) un-hiding it. */
-
- if ((pwin->pnode = wnpgadd(pwin,pwhere->dev,pwhere->page)) == NIL)
- {
- pwin->where_shown.dev = ABSENT;
- return NIL;
- }
-
- pwin->options.hidden = 1;
-
- if (wnunhide(pwin) == NIL)
- {
- if (pwin->where_shown.dev != ABSENT)
- { /* Clean up after error. */
- wnpgrem(pwin);
- pwin->where_shown.dev = ABSENT;
- }
- }
-
- wnselect(pwin); /* Select for I/O */
- wncursor(pwin); /* Select this window as the */
- /* one on this page to have an */
- /* active cursor. */
-
- return pwin; /* Success. */
- }
-
- /**
- *
- * Name bordim -- Calculate actual dimensions required by a
- * border around a rectangular region
- * on the current display device.
- *
- * Synopsis presult = bordim(pregion,pdim,pborder,pwhere);
- *
- * REGION *presult Pointer to structure describing
- * location and dimensions of the region
- * to be occupied by the border.
- * REGION *pregion Pointer to structure describing
- * location and dimensions of the region
- * to be occupied by the border.
- * DIM *pdim Pointer to structure describing
- * dimensions of rectangular region to
- * be surrounded by border.
- * BORDER *pborder Pointer to structure describing
- * type of border.
- * WHERE *pwhere Pointer to WHERE structure denoting
- * location of rectangular region to be
- * surrounded by border.
- *
- * Description This function calculates the actual dimensions required
- * by a border around a rectangular region on the current
- * display device. It takes into account the way WNPUTBOR
- * works at the edges of the screen.
- *
- * This function assumes that the rectangular region fits
- * on the current screen.
- *
- * Returns *presult,*pregion Pointer to structure describing
- * location and dimensions of the region
- * to be occupied by the border.
- *
- **/
-
- static REGION *bordim(pregion,pdim,pborder,pwhere)
- REGION *pregion;
- DIM *pdim;
- BORDER *pborder;
- WHERE *pwhere;
- {
- int bottom_row,right_column;
- int mode,columns,act_page;
-
- bottom_row = pwhere->corner.row + pdim->h;
- right_column = pwhere->corner.col + pdim->w;
-
- if (pborder->type == 0
- || pwhere->corner.row <= 0
- || pwhere->corner.col <= 0
- || bottom_row >= scrows()
- || (scmode(&mode,&columns,&act_page),
- (right_column >= columns)))
- {
- utcopy(&pregion->ul,&pwhere->corner,LOC);
- pregion->lr.row = bottom_row - 1;
- pregion->lr.col = right_column - 1;
- }
- else
- {
- pregion->ul.row = pwhere->corner.row - 1;
- pregion->ul.col = pwhere->corner.col - 1;
- pregion->lr.row = bottom_row;
- pregion->lr.col = right_column;
- }
-
- return pregion;
- }