home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name wncreate -- Allocate and create a window structure.
- *
- * Synopsis presult = wncreate(height,width,attr);
- *
- * BWINDOW *presult Pointer to newly-created BWINDOW
- * structure, or NIL if failure.
- * int height Number of rows in data area
- * int width Number of columns in data area
- * int attr Default attribute in data area
- *
- * Description This function allocates space for a window structure and
- * fills it with default values. This includes allocating
- * and initializing the window's data area with blanks
- * (' ') having the specified attribute.
- *
- * An error occurs if the window dimensions exceed maximum
- * screen dimensions or if the memory allocation fails.
- *
- * Use WNDSTROY to discard the BWINDOW structure and
- * related internal data structures.
- *
- * Returns presult Pointer to newly-created BWINDOW
- * structure, or NIL if failure.
- * b_wnerr Possible values:
- * (No change) Success.
- * WN_ILL_DIM Invalid dimensions.
- * WN_NO_MEMORY Insufficient memory.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <string.h>
-
- #include <bwindow.h>
-
- #if LAT300
- #include <stdlib.h>
- #endif
- #if MSC300
- #include <malloc.h>
- #endif
-
- int b_wnerr = WN_NO_ERROR; /* Most recent error */
- /* (WN_NO_ERROR if none). */
-
- BWINDOW *wncreate(height,width,attr)
- int height,width,attr;
- {
- BWINDOW *pwin;
- CELL *ptr;
- int area,i;
-
- if ( utrange(height,1,PC_BIG_ROWS) /* Validate dimensions. */
- || utrange(width, 1,PC_COLS))
- {
- wnerror(WN_ILL_DIM);
- return NIL;
- }
-
- if ((pwin = utalloc(BWINDOW)) == NIL) /* Allocate space for the */
- { /* structure. */
- wnerror(WN_NO_MEMORY);
- return NIL;
- }
-
- pwin->img.dim.h = height;
- pwin->img.dim.w = width;
- if (wnmkimg(&pwin->img) == NIL) /* Allocate space for memory */
- { /* image. */
-
- free((char *) pwin); /* Clean up after failure. */
- return NIL;
- }
-
- area = height * width;
- for (ptr = pwin->img.pdata, i = 0; i < area; i++)
- {
- ptr ->ch = ' ';
- ptr++->attr = (char) attr;
- }
-
- /* Initialize fields to default values (except where 0 is an */
- /* acceptable default value). */
-
- pwin->attr = attr;
- pwin->where_shown.dev = ABSENT; /* Not currently shown. */
- pwin->cur_type.high = 12; /* Default cursor type. */
- pwin->cur_type.low = 13;
- pwin->options.removable = 1;
-
- strcpy(pwin->signature,BWIN_SIGN);/* Distinctive signature. */
-
- return pwin; /* Success. */
- }