home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name HLREAD -- Display help in a virtual window and read
- * user responses.
- *
- * Synopsis presult = hlread (pwin, phelp_win, ptext, text_length,
- * pfinal, option);
- *
- * WN_EVENT *presult pfinal, or NIL if an error
- * occured.
- * BWINDOW *pwin Pointer to window in which to
- * display help text, or NIL if
- * HLREAD is to create one.
- * HL_WINDOW *phelp_win Pointer to the help window
- * descriptor to use in construct-
- * ing and building the help
- * window, or NIL to use default.
- * const char *ptext Pointer to help text to be
- * displayed.
- * int text_length Length of the text to be
- * displayed.
- * WN_EVENT *pfinal Pointer to structure to fill in
- * with a copy of the event which
- * terminated the read.
- * int option Bitwise ORing of the following:
- * HL_REMOVE_WIN: Remove the
- * window before returning.
- * HL_DESTROY_WIN: Remove and
- * destroy the window before
- * returning.
- * ORed with one of the following:
- * HL_CHARS_ONLY:
- * *ptext contains characters
- * only.
- * HL_CHAR_ATTR:
- * *ptext contains character/
- * attribute pairs.
- * HL_COMPRESSED:
- * *ptext points to text which
- * is in UTSQZSCN format.
- * ORed with one of the following:
- * HL_USE_MOUSE: Use the mouse if
- * it is present.
- * HL_NO_MOUSE: Do not use the
- * mouse.
- * HL_KBIGNORE: Ignore the keyboard
- * and discard all keystrokes.
- *
- *
- * Description This function accepts a pointer to help text and
- * parameters describing the window it should be displayed
- * in, constructs and displays the window, and reads user
- * responses from it until a terminating event is
- * encountered.
- *
- * The help window's characteristics (i.e., viewport size,
- * attributes, etc.) are taken from the help window
- * descriptor pointed to by *phelp_win.
- *
- * If pwin is NIL, then the window will be created and
- * displayed by HLREAD; upon exit, it will always be
- * removed and destroyed. If pwin is non-NIL, then the
- * help text is displayed in it rather than creating a
- * new one; HLREAD will remove and/or destroy it according
- * to the value of option.
- *
- * An error occurs if the location where the window is to
- * be displayed is impossible, for example if the
- * dimensions of the viewport exceed the screen's or the
- * data area's dimensions.
- *
- * The return value is a pointer to the event node which
- * terminated the read. Note that if pwin is NIL, or
- * the HL_DESTROY_WIN option is specified, the pointer
- * will point to an internal static copy of the event
- * structure; this copy will be overwritten with each call
- * to HLREAD.
- *
- * Returns *pfinal Copy of event node which terminated
- * the read process (the event's action
- * will be either WN_TRANSMIT or
- * WN_ABORT).
- * b_pcurwin If HL_REMOVE_WIN or HL_DESTROY_WIN
- * is not specified, pointer to
- * newly-displayed BWINDOW structure,
- * or unchanged if failure.
- * b_wnerr Possible values:
- * (No change) Success.
- * HL_NO_EXIT No event will
- * transmit or abort
- * the window.
- * HL_BAD_OPT Unknown option
- * specified.
- * WN_BAD_DEV Unknown device or
- * window dimensions
- * overflow screen.
- * WN_ILL_DIM Viewport is larger
- * than data area, or
- * origin is illegal.
- * WN_NO_MEMORY Insufficient memory.
- * WN_BAD_WIN Internal error.
- * WN_ALREADY_SHOWN Internal error.
- * WN_BAD_NODE Internal error.
- * WN_BAD_PAGE Internal error.
- * WN_COVERED Internal error.
- * WN_NOT_SHOWN Internal error.
- * WN_NULL_PTR Internal error.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
-
- #include <bhelp.h>
- #include <bwindow.h>
- #include <butil.h>
-
-
- HL_WINDOW b_def_help_win = /* Default help record window. */
- { /* */
- 5, 9, /* Viewport top left corner. */
- 19, 69, /* Viewport bottom right corner.*/
- 0, 0, /* Data area origin coordinates.*/
- NORMAL | INTENSITY, SC_CYAN, /* Window foreground/background.*/
- 0, /* Default border (BBRD_SSSS). */
- NORMAL | INTENSITY, SC_CYAN, /* Border foreground/background.*/
- BBRD_NO_TITLE, /* Title position. */
- NORMAL | INTENSITY, SC_BLUE, /* Title foreground/background. */
- 15, /* Number of rows in data area. */
- 61, /* # of columns in data area. */
- SC_BLUE, SC_CYAN, /* Cross reference attributes. */
- SC_BLUE | INTENSITY, NORMAL, /* Highlighted cross reference. */
- {'\0'} /* # of columns in data area. */
- };
-
- const static int title_table[] = /* Table of title positions. */
- {
- BBRD_TCT,
- BBRD_TRT,
- BBRD_TLT,
- BBRD_BCT,
- BBRD_BRT,
- BBRD_BLT
- };
-
-
- WN_EVENT *hlread(pwin, phelp_win, ptext, text_length, pfinal,
- option)
- BWINDOW *pwin;
- const HL_WINDOW *phelp_win;
- const char *ptext;
- int text_length;
- WN_EVENT *pfinal;
- int option;
- {
- int save_error;
- int made_window = 0;
- char *pwindow_data;
- int dest_length;
- int mode, columns;
- BORDER border;
- WHERE where;
- const HL_WINDOW *phelp_window;
-
- if (phelp_win == NIL)
- phelp_window = &b_def_help_win;
- else
- phelp_window = phelp_win;
-
- if (pwin == NIL)
- {
- pwin = wncreate(phelp_window->data_rows,
- phelp_window->data_columns,
- utnybbyt(phelp_window->data_back,
- phelp_window->data_fore));
- if (pwin == NIL)
- return(NIL);
-
- if (wnsetopt(pwin, WN_CUR_OFF, 1) == NIL)
- {
- save_error = b_wnerr;
- wndstroy(pwin);
- hlreterr(save_error);
- }
-
- made_window = 1;
- }
-
- /* If the window is not displayed, set up a WHERE */
- /* and a BORDER for it based on the default help */
- /* window. Otherwise, just make a copy of the */
- /* values stored in the window. */
- if ((pwin->where_shown.dev != SC_COLOR) &&
- (pwin->where_shown.dev != SC_MONO))
- {
- where.dev = scmode(&mode, &columns, &where.page);
- where.corner.row = phelp_window->view_top;
- where.corner.col = phelp_window->view_left;
-
- if (!utrange(phelp_window->border_type, 0, 15))
- border.type = phelp_window->border_type + 1;
- else
- if (phelp_window->border_type == 255)
- border.type = BBRD_NO_BORDER;
- else
- {
- border.type = 31;
- border.ch = phelp_window->border_type;
- }
- border.attr = utnybbyt(phelp_window->border_back,
- phelp_window->border_fore);
-
- if (utrange(phelp_window->title_type, 0,
- (sizeof(title_table) / sizeof(title_table[0])) - 1) ||
- (phelp_window->pwindow_title == NIL) ||
- (phelp_window->pwindow_title[0] == '\0'))
- {
- border.type |= BBRD_NO_TITLE;
- }
- else
- border.type |= title_table[phelp_window->title_type];
-
- if (border.type != BBRD_NO_BORDER)
- if (border.type & (BBRD_TLT | BBRD_TCT | BBRD_TRT))
- {
- border.pttitle = phelp_window->pwindow_title;
- border.ttattr = utnybbyt(phelp_window->title_back,
- phelp_window->title_fore);
- }
- else
- if (border.type & (BBRD_BLT | BBRD_BCT | BBRD_BRT))
- {
- border.pbtitle = phelp_window->pwindow_title;
- border.btattr = utnybbyt(phelp_window->title_back,
- phelp_window->title_fore);
- }
- }
- else
- {
- memcpy(&where, &(pwin->where_shown), sizeof(where));
- memcpy(&border, &(pwin->bord), sizeof(border));
- }
-
- if (wnselect(pwin) == NIL)
- {
- save_error = b_wnerr;
- if (made_window)
- wndstroy(pwin);
- hlreterr(save_error);
- }
-
- switch (option & HL_TEXT_TYPE)
- {
- case HL_CHARS_ONLY:
- wnwrrect(pwin, 0, 0, wndata_h(pwin) - 1, wndata_w(pwin) - 1,
- ptext, -1, -1, CHARS_ONLY);
- break;
-
- case HL_CHAR_ATTR:
- wnwrrect(pwin, 0, 0, wndata_h(pwin) - 1, wndata_w(pwin) - 1,
- ptext, -1, -1, CHAR_ATTR);
- break;
-
- case HL_COMPRESSED:
- pwindow_data = (char *) pwin->img.pdata;
- dest_length = phelp_window->data_columns *
- phelp_window->data_rows * 2;
- utunsqz(ptext, pwindow_data, text_length, dest_length);
- break;
-
- default:
- hlreterr(HL_BAD_OPT);
- }
-
- /* Now read user responses from the window. Note */
- /* that if the window is already displayed, the */
- /* viewport dimensions, starting origin, where and */
- /* border structures are all ignored. */
- wnread(pwin, &where,
- phelp_window->view_bottom - phelp_window->view_top + 1,
- phelp_window->view_right - phelp_window->view_left + 1,
- phelp_window->origin_row, phelp_window->origin_col,
- &border, pfinal, (option & (HL_NO_MOUSE | HL_KBIGNORE)));
-
- if (made_window || (option & HL_REMOVE_WIN))
- if (wnremove(pwin) == NIL)
- return(NIL);
-
- if (made_window || (option & HL_DESTROY_WIN))
- {
- if (wndstroy(pwin) != WN_NO_ERROR)
- return(NIL);
- }
-
- return(pfinal);
- }