home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name wnsetopt -- Set window option
- *
- * Synopsis presult = wnsetopt(pwin,item,value);
- *
- * BWINDOW *presult Pointer to window, or NIL if
- * failure.
- * BWINDOW *pwin Pointer to window.
- * int item Identifying code number of option to
- * set.
- * int value Data value.
- *
- * Description This function modifies one of a window's
- * characteristics.
- *
- * Depending on the item requested, an error may occur if
- * the window is not attached to a screen location. (That
- * is, the window must have been displayed with WNDSPLAY,
- * although it may be hidden.)
- *
- * An error also occurs if the item requested is unknown or
- * cannot be changed or if pwin does not point to a valid
- * window.
- *
- * Returns presult Pointer to window, or NIL if
- * failure.
- * *pwin Window structure values perhaps
- * altered.
- * b_wnerr Possible values:
- * (No change) Success.
- * WN_BAD_WIN *pwin is invalid.
- * WN_NOT_SHOWN *pwin not currently
- * attached to screen
- * location.
- * WN_HARD Item can't be changed
- * via this routine.
- * WN_ILL_VALUE Illegal value for this
- * item.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <bwindow.h>
-
- #if MSC300
- #include <malloc.h>
- #else
- #include <stdlib.h>
- #endif
-
- #define FALSE 0
- #define TRUE (!FALSE)
-
- /* Macro to build a case statement which tests the new value and */
- /* performs the assignment if the value meets the specified */
- /* condition. */
-
- #define easycase(item_num,cond,data,calc) \
- case (item_num): \
- if (cond) \
- { \
- (data) = (calc); \
- presult = pwin; \
- } \
- else \
- { \
- wnerror(WN_ILL_VALUE); \
- presult = NIL; \
- } \
- break;
-
- /* Macro to build a case which tests and assigns a value for a */
- /* bitfield. */
-
- #define bitcase(item_num,data,calc) \
- easycase(item_num,(value==0||value==1),data,calc)
-
- /* Macro to build a case which assigns the new value without */
- /* testing its validity. */
-
- #define anycase(item_num,data,calc) \
- case (item_num): \
- (data) = (calc); \
- presult = pwin; \
- break;
-
- BWINDOW *wnsetopt(pwin,item,value)
- BWINDOW *pwin;
- int item,value;
- {
- int dev;
- BWINDOW *presult;
-
- if (wnvalwin(pwin) == NIL) /* Validate window structure. */
- {
- wnerror(WN_BAD_WIN);
- return NIL;
- }
-
- dev = pwin->where_shown.dev;
- if (item < 0) /* This kind of item is */
- { /* meaningless unless window is */
- /* displayed. */
- if (dev != MONO && dev != COLOR)
- {
- wnerror(WN_NOT_SHOWN);
- return NIL;
- }
- }
-
- switch (item)
- {
- /* Cursor on/off state */
- bitcase( WN_CUR_OFF, pwin->options.cur_off,
- value)
-
- /* Cursor scan lines */
- easycase( WN_CUR_HIGH, (value >= 0 && value <= 13),
- pwin->cur_type.high,
- value)
- easycase( WN_CUR_LOW, (value >= 0 && value <= 13),
- pwin->cur_type.low,
- value)
-
- /* User-controllable options */
- bitcase( WN_DELAYED, pwin->options.delayed,
- value)
-
- /* Default attributes */
- anycase( WN_ATTR, pwin->attr,
- value)
-
- case WN_REMOVABLE:
- if (value == 0)
- { /* Making non-removable. */
- if (pwin->options.removable)
- {
- /* Discard copy of previous */
- /* screen data. */
- if (pwin->prev.pdata != NIL)
- {
- free((char *) pwin->prev.pdata);
- pwin->prev.pdata = NIL;
- }
- pwin->options.removable = value;
- }
- presult = pwin;
- }
- else if (value == 1)
- { /* Making removable. */
- if ( (!pwin->options.removable)
- && (dev == MONO || dev == COLOR))
- { /* Too late: already displayed */
- /* and non-removable. */
- wnerror(WN_ILL_VALUE);
- presult = NIL;
- }
- else
- { /* Easy to make it removable. */
- pwin->options.removable = value;
- presult = pwin;
- }
- }
- else
- {
- wnerror(WN_ILL_VALUE);
- presult = NIL;
- }
- break;
-
- case WN_HIDDEN:
-
- case WN_ROW_REL:
- case WN_COL_REL:
- case WN_ROW_ABS:
- case WN_COL_ABS:
-
- case WN_IS_CURRENT:
- case WN_ACTIVE_CUR:
-
- case WN_BOR_TYPE:
- case WN_BOR_CHAR:
- case WN_BOR_ATTR:
-
- case WN_DEVICE:
- case WN_PAGE:
- case WN_ROW_CORNER:
- case WN_COL_CORNER:
- case WN_FROZEN:
- case WN_DIRTY:
- case WN_ANY_DATA_COVERED:
- case WN_ROWS:
- case WN_COLS:
- case WN_ROW_OVERALL:
- case WN_COL_OVERALL:
- case WN_HT_OVERALL:
- case WN_WID_OVERALL:
- wnerror(WN_HARD);
- presult = NIL;
- break;
-
- default:
- wnerror(WN_BAD_OPT); /* Unknown item requested. */
- presult = NIL;
- break;
- }
-
- return presult;
- }